|
|
|
@ -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
|
|
|
|
|
{
|
|
|
|
@ -279,7 +281,7 @@ namespace DS.WMS.Core.Check.Method
|
|
|
|
|
|
|
|
|
|
if (req.Ids.Length == 0)
|
|
|
|
|
return DataResult.Failed("明细业务Ids不能为空");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var businessList = tenantDb.Queryable<CheckBillAutoDetail>().Where(x => x.CheckId == checkId && req.Ids.Contains(x.Id)).ToList();
|
|
|
|
|
|
|
|
|
@ -288,7 +290,7 @@ namespace DS.WMS.Core.Check.Method
|
|
|
|
|
|
|
|
|
|
var details = tenantDb.Queryable<CheckBillAutoDetail>().Where(x => x.CheckId == checkId && !req.Ids.Contains(x.Id)).ToList();
|
|
|
|
|
if (details.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (details.Where(x => x.IsEqual == false).Any())
|
|
|
|
|
{
|
|
|
|
@ -346,8 +348,8 @@ namespace DS.WMS.Core.Check.Method
|
|
|
|
|
|
|
|
|
|
if (req.Id.IsNull())
|
|
|
|
|
return DataResult.Failed("业务Id不能为空");
|
|
|
|
|
var info = tenantDb.Queryable<CheckBillAuto>().Where(x => x.Id ==long.Parse(req.Id)).First();
|
|
|
|
|
|
|
|
|
|
var info = tenantDb.Queryable<CheckBillAuto>().Where(x => x.Id == long.Parse(req.Id)).First();
|
|
|
|
|
|
|
|
|
|
if (info.IsNotNull())
|
|
|
|
|
{
|
|
|
|
|
if (info.BillNo.IsNotNull())
|
|
|
|
@ -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("自动对账明细无一致的明细!"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var list = tenantDb.Queryable<CheckBillAutoDetail>().Where(x => x.CheckId == long.Parse(req.Id)).ToList();
|
|
|
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
if (record.Currency == "USD")
|
|
|
|
|
CheckId = entity.Id,
|
|
|
|
|
BusinessId = biz.BusinessId
|
|
|
|
|
});
|
|
|
|
|
foreach (var record in feeRecordList)
|
|
|
|
|
{
|
|
|
|
|
usdAmount += record.Amount;
|
|
|
|
|
feeList.Add(new CheckBillFeeRecords()
|
|
|
|
|
{
|
|
|
|
|
CheckId = entity.Id,
|
|
|
|
|
BusinessId = biz.BusinessId,
|
|
|
|
|
FeeRecordId = record.Id,
|
|
|
|
|
CheckBillAmount = record.Amount,
|
|
|
|
|
});
|
|
|
|
|
//对账标识
|
|
|
|
|
record.IsDebit = true;
|
|
|
|
|
record.DebitNo = entity.Id.ToString();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//更新费用记录
|
|
|
|
|
await tenantDb.Updateable(feeRecordList).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (businessList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.Insertable(businessList).ExecuteCommandAsync();
|
|
|
|
|
if (feeList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.Insertable(feeList).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
tenantDb.Updateable(list).ExecuteCommand(); ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
info.BillNo = sequence.Data;
|
|
|
|
|
await tenantDb.Updateable(info).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
return DataResult.Successed("重新匹配成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <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();
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|