using ICSSoft.Common; using ICSSoft.Entity; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Net.Http; using System.Text; using System.Threading.Tasks; namespace ICSSoft.DataProject { /// /// 使用中 /// 采购模块 /// public class ICSPurchaseService { private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #region 采购到货 /// /// 采购到货接口 /// /// /// /// public static void DeliveryNoticeERP(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 { 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 采购入库 /// /// 采购入库 /// /// /// /// /// /// public static void PurchaseReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary language) { try { string sql = @"DECLARE @Status VARCHAR(10) SELECT @Status=c.Status FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1); RETURN END ELSE IF (@Status='3') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1); RETURN END UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}' FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn001', c.Quantity,1,1,'') /// 采购入库接口 /// /// /// /// public static void PurchaseReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary language,string BusinessCode) { try { #region ERP string sql = ""; //到货指定仓库(批次汇总) string Dsql = @"SELECT a.F_itemCode FROM Sys_SRM_ItemsDetail a INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1'"; Dsql = string.Format(Dsql); DataTable dtdao = DBHelper.SQlReturnData(Dsql, cmd); if (dtdao.Rows.Count > 0 && dtdao != null) { sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,Identification INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}' 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,conWhCode.Enable AS ErpWhCode ,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 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 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 ICSExtension extd ON f.ExtensionID=extd.ID AND f.WorkPoint=extd.WorkPoint 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 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' LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint where ISNULL(extd.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(extd.BatchCode, '') ELSE '' END+'~'+ISNULL(extd.Version, '')+'~'+ISNULL(extd.Brand, '')+'~'+ ISNULL(extd.cFree1, '')+'~'+ISNULL(extd.cFree2, '')+'~'+ISNULL(extd.cFree3, '')+'~'+ISNULL(extd.cFree4, '')+'~'+ISNULL(extd.cFree5, '')+'~'+ISNULL(extd.cFree6, '')+'~'+ISNULL(extd.cFree7, '')+'~'+ISNULL(extd.cFree8, '')+'~'+ISNULL(extd.cFree9, '')+'~'+ISNULL(extd.cFree10, '')=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, '') GROUP BY conWhCode.Enable,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 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,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Amount,PODetailID,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP SELECT a.LotNo,SUM(a.Quantity) AS Quantity,te.Costre2,a.Identification FROM ICSWareHouseLotInfoLog a INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.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 #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 SELECT DISTINCT HasDN FROM #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP "; } else { sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,Identification INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}' 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 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 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 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 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 FROM #TempERP SELECT a.LotNo,SUM(a.Quantity) AS Quantity,te.Costre2,a.Identification FROM ICSWareHouseLotInfoLog a INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.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 #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 SELECT DISTINCT HasDN FROM #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP "; } sql = string.Format(sql, Identification, BusinessCode); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre"); string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2"); var IsDNCode = ds.Tables[3]; if (IsDNCode == null || IsDNCode.Rows.Count != 1) { throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种! } string dncode = Convert.ToString(IsDNCode.Rows[0]["HasDN"]); if (dncode.Equals("0")) { string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DeliveryNoticeURL, Inputstr); 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 allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString() + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString(); ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode); } } } catch (Exception ex) { log.Debug(ex.ToString()); log.Debug(resultStr); } } else { throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message); } } else { string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseOrderURL, Inputstr); 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 allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString() + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString(); ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode); } } } catch (Exception ex) { log.Debug(ex.ToString()); log.Debug(resultStr); } } else { throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message); } } #endregion } catch (Exception) { log.Error(000); throw; } } /// /// 创建标准收货单U9(采购) /// /// /// /// public static void CreatePOArriveERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode,string doctype) { try { #region ERP string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}' SELECT c.VenCode+a.ToWarehouseCode+c.POCode+a.MUSER+CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS DNCode,CASE WHEN(LEN(f.DNID)>=20) 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.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 --,a.lotno AS Costre2 ,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 ,'{2}' as DocTyppe,getdate() as DocDate,c.Sequence as srcDocPOLineNo 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 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 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 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-- a.LotNo, a.TransSequence,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.POCode,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, ''),c.Sequence SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WhCode,POCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,UpdateStock,IsFillClose,DocTyppe, DocDate, DocDate as ArrDate FROM #TempERP SELECT Costre, --Costre2, Sequence,DNSequence,InvCode,Quantity,Amount,PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WarehouseCode AS WhCode,srcDocPOLineNo FROM #TempERP SELECT SUM(a.Quantity) AS Quantity--,a.LotNo AS Costre2,a.LotNo, FROM ICSWareHouseLotInfoLog a INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.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 #TempERP te ON te.Sequence=a.TransSequence WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}' --GROUP BY a.LotNo SELECT DISTINCT HasDN FROM #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP"; sql = string.Format(sql, Identification, BusinessCode,doctype); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre"); //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2"); var IsDNCode = ds.Tables[3]; if (IsDNCode == null || IsDNCode.Rows.Count != 1) { throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种! } string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9CreatePOArrivURL, Inputstr); 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 allcol = jo["cWhCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString() // + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString(); // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(), // det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode); // } //} } 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 采购入库-入库单 /// /// 采购入库-入库单 /// /// /// /// /// /// public static void PurchaseReceiveRevDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary language) { try { string sql = @"DECLARE @Status VARCHAR(10) SELECT @Status=c.Status FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSPurchaseReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1); RETURN END ELSE IF (@Status='2') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1); RETURN END UPDATE c SET RcvQuantity=ISNULL(RcvQuantity,0)+'{2}' FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSPurchaseReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSPurchaseReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn001', c.Quantity,1,1,'') /// 采购入库-入库单接口 /// /// /// /// public static void PurchaseReceiveRevDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode,string UserCode) { try { #region ERP开立状态单据审核 string sql = ""; string Inputstr = ""; string pnsql = ""; DataTable dt = null; string sqlflag = @"select * from ICSConfiguration ConErp where ConErp.Code='UploadERP001' and conerp.enable = 1 "; DataTable dtflag = DBHelper.SQlReturnData(sqlflag, cmd); if (dtflag.Rows.Count>0&& dtflag != null) { sql = @" select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' SELECT b.RCVID+b.Sequence+b.RCVDetailID AS Costre,b.RCVID AS ID,b.RCVDetailID AS DNDetailID,b.Sequence AS DNSequence,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint INTO #TempERP FROM #NewTempERP a INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint GROUP BY b.RCVID,b.RCVDetailID,b.Sequence,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP select Costre,DNSequence,DNDetailID from #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP"; sql = string.Format(sql, Identification); string checksql = @"select distinct b.Quantity AS SUMQty,b.RCVQuantity AS ISSQty,a.transCode,a.transSequence from ICSPurchaseReceive b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.RCVCode AND b.Sequence=a.TransSequence AND a.WorkPoint=b.WorkPoint where a.Identification='{0}' GROUP BY a.transCode,b.Quantity,b.RCVQuantity,a.transSequence"; checksql = string.Format(checksql, Identification); DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd); for (int i=0;i'1' SELECT b.RCVID+b.Sequence+b.RCVDetailID AS Costre,b.RCVID AS ID,b.RCVDetailID AS DNDetailID,b.Sequence AS DNSequence,'{2}' AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint INTO #TempERP FROM #NewTempERP a INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint GROUP BY b.RCVID,b.RCVDetailID,b.Sequence,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP select Costre,DNSequence,DNDetailID from #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP"; pnsql = string.Format(pnsql, trancode, transSequence,UserCode); } else { pnsql = @"select distinct WorkPoint,MUSER,TransCode,TransSequence INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE TransCode='{0}' and TransSequence='{1}' AND ERPUpload='0' SELECT b.RCVID+b.Sequence+b.RCVDetailID AS Costre,b.RCVID AS ID,b.RCVDetailID AS DNDetailID,b.Sequence AS DNSequence,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint INTO #TempERP FROM #NewTempERP a INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint GROUP BY b.RCVID,b.RCVDetailID,b.Sequence,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP select Costre,DNSequence,DNDetailID from #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP"; pnsql = string.Format(pnsql, trancode, transSequence); } DataSet ds = DBHelper.SQlReturnDataSet(pnsql, cmd); Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre"); string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9DeliveryNoticeURL, Inputstr); Result result = new Result(); result = JsonConvert.DeserializeObject(resultStr); if (result.Success) { try { foreach (DataRow dr in dt.Rows) { ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode); } } catch (Exception ex) { log.Debug(ex.ToString()); log.Debug(resultStr); } } else { throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message); } } } } else { sql = @" select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' IF EXISTS(SELECT b.ID FROM ICSPurchaseReceive b WHERE b.RCVCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}') AND b.Quantity!=b.RCVQuantity) BEGIN RAISERROR('采购入库单下的条码必须一次性扫描完成!',16,1); RETURN END SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint FROM #NewTempERP a INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint DROP TABLE #NewTempERP"; sql = string.Format(sql, Identification); dt = DBHelper.SQlReturnData(sql, cmd); Inputstr = JsonConvert.SerializeObject(dt); string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9DeliveryNoticeURL, Inputstr); Result result = new Result(); result = JsonConvert.DeserializeObject(resultStr); if (result.Success) { try { foreach (DataRow dr in dt.Rows) { ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode); } } 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 审核的到货单 /// /// 审核的到货单 /// /// /// /// /// /// public static void DeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary language) { try { string sql = @"DECLARE @Status VARCHAR(10) SELECT @Status=c.Status FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1' IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1); RETURN END ELSE IF (@Status='3') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1); RETURN END UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}' FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1' IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1' AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn002', c.Quantity,1,1,'') /// 审核的到货单接口 /// /// /// /// public static DataTable DeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary language,string BusinessCode) { try { DataTable dtablee = new DataTable(); string checklotno = ""; string checksql = @"SELECT c.dncode,a.lotno FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN (select dncode,Sequence,WorkPoint FROM ICSDeliveryNotice) c ON b.TransCode=c.dncode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint left join ICSWareHouseLotInfo d on a.lotno=d.lotno and a.WorkPoint=d.WorkPoint WHERE c.dncode in (select TransCode from ICSWareHouseLotInfoLog where Identification='{0}' ) and d.lotno is null"; checksql = string.Format(checksql, Identification); DataTable dtt = DBHelper.SQlReturnData(checksql, cmd); if (dtt.Rows.Count > 1) { // 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中 foreach (DataRow row in dtt.Rows) { checklotno += row["lotno"].ToString() + ","; } checklotno = checklotno.TrimEnd(','); // 去除最后一个逗号 } else if (dtt.Rows.Count == 1) { // 如果dtt的行数等于1,直接将lotno赋值给checklotno checklotno = dtt.Rows[0]["lotno"].ToString(); } string checkrcvcode = ""; string checknewsql = @"SELECT distinct c.DNCode FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN (select DNCode,Sequence,WorkPoint FROM ICSDeliveryNotice) c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint left join ICSWareHouseLotInfo d on a.lotno=d.lotno and a.WorkPoint=d.WorkPoint WHERE c.DNCode in (select TransCode from ICSWareHouseLotInfoLog where Identification='{0}' ) and d.lotno is NULL"; checknewsql = string.Format(checknewsql, Identification); DataTable dttnew = DBHelper.SQlReturnData(checknewsql, cmd); if (dttnew.Rows.Count > 1) { // 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中 foreach (DataRow row in dttnew.Rows) { checkrcvcode += row["DNCode"].ToString() + ","; } checkrcvcode = checkrcvcode.TrimEnd(','); // 去除最后一个逗号 } else if (dttnew.Rows.Count == 1) { // 如果dtt的行数等于1,直接将lotno赋值给checklotno checkrcvcode = dttnew.Rows[0]["DNCode"].ToString(); } string sqlflag = @"select * from ICSConfiguration ConErp where ConErp.Code='UploadERP001' and conerp.enable = 1 "; //判断是否启用到货功能(未启用到货的 调用入库采购订单接口) DataTable dtflag = DBHelper.SQlReturnData(sqlflag, cmd); if (dtflag.Rows.Count > 0) { #region ERP string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' SELECT c.VenCode+a.ToWarehouseCode+c.DNCode+a.MUSER+d.POCode AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.DNCode ,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.DNDetailID,a.InvCode) AS Sequence,d.POCode,d.PODetailID, 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.DNDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock ,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 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 ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint inner join ICSPurchaseOrder d on c.PODetailID=d.PODetailID and c.WorkPoint=d.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint GROUP BY d.POCode,d.PODetailID,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.DNCode,c.DNID,a.MUSER,a.InvCode,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conStock.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, '') SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,DNCode,POCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,PODetailID,WarehouseCode AS WHCode,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WarehouseCode AS WHCode FROM #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP "; sql = string.Format(sql, Identification, checklotno, checkrcvcode); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre"); string resultStr = ""; resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DeliveryNoticeURL, Inputstr); 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 allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString() + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString(); ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode); } } } catch (Exception ex) { log.Debug(ex.ToString()); log.Debug(resultStr); } } else { throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message); } //sql= @" SELECT {1},{2} FROM ICSDeliveryNotice b // WHERE b.DNCode + b.WorkPoint IN(SELECT a.TransCode + a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification = '{0}' // and SUM(Quantity)<>SUM(RCVQuantity))"; //sql = string.Format(sql, Identification, checklotno, checkrcvcode); #endregion } else { #region ERP string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,Identification INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}' SELECT Identification,c.VenCode+a.ToWarehouseCode+c.POCode+a.MUSER 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,'' AS DNCode,'0' AS HasDN,a.MUSER,'' 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, '' 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 INTO #TempERP FROM #NewTempERP a WITH(nolock) 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 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 a.TransCode=f.DNCode AND a.TransSequence=f.Sequence AND a.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 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,a.MUSER,a.InvCode,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, '') 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 FROM #TempERP SELECT a.LotNo,SUM(a.Quantity) AS Quantity,te.Costre2,a.Identification FROM ICSWareHouseLotInfoLog a INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.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 #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 SELECT DISTINCT HasDN FROM #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP "; sql = string.Format(sql, Identification, BusinessCode); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre"); string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2"); string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseOrderURL, Inputstr); 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 allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString() + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString(); ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode); } } } catch (Exception ex) { log.Debug(ex.ToString()); log.Debug(resultStr); } } else { throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message); } #endregion } DataTable chekdt = new DataTable(); chekdt.Columns.Add("checkrcvcode", typeof(string)); chekdt.Columns.Add("checklotno", typeof(string)); DataRow newrow = chekdt.NewRow(); newrow["checkrcvcode"] = checkrcvcode; newrow["checklotno"] = checklotno; chekdt.Rows.Add(newrow); string aaaa = JsonConvert.SerializeObject(chekdt); return chekdt; } catch (Exception) { throw; } } #endregion #region 采购拒收 /// /// 采购拒收 /// /// /// /// /// /// public static void PurchaseRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary language) { try { string sql = @"DECLARE @Status VARCHAR(10) SELECT @Status=c.Status FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3' IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1); RETURN END ELSE IF (@Status='3') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1); RETURN END UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}' FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3' IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3' AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn003', c.Quantity,1,1,'') /// 采购拒收接口 /// /// /// /// public static void PurchaseRejectDocInNewERP(string DNCode, string JDNCode, string WorkPoint, SqlCommand cmd, Dictionary language) { //try //{ // #region ERP // string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.DNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,d.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.DNCode,c.DNDetailID,a.InvCode) AS Sequence, // a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.DNDetailID,con.Enable AS UpdateTodoQuantity // ,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,conv.Enable AS VerificationEnable // INTO #TempERP // FROM ICSWareHouseLotInfoLog a // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint // WHERE a.Identification='{0}' AND ERPUpload='0' // GROUP BY c.VenCode,a.ToWarehouseCode,c.DNCode,d.DNCode,a.MUSER,lot.Amount,lot.Quantity,a.InvCode,d.DNDetailID,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conv.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, '') // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 // FROM #TempERP // DROP TABLE #TempERP"; // sql = string.Format(sql, Identification); // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre"); // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr); // 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; // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language); // } // } // } // catch (Exception ex) // { // log.Debug(ex.ToString()); // log.Debug(resultStr); // } // } // else // { // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message); // } // #endregion //} //catch (Exception) //{ // throw; //} try { #region ERP string whcode = string.Empty; string sql = string.Empty; //到货指定仓库(批次汇总) string Dsql = @"SELECT a.F_itemCode FROM Sys_SRM_ItemsDetail a INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1'"; Dsql = string.Format(Dsql); DataTable dtdao = DBHelper.SQlReturnData(Dsql, cmd); if (dtdao.Rows.Count > 0 && dtdao != null) { whcode = dtdao.Rows[0]["F_itemCode"].ToString(); sql = @"SELECT ISNULL(a.VenCode,'')+ISNULL(a.DepCode,'')+ISNULL(x.DNCode,'')+ISNULL(a.MUSER,'') AS Costre,a.VenCode,ISNULL(a.DepCode,'') AS DepCode,x.DNCode,a.MUSER,SYSDATETIME() AS MTIME, ROW_NUMBER() OVER (ORDER BY x.DNCode,x.DNDetailID,a.InvCode) AS Sequence,a.InvCode,Sum(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN a.Amount ELSE '0' END AS Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,x.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 INTO #TempERP FROM ICSDeliveryNotice a 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 LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND '{2}'=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint INNER JOIN ICSDeliveryNotice x ON x.DNDetailID=a.PODetailID AND a.WorkPoint=x.WorkPoint INNER JOIN ICSExtension extd ON x.ExtensionID=extd.ID AND x.WorkPoint=extd.WorkPoint WHERE a.DNCode='{0}' AND a.WorkPoint='{1}' and ISNULL(ext.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END+'~'+ISNULL(ext.Version, '')+'~'+ISNULL(ext.Brand, '')+'~'+ ISNULL(ext.cFree1, '')+'~'+ISNULL(ext.cFree2, '')+'~'+ISNULL(ext.cFree3, '')+'~'+ISNULL(ext.cFree4, '')+'~'+ISNULL(ext.cFree5, '')+'~'+ISNULL(ext.cFree6, '')+'~'+ISNULL(ext.cFree7, '')+'~'+ISNULL(ext.cFree8, '')+'~'+ISNULL(ext.cFree9, '')+'~'+ISNULL(ext.cFree10, '') = ISNULL(extd.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(extd.BatchCode, '') ELSE '' END+'~'+ISNULL(extd.Version, '')+'~'+ISNULL(extd.Brand, '')+'~'+ ISNULL(extd.cFree1, '')+'~'+ISNULL(extd.cFree2, '')+'~'+ISNULL(extd.cFree3, '')+'~'+ISNULL(extd.cFree4, '')+'~'+ISNULL(extd.cFree5, '')+'~'+ISNULL(extd.cFree6, '')+'~'+ISNULL(extd.cFree7, '')+'~'+ISNULL(extd.cFree8, '')+'~'+ISNULL(extd.cFree9, '')+'~'+ISNULL(extd.cFree10, '') GROUP BY a.VenCode,a.DepCode,x.DNCode,a.MUSER,inv.AmountEnable,invBat.BatchEnable,a.InvCode,a.Amount,a.UnitPrice,a.Currency,x.DNDetailID, a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(inv.BatchEnable, ''),ISNULL(ext.BatchCode, ''),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, '') SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,DNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP DROP TABLE #TempERP SELECT * FROM ICSInventoryBatchEnable"; sql = string.Format(sql, JDNCode, WorkPoint, whcode); } else { sql = @"SELECT ISNULL(a.VenCode,'')+ISNULL(a.DepCode,'')+ISNULL(x.DNCode,'')+ISNULL(a.MUSER,'') AS Costre,a.VenCode,ISNULL(a.DepCode,'') AS DepCode,x.DNCode,a.MUSER,SYSDATETIME() AS MTIME, ROW_NUMBER() OVER (ORDER BY x.DNCode,x.DNDetailID,a.InvCode) AS Sequence,a.InvCode,Sum(a.Quantity) AS Quantity,CASE invBat.AmountEnable WHEN '1' THEN a.Amount ELSE '0' END AS Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,x.DNDetailID ,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 INNER JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint INNER JOIN ICSDeliveryNotice x ON x.DNDetailID=a.PODetailID AND a.WorkPoint=x.WorkPoint INNER JOIN ICSExtension extd ON x.ExtensionID=extd.ID AND x.WorkPoint=extd.WorkPoint WHERE a.DNCode='{0}' AND a.WorkPoint='{1}' GROUP BY a.VenCode,a.DepCode,x.DNCode,a.MUSER,invBat.AmountEnable,a.InvCode,a.Amount,a.UnitPrice,a.Currency,x.DNDetailID, a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(invBat.BatchEnable, ''),ISNULL(ext.BatchCode, ''),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, '') SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,DNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP DROP TABLE #TempERP"; sql = string.Format(sql, JDNCode, WorkPoint); } DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre"); string resultStr = HTTPHelper.HttpPost("采购拒收", ERPUrl.CreatePuArrivalVouchURL, Inputstr); 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; //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RJTCode"].ToString(), det["Sequence"].ToString(), cmd, language); string ERPupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}' where PODetailID='{4}' AND DNType='3' AND DNCode='{5}' "; ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], JDNCode); 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; } } /// /// 采购拒收接口 /// /// /// /// public static void PurchaseRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary language,string BusinessCode) { //try //{ // #region ERP // string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.DNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,d.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.DNCode,c.DNDetailID,a.InvCode) AS Sequence, // a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.DNDetailID,con.Enable AS UpdateTodoQuantity // ,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,conv.Enable AS VerificationEnable // INTO #TempERP // FROM ICSWareHouseLotInfoLog a // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint // WHERE a.Identification='{0}' AND ERPUpload='0' // GROUP BY c.VenCode,a.ToWarehouseCode,c.DNCode,d.DNCode,a.MUSER,a.InvCode,d.DNDetailID,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conv.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, '') // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 // FROM #TempERP // DROP TABLE #TempERP"; // sql = string.Format(sql, Identification); // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre"); // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr); // 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; // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language); // } // } // } // 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 采购退货 /// /// 采购退货 /// /// /// /// /// /// public static void PurchaseReceiveDoctNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary language,string TransID) { try { string sql = @"DECLARE @Status VARCHAR(10) SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' AND DNType='2' AND WorkPoint='{1}' and ID='{4}' IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo085") + @"',16,1); RETURN END ELSE IF (@Status!='2') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo086") + @"',16,1); RETURN END UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}' FROM ICSDeliveryNotice a WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.ID='{4}' AND a.WorkPoint='{1}' AND DNType='2' UPDATE b SET Inquantity=ISNULL(b.Inquantity,0)-'{2}' FROM icsPurchaseOrder b inner join ICSDeliveryNotice a on a.poID = b.poid and a.PODetailID = b.PODetailID WHERE a.DNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND DNType='2' IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' and a.ID='{4}' AND a.Quantity /// 采购退货接口 /// /// /// /// public static void PurchaseReceiveDoctNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary language,string BusinessCode) { try { #region ERP string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '3' SELECT y.VenCode+a.FromWarehouseCode+y.DNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.DNCode,y.DNDetailID,a.InvCode) AS Sequence,conWhCode.Enable AS ErpWhCode, a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(y.Amount/y.Quantity)) ELSE '0' END AS Amount,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock ,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 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.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint INNER JOIN ICSDeliveryNotice y ON a.TransCode=y.DNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint GROUP BY conWhCode.Enable,inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.DNCode,a.MUSER,a.InvCode,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conStock.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, '') SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,DNCode AS DNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,DNDetailID AS DNRTDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP"; sql = string.Format(sql, Identification); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre"); string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReturnBackURL, Inputstr); 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 allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString() + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString(); ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNRTDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol,cmd, language,BusinessCode); } } } catch (Exception ex) { log.Debug(ex.ToString()); log.Debug(resultStr); } } else { throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message); } #endregion } catch (Exception) { throw; } } /// /// 采购退货接口 /// /// /// /// public static void RTPurchaseReceiveDoctNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode) { try { #region ERP string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '3' SELECT y.VenCode+a.FromWarehouseCode+y.DNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.DNCode,y.DNDetailID,a.InvCode) AS Sequence,z.Sequence AS srcDocPOLineNo,y.PODetailID,z.DNCode AS POCode,y.DepCode, a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(y.Amount/y.Quantity)) ELSE '0' END AS Amount,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock ,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 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.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint INNER JOIN ICSDeliveryNotice y ON a.TransCode=y.DNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint INNER JOIN ICSDeliveryNotice z ON z.Sequence=y.PoDetailID AND z.DNCode=y.POID AND a.WorkPoint=y.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint GROUP BY y.DepCode,z.Sequence,y.PODetailID,z.DNCode,inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.DNCode,a.MUSER,a.InvCode,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conStock.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, '') SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,POCode,'采购' AS DocType,MUSER AS [User],SYSDATETIME() AS MTime,SYSDATETIME() AS DocDate,SYSDATETIME() AS ArrDate FROM #TempERP SELECT Costre,Sequence,InvCode,srcDocPOLineNo,Quantity,Amount,UnitPrice,Currency,PODetailID,ProjectCode,BatchCode,WarehouseCode AS WhCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP"; sql = string.Format(sql, Identification); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre"); string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.RTPurchaseReturnBackURL, Inputstr); 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 allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString() + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString(); ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNRTDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode); } } } 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 采购退货-采购订单 /// /// 采购退货-采购订单 /// /// /// /// /// /// public static void PurchaseReceiveDoctNegativePo(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary language, string TransID) { try { string sql = ""; sql = @"DECLARE @Status VARCHAR(10) SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' AND DNType='1' AND WorkPoint='{1}' and ID='{4}' IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo085") + @"',16,1); RETURN END ELSE IF (@Status!='2') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo086") + @"',16,1); RETURN END UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)-'{2}' FROM ICSDeliveryNotice a WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.ID='{4}' AND a.WorkPoint='{1}' AND DNType='1' IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' and a.ID='{4}' AND a.RCVQuantity<0 AND DNType='1') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1); RETURN END --东辉采购退货 eattribute9 = 2 扣减 采购订单数量 退补 IF EXISTS(SELECT b.ID FROM ICSDeliveryNotice a inner join icsPurchaseOrder b on a.poID = b.poid and a.PODetailID = b.PODetailID WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.eattribute9='2' AND DNType='2') BEGIN UPDATE b SET Inquantity=ISNULL(b.Inquantity,0)-'{2}' FROM icsPurchaseOrder b inner join ICSDeliveryNotice a on a.poID = b.poid and a.PODetailID = b.PODetailID WHERE a.DNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND DNType='2' END "; sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID); if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo088"));//"采购退货单更新失败!"); } } catch (Exception) { throw; } } public static void PurchaseReceiveDoctNegativePoERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode) { try { #region ERP string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '3' SELECT y.VenCode+a.FromWarehouseCode+y.DNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.DNCode,y.DNDetailID,a.InvCode) AS Sequence,conWhCode.Enable AS ErpWhCode, a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(y.Amount/y.Quantity)) ELSE '0' END AS Amount,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock ,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 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.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint INNER JOIN ICSDeliveryNotice y ON a.TransCode=y.DNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint GROUP BY conWhCode.Enable,inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.DNCode,a.MUSER,a.InvCode,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conStock.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, '') SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,DNCode AS POCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,DNDetailID AS PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP"; sql = string.Format(sql, Identification); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre"); string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReturnBackPoURL, Inputstr); 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 allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString() + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString(); ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNRTDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode); } } } 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 开立红字入库 /// /// 开立红字入库 /// /// /// /// /// /// public static void PurchaseReceive(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary language,string TransID) { try { string sql = @"DECLARE @Status VARCHAR(10) SELECT @Status=a.Status FROM ICSPurchaseReceive a WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}' AND a.Type='2' IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo089") + @"',16,1); RETURN END ELSE IF (@Status!='1') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo090") + @"',16,1); RETURN END UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}' FROM ICSPurchaseReceive a WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}' AND a.Type='2' IF EXISTS(SELECT a.ID FROM ICSPurchaseReceive a WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' and a.id='{4}' AND a.Type='2' AND a.Quantity /// 开立红字入库接口 /// /// /// /// public static void PurchaseReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary language,string BusinessCode) { try { string sql = string.Empty; if (DBHelper.IsPNU9()) { #region ERP开立状态单据审核 sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '4' SELECT b.RCVCode AS RCVTCode,b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint FROM #NewTempERP a INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint GROUP BY b.RCVCode,b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint DROP TABLE #NewTempERP"; sql = string.Format(sql, Identification); //DataTable dt = DBHelper.SQlReturnData(sql, cmd); //string Inputstr = JsonConvert.SerializeObject(dt); string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.RCVQuantity) AS ISSQty,a.transCode from ICSPurchaseReceive b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.RCVCode AND a.WorkPoint=b.WorkPoint where a.Identification='{0}' AND a.BusinessCode = '4' GROUP BY a.transCode"; checksql = string.Format(checksql, Identification); DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd); decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]); decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]); string trancode = chekdt.Rows[0]["transCode"].ToString(); if (SUMQty - ISSQty == 0) { string pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '4' SELECT b.RCVCode AS RCVTCode,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint FROM #NewTempERP a INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint GROUP BY b.RCVCode,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint DROP TABLE #NewTempERP"; pnsql = string.Format(pnsql, trancode); DataTable dt = DBHelper.SQlReturnData(pnsql, cmd); string Inputstr = JsonConvert.SerializeObject(dt); string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReceiveDoctNegativeURL, Inputstr); Result result = new Result(); result = JsonConvert.DeserializeObject(resultStr); if (result.Success) { try { foreach (DataRow dr in dt.Rows) { ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode); } } catch (Exception ex) { log.Debug(ex.ToString()); log.Debug(resultStr); } } else { throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message); } } #endregion } else { #region ERP开立状态单据审核 sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '4' IF EXISTS(SELECT b.id FROM ICSPurchaseReceive b where rcvcode in (select DISTINCT TransCode from ICSWareHouseLotInfoLog where Identification='{0}') and b.Quantity!=b.RCVQuantity) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo093") + @"',16,1); RETURN END SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint,b.RCVCode as RCVTCode FROM #NewTempERP a INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint,b.RCVCode DROP TABLE #NewTempERP"; sql = string.Format(sql, Identification); DataTable dt = DBHelper.SQlReturnData(sql, cmd); string Inputstr = JsonConvert.SerializeObject(dt); string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReceiveDoctNegativeURL, Inputstr); Result result = new Result(); result = JsonConvert.DeserializeObject(resultStr); if (result.Success) { try { foreach (DataRow dr in dt.Rows) { ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode); } } catch (Exception ex) { log.Debug(ex.ToString()); log.Debug(resultStr); } } else { throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message); } #endregion } } catch (Exception) { throw; } } #endregion } }