From 4300fa0abc42743e6e5360cb31a7faa37e5c5eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E9=B9=8F?= Date: Mon, 28 Apr 2025 13:57:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E4=BE=9B=E6=96=99=E6=9D=A1=E7=A0=81?= =?UTF-8?q?=E4=B8=8A=E6=9E=B6=E3=80=81=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E4=BA=A4ERP=E3=80=81=E5=9B=9E=E5=86=99ERP?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ICSSoft.DataProject/ICSPurchaseService.cs | 21 +- .../ICSSoft.DataProject/ICSSubmitService.cs | 15 +- .../ICSWareHouseLotInfoService.cs | 841 +++--------------- 3 files changed, 150 insertions(+), 727 deletions(-) diff --git a/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSPurchaseService.cs b/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSPurchaseService.cs index 2edb4e1..648b6c6 100644 --- a/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSPurchaseService.cs +++ b/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSPurchaseService.cs @@ -2229,28 +2229,25 @@ IF EXISTS(SELECT b.id FROM ICSPurchaseReceive b where rcvcode in SELECT Identification,c.VenCode+a.ToWarehouseCode+c.POCode+a.MUSER+CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS Costre,a.TransCode+a.TransSequence+CONVERT(VARCHAR,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.POCode,c.PODetailID,a.InvCode)) AS Costre2,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.POCode,CASE WHEN(LEN(f.DNDetailID)=36) THEN '' ELSE f.DNCode END AS DNCode,CASE WHEN((LEN(f.DNDetailID)<>36)) THEN '1' ELSE '0' END AS HasDN,a.MUSER,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.Sequence END AS DNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.POCode,c.PODetailID,a.InvCode) AS Sequence,a.TransSequence, a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.PODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose,case when ConErp.enable=1 then f.DNDetailID else '' end AS DNDetailID - ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS 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 AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand, - ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10 + ,a.WorkPoint INTO #TempERP FROM #NewTempERP 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.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint 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 f ON b.TransCode=f.DNCode AND f.Sequence=b.TransSequence AND b.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID - INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint + INNER JOIN ICSDeliveryNotice f ON b.TransCode=f.DNCode AND f.Sequence=b.TransSequence AND b.WorkPoint=f.WorkPoint + INNER JOIN ICSPurchaseOrder c ON f.POID=c.POID AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conn ON a.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001' INNER JOIN ICSConfiguration ConErp ON a.WorkPoint=ConErp.WorkPoint AND ConErp.Code='UploadERP001' INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001' INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose003' GROUP BY ConErp.Enable,a.TransCode,a.Identification,a.TransSequence,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.POCode,f.DNDetailID,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END,f.DNID,a.MUSER,a.InvCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.Sequence END,c.PODetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable,conStock.Enable,conStocknew.Enable - ,a.WorkPoint,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, ''),f.DNCode + ,a.WorkPoint,f.DNCode SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,POCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,UpdateStock,IsFillClose FROM #TempERP - SELECT Costre, Costre2,Sequence,DNSequence,InvCode,Quantity,Amount,PODetailID,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WarehouseCode AS WHCode + SELECT Costre, Costre2,Sequence,DNSequence,InvCode,Quantity,Amount,PODetailID,DNDetailID,Currency,UnitPrice,WarehouseCode AS WHCode FROM #TempERP SELECT a.LotNo,SUM(a.Quantity) AS Quantity,te.Costre2,a.Identification @@ -2259,10 +2256,9 @@ IF EXISTS(SELECT b.id FROM ICSPurchaseReceive b where rcvcode in 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 - INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint - INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint - INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID - INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint + 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 f ON f.DNCode=b.TransCode AND f.Sequence=b.TransSequence AND f.WorkPoint=b.WorkPoint + INNER JOIN ICSPurchaseOrder c ON f.POID=c.POID AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint INNER JOIN #TempERP te ON te.TransSequence=a.TransSequence WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}' GROUP BY a.LotNo,a.Identification,a.TransCode,a.TransSequence,c.VenCode,a.ToWarehouseCode,c.POCode,c.PODetailID,a.InvCode,te.Sequence,te.Costre2 @@ -2271,6 +2267,7 @@ IF EXISTS(SELECT b.id FROM ICSPurchaseReceive b where rcvcode in DROP TABLE #TempERP DROP TABLE #NewTempERP + "; sql = string.Format(sql, Identification, BusinessCode); diff --git a/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSubmitService.cs b/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSubmitService.cs index 2b46495..bc3ebc1 100644 --- a/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSubmitService.cs +++ b/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSubmitService.cs @@ -10711,10 +10711,19 @@ BEGIN item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode, itemInfo.TransCode, itemInfo.TransSequence); } } - + foreach (var item in JsonData) + { + foreach (var itemInfo in item.detail) + { + //记录日志 + ICSWareHouseLotInfoService.WareHouseLotByClientInfoUpLog(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, + item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode, itemInfo.TransCode, itemInfo.TransSequence); + } + } - //上传ERP - if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"])) + + //上传ERP + if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"])) { if (TransTypeOriginal != string.Empty) { diff --git a/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSWareHouseLotInfoService.cs b/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSWareHouseLotInfoService.cs index e266448..78c8ee0 100644 --- a/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSWareHouseLotInfoService.cs +++ b/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSWareHouseLotInfoService.cs @@ -2247,7 +2247,7 @@ where d.LotNo='{0}' and a.WorkPoint='{1}' and a.SupplyType='1' and a.quantity>0" } } /// - /// 添加库存(奥美专用) + /// 客供料添加库存 /// /// /// @@ -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()) - { - 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='{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()) - { - ///添加日志 - 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.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 中的已匹配数据删除或更新 + 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 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")); - } - } + if (!DBHelper.ExecuteNonQuery(sql, cmd)) + { + throw new Exception(language.GetNameByCode("WMSAPIInfo165")); } - #endregion - + } + catch (Exception) + { + throw; + } + } + /// + /// 客供料上架日志记录 + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static void WareHouseLotByClientInfoUpLog(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 + { + 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()) {