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

1404 lines
104 KiB

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