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

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