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

1296 lines
78 KiB

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