纽威
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.

1186 lines
73 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 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, string BusinessCode)
  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*(x.Amount/x.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,conv.Enable AS CompleteVerification
  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. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  96. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '13'
  97. GROUP BY y.DepCode,a.FromWarehouseCode,y.MOCode,a.MUSER,a.InvCode,x.PickID,x.MODetailID,con.Enable,conv.Enable
  98. ,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, ''),
  99. 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, '')
  100. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  101. 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
  102. DROP TABLE #TempERP";
  103. sql = string.Format(sql, Identification);
  104. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  105. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  106. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueDocURL, Inputstr);
  107. Result result = new Result();
  108. result = JsonConvert.DeserializeObject<Result>(resultStr);
  109. if (result.Success)
  110. {
  111. try
  112. {
  113. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  114. foreach (var item in res)
  115. {
  116. JObject jo = (JObject)item;
  117. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  118. foreach (var detail in resdetail)
  119. {
  120. JObject det = (JObject)detail;
  121. string allcol = jo["cWhCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  122. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  123. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  124. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  125. }
  126. }
  127. }
  128. catch (Exception ex)
  129. {
  130. log.Debug(ex.ToString());
  131. log.Debug(resultStr);
  132. }
  133. }
  134. else
  135. {
  136. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  137. }
  138. #endregion
  139. }
  140. catch (Exception)
  141. {
  142. throw;
  143. }
  144. }
  145. #endregion
  146. #region 领料申请单生产发料
  147. /// <summary>
  148. /// 领料申请单生产发料
  149. /// </summary>
  150. /// <param name="TransCode"></param>
  151. /// <param name="TransSequence"></param>
  152. /// <param name="Quantity"></param>
  153. /// <param name="WorkPoint"></param>
  154. /// <param name="cmd"></param>
  155. public static void MOApply(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  156. {
  157. try
  158. {
  159. string sql = @"DECLARE @Status VARCHAR(10)
  160. SELECT @Status=a.Status FROM ICSMOApply a
  161. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  162. IF (@Status IS NULL)
  163. BEGIN
  164. RAISERROR('" + language.GetNameByCode("WMSAPIInfo128") + @"',16,1);
  165. RETURN
  166. END
  167. ELSE IF (@Status!='2')
  168. BEGIN
  169. RAISERROR('" + language.GetNameByCode("WMSAPIInfo129") + @"',16,1);
  170. RETURN
  171. END
  172. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  173. FROM ICSMOApply a
  174. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  175. IF EXISTS(SELECT a.ID FROM ICSMOApply a
  176. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  177. BEGIN
  178. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  179. RETURN
  180. END";
  181. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  182. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  183. {
  184. throw new Exception(language.GetNameByCode("WMSAPIInfo130"));//"领料申请单更新失败!");
  185. }
  186. }
  187. catch (Exception)
  188. {
  189. throw;
  190. }
  191. }
  192. /// <summary>
  193. /// 领料申请单发料确认(记录发料人员)
  194. /// </summary>
  195. /// <param name="TransCode"></param>
  196. /// <param name="TransSequence"></param>
  197. /// <param name="Quantity"></param>
  198. /// <param name="WorkPoint"></param>
  199. /// <param name="cmd"></param>
  200. /// <param name="language"></param>
  201. public static void MOApplySaveUser(string TransCode, string MuserName, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  202. {
  203. try
  204. {
  205. string sql = @"DECLARE @Status VARCHAR(10)
  206. SELECT @Status=a.Status FROM ICSMOApply a
  207. WHERE a.ApplyCode='{0}' AND a.WorkPoint='{1}'
  208. IF (@Status IS NULL)
  209. BEGIN
  210. RAISERROR('" + language.GetNameByCode("WMSAPIInfo130") + @"',16,1);
  211. RETURN
  212. END
  213. UPDATE a SET MUSERNAME='{2}'
  214. FROM ICSMOApply a
  215. WHERE a.ApplyCode='{0}' AND a.WorkPoint='{1}'";
  216. sql = string.Format(sql, TransCode, WorkPoint, MuserName);
  217. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  218. {
  219. throw new Exception(language.GetNameByCode("WMSAPIInfo204"));//"领料申请单确认人员更新失败!");
  220. }
  221. }
  222. catch (Exception)
  223. {
  224. throw;
  225. }
  226. }
  227. /// <summary>
  228. /// 领料申请单生产发料接口(SAP)
  229. /// </summary>
  230. /// <param name="TransType"></param>
  231. /// <param name="Identification"></param>
  232. /// <param name="cmd"></param>
  233. public static void MOApplyERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  234. {
  235. try
  236. {
  237. #region SAP
  238. string IsSuccess = "";
  239. string ErrorMessage = "";
  240. string sql = @" select Distinct A.ApplyCode,A.WorkPoint from ICSMOApply A
  241. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.ApplyCode AND B.WorkPoint=A.WorkPoint
  242. where B.Identification='{0}' AND BusinessCode='14'";
  243. sql = string.Format(sql, Identification);
  244. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  245. if (dt.Rows.Count > 1)
  246. {
  247. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  248. }
  249. for (int i = 0; i < dt.Rows.Count; i++)
  250. {
  251. string chksql = @"select SUM(Quantity) AS Quantity,SUM(IssueQuantity) AS IssueQuantity from ICSMOApply
  252. where ApplyCode='{0}' and WorkPoint='{1}'
  253. GROUP BY ApplyCode,WorkPoint";
  254. chksql = string.Format(chksql, dt.Rows[i]["ApplyCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  255. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  256. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["IssueQuantity"]))
  257. {
  258. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo203"), chkdt.Rows[0]["Quantity"].ToString(), chkdt.Rows[0]["IssueQuantity"].ToString()));//单次提交数量卡控(必须整单提交)
  259. }
  260. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  261. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  262. Info.NEWID = Identification;
  263. Info.DANJU = dt.Rows[i]["ApplyCode"].ToString();
  264. Info.STATE = "1";
  265. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  266. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  267. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  268. sql = @"select A.ApplyCode,A.Sequence,A.Quantity,A.IssueQuantity,B.BatchCode from ICSMOApply A
  269. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  270. WHERE ApplyCode='{0}' AND A.WorkPoint='{1}'";
  271. sql = string.Format(sql, dt.Rows[i]["ApplyCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  272. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  273. foreach (DataRow dr in Sapdt.Rows)
  274. {
  275. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["IssueQuantity"].ToString()))
  276. {
  277. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  278. Item.DANJU = dr["ApplyCode"].ToString();
  279. Item.POSNR = dr["Sequence"].ToString();
  280. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  281. Item.SERNP = dr["BatchCode"].ToString();
  282. ItemList.Add(Item);
  283. }
  284. }
  285. if (ItemList.Count > 0)
  286. {
  287. Info.Z_ITEM = ItemList.ToArray();
  288. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  289. result = Client.CallZWMS_SK_WS_PZ(Info);
  290. if (result.Z_NULL == "N")
  291. {
  292. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  293. {
  294. IsSuccess = "N";
  295. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  296. }
  297. }
  298. }
  299. }
  300. if (IsSuccess == "N")
  301. {
  302. throw new Exception(ErrorMessage);
  303. }
  304. #endregion
  305. }
  306. catch (Exception ex)
  307. {
  308. throw;
  309. }
  310. }
  311. /// <summary>
  312. /// 领料申请单过账SAP
  313. /// </summary>
  314. /// <param name="TransCode"></param>
  315. /// <param name="MuserName"></param>
  316. /// <param name="WorkPoint"></param>
  317. /// <param name="cmd"></param>
  318. /// <param name="language"></param>
  319. public static void MOApplySAPGZ(string TransCode, string MuserName, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  320. {
  321. try
  322. {
  323. #region SAP
  324. string IsSuccess = "";
  325. string ErrorMessage = "";
  326. string sql = @"select A.ID,A.ApplyCode,A.Sequence,A.Quantity,A.IssueQuantity,B.BatchCode from ICSMOApply A
  327. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  328. WHERE ApplyCode='{0}' AND A.WorkPoint='{1}'";
  329. sql = string.Format(sql, TransCode, WorkPoint);
  330. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  331. if (Sapdt.Rows.Count == 0)
  332. {
  333. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo205"), TransCode));//单据查询失败
  334. }
  335. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  336. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  337. Info.NEWID = Sapdt.Rows[0]["ID"].ToString();
  338. Info.DANJU = TransCode;
  339. Info.STATE = "0";
  340. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  341. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  342. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  343. foreach (DataRow dr in Sapdt.Rows)
  344. {
  345. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["IssueQuantity"].ToString()))
  346. {
  347. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  348. Item.DANJU = dr["ApplyCode"].ToString();
  349. Item.POSNR = dr["Sequence"].ToString();
  350. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  351. Item.SERNP = dr["BatchCode"].ToString();
  352. ItemList.Add(Item);
  353. }
  354. }
  355. if (ItemList.Count > 0)
  356. {
  357. Info.Z_ITEM = ItemList.ToArray();
  358. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  359. result = Client.CallZWMS_SK_WS_PZ(Info);
  360. if (result.Z_NULL == "N")
  361. {
  362. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  363. {
  364. IsSuccess = "N";
  365. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  366. }
  367. }
  368. }
  369. if (IsSuccess == "N")
  370. {
  371. throw new Exception(ErrorMessage);
  372. }
  373. #endregion
  374. }
  375. catch (Exception)
  376. {
  377. throw;
  378. }
  379. }
  380. #endregion
  381. #region 材料出库单生产发料
  382. /// <summary>
  383. /// 材料出库单生产发料
  384. /// </summary>
  385. /// <param name="TransCode"></param>
  386. /// <param name="TransSequence"></param>
  387. /// <param name="Quantity"></param>
  388. /// <param name="WorkPoint"></param>
  389. /// <param name="cmd"></param>
  390. public static void MOIssue(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  391. {
  392. try
  393. {
  394. string sql = @"DECLARE @Status VARCHAR(10)
  395. SELECT @Status=a.Status FROM ICSMOIssue a
  396. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  397. IF (@Status IS NULL)
  398. BEGIN
  399. RAISERROR('" + language.GetNameByCode("WMSAPIInfo131") + @"',16,1);
  400. RETURN
  401. END
  402. --ELSE IF (@Status!='1')
  403. --BEGIN
  404. --RAISERROR('" + language.GetNameByCode("WMSAPIInfo132") + @"',16,1);
  405. --RETURN
  406. --END
  407. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  408. FROM ICSMOIssue a
  409. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  410. IF EXISTS(SELECT a.ID FROM ICSMOIssue a
  411. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  412. BEGIN
  413. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  414. RETURN
  415. END";
  416. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  417. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  418. {
  419. throw new Exception(language.GetNameByCode("WMSAPIInfo133"));//"材料出库单更新失败!");
  420. }
  421. }
  422. catch (Exception)
  423. {
  424. throw;
  425. }
  426. }
  427. /// <summary>
  428. /// 材料出库单生产发料接口
  429. /// </summary>
  430. /// <param name="TransType"></param>
  431. /// <param name="Identification"></param>
  432. /// <param name="cmd"></param>
  433. public static void MOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  434. {
  435. try
  436. {
  437. #region ERP开立状态单据审核
  438. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  439. INNER JOIN ICSMOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  440. WHERE a.Identification='{0}' AND b.Quantity!=b.IssueQuantity)
  441. BEGIN
  442. RAISERROR('" + language.GetNameByCode("WMSAPIInfo094") + @"',16,1);
  443. RETURN
  444. END
  445. SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity
  446. ,conStock.Enable AS UpdateStock,a.WorkPoint
  447. FROM ICSWareHouseLotInfoLog a
  448. INNER JOIN ICSMOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  449. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  450. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  451. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '15'
  452. GROUP BY b.IssueID,a.MUSER,con.Enable
  453. ,conStock.Enable,a.WorkPoint";
  454. sql = string.Format(sql, Identification);
  455. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  456. string Inputstr = JsonConvert.SerializeObject(dt);
  457. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueURL, Inputstr);
  458. Result result = new Result();
  459. result = JsonConvert.DeserializeObject<Result>(resultStr);
  460. if (result.Success)
  461. {
  462. try
  463. {
  464. foreach (DataRow dr in dt.Rows)
  465. {
  466. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  467. }
  468. }
  469. catch (Exception ex)
  470. {
  471. log.Debug(ex.ToString());
  472. log.Debug(resultStr);
  473. }
  474. }
  475. else
  476. {
  477. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  478. }
  479. #endregion
  480. }
  481. catch (Exception)
  482. {
  483. throw;
  484. }
  485. }
  486. #endregion
  487. #region 生产退料
  488. /// <summary>
  489. /// 生产退料
  490. /// </summary>
  491. /// <param name="TransCode"></param>
  492. /// <param name="TransSequence"></param>
  493. /// <param name="Quantity"></param>
  494. /// <param name="WorkPoint"></param>
  495. /// <param name="cmd"></param>
  496. public static void MOIssueDocNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  497. {
  498. try
  499. {
  500. string table = "";
  501. string sql = "";
  502. if (string.IsNullOrWhiteSpace(LogID))
  503. {
  504. string type = "";
  505. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  506. {
  507. table = "INNER JOIN ICSMOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint";
  508. type = "1";
  509. }
  510. //改动 生产退料 -生产退料单 - 领料申请单 和发料申请单没有关系
  511. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  512. {
  513. //table = "INNER JOIN ICSMOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
  514. type = "2";
  515. }
  516. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  517. {
  518. table = "INNER JOIN ICSMOIssue e ON c.SourceDetailID=e.IssueDetailID AND c.WorkPoint=e.WorkPoint";
  519. type = "3";
  520. }
  521. else
  522. {
  523. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  524. }
  525. #region 新条码
  526. if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  527. {
  528. sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  529. FROM ICSInventoryLot a
  530. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  531. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  532. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  533. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  534. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  535. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  536. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  537. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  538. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND c.Quantity<c.IssueNegQuantity)
  539. BEGIN
  540. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  541. END";
  542. }
  543. else
  544. {
  545. sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  546. FROM ICSInventoryLot a
  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 ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  550. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  551. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  552. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  553. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  554. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  555. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND c.Quantity<c.IssueNegQuantity)
  556. BEGIN
  557. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  558. END
  559. UPDATE e SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  560. FROM ICSInventoryLot a
  561. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  562. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  563. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  564. {3}
  565. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  566. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  567. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  568. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  569. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  570. {3}
  571. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND e.IssueQuantity<0)
  572. BEGIN
  573. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  574. END";
  575. }
  576. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type);
  577. #endregion
  578. }
  579. else
  580. {
  581. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  582. {
  583. table = @"INNER JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  584. INNER JOIN ICSMOPick c ON b.MODetailID = c.MODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
  585. }
  586. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  587. {
  588. table = "INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  589. }
  590. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  591. {
  592. table = "INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  593. }
  594. else
  595. {
  596. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  597. }
  598. #region 原条码
  599. sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  600. FROM ICSWareHouseLotInfoLog a
  601. {3}
  602. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}'
  603. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
  604. {3}
  605. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0)
  606. BEGIN
  607. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  608. END";
  609. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID);
  610. #endregion
  611. }
  612. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  613. {
  614. throw new Exception(language.GetNameByCode("WMSAPIInfo134"));//"生产退料单更新失败!");
  615. }
  616. }
  617. catch (Exception)
  618. {
  619. throw;
  620. }
  621. }
  622. /// <summary>
  623. /// 生产退料接口
  624. /// </summary>
  625. /// <param name="TransType"></param>
  626. /// <param name="Identification"></param>
  627. /// <param name="cmd"></param>
  628. public static void MOIssueDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  629. {
  630. try
  631. {
  632. #region SAP
  633. string IsSuccess = "";
  634. string ErrorMessage = "";
  635. string sql = @" select Distinct A.ApplyNegCode,A.WorkPoint from ICSMOApplyNeg A
  636. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.ApplyNegCode AND B.WorkPoint=A.WorkPoint
  637. where B.Identification='{0}' AND BusinessCode='16'";
  638. sql = string.Format(sql, Identification);
  639. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  640. if (dt.Rows.Count > 1)
  641. {
  642. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  643. }
  644. for (int i = 0; i < dt.Rows.Count; i++)
  645. {
  646. string chksql = @"select SUM(B.Quantity) AS Quantity,SUM(B.IssueNegQuantity) AS IssueQuantity from ICSMOApplyNeg A
  647. LEFT JOIN ICSMOApplyNegDetail B ON B.ApplyNegCode=A.ApplyNegCode AND B.WorkPoint=A.WorkPoint
  648. where A.ApplyNegCode='{0}' and A.WorkPoint='{1}'
  649. GROUP BY A.ApplyNegCode,A.WorkPoint";
  650. chksql = string.Format(chksql, dt.Rows[i]["ApplyNegCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  651. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  652. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["IssueQuantity"]))
  653. {
  654. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo203"), chkdt.Rows[0]["Quantity"].ToString(), chkdt.Rows[0]["IssueQuantity"].ToString()));//单次提交数量卡控(必须整单提交)
  655. }
  656. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  657. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  658. Info.NEWID = Identification;
  659. Info.DANJU = dt.Rows[i]["ApplyNegCode"].ToString();
  660. Info.STATE = "0";
  661. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  662. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  663. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  664. sql = @" select A.ApplyNegCode,B.Sequence,B.Quantity,B.IssueNegQuantity,C.BatchCode from ICSMOApplyNeg A
  665. LEFT JOIN ICSMOApplyNegDetail B ON B.ApplyNegCode=A.ApplyNegCode AND B.WorkPoint=A.WorkPoint
  666. LEFT JOIN ICSExtension C ON C.ID=B.ExtensionID AND C.WorkPoint=B.WorkPoint
  667. WHERE A.ApplyNegCode='{0}' AND A.WorkPoint='{1}'";
  668. sql = string.Format(sql, dt.Rows[i]["ApplyNegCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  669. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  670. foreach (DataRow dr in Sapdt.Rows)
  671. {
  672. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["IssueNegQuantity"].ToString()))
  673. {
  674. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  675. Item.DANJU = dr["ApplyNegCode"].ToString();
  676. Item.POSNR = dr["Sequence"].ToString();
  677. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  678. Item.SERNP = dr["BatchCode"].ToString();
  679. ItemList.Add(Item);
  680. }
  681. }
  682. if (ItemList.Count > 0)
  683. {
  684. Info.Z_ITEM = ItemList.ToArray();
  685. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  686. result = Client.CallZWMS_SK_WS_PZ(Info);
  687. if (result.Z_NULL == "N")
  688. {
  689. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  690. {
  691. IsSuccess = "N";
  692. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  693. }
  694. }
  695. }
  696. }
  697. if (IsSuccess == "N")
  698. {
  699. throw new Exception(ErrorMessage);
  700. }
  701. #endregion
  702. }
  703. catch (Exception)
  704. {
  705. throw;
  706. }
  707. }
  708. #endregion
  709. #region 生产入库
  710. /// <summary>
  711. /// 生产入库
  712. /// </summary>
  713. /// <param name="TransCode"></param>
  714. /// <param name="TransSequence"></param>
  715. /// <param name="Quantity"></param>
  716. /// <param name="WorkPoint"></param>
  717. /// <param name="cmd"></param>
  718. public static void ManufactureReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  719. {
  720. try
  721. {
  722. string sql = @"DECLARE @Status VARCHAR(10)
  723. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  724. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  725. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  726. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  727. IF (@Status IS NULL)
  728. BEGIN
  729. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  730. RETURN
  731. END
  732. ELSE IF (@Status='3')
  733. BEGIN
  734. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  735. RETURN
  736. END
  737. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  738. FROM ICSInventoryLot a
  739. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  740. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  741. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  742. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  743. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  744. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  745. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.RCVQuantity)
  746. BEGIN
  747. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  748. END";
  749. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  750. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  751. {
  752. throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
  753. }
  754. }
  755. catch (Exception)
  756. {
  757. throw;
  758. }
  759. }
  760. /// <summary>
  761. /// 生产入库接口
  762. /// </summary>
  763. /// <param name="TransType"></param>
  764. /// <param name="Identification"></param>
  765. /// <param name="cmd"></param>
  766. public static void ManufactureReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  767. {
  768. try
  769. {
  770. #region ERP
  771. string sql = @"SELECT c.DepCode+a.ToWarehouseCode+c.MOCode+a.MUSER AS Costre,c.MODetailID+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, '')+
  772. 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, '') 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,
  773. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,c.MODetailID,con.Enable AS UpdateTodoQuantity
  774. ,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,
  775. 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
  776. INTO #TempERP
  777. FROM ICSWareHouseLotInfoLog a
  778. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  779. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  780. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  781. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  782. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  783. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  784. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  785. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  786. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  787. GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,c.MODetailID,con.Enable,conv.Enable
  788. ,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, ''),
  789. 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
  790. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  791. SELECT Costre,Costre2,TransSequence,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  792. FROM #TempERP
  793. SELECT a.FromWarehouseCode AS WHCode,c.MODetailID+te.ProjectCode+te.BatchCode+te.Version+te.Brand+te.cFree1+te.cFree2+te.cFree3+te.cFree4+te.cFree5+te.cFree6+te.cFree7+te.cFree8+te.cFree9+te.cFree10 AS Costre2,a.TransCode,a.TransSequence AS Sequence,a.InvCode,SUM(c.Quantity/b.Quantity*a.Quantity) as Quantity,SUM((c.Quantity/b.Quantity*a.Quantity)*(c.Amount/c.Quantity)) AS 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
  794. FROM ICSWareHouseLotInfoLog a
  795. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  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. INNER JOIN #TempERP te ON te.TransSequence=SUBSTRING(a.TransSequence,1,CHARINDEX('~',a.TransSequence)-1)
  802. WHERE a.Identification='{0}' AND a.TransType='12'
  803. GROUP BY a.FromWarehouseCode,c.MODetailID,a.TransCode,a.TransSequence,a.InvCode,c.PickID,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, ''),
  804. 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,te.ProjectCode,te.BatchCode,te.Version,te.Brand,te.cFree1,te.cFree2,te.cFree3,te.cFree4,te.cFree5,te.cFree6,te.cFree7,te.cFree8,te.cFree9,te.cFree10
  805. DROP TABLE #TempERP";
  806. sql = string.Format(sql, Identification, BusinessCode);
  807. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  808. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "detailss", "Costre2");
  809. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ManufactureReceiveDocURL, Inputstr);
  810. Result result = new Result();
  811. result = JsonConvert.DeserializeObject<Result>(resultStr);
  812. if (result.Success)
  813. {
  814. try
  815. {
  816. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  817. foreach (var item in res)
  818. {
  819. JObject jo = (JObject)item;
  820. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  821. foreach (var detail in resdetail)
  822. {
  823. JObject det = (JObject)detail;
  824. string allcol = "" + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  825. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  826. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  827. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  828. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  829. foreach (var details in resdetails)
  830. {
  831. JObject dets = (JObject)details;
  832. if (dets != null)
  833. {
  834. //直接回写
  835. string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  836. FROM ICSWareHouseLotInfoLog a
  837. LEFT JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  838. LEFT JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  839. WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{6}'";
  840. ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString()
  841. , dets["Sequence"].ToString(), BusinessCode);
  842. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  843. {
  844. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"成品倒冲回写失败!";
  845. }
  846. }
  847. }
  848. }
  849. }
  850. }
  851. catch (Exception ex)
  852. {
  853. log.Debug(ex.ToString());
  854. log.Debug(resultStr);
  855. throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  856. }
  857. }
  858. else
  859. {
  860. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  861. }
  862. #endregion
  863. }
  864. catch (Exception)
  865. {
  866. throw;
  867. }
  868. }
  869. #endregion
  870. #region 开立的生产入库单
  871. /// <summary>
  872. /// 开立的生产入库单
  873. /// </summary>
  874. /// <param name="TransCode"></param>
  875. /// <param name="TransSequence"></param>
  876. /// <param name="Quantity"></param>
  877. /// <param name="WorkPoint"></param>
  878. /// <param name="cmd"></param>
  879. public static void ManufactureReceive(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  880. {
  881. try
  882. {
  883. string sql = @"DECLARE @Status VARCHAR(10)
  884. SELECT @Status=c.Status FROM ICSInventoryLot a
  885. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  886. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  887. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  888. IF (@Status IS NULL)
  889. BEGIN
  890. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  891. RETURN
  892. END
  893. ELSE IF (@Status!='1')
  894. BEGIN
  895. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  896. RETURN
  897. END
  898. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  899. FROM ICSInventoryLot a
  900. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  901. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  902. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  903. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  904. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  905. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  906. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1' AND c.Quantity<c.RCVQuantity)
  907. BEGIN
  908. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  909. END";
  910. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  911. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  912. {
  913. throw new Exception(language.GetNameByCode("WMSAPIInfo138"));//"生产入库单更新失败!");
  914. }
  915. }
  916. catch (Exception)
  917. {
  918. throw;
  919. }
  920. }
  921. /// <summary>
  922. /// 开立的生产入库单
  923. /// </summary>
  924. /// <param name="TransType"></param>
  925. /// <param name="Identification"></param>
  926. /// <param name="cmd"></param>
  927. public static void ManufactureReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  928. {
  929. try
  930. {
  931. #region SAP
  932. string IsSuccess = "";
  933. string ErrorMessage = "";
  934. string sql = @" select Distinct A.RCVCode,A.WorkPoint from ICSManufactureReceive A
  935. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.RCVCode AND B.WorkPoint=A.WorkPoint
  936. where B.Identification='{0}' AND BusinessCode='18'";
  937. sql = string.Format(sql, Identification);
  938. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  939. if (dt.Rows.Count > 1)
  940. {
  941. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  942. }
  943. for (int i = 0; i < dt.Rows.Count; i++)
  944. {
  945. string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSManufactureReceive
  946. where RCVCode='{0}' and WorkPoint='{1}'
  947. GROUP BY RCVCode,WorkPoint";
  948. chksql = string.Format(chksql, dt.Rows[i]["RCVCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  949. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  950. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["RCVQuantity"]))
  951. {
  952. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo203"), chkdt.Rows[0]["Quantity"].ToString(), chkdt.Rows[0]["RCVQuantity"].ToString()));//单次提交数量卡控(必须整单提交)
  953. }
  954. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  955. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  956. Info.NEWID = Identification;
  957. Info.DANJU = dt.Rows[i]["RCVCode"].ToString();
  958. Info.STATE = "0";
  959. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  960. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  961. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  962. sql = @"select A.RCVCode,A.Sequence,A.Quantity,A.RCVQuantity,B.BatchCode from ICSManufactureReceive A
  963. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  964. WHERE RCVCode='{0}' AND A.WorkPoint='{1}'";
  965. sql = string.Format(sql, dt.Rows[i]["RCVCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  966. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  967. foreach (DataRow dr in Sapdt.Rows)
  968. {
  969. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["RCVQuantity"].ToString()))
  970. {
  971. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  972. Item.DANJU = dr["RCVCode"].ToString();
  973. Item.POSNR = dr["Sequence"].ToString();
  974. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  975. Item.SERNP = dr["BatchCode"].ToString();
  976. ItemList.Add(Item);
  977. }
  978. }
  979. if (ItemList.Count > 0)
  980. {
  981. Info.Z_ITEM = ItemList.ToArray();
  982. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  983. result = Client.CallZWMS_SK_WS_PZ(Info);
  984. if (result.Z_NULL == "N")
  985. {
  986. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  987. {
  988. IsSuccess = "N";
  989. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  990. }
  991. }
  992. }
  993. }
  994. if (IsSuccess == "N")
  995. {
  996. throw new Exception(ErrorMessage);
  997. }
  998. #endregion
  999. }
  1000. catch (Exception)
  1001. {
  1002. throw;
  1003. }
  1004. }
  1005. #endregion
  1006. #region 返工工单
  1007. /// <summary>
  1008. /// 返工工单
  1009. /// </summary>
  1010. /// <param name="TransCode"></param>
  1011. /// <param name="TransSequence"></param>
  1012. /// <param name="Quantity"></param>
  1013. /// <param name="WorkPoint"></param>
  1014. /// <param name="cmd"></param>
  1015. public static void ReWorkReceiveMo(string LotNo, string Quantity, string WarehouseCode,
  1016. string LocationCode, string WorkPoint, String User, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1017. {
  1018. try
  1019. {
  1020. string sql = @"DECLARE @Status VARCHAR(10)
  1021. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  1022. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1023. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1024. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1025. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1026. IF (@Status IS NULL)
  1027. BEGIN
  1028. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1029. RETURN
  1030. END
  1031. ELSE IF (@Status='3')
  1032. BEGIN
  1033. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1034. RETURN
  1035. END
  1036. UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  1037. FROM ICSInventoryLot a
  1038. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1039. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1040. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1041. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1042. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1043. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1044. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1045. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1046. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.IssueQuantity>d.Quantity)
  1047. BEGIN
  1048. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1049. END";
  1050. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1051. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1052. {
  1053. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));//"生产工单更新失败!");
  1054. }
  1055. }
  1056. catch (Exception)
  1057. {
  1058. throw;
  1059. }
  1060. }
  1061. /// <summary>
  1062. /// 返工工单
  1063. /// </summary>
  1064. /// <param name="TransType"></param>
  1065. /// <param name="Identification"></param>
  1066. /// <param name="cmd"></param>
  1067. public static void ReWorkReceiveMoERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1068. {
  1069. try
  1070. {
  1071. #region ERP开立状态单据审核
  1072. 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,
  1073. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,d.PickID AS MODetailID,Enable AS UpdateTodoQuantity
  1074. ,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,
  1075. 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
  1076. INTO #TempERP
  1077. FROM ICSWareHouseLotInfoLog a
  1078. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1079. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1080. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1081. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1082. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1083. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1084. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1085. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1086. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1087. GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,d.PickID,Enable,d.Sequence
  1088. ,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, ''),
  1089. 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, '')
  1090. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  1091. SELECT Costre,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1092. FROM #TempERP
  1093. DROP TABLE #TempERP";
  1094. sql = string.Format(sql, Identification, BusinessCode);
  1095. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1096. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1097. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSReWorkReceiveMoURL, Inputstr);
  1098. Result result = new Result();
  1099. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1100. if (result.Success)
  1101. {
  1102. try
  1103. {
  1104. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1105. foreach (var item in res)
  1106. {
  1107. JObject jo = (JObject)item;
  1108. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1109. foreach (var detail in resdetail)
  1110. {
  1111. JObject det = (JObject)detail;
  1112. string col = jo["cWhCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  1113. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1114. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1115. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), col, cmd, language, BusinessCode);
  1116. }
  1117. }
  1118. }
  1119. catch (Exception ex)
  1120. {
  1121. log.Debug(ex.ToString());
  1122. log.Debug(resultStr);
  1123. }
  1124. }
  1125. else
  1126. {
  1127. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1128. }
  1129. #endregion
  1130. }
  1131. catch (Exception)
  1132. {
  1133. throw;
  1134. }
  1135. }
  1136. #endregion
  1137. }
  1138. }