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.

160 lines
6.0 KiB
C#

using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.UserModule;
using DS.WMS.Core.FeeModule.Entity;
using DS.WMS.Core.FeeModule.Interface;
using DS.WMS.Core.WmsModule.Entity;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.FeeModule.Method;
/// <summary>
/// 费用公共方法
/// </summary>
public class WmsFeeComonService:IWmsFeeComonService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="serviceProvider"></param>
public WmsFeeComonService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
}
public DataResult<List<OP_WMS_FEERATE_STORE_DETAIL>> InitOpWmsStoreRate(Guid wmsId, List<OP_WMS_FEERATE_DO_DETAIL> doFees, Guid? feeTypeGid)
{
var res = new List<OP_WMS_FEERATE_STORE_DETAIL>();
if (feeTypeGid.IsNull())
{
feeTypeGid = doFees.Where(x => x.GoodsFeeTypeGID.IsNotNull()).First().GoodsFeeTypeGID;
}
foreach (var item in doFees)
{
if (item.GOODSFEETYPE.IsNullOrEmpty() || item.GoodsFeeTypeGID == feeTypeGid)
{
var newfeerate = item.Adapt<OP_WMS_FEERATE_STORE_DETAIL>();
newfeerate.PID = wmsId;
res.Add(newfeerate);
}
}
return DataResult<List<OP_WMS_FEERATE_STORE_DETAIL>>.Success(res);
}
public DataResult<OP_WMS_FEEPAYINFO> InitOpWmsPayInfo(OP_WMS_IN_DO inDo, OP_WMS wms)
{
var res = new OP_WMS_FEEPAYINFO();
// res.GID = Guid.NewGuid();
res.WMSID = wms.WMSID;
res.WMSBASEID = wms.WMSBASEID==null?Guid.Empty: (Guid)wms.WMSBASEID;
res.FEESTARTDATE = (DateTime)wms.FEESTARTDATE;
res.ARCLIENTWMSOUT = wms.ARCLIENTWMSOUT;
res.ARCLIENTWMSIN = wms.ARCLIENTWMSOUT;
res.ARCLIENTWMS_OUTDO = wms.ARCLIENTWMSOUT;
res.APCLIENTWMSOUT = inDo.APCLIENTWMSOUT;
res.APCLIENTWMSIN = inDo.APCLIENTWMSOUT;
res.APCLIENTWMS_OUTDO = inDo.APCLIENTWMSOUT;
res.STORAGEUNITCOUNT = wms.STORAGEUNITCOUNT;
res.FEERATEWMSID = wms.WMSID;
res.SOURCEDOID = wms.WMSID;
return DataResult<OP_WMS_FEEPAYINFO>.Success(res);
}
public DataResult<List<Fee>> InitOpWmsFee(List<OP_WMS_FEERATE_DO_DETAIL> doFees, List<OP_WMS_IN_DO_GOODS> details, OP_WMS_IN_DO inDo,List<CodeFee> codeFees)
{
var res = new List<Fee>();
foreach (var item in doFees)
{
if (item.FEEMAKETYPE=="入库现结")
{
decimal num = 0.0m;
if (item.DEFAULTUNIT == "计费单位")
{
foreach (var detail in details)
{
num += (decimal)(detail.STORAGEUNITCOUNT);
}
};
if (item.DEFAULTUNIT == "单票") num = 1;
if (item.DEFAULTUNIT == "单柜")
{
//遍历入库执行明细 看看有几个箱号
var cntrnolist = new List<string>();
foreach (var detail in details)
{
if (!cntrnolist.Exists(x => x == detail.CNTRNO))
{
cntrnolist.Add(detail.CNTRNO);
}
}
num = cntrnolist.Count();
};
decimal amount = num * item.FEEPRICE.ToDecimal();
if (amount != 0)
{
if (res.Count == 0 || !res.Any(e => e.FeeId == item.FeeId))
{
var codefee = codeFees.First(x => x.GID == item.FeeId);
//给列表增加一条费用
var newfee = new Fee()
{
GID = Guid.NewGuid().ToString(),
ClientId = inDo.ClientId,
FeeId = codefee.GID,
SETTLEMENT = 0,
ORDERAMOUNT = 0,
ORDERINVOICE = 0,
ORDERINVSETTLEMENT = 0,
INVOICE = 0,
CURRENCY = "RMB",
EXCHANGERATE = 1,
ENTERDATE = DateTime.Now,
ENTEROPERATOR = user.GetUserGID(),
FEESTATUS = 1,
TAXRATE = 0,
ISADVANCEDPAY = false,
ISINVOICE = false,
ISCRMORDERFEE = false,
INPUTMODE = "月结",
};
newfee.BSNO = inDo.WMSDOID.ToString().ToUpper();
//newfee.SetCreateDefaultVal();
newfee.FEENAME = item.FEENAME;
newfee.UNITPRICE = item.FEEPRICE;
newfee.QUANTITY = num;
newfee.AMOUNT = amount;
newfee.CUSTOMERNAME = inDo.CUSTOMERNAME;
newfee.FEETYPE = item.FEETYPE;
newfee.setTax(ref newfee);
res.Add(newfee);
}
else
{
var fee = res.First(e => e.FEENAME == item.FEENAME);
var index = res.IndexOf(fee);
fee.QUANTITY = fee.QUANTITY + num;
fee.AMOUNT = fee.AMOUNT + amount;
fee.setTax(ref fee);
res[index] = fee;
}
}
}
}
return DataResult<List<Fee>>.Success(res);
}
}