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

1417 lines
105 KiB

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