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

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