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.

3720 lines
277 KiB

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