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

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