爱思开
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.

1408 lines
104 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. namespace ICSSoft.DataProject
  10. {
  11. /// <summary>
  12. /// 使用中
  13. /// 生产模块
  14. /// </summary>
  15. public class ICSManufactureService
  16. {
  17. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  18. #region 生产发料
  19. /// <summary>
  20. /// 生产发料
  21. /// </summary>
  22. /// <param name="TransCode"></param>
  23. /// <param name="TransSequence"></param>
  24. /// <param name="Quantity"></param>
  25. /// <param name="WorkPoint"></param>
  26. /// <param name="cmd"></param>
  27. public static void MOIssueDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  28. {
  29. try
  30. {
  31. string sql = @"DECLARE @Status VARCHAR(10)
  32. SELECT @Status=b.ERPStatus FROM ICSMOPick a
  33. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  34. WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}'
  35. IF (@Status IS NULL)
  36. BEGIN
  37. RAISERROR('" + language.GetNameByCode("WMSAPIInfo125") + @"',16,1);
  38. RETURN
  39. END
  40. ELSE IF (@Status!='2')
  41. BEGIN
  42. RAISERROR('" + language.GetNameByCode("WMSAPIInfo126") + @"',16,1);
  43. RETURN
  44. END
  45. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  46. FROM ICSMOPick a
  47. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  48. WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}'
  49. IF EXISTS(SELECT a.ID FROM ICSMOPick a
  50. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  51. WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  52. BEGIN
  53. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  54. RETURN
  55. END";
  56. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  57. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  58. {
  59. throw new Exception(language.GetNameByCode("WMSAPIInfo127"));//"生产领料单更新失败!");
  60. }
  61. }
  62. catch (Exception)
  63. {
  64. throw;
  65. }
  66. }
  67. /// <summary>
  68. /// 生产发料接口
  69. /// </summary>
  70. /// <param name="TransType"></param>
  71. /// <param name="Identification"></param>
  72. /// <param name="cmd"></param>
  73. public static void MOIssueDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  74. {
  75. try
  76. {
  77. #region ERP
  78. string sql = @"SELECT 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,
  79. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*lot.Amount/lot.Quantity) AS Amount,x.PickID,con.Enable AS UpdateTodoQuantity
  80. ,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,
  81. 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
  82. INTO #TempERP
  83. FROM ICSWareHouseLotInfoLog a
  84. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  85. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  86. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  87. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  88. INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
  89. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  90. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  91. WHERE a.Identification='{0}' AND ERPUpload='0' AND (a.BusinessCode = '13' OR a.BusinessCode = '105')
  92. GROUP BY y.DepCode,a.FromWarehouseCode,y.MOCode,a.MUSER,a.InvCode,x.PickID,x.MODetailID,con.Enable
  93. ,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, ''),
  94. 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, '')
  95. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  96. SELECT Costre,Sequence,InvCode,Quantity,Amount,PickID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  97. DROP TABLE #TempERP";
  98. sql = string.Format(sql, Identification);
  99. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  100. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  101. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueDocURL, Inputstr);
  102. Result result = new Result();
  103. result = JsonConvert.DeserializeObject<Result>(resultStr);
  104. if (result.Success)
  105. {
  106. try
  107. {
  108. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  109. foreach (var item in res)
  110. {
  111. JObject jo = (JObject)item;
  112. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  113. foreach (var detail in resdetail)
  114. {
  115. JObject det = (JObject)detail;
  116. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  117. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  118. }
  119. }
  120. }
  121. catch (Exception ex)
  122. {
  123. log.Debug(ex.ToString());
  124. log.Debug(resultStr);
  125. }
  126. }
  127. else
  128. {
  129. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  130. }
  131. #endregion
  132. }
  133. catch (Exception)
  134. {
  135. throw;
  136. }
  137. }
  138. #endregion
  139. #region 领料申请单生产发料
  140. /// <summary>
  141. /// 领料申请单生产发料
  142. /// </summary>
  143. /// <param name="TransCode"></param>
  144. /// <param name="TransSequence"></param>
  145. /// <param name="Quantity"></param>
  146. /// <param name="WorkPoint"></param>
  147. /// <param name="cmd"></param>
  148. public static void MOApply(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  149. {
  150. try
  151. {
  152. string sql = @"DECLARE @Status VARCHAR(10)
  153. SELECT @Status=a.Status FROM ICSMOApply a
  154. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  155. IF (@Status IS NULL)
  156. BEGIN
  157. RAISERROR('" + language.GetNameByCode("WMSAPIInfo128") + @"',16,1);
  158. RETURN
  159. END
  160. ELSE IF (@Status!='2')
  161. BEGIN
  162. RAISERROR('" + language.GetNameByCode("WMSAPIInfo129") + @"',16,1);
  163. RETURN
  164. END
  165. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  166. FROM ICSMOApply a
  167. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  168. IF EXISTS(SELECT a.ID FROM ICSMOApply a
  169. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  170. BEGIN
  171. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  172. RETURN
  173. END";
  174. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  175. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  176. {
  177. throw new Exception(language.GetNameByCode("WMSAPIInfo130"));//"领料申请单更新失败!");
  178. }
  179. }
  180. catch (Exception)
  181. {
  182. throw;
  183. }
  184. }
  185. /// <summary>
  186. /// 领料申请单生产发料接口
  187. /// </summary>
  188. /// <param name="TransType"></param>
  189. /// <param name="Identification"></param>
  190. /// <param name="cmd"></param>
  191. public static void MOApplyERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  192. {
  193. try
  194. {
  195. #region ERP
  196. string sql = @"SELECT a.FromWarehouseCode+b.ApplyCode+a.MUSER AS Costre,a.FromWarehouseCode AS WarehouseCode,b.ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.ApplyCode,b.ApplyDetailID,a.InvCode) AS Sequence,
  197. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*lot.Amount/lot.Quantity) AS Amount,b.ApplyDetailID,Enable AS UpdateTodoQuantity
  198. ,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,
  199. 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
  200. INTO #TempERP
  201. FROM ICSWareHouseLotInfoLog a
  202. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  203. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  204. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  205. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  206. INNER JOIN ICSMOApply b ON a.TransCode=b.ApplyCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  207. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  208. WHERE a.Identification='{0}' AND ERPUpload='0' AND (a.BusinessCode = '14' OR a.BusinessCode = '105')
  209. GROUP BY a.FromWarehouseCode,b.ApplyCode,a.MUSER,a.InvCode,b.ApplyDetailID,Enable
  210. ,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, ''),
  211. 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, '')
  212. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  213. SELECT Costre,Sequence,InvCode,Quantity,Amount,ApplyDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  214. DROP TABLE #TempERP";
  215. sql = string.Format(sql, Identification);
  216. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  217. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  218. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOApplyURL, Inputstr);
  219. Result result = new Result();
  220. result = JsonConvert.DeserializeObject<Result>(resultStr);
  221. if (result.Success)
  222. {
  223. try
  224. {
  225. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  226. foreach (var item in res)
  227. {
  228. JObject jo = (JObject)item;
  229. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  230. foreach (var detail in resdetail)
  231. {
  232. JObject det = (JObject)detail;
  233. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  234. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  235. }
  236. }
  237. }
  238. catch (Exception ex)
  239. {
  240. log.Debug(ex.ToString());
  241. log.Debug(resultStr);
  242. }
  243. }
  244. else
  245. {
  246. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  247. }
  248. #endregion
  249. }
  250. catch (Exception)
  251. {
  252. throw;
  253. }
  254. }
  255. #endregion
  256. #region 材料出库单生产发料
  257. /// <summary>
  258. /// 材料出库单生产发料
  259. /// </summary>
  260. /// <param name="TransCode"></param>
  261. /// <param name="TransSequence"></param>
  262. /// <param name="Quantity"></param>
  263. /// <param name="WorkPoint"></param>
  264. /// <param name="cmd"></param>
  265. public static void MOIssue(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  266. {
  267. try
  268. {
  269. string sql = @"DECLARE @Status VARCHAR(10)
  270. SELECT @Status=a.Status FROM ICSMOIssue a
  271. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  272. IF (@Status IS NULL)
  273. BEGIN
  274. RAISERROR('" + language.GetNameByCode("WMSAPIInfo131") + @"',16,1);
  275. RETURN
  276. END
  277. ELSE IF (@Status!='1')
  278. BEGIN
  279. RAISERROR('" + language.GetNameByCode("WMSAPIInfo132") + @"',16,1);
  280. RETURN
  281. END
  282. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  283. FROM ICSMOIssue a
  284. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  285. IF EXISTS(SELECT a.ID FROM ICSMOIssue a
  286. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  287. BEGIN
  288. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  289. RETURN
  290. END";
  291. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  292. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  293. {
  294. throw new Exception(language.GetNameByCode("WMSAPIInfo133"));//"材料出库单更新失败!");
  295. }
  296. }
  297. catch (Exception)
  298. {
  299. throw;
  300. }
  301. }
  302. /// <summary>
  303. /// 材料出库单生产发料接口
  304. /// </summary>
  305. /// <param name="TransType"></param>
  306. /// <param name="Identification"></param>
  307. /// <param name="cmd"></param>
  308. public static void MOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  309. {
  310. try
  311. {
  312. #region ERP开立状态单据审核
  313. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  314. INNER JOIN ICSMOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  315. WHERE a.Identification='{0}' AND b.Quantity!=b.IssueQuantity)
  316. BEGIN
  317. RAISERROR('" + language.GetNameByCode("WMSAPIInfo094") + @"',16,1);
  318. RETURN
  319. END
  320. SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity
  321. ,conStock.Enable AS UpdateStock,a.WorkPoint
  322. FROM ICSWareHouseLotInfoLog a
  323. INNER JOIN ICSMOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  324. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  325. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  326. WHERE a.Identification='{0}' AND ERPUpload='0' AND (a.BusinessCode = '15' OR a.BusinessCode = '105')
  327. GROUP BY b.IssueID,a.MUSER,con.Enable
  328. ,conStock.Enable,a.WorkPoint";
  329. sql = string.Format(sql, Identification);
  330. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  331. string Inputstr = JsonConvert.SerializeObject(dt);
  332. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueURL, Inputstr);
  333. Result result = new Result();
  334. result = JsonConvert.DeserializeObject<Result>(resultStr);
  335. if (result.Success)
  336. {
  337. try
  338. {
  339. foreach (DataRow dr in dt.Rows)
  340. {
  341. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", cmd, language);
  342. }
  343. }
  344. catch (Exception ex)
  345. {
  346. log.Debug(ex.ToString());
  347. log.Debug(resultStr);
  348. }
  349. }
  350. else
  351. {
  352. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  353. }
  354. #endregion
  355. }
  356. catch (Exception)
  357. {
  358. throw;
  359. }
  360. }
  361. #endregion
  362. #region 生产退料
  363. /// <summary>
  364. /// 生产退料
  365. /// </summary>
  366. /// <param name="TransCode"></param>
  367. /// <param name="TransSequence"></param>
  368. /// <param name="Quantity"></param>
  369. /// <param name="WorkPoint"></param>
  370. /// <param name="cmd"></param>
  371. public static void MOIssueDocNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  372. {
  373. try
  374. {
  375. string table = "";
  376. string sql = "";
  377. if (string.IsNullOrWhiteSpace(LogID))
  378. {
  379. string type = "";
  380. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  381. {
  382. table = "INNER JOIN ICSMOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint";
  383. type = "1";
  384. }
  385. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  386. {
  387. table = "INNER JOIN ICSMOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
  388. type = "2";
  389. }
  390. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  391. {
  392. table = "INNER JOIN ICSMOIssue e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
  393. type = "3";
  394. }
  395. else
  396. {
  397. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  398. }
  399. #region 新条码
  400. sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  401. FROM ICSInventoryLot a
  402. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  403. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  404. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  405. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  406. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  407. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  408. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  409. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  410. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND c.Quantity<c.IssueNegQuantity)
  411. BEGIN
  412. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  413. END
  414. UPDATE e SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  415. FROM ICSInventoryLot a
  416. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  417. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  418. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  419. {3}
  420. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  421. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  422. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  423. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  424. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  425. {3}
  426. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND e.IssueQuantity<0)
  427. BEGIN
  428. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  429. END";
  430. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type);
  431. #endregion
  432. }
  433. else
  434. {
  435. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  436. {
  437. table = @"INNER JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  438. INNER JOIN ICSMOPick c ON b.MODetailID = c.MODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
  439. }
  440. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  441. {
  442. table = "INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  443. }
  444. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  445. {
  446. table = "INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  447. }
  448. else
  449. {
  450. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  451. }
  452. #region 原条码
  453. sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  454. FROM ICSWareHouseLotInfoLog a
  455. {3}
  456. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}'
  457. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
  458. {3}
  459. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0)
  460. BEGIN
  461. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  462. END";
  463. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID);
  464. #endregion
  465. }
  466. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  467. {
  468. throw new Exception(language.GetNameByCode("WMSAPIInfo134"));//"生产退料单更新失败!");
  469. }
  470. }
  471. catch (Exception)
  472. {
  473. throw;
  474. }
  475. }
  476. /// <summary>
  477. /// 生产退料接口
  478. /// </summary>
  479. /// <param name="TransType"></param>
  480. /// <param name="Identification"></param>
  481. /// <param name="cmd"></param>
  482. public static void MOIssueDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  483. {
  484. try
  485. {
  486. #region ERP
  487. string sql = string.Empty;
  488. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  489. {
  490. sql = @"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,
  491. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*lot.Amount/lot.Quantity) AS Amount,x.PickID AS SourceDetailID,Enable AS UpdateTodoQuantity
  492. ,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,
  493. 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
  494. INTO #TempERP
  495. FROM ICSWareHouseLotInfoLog a
  496. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  497. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  498. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  499. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  500. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  501. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  502. INNER JOIN ICSMOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
  503. INNER JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  504. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  505. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')=''
  506. GROUP BY y.DepCode,a.ToWarehouseCode,y.MOCode,a.MUSER,a.InvCode,x.PickID,x.MODetailID,Enable
  507. ,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, ''),
  508. 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, '')
  509. UNION ALL
  510. 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,
  511. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,x.PickID AS SourceDetailID,Enable AS UpdateTodoQuantity
  512. ,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,
  513. 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
  514. FROM ICSWareHouseLotInfoLog a
  515. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  516. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  517. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  518. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  519. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  520. INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
  521. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  522. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  523. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>''
  524. GROUP BY y.DepCode,a.ToWarehouseCode,y.MOCode,a.MUSER,a.InvCode,x.PickID,x.MODetailID,Enable
  525. ,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, ''),
  526. 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, '')
  527. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  528. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  529. DROP TABLE #TempERP";
  530. }
  531. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  532. {
  533. sql = @"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,
  534. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,Enable AS UpdateTodoQuantity
  535. ,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,
  536. 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
  537. INTO #TempERP
  538. FROM ICSWareHouseLotInfoLog a
  539. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  540. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  541. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  542. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  543. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  544. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  545. INNER JOIN ICSMOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint
  546. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  547. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')=''
  548. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,Enable
  549. ,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, ''),
  550. 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, '')
  551. UNION ALL
  552. 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,
  553. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,Enable AS UpdateTodoQuantity
  554. ,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,
  555. 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
  556. FROM ICSWareHouseLotInfoLog a
  557. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  558. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  559. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  560. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  561. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  562. INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  563. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  564. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>''
  565. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,Enable
  566. ,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, ''),
  567. 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, '')
  568. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  569. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  570. DROP TABLE #TempERP";
  571. }
  572. //根据材料出库单查询上游单据,根据上游单据生成红字材料出库
  573. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  574. {
  575. sql = @"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,
  576. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,Enable AS UpdateTodoQuantity
  577. ,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,
  578. 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
  579. INTO #TempERP
  580. FROM ICSWareHouseLotInfoLog a
  581. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  582. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  583. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  584. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  585. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  586. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  587. INNER JOIN ICSMOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  588. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  589. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  590. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  591. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  592. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')=''
  593. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,Enable
  594. ,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, ''),
  595. 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, '')
  596. UNION ALL
  597. 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,
  598. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,Enable AS UpdateTodoQuantity
  599. ,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,
  600. 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
  601. FROM ICSWareHouseLotInfoLog a
  602. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  603. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  604. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  605. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  606. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  607. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  608. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  609. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  610. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  611. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  612. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>''
  613. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,Enable
  614. ,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, ''),
  615. 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, '')
  616. IF EXISTS(SELECT Costre FROM #TempERP WHERE SourceType='{0}')
  617. BEGIN
  618. RAISERROR('" + language.GetNameByCode("WMSAPIInfo135") + @"',16,1);
  619. END
  620. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  621. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  622. DROP TABLE #TempERP";
  623. }
  624. else
  625. {
  626. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  627. }
  628. sql = string.Format(sql, Identification);
  629. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  630. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  631. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueDocNegativeURL, Inputstr);
  632. Result result = new Result();
  633. result = JsonConvert.DeserializeObject<Result>(resultStr);
  634. if (result.Success)
  635. {
  636. try
  637. {
  638. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  639. foreach (var item in res)
  640. {
  641. JObject jo = (JObject)item;
  642. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  643. foreach (var detail in resdetail)
  644. {
  645. JObject det = (JObject)detail;
  646. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  647. det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  648. }
  649. }
  650. }
  651. catch (Exception ex)
  652. {
  653. log.Debug(ex.ToString());
  654. log.Debug(resultStr);
  655. }
  656. }
  657. else
  658. {
  659. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  660. }
  661. #endregion
  662. }
  663. catch (Exception)
  664. {
  665. throw;
  666. }
  667. }
  668. #endregion
  669. #region 生产入库
  670. /// <summary>
  671. /// 生产入库
  672. /// </summary>
  673. /// <param name="TransCode"></param>
  674. /// <param name="TransSequence"></param>
  675. /// <param name="Quantity"></param>
  676. /// <param name="WorkPoint"></param>
  677. /// <param name="cmd"></param>
  678. public static void ManufactureReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  679. {
  680. try
  681. {
  682. string sql = @"
  683. IF NOT EXISTS (
  684. SELECT bcLog.ID
  685. FROM ICSMO a
  686. INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.MoCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  687. INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
  688. INNER JOIN ICSExtension d ON d.ID=c.ExtensionID AND d.WorkPoint=c.WorkPoint
  689. INNER JOIN ICSBackflushBCLog bclog ON a.MOCode=bclog.TransCode AND a.Sequence=bclog.TransSequence AND bclog.BatchCode=d.BatchCode
  690. WHERE c.LotNo = '{0}' AND (a.EATTRIBUTE2 <> '03' OR a.EATTRIBUTE2 IS NULL)
  691. )
  692. BEGIN
  693. RAISERROR('" + language.GetNameByCode("WMSAPIInfo468") + @"',16,1);
  694. RETURN;
  695. END
  696. DECLARE @Status VARCHAR(10)
  697. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  698. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  699. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  700. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  701. IF (@Status IS NULL)
  702. BEGIN
  703. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  704. RETURN
  705. END
  706. ELSE IF (@Status='3')
  707. BEGIN
  708. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  709. RETURN
  710. END
  711. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  712. FROM ICSInventoryLot a
  713. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  714. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  715. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  716. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  717. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  718. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  719. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.RCVQuantity)
  720. BEGIN
  721. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  722. END";
  723. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  724. log.Debug("生产入库:" + sql);
  725. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  726. {
  727. throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
  728. }
  729. }
  730. catch (Exception)
  731. {
  732. throw;
  733. }
  734. }
  735. /// <summary>
  736. /// 生产入库接口
  737. /// </summary>
  738. /// <param name="TransType"></param>
  739. /// <param name="Identification"></param>
  740. /// <param name="cmd"></param>
  741. public static void ManufactureReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  742. {
  743. try
  744. {
  745. #region 物料bom是联副产品的生成产成品入库单
  746. DataSet ds2 = new DataSet();
  747. string sql2 = @"SELECT a.Identification from ICSWareHouseLotInfoLog a
  748. inner JOIN icsMOPick b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  749. where a.Identification='{0}' AND ERPUpload='0' and b.EATTRIBUTE1='1' ";
  750. sql2 = string.Format(sql2, Identification);
  751. DataTable data = DBHelper.SQlReturnData(sql2, cmd);
  752. if (data != null && data.Rows.Count > 0)
  753. {
  754. ds2 = ManufactureLFReceiveDocERP("返工工单", Identification, cmd, language);
  755. }
  756. #endregion
  757. #region ERP
  758. string sql = "";
  759. Result result = new Result();
  760. DataSet ds;
  761. #region 副产品生成产成品入库单
  762. try {
  763. sql = @"-- 判断本工单中对应行号与本批次副产品是否已生成入库单号
  764. IF(
  765. SELECT DISTINCT bypro.BatchCode
  766. FROM ICSWareHouseLotInfoLog a
  767. LEFT JOIN ICSInventoryLot b ON b.LotNo = a.LotNo AND b.WorkPoint = a.WorkPoint
  768. LEFT JOIN ICSExtension c ON c.ID = b.ExtensionID AND c.WorkPoint = b.WorkPoint
  769. LEFT JOIN ICSMOByProductLog bypro ON bypro.MoCode = a.TransCode AND bypro.Sequence = a.TransSequence AND bypro.BatchCode = c.BatchCode AND bypro.WorkPoint = a.WorkPoint
  770. WHERE a.Identification='{0}'
  771. ) IS NULL
  772. BEGIN
  773. --
  774. DECLARE @BatchCount VARCHAR(10)
  775. SELECT @BatchCount=COUNT(DISTINCT c.BatchCode)
  776. FROM ICSWareHouseLotInfoLog a
  777. LEFT JOIN ICSInventoryLot b ON b.LotNo = a.LotNo AND b.WorkPoint = a.WorkPoint
  778. LEFT JOIN ICSExtension c ON c.ID = b.ExtensionID AND c.WorkPoint = b.WorkPoint
  779. LEFT JOIN ICSInventoryLotDetail d ON d.LotNo = b.LotNo AND d.WorkPoint = b.WorkPoint
  780. LEFT JOIN ICSMO e ON e.MOCode = d.TransCode AND e.WorkPoint = d.WorkPoint
  781. LEFT JOIN ICSMOPick f ON f.MODetailID = e.MODetailID AND f.WorkPoint = d.WorkPoint
  782. WHERE a.Identification = '{0}'
  783. AND(SELECT 1 FROM ICSMOByProductLog bypro WHERE bypro.MoCode = a.TransCode AND bypro.Sequence = a.TransSequence AND bypro.BatchCode = c.BatchCode AND bypro.WorkPoint = a.WorkPoint) IS NULL
  784. -- SELECT @BatchCount
  785. --
  786. SELECT e.DepCode+f.WHCode+e.MOCode+a.MUSER AS Costre,e.DepCode,f.WHCode AS WarehouseCode,e.MoCode,a.MUSER,f.Sequence AS Sequence,f.InvCode,f.EATTRIBUTE2 AS Quantity,0 AS Amount,f.PickID as MODetailID,Enable AS UpdateTodoQuantity,a.WorkPoint,conStock.Enable AS UpdateStock
  787. ,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
  788. INTO #TempERP
  789. FROM ICSWareHouseLotInfoLog a
  790. LEFT JOIN ICSInventoryLot b ON b.LotNo=a.LotNo AND b.WorkPoint=a.WorkPoint
  791. LEFT JOIN ICSExtension ext ON ext.ID=b.ExtensionID AND ext.WorkPoint=b.WorkPoint
  792. LEFT JOIN ICSInventoryLotDetail d ON d.LotNo=b.LotNo AND d.WorkPoint=b.WorkPoint
  793. LEFT JOIN ICSMO e ON e.MOCode=d.TransCode AND e.Sequence=d.TransSequence AND e.WorkPoint=d.WorkPoint
  794. LEFT JOIN ICSMOPick f ON f.MODetailID=e.MODetailID AND f.WorkPoint=d.WorkPoint
  795. INNER JOIN ICSInventory inv ON f.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  796. LEFT JOIN ICSInventoryBatchEnable invBat ON f.InvCode=invBat.InvCode AND f.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  797. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  798. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  799. WHERE a.Identification='{0}'
  800. AND f.EATTRIBUTE1='1'
  801. AND (SELECT 1 FROM ICSMOByProductLog bypro WHERE bypro.MoCode=e.MoCode AND bypro.Sequence=f.Sequence AND bypro.BatchCode=ext.BatchCode AND bypro.WorkPoint=a.WorkPoint) IS NULL
  802. GROUP BY e.DepCode,f.WHCode,e.MoCode,a.MUSER,f.InvCode,f.EATTRIBUTE2,f.Sequence,f.PickID,Enable,a.WorkPoint
  803. ,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  804. SELECT DISTINCT Costre, '' as TYPE,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  805. SELECT Costre,Sequence,InvCode,Quantity*@BatchCount AS Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  806. FROM #TempERP
  807. DROP TABLE #TempERP
  808. END
  809. ELSE
  810. BEGIN
  811. RAISERROR('" + language.GetNameByCode("WMSAPIInfo467") + @"',16,1);
  812. -- RAISERROR('',16,1)
  813. END";
  814. sql = string.Format(sql, Identification);
  815. log.Debug("副产品生成入库单逻辑:");
  816. log.Debug(sql);
  817. ds = DBHelper.SQlReturnDataSet(sql, cmd);
  818. string ByProductInputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  819. string byProductResultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ManufactureReceiveDocASKURL, ByProductInputstr);
  820. result = new Result();
  821. result = JsonConvert.DeserializeObject<Result>(byProductResultStr);
  822. if (result.Success)
  823. {
  824. //向ICSMOByProductLog表中插入数据
  825. sql = @"SELECT a.TransCode,a.TransSequence,a.Quantity,c.BatchCode,b.InvCode,a.WorkPoint
  826. FROM ICSWareHouseLotInfoLog a
  827. LEFT JOIN ICSInventoryLot b ON b.LotNo=a.LotNo AND b.WorkPoint=a.WorkPoint
  828. LEFT JOIN ICSExtension c ON c.ID=b.ExtensionID AND c.WorkPoint=a.WorkPoint
  829. WHERE a.Identification='{0}'";
  830. sql = string.Format(sql,Identification);
  831. log.Debug("查询入库的主产品及批次SQL:");
  832. log.Error(sql);
  833. DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
  834. string jsonStr = JsonConvert.SerializeObject(dtt);
  835. log.Debug("SQL执行结果:" + jsonStr);
  836. List<MoStockInModel> moStockIns = JsonConvert.DeserializeObject<List<MoStockInModel>>(jsonStr);
  837. foreach (MoStockInModel moStockIn in moStockIns)
  838. {
  839. try
  840. {
  841. sql = @"INSERT INTO ICSMOByProductLog VALUES(NEWID(),'{0}','{1}',{2},'{3}','{4}','{5}')";
  842. sql = string.Format(sql, moStockIn.TransCode, moStockIn.TransSequence, moStockIn.Quantity, moStockIn.BatchCode, moStockIn.InvCode, moStockIn.WorkPoint);
  843. log.Debug("向ICSMOByProductLog表中插入数据:");
  844. log.Debug(sql);
  845. DBHelper.ExecuteNonQuery(sql, cmd);
  846. }
  847. catch
  848. {
  849. throw new Exception(language.GetNameByCode("WMSAPIInfo466"));
  850. }
  851. }
  852. log.Debug(language.GetNameByCode("WMSAPIInfo465") + ":" + result.ToString());
  853. }
  854. else
  855. {
  856. log.Debug(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  857. throw new Exception(language.GetNameByCode("WMSAPIInfo469"));
  858. }
  859. }
  860. catch(Exception ex)
  861. {
  862. log.Debug(ex.Message);
  863. }
  864. #endregion
  865. #region SQL
  866. sql = @"SELECT c.DepCode+a.ToWarehouseCode+c.MOCode+a.MUSER AS Costre,c.MODetailID+ext.BatchCode AS Costre2,c.DepCode,a.ToWarehouseCode AS WarehouseCode,c.MOCode,a.MUSER,'' AS Sequence,
  867. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,c.MODetailID,con.Enable AS UpdateTodoQuantity
  868. ,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,
  869. 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,a.TransSequence
  870. INTO #TempERP
  871. FROM ICSWareHouseLotInfoLog a
  872. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  873. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  874. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  875. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  876. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  877. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  878. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  879. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  880. WHERE a.Identification='{0}' AND ERPUpload='0'
  881. GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,lot.Amount,lot.Quantity,a.InvCode,c.MODetailID,con.Enable,conv.Enable
  882. ,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, ''),
  883. 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,ext.BatchCode
  884. SELECT d.WHCode+a.TransCode+a.MUSER AS Costre,f.F_DepartmentId as DepCode,d.WHCode AS WarehouseCode,a.TransCode as MOCode,a.MUSER,d.Sequence AS Sequence,
  885. a.InvCode,sum(d.Quantity/c.Quantity*a.Quantity) AS Quantity,convert(decimal(18,6),'0') AS Amount,d.PickID AS MODetailID,Enable AS UpdateTodoQuantity
  886. ,a.WorkPoint, '' AS ProjectCode,'' AS BatchCode,'' AS Version,'' AS Brand,
  887. '' AS cFree1,'' AS cFree2,'' AS cFree3,'' AS cFree4,'' AS cFree5,'' AS cFree6,'' AS cFree7,'' AS cFree8,'' AS cFree9,'' AS cFree10,CONVERT(nvarchar(50) ,ROW_NUMBER() OVER(ORDER BY d.PickID)) as Costre2
  888. INTO #TempERP2
  889. FROM ICSWareHouseLotInfoLog a
  890. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  891. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  892. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  893. INNER JOIN ICSMO c ON a.TransCode=c.MOCode AND a.WorkPoint=c.WorkPoint
  894. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and a.TransSequence=c.Sequence+'~'+d.Sequence
  895. INNER JOIN Sys_SRM_User f ON f.F_Account=a.MUSER AND a.WorkPoint=f.F_Location
  896. WHERE a.Identification='{0}' AND ERPUpload='0' and d.EATTRIBUTE1='1'
  897. GROUP BY a.TransCode,a.MUSER,a.InvCode,d.PickID,Enable,d.Sequence
  898. ,a.WorkPoint,f.F_DepartmentId,d.WHCode--,d.Quantity,c.Quantity,a.Quantity
  899. SELECT DISTINCT '' as TYPE,Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  900. union all
  901. SELECT DISTINCT '' as TYPE,Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,'' as CompleteVerification FROM #TempERP2
  902. SELECT Costre,Costre2,TransSequence,Sequence,InvCode,SUM(Quantity) as Quantity ,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  903. FROM #TempERP GROUP BY Costre,Costre2,TransSequence,Sequence,InvCode,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  904. union all
  905. SELECT Costre,Costre2,'' TransSequence,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  906. FROM #TempERP2
  907. SELECT c.WHCode,c.MODetailID+ISNULL(a.EATTRIBUTE2, '') AS Costre2,a.TransCode,a.TransSequence AS Sequence,
  908. a.InvCode,sum(c.Quantity/b.Quantity*a.Quantity) as Quantity,c.Amount,c.PickID,ISNULL(ext.ProjectCode, '') AS ProjectCode,
  909. ISNULL(a.EATTRIBUTE4, '') AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  910. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,
  911. ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,
  912. ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  913. FROM ICSWareHouseLotInfoLog a
  914. INNER JOIN ICSMO b ON b.MOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  915. INNER JOIN ICSMOPick c ON c.MODetailID=b.MODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  916. INNER JOIN ICSExtension ext ON ext.ID=c.ExtensionID AND ext.WorkPoint=c.WorkPoint
  917. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  918. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  919. WHERE a.Identification='{0}' AND a.TransType='30' and c.EATTRIBUTE1<>'1'
  920. GROUP BY c.WHCode,c.MODetailID,a.TransCode,a.TransSequence,a.InvCode,c.Amount,c.PickID,ext.ProjectCode,
  921. invBat.BatchEnable,inv.BatchEnable,invBat.BatchEnable,ext.BatchCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,
  922. ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.EATTRIBUTE2,a.EATTRIBUTE4
  923. DROP TABLE #TempERP
  924. DROP TABLE #TempERP2";
  925. #endregion
  926. #region 原sql
  927. // string sql = @"SELECT * INTO #TempERP from (
  928. //SELECT c.DepCode+cc.WHCode+c.MOCode+a.TransSequence+a.MUSER AS Costre,c.MODetailID AS Costre2,c.DepCode,cc.WHCode AS WarehouseCode,c.MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.DepCode,cc.WHCode,c.MOCode,c.MODetailID,a.InvCode) AS Sequence,
  929. // a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,c.MODetailID,con.Enable AS UpdateTodoQuantity
  930. // ,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,
  931. // 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,'false' AS CompleteVerification,a.TransSequence --,conv.Enable AS CompleteVerification
  932. // FROM ICSWareHouseLotInfoLog a
  933. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  934. // LEFT JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  935. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  936. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  937. // INNER JOIN ICSMO c ON a.TransCode=c.MOCode AND CHARINDEX('~', a.TransSequence)=c.Sequence AND a.WorkPoint=c.WorkPoint
  938. // INNER JOIN ICSMOPick cc ON cc.MODetailID=c.MODetailID AND cc.WorkPoint=a.WorkPoint AND a.TransSequence=c.Sequence+'~'+cc.Sequence
  939. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  940. // INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  941. // WHERE a.Identification='{0}' AND ERPUpload='0'
  942. // GROUP BY c.DepCode,cc.WHCode,c.MOCode,a.MUSER,lot.Amount,lot.Quantity,a.InvCode,c.MODetailID,con.Enable,conv.Enable
  943. // ,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, ''),
  944. // 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
  945. //
  946. //UNION ALL
  947. //SELECT c.DepCode+a.ToWarehouseCode+c.MOCode+a.TransSequence+a.MUSER AS Costre,c.MODetailID AS Costre2,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,
  948. // a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,c.MODetailID,con.Enable AS UpdateTodoQuantity
  949. // ,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,
  950. // 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,'false' AS CompleteVerification,a.TransSequence --,conv.Enable AS CompleteVerification
  951. // FROM ICSWareHouseLotInfoLog a
  952. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  953. // LEFT JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  954. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  955. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  956. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  957. // INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  958. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  959. // INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  960. // WHERE a.Identification='{0}' AND ERPUpload='0'
  961. // GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,lot.Amount,lot.Quantity,a.InvCode,c.MODetailID,con.Enable,conv.Enable
  962. // ,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, ''),
  963. // 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
  964. //) a
  965. //
  966. // SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  967. // SELECT Costre,Costre2,TransSequence,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  968. // FROM #TempERP
  969. //
  970. // SELECT c.MODetailID AS Costre2,a.TransCode,a.TransSequence AS Sequence,a.InvCode,a.Quantity,c.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
  971. // FROM ICSWareHouseLotInfoLog a
  972. // INNER JOIN ICSMO b ON b.MOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  973. // INNER JOIN ICSMOPick c ON c.MODetailID=b.MODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  974. // INNER JOIN ICSExtension ext ON ext.ID=c.ExtensionID AND ext.WorkPoint=c.WorkPoint
  975. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  976. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  977. // WHERE a.Identification='{0}' AND a.TransType='12'
  978. //
  979. // DROP TABLE #TempERP";
  980. #endregion
  981. sql = string.Format(sql, Identification);
  982. ds = DBHelper.SQlReturnDataSet(sql, cmd);
  983. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "detailss", "Costre2");
  984. string inputjson = Inputstr;
  985. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ManufactureReceiveDocASKURL, Inputstr);
  986. result = JsonConvert.DeserializeObject<Result>(resultStr);
  987. if (result.Success)
  988. {
  989. try
  990. {
  991. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  992. foreach (var item in res)
  993. {
  994. JObject jo = (JObject)item;
  995. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  996. foreach (var detail in resdetail)
  997. {
  998. JObject det = (JObject)detail;
  999. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1000. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  1001. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  1002. foreach (var details in resdetails)
  1003. {
  1004. JObject dets = (JObject)details;
  1005. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, dets["ERPID"].ToString(),
  1006. dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString(), dets["Sequence"].ToString(), cmd, language);
  1007. }
  1008. }
  1009. }
  1010. }
  1011. catch (Exception ex)
  1012. {
  1013. log.Debug(ex.ToString());
  1014. log.Debug(resultStr);
  1015. }
  1016. }
  1017. else
  1018. {
  1019. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1020. }
  1021. }
  1022. catch (Exception)
  1023. {
  1024. throw;
  1025. }
  1026. }
  1027. #endregion
  1028. #region 开立的生产入库单
  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 ManufactureReceive(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1038. {
  1039. try
  1040. {
  1041. string sql = @"DECLARE @Status VARCHAR(10)
  1042. SELECT @Status=c.Status FROM ICSInventoryLot a
  1043. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1044. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1045. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  1046. IF (@Status IS NULL)
  1047. BEGIN
  1048. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1049. RETURN
  1050. END
  1051. ELSE IF (@Status!='1')
  1052. BEGIN
  1053. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  1054. RETURN
  1055. END
  1056. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1057. FROM ICSInventoryLot a
  1058. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1059. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1060. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  1061. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1062. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1063. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1064. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1' AND c.Quantity<c.RCVQuantity)
  1065. BEGIN
  1066. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1067. END";
  1068. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1069. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1070. {
  1071. throw new Exception(language.GetNameByCode("WMSAPIInfo138"));//"生产入库单更新失败!");
  1072. }
  1073. }
  1074. catch (Exception)
  1075. {
  1076. throw;
  1077. }
  1078. }
  1079. /// <summary>
  1080. /// 开立的生产入库单
  1081. /// </summary>
  1082. /// <param name="TransType"></param>
  1083. /// <param name="Identification"></param>
  1084. /// <param name="cmd"></param>
  1085. public static void ManufactureReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1086. {
  1087. try
  1088. {
  1089. #region ERP开立状态单据审核
  1090. string sql = @"IF EXISTS(SELECT b.ID FROM ICSManufactureReceive b
  1091. WHERE b.RCVCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1092. AND b.Quantity!=b.RCVQuantity)
  1093. BEGIN
  1094. RAISERROR('" + language.GetNameByCode("WMSAPIInfo096") + @"',16,1);
  1095. RETURN
  1096. END
  1097. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1098. FROM ICSWareHouseLotInfoLog a
  1099. INNER JOIN ICSManufactureReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1100. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1101. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  1102. WHERE a.Identification='{0}' AND ERPUpload='0'
  1103. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  1104. sql = string.Format(sql, Identification);
  1105. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1106. string Inputstr = JsonConvert.SerializeObject(dt);
  1107. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSManufactureReceiveURL, Inputstr);
  1108. Result result = new Result();
  1109. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1110. if (result.Success)
  1111. {
  1112. try
  1113. {
  1114. foreach (DataRow dr in dt.Rows)
  1115. {
  1116. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", cmd, language);
  1117. }
  1118. }
  1119. catch (Exception ex)
  1120. {
  1121. log.Debug(ex.ToString());
  1122. log.Debug(resultStr);
  1123. }
  1124. }
  1125. else
  1126. {
  1127. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1128. }
  1129. #endregion
  1130. }
  1131. catch (Exception)
  1132. {
  1133. throw;
  1134. }
  1135. }
  1136. #endregion
  1137. #region 返工工单
  1138. /// <summary>
  1139. /// 返工工单
  1140. /// </summary>
  1141. /// <param name="TransCode"></param>
  1142. /// <param name="TransSequence"></param>
  1143. /// <param name="Quantity"></param>
  1144. /// <param name="WorkPoint"></param>
  1145. /// <param name="cmd"></param>
  1146. public static void ReWorkReceiveMo(string LotNo, string Quantity, string WarehouseCode,
  1147. string LocationCode, string WorkPoint, String User, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1148. {
  1149. try
  1150. {
  1151. string sql = @"DECLARE @Status VARCHAR(10)
  1152. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  1153. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1154. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1155. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1156. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1157. IF (@Status IS NULL)
  1158. BEGIN
  1159. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1160. RETURN
  1161. END
  1162. ELSE IF (@Status='3')
  1163. BEGIN
  1164. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1165. RETURN
  1166. END
  1167. UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  1168. FROM ICSInventoryLot a
  1169. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1170. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1171. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1172. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1173. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1174. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1175. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1176. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1177. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.IssueQuantity>d.Quantity)
  1178. BEGIN
  1179. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1180. END";
  1181. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1182. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1183. {
  1184. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));//"生产工单更新失败!");
  1185. }
  1186. }
  1187. catch (Exception)
  1188. {
  1189. throw;
  1190. }
  1191. }
  1192. /// <summary>
  1193. /// 返工工单
  1194. /// </summary>
  1195. /// <param name="TransType"></param>
  1196. /// <param name="Identification"></param>
  1197. /// <param name="cmd"></param>
  1198. public static void ReWorkReceiveMoERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1199. {
  1200. try
  1201. {
  1202. #region ERP开立状态单据审核
  1203. String sql = @"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,
  1204. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,d.PickID AS MODetailID,Enable AS UpdateTodoQuantity
  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. INTO #TempERP
  1208. FROM ICSWareHouseLotInfoLog a
  1209. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1210. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1211. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1212. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1213. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1214. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1215. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1216. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1217. WHERE a.Identification='{0}' AND ERPUpload='0'
  1218. GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,d.PickID,Enable,d.Sequence
  1219. ,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, ''),
  1220. 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, '')
  1221. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  1222. SELECT Costre,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1223. FROM #TempERP
  1224. DROP TABLE #TempERP";
  1225. sql = string.Format(sql, Identification);
  1226. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1227. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1228. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSReWorkReceiveMoURL, Inputstr);
  1229. Result result = new Result();
  1230. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1231. if (result.Success)
  1232. {
  1233. try
  1234. {
  1235. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1236. foreach (var item in res)
  1237. {
  1238. JObject jo = (JObject)item;
  1239. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1240. foreach (var detail in resdetail)
  1241. {
  1242. JObject det = (JObject)detail;
  1243. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1244. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  1245. }
  1246. }
  1247. }
  1248. catch (Exception ex)
  1249. {
  1250. log.Debug(ex.ToString());
  1251. log.Debug(resultStr);
  1252. }
  1253. }
  1254. else
  1255. {
  1256. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1257. }
  1258. #endregion
  1259. }
  1260. catch (Exception)
  1261. {
  1262. throw;
  1263. }
  1264. }
  1265. #endregion
  1266. #region 生成产成品入库单
  1267. public static DataSet ManufactureLFReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1268. {
  1269. try
  1270. {
  1271. #region ERP开立状态单据审核
  1272. String sql = @"SELECT d.WHCode+a.TransCode+a.MUSER AS Costre,f.F_DepartmentId as DepCode,d.WHCode AS WarehouseCode,a.TransCode as MOCode,a.MUSER,d.Sequence AS Sequence,
  1273. a.InvCode,sum(d.Quantity/c.Quantity*a.Quantity) AS Quantity,convert(decimal(18,6),'0') AS Amount,d.PickID AS MODetailID,Enable AS UpdateTodoQuantity
  1274. ,a.WorkPoint, '' AS ProjectCode,'' AS BatchCode,'' AS Version,'' AS Brand,
  1275. '' AS cFree1,'' AS cFree2,'' AS cFree3,'' AS cFree4,'' AS cFree5,'' AS cFree6,'' AS cFree7,'' AS cFree8,'' AS cFree9,'' AS cFree10
  1276. INTO #TempERP
  1277. FROM ICSWareHouseLotInfoLog a
  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 ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1281. INNER JOIN ICSMO c ON a.TransCode=c.MOCode AND a.WorkPoint=c.WorkPoint
  1282. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and a.TransSequence=c.Sequence+'~'+d.Sequence
  1283. INNER JOIN Sys_SRM_User f ON f.F_Account=a.MUSER AND a.WorkPoint=f.F_Location
  1284. WHERE a.Identification='{0}' AND ERPUpload='0' and d.EATTRIBUTE1='1'
  1285. GROUP BY a.TransCode,a.MUSER,a.InvCode,d.PickID,Enable,d.Sequence
  1286. ,a.WorkPoint,f.F_DepartmentId,d.WHCode--,d.Quantity,c.Quantity,a.Quantity
  1287. SELECT DISTINCT '' as TYPE,Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  1288. SELECT Costre,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1289. FROM #TempERP
  1290. DROP TABLE #TempERP";
  1291. sql = string.Format(sql, Identification);
  1292. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1293. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1294. return ds;
  1295. //string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSReWorkReceiveMoURL, Inputstr);
  1296. //Result result = new Result();
  1297. //result = JsonConvert.DeserializeObject<Result>(resultStr);
  1298. //if (result.Success)
  1299. //{
  1300. // try
  1301. // {
  1302. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1303. // foreach (var item in res)
  1304. // {
  1305. // JObject jo = (JObject)item;
  1306. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1307. // foreach (var detail in resdetail)
  1308. // {
  1309. // JObject det = (JObject)detail;
  1310. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1311. // det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  1312. // }
  1313. // }
  1314. // }
  1315. // catch (Exception ex)
  1316. // {
  1317. // log.Debug(ex.ToString());
  1318. // log.Debug(resultStr);
  1319. // }
  1320. //}
  1321. //else
  1322. //{
  1323. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1324. //}
  1325. #endregion
  1326. }
  1327. catch (Exception)
  1328. {
  1329. throw;
  1330. }
  1331. }
  1332. #endregion
  1333. }
  1334. }
  1335. #endregion