|
|
@ -63,7 +63,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
|
|
|
|
var groupNumList= entitys.Select(p=>p.GroupNum).Distinct().ToList(); |
|
|
|
|
|
|
|
var notList =_notRepository.Where(p => groupNumList.Contains(p.InvGroupNum)).ToList();//不能结算
|
|
|
|
//var groupNumList = entitys.Select(p => new { p.GroupNum).Distinct().ToList();
|
|
|
|
|
|
|
|
var notList =_notRepository.Where(p => groupNumList.Contains(p.GroupNum)).ToList();//不能结算
|
|
|
|
|
|
|
|
var dtos = ObjectMapper.Map<List<BBAC_CAN_SA_DETAIL>, List<BBAC_CAN_SA_DETAIL_DTO>>(entitys); |
|
|
|
|
|
|
@ -72,6 +74,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
dto.Amt = Math.Round(dto.Price * dto.Qty, 2); |
|
|
|
}); |
|
|
|
|
|
|
|
dtos = dtos.OrderBy(p => p.SettleDate).ToList(); |
|
|
|
|
|
|
|
|
|
|
|
var _query= dtos.GroupBy(p => new { p.GroupNum }).Select(p =>new {GroupNum=p.Key.GroupNum, Amt=p.Sum(itm=>itm.Amt)}); |
|
|
|
|
|
|
|
Dictionary<string, decimal> dic = new Dictionary<string, decimal>();//原本
|
|
|
@ -90,8 +95,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
List<string> invoiceGroupNumList = new List<string>();//每个发票对应的结算分组号
|
|
|
|
List<string> List = new List<string>(); |
|
|
|
decimal sum = itm.Value;//初始分组合计金额
|
|
|
|
List<string> luList= dtos.Where(p => p.GroupNum == itm.Key).Select(p => p.LU).Distinct().ToList(); //初始LU种类
|
|
|
|
|
|
|
|
List<string> luList= dtos.Where(p => p.GroupNum == itm.Key).Select(p => p.LU+p.ContractDocID ).Distinct().ToList(); //初始LU种类
|
|
|
|
if (copyDic.ContainsKey(itm.Key)==true)//是否存在分组
|
|
|
|
{ |
|
|
|
foreach (var _itm1 in copyDic) |
|
|
@ -101,7 +105,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
invoiceGroupNumList.Add(itm.Key); |
|
|
|
continue; |
|
|
|
} |
|
|
|
var grouplist = dtos.Where(p => p.GroupNum == _itm1.Key).Select(p => p.LU).Distinct().ToList();//每项LU种类
|
|
|
|
var grouplist = dtos.Where(p => p.GroupNum == _itm1.Key).Select(p => p.LU + p.ContractDocID).Distinct().ToList();//每项LU种类
|
|
|
|
luList.AddRange(grouplist); |
|
|
|
luList = luList.Distinct().ToList(); |
|
|
|
if (luList.Count > 20)//累加零件不超过20种
|
|
|
@ -125,99 +129,115 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
} |
|
|
|
if(invoiceMap.Keys.Count > 0) { |
|
|
|
|
|
|
|
var inv=new INVOICE_GRP(); |
|
|
|
var groupList = new List<INVOICE_MAP_GROUP>(); |
|
|
|
var notDetialList=new List<INVOICE_NOT_SETTLE>(); |
|
|
|
var detailList= new List<INVOICE_WAIT_DETAIL>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var itm in invoiceMap) |
|
|
|
var notDetialList = new List<INVOICE_NOT_SETTLE>(); |
|
|
|
var detailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
|
var invlist = new List<INVOICE_GRP>(); |
|
|
|
foreach (var itm in invoiceMap)//分组影响和
|
|
|
|
{ |
|
|
|
var key = itm.Key;//发票票号
|
|
|
|
var ls = itm.Value;//结算分组号列表
|
|
|
|
var detailDtos= dtos.Where(p => ls.Contains(p.GroupNum)).GroupBy(p=>new {p.InvGroupNum, p.LU,p.Price }) |
|
|
|
.Select(itm=>new { InvGroupNum=itm.Key.InvGroupNum, |
|
|
|
var detailDtos= dtos.Where(p => ls.Contains(p.GroupNum)).GroupBy(p=>new {p.InvGroupNum, p.LU,p.Price,p.ContractDocID }) |
|
|
|
.Select(itm=>new { |
|
|
|
InvGroupNum=itm.Key.InvGroupNum, |
|
|
|
LU=itm.Key.LU, |
|
|
|
Price=itm.Key.Price,Amt=Math.Round(itm.Sum(k=>k.Qty)*itm.Key.Price,2) , |
|
|
|
Qty= itm.Sum(k => k.Qty) }) |
|
|
|
ContactDocID=itm.Key.ContractDocID, |
|
|
|
Price=itm.Key.Price, |
|
|
|
Amt=Math.Round(itm.Sum(k=>k.Qty)*itm.Key.Price,2) , |
|
|
|
Qty= itm.Sum(k => k.Qty) |
|
|
|
}) |
|
|
|
.ToList(); |
|
|
|
var invbill=new INVOICE_GRP(); |
|
|
|
|
|
|
|
decimal amt=detailDtos.Sum(k=>k.Amt); |
|
|
|
decimal txtAmt=Math.Round(detailDtos.Sum(k => k.Amt),2); |
|
|
|
|
|
|
|
foreach (var obj in detailDtos) |
|
|
|
var mapList= new List<INVOICE_MAP_GROUP>(); |
|
|
|
|
|
|
|
foreach (var groupnum in ls) |
|
|
|
{ |
|
|
|
new INVOICE_WAIT_DETAIL( |
|
|
|
amt=dtos.Where(p => p.GroupNum == groupnum).Sum(p => p.Amt); |
|
|
|
mapList.Add(new INVOICE_MAP_GROUP( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
version:main.Version, |
|
|
|
version: main.Version, |
|
|
|
invbillNum: key, |
|
|
|
invGroupNum: obj.InvGroupNum, |
|
|
|
lU: obj.LU, |
|
|
|
qty: obj.Qty, |
|
|
|
bussiessType: EnumBusinessType.BBAC, |
|
|
|
amt: obj.Amt, |
|
|
|
pRICE:obj.Price, |
|
|
|
extend1: string.Empty, extend2: string.Empty, extend3: string.Empty, extend4: string.Empty |
|
|
|
invGroupNum: main.InvGroupNum, |
|
|
|
settleGroupNum:groupnum, |
|
|
|
amt:amt, |
|
|
|
extend1:string.Empty, |
|
|
|
extend2:string.Empty |
|
|
|
) |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach (var groupnum in ls) |
|
|
|
if(mapList.Count > 0) |
|
|
|
{ |
|
|
|
groupList.AddRange(mapList); |
|
|
|
|
|
|
|
} |
|
|
|
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:main.Version, |
|
|
|
invbillNum: key, |
|
|
|
invGroupNum: main.InvGroupNum, |
|
|
|
lU: detail.LU, |
|
|
|
qty: detail.Qty, |
|
|
|
bussiessType: EnumBusinessType.BBAC, |
|
|
|
amt: detail.Amt, |
|
|
|
pRICE:detail.Price, |
|
|
|
extend1: detail.ContactDocID, |
|
|
|
extend2: string.Empty, |
|
|
|
extend3: string.Empty, |
|
|
|
extend4: string.Empty |
|
|
|
)); |
|
|
|
} |
|
|
|
|
|
|
|
if (_entityDetailList.Count > 0) |
|
|
|
{ |
|
|
|
detailList.AddRange(_entityDetailList); |
|
|
|
} |
|
|
|
|
|
|
|
var notls= notList.GroupBy(p => new { p.GroupNum, p.LU }).Select(p=>new {GroupNum= p.Key.GroupNum,LU=p.Key.LU,Qty= p.Sum(itm=>itm.Qty) }); |
|
|
|
|
|
|
|
var innotls= new List<INVOICE_NOT_SETTLE>(); |
|
|
|
foreach (var nitm in notls) |
|
|
|
{ |
|
|
|
innotls.Add(new INVOICE_NOT_SETTLE( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
version: main.Version, |
|
|
|
invGroupNum: main.InvGroupNum, |
|
|
|
settleGroupNum: nitm.GroupNum, |
|
|
|
lU: string.Empty, |
|
|
|
lU1: nitm.LU, |
|
|
|
extend1: string.Empty, |
|
|
|
extend2: string.Empty, |
|
|
|
qty: nitm.Qty |
|
|
|
)); |
|
|
|
} |
|
|
|
if (innotls.Count > 0) |
|
|
|
{ |
|
|
|
notDetialList.AddRange(innotls); |
|
|
|
} |
|
|
|
var invbill = new INVOICE_GRP |
|
|
|
(guid: GuidGenerator.Create(), |
|
|
|
realnvBillNum: string.Empty, |
|
|
|
invbillNum: key, |
|
|
|
amt:amt, |
|
|
|
taxAmt:txtAmt, |
|
|
|
fileName: string.Empty, |
|
|
|
businessType: EnumBusinessType.BBAC, |
|
|
|
invGroupNum: main.InvGroupNum, |
|
|
|
state: SettleBillState.已开票, |
|
|
|
invoiceBillState: InvoiceBillState.正常 |
|
|
|
|
|
|
|
); |
|
|
|
invlist.Add( invbill ); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return ApplicationConsts.SuccessStr; |
|
|
|
} |
|
|
|
//private Dictionary<string, decimal> GenerateInvoice(Dictionary<string, decimal> p_dic)
|
|
|
|
//{
|
|
|
|
|
|
|
|
// string invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("INV");
|
|
|
|
// List<string> invoiceGroupNumList = new List<string>();//每个发票对应的结算分组号
|
|
|
|
|
|
|
|
// List<string> List = new List<string>();
|
|
|
|
// decimal sum = p_dic.Value;//初始分组合计金额
|
|
|
|
// List<string> luList = dtos.Where(p => p.GroupNum == itm.Key).Select(p => p.LU).Distinct().ToList(); //初始LU种类
|
|
|
|
|
|
|
|
|
|
|
|
// foreach (var _itm1 in copyDic)
|
|
|
|
// {
|
|
|
|
// if (itm.Key == _itm1.Key)//相同结算分组项不计算
|
|
|
|
// {
|
|
|
|
// invoiceGroupNumList.Add(itm.Key);
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// var grouplist = dtos.Where(p => p.GroupNum == _itm1.Key).Select(p => p.LU).Distinct().ToList();//每项LU种类
|
|
|
|
// luList.AddRange(grouplist);
|
|
|
|
// luList = luList.Distinct().ToList();
|
|
|
|
// if (luList.Count > 20)//累加零件不超过20种
|
|
|
|
// {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (sum > 10000000)
|
|
|
|
// {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// sum += _itm1.Value;
|
|
|
|
// invoiceGroupNumList.Add(_itm1.Key);//所有条件都满足添加发票和结算分组对应关系
|
|
|
|
// }
|
|
|
|
// foreach (var rem in invoiceGroupNumList)//移除
|
|
|
|
// {
|
|
|
|
// copyDic.Remove(rem);
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|