You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
902 lines
41 KiB
C#
902 lines
41 KiB
C#
using AngleSharp.Dom;
|
|
using DS.Module.Core;
|
|
using DS.Module.Core.Data;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.Module.SqlSugar;
|
|
using DS.Module.UserModule;
|
|
using DS.WMS.Core.Check.Dtos;
|
|
using DS.WMS.Core.Check.Entity;
|
|
using DS.WMS.Core.Check.Interface;
|
|
using DS.WMS.Core.Check.View;
|
|
using DS.WMS.Core.Code.Entity;
|
|
using DS.WMS.Core.Fee.Dtos;
|
|
using DS.WMS.Core.Fee.Entity;
|
|
using DS.WMS.Core.Info.Entity;
|
|
using DS.WMS.Core.Op.Dtos;
|
|
using DS.WMS.Core.Op.Entity;
|
|
using DS.WMS.Core.Op.View;
|
|
using DS.WMS.Core.Sys.Entity;
|
|
using DS.WMS.Core.Sys.Interface;
|
|
using DS.WMS.Core.Sys.Method;
|
|
using LanguageExt.Common;
|
|
using Mapster;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Spire.Xls;
|
|
using SqlSugar;
|
|
using static AnyDiff.DifferenceLines;
|
|
|
|
namespace DS.WMS.Core.Check.Method
|
|
{
|
|
public class CheckBillService : ICheckBillService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ISqlSugarClient db;
|
|
private readonly IUser user;
|
|
private readonly ISaasDbService saasService;
|
|
private readonly ICommonService commonService;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public CheckBillService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
|
|
commonService = _serviceProvider.GetRequiredService<ICommonService>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 业务明细查询列表
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public DataResult<List<VW_CheckBill_Detail>> GetBusinessQueryList(PageRequest request)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var users = db.Queryable<SysUser>().Select(x => new { x.Id, x.UserName }).ToList();
|
|
//序列化查询条件
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
|
|
var otherConditons = new List<IConditionalModel>();
|
|
if (request.OtherQueryCondition.IsNotNull())
|
|
otherConditons = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.OtherQueryCondition);
|
|
|
|
var queryData = tenantDb.Queryable<VW_CheckBill_Detail>()
|
|
.Where(whereList);
|
|
if (otherConditons.Count > 0)
|
|
{
|
|
var businessIds = tenantDb.Queryable<FeeRecord>().Where(otherConditons).Select(x => x.BusinessId).Distinct().ToList();
|
|
|
|
queryData = queryData.Where(x => businessIds.Contains(x.Id));
|
|
}
|
|
var data = queryData.ToQueryPage(request.PageCondition);
|
|
return data;
|
|
}
|
|
/// <summary>
|
|
/// 业务明细对应费用查询列表
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public DataResult<List<CheckBillFeeRecordRes>> GetFeeRecordQueryList(PageRequest request)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
//序列化查询条件
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
var data = tenantDb.Queryable<FeeRecord>()
|
|
.Where(whereList).Select<CheckBillFeeRecordRes>()
|
|
.ToQueryPage(request.PageCondition);
|
|
return data;
|
|
}
|
|
/// <summary>
|
|
/// 客户对账列表
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public async Task<DataResult<CheckBillListRes>> GetCheckBillList(PageRequest request)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var users = db.Queryable<SysUser>().Select(x => new { x.Id, x.UserName }).ToList();
|
|
//序列化查询条件
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
|
|
var otherConditons = new List<IConditionalModel>();
|
|
if (request.OtherQueryCondition.IsNotNull())
|
|
otherConditons = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.OtherQueryCondition);
|
|
|
|
var queryData = tenantDb.Queryable<CheckBill>()
|
|
.Where(whereList)
|
|
.Select<CheckBillSumRes>();
|
|
if (otherConditons.Count > 0)
|
|
{
|
|
var checkIds = tenantDb.Queryable<VW_CheckBill_Business>().Where(otherConditons).Select(x => x.CheckId).Distinct().ToList();
|
|
|
|
queryData = queryData.Where(x => checkIds.Contains(x.Id));
|
|
}
|
|
|
|
var result = queryData.Mapper(it =>
|
|
{
|
|
var checkBillDetails = tenantDb.Queryable<VW_CheckBill_Business>().Where(x => x.CheckId == it.Id).ToList();
|
|
//it.CreateByName = users.Find(x => x.Id == it.CreateBy).UserName;
|
|
it.RMBDR = checkBillDetails.Sum(x => x.RMBDR);
|
|
it.RMBCR = checkBillDetails.Sum(x => x.RMBCR);
|
|
it.USDDR = checkBillDetails.Sum(x => x.USDDR);
|
|
it.USDCR = checkBillDetails.Sum(x => x.USDCR);
|
|
it.BALRMBDR = checkBillDetails.Sum(x => x.BALRMBDR);
|
|
it.BALRMBCR = checkBillDetails.Sum(x => x.BALRMBCR);
|
|
it.BALUSDDR = checkBillDetails.Sum(x => x.BALUSDDR);
|
|
it.BALUSDCR = checkBillDetails.Sum(x => x.BALUSDCR);
|
|
it.OtherDR = checkBillDetails.Sum(x => x.OtherDR);
|
|
it.OtherCR = checkBillDetails.Sum(x => x.OtherCR);
|
|
it.BALOtherDR = checkBillDetails.Sum(x => x.BALOtherDR);
|
|
it.TTLDR = checkBillDetails.Sum(x => x.TTLDR);
|
|
it.TTLCR = checkBillDetails.Sum(x => x.TTLCR);
|
|
it.BALTTLDR = checkBillDetails.Sum(x => x.BALTTLDR);
|
|
it.BALTTLCR = checkBillDetails.Sum(x => x.BALTTLCR);
|
|
it.OrderInvoiceRMBDR = checkBillDetails.Sum(x => x.OrderInvoiceRMBDR);
|
|
it.OrderInvoiceUSDDR = checkBillDetails.Sum(x => x.OrderInvoiceUSDDR);
|
|
it.OrderAmountRMBCR = checkBillDetails.Sum(x => x.OrderAmountRMBCR);
|
|
it.OrderAmountUSDCR = checkBillDetails.Sum(x => x.OrderAmountUSDCR);
|
|
}
|
|
);
|
|
var list = result.ToList();
|
|
var data = await result.ToQueryPageAsync(request.PageCondition);
|
|
var totalData = new CheckBillTotalRes()
|
|
{
|
|
RMBDR = list.Sum(x => x.RMBDR),
|
|
RMBCR = list.Sum(x => x.RMBCR),
|
|
USDDR = list.Sum(x => x.USDDR),
|
|
USDCR = list.Sum(x => x.USDCR),
|
|
BALRMBDR = list.Sum(x => x.BALRMBDR),
|
|
BALRMBCR = list.Sum(x => x.BALRMBCR),
|
|
BALUSDDR = list.Sum(x => x.BALUSDDR),
|
|
BALUSDCR = list.Sum(x => x.BALUSDCR),
|
|
OtherDR = list.Sum(x => x.OtherDR),
|
|
OtherCR = list.Sum(x => x.OtherCR),
|
|
BALOtherDR = list.Sum(x => x.BALOtherDR),
|
|
TTLDR = list.Sum(x => x.TTLDR),
|
|
TTLCR = list.Sum(x => x.TTLCR),
|
|
BALTTLDR = list.Sum(x => x.BALTTLDR),
|
|
BALTTLCR = list.Sum(x => x.BALTTLCR),
|
|
OrderInvoiceRMBDR = list.Sum(x => x.OrderInvoiceRMBDR),
|
|
OrderInvoiceUSDDR = list.Sum(x => x.OrderInvoiceUSDDR),
|
|
OrderAmountRMBCR = list.Sum(x => x.OrderAmountRMBCR),
|
|
OrderAmountUSDCR = list.Sum(x => x.OrderAmountUSDCR),
|
|
};
|
|
var res = new CheckBillListRes()
|
|
{
|
|
List = data.Data,
|
|
TotalCount = list.Count(),
|
|
DataTotal = totalData
|
|
};
|
|
return await Task.FromResult(DataResult<CheckBillListRes>.Success(res, MultiLanguageConst.DataQuerySuccess));
|
|
//.ToQueryPage(request.PageCondition);
|
|
//return data;
|
|
}
|
|
/// <summary>
|
|
/// 详情
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public DataResult<CheckBillInfoRes> GetCheckBillInfo(string id)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var data = tenantDb.Queryable<CheckBill>()
|
|
.Where(a => a.Id == long.Parse(id))
|
|
.Select<CheckBillInfoRes>()
|
|
.First();
|
|
return DataResult<CheckBillInfoRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 客户对账明细列表
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public async Task<DataResult<CheckBillBusinessRes>> GetCheckBillBusinessList(PageRequest request)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
//序列化查询条件
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
var result = tenantDb.Queryable<VW_CheckBill_Business>()
|
|
.Where(whereList);
|
|
var list = result.ToList();
|
|
var data = await result.ToQueryPageAsync(request.PageCondition);
|
|
var totalData = new CheckBillTotalRes()
|
|
{
|
|
RMBDR = list.Sum(x => x.RMBDR),
|
|
RMBCR = list.Sum(x => x.RMBCR),
|
|
USDDR = list.Sum(x => x.USDDR),
|
|
USDCR = list.Sum(x => x.USDCR),
|
|
BALRMBDR = list.Sum(x => x.BALRMBDR),
|
|
BALRMBCR = list.Sum(x => x.BALRMBCR),
|
|
BALUSDDR = list.Sum(x => x.BALUSDDR),
|
|
BALUSDCR = list.Sum(x => x.BALUSDCR),
|
|
OtherDR = list.Sum(x => x.OtherDR),
|
|
OtherCR = list.Sum(x => x.OtherCR),
|
|
BALOtherDR = list.Sum(x => x.BALOtherDR),
|
|
TTLDR = list.Sum(x => x.TTLDR),
|
|
TTLCR = list.Sum(x => x.TTLCR),
|
|
BALTTLDR = list.Sum(x => x.BALTTLDR),
|
|
BALTTLCR = list.Sum(x => x.BALTTLCR),
|
|
OrderInvoiceRMBDR = list.Sum(x => x.OrderInvoiceRMBDR),
|
|
OrderInvoiceUSDDR = list.Sum(x => x.OrderInvoiceUSDDR),
|
|
OrderAmountRMBCR = list.Sum(x => x.OrderAmountRMBCR),
|
|
OrderAmountUSDCR = list.Sum(x => x.OrderAmountUSDCR),
|
|
};
|
|
var res = new CheckBillBusinessRes()
|
|
{
|
|
List = data.Data,
|
|
TotalCount = list.Count(),
|
|
DataTotal = totalData
|
|
};
|
|
return await Task.FromResult(DataResult<CheckBillBusinessRes>.Success(res, MultiLanguageConst.DataQuerySuccess));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 客户对账明细对应费用列表
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public DataResult<List<VW_CheckBill_Fee_Records>> GetCheckBillFeeRecordsList(PageRequest request)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
//序列化查询条件
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
var data = tenantDb.Queryable<VW_CheckBill_Fee_Records>()
|
|
.Where(whereList)
|
|
.ToQueryPage(request.PageCondition);
|
|
return data;
|
|
}
|
|
/// <summary>
|
|
/// 编辑
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public DataResult EditCheckBill(CheckBillReq req)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
if (req.Id == 0)
|
|
{
|
|
var data = req.Adapt<CheckBill>();
|
|
var sequence = commonService.GetSequenceNext<CheckBill>();
|
|
if (!sequence.Succeeded)
|
|
{
|
|
return DataResult.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist);
|
|
}
|
|
data.BillNo = sequence.Data;
|
|
var entity = tenantDb.Insertable(data).ExecuteReturnEntity();
|
|
|
|
if (req.BusinessIds.Count > 0)
|
|
{
|
|
var businessList = new List<CheckBillBusiness>();
|
|
var feeList = new List<CheckBillFeeRecords>();
|
|
foreach (var item in req.BusinessIds)
|
|
{
|
|
businessList.Add(new CheckBillBusiness()
|
|
{
|
|
CheckId = entity.Id,
|
|
BusinessId = item
|
|
});
|
|
var feeRecords = tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == item).ToList();
|
|
foreach (var record in feeRecords)
|
|
{
|
|
feeList.Add(new CheckBillFeeRecords()
|
|
{
|
|
CheckId = entity.Id,
|
|
BusinessId = item,
|
|
FeeRecordId = record.Id,
|
|
CheckBillAmount = record.Amount,
|
|
});
|
|
//对账标识
|
|
record.IsDebit = true;
|
|
record.DebitNo = entity.Id.ToString();
|
|
}
|
|
//更新费用记录
|
|
tenantDb.Updateable(feeRecords).ExecuteCommand();
|
|
|
|
}
|
|
tenantDb.Insertable(businessList).ExecuteCommand();
|
|
tenantDb.Insertable(feeList).ExecuteCommand();
|
|
}
|
|
|
|
return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
|
|
}
|
|
else
|
|
{
|
|
var info = tenantDb.Queryable<CheckBill>().Where(x => x.Id == req.Id).First();
|
|
if ((bool)info.IsLocking)
|
|
return DataResult.Failed("客户对账信息已锁定");
|
|
info = req.Adapt(info);
|
|
|
|
tenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
|
|
//var businessList = new List<CheckBillBusiness>();
|
|
//var feeList = new List<CheckBillFeeRecords>();
|
|
//if (req.BusinessIds.Count > 0)
|
|
//{
|
|
// var businessIds = tenantDb.Queryable<CheckBillBusiness>().Where(x => x.CheckId == req.Id).Select(x => x.BusinessId).ToList();
|
|
// var addBusinessIds = req.BusinessIds.AsQueryable().Except(businessIds);
|
|
|
|
|
|
// if (addBusinessIds.Count() > 0)
|
|
// {
|
|
|
|
// foreach (var item in addBusinessIds)
|
|
// {
|
|
// businessList.Add(new CheckBillBusiness()
|
|
// {
|
|
// CheckId = info.Id,
|
|
// BusinessId = item
|
|
// });
|
|
// var feeRecords = tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == item).ToList();
|
|
// foreach (var record in feeRecords)
|
|
// {
|
|
// feeList.Add(new CheckBillFeeRecords()
|
|
// {
|
|
// CheckId = info.Id,
|
|
// BusinessId = item,
|
|
// FeeRecordId = record.Id,
|
|
// CheckBillAmount = record.Amount,
|
|
// });
|
|
// //对账标识
|
|
// record.IsDebit = true;
|
|
// record.DebitNo = info.Id.ToString();
|
|
// }
|
|
// //更新费用记录
|
|
// tenantDb.Updateable(feeRecords).ExecuteCommand();
|
|
// }
|
|
// tenantDb.Insertable(businessList).ExecuteCommand();
|
|
// tenantDb.Insertable(feeList).ExecuteCommand();
|
|
// }
|
|
//}
|
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 对账明细批量删除
|
|
/// </summary>
|
|
/// <param name="req">主表Id及明细业务Ids</param>
|
|
/// <returns></returns>
|
|
public DataResult BatchDelCheckBillDetail(IdModel req)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var checkId = long.Parse(req.Id);
|
|
if (req.Id.IsNull())
|
|
return DataResult.Failed("主表Id不能为空");
|
|
|
|
var info = tenantDb.Queryable<CheckBill>().First(x => x.Id == checkId);
|
|
if (info.IsNull())
|
|
return DataResult.Failed("客户对账信息不存在");
|
|
|
|
if (req.Ids.Length == 0)
|
|
return DataResult.Failed("明细业务Ids不能为空");
|
|
|
|
if ((bool)info.IsLocking)
|
|
return DataResult.Failed("客户对账信息已锁定");
|
|
|
|
var businessList = tenantDb.Queryable<CheckBillBusiness>().Where(x => x.CheckId == checkId && req.Ids.Contains(x.BusinessId)).ToList();
|
|
|
|
if (businessList.Count > 0)
|
|
tenantDb.Deleteable(businessList).ExecuteCommand();
|
|
var feeList = tenantDb.Queryable<CheckBillFeeRecords>().Where(x => x.CheckId == checkId && req.Ids.Contains(x.BusinessId)).ToList();
|
|
|
|
if (feeList.Count > 0)
|
|
{
|
|
#region 更新费用记录对账标识
|
|
var feeIds = feeList.Select(x => x.FeeRecordId).Distinct().ToList();
|
|
var feeRecords = tenantDb.Queryable<FeeRecord>().Where(x => feeIds.Contains(x.Id)).ToList();
|
|
foreach (var record in feeRecords)
|
|
{
|
|
//对账标识
|
|
record.IsDebit = false;
|
|
record.DebitNo = "";
|
|
}
|
|
//更新费用记录
|
|
tenantDb.Updateable(feeRecords).ExecuteCommand();
|
|
#endregion
|
|
tenantDb.Deleteable(feeList).ExecuteCommand();
|
|
}
|
|
|
|
return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 对账明细费用批量删除
|
|
/// </summary>
|
|
/// <param name="req">主表Id及费用Ids</param>
|
|
/// <returns></returns>
|
|
public DataResult BatchDelCheckBillFeeRecords(IdModel req)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var checkId = long.Parse(req.Id);
|
|
if (req.Id.IsNull())
|
|
return DataResult.Failed("主表Id不能为空");
|
|
|
|
var info = tenantDb.Queryable<CheckBill>().First(x => x.Id == checkId);
|
|
if (info.IsNull())
|
|
return DataResult.Failed("客户对账信息不存在");
|
|
|
|
if (req.Ids.Length == 0)
|
|
return DataResult.Failed("明细业务Ids不能为空");
|
|
|
|
if ((bool)info.IsLocking)
|
|
return DataResult.Failed("客户对账信息已锁定");
|
|
|
|
|
|
var feeList = tenantDb.Queryable<CheckBillFeeRecords>().Where(x => x.CheckId == checkId && req.Ids.Contains(x.FeeRecordId)).ToList();
|
|
|
|
if (feeList.Count > 0)
|
|
{
|
|
#region 更新费用记录对账标识
|
|
var feeRecords = tenantDb.Queryable<FeeRecord>().Where(x => req.Ids.Contains(x.Id)).ToList();
|
|
foreach (var record in feeRecords)
|
|
{
|
|
//对账标识
|
|
record.IsDebit = false;
|
|
record.DebitNo = "";
|
|
}
|
|
//更新费用记录
|
|
tenantDb.Updateable(feeRecords).ExecuteCommand();
|
|
#endregion
|
|
|
|
tenantDb.Deleteable(feeList).ExecuteCommand();
|
|
}
|
|
return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess);
|
|
}
|
|
/// <summary>
|
|
/// 对账列表批量删除
|
|
/// </summary>
|
|
/// <param name="req">主表Ids</param>
|
|
/// <returns></returns>
|
|
public async Task<DataResult> BatchDelCheckBill(IdModel req)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
if (req.Ids.Length == 0)
|
|
return DataResult.Failed("业务Ids不能为空");
|
|
|
|
if (tenantDb.Queryable<CheckBill>().Where(x => req.Ids.Contains(x.Id) && x.IsLocking == true).Any())
|
|
{
|
|
return DataResult.Failed("存在客户对账信息已锁定");
|
|
}
|
|
try
|
|
{
|
|
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
foreach (var item in req.Ids)
|
|
{
|
|
var info = await tenantDb.Queryable<CheckBill>().FirstAsync(x => x.Id == item);
|
|
//if (info.IsNull())
|
|
// return DataResult.Failed("客户对账信息不存在");
|
|
|
|
var businessList = tenantDb.Queryable<CheckBillBusiness>().Where(x => x.CheckId == item).ToList();
|
|
|
|
if (businessList.Count > 0)
|
|
tenantDb.Deleteable(businessList).ExecuteCommand();
|
|
var feeList = tenantDb.Queryable<CheckBillFeeRecords>().Where(x => x.CheckId == item).ToList();
|
|
|
|
if (feeList.Count > 0)
|
|
{
|
|
#region 更新费用记录对账标识
|
|
var feeIds = feeList.Select(x => x.FeeRecordId).Distinct().ToList();
|
|
var feeRecords = tenantDb.Queryable<FeeRecord>().Where(x => feeIds.Contains(x.Id)).ToList();
|
|
foreach (var record in feeRecords)
|
|
{
|
|
//对账标识
|
|
record.IsDebit = false;
|
|
record.DebitNo = "";
|
|
}
|
|
//更新费用记录
|
|
tenantDb.Updateable(feeRecords).ExecuteCommand();
|
|
#endregion
|
|
tenantDb.Deleteable(feeList).ExecuteCommand();
|
|
}
|
|
tenantDb.Deleteable(info).ExecuteCommand();
|
|
|
|
}
|
|
await tenantDb.Ado.CommitTranAsync();
|
|
return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
await tenantDb.Ado.RollbackTranAsync();
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 对账明细添加
|
|
/// </summary>
|
|
/// <param name="req">主表Id及明细业务Ids</param>
|
|
/// <returns></returns>
|
|
public async Task<DataResult> AddCheckBillDetail(AddCheckBillDetailReq req)
|
|
{
|
|
var conditions = new List<IConditionalModel>();
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var checkId = req.Id;
|
|
if (checkId == 0)
|
|
{
|
|
if (req.Ids.Length == 0)
|
|
return DataResult.Failed("明细业务Ids不能为空");
|
|
|
|
var first = await tenantDb.Queryable<VW_Op_Business>().Where(x => x.BusinessId == req.Ids[0]).FirstAsync();
|
|
|
|
if (tenantDb.Queryable<VW_Op_Business>().Where(x => req.Ids.Contains(x.BusinessId) && x.CustomerId != first.CustomerId).Any())
|
|
return DataResult.Failed("明细客户不一致");
|
|
|
|
var sequence = commonService.GetSequenceNext<CheckBill>();
|
|
if (!sequence.Succeeded)
|
|
{
|
|
return DataResult.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist);
|
|
}
|
|
var data = new CheckBill()
|
|
{
|
|
CustomerId = first.CustomerId,
|
|
CustomerName = first.CustomerName,
|
|
CheckDate = DateTime.Now,
|
|
BillType = req.BillType,
|
|
IsLocking = false,
|
|
IsNoTax = false,
|
|
};
|
|
|
|
data.BillNo = sequence.Data;
|
|
data.BillName = first.CustomerName + sequence.Data;
|
|
|
|
var businessList = new List<CheckBillBusiness>();
|
|
var feeList = new List<CheckBillFeeRecords>();
|
|
|
|
try
|
|
{
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
var entity = await tenantDb.Insertable(data).ExecuteReturnEntityAsync();
|
|
foreach (var item in req.Ids)
|
|
{
|
|
businessList.Add(new CheckBillBusiness()
|
|
{
|
|
CheckId = entity.Id,
|
|
BusinessId = item
|
|
});
|
|
if (!string.IsNullOrEmpty(req.QueryString))
|
|
{
|
|
//序列化查询条件
|
|
conditions = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(req.QueryString);
|
|
}
|
|
var feeRecords = await tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == item).Where(conditions).ToListAsync();
|
|
foreach (var record in feeRecords)
|
|
{
|
|
feeList.Add(new CheckBillFeeRecords()
|
|
{
|
|
CheckId = entity.Id,
|
|
BusinessId = item,
|
|
FeeRecordId = record.Id,
|
|
CheckBillAmount = record.Amount,
|
|
});
|
|
//对账标识
|
|
record.IsDebit = true;
|
|
record.DebitNo = entity.Id.ToString();
|
|
}
|
|
//更新费用记录
|
|
await tenantDb.Updateable(feeRecords).ExecuteCommandAsync();
|
|
}
|
|
await tenantDb.Insertable(businessList).ExecuteCommandAsync();
|
|
await tenantDb.Insertable(feeList).ExecuteCommandAsync();
|
|
|
|
await tenantDb.Ado.CommitTranAsync();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
await tenantDb.Ado.RollbackTranAsync();
|
|
throw;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
var info = await tenantDb.Queryable<CheckBill>().FirstAsync(x => x.Id == checkId);
|
|
if (info.IsNull())
|
|
return DataResult.Failed("客户对账信息不存在");
|
|
|
|
if (req.Ids.Length == 0)
|
|
return DataResult.Failed("明细业务Ids不能为空");
|
|
if ((bool)info.IsLocking)
|
|
return DataResult.Failed("客户对账信息已锁定");
|
|
|
|
var businessList = new List<CheckBillBusiness>();
|
|
var feeList = new List<CheckBillFeeRecords>();
|
|
|
|
if (tenantDb.Queryable<VW_Op_Business>().Where(x => req.Ids.Contains(x.BusinessId) && x.CustomerId != info.CustomerId).Any())
|
|
return DataResult.Failed("明细客户与对账客户不一致");
|
|
|
|
var businessIds = await tenantDb.Queryable<CheckBillBusiness>().Where(x => x.CheckId == checkId).Select(x => x.BusinessId).ToListAsync();
|
|
if (businessIds.Where(x => req.Ids.Contains(x)).Any())
|
|
return DataResult.Failed("明细业务存在已添加");
|
|
|
|
var addBusinessIds = req.Ids.AsQueryable().Except(businessIds);
|
|
|
|
try
|
|
{
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
if (addBusinessIds.Count() > 0)
|
|
{
|
|
foreach (var item in addBusinessIds)
|
|
{
|
|
businessList.Add(new CheckBillBusiness()
|
|
{
|
|
CheckId = info.Id,
|
|
BusinessId = item
|
|
});
|
|
if (!string.IsNullOrEmpty(req.QueryString))
|
|
{
|
|
//序列化查询条件
|
|
conditions = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(req.QueryString);
|
|
}
|
|
var feeRecords = await tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == item).Where(conditions).ToListAsync();
|
|
foreach (var record in feeRecords)
|
|
{
|
|
feeList.Add(new CheckBillFeeRecords()
|
|
{
|
|
CheckId = info.Id,
|
|
BusinessId = item,
|
|
FeeRecordId = record.Id,
|
|
CheckBillAmount = record.Amount,
|
|
});
|
|
//对账标识
|
|
record.IsDebit = true;
|
|
record.DebitNo = info.Id.ToString();
|
|
}
|
|
//更新费用记录
|
|
await tenantDb.Updateable(feeRecords).ExecuteCommandAsync();
|
|
}
|
|
await tenantDb.Insertable(businessList).ExecuteCommandAsync();
|
|
await tenantDb.Insertable(feeList).ExecuteCommandAsync();
|
|
await tenantDb.Ado.CommitTranAsync();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
await tenantDb.Ado.RollbackTranAsync();
|
|
throw;
|
|
}
|
|
}
|
|
return DataResult.Successed("添加成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 对账明细费用添加
|
|
/// </summary>
|
|
/// <param name="req">主表Id及明细业务费用Ids</param>
|
|
/// <returns></returns>
|
|
public async Task<DataResult> AddCheckBillFeeRecords(IdModel req)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var checkId = long.Parse(req.Id);
|
|
if (req.Id.IsNull())
|
|
return DataResult.Failed("主表Id不能为空");
|
|
|
|
var info = tenantDb.Queryable<CheckBill>().First(x => x.Id == checkId);
|
|
if (info.IsNull())
|
|
return DataResult.Failed("客户对账信息不存在");
|
|
|
|
if (req.Ids.Length == 0)
|
|
return DataResult.Failed("明细业务费用Ids不能为空");
|
|
if ((bool)info.IsLocking)
|
|
return DataResult.Failed("客户对账信息已锁定");
|
|
|
|
var feeList = new List<CheckBillFeeRecords>();
|
|
var feeIds = await tenantDb.Queryable<CheckBillFeeRecords>().Where(x => x.CheckId == checkId).Select(x => x.FeeRecordId).ToListAsync();
|
|
if (feeIds.Where(x => req.Ids.Contains(x)).Any())
|
|
return DataResult.Failed("费用明细存在已添加");
|
|
var addFeeIds = req.Ids.AsQueryable().Except(feeIds);
|
|
|
|
var businessId = await tenantDb.Queryable<FeeRecord>().Where(x => addFeeIds.Contains(x.Id)).Select(n=> n.BusinessId).FirstAsync();
|
|
|
|
if (tenantDb.Queryable<VW_Op_Business>().Where(x => x.BusinessId == businessId && x.CustomerId != info.CustomerId).Any())
|
|
return DataResult.Failed("明细客户与对账客户不一致");
|
|
|
|
var businessList = new List<CheckBillBusiness>();
|
|
if (addFeeIds.Count() > 0)
|
|
{
|
|
try
|
|
{
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
foreach (var item in addFeeIds)
|
|
{
|
|
var feeRecords = await tenantDb.Queryable<FeeRecord>().Where(x => x.Id == item).ToListAsync();
|
|
var detail = await tenantDb.Queryable<CheckBillBusiness>().Where(x => x.BusinessId == feeRecords[0].BusinessId && x.CheckId == checkId).FirstAsync();
|
|
|
|
if (detail.IsNull())
|
|
{
|
|
businessList.Add(new CheckBillBusiness()
|
|
{
|
|
CheckId = info.Id,
|
|
BusinessId = feeRecords[0].BusinessId
|
|
});
|
|
}
|
|
foreach (var record in feeRecords)
|
|
{
|
|
feeList.Add(new CheckBillFeeRecords()
|
|
{
|
|
CheckId = info.Id,
|
|
BusinessId = record.BusinessId,
|
|
FeeRecordId = record.Id,
|
|
CheckBillAmount = record.Amount,
|
|
});
|
|
//对账标识
|
|
record.IsDebit = true;
|
|
record.DebitNo = info.Id.ToString();
|
|
}
|
|
//更新费用记录
|
|
await tenantDb.Updateable(feeRecords).ExecuteCommandAsync();
|
|
}
|
|
await tenantDb.Insertable(businessList).ExecuteCommandAsync();
|
|
await tenantDb.Insertable(feeList).ExecuteCommandAsync();
|
|
await tenantDb.Ado.CommitTranAsync();
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
await tenantDb.Ado.RollbackTranAsync();
|
|
throw;
|
|
}
|
|
}
|
|
return DataResult.Successed("添加成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 锁定
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public DataResult CheckBillLocking(IdModel req)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
if (req.Ids.Length == 0)
|
|
return DataResult.Failed("业务Ids不能为空");
|
|
|
|
if (tenantDb.Queryable<CheckBill>().Where(x => req.Ids.Contains(x.Id) && x.IsLocking == true).Any())
|
|
return DataResult.Failed("存在已锁定的客户对账信息");
|
|
|
|
var list = tenantDb.Queryable<CheckBill>().Where(x => req.Ids.Contains(x.Id)).ToList();
|
|
|
|
//tenantDb.Updateable(list).SetColumns(it=>it.IsLocking == true).ExecuteCommand();
|
|
|
|
foreach (var item in list)
|
|
{
|
|
item.IsLocking = true;
|
|
}
|
|
tenantDb.Updateable(list).ExecuteCommand();
|
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 解除锁定
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public DataResult CheckBillUnLocking(IdModel req)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
if (req.Ids.Length == 0)
|
|
return DataResult.Failed("业务Ids不能为空");
|
|
|
|
if (tenantDb.Queryable<CheckBill>().Where(x => req.Ids.Contains(x.Id) && x.IsLocking == false).Any())
|
|
return DataResult.Failed("存在已解除锁定的客户对账信息");
|
|
|
|
var list = tenantDb.Queryable<CheckBill>().Where(x => req.Ids.Contains(x.Id)).ToList();
|
|
|
|
//tenantDb.Updateable(list).SetColumns(it => it.IsLocking == false).ExecuteCommand();
|
|
foreach (var item in list)
|
|
{
|
|
item.IsLocking = false;
|
|
}
|
|
tenantDb.Updateable(list).ExecuteCommand();
|
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 客户对账模板下拉列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public DataResult<List<CheckBillTemplateSelectRes>> GetCheckBillTemplateList()
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
var data = tenantDb.Queryable<CodeCheckBillTemplate>().Where(x => x.Status == StatusEnum.Enable)
|
|
.Select<CheckBillTemplateSelectRes>().ToList();
|
|
return DataResult<List<CheckBillTemplateSelectRes>>.Success(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// TODO 客户对账模板打印数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public DataResult<CheckBillTemplatePrintRes> GetCheckBillTemplatePrintInfo(string id)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var data = new CheckBillTemplatePrintRes();
|
|
var checkId = long.Parse(id);
|
|
var users = db.Queryable<SysUser>().Select(x => new { x.Id, x.UserName }).ToList();
|
|
var bill = tenantDb.Queryable<CheckBill>().Where(x => x.Id == checkId).First();
|
|
|
|
if (bill.IsNull())
|
|
return DataResult<CheckBillTemplatePrintRes>.Failed("客户对账信息不存在");
|
|
if (bill.CheckBillTemplateId == 0)
|
|
return DataResult<CheckBillTemplatePrintRes>.Failed("请选择保存客户对账模板");
|
|
|
|
var template = tenantDb.Queryable<CodeCheckBillTemplate>().Where(x => x.Id == bill.CheckBillTemplateId && x.Status == StatusEnum.Enable).First();
|
|
if (template.IsNull())
|
|
return DataResult<CheckBillTemplatePrintRes>.Failed("客户对账模板不存在或着被禁用");
|
|
|
|
var feeList = tenantDb.Queryable<CodeCheckBillTemplateFee>().Where(x => x.TemplateId == bill.CheckBillTemplateId ).ToList();
|
|
if (feeList.Count==0)
|
|
return DataResult<CheckBillTemplatePrintRes>.Failed("客户对账模板费用信息不能为空");
|
|
var sortList = tenantDb.Queryable<CodeCheckBillTemplateSort>().Where(x => x.TemplateId == bill.CheckBillTemplateId).ToList();
|
|
if (sortList.Count == 0)
|
|
return DataResult<CheckBillTemplatePrintRes>.Failed("客户对账模板排序信息不能为空");
|
|
|
|
data = tenantDb.Queryable<CheckBill>()
|
|
.Where(x => x.Id == checkId)
|
|
.Select<CheckBillTemplatePrintRes>()
|
|
.Mapper(it =>
|
|
{
|
|
var checkBillDetails = tenantDb.Queryable<VW_CheckBill_Business>().Where(x => x.CheckId == it.Id).ToList();
|
|
it.CreateByName = users.Find(x => x.Id == it.CreateBy).UserName;
|
|
it.RMBDR = checkBillDetails.Sum(x => x.RMBDR);
|
|
it.RMBCR = checkBillDetails.Sum(x => x.RMBCR);
|
|
it.USDDR = checkBillDetails.Sum(x => x.USDDR);
|
|
it.USDCR = checkBillDetails.Sum(x => x.USDCR);
|
|
it.BALRMBDR = checkBillDetails.Sum(x => x.BALRMBDR);
|
|
it.BALRMBCR = checkBillDetails.Sum(x => x.BALRMBCR);
|
|
it.BALUSDDR = checkBillDetails.Sum(x => x.BALUSDDR);
|
|
it.BALUSDCR = checkBillDetails.Sum(x => x.BALUSDCR);
|
|
}
|
|
).First();
|
|
var businessList = tenantDb.Queryable<VW_CheckBill_Business>().Where(x => x.CheckId == checkId).ToList();
|
|
|
|
var businessList1 = tenantDb.Queryable<dynamic>().AS("VW_CheckBill_Business").Where("CheckId=@id", new { CheckId = 1 }).ToList();
|
|
//foreach (var item in businessList1)
|
|
//{
|
|
// for (global::System.Int32 i = 0; i < feeList.Count; i++)
|
|
// {
|
|
// var fee = feeList[i];
|
|
// var str = fee.FeeName + "-" + fee.FeeType + "-" + fee.Currency;
|
|
|
|
// var sumFee = tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == item.BusinessId && x.FeeId == fee.FeeId).Sum(x=>x.Amount);
|
|
// item[str] = sumFee;
|
|
|
|
// //var value = db.DynamicBuilder().CreateObjectByType(type, new Dictionary<string, object>() { { "Id", 1 }, { "Name", "jack" } })
|
|
// }
|
|
// //item.CreateProperty
|
|
//}
|
|
var otherList = new List<KeyValuePair<string, decimal>>();
|
|
for (global::System.Int32 i = 0; i < feeList.Count; i++)
|
|
{
|
|
var fee = feeList[i];
|
|
var str = fee.FeeName + "-" + fee.FeeType + "-" + fee.Currency;
|
|
|
|
//var sumFee = tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == item.BusinessId && x.FeeId == fee.FeeId).Sum(x => x.Amount);
|
|
//item[str] = sumFee;
|
|
|
|
//var value = db.DynamicBuilder().CreateObjectByType(type, new Dictionary<string, object>() { { "Id", 1 }, { "Name", "jack" } })
|
|
}
|
|
|
|
|
|
return DataResult<CheckBillTemplatePrintRes>.Success(data);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|