|
@ -50,6 +50,164 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
_relationRepository = relationRepository; |
|
|
_relationRepository = relationRepository; |
|
|
_pdRepository = pdRepository; |
|
|
_pdRepository = pdRepository; |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 提交发票
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="p_list"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <exception cref="UserFriendlyException"></exception>
|
|
|
|
|
|
/// <exception cref="BusinessException"></exception>
|
|
|
|
|
|
[HttpPost] |
|
|
|
|
|
[UnitOfWork(false)] |
|
|
|
|
|
public virtual async Task<IActionResult> BackReissueInvoice([FromBody] string p_inv) |
|
|
|
|
|
{ |
|
|
|
|
|
//var errorlist = await CheckRepeat(p_list).ConfigureAwait(false);
|
|
|
|
|
|
//if (errorlist.Count > 0)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, Message = "错误提示文件已下载,请打开文件查看", fileName = await ExportErrorReportAsync(errorlist) });
|
|
|
|
|
|
//}
|
|
|
|
|
|
//var first = p_list.FirstOrDefault();
|
|
|
|
|
|
var invbillnum = p_inv; |
|
|
|
|
|
List<INVOICE_WAIT_DETAIL_DTO> ls = new List<INVOICE_WAIT_DETAIL_DTO>(); |
|
|
|
|
|
//var adjlist = ObjectMapper.Map<List<PUB_ADJ_DETAIL_DTO>, List<PUB_ADJ_DETAIL>>(p_list);
|
|
|
|
|
|
//if (adjlist == null && adjlist.Count == 0)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// throw new UserFriendlyException($"调整表无数据!", "400");
|
|
|
|
|
|
//}
|
|
|
|
|
|
//var mappingList = await GetMapGroupAsync(p_invbillnum);//发票对应结算分组
|
|
|
|
|
|
//if (mappingList != null && mappingList.Count() > 0)
|
|
|
|
|
|
//{
|
|
|
|
|
|
var version = int.Parse(DateTime.Now.ToString("yyyymm")); |
|
|
|
|
|
//var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组
|
|
|
|
|
|
var inv = await GetInvoiceGroupByInvBillNum(invbillnum).ConfigureAwait(false); |
|
|
|
|
|
var settle = await _pubMng.GetMainAsync(inv.InvGroupNum).ConfigureAwait(false); |
|
|
|
|
|
if (settle == null) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new UserFriendlyException($"选择发票:{invbillnum}对应的可结算单不在请检查!", "400"); |
|
|
|
|
|
} |
|
|
|
|
|
version = settle.Version; |
|
|
|
|
|
if (inv != null) |
|
|
|
|
|
{ |
|
|
|
|
|
if (inv.InvoiceState == InvoiceBillState.报废) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new UserFriendlyException($"选择发票:{invbillnum}状态为报废状态不能重开!", "400"); |
|
|
|
|
|
} |
|
|
|
|
|
if (inv.State == SettleBillState.商务已审核 || inv.State == SettleBillState.已开票) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new UserFriendlyException($"选择发票:{invbillnum}状态在财务审核后可以报废重开,之前不能重开可以退回!", "400"); |
|
|
|
|
|
} |
|
|
|
|
|
var publist = await _pubMng.GetContainsAsync(inv.InvbillNum).ConfigureAwait(false);//结算分组对应结算零件
|
|
|
|
|
|
//var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细
|
|
|
|
|
|
//if (adjlist != null && adjlist.Count > 0)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// var relationList = _relationRepository.Where(p => p.BusinessType == inv.BusinessType).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
// var relist = relationList.GroupBy(p => new { p.SettleMaterialCode, p.ErpMaterialCode }).Select(p => p.FirstOrDefault());
|
|
|
|
|
|
|
|
|
|
|
|
// var errors = await CheckAdJRules(adjlist, relist.ToList(), inv.BusinessType);
|
|
|
|
|
|
// if (errors.Count > 0)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, Message = "错误提示文件已下载,请打开文件查看", fileName = await ExportErrorReportAsync(errors).ConfigureAwait(false) });
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// foreach (var itm in adjlist)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// publist.Add(new PUB_CAN_SA_DETAIL(
|
|
|
|
|
|
// guid: GuidGenerator.Create(),
|
|
|
|
|
|
// keyCode: itm.KeyCode,
|
|
|
|
|
|
// version: itm.Version,
|
|
|
|
|
|
// billNum: itm.InvGroupNum,
|
|
|
|
|
|
// settleBillNum: itm.SettleBillNum,
|
|
|
|
|
|
// lU: itm.LU,
|
|
|
|
|
|
// pN: itm.PN,
|
|
|
|
|
|
// site: itm.Site,
|
|
|
|
|
|
// qty: itm.Qty,
|
|
|
|
|
|
// price: itm.Price,
|
|
|
|
|
|
// businessType: itm.BusinessType,
|
|
|
|
|
|
// settleDate: itm.SettleDate,
|
|
|
|
|
|
// groupNum: itm.GroupNum,
|
|
|
|
|
|
// invGroupNum: inv.InvGroupNum,
|
|
|
|
|
|
// invbillnum: string.Empty,
|
|
|
|
|
|
// partcode: relist.FirstOrDefault(p => p.SettleMaterialCode == itm.LU).ErpMaterialCode,
|
|
|
|
|
|
// pobillnum: string.Empty
|
|
|
|
|
|
// ));
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
var entitys = publist;//合并库存调整单和就发票可结算明细数据
|
|
|
|
|
|
var gNumList = entitys.Select(p => p.GroupNum).Distinct().ToList(); |
|
|
|
|
|
//var groupNumList = entitys.Select(p => new { p.GroupNum).Distinct().ToList();
|
|
|
|
|
|
//var notList = _notRepository.Where(p => gNumList.Contains(p.GroupNum)).ToList();//不能结算
|
|
|
|
|
|
List<PriceList> priceList = new List<PriceList>(); |
|
|
|
|
|
if (inv.BusinessType == EnumBusinessType.BeiJian) |
|
|
|
|
|
{ |
|
|
|
|
|
var priceListbj = _pricebjRepository.ToList();//价格单
|
|
|
|
|
|
foreach (var itm in priceListbj) |
|
|
|
|
|
{ |
|
|
|
|
|
priceList.Add(new PriceList() { LU = itm.LU, BeginTime = itm.BeginDate, EndTime = itm.EndDate, Price = itm.Price, ClientCode = "1049" }); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
priceList = _priceRepository.Where(p => p.IsCancel == false && p.ClientCode == inv.Site).ToList();//价格单
|
|
|
|
|
|
} |
|
|
|
|
|
var errorList = await CheckInvoiceGenerationRules(entitys, priceList, inv.BusinessType).ConfigureAwait(false); |
|
|
|
|
|
if (errorList.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, Message = "错误提示文件已下载,请打开文件查看", fileName = await ExportErrorReportAsync(errorList).ConfigureAwait(false) }); |
|
|
|
|
|
} |
|
|
|
|
|
// var dto1s = ObjectMapper.Map<List<HBPO_CAN_SA_DETAIL>, List<HBPO_CAN_SA_DETAIL_DTO>>(entitys);
|
|
|
|
|
|
var q = from d in entitys |
|
|
|
|
|
join p in priceList on d.LU equals p.LU |
|
|
|
|
|
where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime && p.IsCancel == false && p.ClientCode == inv.Site |
|
|
|
|
|
select new TEMP_CAN_SA_DETAIL |
|
|
|
|
|
{ |
|
|
|
|
|
SettleBillNum = d.SettleBillNum, |
|
|
|
|
|
Site = d.Site, |
|
|
|
|
|
Version = d.Version, |
|
|
|
|
|
Price = p.Price, |
|
|
|
|
|
BillNum = d.BillNum, |
|
|
|
|
|
SettleDate = d.SettleDate, |
|
|
|
|
|
InvGroupNum = d.InvGroupNum, |
|
|
|
|
|
LU = d.LU, |
|
|
|
|
|
// MaterialDesc = d.MaterialDesc,
|
|
|
|
|
|
PN = d.PN, |
|
|
|
|
|
Qty = d.Qty, |
|
|
|
|
|
GroupNum = d.GroupNum, |
|
|
|
|
|
Amt = Math.Round(d.Qty * p.Price, 2), |
|
|
|
|
|
ContractDocID = "n", |
|
|
|
|
|
BeginDate = p.BeginTime, |
|
|
|
|
|
EndDate = p.EndTime, |
|
|
|
|
|
PartCode = d.PartCode |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
var dtos = q.ToList(); |
|
|
|
|
|
if (dtos != null && dtos.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
if (invbillnum.Substring(0, 3) == "INV")//一次开票重开
|
|
|
|
|
|
{ |
|
|
|
|
|
await ReissueFirstInvoice(publist,new List<PUB_ADJ_DETAIL>(), dtos, version, invbillnum).ConfigureAwait(false); |
|
|
|
|
|
} |
|
|
|
|
|
else//二次开票
|
|
|
|
|
|
{ |
|
|
|
|
|
await ReissueSecInvoice(publist, new List<PUB_ADJ_DETAIL>(), dtos, version, invbillnum).ConfigureAwait(false); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
throw new BusinessException("8989", $"不存发票号为:{invbillnum}发票"); |
|
|
|
|
|
} |
|
|
|
|
|
//}
|
|
|
|
|
|
//else
|
|
|
|
|
|
//{
|
|
|
|
|
|
// throw new BusinessException("8989", $"不存发票号:{p_invbillnum}对应的结算分组号");
|
|
|
|
|
|
//}
|
|
|
|
|
|
return new JsonResult(new { Code = 200, Message = "发票重开成功" }); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 提交发票
|
|
|
/// 提交发票
|
|
|