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

1363 lines
102 KiB

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