Commit 2218a692 by 陶然

新增创建空账单接口

parent df2d17cb
......@@ -38,10 +38,10 @@ namespace Kivii.Finances
return offsetBillDetail;
}
public static Bill Accept(this Bill bill, List<Settlement> settlements, IDbConnection conn = null)
public static Bill Accept(this Bill bill, List<Settlement> settlements = null, IDbConnection conn = null)
{
bill.ThrowIfNull("账单不能为空!");
settlements.ThrowIfNullOrEmpty("结算不能为空!");
//settlements.ThrowIfNullOrEmpty("结算不能为空!");
var rtns = new Bill();
......@@ -65,6 +65,8 @@ namespace Kivii.Finances
rtns.OwnerName = KiviiContext.CurrentMember.DepartmentName;
conn.Insert(rtns);
if (!settlements.IsNullOrEmpty())
{
foreach (var settlement in settlements)
{
var billDetail = new BillDetail();
......@@ -84,6 +86,7 @@ namespace Kivii.Finances
billDetail.OperatorName = KiviiContext.CurrentMember.FullName;
conn.Insert(billDetail);
}
}
trans?.Commit();
return rtns;
}
......@@ -92,7 +95,6 @@ namespace Kivii.Finances
trans?.Rollback();
throw ex;
}
}
......
......@@ -197,4 +197,41 @@ namespace Kivii.Finances.Transforms
return rtns;
}
}
[Api(Description = "创建空账单")]
[RequiresAnyRole(SystemRoles.Everyone)]
public class BillCreateEx:RestfulExecution<Bill>
{
public Bill Item { get; set; }
public override object OnExecution(IRequest req, IResponse res)
{
if (Item.PayerName.IsNullOrEmpty() || Item.PayeeName.IsNullOrEmpty()) throw new Exception("收付双方不能为空!");
if (Item.Currency == CurrencyUnit.Unsupported) throw new Exception("未传入货币单位!");
var conn = KiviiContext.GetOpenedDbConnection<Bill>();
conn.InitEntityType<Bill>();
conn.InitEntityType<BillDetail>();
if (Item.Amount<=0) throw new Exception("账单金额不能小于0!");
var rtns = new RestfulCreateResponse<Bill>();
rtns.Results = new List<Bill>();
//var trans = conn.OpenTransaction();
try
{
var bill = Item.Accept(null,conn);
bill.RemoveAllOnlyProperties();
rtns.Results.Add(bill);
//trans.Commit();
}
catch (Exception ex)
{
//trans.Rollback();
throw ex;
}
return rtns;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment