|
|
@ -1,6 +1,7 @@ |
|
|
|
using CodeArts.Db; |
|
|
|
using DocumentFormat.OpenXml.Bibliography; |
|
|
|
using DocumentFormat.OpenXml.Drawing.Diagrams; |
|
|
|
using DocumentFormat.OpenXml.Office.Drawing; |
|
|
|
using DocumentFormat.OpenXml.Spreadsheet; |
|
|
|
using DocumentFormat.OpenXml.Wordprocessing; |
|
|
|
using EFCore.BulkExtensions; |
|
|
@ -13,6 +14,7 @@ using Microsoft.AspNetCore.Mvc; |
|
|
|
using NPOI.HPSF; |
|
|
|
using SettleAccount.Domain.BQ; |
|
|
|
using Shouldly; |
|
|
|
using SqlSugar; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.ComponentModel.DataAnnotations; |
|
|
@ -161,6 +163,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
var invs = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount); |
|
|
|
var m = await _mRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount); |
|
|
|
var mdtos = ObjectMapper.Map<List<INVOICE_MAP_GROUP>, List<INVOICE_MAP_GROUP_DTO>>(m); |
|
|
|
var first = invs.FirstOrDefault(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (invs.FirstOrDefault().BusinessType == EnumBusinessType.JisBBAC) |
|
|
|
{ |
|
|
|
var A = await _wRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount); |
|
|
@ -249,17 +255,13 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
BeginDate = itm.BeginDate, |
|
|
|
EndDate = itm.EndDate, |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
entity.INVOICE_WAIT_DETAIL= wquery.OrderBy(p=>p.LU).ToList(); |
|
|
|
entity.INVOICE_WAIT_DETAIL = wquery.OrderBy(p => p.LU).ToList(); |
|
|
|
} |
|
|
|
|
|
|
|
var s = await _sRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount); |
|
|
|
var sdtos = ObjectMapper.Map<List<INVOICE_NOT_SETTLE>, List<INVOICE_NOT_SETTLE_DTO>>(s); |
|
|
|
var adjs =await _adjRepository.GetListByFilterAsync(input.Filters); |
|
|
|
var adjdtos = ObjectMapper.Map<List<PUB_ADJ_DETAIL>, List<PUB_ADJ_DETAIL_DTO>>(adjs); |
|
|
|
var sdtos = ObjectMapper.Map<List<INVOICE_NOT_SETTLE>, List<INVOICE_NOT_SETTLE_DTO>>(s);//不可结
|
|
|
|
var adjs = await _adjRepository.GetListByFilterAsync(input.Filters);//调整数据
|
|
|
|
var adjdtos = ObjectMapper.Map<List<PUB_ADJ_DETAIL>, List<PUB_ADJ_DETAIL_DTO>>(adjs);//调整数据DTO
|
|
|
|
|
|
|
|
var notquery = from itm in sdtos |
|
|
|
join itm1 in invs on itm.InvBillNum equals itm1.InvbillNum |
|
|
|
select |
|
|
@ -274,8 +276,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
Qty = itm.Qty, |
|
|
|
Extend1 = itm.Extend1, |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var mquery = from itm in mdtos |
|
|
|
join itm1 in invs on itm.InvbillNum equals itm1.InvbillNum |
|
|
|
select |
|
|
@ -304,12 +304,32 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
Price = itm.Price |
|
|
|
}; |
|
|
|
|
|
|
|
entity.INVOICE_NOT_SETTLE = notquery.ToList(); |
|
|
|
entity.INVOICE_MAP_GROUP = mquery.ToList(); |
|
|
|
entity.ADJ_DETAIL = adjQuery.ToList(); |
|
|
|
return entity; |
|
|
|
entity.INVOICE_NOT_SETTLE = notquery.OrderBy(p=>p.SettleGroupNum).ThenBy(p=>p.LU).ToList(); |
|
|
|
|
|
|
|
var lscompare = entity.INVOICE_NOT_SETTLE.GroupBy(x => new { x.InvBillNum, x.SettleGroupNum }).Select(p => |
|
|
|
new INVOICE_MAP_GROUP_DTO() |
|
|
|
{ |
|
|
|
InvbillNum = p.FirstOrDefault().InvBillNum, |
|
|
|
InvGroupNum = p.FirstOrDefault().InvGroupNum, |
|
|
|
RealInvBillNum = p.FirstOrDefault().RealInvBillNum, |
|
|
|
InvDate = p.FirstOrDefault().InvDate, |
|
|
|
SettleGroupNum = p.FirstOrDefault().SettleGroupNum, |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
var all= entity.INVOICE_NOT_SETTLE.Select(p => p.SettleGroupNum).Distinct().ToList();//全部分组号
|
|
|
|
var part = mquery.ToList().Select(p => p.SettleGroupNum).Distinct().ToList();//发票对应分组号
|
|
|
|
var unsettled= all.Where(p => !part.Contains(p));//排除发票对应分组号,都为不可结
|
|
|
|
var unsettledList= entity.INVOICE_NOT_SETTLE.Where(p => unsettled.Contains(p.SettleGroupNum)) |
|
|
|
.GroupBy(p => new { p.LU, p.SettleGroupNum }) |
|
|
|
.Select(p => new UNSETTLED_DETAIL_DTO { LU = p.Key.LU, GroupNum = p.Key.SettleGroupNum, Qty = p.Sum(itm => itm.Qty.Value) }); |
|
|
|
|
|
|
|
|
|
|
|
entity.UNSETTLED_DETAIL = unsettledList.ToList().OrderBy(p=>p.GroupNum).ThenBy(p=>p.LU).ToList(); |
|
|
|
|
|
|
|
entity.INVOICE_MAP_GROUP = lscompare.ToList().OrderBy(p => p.SettleGroupNum).ToList();//包含不可结结算分组号
|
|
|
|
entity.ADJ_DETAIL = adjQuery.ToList().OrderBy(p=>p.GroupNum).ThenBy(p=>p.LU).ToList(); |
|
|
|
return entity; |
|
|
|
} |
|
|
|
[HttpPost] |
|
|
|
public virtual async Task<string> ExportAsync(INVOICE_GRP_REQ_DTO input) |
|
|
@ -350,9 +370,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
return _fileName; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 导出发票组明细
|
|
|
|
/// </summary>
|
|
|
@ -363,26 +380,26 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
{ |
|
|
|
IExporter _csv = new CsvExporter(); |
|
|
|
ExcelExporter _excel = new ExcelExporter(); |
|
|
|
|
|
|
|
var materialList = await _baseservice.GetMaterialList(); |
|
|
|
|
|
|
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true); |
|
|
|
|
|
|
|
var first=entities.FirstOrDefault(); |
|
|
|
|
|
|
|
var dtoDetails = ObjectMapper.Map<List<INVOICE_GRP>, List<INVOICE_GRP_EXP_DTO>>(entities); |
|
|
|
var invdetail= await DetailQueryAsync(input); |
|
|
|
var m = invdetail.INVOICE_MAP_GROUP; |
|
|
|
var not=invdetail.INVOICE_NOT_SETTLE; |
|
|
|
var detail =invdetail.INVOICE_WAIT_DETAIL; |
|
|
|
var adj = invdetail.ADJ_DETAIL; |
|
|
|
var bbac = invdetail.INVOICE_WAIT_DETAIL_BBAC; |
|
|
|
var bj = invdetail.INVOICE_WAIT_DETAIL_BJ; |
|
|
|
var not=invdetail.INVOICE_NOT_SETTLE;//零件结算对应关系
|
|
|
|
var detail =invdetail.INVOICE_WAIT_DETAIL;//常规明细
|
|
|
|
var adj = invdetail.ADJ_DETAIL;//调整表
|
|
|
|
var bbac = invdetail.INVOICE_WAIT_DETAIL_BBAC;//BBACJIS明细
|
|
|
|
var bj = invdetail.INVOICE_WAIT_DETAIL_BJ;//备件明细
|
|
|
|
var unsettle = invdetail.UNSETTLED_DETAIL;//未结明细
|
|
|
|
|
|
|
|
|
|
|
|
var classDisplayName = typeof(INVOICE_GRP_DTO).GetCustomAttribute<DisplayAttribute>()?.Name ?? typeof(INVOICE_GRP_DTO).Name; |
|
|
|
string _fileName = $"{classDisplayName}_{Guid.NewGuid().ToString()}.xlsx"; |
|
|
|
|
|
|
|
//发票明细
|
|
|
|
if (entities.FirstOrDefault().BusinessType == EnumBusinessType.JisBBAC) |
|
|
|
{ |
|
|
|
|
|
|
|
_excel.Append(bbac, "发票明细"); |
|
|
|
} |
|
|
|
else if (entities.FirstOrDefault().BusinessType == EnumBusinessType.BeiJian) |
|
|
@ -393,6 +410,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
{ |
|
|
|
_excel.Append(detail, "发票明细"); |
|
|
|
} |
|
|
|
_excel.Append(m, "发票结算分组对应");//发票分组对应结算号
|
|
|
|
if (first.BusinessType == EnumBusinessType.ZhiGongJianBBAC || first.BusinessType == EnumBusinessType.ZhiGongJianHBPO) |
|
|
|
{ |
|
|
|
_excel.Append(unsettle, "未结零件分组汇总"); |
|
|
|
} |
|
|
|
foreach (var itm in entities) |
|
|
|
{ |
|
|
|
var mgroup =m.Where(p => p.InvbillNum == itm.InvbillNum).ToList(); |
|
|
@ -412,11 +434,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
RealInvBillNum =p.Key.RealInvBillNum, |
|
|
|
InvDate =p.Key.InvDate, |
|
|
|
InvBillNum =p.Key.InvBillNum, |
|
|
|
|
|
|
|
InvGroupNum =p.Key.InvGroupNum, |
|
|
|
Qty=p.Sum(itm=>itm.Qty) |
|
|
|
|
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
var lsN = nolist.Where(p => p.Extend1 == "不可结算").ToList() |
|
|
|
.GroupBy(p => new |
|
|
|
{ |
|
|
@ -435,8 +457,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
InvGroupNum = p.Key.InvGroupNum, |
|
|
|
Qty = p.Sum(itm => itm.Qty) |
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
|
|
|
|
var lineC = lsC.Count; |
|
|
|
var lineN = lsN.Count; |
|
|
|
List<INVOICE_NOT_SETTLE_EXT_DTO> ls = new List<INVOICE_NOT_SETTLE_EXT_DTO>(); |
|
|
@ -457,9 +477,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
} |
|
|
|
var entity= nolist.FirstOrDefault(); |
|
|
|
var disList = mgroup.Select(p => p.SettleGroupNum).Distinct().ToList(); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < lineC; i++) |
|
|
|
for (int i = 0; i < lineC; i++)//更新可结信息
|
|
|
|
{ |
|
|
|
ls[i].RealInvBillNum = entity.RealInvBillNum; |
|
|
|
ls[i].InvDate = entity.InvDate; |
|
|
@ -469,7 +487,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
ls[i].SettleLU = lsC[i].LU; |
|
|
|
ls[i].SettleQty = lsC[i].Qty == null ? string.Empty : lsC[i].Qty.ToString(); |
|
|
|
} |
|
|
|
for (int i = 0; i < lineN; i++) |
|
|
|
for (int i = 0; i < lineN; i++)//更新不可结信息
|
|
|
|
{ |
|
|
|
ls[i].RealInvBillNum = entity.RealInvBillNum; |
|
|
|
ls[i].InvDate = entity.InvDate; |
|
|
@ -479,98 +497,17 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
ls[i].NotSettleLU = lsN[i].LU; |
|
|
|
ls[i].Qty = lsN[i].Qty == null ? string.Empty : lsN[i].Qty.ToString(); |
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < disList.Count; i++) |
|
|
|
for (int i = 0; i < disList.Count; i++)//更新结算分组
|
|
|
|
{ |
|
|
|
ls[i].SettleGroupNum = disList[i]; |
|
|
|
} |
|
|
|
if (first.BusinessType == EnumBusinessType.JisBBAC || first.BusinessType == EnumBusinessType.JisHBPO) |
|
|
|
{ |
|
|
|
_excel.Append(ls, "结算分组零件" + itm.InvbillNum); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (lineC > lineN)//可结大于不可结行数时
|
|
|
|
//{
|
|
|
|
// for (int number = 0; number < lineC; number++)
|
|
|
|
// {
|
|
|
|
// if (number + 1 > lineN)
|
|
|
|
// {
|
|
|
|
// INVOICE_NOT_SETTLE_EXT_DTO entity = new INVOICE_NOT_SETTLE_EXT_DTO();
|
|
|
|
// entity.RealInvBillNum = lsC[number].RealInvBillNum;
|
|
|
|
// entity.InvDate = lsC[number].InvDate;
|
|
|
|
// entity.InvBillNum = lsC[number].InvBillNum;
|
|
|
|
// entity.InvGroupNum = lsC[number].InvGroupNum;
|
|
|
|
// entity.SettleGroupNum = lsC[number].SettleGroupNum;
|
|
|
|
// entity.SettleLU = lsC[number].LU;
|
|
|
|
// entity.SettleQty = lsC[number].Qty == null ? string.Empty : lsC[number].Qty.ToString();
|
|
|
|
// entity.NotSettleLU = string.Empty;
|
|
|
|
// entity.Qty = string.Empty;
|
|
|
|
// ls.Add(entity);
|
|
|
|
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// INVOICE_NOT_SETTLE_EXT_DTO entity = new INVOICE_NOT_SETTLE_EXT_DTO();
|
|
|
|
// entity.RealInvBillNum = lsC[number].RealInvBillNum;
|
|
|
|
// entity.InvDate = lsC[number].InvDate;
|
|
|
|
// entity.InvBillNum = lsC[number].InvBillNum;
|
|
|
|
// entity.InvGroupNum = lsC[number].InvGroupNum;
|
|
|
|
// entity.SettleGroupNum = lsC[number].SettleGroupNum;
|
|
|
|
// entity.SettleLU = lsC[number].LU;
|
|
|
|
// entity.SettleQty= lsC[number].Qty==null?string.Empty:lsC[number].Qty.ToString();
|
|
|
|
// entity.NotSettleLU = lsN[number].LU;
|
|
|
|
// entity.Qty = lsN[number].Qty == null ? string.Empty : lsC[number].Qty.ToString();
|
|
|
|
// ls.Add(entity);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
//{
|
|
|
|
// for (int number = 0; number < lineN; number++)
|
|
|
|
// {
|
|
|
|
// if (number + 1 > lineC)//不可结大于可结行数时
|
|
|
|
// {
|
|
|
|
// INVOICE_NOT_SETTLE_EXT_DTO entity = new INVOICE_NOT_SETTLE_EXT_DTO();
|
|
|
|
// entity.RealInvBillNum = lsN[number].RealInvBillNum;
|
|
|
|
// entity.InvDate = lsN[number].InvDate;
|
|
|
|
// entity.InvBillNum = lsN[number].InvBillNum;
|
|
|
|
// entity.InvGroupNum = lsN[number].InvGroupNum;
|
|
|
|
// entity.SettleGroupNum = lsN[number].SettleGroupNum;
|
|
|
|
// entity.SettleLU = string.Empty;
|
|
|
|
// entity.SettleQty = string.Empty;
|
|
|
|
// entity.NotSettleLU = lsN[number].LU;
|
|
|
|
// entity.Qty = lsN[number].Qty == null ? string.Empty : lsN[number].Qty.ToString();
|
|
|
|
// ls.Add(entity);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// INVOICE_NOT_SETTLE_EXT_DTO entity = new INVOICE_NOT_SETTLE_EXT_DTO();
|
|
|
|
// entity.RealInvBillNum = lsN[number].RealInvBillNum;
|
|
|
|
// entity.InvDate = lsN[number].InvDate;
|
|
|
|
// entity.InvBillNum = lsN[number].InvBillNum;
|
|
|
|
// entity.InvGroupNum = lsN[number].InvGroupNum;
|
|
|
|
// entity.SettleGroupNum = lsN[number].SettleGroupNum;
|
|
|
|
// entity.SettleLU = lsC[number].LU;
|
|
|
|
// entity.NotSettleLU = lsN[number].LU;
|
|
|
|
// entity.Qty = lsN[number].Qty == null ? string.Empty : lsN[number].Qty.ToString(); ;
|
|
|
|
// entity.SettleQty = lsC[number].Qty == null ? string.Empty : lsC[number].Qty.ToString(); ;
|
|
|
|
// ls.Add(entity);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
//var disList= ls.Select(p => p.SettleGroupNum).Distinct().ToList();
|
|
|
|
//foreach (var de in ls)
|
|
|
|
//{
|
|
|
|
// de.SettleGroupNum = string.Empty;
|
|
|
|
//}
|
|
|
|
//for (int i = 0; i < disList.Count; i++)
|
|
|
|
//{
|
|
|
|
// ls[i].SettleGroupNum = disList[i];
|
|
|
|
//}
|
|
|
|
_excel.Append(ls, "结算分组零件" + itm.InvbillNum); |
|
|
|
_excel.Append(mgroup, "发票结算分组对应" + itm.InvbillNum).SeparateBySheet(); |
|
|
|
_excel.Append(adjp, "发票调整数据" + itm.InvbillNum).SeparateBySheet(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var result = _excel.ExportAppendDataAsByteArray(); |
|
|
|