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

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