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