|
|
|
using DS.Module.Core;
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
using DS.Module.UserModule;
|
|
|
|
using DS.WMS.Core.FeeModule.Dtos;
|
|
|
|
using DS.WMS.Core.FeeModule.Entity;
|
|
|
|
using DS.WMS.Core.FeeModule.Interface;
|
|
|
|
using DS.WMS.Core.System.Entity;
|
|
|
|
using DS.WMS.Core.WmsModule.Entity;
|
|
|
|
using Mapster;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using SqlSugar;
|
|
|
|
using Extensions = DS.Module.Core.Extensions.Extensions;
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.FeeModule.Method;
|
|
|
|
|
|
|
|
public class WmsFeeService : IWmsFeeService
|
|
|
|
{
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
private readonly IUser user;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="serviceProvider"></param>
|
|
|
|
public WmsFeeService(IServiceProvider serviceProvider)
|
|
|
|
{
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public DataResult GetWmsFeeList(PageRequest request)
|
|
|
|
{
|
|
|
|
var sysEnum = db.Queryable<SysEnum>().Where(x => x.EnumTypeID == 99024);
|
|
|
|
//序列化查询条件
|
|
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
|
|
var data = db.Queryable<Fee>()
|
|
|
|
.Select(x => new WmsFeeListPageModel()
|
|
|
|
{
|
|
|
|
FEETYPENAME = x.FEETYPE == 1 ? "应收" : "应付",
|
|
|
|
FeeStatusName= x.FEESTATUS == 0 ? "审核通过" : "录入状态",
|
|
|
|
},
|
|
|
|
true)
|
|
|
|
// .Mapper(it =>
|
|
|
|
// {
|
|
|
|
// if (it.FEESTATUS !=null)
|
|
|
|
// {
|
|
|
|
// var temp = sysEnum.Where(a => a.EnumValueID == it.FEESTATUS.ToString()).First();
|
|
|
|
// //只能写在Select后面
|
|
|
|
// it.FeeStatusName = temp.EnumValueName;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// })
|
|
|
|
// .Select<WmsFeeListPageModel>()
|
|
|
|
.Where(whereList).ToList();
|
|
|
|
// .Where(x => x.BSNO == id).ToList();
|
|
|
|
return DataResult.Successed("查询成功!", data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public DataResult SaveWmsFee(WmsFeeInput model)
|
|
|
|
{
|
|
|
|
var gid = model.GID;
|
|
|
|
var bsno = gid.ToString().ToUpper();
|
|
|
|
var wmsOutDo = db.Queryable<OP_WMS_IN_DO>().First(x => x.WMSDOID == gid);
|
|
|
|
|
|
|
|
// if (wmsOutDo.BILLSTATUS == "1003" )
|
|
|
|
// {
|
|
|
|
// return DataResult.Failed("已执行出库!");
|
|
|
|
// }
|
|
|
|
if (db.Queryable<Fee>().Any(x =>
|
|
|
|
x.BSNO == bsno && x.FEESTATUS == 2 && model.List.Select(a => a.GID).Contains(x.GID)))
|
|
|
|
{
|
|
|
|
return DataResult.Failed("存在已经提交审核明细!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (model.List.Count() > 0)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//开启事务
|
|
|
|
db.Ado.BeginTran();
|
|
|
|
// //先删除 明细
|
|
|
|
// var existList = db.Queryable<Fee>().Where(x => x.BSNO == bsno)
|
|
|
|
// .Select(n => n.GID).ToArray();
|
|
|
|
// var inList = model.List.Select(x => x.GID).ToArray();
|
|
|
|
// IEnumerable<string> delList = existList.AsQueryable().Except(inList);
|
|
|
|
// if (delList.Count() > 0)
|
|
|
|
// {
|
|
|
|
// foreach (var item in delList)
|
|
|
|
// {
|
|
|
|
// var existInfo = db.Queryable<Fee>()
|
|
|
|
// .Where(x => x.BSNO == bsno && x.GID == item).First();
|
|
|
|
// db.Deleteable(existInfo).ExecuteCommand();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
//更新 明细
|
|
|
|
// var updateList = model.List.Where(x => x.GID.IsNotEmptyOrNull() && !delList.Contains(x.GID))
|
|
|
|
// .ToList();
|
|
|
|
var feelist = db.Queryable<Fee>().Where(x => x.BSNO == bsno).ToList();
|
|
|
|
foreach (var item in model.List)
|
|
|
|
{
|
|
|
|
if (item.GID.IsNotEmptyOrNull())
|
|
|
|
{
|
|
|
|
var detail = feelist.First(x => x.GID == item.GID);
|
|
|
|
// var detail = item.Adapt<Fee>();
|
|
|
|
detail.FeeId = item.FeeId;
|
|
|
|
detail.FEETYPE = item.FEETYPE;
|
|
|
|
detail.FEENAME = item.FEENAME;
|
|
|
|
detail.UNITPRICE = item.UNITPRICE;
|
|
|
|
detail.QUANTITY = item.QUANTITY;
|
|
|
|
detail.AMOUNT = item.AMOUNT;
|
|
|
|
detail.CURRENCY = item.CURRENCY;
|
|
|
|
detail.REMARK = item.REMARK;
|
|
|
|
detail.TAXUNITPRICE = item.TAXUNITPRICE;
|
|
|
|
detail.INPUTMODE = item.INPUTMODE;
|
|
|
|
|
|
|
|
detail.setTax(ref detail);
|
|
|
|
db.Updateable(detail).ExecuteCommand();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var detail = item.Adapt<Fee>();
|
|
|
|
// detail.FEERATEDETAILID = item.FEERATEDETAILID;
|
|
|
|
detail.GID = Guid.NewGuid().ToString();
|
|
|
|
detail.SETTLEMENT = 0;
|
|
|
|
detail.ORDERAMOUNT = 0;
|
|
|
|
detail.ORDERINVOICE = 0;
|
|
|
|
detail.ORDERINVSETTLEMENT = 0;
|
|
|
|
detail.INVOICE = 0;
|
|
|
|
detail.EXCHANGERATE = 1;
|
|
|
|
detail.ENTERDATE = DateTime.Now;
|
|
|
|
detail.ENTEROPERATOR = user.GetUserGID();
|
|
|
|
detail.FEESTATUS = 1;
|
|
|
|
detail.ISADVANCEDPAY = false;
|
|
|
|
detail.ISINVOICE = false;
|
|
|
|
detail.ISCRMORDERFEE = false;
|
|
|
|
detail.BSNO = bsno;
|
|
|
|
detail.setTax(ref detail);
|
|
|
|
db.Insertable(detail).ExecuteCommand();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// //追加 明细
|
|
|
|
// var addList = model.List.Where(x => x.GID == "").ToList();
|
|
|
|
//
|
|
|
|
// foreach (var item in addList)
|
|
|
|
// {
|
|
|
|
// var detail = item.Adapt<Fee>();
|
|
|
|
// // detail.FEERATEDETAILID = item.FEERATEDETAILID;
|
|
|
|
// detail.GID = Guid.NewGuid().ToString();
|
|
|
|
// detail.SETTLEMENT = 0;
|
|
|
|
// detail.ORDERAMOUNT = 0;
|
|
|
|
// detail.ORDERINVOICE = 0;
|
|
|
|
// detail.ORDERINVSETTLEMENT = 0;
|
|
|
|
// detail.INVOICE = 0;
|
|
|
|
// detail.EXCHANGERATE = 1;
|
|
|
|
// detail.ENTERDATE = DateTime.Now;
|
|
|
|
// detail.ENTEROPERATOR = user.GetUserGID();
|
|
|
|
// detail.FEESTATUS = 1;
|
|
|
|
// detail.ISADVANCEDPAY = false;
|
|
|
|
// detail.ISINVOICE = false;
|
|
|
|
// detail.ISCRMORDERFEE = false;
|
|
|
|
// detail.BSNO = bsno;
|
|
|
|
// detail.setTax(ref detail);
|
|
|
|
// db.Insertable(detail).ExecuteCommand();
|
|
|
|
// }
|
|
|
|
|
|
|
|
db.Ado.CommitTran();
|
|
|
|
return DataResult.Successed("更新费用成功!");
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
db.Ado.RollbackTran();
|
|
|
|
return DataResult.Failed("更新失败!" + ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult.Successed("更新费率成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DataResult DelWmsFee(string id)
|
|
|
|
{
|
|
|
|
var fee = db.Queryable<Fee>().First(x => x.GID == id);
|
|
|
|
if (fee.FEESTATUS != 1 && fee.FEESTATUS != 6)
|
|
|
|
{
|
|
|
|
return DataResult.Failed("非法状态,不能删除!");
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//开启事务
|
|
|
|
db.Ado.BeginTran();
|
|
|
|
db.Deleteable(fee).ExecuteCommand();
|
|
|
|
db.Ado.CommitTran();
|
|
|
|
return DataResult.Successed("删除成功!");
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
db.Ado.RollbackTran();
|
|
|
|
return DataResult.Failed("删除失败!" + ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DataResult SubmitWmsFee(string id)
|
|
|
|
{
|
|
|
|
var fee = db.Queryable<Fee>().First(x => x.GID == id);
|
|
|
|
if (fee.FEESTATUS == 0)
|
|
|
|
{
|
|
|
|
return DataResult.Failed("已审核通过!");
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//开启事务
|
|
|
|
db.Ado.BeginTran();
|
|
|
|
|
|
|
|
fee.FEESTATUS = 0;
|
|
|
|
db.Updateable(fee).ExecuteCommand();
|
|
|
|
db.Ado.CommitTran();
|
|
|
|
return DataResult.Successed("提交成功!");
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
db.Ado.RollbackTran();
|
|
|
|
return DataResult.Failed("提交失败!" + ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public DataResult CancelWmsFee(string id)
|
|
|
|
{
|
|
|
|
var fee = db.Queryable<Fee>().First(x => x.GID == id);
|
|
|
|
if (fee.FEESTATUS != 0)
|
|
|
|
{
|
|
|
|
return DataResult.Failed("非法状态,不能撤回!");
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//开启事务
|
|
|
|
db.Ado.BeginTran();
|
|
|
|
|
|
|
|
fee.FEESTATUS = 1;
|
|
|
|
db.Updateable(fee).ExecuteCommand();
|
|
|
|
db.Ado.CommitTran();
|
|
|
|
return DataResult.Successed("撤回成功!");
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
db.Ado.RollbackTran();
|
|
|
|
return DataResult.Failed("撤回失败!" + ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|