using Rhea.Common;
|
using Tiger.IBusiness;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Linq.Expressions;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using Tiger.Model;
|
using System.Collections;
|
|
namespace Tiger.Business.WMS.Transaction
|
{
|
/// <summary>
|
/// 客供料入库清点事务
|
/// </summary>
|
public class CustSupplyCheckingNew : WMSTransactionBase, ICustSupplyCheckingNew
|
{
|
/// <summary>
|
/// 事务初始化函数
|
/// </summary>
|
/// <param name="id"></param>
|
/// <param name="userCode"></param>
|
/// <param name="apiHost"></param>
|
/// <param name="orgCode"></param>
|
public ICustSupplyCheckingNew Init(string id, string userCode, string apiHost, string orgCode)
|
{
|
TransID = id;
|
UserCode = userCode;
|
ApiHost = apiHost;
|
OrgCode = orgCode;
|
Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]");
|
return this;
|
}
|
|
#region Propertys & Variables
|
|
public string UserCode { get; set; }
|
public long UserId { get; set; }
|
public string VenderCode { get; set; }
|
public string LotNo { get; set; }
|
public string SecondVenderCode { get; set; }
|
public string WarehouseCode { get; set; }
|
public string WarehouseName { get; set; }
|
public string OrgCode { get; set; }
|
public string CustomsNo { get; set; }
|
public List<ParameterReturn> suppliers { get; set; }
|
public bool T100Success { get; set; } = false;
|
|
#endregion Propertys & Variables
|
|
#region Functions
|
|
/// <summary>
|
/// 扫描物料并复核,如果物料已经完成移库则货架上亮灯提醒储位
|
/// </summary>
|
public async Task<ApiAction> ScanItem(CustSupplyCheckingInput input)
|
{
|
var action = new ApiAction();
|
try
|
{
|
//if (string.IsNullOrEmpty(input.WarehouseCode))
|
//{
|
// action.IsSuccessed = false;
|
// action.Message = $"库位不能为空";
|
// return action;
|
//}
|
string[] _strVenderCodes = input.SecondSuppCode.Split(',');
|
SecondVenderCode = _strVenderCodes[0];
|
LotNo = input.LotNo;
|
if (string.IsNullOrEmpty(VenderCode)) { VenderCode = _strVenderCodes[1]; }
|
if (string.IsNullOrEmpty(input.SN))
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.SnEmptyFailure", input.SN);
|
return action;
|
}
|
|
#region 报关单号判断
|
|
if (input.AuthOption.CurOrg == "YTXC" && string.IsNullOrWhiteSpace(CustomsNo))
|
{
|
if (string.IsNullOrWhiteSpace(input.SN))
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L($"盐田据点请扫描报关单号二维码!");
|
return action;
|
}
|
var customsNo = input.SN.Replace(",", ",").Trim();
|
if (customsNo.Split(",").Length != 2)
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L($"报关单号格式错误,请确认格式是否为【报关单号,核算清单号】!");
|
return action;
|
}
|
CustomsNo = input.SN;
|
action.Data = new IncomingMatStorage
|
{
|
sn = CustomsNo,
|
IsCustomsNo = true
|
};
|
action.IsSuccessed = true;
|
action.LocaleMsg = Biz.L($"报关单号二维码扫描成功");
|
return action;
|
}
|
|
#endregion 报关单号判断
|
|
//判断是否扫描的仓库,并查询是否存在
|
var query = await Biz.Db.Queryable<WMS_WAREHOUSE>().Where(t => t.WH_CODE == input.SN.Trim()).FirstAsync();
|
if (query != null)
|
{
|
//if (!string.IsNullOrEmpty(WarehouseCode))
|
//{
|
// action.IsSuccessed = false;
|
// action.Data = query;
|
// action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.WhExist", input.SN);
|
// return action;
|
//}
|
//else
|
{
|
WarehouseCode = query.WH_CODE;
|
WarehouseName = query.WH_NAME;
|
action.Data = query;
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.GetWhSuccess", WarehouseCode);
|
return action;
|
}
|
}
|
if (string.IsNullOrEmpty(WarehouseCode))
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.NotExist", input.SN);
|
return action;
|
}
|
input.AuthOption.OrgCode = input.AuthOption.OrgCode.IsNullOrEmpty() ? input.AuthOption.CurOrg : input.AuthOption.OrgCode;
|
Result<IInventory> result = WMS_ITEM_Biz.WmsItem.GetK(input.SN, input.AuthOption, false);
|
if (result.Flag != Result.Flags.Success)
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = result.LocaleMsg;
|
return action;
|
}
|
var curInv = result.Data as Inventory;
|
if (!curInv.IsQRCode)
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.NotQrCode", curInv.Barcode.MetaSn);
|
return action;
|
}
|
//判断条码是否为最少包装
|
if (!new[] { Barcode.Types.Small, Barcode.Types.Other }.Contains(curInv.Barcode.Type))
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.TypeError", curInv.SN);
|
return action;
|
}
|
if (curInv.Items.Any())
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.ExistItem", curInv.ItemInfo?.ITEM_CODE);
|
return action;
|
}
|
|
if (string.IsNullOrEmpty(curInv.ItemInfo?.ITEM_CODE))
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.NotFound", curInv.ItemInfo?.ITEM_CODE);
|
return action;
|
}
|
|
// 其它入库清点不能扫入拆包后带-1的标签
|
if (curInv.isNormalStatus && curInv.Status == WMS_ITEM.STATUSs.WaitIn)
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.NotAllowIn", curInv.ItemInfo?.ITEM_CODE);
|
return action;
|
}
|
//物料验证
|
if (curInv.ItemInfo.IsNullOrEmpty() || curInv.ItemInfo.IS_ACTIVE == "N")
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("WMS.ProdMReq.ScanItem.ItemCodeNotExistsOrNotActive", curInv.ItemInfo.ITEM_CODE.IsNullOrEmpty(curInv.Barcode.ItemCode));
|
return action;
|
}
|
OrgCode = input.AuthOption.CurOrg;
|
//string[] _strVenderCodes = input.SecondSuppCode.Split(',');
|
//SecondVenderCode = _strVenderCodes[0];
|
//LotNo = input.LotNo;
|
//if (string.IsNullOrEmpty(VenderCode)) { VenderCode = _strVenderCodes[1]; }
|
//暂时不判断
|
//if (_strVenderCodes[1] != VenderCode)
|
//{
|
// action.IsSuccessed = false;
|
// action.Message = $"二级供应商代码不符!请重新选择二级供应商!";
|
// return action;
|
|
//}
|
|
var scanResult = new BIZ_ERP_OTH_IN_SN
|
{
|
ID = Guid.NewGuid().ToString(),
|
BUSINESSCODE = UserCode,
|
WAREHOUSECODE = WarehouseCode,
|
SN = curInv.SN,
|
ITEM_CODE = curInv.ItemInfo.ITEM_CODE,
|
QTY = curInv.Barcode.Qty ?? 0,
|
DATECODE = curInv.Barcode.ProdDate ?? DateTime.MinValue,
|
LOTNO = LotNo, //item.Barcode.LotNo,
|
STATUS = WMS_ITEM.STATUSs.Counted.GetValue(),
|
META_SN = input.SN,
|
AUTH_ORG = input.AuthOption.CurOrg
|
};
|
var snExt = new BIZ_ERP_OTH_IN_SNExt()
|
{
|
BUSINESSCODE = scanResult.BUSINESSCODE,
|
WAREHOUSECODE = scanResult.WAREHOUSECODE,
|
SN = scanResult.SN,
|
ITEM_CODE = scanResult.ITEM_CODE,
|
QTY = scanResult.QTY,
|
DATECODE = scanResult.DATECODE,
|
DATECODESTR = scanResult.DATECODESTR,
|
LOTNO = scanResult.LOTNO,
|
STATUS = scanResult.STATUS,
|
WH_CODE = scanResult.WAREHOUSECODE,
|
WH_NAME = WarehouseName,
|
MName = curInv.ItemInfo.ITEM_NAME,
|
MDesc = curInv.ItemInfo.SPEC,
|
MUom = curInv.ItemInfo.UNIT
|
};
|
|
//验证条码是否已做过清点
|
var nLogs = Biz.Db.Queryable<BIZ_ERP_OTH_IN_SN>().Where(t => t.SN.ToUpper() == curInv.SN.ToUpper()).First();
|
if (nLogs != null)
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.BarcodeCounted", curInv.SN);
|
return action;
|
}
|
|
//保存到数据库
|
var db = Business.Biz.Db;
|
|
var model = new BIZ_ERP_CUSTOMS()
|
{
|
AUTH_ORG = input.AuthOption.CurOrg,
|
CREATE_USER = UserCode,
|
OrderNo = UserCode,
|
Barcodes = curInv.SN,
|
CustomsNo = CustomsNo.Replace(",", ",").Trim().Split(',')[0],
|
AccountingNo = CustomsNo.Replace(",", ",").Trim().Split(',')[1],
|
CountsType = BIZ_ERP_CUSTOMS.CountsEnum.Incoming
|
};
|
|
var dbTran = db.UseTran(() =>
|
{
|
db.Insertable(scanResult, UserCode).ExecuteCommand();
|
//db.Insertable(wi, UserCode).ExecuteCommand();
|
//db.Insertable(his, UserCode).ExecuteCommand();
|
if (model != null)
|
{
|
db.Insertable(model).ExecuteCommand();
|
}
|
});
|
if (!dbTran.IsSuccess)
|
{
|
Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception");
|
this.Close(!dbTran.IsSuccess);
|
throw dbTran.ErrorException;
|
}
|
action.Data = snExt;
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.CountSuccess", input.SN);
|
}
|
catch (Exception ex)
|
{
|
//取消当前操作
|
|
action.CatchExceptionWithLog(ex, $"扫描物料[{input.SN}]复核异常");
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.ScanException", input.SN);
|
}
|
return action;
|
}
|
|
/// <summary>
|
/// 生成客供物料入库单据
|
/// </summary>
|
/// <returns></returns>
|
public async Task<ApiAction> SubmitInvBill()
|
{
|
var action = new ApiAction();
|
bool isIQCOk = true;
|
try
|
{
|
//获取当前用户所有已清点、未制单的条码数据
|
var nScannedBarcodes = await Biz.Db.Queryable<BIZ_ERP_OTH_IN_SN, BAS_ITEM>((t, m) =>
|
new JoinQueryInfos(
|
JoinType.Left, t.ITEM_CODE == m.ITEM_CODE
|
))
|
.Where((t, m) => t.WAREHOUSECODE.ToUpper() == WarehouseCode.ToUpper()
|
&& t.STATUS == WMS_ITEM.STATUSs.Counted.GetValue()
|
&& t.BUSINESSCODE == UserCode
|
&& t.AUTH_ORG == OrgCode)
|
.Select((t, m) => new BIZ_ERP_OTH_IN_SNExt
|
{
|
ID = t.ID,
|
SN = t.SN,
|
ITEM_CODE = t.ITEM_CODE,
|
QTY = t.QTY,
|
META_SN = t.META_SN,
|
BUSINESSCODE = t.BUSINESSCODE,
|
BUSINESSLINE = t.BUSINESSLINE,
|
UPDATE_TIME = t.UPDATE_TIME,
|
UPDATE_USER = t.UPDATE_USER,
|
CREATE_TIME = t.CREATE_TIME,
|
CREATE_USER = t.CREATE_USER,
|
DATECODE = t.DATECODE,
|
DATECODESTR = t.DATECODESTR,
|
LOTNO = t.LOTNO,
|
STATUS = t.STATUS,
|
WAREHOUSECODE = t.WAREHOUSECODE,
|
MUom = m.UNIT,
|
MName = m.ITEM_NAME,
|
MDesc = m.SPEC,
|
})
|
.ToListAsync();
|
if (!nScannedBarcodes.Any())
|
{
|
action.IsSuccessed = false;
|
action.Message = $"没有可以提交的清点数据";
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.NotDataToSubmit");
|
return action;
|
}
|
|
// 查询条码清点表所有仓库代码
|
//var nWarehouseCodes = nScannedBarcodes.Select(x => x.WarehouseCode).Distinct().ToList();
|
|
//新建其他入库单据头 OtherInstockHeader
|
Result ruleResult = Cache.CodeRule["CI001"].Generate("CI"); //iWMS.GetBillNoByType("CI");
|
if (!ruleResult.IsSuccessed)
|
{
|
throw new Exception(ruleResult.ExceptionMsg.Message);
|
}
|
var billcode = ruleResult.Data.ToString();
|
var nBillHeader = new BIZ_ERP_OTH_IN
|
{
|
BILLCODE = billcode,
|
BILLDATE = DateTime.Now.Date,
|
WAREHOUSECODE = WarehouseCode,
|
STATUS = BIZ_ERP_OTH_IN.STATUSs.WORKING.GetValue(),
|
REMARK = LotNo,
|
AUTH_ORG = OrgCode
|
};
|
|
List<WMS_ITEM> Items = new List<WMS_ITEM>();
|
List<WMS_ITEM_PKG> ItemPkgs = new List<WMS_ITEM_PKG>();
|
List<WMS_ITEM_HIS> ItemHistorys = new List<WMS_ITEM_HIS>();
|
foreach (var wi in nScannedBarcodes)
|
{
|
Barcode barcode = new Barcode(wi.META_SN);
|
WMS_ITEM wmsItem = new WMS_ITEM
|
{
|
SN = wi.SN,
|
ITEM_CODE = wi.ITEM_CODE,
|
QTY = wi.QTY,
|
PROD_DATE = barcode.ProdDate ?? DateTime.MinValue,
|
SUPP_CODE = VenderCode,
|
LOTNO = LotNo,
|
ERP_WH = WarehouseCode,
|
STATUS = WMS_ITEM.STATUSs.WaitTest.GetValue(),
|
TRANS_CODE = nameof(BIZ_ERP_OTH_IN),
|
TRANS_NO = billcode,
|
//TRANS_LINE = item.SOURCELINE,
|
//SOURCE_CODE = nameof(BIZ_ERP_IQC),
|
//SOURCE_ORDER = item.BILLCODE,
|
AUTH_ORG = OrgCode,
|
};
|
Items.Add(wmsItem);
|
WMS_ITEM_PKG pKG = new WMS_ITEM_PKG
|
{
|
SN = wi.SN,
|
ITEM_CODE = wi.ITEM_CODE,
|
PARENT_SN = "",
|
PKG_TYPE = WMS_ITEM_PKG.PKG_TYPEs.OnePiece.GetValue(),
|
QTY = wi.QTY,
|
SUPP_CODE = VenderCode,
|
LOTNO = LotNo,
|
ERP_WH = WarehouseCode,
|
TRANS_CODE = nameof(BIZ_ERP_OTH_IN),
|
TRANS_NO = billcode,
|
//TRANS_LINE = item.SOURCELINE,
|
//SOURCE_CODE = nameof(BIZ_ERP_IQC),
|
//SOURCE_ORDER = item.BILLCODE,
|
AUTH_ORG = OrgCode,
|
};
|
ItemPkgs.Add(pKG);
|
}
|
|
// 查找待处理记录料号列表
|
var nMaterials = nScannedBarcodes.Select(x => x.ITEM_CODE).Distinct().ToList();
|
|
// 单据行号变量,初始值1
|
var nLineSeq = 1;
|
|
List<BIZ_ERP_OTH_IN_SN> scanList = new List<BIZ_ERP_OTH_IN_SN>();
|
List<BIZ_ERP_OTH_IN_DTL> detailList = new List<BIZ_ERP_OTH_IN_DTL>();
|
List<BIZ_ERP_IQC> iqcHeaders = new List<BIZ_ERP_IQC>();
|
List<Detail> details = new List<Detail>();
|
// 按照料号列表处理单据明细
|
foreach (var matCode in nMaterials)
|
{
|
// 按照料号、计量单位汇总scanBarcode
|
var lineMaterials = (from codes in nScannedBarcodes.Where(x => x.ITEM_CODE.ToUpper() == matCode.ToUpper())
|
group codes by new { codes.ITEM_CODE, codes.MUom } into g
|
select new
|
{
|
g.Key.ITEM_CODE,
|
g.Key.MUom,
|
sumQty = g.Sum(x => x.QTY)
|
}
|
).ToList();
|
|
// 循环处理每一行
|
foreach (var matLine in lineMaterials)
|
{
|
//插入单据明细行
|
var billDetail = new BIZ_ERP_OTH_IN_DTL
|
{
|
WAREHOUSECODE = WarehouseCode,
|
BILLCODE = billcode,
|
BILLLINE = nLineSeq.ToString(),
|
LINESTATUS = BIZ_ERP_OTH_IN.STATUSs.WORKING.GetValue(),
|
ITEM_CODE = matLine.ITEM_CODE,
|
UNITCODE = matLine.MUom,
|
PRQTY = matLine.sumQty,
|
ERP_BILL_CODE = "",
|
AUTH_ORG = OrgCode,
|
QTY = 0
|
};
|
detailList.Add(billDetail);
|
|
details.Add(new Detail
|
{
|
pmdtseq = nLineSeq.ToString(),
|
pmdt001 = "",
|
pmdt002 = "",
|
pmdt003 = "",
|
pmdt004 = "",
|
pmdt006 = matLine.ITEM_CODE, //"K7015AA016141",
|
pmdt018 = "创米科技",
|
pmdt020 = matLine.sumQty.ToString(), //"100.00000",
|
pmdtud011 = "0"
|
});
|
|
Result iqcResult = Cache.CodeRule["IQC001"].Generate("IQC");
|
if (!iqcResult.IsSuccessed)
|
{
|
throw new Exception(iqcResult.ExceptionMsg.Message);
|
}
|
//nBillHeader.SOURCECODE = iqcResult.Data.ToString();
|
var nIqcHeader = new BIZ_ERP_IQC
|
{
|
BILLCODE = iqcResult.Data.ToString(),
|
SOURCETYPE = (int)BIZ_ERP_IQC.BillType.CustSupplyInStock,
|
SOURCECODE = billcode,
|
SOURCELINE = nLineSeq.ToString(),
|
PONO = billcode,
|
POLINE = nLineSeq.ToString(),
|
MEASURE = "Y",
|
AUTH_ORG = OrgCode,
|
QCTIMES = 0,
|
QCSTATUS = (int)BIZ_ERP_IQC.QCSTATUSs.Finished, /*(int)IqcManagementSides.QCStatus.UnFinish,*/
|
QCRESULT = (int)BIZ_ERP_IQC.QCRESULTs.Wait,
|
QCREVIEW = (int)BIZ_ERP_IQC.QCReview.UnReview,
|
QCLEVEL = 11,
|
ITEM_CODE = matLine.ITEM_CODE
|
//ReceiveQty = detail.Qty, //生成送检单加上接收数量 2022/07/27 Ben Lin 2022/09/03 Ben Lin 注释
|
};
|
iqcHeaders.Add(nIqcHeader);
|
|
// 更新清点表,单据号
|
foreach (BIZ_ERP_OTH_IN_SN barcode in nScannedBarcodes.Where(x => x.ITEM_CODE == matLine.ITEM_CODE))
|
{
|
barcode.BUSINESSCODE = billcode;
|
barcode.BUSINESSLINE = nLineSeq.ToString();
|
barcode.STATUS = WMS_ITEM.STATUSs.WaitTest.GetValue();
|
barcode.AUTH_ORG = OrgCode;
|
barcode.UPDATE_TIME = DateTime.Now;
|
barcode.UPDATE_USER = UserCode;
|
scanList.Add(barcode);
|
}
|
|
// 单据明细行号 ++
|
nLineSeq++;
|
}
|
}
|
|
var sns = nScannedBarcodes.Select(i => i.SN).Distinct().ToList();
|
var customsData = Biz.Db.Queryable<BIZ_ERP_CUSTOMS>().Where(i => sns.Contains(i.Barcodes)).First();
|
|
//调用T100接口生成到货单
|
var ret = ErpT100.GenerateCustReceipt(new CustReceiptInputParameter
|
{
|
parameter = new Parameter<Detail>
|
{
|
pmds000 = "2",
|
pmdsdocno = "3453",
|
pmdsdocdt = DateTime.Now.ToString("yyyy-MM-dd"), //"2023-04-26", //当天时间
|
pmds002 = UserCode == "admin" ? "00000" : UserCode, //"L36783", //用户ID
|
pmds003 = "",
|
pmds007 = VenderCode, //"C0006", //供应商代码
|
pmdsud003 = customsData.CustomsNo, // 报关单号
|
pmdsud004 = customsData.AccountingNo,// 核放清单号
|
pmds010 = "", //"测试客供料无采购收货", //送货单号
|
pmdsud001 = SecondVenderCode, //"CM017", //二级供应编号
|
detail = details
|
},
|
datakey = new Datakey
|
{
|
EntId = "88",
|
CompanyId = OrgCode
|
}
|
});
|
if (ret.payload.std_data.execution.code == "0") //成功
|
{
|
nBillHeader.ERP_BILL_CODE = ret.payload.std_data.parameter.docno;
|
action.Message += $"{action.Message.IsNullOrEmpty("", ";")}{ret.payload.std_data.execution.description},返回的收货单号:[{ret.payload.std_data.parameter.docno}]";
|
T100Success = true;
|
|
#region 生成送检单
|
|
foreach (var item in iqcHeaders)
|
{
|
var retIns = ErpT100.GenerateInspection(new InsInputParameter
|
{
|
parameter = new InsParameter
|
{
|
pmdsdocno = ret.payload.std_data.parameter.docno,
|
pmdsdocdt = DateTime.Now.ToString("yyyy-MM-dd"),
|
pmdtseq = item.SOURCELINE.ToString(),
|
pmdt020 = item.QCQTY.ToString(),
|
qcbadocno = "3701",
|
},
|
datakey = new Datakey
|
{
|
EntId = "88",
|
CompanyId = OrgCode
|
}
|
});
|
isIQCOk &= retIns.payload.std_data.execution.code == "0";
|
if (retIns.payload.std_data.execution.code != "0")
|
{
|
//isIQCOk = false;
|
action.IsSuccessed = false;
|
action.Message = $"到货单[{ret.payload.std_data.parameter.docno}],当前用户[{UserCode}],供应商编号[{VenderCode}],二级供应商编号[{SecondVenderCode}],返回的信息:{retIns.payload.std_data.execution.description}"; ;
|
//return action;
|
}
|
else
|
{
|
item.ERP_BILL_CODE = retIns.payload.std_data.parameter.docno;
|
//更新库存表
|
foreach (var wi in Items.Where(x => x.TRANS_NO == billcode && x.ITEM_CODE == item.ITEM_CODE))
|
{
|
wi.STATUS = WMS_ITEM.STATUSs.WaitTest.GetValue();
|
wi.TRANS_CODE = nameof(BIZ_ERP_OTH_IN);
|
wi.TRANS_NO = billcode;
|
wi.TRANS_LINE = item.SOURCELINE;
|
wi.SOURCE_CODE = nameof(item);
|
wi.ERP_WH = WarehouseCode;
|
wi.SOURCE_ORDER = item.BILLCODE;
|
wi.UPDATE_USER = UserCode;
|
wi.UPDATE_TIME = DateTime.Now;
|
wi.AUTH_ORG = OrgCode;
|
|
WMS_ITEM_HIS his = new WMS_ITEM_HIS(wi, $"客供来料清点,到货单[{billcode}][{string.Join(",", detailList.Where(s => s.ITEM_CODE == item.ITEM_CODE).Select(q => q.BILLLINE))}],送检单[{item.BILLCODE}]");
|
ItemHistorys.Add(his);
|
}
|
foreach (var pkg in ItemPkgs.Where(x => x.TRANS_NO == billcode && x.ITEM_CODE == item.ITEM_CODE))
|
{
|
pkg.PARENT_SN = "";
|
pkg.PKG_TYPE = WMS_ITEM_PKG.PKG_TYPEs.OnePiece.GetValue();
|
pkg.SUPP_CODE = VenderCode;
|
pkg.LOTNO = LotNo;
|
pkg.ERP_WH = WarehouseCode;
|
pkg.TRANS_LINE = item.SOURCELINE;
|
pkg.SOURCE_CODE = nameof(item);
|
pkg.SOURCE_ORDER = item.BILLCODE;
|
pkg.UPDATE_USER = UserCode;
|
pkg.UPDATE_TIME = DateTime.Now;
|
pkg.AUTH_ORG = OrgCode;
|
}
|
}
|
}
|
|
#endregion 生成送检单
|
}
|
else //失败
|
{
|
action.IsSuccessed = false;
|
action.Message = $"当前用户[{UserCode}],供应商编号[{VenderCode}],二级供应商编号[{SecondVenderCode}],返回的信息:{ret.payload.std_data.execution.description}";
|
return action;
|
}
|
|
//保存到数据库
|
var db = Business.Biz.Db;
|
var dbTran = db.UseTran(() =>
|
{
|
// 插入单据表头
|
var headerId = Biz.Db.Insertable(nBillHeader, UserCode).ExecuteReturnBigIdentity();
|
var x = db.Storageable(detailList, UserCode).ToStorage();
|
x.AsInsertable.ExecuteCommand();//不存在插入
|
x.AsUpdateable.IgnoreColumns(z => new { z.CREATE_TIME, z.CREATE_USER }).ExecuteCommand();//存在更新,更新时忽略字段CreationTime、CreatorUserId
|
|
//db.Updateable(scanList, UserCode).ExecuteCommand();
|
db.Fastest<BIZ_ERP_OTH_IN_SN>().BulkUpdate(scanList);
|
if (action.IsSuccessed && isIQCOk)
|
{
|
db.Insertable(iqcHeaders, UserCode).ExecuteCommand();
|
action.Message += $"{action.Message.IsNullOrEmpty("", ";")}生成客供物料入库单据和送检单成功";
|
}
|
//var ret = Biz.GenerateCustReceipt("", "");
|
|
if (Items.Count > 100)
|
{
|
db.Fastest<WMS_ITEM>().BulkCopy(Items);
|
}
|
else
|
{
|
db.Insertable(Items, UserCode).ExecuteCommand();
|
}
|
if (ItemPkgs.Count > 100)
|
{
|
db.Fastest<WMS_ITEM_PKG>().BulkCopy(ItemPkgs);
|
}
|
else
|
{
|
db.Insertable(ItemPkgs, UserCode).ExecuteCommand();
|
}
|
if (ItemHistorys.Count > 100)
|
{
|
db.Fastest<WMS_ITEM_HIS>().BulkCopy(ItemHistorys);
|
}
|
else
|
{
|
db.Insertable(ItemHistorys, UserCode).ExecuteCommand();
|
}
|
});
|
if (!dbTran.IsSuccess)
|
{
|
Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception");
|
this.Close(!dbTran.IsSuccess);
|
throw dbTran.ErrorException;
|
}
|
}
|
catch (System.Exception ex)
|
{
|
return action.CatchExceptionWithLog(ex, Biz.L(""));
|
}
|
return action;
|
}
|
|
/// <summary>
|
/// 删除当前用户的已扫记录(缓存表)
|
/// </summary>
|
/// <returns></returns>
|
public async Task<ApiAction> DeleteAllScannedBarcode()
|
{
|
var action = new ApiAction();
|
try
|
{
|
if (WarehouseCode.IsNullOrEmpty())
|
{
|
action.IsSuccessed = false;
|
action.Message = $"空,无法删除已清点条码";
|
return action;
|
}
|
else
|
{
|
await Biz.Db.Deleteable<BIZ_ERP_OTH_IN_SN>(x => x.CREATE_USER == UserCode
|
&& x.WAREHOUSECODE == WarehouseCode
|
&& x.STATUS == WMS_ITEM.STATUSs.Counted.GetValue()
|
&& x.BUSINESSCODE == UserCode).ExecuteCommandAsync();
|
}
|
}
|
catch (System.Exception ex)
|
{
|
}
|
return action;
|
}
|
|
/// <summary>
|
/// 删除当前用户的已扫单个记录
|
/// </summary>
|
/// <returns></returns>
|
public async Task<ApiAction> DeleteScannedBarcode(CustSupplyInInput input)
|
{
|
var action = new ApiAction();
|
try
|
{
|
if (WarehouseCode.IsNullOrEmpty())
|
{
|
action.IsSuccessed = false;
|
action.Message = $"空,无法删除已清点条码";
|
return action;
|
}
|
else
|
{
|
await Biz.Db.Deleteable<BIZ_ERP_OTH_IN_SN>(x => x.SN == input.SN).ExecuteCommandAsync();
|
}
|
}
|
catch (System.Exception ex)
|
{
|
}
|
return action;
|
}
|
|
/// <summary>
|
/// 删除当前用户的已扫记录(缓存表)
|
/// </summary>
|
/// <returns></returns>
|
public async Task<ApiAction> CheckingT100Staut()
|
{
|
var action = new ApiAction();
|
try
|
{
|
if (T100Success)
|
{
|
action.IsSuccessed = true;
|
T100Success = false;
|
}
|
else
|
{
|
action.IsSuccessed = false;
|
}
|
}
|
catch (System.Exception ex)
|
{
|
}
|
return action;
|
}
|
|
/// <summary>
|
/// 获取已清点的物料汇总
|
/// </summary>
|
/// <returns></returns>
|
public async Task<PageAble<Model.Minsun.CustSupplyCheckList>> GetScannedMaterialSummarys()
|
{
|
var query = Biz.Db.Queryable<BIZ_ERP_OTH_IN_SN, BAS_ITEM>((t, m) =>
|
new JoinQueryInfos(
|
JoinType.Left, t.ITEM_CODE == m.ITEM_CODE
|
))
|
.Where((t, m) => t.CREATE_USER == UserCode
|
&& t.WAREHOUSECODE.ToUpper() == WarehouseCode.ToUpper()
|
&& t.STATUS == WMS_ITEM.STATUSs.Counted.GetValue()
|
&& t.AUTH_ORG == OrgCode.ToUpper()
|
&& t.BUSINESSCODE == UserCode)
|
.GroupBy((t, m) => new { t.WAREHOUSECODE, t.ITEM_CODE })
|
.Select((t, m) => new Model.Minsun.CustSupplyCheckList
|
{
|
WarehouseCode = t.WAREHOUSECODE,
|
MaterialCode = t.ITEM_CODE,
|
MaterialName = SqlFunc.AggregateMax(m.ITEM_NAME),
|
MaterialStandard = SqlFunc.AggregateMax(m.SPEC),
|
InventoryQty = SqlFunc.AggregateSum(t.QTY),
|
Unit = SqlFunc.AggregateMax(m.UNIT)
|
})
|
.ToList();
|
return await Task.FromResult(new PageAble<Model.Minsun.CustSupplyCheckList>()
|
{
|
data = query,
|
totals = query.Count(),
|
});
|
}
|
|
/// <summary>
|
/// 查询物料对应的条码
|
/// </summary>
|
/// <param name="MaterialCode"></param>
|
/// <returns></returns>
|
public async Task<PageAble<Model.Minsun.CustSupplyCheckDetail>> GetScannedMaterialDetailBarcodes(string MaterialCode)
|
{
|
var query = await Biz.Db.Queryable<BIZ_ERP_OTH_IN_SN, BAS_ITEM>((t, m) =>
|
new JoinQueryInfos(
|
JoinType.Left, t.ITEM_CODE == m.ITEM_CODE
|
))
|
.Where((t, m) => t.CREATE_USER == UserCode
|
&& t.WAREHOUSECODE.ToUpper() == WarehouseCode.ToUpper()
|
&& t.STATUS == WMS_ITEM.STATUSs.Counted.GetValue()
|
&& t.ITEM_CODE.ToUpper() == MaterialCode.ToUpper()
|
&& t.BUSINESSCODE == UserCode)
|
.Select((t, m) => new Model.Minsun.CustSupplyCheckDetail
|
{
|
Barcode = t.SN,
|
BarcodeQty = t.QTY,
|
Unit = m.UNIT
|
})
|
.ToListAsync();
|
return new PageAble<Model.Minsun.CustSupplyCheckDetail>()
|
{
|
data = query,
|
totals = query.Count(),
|
};
|
}
|
|
#endregion Functions
|
|
public override bool Close(bool needSaveHistoryLog = false)
|
{
|
//保存操作日志
|
|
this.IsFinished = true;
|
return IsFinished ? base.Close(needSaveHistoryLog) : IsFinished;
|
}
|
}//endClass
|
}
|