|
|
|
@ -21,6 +21,7 @@ using DS.WMS.Core.Sys.Method;
|
|
|
|
|
using LanguageExt.Common;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Spire.Xls;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Check.Method
|
|
|
|
@ -280,7 +281,7 @@ namespace DS.WMS.Core.Check.Method
|
|
|
|
|
CheckId = entity.Id,
|
|
|
|
|
BusinessId = item
|
|
|
|
|
});
|
|
|
|
|
var feeRecords = tenantDb.Queryable<FeeRecord>().Where(x => x.Id == item).ToList();
|
|
|
|
|
var feeRecords = tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == item).ToList();
|
|
|
|
|
foreach (var record in feeRecords)
|
|
|
|
|
{
|
|
|
|
|
feeList.Add(new CheckBillFeeRecords()
|
|
|
|
@ -313,45 +314,45 @@ namespace DS.WMS.Core.Check.Method
|
|
|
|
|
|
|
|
|
|
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.Id == 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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//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);
|
|
|
|
|
}
|
|
|
|
@ -513,64 +514,154 @@ namespace DS.WMS.Core.Check.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req">主表Id及明细业务Ids</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult AddCheckBillDetail(IdModel req)
|
|
|
|
|
public async Task<DataResult> AddCheckBillDetail(AddCheckBillDetailReq req)
|
|
|
|
|
{
|
|
|
|
|
var conditions = new List<IConditionalModel>();
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var checkId = long.Parse(req.Id);
|
|
|
|
|
if (req.Id.IsNull())
|
|
|
|
|
return DataResult.Failed("主表Id不能为空");
|
|
|
|
|
var checkId = req.Id;
|
|
|
|
|
if (checkId == 0)
|
|
|
|
|
{
|
|
|
|
|
if (req.Ids.Length == 0)
|
|
|
|
|
return DataResult.Failed("明细业务Ids不能为空");
|
|
|
|
|
|
|
|
|
|
var info = tenantDb.Queryable<CheckBill>().First(x => x.Id == checkId);
|
|
|
|
|
if (info.IsNull())
|
|
|
|
|
return DataResult.Failed("客户对账信息不存在");
|
|
|
|
|
var first = await tenantDb.Queryable<VW_Op_Business>().Where(x => x.BusinessId == req.Ids[0]).FirstAsync();
|
|
|
|
|
|
|
|
|
|
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 != first.CustomerId).Any())
|
|
|
|
|
return DataResult.Failed("明细客户不一致");
|
|
|
|
|
|
|
|
|
|
if (tenantDb.Queryable<VW_Op_Business>().Where(x => req.Ids.Contains(x.BusinessId) && x.CustomerId!= info.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 businessIds = tenantDb.Queryable<CheckBillBusiness>().Where(x => x.CheckId == checkId).Select(x => x.BusinessId).ToList();
|
|
|
|
|
if (businessIds.Where(x=> req.Ids.Contains(x)).Any())
|
|
|
|
|
return DataResult.Failed("明细业务存在已添加");
|
|
|
|
|
var businessList = new List<CheckBillBusiness>();
|
|
|
|
|
var feeList = new List<CheckBillFeeRecords>();
|
|
|
|
|
|
|
|
|
|
var addBusinessIds = req.Ids.AsQueryable().Except(businessIds);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (addBusinessIds.Count() > 0)
|
|
|
|
|
}
|
|
|
|
|
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("明细客户与对账客户不一致");
|
|
|
|
|
|
|
|
|
|
foreach (var item in addBusinessIds)
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
|
|
|
if (addBusinessIds.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
feeList.Add(new CheckBillFeeRecords()
|
|
|
|
|
foreach (var item in addBusinessIds)
|
|
|
|
|
{
|
|
|
|
|
CheckId = info.Id,
|
|
|
|
|
BusinessId = item,
|
|
|
|
|
FeeRecordId = record.Id,
|
|
|
|
|
CheckBillAmount = record.Amount,
|
|
|
|
|
});
|
|
|
|
|
//对账标识
|
|
|
|
|
record.IsDebit = true;
|
|
|
|
|
record.DebitNo = info.Id.ToString();
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
//更新费用记录
|
|
|
|
|
tenantDb.Updateable(feeRecords).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
tenantDb.Insertable(businessList).ExecuteCommand();
|
|
|
|
|
tenantDb.Insertable(feeList).ExecuteCommand();
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.Ado.RollbackTranAsync();
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return DataResult.Successed("添加成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
}
|
|
|
|
@ -581,7 +672,7 @@ namespace DS.WMS.Core.Check.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req">主表Id及明细业务费用Ids</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult AddCheckBillFeeRecords(IdModel req)
|
|
|
|
|
public async Task<DataResult> AddCheckBillFeeRecords(IdModel req)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var checkId = long.Parse(req.Id);
|
|
|
|
@ -598,36 +689,56 @@ namespace DS.WMS.Core.Check.Method
|
|
|
|
|
return DataResult.Failed("客户对账信息已锁定");
|
|
|
|
|
|
|
|
|
|
var feeList = new List<CheckBillFeeRecords>();
|
|
|
|
|
var feeIds = tenantDb.Queryable<CheckBillFeeRecords>().Where(x => x.CheckId == checkId).Select(x => x.FeeRecordId).ToList();
|
|
|
|
|
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 businessList = new List<CheckBillBusiness>();
|
|
|
|
|
if (addFeeIds.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
foreach (var item in addFeeIds)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var feeRecords = tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == item).ToList();
|
|
|
|
|
foreach (var record in feeRecords)
|
|
|
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
|
|
|
foreach (var item in addFeeIds)
|
|
|
|
|
{
|
|
|
|
|
feeList.Add(new CheckBillFeeRecords()
|
|
|
|
|
var feeRecords = await tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == item).ToListAsync();
|
|
|
|
|
var detail = await tenantDb.Queryable<CheckBillBusiness>().Where(x => x.BusinessId == item && x.CheckId == checkId).FirstAsync();
|
|
|
|
|
if (detail.IsNull())
|
|
|
|
|
{
|
|
|
|
|
CheckId = info.Id,
|
|
|
|
|
BusinessId = record.BusinessId,
|
|
|
|
|
FeeRecordId = record.Id,
|
|
|
|
|
CheckBillAmount = record.Amount,
|
|
|
|
|
});
|
|
|
|
|
//对账标识
|
|
|
|
|
record.IsDebit = true;
|
|
|
|
|
record.DebitNo = info.Id.ToString();
|
|
|
|
|
businessList.Add(new CheckBillBusiness()
|
|
|
|
|
{
|
|
|
|
|
CheckId = info.Id,
|
|
|
|
|
BusinessId = item
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
//更新费用记录
|
|
|
|
|
tenantDb.Updateable(feeRecords).ExecuteCommand();
|
|
|
|
|
await tenantDb.Insertable(businessList).ExecuteCommandAsync();
|
|
|
|
|
await tenantDb.Insertable(feeList).ExecuteCommandAsync();
|
|
|
|
|
await tenantDb.Ado.CommitTranAsync();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.Ado.RollbackTranAsync();
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
tenantDb.Insertable(feeList).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
return DataResult.Successed("添加成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
}
|
|
|
|
|