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

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