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

1406 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}'
  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
  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. WHERE a.Identification='{0}'
  799. AND f.EATTRIBUTE1='1'
  800. 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
  801. GROUP BY e.DepCode,f.WHCode,e.MoCode,a.MUSER,f.InvCode,f.EATTRIBUTE2,f.Sequence,f.PickID,Enable,a.WorkPoint
  802. ,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, '')
  803. SELECT DISTINCT Costre, '' as TYPE,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  804. SELECT Costre,Sequence,InvCode,Quantity*@BatchCount AS Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  805. FROM #TempERP
  806. DROP TABLE #TempERP
  807. END
  808. ELSE
  809. BEGIN
  810. RAISERROR('" + language.GetNameByCode("WMSAPIInfo467") + @"',16,1);
  811. -- RAISERROR('',16,1)
  812. END";
  813. sql = string.Format(sql, Identification);
  814. log.Debug("副产品生成入库单逻辑:");
  815. log.Debug(sql);
  816. ds = DBHelper.SQlReturnDataSet(sql, cmd);
  817. string ByProductInputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  818. string byProductResultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ManufactureReceiveDocASKURL, ByProductInputstr);
  819. result = new Result();
  820. result = JsonConvert.DeserializeObject<Result>(byProductResultStr);
  821. if (result.Success)
  822. {
  823. //向ICSMOByProductLog表中插入数据
  824. sql = @"SELECT a.TransCode,a.TransSequence,a.Quantity,c.BatchCode,b.InvCode,a.WorkPoint
  825. FROM ICSWareHouseLotInfoLog a
  826. LEFT JOIN ICSInventoryLot b ON b.LotNo=a.LotNo AND b.WorkPoint=a.WorkPoint
  827. LEFT JOIN ICSExtension c ON c.ID=b.ExtensionID AND c.WorkPoint=a.WorkPoint
  828. WHERE a.Identification='{0}'";
  829. sql = string.Format(sql,Identification);
  830. log.Debug("查询入库的主产品及批次SQL:");
  831. log.Error(sql);
  832. DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
  833. string jsonStr = JsonConvert.SerializeObject(dtt);
  834. log.Debug("SQL执行结果:" + jsonStr);
  835. List<MoStockInModel> moStockIns = JsonConvert.DeserializeObject<List<MoStockInModel>>(jsonStr);
  836. foreach (MoStockInModel moStockIn in moStockIns)
  837. {
  838. try
  839. {
  840. sql = @"INSERT INTO ICSMOByProductLog VALUES(NEWID(),'{0}','{1}',{2},'{3}','{4}','{5}')";
  841. sql = string.Format(sql, moStockIn.TransCode, moStockIn.TransSequence, moStockIn.Quantity, moStockIn.BatchCode, moStockIn.InvCode, moStockIn.WorkPoint);
  842. log.Debug("向ICSMOByProductLog表中插入数据:");
  843. log.Debug(sql);
  844. DBHelper.ExecuteNonQuery(sql, cmd);
  845. }
  846. catch
  847. {
  848. throw new Exception(language.GetNameByCode("WMSAPIInfo466"));
  849. }
  850. }
  851. log.Debug(language.GetNameByCode("WMSAPIInfo465") + ":" + result.ToString());
  852. }
  853. else
  854. {
  855. log.Debug(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  856. }
  857. }
  858. catch(Exception ex)
  859. {
  860. log.Debug(ex.Message);
  861. }
  862. #endregion
  863. #region SQL
  864. 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,
  865. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,c.MODetailID,con.Enable AS UpdateTodoQuantity
  866. ,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,
  867. 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
  868. INTO #TempERP
  869. FROM ICSWareHouseLotInfoLog a
  870. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  871. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  872. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  873. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  874. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  875. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  876. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  877. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  878. WHERE a.Identification='{0}' AND ERPUpload='0'
  879. GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,lot.Amount,lot.Quantity,a.InvCode,c.MODetailID,con.Enable,conv.Enable
  880. ,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, ''),
  881. 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
  882. 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,
  883. 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
  884. ,a.WorkPoint, '' AS ProjectCode,'' AS BatchCode,'' AS Version,'' AS Brand,
  885. '' 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
  886. INTO #TempERP2
  887. FROM ICSWareHouseLotInfoLog a
  888. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  889. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  890. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  891. INNER JOIN ICSMO c ON a.TransCode=c.MOCode AND a.WorkPoint=c.WorkPoint
  892. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and a.TransSequence=c.Sequence+'~'+d.Sequence
  893. INNER JOIN Sys_SRM_User f ON f.F_Account=a.MUSER AND a.WorkPoint=f.F_Location
  894. WHERE a.Identification='{0}' AND ERPUpload='0' and d.EATTRIBUTE1='1'
  895. GROUP BY a.TransCode,a.MUSER,a.InvCode,d.PickID,Enable,d.Sequence
  896. ,a.WorkPoint,f.F_DepartmentId,d.WHCode--,d.Quantity,c.Quantity,a.Quantity
  897. SELECT DISTINCT '' as TYPE,Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  898. union all
  899. SELECT DISTINCT '' as TYPE,Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,'' as CompleteVerification FROM #TempERP2
  900. 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
  901. 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
  902. union all
  903. SELECT Costre,Costre2,'' TransSequence,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  904. FROM #TempERP2
  905. SELECT c.WHCode,c.MODetailID+ISNULL(a.EATTRIBUTE2, '') AS Costre2,a.TransCode,a.TransSequence AS Sequence,
  906. a.InvCode,sum(c.Quantity/b.Quantity*a.Quantity) as Quantity,c.Amount,c.PickID,ISNULL(ext.ProjectCode, '') AS ProjectCode,
  907. ISNULL(a.EATTRIBUTE4, '') AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  908. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,
  909. ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,
  910. ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  911. FROM ICSWareHouseLotInfoLog a
  912. INNER JOIN ICSMO b ON b.MOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  913. INNER JOIN ICSMOPick c ON c.MODetailID=b.MODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  914. INNER JOIN ICSExtension ext ON ext.ID=c.ExtensionID AND ext.WorkPoint=c.WorkPoint
  915. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  916. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  917. WHERE a.Identification='{0}' AND a.TransType='30' and c.EATTRIBUTE1<>'1'
  918. GROUP BY c.WHCode,c.MODetailID,a.TransCode,a.TransSequence,a.InvCode,c.Amount,c.PickID,ext.ProjectCode,
  919. invBat.BatchEnable,inv.BatchEnable,invBat.BatchEnable,ext.BatchCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,
  920. ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.EATTRIBUTE2,a.EATTRIBUTE4
  921. DROP TABLE #TempERP
  922. DROP TABLE #TempERP2";
  923. #endregion
  924. #region 原sql
  925. // string sql = @"SELECT * INTO #TempERP from (
  926. //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,
  927. // a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,c.MODetailID,con.Enable AS UpdateTodoQuantity
  928. // ,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,
  929. // 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
  930. // FROM ICSWareHouseLotInfoLog a
  931. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  932. // LEFT JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  933. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  934. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  935. // INNER JOIN ICSMO c ON a.TransCode=c.MOCode AND CHARINDEX('~', a.TransSequence)=c.Sequence AND a.WorkPoint=c.WorkPoint
  936. // INNER JOIN ICSMOPick cc ON cc.MODetailID=c.MODetailID AND cc.WorkPoint=a.WorkPoint AND a.TransSequence=c.Sequence+'~'+cc.Sequence
  937. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  938. // INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  939. // WHERE a.Identification='{0}' AND ERPUpload='0'
  940. // GROUP BY c.DepCode,cc.WHCode,c.MOCode,a.MUSER,lot.Amount,lot.Quantity,a.InvCode,c.MODetailID,con.Enable,conv.Enable
  941. // ,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, ''),
  942. // 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
  943. //
  944. //UNION ALL
  945. //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,
  946. // a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,c.MODetailID,con.Enable AS UpdateTodoQuantity
  947. // ,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,
  948. // 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
  949. // FROM ICSWareHouseLotInfoLog a
  950. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  951. // LEFT JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  952. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  953. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  954. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  955. // INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  956. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  957. // INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  958. // WHERE a.Identification='{0}' AND ERPUpload='0'
  959. // GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,lot.Amount,lot.Quantity,a.InvCode,c.MODetailID,con.Enable,conv.Enable
  960. // ,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, ''),
  961. // 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
  962. //) a
  963. //
  964. // SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  965. // SELECT Costre,Costre2,TransSequence,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  966. // FROM #TempERP
  967. //
  968. // 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
  969. // FROM ICSWareHouseLotInfoLog a
  970. // INNER JOIN ICSMO b ON b.MOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  971. // INNER JOIN ICSMOPick c ON c.MODetailID=b.MODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  972. // INNER JOIN ICSExtension ext ON ext.ID=c.ExtensionID AND ext.WorkPoint=c.WorkPoint
  973. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  974. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  975. // WHERE a.Identification='{0}' AND a.TransType='12'
  976. //
  977. // DROP TABLE #TempERP";
  978. #endregion
  979. sql = string.Format(sql, Identification);
  980. ds = DBHelper.SQlReturnDataSet(sql, cmd);
  981. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "detailss", "Costre2");
  982. string inputjson = Inputstr;
  983. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ManufactureReceiveDocASKURL, Inputstr);
  984. result = JsonConvert.DeserializeObject<Result>(resultStr);
  985. if (result.Success)
  986. {
  987. try
  988. {
  989. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  990. foreach (var item in res)
  991. {
  992. JObject jo = (JObject)item;
  993. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  994. foreach (var detail in resdetail)
  995. {
  996. JObject det = (JObject)detail;
  997. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  998. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  999. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  1000. foreach (var details in resdetails)
  1001. {
  1002. JObject dets = (JObject)details;
  1003. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, dets["ERPID"].ToString(),
  1004. dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString(), dets["Sequence"].ToString(), cmd, language);
  1005. }
  1006. }
  1007. }
  1008. }
  1009. catch (Exception ex)
  1010. {
  1011. log.Debug(ex.ToString());
  1012. log.Debug(resultStr);
  1013. }
  1014. }
  1015. else
  1016. {
  1017. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1018. }
  1019. }
  1020. catch (Exception)
  1021. {
  1022. throw;
  1023. }
  1024. }
  1025. #endregion
  1026. #region 开立的生产入库单
  1027. /// <summary>
  1028. /// 开立的生产入库单
  1029. /// </summary>
  1030. /// <param name="TransCode"></param>
  1031. /// <param name="TransSequence"></param>
  1032. /// <param name="Quantity"></param>
  1033. /// <param name="WorkPoint"></param>
  1034. /// <param name="cmd"></param>
  1035. public static void ManufactureReceive(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1036. {
  1037. try
  1038. {
  1039. string sql = @"DECLARE @Status VARCHAR(10)
  1040. SELECT @Status=c.Status FROM ICSInventoryLot a
  1041. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1042. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1043. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  1044. IF (@Status IS NULL)
  1045. BEGIN
  1046. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1047. RETURN
  1048. END
  1049. ELSE IF (@Status!='1')
  1050. BEGIN
  1051. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  1052. RETURN
  1053. END
  1054. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1055. FROM ICSInventoryLot a
  1056. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1057. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1058. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  1059. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1060. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1061. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1062. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1' AND c.Quantity<c.RCVQuantity)
  1063. BEGIN
  1064. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1065. END";
  1066. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1067. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1068. {
  1069. throw new Exception(language.GetNameByCode("WMSAPIInfo138"));//"生产入库单更新失败!");
  1070. }
  1071. }
  1072. catch (Exception)
  1073. {
  1074. throw;
  1075. }
  1076. }
  1077. /// <summary>
  1078. /// 开立的生产入库单
  1079. /// </summary>
  1080. /// <param name="TransType"></param>
  1081. /// <param name="Identification"></param>
  1082. /// <param name="cmd"></param>
  1083. public static void ManufactureReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1084. {
  1085. try
  1086. {
  1087. #region ERP开立状态单据审核
  1088. string sql = @"IF EXISTS(SELECT b.ID FROM ICSManufactureReceive b
  1089. WHERE b.RCVCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1090. AND b.Quantity!=b.RCVQuantity)
  1091. BEGIN
  1092. RAISERROR('" + language.GetNameByCode("WMSAPIInfo096") + @"',16,1);
  1093. RETURN
  1094. END
  1095. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1096. FROM ICSWareHouseLotInfoLog a
  1097. INNER JOIN ICSManufactureReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1098. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1099. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  1100. WHERE a.Identification='{0}' AND ERPUpload='0'
  1101. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  1102. sql = string.Format(sql, Identification);
  1103. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1104. string Inputstr = JsonConvert.SerializeObject(dt);
  1105. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSManufactureReceiveURL, Inputstr);
  1106. Result result = new Result();
  1107. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1108. if (result.Success)
  1109. {
  1110. try
  1111. {
  1112. foreach (DataRow dr in dt.Rows)
  1113. {
  1114. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", cmd, language);
  1115. }
  1116. }
  1117. catch (Exception ex)
  1118. {
  1119. log.Debug(ex.ToString());
  1120. log.Debug(resultStr);
  1121. }
  1122. }
  1123. else
  1124. {
  1125. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1126. }
  1127. #endregion
  1128. }
  1129. catch (Exception)
  1130. {
  1131. throw;
  1132. }
  1133. }
  1134. #endregion
  1135. #region 返工工单
  1136. /// <summary>
  1137. /// 返工工单
  1138. /// </summary>
  1139. /// <param name="TransCode"></param>
  1140. /// <param name="TransSequence"></param>
  1141. /// <param name="Quantity"></param>
  1142. /// <param name="WorkPoint"></param>
  1143. /// <param name="cmd"></param>
  1144. public static void ReWorkReceiveMo(string LotNo, string Quantity, string WarehouseCode,
  1145. string LocationCode, string WorkPoint, String User, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1146. {
  1147. try
  1148. {
  1149. string sql = @"DECLARE @Status VARCHAR(10)
  1150. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  1151. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1152. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1153. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1154. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1155. IF (@Status IS NULL)
  1156. BEGIN
  1157. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1158. RETURN
  1159. END
  1160. ELSE IF (@Status='3')
  1161. BEGIN
  1162. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1163. RETURN
  1164. END
  1165. UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  1166. FROM ICSInventoryLot a
  1167. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1168. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1169. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1170. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1171. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1172. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1173. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1174. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1175. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.IssueQuantity>d.Quantity)
  1176. BEGIN
  1177. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1178. END";
  1179. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1180. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1181. {
  1182. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));//"生产工单更新失败!");
  1183. }
  1184. }
  1185. catch (Exception)
  1186. {
  1187. throw;
  1188. }
  1189. }
  1190. /// <summary>
  1191. /// 返工工单
  1192. /// </summary>
  1193. /// <param name="TransType"></param>
  1194. /// <param name="Identification"></param>
  1195. /// <param name="cmd"></param>
  1196. public static void ReWorkReceiveMoERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1197. {
  1198. try
  1199. {
  1200. #region ERP开立状态单据审核
  1201. 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,
  1202. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,d.PickID AS MODetailID,Enable AS UpdateTodoQuantity
  1203. ,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,
  1204. 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
  1205. INTO #TempERP
  1206. FROM ICSWareHouseLotInfoLog a
  1207. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1208. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1209. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1210. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1211. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1212. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1213. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1214. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1215. WHERE a.Identification='{0}' AND ERPUpload='0'
  1216. GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,d.PickID,Enable,d.Sequence
  1217. ,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, ''),
  1218. 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, '')
  1219. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  1220. SELECT Costre,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1221. FROM #TempERP
  1222. DROP TABLE #TempERP";
  1223. sql = string.Format(sql, Identification);
  1224. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1225. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1226. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSReWorkReceiveMoURL, Inputstr);
  1227. Result result = new Result();
  1228. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1229. if (result.Success)
  1230. {
  1231. try
  1232. {
  1233. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1234. foreach (var item in res)
  1235. {
  1236. JObject jo = (JObject)item;
  1237. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1238. foreach (var detail in resdetail)
  1239. {
  1240. JObject det = (JObject)detail;
  1241. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1242. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  1243. }
  1244. }
  1245. }
  1246. catch (Exception ex)
  1247. {
  1248. log.Debug(ex.ToString());
  1249. log.Debug(resultStr);
  1250. }
  1251. }
  1252. else
  1253. {
  1254. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1255. }
  1256. #endregion
  1257. }
  1258. catch (Exception)
  1259. {
  1260. throw;
  1261. }
  1262. }
  1263. #endregion
  1264. #region 生成产成品入库单
  1265. public static DataSet ManufactureLFReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1266. {
  1267. try
  1268. {
  1269. #region ERP开立状态单据审核
  1270. 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,
  1271. 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
  1272. ,a.WorkPoint, '' AS ProjectCode,'' AS BatchCode,'' AS Version,'' AS Brand,
  1273. '' AS cFree1,'' AS cFree2,'' AS cFree3,'' AS cFree4,'' AS cFree5,'' AS cFree6,'' AS cFree7,'' AS cFree8,'' AS cFree9,'' AS cFree10
  1274. INTO #TempERP
  1275. FROM ICSWareHouseLotInfoLog a
  1276. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1277. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1278. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1279. INNER JOIN ICSMO c ON a.TransCode=c.MOCode AND a.WorkPoint=c.WorkPoint
  1280. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and a.TransSequence=c.Sequence+'~'+d.Sequence
  1281. INNER JOIN Sys_SRM_User f ON f.F_Account=a.MUSER AND a.WorkPoint=f.F_Location
  1282. WHERE a.Identification='{0}' AND ERPUpload='0' and d.EATTRIBUTE1='1'
  1283. GROUP BY a.TransCode,a.MUSER,a.InvCode,d.PickID,Enable,d.Sequence
  1284. ,a.WorkPoint,f.F_DepartmentId,d.WHCode--,d.Quantity,c.Quantity,a.Quantity
  1285. SELECT DISTINCT '' as TYPE,Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  1286. SELECT Costre,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1287. FROM #TempERP
  1288. DROP TABLE #TempERP";
  1289. sql = string.Format(sql, Identification);
  1290. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1291. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1292. return ds;
  1293. //string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSReWorkReceiveMoURL, Inputstr);
  1294. //Result result = new Result();
  1295. //result = JsonConvert.DeserializeObject<Result>(resultStr);
  1296. //if (result.Success)
  1297. //{
  1298. // try
  1299. // {
  1300. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1301. // foreach (var item in res)
  1302. // {
  1303. // JObject jo = (JObject)item;
  1304. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1305. // foreach (var detail in resdetail)
  1306. // {
  1307. // JObject det = (JObject)detail;
  1308. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1309. // det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  1310. // }
  1311. // }
  1312. // }
  1313. // catch (Exception ex)
  1314. // {
  1315. // log.Debug(ex.ToString());
  1316. // log.Debug(resultStr);
  1317. // }
  1318. //}
  1319. //else
  1320. //{
  1321. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1322. //}
  1323. #endregion
  1324. }
  1325. catch (Exception)
  1326. {
  1327. throw;
  1328. }
  1329. }
  1330. #endregion
  1331. }
  1332. }
  1333. #endregion