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

1377 lines
81 KiB

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