diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs index a9ffa065..bb3c01bd 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs @@ -129,7 +129,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ customConditionList.Add(new CustomCondition() { Name = "BillNum", Value = invbillNum }); customConditionList.Add(new CustomCondition() { Name = "BussinessType", Value = main.BusinessType.ToString() }); await _bbacMng.SetWaitingState(invbillNum).ConfigureAwait(false); - var _taskid = await _service.ExportEnqueueAsync("生成发票任务", ExportExtentsion.Excel, string.Empty, string.Empty, CurrentUser, typeof(GenerateJisInvoiceService), customConditionList, (rs) => + var _taskid = await _service.ExportEnqueueAsync("生成发票任务", ExportExtentsion.Excel, string.Empty, string.Empty, CurrentUser, typeof(GenerateJisInvoiceService), customConditionList, (rs) => { }).ConfigureAwait(false); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs index a4170657..f4eb5c6b 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs @@ -68,6 +68,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime && p.IsCancel == false && p.ClientCode == main.Site select new TEMP_CAN_SA_DETAIL { + Id = d.Id, SettleBillNum = d.SettleBillNum, Site = d.Site, Version = d.Version, @@ -149,8 +150,17 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs PartCode = p.PartCode }).ToList();//不能结算 - var invs = FirstInvoiceExtend(entitys, new List(), dtos, notlist, main.Version, main.InvGroupNum, string.Empty, main.BusinessType); - //var invs = SecInvoice(entitys, new List(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType, query.ToList()); + + entitys = entitys.OrderBy(p => p.LU).ToList(); + + + + + + + + var invs = FirstInvoiceExtend1(entitys, new List(), dtos, notlist, main.Version, main.InvGroupNum, string.Empty, main.BusinessType); + // var invs = SecInvoice(entitys, new List(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType, query.ToList()); if (invs.Count > 0) { main.State = SettleBillState.已开票; @@ -239,7 +249,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs Qty = g.Sum(p => p.Qty), }; - + //var invs = FirstInvoiceExtend1(entitys, new List(), dtos, notlist, main.Version, main.InvGroupNum, string.Empty, main.BusinessType); var invs = SecInvoice(entitys, new List(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType, query.ToList()); if (invs.Count > 0) { @@ -281,7 +291,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs Dictionary> invoiceMap = new Dictionary>();//发票和发票明细关系 foreach (var group in groups) { - int i = groups1.Count(p => p.LU == group.LU + int i = groups1.Count(p => + p.LU == group.LU + && p.PartCode == group.PartCode && p.BeginDate == group.BeginDate && p.EndDate == group.EndDate @@ -1193,25 +1205,196 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs } return _invls; } - // public List FirstInvoiceExtend1(List p_list, List p_adjlist, List dtos, List p_notlist, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType) - //where TDetail : SA_CAN_BASE, new() - // { - // var gener = new InvoiceGenerator(); - // gener.GenerateInvoices(p_list); - // var invList = gener.Invoices; - // if (invList.Count > 0) - // { - // foreach (var inv in invList) - // { - // var partlist = inv.Parts; - // if (partlist.Count > 0) - // { - // partlist.GroupBy(p => new { p.InvGroupNum, p.PartCode, p.Price, p.BeginDate, p.EndDate, p.ContractDocID, p.LU }) - // } - // } - // } - // return new List(); - // } + + + + + + + + public List FirstInvoiceExtend1(List p_list, List p_adjlist, List dtos, List p_notlist, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType) + where TDetail : SA_CAN_BASE, new() + { + //var gener = new InvoiceGeneratorSame(); + //var list =p_list.OrderBy(p => p.LU).ThenBy(p=>p.PartCode).ToList(); + //gener.GenerateInvoices(p_list); + //var invList = gener.Invoices; + + + var detailDtos = dtos.GroupBy(p => new { p.InvGroupNum, p.PartCode, p.Price, p.BeginDate, p.EndDate, p.ContractDocID, p.LU })//明细 + .Select(itm => new GroupPartCode + { + PartCode = itm.Key.PartCode, + InvGroupNum = itm.Key.InvGroupNum, + LU = itm.Key.LU, + ContactDocID = itm.Key.ContractDocID, + Price = itm.Key.Price, + Amt = Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2),//税前 + Tax = Math.Round(Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2) * 0.13m, 2),//税 + TaxAmt = Math.Round(Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2) * 0.13m, 2) + Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2),//税后进 + Qty = itm.Sum(k => k.Qty), + BeginDate = itm.Key.BeginDate, + EndDate = itm.Key.EndDate + }).ToList(); + + + List biglist = new List(); + List smalllist = new List(); + foreach (var itm in detailDtos) + { + if (itm.Amt > 10000000) + { + biglist.Add(itm); + } + else + { + smalllist.Add(itm); + } + } + + foreach (var itm in biglist) + { + var list = p_list.Where(p => p.InvGroupNum == itm.InvGroupNum && p.PartCode == itm.PartCode && p.Price == itm.Price && p.LU == itm.LU); + var gener = new InvoiceGeneratorSame(); + gener.GenerateInvoices(p_list); + var invList = gener.Invoices; + } + smalllist = smalllist.OrderBy(p => p.Amt).ToList(); + var gener1 = new InvoiceGeneratorDiff(); + gener1.GenerateInvoices(smalllist); + var invList1 = gener1.Invoices; + + + + + + + + + + + + + + + + + + + + + + // if (invList.Count > 0) + // { + // var groupList = new List(); + // var notDetialList = new List(); + // var detailList = new List(); + // var invlist = new List(); + // var salist = new List(); + // var adjlist = new List(); + // foreach (var inv in invList) + // { + // var partlist = inv.Parts; + // if (partlist.Count > 0) + // { + // var query = from itm in p_list join itm1 in dtos on itm.Id equals itm1.Id + // select itm1; + // var Dtos = query.ToList(); + // var detailDtos = Dtos.GroupBy(p => new { p.InvGroupNum, p.PartCode, p.Price, p.BeginDate, p.EndDate, p.ContractDocID, p.LU })//明细 + // .Select(itm => new + // { + // PartCode = itm.Key.PartCode, + // InvGroupNum = itm.Key.InvGroupNum, + // LU = itm.Key.LU, + // ContactDocID = itm.Key.ContractDocID, + // Price = itm.Key.Price, + // Amt = Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2),//税前 + // Tax = Math.Round(Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2) * 0.13m, 2),//税 + // TaxAmt = Math.Round(Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2) * 0.13m, 2) + Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2),//税后进 + // Qty = itm.Sum(k => k.Qty), + // BeginDate = itm.Key.BeginDate, + // EndDate = itm.Key.EndDate + // }).ToList(); + + // decimal amt = detailDtos.Sum(k => k.Amt);//金额 + // decimal txtAmt = detailDtos.Sum(k => k.TaxAmt);//税后金额 + // decimal realAmt = detailDtos.Sum(k => k.Tax);//税额 + + + //#region 发票明细 + // List _entityDetailList = new List(); + // foreach (var detail in detailDtos) + // { + // _entityDetailList.Add( + // new INVOICE_WAIT_DETAIL( + // guid: GuidGenerator.Create(), + // version: p_version, + // invbillNum: inv.InvBillNum, + // invGroupNum: p_InvGroupNum, + // lU: detail.LU, + // qty: detail.Qty, + // bussiessType: businessType, + // amt: detail.Amt, + // pRICE: detail.Price, + // extend1: detail.ContactDocID, + // extend2: string.Empty, + // beginDate: detail.BeginDate, + // endDate: detail.EndDate, + // partcode: detail.PartCode + // )); + // } + // if (_entityDetailList.Count > 0) + // { + // detailList.AddRange(_entityDetailList); + // } + // #endregion + // #region 发票 + // var invbill = new INVOICE_GRP + // (guid: GuidGenerator.Create(), + // realnvBillNum: string.Empty, + // invbillNum: inv.InvBillNum, + // amt: amt, + // taxAmt: txtAmt, + // fileName: string.Empty, + // businessType: businessType, + // invGroupNum: p_InvGroupNum, + // state: SettleBillState.已开票, + // invoiceBillState: InvoiceBillState.正常, + // tax: 0.13m, + // parent: !string.IsNullOrEmpty(p_parentInvBillNum) ? p_parentInvBillNum : string.Empty, + // preTaxDiff: 0, + // taxDiff: 0, + // clientCode: string.Empty, + // realAmt: realAmt + + // ); + // string site = dtos.Where(p => !string.IsNullOrEmpty(p.Site)).FirstOrDefault().Site; + // string clientCode = string.Empty; + // switch (site) + // { + // case "1040": + // clientCode = "C001"; + // break; + // case "1046": + // clientCode = "C171"; + // break; + // default: + // clientCode = "C004"; + // break; + // } + // invbill.ClientCode = clientCode; + // invbill.Site = dtos.FirstOrDefault().Site; + // invbill.CreationTime = DateTime.MinValue; + // invbill.LastModificationTime = DateTime.Now; + // invlist.Add(invbill); + // #endregion + + + // } + // } + // } + return new List(); + } @@ -1219,61 +1402,135 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs } - public class InvoiceExtend + public class InvoiceBySame { public string InvBillNum { set; get; } - public InvoiceExtend() { } + public InvoiceBySame() { } private List parts = new List(); public IReadOnlyList Parts => parts.AsReadOnly(); public decimal TotalAmount => parts.Sum(p => p.Price); - public int PartCount => parts.Count; + public int PartCount => parts.GroupBy(p => new { p.LU, p.PartCode }).Count(); public bool CanAddPart(SA_CAN_BASE part) { - return TotalAmount + part.Price <= 10000000 && PartCount < 15; + return TotalAmount + part.Price <= 10000000 && PartCount < 15; ; } public void AddPart(SA_CAN_BASE part) { - if (!CanAddPart(part)) + if (CanAddPart(part)) { + part.InvbillNum = InvBillNum; + parts.Add(part); //throw new InvalidOperationException("Cannot add part to invoice. Check constraints."); } - part.InvbillNum = InvBillNum; - parts.Add(part); + } } - public class InvoiceGenerator + public class InvoiceGeneratorSame { - private List invoices = new List(); + private List invoices = new List(); - public IReadOnlyList Invoices => invoices.AsReadOnly(); + public IReadOnlyList Invoices => invoices.AsReadOnly(); public void GenerateInvoices(List parts) where TDetail : SA_CAN_BASE, new() { - InvoiceExtend currentInvoice = new InvoiceExtend(); + InvoiceBySame currentInvoice = new InvoiceBySame(); invoices.Add(currentInvoice); currentInvoice.InvBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); foreach (var part in parts) { if (!currentInvoice.CanAddPart(part)) { - currentInvoice = new InvoiceExtend(); + currentInvoice = new InvoiceBySame(); currentInvoice.InvBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); invoices.Add(currentInvoice); } currentInvoice.AddPart(part); } } - public InvoiceGenerator() + public InvoiceGeneratorSame() { } - public InvoiceGenerator(List invoices) + public InvoiceGeneratorSame(List invoices) + { + this.invoices = invoices; + } + } + + public class InvoiceByDiff + { + public string InvBillNum { set; get; } + public InvoiceByDiff() { } + private List parts = new List(); + public IReadOnlyList Parts => parts.AsReadOnly(); + public decimal TotalAmount => parts.Sum(p => p.Amt); + // public int PartCount => parts.GroupBy(p => new { p.LU, p.PartCode }).Count(); + public bool CanAddPart(GroupPartCode part) + { + return TotalAmount + part.Amt <= 10000000; + } + public void AddPart(GroupPartCode part) + { + if (CanAddPart(part)) + { + //part.InvbillNum = InvBillNum; + parts.Add(part); + //throw new InvalidOperationException("Cannot add part to invoice. Check constraints."); + } + } + } + + public class InvoiceGeneratorDiff + { + private List invoices = new List(); + + public IReadOnlyList Invoices => invoices.AsReadOnly(); + + public void GenerateInvoices(List parts) + { + InvoiceByDiff currentInvoice = new InvoiceByDiff(); + invoices.Add(currentInvoice); + currentInvoice.InvBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); + foreach (var part in parts) + { + if (!currentInvoice.CanAddPart(part)) + { + currentInvoice = new InvoiceByDiff(); + currentInvoice.InvBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); + invoices.Add(currentInvoice); + } + currentInvoice.AddPart(part); + } + } + public InvoiceGeneratorDiff() + { + + } + public InvoiceGeneratorDiff(List invoices) { this.invoices = invoices; } } + public class GroupPartCode + { + public string PartCode { set; get; } + public string InvGroupNum { set; get; } + public string LU { set; get; } + public string ContactDocID { set; get; } + public decimal Price { set; get; } + public decimal Amt { set; get; } + public decimal Tax { set; get; } + public decimal TaxAmt { set; get; } + public decimal Qty { set; get; } + public DateTime? BeginDate { set; get; } + public DateTime? EndDate { set; get; } + + } + + + diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs index 15f0b784..19c0bba4 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs @@ -1575,7 +1575,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ "ElSE 0 END ONLY_SA_QTY \n" + "from (\n" + "SELECT LU,PN,BusinessType,Qty,10 Type \n" + - $"from {setablename} A WITH(NOLOCK) where BusinessType={(int)p_businessType} AND Qty>0 AND REMARK='期初初始化' \n"; + $"from {setablename} A WITH(NOLOCK) where BusinessType={(int)p_businessType} AND Qty>0 AND WmsBillNum='0' \n"; if (!string.IsNullOrEmpty(sebegin)) { @@ -1589,7 +1589,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ sql += "UNION ALL\n" + "SELECT LU,PN,BusinessType,Qty,20 Type\n" + - $"from {setablename} A WITH(NOLOCK) where BusinessType={(int)p_businessType} AND Qty<0 and Remark='期初初始化' \n"; + $"from {setablename} A WITH(NOLOCK) where BusinessType={(int)p_businessType} AND Qty<0 and WmsBillNum='0' \n"; if (!string.IsNullOrEmpty(sebegin)) { @@ -1602,7 +1602,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ sql += "UNION ALL\n" + "SELECT LU,PN,BusinessType,Qty,100 Type\n" + - $"from {setablename} A WITH(NOLOCK) where BusinessType={(int)p_businessType} AND Qty>0 AND REMARK<>'期初初始化' \n"; + $"from {setablename} A WITH(NOLOCK) where BusinessType={(int)p_businessType} AND Qty>0 AND WmsBillNum<>'0' \n"; if (!string.IsNullOrEmpty(sebegin)) { @@ -1614,7 +1614,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } sql += "UNION ALL\n" + "SELECT LU,PN,BusinessType,Qty,150 Type\n" + - $"from {setablename} A WITH(NOLOCK) where BusinessType={(int)p_businessType} AND Qty<0 and Remark<>'期初初始化' \n"; + $"from {setablename} A WITH(NOLOCK) where BusinessType={(int)p_businessType} AND Qty<0 and WmsBillNum<>'0' \n"; if (!string.IsNullOrEmpty(sebegin)) { @@ -1639,6 +1639,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { sql += $" AND SettleDate <='{saend}'\n"; } + sql += "UNION ALL\n" + @@ -1696,8 +1697,18 @@ namespace Win.Sfs.SettleAccount.Entities.BQ connection.Close(); return ls; } + /// + /// jisbbac收发汇总 + /// + /// 发运开始时间 + /// 结算时间 + /// 结算开始时间 + /// 结算结算时间 + /// + /// [HttpPost] - public async Task GetReceiveShipSum(string sebegin, string seend, string sabegin, string saend) + + public async Task GetReceiveShipSum(string sebegin, string seend, string sabegin, string saend,string partcode) { ConcurrentBag bagList = new ConcurrentBag(); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/SHIP_REC_SUM.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/SHIP_REC_SUM.cs new file mode 100644 index 00000000..26fbcae3 --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/SHIP_REC_SUM.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Domain.Entities.Auditing; + +namespace Win.Sfs.SettleAccount.Entities.BQ +{ + public class SHIP_REC_SUM : AuditedAggregateRoot + { + [Display(Name = "客户零件号")] + public string LU { set; get; } + [Display(Name = "厂内零件号")] + public string PartCode { set; get; } + [Display(Name = "业务类型")] + public string BusinessType { set; get; } + [Display(Name = "期初发货数量")] + public string BSEQty { set; get; } + [Display(Name = "期初退货数量")] + public string BRETQty { set; get; } + [Display(Name = "实际发货数量")] + public string SEQTY { set; get; } + [Display(Name = "实际退货数量")] + public string RETQty { set; get; } + [Display(Name = "可结数量")] + public string CANQty { set; get; } + [Display(Name = "不可结数量")] + public string NOTQty { set; get; } + [Display(Name = "有发有结有价格数量")] + public string SE_SA_CAN_QTY { set; get; } + [Display(Name = "有发有结无价格数量")] + public string SE_SA_NOT_QTY { set; get; } + [Display(Name = "有发运无结算数量")] + public string ONLY_SE_QTY { set; get; } + [Display(Name = "有结算无发运数量")] + public string ONLY_SA_QTY { set; get; } + [Display(Name = "已开票数量")] + public string INVQty { set; get; } + + public SHIP_REC_SUM(string lU, string partCode, string businessType, string bSEQty, string bRETQty, string sEQTY, string rETQty, string cANQty, string nOTQty, string sE_SA_CAN_QTY, string sE_SA_NOT_QTY, string oNLY_SE_QTY, string oNLY_SA_QTY, string iNVQty) + { + LU = lU; + PartCode = partCode; + BusinessType = businessType; + BSEQty = bSEQty; + BRETQty = bRETQty; + SEQTY = sEQTY; + RETQty = rETQty; + CANQty = cANQty; + NOTQty = nOTQty; + SE_SA_CAN_QTY = sE_SA_CAN_QTY; + SE_SA_NOT_QTY = sE_SA_NOT_QTY; + ONLY_SE_QTY = oNLY_SE_QTY; + ONLY_SA_QTY = oNLY_SA_QTY; + INVQty = iNVQty; + } + } +}