|
|
@ -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<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) |
|
|
|
{ |
|
|
|
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<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) |
|
|
|
{ |
|
|
@ -281,7 +291,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
Dictionary<string, List<TMEP_INV>> invoiceMap = new Dictionary<string, List<TMEP_INV>>();//发票和发票明细关系
|
|
|
|
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<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;
|
|
|
|
// 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<string>();
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
// {
|
|
|
|
// 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)
|
|
|
|
// {
|
|
|
|
// 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<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>(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -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<SA_CAN_BASE> parts = new List<SA_CAN_BASE>(); |
|
|
|
public IReadOnlyList<SA_CAN_BASE> 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<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() |
|
|
|
{ |
|
|
|
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<InvoiceExtend> invoices) |
|
|
|
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); |
|
|
|
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<InvoiceByDiff> 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; } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|