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 ICSOutsourcingService { private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #region 委外发料 /// /// 委外发料 /// /// /// /// /// /// public static void OutsourcingIssueDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary language,string enableCode,string TransID) { try { string sql = @"DECLARE @Status VARCHAR(10) SELECT @Status=b.Status FROM ICSOOPick a INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint WHERE b.OOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{5}' IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo104") + @"',16,1); RETURN END ELSE IF (@Status!='2') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo105") + @"',16,1); RETURN END UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}' FROM ICSOOPick a INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint WHERE b.OOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' and a.id='{5}' AND a.WorkPoint='{1}' IF EXISTS(SELECT a.ID FROM ICSOOPick a INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint WHERE b.OOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' and a.id='{5}' and b.WorkPoint='{1}' AND (dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{4}',2,2,'')) /// 委外发料接口 /// /// /// /// public static void OutsourcingIssueDocERP(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 = '5' SELECT isnull(y.DepCode,'') + a.FromWarehouseCode + y.OOCode + a.MUSER AS Costre, y.DepCode,a.FromWarehouseCode AS WarehouseCode,y.OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.FromWarehouseCode,y.OOCode,x.PickID,a.InvCode) AS Sequence, a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(x.Amount/x.Quantity)) ELSE '0' END AS Amount,x.PickID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,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,conv.Enable AS CompleteVerification , x.OODetailID 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 ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.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.DepCode,a.FromWarehouseCode,y.OOCode,a.MUSER,a.InvCode,x.PickID,x.OODetailID,con.Enable,conv.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,DepCode,WarehouseCode AS WHCode,'委外订单' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock FROM #TempERP SELECT Costre,WarehouseCode AS WHCode,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,PickID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,OODetailID as SourceLineID 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 = ""; if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["IsU9Api"])) { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OutsourcingIssueDocURL, Inputstr); } else { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDocURL, 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["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["IssueCode"].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 OOApply(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary language,string enableCode,string TransID) { try { string sql = @"DECLARE @Status VARCHAR(10) SELECT @Status=a.Status FROM ICSOApply a WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.id='{5}' AND a.WorkPoint='{1}' IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo108") + @"',16,1); RETURN END ELSE IF (@Status!='2') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo109") + @"',16,1); RETURN END UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}' FROM ICSOApply a WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.id='{5}' AND a.WorkPoint='{1}' IF EXISTS(SELECT a.ID FROM ICSOApply a WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.id='{5}' and a.WorkPoint='{1}' AND (dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{4}',2,2,'')) /// 委外领料申请单生产发料接口 /// /// /// /// public static void OOApplyERP(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,transid INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '6' SELECT a.FromWarehouseCode+b.ApplyCode+a.MUSER AS Costre,a.FromWarehouseCode AS WarehouseCode,b.ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.ApplyCode,b.ApplyDetailID,a.InvCode) AS Sequence, a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount,b.ApplyDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,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,conv.Enable AS CompleteVerification 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 ICSOApply b ON a.TransCode=b.ApplyCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.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,a.FromWarehouseCode,b.ApplyCode,a.MUSER,a.InvCode,b.ApplyDetailID,con.Enable,conv.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,'' AS DepCode,WarehouseCode AS WHCode,'委外领料申请单' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ApplyDetailID AS SourceDetailID,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.OOApplyURL, 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["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["IssueCode"].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 OOIssue(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 ICSOIssue a WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}' IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo111") + @"',16,1); RETURN END ELSE IF (@Status!='1') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo112") + @"',16,1); RETURN END UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}' FROM ICSOIssue a WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}' IF EXISTS(SELECT a.ID FROM ICSOIssue a WHERE a.IssueCode='{0}' AND a.Sequence='{3}' and a.id='{4}' and a.WorkPoint='{1}' AND a.Quantity /// 委外材料出库单生产发料接口 /// /// /// /// public static void OOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary language,string BusinessCode) { try { #region ERP开立状态单据审核 string sql = ""; if (DBHelper.IsPNU9()) { sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '7' SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint FROM #NewTempERP a INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode 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='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint GROUP BY b.IssueID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint DROP TABLE #NewTempERP"; sql = string.Format(sql, Identification); string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.IssueQuantity) AS ISSQty,a.transCode from ICSOIssue b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.IssueCode AND a.WorkPoint=b.WorkPoint where a.Identification='{0}' 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 = '7' and EATTRIBUTE1<>'1' SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint FROM #NewTempERP a INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode 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='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint GROUP BY b.IssueID,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.OOIssueURL, 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,FromWarehouseCode INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '7' IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint WHERE a.Identification='{0}' AND b.Quantity!=b.IssueQuantity) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo095") + @"',16,1); RETURN END SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint FROM #NewTempERP a INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode 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='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint GROUP BY b.IssueID,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 resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOIssueURL, 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 OutsourcingIssueDoNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint, string TransCode, string TransSequence, SqlCommand cmd, Dictionary language) { try { string table = ""; string sql = ""; if (string.IsNullOrWhiteSpace(LogID)) { string type = ""; string quantitySql = "c.Quantity"; if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()) { table = "INNER JOIN ICSOOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint"; type = "1"; quantitySql = "dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn008', c.Quantity,1,1,'')"; } else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()) { table = "INNER JOIN ICSOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint"; type = "2"; quantitySql = "dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn009', c.Quantity,1,1,'')"; } else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription()) { table = "INNER JOIN ICSOIssue e ON c.SourceDetailID=e.IssueDetailID AND c.WorkPoint=e.WorkPoint"; type = "3"; quantitySql = "dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn010', c.Quantity,1,1,'')"; } else { throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!"); } #region 新条码 sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}' FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND {5}'{2}' and OApplyNegCode='{5}' and Sequence='{6}') BEGIN UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}' FROM ICSOApplyNegDetail c INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint WHERE c.WorkPoint='{1}' and c.OApplyNegCode='{5}' and c.Sequence='{6}' END"; sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID, TransCode, TransSequence); #endregion } if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!"); } } catch (Exception) { throw; } } /// /// 委外退料接口 /// /// /// /// public static void OutsourcingIssueDoNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary language,string BusinessCode) { try { #region ERP string sql = string.Empty; if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()) { if (DBHelper.IsU9()) { sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')='' select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID INTO #NewDouTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>'' SELECT y.DepCode+a.ToWarehouseCode+y.OOCode+a.MUSER AS Costre,y.DepCode,a.ToWarehouseCode AS WarehouseCode,y.OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.ToWarehouseCode,y.OOCode,x.PickID,a.InvCode) AS Sequence1, 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,x.PickID AS SourceDetailID,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,y.Sequence 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 ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint INNER JOIN ICSOOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint INNER JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint GROUP BY inv.AmountEnable,y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,x.PickID,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, ''),y.Sequence SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'委外订单' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP DROP TABLE #NewDouTempERP"; } else { sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')='' select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID INTO #NewDouTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>'' SELECT isnull(y.DepCode,'')+a.ToWarehouseCode+y.OOCode+a.MUSER AS Costre,y.DepCode,a.ToWarehouseCode AS WarehouseCode,y.OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.ToWarehouseCode,y.OOCode,x.PickID,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,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,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 ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint INNER JOIN ICSOOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint INNER JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint GROUP BY conWhCode.Enable,inv.AmountEnable,y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,x.PickID,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, ''),y.Sequence UNION ALL SELECT isnull(y.DepCode,'')+a.ToWarehouseCode+y.OOCode+a.MUSER AS Costre,y.DepCode,a.ToWarehouseCode AS WarehouseCode,y.OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.ToWarehouseCode,y.OOCode,x.PickID,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,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,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 FROM #NewDouTempERP 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 ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint GROUP BY conWhCode.Enable,inv.AmountEnable,y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,x.PickID,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,DepCode,WarehouseCode AS WHCode,'委外订单' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP DROP TABLE #NewDouTempERP"; } } else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()) { sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')='' select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID INTO #NewDouTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>'' SELECT a.ToWarehouseCode+z.ApplyCode+a.MUSER AS Costre,'' AS DepCode,a.ToWarehouseCode AS WarehouseCode,z.ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,z.ApplyCode,z.ApplyDetailID,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,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,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 ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint INNER JOIN ICSOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint GROUP BY conWhCode.Enable,inv.AmountEnable,a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,z.ApplyDetailID,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, '') UNION ALL SELECT a.ToWarehouseCode+z.ApplyCode+a.MUSER AS Costre,'' AS DepCode,a.ToWarehouseCode AS WarehouseCode,z.ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,z.ApplyCode,z.ApplyDetailID,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,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,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 FROM #NewDouTempERP 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 ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint GROUP BY conWhCode.Enable,inv.AmountEnable,a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,z.ApplyDetailID,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,DepCode,WarehouseCode AS WHCode,'委外领料申请单' AS SourceType,ApplyCode AS SourceCode,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,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP DROP TABLE #NewDouTempERP"; } //根据材料出库单查询上游单据,根据上游单据生成红字材料出库 else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription()) { sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')='' select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID INTO #NewDouTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>'' IF EXISTS(select * 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 ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint INNER JOIN ICSOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint where m.ApplyDetailID<>null and z.ApplyDetailID=null) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1); RETURN END IF EXISTS(select * FROM #NewDouTempERP 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 ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint where m.ApplyDetailID<>null and z.ApplyDetailID=null) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1); RETURN END SELECT ISNULL(y.DepCode, '')+a.ToWarehouseCode+a.MUSER AS Costre,ISNULL(y.DepCode, '') AS DepCode,a.ToWarehouseCode AS WarehouseCode,CASE WHEN m.ApplyDetailID IS NOT NULL THEN '委外领料申请单' WHEN m.PickID IS NOT NULL THEN '委外订单' ELSE '' END AS SourceType,ISNULL(z.ApplyCode, y.OOCode) AS OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),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(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,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 ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint INNER JOIN ICSOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint GROUP BY conWhCode.Enable,inv.AmountEnable,ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.MUSER,a.InvCode,m.PickID,m.ApplyDetailID,con.Enable,lot.Amount,lot.Quantity,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, '') UNION ALL SELECT ISNULL(y.DepCode, '')+a.ToWarehouseCode+a.MUSER AS Costre,ISNULL(y.DepCode, '') AS DepCode,a.ToWarehouseCode AS WarehouseCode,CASE WHEN m.ApplyDetailID IS NOT NULL THEN '委外领料申请单' WHEN m.PickID IS NOT NULL THEN '委外订单' ELSE '' END AS SourceType,ISNULL(z.ApplyCode, y.OOCode) AS OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),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(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,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 FROM #NewDouTempERP 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 ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint GROUP BY conWhCode.Enable,inv.AmountEnable,ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.MUSER,a.InvCode,m.PickID,m.ApplyDetailID,con.Enable,lot.Amount,lot.Quantity,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, '') IF EXISTS(SELECT Costre FROM #TempERP WHERE SourceType='{0}') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo116") + @"',16,1); END SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP DROP TABLE #NewDouTempERP"; } else { throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!"); } sql = string.Format(sql, Identification); log.Debug("退料erpsql:"+sql); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre"); string resultStr = ""; if (DBHelper.IsU9()) resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OutsourcingIssueDoNegativeURL, Inputstr); else resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDoNegativeURL, 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["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode); } } //List negList = JsonConvert.DeserializeObject>(result.Data.ToString()); //foreach (var neg in negList) //{ // foreach (var detail in neg.details) // { // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, detail.SourceDetailID, Identification, neg.ID, detail.DetailID, neg.IssueNEGCode, detail.Sequence, cmd); // } //} } 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 OutsourcingDeliveryNoticeERP(string ODNCode, string WorkPoint, SqlCommand cmd, Dictionary language) { try { #region ERP string sql = @"SELECT a.VenCode+a.DepCode+y.OOCode+a.MUSER AS Costre,a.VenCode,a.DepCode,y.OOCode,a.MUSER,a.MTIME,conStock.Enable AS CompleteVerification, 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.OODetailID ,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 ICSODeliveryNotice 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 ICSOutsourcingOrder y ON a.OODetailID=y.OODetailID AND a.WorkPoint=y.WorkPoint INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='CompleteVerification003' WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}' SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,OOCode,MUSER AS [User],SYSDATETIME() AS MTime,CompleteVerification FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,OODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP DROP TABLE #TempERP"; sql = string.Format(sql, ODNCode, WorkPoint); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre"); string resultStr = HTTPHelper.HttpPost("委外到货", ERPUrl.ODeliveryNoticeURL, 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 ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}' where OODetailID='{4}' AND ODNType='1' AND ODNCode='{5}' and Sequence='{1}'"; ERPupdate = string.Format(ERPupdate, jo["ODNCode"], det["Sequence"], jo["ID"], det["DetailID"], det["OODetailID"], ODNCode); 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 OutsourcingReceiveDoc(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 ICSOutsourcingOrder c ON b.TransCode=c.OOCode 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 ICSOutsourcingOrder c ON b.TransCode=c.OOCode 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 ICSOutsourcingOrder c ON b.TransCode=c.OOCode 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, 'OverIn004', c.Quantity,1,1,'') /// 委外入库(奥美) /// /// /// /// /// /// public static void OutsourcingReceiveAMDoc(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 ICSOutsourcingOrder c ON b.TransCode=c.OOCode 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 ICSOutsourcingOrder c ON b.TransCode=c.OOCode 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 ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint -- WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity /// 委外入库接口 /// /// /// /// public static void OutsourcingReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary language,string BusinessCode) { try { string outwhcode = ""; DataTable flag = null; string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'"; flag = DBHelper.SQlReturnData(enablesql, cmd); #region ERP string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}' select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID,TransSequence,TransCode,FromWarehouseCode,isnull(EATTRIBUTE3,'') as EATTRIBUTE3 INTO #NewDouTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND TransType='13' and BusinessCode ='60' SELECT c.VenCode+a.ToWarehouseCode+c.OOCode+a.MUSER+f.ODNCode AS Costre,c.OODetailID+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, '') AS Costre2,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.OOCode,c.OOID,f.ODNCode,case when ConErp.enable=1 then f.ODNDetailID else '' end ODNDetailID,a.MUSER,f.Sequence AS ODNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.OOCode,c.OODetailID,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.OODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose,conStockneww.Enable AS CompleteVerification,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,a.TransSequence,lot.eattribute10 as Reason INTO #TempERP FROM #NewTempERP a INNER JOIN ICSConfiguration ConErp ON a.WorkPoint=ConErp.WorkPoint AND ConErp.Code='UploadERP002' 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 ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint --INNER JOIN ICSODeliveryNotice f ON g.OASNCode=f.OASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID left JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint INNER JOIN ICSODeliveryNotice f ON (g.OASNCode=f.OASNCode or a.TransCode = f.ODNCode) AND a.WorkPoint=f.WorkPoint AND (conerp.enable = 0 or lot.ExtensionID=f.ExtensionID) INNER JOIN ICSOutsourcingOrder c ON b.TransCode = c.OOCode AND b.TransSequence = c.Sequence AND f.OODetailID = c.OODetailID AND b.WorkPoint = c.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001' --INNER JOIN ICSConfiguration ConErp ON a.WorkPoint=ConErp.WorkPoint AND ConErp.Code='UploadERP002' 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='FillClose002' INNER JOIN ICSConfiguration conStockneww ON a.WorkPoint=conStockneww.WorkPoint AND conStockneww.Code='CompleteVerification005' LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint GROUP BY conWhCode.Enable,ConErp.Enable,conStockneww.Enable,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.OOCode,a.MUSER,f.ODNCode,f.ODNDetailID,f.Sequence,a.TransSequence,a.InvCode,c.OOID,c.OODetailID,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, ''),lot.eattribute10 SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,OOCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime, Enable,UpdateTodoQuantity,CompleteVerification,UpdateStock,IsFillClose FROM #TempERP SELECT Costre,Costre2,Sequence,ODNSequence,TransSequence, InvCode,Quantity,Amount,OODetailID,ODNDetailID,Currency,UnitPrice,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode, ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Reason FROM #TempERP SELECT a.FromWarehouseCode AS WHCode,c.OODetailID+te.ProjectCode+te.BatchCode+te.Version+te.Brand+te.cFree1+te.cFree2+te.cFree3+te.cFree4+te.cFree5+te.cFree6+te.cFree7+te.cFree8+te.cFree9+te.cFree10 AS Costre2, a.TransCode,a.TransSequence AS Sequence,a.InvCode,SUM(a.Quantity) as Quantity,SUM((a.Quantity)*(c.Amount/c.Quantity)) AS Amount, c.PickID,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode, ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2, ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6, ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10 FROM #NewDouTempERP a INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint INNER JOIN ICSOutsourcingOrder b ON b.OOCode=a.TransCode AND b.WorkPoint=a.WorkPoint INNER JOIN ICSOOPick c ON c.OODetailID=b.OODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence INNER JOIN ICSExtension ext ON ext.ID=lot.ExtensionID AND ext.WorkPoint=lot.WorkPoint INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint INNER JOIN #TempERP te ON te.TransSequence=SUBSTRING(a.TransSequence,1,CHARINDEX('~',a.TransSequence)-1) and c.OODetailID+a.EATTRIBUTE3 = c.OODetailID+te.ProjectCode+te.BatchCode+te.Version+te.Brand+te.cFree1+te.cFree2+te.cFree3+te.cFree4+te.cFree5+te.cFree6+te.cFree7+te.cFree8+te.cFree9+te.cFree10 GROUP BY a.EATTRIBUTE3,a.FromWarehouseCode,c.OODetailID,a.TransCode,a.TransSequence,a.InvCode,c.PickID,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, ''),a.TransSequence,te.ProjectCode,te.BatchCode,te.Version,te.Brand,te.cFree1,te.cFree2,te.cFree3,te.cFree4,te.cFree5,te.cFree6,te.cFree7,te.cFree8,te.cFree9,te.cFree10 DROP TABLE #TempERP DROP TABLE #NewTempERP DROP TABLE #NewDouTempERP"; sql = string.Format(sql, Identification, BusinessCode); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "detailss", "Costre2"); string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocURL, Inputstr); log.Debug("委外入库ERP接口返回值:" + Environment.NewLine + resultStr); Result result = new Result(); result = JsonConvert.DeserializeObject(resultStr); if (result.Success) { try { if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9) { string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'"; newsql = string.Format(newsql, Identification, BusinessCode); DataTable dt = DBHelper.SQlReturnData(newsql, cmd); 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 = "" + 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["OODetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode); if (det["detailss"] != null) { JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString()); foreach (var details in resdetails) { JObject dets = (JObject)details; if (dets != null) { //for (int i = 0; i < dt.Rows.Count; i++) //{ //派纳倒冲排除仓库逻辑 string whsql = @"SELECT b.F_ItemCode,b.F_ItemName FROM Sys_SRM_Items a INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1'"; whsql = string.Format(whsql); DataTable dtt = DBHelper.SQlReturnData(whsql, cmd); if (dtt.Rows.Count > 0 && dtt != null) { if (!dtt.Rows[0]["F_ItemCode"].ToString().Equals(dets["WHCode"].ToString())) { ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(), dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(), dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(), dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(), dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["BatchCode"].ToString(), dets["Version"].ToString(), dets["Brand"].ToString(), cmd, language); } //回写已领数量 sql = @"UPDATE ICSOOPick SET IssueQuantity=Quantity WHERE PickID='{0}' AND WorkPoint='{1}'"; sql = String.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString()); if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo199")); } } else { ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(), dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(), dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(), dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(), dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["BatchCode"].ToString(), dets["Version"].ToString(), dets["Brand"].ToString(), cmd, language); //回写已领数量 sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + dets["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'"; sql = String.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString()); if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo199")); } } //ICSWareHouseLotInfoService.WareHouseLotInfoBack(Identification, "", dt.Rows[i]["LotNo"].ToString(), dets["Quantity"].ToString(), //"", dt.Rows[i]["WorkPoint"].ToString(), "", "", cmd, language, "", "", "", "", dets["DCInvCode"].ToString(), dets["WHCode"].ToString()); //} } } } } } } else { 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 = "" + 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["OODetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode); if (det["detailss"] != null) { JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString()); foreach (var details in resdetails) { JObject dets = (JObject)details; if (dets != null) { //直接回写 string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1' FROM ICSWareHouseLotInfoLog a LEFT JOIN ICSOutsourcingOrder b ON a.TransCode=b.OOCode AND a.WorkPoint=b.WorkPoint LEFT JOIN ICSOOPick c ON b.OODetailID=c.OODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode='60'"; ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["DetailID"].ToString(), dets["MRCVCode"].ToString() , dets["Sequence"].ToString(), BusinessCode); if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd)) { //throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"委外倒冲回写失败!"; } //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, dets["ERPID"].ToString(), // dets[" "].ToString(), dets["MRCVCode"].ToString(), dets["Sequence"].ToString(), allcol, cmd, language); } } } } } } } catch (Exception ex) { log.Debug(ex.ToString()); log.Debug(resultStr); throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex); } } else { throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message); } #endregion } catch (Exception) { throw; } } public static void CreateOOArriveERP(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,TransCode INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}' select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID,TransSequence,TransCode,FromWarehouseCode INTO #NewDouTempERP from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND TransType='13' SELECT c.VenCode+a.ToWarehouseCode+c.OOCode+a.MUSER+f.ODNCode AS Costre,c.OODetailID+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, '') AS Costre2,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.OOCode,c.OOID,f.ODNCode,f.ODNDetailID,a.MUSER,f.Sequence AS ODNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.OOCode,c.OODetailID,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.OODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose,conStockneww.Enable AS CompleteVerification ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand, ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10,a.TransSequence ,'{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 ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint INNER JOIN ICSODeliveryNotice f ON g.OASNCode=f.OASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID INNER JOIN ICSOutsourcingOrder c ON b.TransCode = c.OOCode AND b.TransSequence = c.Sequence AND f.OODetailID = c.OODetailID AND b.WorkPoint = c.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conn ON con.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='FillClose002' INNER JOIN ICSConfiguration conStockneww ON a.WorkPoint=conStockneww.WorkPoint AND conStockneww.Code='CompleteVerification005' GROUP BY conStockneww.Enable,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.OOCode,a.MUSER,f.ODNCode,f.ODNDetailID,f.Sequence,a.TransSequence,a.InvCode,c.OOID,c.OODetailID,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,OOCode as POCode,ODNCode as DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,CompleteVerification,UpdateStock,IsFillClose,DocTyppe, DocDate, DocDate as ArrDate FROM #TempERP SELECT Costre,Costre2,Sequence,ODNSequence as DNSequence,TransSequence,InvCode,Quantity,Amount,OODetailID as PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WarehouseCode AS WhCode,srcDocPOLineNo FROM #TempERP DROP TABLE #TempERP DROP TABLE #NewTempERP DROP TABLE #NewDouTempERP "; // 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 OutsourcingReceiveRcvDoc(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 ICSOutsourcingReceive 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 ICSOutsourcingReceive 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 ICSOutsourcingReceive 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 OutsourcingReceiveRcvDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode,string UserCode) { try { #region ERP开立状态单据审核 string sql = ""; string outwhcode = ""; string pnsql = ""; string Inputstr = ""; DataTable flag = null; DataTable dt = null; string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'"; flag = DBHelper.SQlReturnData(enablesql, cmd); 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 ICSOutsourcingReceive 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 ICSOutsourcingReceive 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 < chekdt.Rows.Count; i++) { decimal SUMQty = Convert.ToDecimal(chekdt.Rows[i]["SUMQty"]); decimal ISSQty = Convert.ToDecimal(chekdt.Rows[i]["ISSQty"]); string trancode = chekdt.Rows[i]["transCode"].ToString(); string transSequence = chekdt.Rows[i]["transSequence"].ToString(); if (SUMQty - ISSQty == 0) { if (DBHelper.IsPNU9()) { pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence INTO #NewTempERP from ICSWareHouseLotInfoLog WHERE TransCode='{0}' and TransSequence='{1}' AND ERPUpload='0' and EATTRIBUTE1<>'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 ICSOutsourcingReceive 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 LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,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 ICSOutsourcingReceive 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 { if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9) { string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'"; newsql = string.Format(newsql, Identification, BusinessCode); DataTable dtnew = DBHelper.SQlReturnData(newsql, cmd); JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString()); foreach (var item in res) { JObject jo = (JObject)item; ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, jo["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode); //派纳倒冲排除仓库逻辑 string whsql = @"SELECT b.F_ItemCode,b.F_ItemName FROM Sys_SRM_Items a INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1' and b.F_ItemCode='{0}'"; whsql = string.Format(whsql, jo["WHCode"].ToString()); DataTable dtt = DBHelper.SQlReturnData(whsql, cmd); if (dtt.Rows.Count > 0 && dtt != null) { //if (!jo["WHCode"].ToString().Equals(dtt.Rows[0]["F_ItemCode"].ToString())) //{ // //倒冲 // ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(), // jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(), // jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(), // jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(), // jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(), // jo["Brand"].ToString(), cmd, language); //} //回写已领数量 sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'"; sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString()); if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo199")); } //for (int i = 0; i < dtt.Rows.Count; i++) //{ // if (outwhcode == "") // { // outwhcode += "" + dtt.Rows[i]["F_ItemCode"].ToString() + ""; // } // else // { // outwhcode += "," + dtt.Rows[i]["F_ItemCode"].ToString() + ""; // } //} } else { //倒冲 ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(), jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(), jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(), jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(), jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(), jo["Brand"].ToString(), cmd, language); //回写已领数量 sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'"; sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString()); if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo199")); } } } } else { 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' 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 ICSOutsourcingReceive 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 { if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9) { string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'"; newsql = string.Format(newsql, Identification, BusinessCode); DataTable dtnew = DBHelper.SQlReturnData(newsql, cmd); JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString()); foreach (var item in res) { JObject jo = (JObject)item; ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, jo["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode); //派纳倒冲排除仓库逻辑 string whsql = @"SELECT b.F_ItemCode,b.F_ItemName FROM Sys_SRM_Items a INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1'"; whsql = string.Format(whsql); DataTable dtt = DBHelper.SQlReturnData(whsql, cmd); if (dtt.Rows.Count > 0 && dtt != null) { if (!jo["WHCode"].ToString().Equals(dtt.Rows[0]["F_ItemCode"].ToString())) { //倒冲 ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(), jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(), jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(), jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(), jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(), jo["Brand"].ToString(), cmd, language); } //回写已领数量 sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'"; sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString()); if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo199")); } //for (int i = 0; i < dtt.Rows.Count; i++) //{ // if (outwhcode == "") // { // outwhcode += "" + dtt.Rows[i]["F_ItemCode"].ToString() + ""; // } // else // { // outwhcode += "," + dtt.Rows[i]["F_ItemCode"].ToString() + ""; // } //} } else { //倒冲 ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(), jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(), jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(), jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(), jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(), jo["Brand"].ToString(), cmd, language); //回写已领数量 sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'"; sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString()); if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo199")); } } } } else { 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); } } // string sql = @" //select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence //INTO #NewTempERP //from ICSWareHouseLotInfoLog // WHERE Identification='{0}' AND ERPUpload='0' // 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 ICSOutsourcingReceive 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); // DataTable dt = DBHelper.SQlReturnData(sql, cmd); // string Inputstr = JsonConvert.SerializeObject(dt); #endregion } catch (Exception) { throw; } } #endregion #region 审核的委外到货单 /// /// 审核的委外到货单 /// /// /// /// /// /// public static void ODeliveryNoticeIn(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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1' AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn005', c.Quantity,1,1,'') /// 审核的委外到货单接口 /// /// /// /// public static void ODeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary language,string BusinessCode) { try { DataTable flag = null; string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'"; flag = DBHelper.SQlReturnData(enablesql, cmd); if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9) { //校验库存数量是否满足子件计划数量(倒冲) string logsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,ToLocationCode,TransCode,TransSequence from ICSWareHouseLotInfoLog WHERE Identification = '{0}' AND ERPUpload = '0'"; logsql = string.Format(logsql, Identification); DataTable logdt = DBHelper.SQlReturnData(logsql, cmd); if (logdt.Rows.Count > 0 && logdt != null) { for (int i = 0; i < logdt.Rows.Count; i++) { ICSWareHouseLotInfoService.WareHouseLotInfoBackOutBefore(Identification, logdt.Rows[i]["ToLocationCode"].ToString(), logdt.Rows[i]["LotNo"].ToString(), logdt.Rows[i]["Quantity"].ToString(), logdt.Rows[i]["MUSER"].ToString(), logdt.Rows[i]["WorkPoint"].ToString(), "2", BusinessCode, cmd, language, "", "", logdt.Rows[i]["TransCode"].ToString(), logdt.Rows[i]["TransSequence"].ToString()); } } } #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.ODNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.ODNCode ,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.ODNDetailID,a.InvCode) AS Sequence,d.OOCode,d.OODetailID, 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.ODNDetailID,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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint inner join ICSOutsourcingOrder d on c.OODetailID=d.OODetailID 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.OOCode,d.OODetailID,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.ODNCode,c.ODNID,a.MUSER,a.InvCode,c.ODNDetailID,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,ODNCode,OOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,ODNDetailID,OODetailID,WarehouseCode AS WHCode,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,BusinessCode); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre"); string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ODeliveryNoticeInURL, Inputstr); Result result = new Result(); log.Debug(resultStr); result = JsonConvert.DeserializeObject(resultStr); if (result.Success) { try { if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9) { string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'"; newsql = string.Format(newsql, Identification, BusinessCode); DataTable dt = DBHelper.SQlReturnData(newsql, cmd); 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 = "" + 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["OODetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode); if (det["detailss"] != null) { JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString()); foreach (var details in resdetails) { JObject dets = (JObject)details; if (dets != null) { //for (int i = 0; i < dt.Rows.Count; i++) //{ ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(), dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(), dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(), dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(), dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["BatchCode"].ToString(), dets["Version"].ToString(), dets["Brand"].ToString(), cmd, language); //回写已领数量 sql = @"select pickid from ICSOOPick WHERE PickID='{0}' AND WorkPoint='{1}'"; sql = string.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString()); DataTable ssdt = DBHelper.SQlReturnData(sql, cmd); sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + dets["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'"; sql = string.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString()); if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo199")); } //ICSWareHouseLotInfoService.WareHouseLotInfoBack(Identification, "", "", dets["Quantity"].ToString(), //dt.Rows[0]["MUSER"].ToString(), "", "", BusinessCode, cmd, language, "", "", "", "", dets["DCInvCode"].ToString(), dets["WHCode"].ToString()); //} } } } } } } else { 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["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode); } } } } catch (Exception ex) { log.Debug(ex.ToString()); log.Debug(resultStr); throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex); } } else { throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message); } #endregion } catch (Exception) { throw; } } #endregion #region 委外拒收 /// /// 委外拒收 /// /// /// /// /// /// public static void OutsourcingRejectDocIn(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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3' AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn006', c.Quantity,1,1,'') /// 委外拒收接口 /// /// /// /// public static void OutsourcingRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary language,string BusinessCode) { // try // { // #region ERP // string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.ODNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,d.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.ODNCode,c.ODNDetailID,a.InvCode) AS Sequence, // a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.ODNDetailID,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 // 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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint // INNER JOIN ICSODeliveryNotice d ON c.OODetailID=d.ODNDetailID AND d.WorkPoint=c.WorkPoint // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint // WHERE a.Identification='{0}' AND ERPUpload='0' // GROUP BY c.VenCode,a.ToWarehouseCode,c.ODNCode,d.ODNCode,a.MUSER,a.InvCode,d.ODNDetailID,c.ODNDetailID,isnull((c.UnitPrice),0),c.Currency,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,ODNCode AS DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint FROM #TempERP //SELECT Costre,Sequence,InvCode,Quantity,Amount,ODNDetailID AS 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.CreateWPuArrivalVouchURL, 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["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["OODetailID"].ToString(), jo["ORCVTCode"].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; // } } /// /// 委外拒收接口 /// /// /// /// public static void OutsourcingRejectDocInNewERP(string ODNCode, string OJDNCode, string WorkPoint, SqlCommand cmd, Dictionary language) { try { #region ERP string sql = @"SELECT a.VenCode+a.DepCode+x.ODNCode+a.MUSER AS Costre,a.VenCode,a.DepCode,x.ODNCode,a.MUSER,a.MTIME, a.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.ODNDetailID ,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 ICSODeliveryNotice 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 ICSODeliveryNotice x ON x.ODNDetailID=a.OODetailID AND a.WorkPoint=x.WorkPoint WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}' GROUP BY invBat.AmountEnable,a.VenCode,a.DepCode,invBat.AmountEnable,x.ODNCode,a.MUSER,a.MTIME,a.Sequence,a.InvCode,a.Amount,a.Quantity,a.UnitPrice,a.Currency,x.ODNDetailID, 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,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,ODNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP DROP TABLE #TempERP"; sql = string.Format(sql, OJDNCode, WorkPoint); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd); string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre"); string resultStr = HTTPHelper.HttpPost("委外拒收", ERPUrl.CreateWPuArrivalVouchURL, 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 ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}' where OODetailID='{4}' AND ODNType='3' AND ODNCode='{5}' "; ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], OJDNCode); 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 OutsourcingReturnBack(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 ICSODeliveryNotice WHERE ODNCode='{0}' AND ODNType='2' AND id='{4}' and WorkPoint='{1}' IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo119") + @"',16,1); RETURN END ELSE IF (@Status!='2') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo120") + @"',16,1); RETURN END UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}' FROM ICSODeliveryNotice a WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.id='{4}' AND ODNType='2' UPDATE b SET Inquantity=ISNULL(b.Inquantity,0)-'{2}' FROM ICSOutsourcingOrder b inner join ICSODeliveryNotice a on a.ooID = b.ooID and a.OODetailID = b.OODetailID WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND ODNType='2' IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.id='{4}' AND a.Quantity language, string TransID) { try { string sql = @"DECLARE @Status VARCHAR(10) SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' AND ODNType='1' AND id='{4}' and WorkPoint='{1}' IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo119") + @"',16,1); RETURN END ELSE IF (@Status!='2') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo120") + @"',16,1); RETURN END UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)-'{2}' FROM ICSODeliveryNotice a WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.id='{4}' AND ODNType='1' IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.id='{4}' AND a.RCVQuantity<0 AND ODNType='1') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1); RETURN END"; sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID); if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo121"));//"委外退货单更新失败!"); } } catch (Exception) { throw; } } /// /// 委外退货接口 /// /// /// /// public static void OutsourcingReturnBackERP(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 = '11' SELECT y.VenCode+a.FromWarehouseCode+y.ODNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.ODNCode,y.ODNDetailID,a.InvCode) AS Sequence, 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.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,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,conv.Enable AS CompleteVerification 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 ICSODeliveryNotice y ON a.TransCode=y.ODNCode 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 conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.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.ODNCode,a.MUSER,a.InvCode,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conv.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,ODNCode AS ODNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,ODNCode AS SourceCode, SYSDATETIME() AS DocDate,'RCV25' as DocTypeCode FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ODNDetailID AS ODNRTDetailID,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 = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReturnBackURL, 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["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["ORCVNEGCode"].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 string OutsourcingReturnBackOOERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode) { string msg = ""; 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 = '11' SELECT y.VenCode+a.FromWarehouseCode+y.ODNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.ODNCode,y.ODNDetailID,a.InvCode) AS Sequence, 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.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,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,conv.Enable AS CompleteVerification 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 ICSODeliveryNotice y ON a.TransCode=y.ODNCode 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 conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.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.ODNCode,a.MUSER,a.InvCode,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conv.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,ODNCode AS OOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,ODNCode AS SourceCode, SYSDATETIME() AS DocDate,'RCV25' as DocTypeCode FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ODNDetailID AS OODetailID,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 = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReturnBackOOURL, Inputstr); Result result = new Result(); result = JsonConvert.DeserializeObject(resultStr); if (result.Success) { log.Debug(resultStr); try { string newsql = @"select LotNo,WorkPoint,InvCode,FromWarehouseCode,MUSER,Quantity,TransSequence,TransCode from ICSWareHouseLotInfoLog WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'"; newsql = string.Format(newsql, Identification, BusinessCode); DataTable dt = DBHelper.SQlReturnData(newsql, cmd); 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["OODetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode); if (det["detailss"] != null) { JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString()); foreach (var details in resdetails) { JObject dets = (JObject)details; if (dets != null) { //for (int i = 0; i < dt.Rows.Count; i++) //(string Identification, //string TransCode, string TransSequence, string InvCode, string WHCode, string Quantity, string User, //string WorkPoint, string TransType, string BusinessCode, string ERPID, string ERPDetailID, string ERPCode, string ERPSequence, ICSWareHouseLotInfoService.WareHouseLotInfoBackInMF(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(), dets["WhCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(), dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(), dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(), dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["cBatch"].ToString(), dets["version"].ToString(), dets["brand"].ToString(), dets["PickID"].ToString(), cmd, language); //ICSWareHouseLotInfoService.WareHouseLotInfoBack(Identification, "", dt.Rows[i]["LotNo"].ToString(), dets["Quantity"].ToString(), //"", dt.Rows[i]["WorkPoint"].ToString(), "", "", cmd, language, "", "", "", "", dets["DCInvCode"].ToString(), dets["WHCode"].ToString()); //} } } } } } } catch (Exception ex) { log.Debug(ex.ToString()); log.Debug(resultStr); } } else { throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message); } #endregion } catch (Exception) { throw; } return msg; } public static void RTOutsourcingReturnBackERP(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 = '11' SELECT y.VenCode+a.FromWarehouseCode+y.ODNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.ODNCode,y.ODNDetailID,a.InvCode) AS Sequence,z.Sequence AS srcDocPOLineNo,y.OODetailID,z.ODNCode 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.ODNDetailID,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 ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint INNER JOIN ICSODeliveryNotice z ON z.Sequence=y.OoDetailID AND z.ODNCode=y.OOID 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.OODetailID,z.ODNCode,inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.ODNCode,a.MUSER,a.InvCode,y.ODNDetailID,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,OODetailID AS 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 = 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["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["ORCVNEGCode"].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 U9OutsourcingReturnBackERP(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 = '11' IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a INNER JOIN ICSODeliveryNotice b ON a.TransCode=b.ODNCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',16,1); RETURN END SELECT y.VenCode+a.FromWarehouseCode+y.ODNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.ODNCode,y.ODNDetailID,a.InvCode) AS Sequence, 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.ODNDetailID,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,conv.Enable AS CompleteVerification ,y.Sequence as oSequence 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 ICSODeliveryNotice y ON a.TransCode=y.ODNCode 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 conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint GROUP BY inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.ODNCode,a.MUSER,a.InvCode,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conv.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, ''),y.Sequence SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNCode AS ODNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,ODNCode AS SourceCode, SYSDATETIME() AS DocDate,oSequence as Sequence,InvCode,Quantity,'RCV25' as DocTypeCode,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.ToJson(ds.Tables[0]); string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OutsourcingReturnBackURL, 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["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["ORCVNEGCode"].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 OutsourcingReceiveDocNegative(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 ICSOutsourcingReceive 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("WMSAPIInfo122") + @"',16,1); RETURN END ELSE IF (@Status!='1') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo123") + @"',16,1); RETURN END UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}' FROM ICSOutsourcingReceive 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 ICSOutsourcingReceive 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 OutsourcingReceiveDocNegativeERP(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 = '12' 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 ICSOutsourcingReceive 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 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 ICSOutsourcingReceive b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint where a.Identification='{0}' 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 = '12' 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 ICSOutsourcingReceive 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 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.OutsourcingReceiveDocNegativeURL, 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 = '12' IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',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 ICSOutsourcingReceive 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 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.OutsourcingReceiveDocNegativeURL, 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 } }