diff --git a/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSPurchaseService.cs b/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSPurchaseService.cs index 3808a5c..ad0778b 100644 --- a/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSPurchaseService.cs +++ b/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSPurchaseService.cs @@ -2037,6 +2037,88 @@ IF EXISTS(SELECT b.id FROM ICSPurchaseReceive b where rcvcode in Result result = new Result(); result = JsonConvert.DeserializeObject(resultStr); if (result.Success) + { + //try + //{ + // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString()); + // foreach (var item in res) + // { + // JObject jo = (JObject)item; + // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString()); + // foreach (var detail in resdetail) + // { + // JObject det = (JObject)detail; + + // string ERPupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}' + // where PODetailID='{4}' AND DNType='1' AND DNCode='{5}' and Sequence='{1}'"; + // ERPupdate = string.Format(ERPupdate, jo["DNCode"], det["Sequence"], jo["ID"], det["DetailID"], det["PODetailID"], DNCode); + + // if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd)) + // { + // throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!"); + // } + // } + // } + //} + //catch (Exception ex) + //{ + // log.Debug(ex.ToString()); + // log.Debug(resultStr); + //} + } + else + { + throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message); + } + #endregion + } + catch (Exception) + { + throw; + } + } + #endregion + + #region YS到货单创建 + public static void YSDeliveryNoticeERP(string DNCode, string WorkPoint, SqlCommand cmd, Dictionary language) + { + try + { + #region ERP + string sql = ""; + sql = @"SELECT a.VenCode+a.DepCode+a.MUSER AS Costre,a.VenCode,a.DepCode,y.POCode,a.MUSER,a.MTIME, + a.Sequence,a.InvCode,a.Quantity,CASE invBat.AmountEnable WHEN '1' THEN a.Amount ELSE '0' END AS Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.PODetailID + ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN 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 + INTO #TempERP + FROM ICSDeliveryNotice a + INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint + LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint + INNER JOIN ICSPurchaseOrder y ON a.PODetailID=y.PODetailID AND a.WorkPoint=y.WorkPoint + WHERE a.DNCode='{0}' AND a.WorkPoint='{1}' + + -- SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,POCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP + -- SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,PODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 + -- FROM #TempERP + + SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode + ,CASE (SELECT Enable FROM ICSConfiguration WHERE Code='POCodeDisplayed' AND WorkPoint='{1}') WHEN 0 THEN '' ELSE POCode END AS POCode + ,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP + SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,POCode,PODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 + FROM #TempERP + + DROP TABLE #TempERP"; + sql = string.Format(sql, DNCode, WorkPoint); + + + + DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); + + string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre"); + string resultStr = HTTPHelper.HttpPost("采购到货", ERPUrl.CreatePOArrivURL, Inputstr); + Result result = new Result(); + result = JsonConvert.DeserializeObject(resultStr); + if (result.Success) { try { @@ -2078,5 +2160,7 @@ IF EXISTS(SELECT b.id FROM ICSPurchaseReceive b where rcvcode in } } #endregion + + } } diff --git a/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSubmitService.cs b/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSubmitService.cs index 6e628c3..431fe2a 100644 --- a/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSubmitService.cs +++ b/ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSSubmitService.cs @@ -7365,384 +7365,304 @@ ISNULL(c.MTIME,'') AS MTIME,'' AS VenCode,'' AS cVenName,d.InvUnit,'' AS POCode, } else { - //派纳调拨,不用站点条件 - if (DBHelper.IsPNU9() && TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription()) + if (ScanType == "LOTNO") { - if (ScanType == "LOTNO") - { - sql = @"SELECT a.ID, - con.ContainerCode, - con.ContainerName, - a.LotNo, - a.InvCode, - inv.InvName, - inv.InvStd, - inv.InvUnit, - inv.LotEnable, - {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], - '" + ScanType + @"' AS ScanType - FROM {1} - 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 - WHERE a.LotNo='{2}' "; - } - else + #region 验证是否到货 + if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveDRCoffeeDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveDRCoffeeDoc.GetDescription()) { - sql = @"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], - '" + ScanType + @"' AS ScanType - FROM {1} - LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint - LEFT JOIN ICSBomALL bom ON bom.ID=conlot.ContainerID - 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 - WHERE bom.TContainerCode='{2}' "; + + string arrivalCtrlSql = string.Format(@"IF NOT EXISTS(SELECT + 1 + FROM ICSInventoryLot lot + INNER JOIN ICSASNDetail asde ON asde.LotNo=lot.LotNo AND asde.WorkPoint=lot.WorkPoint + INNER JOIN ICSDeliveryNotice dn ON dn.ASNCode=asde.ASNCode AND dn.WorkPoint=asde.WorkPoint + WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}') + BEGIN + RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo532"), "{0}") + @"',16,1); + RETURN + END", JsonData.Code, JsonData.WorkPoint); + DBHelper.ExecuteNonQuery(arrivalCtrlSql, cmd); + } + if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription()) + { + string arrivalCtrlSql = string.Format(@"IF NOT EXISTS(SELECT + 1 + FROM ICSInventoryLot lot + INNER JOIN ICSOASNDetail asde ON asde.LotNo=lot.LotNo AND asde.WorkPoint=lot.WorkPoint + INNER JOIN ICSODeliveryNotice dn ON dn.OASNCode=asde.OASNCode AND dn.WorkPoint=asde.WorkPoint + WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}' + --铭锋特殊 委外订单和到货单源头均为委外订单 + union + select 1 FROM ICSInventoryLot a + INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint + INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint + INNER JOIN ICSODeliveryNotice d ON b.TransCode=d.ODNCode AND b.TransSequence=d.Sequence AND b.WorkPoint=d.WorkPoint + WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' +) + BEGIN + RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo532"), "{0}") + @"',16,1); + RETURN + END", JsonData.Code, JsonData.WorkPoint); + DBHelper.ExecuteNonQuery(arrivalCtrlSql, cmd); } - } - else - { - if (ScanType == "LOTNO") - { - #region 验证是否到货 - if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveDRCoffeeDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveDRCoffeeDoc.GetDescription()) - { + #endregion - string arrivalCtrlSql = string.Format(@"IF NOT EXISTS(SELECT - 1 - FROM ICSInventoryLot lot - INNER JOIN ICSASNDetail asde ON asde.LotNo=lot.LotNo AND asde.WorkPoint=lot.WorkPoint - INNER JOIN ICSDeliveryNotice dn ON dn.ASNCode=asde.ASNCode AND dn.WorkPoint=asde.WorkPoint - WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}') + //验证条码是否存在 + string verifyLotExistSql = ""; + if (DBHelper.IsPNU9() && TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription()) + { + verifyLotExistSql = string.Format(@"IF NOT EXISTS(SELECT 1 FROM ICSInventoryLot WHERE LotNo='{0}') BEGIN - RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo532"), "{0}") + @"',16,1); + RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{0}") + @"',16,1); RETURN END", JsonData.Code, JsonData.WorkPoint); - DBHelper.ExecuteNonQuery(arrivalCtrlSql, cmd); - } - if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription()) - { - string arrivalCtrlSql = string.Format(@"IF NOT EXISTS(SELECT - 1 - FROM ICSInventoryLot lot - INNER JOIN ICSOASNDetail asde ON asde.LotNo=lot.LotNo AND asde.WorkPoint=lot.WorkPoint - INNER JOIN ICSODeliveryNotice dn ON dn.OASNCode=asde.OASNCode AND dn.WorkPoint=asde.WorkPoint - WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}' - --铭锋特殊 委外订单和到货单源头均为委外订单 - union - select 1 FROM ICSInventoryLot a - INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint - INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint - INNER JOIN ICSODeliveryNotice d ON b.TransCode=d.ODNCode AND b.TransSequence=d.Sequence AND b.WorkPoint=d.WorkPoint - WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' -) + } + else + { + verifyLotExistSql = string.Format(@"IF NOT EXISTS(SELECT 1 FROM ICSInventoryLot WHERE LotNo='{0}' AND WorkPoint='{1}') BEGIN - RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo532"), "{0}") + @"',16,1); + RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{0}") + @"',16,1); RETURN END", JsonData.Code, JsonData.WorkPoint); - DBHelper.ExecuteNonQuery(arrivalCtrlSql, cmd); - } - #endregion + } - //验证条码是否存在 - string verifyLotExistSql = ""; - if (DBHelper.IsPNU9() && TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription()) - { - verifyLotExistSql = string.Format(@"IF NOT EXISTS(SELECT 1 FROM ICSInventoryLot WHERE LotNo='{0}') - BEGIN - RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{0}") + @"',16,1); - RETURN - END", JsonData.Code, JsonData.WorkPoint); - } - else - { - verifyLotExistSql = string.Format(@"IF NOT EXISTS(SELECT 1 FROM ICSInventoryLot WHERE LotNo='{0}' AND WorkPoint='{1}') - BEGIN - RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{0}") + @"',16,1); - RETURN - END", JsonData.Code, JsonData.WorkPoint); - } + DBHelper.ExecuteNonQuery(verifyLotExistSql, cmd); - DBHelper.ExecuteNonQuery(verifyLotExistSql, cmd); + sql = @"SELECT a.ID, + con.ContainerCode, + con.ContainerName, + a.LotNo, + a.InvCode, + inv.InvName, + inv.InvStd, + inv.InvUnit, + inv.LotEnable, + {0} + inv.AmountUnit, + ext.ID AS ExtensionID, + ext.ProjectCode, + ext.Version, + --ext.BatchCode, + isnull((select a.F_EnabledMark from Sys_SRM_ItemsDetail a + inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id + where b.F_id='500fb2a3-c597-4371-ab18-b280b55d571e'),'') AS LotSplitEnable, + 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], + '" + ScanType + @"' AS ScanType + FROM {1} + 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 + WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' "; + } + else + { + #region 验证是否到货 + if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveDRCoffeeDoc.GetDescription()) + { + + string arrivalCtrlSql = string.Format(@"WITH ICSBomALL AS + ( + SELECT + ContainerCode AS TContainerCode, + ContainerCode AS PContainerCode, + ContainerCode AS ContainerCode, + ID, + ContainerID, + WorkPoint, + 0 AS [Level], + CAST(1 AS nvarchar(MAX)) AS SortSeq, + CAST('00001' AS nvarchar(MAX)) AS Sort + FROM ICSContainer + WHERE ContainerCode='{0}' AND WorkPoint='{1}' + UNION ALL + SELECT + b.TContainerCode, + b.ContainerCode AS PContainerCode, + a.ContainerCode, + a.ID, + a.ContainerID, + a.WorkPoint, + b.[Level]+1 AS [Level], + CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq, + CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort + FROM + ICSContainer a + INNER JOIN ICSBomALL b ON a.ContainerID=b.ID AND a.WorkPoint=b.WorkPoint + ) + + SELECT * + INTO #TempICSBomALL + FROM ICSBomALL; + + IF NOT EXISTS(SELECT + 1 + FROM #TempICSBomALL con + INNER JOIN ICSContainerLot conlot ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint + INNER JOIN ICSInventoryLot lot ON lot.LotNo=conlot.LotNo AND lot.WorkPoint=conlot.WorkPoint + INNER JOIN ICSASNDetail asde ON asde.LotNo=lot.LotNo AND asde.WorkPoint=lot.WorkPoint + INNER JOIN ICSDeliveryNotice dn ON dn.ASNCode=asde.ASNCode AND dn.WorkPoint=asde.WorkPoint + WHERE con.TContainerCode='{0}' AND con.WorkPoint='{1}') + BEGIN + RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo532"), "{0}") + @"',16,1); + RETURN + END - sql = @"SELECT a.ID, - con.ContainerCode, - con.ContainerName, - a.LotNo, - a.InvCode, - inv.InvName, - inv.InvStd, - inv.InvUnit, - inv.LotEnable, - {0} - inv.AmountUnit, - ext.ID AS ExtensionID, - ext.ProjectCode, - ext.Version, - --ext.BatchCode, - isnull((select a.F_EnabledMark from Sys_SRM_ItemsDetail a - inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id - where b.F_id='500fb2a3-c597-4371-ab18-b280b55d571e'),'') AS LotSplitEnable, - 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], - '" + ScanType + @"' AS ScanType - FROM {1} - 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 - WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' "; + + + DROP TABLE #TempICSBomALL", JsonData.Code, JsonData.WorkPoint); + DBHelper.ExecuteNonQuery(arrivalCtrlSql, cmd); } - else + if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription()) { - #region 验证是否到货 - if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveDRCoffeeDoc.GetDescription()) - { - - string arrivalCtrlSql = string.Format(@"WITH ICSBomALL AS - ( - SELECT - ContainerCode AS TContainerCode, - ContainerCode AS PContainerCode, - ContainerCode AS ContainerCode, - ID, - ContainerID, - WorkPoint, - 0 AS [Level], - CAST(1 AS nvarchar(MAX)) AS SortSeq, - CAST('00001' AS nvarchar(MAX)) AS Sort - FROM ICSContainer - WHERE ContainerCode='{0}' AND WorkPoint='{1}' - UNION ALL - SELECT - b.TContainerCode, - b.ContainerCode AS PContainerCode, - a.ContainerCode, - a.ID, - a.ContainerID, - a.WorkPoint, - b.[Level]+1 AS [Level], - CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq, - CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort - FROM - ICSContainer a - INNER JOIN ICSBomALL b ON a.ContainerID=b.ID AND a.WorkPoint=b.WorkPoint - ) + string arrivalCtrlSql = string.Format(@"WITH ICSBomALL AS + ( + SELECT + ContainerCode AS TContainerCode, + ContainerCode AS PContainerCode, + ContainerCode AS ContainerCode, + ID, + ContainerID, + WorkPoint, + 0 AS [Level], + CAST(1 AS nvarchar(MAX)) AS SortSeq, + CAST('00001' AS nvarchar(MAX)) AS Sort + FROM ICSContainer + WHERE ContainerCode='{0}' AND WorkPoint='{1}' + UNION ALL + SELECT + b.TContainerCode, + b.ContainerCode AS PContainerCode, + a.ContainerCode, + a.ID, + a.ContainerID, + a.WorkPoint, + b.[Level]+1 AS [Level], + CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq, + CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort + FROM + ICSContainer a + INNER JOIN ICSBomALL b ON a.ContainerID=b.ID AND a.WorkPoint=b.WorkPoint + ) - SELECT * - INTO #TempICSBomALL - FROM ICSBomALL; + SELECT * + INTO #TempICSBomALL + FROM ICSBomALL; + + IF NOT EXISTS(SELECT + 1 + FROM #TempICSBomALL con + INNER JOIN ICSContainerLot conlot ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint + INNER JOIN ICSInventoryLot lot ON lot.LotNo=conlot.LotNo AND lot.WorkPoint=conlot.WorkPoint + INNER JOIN ICSOASNDetail asde ON asde.LotNo=lot.LotNo AND asde.WorkPoint=lot.WorkPoint + INNER JOIN ICSODeliveryNotice dn ON dn.OASNCode=asde.OASNCode AND dn.WorkPoint=asde.WorkPoint + WHERE con.TContainerCode='{0}' AND con.WorkPoint='{1}') + BEGIN + RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo532"), "{0}") + @"',16,1); + RETURN + END - IF NOT EXISTS(SELECT - 1 - FROM #TempICSBomALL con - INNER JOIN ICSContainerLot conlot ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint - INNER JOIN ICSInventoryLot lot ON lot.LotNo=conlot.LotNo AND lot.WorkPoint=conlot.WorkPoint - INNER JOIN ICSASNDetail asde ON asde.LotNo=lot.LotNo AND asde.WorkPoint=lot.WorkPoint - INNER JOIN ICSDeliveryNotice dn ON dn.ASNCode=asde.ASNCode AND dn.WorkPoint=asde.WorkPoint - WHERE con.TContainerCode='{0}' AND con.WorkPoint='{1}') - BEGIN - RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo532"), "{0}") + @"',16,1); - RETURN - END + DROP TABLE #TempICSBomALL", JsonData.Code, JsonData.WorkPoint); + DBHelper.ExecuteNonQuery(arrivalCtrlSql, cmd); + } + #endregion - DROP TABLE #TempICSBomALL", JsonData.Code, JsonData.WorkPoint); - DBHelper.ExecuteNonQuery(arrivalCtrlSql, cmd); - } - if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription()) - { - string arrivalCtrlSql = string.Format(@"WITH ICSBomALL AS - ( - SELECT - ContainerCode AS TContainerCode, - ContainerCode AS PContainerCode, - ContainerCode AS ContainerCode, - ID, - ContainerID, - WorkPoint, - 0 AS [Level], - CAST(1 AS nvarchar(MAX)) AS SortSeq, - CAST('00001' AS nvarchar(MAX)) AS Sort - FROM ICSContainer - WHERE ContainerCode='{0}' AND WorkPoint='{1}' - UNION ALL - SELECT - b.TContainerCode, - b.ContainerCode AS PContainerCode, - a.ContainerCode, - a.ID, - a.ContainerID, - a.WorkPoint, - b.[Level]+1 AS [Level], - CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq, - CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort - FROM - ICSContainer a - INNER JOIN ICSBomALL b ON a.ContainerID=b.ID AND a.WorkPoint=b.WorkPoint - ) + //验证箱号中的条码是否存在 + string verifyLotExistSql = string.Format(@"WITH ICSBomALL AS + ( + SELECT + ContainerCode AS TContainerCode, + ContainerCode AS PContainerCode, + ContainerCode AS ContainerCode, + ID, + ContainerID, + WorkPoint, + 0 AS [Level], + CAST(1 AS nvarchar(MAX)) AS SortSeq, + CAST('00001' AS nvarchar(MAX)) AS Sort + FROM ICSContainer + WHERE ContainerCode='{0}' AND WorkPoint='{1}' + UNION ALL + SELECT + b.TContainerCode, + b.ContainerCode AS PContainerCode, + a.ContainerCode, + a.ID, + a.ContainerID, + a.WorkPoint, + b.[Level]+1 AS [Level], + CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq, + CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort + FROM + ICSContainer a + INNER JOIN ICSBomALL b ON a.ContainerID=b.ID AND a.WorkPoint=b.WorkPoint + ) - SELECT * - INTO #TempICSBomALL - FROM ICSBomALL; - - IF NOT EXISTS(SELECT - 1 - FROM #TempICSBomALL con - INNER JOIN ICSContainerLot conlot ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint - INNER JOIN ICSInventoryLot lot ON lot.LotNo=conlot.LotNo AND lot.WorkPoint=conlot.WorkPoint - INNER JOIN ICSOASNDetail asde ON asde.LotNo=lot.LotNo AND asde.WorkPoint=lot.WorkPoint - INNER JOIN ICSODeliveryNotice dn ON dn.OASNCode=asde.OASNCode AND dn.WorkPoint=asde.WorkPoint - WHERE con.TContainerCode='{0}' AND con.WorkPoint='{1}') + SELECT * + INTO #TempICSBomALL + FROM ICSBomALL; + + IF NOT EXISTS(SELECT 1 FROM #TempICSBomALL a + INNER JOIN ICSContainerLot b ON b.ContainerID=a.ID AND b.WorkPoint=a.WorkPoint + INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint + WHERE a.TContainerCode='{0}' AND a.WorkPoint='{1}') BEGIN - RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo532"), "{0}") + @"',16,1); + RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{0}") + @"',16,1); RETURN END + DROP TABLE #TempICSBomALL", JsonData.Code, JsonData.WorkPoint); + DBHelper.ExecuteNonQuery(verifyLotExistSql, cmd); - - DROP TABLE #TempICSBomALL", JsonData.Code, JsonData.WorkPoint); - DBHelper.ExecuteNonQuery(arrivalCtrlSql, cmd); - } - #endregion - - //验证箱号中的条码是否存在 - string verifyLotExistSql = string.Format(@"WITH ICSBomALL AS - ( - SELECT - ContainerCode AS TContainerCode, - ContainerCode AS PContainerCode, - ContainerCode AS ContainerCode, - ID, - ContainerID, - WorkPoint, - 0 AS [Level], - CAST(1 AS nvarchar(MAX)) AS SortSeq, - CAST('00001' AS nvarchar(MAX)) AS Sort - FROM ICSContainer - WHERE ContainerCode='{0}' AND WorkPoint='{1}' - UNION ALL - SELECT - b.TContainerCode, - b.ContainerCode AS PContainerCode, - a.ContainerCode, - a.ID, - a.ContainerID, - a.WorkPoint, - b.[Level]+1 AS [Level], - CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq, - CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort - FROM - ICSContainer a - INNER JOIN ICSBomALL b ON a.ContainerID=b.ID AND a.WorkPoint=b.WorkPoint - ) - - SELECT * - INTO #TempICSBomALL - FROM ICSBomALL; - - IF NOT EXISTS(SELECT 1 FROM #TempICSBomALL a - INNER JOIN ICSContainerLot b ON b.ContainerID=a.ID AND b.WorkPoint=a.WorkPoint - INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint - WHERE a.TContainerCode='{0}' AND a.WorkPoint='{1}') - BEGIN - RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{0}") + @"',16,1); - RETURN - END - - DROP TABLE #TempICSBomALL", JsonData.Code, JsonData.WorkPoint); - DBHelper.ExecuteNonQuery(verifyLotExistSql, cmd); - - sql = @"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], - '" + ScanType + @"' AS ScanType - FROM {1} - LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint - LEFT JOIN #TempICSBomALL bom ON bom.ID=conlot.ContainerID - 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 - WHERE bom.TContainerCode='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0"; - } + sql = @"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], + '" + ScanType + @"' AS ScanType + FROM {1} + LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint + LEFT JOIN #TempICSBomALL bom ON bom.ID=conlot.ContainerID + 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 + WHERE bom.TContainerCode='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0"; } + } @@ -9291,55 +9211,18 @@ BEGIN || TransType == TransTypeEnum.MOStockINByProduct.GetDescription() || TransType == TransTypeEnum.OtherInDoc.GetDescription() || TransType == TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription() || TransType == TransTypeEnum.ManufactureMESReceive.GetDescription()) && needIns) { - if (DBHelper.IsPNU9() && TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription()) - { - columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity, - a.Quantity*(a.Amount/a.Quantity) AS Amount, - isnull(pev.EATTRIBUTE3,'') AS VenName, - {0},{2}, - lotdd.TransCode,lotdd.TransSequence, - {3} - {1} - ext.BatchCode AS BatchCode,"; - - tableName = @"ICSInventoryLot a - INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint - LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint - LEFT JOIN ICSPurchaseReceive pev ON lotdd.TransCode=pev.RCVCode AND lotdd.TransSequence=pev.Sequence AND lotdd.WorkPoint=pev.WorkPoint - LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1"; - } - else if (DBHelper.IsPNU9() && TransType == TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription()) - { - columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity, - a.Quantity*(a.Amount/a.Quantity) AS Amount, - isnull(pev.EATTRIBUTE3,'') AS VenName, - {0},{2}, - lotdd.TransCode,lotdd.TransSequence, - {3} - {1} - ext.BatchCode AS BatchCode,"; - - tableName = @"ICSInventoryLot a - INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint - LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint - LEFT JOIN ICSOutsourcingReceive pev ON lotdd.TransCode=pev.RCVCode AND lotdd.TransSequence=pev.Sequence AND lotdd.WorkPoint=pev.WorkPoint - LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1"; - } - else - { - columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity, - a.Quantity*(a.Amount/a.Quantity) AS Amount, - {0},{2}, - lotdd.TransCode,lotdd.TransSequence, - {3} - {1} - ext.BatchCode AS BatchCode,"; + columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity, + a.Quantity*(a.Amount/a.Quantity) AS Amount, + {0},{2}, + lotdd.TransCode,lotdd.TransSequence, + {3} + {1} + ext.BatchCode AS BatchCode,"; - tableName = @"ICSInventoryLot a - INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint - LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint - LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1"; - } + tableName = @"ICSInventoryLot a + INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint + LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint + LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1"; } else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription()) @@ -32881,7 +32764,144 @@ END as NEWLotNo } } - public static DataTable YSDeliveryNoticeApprove(List JsonData) + public static DataTable YSDeliveryNoticeApprove(List JsonData) + { + var language = LanguageHelper.GetName("WMSAPIInfo"); + if (JsonData.Count <= 0) + { + throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!" + } + using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString)) + { + conn.Open(); + SqlTransaction sqlTran = conn.BeginTransaction(); + SqlCommand cmd = new SqlCommand(); + cmd.Transaction = sqlTran; + cmd.Connection = conn; + cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]); + try + { + string DNCodes = string.Empty; + string DNLotNo = string.Empty; + string sql = string.Empty; + + foreach (var item in JsonData) + { + sql = string.Format(@"UPDATE ICSDeliveryNotice SET STATUS='2' WHERE DNCode='{0}' AND WorkPoint='{1}' AND STATUS='1'", item.DNCode, item.WorkPoint); + //修改送货单到货数量 + foreach (var itemInfo in item.detail) + { + string detailSql = @"UPDATE ICSInventoryLot SET EATTRIBUTE15='' WHERE LotNo='{0}' AND WorkPoint='{4}' + IF EXISTS(SELECT 1 FROM ICSInventoryLotDetail WHERE LotNo='{0}' AND WorkPoint='{4}') + BEGIN + UPDATE ICSInventoryLotDetail SET TransCode='{1}',TransSequence='{2}',TransID='{5}' WHERE LotNo='{0}' AND WorkPoint='{4}' + END + ELSE + BEGIN + Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint,TransID) + Values('{0}','{1}','{2}','{3}',(SELECT F_RealName FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{4}'),getdate(),'{4}','{5}') + END + "; + detailSql = string.Format(detailSql, itemInfo.LotNo, item.DNCode, itemInfo.Sequence, item.User, item.WorkPoint, item.ID, itemInfo.locationCode); + sql += detailSql; + } + + sql = string.Format(@"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}') + BEGIN + RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{0}") + @"',16,1); + RETURN + END + ", item.User, item.WorkPoint) + sql; + if (!DBHelper.ExecuteNonQuery(sql, cmd)) + { + throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败! + } + + string sqlCheckSign = @"select * from ICSConfiguration where code = 'UploadERP001' and enable = '1'"; + DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd); + if (flag != null && flag.Rows.Count > 0) + { + if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"])) + { + ICSPurchaseService.YSDeliveryNoticeApproveERP(JsonData[0].DNCode, item.WorkPoint, cmd, language); + } + } + + DNCodes += "'" + item.DNCode + item.WorkPoint + "',"; + } + if (string.IsNullOrWhiteSpace(DNCodes)) + { + throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!"); + } + #region 查询返回数据 + sql = @"SELECT + n.POCode, + n.Sequence AS POSequence, + a.ASNCode, + a.DNCode, + a.Sequence, + a.VenCode, + a.DepCode, + a.InvCode, + inv.InvName, + inv.InvStd, + a.Quantity, + inv.InvUnit, + a.Amount, + inv.AmountUnit, + a.RCVQuantity, + a.UnitPrice, + a.Currency, + a.POID, + a.PODetailID, + a.DNID, + a.DNDetailID, + 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, + a.MUSER AS [User], + a.MTIME AS [MTime] + FROM ICSDeliveryNotice a + INNER JOIN ICSPurchaseOrder n ON a.POID =n.POID AND a.PODetailID=n.PODetailID AND a.WorkPoint=n.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 + WHERE a.DNCode+a.WorkPoint IN ({0}) AND a.STATUS='2'"; + sql = string.Format(sql, DNCodes.Substring(0, DNCodes.Length - 1)); + DataTable data = DBHelper.SQlReturnData(sql, cmd); + #endregion + cmd.Transaction.Commit(); + return data; + } + catch (Exception ex) + { + if (cmd.Transaction != null) + cmd.Transaction.Rollback(); + log.Error(ex.Message); + throw new Exception(ex.Message); + } + finally + { + if (conn.State == ConnectionState.Open) + { + conn.Close(); + } + conn.Dispose(); + } + } + } + + public static DataTable YSDeliveryNoticeCreate(List JsonData) { var language = LanguageHelper.GetName("WMSAPIInfo"); if (JsonData.Count <= 0) @@ -32898,40 +32918,202 @@ END as NEWLotNo cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]); try { + string asncodes = string.Empty; string DNCodes = string.Empty; string DNLotNo = string.Empty; string sql = string.Empty; - + string picname = string.Empty; + string Colspan = ""; + string IDD = ""; + string whcode = ""; foreach (var item in JsonData) { - sql = string.Format(@"UPDATE ICSDeliveryNotice SET STATUS='2' WHERE DNCode='{0}' AND WorkPoint='{1}' AND STATUS='1'", item.DNCode, item.WorkPoint); + if (string.IsNullOrEmpty(item.ASNCode)) + { + throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!" + } + + sql = @"SELECT a.DNCode FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}'"; + sql = string.Format(sql, item.ASNCode, item.WorkPoint); + DataTable dt = DBHelper.SQlReturnData(sql, cmd); + if (dt.Rows.Count > 0) + { + DNCodes = dt.Rows[0]["DNCode"].ToString(); + } + + + //获取单号 + sql = @"IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}') + BEGIN + RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1); + RETURN + END + DECLARE @Status VARCHAR(10) + SELECT @Status=Status FROM ICSASN WHERE ASNCode='{0}' and WorkPoint='{1}' + + IF (@Status IS NULL) + BEGIN + RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1); + RETURN + END + ELSE IF (@Status!='2') + BEGIN + RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1); + RETURN + END + + DECLARE @MaxNO INT,@date varchar(20)='DN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8) + SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice + WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date + IF @MaxNO IS NULL + BEGIN + SELECT @date+'00001' AS Code + END + ELSE + BEGIN + SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code + END "; + sql = string.Format(sql, item.ASNCode, item.WorkPoint, DNCodes); + string Code = DBHelper.ExecuteScalar(sql, cmd).ToString(); //修改送货单到货数量 foreach (var itemInfo in item.detail) { - string detailSql = @"UPDATE ICSInventoryLot SET EATTRIBUTE15='' WHERE LotNo='{0}' AND WorkPoint='{4}' - IF EXISTS(SELECT 1 FROM ICSInventoryLotDetail WHERE LotNo='{0}' AND WorkPoint='{4}') - BEGIN - UPDATE ICSInventoryLotDetail SET TransCode='{1}',TransSequence='{2}',TransID='{5}' WHERE LotNo='{0}' AND WorkPoint='{4}' - END - ELSE - BEGIN - Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint,TransID) - Values('{0}','{1}','{2}','{3}',(SELECT F_RealName FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{4}'),getdate(),'{4}','{5}') - END - "; - detailSql = string.Format(detailSql, itemInfo.LotNo, item.DNCode, itemInfo.Sequence, item.User, item.WorkPoint, item.ID, itemInfo.locationCode); - sql += detailSql; + if (string.IsNullOrEmpty(itemInfo.TransSequence)) + { + picname = ""; + } + else + { + picname = itemInfo.TransSequence; + } + sql = @" + + UPDATE ICSASNDetail SET DNQuantity=ISNULL(DNQuantity, 0)+'{2}' + WHERE LotNo='{0}' AND WorkPoint='{1}' + IF EXISTS(SELECT id FROM ICSASNDetail WHERE LotNo='{0}' AND WorkPoint='{1}' AND Quantity 0 && dtdao != null) + { + whcode = dtdao.Rows[0]["F_itemCode"].ToString(); + + //创建到货单信息 + sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}') + BEGIN + RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1); + RETURN + END + +Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10) +SELECT DISTINCT newid(),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, ''),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 +FROM ICSASNDetail a + INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint +INNER JOIN ICSExtension ext ON b.ExtensionID=ext.ID AND b.WorkPoint=ext.WorkPoint +LEFT JOIN ICSInventory inv ON b.InvCode=inv.InvCode AND b.WorkPoint=inv.WorkPoint +LEFT JOIN ICSInventoryBatchEnable invBat ON b.InvCode=invBat.InvCode AND '{5}'=invBat.WHCode AND b.WorkPoint=invBat.WorkPoint +INNER JOIN ICSExtension extt ON 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, '')=extt.Colspan + +WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}' and a.DNQuantity>0 AND ext.id is NULL + + INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode, + DNType,InvCode,Quantity,Amount,RCVQuantity, + UnitPrice,Currency,Status,CreatePerson,CreateDateTime, + POID,PODetailID,DNID,DNDetailID,ExtensionID, + MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode,EATTRIBUTE8) + SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode, + '1',b.InvCode,SUM(a.DNQuantity),'0','0', + d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(), + d.POID,d.PODetailID,'{0}',newid(),extt.ID, + e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.ASNCode,'{4}' + FROM ICSASNDetail a + INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint + INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint +INNER JOIN ICSExtension ext ON b.ExtensionID=ext.ID AND b.WorkPoint=ext.WorkPoint +LEFT JOIN ICSInventory inv ON b.InvCode=inv.InvCode AND b.WorkPoint=inv.WorkPoint +LEFT JOIN ICSInventoryBatchEnable invBat ON b.InvCode=invBat.InvCode AND '{5}'=invBat.WHCode AND b.WorkPoint=invBat.WorkPoint +INNER JOIN ICSExtension extt ON 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, '')=extt.Colspan + + INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint + INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}' + WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}' and a.DNQuantity>0 + GROUP BY d.POID,d.PODetailID,d.VenCode,d.UnitPrice,d.Currency,d.DepCode,b.InvCode,a.ASNCode,e.F_Account,e.F_RealName,a.WorkPoint,extt.ID"; + sql = string.Format(sql, Code, item.User, item.WorkPoint, item.ASNCode, picname, whcode); + } + else + { + //创建到货单信息 + sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}') + BEGIN + RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1); + RETURN + END + + INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode, + DNType,InvCode,Quantity,Amount,RCVQuantity, + UnitPrice,Currency,Status,CreatePerson,CreateDateTime, + POID,PODetailID,DNID,DNDetailID,ExtensionID, + MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode,EATTRIBUTE8) + SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode, + '1',b.InvCode,SUM(a.DNQuantity),'0','0', + d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(), + d.POID,d.PODetailID,'{0}',newid(),b.ExtensionID, + e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.ASNCode,'{4}' + FROM ICSASNDetail a + INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint + INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint + INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint + INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}' + WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}' and a.DNQuantity>0 + GROUP BY d.POID,d.PODetailID,d.VenCode,d.UnitPrice,d.Currency,d.DepCode,b.ExtensionID,b.InvCode,a.ASNCode,e.F_Account,e.F_RealName,a.WorkPoint"; + sql = string.Format(sql, Code, item.User, item.WorkPoint, item.ASNCode, picname); + } + + if (!DBHelper.ExecuteNonQuery(sql, cmd)) { - throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败! + throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!"); } string sqlCheckSign = @"select * from ICSConfiguration where code = 'UploadERP001' and enable = '1'"; @@ -32940,13 +33122,13 @@ END as NEWLotNo { if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"])) { - ICSPurchaseService.YSDeliveryNoticeApproveERP(JsonData[0].DNCode, item.WorkPoint, cmd, language); + ICSPurchaseService.YSDeliveryNoticeERP(Code, item.WorkPoint, cmd, language); } } - DNCodes += "'" + item.DNCode + item.WorkPoint + "',"; + asncodes += "'" + item.ASNCode + item.WorkPoint + "',"; } - if (string.IsNullOrWhiteSpace(DNCodes)) + if (string.IsNullOrWhiteSpace(asncodes)) { throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!"); } @@ -32993,8 +33175,8 @@ END as NEWLotNo INNER JOIN ICSPurchaseOrder n ON a.POID =n.POID AND a.PODetailID=n.PODetailID AND a.WorkPoint=n.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 - WHERE a.DNCode+a.WorkPoint IN ({0}) AND a.STATUS='2'"; - sql = string.Format(sql, DNCodes.Substring(0, DNCodes.Length - 1)); + WHERE a.ASNCode+a.WorkPoint IN ({0})"; + sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1)); DataTable data = DBHelper.SQlReturnData(sql, cmd); #endregion cmd.Transaction.Commit(); @@ -33018,7 +33200,5 @@ END as NEWLotNo } } - - } } \ No newline at end of file diff --git a/ICSSoft.WMS.WebAPI/ICSSoft.WMS.WebAPI/Controllers/WMSBarCoreController.cs b/ICSSoft.WMS.WebAPI/ICSSoft.WMS.WebAPI/Controllers/WMSBarCoreController.cs index 9f59863..c3205e3 100644 --- a/ICSSoft.WMS.WebAPI/ICSSoft.WMS.WebAPI/Controllers/WMSBarCoreController.cs +++ b/ICSSoft.WMS.WebAPI/ICSSoft.WMS.WebAPI/Controllers/WMSBarCoreController.cs @@ -159,148 +159,7 @@ namespace ICSSoft.WebAPI.Controllers log.Debug("获取层级返回值:" + str); return result; } - //#region 委外送货单 - ///// - ///// 委外送货单查询 - ///// - ///// - //[HttpPost] - //[Route("api/AdvancedShipmentNotice/NoticeGet")] - //public HttpResponseMessage NoticeGET([FromBody] object JsonData) - //{ - // log.Info("委外送货单信息传入值" + JsonData); - // try - // { - // if (JsonData != null && !string.IsNullOrWhiteSpace(JsonData.ToString()) && JsonData.ToString() != "[]") - // { - // OutsourcingModel model = new OutsourcingModel(); - // model = JsonConvert.DeserializeObject(JsonData.ToString()); - // OutsourcingSevice action = new OutsourcingSevice(); - // OutsourcingModelInfo resultStr = action.Get(model); - // if (resultStr == null) - // { - // res.Success = false; - // res.Message = LanguageHelper.GetNameSingle("WMSAPI003");//"未查询到相关数据!"; - // } - // else - // { - // res.Success = true; - // res.Message = LanguageHelper.GetNameSingle("WMSAPI001");// "接口调用成功!"; - // res.Data = resultStr; - // } - - // } - // } - // catch (Exception ex) - // { - // log.Error("转换失败:" + ex.ToString()); - // res.Success = false; - // res.Message = ex.Message; - // } - // finally - // { - // str = JsonConvert.SerializeObject(res); - // result.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); - // } - // log.Debug("委外送货单信息返回值:" + str); - // return result; - //} - //#endregion - - - ///// - ///// 委外送货单添加 - ///// - ///// - ///// - //[HttpPost] - //[Route("api/AdvancedShipmentNotice/NoticeCreate")] - //public HttpResponseMessage NoticeCreate([FromBody] object JsonData) - //{ - // log.Info("委外送货单添加信息传入值" + JsonData); - // try - // { - // if (JsonData != null && !string.IsNullOrWhiteSpace(JsonData.ToString()) && JsonData.ToString() != "[]") - // { - // List model = new List(); - // model = JsonConvert.DeserializeObject>(JsonData.ToString()); - // OutsourcingSevice action = new OutsourcingSevice(); - // var resultStr = action.Create(model); - // if (resultStr < 0) - // { - // res.Success = false; - // res.Message = LanguageHelper.GetNameSingle("WMSAPI003");//"未查询到相关数据!"; - // } - // else - // { - // res.Success = true; - // res.Message = LanguageHelper.GetNameSingle("WMSAPI001");// "接口调用成功!"; - // res.Data = null; - // } - - // } - // } - // catch (Exception ex) - // { - // log.Error("转换失败:" + ex.ToString()); - // res.Success = false; - // res.Message = ex.Message; - // } - // finally - // { - // str = JsonConvert.SerializeObject(res); - // result.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); - // } - // log.Debug("委外送货单信息返回值:" + str); - // return result; - //} - - ///// - ///// 委外送货单删除 - ///// - ///// - ///// - //[HttpPost] - //[Route("api/AdvancedShipmentNotice/NoticeDelete")] - //public HttpResponseMessage NoticeDelete([FromBody] object JsonData) - //{ - // log.Info("委外送货单删除信息传入值" + JsonData); - // try - // { - // if (JsonData != null && !string.IsNullOrWhiteSpace(JsonData.ToString()) && JsonData.ToString() != "[]") - // { - // NoticeDelete model = new NoticeDelete(); - // model = JsonConvert.DeserializeObject(JsonData.ToString()); - // OutsourcingSevice action = new OutsourcingSevice(); - // var resultStr = action.Delete(model); - // if (resultStr == null) - // { - // res.Success = false; - // res.Message = LanguageHelper.GetNameSingle("WMSAPI003");//"未查询到相关数据!"; - // } - // else - // { - // res.Success = true; - // res.Message = LanguageHelper.GetNameSingle("WMSAPI001");// "接口调用成功!"; - // res.Data = resultStr; - // } - - // } - // } - // catch (Exception ex) - // { - // log.Error("转换失败:" + ex.ToString()); - // res.Success = false; - // res.Message = ex.Message; - // } - // finally - // { - // str = JsonConvert.SerializeObject(res); - // result.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); - // } - // log.Debug("委外送货单删除信息返回值:" + str); - // return result; - //} + /// /// 使用中 /// 获取源头单据信息 @@ -930,10 +789,6 @@ namespace ICSSoft.WebAPI.Controllers { BarCodeModel model = new BarCodeModel(); model = JsonConvert.DeserializeObject(JsonData.ToString()); - //var resultStr = ICSSubmitService.BarCodeInformationGet(model); - //res.Success = true; - //res.Message = LanguageHelper.GetNameSingle("WMSAPI001");// "接口调用成功!"; - //res.Data = resultStr; lock (key) { res = ICSSubmitService.BarCodeInformationGet(model); @@ -6936,6 +6791,40 @@ namespace ICSSoft.WebAPI.Controllers return result; } + [HttpPost] + [Route("api/YSDeliveryNotice/Create")] + public HttpResponseMessage YSDeliveryNoticeCreate([FromBody] object JsonData) + { + log.Info("采购到货传入值" + JsonData); + try + { + List model = new List(); + if (JsonData != null && !string.IsNullOrWhiteSpace(JsonData.ToString()) && JsonData.ToString() != "[]") + { + model = JsonConvert.DeserializeObject>(JsonData.ToString()); + var resultStr = ICSSubmitService.DeliveryNoticeCreate(model); + res.Success = true; + res.Message = LanguageHelper.GetNameSingle("WMSAPI001") + "到货单号:" + resultStr.Rows[0]["DNCode"];// "接口调用成功!"; + if (resultStr != null && resultStr.Rows.Count > 0 && resultStr.ToString() != "[]") + { + res.Data = resultStr; + } + } + } + catch (Exception ex) + { + log.Error("转换失败:" + ex.ToString()); + res.Success = false; + res.Message = ex.Message; + } + finally + { + str = JsonConvert.SerializeObject(res); + result.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); + } + log.Debug("采购到货返回值:" + str); + return result; + } } diff --git a/ICSSoft.WMS.WebAPI/ICSSoft.WMS.WebAPI/Web.config b/ICSSoft.WMS.WebAPI/ICSSoft.WMS.WebAPI/Web.config index c3bb6a4..0c24f9f 100644 --- a/ICSSoft.WMS.WebAPI/ICSSoft.WMS.WebAPI/Web.config +++ b/ICSSoft.WMS.WebAPI/ICSSoft.WMS.WebAPI/Web.config @@ -8,7 +8,7 @@ - + @@ -20,7 +20,7 @@ - +