|
@ -188,22 +188,21 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
_globalConfigOptions.IsSyncInvoiceQadState = true; |
|
|
_globalConfigOptions.IsSyncInvoiceQadState = true; |
|
|
var invoiceGrps1 = _settleAccountDbContext.Set<INVOICE_GRP>() |
|
|
var invoiceGrps1 = _settleAccountDbContext.Set<INVOICE_GRP>() |
|
|
.Where(t => invbillNums.Contains(t.InvbillNum) && t.State == SettleBillState.红冲发票); |
|
|
.Where(t => invbillNums.Contains(t.InvbillNum) && t.State == SettleBillState.红冲发票); |
|
|
var grouplist=invoiceGrps1.Select(p => p.InvGroupNum).ToList();//发票分组
|
|
|
//var grouplist=invoiceGrps1.Select(p => p.InvGroupNum).ToList();//发票分组
|
|
|
var invList=_settleAccountDbContext.Set<INVOICE_GRP>().Where(p => grouplist.Contains(p.InvGroupNum)).ToList(); |
|
|
//var invList=_settleAccountDbContext.Set<INVOICE_GRP>().Where(p => grouplist.Contains(p.InvGroupNum)).ToList();
|
|
|
var query =from itm in invList join itm1 in invoiceGrps1 on new { itm.InvGroupNum, itm.InvbillNum } equals new { itm1.InvGroupNum, itm1.InvbillNum } |
|
|
//var query =from itm in invList join itm1 in invoiceGrps1 on new { itm.InvGroupNum, itm.InvbillNum } equals new { itm1.InvGroupNum, itm1.InvbillNum }
|
|
|
into temp |
|
|
// into temp
|
|
|
from tm in temp.DefaultIfEmpty() |
|
|
// from tm in temp.DefaultIfEmpty()
|
|
|
where tm == null |
|
|
// where tm == null
|
|
|
select itm; |
|
|
// select itm;
|
|
|
|
|
|
|
|
|
var invoices = query.ToList(); |
|
|
//var invoices = query.ToList();
|
|
|
if (invoices.Count > 0) |
|
|
//if (invoices.Count > 0)
|
|
|
{ |
|
|
//{
|
|
|
var invbilllist=invoices.Select(p => p.InvGroupNum).ToList(); |
|
|
// var invbilllist=invoices.Select(p => p.InvGroupNum).ToList();
|
|
|
var invs = invoiceGrps1.Where(p => invbilllist.Contains(p.InvGroupNum)).Select(p => p.InvbillNum).ToList(); |
|
|
// var invs = invoiceGrps1.Where(p => invbilllist.Contains(p.InvGroupNum)).Select(p => p.InvbillNum).ToList();
|
|
|
throw new UserFriendlyException($"发票{string.Join(",", invs.ToArray())}对应结算单(发票分组)有其他发票状态不在撤销状态,不能退回", "400"); |
|
|
// throw new UserFriendlyException($"发票{string.Join(",", invs.ToArray())}对应结算单(发票分组)有其他发票状态不在撤销状态,不能退回", "400");
|
|
|
} |
|
|
//}
|
|
|
|
|
|
|
|
|
foreach (var itm in invoiceGrps1) |
|
|
foreach (var itm in invoiceGrps1) |
|
|
{ |
|
|
{ |
|
|
itm.State = SettleBillState.提交QAD退回到已开票; |
|
|
itm.State = SettleBillState.提交QAD退回到已开票; |
|
@ -2001,67 +2000,78 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
return new JsonResult(new { Code = 200, Message = "退回成功" }); ; |
|
|
return new JsonResult(new { Code = 200, Message = "退回成功" }); ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//[HttpPost]
|
|
|
|
|
|
//public virtual async Task<IActionResult> RejectAsync(INVOICE_GRP_DTO p_dto)
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
|
|
// var invgrouplist=_repository.Where(p=>p.InvGroupNum==p_dto.InvGroupNum);
|
|
|
|
|
|
|
|
|
|
|
|
// if (invgrouplist.Count(p => p.State < SettleBillState.财务已审核) == invgrouplist.Count())//所有发票分组下的放票全为财务已审核的
|
|
|
|
|
|
// {
|
|
|
|
|
|
// await RejectAsync(p_dto.InvGroupNum).ConfigureAwait(false);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var inv= _repository.FirstOrDefault(p => p.InvbillNum == p_dto.InvbillNum);
|
|
|
|
|
|
// if (inv == null)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// return new JsonResult(new { Code = 500, Message = "发票不存在" });
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task RejectionAsync<Tmain, Tdetail>(Tmain main,List<Tdetail> details) |
|
|
|
|
|
where Tdetail: SA_CAN_BASE, new() where Tmain : SA_CAN_BASE_MAIN, new() |
|
|
|
|
|
{ |
|
|
|
|
|
var billNum = string.Empty; |
|
|
|
|
|
if (main.BillNum.Substring(0,1)=="N") |
|
|
|
|
|
{ |
|
|
|
|
|
billNum = OrderNumberGenerator.GenerateOrderNumber("N"); |
|
|
|
|
|
} |
|
|
|
|
|
if (main.BillNum.Substring(0, 1) == "C") |
|
|
|
|
|
{ |
|
|
|
|
|
billNum = OrderNumberGenerator.GenerateOrderNumber("C"); |
|
|
|
|
|
} |
|
|
|
|
|
Tmain newmain = new Tmain(); |
|
|
|
|
|
newmain.InjectFrom(main); |
|
|
|
|
|
newmain.SetId(Guid.NewGuid()); |
|
|
|
|
|
newmain.BillNum = billNum; |
|
|
|
|
|
newmain.CreationTime = DateTime.Now; |
|
|
|
|
|
newmain.State = SettleBillState.已退回; |
|
|
|
|
|
newmain.ExtraProperties.TryAdd("ParentBillNum", main.BillNum); |
|
|
|
|
|
newmain.ExtraProperties.TryAdd("InvBillNum", details.FirstOrDefault().InvbillNum); |
|
|
|
|
|
newmain.ExtraProperties.TryAdd("IsReturn", "是"); |
|
|
|
|
|
var _dbcontext = await _repository.GetDbContextAsync().ConfigureAwait(false); |
|
|
|
|
|
var list = details; |
|
|
|
|
|
foreach (var item in list) |
|
|
|
|
|
{ |
|
|
|
|
|
item.InvbillNum = billNum; |
|
|
|
|
|
} |
|
|
|
|
|
await _dbcontext.BulkInsertAsync(new List<Tmain>() { newmain }).ConfigureAwait(false); |
|
|
|
|
|
await _dbcontext.BulkUpdateAsync(list).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
|
|
public virtual async Task<IActionResult> ReturnAsync(INVOICE_GRP_DTO p_dto) |
|
|
|
|
|
{ |
|
|
|
|
|
var invgrouplist = _repository.Where(p => p.InvGroupNum == p_dto.InvGroupNum); |
|
|
|
|
|
if (invgrouplist.Count(p => p.State < SettleBillState.财务已审核) == invgrouplist.Count())//所有发票分组下的发票全为财务已审核的
|
|
|
|
|
|
{ |
|
|
|
|
|
await RejectAsync(p_dto.InvGroupNum).ConfigureAwait(false); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
var inv = _repository.FirstOrDefault(p => p.InvbillNum == p_dto.InvbillNum); |
|
|
|
|
|
if (inv == null) |
|
|
|
|
|
{ |
|
|
|
|
|
return new JsonResult(new { Code = 500, Message = "发票不存在" }); |
|
|
|
|
|
} |
|
|
|
|
|
var dbcontext = await _repository.GetDbContextAsync().ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
switch(inv.BusinessType) |
|
|
|
|
|
{ |
|
|
|
|
|
case EnumBusinessType.JisBBAC: |
|
|
|
|
|
var bbaclist = await dbcontext.Set<BBAC_CAN_SA_DETAIL>().Where(p => p.InvbillNum == p_dto.InvbillNum).AsNoTracking().ToListAsync().ConfigureAwait(false); |
|
|
|
|
|
var bbacfirst = await dbcontext.Set<BBAC_CAN_SA>().FirstOrDefaultAsync(p => p.BillNum == p_dto.InvGroupNum).ConfigureAwait(false); |
|
|
|
|
|
await RejectionAsync<BBAC_CAN_SA, BBAC_CAN_SA_DETAIL>(bbacfirst, bbaclist.ToList()).ConfigureAwait(false); |
|
|
|
|
|
break; |
|
|
|
|
|
case EnumBusinessType.JisHBPO: |
|
|
|
|
|
var hbpolist = await dbcontext.Set<HBPO_CAN_SA_DETAIL>().Where(p => p.InvbillNum == p_dto.InvbillNum).AsNoTracking().ToListAsync().ConfigureAwait(false); |
|
|
|
|
|
var hbpofirst = await dbcontext.Set<HBPO_CAN_SA>().FirstOrDefaultAsync(p => p.BillNum == p_dto.InvGroupNum).ConfigureAwait(false); |
|
|
|
|
|
await RejectionAsync<HBPO_CAN_SA, HBPO_CAN_SA_DETAIL>(hbpofirst, hbpolist.ToList()).ConfigureAwait(false); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
var publist = await dbcontext.Set<PUB_CAN_SA_DETAIL>().Where(p => p.InvbillNum == p_dto.InvbillNum).ToListAsync().ConfigureAwait(false); |
|
|
|
|
|
var pubfirst = await dbcontext.Set<PUB_CAN_SA>().FirstOrDefaultAsync(p => p.BillNum == p_dto.InvGroupNum).ConfigureAwait(false); |
|
|
|
|
|
await RejectionAsync<PUB_CAN_SA, PUB_CAN_SA_DETAIL>(pubfirst, publist.ToList()).ConfigureAwait(false); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// //var entities = await _invMng.GetMainListAsync(p_invGroupNum).ConfigureAwait(false);
|
|
|
return new JsonResult(new { Code = 200, Message = "退回成功" }); ; |
|
|
// //var entity = entities.FirstOrDefault();
|
|
|
} |
|
|
// //bool state = await _invMng.Reject(p_invGroupNum).ConfigureAwait(false);
|
|
|
|
|
|
// //if (state == true)
|
|
|
|
|
|
// //{
|
|
|
|
|
|
// // switch (entity.BusinessType)
|
|
|
|
|
|
// // {
|
|
|
|
|
|
// // case EnumBusinessType.BeiJian:
|
|
|
|
|
|
// // await _pubMng.SetNewState(p_invGroupNum).ConfigureAwait(false);
|
|
|
|
|
|
// // break;
|
|
|
|
|
|
// // case EnumBusinessType.ZhiGongJianBBAC:
|
|
|
|
|
|
// // await _pubMng.SetNewState(p_invGroupNum).ConfigureAwait(false);
|
|
|
|
|
|
// // break;
|
|
|
|
|
|
// // case EnumBusinessType.ZhiGongJianHBPO:
|
|
|
|
|
|
// // await _pubMng.SetNewState(p_invGroupNum).ConfigureAwait(false);
|
|
|
|
|
|
// // break;
|
|
|
|
|
|
// // case EnumBusinessType.YinDuJian:
|
|
|
|
|
|
// // await _pubMng.SetNewState(p_invGroupNum).ConfigureAwait(false);
|
|
|
|
|
|
// // break;
|
|
|
|
|
|
// // case EnumBusinessType.JisBBAC:
|
|
|
|
|
|
// // await _bbacMng.SetNewState(p_invGroupNum).ConfigureAwait(false);
|
|
|
|
|
|
// // break;
|
|
|
|
|
|
// // case EnumBusinessType.JisHBPO:
|
|
|
|
|
|
// // await _hbpoMng.SetNewState(p_invGroupNum).ConfigureAwait(false);
|
|
|
|
|
|
// // break;
|
|
|
|
|
|
// // }
|
|
|
|
|
|
// //}
|
|
|
|
|
|
// return new JsonResult(new { Code = 200, Message = "退回成功" }); ;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -2115,7 +2125,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
var newinv1 = result.Where(p => p.InvbillNum == inv.InvbillNum).FirstOrDefault(); |
|
|
var newinv1 = result.Where(p => p.InvbillNum == inv.InvbillNum).FirstOrDefault(); |
|
|
var newinv = ls.Where(p => p.InvbillNum == inv.InvbillNum).FirstOrDefault(); |
|
|
var newinv = ls.Where(p => p.InvbillNum == inv.InvbillNum).FirstOrDefault(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inv.Tax = 0.13m; |
|
|
inv.Tax = 0.13m; |
|
|
inv.RealnvBillNum = newinv.RealnvBillNum; |
|
|
inv.RealnvBillNum = newinv.RealnvBillNum; |
|
|
inv.TaxDiff = newinv.PreTaxDiff; |
|
|
inv.TaxDiff = newinv.PreTaxDiff; |
|
|