diff --git a/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSubmitService.cs b/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSubmitService.cs index 4420f18..8352468 100644 --- a/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSubmitService.cs +++ b/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSubmitService.cs @@ -1780,6 +1780,7 @@ namespace ICSSoft.DataProject //出库 ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "3", TransTypeEnum.BrrowDoc.GetDescription(), cmd, language, MergeID); + } } #endregion diff --git a/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSWareHouseLotInfoService.cs b/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSWareHouseLotInfoService.cs index 33acec3..a783806 100644 --- a/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSWareHouseLotInfoService.cs +++ b/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSWareHouseLotInfoService.cs @@ -20,10 +20,13 @@ namespace ICSSoft.DataProject { private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + /// - /// 添加库存 + /// 分批 /// - /// + /// + /// + /// /// /// /// @@ -31,7 +34,23 @@ namespace ICSSoft.DataProject /// /// /// - public static void WareHouseLotInfoUp(string Identification, string LocationCode, string LotNo, string Quantity, string User, + 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) { try @@ -133,6 +152,11 @@ namespace ICSSoft.DataProject public static void WareHouseLotInfoDown(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language, string MergeID = "") { + String LotEnable = ""; + String PrintEnable = ""; + string lotstr = ""; + int result = 0; + List NewBarCodeList = new List(); try { ///更新库存 @@ -149,8 +173,118 @@ namespace ICSSoft.DataProject { 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}') + + //检验是否分批 + sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a + LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint + where a.LotNo='{0}' and a.WorkPoint='{1}' + "; + sql = string.Format(sql, LotNo, WorkPoint); + DataTable dt = DBHelper.SQlReturnData(sql, cmd); + if (dt.Rows.Count == 0) + { + throw new Exception(language.GetNameByCode("WMSAPIInfo369")); + } + else + { + LotEnable = dt.Rows[0]["LotEnable"].ToString(); + PrintEnable = dt.Rows[0]["PrintEnable"].ToString(); + } + if (!LotEnable.Equals("False")) + { + #region 获取分批后的条码(lotstr) + sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}' + ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC"; + sql = string.Format(sql, LotNo, WorkPoint); + dt = DBHelper.SQlReturnData(sql, cmd); + if (dt.Rows.Count == 0) + { + lotstr = LotNo + "-" + 1; + } + else + { + lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString(); + } + NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合 + #endregion + + #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零 + sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate, + Quantity,Amount,ExtensionID,Type,PrintTimes, + LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME, + WorkPoint,EATTRIBUTE1) + SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate, + '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes, + a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(), + a.WorkPoint ,'{1}' + From ICSInventoryLot a + where a.LotNo='{1}' and a.WorkPoint='{3}'"; + sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint); + cmd.CommandText = sql; + result = cmd.ExecuteNonQuery(); + if (result <= 0) + { + throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败! + } + sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1) + select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'{2}',InDate,LockQuantity + ,MUSER,MUSERName,GETDATE(),'{3}','' + from ICSWareHouseLotInfo + where LotNO='{1}' AND WorkPoint='{3}'"; + sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint); + cmd.CommandText = sql; + result = cmd.ExecuteNonQuery(); + if (result <= 0) + { + throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败! + } + sql = @"INSERT INTO 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}',a.LotNo ,a.InvCode , + c.WarehouseCode,c.LocationCode,'','','{6}', + '','0','105','{8}','0','', + '','','',f.F_Account ,f.F_RealName , + SYSDATETIME() ,a.WorkPoint ,'{10}','{9}' + FROM ICSInventoryLot a + INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint + INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location + WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' + "; + sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID,lotstr); + cmd.CommandText = sql; + result = cmd.ExecuteNonQuery(); + if (result <= 0) + { + throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败! + } + //sql = @"update ICSWareHouseLotInfo set Quantity-={2} + // where LotNO='{0}' AND WorkPoint='{1}'"; + //sql = string.Format(sql, LotNo, WorkPoint, Quantity); + //cmd.CommandText = sql; + //result = cmd.ExecuteNonQuery(); + //if (result <= 0) + //{ + // throw new Exception(language.GetNameByCode("WMSAPIInfo198"));//条码分批后库存表原条码数量更新失败! + //} + + //if (PrintEnable.Equals("1")) + //{ + // sql = @"select A.LotNO AS OLDLotNo , C.LotQty AS OLDLotQty, A.eattribute1 as LotNO, B.LotQty AS LotQty ,b.ItemCODE,d.INVSTD,d.INVNAME,b.MTIME,d.INVUOM,b.VenderLotNO,b.TransNO + // from ICSWareHouseLotInfolog A + // left join ICSInventoryLot B on A.eattribute1=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.transtype ='105' + // and A.lotno like'{0}%' and a.workpoint='{1}' and a.eattribute1='{2}' + // "; + // sql = string.Format(sql, LotNo, WorkPoint, lotstr); + //} + + ///添加日志 + 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 @@ -171,12 +305,51 @@ namespace ICSSoft.DataProject 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); + sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID); - if (!DBHelper.ExecuteNonQuery(sql, cmd)) + if (!DBHelper.ExecuteNonQuery(sql, cmd)) + { + throw new Exception(language.GetNameByCode("WMSAPIInfo166")); + } + + #endregion + } + else { - throw new Exception(language.GetNameByCode("WMSAPIInfo166")); + 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")); + } } + + + } catch (Exception) { @@ -833,7 +1006,7 @@ namespace ICSSoft.DataProject 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 - Left JOIN ICSOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint + Left JOIN ICSOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint WHERE ISNULL(m.ApplyDetailID,ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' --根据原条码退料-备料表 UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'