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

1350 lines
80 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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
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="WorkPoint"></param>
  567. /// <param name="cmd"></param>
  568. /// <param name="language"></param>
  569. public static void MOIssueDocNegativeHG(string TransCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  570. {
  571. try
  572. {
  573. string sql = "";
  574. sql = @" Update ICSMOApplyNegDetail set IssueNegQuantity=Quantity
  575. where ApplyNegCode='{0}' and WorkPoint='{1}'";
  576. sql = string.Format(sql, TransCode, WorkPoint);
  577. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  578. {
  579. throw new Exception(language.GetNameByCode("WMSAPIInfo134"));//"生产退料单更新失败!");
  580. }
  581. }
  582. catch (Exception)
  583. {
  584. throw;
  585. }
  586. }
  587. /// <summary>
  588. /// 生产退料
  589. /// </summary>
  590. /// <param name="TransCode"></param>
  591. /// <param name="TransSequence"></param>
  592. /// <param name="Quantity"></param>
  593. /// <param name="WorkPoint"></param>
  594. /// <param name="cmd"></param>
  595. public static void MOIssueDocNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  596. {
  597. try
  598. {
  599. string table = "";
  600. string sql = "";
  601. if (string.IsNullOrWhiteSpace(LogID))
  602. {
  603. string type = "";
  604. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  605. {
  606. table = "INNER JOIN ICSMOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint";
  607. type = "1";
  608. }
  609. //改动 生产退料 -生产退料单 - 领料申请单 和发料申请单没有关系
  610. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  611. {
  612. //table = "INNER JOIN ICSMOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
  613. type = "2";
  614. }
  615. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  616. {
  617. table = "INNER JOIN ICSMOIssue e ON c.SourceDetailID=e.IssueDetailID AND c.WorkPoint=e.WorkPoint";
  618. type = "3";
  619. }
  620. else
  621. {
  622. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  623. }
  624. #region 新条码
  625. if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  626. {
  627. sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  628. FROM ICSInventoryLot a
  629. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  630. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  631. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  632. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  633. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  634. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  635. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  636. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  637. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND c.Quantity<c.IssueNegQuantity)
  638. BEGIN
  639. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  640. END";
  641. }
  642. else
  643. {
  644. sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  645. FROM ICSInventoryLot a
  646. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  647. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  648. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  649. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  650. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  651. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  652. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  653. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  654. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND c.Quantity<c.IssueNegQuantity)
  655. BEGIN
  656. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  657. END
  658. UPDATE e SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  659. FROM ICSInventoryLot a
  660. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  661. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  662. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  663. {3}
  664. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  665. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  666. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  667. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  668. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  669. {3}
  670. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND e.IssueQuantity<0)
  671. BEGIN
  672. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  673. END";
  674. }
  675. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type);
  676. #endregion
  677. }
  678. else
  679. {
  680. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  681. {
  682. table = @"INNER JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  683. INNER JOIN ICSMOPick c ON b.MODetailID = c.MODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
  684. }
  685. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  686. {
  687. table = "INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  688. }
  689. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  690. {
  691. table = "INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  692. }
  693. else
  694. {
  695. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  696. }
  697. #region 原条码
  698. sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  699. FROM ICSWareHouseLotInfoLog a
  700. {3}
  701. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}'
  702. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
  703. {3}
  704. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0)
  705. BEGIN
  706. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  707. END";
  708. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID);
  709. #endregion
  710. }
  711. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  712. {
  713. throw new Exception(language.GetNameByCode("WMSAPIInfo134"));//"生产退料单更新失败!");
  714. }
  715. }
  716. catch (Exception)
  717. {
  718. throw;
  719. }
  720. }
  721. /// <summary>
  722. /// 生产退料接口
  723. /// </summary>
  724. /// <param name="TransType"></param>
  725. /// <param name="Identification"></param>
  726. /// <param name="cmd"></param>
  727. public static void MOIssueDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  728. {
  729. try
  730. {
  731. #region SAP(三层结构)
  732. string IsSuccess = "";
  733. string ErrorMessage = "";
  734. string sql = @" select Distinct A.ApplyNegCode,A.WorkPoint from ICSMOApplyNeg A
  735. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.ApplyNegCode AND B.WorkPoint=A.WorkPoint
  736. where B.Identification='{0}' AND BusinessCode='16'";
  737. sql = string.Format(sql, Identification);
  738. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  739. if (dt.Rows.Count > 1)
  740. {
  741. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  742. }
  743. for (int i = 0; i < dt.Rows.Count; i++)
  744. {
  745. string chksql = @"select SUM(B.Quantity) AS Quantity,SUM(B.IssueNegQuantity) AS IssueQuantity from ICSMOApplyNeg A
  746. LEFT JOIN ICSMOApplyNegDetail B ON B.ApplyNegCode=A.ApplyNegCode AND B.WorkPoint=A.WorkPoint
  747. where A.ApplyNegCode='{0}' and A.WorkPoint='{1}'
  748. GROUP BY A.ApplyNegCode,A.WorkPoint";
  749. chksql = string.Format(chksql, dt.Rows[i]["ApplyNegCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  750. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  751. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) == Convert.ToDecimal(chkdt.Rows[0]["IssueQuantity"]))
  752. {
  753. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  754. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  755. Info.NEWID = Identification;
  756. Info.DANJU = dt.Rows[i]["ApplyNegCode"].ToString();
  757. Info.STATE = "0";
  758. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  759. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  760. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  761. sql = @" select A.ApplyNegCode,B.SAPSequence,B.InvCode,B.Sequence,B.Quantity,B.IssueNegQuantity
  762. ,ISNULL(C.BatchCode,'') AS BatchCode from ICSMOApplyNeg A
  763. LEFT JOIN ICSMOApplyNegDetail B ON B.ApplyNegCode=A.ApplyNegCode AND B.WorkPoint=A.WorkPoint
  764. LEFT JOIN ICSExtension C ON C.ID=B.ExtensionID AND C.WorkPoint=B.WorkPoint
  765. WHERE A.ApplyNegCode='{0}' AND A.WorkPoint='{1}'";
  766. sql = string.Format(sql, dt.Rows[i]["ApplyNegCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  767. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  768. foreach (DataRow dr in Sapdt.Rows)
  769. {
  770. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["IssueNegQuantity"].ToString()))
  771. {
  772. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  773. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  774. Item.DANJU = dr["ApplyNegCode"].ToString();
  775. Item.POSNR = dr["SAPSequence"].ToString();
  776. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  777. ItemList.Add(Item);
  778. if (dr["BatchCode"].ToString() != "")
  779. {
  780. ItemLine.DANJU = dr["ApplyNegCode"].ToString();
  781. ItemLine.POSNR = dr["SAPSequence"].ToString();
  782. ItemLine.MATNR = dr["InvCode"].ToString();
  783. ItemLine.GERNR = dr["BatchCode"].ToString();
  784. ItemLineList.Add(ItemLine);
  785. }
  786. }
  787. }
  788. if (ItemList.Count > 0)
  789. {
  790. Info.Z_ITEM = ItemList.ToArray();
  791. if (ItemLineList.Count > 0)
  792. {
  793. Info.Z_GERNR = ItemLineList.ToArray();
  794. }
  795. else
  796. {
  797. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  798. }
  799. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  800. result = Client.CallZWMS_SK_WS_PZ(Info);
  801. if (result.Z_NULL == "N")
  802. {
  803. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  804. {
  805. IsSuccess = "N";
  806. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  807. }
  808. }
  809. }
  810. }
  811. }
  812. if (IsSuccess == "N")
  813. {
  814. throw new Exception(ErrorMessage);
  815. }
  816. #endregion
  817. }
  818. catch (Exception)
  819. {
  820. throw;
  821. }
  822. }
  823. #endregion
  824. #region 生产入库
  825. /// <summary>
  826. /// 生产入库
  827. /// </summary>
  828. /// <param name="TransCode"></param>
  829. /// <param name="TransSequence"></param>
  830. /// <param name="Quantity"></param>
  831. /// <param name="WorkPoint"></param>
  832. /// <param name="cmd"></param>
  833. public static void ManufactureReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  834. {
  835. try
  836. {
  837. string sql = @"DECLARE @Status VARCHAR(10)
  838. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  839. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  840. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  841. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  842. IF (@Status IS NULL)
  843. BEGIN
  844. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  845. RETURN
  846. END
  847. ELSE IF (@Status='3')
  848. BEGIN
  849. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  850. RETURN
  851. END
  852. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  853. FROM ICSInventoryLot a
  854. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  855. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  856. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  857. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  858. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  859. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  860. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.RCVQuantity)
  861. BEGIN
  862. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  863. END";
  864. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  865. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  866. {
  867. throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
  868. }
  869. }
  870. catch (Exception)
  871. {
  872. throw;
  873. }
  874. }
  875. /// <summary>
  876. /// 生产入库接口
  877. /// </summary>
  878. /// <param name="TransType"></param>
  879. /// <param name="Identification"></param>
  880. /// <param name="cmd"></param>
  881. public static void ManufactureReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  882. {
  883. try
  884. {
  885. #region ERP
  886. 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, '')+
  887. 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,
  888. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,c.MODetailID,con.Enable AS UpdateTodoQuantity
  889. ,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,
  890. 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
  891. INTO #TempERP
  892. FROM ICSWareHouseLotInfoLog a
  893. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  894. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  895. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  896. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  897. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  898. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  899. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  900. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  901. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  902. GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,c.MODetailID,con.Enable,conv.Enable
  903. ,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, ''),
  904. 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
  905. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  906. SELECT Costre,Costre2,TransSequence,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  907. FROM #TempERP
  908. 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
  909. FROM ICSWareHouseLotInfoLog a
  910. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  911. INNER JOIN ICSMO b ON b.MOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  912. INNER JOIN ICSMOPick c ON c.MODetailID=b.MODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  913. INNER JOIN ICSExtension ext ON ext.ID=c.ExtensionID AND ext.WorkPoint=c.WorkPoint
  914. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  915. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  916. INNER JOIN #TempERP te ON te.TransSequence=SUBSTRING(a.TransSequence,1,CHARINDEX('~',a.TransSequence)-1)
  917. WHERE a.Identification='{0}' AND a.TransType='12'
  918. 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, ''),
  919. 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
  920. DROP TABLE #TempERP";
  921. sql = string.Format(sql, Identification, BusinessCode);
  922. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  923. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "detailss", "Costre2");
  924. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ManufactureReceiveDocURL, Inputstr);
  925. Result result = new Result();
  926. result = JsonConvert.DeserializeObject<Result>(resultStr);
  927. if (result.Success)
  928. {
  929. try
  930. {
  931. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  932. foreach (var item in res)
  933. {
  934. JObject jo = (JObject)item;
  935. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  936. foreach (var detail in resdetail)
  937. {
  938. JObject det = (JObject)detail;
  939. 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()
  940. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  941. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  942. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  943. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  944. foreach (var details in resdetails)
  945. {
  946. JObject dets = (JObject)details;
  947. if (dets != null)
  948. {
  949. //直接回写
  950. string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  951. FROM ICSWareHouseLotInfoLog a
  952. LEFT JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  953. LEFT JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  954. WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{6}'";
  955. ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString()
  956. , dets["Sequence"].ToString(), BusinessCode);
  957. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  958. {
  959. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"成品倒冲回写失败!";
  960. }
  961. }
  962. }
  963. }
  964. }
  965. }
  966. catch (Exception ex)
  967. {
  968. log.Debug(ex.ToString());
  969. log.Debug(resultStr);
  970. throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  971. }
  972. }
  973. else
  974. {
  975. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  976. }
  977. #endregion
  978. }
  979. catch (Exception)
  980. {
  981. throw;
  982. }
  983. }
  984. #endregion
  985. #region 开立的生产入库单
  986. /// <summary>
  987. /// 开立的生产入库单
  988. /// </summary>
  989. /// <param name="TransCode"></param>
  990. /// <param name="TransSequence"></param>
  991. /// <param name="Quantity"></param>
  992. /// <param name="WorkPoint"></param>
  993. /// <param name="cmd"></param>
  994. public static void ManufactureReceive(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  995. {
  996. try
  997. {
  998. string sql = @"DECLARE @Status VARCHAR(10)
  999. SELECT @Status=c.Status FROM ICSInventoryLot a
  1000. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1001. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1002. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  1003. IF (@Status IS NULL)
  1004. BEGIN
  1005. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1006. RETURN
  1007. END
  1008. ELSE IF (@Status!='1')
  1009. BEGIN
  1010. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  1011. RETURN
  1012. END
  1013. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1014. FROM ICSInventoryLot a
  1015. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1016. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1017. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  1018. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1019. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1020. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1021. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1' AND c.Quantity<c.RCVQuantity)
  1022. BEGIN
  1023. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1024. END";
  1025. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1026. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1027. {
  1028. throw new Exception(language.GetNameByCode("WMSAPIInfo138"));//"生产入库单更新失败!");
  1029. }
  1030. }
  1031. catch (Exception)
  1032. {
  1033. throw;
  1034. }
  1035. }
  1036. /// <summary>
  1037. /// 开立的生产入库单(货柜)
  1038. /// </summary>
  1039. /// <param name="TransCode"></param>
  1040. /// <param name="TransSequence"></param>
  1041. /// <param name="Quantity"></param>
  1042. /// <param name="WorkPoint"></param>
  1043. /// <param name="cmd"></param>
  1044. public static void ManufactureReceiveForHG(string TransCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1045. {
  1046. try
  1047. {
  1048. string sql = @"UPDATE ICSManufactureReceive set RCVQuantity=Quantity
  1049. Where RCVCode='{0}' and WorkPoint='{1}'";
  1050. sql = string.Format(sql, TransCode, WorkPoint);
  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="TransType"></param>
  1065. /// <param name="Identification"></param>
  1066. /// <param name="cmd"></param>
  1067. public static void ManufactureReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1068. {
  1069. try
  1070. {
  1071. #region SAP(三层结构)
  1072. string IsSuccess = "";
  1073. string ErrorMessage = "";
  1074. string sql = @" select Distinct A.RCVCode,A.WorkPoint from ICSManufactureReceive A
  1075. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.RCVCode AND B.WorkPoint=A.WorkPoint
  1076. where B.Identification='{0}' AND BusinessCode='18'";
  1077. sql = string.Format(sql, Identification);
  1078. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1079. if (dt.Rows.Count > 1)
  1080. {
  1081. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  1082. }
  1083. for (int i = 0; i < dt.Rows.Count; i++)
  1084. {
  1085. string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSManufactureReceive
  1086. where RCVCode='{0}' and WorkPoint='{1}'
  1087. GROUP BY RCVCode,WorkPoint";
  1088. chksql = string.Format(chksql, dt.Rows[i]["RCVCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  1089. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  1090. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) == Convert.ToDecimal(chkdt.Rows[0]["RCVQuantity"]))
  1091. {
  1092. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  1093. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  1094. Info.NEWID = Identification;
  1095. Info.DANJU = dt.Rows[i]["RCVCode"].ToString();
  1096. Info.STATE = "0";
  1097. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  1098. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  1099. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  1100. sql = @"select A.RCVCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.RCVQuantity
  1101. ,ISNULL(B.BatchCode,'') AS BatchCode from ICSManufactureReceive A
  1102. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  1103. WHERE RCVCode='{0}' AND A.WorkPoint='{1}'";
  1104. sql = string.Format(sql, dt.Rows[i]["RCVCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  1105. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  1106. foreach (DataRow dr in Sapdt.Rows)
  1107. {
  1108. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["RCVQuantity"].ToString()))
  1109. {
  1110. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  1111. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  1112. Item.DANJU = dr["RCVCode"].ToString();
  1113. Item.POSNR = dr["SAPSequence"].ToString();
  1114. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  1115. ItemList.Add(Item);
  1116. if (dr["BatchCode"].ToString() != "")
  1117. {
  1118. ItemLine.DANJU = dr["RCVCode"].ToString();
  1119. ItemLine.POSNR = dr["SAPSequence"].ToString();
  1120. ItemLine.MATNR = dr["InvCode"].ToString();
  1121. ItemLine.GERNR = dr["BatchCode"].ToString();
  1122. ItemLineList.Add(ItemLine);
  1123. }
  1124. }
  1125. }
  1126. if (ItemList.Count > 0)
  1127. {
  1128. Info.Z_ITEM = ItemList.ToArray();
  1129. if (ItemLineList.Count > 0)
  1130. {
  1131. Info.Z_GERNR = ItemLineList.ToArray();
  1132. }
  1133. else
  1134. {
  1135. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  1136. }
  1137. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  1138. result = Client.CallZWMS_SK_WS_PZ(Info);
  1139. if (result.Z_NULL == "N")
  1140. {
  1141. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  1142. {
  1143. IsSuccess = "N";
  1144. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  1145. }
  1146. }
  1147. }
  1148. }
  1149. }
  1150. if (IsSuccess == "N")
  1151. {
  1152. throw new Exception(ErrorMessage);
  1153. }
  1154. #endregion
  1155. }
  1156. catch (Exception)
  1157. {
  1158. throw;
  1159. }
  1160. }
  1161. #endregion
  1162. #region 返工工单
  1163. /// <summary>
  1164. /// 返工工单
  1165. /// </summary>
  1166. /// <param name="TransCode"></param>
  1167. /// <param name="TransSequence"></param>
  1168. /// <param name="Quantity"></param>
  1169. /// <param name="WorkPoint"></param>
  1170. /// <param name="cmd"></param>
  1171. public static void ReWorkReceiveMo(string LotNo, string Quantity, string WarehouseCode,
  1172. string LocationCode, string WorkPoint, String User, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1173. {
  1174. try
  1175. {
  1176. string sql = @"DECLARE @Status VARCHAR(10)
  1177. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  1178. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1179. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1180. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1181. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1182. IF (@Status IS NULL)
  1183. BEGIN
  1184. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1185. RETURN
  1186. END
  1187. ELSE IF (@Status='3')
  1188. BEGIN
  1189. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1190. RETURN
  1191. END
  1192. UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  1193. FROM ICSInventoryLot a
  1194. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1195. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1196. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1197. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1198. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1199. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1200. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1201. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1202. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.IssueQuantity>d.Quantity)
  1203. BEGIN
  1204. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1205. END";
  1206. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1207. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1208. {
  1209. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));//"生产工单更新失败!");
  1210. }
  1211. }
  1212. catch (Exception)
  1213. {
  1214. throw;
  1215. }
  1216. }
  1217. /// <summary>
  1218. /// 返工工单
  1219. /// </summary>
  1220. /// <param name="TransType"></param>
  1221. /// <param name="Identification"></param>
  1222. /// <param name="cmd"></param>
  1223. public static void ReWorkReceiveMoERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1224. {
  1225. try
  1226. {
  1227. #region ERP开立状态单据审核
  1228. 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,
  1229. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,d.PickID AS MODetailID,Enable AS UpdateTodoQuantity
  1230. ,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,
  1231. 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
  1232. INTO #TempERP
  1233. FROM ICSWareHouseLotInfoLog a
  1234. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1235. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1236. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1237. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1238. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1239. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1240. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1241. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1242. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1243. GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,d.PickID,Enable,d.Sequence
  1244. ,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, ''),
  1245. 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, '')
  1246. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  1247. SELECT Costre,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1248. FROM #TempERP
  1249. DROP TABLE #TempERP";
  1250. sql = string.Format(sql, Identification, BusinessCode);
  1251. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1252. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1253. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSReWorkReceiveMoURL, Inputstr);
  1254. Result result = new Result();
  1255. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1256. if (result.Success)
  1257. {
  1258. try
  1259. {
  1260. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1261. foreach (var item in res)
  1262. {
  1263. JObject jo = (JObject)item;
  1264. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1265. foreach (var detail in resdetail)
  1266. {
  1267. JObject det = (JObject)detail;
  1268. 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()
  1269. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1270. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1271. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), col, cmd, language, BusinessCode);
  1272. }
  1273. }
  1274. }
  1275. catch (Exception ex)
  1276. {
  1277. log.Debug(ex.ToString());
  1278. log.Debug(resultStr);
  1279. }
  1280. }
  1281. else
  1282. {
  1283. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1284. }
  1285. #endregion
  1286. }
  1287. catch (Exception)
  1288. {
  1289. throw;
  1290. }
  1291. }
  1292. #endregion
  1293. }
  1294. }