|
|
@ -26,6 +26,7 @@ using Volo.Abp.Uow; |
|
|
|
using Win.Abp.Snowflakes; |
|
|
|
using Win.Sfs.BaseData.ImportExcelCommon; |
|
|
|
using Win.Sfs.SettleAccount.Bases; |
|
|
|
using Win.Sfs.SettleAccount.Bases.DomainServices; |
|
|
|
using Win.Sfs.SettleAccount.CommonManagers; |
|
|
|
using Win.Sfs.SettleAccount.Constant; |
|
|
|
using Win.Sfs.SettleAccount.Entities.BQ.Dtos; |
|
|
@ -49,6 +50,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
private readonly BBAC_CAN_SA_MNG _bbacMng; |
|
|
|
private readonly HBPO_CAN_SA_MNG _hbpoMng; |
|
|
|
private readonly INV_MNG _invMng; |
|
|
|
private readonly BaseDomainService _baseservice; |
|
|
|
public INVOICE_SERVICE(IExcelImportAppService excelImportService, |
|
|
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
|
|
|
ICommonManager commonManager, |
|
|
@ -57,6 +59,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
INormalEfCoreRepository<INVOICE_NOT_SETTLE, Guid> sRepository, |
|
|
|
INormalEfCoreRepository<INVOICE_MAP_GROUP, Guid> mRepository, |
|
|
|
INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> adjRepository, |
|
|
|
BaseDomainService baseservice, |
|
|
|
PUB_CAN_SA_MNG pubMng, |
|
|
|
BBAC_CAN_SA_MNG bbacMng, |
|
|
|
HBPO_CAN_SA_MNG hbpoMng, |
|
|
@ -64,6 +67,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
|
|
|
|
) : base(excelImportService, snowflakeIdGenerator, commonManager) |
|
|
|
{ |
|
|
|
_baseservice = baseservice; |
|
|
|
_repository = repository; |
|
|
|
_wRepository = wRepository; |
|
|
|
_mRepository = mRepository; |
|
|
@ -146,20 +150,24 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
public virtual async Task<INVOICE_GRP_DETAIL_DTO> DetailQueryAsync(INVOICE_GRP_REQ_DTO input) |
|
|
|
{ |
|
|
|
INVOICE_GRP_DETAIL_DTO entity = new INVOICE_GRP_DETAIL_DTO(); |
|
|
|
|
|
|
|
var materialList = await _baseservice.GetMaterialList(); |
|
|
|
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); |
|
|
|
|
|
|
|
if (invs.FirstOrDefault().BusinessType == EnumBusinessType.JisBBAC) |
|
|
|
{ |
|
|
|
var A = await _wRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount); |
|
|
|
var AMap = ObjectMapper.Map<List<INVOICE_WAIT_DETAIL>, List<INVOICE_WAIT_DETAIL_BBAC_DTO>>(A); |
|
|
|
var wquery = from itm in AMap |
|
|
|
join itm1 in invs on itm.InvbillNum equals itm1.InvbillNum |
|
|
|
join itm2 in materialList on itm.LU equals itm2.SettleMaterialCode into temp |
|
|
|
|
|
|
|
|
|
|
|
select from tm in temp.DefaultIfEmpty() |
|
|
|
select |
|
|
|
new INVOICE_WAIT_DETAIL_BBAC_DTO() |
|
|
|
{ |
|
|
|
PartDesc = tm == null ? string.Empty : itm.PartDesc, |
|
|
|
InvDate = itm1.CreationTime, |
|
|
|
RealInvbillNum = string.IsNullOrEmpty(itm1.RealnvBillNum) ? string.Empty : itm1.RealnvBillNum, |
|
|
|
Version = itm.Version, |
|
|
@ -184,9 +192,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
|
|
|
|
var wquery = from itm in BMap |
|
|
|
join itm1 in invs on itm.InvbillNum equals itm1.InvbillNum |
|
|
|
join itm2 in materialList on itm.LU equals itm2.SettleMaterialCode into temp |
|
|
|
select from tm in temp.DefaultIfEmpty() |
|
|
|
select |
|
|
|
new INVOICE_WAIT_DETAIL_BJ_DTO() |
|
|
|
{ |
|
|
|
PartDesc = tm == null ? string.Empty : itm.PartDesc, |
|
|
|
InvDate = itm1.CreationTime, |
|
|
|
RealInvbillNum = string.IsNullOrEmpty(itm1.RealnvBillNum) ? string.Empty : itm1.RealnvBillNum, |
|
|
|
Version = itm.Version, |
|
|
@ -211,9 +222,13 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
var wdtos = ObjectMapper.Map<List<INVOICE_WAIT_DETAIL>, List<INVOICE_WAIT_DETAIL_DTO>>(w); |
|
|
|
var wquery = from itm in wdtos |
|
|
|
join itm1 in invs on itm.InvbillNum equals itm1.InvbillNum |
|
|
|
join itm2 in materialList on itm.LU equals itm2.SettleMaterialCode into temp |
|
|
|
select from tm in temp.DefaultIfEmpty() |
|
|
|
select |
|
|
|
new INVOICE_WAIT_DETAIL_DTO() |
|
|
|
{ |
|
|
|
|
|
|
|
PartDesc = tm == null ? string.Empty : itm.PartDesc, |
|
|
|
InvDate = itm1.CreationTime, |
|
|
|
RealInvbillNum = string.IsNullOrEmpty(itm1.RealnvBillNum) ? string.Empty : itm1.RealnvBillNum, |
|
|
|
Version = itm.Version, |
|
|
@ -334,7 +349,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
IExporter _csv = new CsvExporter(); |
|
|
|
ExcelExporter _excel = new ExcelExporter(); |
|
|
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true); |
|
|
|
|
|
|
|
var dtoDetails = ObjectMapper.Map<List<INVOICE_GRP>, List<INVOICE_GRP_EXP_DTO>>(entities); |
|
|
|
var invdetail= await DetailQueryAsync(input); |
|
|
|
var m = invdetail.INVOICE_MAP_GROUP; |
|
|
@ -343,40 +357,165 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
var adj = invdetail.ADJ_DETAIL; |
|
|
|
var bbac = invdetail.INVOICE_WAIT_DETAIL_BBAC; |
|
|
|
var bj = invdetail.INVOICE_WAIT_DETAIL_BJ; |
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
{ |
|
|
|
_excel.Append(bj, "发票明细"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_excel.Append(detail, "发票明细"); |
|
|
|
} |
|
|
|
foreach (var itm in entities) |
|
|
|
{ |
|
|
|
|
|
|
|
var mgroup =m.Where(p => p.InvbillNum == itm.InvbillNum).ToList(); |
|
|
|
var adjp = adj.Where(p => p.InvBillNum == itm.InvbillNum).ToList(); |
|
|
|
var nolist = not.Where(p => p.InvBillNum == itm.InvbillNum).ToList(); |
|
|
|
var lsC =nolist.Where(p => p.Extend1 == "可结算").ToList(); |
|
|
|
var lsN = nolist.Where(p => p.Extend1 == "不可结算").ToList(); |
|
|
|
// var r = (from t1 in lsC
|
|
|
|
// join t2 in lsN on new { t1.LU, t1.SettleGroupNum }
|
|
|
|
// equals new { t2.LU, t2.SettleGroupNum }
|
|
|
|
|
|
|
|
// into temp
|
|
|
|
// from tm in temp.DefaultIfEmpty()
|
|
|
|
// select new INVOICE_NOT_SETTLE_EXT_DTO
|
|
|
|
// {
|
|
|
|
// RealInvBillNum = t1.RealInvBillNum,
|
|
|
|
// InvDate = t1.InvDate,
|
|
|
|
// InvBillNum = t1.InvBillNum,
|
|
|
|
// InvGroupNum = t1.InvGroupNum,
|
|
|
|
// SettleGroupNum = t1.SettleGroupNum,
|
|
|
|
// SettleLU = t1.LU,
|
|
|
|
// NotSettleLU = tm == null ? string.Empty : tm.LU,
|
|
|
|
// Qty = tm == null ? string.Empty : tm.Qty
|
|
|
|
|
|
|
|
// }
|
|
|
|
// )
|
|
|
|
//.Union
|
|
|
|
//(from t2 in lsN
|
|
|
|
// join t1 in lsC
|
|
|
|
// on new { t2.LU, t2.SettleGroupNum }
|
|
|
|
// equals new { t1.LU, t1.SettleGroupNum }
|
|
|
|
// into temp
|
|
|
|
// from tm in temp.DefaultIfEmpty()
|
|
|
|
// where tm == null
|
|
|
|
// select new INVOICE_NOT_SETTLE_EXT_DTO
|
|
|
|
// {
|
|
|
|
// RealInvBillNum = t2.RealInvBillNum,
|
|
|
|
// InvDate = t2.InvDate,
|
|
|
|
// InvBillNum = t2.InvBillNum,
|
|
|
|
// InvGroupNum = t2.InvGroupNum,
|
|
|
|
// SettleGroupNum = t2.SettleGroupNum,
|
|
|
|
// SettleLU = string.Empty,
|
|
|
|
// NotSettleLU = t2.LU,
|
|
|
|
// Qty = t2.Qty
|
|
|
|
|
|
|
|
// }
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (entities.FirstOrDefault().BusinessType == EnumBusinessType.JisBBAC) |
|
|
|
//_excel.Append(r.OrderBy(p=>p.SettleGroupNum).ToList(), "结算分组零件" + itm.InvbillNum);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var lineC = lsC.Count; |
|
|
|
var lineN = lsN.Count; |
|
|
|
List<INVOICE_NOT_SETTLE_EXT_DTO> ls = new List<INVOICE_NOT_SETTLE_EXT_DTO>(); |
|
|
|
if (lineC > lineN)//可结大于不可结行数时
|
|
|
|
{ |
|
|
|
var bbaclist = bbac.Where(p => p.InvbillNum == itm.InvbillNum).ToList(); |
|
|
|
_excel.Append(bbaclist, "发票号" + itm.InvbillNum).SeparateBySheet(); |
|
|
|
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; |
|
|
|
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; |
|
|
|
entity.NotSettleLU = lsN[number].LU; |
|
|
|
entity.Qty = lsN[number].Qty; |
|
|
|
ls.Add(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (entities.FirstOrDefault().BusinessType == EnumBusinessType.BeiJian) |
|
|
|
else |
|
|
|
{ |
|
|
|
var bjlist = bj.Where(p => p.InvbillNum == itm.InvbillNum).ToList(); |
|
|
|
_excel.Append(bjlist, "发票号" + itm.InvbillNum).SeparateBySheet(); |
|
|
|
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; |
|
|
|
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; |
|
|
|
entity.SettleQty = lsC[number].Qty; |
|
|
|
ls.Add(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var disList= ls.Select(p => p.SettleGroupNum).Distinct().ToList(); |
|
|
|
foreach (var de in ls) |
|
|
|
{ |
|
|
|
de.SettleGroupNum = string.Empty; |
|
|
|
} |
|
|
|
else |
|
|
|
for (int i = 0; i < disList.Count; i++) |
|
|
|
{ |
|
|
|
var invlist = detail.Where(p => p.InvbillNum == itm.InvbillNum).ToList(); |
|
|
|
_excel.Append(invlist, "发票号" + itm.InvbillNum).SeparateBySheet(); |
|
|
|
ls[i].SettleGroupNum = disList[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
_excel.Append(ls, "结算分组零件" + itm.InvbillNum); |
|
|
|
_excel.Append(mgroup, "发票结算分组对应" + itm.InvbillNum).SeparateBySheet(); |
|
|
|
_excel.Append(adjp, "发票调整数据" + itm.InvbillNum).SeparateBySheet(); |
|
|
|
_excel.Append(nolist, "结算分组零件" + itm.InvbillNum); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = _excel.ExportAppendDataAsByteArray(); |
|
|
|
result.ShouldNotBeNull(); |
|
|
|
//保存导出文件到服务器存成二进制
|
|
|
|