You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3605 lines
269 KiB

3 weeks ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Linq;
  10. using System.Net.Http;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace ICSSoft.DataProject
  14. {
  15. /// <summary>
  16. /// 使用中
  17. /// 委外模块
  18. /// </summary>
  19. public class ICSOutsourcingService
  20. {
  21. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  22. #region 委外发料
  23. /// <summary>
  24. /// 委外发料
  25. /// </summary>
  26. /// <param name="TransCode"></param>
  27. /// <param name="TransSequence"></param>
  28. /// <param name="Quantity"></param>
  29. /// <param name="WorkPoint"></param>
  30. /// <param name="cmd"></param>
  31. public static void OutsourcingIssueDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string enableCode,string TransID)
  32. {
  33. try
  34. {
  35. string sql = @"DECLARE @Status VARCHAR(10)
  36. SELECT @Status=b.Status FROM ICSOOPick a
  37. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  38. WHERE b.OOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{5}'
  39. IF (@Status IS NULL)
  40. BEGIN
  41. RAISERROR('" + language.GetNameByCode("WMSAPIInfo104") + @"',16,1);
  42. RETURN
  43. END
  44. ELSE IF (@Status!='2')
  45. BEGIN
  46. RAISERROR('" + language.GetNameByCode("WMSAPIInfo105") + @"',16,1);
  47. RETURN
  48. END
  49. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  50. FROM ICSOOPick a
  51. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  52. WHERE b.OOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' and a.id='{5}' AND a.WorkPoint='{1}'
  53. IF EXISTS(SELECT a.ID FROM ICSOOPick a
  54. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  55. WHERE b.OOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' and a.id='{5}' and b.WorkPoint='{1}' AND
  56. (dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{4}',2,2,''))<a.IssueQuantity)
  57. BEGIN
  58. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  59. RETURN
  60. END";
  61. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence,enableCode, TransID);
  62. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  63. {
  64. throw new Exception(language.GetNameByCode("WMSAPIInfo107"));
  65. }
  66. }
  67. catch (Exception)
  68. {
  69. throw;
  70. }
  71. }
  72. /// <summary>
  73. /// 委外发料接口
  74. /// </summary>
  75. /// <param name="TransType"></param>
  76. /// <param name="Identification"></param>
  77. /// <param name="cmd"></param>
  78. public static void OutsourcingIssueDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  79. {
  80. try
  81. {
  82. #region ERP
  83. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  84. INTO #NewTempERP
  85. from ICSWareHouseLotInfoLog
  86. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '5'
  87. SELECT isnull(y.DepCode,'') + a.FromWarehouseCode + y.OOCode + a.MUSER AS Costre,
  88. 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,
  89. 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
  90. ,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,
  91. 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
  92. , x.OODetailID
  93. INTO #TempERP
  94. FROM #NewTempERP a
  95. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  96. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  97. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  98. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  99. INNER JOIN ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint
  100. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  101. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  102. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  103. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  104. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  105. 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
  106. ,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, ''),
  107. 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, '')
  108. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock FROM #TempERP
  109. 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
  110. DROP TABLE #TempERP
  111. DROP TABLE #NewTempERP";
  112. sql = string.Format(sql, Identification);
  113. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  114. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  115. string resultStr = "";
  116. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["IsU9Api"]))
  117. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OutsourcingIssueDocURL, Inputstr); }
  118. else { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDocURL, Inputstr); }
  119. Result result = new Result();
  120. result = JsonConvert.DeserializeObject<Result>(resultStr);
  121. if (result.Success)
  122. {
  123. try
  124. {
  125. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  126. foreach (var item in res)
  127. {
  128. JObject jo = (JObject)item;
  129. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  130. foreach (var detail in resdetail)
  131. {
  132. JObject det = (JObject)detail;
  133. 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()
  134. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  135. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  136. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol,cmd, language, BusinessCode);
  137. }
  138. }
  139. }
  140. catch (Exception ex)
  141. {
  142. log.Debug(ex.ToString());
  143. log.Debug(resultStr);
  144. }
  145. }
  146. else
  147. {
  148. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  149. }
  150. #endregion
  151. }
  152. catch (Exception)
  153. {
  154. throw;
  155. }
  156. }
  157. #endregion
  158. #region 委外领料申请单生产发料
  159. /// <summary>
  160. /// 委外领料申请单生产发料
  161. /// </summary>
  162. /// <param name="TransCode"></param>
  163. /// <param name="TransSequence"></param>
  164. /// <param name="Quantity"></param>
  165. /// <param name="WorkPoint"></param>
  166. /// <param name="cmd"></param>
  167. public static void OOApply(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string enableCode,string TransID)
  168. {
  169. try
  170. {
  171. string sql = @"DECLARE @Status VARCHAR(10)
  172. SELECT @Status=a.Status FROM ICSOApply a
  173. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.id='{5}' AND a.WorkPoint='{1}'
  174. IF (@Status IS NULL)
  175. BEGIN
  176. RAISERROR('" + language.GetNameByCode("WMSAPIInfo108") + @"',16,1);
  177. RETURN
  178. END
  179. ELSE IF (@Status!='2')
  180. BEGIN
  181. RAISERROR('" + language.GetNameByCode("WMSAPIInfo109") + @"',16,1);
  182. RETURN
  183. END
  184. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  185. FROM ICSOApply a
  186. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.id='{5}' AND a.WorkPoint='{1}'
  187. IF EXISTS(SELECT a.ID FROM ICSOApply a
  188. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.id='{5}' and a.WorkPoint='{1}' AND
  189. (dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{4}',2,2,''))<a.IssueQuantity)
  190. BEGIN
  191. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  192. RETURN
  193. END";
  194. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence,enableCode, TransID);
  195. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  196. {
  197. throw new Exception(language.GetNameByCode("WMSAPIInfo110"));
  198. }
  199. }
  200. catch (Exception)
  201. {
  202. throw;
  203. }
  204. }
  205. /// <summary>
  206. /// 委外领料申请单生产发料接口
  207. /// </summary>
  208. /// <param name="TransType"></param>
  209. /// <param name="Identification"></param>
  210. /// <param name="cmd"></param>
  211. public static void OOApplyERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  212. {
  213. try
  214. {
  215. #region ERP
  216. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
  217. INTO #NewTempERP
  218. from ICSWareHouseLotInfoLog
  219. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '6'
  220. 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,
  221. 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
  222. ,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,
  223. 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
  224. ,b.ApplyID
  225. INTO #TempERP
  226. FROM #NewTempERP a
  227. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  228. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  229. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  230. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  231. INNER JOIN ICSOApply b ON a.TransCode=b.ApplyCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint
  232. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  233. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  234. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  235. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  236. GROUP BY conWhCode.Enable,inv.AmountEnable,a.FromWarehouseCode,b.ApplyCode,b.ApplyID,a.MUSER,a.InvCode,b.ApplyDetailID,con.Enable,conv.Enable,conStock.Enable
  237. ,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, ''),
  238. 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, '')
  239. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,ApplyID as SourceID FROM #TempERP
  240. 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
  241. DROP TABLE #TempERP
  242. DROP TABLE #NewTempERP";
  243. sql = string.Format(sql, Identification);
  244. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  245. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  246. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOApplyURL, Inputstr);
  247. Result result = new Result();
  248. result = JsonConvert.DeserializeObject<Result>(resultStr);
  249. if (result.Success)
  250. {
  251. try
  252. {
  253. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  254. foreach (var item in res)
  255. {
  256. JObject jo = (JObject)item;
  257. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  258. foreach (var detail in resdetail)
  259. {
  260. JObject det = (JObject)detail;
  261. 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()
  262. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  263. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  264. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  265. }
  266. }
  267. }
  268. catch (Exception ex)
  269. {
  270. log.Debug(ex.ToString());
  271. log.Debug(resultStr);
  272. }
  273. }
  274. else
  275. {
  276. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  277. }
  278. #endregion
  279. }
  280. catch (Exception)
  281. {
  282. throw;
  283. }
  284. }
  285. #endregion
  286. #region 委外材料出库单生产发料
  287. /// <summary>
  288. /// 委外材料出库单生产发料
  289. /// </summary>
  290. /// <param name="TransCode"></param>
  291. /// <param name="TransSequence"></param>
  292. /// <param name="Quantity"></param>
  293. /// <param name="WorkPoint"></param>
  294. /// <param name="cmd"></param>
  295. public static void OOIssue(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string TransID)
  296. {
  297. try
  298. {
  299. string sql = @"DECLARE @Status VARCHAR(10)
  300. SELECT @Status=a.Status FROM ICSOIssue a
  301. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}'
  302. IF (@Status IS NULL)
  303. BEGIN
  304. RAISERROR('" + language.GetNameByCode("WMSAPIInfo111") + @"',16,1);
  305. RETURN
  306. END
  307. ELSE IF (@Status!='1')
  308. BEGIN
  309. RAISERROR('" + language.GetNameByCode("WMSAPIInfo112") + @"',16,1);
  310. RETURN
  311. END
  312. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  313. FROM ICSOIssue a
  314. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}'
  315. IF EXISTS(SELECT a.ID FROM ICSOIssue a
  316. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' and a.id='{4}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  317. BEGIN
  318. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  319. RETURN
  320. END";
  321. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  322. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  323. {
  324. throw new Exception(language.GetNameByCode("WMSAPIInfo113"));
  325. }
  326. }
  327. catch (Exception)
  328. {
  329. throw;
  330. }
  331. }
  332. /// <summary>
  333. /// 委外材料出库单生产发料接口
  334. /// </summary>
  335. /// <param name="TransType"></param>
  336. /// <param name="Identification"></param>
  337. /// <param name="cmd"></param>
  338. public static void OOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  339. {
  340. try
  341. {
  342. #region ERP开立状态单据审核
  343. string sql = "";
  344. if (DBHelper.IsPNU9())
  345. {
  346. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  347. INTO #NewTempERP
  348. from ICSWareHouseLotInfoLog
  349. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '7'
  350. SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  351. FROM #NewTempERP a
  352. INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  353. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  354. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  355. GROUP BY b.IssueID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  356. DROP TABLE #NewTempERP";
  357. sql = string.Format(sql, Identification);
  358. 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
  359. where a.Identification='{0}' GROUP BY a.transCode";
  360. checksql = string.Format(checksql, Identification);
  361. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  362. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  363. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  364. string trancode = chekdt.Rows[0]["transCode"].ToString();
  365. if (SUMQty - ISSQty == 0)
  366. {
  367. string pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  368. INTO #NewTempERP
  369. from ICSWareHouseLotInfoLog
  370. WHERE TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '7' and EATTRIBUTE1<>'1'
  371. SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  372. FROM #NewTempERP a
  373. INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  374. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  375. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  376. GROUP BY b.IssueID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  377. DROP TABLE #NewTempERP";
  378. pnsql = string.Format(pnsql, trancode);
  379. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  380. string Inputstr = JsonConvert.SerializeObject(dt);
  381. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOIssueURL, Inputstr);
  382. Result result = new Result();
  383. result = JsonConvert.DeserializeObject<Result>(resultStr);
  384. if (result.Success)
  385. {
  386. try
  387. {
  388. foreach (DataRow dr in dt.Rows)
  389. {
  390. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  391. }
  392. }
  393. catch (Exception ex)
  394. {
  395. log.Debug(ex.ToString());
  396. log.Debug(resultStr);
  397. }
  398. }
  399. else
  400. {
  401. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  402. }
  403. }
  404. }
  405. else
  406. {
  407. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  408. INTO #NewTempERP
  409. from ICSWareHouseLotInfoLog
  410. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '7'
  411. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  412. INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  413. WHERE a.Identification='{0}' AND b.Quantity!=b.IssueQuantity)
  414. BEGIN
  415. RAISERROR('" + language.GetNameByCode("WMSAPIInfo095") + @"',16,1);
  416. RETURN
  417. END
  418. SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  419. FROM #NewTempERP a
  420. INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  421. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  422. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  423. GROUP BY b.IssueID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  424. DROP TABLE #NewTempERP";
  425. sql = string.Format(sql, Identification);
  426. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  427. string Inputstr = JsonConvert.SerializeObject(dt);
  428. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOIssueURL, Inputstr);
  429. Result result = new Result();
  430. result = JsonConvert.DeserializeObject<Result>(resultStr);
  431. if (result.Success)
  432. {
  433. try
  434. {
  435. foreach (DataRow dr in dt.Rows)
  436. {
  437. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  438. }
  439. }
  440. catch (Exception ex)
  441. {
  442. log.Debug(ex.ToString());
  443. log.Debug(resultStr);
  444. }
  445. }
  446. else
  447. {
  448. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  449. }
  450. }
  451. #endregion
  452. }
  453. catch (Exception)
  454. {
  455. throw;
  456. }
  457. }
  458. #endregion
  459. #region 委外退料
  460. /// <summary>
  461. /// 委外退料
  462. /// </summary>
  463. /// <param name="TransCode"></param>
  464. /// <param name="TransSequence"></param>
  465. /// <param name="Quantity"></param>
  466. /// <param name="WorkPoint"></param>
  467. /// <param name="cmd"></param>
  468. public static void OutsourcingIssueDoNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint, string TransCode, string TransSequence, SqlCommand cmd, Dictionary<string, string> language)
  469. {
  470. try
  471. {
  472. string table = "";
  473. string sql = "";
  474. if (string.IsNullOrWhiteSpace(LogID))
  475. {
  476. string type = "";
  477. string quantitySql = "c.Quantity";
  478. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  479. {
  480. table = "INNER JOIN ICSOOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint";
  481. type = "1";
  482. quantitySql = "dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn008', c.Quantity,1,1,'')";
  483. }
  484. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  485. {
  486. table = "INNER JOIN ICSOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
  487. type = "2";
  488. quantitySql = "dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn009', c.Quantity,1,1,'')";
  489. }
  490. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  491. {
  492. table = "INNER JOIN ICSOIssue e ON c.SourceDetailID=e.IssueDetailID AND c.WorkPoint=e.WorkPoint";
  493. type = "3";
  494. quantitySql = "dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn010', c.Quantity,1,1,'')";
  495. }
  496. else
  497. {
  498. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  499. }
  500. #region 新条码
  501. sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  502. FROM ICSInventoryLot a
  503. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  504. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  505. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  506. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  507. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  508. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  509. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  510. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  511. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND {5}<c.IssueNegQuantity)
  512. BEGIN
  513. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  514. END
  515. UPDATE e SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  516. FROM ICSInventoryLot a
  517. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  518. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  519. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  520. {3}
  521. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  522. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  523. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  524. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  525. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  526. {3}
  527. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND e.IssueQuantity<0)
  528. BEGIN
  529. RAISERROR('" + language.GetNameByCode("WMSAPIInfo193") + @"',16,1);
  530. END";
  531. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type, quantitySql);
  532. #endregion
  533. }
  534. else
  535. {
  536. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  537. {
  538. table = @"INNER JOIN ICSOutsourcingOrder b ON a.TransCode=b.OOCode AND a.WorkPoint=b.WorkPoint
  539. INNER JOIN ICSOOPick c ON b.OODetailID = c.OODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
  540. }
  541. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  542. {
  543. table = "INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  544. }
  545. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  546. {
  547. table = "INNER JOIN ICSOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  548. }
  549. else
  550. {
  551. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  552. }
  553. #region 原条码
  554. //sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  555. // FROM ICSWareHouseLotInfoLog a
  556. // {3}
  557. // WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}'
  558. // IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
  559. // {3}
  560. // WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0)
  561. // BEGIN
  562. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo193") + @"',16,1);
  563. // END";
  564. sql = @"IF EXISTS(select * from ICSOApplyNegDetail where Quantity>'{2}' and OApplyNegCode='{5}' and Sequence='{6}')
  565. BEGIN
  566. UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  567. FROM ICSOApplyNegDetail c
  568. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  569. WHERE c.WorkPoint='{1}' and c.OApplyNegCode='{5}' and c.Sequence='{6}'
  570. END";
  571. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID, TransCode, TransSequence);
  572. #endregion
  573. }
  574. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  575. {
  576. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  577. }
  578. }
  579. catch (Exception)
  580. {
  581. throw;
  582. }
  583. }
  584. /// <summary>
  585. /// 委外退料接口
  586. /// </summary>
  587. /// <param name="TransType"></param>
  588. /// <param name="Identification"></param>
  589. /// <param name="cmd"></param>
  590. public static void OutsourcingIssueDoNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  591. {
  592. try
  593. {
  594. #region ERP
  595. string sql = string.Empty;
  596. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  597. {
  598. if (DBHelper.IsU9()) {
  599. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  600. INTO #NewTempERP
  601. from ICSWareHouseLotInfoLog
  602. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  603. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  604. INTO #NewDouTempERP
  605. from ICSWareHouseLotInfoLog
  606. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  607. 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,
  608. 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
  609. ,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,
  610. 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
  611. INTO #TempERP
  612. FROM #NewTempERP a
  613. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  614. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  615. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  616. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  617. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  618. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  619. INNER JOIN ICSOOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
  620. INNER JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  621. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  622. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  623. GROUP BY inv.AmountEnable,y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,x.PickID,con.Enable,conStock.Enable
  624. ,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, ''),
  625. 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
  626. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  627. 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
  628. DROP TABLE #TempERP
  629. DROP TABLE #NewTempERP
  630. DROP TABLE #NewDouTempERP"; }
  631. else { sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  632. INTO #NewTempERP
  633. from ICSWareHouseLotInfoLog
  634. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  635. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  636. INTO #NewDouTempERP
  637. from ICSWareHouseLotInfoLog
  638. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  639. 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,
  640. 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
  641. ,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,
  642. 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
  643. INTO #TempERP
  644. FROM #NewTempERP a
  645. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  646. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  647. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  648. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  649. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  650. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  651. INNER JOIN ICSOOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
  652. INNER JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  653. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  654. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  655. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  656. GROUP BY conWhCode.Enable,inv.AmountEnable,y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,x.PickID,con.Enable,conStock.Enable
  657. ,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, ''),
  658. 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
  659. UNION ALL
  660. 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,
  661. 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
  662. ,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,
  663. 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
  664. FROM #NewDouTempERP a
  665. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  666. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  667. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  668. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  669. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  670. INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint
  671. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  672. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  673. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  674. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  675. 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
  676. ,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, ''),
  677. 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, '')
  678. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  679. 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
  680. DROP TABLE #TempERP
  681. DROP TABLE #NewTempERP
  682. DROP TABLE #NewDouTempERP"; }
  683. }
  684. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  685. {
  686. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  687. INTO #NewTempERP
  688. from ICSWareHouseLotInfoLog
  689. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  690. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  691. INTO #NewDouTempERP
  692. from ICSWareHouseLotInfoLog
  693. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  694. SELECT a.ToWarehouseCode+isnull(z.ApplyCode,zz.ApplyCode)+a.MUSER AS Costre,'' AS DepCode,a.ToWarehouseCode AS WarehouseCode,isnull(z.ApplyCode,zz.ApplyCode)as ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,isnull(z.ApplyCode,zz.ApplyCode),isnull(z.ApplyDetailID,zz.ApplyDetailID),a.InvCode) AS Sequence,
  695. 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(z.ApplyDetailID,zz.ApplyDetailID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  696. ,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,
  697. 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
  698. ,isnull(z.ApplyID ,zz.ApplyID) as ApplyID
  699. INTO #TempERP
  700. FROM #NewTempERP a
  701. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  702. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  703. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  704. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  705. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  706. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  707. left JOIN ICSOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint
  708. left JOIN ICSOApply zz ON c.ID=zz.ApplyDetailID AND c.WorkPoint=zz.WorkPoint
  709. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  710. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  711. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  712. GROUP BY z.ApplyID ,zz.ApplyID,conWhCode.Enable,inv.AmountEnable,a.ToWarehouseCode,z.ApplyCode,zz.ApplyCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,z.ApplyDetailID,con.Enable,conStock.Enable,zz.ApplyDetailID
  713. ,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, ''),
  714. 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, '')
  715. UNION ALL
  716. 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,
  717. 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
  718. ,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,
  719. 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
  720. ,z.ApplyID
  721. FROM #NewDouTempERP a
  722. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  723. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  724. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  725. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  726. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  727. INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  728. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  729. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  730. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  731. GROUP BY conWhCode.Enable,inv.AmountEnable,a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,z.ApplyDetailID,con.Enable,conStock.Enable
  732. ,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, ''),
  733. 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, ''),z.ApplyID
  734. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock,ApplyID as SourceID FROM #TempERP
  735. 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
  736. DROP TABLE #TempERP
  737. DROP TABLE #NewTempERP
  738. DROP TABLE #NewDouTempERP";
  739. }
  740. //根据材料出库单查询上游单据,根据上游单据生成红字材料出库
  741. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  742. {
  743. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  744. INTO #NewTempERP
  745. from ICSWareHouseLotInfoLog
  746. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  747. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  748. INTO #NewDouTempERP
  749. from ICSWareHouseLotInfoLog
  750. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  751. IF EXISTS(select * FROM #NewTempERP a
  752. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  753. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  754. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  755. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  756. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  757. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  758. INNER JOIN ICSOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  759. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  760. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  761. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  762. where m.ApplyDetailID<>null and z.ApplyDetailID=null)
  763. BEGIN
  764. RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
  765. RETURN
  766. END
  767. IF EXISTS(select * FROM #NewDouTempERP a
  768. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  769. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  770. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  771. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  772. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  773. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  774. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  775. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  776. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  777. where m.ApplyDetailID<>null and z.ApplyDetailID=null)
  778. BEGIN
  779. RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
  780. RETURN
  781. END
  782. 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,
  783. 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
  784. ,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,
  785. 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
  786. INTO #TempERP
  787. FROM #NewTempERP a
  788. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  789. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  790. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  791. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  792. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  793. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  794. INNER JOIN ICSOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  795. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  796. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  797. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  798. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  799. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  800. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  801. 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
  802. ,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, ''),
  803. 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, '')
  804. UNION ALL
  805. 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,
  806. 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
  807. ,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,
  808. 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
  809. FROM #NewDouTempERP a
  810. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  811. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  812. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  813. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  814. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  815. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  816. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  817. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  818. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  819. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  820. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  821. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  822. 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
  823. ,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, ''),
  824. 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, '')
  825. IF EXISTS(SELECT Costre FROM #TempERP WHERE SourceType='{0}')
  826. BEGIN
  827. RAISERROR('" + language.GetNameByCode("WMSAPIInfo116") + @"',16,1);
  828. END
  829. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  830. 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
  831. DROP TABLE #TempERP
  832. DROP TABLE #NewTempERP
  833. DROP TABLE #NewDouTempERP";
  834. }
  835. else
  836. {
  837. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  838. }
  839. sql = string.Format(sql, Identification);
  840. log.Debug("退料erpsql:"+sql);
  841. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  842. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  843. string resultStr = "";
  844. if (DBHelper.IsU9())
  845. //resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OutsourcingIssueDoNegativeURL, Inputstr);
  846. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDoNegativeURL, Inputstr);
  847. else
  848. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDoNegativeURL, Inputstr);
  849. Result result = new Result();
  850. result = JsonConvert.DeserializeObject<Result>(resultStr);
  851. if (result.Success)
  852. {
  853. try
  854. {
  855. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  856. foreach (var item in res)
  857. {
  858. JObject jo = (JObject)item;
  859. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  860. foreach (var detail in resdetail)
  861. {
  862. JObject det = (JObject)detail;
  863. 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()
  864. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  865. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  866. det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  867. }
  868. }
  869. //List<ICSERPReturnIssueNEG> negList = JsonConvert.DeserializeObject<List<ICSERPReturnIssueNEG>>(result.Data.ToString());
  870. //foreach (var neg in negList)
  871. //{
  872. // foreach (var detail in neg.details)
  873. // {
  874. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, detail.SourceDetailID, Identification, neg.ID, detail.DetailID, neg.IssueNEGCode, detail.Sequence, cmd);
  875. // }
  876. //}
  877. }
  878. catch (Exception ex)
  879. {
  880. log.Debug(ex.ToString());
  881. log.Debug(resultStr);
  882. }
  883. }
  884. else
  885. {
  886. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  887. }
  888. #endregion
  889. }
  890. catch (Exception)
  891. {
  892. throw;
  893. }
  894. }
  895. #endregion
  896. #region 委外到货
  897. /// <summary>
  898. /// 委外到货接口
  899. /// </summary>
  900. /// <param name="TransType"></param>
  901. /// <param name="Identification"></param>
  902. /// <param name="cmd"></param>
  903. public static void OutsourcingDeliveryNoticeERP(string ODNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  904. {
  905. try
  906. {
  907. #region ERP
  908. 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,
  909. 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
  910. ,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,
  911. 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
  912. INTO #TempERP
  913. FROM ICSODeliveryNotice a
  914. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  915. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  916. INNER JOIN ICSOutsourcingOrder y ON a.OODetailID=y.OODetailID AND a.WorkPoint=y.WorkPoint
  917. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='CompleteVerification003'
  918. WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}'
  919. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,OOCode,MUSER AS [User],SYSDATETIME() AS MTime,CompleteVerification FROM #TempERP
  920. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,OODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  921. FROM #TempERP
  922. DROP TABLE #TempERP";
  923. sql = string.Format(sql, ODNCode, WorkPoint);
  924. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  925. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  926. string resultStr = HTTPHelper.HttpPost("委外到货", ERPUrl.ODeliveryNoticeURL, Inputstr);
  927. Result result = new Result();
  928. result = JsonConvert.DeserializeObject<Result>(resultStr);
  929. if (result.Success)
  930. {
  931. try
  932. {
  933. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  934. foreach (var item in res)
  935. {
  936. JObject jo = (JObject)item;
  937. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  938. foreach (var detail in resdetail)
  939. {
  940. JObject det = (JObject)detail;
  941. string ERPupdate = @"update ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}'
  942. where OODetailID='{4}' AND ODNType='1' AND ODNCode='{5}' and Sequence='{1}'";
  943. ERPupdate = string.Format(ERPupdate, jo["ODNCode"], det["Sequence"], jo["ID"], det["DetailID"], det["OODetailID"], ODNCode);
  944. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  945. {
  946. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  947. }
  948. }
  949. }
  950. }
  951. catch (Exception ex)
  952. {
  953. log.Debug(ex.ToString());
  954. log.Debug(resultStr);
  955. }
  956. }
  957. else
  958. {
  959. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  960. }
  961. #endregion
  962. }
  963. catch (Exception)
  964. {
  965. throw;
  966. }
  967. }
  968. #endregion
  969. #region 委外入库
  970. /// <summary>
  971. /// 委外入库
  972. /// </summary>
  973. /// <param name="TransCode"></param>
  974. /// <param name="TransSequence"></param>
  975. /// <param name="Quantity"></param>
  976. /// <param name="WorkPoint"></param>
  977. /// <param name="cmd"></param>
  978. public static void OutsourcingReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  979. {
  980. try
  981. {
  982. string sql = @"DECLARE @Status VARCHAR(10)
  983. SELECT @Status=c.Status FROM ICSInventoryLot a
  984. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  985. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  986. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  987. IF (@Status IS NULL)
  988. BEGIN
  989. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  990. RETURN
  991. END
  992. ELSE IF (@Status='3')
  993. BEGIN
  994. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  995. RETURN
  996. END
  997. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  998. FROM ICSInventoryLot a
  999. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1000. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1001. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1002. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1003. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1004. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1005. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1006. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn004', c.Quantity,1,1,'')<c.InQuantity)
  1007. BEGIN
  1008. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1009. END
  1010. --
  1011. if EXISTS(select top 10 * from ICSODeliveryNotice a
  1012. inner join ICSOutsourcingOrder b on a.OODetailID = b.OODetailID and a.OODetailID=a.ODNDetailID and a.ooid = a.ODNID)
  1013. BEGIN
  1014. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1015. FROM ICSInventoryLot a
  1016. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1017. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1018. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1019. END
  1020. ";
  1021. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1022. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1023. {
  1024. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  1025. }
  1026. }
  1027. catch (Exception)
  1028. {
  1029. throw;
  1030. }
  1031. }
  1032. public static void OutsourcingReceiveDoc(string LotNo, string Quantity, Decimal BadQty, string InvCode, bool InvIQC, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1033. {
  1034. try
  1035. {
  1036. if (BadQty > 0)
  1037. {
  1038. string insUptSql;
  1039. if (InvIQC)
  1040. {
  1041. //需要检验物料,修改检验合格数量
  1042. insUptSql = string.Format(@"UPDATE ICSInspection SET QualifiedQuantity=QualifiedQuantity-{2},UnqualifiedQuantity=ISNULL(UnqualifiedQuantity,0) + {2},BCCode='LL',BRCode='短装' WHERE LotNo='{0}' AND WorkPoint='{1}'",
  1043. LotNo, WorkPoint, BadQty);
  1044. }
  1045. else
  1046. {
  1047. //免检物料,修改送货单已到货数量
  1048. insUptSql = string.Format(@"UPDATE ICSOASNDetail SET ODNQuantity=ODNQuantity-{2} WHERE LotNo='{0}' AND WorkPoint='{1}'",
  1049. LotNo, WorkPoint, BadQty);
  1050. }
  1051. if (!DBHelper.ExecuteNonQuery(insUptSql, cmd))
  1052. {
  1053. throw new Exception("更新拒收失败");
  1054. }
  1055. }
  1056. string sql = @"DECLARE @Status VARCHAR(10)
  1057. SELECT @Status=c.Status FROM ICSInventoryLot a
  1058. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1059. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1060. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1061. IF (@Status IS NULL)
  1062. BEGIN
  1063. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1064. RETURN
  1065. END
  1066. ELSE IF (@Status='3')
  1067. BEGIN
  1068. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1069. RETURN
  1070. END
  1071. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  1072. FROM ICSInventoryLot a
  1073. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1074. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1075. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1076. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1077. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1078. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1079. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1080. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn004', c.Quantity,1,1,'')<c.InQuantity)
  1081. BEGIN
  1082. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1083. END
  1084. --
  1085. if EXISTS(select top 10 * from ICSODeliveryNotice a
  1086. inner join ICSOutsourcingOrder b on a.OODetailID = b.OODetailID and a.OODetailID=a.ODNDetailID and a.ooid = a.ODNID)
  1087. BEGIN
  1088. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1089. FROM ICSInventoryLot a
  1090. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1091. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1092. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1093. END
  1094. ";
  1095. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1096. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1097. {
  1098. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  1099. }
  1100. }
  1101. catch (Exception)
  1102. {
  1103. throw;
  1104. }
  1105. }
  1106. /// <summary>
  1107. /// 委外入库(奥美)
  1108. /// </summary>
  1109. /// <param name="LotNo"></param>
  1110. /// <param name="Quantity"></param>
  1111. /// <param name="WorkPoint"></param>
  1112. /// <param name="cmd"></param>
  1113. /// <param name="language"></param>
  1114. public static void OutsourcingReceiveAMDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1115. {
  1116. try
  1117. {
  1118. string sql = @"DECLARE @Status VARCHAR(10)
  1119. SELECT @Status=c.Status FROM ICSInventoryLot a
  1120. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1121. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1122. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1123. IF (@Status IS NULL)
  1124. BEGIN
  1125. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1126. RETURN
  1127. END
  1128. ELSE IF (@Status='3')
  1129. BEGIN
  1130. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1131. RETURN
  1132. END
  1133. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  1134. FROM ICSInventoryLot a
  1135. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1136. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1137. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1138. --IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1139. -- INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1140. -- INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1141. -- WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.InQuantity)
  1142. --BEGIN
  1143. -- RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1144. --END";
  1145. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1146. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1147. {
  1148. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  1149. }
  1150. }
  1151. catch (Exception)
  1152. {
  1153. throw;
  1154. }
  1155. }
  1156. /// <summary>
  1157. /// 委外入库接口
  1158. /// </summary>
  1159. /// <param name="TransType"></param>
  1160. /// <param name="Identification"></param>
  1161. /// <param name="cmd"></param>
  1162. public static void OutsourcingReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1163. {
  1164. try
  1165. {
  1166. string outwhcode = "";
  1167. DataTable flag = null;
  1168. string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'";
  1169. flag = DBHelper.SQlReturnData(enablesql, cmd);
  1170. string sql = "";
  1171. //到货指定仓库(批次汇总)
  1172. string Dsql = @"SELECT a.F_itemCode
  1173. FROM Sys_SRM_ItemsDetail a
  1174. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  1175. WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1'";
  1176. Dsql = string.Format(Dsql);
  1177. DataTable dtdao = DBHelper.SQlReturnData(Dsql, cmd);
  1178. if (dtdao.Rows.Count > 0 && dtdao != null)
  1179. {
  1180. sql = @"select a.LotNo,a.WorkPoint,a.InvCode,a.ToWarehouseCode,a.MUSER,a.Quantity,a.TransCode,a.TransSequence,a.Identification,
  1181. 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,
  1182. 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
  1183. INTO #NewTempERP
  1184. from ICSWareHouseLotInfoLog a
  1185. INNER JOIN ICSInventoryLot lot ON lot.LotNo=a.LotNo AND lot.WorkPoint=a.WOrkPoint
  1186. INNER JOIN ICSExtension ext ON ext.ID=lot.ExtensionID AND ext.WorkPoint=lot.WorkPoint
  1187. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1188. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1189. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND a.BusinessCode='{1}'
  1190. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID,TransSequence,TransCode,FromWarehouseCode,isnull(EATTRIBUTE3,'') as EATTRIBUTE3
  1191. INTO #NewDouTempERP
  1192. from ICSWareHouseLotInfoLog
  1193. WHERE Identification='{0}' AND TransType='13' and BusinessCode ='60'
  1194. SELECT
  1195. DISTINCT Identification,c.VenCode+a.ToWarehouseCode+c.OOCode+a.MUSER+CASE WHEN(LEN(f.ODNID)>=20) THEN '' ELSE f.ODNCode END AS Costre,
  1196. --c.OODetailID+CASE WHEN(LEN(f.ODNID)>=20) THEN '' ELSE f.ODNCode END AS Costre2,
  1197. a.TransCode+a.TransSequence+CONVERT(VARCHAR,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.OOCode,c.OODetailID,a.InvCode)) AS Costre2,
  1198. c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.OOCode,CASE WHEN(LEN(f.ODNDetailID)=36) THEN '' ELSE f.ODNCode END AS ODNCode,a.MUSER,CASE WHEN(LEN(f.ODNID)>=20) THEN '' ELSE f.Sequence END AS DNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.OOCode,c.OODetailID,a.InvCode) AS Sequence,a.TransCode,a.TransSequence,
  1199. 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,case when ConErp.enable=1 then f.ODNDetailID else '' end AS ODNDetailID,conWhCode.Enable AS ErpWhCode,conStockneww.Enable AS CompleteVerification
  1200. ,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,
  1201. 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,lot.eattribute10 as Reason
  1202. INTO #TempERP
  1203. FROM #NewTempERP a
  1204. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1205. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1206. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1207. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1208. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND b.TransCode=a.TransCode AND b.TransSequence=a.TransSequence AND a.WorkPoint=b.WorkPoint
  1209. LEFT JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  1210. INNER JOIN ICSODeliveryNotice f ON (g.OASNCode=f.OASNCode or a.TransCode = f.ODNCode) AND a.WorkPoint=f.WorkPoint --AND lot.ExtensionID=f.ExtensionID
  1211. INNER JOIN ICSExtension extd ON f.ExtensionID=extd.ID AND f.WorkPoint=extd.WorkPoint
  1212. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.oocode AND b.TransSequence=c.Sequence AND f.OODetailID=c.OODetailID AND b.WorkPoint=c.WorkPoint
  1213. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1214. INNER JOIN ICSConfiguration conn ON a.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  1215. INNER JOIN ICSConfiguration ConErp ON a.WorkPoint=ConErp.WorkPoint AND ConErp.Code='UploadERP001'
  1216. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
  1217. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose003'
  1218. INNER JOIN ICSConfiguration conStockneww ON a.WorkPoint=conStockneww.WorkPoint AND conStockneww.Code='CompleteVerification005'
  1219. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1220. where ISNULL(extd.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(extd.BatchCode, '') ELSE '' END+'~'+ISNULL(extd.Version, '')+'~'+ISNULL(extd.Brand, '')+'~'+
  1221. ISNULL(extd.cFree1, '')+'~'+ISNULL(extd.cFree2, '')+'~'+ISNULL(extd.cFree3, '')+'~'+ISNULL(extd.cFree4, '')+'~'+ISNULL(extd.cFree5, '')+'~'+ISNULL(extd.cFree6, '')+'~'+ISNULL(extd.cFree7, '')+'~'+ISNULL(extd.cFree8, '')+'~'+ISNULL(extd.cFree9, '')+'~'+ISNULL(extd.cFree10, '')
  1222. =ISNULL(ext.ProjectCode, '')+'~'+CASE WHEN ISNULL(extd.BatchCode, '')!='' AND ((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, '')+'~'+
  1223. 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, '')
  1224. GROUP BY Identification,c.VenCode+a.ToWarehouseCode+c.OOCode+a.MUSER,CASE WHEN(LEN(f.ODNID)>=20) THEN '' ELSE f.ODNCode END,
  1225. c.OODetailID,c.VenCode,a.ToWarehouseCode,c.OOCode,CASE WHEN(LEN(f.ODNDetailID)=36) THEN '' ELSE f.ODNCode END,a.MUSER,CASE WHEN(LEN(f.ODNID)>=20) THEN '' ELSE f.Sequence END,a.TransCode,a.TransSequence,
  1226. a.InvCode,inv.AmountEnable,isnull((c.UnitPrice),0),c.Currency,c.OODetailID,con.Enable,conn.Enable,conStock.Enable,conStocknew.Enable,case when ConErp.enable=1 then f.ODNDetailID else '' end,conWhCode.Enable,conStockneww.Enable
  1227. ,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, ''),
  1228. 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
  1229. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,OOCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,UpdateStock,IsFillClose FROM #TempERP
  1230. SELECT Costre, Costre2,Sequence,DNSequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Amount,OODetailID,ODNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Reason
  1231. FROM #TempERP
  1232. SELECT a.FromWarehouseCode AS WHCode,
  1233. --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,
  1234. c.OODetailID+CASE WHEN(LEN(f.ODNID)>=20) THEN '' ELSE f.ODNCode END AS Costre2,
  1235. a.TransCode,a.TransSequence AS Sequence,a.InvCode,SUM(a.Quantity) as Quantity,SUM((a.Quantity)*(c.Amount/c.Quantity)) AS Amount,
  1236. 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,
  1237. ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,
  1238. ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,
  1239. ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  1240. FROM #NewDouTempERP a
  1241. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1242. INNER JOIN ICSOutsourcingOrder b ON b.OOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  1243. INNER JOIN ICSOOPick c ON c.OODetailID=b.OODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  1244. INNER JOIN ICSExtension ext ON ext.ID=lot.ExtensionID AND ext.WorkPoint=lot.WorkPoint
  1245. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1246. LEFT JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  1247. INNER JOIN ICSODeliveryNotice f ON (g.OASNCode=f.OASNCode or a.TransCode = f.ODNCode) AND a.WorkPoint=f.WorkPoint --AND lot.ExtensionID=f.ExtensionID
  1248. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1249. INNER JOIN #TempERP te ON te.TransSequence=SUBSTRING(a.TransSequence,1,CHARINDEX('~',a.TransSequence)-1)
  1250. 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
  1251. GROUP BY a.EATTRIBUTE3,a.FromWarehouseCode,c.OODetailID,CASE WHEN(LEN(f.ODNID)>=20) THEN '' ELSE f.ODNCode END,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, ''),
  1252. 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
  1253. DROP TABLE #TempERP
  1254. DROP TABLE #NewTempERP
  1255. DROP TABLE #NewDouTempERP";
  1256. }
  1257. else
  1258. {
  1259. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1260. INTO #NewTempERP
  1261. from ICSWareHouseLotInfoLog
  1262. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1263. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID,TransSequence,TransCode,FromWarehouseCode,isnull(EATTRIBUTE3,'') as EATTRIBUTE3
  1264. INTO #NewDouTempERP
  1265. from ICSWareHouseLotInfoLog
  1266. WHERE Identification='{0}' AND TransType='13' and BusinessCode ='60'
  1267. SELECT c.VenCode+a.ToWarehouseCode+c.OOCode+a.MUSER+f.ODNCode AS Costre,
  1268. --a.TransCode+a.TransSequence+CONVERT(VARCHAR,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.OOCode,c.OODetailID,a.InvCode)) AS Costre2,
  1269. c.OODetailID AS Costre2,
  1270. 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,
  1271. 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
  1272. ,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,
  1273. 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
  1274. INTO #TempERP
  1275. FROM #NewTempERP a
  1276. INNER JOIN ICSConfiguration ConErp ON a.WorkPoint=ConErp.WorkPoint AND ConErp.Code='UploadERP002'
  1277. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1278. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1279. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1280. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1281. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1282. --INNER JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  1283. --INNER JOIN ICSODeliveryNotice f ON g.OASNCode=f.OASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  1284. left JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  1285. INNER JOIN ICSODeliveryNotice f ON (g.OASNCode=f.OASNCode or a.TransCode = f.ODNCode) AND a.WorkPoint=f.WorkPoint AND (lot.ExtensionID=f.ExtensionID)
  1286. INNER JOIN ICSOutsourcingOrder c ON b.TransCode = c.OOCode
  1287. AND b.TransSequence = c.Sequence
  1288. AND f.OODetailID = c.OODetailID
  1289. AND b.WorkPoint = c.WorkPoint
  1290. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1291. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  1292. --INNER JOIN ICSConfiguration ConErp ON a.WorkPoint=ConErp.WorkPoint AND ConErp.Code='UploadERP002'
  1293. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
  1294. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose002'
  1295. INNER JOIN ICSConfiguration conStockneww ON a.WorkPoint=conStockneww.WorkPoint AND conStockneww.Code='CompleteVerification005'
  1296. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1297. GROUP BY a.TransCode,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
  1298. ,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, ''),
  1299. 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
  1300. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,OOCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime,
  1301. Enable,UpdateTodoQuantity,CompleteVerification,UpdateStock,IsFillClose FROM #TempERP
  1302. SELECT Costre,Costre2,Sequence,ODNSequence,TransSequence,
  1303. InvCode,Quantity,Amount,OODetailID,ODNDetailID,Currency,UnitPrice,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,
  1304. ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Reason
  1305. FROM #TempERP
  1306. SELECT a.FromWarehouseCode AS WHCode,
  1307. --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,
  1308. c.OODetailID AS Costre2,
  1309. a.TransCode,a.TransSequence AS Sequence,a.InvCode,SUM(a.Quantity) as Quantity,SUM((a.Quantity)*(c.Amount/c.Quantity)) AS Amount,
  1310. 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,
  1311. ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,
  1312. ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,
  1313. ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  1314. FROM #NewDouTempERP a
  1315. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1316. INNER JOIN ICSOutsourcingOrder b ON b.OOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  1317. INNER JOIN ICSOOPick c ON c.OODetailID=b.OODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  1318. INNER JOIN ICSExtension ext ON ext.ID=lot.ExtensionID AND ext.WorkPoint=lot.WorkPoint
  1319. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1320. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1321. INNER JOIN #TempERP te ON te.TransSequence=SUBSTRING(a.TransSequence,1,CHARINDEX('~',a.TransSequence)-1)
  1322. 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
  1323. 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, ''),
  1324. 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
  1325. DROP TABLE #TempERP
  1326. DROP TABLE #NewTempERP
  1327. DROP TABLE #NewDouTempERP";
  1328. }
  1329. #region ERP
  1330. sql = string.Format(sql, Identification, BusinessCode);
  1331. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1332. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "detailss", "Costre2");
  1333. log.Debug("委外入库ERP接口传参:" + Environment.NewLine + Inputstr);
  1334. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocURL, Inputstr);
  1335. log.Debug("委外入库ERP接口返回值:" + Environment.NewLine + resultStr);
  1336. Result result = new Result();
  1337. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1338. if (result.Success)
  1339. {
  1340. try
  1341. {
  1342. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1343. {
  1344. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1345. from ICSWareHouseLotInfoLog
  1346. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  1347. newsql = string.Format(newsql, Identification, BusinessCode);
  1348. DataTable dt = DBHelper.SQlReturnData(newsql, cmd);
  1349. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1350. foreach (var item in res)
  1351. {
  1352. JObject jo = (JObject)item;
  1353. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1354. foreach (var detail in resdetail)
  1355. {
  1356. JObject det = (JObject)detail;
  1357. 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()
  1358. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1359. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1360. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1361. if (det["detailss"] != null)
  1362. {
  1363. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  1364. foreach (var details in resdetails)
  1365. {
  1366. JObject dets = (JObject)details;
  1367. if (dets != null)
  1368. {
  1369. //for (int i = 0; i < dt.Rows.Count; i++)
  1370. //{
  1371. //派纳倒冲排除仓库逻辑
  1372. string whsql = @"SELECT b.F_ItemCode,b.F_ItemName FROM Sys_SRM_Items a
  1373. INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  1374. where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1'";
  1375. whsql = string.Format(whsql);
  1376. DataTable dtt = DBHelper.SQlReturnData(whsql, cmd);
  1377. if (dtt.Rows.Count > 0 && dtt != null)
  1378. {
  1379. bool ifWHExcluded = false;
  1380. foreach (DataRow dr in dtt.Rows)
  1381. {
  1382. if (dr["F_ItemCode"].ToString().Equals(dets["WHCode"].ToString()))
  1383. {
  1384. ifWHExcluded = true;
  1385. }
  1386. }
  1387. if (!ifWHExcluded)
  1388. {
  1389. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(),
  1390. dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  1391. dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(),
  1392. dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(),
  1393. dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["BatchCode"].ToString(), dets["Version"].ToString(),
  1394. dets["Brand"].ToString(), cmd, language);
  1395. }
  1396. //回写已领数量
  1397. sql = @"UPDATE ICSOOPick SET IssueQuantity=Quantity WHERE PickID='{0}' AND WorkPoint='{1}'";
  1398. sql = String.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  1399. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1400. {
  1401. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1402. }
  1403. }
  1404. else
  1405. {
  1406. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(),
  1407. dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  1408. dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(),
  1409. dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(),
  1410. dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["BatchCode"].ToString(), dets["Version"].ToString(),
  1411. dets["Brand"].ToString(), cmd, language);
  1412. //回写已领数量
  1413. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + dets["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1414. sql = String.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  1415. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1416. {
  1417. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1418. }
  1419. }
  1420. //ICSWareHouseLotInfoService.WareHouseLotInfoBack(Identification, "", dt.Rows[i]["LotNo"].ToString(), dets["Quantity"].ToString(),
  1421. //"", dt.Rows[i]["WorkPoint"].ToString(), "", "", cmd, language, "", "", "", "", dets["DCInvCode"].ToString(), dets["WHCode"].ToString());
  1422. //}
  1423. }
  1424. }
  1425. }
  1426. }
  1427. }
  1428. }
  1429. else
  1430. {
  1431. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1432. foreach (var item in res)
  1433. {
  1434. JObject jo = (JObject)item;
  1435. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1436. foreach (var detail in resdetail)
  1437. {
  1438. JObject det = (JObject)detail;
  1439. 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()
  1440. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1441. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1442. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1443. if (det["detailss"] != null)
  1444. {
  1445. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  1446. foreach (var details in resdetails)
  1447. {
  1448. JObject dets = (JObject)details;
  1449. if (dets != null)
  1450. {
  1451. //直接回写
  1452. string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1453. FROM ICSWareHouseLotInfoLog a
  1454. LEFT JOIN ICSOutsourcingOrder b ON a.TransCode=b.OOCode AND a.WorkPoint=b.WorkPoint
  1455. LEFT JOIN ICSOOPick c ON b.OODetailID=c.OODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  1456. WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode='60'";
  1457. ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["DetailID"].ToString(), dets["MRCVCode"].ToString()
  1458. , dets["Sequence"].ToString(), BusinessCode);
  1459. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1460. {
  1461. //throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"委外倒冲回写失败!";
  1462. }
  1463. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, dets["ERPID"].ToString(),
  1464. // dets[" "].ToString(), dets["MRCVCode"].ToString(), dets["Sequence"].ToString(), allcol, cmd, language);
  1465. }
  1466. }
  1467. }
  1468. }
  1469. }
  1470. }
  1471. }
  1472. catch (Exception ex)
  1473. {
  1474. log.Debug(ex.ToString());
  1475. log.Debug(resultStr);
  1476. throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  1477. }
  1478. }
  1479. else
  1480. {
  1481. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1482. }
  1483. #endregion
  1484. }
  1485. catch (Exception)
  1486. {
  1487. throw;
  1488. }
  1489. }
  1490. public static void CreateOOArriveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode, string doctype)
  1491. {
  1492. try
  1493. {
  1494. #region ERP
  1495. string sql = @"
  1496. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1497. INTO #NewTempERP
  1498. from ICSWareHouseLotInfoLog
  1499. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1500. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID,TransSequence,TransCode,FromWarehouseCode
  1501. INTO #NewDouTempERP
  1502. from ICSWareHouseLotInfoLog
  1503. WHERE Identification='{0}' AND TransType='13'
  1504. 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, '')+
  1505. 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,
  1506. 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
  1507. ,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,
  1508. 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
  1509. ,'{2}' as DocTyppe,getdate() as DocDate,c.Sequence as srcDocPOLineNo
  1510. INTO #TempERP
  1511. FROM #NewTempERP a
  1512. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1513. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1514. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1515. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1516. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1517. INNER JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  1518. INNER JOIN ICSODeliveryNotice f ON g.OASNCode=f.OASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  1519. INNER JOIN ICSOutsourcingOrder c ON b.TransCode = c.OOCode
  1520. AND b.TransSequence = c.Sequence
  1521. AND f.OODetailID = c.OODetailID
  1522. AND b.WorkPoint = c.WorkPoint
  1523. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1524. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  1525. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
  1526. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose002'
  1527. INNER JOIN ICSConfiguration conStockneww ON a.WorkPoint=conStockneww.WorkPoint AND conStockneww.Code='CompleteVerification005'
  1528. 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
  1529. ,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, ''),
  1530. 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
  1531. 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
  1532. 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
  1533. FROM #TempERP
  1534. DROP TABLE #TempERP
  1535. DROP TABLE #NewTempERP
  1536. DROP TABLE #NewDouTempERP
  1537. ";
  1538. // select LotNo, WorkPoint, InvCode, ToWarehouseCode, MUSER, Quantity, TransSequence
  1539. //INTO #NewTempERP
  1540. //from ICSWareHouseLotInfoLog
  1541. //WHERE Identification = '{0}' AND ERPUpload = '0' AND BusinessCode = '{1}'
  1542. //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,
  1543. // 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
  1544. // --,a.lotno AS Costre2
  1545. // ,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,
  1546. // 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
  1547. // INTO #TempERP
  1548. // FROM #NewTempERP a
  1549. // INNER JOIN ICSInventoryLot lot ON a.LotNo = lot.LotNo AND a.WorkPoint = lot.WorkPoint
  1550. // INNER JOIN ICSExtension ext ON lot.ExtensionID = ext.ID AND lot.WorkPoint = ext.WorkPoint
  1551. // INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
  1552. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode = invBat.InvCode AND a.ToWarehouseCode = invBat.WHCode AND a.WorkPoint = invBat.WorkPoint
  1553. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
  1554. // INNER JOIN ICSASNDetail g ON a.LotNo = g.LotNo AND a.WorkPoint = g.WorkPoint
  1555. // INNER JOIN ICSDeliveryNotice f ON g.ASNCode = f.ASNCode AND g.WorkPoint = f.WorkPoint AND lot.ExtensionID = f.ExtensionID
  1556. // INNER JOIN ICSPurchaseOrder c ON b.TransCode = c.POCode AND b.TransSequence = c.Sequence AND f.PODetailID = c.PODetailID AND b.WorkPoint = c.WorkPoint
  1557. // INNER JOIN ICSConfiguration con ON con.Code = 'Stock001' AND a.WorkPoint = con.WorkPoint
  1558. // INNER JOIN ICSConfiguration conn ON a.WorkPoint = conn.WorkPoint AND conn.Code = 'Escrow001'
  1559. //INNER JOIN ICSConfiguration conStock ON a.WorkPoint = conStock.WorkPoint AND conStock.Code = 'UpdateStock001'
  1560. //INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint = conStocknew.WorkPoint AND conStocknew.Code = 'FillClose003'
  1561. // GROUP BY--a.LotNo,
  1562. // 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
  1563. // ,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, ''),
  1564. // 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
  1565. // 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
  1566. // SELECT Costre,
  1567. // --Costre2,
  1568. // 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
  1569. // FROM #TempERP
  1570. //SELECT SUM(a.Quantity) AS Quantity--,a.LotNo AS Costre2,a.LotNo,
  1571. // FROM ICSWareHouseLotInfoLog a
  1572. // INNER JOIN ICSInventoryLot lot ON a.LotNo = lot.LotNo AND a.WorkPoint = lot.WorkPoint
  1573. // INNER JOIN ICSExtension ext ON lot.ExtensionID = ext.ID AND lot.WorkPoint = ext.WorkPoint
  1574. // INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
  1575. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode = invBat.InvCode AND a.ToWarehouseCode = invBat.WHCode AND a.WorkPoint = invBat.WorkPoint
  1576. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
  1577. // INNER JOIN ICSASNDetail g ON a.LotNo = g.LotNo AND a.WorkPoint = g.WorkPoint
  1578. // INNER JOIN ICSDeliveryNotice f ON g.ASNCode = f.ASNCode AND g.WorkPoint = f.WorkPoint AND lot.ExtensionID = f.ExtensionID
  1579. // INNER JOIN ICSPurchaseOrder c ON b.TransCode = c.POCode AND b.TransSequence = c.Sequence AND f.PODetailID = c.PODetailID AND b.WorkPoint = c.WorkPoint
  1580. // INNER JOIN #TempERP te ON te.Sequence=a.TransSequence
  1581. // WHERE a.Identification = '{0}' AND ERPUpload = '0' AND BusinessCode = '{1}'
  1582. // --GROUP BY a.LotNo
  1583. // SELECT DISTINCT HasDN FROM #TempERP
  1584. // DROP TABLE #TempERP
  1585. // DROP TABLE #NewTempERP
  1586. sql = string.Format(sql, Identification, BusinessCode, doctype);
  1587. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1588. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1589. //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
  1590. //var IsDNCode = ds.Tables[3];
  1591. //if (IsDNCode == null || IsDNCode.Rows.Count != 1)
  1592. //{
  1593. // throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种!
  1594. //}
  1595. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9CreatePOArrivURL, Inputstr);
  1596. Result result = new Result();
  1597. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1598. if (result.Success)
  1599. {
  1600. try
  1601. {
  1602. //JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1603. //foreach (var item in res)
  1604. //{
  1605. // JObject jo = (JObject)item;
  1606. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1607. // foreach (var detail in resdetail)
  1608. // {
  1609. // JObject det = (JObject)detail;
  1610. // 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()
  1611. // + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1612. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1613. // det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1614. // }
  1615. //}
  1616. }
  1617. catch (Exception ex)
  1618. {
  1619. log.Debug(ex.ToString());
  1620. log.Debug(resultStr);
  1621. }
  1622. }
  1623. else
  1624. {
  1625. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1626. }
  1627. #endregion
  1628. }
  1629. catch (Exception)
  1630. {
  1631. throw;
  1632. }
  1633. }
  1634. #endregion
  1635. #region 委外入库
  1636. /// <summary>
  1637. /// 委外入库
  1638. /// </summary>
  1639. /// <param name="TransCode"></param>
  1640. /// <param name="TransSequence"></param>
  1641. /// <param name="Quantity"></param>
  1642. /// <param name="WorkPoint"></param>
  1643. /// <param name="cmd"></param>
  1644. public static void OutsourcingReceiveRcvDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1645. {
  1646. try
  1647. {
  1648. string sql = @"DECLARE @Status VARCHAR(10)
  1649. SELECT @Status=c.Status FROM ICSInventoryLot a
  1650. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1651. INNER JOIN ICSOutsourcingReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1652. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1653. IF (@Status IS NULL)
  1654. BEGIN
  1655. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1656. RETURN
  1657. END
  1658. ELSE IF (@Status='2')
  1659. BEGIN
  1660. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  1661. RETURN
  1662. END
  1663. UPDATE c SET RcvQuantity=ISNULL(RcvQuantity,0)+'{2}'+ISNULL(d.Quantity, 0)
  1664. FROM ICSInventoryLot a
  1665. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1666. INNER JOIN ICSOutsourcingReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1667. LEFT JOIN ICSInventoryLot d ON d.EATTRIBUTE29=a.LotNo AND d.WorkPoint=a.WorkPoint
  1668. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1669. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1670. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1671. INNER JOIN ICSOutsourcingReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1672. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1673. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn001', c.Quantity,1,1,'')<c.RcvQuantity)
  1674. BEGIN
  1675. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1676. END";
  1677. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1678. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1679. {
  1680. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  1681. }
  1682. }
  1683. catch (Exception)
  1684. {
  1685. throw;
  1686. }
  1687. }
  1688. /// <summary>
  1689. /// 委外入库-入库单接口
  1690. /// </summary>
  1691. /// <param name="TransType"></param>
  1692. /// <param name="Identification"></param>
  1693. /// <param name="cmd"></param>
  1694. public static void OutsourcingReceiveRcvDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode,string UserCode)
  1695. {
  1696. try
  1697. {
  1698. #region ERP开立状态单据审核
  1699. string sql = "";
  1700. string outwhcode = "";
  1701. string pnsql = "";
  1702. string Inputstr = "";
  1703. DataTable flag = null;
  1704. DataTable dt = null;
  1705. string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'";
  1706. flag = DBHelper.SQlReturnData(enablesql, cmd);
  1707. string sqlflag = @"select * from ICSConfiguration ConErp where ConErp.Code='UploadERP001' and conerp.enable = 1 ";
  1708. DataTable dtflag = DBHelper.SQlReturnData(sqlflag, cmd);
  1709. if (dtflag.Rows.Count > 0 && dtflag != null)
  1710. {
  1711. sql = @"
  1712. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1713. INTO #NewTempERP
  1714. from ICSWareHouseLotInfoLog
  1715. WHERE Identification='{0}' AND ERPUpload='0'
  1716. 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
  1717. INTO #TempERP
  1718. FROM #NewTempERP a
  1719. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1720. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1721. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1722. GROUP BY b.RCVID,b.RCVDetailID,b.Sequence,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1723. SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP
  1724. select Costre,DNSequence,DNDetailID from #TempERP
  1725. DROP TABLE #TempERP
  1726. DROP TABLE #NewTempERP";
  1727. sql = string.Format(sql, Identification);
  1728. string checksql = @"select distinct b.Quantity AS SUMQty,b.RCVQuantity AS ISSQty,a.transCode,a.transSequence,b.RCVID from ICSOutsourcingReceive b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.RCVCode AND b.Sequence=a.TransSequence AND a.WorkPoint=b.WorkPoint
  1729. where a.Identification='{0}' GROUP BY a.transCode,b.Quantity,b.RCVQuantity,a.transSequence,b.RCVID";
  1730. checksql = string.Format(checksql, Identification);
  1731. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  1732. for (int i = 0; i < chekdt.Rows.Count; i++)
  1733. {
  1734. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[i]["SUMQty"]);
  1735. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[i]["ISSQty"]);
  1736. string trancode = chekdt.Rows[i]["transCode"].ToString();
  1737. string transSequence = chekdt.Rows[i]["transSequence"].ToString();
  1738. if (SUMQty - ISSQty == 0)
  1739. {
  1740. if (DBHelper.IsPNU9())
  1741. {
  1742. pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1743. INTO #NewTempERP
  1744. from ICSWareHouseLotInfoLog
  1745. WHERE TransCode='{0}' and TransSequence='{1}' AND ERPUpload='0' and EATTRIBUTE1<>'1'
  1746. 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
  1747. INTO #TempERP
  1748. FROM #NewTempERP a
  1749. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1750. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1751. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1752. GROUP BY b.RCVID,b.RCVDetailID,b.Sequence,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1753. SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP
  1754. select Costre,DNSequence,DNDetailID from #TempERP
  1755. DROP TABLE #TempERP
  1756. DROP TABLE #NewTempERP";
  1757. pnsql = string.Format(pnsql, trancode, transSequence, UserCode);
  1758. }
  1759. else
  1760. {
  1761. pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1762. INTO #NewTempERP
  1763. from ICSWareHouseLotInfoLog
  1764. WHERE TransCode='{0}' AND ISNULL(EATTRIBUTE1, 0)<>'1' and TransSequence='{1}' AND ERPUpload='0'
  1765. 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
  1766. INTO #TempERP
  1767. FROM #NewTempERP a
  1768. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1769. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1770. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1771. GROUP BY b.RCVID,b.RCVDetailID,b.Sequence,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1772. SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP
  1773. select distinct Costre,DNSequence,DNDetailID from #TempERP
  1774. DROP TABLE #TempERP
  1775. DROP TABLE #NewTempERP";
  1776. pnsql = string.Format(pnsql, trancode, transSequence, UserCode);
  1777. }
  1778. DataSet ds = DBHelper.SQlReturnDataSet(pnsql, cmd);
  1779. Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1780. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9DeliveryNoticeURL, Inputstr);
  1781. Result result = new Result();
  1782. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1783. if (result.Success)
  1784. {
  1785. try
  1786. {
  1787. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1788. {
  1789. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1790. from ICSWareHouseLotInfoLog
  1791. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  1792. newsql = string.Format(newsql, Identification, BusinessCode);
  1793. DataTable dtnew = DBHelper.SQlReturnData(newsql, cmd);
  1794. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1795. foreach (var item in res)
  1796. {
  1797. JObject jo = (JObject)item;
  1798. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, jo["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1799. //派纳倒冲排除仓库逻辑
  1800. string whsql = @"SELECT b.F_ItemCode,b.F_ItemName FROM Sys_SRM_Items a
  1801. INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  1802. where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1' and b.F_ItemCode='{0}'";
  1803. whsql = string.Format(whsql, jo["WHCode"].ToString());
  1804. DataTable dtt = DBHelper.SQlReturnData(whsql, cmd);
  1805. if (dtt.Rows.Count > 0 && dtt != null)
  1806. {
  1807. //if (!jo["WHCode"].ToString().Equals(dtt.Rows[0]["F_ItemCode"].ToString()))
  1808. //{
  1809. // //倒冲
  1810. // ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(),
  1811. // jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(),
  1812. // jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(),
  1813. // jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(),
  1814. // jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(),
  1815. // jo["Brand"].ToString(), cmd, language);
  1816. //}
  1817. //回写已领数量
  1818. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1819. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  1820. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1821. {
  1822. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1823. }
  1824. //for (int i = 0; i < dtt.Rows.Count; i++)
  1825. //{
  1826. // if (outwhcode == "")
  1827. // {
  1828. // outwhcode += "" + dtt.Rows[i]["F_ItemCode"].ToString() + "";
  1829. // }
  1830. // else
  1831. // {
  1832. // outwhcode += "," + dtt.Rows[i]["F_ItemCode"].ToString() + "";
  1833. // }
  1834. //}
  1835. }
  1836. else
  1837. {
  1838. //倒冲
  1839. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(),
  1840. jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(),
  1841. jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(),
  1842. jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(),
  1843. jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(),
  1844. jo["Brand"].ToString(), cmd, language);
  1845. //回写已领数量
  1846. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1847. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  1848. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1849. {
  1850. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1851. }
  1852. }
  1853. }
  1854. }
  1855. else
  1856. {
  1857. //foreach (DataRow dr in dt.Rows)
  1858. //{
  1859. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1860. //}
  1861. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, chekdt.Rows[i]["RCVID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1862. }
  1863. }
  1864. catch (Exception ex)
  1865. {
  1866. log.Debug(ex.ToString());
  1867. log.Debug(resultStr);
  1868. }
  1869. }
  1870. else
  1871. {
  1872. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1873. }
  1874. }
  1875. }
  1876. }
  1877. else
  1878. {
  1879. sql = @"
  1880. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1881. INTO #NewTempERP
  1882. from ICSWareHouseLotInfoLog
  1883. WHERE Identification='{0}' AND ISNULL(EATTRIBUTE1, 0)<>'1' AND ERPUpload='0'
  1884. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1885. FROM #NewTempERP a
  1886. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1887. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1888. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1889. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1890. DROP TABLE #NewTempERP";
  1891. sql = string.Format(sql, Identification);
  1892. dt = DBHelper.SQlReturnData(sql, cmd);
  1893. Inputstr = JsonConvert.SerializeObject(dt);
  1894. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9DeliveryNoticeURL, Inputstr);
  1895. Result result = new Result();
  1896. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1897. if (result.Success)
  1898. {
  1899. try
  1900. {
  1901. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1902. {
  1903. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1904. from ICSWareHouseLotInfoLog
  1905. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  1906. newsql = string.Format(newsql, Identification, BusinessCode);
  1907. DataTable dtnew = DBHelper.SQlReturnData(newsql, cmd);
  1908. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1909. foreach (var item in res)
  1910. {
  1911. JObject jo = (JObject)item;
  1912. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, jo["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1913. //派纳倒冲排除仓库逻辑
  1914. string whsql = @"SELECT b.F_ItemCode,b.F_ItemName FROM Sys_SRM_Items a
  1915. INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  1916. where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1'";
  1917. whsql = string.Format(whsql);
  1918. DataTable dtt = DBHelper.SQlReturnData(whsql, cmd);
  1919. if (dtt.Rows.Count > 0 && dtt != null)
  1920. {
  1921. if (!jo["WHCode"].ToString().Equals(dtt.Rows[0]["F_ItemCode"].ToString()))
  1922. {
  1923. //倒冲
  1924. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(),
  1925. jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(),
  1926. jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(),
  1927. jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(),
  1928. jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(),
  1929. jo["Brand"].ToString(), cmd, language);
  1930. }
  1931. //回写已领数量
  1932. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1933. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  1934. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1935. {
  1936. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1937. }
  1938. //for (int i = 0; i < dtt.Rows.Count; i++)
  1939. //{
  1940. // if (outwhcode == "")
  1941. // {
  1942. // outwhcode += "" + dtt.Rows[i]["F_ItemCode"].ToString() + "";
  1943. // }
  1944. // else
  1945. // {
  1946. // outwhcode += "," + dtt.Rows[i]["F_ItemCode"].ToString() + "";
  1947. // }
  1948. //}
  1949. }
  1950. else
  1951. {
  1952. //倒冲
  1953. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(),
  1954. jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(),
  1955. jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(),
  1956. jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(),
  1957. jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(),
  1958. jo["Brand"].ToString(), cmd, language);
  1959. //回写已领数量
  1960. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1961. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  1962. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1963. {
  1964. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1965. }
  1966. }
  1967. }
  1968. }
  1969. else
  1970. {
  1971. foreach (DataRow dr in dt.Rows)
  1972. {
  1973. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1974. }
  1975. }
  1976. }
  1977. catch (Exception ex)
  1978. {
  1979. log.Debug(ex.ToString());
  1980. log.Debug(resultStr);
  1981. }
  1982. }
  1983. else
  1984. {
  1985. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1986. }
  1987. }
  1988. // string sql = @"
  1989. //select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1990. //INTO #NewTempERP
  1991. //from ICSWareHouseLotInfoLog
  1992. // WHERE Identification='{0}' AND ERPUpload='0'
  1993. // SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1994. // FROM #NewTempERP a
  1995. // INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1996. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1997. // INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1998. // GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1999. //DROP TABLE #NewTempERP";
  2000. // sql = string.Format(sql, Identification);
  2001. // DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2002. // string Inputstr = JsonConvert.SerializeObject(dt);
  2003. #endregion
  2004. }
  2005. catch (Exception)
  2006. {
  2007. throw;
  2008. }
  2009. }
  2010. /// <summary>
  2011. /// 鑫隽渊委外收货提交ERP接口
  2012. /// </summary>
  2013. /// <param name="TransType"></param>
  2014. /// <param name="Identification"></param>
  2015. /// <param name="cmd"></param>
  2016. /// <param name="language"></param>
  2017. /// <param name="BusinessCode"></param>
  2018. /// <param name="UserCode"></param>
  2019. public static void OutsourcingReceiveRcvXJYDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode, string UserCode)
  2020. {
  2021. try
  2022. {
  2023. #region ERP开立状态单据审核
  2024. string sql = "";
  2025. string outwhcode = "";
  2026. string pnsql = "";
  2027. string Inputstr = "";
  2028. DataTable flag = null;
  2029. DataTable dt = null;
  2030. string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'";
  2031. flag = DBHelper.SQlReturnData(enablesql, cmd);
  2032. string sqlflag = @"select * from ICSConfiguration ConErp where ConErp.Code='UploadERP001' and conerp.enable = 1 ";
  2033. DataTable dtflag = DBHelper.SQlReturnData(sqlflag, cmd);
  2034. if (dtflag != null && dtflag.Rows.Count > 0)
  2035. {
  2036. sql = @"
  2037. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  2038. INTO #NewTempERP
  2039. from ICSWareHouseLotInfoLog
  2040. WHERE Identification='{0}' AND ISNULL(EATTRIBUTE1, 0)<>'1' AND ERPUpload='0'
  2041. SELECT b.RCVID+b.Sequence+b.RCVDetailID AS Costre,b.RCVID AS ID,b.RCVDetailID AS DNDetailID,b.Sequence AS DNSequence,'{1}' AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint,a.Quantity
  2042. INTO #TempERP
  2043. FROM #NewTempERP a
  2044. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2045. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2046. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  2047. SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP
  2048. select distinct Costre,DNSequence,DNDetailID,SUM(Quantity) AS Quantity
  2049. from #TempERP
  2050. GROUP BY Costre,DNSequence,DNDetailID
  2051. DROP TABLE #TempERP
  2052. DROP TABLE #NewTempERP";
  2053. sql = string.Format(sql, Identification, UserCode);
  2054. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2055. Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2056. log.Info("鑫隽渊委外收货ERP传参" + Environment.NewLine + Inputstr);
  2057. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9DeliveryNoticeSplitURL, Inputstr);
  2058. log.Info("鑫隽渊委外收货ERP接口返回值" + Environment.NewLine + resultStr);
  2059. Result result = new Result();
  2060. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2061. if (result.Success)
  2062. {
  2063. try
  2064. {
  2065. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  2066. {
  2067. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  2068. from ICSWareHouseLotInfoLog
  2069. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  2070. newsql = string.Format(newsql, Identification, BusinessCode);
  2071. DataTable dtnew = DBHelper.SQlReturnData(newsql, cmd);
  2072. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2073. foreach (var item in res)
  2074. {
  2075. JObject jo = (JObject)item;
  2076. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, jo["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2077. //派纳倒冲排除仓库逻辑
  2078. string whsql = @"SELECT b.F_ItemCode,b.F_ItemName FROM Sys_SRM_Items a
  2079. INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  2080. where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1' and b.F_ItemCode='{0}'";
  2081. whsql = string.Format(whsql, jo["WHCode"].ToString());
  2082. DataTable dtt = DBHelper.SQlReturnData(whsql, cmd);
  2083. if (dtt.Rows.Count > 0 && dtt != null)
  2084. {
  2085. //回写已领数量
  2086. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  2087. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  2088. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2089. {
  2090. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  2091. }
  2092. }
  2093. else
  2094. {
  2095. //倒冲
  2096. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(),
  2097. jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(),
  2098. jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(),
  2099. jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(),
  2100. jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(),
  2101. jo["Brand"].ToString(), cmd, language);
  2102. //回写已领数量
  2103. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  2104. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  2105. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2106. {
  2107. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  2108. }
  2109. }
  2110. }
  2111. }
  2112. else
  2113. {
  2114. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, ds.Tables[0].Rows[0]["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2115. }
  2116. }
  2117. catch (Exception ex)
  2118. {
  2119. log.Debug(ex.ToString());
  2120. log.Debug(resultStr);
  2121. }
  2122. }
  2123. else
  2124. {
  2125. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2126. }
  2127. }
  2128. else
  2129. {
  2130. sql = @"
  2131. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  2132. INTO #NewTempERP
  2133. from ICSWareHouseLotInfoLog
  2134. WHERE Identification='{0}' AND ERPUpload='0'
  2135. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2136. FROM #NewTempERP a
  2137. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2138. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2139. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  2140. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2141. DROP TABLE #NewTempERP";
  2142. sql = string.Format(sql, Identification);
  2143. dt = DBHelper.SQlReturnData(sql, cmd);
  2144. Inputstr = JsonConvert.SerializeObject(dt);
  2145. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9DeliveryNoticeURL, Inputstr);
  2146. Result result = new Result();
  2147. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2148. if (result.Success)
  2149. {
  2150. try
  2151. {
  2152. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  2153. {
  2154. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  2155. from ICSWareHouseLotInfoLog
  2156. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  2157. newsql = string.Format(newsql, Identification, BusinessCode);
  2158. DataTable dtnew = DBHelper.SQlReturnData(newsql, cmd);
  2159. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2160. foreach (var item in res)
  2161. {
  2162. JObject jo = (JObject)item;
  2163. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, jo["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2164. //派纳倒冲排除仓库逻辑
  2165. string whsql = @"SELECT b.F_ItemCode,b.F_ItemName FROM Sys_SRM_Items a
  2166. INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  2167. where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1'";
  2168. whsql = string.Format(whsql);
  2169. DataTable dtt = DBHelper.SQlReturnData(whsql, cmd);
  2170. if (dtt.Rows.Count > 0 && dtt != null)
  2171. {
  2172. if (!jo["WHCode"].ToString().Equals(dtt.Rows[0]["F_ItemCode"].ToString()))
  2173. {
  2174. //倒冲
  2175. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(),
  2176. jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(),
  2177. jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(),
  2178. jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(),
  2179. jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(),
  2180. jo["Brand"].ToString(), cmd, language);
  2181. }
  2182. //回写已领数量
  2183. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  2184. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  2185. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2186. {
  2187. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  2188. }
  2189. }
  2190. else
  2191. {
  2192. //倒冲
  2193. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(),
  2194. jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(),
  2195. jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(),
  2196. jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(),
  2197. jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(),
  2198. jo["Brand"].ToString(), cmd, language);
  2199. //回写已领数量
  2200. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  2201. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  2202. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2203. {
  2204. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  2205. }
  2206. }
  2207. }
  2208. }
  2209. else
  2210. {
  2211. foreach (DataRow dr in dt.Rows)
  2212. {
  2213. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2214. }
  2215. }
  2216. }
  2217. catch (Exception ex)
  2218. {
  2219. log.Debug(ex.ToString());
  2220. log.Debug(resultStr);
  2221. }
  2222. }
  2223. else
  2224. {
  2225. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2226. }
  2227. }
  2228. #endregion
  2229. }
  2230. catch (Exception)
  2231. {
  2232. throw;
  2233. }
  2234. }
  2235. #endregion
  2236. #region 审核的委外到货单
  2237. /// <summary>
  2238. /// 审核的委外到货单
  2239. /// </summary>
  2240. /// <param name="TransCode"></param>
  2241. /// <param name="TransSequence"></param>
  2242. /// <param name="Quantity"></param>
  2243. /// <param name="WorkPoint"></param>
  2244. /// <param name="cmd"></param>
  2245. public static void ODeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2246. {
  2247. try
  2248. {
  2249. string sql = @"DECLARE @Status VARCHAR(10)
  2250. SELECT @Status=c.Status FROM ICSInventoryLot a
  2251. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2252. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2253. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  2254. IF (@Status IS NULL)
  2255. BEGIN
  2256. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2257. RETURN
  2258. END
  2259. ELSE IF (@Status='3')
  2260. BEGIN
  2261. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  2262. RETURN
  2263. END
  2264. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  2265. FROM ICSInventoryLot a
  2266. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2267. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2268. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  2269. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2270. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2271. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2272. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  2273. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn005', c.Quantity,1,1,'')<c.RCVQuantity)
  2274. BEGIN
  2275. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  2276. END";
  2277. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2278. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2279. {
  2280. throw new Exception(language.GetNameByCode("WMSAPIInfo117"));//"委外到货单更新失败!");
  2281. }
  2282. }
  2283. catch (Exception)
  2284. {
  2285. throw;
  2286. }
  2287. }
  2288. /// <summary>
  2289. /// 审核的委外到货单接口
  2290. /// </summary>
  2291. /// <param name="TransType"></param>
  2292. /// <param name="Identification"></param>
  2293. /// <param name="cmd"></param>
  2294. public static void ODeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  2295. {
  2296. try
  2297. {
  2298. DataTable flag = null;
  2299. string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'";
  2300. flag = DBHelper.SQlReturnData(enablesql, cmd);
  2301. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  2302. {
  2303. //校验库存数量是否满足子件计划数量(倒冲)
  2304. string logsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,ToLocationCode,TransCode,TransSequence
  2305. from ICSWareHouseLotInfoLog
  2306. WHERE Identification = '{0}' AND ERPUpload = '0'";
  2307. logsql = string.Format(logsql, Identification);
  2308. DataTable logdt = DBHelper.SQlReturnData(logsql, cmd);
  2309. if (logdt.Rows.Count > 0 && logdt != null)
  2310. {
  2311. for (int i = 0; i < logdt.Rows.Count; i++)
  2312. {
  2313. ICSWareHouseLotInfoService.WareHouseLotInfoBackOutBefore(Identification, logdt.Rows[i]["ToLocationCode"].ToString(), logdt.Rows[i]["LotNo"].ToString(), logdt.Rows[i]["Quantity"].ToString(),
  2314. logdt.Rows[i]["MUSER"].ToString(), logdt.Rows[i]["WorkPoint"].ToString(), "2", BusinessCode, cmd, language, "", "", logdt.Rows[i]["TransCode"].ToString(), logdt.Rows[i]["TransSequence"].ToString());
  2315. }
  2316. }
  2317. }
  2318. #region ERP
  2319. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  2320. INTO #NewTempERP
  2321. from ICSWareHouseLotInfoLog
  2322. WHERE Identification='{0}' AND ERPUpload='0'
  2323. 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,
  2324. 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
  2325. ,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,
  2326. 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
  2327. ,c.ODNID
  2328. INTO #TempERP
  2329. FROM #NewTempERP a
  2330. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2331. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2332. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2333. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2334. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2335. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2336. inner join ICSOutsourcingOrder d on c.OODetailID=d.OODetailID and c.WorkPoint=d.WorkPoint
  2337. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2338. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  2339. 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
  2340. ,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, ''),
  2341. 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, '')
  2342. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNID,ODNCode,OOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  2343. 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
  2344. FROM #TempERP
  2345. DROP TABLE #TempERP
  2346. DROP TABLE #NewTempERP";
  2347. sql = string.Format(sql, Identification,BusinessCode);
  2348. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2349. log.Debug(sql);
  2350. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2351. log.Debug(Inputstr);
  2352. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ODeliveryNoticeInURL, Inputstr);
  2353. Result result = new Result();
  2354. log.Debug(resultStr);
  2355. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2356. if (result.Success)
  2357. {
  2358. try
  2359. {
  2360. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  2361. {
  2362. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  2363. from ICSWareHouseLotInfoLog
  2364. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  2365. newsql = string.Format(newsql, Identification, BusinessCode);
  2366. DataTable dt = DBHelper.SQlReturnData(newsql, cmd);
  2367. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2368. foreach (var item in res)
  2369. {
  2370. JObject jo = (JObject)item;
  2371. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2372. foreach (var detail in resdetail)
  2373. {
  2374. JObject det = (JObject)detail;
  2375. 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()
  2376. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2377. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  2378. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2379. if (det["detailss"] != null)
  2380. {
  2381. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  2382. foreach (var details in resdetails)
  2383. {
  2384. JObject dets = (JObject)details;
  2385. if (dets != null)
  2386. {
  2387. //for (int i = 0; i < dt.Rows.Count; i++)
  2388. //{
  2389. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(),
  2390. dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  2391. dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(),
  2392. dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(),
  2393. dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["BatchCode"].ToString(), dets["Version"].ToString(),
  2394. dets["Brand"].ToString(), cmd, language);
  2395. //回写已领数量
  2396. sql = @"select pickid from ICSOOPick WHERE PickID='{0}' AND WorkPoint='{1}'";
  2397. sql = string.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  2398. DataTable ssdt = DBHelper.SQlReturnData(sql, cmd);
  2399. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + dets["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  2400. sql = string.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  2401. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2402. {
  2403. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  2404. }
  2405. //ICSWareHouseLotInfoService.WareHouseLotInfoBack(Identification, "", "", dets["Quantity"].ToString(),
  2406. //dt.Rows[0]["MUSER"].ToString(), "", "", BusinessCode, cmd, language, "", "", "", "", dets["DCInvCode"].ToString(), dets["WHCode"].ToString());
  2407. //}
  2408. }
  2409. }
  2410. }
  2411. }
  2412. }
  2413. }
  2414. else
  2415. {
  2416. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2417. foreach (var item in res)
  2418. {
  2419. JObject jo = (JObject)item;
  2420. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2421. foreach (var detail in resdetail)
  2422. {
  2423. JObject det = (JObject)detail;
  2424. 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()
  2425. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2426. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2427. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2428. }
  2429. }
  2430. }
  2431. }
  2432. catch (Exception ex)
  2433. {
  2434. log.Debug(ex.ToString());
  2435. log.Debug(resultStr);
  2436. throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  2437. }
  2438. }
  2439. else
  2440. {
  2441. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2442. }
  2443. #endregion
  2444. }
  2445. catch (Exception)
  2446. {
  2447. throw;
  2448. }
  2449. }
  2450. #endregion
  2451. #region 委外拒收
  2452. /// <summary>
  2453. /// 委外拒收
  2454. /// </summary>
  2455. /// <param name="TransCode"></param>
  2456. /// <param name="TransSequence"></param>
  2457. /// <param name="Quantity"></param>
  2458. /// <param name="WorkPoint"></param>
  2459. /// <param name="cmd"></param>
  2460. public static void OutsourcingRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2461. {
  2462. try
  2463. {
  2464. string sql = @"DECLARE @Status VARCHAR(10)
  2465. SELECT @Status=c.Status FROM ICSInventoryLot a
  2466. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2467. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2468. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  2469. IF (@Status IS NULL)
  2470. BEGIN
  2471. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2472. RETURN
  2473. END
  2474. ELSE IF (@Status='3')
  2475. BEGIN
  2476. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  2477. RETURN
  2478. END
  2479. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  2480. FROM ICSInventoryLot a
  2481. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2482. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2483. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  2484. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2485. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2486. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2487. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  2488. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn006', c.Quantity,1,1,'')<c.RCVQuantity)
  2489. BEGIN
  2490. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  2491. END";
  2492. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2493. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2494. {
  2495. throw new Exception(language.GetNameByCode("WMSAPIInfo118"));//"委外拒收单更新失败!");
  2496. }
  2497. }
  2498. catch (Exception)
  2499. {
  2500. throw;
  2501. }
  2502. }
  2503. /// <summary>
  2504. /// 委外拒收接口
  2505. /// </summary>
  2506. /// <param name="TransType"></param>
  2507. /// <param name="Identification"></param>
  2508. /// <param name="cmd"></param>
  2509. public static void OutsourcingRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  2510. {
  2511. // try
  2512. // {
  2513. // #region ERP
  2514. // 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,
  2515. // a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.ODNDetailID,Enable AS UpdateTodoQuantity
  2516. // ,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,
  2517. // 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
  2518. // INTO #TempERP
  2519. // FROM ICSWareHouseLotInfoLog a
  2520. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2521. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2522. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2523. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2524. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2525. // INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2526. // INNER JOIN ICSODeliveryNotice d ON c.OODetailID=d.ODNDetailID AND d.WorkPoint=c.WorkPoint
  2527. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2528. // WHERE a.Identification='{0}' AND ERPUpload='0'
  2529. // 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
  2530. // ,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, ''),
  2531. // 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, '')
  2532. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,ODNCode AS DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint FROM #TempERP
  2533. //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
  2534. // FROM #TempERP
  2535. // DROP TABLE #TempERP";
  2536. // sql = string.Format(sql, Identification);
  2537. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2538. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  2539. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateWPuArrivalVouchURL, Inputstr);
  2540. // Result result = new Result();
  2541. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  2542. // if (result.Success)
  2543. // {
  2544. // try
  2545. // {
  2546. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2547. // foreach (var item in res)
  2548. // {
  2549. // JObject jo = (JObject)item;
  2550. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2551. // foreach (var detail in resdetail)
  2552. // {
  2553. // JObject det = (JObject)detail;
  2554. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["OODetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  2555. // }
  2556. // }
  2557. // }
  2558. // catch (Exception ex)
  2559. // {
  2560. // log.Debug(ex.ToString());
  2561. // log.Debug(resultStr);
  2562. // }
  2563. // }
  2564. // else
  2565. // {
  2566. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2567. // }
  2568. // #endregion
  2569. // }
  2570. // catch (Exception)
  2571. // {
  2572. // throw;
  2573. // }
  2574. }
  2575. /// <summary>
  2576. /// 委外拒收接口
  2577. /// </summary>
  2578. /// <param name="TransType"></param>
  2579. /// <param name="Identification"></param>
  2580. /// <param name="cmd"></param>
  2581. public static void OutsourcingRejectDocInNewERP(string ODNCode, string OJDNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2582. {
  2583. try
  2584. {
  2585. #region ERP
  2586. string sql = @"SELECT a.VenCode+a.DepCode+x.ODNCode+a.MUSER AS Costre,a.VenCode,a.DepCode,x.ODNCode,a.MUSER,a.MTIME,
  2587. 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
  2588. ,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,
  2589. 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
  2590. INTO #TempERP
  2591. FROM ICSODeliveryNotice a
  2592. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2593. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  2594. INNER JOIN ICSODeliveryNotice x ON x.ODNDetailID=a.OODetailID AND a.WorkPoint=x.WorkPoint
  2595. WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}'
  2596. 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,
  2597. a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(invBat.BatchEnable, ''),ISNULL(ext.BatchCode, ''),ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  2598. 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, '')
  2599. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  2600. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,ODNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  2601. FROM #TempERP
  2602. DROP TABLE #TempERP";
  2603. sql = string.Format(sql, OJDNCode, WorkPoint);
  2604. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2605. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  2606. string resultStr = HTTPHelper.HttpPost("委外拒收", ERPUrl.CreateWPuArrivalVouchURL, Inputstr);
  2607. Result result = new Result();
  2608. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2609. if (result.Success)
  2610. {
  2611. try
  2612. {
  2613. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2614. foreach (var item in res)
  2615. {
  2616. JObject jo = (JObject)item;
  2617. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2618. foreach (var detail in resdetail)
  2619. {
  2620. JObject det = (JObject)detail;
  2621. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RJTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  2622. string ERPupdate = @"update ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}'
  2623. where OODetailID='{4}' AND ODNType='3' AND ODNCode='{5}' ";
  2624. ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], OJDNCode);
  2625. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  2626. {
  2627. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  2628. }
  2629. }
  2630. }
  2631. }
  2632. catch (Exception ex)
  2633. {
  2634. log.Debug(ex.ToString());
  2635. log.Debug(resultStr);
  2636. }
  2637. }
  2638. else
  2639. {
  2640. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2641. }
  2642. #endregion
  2643. }
  2644. catch (Exception)
  2645. {
  2646. throw;
  2647. }
  2648. }
  2649. #endregion
  2650. #region 委外退货
  2651. /// <summary>
  2652. /// 委外退货
  2653. /// </summary>
  2654. /// <param name="TransCode"></param>
  2655. /// <param name="TransSequence"></param>
  2656. /// <param name="Quantity"></param>
  2657. /// <param name="WorkPoint"></param>
  2658. /// <param name="cmd"></param>
  2659. public static void OutsourcingReturnBack(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string TransID)
  2660. {
  2661. try
  2662. {
  2663. string sql = @"DECLARE @Status VARCHAR(10)
  2664. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' AND ODNType='2' AND id='{4}' and WorkPoint='{1}'
  2665. IF (@Status IS NULL)
  2666. BEGIN
  2667. RAISERROR('" + language.GetNameByCode("WMSAPIInfo119") + @"',16,1);
  2668. RETURN
  2669. END
  2670. ELSE IF (@Status!='2')
  2671. BEGIN
  2672. RAISERROR('" + language.GetNameByCode("WMSAPIInfo120") + @"',16,1);
  2673. RETURN
  2674. END
  2675. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  2676. FROM ICSODeliveryNotice a
  2677. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.id='{4}' AND ODNType='2'
  2678. UPDATE b SET Inquantity=ISNULL(b.Inquantity,0)-'{2}'
  2679. FROM ICSOutsourcingOrder b inner join ICSODeliveryNotice a on a.ooID = b.ooID and a.OODetailID = b.OODetailID
  2680. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND ODNType='2'
  2681. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a
  2682. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.id='{4}' AND a.Quantity<a.RCVQuantity AND ODNType='2')
  2683. BEGIN
  2684. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  2685. RETURN
  2686. END
  2687. --退 eattribute4 = ODNDetailID 退
  2688. IF EXISTS(SELECT b.ID FROM ICSODeliveryNotice a inner join ICSODeliveryNotice b on a.eattribute4 = b.ODNDetailID
  2689. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.ODNType='2' AND a.eattribute3='退')
  2690. BEGIN
  2691. UPDATE b SET RCVQuantity=ISNULL(b.RCVQuantity,0)-'{2}'
  2692. FROM ICSODeliveryNotice b inner join ICSODeliveryNotice a on a.eattribute4 = b.ODNDetailID
  2693. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.ODNType='2' AND a.eattribute3='退'
  2694. END
  2695. ";
  2696. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  2697. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2698. {
  2699. throw new Exception(language.GetNameByCode("WMSAPIInfo121"));//"委外退货单更新失败!");
  2700. }
  2701. }
  2702. catch (Exception)
  2703. {
  2704. throw;
  2705. }
  2706. }
  2707. public static void OutsourcingReturnBackOO(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string TransID)
  2708. {
  2709. try
  2710. {
  2711. string sql = @"DECLARE @Status VARCHAR(10)
  2712. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' AND ODNType='1' AND id='{4}' and WorkPoint='{1}'
  2713. IF (@Status IS NULL)
  2714. BEGIN
  2715. RAISERROR('" + language.GetNameByCode("WMSAPIInfo119") + @"',16,1);
  2716. RETURN
  2717. END
  2718. ELSE IF (@Status!='2')
  2719. BEGIN
  2720. RAISERROR('" + language.GetNameByCode("WMSAPIInfo120") + @"',16,1);
  2721. RETURN
  2722. END
  2723. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)-'{2}'
  2724. FROM ICSODeliveryNotice a
  2725. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.id='{4}' AND ODNType='1'
  2726. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a
  2727. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.id='{4}' AND a.RCVQuantity<0 AND ODNType='1')
  2728. BEGIN
  2729. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  2730. RETURN
  2731. END";
  2732. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  2733. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2734. {
  2735. throw new Exception(language.GetNameByCode("WMSAPIInfo121"));//"委外退货单更新失败!");
  2736. }
  2737. }
  2738. catch (Exception)
  2739. {
  2740. throw;
  2741. }
  2742. }
  2743. /// <summary>
  2744. /// 委外退货接口
  2745. /// </summary>
  2746. /// <param name="TransType"></param>
  2747. /// <param name="Identification"></param>
  2748. /// <param name="cmd"></param>
  2749. public static void OutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  2750. {
  2751. try
  2752. {
  2753. #region ERP
  2754. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2755. INTO #NewTempERP
  2756. from ICSWareHouseLotInfoLog
  2757. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  2758. 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,
  2759. 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
  2760. ,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,
  2761. 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
  2762. INTO #TempERP
  2763. FROM #NewTempERP a
  2764. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2765. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2766. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2767. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2768. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  2769. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2770. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  2771. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  2772. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  2773. 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
  2774. ,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, ''),
  2775. 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, '')
  2776. 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
  2777. 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
  2778. FROM #TempERP
  2779. DROP TABLE #TempERP
  2780. DROP TABLE #NewTempERP";
  2781. sql = string.Format(sql, Identification);
  2782. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2783. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2784. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReturnBackURL, Inputstr);
  2785. Result result = new Result();
  2786. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2787. if (result.Success)
  2788. {
  2789. try
  2790. {
  2791. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2792. foreach (var item in res)
  2793. {
  2794. JObject jo = (JObject)item;
  2795. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2796. foreach (var detail in resdetail)
  2797. {
  2798. JObject det = (JObject)detail;
  2799. 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()
  2800. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2801. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2802. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2803. }
  2804. }
  2805. }
  2806. catch (Exception ex)
  2807. {
  2808. log.Debug(ex.ToString());
  2809. log.Debug(resultStr);
  2810. }
  2811. }
  2812. else
  2813. {
  2814. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2815. }
  2816. #endregion
  2817. }
  2818. catch (Exception)
  2819. {
  2820. throw;
  2821. }
  2822. }
  2823. public static string OutsourcingReturnBackOOERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2824. {
  2825. string msg = "";
  2826. try
  2827. {
  2828. #region ERP
  2829. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2830. INTO #NewTempERP
  2831. from ICSWareHouseLotInfoLog
  2832. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  2833. 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,
  2834. 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
  2835. ,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,
  2836. 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
  2837. INTO #TempERP
  2838. FROM #NewTempERP a
  2839. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2840. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2841. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2842. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2843. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  2844. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2845. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  2846. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  2847. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  2848. 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
  2849. ,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, ''),
  2850. 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, '')
  2851. 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
  2852. 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
  2853. FROM #TempERP
  2854. DROP TABLE #TempERP
  2855. DROP TABLE #NewTempERP";
  2856. sql = string.Format(sql, Identification);
  2857. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2858. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2859. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReturnBackOOURL, Inputstr);
  2860. Result result = new Result();
  2861. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2862. if (result.Success)
  2863. {
  2864. log.Debug(resultStr);
  2865. try
  2866. {
  2867. string newsql = @"select LotNo,WorkPoint,InvCode,FromWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  2868. from ICSWareHouseLotInfoLog
  2869. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  2870. newsql = string.Format(newsql, Identification, BusinessCode);
  2871. DataTable dt = DBHelper.SQlReturnData(newsql, cmd);
  2872. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2873. foreach (var item in res)
  2874. {
  2875. JObject jo = (JObject)item;
  2876. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2877. foreach (var detail in resdetail)
  2878. {
  2879. JObject det = (JObject)detail;
  2880. 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()
  2881. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2882. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  2883. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2884. if (det["detailss"] != null)
  2885. {
  2886. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  2887. foreach (var details in resdetails)
  2888. {
  2889. JObject dets = (JObject)details;
  2890. if (dets != null)
  2891. {
  2892. //for (int i = 0; i < dt.Rows.Count; i++)
  2893. //(string Identification,
  2894. //string TransCode, string TransSequence, string InvCode, string WHCode, string Quantity, string User,
  2895. //string WorkPoint, string TransType, string BusinessCode, string ERPID, string ERPDetailID, string ERPCode, string ERPSequence,
  2896. ICSWareHouseLotInfoService.WareHouseLotInfoBackInMF(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(),
  2897. dets["WhCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  2898. dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(),
  2899. dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(),
  2900. dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["cBatch"].ToString(), dets["version"].ToString(),
  2901. dets["brand"].ToString(), dets["PickID"].ToString(), cmd, language);
  2902. //ICSWareHouseLotInfoService.WareHouseLotInfoBack(Identification, "", dt.Rows[i]["LotNo"].ToString(), dets["Quantity"].ToString(),
  2903. //"", dt.Rows[i]["WorkPoint"].ToString(), "", "", cmd, language, "", "", "", "", dets["DCInvCode"].ToString(), dets["WHCode"].ToString());
  2904. //}
  2905. }
  2906. }
  2907. }
  2908. }
  2909. }
  2910. }
  2911. catch (Exception ex)
  2912. {
  2913. log.Debug(ex.ToString());
  2914. log.Debug(resultStr);
  2915. }
  2916. }
  2917. else
  2918. {
  2919. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2920. }
  2921. #endregion
  2922. }
  2923. catch (Exception)
  2924. {
  2925. throw;
  2926. }
  2927. return msg;
  2928. }
  2929. public static void RTOutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2930. {
  2931. try
  2932. {
  2933. #region ERP
  2934. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2935. INTO #NewTempERP
  2936. from ICSWareHouseLotInfoLog
  2937. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  2938. 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,
  2939. 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
  2940. ,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,
  2941. 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
  2942. INTO #TempERP
  2943. FROM #NewTempERP a
  2944. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2945. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2946. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2947. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2948. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  2949. INNER JOIN ICSODeliveryNotice z ON z.Sequence=y.OoDetailID AND z.ODNCode=y.OOID AND a.WorkPoint=y.WorkPoint
  2950. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2951. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  2952. 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
  2953. ,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, ''),
  2954. 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, '')
  2955. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,POCode,'' AS DocType,MUSER AS [User],SYSDATETIME() AS MTime,SYSDATETIME() AS DocDate,SYSDATETIME() AS ArrDate FROM #TempERP
  2956. 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
  2957. FROM #TempERP
  2958. DROP TABLE #TempERP
  2959. DROP TABLE #NewTempERP";
  2960. sql = string.Format(sql, Identification);
  2961. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2962. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2963. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.RTPurchaseReturnBackURL, Inputstr);
  2964. Result result = new Result();
  2965. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2966. if (result.Success)
  2967. {
  2968. try
  2969. {
  2970. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2971. foreach (var item in res)
  2972. {
  2973. JObject jo = (JObject)item;
  2974. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2975. foreach (var detail in resdetail)
  2976. {
  2977. JObject det = (JObject)detail;
  2978. 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()
  2979. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2980. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2981. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2982. }
  2983. }
  2984. }
  2985. catch (Exception ex)
  2986. {
  2987. log.Debug(ex.ToString());
  2988. log.Debug(resultStr);
  2989. }
  2990. }
  2991. else
  2992. {
  2993. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2994. }
  2995. #endregion
  2996. }
  2997. catch (Exception)
  2998. {
  2999. throw;
  3000. }
  3001. }
  3002. public static void U9OutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  3003. {
  3004. try
  3005. {
  3006. #region ERP
  3007. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  3008. INTO #NewTempERP
  3009. from ICSWareHouseLotInfoLog
  3010. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  3011. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  3012. INNER JOIN ICSODeliveryNotice b ON a.TransCode=b.ODNCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  3013. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  3014. BEGIN
  3015. RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',16,1);
  3016. RETURN
  3017. END
  3018. 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,
  3019. 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
  3020. ,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,
  3021. 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
  3022. ,y.Sequence as oSequence INTO #TempERP
  3023. FROM #NewTempERP a
  3024. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3025. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3026. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3027. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3028. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  3029. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  3030. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  3031. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  3032. 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
  3033. ,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, ''),
  3034. 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
  3035. 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
  3036. DROP TABLE #TempERP
  3037. DROP TABLE #NewTempERP";
  3038. sql = string.Format(sql, Identification);
  3039. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  3040. string Inputstr = DataToJsonHelper.ToJson(ds.Tables[0]);
  3041. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OutsourcingReturnBackURL, Inputstr);
  3042. Result result = new Result();
  3043. result = JsonConvert.DeserializeObject<Result>(resultStr);
  3044. if (result.Success)
  3045. {
  3046. try
  3047. {
  3048. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  3049. foreach (var item in res)
  3050. {
  3051. JObject jo = (JObject)item;
  3052. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  3053. foreach (var detail in resdetail)
  3054. {
  3055. JObject det = (JObject)detail;
  3056. 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()
  3057. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  3058. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  3059. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  3060. }
  3061. }
  3062. }
  3063. catch (Exception ex)
  3064. {
  3065. log.Debug(ex.ToString());
  3066. log.Debug(resultStr);
  3067. }
  3068. }
  3069. else
  3070. {
  3071. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  3072. }
  3073. #endregion
  3074. }
  3075. catch (Exception)
  3076. {
  3077. throw;
  3078. }
  3079. }
  3080. #endregion
  3081. #region 开立委外红字入库
  3082. /// <summary>
  3083. /// 开立委外红字入库
  3084. /// </summary>
  3085. /// <param name="TransCode"></param>
  3086. /// <param name="TransSequence"></param>
  3087. /// <param name="Quantity"></param>
  3088. /// <param name="WorkPoint"></param>
  3089. /// <param name="cmd"></param>
  3090. public static void OutsourcingReceiveDocNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string TransID)
  3091. {
  3092. try
  3093. {
  3094. string sql = @"DECLARE @Status VARCHAR(10)
  3095. SELECT @Status=a.Status FROM ICSOutsourcingReceive a
  3096. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}' AND a.Type='2'
  3097. IF (@Status IS NULL)
  3098. BEGIN
  3099. RAISERROR('" + language.GetNameByCode("WMSAPIInfo122") + @"',16,1);
  3100. RETURN
  3101. END
  3102. ELSE IF (@Status!='1')
  3103. BEGIN
  3104. RAISERROR('" + language.GetNameByCode("WMSAPIInfo123") + @"',16,1);
  3105. RETURN
  3106. END
  3107. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  3108. FROM ICSOutsourcingReceive a
  3109. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}' AND a.Type='2'
  3110. IF EXISTS(SELECT a.ID FROM ICSOutsourcingReceive a
  3111. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' and a.id='{4}' AND a.Type='2' AND a.Quantity<a.RCVQuantity)
  3112. BEGIN
  3113. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  3114. RETURN
  3115. END";
  3116. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence,TransID);
  3117. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3118. {
  3119. throw new Exception(language.GetNameByCode("WMSAPIInfo124"));//"委外红字入库单更新失败!");
  3120. }
  3121. }
  3122. catch (Exception)
  3123. {
  3124. throw;
  3125. }
  3126. }
  3127. /// <summary>
  3128. /// 开立委外红字入库接口
  3129. /// </summary>
  3130. /// <param name="TransType"></param>
  3131. /// <param name="Identification"></param>
  3132. /// <param name="cmd"></param>
  3133. public static void OutsourcingReceiveDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  3134. {
  3135. try
  3136. {
  3137. string sql = string.Empty;
  3138. if (DBHelper.IsPNU9())
  3139. {
  3140. #region ERP开立状态单据审核
  3141. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  3142. INTO #NewTempERP
  3143. from ICSWareHouseLotInfoLog
  3144. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '12'
  3145. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  3146. FROM #NewTempERP a
  3147. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  3148. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  3149. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  3150. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  3151. DROP TABLE #NewTempERP";
  3152. sql = string.Format(sql, Identification);
  3153. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3154. //string Inputstr = JsonConvert.SerializeObject(dt);
  3155. 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
  3156. where a.Identification='{0}' GROUP BY a.transCode";
  3157. checksql = string.Format(checksql, Identification);
  3158. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  3159. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  3160. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  3161. string trancode = chekdt.Rows[0]["transCode"].ToString();
  3162. if (SUMQty - ISSQty == 0)
  3163. {
  3164. string pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  3165. INTO #NewTempERP
  3166. from ICSWareHouseLotInfoLog
  3167. WHERE TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '12'
  3168. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  3169. FROM #NewTempERP a
  3170. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  3171. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  3172. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  3173. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  3174. DROP TABLE #NewTempERP";
  3175. pnsql = string.Format(pnsql, trancode);
  3176. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  3177. string Inputstr = JsonConvert.SerializeObject(dt);
  3178. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocNegativeURL, Inputstr);
  3179. Result result = new Result();
  3180. result = JsonConvert.DeserializeObject<Result>(resultStr);
  3181. if (result.Success)
  3182. {
  3183. try
  3184. {
  3185. foreach (DataRow dr in dt.Rows)
  3186. {
  3187. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  3188. }
  3189. }
  3190. catch (Exception ex)
  3191. {
  3192. log.Debug(ex.ToString());
  3193. log.Debug(resultStr);
  3194. }
  3195. }
  3196. else
  3197. {
  3198. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  3199. }
  3200. }
  3201. #endregion
  3202. }
  3203. else
  3204. {
  3205. #region ERP开立状态单据审核
  3206. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  3207. INTO #NewTempERP
  3208. from ICSWareHouseLotInfoLog
  3209. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '12'
  3210. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  3211. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  3212. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  3213. BEGIN
  3214. RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',16,1);
  3215. RETURN
  3216. END
  3217. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  3218. FROM #NewTempERP a
  3219. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  3220. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  3221. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  3222. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  3223. DROP TABLE #NewTempERP";
  3224. sql = string.Format(sql, Identification);
  3225. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3226. string Inputstr = JsonConvert.SerializeObject(dt);
  3227. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocNegativeURL, Inputstr);
  3228. Result result = new Result();
  3229. result = JsonConvert.DeserializeObject<Result>(resultStr);
  3230. if (result.Success)
  3231. {
  3232. try
  3233. {
  3234. foreach (DataRow dr in dt.Rows)
  3235. {
  3236. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  3237. }
  3238. }
  3239. catch (Exception ex)
  3240. {
  3241. log.Debug(ex.ToString());
  3242. log.Debug(resultStr);
  3243. }
  3244. }
  3245. else
  3246. {
  3247. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  3248. }
  3249. #endregion
  3250. }
  3251. }
  3252. catch (Exception)
  3253. {
  3254. throw;
  3255. }
  3256. }
  3257. #endregion
  3258. #region 获取生成拒收单的参数
  3259. public static List<ICSDeliveryNotice> GetOORefuseMsg(LOTStockUpCreateIModel model, SqlCommand cmd)
  3260. {
  3261. try
  3262. {
  3263. StringBuilder lotSb = new StringBuilder();
  3264. foreach (var det in model.detail)
  3265. {
  3266. if (lotSb.Length > 0)
  3267. lotSb = lotSb.Append(",");
  3268. lotSb = lotSb.Append("'").Append(det.LotNo).Append("'");
  3269. }
  3270. string sql = string.Format(@"select distinct a.VenCode,a.ODNID,a.DepCode,a.ODNCode,a.WorkPoint,'{1}' AS [User] from ICSODeliveryNotice a
  3271. left join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint
  3272. inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  3273. left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  3274. inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint
  3275. WHERE b.LotNo IN ({0})
  3276. select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,ODNDetailID,ODNID,b.LotNo
  3277. from ICSODeliveryNotice a
  3278. inner join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint
  3279. inner join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  3280. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  3281. inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND c.WorkPoint=l.WorkPoint
  3282. LEFT join ICSInspection d on c.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint and d.Enable='1'
  3283. WHERE b.LotNo in ({0})", lotSb, model.User);
  3284. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  3285. string jsonStr = DataToJsonHelper.DataSetToJson(ds, "detail", "ODNID");
  3286. List<ICSDeliveryNotice> list = JsonConvert.DeserializeObject<List<ICSDeliveryNotice>>(jsonStr);
  3287. foreach (ICSDeliveryNotice item in list)
  3288. {
  3289. for (int i = 0; i < item.detail.Count; i++)
  3290. {
  3291. var det = item.detail[i];
  3292. det.Sequence = "" + (i + 1);
  3293. foreach (var modelDet in model.detail)
  3294. {
  3295. if (modelDet.LotNo == det.LotNo)
  3296. {
  3297. det.Quantity = modelDet.BadQty.ToString();
  3298. break;
  3299. }
  3300. }
  3301. }
  3302. }
  3303. return list;
  3304. }
  3305. catch
  3306. {
  3307. throw;
  3308. }
  3309. }
  3310. #endregion
  3311. }
  3312. }