Browse Source

更新版本

master
zhaoxinyu 5 months ago
parent
commit
dc89eeeaa4
  1. 309
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs
  2. 21
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs
  3. 60
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/SHIP_REC_SUM.cs

309
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 where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime && p.IsCancel == false && p.ClientCode == main.Site
select new TEMP_CAN_SA_DETAIL select new TEMP_CAN_SA_DETAIL
{ {
Id = d.Id,
SettleBillNum = d.SettleBillNum, SettleBillNum = d.SettleBillNum,
Site = d.Site, Site = d.Site,
Version = d.Version, Version = d.Version,
@ -149,8 +150,17 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs
PartCode = p.PartCode PartCode = p.PartCode
}).ToList();//不能结算 }).ToList();//不能结算
var invs = FirstInvoiceExtend(entitys, new List<PUB_ADJ_DETAIL>(), dtos, notlist, main.Version, main.InvGroupNum, string.Empty, main.BusinessType);
//var invs = SecInvoice(entitys, new List<PUB_ADJ_DETAIL>(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType, query.ToList()); entitys = entitys.OrderBy(p => p.LU).ToList();
var invs = FirstInvoiceExtend1(entitys, new List<PUB_ADJ_DETAIL>(), dtos, notlist, main.Version, main.InvGroupNum, string.Empty, main.BusinessType);
// var invs = SecInvoice(entitys, new List<PUB_ADJ_DETAIL>(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType, query.ToList());
if (invs.Count > 0) if (invs.Count > 0)
{ {
main.State = SettleBillState.; main.State = SettleBillState.;
@ -239,7 +249,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs
Qty = g.Sum(p => p.Qty), Qty = g.Sum(p => p.Qty),
}; };
//var invs = FirstInvoiceExtend1(entitys, new List<PUB_ADJ_DETAIL>(), dtos, notlist, main.Version, main.InvGroupNum, string.Empty, main.BusinessType);
var invs = SecInvoice(entitys, new List<PUB_ADJ_DETAIL>(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType, query.ToList()); var invs = SecInvoice(entitys, new List<PUB_ADJ_DETAIL>(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType, query.ToList());
if (invs.Count > 0) if (invs.Count > 0)
{ {
@ -281,7 +291,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs
Dictionary<string, List<TMEP_INV>> invoiceMap = new Dictionary<string, List<TMEP_INV>>();//发票和发票明细关系 Dictionary<string, List<TMEP_INV>> invoiceMap = new Dictionary<string, List<TMEP_INV>>();//发票和发票明细关系
foreach (var group in groups) 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.PartCode == group.PartCode
&& p.BeginDate == group.BeginDate && p.BeginDate == group.BeginDate
&& p.EndDate == group.EndDate && p.EndDate == group.EndDate
@ -1193,25 +1205,196 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs
} }
return _invls; return _invls;
} }
// public List<string> FirstInvoiceExtend1<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_adjlist, List<TEMP_CAN_SA_DETAIL> dtos, List<TEMP_NOT_SA_DETAIL> 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;
public List<string> FirstInvoiceExtend1<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_adjlist, List<TEMP_CAN_SA_DETAIL> dtos, List<TEMP_NOT_SA_DETAIL> 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<GroupPartCode> biglist = new List<GroupPartCode>();
List<GroupPartCode> smalllist = new List<GroupPartCode>();
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) // if (invList.Count > 0)
// { // {
// var groupList = new List<INVOICE_MAP_GROUP>();
// var notDetialList = new List<INVOICE_NOT_SETTLE>();
// var detailList = new List<INVOICE_WAIT_DETAIL>();
// var invlist = new List<INVOICE_GRP>();
// var salist = new List<TDetail>();
// var adjlist = new List<PUB_ADJ_DETAIL>();
// foreach (var inv in invList) // foreach (var inv in invList)
// { // {
// var partlist = inv.Parts; // var partlist = inv.Parts;
// if (partlist.Count > 0) // if (partlist.Count > 0)
// { // {
// partlist.GroupBy(p => new { p.InvGroupNum, p.PartCode, p.Price, p.BeginDate, p.EndDate, p.ContractDocID, p.LU }) // 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<INVOICE_WAIT_DETAIL> _entityDetailList = new List<INVOICE_WAIT_DETAIL>();
// 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<string>();
// } // }
return new List<string>();
}
@ -1219,61 +1402,135 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs
} }
public class InvoiceExtend public class InvoiceBySame
{ {
public string InvBillNum { set; get; } public string InvBillNum { set; get; }
public InvoiceExtend() { } public InvoiceBySame() { }
private List<SA_CAN_BASE> parts = new List<SA_CAN_BASE>(); private List<SA_CAN_BASE> parts = new List<SA_CAN_BASE>();
public IReadOnlyList<SA_CAN_BASE> Parts => parts.AsReadOnly(); public IReadOnlyList<SA_CAN_BASE> Parts => parts.AsReadOnly();
public decimal TotalAmount => parts.Sum(p => p.Price); 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) 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) public void AddPart(SA_CAN_BASE part)
{ {
if (!CanAddPart(part)) if (CanAddPart(part))
{ {
//throw new InvalidOperationException("Cannot add part to invoice. Check constraints.");
}
part.InvbillNum = InvBillNum; part.InvbillNum = InvBillNum;
parts.Add(part); parts.Add(part);
//throw new InvalidOperationException("Cannot add part to invoice. Check constraints.");
}
} }
} }
public class InvoiceGenerator public class InvoiceGeneratorSame
{ {
private List<InvoiceExtend> invoices = new List<InvoiceExtend>(); private List<InvoiceBySame> invoices = new List<InvoiceBySame>();
public IReadOnlyList<InvoiceExtend> Invoices => invoices.AsReadOnly(); public IReadOnlyList<InvoiceBySame> Invoices => invoices.AsReadOnly();
public void GenerateInvoices<TDetail>(List<TDetail> parts) where TDetail : SA_CAN_BASE, new() public void GenerateInvoices<TDetail>(List<TDetail> 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 InvoiceBySame();
currentInvoice.InvBillNum = OrderNumberGenerator.GenerateOrderNumber("INV");
invoices.Add(currentInvoice);
}
currentInvoice.AddPart(part);
}
}
public InvoiceGeneratorSame()
{
}
public InvoiceGeneratorSame(List<InvoiceBySame> invoices)
{
this.invoices = invoices;
}
}
public class InvoiceByDiff
{
public string InvBillNum { set; get; }
public InvoiceByDiff() { }
private List<GroupPartCode> parts = new List<GroupPartCode>();
public IReadOnlyList<GroupPartCode> 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<InvoiceByDiff> invoices = new List<InvoiceByDiff>();
public IReadOnlyList<InvoiceByDiff> Invoices => invoices.AsReadOnly();
public void GenerateInvoices(List<GroupPartCode> parts)
{
InvoiceByDiff currentInvoice = new InvoiceByDiff();
invoices.Add(currentInvoice); invoices.Add(currentInvoice);
currentInvoice.InvBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); currentInvoice.InvBillNum = OrderNumberGenerator.GenerateOrderNumber("INV");
foreach (var part in parts) foreach (var part in parts)
{ {
if (!currentInvoice.CanAddPart(part)) if (!currentInvoice.CanAddPart(part))
{ {
currentInvoice = new InvoiceExtend(); currentInvoice = new InvoiceByDiff();
currentInvoice.InvBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); currentInvoice.InvBillNum = OrderNumberGenerator.GenerateOrderNumber("INV");
invoices.Add(currentInvoice); invoices.Add(currentInvoice);
} }
currentInvoice.AddPart(part); currentInvoice.AddPart(part);
} }
} }
public InvoiceGenerator() public InvoiceGeneratorDiff()
{ {
} }
public InvoiceGenerator(List<InvoiceExtend> invoices) public InvoiceGeneratorDiff(List<InvoiceByDiff> invoices)
{ {
this.invoices = 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; }
}

21
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" + "ElSE 0 END ONLY_SA_QTY \n" +
"from (\n" + "from (\n" +
"SELECT LU,PN,BusinessType,Qty,10 Type \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)) if (!string.IsNullOrEmpty(sebegin))
{ {
@ -1589,7 +1589,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
sql += sql +=
"UNION ALL\n" + "UNION ALL\n" +
"SELECT LU,PN,BusinessType,Qty,20 Type\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)) if (!string.IsNullOrEmpty(sebegin))
{ {
@ -1602,7 +1602,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
sql += sql +=
"UNION ALL\n" + "UNION ALL\n" +
"SELECT LU,PN,BusinessType,Qty,100 Type\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)) if (!string.IsNullOrEmpty(sebegin))
{ {
@ -1614,7 +1614,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
} }
sql += "UNION ALL\n" + sql += "UNION ALL\n" +
"SELECT LU,PN,BusinessType,Qty,150 Type\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)) if (!string.IsNullOrEmpty(sebegin))
{ {
@ -1641,6 +1641,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
} }
sql += "UNION ALL\n" + sql += "UNION ALL\n" +
"SELECT LU,PN,BusinessType,Qty,800 Type\n" + "SELECT LU,PN,BusinessType,Qty,800 Type\n" +
$"from {sanottablename} A WITH(NOLOCK) WHERE BusinessType={(int)p_businessType} \n"; $"from {sanottablename} A WITH(NOLOCK) WHERE BusinessType={(int)p_businessType} \n";
@ -1696,8 +1697,18 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
connection.Close(); connection.Close();
return ls; return ls;
} }
/// <summary>
/// jisbbac收发汇总
/// </summary>
/// <param name="sebegin">发运开始时间</param>
/// <param name="seend">结算时间</param>
/// <param name="sabegin">结算开始时间</param>
/// <param name="saend">结算结算时间</param>
/// <param name="partcode"></param>
/// <returns></returns>
[HttpPost] [HttpPost]
public async Task<string> GetReceiveShipSum(string sebegin, string seend, string sabegin, string saend)
public async Task<string> GetReceiveShipSum(string sebegin, string seend, string sabegin, string saend,string partcode)
{ {
ConcurrentBag<ShipReceiveSum> bagList = new ConcurrentBag<ShipReceiveSum>(); ConcurrentBag<ShipReceiveSum> bagList = new ConcurrentBag<ShipReceiveSum>();

60
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<Guid>
{
[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;
}
}
}
Loading…
Cancel
Save