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

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