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

1490 lines
89 KiB

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