Commit 81fa1495 by 陶然

优化了合并申请的接口

parent 18b0c433
......@@ -336,25 +336,20 @@ namespace Kivii.Finances.Transforms
public List<Guid> Kvids { get; set; }
public InvoiceApplyDetail Detail { get; set; }
public List<InvoiceApplyDetail> Details { get; set; }
//发票开具最大额度限制 默认10万
public decimal Limit { get; set; } = 100000;
public override object OnExecution(IRequest req, IResponse res)
{
(Detail == null && Details.IsNullOrEmpty()).ThrowIfTrue("Need Detail Or Details!");
if (Details.IsNullOrEmpty()) Details = new List<InvoiceApplyDetail>();
if (Detail != null) Details.Add(Detail);
if (Kvids == null || Kvids.Count <= 0) throw new Exception("请先选择申请条目!");
Item.ThrowIfNull("申请内容不能为空!");
Item.Details.ThrowIfNullOrEmpty("缺少申请明细信息!");
if (Item.OperateType != InvoiceApplyType.Payment) throw new Exception("合并开票只针对收款刷卡现金申请!");
if (Kvids == null || Kvids.Count <= 0) throw new Exception("请先选择申请条目!");
if (Details.Exists(o => o.GoodsFullName.IsNullOrEmpty())) throw new Exception("明细名称存在空值!");
if (Details.Exists(o => o.TaxRate < 0) || Details.Exists(o => o.TaxRate > 1)) throw new Exception("存在明细税率设置范围不在0-1之间!");
if (Details.Exists(o => o.Quantity <= 0)) throw new Exception("请填写数量!");
var group = Details.GroupBy(o => o.GoodsId);
if (Item.Details.Exists(o => o.GoodsFullName.IsNullOrEmpty())) throw new Exception("明细名称存在空值!");
if (Item.Details.Exists(o => o.TaxRate < 0) || Item.Details.Exists(o => o.TaxRate > 1)) throw new Exception("存在明细税率设置范围不在0-1之间!");
if (Item.Details.Exists(o => o.Quantity <= 0)) throw new Exception("请填写数量!");
var group = Item.Details.GroupBy(o => o.GoodsId);
foreach (var kv in group)
{
var sum = kv.Sum(o => o.Amount);
......@@ -368,22 +363,22 @@ namespace Kivii.Finances.Transforms
if (applys.Count < 2) throw new Exception("请选择两条以上的申请进行合并!");
//if (applys.Exists(o => o.Type != "VATS")) throw new Exception("普票暂时无法合并开票");
if (applys.Exists(o => o.PayerName != Item.PayerName)) throw new Exception("合并申请抬头不一致!");
if (!applys.Exists(o => o.OperateType != InvoiceApplyType.Payment)) throw new Exception("合并开票只针对收款刷卡现金申请!");
if (applys.Exists(o => o.OperateType != InvoiceApplyType.Payment)) throw new Exception("合并开票只针对收款刷卡现金申请!");
if (applys.Exists(o => o.OperateType == InvoiceApplyType.Payment)) Item.OperateType = InvoiceApplyType.Payment;
var groups = applys.GroupBy(o => new { o.PayerName, o.PayerTaxNumber });
if (groups.Count() != 1) throw new Exception("合并申请抬头不一致!");
if (applys.Exists(o => o.Status > (int)InvoiceApplyStatus.FinancialExecute)) throw new Exception("请勿重复申请开票!");
if (applys.Exists(o => o.Status < (int)InvoiceApplyStatus.ProcessAdoption)) throw new Exception("此申请还在审批中...");
if (applys.Sum(o => o.Amount) != Item.Amount) throw new Exception("合并金额与申请金额不一致!");
if (Item.Amount != Details.Sum(o => o.Amount)) throw new Exception("总金额和明细总额不一致!");
if (Item.Amount != Item.Details.Sum(o => o.Amount)) throw new Exception("总金额和明细总额不一致!");
var remark = $"[总: {Item.Amount}元]";
var summary = $"申请合并:[总: {Item.Amount}元]";
foreach (var item in applys)
{
remark += $"[{item.OwnerName}: {item.Amount}元]";
summary += $"[{item.OwnerName}: {item.Amount}元]";
}
#region 计算(不根据前端传来)
foreach (var detail in Details)
foreach (var detail in Item.Details)
{
detail.AmountUntaxed = Math.Round(detail.Amount / (1 + detail.TaxRate), 2);
detail.AmountTax = detail.Amount - detail.AmountUntaxed;
......@@ -410,8 +405,8 @@ namespace Kivii.Finances.Transforms
newApply.Amount = applys.Sum(o => o.Amount);
//newApply.AmountUsed = applys.Sum(o => o.AmountUsed);
newApply.Status = (int)InvoiceApplyStatus.FinancialApproval;
newApply.Summary = Item.Summary;
newApply.Remark = remark;
newApply.Summary = summary;
newApply.Remark = Item.Remark;
newApply.Metadata["PayeeOperatorName"] = Item.Metadata.ContainsKey("PayeeOperatorName") ? Item.Metadata["PayeeOperatorName"] : KiviiContext.CurrentMember.FullName;
newApply.Metadata["ReviewerName"] = Item.Metadata.ContainsKey("ReviewerName") ? Item.Metadata["ReviewerName"] : KiviiContext.CurrentMember.FullName;
conn.Insert(newApply);
......@@ -419,7 +414,7 @@ namespace Kivii.Finances.Transforms
#endregion
#region ApplyDetail入库
foreach (var detail in Details)
foreach (var detail in Item.Details)
{
detail.ApplyKvid = newInvoiceApplyKvid;
conn.Insert(detail);
......
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