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

1407 lines
83 KiB

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