|
|
@ -2247,7 +2247,7 @@ where d.LotNo='{0}' and a.WorkPoint='{1}' and a.SupplyType='1' and a.quantity>0" |
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 添加库存(奥美专用)
|
|
|
|
/// 客供料添加库存
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="LocationCode"></param>
|
|
|
|
/// <param name="LotNo"></param>
|
|
|
@ -2263,723 +2263,122 @@ where d.LotNo='{0}' and a.WorkPoint='{1}' and a.SupplyType='1' and a.quantity>0" |
|
|
|
{ |
|
|
|
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<DBValue>()) |
|
|
|
{ |
|
|
|
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<DBValue>()) |
|
|
|
{ |
|
|
|
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='{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, newlocationcode); |
|
|
|
} |
|
|
|
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<DBValue>()) |
|
|
|
{ |
|
|
|
///添加日志
|
|
|
|
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<DBValue>()) |
|
|
|
{ |
|
|
|
///添加日志
|
|
|
|
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.OOStockINByProduct.GetDescription<DBValue>()) |
|
|
|
{ |
|
|
|
///添加日志
|
|
|
|
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<LotNoMode> modelNew = JsonConvert.DeserializeObject<List<LotNoMode>>(json); |
|
|
|
|
|
|
|
//当不存在料品管控条码时,生成新条码
|
|
|
|
if (!(modelNew.Count > 0)) |
|
|
|
{ |
|
|
|
//获取旧条码的信息
|
|
|
|
string jsonStr = ICSControlModeService.QueryLotNo(LotNo, WorkPoint); |
|
|
|
List<LotNoMode> model = JsonConvert.DeserializeObject<List<LotNoMode>>(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<DBValue>(), "", cmd, language); |
|
|
|
|
|
|
|
//更新目标条码库存
|
|
|
|
WareHouseLotInfoMerge(Identification, jointLotNo, LotNo, Quantity, User, WorkPoint, "2", |
|
|
|
TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language); |
|
|
|
|
|
|
|
//合并后日志
|
|
|
|
WareHouseLotInfoLog(Identification, jointLotNo, User, WorkPoint, "2", |
|
|
|
TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), "", cmd, language); |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
throw; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 成品(生产)入库,倒冲
|
|
|
|
if (BusinessCode.Equals(TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>())) |
|
|
|
{ |
|
|
|
#region sql
|
|
|
|
sql = @"-- 1.创建临时表 初始单据数据 maintemp
|
|
|
|
SELECT |
|
|
|
c.MOCode AS TransCode, |
|
|
|
a.MODetailID AS DetailID, |
|
|
|
a.InvCode, |
|
|
|
b.InvName, |
|
|
|
b.InvStd, |
|
|
|
a.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<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(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<DBValue>())) |
|
|
|
{ |
|
|
|
#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 中的已匹配数据删除或更新 |
|
|
|
string sql = string.Empty; |
|
|
|
string locationcode = ""; |
|
|
|
|
|
|
|
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 |
|
|
|
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 |
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
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<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(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")); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd)) |
|
|
|
{ |
|
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo165")); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
throw; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 客供料上架日志记录
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="Identification"></param>
|
|
|
|
/// <param name="LocationCode"></param>
|
|
|
|
/// <param name="LotNo"></param>
|
|
|
|
/// <param name="Quantity"></param>
|
|
|
|
/// <param name="User"></param>
|
|
|
|
/// <param name="WorkPoint"></param>
|
|
|
|
/// <param name="TransType"></param>
|
|
|
|
/// <param name="BusinessCode"></param>
|
|
|
|
/// <param name="cmd"></param>
|
|
|
|
/// <param name="language"></param>
|
|
|
|
/// <param name="LogID"></param>
|
|
|
|
/// <param name="jointLotNo"></param>
|
|
|
|
/// <param name="TransCode"></param>
|
|
|
|
/// <param name="TransSequence"></param>
|
|
|
|
public static void WareHouseLotByClientInfoUpLog(string Identification, string LocationCode, string LotNo, string Quantity, string User, |
|
|
|
string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string LogID, string jointLotNo, string TransCode, string TransSequence) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
string sql = string.Empty; |
|
|
|
|
|
|
|
///添加日志
|
|
|
|
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 ICSInventoryLotDetailKG b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint AND b.TransCode='{8}' AND b.TransSequence='{9}' |
|
|
|
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")); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
@ -8032,6 +7431,24 @@ BEGIN |
|
|
|
|
|
|
|
DROP TABLE #NewTempERP";
|
|
|
|
} |
|
|
|
//客供料入库
|
|
|
|
else if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription()) |
|
|
|
{ |
|
|
|
ERPupdate = @"SELECT a.id
|
|
|
|
INTO #NewTempERP |
|
|
|
FROM ICSWareHouseLotInfoLog a |
|
|
|
INNER JOIN ICSInventoryLotDetailKG b ON a.LotNo=b.LotNo AND b.TransCode=a.TransCode AND b.TransSequence=a.TransSequence 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 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}' |
|
|
|
|
|
|
|
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()) |
|
|
|
{ |
|
|
|