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

1117 lines
80 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
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)
  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*(lot.Amount/lot.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["BatchCode"].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);
  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)
  199. {
  200. try
  201. {
  202. #region ERP
  203. string sql = @"SELECT a.FromWarehouseCode+b.ApplyCode+a.MUSER AS Costre,a.FromWarehouseCode AS WarehouseCode,b.ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.ApplyCode,b.ApplyDetailID,a.InvCode) AS Sequence,
  204. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,b.ApplyDetailID,con.Enable AS UpdateTodoQuantity
  205. ,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,
  206. 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
  207. INTO #TempERP
  208. FROM ICSWareHouseLotInfoLog a
  209. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  210. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  211. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  212. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  213. INNER JOIN ICSMOApply b ON a.TransCode=b.ApplyCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  214. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  215. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  216. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '14'
  217. GROUP BY a.FromWarehouseCode,b.ApplyCode,a.MUSER,a.InvCode,b.ApplyDetailID,con.Enable,conv.Enable
  218. ,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, ''),
  219. 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, '')
  220. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  221. SELECT Costre,Sequence,InvCode,Quantity,Amount,ApplyDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  222. DROP TABLE #TempERP";
  223. sql = string.Format(sql, Identification);
  224. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  225. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  226. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOApplyURL, Inputstr);
  227. Result result = new Result();
  228. result = JsonConvert.DeserializeObject<Result>(resultStr);
  229. if (result.Success)
  230. {
  231. try
  232. {
  233. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  234. foreach (var item in res)
  235. {
  236. JObject jo = (JObject)item;
  237. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  238. foreach (var detail in resdetail)
  239. {
  240. JObject det = (JObject)detail;
  241. string allcol = jo["cWhCode"].ToString() + det["ProjectCode"].ToString() + det["BatchCode"].ToString() + det["Version"].ToString() + det["Brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  242. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  243. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  244. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language);
  245. }
  246. }
  247. }
  248. catch (Exception ex)
  249. {
  250. log.Debug(ex.ToString());
  251. log.Debug(resultStr);
  252. }
  253. }
  254. else
  255. {
  256. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  257. }
  258. #endregion
  259. }
  260. catch (Exception)
  261. {
  262. throw;
  263. }
  264. }
  265. #endregion
  266. #region 材料出库单生产发料
  267. /// <summary>
  268. /// 材料出库单生产发料
  269. /// </summary>
  270. /// <param name="TransCode"></param>
  271. /// <param name="TransSequence"></param>
  272. /// <param name="Quantity"></param>
  273. /// <param name="WorkPoint"></param>
  274. /// <param name="cmd"></param>
  275. public static void MOIssue(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  276. {
  277. try
  278. {
  279. string sql = @"DECLARE @Status VARCHAR(10)
  280. SELECT @Status=a.Status FROM ICSMOIssue a
  281. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  282. IF (@Status IS NULL)
  283. BEGIN
  284. RAISERROR('" + language.GetNameByCode("WMSAPIInfo131") + @"',16,1);
  285. RETURN
  286. END
  287. ELSE IF (@Status!='1')
  288. BEGIN
  289. RAISERROR('" + language.GetNameByCode("WMSAPIInfo132") + @"',16,1);
  290. RETURN
  291. END
  292. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  293. FROM ICSMOIssue a
  294. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  295. IF EXISTS(SELECT a.ID FROM ICSMOIssue a
  296. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  297. BEGIN
  298. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  299. RETURN
  300. END";
  301. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  302. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  303. {
  304. throw new Exception(language.GetNameByCode("WMSAPIInfo133"));//"材料出库单更新失败!");
  305. }
  306. }
  307. catch (Exception)
  308. {
  309. throw;
  310. }
  311. }
  312. /// <summary>
  313. /// 材料出库单生产发料接口
  314. /// </summary>
  315. /// <param name="TransType"></param>
  316. /// <param name="Identification"></param>
  317. /// <param name="cmd"></param>
  318. public static void MOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  319. {
  320. try
  321. {
  322. #region ERP开立状态单据审核
  323. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  324. INNER JOIN ICSMOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  325. WHERE a.Identification='{0}' AND b.Quantity!=b.IssueQuantity)
  326. BEGIN
  327. RAISERROR('" + language.GetNameByCode("WMSAPIInfo094") + @"',16,1);
  328. RETURN
  329. END
  330. SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity
  331. ,conStock.Enable AS UpdateStock,a.WorkPoint
  332. FROM ICSWareHouseLotInfoLog a
  333. INNER JOIN ICSMOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  334. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  335. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  336. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '15'
  337. GROUP BY b.IssueID,a.MUSER,con.Enable
  338. ,conStock.Enable,a.WorkPoint";
  339. sql = string.Format(sql, Identification);
  340. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  341. string Inputstr = JsonConvert.SerializeObject(dt);
  342. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueURL, Inputstr);
  343. Result result = new Result();
  344. result = JsonConvert.DeserializeObject<Result>(resultStr);
  345. if (result.Success)
  346. {
  347. try
  348. {
  349. foreach (DataRow dr in dt.Rows)
  350. {
  351. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "",cmd, language);
  352. }
  353. }
  354. catch (Exception ex)
  355. {
  356. log.Debug(ex.ToString());
  357. log.Debug(resultStr);
  358. }
  359. }
  360. else
  361. {
  362. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  363. }
  364. #endregion
  365. }
  366. catch (Exception)
  367. {
  368. throw;
  369. }
  370. }
  371. #endregion
  372. #region 生产退料
  373. /// <summary>
  374. /// 生产退料
  375. /// </summary>
  376. /// <param name="TransCode"></param>
  377. /// <param name="TransSequence"></param>
  378. /// <param name="Quantity"></param>
  379. /// <param name="WorkPoint"></param>
  380. /// <param name="cmd"></param>
  381. public static void MOIssueDocNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  382. {
  383. try
  384. {
  385. string table = "";
  386. string sql = "";
  387. if (string.IsNullOrWhiteSpace(LogID))
  388. {
  389. string type = "";
  390. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  391. {
  392. table = "INNER JOIN ICSMOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint";
  393. type = "1";
  394. }
  395. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  396. {
  397. table = "INNER JOIN ICSMOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
  398. type = "2";
  399. }
  400. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  401. {
  402. table = "INNER JOIN ICSMOIssue e ON c.SourceDetailID=e.IssueDetailID AND c.WorkPoint=e.WorkPoint";
  403. type = "3";
  404. }
  405. else
  406. {
  407. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  408. }
  409. #region 新条码
  410. sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  411. FROM ICSInventoryLot a
  412. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  413. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  414. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  415. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  416. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  417. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  418. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  419. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  420. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND c.Quantity<c.IssueNegQuantity)
  421. BEGIN
  422. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  423. END
  424. UPDATE e SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  425. FROM ICSInventoryLot a
  426. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  427. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  428. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  429. {3}
  430. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  431. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  432. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  433. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  434. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  435. {3}
  436. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND e.IssueQuantity<0)
  437. BEGIN
  438. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  439. END";
  440. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type);
  441. #endregion
  442. }
  443. else
  444. {
  445. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  446. {
  447. table = @"INNER JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  448. INNER JOIN ICSMOPick c ON b.MODetailID = c.MODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
  449. }
  450. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  451. {
  452. table = "INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  453. }
  454. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  455. {
  456. table = "INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  457. }
  458. else
  459. {
  460. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  461. }
  462. #region 原条码
  463. sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  464. FROM ICSWareHouseLotInfoLog a
  465. {3}
  466. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}'
  467. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
  468. {3}
  469. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0)
  470. BEGIN
  471. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  472. END";
  473. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID);
  474. #endregion
  475. }
  476. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  477. {
  478. throw new Exception(language.GetNameByCode("WMSAPIInfo134"));//"生产退料单更新失败!");
  479. }
  480. }
  481. catch (Exception)
  482. {
  483. throw;
  484. }
  485. }
  486. /// <summary>
  487. /// 生产退料接口
  488. /// </summary>
  489. /// <param name="TransType"></param>
  490. /// <param name="Identification"></param>
  491. /// <param name="cmd"></param>
  492. public static void MOIssueDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  493. {
  494. try
  495. {
  496. #region ERP
  497. string sql = string.Empty;
  498. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  499. {
  500. 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,
  501. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  502. ,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,
  503. 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
  504. INTO #TempERP
  505. FROM ICSWareHouseLotInfoLog a
  506. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  507. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  508. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  509. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  510. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  511. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  512. INNER JOIN ICSMOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
  513. INNER JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  514. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  515. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')=''
  516. GROUP BY y.DepCode,a.ToWarehouseCode,y.MOCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,x.PickID,x.MODetailID,con.Enable
  517. ,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, ''),
  518. 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, '')
  519. UNION ALL
  520. 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,
  521. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  522. ,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,
  523. 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
  524. FROM ICSWareHouseLotInfoLog a
  525. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  526. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  527. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  528. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  529. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  530. INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
  531. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  532. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  533. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>''
  534. GROUP BY y.DepCode,a.ToWarehouseCode,y.MOCode,a.MUSER,a.InvCode,x.PickID,x.MODetailID,con.Enable
  535. ,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, ''),
  536. 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, '')
  537. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  538. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  539. DROP TABLE #TempERP";
  540. }
  541. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  542. {
  543. 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,
  544. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  545. ,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,
  546. 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
  547. INTO #TempERP
  548. FROM ICSWareHouseLotInfoLog a
  549. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  550. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  551. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  552. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  553. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  554. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  555. INNER JOIN ICSMOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint
  556. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  557. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')=''
  558. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,con.Enable
  559. ,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, ''),
  560. 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, '')
  561. UNION ALL
  562. 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,
  563. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  564. ,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,
  565. 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
  566. FROM ICSWareHouseLotInfoLog a
  567. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  568. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  569. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  570. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  571. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  572. INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  573. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  574. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>''
  575. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,con.Enable
  576. ,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, ''),
  577. 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, '')
  578. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  579. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  580. DROP TABLE #TempERP";
  581. }
  582. //根据材料出库单查询上游单据,根据上游单据生成红字材料出库
  583. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  584. {
  585. 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,
  586. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  587. ,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,
  588. 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
  589. INTO #TempERP
  590. FROM ICSWareHouseLotInfoLog a
  591. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  592. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  593. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  594. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  595. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  596. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  597. INNER JOIN ICSMOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  598. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  599. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  600. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  601. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  602. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')=''
  603. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,con.Enable
  604. ,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, ''),
  605. 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, '')
  606. UNION ALL
  607. 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,
  608. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  609. ,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,
  610. 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
  611. FROM ICSWareHouseLotInfoLog a
  612. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  613. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  614. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  615. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  616. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  617. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  618. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  619. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  620. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  621. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  622. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>''
  623. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,con.Enable
  624. ,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, ''),
  625. 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, '')
  626. IF EXISTS(SELECT Costre FROM #TempERP WHERE SourceType='{0}')
  627. BEGIN
  628. RAISERROR('" + language.GetNameByCode("WMSAPIInfo135") + @"',16,1);
  629. END
  630. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  631. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  632. DROP TABLE #TempERP";
  633. }
  634. else
  635. {
  636. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  637. }
  638. sql = string.Format(sql, Identification);
  639. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  640. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  641. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueDocNegativeURL, Inputstr);
  642. Result result = new Result();
  643. result = JsonConvert.DeserializeObject<Result>(resultStr);
  644. if (result.Success)
  645. {
  646. try
  647. {
  648. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  649. foreach (var item in res)
  650. {
  651. JObject jo = (JObject)item;
  652. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  653. foreach (var detail in resdetail)
  654. {
  655. JObject det = (JObject)detail;
  656. string allcol = jo["cWhCode"].ToString() + det["ProjectCode"].ToString() + det["BatchCode"].ToString() + det["Version"].ToString() + det["Brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  657. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  658. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  659. det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language);
  660. }
  661. }
  662. }
  663. catch (Exception ex)
  664. {
  665. log.Debug(ex.ToString());
  666. log.Debug(resultStr);
  667. }
  668. }
  669. else
  670. {
  671. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  672. }
  673. #endregion
  674. }
  675. catch (Exception)
  676. {
  677. throw;
  678. }
  679. }
  680. #endregion
  681. #region 生产入库
  682. /// <summary>
  683. /// 生产入库
  684. /// </summary>
  685. /// <param name="TransCode"></param>
  686. /// <param name="TransSequence"></param>
  687. /// <param name="Quantity"></param>
  688. /// <param name="WorkPoint"></param>
  689. /// <param name="cmd"></param>
  690. public static void ManufactureReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  691. {
  692. try
  693. {
  694. string sql = @"DECLARE @Status VARCHAR(10)
  695. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  696. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  697. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  698. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  699. IF (@Status IS NULL)
  700. BEGIN
  701. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  702. RETURN
  703. END
  704. ELSE IF (@Status='3')
  705. BEGIN
  706. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  707. RETURN
  708. END
  709. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  710. FROM ICSInventoryLot a
  711. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  712. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  713. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  714. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  715. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  716. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  717. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.RCVQuantity)
  718. BEGIN
  719. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  720. END";
  721. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  722. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  723. {
  724. throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
  725. }
  726. }
  727. catch (Exception)
  728. {
  729. throw;
  730. }
  731. }
  732. /// <summary>
  733. /// 生产入库接口
  734. /// </summary>
  735. /// <param name="TransType"></param>
  736. /// <param name="Identification"></param>
  737. /// <param name="cmd"></param>
  738. public static void ManufactureReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  739. {
  740. try
  741. {
  742. #region ERP
  743. string sql = @"SELECT c.DepCode+a.ToWarehouseCode+c.MOCode+a.MUSER AS Costre,c.MODetailID 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,
  744. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,c.MODetailID,con.Enable AS UpdateTodoQuantity
  745. ,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,
  746. 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
  747. INTO #TempERP
  748. FROM ICSWareHouseLotInfoLog a
  749. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  750. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  751. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  752. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  753. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  754. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  755. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  756. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  757. WHERE a.Identification='{0}' AND ERPUpload='0'
  758. GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,c.MODetailID,con.Enable,conv.Enable
  759. ,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, ''),
  760. 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
  761. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  762. SELECT Costre,Costre2,TransSequence,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  763. FROM #TempERP
  764. SELECT c.MODetailID AS Costre2,a.TransCode,a.TransSequence AS Sequence,a.InvCode,a.Quantity,c.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
  765. FROM ICSWareHouseLotInfoLog a
  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. WHERE a.Identification='{0}' AND a.TransType='12'
  772. DROP TABLE #TempERP";
  773. sql = string.Format(sql, Identification);
  774. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  775. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre","detailss", "Costre2");
  776. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ManufactureReceiveDocURL, Inputstr);
  777. Result result = new Result();
  778. result = JsonConvert.DeserializeObject<Result>(resultStr);
  779. if (result.Success)
  780. {
  781. try
  782. {
  783. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  784. foreach (var item in res)
  785. {
  786. JObject jo = (JObject)item;
  787. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  788. foreach (var detail in resdetail)
  789. {
  790. JObject det = (JObject)detail;
  791. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  792. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(),"", cmd, language);
  793. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  794. foreach (var details in resdetails)
  795. {
  796. JObject dets = (JObject)details;
  797. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, det["ERPID"].ToString(),
  798. dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString(), dets["Sequence"].ToString(),"", cmd, language);
  799. }
  800. }
  801. }
  802. }
  803. catch (Exception ex)
  804. {
  805. log.Debug(ex.ToString());
  806. log.Debug(resultStr);
  807. }
  808. }
  809. else
  810. {
  811. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  812. }
  813. #endregion
  814. }
  815. catch (Exception)
  816. {
  817. throw;
  818. }
  819. }
  820. #endregion
  821. #region 开立的生产入库单
  822. /// <summary>
  823. /// 开立的生产入库单
  824. /// </summary>
  825. /// <param name="TransCode"></param>
  826. /// <param name="TransSequence"></param>
  827. /// <param name="Quantity"></param>
  828. /// <param name="WorkPoint"></param>
  829. /// <param name="cmd"></param>
  830. public static void ManufactureReceive(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  831. {
  832. try
  833. {
  834. string sql = @"DECLARE @Status VARCHAR(10)
  835. SELECT @Status=c.Status FROM ICSInventoryLot a
  836. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  837. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  838. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  839. IF (@Status IS NULL)
  840. BEGIN
  841. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  842. RETURN
  843. END
  844. ELSE IF (@Status!='1')
  845. BEGIN
  846. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  847. RETURN
  848. END
  849. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  850. FROM ICSInventoryLot a
  851. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  852. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  853. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  854. IF EXISTS(SELECT a.LotNo 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' AND c.Quantity<c.RCVQuantity)
  858. BEGIN
  859. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  860. END";
  861. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  862. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  863. {
  864. throw new Exception(language.GetNameByCode("WMSAPIInfo138"));//"生产入库单更新失败!");
  865. }
  866. }
  867. catch (Exception)
  868. {
  869. throw;
  870. }
  871. }
  872. /// <summary>
  873. /// 开立的生产入库单
  874. /// </summary>
  875. /// <param name="TransType"></param>
  876. /// <param name="Identification"></param>
  877. /// <param name="cmd"></param>
  878. public static void ManufactureReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  879. {
  880. try
  881. {
  882. #region ERP开立状态单据审核
  883. string sql = @"IF EXISTS(SELECT b.ID FROM ICSManufactureReceive b
  884. WHERE b.RCVCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  885. AND b.Quantity!=b.RCVQuantity)
  886. BEGIN
  887. RAISERROR('" + language.GetNameByCode("WMSAPIInfo096") + @"',16,1);
  888. RETURN
  889. END
  890. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  891. FROM ICSWareHouseLotInfoLog a
  892. INNER JOIN ICSManufactureReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  893. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  894. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  895. WHERE a.Identification='{0}' AND ERPUpload='0'
  896. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  897. sql = string.Format(sql, Identification);
  898. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  899. string Inputstr = JsonConvert.SerializeObject(dt);
  900. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSManufactureReceiveURL, Inputstr);
  901. Result result = new Result();
  902. result = JsonConvert.DeserializeObject<Result>(resultStr);
  903. if (result.Success)
  904. {
  905. try
  906. {
  907. foreach (DataRow dr in dt.Rows)
  908. {
  909. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "",cmd, language);
  910. }
  911. }
  912. catch (Exception ex)
  913. {
  914. log.Debug(ex.ToString());
  915. log.Debug(resultStr);
  916. }
  917. }
  918. else
  919. {
  920. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  921. }
  922. #endregion
  923. }
  924. catch (Exception)
  925. {
  926. throw;
  927. }
  928. }
  929. #endregion
  930. #region 返工工单
  931. /// <summary>
  932. /// 返工工单
  933. /// </summary>
  934. /// <param name="TransCode"></param>
  935. /// <param name="TransSequence"></param>
  936. /// <param name="Quantity"></param>
  937. /// <param name="WorkPoint"></param>
  938. /// <param name="cmd"></param>
  939. public static void ReWorkReceiveMo(string LotNo, string Quantity, string WarehouseCode,
  940. string LocationCode, string WorkPoint, String User, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  941. {
  942. try
  943. {
  944. string sql = @"DECLARE @Status VARCHAR(10)
  945. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  946. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  947. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  948. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  949. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  950. IF (@Status IS NULL)
  951. BEGIN
  952. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  953. RETURN
  954. END
  955. ELSE IF (@Status='3')
  956. BEGIN
  957. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  958. RETURN
  959. END
  960. UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  961. FROM ICSInventoryLot a
  962. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  963. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  964. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  965. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  966. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  967. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  968. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  969. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  970. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.IssueQuantity>d.Quantity)
  971. BEGIN
  972. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  973. END";
  974. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  975. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  976. {
  977. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));//"生产工单更新失败!");
  978. }
  979. }
  980. catch (Exception)
  981. {
  982. throw;
  983. }
  984. }
  985. /// <summary>
  986. /// 返工工单
  987. /// </summary>
  988. /// <param name="TransType"></param>
  989. /// <param name="Identification"></param>
  990. /// <param name="cmd"></param>
  991. public static void ReWorkReceiveMoERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  992. {
  993. try
  994. {
  995. #region ERP开立状态单据审核
  996. 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,
  997. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,d.PickID AS MODetailID,Enable AS UpdateTodoQuantity
  998. ,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,
  999. 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
  1000. INTO #TempERP
  1001. FROM ICSWareHouseLotInfoLog a
  1002. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1003. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1004. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1005. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1006. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1007. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1008. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1009. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1010. WHERE a.Identification='{0}' AND ERPUpload='0'
  1011. GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,d.PickID,Enable,d.Sequence
  1012. ,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, ''),
  1013. 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, '')
  1014. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  1015. SELECT Costre,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1016. FROM #TempERP
  1017. DROP TABLE #TempERP";
  1018. sql = string.Format(sql, Identification);
  1019. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1020. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1021. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSReWorkReceiveMoURL, Inputstr);
  1022. Result result = new Result();
  1023. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1024. if (result.Success)
  1025. {
  1026. try
  1027. {
  1028. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1029. foreach (var item in res)
  1030. {
  1031. JObject jo = (JObject)item;
  1032. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1033. foreach (var detail in resdetail)
  1034. {
  1035. JObject det = (JObject)detail;
  1036. string col = "";
  1037. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1038. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), col, cmd, language);
  1039. }
  1040. }
  1041. }
  1042. catch (Exception ex)
  1043. {
  1044. log.Debug(ex.ToString());
  1045. log.Debug(resultStr);
  1046. }
  1047. }
  1048. else
  1049. {
  1050. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1051. }
  1052. #endregion
  1053. }
  1054. catch (Exception)
  1055. {
  1056. throw;
  1057. }
  1058. }
  1059. #endregion
  1060. }
  1061. }