|
|
|
@ -75,7 +75,14 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
var tids = list.Select(x => x.Id);
|
|
|
|
|
var orders = await TenantDb.Queryable<SeaExport>().Where(x => SqlFunc.DateIsSame(x.ETD, etd) &&
|
|
|
|
|
SqlFunc.Subqueryable<FeeCustTemplateRecord>().Where(y => y.BusinessId == x.Id && y.BusinessType == BusinessType.OceanShippingExport && tids.Contains(y.TemplateId)).NotAny())
|
|
|
|
|
.Select<SeaExportRes>().ToListAsync();
|
|
|
|
|
.Select(x => new SeaExportRes
|
|
|
|
|
{
|
|
|
|
|
CtnInfo = SqlFunc.Subqueryable<OpCtn>().Where(y => y.BSNO == x.Id.ToString()).ToList(y => new OpCtnRes
|
|
|
|
|
{
|
|
|
|
|
Ctn = y.Ctn,
|
|
|
|
|
CtnNum = SqlFunc.IsNull(y.CtnNum.Value, 0)
|
|
|
|
|
})
|
|
|
|
|
}, true).ToListAsync();
|
|
|
|
|
if (orders.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
@ -83,23 +90,25 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
await TenantDb.Ado.BeginTranAsync();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var localCurrecy = await Db.Queryable<SysOrg>().Where(x => x.Id == User.OrgId).Select(x => x.LocalCurrency).FirstAsync();
|
|
|
|
|
|
|
|
|
|
foreach (var order in orders)
|
|
|
|
|
{
|
|
|
|
|
var custList = list.Where(x => x.CustomerId == order.CustomerId).OrderBy(x => x.Priority);
|
|
|
|
|
foreach (var template in custList) //遍历客户费用模板,查找匹配项
|
|
|
|
|
{
|
|
|
|
|
var fees = await CreateFeesIfMatchAsync(order, template);
|
|
|
|
|
var fees = await CreateFeesIfMatchAsync(order, template, localCurrecy);
|
|
|
|
|
if (fees != null)
|
|
|
|
|
{
|
|
|
|
|
feeList.AddRange(fees);
|
|
|
|
|
|
|
|
|
|
var record = new FeeCustTemplateRecord
|
|
|
|
|
{
|
|
|
|
|
BusinessId = order.CustomerId,
|
|
|
|
|
BusinessId = order.Id,
|
|
|
|
|
BusinessType = BusinessType.OceanShippingExport,
|
|
|
|
|
CreateBy = long.Parse(User.UserId),
|
|
|
|
|
CreateTime = dt,
|
|
|
|
|
FeeCategoryId = template.FeeCategoryId,
|
|
|
|
|
FeeCategoryId = string.IsNullOrEmpty(template.FeeCategoryId) ? null : template.FeeCategoryId,
|
|
|
|
|
FeeType = template.FeeType,
|
|
|
|
|
TemplateId = template.Id
|
|
|
|
|
};
|
|
|
|
@ -113,18 +122,18 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
var sharedList = list.Where(x => x.IsShared).OrderBy(x => x.Priority).ToList();
|
|
|
|
|
foreach (var template in sharedList)
|
|
|
|
|
{
|
|
|
|
|
var fees = await CreateFeesIfMatchAsync(order, template);
|
|
|
|
|
var fees = await CreateFeesIfMatchAsync(order, template, localCurrecy);
|
|
|
|
|
if (fees != null)
|
|
|
|
|
{
|
|
|
|
|
feeList.AddRange(fees);
|
|
|
|
|
|
|
|
|
|
var record = new FeeCustTemplateRecord
|
|
|
|
|
{
|
|
|
|
|
BusinessId = order.CustomerId,
|
|
|
|
|
BusinessId = order.Id,
|
|
|
|
|
BusinessType = BusinessType.OceanShippingExport,
|
|
|
|
|
CreateBy = long.Parse(User.UserId),
|
|
|
|
|
CreateTime = dt,
|
|
|
|
|
FeeCategoryId = template.FeeCategoryId,
|
|
|
|
|
FeeCategoryId = string.IsNullOrEmpty(template.FeeCategoryId) ? null : template.FeeCategoryId,
|
|
|
|
|
FeeType = template.FeeType,
|
|
|
|
|
TemplateId = template.Id
|
|
|
|
|
};
|
|
|
|
@ -157,7 +166,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<List<FeeRecord>?> CreateFeesIfMatchAsync(SeaExportRes order, FeeCustTemplate template)
|
|
|
|
|
private async Task<List<FeeRecord>?> CreateFeesIfMatchAsync(SeaExportRes order, FeeCustTemplate template, string localCurrecy)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(template.POLCode) && template.POLCode != order.LoadPortCode)
|
|
|
|
|
return null;
|
|
|
|
@ -165,7 +174,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
if (!string.IsNullOrEmpty(template.PODCode) && template.PODCode != order.DischargePortCode)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(template.MBLFrtCode) && template.MBLFrtCode != order.MBLFrtCode)
|
|
|
|
|
if (!string.IsNullOrEmpty(template.MBLFrtCode) && template.MBLFrtCode != order.MBLFrt)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
if (template.LaneId.HasValue && template.LaneId != order.LaneId)
|
|
|
|
@ -191,38 +200,62 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
x.FeeType == template.FeeType && x.FeeCategoryId == template.FeeCategoryId))
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var details = await TenantDb.Queryable<FeeCustTemplateDetail>().Where(y => y.TemplateId == template.Id)
|
|
|
|
|
.Select(x => new FeeRecord
|
|
|
|
|
var templateDetails = await TenantDb.Queryable<FeeCustTemplateDetail>().Where(y => y.TemplateId == template.Id).ToListAsync();
|
|
|
|
|
var groups = templateDetails.GroupBy(x => new
|
|
|
|
|
{
|
|
|
|
|
x.FeeId,
|
|
|
|
|
x.Unit
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
List<FeeRecord> fees = new(groups.Count);
|
|
|
|
|
foreach (var g in groups)
|
|
|
|
|
{
|
|
|
|
|
FeeCustTemplateDetail? detail = null;
|
|
|
|
|
int qty = 0;
|
|
|
|
|
if (string.Equals(g.Key.Unit, "P", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
detail = g.FirstOrDefault()!;
|
|
|
|
|
qty = detail.IsCtn ? 0 : 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var ctn = order.CtnInfo?.Find(x => x.Ctn == g.Key.Unit);
|
|
|
|
|
if (ctn == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
detail = g.FirstOrDefault(x => x.Unit == ctn.Ctn);
|
|
|
|
|
qty = ctn.CtnNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var fee = new FeeRecord
|
|
|
|
|
{
|
|
|
|
|
BusinessId = order.Id,
|
|
|
|
|
BusinessType = BusinessType.OceanShippingExport,
|
|
|
|
|
FeeType = template.FeeType,
|
|
|
|
|
FeeId = x.FeeId,
|
|
|
|
|
FeeCode = x.FeeCode,
|
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
|
CustomerId = x.CustomerId,
|
|
|
|
|
CustomerName = x.CustomerName,
|
|
|
|
|
CustomerType = x.CustomerType,
|
|
|
|
|
Unit = x.Unit,
|
|
|
|
|
UnitPrice = SqlFunc.IsNull(x.UnitPrice.Value, 0),
|
|
|
|
|
//Quantity = x.IsCtn ? 1 : 0,
|
|
|
|
|
Currency = x.Currency,
|
|
|
|
|
ExchangeRate = x.ExchangeRate,
|
|
|
|
|
TaxRate = SqlFunc.IsNull(x.TaxRate.Value, 0),
|
|
|
|
|
AccTaxRate = SqlFunc.IsNull(x.AccTaxRate.Value, 0),
|
|
|
|
|
Tax = SqlFunc.IsNull(x.Tax.Value, 0),
|
|
|
|
|
TaxUnitPrice = SqlFunc.IsNull(x.TaxUnitPrice.Value, 0),
|
|
|
|
|
IsInvoice = x.IsInvoice,
|
|
|
|
|
IsAdvancedPay = x.IsAdvancedPay,
|
|
|
|
|
FeeId = g.Key.FeeId,
|
|
|
|
|
Unit = g.Key.Unit,
|
|
|
|
|
Remark = template.FeeCategoryName,
|
|
|
|
|
TemplateId = x.TemplateId,
|
|
|
|
|
InputMethod = InputMethod.Automatic
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
TemplateId = template.Id,
|
|
|
|
|
CustomerId = detail.CustomerId,
|
|
|
|
|
CustomerName = detail.CustomerName,
|
|
|
|
|
CustomerType = detail.CustomerType,
|
|
|
|
|
InputMethod = InputMethod.Automatic,
|
|
|
|
|
|
|
|
|
|
Quantity = qty,
|
|
|
|
|
FeeCode = detail.FeeCode,
|
|
|
|
|
FeeName = detail.FeeName,
|
|
|
|
|
UnitPrice = detail.UnitPrice.GetValueOrDefault(),
|
|
|
|
|
Currency = detail.Currency,
|
|
|
|
|
ExchangeRate = detail.ExchangeRate,
|
|
|
|
|
TaxRate = detail.TaxRate.GetValueOrDefault(),
|
|
|
|
|
AccTaxRate = detail.AccTaxRate.GetValueOrDefault(),
|
|
|
|
|
Tax = detail.Tax.GetValueOrDefault(),
|
|
|
|
|
TaxUnitPrice = detail.TaxUnitPrice.GetValueOrDefault(),
|
|
|
|
|
IsInvoice = detail.IsInvoice,
|
|
|
|
|
IsAdvancedPay = detail.IsAdvancedPay
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var localCurrecy = await Db.Queryable<SysOrg>().Where(x => x.Id == User.OrgId).Select(x => x.LocalCurrency).FirstAsync();
|
|
|
|
|
foreach (var detail in details)
|
|
|
|
|
{
|
|
|
|
|
if (detail.ExchangeRate.GetValueOrDefault() == 0 && detail.Currency != localCurrecy)
|
|
|
|
|
if (fee.ExchangeRate.GetValueOrDefault() == 0 && fee.Currency != localCurrecy)
|
|
|
|
|
{
|
|
|
|
|
var er = await exchangeService.Value.GetExchangeRateAsync(new ExchangeRate
|
|
|
|
|
{
|
|
|
|
@ -230,76 +263,74 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
CurrencyTo = localCurrecy,
|
|
|
|
|
FeeType = template.FeeType
|
|
|
|
|
});
|
|
|
|
|
fee.ExchangeRate = er.Data?.Rate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (detail.CustomerId == 0)
|
|
|
|
|
if (fee.CustomerId == 0)
|
|
|
|
|
{
|
|
|
|
|
switch (detail.CustomerType)
|
|
|
|
|
switch (fee.CustomerType)
|
|
|
|
|
{
|
|
|
|
|
case "controller":
|
|
|
|
|
detail.CustomerId = order.CustomerId;
|
|
|
|
|
detail.CustomerName = order.CustomerName;
|
|
|
|
|
fee.CustomerId = order.CustomerId;
|
|
|
|
|
fee.CustomerName = order.CustomerName;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "yard":
|
|
|
|
|
detail.CustomerId = order.YardId;
|
|
|
|
|
detail.CustomerName = order.Yard;
|
|
|
|
|
fee.CustomerId = order.YardId;
|
|
|
|
|
fee.CustomerName = order.Yard;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "custom":
|
|
|
|
|
detail.CustomerId = order.CustomserId;
|
|
|
|
|
detail.CustomerName = order.Customser;
|
|
|
|
|
fee.CustomerId = order.CustomserId;
|
|
|
|
|
fee.CustomerName = order.Customser;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "contract":
|
|
|
|
|
detail.CustomerId = order.ContractClientId;
|
|
|
|
|
detail.CustomerName = order.ContractClientName;
|
|
|
|
|
fee.CustomerId = order.ContractClientId;
|
|
|
|
|
fee.CustomerName = order.ContractClientName;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "shipagency":
|
|
|
|
|
detail.CustomerId = order.ShipAgencyId;
|
|
|
|
|
detail.CustomerName = order.ShipAgency;
|
|
|
|
|
fee.CustomerId = order.ShipAgencyId;
|
|
|
|
|
fee.CustomerName = order.ShipAgency;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "shipper":
|
|
|
|
|
detail.CustomerId = order.ShipperId.GetValueOrDefault();
|
|
|
|
|
detail.CustomerName = order.Shipper;
|
|
|
|
|
fee.CustomerId = order.ShipperId.GetValueOrDefault();
|
|
|
|
|
fee.CustomerName = order.Shipper;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "truck":
|
|
|
|
|
detail.CustomerId = order.TruckerId;
|
|
|
|
|
detail.CustomerName = order.Trucker;
|
|
|
|
|
fee.CustomerId = order.TruckerId;
|
|
|
|
|
fee.CustomerName = order.Trucker;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "booking":
|
|
|
|
|
detail.CustomerId = order.ForwarderId;
|
|
|
|
|
detail.CustomerName = order.Forwarder;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "carrier":
|
|
|
|
|
detail.CustomerId = order.CarrierId;
|
|
|
|
|
detail.CustomerName = order.Carrier;
|
|
|
|
|
fee.CustomerId = order.ForwarderId;
|
|
|
|
|
fee.CustomerName = order.Forwarder;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "wareHouse":
|
|
|
|
|
detail.CustomerId = order.WareHouseId;
|
|
|
|
|
detail.CustomerName = order.WareHouse;
|
|
|
|
|
fee.CustomerId = order.WareHouseId;
|
|
|
|
|
fee.CustomerName = order.WareHouse;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "shippercn":
|
|
|
|
|
detail.CustomerId = order.ShipperCnId.GetValueOrDefault();
|
|
|
|
|
detail.CustomerName = order.ShipperCn;
|
|
|
|
|
fee.CustomerId = order.ShipperCnId.GetValueOrDefault();
|
|
|
|
|
fee.CustomerName = order.ShipperCn;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "agent":
|
|
|
|
|
detail.CustomerId = order.AgentId.GetValueOrDefault();
|
|
|
|
|
detail.CustomerName = order.Agent;
|
|
|
|
|
fee.CustomerId = order.AgentId.GetValueOrDefault();
|
|
|
|
|
fee.CustomerName = order.Agent;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fees.Add(fee);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return details;
|
|
|
|
|
return fees;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|