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
{
///
/// 使用中
/// 更新库存表、日志表
///
public class ICSWareHouseLotInfoService
{
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
///
/// 分批
///
///
///
///
///
///
///
///
///
///
///
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 language, string MergeID = "")
{
}
///
/// 添加库存
///
///
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoUp(string Identification, string LocationCode, string LotNo, string Quantity, string User,
string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language, string LogID,string jointLotNo, string TransCode, string TransSequence)
{
try
{
#region 正常入库
///添加库存(原条码退回,更新库存;新条码直接入库)
//stirng locationcode = "";
string sql = string.Empty;
string locationcode = "";
if (BusinessCode != TransTypeEnum.SalesReturnBack.GetDescription())
{
if (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 ";
}
else
{
sql = @"SELECT LocationCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt == null || dt.Rows.Count <= 0)
{
throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
}
locationcode = dt.Rows[0]["LocationCode"].ToString();
}
}
if (BusinessCode == TransTypeEnum.MOStockINByProductNoTrans.GetDescription())
{
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 ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
BEGIN
UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
From ICSWareHouseLotInfo a
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
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
END
ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
BEGIN
UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
WHERE LotNo='{0}' AND WorkPoint='{1}'
END
ELSE IF('" + locationcode + @"' != '{4}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
RETURN
END
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
LEFT 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";
}
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 a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
BEGIN
UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
From ICSWareHouseLotInfo a
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
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
END
ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
BEGIN
UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
WHERE LotNo='{0}' AND WorkPoint='{1}'
END
ELSE IF('" + locationcode + @"' != '{4}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
RETURN
END
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"));
}
if (BusinessCode == TransTypeEnum.MOStockINByProductNoTrans.GetDescription())
{
///添加日志
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
LEFT 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}'
";
}
else
{
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 管控方式是"料品"时
ControlMode mode = ICSControlModeService.GetControlMode();
if (mode.itemCode.Equals("ControlMode02"))
{
//查询是否存在料品管控的条码
string sqlStrNew = @"SELECT a.ID,
con.ContainerCode,
con.ContainerName,
a.LotNo,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,-- {0}
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.Version,
ext.BatchCode,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [ USER ],
a.MTIME AS [ MTime ]
FROM
ICSInventoryLot a
LEFT JOIN ICSContainerLot conlot ON a.LotNo = conlot.LotNo AND a.WorkPoint = conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID = con.ID AND conlot.WorkPoint = con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
INNER JOIN ICSExtension ext ON a.ExtensionID = ext.ID AND a.WorkPoint = ext.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
sqlStrNew = string.Format(sqlStrNew, jointLotNo, WorkPoint);
DataTable table = DBHelper.SQlReturnData(sqlStrNew, cmd);
string json = JsonConvert.SerializeObject(table);
List modelNew = JsonConvert.DeserializeObject>(json);
//当不存在料品管控条码时,生成新条码
if (!(modelNew.Count > 0))
{
//获取旧条码的信息
string jsonStr = ICSControlModeService.QueryLotNo(LotNo, WorkPoint);
List model = JsonConvert.DeserializeObject>(jsonStr);
//在条码表中插入一条新数据,在条码表中插入一条新数据,并在库存表中添加新数据
LotNoMode lotNoMode = model[0];
CreateLotNo(jointLotNo, Quantity, "", "", WorkPoint, Identification, User, lotNoMode.InvCode, BusinessCode, lotNoMode.ProjectCode, lotNoMode.BatchCode,
lotNoMode.Version, lotNoMode.Brand, lotNoMode.cFree1, lotNoMode.cFree2, lotNoMode.cFree3, lotNoMode.cFree4, lotNoMode.cFree5, lotNoMode.cFree6, lotNoMode.cFree7,
lotNoMode.cFree8, lotNoMode.cFree9, lotNoMode.cFree10, cmd, language, LocationCode, LotNo);
}
try
{
//合并前日志
WareHouseLotInfoLog(Identification, jointLotNo, User, WorkPoint, "2",
TransTypeEnum.LOTMergeBefore.GetDescription(),"", cmd, language);
//更新目标条码库存
WareHouseLotInfoMerge(Identification, jointLotNo, LotNo, Quantity, User, WorkPoint, "2",
TransTypeEnum.LOTMergeAfter.GetDescription(), cmd, language);
//合并后日志
WareHouseLotInfoLog(Identification, jointLotNo, User, WorkPoint, "2",
TransTypeEnum.LOTMergeAfter.GetDescription(), "",cmd, language);
}
catch (Exception)
{
throw;
}
}
#endregion
#region 成品(生产)入库,倒冲
if (BusinessCode.Equals(TransTypeEnum.ManufactureReceiveDoc.GetDescription()))
{
#region sql
sql = @"-- 1.创建临时表 初始单据数据 maintemp
SELECT
c.MOCode AS TransCode,
a.MODetailID AS DetailID,
a.InvCode,
b.InvName,
b.InvStd,
a.ParentQuantity/c.Quantity*{2} 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 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.ParentQuantity,a.Quantity,c.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 = 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, Quantity);
DataTable table = DBHelper.SQlReturnData(sql,cmd);
string json = JsonConvert.SerializeObject(table);
List downItemModels = JsonConvert.DeserializeObject>(json);
foreach (DownItemModel model in downItemModels)
{
if (model != null && model.LotNo == null || "" == model.LotNo)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo201"));
}
WareHouseLotInfoDown(Identification,model.TransCode,model.Sequence + "~" + model.TransSequence,model.LotNo,model.Quantity,User,WorkPoint,"12",BusinessCode,cmd,language,"","");
//回写已领数量
sql = @"UPDATE ICSMOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + model.Quantity+") 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("WMSAPIInfo199"));
}
}
}
#endregion
#region 委外入库,倒冲
if (BusinessCode.Equals(TransTypeEnum.OutsourcingReceiveDoc.GetDescription()))
{
#region sql
sql = @"-- 1.创建临时表 初始单据数据 maintemp
SELECT
c.OOCode AS TransCode,
a.OODetailID AS DetailID,
a.InvCode,
b.InvName,
b.InvStd,
a.ParentQuantity/c.Quantity*{2} 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 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.ParentQuantity,a.Quantity,c.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, Quantity);
DataTable table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
List downItemModels = JsonConvert.DeserializeObject>(json);
foreach (DownItemModel model in downItemModels)
{
if (model != null && model.LotNo == null || "" == model.LotNo)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo201"));
}
WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, User, WorkPoint, "13", 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;
}
}
///
/// 添加库存(奥美专用)
///
///
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoUpAM(string Identification, string LocationCode, string LotNo, string Quantity, string User,
string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language, string LogID, string jointLotNo,string TransCode,string TransSequence)
{
try
{
#region 正常入库
///添加库存(原条码退回,更新库存;新条码直接入库)
//stirng locationcode = "";
string sql = string.Empty;
string locationcode = "";
string newlocationcode = "";
string amount = "";
//string sqql = @"select a.Amount FROM ICSInventoryLot a
// WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
//sqql = string.Format(sqql, LotNo, WorkPoint);
//DataTable dtaa = DBHelper.SQlReturnData(sqql, cmd);
//amount = dtaa.Rows[0]["Amount"].ToString();
//string cheksql = @"select d.EATTRIBUTE1 FROM ICSInventoryLot a
// INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
// INNER JOIN ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
// WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and d.AmountEnable='1'";
//cheksql = string.Format(cheksql, LotNo, WorkPoint);
//DataTable dta = DBHelper.SQlReturnData(cheksql, cmd);
//if (dta.Rows.Count > 0)
//{
// Quantity = (decimal.Parse(Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
//}
if (BusinessCode != TransTypeEnum.SalesReturnBack.GetDescription())
{
if (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 ";
}
else
{
sql = @"SELECT LocationCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt == null || dt.Rows.Count <= 0)
{
throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
}
locationcode = dt.Rows[0]["LocationCode"].ToString();
}
}
if(BusinessCode == TransTypeEnum.MOIssueDocNegative.GetDescription())
{
sql = @"SELECT FromLocationCode FROM ICSWareHouseLotInfoLog a WHERE LotNo='{0}' AND WorkPoint='{1}' AND ID='{2}'";
sql = string.Format(sql, LotNo, WorkPoint,LogID);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt == null || dt.Rows.Count <= 0)
{
throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
}
newlocationcode = dt.Rows[0]["FromLocationCode"].ToString();
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 ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
BEGIN
UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
From ICSWareHouseLotInfo a
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
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
END
ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode=(select a.FromLocationCode FROM ICSWareHouseLotInfoLog a WHERE a.LotNo='CP-41100212' AND a.WorkPoint='UFDATA_999_2021' AND a.id='{5}'
AND a.FromLocationCode='" + locationcode + @"'))
BEGIN
UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
WHERE LotNo='{0}' AND WorkPoint='{1}'
END
ELSE
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
RETURN
END
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, newlocationcode, LogID);
}
else if (BusinessCode == TransTypeEnum.MOStockINByProductNoTrans.GetDescription())
{
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 ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
BEGIN
UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
From ICSWareHouseLotInfo a
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
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
END
ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
BEGIN
UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
WHERE LotNo='{0}' AND WorkPoint='{1}'
END
ELSE IF('" + locationcode + @"' != '{4}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
RETURN
END
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
LEFT 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);
}
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 a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
BEGIN
UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
From ICSWareHouseLotInfo a
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
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
END
ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
BEGIN
UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
WHERE LotNo='{0}' AND WorkPoint='{1}'
END
ELSE IF('" + locationcode + @"' != '{4}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
RETURN
END
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"));
}
if (BusinessCode == TransTypeEnum.MOIssueDocNegative.GetDescription())
{
///添加日志
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}','{8}','{9}',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,TransCode,TransSequence);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
}
else if (BusinessCode == TransTypeEnum.MOStockINByProduct.GetDescription())
{
///添加日志
sql = @"IF EXISTS(SELECT 1 FROM ICSInventoryLot lot WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}' AND lot.Type=19)
BEGIN
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}','','',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 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}'
END
ELSE
BEGIN
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}'
END
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
}
else if (BusinessCode == TransTypeEnum.MOStockINByProductNoTrans.GetDescription())
{
///添加日志
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
LEFT 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"));
}
}
else if (BusinessCode == TransTypeEnum.OOStockINByProduct.GetDescription())
{
///添加日志
sql = @"IF EXISTS(SELECT 1 FROM ICSInventoryLot lot WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}' AND lot.Type=19)
BEGIN
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}','','',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 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}'
END
ELSE
BEGIN
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}'
END
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
}
else
{
///添加日志
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 管控方式是"料品"时
ControlMode mode = ICSControlModeService.GetControlMode();
if (mode.itemCode.Equals("ControlMode02"))
{
//查询是否存在料品管控的条码
string sqlStrNew = @"SELECT a.ID,
con.ContainerCode,
con.ContainerName,
a.LotNo,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,-- {0}
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.Version,
ext.BatchCode,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [ USER ],
a.MTIME AS [ MTime ]
FROM
ICSInventoryLot a
LEFT JOIN ICSContainerLot conlot ON a.LotNo = conlot.LotNo AND a.WorkPoint = conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID = con.ID AND conlot.WorkPoint = con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
INNER JOIN ICSExtension ext ON a.ExtensionID = ext.ID AND a.WorkPoint = ext.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
sqlStrNew = string.Format(sqlStrNew, jointLotNo, WorkPoint);
DataTable table = DBHelper.SQlReturnData(sqlStrNew, cmd);
string json = JsonConvert.SerializeObject(table);
List modelNew = JsonConvert.DeserializeObject>(json);
//当不存在料品管控条码时,生成新条码
if (!(modelNew.Count > 0))
{
//获取旧条码的信息
string jsonStr = ICSControlModeService.QueryLotNo(LotNo, WorkPoint);
List model = JsonConvert.DeserializeObject>(jsonStr);
//在条码表中插入一条新数据,在条码表中插入一条新数据,并在库存表中添加新数据
LotNoMode lotNoMode = model[0];
CreateLotNo(jointLotNo, Quantity, "", "", WorkPoint, Identification, User, lotNoMode.InvCode, BusinessCode, lotNoMode.ProjectCode, lotNoMode.BatchCode,
lotNoMode.Version, lotNoMode.Brand, lotNoMode.cFree1, lotNoMode.cFree2, lotNoMode.cFree3, lotNoMode.cFree4, lotNoMode.cFree5, lotNoMode.cFree6, lotNoMode.cFree7,
lotNoMode.cFree8, lotNoMode.cFree9, lotNoMode.cFree10, cmd, language, LocationCode, LotNo);
}
try
{
//合并前日志
WareHouseLotInfoLog(Identification, jointLotNo, User, WorkPoint, "2",
TransTypeEnum.LOTMergeBefore.GetDescription(), "", cmd, language);
//更新目标条码库存
WareHouseLotInfoMerge(Identification, jointLotNo, LotNo, Quantity, User, WorkPoint, "2",
TransTypeEnum.LOTMergeAfter.GetDescription(), cmd, language);
//合并后日志
WareHouseLotInfoLog(Identification, jointLotNo, User, WorkPoint, "2",
TransTypeEnum.LOTMergeAfter.GetDescription(), "", cmd, language);
}
catch (Exception)
{
throw;
}
}
#endregion
#region 成品(生产)入库,倒冲
if (BusinessCode.Equals(TransTypeEnum.ManufactureReceiveDoc.GetDescription()))
{
#region sql
sql = @"-- 1.创建临时表 初始单据数据 maintemp
SELECT
c.MOCode AS TransCode,
a.MODetailID AS DetailID,
a.InvCode,
b.InvName,
b.InvStd,
a.ParentQuantity/c.Quantity*{2} 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 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.ParentQuantity,a.Quantity,c.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 = 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, Quantity);
DataTable table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
List downItemModels = JsonConvert.DeserializeObject>(json);
foreach (DownItemModel model in downItemModels)
{
if (model != null && model.LotNo == null || "" == model.LotNo)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo201"));
}
WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, User, WorkPoint, "12", BusinessCode, cmd, language, "", "");
//回写已领数量
sql = @"UPDATE ICSMOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + model.Quantity + ") 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("WMSAPIInfo199"));
}
}
}
#endregion
#region 委外入库,倒冲
if (BusinessCode.Equals(TransTypeEnum.OutsourcingReceiveDoc.GetDescription()))
{
#region sql
sql = @"-- 1.创建临时表 初始单据数据 maintemp
SELECT
c.OOCode AS TransCode,
a.OODetailID AS DetailID,
a.InvCode,
b.InvName,
b.InvStd,
a.ParentQuantity/c.Quantity*{2} 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 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.ParentQuantity,a.Quantity,c.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, Quantity);
DataTable table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
List downItemModels = JsonConvert.DeserializeObject>(json);
foreach (DownItemModel model in downItemModels)
{
if (model != null && model.LotNo == null || "" == model.LotNo)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo201"));
}
WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, User, WorkPoint, "13", 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;
}
}
///
/// 减少库存
///
///
///
///
///
///
///
///
///
///
///
public static DataTable WareHouseLotInfoDown(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language, string LogID, string MergeID = "")
{
decimal LotQTYYY = 0;
decimal LotQTY = 0;
string LotEnable = "";
string chekEnable = "";
string DisPrintEnable = "";
string PrintEnable = "";
string sql = "";
string lotstr = "";
int result = 0;
List NewBarCodeList = new List();
DataTable dtLotno = new DataTable();
DataTable lstDt = new DataTable();
DataTable ZLtable = new DataTable();
try
{
//检验是否分批
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();
}
string cheksql = @"IF NOT EXISTS(select b.F_ItemCode as Code ,b.F_ItemName as Name,b.F_EnabledMark AS Enable ,b.F_IsDefault AS DisPrintEnable
from Sys_SRM_Items a
left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
where a.F_EnCode='TransBatch' and b.F_ItemCode='{0}' )
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo470") + @"',16,1);
RETURN
END
select b.F_ItemCode as Code ,b.F_ItemName as Name,b.F_EnabledMark AS Enable ,b.F_IsDefault AS DisPrintEnable
from Sys_SRM_Items a
left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
where a.F_EnCode='TransBatch' and b.F_ItemCode='{0}'
";
cheksql = string.Format(cheksql, BusinessCode);
DataTable chekdt = DBHelper.SQlReturnData(cheksql, cmd);
if (chekdt.Rows.Count == 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
}
else
{
chekEnable = chekdt.Rows[0]["Enable"].ToString();
DisPrintEnable = chekdt.Rows[0]["DisPrintEnable"].ToString();
}
sql = @"select Quantity from ICSWareHouseLotInfo
where LotNO='{0}' AND WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint);
DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
LotQTYYY = Convert.ToDecimal(dtt.Rows[0]["Quantity"]);
LotQTY = Convert.ToDecimal(Quantity);
if (!LotEnable.Equals("False")&&!chekEnable.Equals("False") && LotQTYYY - LotQTY > 0)
{
ZLtable = ICSControlModeService.GetZL();
if (ZLtable == null)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
}
for (int i = 0; i < ZLtable.Rows.Count; i++)
{
string zlName = ZLtable.Rows[i]["Name"].ToString();
string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
string Enable = ZLtable.Rows[i]["Enable"].ToString();
if (zlTransCode.Equals(BusinessCode))
{
if (Enable.Equals("True"))
{
///更新日志
sql = @"
IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and transtype='15')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo472") + @"',16,1);
RETURN
END
UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE2='1' WHERE LotNo='{0}' AND WorkPoint='{1}' and transtype='15'
";
sql = string.Format(sql, LotNo, WorkPoint, LogID);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"占料标识更新失败!");
}
///更新库存
sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}',LockQuantity=ISNULL(LockQuantity,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-LockQuantity<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"));//"库存更新失败!");
}
}
else
{
///更新库存
sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-ISNULL(LockQuantity,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-LockQuantity<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 = @"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}','{7}','{8}',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, TransCode, TransSequence);
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.Quantity*Quantity,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,'0',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}','{8}','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")&& DisPrintEnable.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.lotno ='{0}' and a.workpoint='{1}' and a.BusinessCode='{2}'
";
sql = string.Format(sql, lotstr, WorkPoint,BusinessCode);
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)
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}'
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"));
}
ZLtable = ICSControlModeService.GetZL();
if (ZLtable == null)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
}
for (int i = 0; i < ZLtable.Rows.Count; i++)
{
string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
string Enable = ZLtable.Rows[i]["Enable"].ToString();
if (zlTransCode.Equals(BusinessCode))
{
if (Enable.Equals("True"))
{
///更新日志
sql = @"
IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and transtype='15')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo472") + @"',16,1);
RETURN
END
UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE2='1' WHERE LotNo='{0}' AND WorkPoint='{1}' and transtype='15'
";
sql = string.Format(sql, LotNo, WorkPoint, LogID);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"占料标识更新失败!");
}
///更新库存
sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}',LockQuantity=ISNULL(LockQuantity,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-LockQuantity<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"));//"库存更新失败!");
}
}
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-LockQuantity<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 = @"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"));//"库存更新失败!");
//}
}
}
catch (Exception)
{
throw;
}
return lstDt;
}
///
/// 减少库存(奥美专用)
///
///
///
///
///
///
///
///
///
///
///
public static DataTable AMWareHouseLotInfoDown(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language, string LogID, string MergeID = "")
{
decimal LotQTYYY = 0;
decimal LotQTY = 0;
string LotEnable = "";
string chekEnable = "";
string DisPrintEnable = "";
string PrintEnable = "";
string sql = "";
string lotstr = "";
int result = 0;
List NewBarCodeList = new List();
DataTable dtLotno = new DataTable();
DataTable lstDt = new DataTable();
DataTable ZLtable = new DataTable();
try
{
string amount = "";
//string sqql = @"select a.Amount FROM ICSInventoryLot a
// WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
//sqql = string.Format(sqql, LotNo, WorkPoint);
//DataTable dtaa = DBHelper.SQlReturnData(sqql, cmd);
//amount = dtaa.Rows[0]["Amount"].ToString();
//string chekksql = @"select c.EATTRIBUTE1 FROM ICSMOPick a
// INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
// INNER JOIN ICSInventory c on a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
// WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}' and c.AmountEnable='1'";
//chekksql = string.Format(chekksql, TransCode, WorkPoint, Quantity, TransSequence);
//DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
//if (dta.Rows.Count > 0)
//{
// Quantity = (decimal.Parse(Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
//}
//检验是否分批
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();
}
string cheksql = @"IF NOT EXISTS(select b.F_ItemCode as Code ,b.F_ItemName as Name,b.F_EnabledMark AS Enable ,b.F_IsDefault AS DisPrintEnable
from Sys_SRM_Items a
left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
where a.F_EnCode='TransBatch' and b.F_ItemCode='{0}' )
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo470") + @"',16,1);
RETURN
END
select b.F_ItemCode as Code ,b.F_ItemName as Name,b.F_EnabledMark AS Enable ,b.F_IsDefault AS DisPrintEnable
from Sys_SRM_Items a
left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
where a.F_EnCode='TransBatch' and b.F_ItemCode='{0}'
";
cheksql = string.Format(cheksql, BusinessCode);
DataTable chekdt = DBHelper.SQlReturnData(cheksql, cmd);
if (chekdt.Rows.Count == 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
}
else
{
chekEnable = chekdt.Rows[0]["Enable"].ToString();
DisPrintEnable = chekdt.Rows[0]["DisPrintEnable"].ToString();
}
sql = @"select Quantity from ICSWareHouseLotInfo
where LotNO='{0}' AND WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint);
DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
LotQTYYY = Convert.ToDecimal(dtt.Rows[0]["Quantity"]);
LotQTY = Convert.ToDecimal(Quantity);
if (!LotEnable.Equals("False") && !chekEnable.Equals("False") && LotQTYYY - LotQTY > 0)
{
ZLtable = ICSControlModeService.GetZL();
if (ZLtable == null)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
}
for (int i = 0; i < ZLtable.Rows.Count; i++)
{
string zlName = ZLtable.Rows[i]["Name"].ToString();
string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
string Enable = ZLtable.Rows[i]["Enable"].ToString();
if (zlTransCode.Equals(BusinessCode))
{
if (Enable.Equals("True"))
{
///更新日志
sql = @"
IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and transtype='15')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo472") + @"',16,1);
RETURN
END
UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE2='1' WHERE LotNo='{0}' AND WorkPoint='{1}' and transtype='15'
";
sql = string.Format(sql, LotNo, WorkPoint, LogID);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"占料标识更新失败!");
}
///更新库存
sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}',LockQuantity=ISNULL(LockQuantity,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-LockQuantity<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"));//"库存更新失败!");
}
}
else
{
///更新库存
sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-ISNULL(LockQuantity,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-LockQuantity<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 = @"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}','{7}','{8}',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, TransCode, TransSequence);
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.Quantity*Quantity,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,'0',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}','{8}','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") && DisPrintEnable.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.lotno ='{0}' and a.workpoint='{1}' and a.BusinessCode='{2}'
";
sql = string.Format(sql, lotstr, WorkPoint, BusinessCode);
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)
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}'
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);
log.Debug("出库增加日志:" + sql);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
ZLtable = ICSControlModeService.GetZL();
if (ZLtable == null)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
}
for (int i = 0; i < ZLtable.Rows.Count; i++)
{
string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
string Enable = ZLtable.Rows[i]["Enable"].ToString();
if (zlTransCode.Equals(BusinessCode))
{
if (Enable.Equals("True"))
{
///更新日志
sql = @"
IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and transtype='15')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo472") + @"',16,1);
RETURN
END
UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE2='1' WHERE LotNo='{0}' AND WorkPoint='{1}' and transtype='15'
";
sql = string.Format(sql, LotNo, WorkPoint, LogID);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"占料标识更新失败!");
}
///更新库存
sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}',LockQuantity=ISNULL(LockQuantity,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-LockQuantity<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"));//"库存更新失败!");
}
}
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-LockQuantity<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 = @"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"));//"库存更新失败!");
//}
}
}
catch (Exception)
{
throw;
}
return lstDt;
}
///
/// 无源头调拨
///
///
///
///
///
///
///
///
///
public static DataTable WareHouseLotInfoNoTransfer(string Identification, string WarehouseCode, string LocationCode,
string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language, string MergeID)
{
decimal LotQTYYY = 0;
decimal LotQTY = 0;
String LotEnable = "";
String PrintEnable = "";
String ToWareHouseCode = "";
String ToLocationCode = "";
string lotstr = "";
int result = 0;
DataTable dtLotno = new DataTable();
DataTable lstDt = new DataTable();
List NewBarCodeList = new List();
try
{
//检验是否分批
string 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();
}
sql = @"select Quantity from ICSWareHouseLotInfo
where LotNO='{0}' AND WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint);
DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
LotQTYYY = Convert.ToDecimal(dtt.Rows[0]["Quantity"]);
LotQTY = Convert.ToDecimal(Quantity);
if (!LotEnable.Equals("False") && LotQTYYY - LotQTY > 0)
{
///更新库存
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 = @"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}','','',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);
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"));//条码分批后条码表存入失败!
}
#endregion
sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
select NEWID(),'{0}','{4}','{5}',InvCode,'{2}',InDate,LockQuantity
,MUSER,MUSERName,GETDATE(),'{3}',''
from ICSWareHouseLotInfo
where LotNO='{1}' AND WorkPoint='{3}'";
sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint, WarehouseCode, LocationCode);
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}','','','{8}' ,a.InvCode ,
c.WarehouseCode,c.LocationCode,'{9}','{10}','{4}',
'','0','{5}','{6}','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,a.WorkPoint ,'','{7}'
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, Quantity, TransType, BusinessCode, MergeID, lotstr, WarehouseCode, LocationCode);
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
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,'','',c.Quantity,
'','0','{5}','32','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,a.WorkPoint ,'','{7}'
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, Quantity, TransType, BusinessCode, 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='{7}' AND LocationCode='{8}' 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,'{7}','{8}',{4},
'','0','{5}','{6}','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, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode, MergeID);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
///更新库存
sql = @"UPDATE ICSWareHouseLotInfo SET WareHouseCode='{2}',LocationCode='{3}' 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, WarehouseCode, LocationCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
}
}
}
catch (Exception)
{
throw;
}
return lstDt;
}
///
/// 修改库存
///
///
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoUpdate(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
string WorkPoint, string TransType,string CheckKind, SqlCommand cmd, Dictionary 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
IF EXISTS(SELECT id FROM ICSInventoryLot WHERE LotNo='{0}' AND Quantity<'{9}')
BEGIN
RAISERROR('条码 {0} 盘点数量不能超过生成数量!',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,
'{8}','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(), CheckKind, Quantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
///更新库存
sql = @"UPDATE ICSWareHouseLotInfo SET Quantity='{2}',LockQuantity=LockQuantity-{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 = @"UPDATE ICSCheck SET Status='2' WHERE CHeckCode='{0}' AND WorkPoint='{1}'";
sql = string.Format(sql, TransCode, WorkPoint);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception("盘点状态更新失败!");//"库存更新失败!");
}
///添加日志
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,
'{8}','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(), CheckKind);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
}
catch (Exception)
{
throw;
}
}
///
/// 调拨
///
///
///
///
///
///
///
///
///
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 language, string MergeID)
{
decimal LotQTYYY = 0;
decimal LotQTY = 0;
String LotEnable = "";
String PrintEnable = "";
string lotstr = "";
int result = 0;
DataTable dtLotno = new DataTable();
DataTable lstDt = new DataTable();
List NewBarCodeList = new List();
try
{
//检验是否分批
string 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();
}
sql = @"select Quantity from ICSWareHouseLotInfo
where LotNO='{0}' AND WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint);
DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
LotQTYYY = Convert.ToDecimal(dtt.Rows[0]["Quantity"]);
LotQTY = Convert.ToDecimal(Quantity);
if (!LotEnable.Equals("False") && LotQTYYY - LotQTY > 0)//增加数量判断
{
///更新库存
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 = @"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}','{7}','{8}',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, TransCode, TransSequence);
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"));//条码分批后条码表存入失败!
}
#endregion
sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
select NEWID(),'{0}','{4}','{5}',InvCode,'{2}',InDate,LockQuantity
,MUSER,MUSERName,GETDATE(),'{3}',''
from ICSWareHouseLotInfo
where LotNO='{1}' AND WorkPoint='{3}'";
sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint,WarehouseCode,LocationCode);
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,'{11}','{12}','{6}',
'','0','{7}','{8}','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, WarehouseCode, LocationCode);
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
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"));
}
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.lotno ='{0}' and a.workpoint='{1}' and a.BusinessCode='{2}'
";
sql = string.Format(sql, lotstr, WorkPoint, BusinessCode);
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}','{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 ,'','{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 = @"UPDATE ICSWareHouseLotInfo SET WareHouseCode='{2}',LocationCode='{3}' 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, WarehouseCode, LocationCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
}
}
DateTime now = DateTime.Now;
sql = @"select 1 from ICSContainerLot
where LotNo='{0}' and WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint);
log.Debug("查询容器条码关联表是否存在");
DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
if (dttte.Rows.Count > 0)
{
///删除条码关联表数据
sql = @"DELETE FROM ICSContainerLot
where LotNo='{0}' and WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("容器条码关联表数据删除失败"));
}
}
}
catch (Exception)
{
throw;
}
return lstDt;
}
///
/// 移库
///
///
///
///
///
///
///
///
///
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 language)
{
try
{
string sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
sql = string.Format(sql, LotNo,WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt == null || dt.Rows.Count <= 0)
{
throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
}
string whcode = dt.Rows[0]["WarehouseCode"].ToString();
///添加日志
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('" + whcode + @"' != '{8}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo394"), "{8}", whcode) + @"', 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
IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.WarehouseCode='{2}')
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"));//"库存表更新失败!");
}
DateTime now = DateTime.Now;
sql = @"select 1 from ICSContainerLot
where LotNo='{0}' and WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint);
log.Debug("查询容器条码关联表是否存在");
DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
if (dttte.Rows.Count > 0)
{
///删除条码关联表数据
sql = @"DELETE FROM ICSContainerLot
where LotNo='{0}' and WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("容器条码关联表数据删除失败"));
}
}
}
catch (Exception)
{
throw;
}
}
///
/// 两步调入
///
///
///
///
///
///
///
///
///
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 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,
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 ,
'{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=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;
}
}
///
/// 合并日志
///
///
///
///
///
///
///
///
public static DataTable WareHouseLotInfoLogMerge(string Identification, string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, string newLotno, SqlCommand cmd, Dictionary language)
{
String LotEnable = "";
String PrintEnable = "";
DataTable dtLotno = new DataTable();
DataTable lstDt = new DataTable();
try
{
//检验是否分批
string 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();
}
///添加日志
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"));
}
if (PrintEnable.Equals("True"))
{
sql = @"select A.LotNO , B.Quantity AS OLDLotQty, C.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='34'
and A.lotno = '{0}' and a.workpoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, BusinessCode, newLotno);
dtLotno = DBHelper.SQlReturnData(sql, cmd);
lstDt = dtLotno;
}
}
catch (Exception)
{
throw;
}
return lstDt;
}
///
/// 拆分、合并日志
///
///
///
///
///
///
///
///
public static DataTable WareHouseLotInfoLog(string Identification, string LotNo, string User, string WorkPoint, string TransType, string BusinessCode,string newLotno, SqlCommand cmd, Dictionary language)
{
String LotEnable = "";
String PrintEnable = "";
DataTable dtLotno = new DataTable();
DataTable lstDt = new DataTable();
try{
//检验是否分批
string 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();
}
///添加日志
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"));
}
if (PrintEnable.Equals("True"))
{
sql = @"select A.LotNO , C.Quantity AS OLDLotQty, B.Quantity AS LotQty ,b.InvCode,d.INVSTD,d.INVNAME,b.MTIME,A.TransCode,c.LocationCode,f.BatchCode
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
left JOIN ICSExtension f on b.ExtensionID=f.id and b.WorkPoint=f.WorkPoint
where a.BusinessCode='32'
and A.lotno = '{3}' and a.workpoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, BusinessCode,newLotno);
dtLotno = DBHelper.SQlReturnData(sql, cmd);
lstDt = dtLotno;
}
}
catch (Exception)
{
throw;
}
return lstDt;
}
///
/// 合并
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoMerge(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
string BusinessCode, SqlCommand cmd, Dictionary 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 EXISTS(
SELECT * FROM ICSWareHouseLotInfo a
INNER JOIN ICSInventoryLot c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventory d on c.invcode=d.invcode and c.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and d.BatchEnable='1'
)
BEGIN
IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a
INNER JOIN ICSWareHouseLotInfo b ON b.LotNo='{3}' AND a.WarehouseCode=b.WarehouseCode AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSInventoryLot c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint
INNER JOIN ICSExtension e on c.ExtensionID=e.ID and c.WorkPoint=e.WorkPoint
INNER JOIN ICSExtension f on d.ExtensionID=f.id and d.WorkPoint=f.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and e.ID=f.ID)
BEGIN
RAISERROR('不同仓库/批次条码,不能合并',16,1);
RETURN
END
END
IF NOT EXISTS(
SELECT * FROM ICSWareHouseLotInfo a
INNER JOIN ICSInventoryLot c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventory d on c.invcode=d.invcode and c.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and d.BatchEnable='1'
)
BEGIN
IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a
INNER JOIN ICSWareHouseLotInfo b ON b.LotNo='{3}' AND a.WarehouseCode=b.WarehouseCode AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSInventoryLot c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
RAISERROR('不同仓库/批次条码,不能合并',16,1);
RETURN
END
END
UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
UPDATE ICSInventoryLot SET Amount=(ISNULL(Amount,0)+(select Amount from
ICSInventoryLot where LotNo='{3}' AND WorkPoint='{1}')) 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}'
UPDATE ICSInventoryLot SET Amount=(ISNULL(Amount,0)-(select Amount from
ICSInventoryLot where LotNo='{0}' AND WorkPoint='{1}')) 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)
{
throw;
}
}
///
/// 拆分
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoSplit(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
string BusinessCode, SqlCommand cmd, Dictionary 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,Amount,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
SELECT NEWID(),'{4}' ,a.InvCode,a.ProductDate,a.ExpirationDate ,'{3}',a.Amount/a.Quantity*{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
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;
}
}
///
/// 拆分(奥美)
///
///
///
///
///
///
///
///
public static void AMWareHouseLotInfoSplit(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
string BusinessCode, SqlCommand cmd, Dictionary language)
{
try
{
string amount = "";
//string sqql = @"select a.Amount FROM ICSInventoryLot a
// WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
//sqql = string.Format(sqql, LotNo, WorkPoint);
//DataTable dtaa = DBHelper.SQlReturnData(sqql, cmd);
//amount = dtaa.Rows[0]["Amount"].ToString();
string cheksql = @"select d.EATTRIBUTE1 FROM ICSInventoryLot a
INNER JOIN ICSWareHouseLotInfo b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and d.AmountEnable='1'";
cheksql = string.Format(cheksql, LotNo, WorkPoint);
DataTable dta = DBHelper.SQlReturnData(cheksql, cmd);
if (dta.Rows.Count > 0)
{
Quantity = (decimal.Parse(Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
}
///更新库存
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,Amount,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
SELECT NEWID(),'{4}' ,a.InvCode,a.ProductDate,a.ExpirationDate ,'{3}',a.Amount/a.Quantity*{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
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;
}
}
///
/// 回写ERP ID
///
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoLogUpdate(string TransType, string SourceDetailID, string Identification, string ID, string DetailID, string Code, string Sequence, string col, SqlCommand cmd, Dictionary language, string BusinessCode)
{
string ERPupdate = string.Empty;
string NewERPupdate = string.Empty;
try
{
//采购入库
if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.PODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.towarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP";
}
//审核的到货单
else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.towarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//采购拒收
else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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 ='{7}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//审核的委外到货单
else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//委外拒收
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
";
}
//采购退货
else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSDeliveryNotice c ON a.TransCode=c.DNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DNType='2' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//委外发料
else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//委外退料
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
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE ISNULL(m.ApplyDetailID,ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
--根据原条码退料-备料表
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
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
--根据原条码退料-申请单
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
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
--根据原条码退料-材料出库单
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
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//委外入库
else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.OODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP";
}
//委外退货
else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSODeliveryNotice c ON a.TransCode=c.ODNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.ODNType='2' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//生产发料
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
// INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
// INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
// INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
// LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
// WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
// and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
// ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
// ";
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP";
}
//生产退料
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 ='{7}'
--根据原条码退料-备料表
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 ='{7}'
--根据原条码退料-申请单
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 ='{7}'
--根据原条码退料-材料出库单
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 ='{7}'
";
}
//生产入库
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
// INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
// INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
// INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
// INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
// LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
// WHERE c.MODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
// and (ISNULL(a.fromwarehousecode, '')
// + CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END
// + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END
// + CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END
// + CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END
// + CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END
// + CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END
// + CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END
// + CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END
// + CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END
// + CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END
// + CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END
// + CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END
// + CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END
// + CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END)='{6}'
//";
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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
INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.MODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '')
+ CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END
+ CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END
+ CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END
+ CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END)='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//开立的生产入库单
else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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 ='{7}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//销售出库
else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//销售退货
else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP";
}
//返工工单
else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE d.PickID='{3}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//一步调拨
else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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 ='{7}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//调拨
else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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 ='{7}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//无源头调拨
else if (TransType == TransTypeEnum.StepNoTransferDocIn.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode='70'
and (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//两步调出
else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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 ='{7}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//两步调入
else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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 ='{7}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//销售退货-原条码
else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP";
}
//其他出库
else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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 ='{7}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//其他入库
else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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 ='{7}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//拆卸单
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 ='{7}'
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 ='{7}'
";
}
//领料申请单
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
// INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
// INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
// INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
// LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
// WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
// and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
// ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
// ";
ERPupdate = @"SELECT a.id
INTO #NewTempERP
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//补料申请单
else if (TransType == TransTypeEnum.MOReplenishment.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
// INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
// INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
// INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
// LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
// WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
// and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
// ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
// ";
ERPupdate = @"SELECT a.id
INTO #NewTempERP
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSMOReplenishment c ON a.TransCode=c.ReplenishmentCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.ReplenishmentDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//委外领料申请单
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
// INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
// INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
// INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
// LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
// WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
// and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
// ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
// ";
ERPupdate = @"SELECT a.id
INTO #NewTempERP
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//开立材料出库
else if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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 ='{7}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//开立委外材料出库
else if (TransType == TransTypeEnum.OOIssue.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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 ='{7}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//开立红字入库单
else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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 ='{7}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//开立委外红字入库单
else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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 ='{7}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP
";
}
//借用
else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSBrrow c ON a.TransCode=c.BrrowCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.BrrowDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP";
}
//归还
else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
{
ERPupdate = @"SELECT a.id
INTO #NewTempERP
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
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.ReturnDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.tohwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
where ID in (select id from #NewTempERP)
DROP TABLE #NewTempERP";
}
ERPupdate = string.Format(ERPupdate, SourceDetailID, Identification, ID, DetailID, Code, Sequence, col, BusinessCode);
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);
throw;
}
}
///
/// 倒冲时子件已领数量回写
///
public static void DetailQTYUpdate()
{
}
///
/// 生成条码
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
public static void CreateLotNo(string LotNo, string Quantity, string TransCode, string TransSequence, string WorkPoint, string Identification, string User, string InvCode, string BusinessCode,
string ProjectCode, string BatchCode, string Version, string Brand, string cFree1, string cFree2, string cFree3, string cFree4, string cFree5,string cFree6, string cFree7, string cFree8, string cFree9, string cFree10, SqlCommand cmd, Dictionary language,string LocationCode,string OLDLotNo)
{
try
{
String EffectiveEnable = "";
String Colspan = "";
String IDD = "";
int EffectiveDays = 0;
String Time = "";
int EffectiveDayss = 0;
DateTime dtt;
DateTime now = DateTime.Now;
string sql = string.Empty;
//string sql = @"select EffectiveEnable,EffectiveDays from ICSInventory a
// Left Join ICSMO b ON a.InvCode=b.InvCode and a.WorkPoint = b.WorkPoint
// where b.MoCode='{0}' and b.WorkPoint='{1}'";
//sql = string.Format(sql, TransCode, WorkPoint);
//DataTable dt = DBHelper.SQlReturnData(sql, cmd);
//if (dt.Rows.Count == 0)
//{
// throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
//}
//else
//{
// EffectiveEnable = dt.Rows[0]["EffectiveEnable"].ToString();
//EffectiveDays = Convert.ToInt32(dt.Rows[0]["EffectiveDays"]);
//}
//EffectiveDayss = Convert.ToInt32(EffectiveDays);
//if (!EffectiveEnable.Equals("False"))
//{
int year = now.Year;
int month = now.Month;
int day = now.Day;
int n = DateTime.DaysInMonth(year, month);
int k = day + EffectiveDays;
if (k > n)
{
day = EffectiveDays - (n - day);
month = month + 1;
if (month > 12)
{
month = 1;
year = year + 1;
}
}
else
{
day = day + EffectiveDays;
}
Time = year + "-" + month + "-" + day;
//}
//else
//{
// Time = "2999-12-31 00:00:00.000";
//}
dtt = Convert.ToDateTime(Time);
//检验自由项
Colspan = ProjectCode + "~" + BatchCode + "~" + Version
+ "~" + Brand + "~" + cFree1
+ "~" + cFree2 + "~" + cFree3 + "~" + cFree4
+ "~" + cFree5 + "~" + cFree6 + "~" + cFree7
+ "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
sql = @"select ID,Colspan from ICSExtension a
where Colspan='{0}' and WorkPoint='{1}'";
sql = string.Format(sql, Colspan, WorkPoint);
DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
if (dttt.Rows.Count == 0)
{
IDD = Guid.NewGuid().ToString();
sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
sql = string.Format(sql, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, User, WorkPoint, IDD);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
}
}
else
{
IDD = dttt.Rows[0]["ID"].ToString();
}
//存入条码表
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
RETURN
END
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}','{8}',GETDATE(),'{6}',
'{1}','0','{7}','16',null,
null,null,'{2}' ,f.F_RealName ,GETDATE(),
'{4}' ,''
FROM Sys_SRM_User f
where f.F_Account='{2}' and f.F_Location='{4}'
";
sql = string.Format(sql, LotNo, Quantity, User, TransCode, WorkPoint, TransSequence, dtt, IDD,InvCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
}
///存入条码关联表
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{3}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
RETURN
END
INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,
WorkPoint,EATTRIBUTE1)
SELECT '{4}','{0}','{1}',f.F_Account ,f.F_RealName,GETDATE(),
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='{5}' AND a.WorkPoint='{3}'
";
sql = string.Format(sql, TransCode, TransSequence, User, WorkPoint, LotNo, OLDLotNo);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
}
//存入库存表
sql = @"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 ,'0',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}'";
sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
}
}
catch (Exception)
{
throw;
}
}
}
}