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

1135 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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Linq;
  10. using System.Net.Http;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace ICSSoft.DataProject
  14. {
  15. /// <summary>
  16. /// 使用中
  17. /// 生产模块
  18. /// </summary>
  19. public class ICSManufactureService
  20. {
  21. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  22. #region 生产发料
  23. /// <summary>
  24. /// 生产发料
  25. /// </summary>
  26. /// <param name="TransCode"></param>
  27. /// <param name="TransSequence"></param>
  28. /// <param name="Quantity"></param>
  29. /// <param name="WorkPoint"></param>
  30. /// <param name="cmd"></param>
  31. public static void MOIssueDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  32. {
  33. try
  34. {
  35. string sql = @"DECLARE @Status VARCHAR(10)
  36. SELECT @Status=b.ERPStatus FROM ICSMOPick a
  37. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  38. WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}'
  39. IF (@Status IS NULL)
  40. BEGIN
  41. RAISERROR('" + language.GetNameByCode("WMSAPIInfo125") + @"',16,1);
  42. RETURN
  43. END
  44. ELSE IF (@Status!='2')
  45. BEGIN
  46. RAISERROR('" + language.GetNameByCode("WMSAPIInfo126") + @"',16,1);
  47. RETURN
  48. END
  49. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  50. FROM ICSMOPick a
  51. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  52. WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}'
  53. IF EXISTS(SELECT a.ID FROM ICSMOPick a
  54. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  55. WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  56. BEGIN
  57. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  58. RETURN
  59. END";
  60. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  61. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  62. {
  63. throw new Exception(language.GetNameByCode("WMSAPIInfo127"));//"生产领料单更新失败!");
  64. }
  65. }
  66. catch (Exception)
  67. {
  68. throw;
  69. }
  70. }
  71. /// <summary>
  72. /// 生产发料接口
  73. /// </summary>
  74. /// <param name="TransType"></param>
  75. /// <param name="Identification"></param>
  76. /// <param name="cmd"></param>
  77. public static void MOIssueDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  78. {
  79. try
  80. {
  81. #region ERP
  82. string sql = @"SELECT y.DepCode+a.FromWarehouseCode+y.MOCode+a.MUSER AS Costre,y.DepCode,a.FromWarehouseCode AS WarehouseCode,y.MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.FromWarehouseCode,y.MOCode,x.PickID,a.InvCode) AS Sequence,
  83. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(x.Amount/x.Quantity)) AS Amount,x.PickID,con.Enable AS UpdateTodoQuantity
  84. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  85. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10,conv.Enable AS CompleteVerification
  86. INTO #TempERP
  87. FROM ICSWareHouseLotInfoLog a
  88. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  89. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  90. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  91. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  92. INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
  93. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  94. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  95. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  96. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '13'
  97. GROUP BY y.DepCode,a.FromWarehouseCode,y.MOCode,a.MUSER,a.InvCode,x.PickID,x.MODetailID,con.Enable,conv.Enable
  98. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  99. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  100. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  101. SELECT Costre,Sequence,InvCode,Quantity,Amount,PickID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  102. DROP TABLE #TempERP";
  103. sql = string.Format(sql, Identification);
  104. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  105. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  106. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueDocURL, Inputstr);
  107. Result result = new Result();
  108. result = JsonConvert.DeserializeObject<Result>(resultStr);
  109. if (result.Success)
  110. {
  111. try
  112. {
  113. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  114. foreach (var item in res)
  115. {
  116. JObject jo = (JObject)item;
  117. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  118. foreach (var detail in resdetail)
  119. {
  120. JObject det = (JObject)detail;
  121. string allcol = jo["cWhCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  122. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  123. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  124. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  125. }
  126. }
  127. }
  128. catch (Exception ex)
  129. {
  130. log.Debug(ex.ToString());
  131. log.Debug(resultStr);
  132. }
  133. }
  134. else
  135. {
  136. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  137. }
  138. #endregion
  139. }
  140. catch (Exception)
  141. {
  142. throw;
  143. }
  144. }
  145. #endregion
  146. #region 领料申请单生产发料
  147. /// <summary>
  148. /// 领料申请单生产发料
  149. /// </summary>
  150. /// <param name="TransCode"></param>
  151. /// <param name="TransSequence"></param>
  152. /// <param name="Quantity"></param>
  153. /// <param name="WorkPoint"></param>
  154. /// <param name="cmd"></param>
  155. public static void MOApply(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  156. {
  157. try
  158. {
  159. string sql = @"DECLARE @Status VARCHAR(10)
  160. SELECT @Status=a.Status FROM ICSMOApply a
  161. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  162. IF (@Status IS NULL)
  163. BEGIN
  164. RAISERROR('" + language.GetNameByCode("WMSAPIInfo128") + @"',16,1);
  165. RETURN
  166. END
  167. ELSE IF (@Status!='2')
  168. BEGIN
  169. RAISERROR('" + language.GetNameByCode("WMSAPIInfo129") + @"',16,1);
  170. RETURN
  171. END
  172. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  173. FROM ICSMOApply a
  174. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  175. IF EXISTS(SELECT a.ID FROM ICSMOApply a
  176. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  177. BEGIN
  178. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  179. RETURN
  180. END";
  181. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  182. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  183. {
  184. throw new Exception(language.GetNameByCode("WMSAPIInfo130"));//"领料申请单更新失败!");
  185. }
  186. }
  187. catch (Exception)
  188. {
  189. throw;
  190. }
  191. }
  192. /// <summary>
  193. /// 领料申请单生产发料接口
  194. /// </summary>
  195. /// <param name="TransType"></param>
  196. /// <param name="Identification"></param>
  197. /// <param name="cmd"></param>
  198. public static void MOApplyERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  199. {
  200. try
  201. {
  202. #region SAP
  203. string IsSuccess = "";
  204. string ErrorMessage = "";
  205. string sql = @" select Distinct A.ApplyCode,A.WorkPoint from ICSMOApply A
  206. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.ApplyCode AND B.WorkPoint=A.WorkPoint
  207. where B.Identification='b1a55561-4a25-4981-a5cc-8fd4d4cf99f6' AND BusinessCode='14'";
  208. sql = string.Format(sql, Identification);
  209. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  210. for (int i = 0; i < dt.Rows.Count; i++)
  211. {
  212. SAPCallBackDoc.ZWMS_SK_WS_PZ Client = new SAPCallBackDoc.ZWMS_SK_WS_PZ();
  213. SAPCallBackDoc.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDoc.ZWMS_SK_WS_PZ1();
  214. Info.NEWID = "b1a55561-4a25-4981-a5cc-8fd4d4cf99f6";
  215. Info.DANJU = dt.Rows[i]["ApplyCode"].ToString();
  216. Info.STATE = "0";
  217. List<SAPCallBackDoc.ZWMS_PZ> ItemList = new List<SAPCallBackDoc.ZWMS_PZ>();
  218. Info.Z_GERNR = new SAPCallBackDoc.ZWEBS_GERNR[1];
  219. Info.Z_FLAG = new SAPCallBackDoc.ZWEB_RETURN[1];
  220. sql = @"select A.ApplyCode,A.Sequence,A.Quantity,A.IssueQuantity,B.BatchCode from ICSMOApply A
  221. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  222. WHERE ApplyCode='{0}' AND A.WorkPoint='{1}'";
  223. sql = string.Format(sql, dt.Rows[i]["ApplyCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  224. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  225. foreach (DataRow dr in Sapdt.Rows)
  226. {
  227. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["IssueQuantity"].ToString()))
  228. {
  229. SAPCallBackDoc.ZWMS_PZ Item = new SAPCallBackDoc.ZWMS_PZ();
  230. Item.DANJU = dr["ApplyCode"].ToString();
  231. Item.POSNR = dr["Sequence"].ToString();
  232. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  233. Item.SERNP = dr["BatchCode"].ToString();
  234. ItemList.Add(Item);
  235. }
  236. }
  237. if (ItemList.Count > 0)
  238. {
  239. Info.Z_ITEM = ItemList.ToArray();
  240. SAPCallBackDoc.ZWMS_SK_WS_PZResponse result = new SAPCallBackDoc.ZWMS_SK_WS_PZResponse();
  241. result = Client.CallZWMS_SK_WS_PZ(Info);
  242. if (result.Z_NULL == "N")
  243. {
  244. foreach (SAPCallBackDoc.ZWEB_RETURN resultItem in result.Z_FLAG)
  245. {
  246. IsSuccess = "N";
  247. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  248. }
  249. }
  250. }
  251. }
  252. if (IsSuccess == "N")
  253. {
  254. throw new Exception(ErrorMessage);
  255. }
  256. #endregion
  257. }
  258. catch (Exception ex)
  259. {
  260. throw;
  261. }
  262. }
  263. #endregion
  264. #region 材料出库单生产发料
  265. /// <summary>
  266. /// 材料出库单生产发料
  267. /// </summary>
  268. /// <param name="TransCode"></param>
  269. /// <param name="TransSequence"></param>
  270. /// <param name="Quantity"></param>
  271. /// <param name="WorkPoint"></param>
  272. /// <param name="cmd"></param>
  273. public static void MOIssue(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  274. {
  275. try
  276. {
  277. string sql = @"DECLARE @Status VARCHAR(10)
  278. SELECT @Status=a.Status FROM ICSMOIssue a
  279. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  280. IF (@Status IS NULL)
  281. BEGIN
  282. RAISERROR('" + language.GetNameByCode("WMSAPIInfo131") + @"',16,1);
  283. RETURN
  284. END
  285. ELSE IF (@Status!='1')
  286. BEGIN
  287. RAISERROR('" + language.GetNameByCode("WMSAPIInfo132") + @"',16,1);
  288. RETURN
  289. END
  290. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  291. FROM ICSMOIssue a
  292. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  293. IF EXISTS(SELECT a.ID FROM ICSMOIssue a
  294. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  295. BEGIN
  296. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  297. RETURN
  298. END";
  299. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  300. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  301. {
  302. throw new Exception(language.GetNameByCode("WMSAPIInfo133"));//"材料出库单更新失败!");
  303. }
  304. }
  305. catch (Exception)
  306. {
  307. throw;
  308. }
  309. }
  310. /// <summary>
  311. /// 材料出库单生产发料接口
  312. /// </summary>
  313. /// <param name="TransType"></param>
  314. /// <param name="Identification"></param>
  315. /// <param name="cmd"></param>
  316. public static void MOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  317. {
  318. try
  319. {
  320. #region ERP开立状态单据审核
  321. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  322. INNER JOIN ICSMOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  323. WHERE a.Identification='{0}' AND b.Quantity!=b.IssueQuantity)
  324. BEGIN
  325. RAISERROR('" + language.GetNameByCode("WMSAPIInfo094") + @"',16,1);
  326. RETURN
  327. END
  328. SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity
  329. ,conStock.Enable AS UpdateStock,a.WorkPoint
  330. FROM ICSWareHouseLotInfoLog a
  331. INNER JOIN ICSMOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  332. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  333. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  334. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '15'
  335. GROUP BY b.IssueID,a.MUSER,con.Enable
  336. ,conStock.Enable,a.WorkPoint";
  337. sql = string.Format(sql, Identification);
  338. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  339. string Inputstr = JsonConvert.SerializeObject(dt);
  340. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueURL, Inputstr);
  341. Result result = new Result();
  342. result = JsonConvert.DeserializeObject<Result>(resultStr);
  343. if (result.Success)
  344. {
  345. try
  346. {
  347. foreach (DataRow dr in dt.Rows)
  348. {
  349. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  350. }
  351. }
  352. catch (Exception ex)
  353. {
  354. log.Debug(ex.ToString());
  355. log.Debug(resultStr);
  356. }
  357. }
  358. else
  359. {
  360. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  361. }
  362. #endregion
  363. }
  364. catch (Exception)
  365. {
  366. throw;
  367. }
  368. }
  369. #endregion
  370. #region 生产退料
  371. /// <summary>
  372. /// 生产退料
  373. /// </summary>
  374. /// <param name="TransCode"></param>
  375. /// <param name="TransSequence"></param>
  376. /// <param name="Quantity"></param>
  377. /// <param name="WorkPoint"></param>
  378. /// <param name="cmd"></param>
  379. public static void MOIssueDocNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  380. {
  381. try
  382. {
  383. string table = "";
  384. string sql = "";
  385. if (string.IsNullOrWhiteSpace(LogID))
  386. {
  387. string type = "";
  388. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  389. {
  390. table = "INNER JOIN ICSMOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint";
  391. type = "1";
  392. }
  393. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  394. {
  395. table = "INNER JOIN ICSMOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
  396. type = "2";
  397. }
  398. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  399. {
  400. table = "INNER JOIN ICSMOIssue e ON c.SourceDetailID=e.IssueDetailID AND c.WorkPoint=e.WorkPoint";
  401. type = "3";
  402. }
  403. else
  404. {
  405. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  406. }
  407. #region 新条码
  408. sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  409. FROM ICSInventoryLot a
  410. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  411. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  412. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  413. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  414. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  415. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  416. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  417. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  418. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND c.Quantity<c.IssueNegQuantity)
  419. BEGIN
  420. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  421. END
  422. UPDATE e SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  423. FROM ICSInventoryLot a
  424. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  425. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  426. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  427. {3}
  428. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  429. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  430. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  431. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  432. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  433. {3}
  434. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND e.IssueQuantity<0)
  435. BEGIN
  436. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  437. END";
  438. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type);
  439. #endregion
  440. }
  441. else
  442. {
  443. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  444. {
  445. table = @"INNER JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  446. INNER JOIN ICSMOPick c ON b.MODetailID = c.MODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
  447. }
  448. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  449. {
  450. table = "INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  451. }
  452. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  453. {
  454. table = "INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  455. }
  456. else
  457. {
  458. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  459. }
  460. #region 原条码
  461. sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  462. FROM ICSWareHouseLotInfoLog a
  463. {3}
  464. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}'
  465. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
  466. {3}
  467. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0)
  468. BEGIN
  469. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  470. END";
  471. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID);
  472. #endregion
  473. }
  474. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  475. {
  476. throw new Exception(language.GetNameByCode("WMSAPIInfo134"));//"生产退料单更新失败!");
  477. }
  478. }
  479. catch (Exception)
  480. {
  481. throw;
  482. }
  483. }
  484. /// <summary>
  485. /// 生产退料接口
  486. /// </summary>
  487. /// <param name="TransType"></param>
  488. /// <param name="Identification"></param>
  489. /// <param name="cmd"></param>
  490. public static void MOIssueDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  491. {
  492. try
  493. {
  494. #region ERP
  495. string sql = string.Empty;
  496. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  497. {
  498. sql = @"SELECT y.DepCode+a.ToWarehouseCode+y.MOCode+a.MUSER AS Costre,y.DepCode,a.ToWarehouseCode AS WarehouseCode,y.MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.ToWarehouseCode,y.MOCode,x.PickID,a.InvCode) AS Sequence,
  499. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  500. ,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,
  501. 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
  502. INTO #TempERP
  503. FROM ICSWareHouseLotInfoLog a
  504. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  505. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  506. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  507. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  508. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  509. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  510. INNER JOIN ICSMOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
  511. INNER JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  512. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  513. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')=''
  514. GROUP BY y.DepCode,a.ToWarehouseCode,y.MOCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,x.PickID,x.MODetailID,con.Enable
  515. ,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, ''),
  516. 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, '')
  517. UNION ALL
  518. SELECT y.DepCode+a.ToWarehouseCode+y.MOCode+a.MUSER AS Costre,y.DepCode,a.ToWarehouseCode AS WarehouseCode,y.MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.ToWarehouseCode,y.MOCode,x.PickID,a.InvCode) AS Sequence,
  519. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  520. ,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,
  521. 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
  522. FROM ICSWareHouseLotInfoLog a
  523. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  524. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  525. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  526. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  527. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  528. INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
  529. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  530. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  531. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>''
  532. GROUP BY y.DepCode,a.ToWarehouseCode,y.MOCode,a.MUSER,a.InvCode,x.PickID,x.MODetailID,con.Enable
  533. ,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, ''),
  534. 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, '')
  535. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  536. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  537. DROP TABLE #TempERP";
  538. }
  539. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  540. {
  541. sql = @"SELECT a.ToWarehouseCode+z.ApplyCode+a.MUSER AS Costre,'' AS DepCode,a.ToWarehouseCode AS WarehouseCode,z.ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,z.ApplyCode,z.ApplyDetailID,a.InvCode) AS Sequence,
  542. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  543. ,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,
  544. 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
  545. INTO #TempERP
  546. FROM ICSWareHouseLotInfoLog a
  547. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  548. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  549. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  550. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  551. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  552. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  553. INNER JOIN ICSMOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint
  554. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  555. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')=''
  556. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,con.Enable
  557. ,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, ''),
  558. 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, '')
  559. UNION ALL
  560. SELECT a.ToWarehouseCode+z.ApplyCode+a.MUSER AS Costre,'' AS DepCode,a.ToWarehouseCode AS WarehouseCode,z.ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,z.ApplyCode,z.ApplyDetailID,a.InvCode) AS Sequence,
  561. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  562. ,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,
  563. 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
  564. FROM ICSWareHouseLotInfoLog a
  565. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  566. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  567. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  568. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  569. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  570. INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  571. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  572. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>''
  573. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,con.Enable
  574. ,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, ''),
  575. 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, '')
  576. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  577. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  578. DROP TABLE #TempERP";
  579. }
  580. //根据材料出库单查询上游单据,根据上游单据生成红字材料出库
  581. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  582. {
  583. sql = @"SELECT ISNULL(y.DepCode, '')+a.ToWarehouseCode+a.MUSER AS Costre,ISNULL(y.DepCode, '') AS DepCode,a.ToWarehouseCode AS WarehouseCode,CASE WHEN m.ApplyDetailID IS NOT NULL THEN '领料申请单' WHEN m.PickID IS NOT NULL THEN '生产订单' ELSE '' END AS SourceType,ISNULL(z.ApplyCode, y.MOCode) AS MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),ISNULL(m.ApplyDetailID, m.PickID),a.InvCode) AS Sequence,
  584. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  585. ,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,
  586. 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
  587. INTO #TempERP
  588. FROM ICSWareHouseLotInfoLog a
  589. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  590. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  591. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  592. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  593. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  594. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  595. INNER JOIN ICSMOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  596. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  597. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  598. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  599. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  600. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')=''
  601. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,con.Enable
  602. ,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, ''),
  603. 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, '')
  604. UNION ALL
  605. SELECT ISNULL(y.DepCode, '')+a.ToWarehouseCode+a.MUSER AS Costre,ISNULL(y.DepCode, '') AS DepCode,a.ToWarehouseCode AS WarehouseCode,CASE WHEN m.ApplyDetailID IS NOT NULL THEN '' WHEN m.PickID IS NOT NULL THEN '' ELSE '' END AS SourceType,ISNULL(z.ApplyCode, y.MOCode) AS MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),ISNULL(m.ApplyDetailID, m.PickID),a.InvCode) AS Sequence,
  606. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  607. ,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,
  608. 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
  609. FROM ICSWareHouseLotInfoLog a
  610. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  611. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  612. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  613. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  614. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  615. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  616. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  617. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  618. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  619. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  620. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>''
  621. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,con.Enable
  622. ,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, ''),
  623. 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, '')
  624. IF EXISTS(SELECT Costre FROM #TempERP WHERE SourceType='{0}')
  625. BEGIN
  626. RAISERROR('" + language.GetNameByCode("WMSAPIInfo135") + @"',16,1);
  627. END
  628. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  629. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  630. DROP TABLE #TempERP";
  631. }
  632. else
  633. {
  634. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  635. }
  636. sql = string.Format(sql, Identification);
  637. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  638. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  639. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueDocNegativeURL, Inputstr);
  640. Result result = new Result();
  641. result = JsonConvert.DeserializeObject<Result>(resultStr);
  642. if (result.Success)
  643. {
  644. try
  645. {
  646. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  647. foreach (var item in res)
  648. {
  649. JObject jo = (JObject)item;
  650. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  651. foreach (var detail in resdetail)
  652. {
  653. JObject det = (JObject)detail;
  654. 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()
  655. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  656. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  657. det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  658. }
  659. }
  660. }
  661. catch (Exception ex)
  662. {
  663. log.Debug(ex.ToString());
  664. log.Debug(resultStr);
  665. }
  666. }
  667. else
  668. {
  669. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  670. }
  671. #endregion
  672. }
  673. catch (Exception)
  674. {
  675. throw;
  676. }
  677. }
  678. #endregion
  679. #region 生产入库
  680. /// <summary>
  681. /// 生产入库
  682. /// </summary>
  683. /// <param name="TransCode"></param>
  684. /// <param name="TransSequence"></param>
  685. /// <param name="Quantity"></param>
  686. /// <param name="WorkPoint"></param>
  687. /// <param name="cmd"></param>
  688. public static void ManufactureReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  689. {
  690. try
  691. {
  692. string sql = @"DECLARE @Status VARCHAR(10)
  693. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  694. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  695. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  696. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  697. IF (@Status IS NULL)
  698. BEGIN
  699. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  700. RETURN
  701. END
  702. ELSE IF (@Status='3')
  703. BEGIN
  704. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  705. RETURN
  706. END
  707. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  708. FROM ICSInventoryLot a
  709. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  710. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  711. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  712. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  713. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  714. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  715. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.RCVQuantity)
  716. BEGIN
  717. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  718. END";
  719. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  720. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  721. {
  722. throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
  723. }
  724. }
  725. catch (Exception)
  726. {
  727. throw;
  728. }
  729. }
  730. /// <summary>
  731. /// 生产入库接口
  732. /// </summary>
  733. /// <param name="TransType"></param>
  734. /// <param name="Identification"></param>
  735. /// <param name="cmd"></param>
  736. public static void ManufactureReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  737. {
  738. try
  739. {
  740. #region ERP
  741. 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, '')+
  742. 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,
  743. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,c.MODetailID,con.Enable AS UpdateTodoQuantity
  744. ,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,
  745. 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
  746. INTO #TempERP
  747. FROM ICSWareHouseLotInfoLog a
  748. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  749. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  750. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  751. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  752. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  753. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  754. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  755. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  756. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  757. GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,c.MODetailID,con.Enable,conv.Enable
  758. ,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, ''),
  759. 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
  760. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  761. SELECT Costre,Costre2,TransSequence,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  762. FROM #TempERP
  763. 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
  764. FROM ICSWareHouseLotInfoLog a
  765. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  766. INNER JOIN ICSMO b ON b.MOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  767. INNER JOIN ICSMOPick c ON c.MODetailID=b.MODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  768. INNER JOIN ICSExtension ext ON ext.ID=c.ExtensionID AND ext.WorkPoint=c.WorkPoint
  769. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  770. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  771. INNER JOIN #TempERP te ON te.TransSequence=SUBSTRING(a.TransSequence,1,CHARINDEX('~',a.TransSequence)-1)
  772. WHERE a.Identification='{0}' AND a.TransType='12'
  773. 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, ''),
  774. 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
  775. DROP TABLE #TempERP";
  776. sql = string.Format(sql, Identification, BusinessCode);
  777. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  778. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "detailss", "Costre2");
  779. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ManufactureReceiveDocURL, Inputstr);
  780. Result result = new Result();
  781. result = JsonConvert.DeserializeObject<Result>(resultStr);
  782. if (result.Success)
  783. {
  784. try
  785. {
  786. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  787. foreach (var item in res)
  788. {
  789. JObject jo = (JObject)item;
  790. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  791. foreach (var detail in resdetail)
  792. {
  793. JObject det = (JObject)detail;
  794. 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()
  795. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  796. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  797. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  798. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  799. foreach (var details in resdetails)
  800. {
  801. JObject dets = (JObject)details;
  802. if (dets != null)
  803. {
  804. //直接回写
  805. string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  806. FROM ICSWareHouseLotInfoLog a
  807. LEFT JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  808. LEFT JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  809. WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{6}'";
  810. ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString()
  811. , dets["Sequence"].ToString(), BusinessCode);
  812. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  813. {
  814. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"成品倒冲回写失败!";
  815. }
  816. }
  817. }
  818. }
  819. }
  820. }
  821. catch (Exception ex)
  822. {
  823. log.Debug(ex.ToString());
  824. log.Debug(resultStr);
  825. throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  826. }
  827. }
  828. else
  829. {
  830. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  831. }
  832. #endregion
  833. }
  834. catch (Exception)
  835. {
  836. throw;
  837. }
  838. }
  839. #endregion
  840. #region 开立的生产入库单
  841. /// <summary>
  842. /// 开立的生产入库单
  843. /// </summary>
  844. /// <param name="TransCode"></param>
  845. /// <param name="TransSequence"></param>
  846. /// <param name="Quantity"></param>
  847. /// <param name="WorkPoint"></param>
  848. /// <param name="cmd"></param>
  849. public static void ManufactureReceive(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  850. {
  851. try
  852. {
  853. string sql = @"DECLARE @Status VARCHAR(10)
  854. SELECT @Status=c.Status FROM ICSInventoryLot a
  855. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  856. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  857. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  858. IF (@Status IS NULL)
  859. BEGIN
  860. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  861. RETURN
  862. END
  863. ELSE IF (@Status!='1')
  864. BEGIN
  865. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  866. RETURN
  867. END
  868. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  869. FROM ICSInventoryLot a
  870. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  871. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  872. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  873. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  874. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  875. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  876. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1' AND c.Quantity<c.RCVQuantity)
  877. BEGIN
  878. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  879. END";
  880. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  881. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  882. {
  883. throw new Exception(language.GetNameByCode("WMSAPIInfo138"));//"生产入库单更新失败!");
  884. }
  885. }
  886. catch (Exception)
  887. {
  888. throw;
  889. }
  890. }
  891. /// <summary>
  892. /// 开立的生产入库单
  893. /// </summary>
  894. /// <param name="TransType"></param>
  895. /// <param name="Identification"></param>
  896. /// <param name="cmd"></param>
  897. public static void ManufactureReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  898. {
  899. try
  900. {
  901. #region ERP开立状态单据审核
  902. string sql = @"IF EXISTS(SELECT b.ID FROM ICSManufactureReceive b
  903. WHERE b.RCVCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  904. AND b.Quantity!=b.RCVQuantity)
  905. BEGIN
  906. RAISERROR('" + language.GetNameByCode("WMSAPIInfo096") + @"',16,1);
  907. RETURN
  908. END
  909. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  910. FROM ICSWareHouseLotInfoLog a
  911. INNER JOIN ICSManufactureReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  912. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  913. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  914. WHERE a.Identification='{0}' AND ERPUpload='0'
  915. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  916. sql = string.Format(sql, Identification);
  917. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  918. string Inputstr = JsonConvert.SerializeObject(dt);
  919. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSManufactureReceiveURL, Inputstr);
  920. Result result = new Result();
  921. result = JsonConvert.DeserializeObject<Result>(resultStr);
  922. if (result.Success)
  923. {
  924. try
  925. {
  926. foreach (DataRow dr in dt.Rows)
  927. {
  928. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  929. }
  930. }
  931. catch (Exception ex)
  932. {
  933. log.Debug(ex.ToString());
  934. log.Debug(resultStr);
  935. }
  936. }
  937. else
  938. {
  939. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  940. }
  941. #endregion
  942. }
  943. catch (Exception)
  944. {
  945. throw;
  946. }
  947. }
  948. #endregion
  949. #region 返工工单
  950. /// <summary>
  951. /// 返工工单
  952. /// </summary>
  953. /// <param name="TransCode"></param>
  954. /// <param name="TransSequence"></param>
  955. /// <param name="Quantity"></param>
  956. /// <param name="WorkPoint"></param>
  957. /// <param name="cmd"></param>
  958. public static void ReWorkReceiveMo(string LotNo, string Quantity, string WarehouseCode,
  959. string LocationCode, string WorkPoint, String User, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  960. {
  961. try
  962. {
  963. string sql = @"DECLARE @Status VARCHAR(10)
  964. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  965. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  966. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  967. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  968. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  969. IF (@Status IS NULL)
  970. BEGIN
  971. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  972. RETURN
  973. END
  974. ELSE IF (@Status='3')
  975. BEGIN
  976. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  977. RETURN
  978. END
  979. UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  980. FROM ICSInventoryLot a
  981. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  982. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  983. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  984. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  985. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  986. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  987. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  988. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  989. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.IssueQuantity>d.Quantity)
  990. BEGIN
  991. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  992. END";
  993. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  994. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  995. {
  996. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));//"生产工单更新失败!");
  997. }
  998. }
  999. catch (Exception)
  1000. {
  1001. throw;
  1002. }
  1003. }
  1004. /// <summary>
  1005. /// 返工工单
  1006. /// </summary>
  1007. /// <param name="TransType"></param>
  1008. /// <param name="Identification"></param>
  1009. /// <param name="cmd"></param>
  1010. public static void ReWorkReceiveMoERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1011. {
  1012. try
  1013. {
  1014. #region ERP开立状态单据审核
  1015. 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,
  1016. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,d.PickID AS MODetailID,Enable AS UpdateTodoQuantity
  1017. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  1018. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  1019. INTO #TempERP
  1020. FROM ICSWareHouseLotInfoLog a
  1021. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1022. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1023. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1024. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1025. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1026. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1027. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1028. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1029. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1030. GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,d.PickID,Enable,d.Sequence
  1031. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  1032. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  1033. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  1034. SELECT Costre,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1035. FROM #TempERP
  1036. DROP TABLE #TempERP";
  1037. sql = string.Format(sql, Identification, BusinessCode);
  1038. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1039. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1040. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSReWorkReceiveMoURL, Inputstr);
  1041. Result result = new Result();
  1042. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1043. if (result.Success)
  1044. {
  1045. try
  1046. {
  1047. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1048. foreach (var item in res)
  1049. {
  1050. JObject jo = (JObject)item;
  1051. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1052. foreach (var detail in resdetail)
  1053. {
  1054. JObject det = (JObject)detail;
  1055. 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()
  1056. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1057. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1058. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), col, cmd, language, BusinessCode);
  1059. }
  1060. }
  1061. }
  1062. catch (Exception ex)
  1063. {
  1064. log.Debug(ex.ToString());
  1065. log.Debug(resultStr);
  1066. }
  1067. }
  1068. else
  1069. {
  1070. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1071. }
  1072. #endregion
  1073. }
  1074. catch (Exception)
  1075. {
  1076. throw;
  1077. }
  1078. }
  1079. #endregion
  1080. }
  1081. }