You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2080 lines
137 KiB
2080 lines
137 KiB
using ICSSoft.Common;
|
|
using ICSSoft.Entity;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ICSSoft.DataProject
|
|
{
|
|
/// <summary>
|
|
/// 使用中
|
|
/// 更新库存表、日志表
|
|
/// </summary>
|
|
public class ICSWareHouseLotInfoService
|
|
{
|
|
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
/// <summary>
|
|
/// 分批
|
|
/// </summary>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="TransCode"></param>
|
|
/// <param name="TransSequence"></param>
|
|
/// <param name="LotNo"></param>
|
|
/// <param name="Quantity"></param>
|
|
/// <param name="User"></param>
|
|
/// <param name="WorkPoint"></param>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="BusinessCode"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void WareHouseLotInfoInBatches(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
|
|
string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID = "")
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 添加库存
|
|
/// </summary>
|
|
/// <param name="LocationCode"></param>
|
|
/// <param name="LotNo"></param>
|
|
/// <param name="Quantity"></param>
|
|
/// <param name="User"></param>
|
|
/// <param name="WorkPoint"></param>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="BusinessCode"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void WareHouseLotInfoUp(string Identification, string LocationCode, string LotNo, string Quantity, string User,
|
|
string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string LogID, string InvCode)
|
|
{
|
|
try
|
|
{
|
|
|
|
|
|
#region 添加库存(原条码退回,更新库存;新条码直接入库)
|
|
string sql = string.Empty;
|
|
if (BusinessCode != TransTypeEnum.SalesReturnBack.GetDescription<DBValue>()
|
|
&& string.IsNullOrWhiteSpace(LogID))
|
|
{
|
|
sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
|
|
RETURN
|
|
END ";
|
|
}
|
|
//sql += @"
|
|
// IF NOT EXISTS(SELECT 1
|
|
// FROM ICSMO a
|
|
// INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.MoCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
|
|
// INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
|
|
// INNER JOIN ICSExtension d ON d.ID=c.ExtensionID AND d.WorkPoint=c.WorkPoint
|
|
// INNER JOIN ICSBackflushBCLog bclog ON a.MOCode=bclog.TransCode AND a.Sequence=bclog.TransSequence AND bclog.BatchCode=d.BatchCode
|
|
// WHERE c.LotNo='{0}')
|
|
// BEGIN
|
|
// RAISERROR('" + language.GetNameByCode("WMSAPIInfo468") + @"',16,1);
|
|
// END
|
|
// ";
|
|
sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
|
|
BEGIN
|
|
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
UPDATE ICSInventoryLot SET Quantity = '{3}' WHERE LotNo='{0}' AND WorkPoint = '{1}'
|
|
|
|
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
|
|
BEGIN
|
|
-- UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
|
|
UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL({3},0) WHERE LotNo='{0}' AND WorkPoint='{1}'
|
|
END
|
|
ELSE
|
|
BEGIN
|
|
IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
|
|
INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
|
|
WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
|
|
BEGIN
|
|
IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
|
|
INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
|
|
WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
|
|
RETURN
|
|
END
|
|
END
|
|
INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
|
|
SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
--INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
|
|
INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
END";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
|
|
}
|
|
|
|
List<ControlMode> mode = ICSControlModeService.GetControlModes();
|
|
//管控方式启用"料品"时
|
|
//if (mode.itemCode.Equals("ControlMode02"))
|
|
//{
|
|
|
|
//}
|
|
|
|
///添加日志
|
|
sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1,LogID)
|
|
SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
|
|
'','',c.WarehouseCode,c.LocationCode,'{6}',
|
|
'','0','{4}','{5}','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,a.WorkPoint ,'','{7}'
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region 生产入库,倒冲
|
|
if (BusinessCode.Equals(TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>()))
|
|
{
|
|
#region 原sql
|
|
// sql = @"-- 1.创建临时表 初始单据数据 maintemp
|
|
// select
|
|
// c.mocode as transcode,
|
|
// a.modetailid as detailid,
|
|
// a.invcode,
|
|
// b.invname,
|
|
// b.invstd,
|
|
// a.quantity,
|
|
// a.amount,
|
|
// a.sequence as transsequence,
|
|
// a.issuequantity,
|
|
// c.sequence,
|
|
// inv.invunit,
|
|
// 0 as locationqty,
|
|
// inv.amountunit,
|
|
// a.extensionid,
|
|
// a.workpoint,
|
|
// ext.projectcode,
|
|
// case when isnull(inv.batchenable, '0')='1' then ext.batchcode else '' end as batchcode,
|
|
// ext.version,
|
|
// ext.brand,
|
|
// ext.cfree1,
|
|
// ext.cfree2,
|
|
// ext.cfree3,
|
|
// ext.cfree4,
|
|
// ext.cfree5,
|
|
// ext.cfree6,
|
|
// ext.cfree7,
|
|
// ext.cfree8,
|
|
// ext.cfree9,
|
|
// ext.cfree10
|
|
// into #maintemp
|
|
//
|
|
// from
|
|
// icsmopick a
|
|
// inner join icsmo c on a.modetailid=c.modetailid and a.workpoint=c.workpoint
|
|
// left join icsinventory b on a.invcode = b.invcode and a.workpoint=b.workpoint
|
|
// inner join icsextension ext on a.extensionid=ext.id and a.workpoint=ext.workpoint
|
|
// inner join icsinventory inv on a.invcode=inv.invcode and a.workpoint=inv.workpoint
|
|
// inner join (
|
|
// select a.mocode,a.sequence,a.workpoint
|
|
// from icsmo a
|
|
// inner join icsinventorylotdetail b on b.transcode=a.mocode and b.transsequence=a.sequence and b.workpoint=a.workpoint
|
|
// inner join icsinventorylot c on c.lotno=b.lotno and c.workpoint=b.workpoint
|
|
// where c.lotno='{0}' and c.workpoint='{1}'
|
|
// ) temp on c.mocode=temp.mocode and a.workpoint=temp.workpoint and c.sequence=temp.sequence
|
|
// --where a.supplytype='1'
|
|
// group by c.mocode,a.quantity,a.invcode,b.invname,b.invstd,a.whcode,a.extensionid,a.workpoint,inv.batchenable,a.modetailid,a.amount,a.sequence,a.issuequantity,inv.invname,inv.invcode,inv.invunit,inv.amountunit,c.sequence,
|
|
// ext.projectcode,ext.batchcode,ext.version,ext.brand,ext.cfree1,ext.cfree2,ext.cfree3,ext.cfree4,ext.cfree5,ext.cfree6,ext.cfree7,ext.cfree8,ext.cfree9,ext.cfree10;
|
|
//
|
|
// select * into #resulttemp from #maintemp
|
|
// alter table #resulttemp add lotno varchar(50)
|
|
// delete from #resulttemp
|
|
//
|
|
// -- 2.根据maintemp 中的物料信息 查出库存中对应的条码信息 barcodetemp
|
|
// select a.lotno,a.invcode,(a.quantity-a.lockquantity) as quantity ,a.mtime into #barcodetemp from icswarehouselotinfo a left join
|
|
// (select #maintemp.invcode from #maintemp group by #maintemp.invcode) b on a.invcode = b.invcode where a.quantity-a.lockquantity>0 order by a.mtime asc
|
|
//
|
|
// -- 3.循环maintemp,根据 行号和子表id 向最终结果集中写入数据 ;barcodetemp 中的已匹配数据删除或更新
|
|
// begin
|
|
// declare @transsequence int;--当前循环的行号
|
|
// declare @qty int;--条码表数量
|
|
// declare @needqty int;--本行所需数量
|
|
// declare @lotno varchar(50);--条码
|
|
// declare @detailid varchar(50);--本行所在工单行id
|
|
// declare tempcursor cursor for (select transsequence,detailid from #maintemp); --创建游标tempcursor,并定义游标所指向的集合
|
|
// open tempcursor; --打开游标
|
|
// fetch next from tempcursor into @transsequence,@detailid; --游标读取下一个数据
|
|
// while @@fetch_status=0
|
|
// begin
|
|
// select @needqty=quantity from #maintemp where transsequence = @transsequence and detailid = @detailid
|
|
// print @transsequence
|
|
// while @needqty>0
|
|
// begin
|
|
//
|
|
// select top 1 @qty = quantity,@lotno = lotno from #barcodetemp where invcode = (select invcode from #maintemp where transsequence = @transsequence and detailid = @detailid) order by mtime
|
|
// if(@needqty-@qty>=0)
|
|
// begin
|
|
// insert into #resulttemp (lotno,transcode,detailid,sequence,transsequence,issuequantity,quantity,
|
|
// amount,invcode,invname,invstd,invunit,locationqty,amountunit,
|
|
// extensionid,projectcode,batchcode, version,brand,cfree1,cfree2,cfree3,cfree4,cfree5,cfree6,cfree7,cfree8,cfree9,cfree10,workpoint)
|
|
// select @lotno,transcode,detailid,sequence,transsequence,issuequantity, quantity,
|
|
// isnull(amount, 0), invcode,invname,isnull(invstd, ''),invunit,@qty,isnull(amountunit, ''),
|
|
// extensionid,projectcode,batchcode, version,brand,cfree1,cfree2,cfree3,cfree4,cfree5,cfree6,cfree7,cfree8,cfree9,cfree10,workpoint from #maintemp
|
|
// where #maintemp.transsequence = @transsequence and detailid = @detailid
|
|
// delete from #barcodetemp where lotno = @lotno
|
|
// set @needqty=@needqty-@qty
|
|
// end
|
|
// else
|
|
// begin
|
|
// insert into #resulttemp (lotno,transcode,detailid,sequence,transsequence,issuequantity,quantity,
|
|
// amount,invcode,invname,invstd,invunit,locationqty,amountunit,
|
|
// extensionid,projectcode,batchcode, version,brand,cfree1,cfree2,cfree3,cfree4,cfree5,cfree6,cfree7,cfree8,cfree9,cfree10,workpoint)
|
|
// select @lotno,transcode,detailid,sequence,transsequence,issuequantity, quantity,
|
|
// isnull(amount, 0),invcode,invname,isnull(invstd, ''),invunit,@needqty,isnull(amountunit, ''),
|
|
// extensionid,projectcode,batchcode, version,brand,cfree1,cfree2,cfree3,cfree4,cfree5,cfree6,cfree7,cfree8,cfree9,cfree10,workpoint from #maintemp
|
|
// where #maintemp.transsequence = @transsequence and detailid = @detailid
|
|
// update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
|
|
// set @needqty=@needqty-@qty
|
|
// end
|
|
// end
|
|
// fetch next from tempcursor into @transsequence,@detailid;
|
|
// end
|
|
// close tempcursor
|
|
// deallocate tempcursor
|
|
// end
|
|
//
|
|
// select transcode,lotno,locationqty as quantity,invcode,detailid,sequence,transsequence from #resulttemp
|
|
// --select * from #resulttemp
|
|
//
|
|
// drop table #maintemp
|
|
// drop table #resulttemp
|
|
// drop table #barcodetemp";
|
|
#endregion
|
|
sql = @"SELECT DISTINCT b.lotno,d.invcode
|
|
FROM ICSMO a
|
|
INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.MOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
|
|
INNER JOIN ICSMOPick d ON a.MODetailID=d.MODetailID AND a.WorkPoint=d.WorkPoint
|
|
WHERE b.LotNo='{0}' AND (d.invcode like'1%' or d.invcode like'2%') AND a.WorkPoint='{1}'";
|
|
sql = String.Format(sql, LotNo, WorkPoint);
|
|
DataTable table2 = DBHelper.SQlReturnData(sql, cmd);
|
|
if (table2 != null)
|
|
{
|
|
#region sql(子件为成品)
|
|
sql = @"-- 1.创建临时表 初始单据数据 maintemp
|
|
SELECT
|
|
c.MOCode AS TransCode,
|
|
a.MODetailID AS DetailID,
|
|
a.WHCode,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
(a.Quantity/c.Quantity*temp.Quantity) as Quantity,
|
|
a.Amount,
|
|
a.Sequence AS TransSequence,
|
|
a.IssueQuantity,
|
|
c.Sequence,
|
|
inv.InvUnit,
|
|
0 AS LocationQty,
|
|
inv.AmountUnit,
|
|
a.ExtensionID,
|
|
a.WorkPoint,
|
|
ext.ProjectCode,
|
|
CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS cBatchCode,
|
|
ext.Version,
|
|
ext.Brand,
|
|
ext.cFree1,
|
|
ext.cFree2,
|
|
ext.cFree3,
|
|
ext.cFree4,
|
|
ext.cFree5,
|
|
ext.cFree6,
|
|
ext.cFree7,
|
|
ext.cFree8,
|
|
ext.cFree9,
|
|
ext.cFree10,
|
|
temp.BatchCode
|
|
INTO #maintemp
|
|
|
|
FROM
|
|
ICSMOPick a
|
|
inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
|
|
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
|
|
INNER JOIN (
|
|
SELECT a.MOCode,a.Sequence,a.WorkPoint,d.BatchCode,c.Quantity
|
|
FROM ICSMO a
|
|
INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.MOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
|
|
INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
|
|
LEFT JOIN ICSExtension d ON c.ExtensionID=d.ID AND a.WorkPoint=d.WorkPoint
|
|
WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'
|
|
) temp ON c.MOCode=temp.MOCode AND a.WorkPoint=temp.WorkPoint AND c.Sequence=temp.Sequence
|
|
WHERE a.SupplyType='1'
|
|
GROUP BY c.MOCode,a.Quantity,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID,a.WorkPoint,inv.BatchEnable,a.MODetailID,a.Amount,a.Sequence,a.IssueQuantity,inv.InvName,inv.InvCode,inv.InvUnit,inv.AmountUnit,c.Sequence,
|
|
ext.ProjectCode,ext.BatchCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,temp.BatchCode,c.Quantity,temp.Quantity;
|
|
|
|
|
|
select * into #resulttemp from #maintemp
|
|
ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
|
|
delete from #resulttemp
|
|
|
|
-- 2.根据maintemp 中的物料信息 查出库存中对应的条码信息 barcodetemp
|
|
select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime,ext.BatchCode into #barcodetemp from ICSWareHouseLotInfo a inner JOIN
|
|
(select #maintemp.invcode,#maintemp.WHCode from #maintemp group by #maintemp.InvCode,#maintemp.WHCode) b on a.invcode = b.invcode and a.WarehouseCode=b.WHCode
|
|
LEFT JOIN ICSInventoryLot lot on a.lotno=lot.lotno and a.WorkPoint=lot.WorkPoint
|
|
LEFT JOIN ICSExtension ext on lot.ExtensionID=ext.ID and a.WorkPoint=ext.WorkPoint
|
|
where a.Quantity-a.lockQuantity>0 and a.WorkPoint='{1}' ORDER BY a.MTIME ASC
|
|
|
|
-- 3.循环maintemp,根据 行号和子表ID 向最终结果集中写入数据 ;barcodetemp 中的已匹配数据删除或更新
|
|
BEGIN
|
|
DECLARE @transSequence int;--当前循环的行号
|
|
DECLARE @qty int;--条码表数量
|
|
DECLARE @needqty int;--本行所需数量
|
|
DECLARE @lotno VARCHAR(50);--条码
|
|
DECLARE @batch VARCHAR(50);--条码
|
|
DECLARE @DetailID VARCHAR(50);--本行所在工单行ID
|
|
DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --创建游标tempCursor,并定义游标所指向的集合
|
|
OPEN tempCursor; --打开游标
|
|
FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --游标读取下一个数据
|
|
WHILE @@fetch_status=0
|
|
BEGIN
|
|
select @needqty=Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
|
|
PRINT @transSequence
|
|
WHILE @needqty>0
|
|
BEGIN
|
|
select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,''), @batch=ISNULL(BatchCode, '') from #barcodetemp a
|
|
RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a.invcode=b.invcode ORDER BY mtime
|
|
BEGIN
|
|
--IF(@needqty-@qty>=0)
|
|
IF(@needqty-@qty>0 and ISNULL(@lotno, '')<>'')
|
|
BEGIN
|
|
insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
|
|
Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
|
|
ExtensionID,ProjectCode,cBatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,BatchCode)
|
|
SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
|
|
ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
|
|
ExtensionID,ProjectCode,@batch, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,BatchCode from #maintemp
|
|
where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
|
|
delete from #barcodetemp where lotno = @lotno
|
|
SET @needqty=@needqty-@qty
|
|
END
|
|
ELSE
|
|
BEGIN
|
|
insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
|
|
Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
|
|
ExtensionID,ProjectCode,cBatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,BatchCode)
|
|
SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
|
|
ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
|
|
ExtensionID,ProjectCode,@batch, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,BatchCode from #maintemp
|
|
where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
|
|
SET @needqty=0
|
|
END
|
|
END
|
|
END
|
|
FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
|
|
END
|
|
CLOSE tempCursor
|
|
DEALLOCATE tempCursor
|
|
END
|
|
|
|
select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence,cBatchCode,BatchCode from #resulttemp
|
|
--select * from #resulttemp
|
|
|
|
DROP table #maintemp
|
|
DROP table #resulttemp
|
|
DROP table #barcodetemp";
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
#region sql(子件为原料)
|
|
sql = @"SELECT DISTINCT a.MOCode as TransCode,a.Sequence,d.Sequence as TransSequence,d.invcode,a.WorkPoint,
|
|
d.MODetailID as DetailID,e.BatchCode,{2} as Quantity
|
|
FROM ICSMO a
|
|
INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.MOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
|
|
INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSMOPick d ON a.MODetailID=d.MODetailID AND a.WorkPoint=d.WorkPoint
|
|
INNER JOIN ICSExtension e ON c.ExtensionID=e.ID AND a.WorkPoint=e.WorkPoint
|
|
WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'";
|
|
#endregion
|
|
}
|
|
sql = String.Format(sql, LotNo, WorkPoint, Quantity);
|
|
DataTable table = DBHelper.SQlReturnData(sql, cmd);
|
|
string json = JsonConvert.SerializeObject(table);
|
|
List<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(json);
|
|
foreach (DownItemModel model in downItemModels)
|
|
{
|
|
WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, Quantity, User, WorkPoint, "30", model.InvCode, model.BatchCode, model.cBatchCode, BusinessCode, cmd, language);
|
|
//回写已领数量
|
|
//sql = @"UPDATE ICSMOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)" + model.Quantity + ") WHERE MODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
|
|
sql = @"UPDATE ICSMOPick SET IssueQuantity=case WHEN " + model.Quantity + "<>0 and " + model.Quantity + " is not NULL THEN ISNULL(IssueQuantity,0)+" + model.Quantity + " ELSE ISNULL(IssueQuantity,0) end WHERE MODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
|
|
sql = String.Format(sql, model.DetailID, model.TransSequence, WorkPoint);
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("回写已领数量失败"));
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 委外入库,倒冲
|
|
if (BusinessCode.Equals(TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>()))
|
|
{
|
|
#region sql
|
|
sql = @"-- 1.创建临时表 初始单据数据 maintemp
|
|
SELECT
|
|
c.OOCode AS TransCode,
|
|
a.OODetailID AS DetailID,
|
|
a.InvCode,
|
|
b.InvName,
|
|
b.InvStd,
|
|
a.Quantity,
|
|
a.Amount,
|
|
a.Sequence AS TransSequence,
|
|
a.IssueQuantity,
|
|
c.Sequence,
|
|
inv.InvUnit,
|
|
0 AS LocationQty,
|
|
inv.AmountUnit,
|
|
a.ExtensionID,
|
|
a.WorkPoint,
|
|
ext.ProjectCode,
|
|
CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
|
|
ext.Version,
|
|
ext.Brand,
|
|
ext.cFree1,
|
|
ext.cFree2,
|
|
ext.cFree3,
|
|
ext.cFree4,
|
|
ext.cFree5,
|
|
ext.cFree6,
|
|
ext.cFree7,
|
|
ext.cFree8,
|
|
ext.cFree9,
|
|
ext.cFree10
|
|
INTO #maintemp
|
|
|
|
FROM
|
|
ICSOOPick a
|
|
inner join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
|
|
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
|
|
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
|
|
INNER JOIN (
|
|
SELECT a.OOCode,a.Sequence,a.WorkPoint
|
|
FROM ICSOutsourcingOrder a
|
|
INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.OOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
|
|
INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
|
|
WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'
|
|
) temp ON c.OOCode=temp.OOCode AND a.WorkPoint=temp.WorkPoint AND c.Sequence=temp.Sequence
|
|
WHERE a.SupplyType='1'
|
|
GROUP BY c.OOCode,a.Quantity,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID,a.WorkPoint,inv.BatchEnable,a.OODetailID,a.Amount,a.Sequence,a.IssueQuantity,inv.InvName,inv.InvCode,inv.InvUnit,inv.AmountUnit,c.Sequence,
|
|
ext.ProjectCode,ext.BatchCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10;
|
|
|
|
select * into #resulttemp from #maintemp
|
|
ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
|
|
delete from #resulttemp
|
|
|
|
-- 2.根据maintemp 中的物料信息 查出库存中对应的条码信息 barcodetemp
|
|
select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime into #barcodetemp from ICSWareHouseLotInfo a LEFT JOIN
|
|
(select #maintemp.invcode from #maintemp group by #maintemp.InvCode) b on a.invcode = b.invcode where a.Quantity-a.lockQuantity>0 ORDER BY a.MTIME ASC
|
|
|
|
-- 3.循环maintemp,根据 行号和子表ID 向最终结果集中写入数据 ;barcodetemp 中的已匹配数据删除或更新
|
|
BEGIN
|
|
DECLARE @transSequence int;--当前循环的行号
|
|
DECLARE @qty int;--条码表数量
|
|
DECLARE @needqty int;--本行所需数量
|
|
DECLARE @lotno VARCHAR(50);--条码
|
|
DECLARE @DetailID VARCHAR(50);--本行所在工单行ID
|
|
DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --创建游标tempCursor,并定义游标所指向的集合
|
|
OPEN tempCursor; --打开游标
|
|
FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --游标读取下一个数据
|
|
WHILE @@fetch_status=0
|
|
BEGIN
|
|
select @needqty=Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
|
|
PRINT @transSequence
|
|
WHILE @needqty>0
|
|
BEGIN
|
|
|
|
select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,'') from #barcodetemp a
|
|
RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a.invcode=b.invcode ORDER BY mtime
|
|
BEGIN
|
|
IF(@needqty-@qty>=0 and ISNULL(@lotno, '')<>'')
|
|
BEGIN
|
|
insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
|
|
Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
|
|
ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
|
|
SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
|
|
ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
|
|
ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
|
|
where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
|
|
delete from #barcodetemp where lotno = @lotno
|
|
SET @needqty=@needqty-@qty
|
|
END
|
|
ELSE IF(@needqty-@qty<0 and ISNULL(@lotno, '')<>'')
|
|
BEGIN
|
|
insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
|
|
Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
|
|
ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
|
|
SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
|
|
ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
|
|
ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
|
|
where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
|
|
update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
|
|
SET @needqty=@needqty-@qty
|
|
END
|
|
ELSE
|
|
BEGIN
|
|
insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
|
|
Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
|
|
ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
|
|
SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
|
|
ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,0,ISNULL(AmountUnit, ''),
|
|
ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
|
|
where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
|
|
|
|
SET @needqty=0
|
|
END
|
|
END
|
|
END
|
|
FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
|
|
END
|
|
CLOSE tempCursor
|
|
DEALLOCATE tempCursor
|
|
END
|
|
|
|
select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence from #resulttemp
|
|
--select * from #resulttemp
|
|
|
|
DROP table #maintemp
|
|
DROP table #resulttemp
|
|
DROP table #barcodetemp";
|
|
#endregion
|
|
sql = String.Format(sql, LotNo, WorkPoint);
|
|
DataTable table = DBHelper.SQlReturnData(sql, cmd);
|
|
string json = JsonConvert.SerializeObject(table);
|
|
List<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(json);
|
|
foreach (DownItemModel model in downItemModels)
|
|
{
|
|
WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, Quantity, User, WorkPoint, "12", model.InvCode, model.BatchCode, model.BatchCode, BusinessCode, cmd, language);
|
|
//回写已领数量
|
|
sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)" + model.Quantity + ") WHERE OODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
|
|
sql = String.Format(sql, model.DetailID, model.TransSequence, WorkPoint);
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 减少库存
|
|
/// </summary>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="TransCode"></param>
|
|
/// <param name="TransSequence"></param>
|
|
/// <param name="LotNo"></param>
|
|
/// <param name="Quantity"></param>
|
|
/// <param name="User"></param>
|
|
/// <param name="WorkPoint"></param>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="BusinessCode"></param>
|
|
/// <param name="cmd"></param>
|
|
public static DataTable WareHouseLotInfoDown(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity,string Qty, string User,
|
|
string WorkPoint, string TransType, string InvCode, string BatchCode, string cBatchCode, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID = "")
|
|
{
|
|
String LotEnable = "";
|
|
String PrintEnable = "";
|
|
string lotstr = "";
|
|
int result = 0;
|
|
List<string> NewBarCodeList = new List<string>();
|
|
DataTable dtLotno = new DataTable();
|
|
DataTable lstDt = new DataTable();
|
|
try
|
|
{
|
|
if (LotNo != null && LotNo != "")
|
|
{
|
|
///更新库存
|
|
string sql = "";
|
|
if (TransType == "30")
|
|
{
|
|
sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
|
|
|
|
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
|
|
RETURN
|
|
END";
|
|
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
|
|
}
|
|
else
|
|
{
|
|
sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
|
|
|
|
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
|
|
RETURN
|
|
END";
|
|
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
|
|
}
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
|
|
}
|
|
|
|
|
|
|
|
//检验是否分批
|
|
sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
|
|
LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
where a.LotNo='{0}' and a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint);
|
|
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
|
|
if (dt.Rows.Count == 0)
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
|
|
}
|
|
else
|
|
{
|
|
LotEnable = dt.Rows[0]["LotEnable"].ToString();
|
|
PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
|
|
}
|
|
if (LotEnable.Equals("True"))
|
|
{
|
|
///分批前添加日志
|
|
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
|
|
BEGIN
|
|
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1)
|
|
SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
|
|
'','',c.WarehouseCode,c.LocationCode,c.Quantity+{6},
|
|
'','0','{4}','31','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,a.WorkPoint ,''
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity);
|
|
|
|
log.Error("新增日志sql:" + sql);
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
|
|
}
|
|
#region 获取分批后的条码(lotstr)
|
|
sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
|
|
ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
|
|
sql = string.Format(sql, LotNo, WorkPoint);
|
|
dt = DBHelper.SQlReturnData(sql, cmd);
|
|
if (dt.Rows.Count == 0)
|
|
{
|
|
lotstr = LotNo + "-" + 1;
|
|
}
|
|
else
|
|
{
|
|
lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
|
|
}
|
|
NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
|
|
#endregion
|
|
|
|
#region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
|
|
sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
|
|
Quantity,Amount,ExtensionID,Type,PrintTimes,
|
|
LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
|
|
WorkPoint,EATTRIBUTE1)
|
|
SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
|
|
'{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
|
|
a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
|
|
a.WorkPoint ,'{1}'
|
|
From ICSInventoryLot a
|
|
where a.LotNo='{1}' and a.WorkPoint='{3}'";
|
|
sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
|
|
cmd.CommandText = sql;
|
|
result = cmd.ExecuteNonQuery();
|
|
if (result <= 0)
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
|
|
}
|
|
sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
|
|
select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'{2}',InDate,LockQuantity
|
|
,MUSER,MUSERName,GETDATE(),'{3}',''
|
|
from ICSWareHouseLotInfo
|
|
where LotNO='{1}' AND WorkPoint='{3}'";
|
|
sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
|
|
cmd.CommandText = sql;
|
|
result = cmd.ExecuteNonQuery();
|
|
if (result <= 0)
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
|
|
}
|
|
//插入条码单据表
|
|
sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
|
|
SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
|
|
}
|
|
sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1,LogID)
|
|
SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
|
|
c.WarehouseCode,c.LocationCode,'','','{6}',
|
|
'','0','{7}','105','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,a.WorkPoint ,'','{9}'
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
|
|
cmd.CommandText = sql;
|
|
result = cmd.ExecuteNonQuery();
|
|
if (result <= 0)
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
|
|
}
|
|
|
|
if (PrintEnable.Equals("True"))
|
|
{
|
|
sql = @"select A.LotNO AS OLDLotNo , C.Quantity AS OLDLotQty, A.eattribute1 as LotNO, B.Quantity AS LotQty ,b.InvCode,d.INVSTD,d.INVNAME,b.MTIME,A.TransCode
|
|
from ICSWareHouseLotInfolog A
|
|
left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
|
|
left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
|
|
left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
|
|
where a.BusinessCode ='105'
|
|
and A.lotno like'{0}%' and a.workpoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint);
|
|
dtLotno = DBHelper.SQlReturnData(sql, cmd);
|
|
lstDt = dtLotno;
|
|
}
|
|
|
|
///添加日志
|
|
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
|
|
BEGIN
|
|
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1,MergeID)
|
|
SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
|
|
c.WarehouseCode,c.LocationCode,'','',c.Quantity,
|
|
'','0','{7}','32','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,a.WorkPoint ,'','{9}'
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
NewBarCodeList.Add(LotNo);
|
|
|
|
///添加日志
|
|
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
|
|
BEGIN
|
|
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1,MergeID,EATTRIBUTE2,EATTRIBUTE4)
|
|
SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
|
|
c.WarehouseCode,c.LocationCode,'','','{6}',
|
|
'','0','{7}','{8}','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,a.WorkPoint ,'','{9}','{10}','{11}'
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, BatchCode, cBatchCode);
|
|
log.Error("新增日志sql:" + sql);
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
#region 添加wms没有库存的倒冲日志
|
|
string sql1 = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
|
|
BEGIN
|
|
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1,MergeID,EATTRIBUTE2)
|
|
SELECT NEWID(),'{3}','{4}','{5}','{0}' ,'{0}' ,
|
|
'','','','','{6}',
|
|
'','0','{7}','{8}','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,'{1}' ,'','{9}','{10}'
|
|
FROM Sys_SRM_User f
|
|
WHERE f.F_Account='{2}' AND f.F_Location='{1}'
|
|
";
|
|
sql1 = string.Format(sql1, InvCode, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, BatchCode);
|
|
log.Error("新增日志sql:" + sql1);
|
|
if (!DBHelper.ExecuteNonQuery(sql1, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
return lstDt;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改库存
|
|
/// </summary>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="TransCode"></param>
|
|
/// <param name="TransSequence"></param>
|
|
/// <param name="LotNo"></param>
|
|
/// <param name="Quantity"></param>
|
|
/// <param name="User"></param>
|
|
/// <param name="WorkPoint"></param>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void WareHouseLotInfoUpdate(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
|
|
string WorkPoint, string TransType, SqlCommand cmd, Dictionary<string, string> language)
|
|
{
|
|
try
|
|
{
|
|
///添加日志
|
|
string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
|
|
BEGIN
|
|
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1)
|
|
SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
|
|
a.WarehouseCode,a.LocationCode,'','',a.Quantity,
|
|
'盘点','0','{6}','{7}','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,a.WorkPoint ,''
|
|
FROM ICSWareHouseLotInfo a
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckBefore.GetDescription<DBValue>());
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
|
|
}
|
|
///更新库存
|
|
sql = @"UPDATE ICSWareHouseLotInfo SET Quantity='{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'";
|
|
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
|
|
}
|
|
///添加日志
|
|
sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1)
|
|
SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
|
|
a.WarehouseCode,a.LocationCode,'','',a.Quantity,
|
|
'盘点','0','{6}','{7}','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,a.WorkPoint ,''
|
|
FROM ICSWareHouseLotInfo a
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckAfter.GetDescription<DBValue>());
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 调拨
|
|
/// </summary>
|
|
/// <param name="LocationCode"></param>
|
|
/// <param name="LotNo"></param>
|
|
/// <param name="Quantity"></param>
|
|
/// <param name="User"></param>
|
|
/// <param name="WorkPoint"></param>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="BusinessCode"></param>
|
|
/// <param name="cmd"></param>
|
|
public static DataTable WareHouseLotInfoTransfer(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
|
|
string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID)
|
|
{
|
|
String LotEnable = "";
|
|
String PrintEnable = "";
|
|
string lotstr = "";
|
|
int result = 0;
|
|
DataTable dtLotno = new DataTable();
|
|
DataTable lstDt = new DataTable();
|
|
List<string> NewBarCodeList = new List<string>();
|
|
try
|
|
{
|
|
///分批前添加日志
|
|
string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
|
|
BEGIN
|
|
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1)
|
|
SELECT NEWID(),'{3}','{8}','{9}',a.LotNo ,a.InvCode ,
|
|
c.WarehouseCode,c.LocationCode,'{6}','{7}',c.Quantity,
|
|
'','0','{4}','31','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,a.WorkPoint ,''
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, WarehouseCode, LocationCode, TransCode, TransSequence);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
|
|
}
|
|
//检验是否分批
|
|
sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
|
|
LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
where a.LotNo='{0}' and a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint);
|
|
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
|
|
if (dt.Rows.Count == 0)
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
|
|
}
|
|
else
|
|
{
|
|
LotEnable = dt.Rows[0]["LotEnable"].ToString();
|
|
PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
|
|
}
|
|
if (!LotEnable.Equals("False"))
|
|
{
|
|
#region 获取分批后的条码(lotstr)
|
|
sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
|
|
ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
|
|
sql = string.Format(sql, LotNo, WorkPoint);
|
|
dt = DBHelper.SQlReturnData(sql, cmd);
|
|
if (dt.Rows.Count == 0)
|
|
{
|
|
lotstr = LotNo + "-" + 1;
|
|
}
|
|
else
|
|
{
|
|
lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
|
|
}
|
|
NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
|
|
#endregion
|
|
|
|
#region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
|
|
sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
|
|
Quantity,Amount,ExtensionID,Type,PrintTimes,
|
|
LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
|
|
WorkPoint,EATTRIBUTE1)
|
|
SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
|
|
'{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
|
|
a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
|
|
a.WorkPoint ,'{1}'
|
|
From ICSInventoryLot a
|
|
where a.LotNo='{1}' and a.WorkPoint='{3}'";
|
|
sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
|
|
cmd.CommandText = sql;
|
|
result = cmd.ExecuteNonQuery();
|
|
if (result <= 0)
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
|
|
}
|
|
#endregion
|
|
sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
|
|
select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'{2}',InDate,LockQuantity
|
|
,MUSER,MUSERName,GETDATE(),'{3}',''
|
|
from ICSWareHouseLotInfo
|
|
where LotNO='{1}' AND WorkPoint='{3}'";
|
|
sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
|
|
cmd.CommandText = sql;
|
|
result = cmd.ExecuteNonQuery();
|
|
if (result <= 0)
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
|
|
}
|
|
//插入条码单据表
|
|
sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
|
|
SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
|
|
}
|
|
sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1,LogID)
|
|
SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
|
|
c.WarehouseCode,c.LocationCode,'','','{6}',
|
|
'','0','{7}','105','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,a.WorkPoint ,'','{9}'
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
|
|
cmd.CommandText = sql;
|
|
result = cmd.ExecuteNonQuery();
|
|
if (result <= 0)
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
|
|
}
|
|
///添加日志
|
|
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
|
|
BEGIN
|
|
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
IF EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE WarehouseCode='{9}' AND LocationCode='{10}' AND WorkPoint='{1}' AND LotNo = '{0}')
|
|
BEGIN
|
|
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo355")) + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1,MergeID)
|
|
SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
|
|
c.WarehouseCode,c.LocationCode,'{9}','{10}',{6},
|
|
'','0','{7}','32','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,a.WorkPoint ,'','{11}'
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode, MergeID);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
|
|
}
|
|
if (PrintEnable.Equals("True"))
|
|
{
|
|
sql = @"select A.LotNO AS OLDLotNo , C.Quantity AS OLDLotQty, A.eattribute1 as LotNO, B.Quantity AS LotQty ,b.InvCode,d.INVSTD,d.INVNAME,b.MTIME,A.TransCode
|
|
from ICSWareHouseLotInfolog A
|
|
left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
|
|
left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
|
|
left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
|
|
where a.BusinessCode ='105'
|
|
and A.lotno like'{0}%' and a.workpoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint);
|
|
dtLotno = DBHelper.SQlReturnData(sql, cmd);
|
|
lstDt = dtLotno;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
///添加日志
|
|
// sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
|
|
// BEGIN
|
|
// RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
|
|
// RETURN
|
|
// END
|
|
//
|
|
// IF EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE WarehouseCode='{9}' AND LocationCode='{10}' AND WorkPoint='{1}' AND LotNo = '{0}')
|
|
// BEGIN
|
|
// RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo355")) + @"',16,1);
|
|
// RETURN
|
|
// END
|
|
//
|
|
// INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
// FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
// Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
// ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
// MTIME,WorkPoint,EATTRIBUTE1,MergeID)
|
|
// SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
|
|
// c.WarehouseCode,c.LocationCode,'{9}','{10}',{6},
|
|
// '','0','{7}','{8}','0','',
|
|
// '','','',f.F_Account ,f.F_RealName ,
|
|
// SYSDATETIME() ,a.WorkPoint ,'','{11}'
|
|
// FROM ICSInventoryLot a
|
|
// INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
|
|
// INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
// WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
// ";
|
|
// sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode, MergeID);
|
|
|
|
// if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
// {
|
|
// throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
|
|
// }
|
|
}
|
|
|
|
///添加库存
|
|
sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity>0)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
|
|
RETURN
|
|
END
|
|
IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}' AND a.Quantity<{4})
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode, Quantity);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
return lstDt;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 移库
|
|
/// </summary>
|
|
/// <param name="LocationCode"></param>
|
|
/// <param name="LotNo"></param>
|
|
/// <param name="Quantity"></param>
|
|
/// <param name="User"></param>
|
|
/// <param name="WorkPoint"></param>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="BusinessCode"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void WareHouseLotInfoLibrary(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
|
|
string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
|
|
{
|
|
try
|
|
{
|
|
///添加日志
|
|
string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
|
|
BEGIN
|
|
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1)
|
|
SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
|
|
c.WarehouseCode,c.LocationCode,'{8}','{9}',c.Quantity,
|
|
'','0','{6}','{7}','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,a.WorkPoint ,''
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, BusinessCode, WarehouseCode, LocationCode);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
|
|
}
|
|
///添加库存
|
|
sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity>0)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 两步调入
|
|
/// </summary>
|
|
/// <param name="LocationCode"></param>
|
|
/// <param name="LotNo"></param>
|
|
/// <param name="Quantity"></param>
|
|
/// <param name="User"></param>
|
|
/// <param name="WorkPoint"></param>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="BusinessCode"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void WareHouseLotInfoTwoStepTransferDocIn(string Identification, string TransCode, string TransSequence, string WarehouseCode,
|
|
string LocationCode, string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
|
|
{
|
|
try
|
|
{
|
|
///添加日志
|
|
string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
|
|
BEGIN
|
|
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1)
|
|
SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
|
|
c.WarehouseCode,c.LocationCode,'{9}','{10}','{6}',
|
|
'','0','{7}','{8}','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,a.WorkPoint ,''
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
|
|
}
|
|
///添加库存
|
|
sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}',Quantity='{4}' WHERE LotNo='{0}' AND WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode, Quantity);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 拆分、合并日志
|
|
/// </summary>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="LotNo"></param>
|
|
/// <param name="User"></param>
|
|
/// <param name="WorkPoint"></param>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="BusinessCode"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void WareHouseLotInfoLog(string Identification, string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
|
|
{
|
|
try
|
|
{
|
|
///添加日志
|
|
string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
|
|
BEGIN
|
|
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1)
|
|
SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
|
|
'','',c.WarehouseCode,c.LocationCode,c.Quantity,
|
|
'','0','{4}','{5}','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,a.WorkPoint ,''
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 合并
|
|
/// </summary>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="LotNo"></param>
|
|
/// <param name="User"></param>
|
|
/// <param name="WorkPoint"></param>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="BusinessCode"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void WareHouseLotInfoMerge(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
|
|
string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
|
|
{
|
|
try
|
|
{
|
|
///更新目标条码库存
|
|
string sql = @"IF NOT EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLot b ON b.LotNo='{3}' AND a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo170") + @"',16,1);
|
|
RETURN
|
|
END
|
|
IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
|
|
RETURN
|
|
END
|
|
IF NOT EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
|
|
INNER JOIN ICSExtension b ON a.ExtensionID=b.ID AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN (SELECT a.LotNo,b.BatchCode,a.WorkPoint from ICSInventoryLot a
|
|
INNER JOIN ICSExtension b on a.ExtensionID=b.ID AND a.WorkPoint=b.WorkPoint where a.LotNo='{3}' ) c ON b.BatchCode=c.BatchCode and a.WorkPoint=c.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo199") + @"',16,1);
|
|
RETURN
|
|
END
|
|
IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a
|
|
INNER JOIN ICSWareHouseLotInfo b ON b.LotNo='{3}' AND a.LocationCode=b.LocationCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo200") + @"',16,1);
|
|
RETURN
|
|
END
|
|
UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, LotNo, WorkPoint, Quantity, CurrentLotNo);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo169"));//"目标条码库存更新失败!");
|
|
}
|
|
///更新原条码库存
|
|
sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
|
|
|
|
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
|
|
RETURN
|
|
END";
|
|
sql = string.Format(sql, CurrentLotNo, WorkPoint, Quantity);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
|
|
}
|
|
///添加日志
|
|
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
|
|
BEGIN
|
|
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1)
|
|
SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
|
|
'','',c.WarehouseCode,c.LocationCode,c.Quantity,
|
|
'','0','{4}','{5}','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,a.WorkPoint ,''
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 拆分
|
|
/// </summary>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="LotNo"></param>
|
|
/// <param name="User"></param>
|
|
/// <param name="WorkPoint"></param>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="BusinessCode"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void WareHouseLotInfoSplit(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
|
|
string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
|
|
{
|
|
try
|
|
{
|
|
///更新库存
|
|
string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
|
|
|
|
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
|
|
RETURN
|
|
END";
|
|
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
|
|
}
|
|
#region 添加库存
|
|
//插入条码表
|
|
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
|
|
BEGIN
|
|
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a WHERE a.LotNo='{4}' AND a.WorkPoint='{1}')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo172") + @"',16,1);
|
|
RETURN
|
|
END
|
|
INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
|
|
SELECT NEWID(),'{4}' ,a.InvCode,a.ProductDate,a.ExpirationDate ,'{3}',a.ExtensionID,'101',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,a.LotNo
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, CurrentLotNo);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo173"));//"条码表写入失败!");
|
|
}
|
|
//插入条码单据表
|
|
sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
|
|
SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, CurrentLotNo);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
|
|
}
|
|
///添加库存
|
|
sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
|
|
RETURN
|
|
END
|
|
IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
|
|
INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
|
|
WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
|
|
BEGIN
|
|
IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
|
|
INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint AND il.LocationCode=d.LocationCode
|
|
WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
|
|
RETURN
|
|
END
|
|
END
|
|
INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
|
|
SELECT NEWID(),a.LotNo ,d.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
|
|
sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Quantity);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
|
|
}
|
|
///添加日志
|
|
sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
|
|
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
|
|
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
|
|
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
|
|
MTIME,WorkPoint,EATTRIBUTE1)
|
|
SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
|
|
'','',c.WarehouseCode,c.LocationCode,c.Quantity,
|
|
'','0','{4}','{5}','0','',
|
|
'','','',f.F_Account ,f.F_RealName ,
|
|
SYSDATETIME() ,a.WorkPoint ,''
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
|
|
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
|
|
";
|
|
sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
|
|
}
|
|
#endregion
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 回写ERP ID
|
|
/// </summary>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="SourceDetailID"></param>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="ID"></param>
|
|
/// <param name="DetailID"></param>
|
|
/// <param name="Code"></param>
|
|
/// <param name="Sequence"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void WareHouseLotInfoLogUpdate(string TransType, string SourceDetailID, string Identification, string ID, string DetailID, string Code, string Sequence, SqlCommand cmd, Dictionary<string, string> language)
|
|
{
|
|
string ERPupdate = string.Empty;
|
|
try
|
|
{
|
|
//采购入库
|
|
if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.PODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//审核的到货单
|
|
else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//采购拒收
|
|
else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//审核的委外到货单
|
|
else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//委外拒收
|
|
else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//采购退货
|
|
else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSDeliveryNotice c ON a.TransCode=c.DNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DNType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//委外发料
|
|
else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint
|
|
INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
|
|
WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//委外退料
|
|
else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
|
|
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
|
|
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
|
|
{
|
|
ERPupdate = @"--根据退料单退料
|
|
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
|
|
Left JOIN ICSOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
|
|
WHERE ISNULL(m.ApplyDetailID,ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
--根据原条码退料-备料表
|
|
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint
|
|
INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
|
|
WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
--根据原条码退料-申请单
|
|
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
|
|
WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
--根据原条码退料-材料出库单
|
|
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
|
|
LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
|
|
LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
|
|
LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
|
|
WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//委外入库
|
|
else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.OODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//委外退货
|
|
else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSODeliveryNotice c ON a.TransCode=c.ODNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.ODNType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//生产发料
|
|
else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
|
|
INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
|
|
WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//生产退料
|
|
else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
|
|
|| TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
|
|
|| TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
|
|
{
|
|
ERPupdate = @"--根据退料单退料
|
|
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
|
|
left JOIN ICSMOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
|
|
WHERE ISNULL(m.ApplyDetailID, ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
--根据原条码退料-备料表
|
|
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
|
|
INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
|
|
WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
--根据原条码退料-申请单
|
|
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
|
|
WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
--根据原条码退料-材料出库单
|
|
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
|
|
LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
|
|
LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
|
|
LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
|
|
WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//生产入库
|
|
else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.MODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//开立的生产入库单
|
|
else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//销售出库
|
|
else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//销售退货
|
|
else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
|
|
//返工工单
|
|
else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
|
|
INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
|
|
WHERE d.PickID='{3}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//一步调拨
|
|
else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//调拨
|
|
else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//两步调出
|
|
else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
INNER JOIN ICSTransfer d ON c.TransferDetailID=d.TransferDetailID AND c.WorkPoint=d.WorkPoint
|
|
WHERE c.OutID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//两步调入
|
|
else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
|
|
WHERE b.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//销售退货-原条码
|
|
else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//其他出库
|
|
else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.OutID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//其他入库
|
|
else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE c.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//拆卸单
|
|
else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE d set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
|
|
WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND d.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
|
|
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DABDOCType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//领料申请单
|
|
else if (TransType == TransTypeEnum.MOApply.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//委外领料申请单
|
|
else if (TransType == TransTypeEnum.OOApply.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//开立材料出库
|
|
else if (TransType == TransTypeEnum.MOIssue.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//开立委外材料出库
|
|
else if (TransType == TransTypeEnum.OOIssue.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//开立红字入库单
|
|
else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSPurchaseReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//开立委外红字入库单
|
|
else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSOutsourcingReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//借用
|
|
else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSBrrow c ON a.TransCode=c.BrrowCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
WHERE c.BrrowDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
//归还
|
|
else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
|
|
{
|
|
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE c.ReturnDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
|
|
";
|
|
}
|
|
|
|
ERPupdate = string.Format(ERPupdate, SourceDetailID, Identification, ID, DetailID, Code, Sequence);
|
|
if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
|
|
{
|
|
throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Debug(ex.ToString());
|
|
log.Debug(TransType + Environment.NewLine + ERPupdate);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|