自动对账接口修改

usertest
cjy 5 months ago
parent 66bbf80822
commit de366049c7

@ -128,4 +128,66 @@ public class CheckBillAutoController : ApiController
throw new Exception(ex.ToString());
}
}
/// <summary>
/// 对账明细批量删除
/// </summary>
/// <param name="req">主表Id及明细业务Ids</param>
/// <returns></returns>
[HttpPost]
[Route("BatchDelCheckBillAutoDetail")]
public DataResult BatchDelCheckBillAutoDetail([FromBody] IdModel req)
{
var res = _invokeService.BatchDelCheckBillAutoDetail(req);
return res;
}
/// <summary>
/// 自动对账批量删除
/// </summary>
/// <param name="req">主表Ids</param>
/// <returns></returns>
[HttpPost]
[Route("BatchDelCheckBillAuto")]
public DataResult BatchDelCheckBillAuto([FromBody] IdModel req)
{
var res = _invokeService.BatchDelCheckBillAuto(req);
return res;
}
/// <summary>
/// 自动对账重新匹配
/// </summary>
/// <param name="req">主表Id</param>
/// <returns></returns>
[HttpPost]
[Route("RecountCheckBillAuto")]
public DataResult RecountCheckBillAuto([FromBody] IdModel req)
{
var res = _invokeService.RecountCheckBillAuto(req);
return res;
}
/// <summary>
/// 生成对账单
/// </summary>
/// <param name="req">主表Id</param>
/// <returns></returns>
[HttpPost]
[Route("CreateCheckBill")]
public async Task<DataResult> CreateCheckBill([FromBody] IdModel req)
{
var res = await _invokeService.CreateCheckBill(req);
return res;
}
/// <summary>
/// 取消生成的对账单
/// </summary>
/// <param name="req">主表Id</param>
/// <returns></returns>
[HttpPost]
[Route("CancelCheckBill")]
public async Task<DataResult> CancelCheckBill([FromBody] IdModel req)
{
var res = await _invokeService.CancelCheckBill(req);
return res;
}
}

@ -62,5 +62,24 @@ namespace DS.WMS.Core.Check.Interface
/// <param name="req">主表Ids</param>
/// <returns></returns>
public DataResult BatchDelCheckBillAuto(IdModel req);
/// <summary>
/// 自动对账重新匹配
/// </summary>
/// <param name="req">主表Id</param>
/// <returns></returns>
public DataResult RecountCheckBillAuto(IdModel req);
/// <summary>
/// 生成对账单
/// </summary>
/// <param name="req">主表Id</param>
/// <returns></returns>
public Task<DataResult> CreateCheckBill(IdModel req);
/// <summary>
/// 取消生成的对账单
/// </summary>
/// <param name="req">主表Id</param>
/// <returns></returns>
public Task<DataResult> CancelCheckBill(IdModel req);
}
}

@ -23,6 +23,8 @@ using Quartz.Logging;
using DS.Module.Core.Data;
using System.Collections;
using LanguageExt.ClassInstances.Pred;
using DS.WMS.Core.Fee.Dtos;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace DS.WMS.Core.Check.Method
{
@ -403,7 +405,8 @@ namespace DS.WMS.Core.Check.Method
}
tenantDb.Updateable(info).ExecuteCommand();
}
else {
else
{
return DataResult.Failed("自动对账主表信息不存在");
}
@ -417,26 +420,41 @@ namespace DS.WMS.Core.Check.Method
/// </summary>
/// <param name="req">主表Id</param>
/// <returns></returns>
public DataResult CreateCheckBill(IdModel req)
public async Task<DataResult> CreateCheckBill(IdModel req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Id.IsNull())
return DataResult.Failed("业务Id不能为空");
var info = tenantDb.Queryable<CheckBillAuto>().Where(x => x.Id == long.Parse(req.Id)).First();
return await Task.FromResult(DataResult.Failed("业务Id不能为空"));
var info = await tenantDb.Queryable<CheckBillAuto>().Where(x => x.Id == long.Parse(req.Id)).FirstAsync();
if (info.IsNull())
return DataResult.Failed("自动对账主表信息不存在");
return await Task.FromResult(DataResult.Failed("自动对账主表信息不存在"));
if (info.BillNo.IsNotNull())
return DataResult.Failed("对账信息已生成!");
return await Task.FromResult(DataResult.Failed("对账信息已生成!"));
var list = await tenantDb.Queryable<CheckBillAutoDetail>().Where(x => x.CheckId == long.Parse(req.Id) && x.IsEqual == true).ToListAsync();
if (list.Count == 0)
return await Task.FromResult(DataResult.Failed("自动对账明细无一致的明细!"));
await tenantDb.Ado.BeginTranAsync();
try
{
var list = tenantDb.Queryable<CheckBillAutoDetail>().Where(x => x.CheckId == long.Parse(req.Id)).ToList();
var data = info.Adapt<CheckBill>();
var sequence = commonService.GetSequenceNext<CheckBill>();
if (!sequence.Succeeded)
{
return await Task.FromResult(DataResult.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist));
}
data.BillNo = sequence.Data;
var entity = await tenantDb.Insertable(data).ExecuteReturnEntityAsync();
var businessList = new List<CheckBillBusiness>();
var feeList = new List<CheckBillFeeRecords>();
foreach (var bill in list)
{
var mblno = bill.MBLNO;
var usdAmount = 0M;
var rmbAmount = 0M;
var bizList = tenantDb.Queryable<VW_Op_Business>().Where(x => x.MBLNO.Contains(mblno)).ToList();
var mblnos = bizList.Select(x => x.MBLNO).Distinct();
foreach (var temp in mblnos)
@ -446,31 +464,104 @@ namespace DS.WMS.Core.Check.Method
//var mainBiz = bizlist1[0];
foreach (var biz in bizlist1)
{
var feeList = tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == biz.BusinessId && x.CustomerId == info.CustomerId && x.FeeType == FeeType.Payable).ToList();
foreach (var record in feeList)
var feeRecordList = tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == biz.BusinessId && x.CustomerId == info.CustomerId && x.FeeType == FeeType.Payable).ToList();
if (feeRecordList.Count > 0)
{
if (record.Currency == "RMB")
businessList.Add(new CheckBillBusiness()
{
rmbAmount += record.Amount;
CheckId = entity.Id,
BusinessId = biz.BusinessId
});
foreach (var record in feeRecordList)
{
feeList.Add(new CheckBillFeeRecords()
{
CheckId = entity.Id,
BusinessId = biz.BusinessId,
FeeRecordId = record.Id,
CheckBillAmount = record.Amount,
});
//对账标识
record.IsDebit = true;
record.DebitNo = entity.Id.ToString();
}
if (record.Currency == "USD")
//更新费用记录
await tenantDb.Updateable(feeRecordList).ExecuteCommandAsync();
}
}
}
}
if (businessList.Count > 0)
{
usdAmount += record.Amount;
await tenantDb.Insertable(businessList).ExecuteCommandAsync();
if (feeList.Count > 0)
{
await tenantDb.Insertable(feeList).ExecuteCommandAsync();
}
}
info.BillNo = sequence.Data;
await tenantDb.Updateable(info).ExecuteCommandAsync();
await tenantDb.Ado.CommitTranAsync();
return await Task.FromResult(DataResult.Successed("生成对账单成功!", MultiLanguageConst.DataUpdateSuccess));
}
catch (Exception ex)
{
await tenantDb.Ado.RollbackTranAsync();
//await ex.LogAsync(tenantDb);
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
bill.RMBLocalAmount = rmbAmount;
bill.USDLocalAmount = usdAmount;
bill.RMBDifferenceAmount = rmbAmount - bill.RMBCheckAmount;
bill.USDDifferenceAmount = usdAmount - bill.USDCheckAmount;
bill.IsEqual = (rmbAmount - bill.RMBCheckAmount == 0 && usdAmount - bill.USDCheckAmount == 0) ? true : false;
}
tenantDb.Updateable(list).ExecuteCommand(); ;
/// <summary>
/// 取消生成的对账单
/// </summary>
/// <param name="req">主表Id</param>
/// <returns></returns>
public async Task<DataResult> CancelCheckBill(IdModel req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Id.IsNull())
return await Task.FromResult(DataResult.Failed("业务Id不能为空"));
var info = await tenantDb.Queryable<CheckBillAuto>().Where(x => x.Id == long.Parse(req.Id)).FirstAsync();
if (info.IsNull())
return await Task.FromResult(DataResult.Failed("自动对账主表信息不存在"));
if (info.BillNo.IsNull())
return await Task.FromResult(DataResult.Failed("对账信息未生成!"));
var bill = await tenantDb.Queryable<CheckBill>().Where(x => x.BillNo == info.BillNo).FirstAsync();
return DataResult.Successed("重新匹配成功!", MultiLanguageConst.DataUpdateSuccess);
if (bill.IsNull())
return await Task.FromResult(DataResult.Failed("对账信息不存在!"));
if ((bool)bill.IsLocking)
return await Task.FromResult(DataResult.Failed("对账信息已锁定!"));
await tenantDb.Ado.BeginTranAsync();
try
{
var billlist = await tenantDb.Queryable<CheckBillBusiness>().Where(x => x.CheckId == bill.Id).ToListAsync();
var feelist = await tenantDb.Queryable<CheckBillFeeRecords>().Where(x => x.CheckId == bill.Id).ToListAsync();
await tenantDb.Deleteable(feelist).ExecuteCommandAsync();
await tenantDb.Deleteable(billlist).ExecuteCommandAsync();
await tenantDb.Deleteable(bill).ExecuteCommandAsync();
info.BillNo = "";
await tenantDb.Updateable(info).ExecuteCommandAsync();
await tenantDb.Ado.CommitTranAsync();
return await Task.FromResult(DataResult.Successed("取消对账单成功!", MultiLanguageConst.DataUpdateSuccess));
}
catch (Exception ex)
{
await tenantDb.Ado.RollbackTranAsync();
//await ex.LogAsync(tenantDb);
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
}
}
}

Loading…
Cancel
Save