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

1404 lines
83 KiB

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