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.

883 lines
33 KiB
C#

4 months ago
using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.ContainerManagement.Info.Dtos;
using DS.WMS.ContainerManagement.Info.Entity;
using DS.WMS.ContainerManagement.Info.Interface;
using DS.WMS.Core.Application.Dtos;
using DS.WMS.Core.Application.Entity;
using DS.WMS.Core;
4 months ago
using DS.WMS.Core.Info.Dtos;
using DS.WMS.Core.Info.Entity;
using DS.WMS.Core.Info.Interface;
using DS.WMS.Core.Invoice.Dtos;
4 months ago
using DS.WMS.Core.Op.View;
using DS.WMS.Core.Sys.Entity;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
4 months ago
using SqlSugar;
using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Op.Entity;
4 months ago
using AngleSharp.Dom;
using NPOI.Util;
using DS.WMS.Core.Sys.Method;
using DS.WMS.Core.Sys.Interface;
using DS.WMS.Core.Fee.Interface;
using DS.Module.Core.Enums;
using Masuit.Tools.Systems;
using DS.WMS.Core.TaskPlat.Dtos;
3 months ago
using DS.WMS.Core.Fee.Dtos;
using DS.WMS.Core.Fee.Method;
3 months ago
using Org.BouncyCastle.Ocsp;
4 months ago
namespace DS.WMS.ContainerManagement.Info.Method;
//<TEntity> : FeeServiceBase, ISettlementService<TEntity> where TEntity : SettlementBase, new ()
public class CM_RentInService : CMServiceBase, ICM_RentInService
4 months ago
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
4 months ago
private readonly ICommonService commonService;
readonly IFeeRecordService _feeService;
readonly ICM_State_ChangeService _Changeservice;
3 months ago
private readonly IFeeCurrencyExchangeService feeCurrencyExchangeService;
4 months ago
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public CM_RentInService(IServiceProvider serviceProvider) : base(serviceProvider)
4 months ago
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
4 months ago
commonService = _serviceProvider.GetRequiredService<ICommonService>();
_feeService = _serviceProvider.GetRequiredService<IFeeRecordService>();
_Changeservice = _serviceProvider.GetRequiredService<ICM_State_ChangeService>();
3 months ago
feeCurrencyExchangeService = _serviceProvider.GetRequiredService<IFeeCurrencyExchangeService>();
4 months ago
}
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<DataResult<List<CM_RentInRes>>> GetListByPage(PageRequest request)
4 months ago
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = tenantDb.Queryable<CM_RentIn>()
.InnerJoin<BusinessFeeStatus>((a, b) => a.Id == b.BusinessId)
//.LeftJoin<SysOrg>((a, b, c) => a.SaleOrgId == c.Id, "shippingweb8_dev.sys_org")
.LeftJoin<SysOrg>((a, b, c) => a.OrgId == c.Id, "shippingweb8_dev.sys_org")
.Select((a, b, c) => new CM_RentInRes()
{
OrgName = c.OrgName,
},
true)
4 months ago
.Where(whereList)
//.Select<CM_RentInRes>()
.ToQueryPage(request.PageCondition);
4 months ago
return data;
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
4 months ago
public async Task<DataResult> EditCM_RentIn(CM_RentInReq req)
4 months ago
{
if (req.BodyList.Count > 0)
{
if (req.BodyList.Exists(x => string.IsNullOrWhiteSpace(x.Cntrno))) {
return DataResult.Failed("保存失败!", MultiLanguageConst.CM_CntrnoNotNull);
}
//判断是否有重复的 如有则报错
bool hasDuplicates = req.BodyList.GroupBy(item => item.Cntrno).Any(group => group.Count() > 1);
if (hasDuplicates)
return DataResult.Failed("保存失败!", MultiLanguageConst.CM_CntrnoRepeat);
}
3 months ago
(ref req);
req.Ctntotal = "";
var ch = new CtnTotalHelper();
4 months ago
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Id == 0)
{
var data = req.Adapt<CM_RentIn>();
4 months ago
4 months ago
var sequence = commonService.GetSequenceNext<CM_RentIn>();
if (!sequence.Succeeded)
{
return await Task.FromResult(DataResult.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist));
}
data.Billno = sequence.Data;
if (req.BodyList.Count > 0)
{
//var ctnList = await tenantDb.Queryable<CM_RentIn_Detail>().Where(x => x.pid == req.Id.ToString()).ToListAsync();
foreach (var item in req.BodyList)
{
ch.Add(item.Ctnall);
}
}
data.Ctntotal = ch.GetStr();
4 months ago
//var entity = tenantDb.Insertable(data).ExecuteReturnEntity();
var entity = await tenantDb.Insertable(data).ExecuteReturnEntityAsync();
//(typeof(BusinessType)).GetDescriptionAndValue().Select(x => new { Id = x.Value, Name = x.Key }).Where(x=>x.Id).ToList();
InitBusiness(entity.Id);
4 months ago
if (req.BodyList.Count > 0)
{
//var ctnList = await tenantDb.Queryable<CM_RentIn_Detail>().Where(x => x.pid == req.Id.ToString()).ToListAsync();
foreach (var item in req.BodyList)
{
item.Id = 0;
item.Pid = entity.Id;
var newdetail = item.Adapt<CM_RentIn_Detail>();
//newdetail.BillState = data.BillState;
4 months ago
await tenantDb.Insertable(newdetail).ExecuteCommandAsync();
}
}
//return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
return await Task.FromResult(DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess));
4 months ago
}
else
{
4 months ago
var info = await tenantDb.Queryable<CM_RentIn>().Where(x => x.Id == req.Id).FirstAsync();
4 months ago
info = req.Adapt(info);
if (req.BodyList.Count > 0)
{
//var ctnList = await tenantDb.Queryable<CM_RentIn_Detail>().Where(x => x.pid == req.Id.ToString()).ToListAsync();
foreach (var item in req.BodyList)
{
ch.Add(item.Ctnall);
}
}
info.Ctntotal = ch.GetStr();
4 months ago
await tenantDb.Updateable(info).ExecuteCommandAsync();
if (req.BodyList.Count > 0)
{
var _BodyList = await tenantDb.Queryable<CM_RentIn_Detail>().Where(x => x.Pid == req.Id).ToListAsync();
3 months ago
4 months ago
foreach (var item in req.BodyList)
{
if (item.Id == 0)
{
3 months ago
if (_BodyList.Exists(x => x.Cntrno == item.Cntrno)) {
//防止箱号重复
continue;
}
4 months ago
//item.Id = 0;
3 months ago
//item.Pid = info.Id;
//item.Billno= info.Billno;
3 months ago
//item.RentDirectId = info.RentDirectId;
//item.RentTypeId = info.RentTypeId;
//item.BillState = item.BillState;
4 months ago
var newdetail = item.Adapt<CM_RentIn_Detail>();
await tenantDb.Insertable(newdetail).ExecuteCommandAsync();
}
else
{
3 months ago
if (!_BodyList.Exists(x => x.Id == item.Id))
{
continue;
}
4 months ago
var updrec = _BodyList.First(x => x.Id == item.Id);
//item.Billno = info.Billno;
3 months ago
//item.RentDirectId = info.RentDirectId;
//item.RentTypeId = info.RentTypeId;
//item.Pid = info.Id;
//item.BillState = item.BillState;
4 months ago
updrec = item.Adapt(updrec);
await tenantDb.Updateable(updrec).ExecuteCommandAsync();
}
}
}
return await Task.FromResult(DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess));
4 months ago
}
}
3 months ago
private void (ref CM_RentInReq req)
{
if (req.BodyList.Count > 0)
{
foreach (var item in req.BodyList)
{
item.Pid = req.Id;
if (req.Bsdate != null) {
if (item.Bsdate == null) { item.Bsdate = req.Bsdate; }
}
if (req.Bsdate != null)
{
if (item.FeeStartDate == null) { item.FeeStartDate = req.Bsdate; }
}
if (req.OldContainerOwnerId != null)
{
if (item.OldContainerOwnerId == null || item.OldContainerOwnerId == 0)
{
item.OldContainerOwnerId = req.OldContainerOwnerId;
item.OldContainerOwner = req.OldContainerOwner;
3 months ago
}
}
item.RentDirectId = req.RentDirectId;
item.RentTypeId = req.RentTypeId;
if (string.IsNullOrWhiteSpace(item.Currency))
{
item.Currency = "USD";
}
if (item.DailyRate == null)
{
item.DailyRate = 0M;
}
if (item.PickupFee == null)
{
item.PickupFee = 0M;
}
if (item.DropoffFee == null)
{
item.DropoffFee = 0M;
}
}
}
}
4 months ago
/// <summary>
/// 详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult<CM_RentInRes> GetCM_RentIn(string id)
4 months ago
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var data = tenantDb.Queryable<CM_RentIn>()
4 months ago
.Where(a => a.Id == long.Parse(id))
.Select<CM_RentInRes>()
4 months ago
.First();
return DataResult<CM_RentInRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
}
#region 删除
/// <summary>
/// 删除
/// </summary>
/// <param name="ids">费用记录ID</param>
/// <returns></returns>
public async Task<DataResult> DeleteCM_RentInAsync(params long[] ids)
{
foreach (var _id in ids) {
if (await IsLockedAsync(_id, BusinessType.CM_RentIn))
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.FeeLocked));
}
4 months ago
//如果包含费用 不允许删除
var feeCount = await TenantDb.Queryable<FeeRecord>().Where(x => ids.Contains(x.BusinessId)).CountAsync();
if (feeCount > 0) {
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.CM_FeeExist));
}
int result = await TenantDb.Deleteable<CM_RentIn>(x => ids.Contains(x.Id)).ExecuteCommandAsync();
4 months ago
if (result > 0) {
//删除所有明细
await TenantDb.Deleteable<CM_RentIn_Detail>(x => ids.Contains(x.Pid)).ExecuteCommandAsync();
}
//await WriteBackStatusAsync(model.BusinessId, model.BusinessType);
return result > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
4 months ago
}
#endregion
4 months ago
/// <summary>
/// 租箱租入_确认
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<DataResult> CM_RentIn_Confirm(string id, params long[] ids)
4 months ago
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var data = tenantDb.Queryable<CM_RentIn>()
.Where(a => a.Id == long.Parse(id))
//.Select<CM_RentInRes>()
4 months ago
.First();
var body = tenantDb.Queryable<CM_RentIn_Detail>().Where(a => a.Pid == data.Id).ToList();
//20240808 首先判断该箱号能否执行确认
//if (!string.IsNullOrWhiteSpace(data.BillState))
//{
// return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
//}
var = new CtnTotalHelper();
var = new CtnTotalHelper();
//var 已还箱 = new CtnTotalHelper();
//var 未还箱 = new CtnTotalHelper();
if (body.Count > 0)
{
//var ctnList = await tenantDb.Queryable<CM_RentIn_Detail>().Where(x => x.pid == req.Id.ToString()).ToListAsync();
foreach (var item in body) {
if (item.PickupDate == null)
{
.Add(item.Ctnall);
}
if (item.PickupDate != null)
{
.Add(item.Ctnall);
}
//if (item.PickupDate != null && item.DropoffDate == null)
//{
// 未还箱.Add(item.Ctnall);
//}
//if (item.PickupDate != null && item.DropoffDate != null)
//{
// 已还箱.Add(item.Ctnall);
//}
}
}
data.PickupCtntotal = .GetStr();
data.PickupRemainCtntotal = .GetStr();
//data.DropoffCtntotal = 已还箱.GetStr();
//data.DropoffRemainCtntotal = 未还箱.GetStr();
data.BillState = "Confirm";
//data.IsBusinessLocking = true;
var entity = await tenantDb.Updateable(data).ExecuteCommandAsync();
//20240812 生成箱状态变动
//如果是租入 生成租入变动
3 months ago
if (data.RentDirectId == CMRentDirectEnum.)
{
foreach (var detail in body)
{
3 months ago
if (detail.PickupDate == null)
{
continue;
}
var changerec = new CM_State_ChangeReq();
changerec.Cntrno = detail.Cntrno;
changerec.CtnCode = detail.CtnCode;
3 months ago
changerec.Ctnall = detail.Ctnall;
changerec.UsedState = "USED";
changerec.CtnOwnerId = data.OldContainerOwnerId;
3 months ago
changerec.CtnOwner = data.OldContainerOwner;
//默认长租租入
changerec.CtnSourceId = CM_CtnSourceEnum.;
3 months ago
if (data.RentTypeId == CMRentTypeEnum. || data.RentTypeId == CMRentTypeEnum.)
{
changerec.CtnSourceId = CM_CtnSourceEnum.;
}
3 months ago
changerec.CtnBizStateId = CM_CtnBizStateEnum.;
changerec.ChangeSourceId = CMChangeSourceEnum.;
changerec.ChangeSourceDetailId = data.Id;
3 months ago
changerec.CtnFlowStateId = null;
changerec.CtnStateId = CMCtnStateEnum.AV;
changerec.CtnBreakStateId = CMCtnBreakStateEnum.AV;
changerec.IsHeavy = false;
changerec.Billno = detail.Mblno;
changerec.IsOnlineId = CM_IsOnlineEnum.线;
if (detail.PickupPortid != null)
{
changerec.Portid = detail.PickupPortid;
changerec.PortCode = detail.PickupPortCode;
changerec.Port = detail.PickupPort;
}
changerec.ChangeTime = data.Bsdate;
changerec.CtnFlowStateId = null;
//如果没有填写提箱日期 则变动来源id设为租箱主单 变动日期设为业务日期
//如果填写了提箱日期 则变动来源id设为租箱主单 变动日期设为提箱日期
3 months ago
if (detail.PickupDate != null)
{
changerec.CtnStateId = CMCtnStateEnum.AV;
changerec.ChangeSourceDetailId = detail.Id;
changerec.CtnFlowStateId = CMCtnFlowStateEnum.;
changerec.ChangeTime = detail.PickupDate;
changerec.IsOnlineId = CM_IsOnlineEnum.线;
}
3 months ago
if (changerec.ChangeTime == null) changerec.ChangeTime = data.Bsdate;
//await TenantDb.Insertable(changerec).ExecuteReturnEntityAsync();
//await _Changeservice.UpdateCM_CurrentStateAsync(changerec);
await _Changeservice.AddCM_State_ChangeAsync(changerec);
}
}
//如果是退租 生成退租变动 同时找到相应的租入明细 向其中更新还箱日期
if (data.RentDirectId == CMRentDirectEnum.退)
{
var RentInDetailIdList = body.Select(s => s.RentDetailId).ToList();
3 months ago
var RentInDetailList = tenantDb.Queryable<CM_RentIn_Detail>().Where(x => RentInDetailIdList.Contains(x.Id)).ToList();
foreach (var detail in body)
{
3 months ago
if (detail.DropoffDate == null)
{
continue;
}
var changerec = new CM_State_ChangeReq();
changerec.Cntrno = detail.Cntrno;
changerec.CtnCode = detail.CtnCode;
changerec.Ctnall = detail.Ctnall;
changerec.UsedState = "USED";
//changerec.CtnOwnerId = data.OldContainerOwnerId;
//changerec.CtnOwner = data.OldContainerOwner;
//默认长租租入
//changerec.CtnSourceId = CM_CtnSourceEnum.长租租入;
//if (data.RentTypeId == CMRentTypeEnum.短租 || data.RentTypeId == CMRentTypeEnum.单程)
//{
// changerec.CtnSourceId = CM_CtnSourceEnum.短租租入;
//}
changerec.CtnBizStateId = CM_CtnBizStateEnum.退;
changerec.ChangeSourceId = CMChangeSourceEnum.;
changerec.ChangeSourceDetailId = data.Id;
changerec.CtnStateId = CMCtnStateEnum.POS;
changerec.CtnBreakStateId = CMCtnBreakStateEnum.AV;
changerec.IsHeavy = false;
//changerec.Billno = detail.Mblno;
//changerec.Depot=detail.depot
changerec.ChangeTime = DateTime.Now;
if (detail.DropoffPortid != null)
{
changerec.Portid = detail.DropoffPortid;
changerec.PortCode = detail.DropoffPortCode;
changerec.Port = detail.DropoffPort;
RentInDetailList.First(x => x.Id == detail.RentDetailId).DropoffPortid = detail.DropoffPortid;
RentInDetailList.First(x => x.Id == detail.RentDetailId).DropoffPortCode = detail.DropoffPortCode;
RentInDetailList.First(x => x.Id == detail.RentDetailId).DropoffPort = detail.DropoffPort;
}
//if (detail.DropoffDate != null) {
// changerec.ChangeTime = detail.DropoffDate;
//}
//如果没有填写提箱日期 则变动来源id设为租箱主单 变动日期设为业务日期
//如果填写了提箱日期 则变动来源id设为租箱主单 变动日期设为提箱日期
changerec.IsOnlineId = CM_IsOnlineEnum.线;
if (detail.DropoffDate != null)
{
changerec.CtnStateId = CMCtnStateEnum.AV;
changerec.ChangeSourceDetailId = detail.Id;
changerec.CtnFlowStateId = CMCtnFlowStateEnum.;
changerec.ChangeTime = detail.DropoffDate;
changerec.IsOnlineId = CM_IsOnlineEnum.线;
RentInDetailList.First(x => x.Id == detail.RentDetailId).DropoffDate = detail.DropoffDate;
}
await _Changeservice.AddCM_State_ChangeAsync(changerec);
//20240826 向原租入明细中写入提箱相关信息
await tenantDb.Updateable(RentInDetailList.First(x => x.Id == detail.RentDetailId)).ExecuteCommandAsync();
}
}
return await Task.FromResult(DataResult.Successed("添加成功!", id, MultiLanguageConst.DataCreateSuccess));
}
3 months ago
public async Task<DataResult> CM_RentIn_Confirm(params long[] ids)
{
3 months ago
var _r = DataResult.Successed("添加成功!", null, MultiLanguageConst.DataCreateSuccess);
3 months ago
foreach (var id in ids)
{
_r = await CM_RentIn_Confirm(id.ToString(), null);
}
return _r;
4 months ago
}
/// <summary>
/// 租箱租入_取消
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
3 months ago
public async Task<DataResult> CM_RentIn_Cancel(string id, params long[] ids)
4 months ago
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var data = tenantDb.Queryable<CM_RentIn>()
.Where(a => a.Id == long.Parse(id))
//.Select<CM_RentInRes>()
4 months ago
.First();
3 months ago
if (data.BillState != "Confirm")
{
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
data.BillState = "";
//data.IsBusinessLocking = false;
var entity = await tenantDb.Updateable(data).ExecuteCommandAsync();
return await Task.FromResult(DataResult.Successed("取消成功!", id, MultiLanguageConst.DataCreateSuccess));
4 months ago
}
public async Task<DataResult> CM_RentIn_Cancel(params long[] ids)
{
var _r = DataResult.Successed("取消成功!", null, MultiLanguageConst.DataCreateSuccess);
foreach (var id in ids)
{
_r = await CM_RentIn_Cancel(id.ToString(), null);
}
return _r;
}
/// <summary>
/// 租箱租入_生成费用
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<DataResult> CM_RentIn_MakeFee(string id)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var data = tenantDb.Queryable<CM_RentIn>()
.Where(a => a.Id == long.Parse(id))
.Select<CM_RentInRes>()
.First();
if (data.BillState != "Confirm")
{
return await Task.FromResult(DataResult.Failed("添加失败!", MultiLanguageConst.CM_CanNotMakeFee));
}
else {
3 months ago
//var newFee = new FeeRecord();
//newFee.Id = 0;
//newFee.FeeType = FeeType.Payable;
//newFee.FeeName = "提箱费";
//newFee.TaxUnitPrice = 10;
//newFee.Amount = 10;
//newFee.TaxRate = 0;
//newFee.Quantity = 1;
//var feeDetail = new List<FeeRecord>();
//feeDetail.Add(newFee);
3 months ago
//return await _feeService.SaveAsync(feeDetail);
3 months ago
//租入生成提箱费
//退租生成还箱费
3 months ago
if (data.RentDirectId == CMRentDirectEnum.) {
//根据明细生成费用
//var head = TenantDb.Queryable<CM_RentIn_Detail>().Where(x => x.Pid == data.Id).FirstAsync();
var feecode = await tenantDb.Queryable<FeeCode>().FirstAsync(x => x.Name == "提箱费");
if (feecode == null)
{
return await Task.FromResult(DataResult.Failed(MultiLanguageConst.NoFeeName));
}
var body = await TenantDb.Queryable<CM_RentIn_Detail>().Where(x => x.Pid == data.Id).ToListAsync();
//按箱型和币别和单价分组
var groupList = new List<CM_RentIn_Detail>();
foreach (var item in body)
{
if (groupList.Exists(x => x.Ctnall == item.Ctnall && x.Currency == item.Currency && x.PickupFee== item.PickupFee))
{
groupList.First(x => x.Ctnall == item.Ctnall && x.Currency == item.Currency ).DailyRate += item.PickupFee;
}
else
{
item.DailyRate = item.PickupFee;//用DailyRate承载总金额
groupList.Add(item);
}
}
var savefeeList = new List<FeeRecord>();
if (groupList != null && groupList.Count > 0)
{
foreach (var groupdetail in groupList)
{
if (groupdetail.PickupFee <= 0) continue;
var newFee = new FeeRecord();
newFee.Id = 0;
//newFee.FeeName = "提箱费";
newFee.FeeId= feecode.Id;
newFee.FeeName = feecode.Name;
newFee.TaxRate = feecode.TaxRate==null?0: (decimal)feecode.TaxRate;
newFee.BusinessType = BusinessType.CM_RentIn;
newFee.BusinessId = data.Id;
newFee.CustomerId= (long)data.OldContainerOwnerId;
newFee.CustomerName = data.OldContainerOwner;
//newFee.Amount = (decimal)groupdetail.FeeType == FeeType.Receivable ? x.Amount : -x.Amount);
newFee.FeeType = FeeType.Payable;
newFee.Amount = (decimal)groupdetail.DailyRate;
newFee.Currency = groupdetail.Currency;
newFee.TaxUnitPrice = (decimal)groupdetail.PickupFee;
newFee.Quantity = (decimal)groupdetail.DailyRate/ (decimal)groupdetail.PickupFee;
newFee.Unit = groupdetail.CtnCode;
newFee.UnitText = groupdetail.Ctnall;
3 months ago
var feecurrencyinfo = await feeCurrencyExchangeService.GetExchangeRateAsync(new ExchangeRate
3 months ago
{
CurrencyFrom = newFee.Currency,
CurrencyTo = "",
FeeType = newFee.FeeType
});
newFee.ExchangeRate = feecurrencyinfo.Data.Rate;
newFee.SetTax();
savefeeList.Add(newFee);
}
}
if (savefeeList != null && savefeeList.Count > 0)
{
await TenantDb.Insertable(savefeeList).ExecuteCommandAsync();
}
}
if (data.RentDirectId == CMRentDirectEnum.退)
{
var feecode = await tenantDb.Queryable<FeeCode>().FirstAsync(x => x.Name == "还箱费");
if (feecode == null)
{
return await Task.FromResult(DataResult.Failed(MultiLanguageConst.NoFeeName));
}
//根据明细生成费用
var body = await TenantDb.Queryable<CM_RentIn_Detail>().Where(x => x.Pid == data.Id).ToListAsync();
//按箱型和币别和单价分组
var groupList = new List<CM_RentIn_Detail>();
foreach (var item in body)
{
if (groupList.Exists(x => x.Ctnall == item.Ctnall && x.Currency == item.Currency && x.DropoffFee == item.DropoffFee))
{
groupList.First(x => x.Ctnall == item.Ctnall && x.Currency == item.Currency).DailyRate += item.DropoffFee;
}
else
{
item.DailyRate = item.DropoffFee;//用DailyRate承载总金额
groupList.Add(item);
}
}
var savefeeList = new List<FeeRecord>();
if (groupList != null && groupList.Count > 0)
{
foreach (var groupdetail in groupList)
{
if (groupdetail.DropoffFee <= 0) continue;
var newFee = new FeeRecord();
newFee.Id = 0;
//newFee.FeeName = "还箱费";
newFee.FeeId = feecode.Id;
newFee.FeeName = feecode.Name;
newFee.TaxRate = feecode.TaxRate == null ? 0 : (decimal)feecode.TaxRate;
newFee.BusinessType = BusinessType.CM_CustFeeDui;
newFee.BusinessId = data.Id;
//newFee.Amount = (decimal)groupdetail.FeeType == FeeType.Receivable ? x.Amount : -x.Amount);
newFee.CustomerId = (long)data.OldContainerOwnerId;
newFee.CustomerName = data.OldContainerOwner;
newFee.FeeType = FeeType.Payable;
newFee.Amount = (decimal)groupdetail.DailyRate;
newFee.Currency = groupdetail.Currency;
newFee.TaxUnitPrice = (decimal)groupdetail.DropoffFee;
newFee.Quantity = (decimal)groupdetail.DailyRate / (decimal)groupdetail.DropoffFee;
newFee.Unit = groupdetail.CtnCode;
var feecurrencyinfo = await feeCurrencyExchangeService.GetExchangeRateAsync(new ExchangeRate
3 months ago
{
CurrencyFrom = newFee.Currency,
CurrencyTo = "",
FeeType = newFee.FeeType
});
newFee.ExchangeRate = feecurrencyinfo.Data.Rate;
newFee.SetTax();
savefeeList.Add(newFee);
}
}
if (savefeeList != null && savefeeList.Count > 0)
{
await TenantDb.Insertable(savefeeList).ExecuteCommandAsync();
}
}
}
3 months ago
return await Task.FromResult(DataResult.Successed("添加成功!", data.Id, MultiLanguageConst.DataCreateSuccess));
}
/// <summary>
/// 租箱租入明细视图_列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<DataResult<List<VW_CM_NeedEndLease_DetailRes>>> CM_RentIn_Detail_View(PageRequest request)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = tenantDb.Queryable<VW_CM_NeedEndLease_Detail>()
.Where(whereList)
.Select<VW_CM_NeedEndLease_DetailRes>().ToQueryPage(request.PageCondition);
return data;
}
/// <summary>
/// 租箱租入退租_添加箱
/// </summary>
/// <param name="ids">租入明细ID</param>
/// <returns></returns>
public async Task<DataResult> CM_RentIn_AddCtn(long id,params long[] ids)
{
//foreach (var _id in ids)
//{
if (await IsLockedAsync(id, BusinessType.CM_RentIn))
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.FeeLocked));
//}
//
var head = TenantDb.Queryable<CM_RentIn>().Where(a => a.Id == id).First();
var CurrentDetailList = TenantDb.Queryable<CM_RentIn_Detail>()
.Where(a => a.Pid == id).ToList();
var OnAddDetail = TenantDb.Queryable<CM_RentIn_Detail>()
.Where(a => ids.Contains(a.Id)).ToList();
var addList = new List<CM_RentIn_Detail>();
if (OnAddDetail != null && OnAddDetail.Count > 0)
{
foreach (var addrec in OnAddDetail) {
if (CurrentDetailList.Exists(x => x.Cntrno == addrec.Cntrno))
{
//箱号已存在 就不添加
}
else {
var newrec = new CM_RentIn_Detail();
newrec = addrec.Adapt<CM_RentIn_Detail>();
newrec.Id = 0;
newrec.Pid = id;
newrec.RentDirectId = CMRentDirectEnum.退;
newrec.DropoffDate = head.Bsdate;
newrec.RentDetailId = addrec.Id;//
addList.Add(newrec);
}
}
if (addList != null && addList.Count > 0) {
await TenantDb.Insertable(addList).ExecuteCommandAsync();
return DataResult.Successed("添加成功!", id, MultiLanguageConst.DataCreateSuccess);
}
else {
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
}
else {
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
//await WriteBackStatusAsync(model.BusinessId, model.BusinessType);
//return result > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
4 months ago
}