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.

2575 lines
180 KiB

1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year 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,string enableCode)
  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}'
  56. -- AND (dbo.GetExcessQty(a.InvCode, b.Sequence+'~'+a.Sequence, b.MOCode, a.WorkPoint,'{4}'))<a.IssueQuantity)
  57. --BEGIN
  58. --RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  59. --RETURN
  60. --END
  61. ";
  62. log.Debug("子件已发数量增加"+sql);
  63. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, enableCode);
  64. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  65. {
  66. throw new Exception(language.GetNameByCode("WMSAPIInfo127"));//"生产领料单更新失败!");
  67. }
  68. }
  69. catch (Exception)
  70. {
  71. throw;
  72. }
  73. }
  74. /// <summary>
  75. /// 生产发料
  76. /// </summary>
  77. /// <param name="TransCode"></param>
  78. /// <param name="TransSequence"></param>
  79. /// <param name="Quantity"></param>
  80. /// <param name="WorkPoint"></param>
  81. /// <param name="cmd"></param>
  82. public static void AMMOIssueDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string enableCode)
  83. {
  84. try
  85. {
  86. string cheksql = @"select c.EATTRIBUTE1 FROM ICSMOPick a
  87. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  88. INNER JOIN ICSInventory c on a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  89. WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}' and c.AmountEnable='1'";
  90. cheksql = string.Format(cheksql, TransCode, WorkPoint, Quantity, TransSequence, enableCode);
  91. DataTable dt = DBHelper.SQlReturnData(cheksql, cmd);
  92. if (dt.Rows.Count > 0)
  93. {
  94. Quantity = (decimal.Parse(Quantity) * decimal.Parse(dt.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  95. }
  96. string sql = @"DECLARE @Status VARCHAR(10)
  97. SELECT @Status=b.ERPStatus FROM ICSMOPick a
  98. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  99. WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}'
  100. IF (@Status IS NULL)
  101. BEGIN
  102. RAISERROR('" + language.GetNameByCode("WMSAPIInfo125") + @"',16,1);
  103. RETURN
  104. END
  105. ELSE IF (@Status!='2')
  106. BEGIN
  107. RAISERROR('" + language.GetNameByCode("WMSAPIInfo126") + @"',16,1);
  108. RETURN
  109. END
  110. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  111. FROM ICSMOPick a
  112. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  113. WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}'
  114. --IF EXISTS(SELECT a.ID FROM ICSMOPick a
  115. --INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  116. --WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' and a.WorkPoint='{1}'
  117. -- AND (dbo.GetExcessQty(a.InvCode, b.Sequence+'~'+a.Sequence, b.MOCode, a.WorkPoint,'{4}'))<a.IssueQuantity)
  118. --BEGIN
  119. --RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  120. --RETURN
  121. --END
  122. ";
  123. log.Debug("子件已发数量增加" + sql);
  124. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, enableCode);
  125. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  126. {
  127. throw new Exception(language.GetNameByCode("WMSAPIInfo127"));//"生产领料单更新失败!");
  128. }
  129. }
  130. catch (Exception)
  131. {
  132. throw;
  133. }
  134. }
  135. /// <summary>
  136. /// 生产发料接口
  137. /// </summary>
  138. /// <param name="TransType"></param>
  139. /// <param name="Identification"></param>
  140. /// <param name="cmd"></param>
  141. public static void MOIssueDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  142. {
  143. try
  144. {
  145. #region ERP
  146. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  147. INTO #NewTempERP
  148. from ICSWareHouseLotInfoLog
  149. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '13'
  150. 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,
  151. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(x.Amount/x.Quantity)) ELSE '0' END AS Amount,x.PickID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  152. ,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,
  153. 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
  154. ,'1'as DocTypeCode
  155. INTO #TempERP
  156. FROM #NewTempERP a
  157. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  158. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  159. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  160. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  161. INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
  162. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  163. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  164. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  165. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  166. GROUP BY inv.AmountEnable,y.DepCode,a.FromWarehouseCode,y.MOCode,a.MUSER,a.InvCode,x.PickID,x.MODetailID,con.Enable,conv.Enable,conStock.Enable
  167. ,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, ''),
  168. 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, '')
  169. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock FROM #TempERP
  170. SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,PickID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  171. DROP TABLE #TempERP
  172. DROP TABLE #NewTempERP";
  173. sql = string.Format(sql, Identification);
  174. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  175. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  176. string resultStr = "";
  177. if (DBHelper.IsU9())
  178. {
  179. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOIssueDocURL, Inputstr);
  180. }
  181. else
  182. {
  183. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueDocURL, Inputstr);
  184. }
  185. Result result = new Result();
  186. result = JsonConvert.DeserializeObject<Result>(resultStr);
  187. if (result.Success)
  188. {
  189. try
  190. {
  191. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  192. foreach (var item in res)
  193. {
  194. JObject jo = (JObject)item;
  195. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  196. foreach (var detail in resdetail)
  197. {
  198. JObject det = (JObject)detail;
  199. string allcol = jo["WHCode"].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()
  200. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  201. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  202. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol,cmd, language, BusinessCode);
  203. }
  204. }
  205. }
  206. catch (Exception ex)
  207. {
  208. log.Debug(ex.ToString());
  209. log.Debug(resultStr);
  210. }
  211. }
  212. else
  213. {
  214. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  215. }
  216. #endregion
  217. }
  218. catch (Exception)
  219. {
  220. throw;
  221. }
  222. }
  223. #endregion
  224. #region 补料申请单生产发料
  225. /// <summary>
  226. /// 补料申请单生产发料
  227. /// </summary>
  228. /// <param name="TransCode"></param>
  229. /// <param name="TransSequence"></param>
  230. /// <param name="Quantity"></param>
  231. /// <param name="WorkPoint"></param>
  232. /// <param name="cmd"></param>
  233. public static void MOReplenishment(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string enableCode)
  234. {
  235. try
  236. {
  237. string sql = @"DECLARE @Status VARCHAR(10)
  238. SELECT @Status=a.Status FROM ICSMOReplenishment a
  239. WHERE a.ReplenishmentCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  240. IF (@Status IS NULL)
  241. BEGIN
  242. RAISERROR('" + language.GetNameByCode("WMSAPIInfo128") + @"',16,1);
  243. RETURN
  244. END
  245. ELSE IF (@Status!='2')
  246. BEGIN
  247. RAISERROR('" + language.GetNameByCode("WMSAPIInfo129") + @"',16,1);
  248. RETURN
  249. END
  250. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  251. FROM ICSMOReplenishment a
  252. WHERE a.ReplenishmentCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  253. IF EXISTS(SELECT a.ID FROM ICSMOReplenishment a
  254. WHERE a.ReplenishmentCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}'
  255. AND (dbo.GetExcessQty(a.InvCode, a.Sequence, a.ReplenishmentCode, a.WorkPoint,'{4}'))<a.IssueQuantity)
  256. BEGIN
  257. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  258. RETURN
  259. END";
  260. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence,enableCode);
  261. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  262. {
  263. throw new Exception(language.GetNameByCode("WMSAPIInfo130"));//"领料申请单更新失败!");
  264. }
  265. }
  266. catch (Exception)
  267. {
  268. throw;
  269. }
  270. }
  271. /// <summary>
  272. /// 补料申请单生产发料接口
  273. /// </summary>
  274. /// <param name="TransType"></param>
  275. /// <param name="Identification"></param>
  276. /// <param name="cmd"></param>
  277. public static void MOReplenishmentERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  278. {
  279. try
  280. {
  281. #region ERP
  282. string sql = @"SELECT a.FromWarehouseCode+b.ReplenishmentCode+a.MUSER AS Costre,a.FromWarehouseCode AS WarehouseCode,b.ReplenishmentCode,b.SourceCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.ReplenishmentCode,b.ReplenishmentDetailID,a.InvCode) AS Sequence,
  283. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount,b.ReplenishmentDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  284. ,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,
  285. 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
  286. INTO #TempERP
  287. FROM ICSWareHouseLotInfoLog a
  288. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  289. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  290. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  291. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  292. INNER JOIN ICSMOReplenishment b ON a.TransCode=b.ReplenishmentCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  293. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  294. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  295. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  296. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '49'
  297. GROUP BY inv.AmountEnable,a.FromWarehouseCode,b.ReplenishmentCode,b.SourceCode,a.MUSER,a.InvCode,b.ReplenishmentDetailID,con.Enable,conv.Enable,conStock.Enable
  298. ,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, ''),
  299. 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, '')
  300. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ReplenishmentCode AS SourceCode,SourceCode AS IssueCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock FROM #TempERP
  301. SELECT Costre,Sequence,InvCode,Quantity,Amount,ReplenishmentDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  302. DROP TABLE #TempERP";
  303. sql = string.Format(sql, Identification);
  304. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  305. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  306. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOReplenishmentURL, Inputstr);
  307. Result result = new Result();
  308. result = JsonConvert.DeserializeObject<Result>(resultStr);
  309. if (result.Success)
  310. {
  311. try
  312. {
  313. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  314. foreach (var item in res)
  315. {
  316. JObject jo = (JObject)item;
  317. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  318. foreach (var detail in resdetail)
  319. {
  320. JObject det = (JObject)detail;
  321. string allcol = jo["WHCode"].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()
  322. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  323. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  324. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  325. }
  326. }
  327. }
  328. catch (Exception ex)
  329. {
  330. log.Debug(ex.ToString());
  331. log.Debug(resultStr);
  332. }
  333. }
  334. else
  335. {
  336. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  337. }
  338. #endregion
  339. }
  340. catch (Exception)
  341. {
  342. throw;
  343. }
  344. }
  345. #endregion
  346. #region 领料申请单生产发料
  347. /// <summary>
  348. /// 领料申请单生产发料
  349. /// </summary>
  350. /// <param name="TransCode"></param>
  351. /// <param name="TransSequence"></param>
  352. /// <param name="Quantity"></param>
  353. /// <param name="WorkPoint"></param>
  354. /// <param name="cmd"></param>
  355. public static void MOApply(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string enableCode)
  356. {
  357. try
  358. {
  359. string sql = @"DECLARE @Status VARCHAR(10)
  360. SELECT @Status=a.Status FROM ICSMOApply a
  361. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  362. IF (@Status IS NULL)
  363. BEGIN
  364. RAISERROR('" + language.GetNameByCode("WMSAPIInfo128") + @"',16,1);
  365. RETURN
  366. END
  367. ELSE IF (@Status!='2')
  368. BEGIN
  369. RAISERROR('" + language.GetNameByCode("WMSAPIInfo129") + @"',16,1);
  370. RETURN
  371. END
  372. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  373. FROM ICSMOApply a
  374. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  375. IF EXISTS(SELECT a.ID FROM ICSMOApply a
  376. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}'
  377. AND (dbo.GetExcessQty(a.InvCode, a.Sequence, a.ApplyCode, a.WorkPoint,'{4}'))<a.IssueQuantity)
  378. BEGIN
  379. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  380. RETURN
  381. END";
  382. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, enableCode);
  383. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  384. {
  385. throw new Exception(language.GetNameByCode("WMSAPIInfo130"));//"领料申请单更新失败!");
  386. }
  387. }
  388. catch (Exception)
  389. {
  390. throw;
  391. }
  392. }
  393. /// <summary>
  394. /// 领料申请单生产发料接口
  395. /// </summary>
  396. /// <param name="TransType"></param>
  397. /// <param name="Identification"></param>
  398. /// <param name="cmd"></param>
  399. public static void MOApplyERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  400. {
  401. try
  402. {
  403. #region ERP
  404. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  405. INTO #NewTempERP
  406. from ICSWareHouseLotInfoLog
  407. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '14'
  408. SELECT a.FromWarehouseCode+b.ApplyCode+a.MUSER+ISNULL(b.SourceCode,'')+ISNULL(c.DepCode,'') AS Costre,a.FromWarehouseCode AS WarehouseCode,b.ApplyCode,ISNULL(b.SourceCode,'') AS SourceCode,ISNULL(c.DepCode,'') AS DepCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.ApplyCode,b.ApplyDetailID,a.InvCode) AS Sequence,
  409. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount,b.ApplyDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  410. ,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,
  411. 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
  412. ,b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode,b.EATTRIBUTE7 as Project,b.EATTRIBUTE as Dep
  413. INTO #TempERP
  414. FROM #NewTempERP a
  415. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  416. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  417. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  418. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  419. INNER JOIN ICSMOApply b ON a.TransCode=b.ApplyCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  420. LEFT JOIN ICSMO c ON b.SourceCode=c.MOCode AND b.SourceSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  421. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  422. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  423. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  424. GROUP BY inv.AmountEnable,a.FromWarehouseCode,b.ApplyCode,b.SourceCode,c.DepCode,a.MUSER,a.InvCode,b.ApplyDetailID,con.Enable,conv.Enable,conStock.Enable
  425. ,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, ''),
  426. 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, ''),b.EATTRIBUTE2,b.EATTRIBUTE4,b.EATTRIBUTE,b.EATTRIBUTE7
  427. SELECT DISTINCT Costre,WorkPoint,ISNULL(DepCode,'') AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,ISNULL(SourceCode,'') AS IssueCode ,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,DocType,ClientCode FROM #TempERP
  428. SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,ApplyDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Project,Dep FROM #TempERP
  429. DROP TABLE #TempERP
  430. DROP TABLE #NewTempERP";
  431. sql = string.Format(sql, Identification);
  432. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  433. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  434. string resultStr="";
  435. if (DBHelper.IsU9())
  436. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherOutDocURL, Inputstr); }
  437. else
  438. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOApplyURL, Inputstr); }
  439. Result result = new Result();
  440. result = JsonConvert.DeserializeObject<Result>(resultStr);
  441. if (result.Success)
  442. {
  443. try
  444. {
  445. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  446. foreach (var item in res)
  447. {
  448. JObject jo = (JObject)item;
  449. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  450. foreach (var detail in resdetail)
  451. {
  452. JObject det = (JObject)detail;
  453. string allcol = jo["WHCode"].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()
  454. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  455. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  456. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  457. }
  458. }
  459. }
  460. catch (Exception ex)
  461. {
  462. log.Debug(ex.ToString());
  463. log.Debug(resultStr);
  464. }
  465. }
  466. else
  467. {
  468. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  469. }
  470. #endregion
  471. }
  472. catch (Exception)
  473. {
  474. throw;
  475. }
  476. }
  477. #endregion
  478. #region 材料出库单生产发料
  479. /// <summary>
  480. /// 材料出库单生产发料
  481. /// </summary>
  482. /// <param name="TransCode"></param>
  483. /// <param name="TransSequence"></param>
  484. /// <param name="Quantity"></param>
  485. /// <param name="WorkPoint"></param>
  486. /// <param name="cmd"></param>
  487. public static void MOIssue(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  488. {
  489. try
  490. {
  491. string sql = @"DECLARE @Status VARCHAR(10)
  492. SELECT @Status=a.Status FROM ICSMOIssue a
  493. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  494. IF (@Status IS NULL)
  495. BEGIN
  496. RAISERROR('" + language.GetNameByCode("WMSAPIInfo131") + @"',16,1);
  497. RETURN
  498. END
  499. ELSE IF (@Status!='1')
  500. BEGIN
  501. RAISERROR('" + language.GetNameByCode("WMSAPIInfo132") + @"',16,1);
  502. RETURN
  503. END
  504. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  505. FROM ICSMOIssue a
  506. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  507. IF EXISTS(SELECT a.ID FROM ICSMOIssue a
  508. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  509. BEGIN
  510. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  511. RETURN
  512. END";
  513. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  514. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  515. {
  516. throw new Exception(language.GetNameByCode("WMSAPIInfo133"));//"材料出库单更新失败!");
  517. }
  518. }
  519. catch (Exception)
  520. {
  521. throw;
  522. }
  523. }
  524. /// <summary>
  525. /// 材料出库单生产发料接口
  526. /// </summary>
  527. /// <param name="TransType"></param>
  528. /// <param name="Identification"></param>
  529. /// <param name="cmd"></param>
  530. public static void MOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  531. {
  532. try
  533. {
  534. #region ERP开立状态单据审核
  535. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  536. INTO #NewTempERP
  537. from ICSWareHouseLotInfoLog
  538. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '15'
  539. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  540. INNER JOIN ICSMOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  541. WHERE a.Identification='{0}' AND b.Quantity!=b.IssueQuantity)
  542. BEGIN
  543. RAISERROR('" + language.GetNameByCode("WMSAPIInfo094") + @"',16,1);
  544. RETURN
  545. END
  546. SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity
  547. ,conStock.Enable AS UpdateStock,a.WorkPoint
  548. FROM #NewTempERP a
  549. INNER JOIN ICSMOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  550. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  551. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  552. GROUP BY b.IssueID,a.MUSER,con.Enable
  553. ,conStock.Enable,a.WorkPoint
  554. DROP TABLE #NewTempERP";
  555. sql = string.Format(sql, Identification);
  556. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  557. string Inputstr = JsonConvert.SerializeObject(dt);
  558. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueURL, Inputstr);
  559. Result result = new Result();
  560. result = JsonConvert.DeserializeObject<Result>(resultStr);
  561. if (result.Success)
  562. {
  563. try
  564. {
  565. foreach (DataRow dr in dt.Rows)
  566. {
  567. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "",cmd, language, BusinessCode);
  568. }
  569. }
  570. catch (Exception ex)
  571. {
  572. log.Debug(ex.ToString());
  573. log.Debug(resultStr);
  574. }
  575. }
  576. else
  577. {
  578. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  579. }
  580. #endregion
  581. }
  582. catch (Exception)
  583. {
  584. throw;
  585. }
  586. }
  587. /// <summary>
  588. /// U9超额领料单审核接口
  589. /// </summary>
  590. /// <param name="TransType"></param>
  591. /// <param name="Identification"></param>
  592. /// <param name="cmd"></param>
  593. public static void U9MOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  594. {
  595. try
  596. {
  597. #region ERP
  598. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  599. INTO #NewTempERP
  600. from ICSWareHouseLotInfoLog
  601. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '15'
  602. SELECT a.FromWarehouseCode+b.IssueCode+a.MUSER+ISNULL(b.SourceCode,'')+ISNULL(c.DepCode,'') AS Costre,a.FromWarehouseCode AS WarehouseCode,b.IssueCode,ISNULL(b.SourceCode,'') AS SourceCode,ISNULL(c.DepCode,'') AS DepCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.IssueCode,b.IssueDetailID,a.InvCode) AS Sequence,
  603. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount,b.IssueDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  604. ,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,
  605. 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
  606. ,b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode
  607. INTO #TempERP
  608. FROM #NewTempERP a
  609. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  610. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  611. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  612. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  613. INNER JOIN ICSMoIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  614. LEFT JOIN ICSMO c ON b.SourceCode=c.MOCode AND b.SourceSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  615. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  616. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  617. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  618. GROUP BY inv.AmountEnable,a.FromWarehouseCode,b.IssueCode,b.SourceCode,c.DepCode,a.MUSER,a.InvCode,b.IssueDetailID,con.Enable,conv.Enable,conStock.Enable
  619. ,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, ''),
  620. 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, ''),b.EATTRIBUTE2,b.EATTRIBUTE4
  621. SELECT DISTINCT Costre,WorkPoint,ISNULL(DepCode,'') AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,IssueCode AS SourceCode,ISNULL(SourceCode,'') AS IssueCode ,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,DocType,ClientCode FROM #TempERP
  622. SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,IssueDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  623. DROP TABLE #TempERP
  624. DROP TABLE #NewTempERP";
  625. sql = string.Format(sql, Identification);
  626. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  627. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  628. string resultStr = "";
  629. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOApplyURL, Inputstr);
  630. Result result = new Result();
  631. result = JsonConvert.DeserializeObject<Result>(resultStr);
  632. if (result.Success)
  633. {
  634. try
  635. {
  636. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  637. foreach (var item in res)
  638. {
  639. JObject jo = (JObject)item;
  640. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  641. foreach (var detail in resdetail)
  642. {
  643. JObject det = (JObject)detail;
  644. 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()
  645. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  646. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  647. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  648. }
  649. }
  650. }
  651. catch (Exception ex)
  652. {
  653. log.Debug(ex.ToString());
  654. log.Debug(resultStr);
  655. }
  656. }
  657. else
  658. {
  659. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  660. }
  661. #endregion
  662. }
  663. catch (Exception)
  664. {
  665. throw;
  666. }
  667. }
  668. #endregion
  669. #region 生产退料
  670. /// <summary>
  671. /// 生产退料
  672. /// </summary>
  673. /// <param name="TransCode"></param>
  674. /// <param name="TransSequence"></param>
  675. /// <param name="Quantity"></param>
  676. /// <param name="WorkPoint"></param>
  677. /// <param name="cmd"></param>
  678. public static void MOIssueDocNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  679. {
  680. try
  681. {
  682. string table = "";
  683. string table1 = "";
  684. string sql = "";
  685. if (string.IsNullOrWhiteSpace(LogID))
  686. {
  687. string type = "";
  688. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  689. {
  690. table = "INNER JOIN ICSMOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint";
  691. type = "1";
  692. }
  693. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  694. {
  695. table = "INNER JOIN ICSMOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
  696. type = "2";
  697. }
  698. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  699. {
  700. table = "INNER JOIN ICSMOIssue e ON c.SourceDetailID=e.IssueDetailID AND c.WorkPoint=e.WorkPoint";
  701. table1 = " INNER JOIN ICSMOIssue ee ON c.SourceDetailID=ee.IssueDetailID AND c.WorkPoint=ee.WorkPoint " +
  702. " INNER JOIN icsmopick e ON e.pickid = ee.pickid";
  703. type = "3";
  704. }
  705. else
  706. {
  707. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  708. }
  709. #region 新条码
  710. sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  711. FROM ICSInventoryLot a
  712. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  713. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  714. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  715. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  716. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  717. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  718. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  719. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  720. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND c.Quantity<c.IssueNegQuantity)
  721. BEGIN
  722. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  723. END
  724. UPDATE e SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  725. FROM ICSInventoryLot a
  726. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  727. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  728. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  729. {3}
  730. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  731. UPDATE e SET e.IssueQuantity=ISNULL(e.IssueQuantity,0)-'{2}'
  732. FROM ICSInventoryLot a
  733. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  734. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  735. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  736. {5}
  737. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' and ISNULL(e.IssueQuantity,0)>0
  738. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  739. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  740. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  741. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  742. {3}
  743. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND e.IssueQuantity<0)
  744. BEGIN
  745. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  746. END";
  747. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type,table1);
  748. #endregion
  749. }
  750. else
  751. {
  752. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  753. {
  754. table = @"INNER JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  755. INNER JOIN ICSMOPick c ON b.MODetailID = c.MODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
  756. }
  757. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  758. {
  759. table = "INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  760. }
  761. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  762. {
  763. table = "INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  764. }
  765. else
  766. {
  767. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  768. }
  769. #region 原条码
  770. sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  771. FROM ICSWareHouseLotInfoLog a
  772. {3}
  773. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}'
  774. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
  775. {3}
  776. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0)
  777. BEGIN
  778. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  779. END";
  780. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID);
  781. #endregion
  782. }
  783. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  784. {
  785. throw new Exception(language.GetNameByCode("WMSAPIInfo134"));//"生产退料单更新失败!");
  786. }
  787. }
  788. catch (Exception)
  789. {
  790. throw;
  791. }
  792. }
  793. /// <summary>
  794. /// 生产退料(奥美专用)
  795. /// </summary>
  796. /// <param name="TransCode"></param>
  797. /// <param name="TransSequence"></param>
  798. /// <param name="Quantity"></param>
  799. /// <param name="WorkPoint"></param>
  800. /// <param name="cmd"></param>
  801. public static void AMMOIssueDocNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint,string TransCode,string TransSequence, SqlCommand cmd, Dictionary<string, string> language)
  802. {
  803. try
  804. {
  805. string table = "";
  806. string sql = "";
  807. if (string.IsNullOrWhiteSpace(LogID))
  808. {
  809. string type = "";
  810. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  811. {
  812. table = "INNER JOIN ICSMOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint";
  813. type = "1";
  814. }
  815. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  816. {
  817. table = "INNER JOIN ICSMOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
  818. type = "2";
  819. }
  820. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  821. {
  822. table = "INNER JOIN ICSMOIssue e ON c.SourceDetailID=e.IssueDetailID AND c.WorkPoint=e.WorkPoint";
  823. type = "3";
  824. }
  825. else
  826. {
  827. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  828. }
  829. #region 新条码
  830. sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  831. FROM ICSInventoryLot a
  832. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  833. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  834. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  835. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  836. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  837. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  838. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  839. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  840. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND c.Quantity<c.IssueNegQuantity)
  841. BEGIN
  842. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  843. END
  844. UPDATE e SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  845. FROM ICSInventoryLot a
  846. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  847. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  848. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  849. {3}
  850. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  851. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  852. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  853. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  854. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  855. {3}
  856. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND e.IssueQuantity<0)
  857. BEGIN
  858. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  859. END";
  860. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type);
  861. #endregion
  862. }
  863. else
  864. {
  865. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  866. {
  867. table = @"INNER JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  868. INNER JOIN ICSMOPick c ON b.MODetailID = c.MODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
  869. }
  870. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  871. {
  872. table = "INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  873. }
  874. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  875. {
  876. table = "INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  877. }
  878. else
  879. {
  880. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  881. }
  882. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  883. {
  884. #region 原条码
  885. sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  886. FROM ICSWareHouseLotInfoLog a
  887. {3}
  888. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' and b.MoCode='{5}' AND b.Sequence + '~' + c.Sequence='{6}'
  889. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
  890. {3}
  891. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0 and b.MoCode='{5}' AND b.Sequence + '~' + c.Sequence='{6}')
  892. BEGIN
  893. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  894. END";
  895. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID, TransCode, TransSequence);
  896. }
  897. else
  898. {
  899. sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  900. FROM ICSWareHouseLotInfoLog a
  901. {3}
  902. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}'
  903. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
  904. {3}
  905. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0)
  906. BEGIN
  907. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  908. END";
  909. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID, TransCode, TransSequence);
  910. }
  911. #endregion
  912. }
  913. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  914. {
  915. throw new Exception(language.GetNameByCode("WMSAPIInfo134"));//"生产退料单更新失败!");
  916. }
  917. }
  918. catch (Exception)
  919. {
  920. throw;
  921. }
  922. }
  923. /// <summary>
  924. /// 生产退料接口
  925. /// </summary>
  926. /// <param name="TransType"></param>
  927. /// <param name="Identification"></param>
  928. /// <param name="cmd"></param>
  929. public static void MOIssueDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  930. {
  931. try
  932. {
  933. #region ERP
  934. log.Debug("调用ERP接口入口");
  935. string sql = string.Empty;
  936. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  937. {
  938. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  939. INTO #NewTempERP
  940. from ICSWareHouseLotInfoLog
  941. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  942. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  943. INTO #NewDouTempERP
  944. from ICSWareHouseLotInfoLog
  945. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  946. 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,
  947. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  948. ,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,
  949. 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
  950. INTO #TempERP
  951. FROM #NewTempERP a
  952. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  953. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  954. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  955. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  956. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  957. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  958. INNER JOIN ICSMOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
  959. INNER JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  960. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  961. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  962. GROUP BY inv.AmountEnable,y.DepCode,a.ToWarehouseCode,y.MOCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,x.PickID,x.MODetailID,con.Enable,conStock.Enable
  963. ,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, ''),
  964. 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, '')
  965. UNION ALL
  966. 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,
  967. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  968. ,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,
  969. 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
  970. FROM #NewDouTempERP a
  971. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  972. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  973. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  974. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  975. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  976. INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
  977. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  978. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  979. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  980. GROUP BY y.DepCode,a.ToWarehouseCode,y.MOCode,a.MUSER,a.InvCode,x.PickID,x.MODetailID,con.Enable,conStock.Enable
  981. ,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, ''),
  982. 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, '')
  983. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  984. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ,WarehouseCode AS WHCode FROM #TempERP
  985. DROP TABLE #TempERP
  986. DROP TABLE #NewTempERP
  987. DROP TABLE #NewDouTempERP";
  988. }
  989. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  990. {
  991. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  992. INTO #NewTempERP
  993. from ICSWareHouseLotInfoLog
  994. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  995. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  996. INTO #NewDouTempERP
  997. from ICSWareHouseLotInfoLog
  998. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  999. 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,
  1000. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1001. ,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,
  1002. 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
  1003. INTO #TempERP
  1004. FROM #NewTempERP a
  1005. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1006. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1007. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1008. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1009. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1010. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1011. INNER JOIN ICSMOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint
  1012. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1013. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1014. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,con.Enable,conStock.Enable
  1015. ,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, ''),
  1016. 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, '')
  1017. UNION ALL
  1018. 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,
  1019. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1020. ,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,
  1021. 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
  1022. FROM #NewDouTempERP a
  1023. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1024. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1025. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1026. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1027. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1028. INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  1029. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1030. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1031. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,con.Enable,conStock.Enable
  1032. ,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, ''),
  1033. 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, '')
  1034. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1035. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ,WarehouseCode AS WHCode FROM #TempERP
  1036. DROP TABLE #TempERP
  1037. DROP TABLE #NewTempERP
  1038. DROP TABLE #NewDouTempERP";
  1039. }
  1040. //根据材料出库单查询上游单据,根据上游单据生成红字材料出库
  1041. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1042. {
  1043. sql = @"
  1044. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  1045. INTO #NewTempERP
  1046. from ICSWareHouseLotInfoLog
  1047. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  1048. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  1049. INTO #NewDouTempERP
  1050. from ICSWareHouseLotInfoLog
  1051. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  1052. IF EXISTS(select * FROM #NewTempERP a
  1053. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1054. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1055. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1056. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1057. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1058. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1059. INNER JOIN ICSMOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1060. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1061. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1062. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1063. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1064. where m.ApplyDetailID<>null and z.ApplyDetailID=null)
  1065. BEGIN
  1066. RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
  1067. RETURN
  1068. END
  1069. IF EXISTS(select * FROM #NewDouTempERP a
  1070. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1071. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1072. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1073. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1074. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1075. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1076. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1077. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1078. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1079. where m.ApplyDetailID<>null and z.ApplyDetailID=null)
  1080. BEGIN
  1081. RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
  1082. RETURN
  1083. END
  1084. 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,
  1085. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1086. ,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,
  1087. 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
  1088. ,m.issuecode as DocCode,m.Sequence as DocLineNo
  1089. INTO #TempERP
  1090. FROM #NewTempERP a
  1091. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1092. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1093. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1094. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1095. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1096. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1097. INNER JOIN ICSMOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1098. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1099. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1100. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1101. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1102. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1103. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,con.Enable,conStock.Enable
  1104. ,m.issuecode,m.Sequence ,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, ''),
  1105. 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, '')
  1106. UNION ALL
  1107. 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,
  1108. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1109. ,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,
  1110. 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
  1111. ,m.issuecode as DocCode,m.Sequence as DocLineNo
  1112. FROM #NewDouTempERP a
  1113. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1114. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1115. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1116. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1117. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1118. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1119. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1120. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1121. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1122. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1123. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1124. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,con.Enable,conStock.Enable
  1125. ,m.issuecode,m.Sequence ,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, ''),
  1126. 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, '')
  1127. IF EXISTS(SELECT Costre FROM #TempERP WHERE SourceType='{0}')
  1128. BEGIN
  1129. RAISERROR('" + language.GetNameByCode("WMSAPIInfo135") + @"',16,1);
  1130. END
  1131. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock,DocCode FROM #TempERP
  1132. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ,WarehouseCode AS WHCode, DocLineNo FROM #TempERP
  1133. DROP TABLE #TempERP
  1134. DROP TABLE #NewTempERP
  1135. DROP TABLE #NewDouTempERP";
  1136. }
  1137. else
  1138. {
  1139. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  1140. }
  1141. sql = string.Format(sql, Identification);
  1142. log.Debug("调用ERP接口sql");
  1143. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1144. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1145. string resultStr = "";
  1146. log.Debug("ERP接口日志前");
  1147. if (DBHelper.IsU9())
  1148. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOIssueDocNegativeURL, Inputstr); }
  1149. else
  1150. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueDocNegativeURL, Inputstr); }
  1151. log.Debug("ERP接口日志后");
  1152. Result result = new Result();
  1153. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1154. if (result.Success)
  1155. {
  1156. try
  1157. {
  1158. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1159. foreach (var item in res)
  1160. {
  1161. JObject jo = (JObject)item;
  1162. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1163. foreach (var detail in resdetail)
  1164. {
  1165. JObject det = (JObject)detail;
  1166. string allcol = jo["WHCode"].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()
  1167. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1168. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1169. det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1170. }
  1171. }
  1172. }
  1173. catch (Exception ex)
  1174. {
  1175. log.Debug(ex.ToString());
  1176. log.Debug(resultStr);
  1177. }
  1178. }
  1179. else
  1180. {
  1181. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1182. }
  1183. #endregion
  1184. }
  1185. catch (Exception)
  1186. {
  1187. throw;
  1188. }
  1189. }
  1190. #endregion
  1191. #region 生产入库
  1192. /// <summary>
  1193. /// 生产入库
  1194. /// </summary>
  1195. /// <param name="TransCode"></param>
  1196. /// <param name="TransSequence"></param>
  1197. /// <param name="Quantity"></param>
  1198. /// <param name="WorkPoint"></param>
  1199. /// <param name="cmd"></param>
  1200. public static void ManufactureReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1201. {
  1202. try
  1203. {
  1204. string sql = @"DECLARE @Status VARCHAR(10)
  1205. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  1206. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1207. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1208. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1209. IF (@Status IS NULL)
  1210. BEGIN
  1211. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1212. RETURN
  1213. END
  1214. ELSE IF (@Status='3')
  1215. BEGIN
  1216. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1217. RETURN
  1218. END
  1219. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1220. FROM ICSInventoryLot a
  1221. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1222. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1223. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1224. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1225. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1226. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1227. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1228. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn001', '{0}')<c.RCVQuantity)
  1229. BEGIN
  1230. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1231. END";
  1232. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1233. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1234. {
  1235. throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
  1236. }
  1237. }
  1238. catch (Exception)
  1239. {
  1240. throw;
  1241. }
  1242. }
  1243. /// <summary>
  1244. /// 生产入库(奥美专用)
  1245. /// </summary>
  1246. /// <param name="TransCode"></param>
  1247. /// <param name="TransSequence"></param>
  1248. /// <param name="Quantity"></param>
  1249. /// <param name="WorkPoint"></param>
  1250. /// <param name="cmd"></param>
  1251. public static void ManufactureReceiveDocAM(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1252. {
  1253. try
  1254. {
  1255. string cheksql = @"select d.EATTRIBUTE1 FROM ICSInventoryLot a
  1256. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1257. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1258. INNER JOIN ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1259. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and d.AmountEnable='1'";
  1260. cheksql = string.Format(cheksql, LotNo, WorkPoint);
  1261. DataTable dt = DBHelper.SQlReturnData(cheksql, cmd);
  1262. if (dt.Rows.Count > 0)
  1263. {
  1264. Quantity = (decimal.Parse(Quantity) * decimal.Parse(dt.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  1265. }
  1266. string sql = @"DECLARE @Status VARCHAR(10)
  1267. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  1268. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1269. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1270. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1271. IF (@Status IS NULL)
  1272. BEGIN
  1273. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1274. RETURN
  1275. END
  1276. ELSE IF (@Status='3')
  1277. BEGIN
  1278. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1279. RETURN
  1280. END
  1281. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1282. FROM ICSInventoryLot a
  1283. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1284. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1285. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1286. --IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1287. -- INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1288. -- INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1289. -- WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1290. -- AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn001', '{0}')<c.RCVQuantity)
  1291. --BEGIN
  1292. -- RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1293. --END";
  1294. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1295. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1296. {
  1297. throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
  1298. }
  1299. }
  1300. catch (Exception)
  1301. {
  1302. throw;
  1303. }
  1304. }
  1305. /// <summary>
  1306. /// 生产入库接口
  1307. /// </summary>
  1308. /// <param name="TransType"></param>
  1309. /// <param name="Identification"></param>
  1310. /// <param name="cmd"></param>
  1311. public static void ManufactureReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1312. {
  1313. try
  1314. {
  1315. #region ERP
  1316. string sql = @"SELECT ISNULL(c.DepCode,'')+a.ToWarehouseCode+c.MOCode+a.MUSER AS Costre,
  1317. c.MODetailID+CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END+ CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END
  1318. + CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END
  1319. + CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END
  1320. + CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END
  1321. + CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END
  1322. + CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END
  1323. + CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END
  1324. + CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END
  1325. + CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END
  1326. + CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END
  1327. + CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END
  1328. + CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS Costre2,lot.EATTRIBUTE2,
  1329. 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,
  1330. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,c.MODetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose
  1331. ,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END AS ProjectCode,
  1332. 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,
  1333. CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END AS Version,
  1334. CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END AS Brand,
  1335. CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END AS cFree1,
  1336. CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END AS cFree2,
  1337. CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END AS cFree3,
  1338. CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END AS cFree4,
  1339. CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END AS cFree5,
  1340. CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END AS cFree6,
  1341. CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END AS cFree7,
  1342. CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END AS cFree8,
  1343. CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END AS cFree9,
  1344. CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS cFree10,
  1345. conv.Enable AS CompleteVerification,a.TransSequence
  1346. INTO #TempERP
  1347. FROM ICSWareHouseLotInfoLog a
  1348. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1349. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1350. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1351. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1352. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1353. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1354. INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
  1355. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1356. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  1357. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  1358. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose001'
  1359. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1360. GROUP BY inv.AmountEnable,c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,c.MODetailID,con.Enable,conv.Enable,conStock.Enable,conStocknew.Enable
  1361. ,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END,lot.EATTRIBUTE2,
  1362. CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,
  1363. CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END,
  1364. CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END,
  1365. CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END,
  1366. CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END,
  1367. CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END,
  1368. CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END,
  1369. CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END,
  1370. CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END,
  1371. CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END,
  1372. CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END,
  1373. CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END,
  1374. CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END,a.TransSequence
  1375. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,IsFillClose FROM #TempERP
  1376. SELECT Costre,Costre2,TransSequence,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,EATTRIBUTE2 as OutType
  1377. FROM #TempERP
  1378. 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
  1379. FROM ICSWareHouseLotInfoLog a
  1380. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1381. INNER JOIN ICSMO b ON b.MOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  1382. INNER JOIN ICSMOPick c ON c.MODetailID=b.MODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  1383. INNER JOIN ICSExtension ext ON ext.ID=c.ExtensionID AND ext.WorkPoint=c.WorkPoint
  1384. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1385. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1386. INNER JOIN #TempERP te ON te.TransSequence=SUBSTRING(a.TransSequence,1,CHARINDEX('~',a.TransSequence)-1)
  1387. WHERE a.Identification='{0}' AND a.TransType='12'
  1388. 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, ''),
  1389. 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
  1390. DROP TABLE #TempERP";
  1391. sql = string.Format(sql, Identification, BusinessCode);
  1392. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1393. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre","detailss", "Costre2");
  1394. string resultStr = "";
  1395. if (DBHelper.IsU9())
  1396. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOStockINByProductDocURL, Inputstr); }
  1397. else { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ManufactureReceiveDocURL, Inputstr); }
  1398. Result result = new Result();
  1399. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1400. if (result.Success)
  1401. {
  1402. try
  1403. {
  1404. if (result.Data!=null)
  1405. {
  1406. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1407. foreach (var item in res)
  1408. {
  1409. JObject jo = (JObject)item;
  1410. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1411. foreach (var detail in resdetail)
  1412. {
  1413. JObject det = (JObject)detail;
  1414. 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()
  1415. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1416. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1417. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1418. if (det["detailss"] != null)
  1419. {
  1420. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  1421. foreach (var details in resdetails)
  1422. {
  1423. JObject dets = (JObject)details;
  1424. if (dets != null)
  1425. {
  1426. //直接回写
  1427. string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1428. FROM ICSWareHouseLotInfoLog a
  1429. LEFT JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  1430. LEFT JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  1431. WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{6}'";
  1432. ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString()
  1433. , dets["Sequence"].ToString(), BusinessCode);
  1434. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1435. {
  1436. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"成品倒冲回写失败!";
  1437. }
  1438. }
  1439. }
  1440. }
  1441. }
  1442. }
  1443. }
  1444. }
  1445. catch (Exception ex)
  1446. {
  1447. log.Debug(ex.ToString());
  1448. log.Debug(resultStr);
  1449. throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  1450. }
  1451. }
  1452. else
  1453. {
  1454. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1455. }
  1456. #endregion
  1457. }
  1458. catch (Exception)
  1459. {
  1460. throw;
  1461. }
  1462. }
  1463. #endregion
  1464. #region 副产品入库
  1465. /// <summary>
  1466. /// 副产品入库
  1467. /// </summary>
  1468. /// <param name="TransCode"></param>
  1469. /// <param name="TransSequence"></param>
  1470. /// <param name="Quantity"></param>
  1471. /// <param name="WorkPoint"></param>
  1472. /// <param name="cmd"></param>
  1473. public static void MOStockINByProductDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1474. {
  1475. try
  1476. {
  1477. string sql = @"DECLARE @Status VARCHAR(10)
  1478. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  1479. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1480. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1481. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  1482. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1483. IF (@Status IS NULL)
  1484. BEGIN
  1485. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1486. RETURN
  1487. END
  1488. ELSE IF (@Status='3')
  1489. BEGIN
  1490. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1491. RETURN
  1492. END
  1493. UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  1494. FROM ICSInventoryLot a
  1495. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1496. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1497. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  1498. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1499. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1500. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1501. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1502. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  1503. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1504. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn001', '{0}')<c.RCVQuantity)
  1505. BEGIN
  1506. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1507. END";
  1508. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1509. log.Debug("副产品入库:" + sql);
  1510. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1511. {
  1512. throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
  1513. }
  1514. }
  1515. catch (Exception)
  1516. {
  1517. throw;
  1518. }
  1519. }
  1520. /// <summary>
  1521. /// 委外副产品入库
  1522. /// </summary>
  1523. /// <param name="TransCode"></param>
  1524. /// <param name="TransSequence"></param>
  1525. /// <param name="Quantity"></param>
  1526. /// <param name="WorkPoint"></param>
  1527. /// <param name="cmd"></param>
  1528. public static void OOStockINByProductDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1529. {
  1530. try
  1531. {
  1532. string sql = @"DECLARE @Status VARCHAR(10)
  1533. SELECT @Status=c.Status FROM ICSInventoryLot a
  1534. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1535. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.WorkPoint=c.WorkPoint
  1536. INNER JOIN ICSOOPick d ON c.OODetailID=d.OODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  1537. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1538. IF (@Status IS NULL)
  1539. BEGIN
  1540. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1541. RETURN
  1542. END
  1543. ELSE IF (@Status='3')
  1544. BEGIN
  1545. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1546. RETURN
  1547. END
  1548. UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  1549. FROM ICSInventoryLot a
  1550. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1551. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.WorkPoint=c.WorkPoint
  1552. INNER JOIN ICSOOPick d ON c.OODetailID=d.OODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  1553. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1554. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1555. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1556. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.WorkPoint=c.WorkPoint
  1557. INNER JOIN ICSOOPick d ON c.OODetailID=d.OODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  1558. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1559. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn001', '{0}')<c.InQuantity)
  1560. BEGIN
  1561. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1562. END";
  1563. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1564. log.Debug("委外副产品入库:" + sql);
  1565. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1566. {
  1567. throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
  1568. }
  1569. }
  1570. catch (Exception)
  1571. {
  1572. throw;
  1573. }
  1574. }
  1575. /// <summary>
  1576. /// 联副产品入库(奥美专用)
  1577. /// </summary>
  1578. /// <param name="LotNo"></param>
  1579. /// <param name="Quantity"></param>
  1580. /// <param name="WorkPoint"></param>
  1581. /// <param name="cmd"></param>
  1582. /// <param name="language"></param>
  1583. public static void MOStockINByProductAMDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1584. {
  1585. try
  1586. {
  1587. //条码表类型为19(无源头副产品条码),则不作数量卡控
  1588. string checkSql = @"SELECT Type FROM ICSInventoryLot WHERE LotNo='{0}'";
  1589. checkSql = string.Format(checkSql, LotNo);
  1590. string type = DBHelper.ExecuteScalar(checkSql, cmd).ToString();
  1591. if ("19".Equals(type))
  1592. {
  1593. return;
  1594. }
  1595. string sql = @"DECLARE @Status VARCHAR(10)
  1596. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  1597. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1598. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1599. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  1600. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1601. IF (@Status IS NULL)
  1602. BEGIN
  1603. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1604. RETURN
  1605. END
  1606. ELSE IF (@Status='3')
  1607. BEGIN
  1608. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1609. RETURN
  1610. END
  1611. UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  1612. FROM ICSInventoryLot a
  1613. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1614. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1615. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  1616. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1617. DECLARE @MoTypeValue VARCHAR(50)
  1618. DECLARE @QtyBeyond DECIMAL(18,4)=9999
  1619. SELECT @MoTypeValue=c.EATTRIBUTE1 FROM ICSInventoryLot a
  1620. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1621. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1622. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  1623. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1624. IF(@MoTypeValue='0')--
  1625. BEGIN
  1626. select
  1627. -- @QtyBeyond = cast( isnull(h.BL,0)*d.Quantity AS DECIMAL(18,4))
  1628. @QtyBeyond = 9999
  1629. from ICSInventoryLot a
  1630. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1631. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint AND c.MOStatus<>'3'
  1632. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  1633. left join
  1634. (
  1635. select MinBL as BL ,MODetailID from (
  1636. select a.MODetailID,
  1637. min(ALLBL)*max(isnull(F_Define1,0)/100.0) as MinBL
  1638. from (
  1639. select a.MODetailID ,
  1640. case when a.Quantity =0 then 0 when a.IssueQuantity=0 then 0 else a.IssueQuantity/a.Quantity end as ALLBL
  1641. from dbo.ICSMOPick a
  1642. inner join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1643. where a.EATTRIBUTE1<>'1' and a.IssueQuantity>0 )a
  1644. left join Sys_SRM_ItemsDetail flag on flag.F_ItemCode='GDCS0001'
  1645. group by MODetailID )a
  1646. ) h on d.MODetailID=h.MODetailID
  1647. left join ICSExtension e on d.ExtensionID=e.ID and a.WorkPoint=e.WorkPoint
  1648. WHERE 1=1 AND a.LotNo='{0}' AND a.WorkPoint='{1}'
  1649. END
  1650. ELSE IF(@MoTypeValue='1')--
  1651. BEGIN
  1652. select
  1653. -- @QtyBeyond = cast( isnull(h.BL,0)*d.Quantity AS DECIMAL(18,4))
  1654. @QtyBeyond = 9999
  1655. from ICSInventoryLot a
  1656. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1657. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint AND c.MOStatus<>'3'
  1658. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  1659. left join
  1660. (
  1661. select case when Flag>0 then ( case when PSLNUM>MLNUM then MLNUM else PSLNUM end) else PSLNUM end as BL ,MODetailID from (
  1662. select a.MODetailID,
  1663. case when isnull(sum(a.PSLYL),0)=0 then 0 else sum(a.PSLLSS)/sum(a.PSLYL)* max(isnull(F_Define1,0)/100.0) end as PSLNUM,
  1664. case when isnull(sum(a.MLYL),0)=0 then 0 else sum(a.MLLSS)/sum(a.MLYL)*max(isnull(F_Define1,0)/100.0) end as MLNUM,
  1665. sum(Flag) as Flag
  1666. from (
  1667. select a.MODetailID ,
  1668. case when SUBSTRING(b.ClassCode, 1, 2) IN ('01','04','05') then a.Quantity else 0 end PSLYL,
  1669. case when SUBSTRING(b.ClassCode, 1, 2) IN ('01','04','05') then a.IssueQuantity else 0 end PSLLSS,
  1670. case when SUBSTRING(b.ClassCode, 1, 2) IN ('03') then a.Quantity else 0 end MLYL,
  1671. case when SUBSTRING(b.ClassCode, 1, 2) IN ('03') then a.IssueQuantity else 0 end MLLSS,
  1672. case when SUBSTRING(b.ClassCode, 1, 2) IN ('03') then 1 else 0 end Flag
  1673. from dbo.ICSMOPick a
  1674. inner join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1675. where a.EATTRIBUTE1 <> '1')a
  1676. left join Sys_SRM_ItemsDetail flag on flag.F_ItemCode='GDCS0001'
  1677. group by MODetailID )a
  1678. ) h on d.MODetailID=h.MODetailID
  1679. left join ICSExtension e on d.ExtensionID=e.ID and a.WorkPoint=e.WorkPoint
  1680. WHERE 1=1 AND a.LotNo='{0}' AND a.WorkPoint='{1}'
  1681. END
  1682. ELSE
  1683. BEGIN
  1684. RAISERROR(' {0} ',16,1);
  1685. END
  1686. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1687. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1688. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1689. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  1690. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1691. AND @QtyBeyond<d.IssueQuantity)
  1692. BEGIN
  1693. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1694. END
  1695. ";
  1696. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1697. log.Debug("联副产品入库:" + sql);
  1698. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1699. {
  1700. throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
  1701. }
  1702. }
  1703. catch (Exception)
  1704. {
  1705. throw;
  1706. }
  1707. }
  1708. /// <summary>
  1709. /// 副产品入库接口
  1710. /// </summary>
  1711. /// <param name="TransType"></param>
  1712. /// <param name="Identification"></param>
  1713. /// <param name="cmd"></param>
  1714. public static void MOStockINByProductDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1715. {
  1716. try
  1717. {
  1718. #region ERP
  1719. string sql = @"SELECT ISNULL(c.DepCode,'')+a.ToWarehouseCode+c.MOCode+a.MUSER AS Costre,
  1720. c.DepCode,a.ToWarehouseCode AS WarehouseCode,c.MOCode,a.MUSER,mopick.Sequence,lot.EATTRIBUTE2,
  1721. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,mopick.PickID AS MODetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose
  1722. ,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END AS ProjectCode,
  1723. 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,
  1724. CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END AS Version,
  1725. CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END AS Brand,
  1726. CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END AS cFree1,
  1727. CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END AS cFree2,
  1728. CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END AS cFree3,
  1729. CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END AS cFree4,
  1730. CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END AS cFree5,
  1731. CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END AS cFree6,
  1732. CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END AS cFree7,
  1733. CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END AS cFree8,
  1734. CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END AS cFree9,
  1735. CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS cFree10,
  1736. conv.Enable AS CompleteVerification,a.TransSequence
  1737. INTO #TempERP
  1738. FROM ICSWareHouseLotInfoLog a
  1739. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1740. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1741. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1742. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1743. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1744. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1745. INNER JOIN ICSMOPick mopick ON mopick.MODetailID=c.MODetailID AND b.TransSequence=c.Sequence+'~'+mopick.Sequence AND mopick.WorkPoint=c.WorkPoint
  1746. INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
  1747. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1748. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  1749. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  1750. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose001'
  1751. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1752. GROUP BY inv.AmountEnable,c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,mopick.PickID,con.Enable,conv.Enable,conStock.Enable,conStocknew.Enable
  1753. ,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END,c.MODetailID,mopick.Sequence,lot.EATTRIBUTE2,
  1754. CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,
  1755. CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END,
  1756. CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END,
  1757. CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END,
  1758. CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END,
  1759. CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END,
  1760. CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END,
  1761. CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END,
  1762. CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END,
  1763. CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END,
  1764. CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END,
  1765. CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END,
  1766. CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END,a.TransSequence
  1767. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,'false' AS CompleteVerification,UpdateStock,IsFillClose FROM #TempERP
  1768. SELECT Costre,TransSequence,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,EATTRIBUTE2 as OutType
  1769. FROM #TempERP
  1770. DROP TABLE #TempERP";
  1771. sql = string.Format(sql, Identification, BusinessCode);
  1772. log.Debug("副产品入库ERP:" + sql);
  1773. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1774. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1775. string resultStr = "";
  1776. if (DBHelper.IsU9())
  1777. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOStockINByProductDocURL, Inputstr); }
  1778. else { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOStockINByProductDocURL, Inputstr); }
  1779. Result result = new Result();
  1780. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1781. log.Debug("副产品入库ERP返回值:" + result);
  1782. if (result.Success)
  1783. {
  1784. //try
  1785. //{
  1786. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1787. // foreach (var item in res)
  1788. // {
  1789. // JObject jo = (JObject)item;
  1790. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1791. // foreach (var detail in resdetail)
  1792. // {
  1793. // JObject det = (JObject)detail;
  1794. // 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()
  1795. // + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1796. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1797. // det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1798. // if (det["detailss"] != null)
  1799. // {
  1800. // JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  1801. // foreach (var details in resdetails)
  1802. // {
  1803. // JObject dets = (JObject)details;
  1804. // if (dets != null)
  1805. // {
  1806. // //直接回写
  1807. // string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1808. // FROM ICSWareHouseLotInfoLog a
  1809. // LEFT JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  1810. // LEFT JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'-'+c.Sequence
  1811. // WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{6}'";
  1812. // ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString()
  1813. // , dets["Sequence"].ToString(), BusinessCode);
  1814. // if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1815. // {
  1816. // throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"成品倒冲回写失败!";
  1817. // }
  1818. // }
  1819. // }
  1820. // }
  1821. // }
  1822. // }
  1823. //}
  1824. //catch (Exception ex)
  1825. //{
  1826. // log.Debug(ex.ToString());
  1827. // log.Debug(resultStr);
  1828. // throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  1829. //}
  1830. }
  1831. else
  1832. {
  1833. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1834. }
  1835. #endregion
  1836. }
  1837. catch (Exception)
  1838. {
  1839. throw;
  1840. }
  1841. }
  1842. /// <summary>
  1843. /// 委外副产品入库接口
  1844. /// </summary>
  1845. /// <param name="TransType"></param>
  1846. /// <param name="Identification"></param>
  1847. /// <param name="cmd"></param>
  1848. public static void OOStockINByProductDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1849. {
  1850. try
  1851. {
  1852. #region ERP
  1853. string sql = @"SELECT ISNULL(c.DepCode,'')+a.ToWarehouseCode+c.OOCode+a.MUSER AS Costre,c.VenCode,
  1854. c.DepCode,a.ToWarehouseCode AS WarehouseCode,c.OOCode,a.MUSER,mopick.Sequence,lot.EATTRIBUTE2,
  1855. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,mopick.PickID AS OODetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose
  1856. ,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END AS ProjectCode,
  1857. 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,
  1858. CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END AS Version,
  1859. CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END AS Brand,
  1860. CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END AS cFree1,
  1861. CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END AS cFree2,
  1862. CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END AS cFree3,
  1863. CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END AS cFree4,
  1864. CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END AS cFree5,
  1865. CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END AS cFree6,
  1866. CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END AS cFree7,
  1867. CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END AS cFree8,
  1868. CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END AS cFree9,
  1869. CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS cFree10,
  1870. conv.Enable AS CompleteVerification,a.TransSequence
  1871. INTO #TempERP
  1872. FROM ICSWareHouseLotInfoLog a
  1873. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1874. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1875. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1876. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1877. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1878. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.WorkPoint=c.WorkPoint
  1879. INNER JOIN ICSOOPick mopick ON mopick.OODetailID=c.OODetailID AND b.TransSequence=c.Sequence+'~'+mopick.Sequence AND mopick.WorkPoint=c.WorkPoint
  1880. INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
  1881. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1882. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  1883. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  1884. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose001'
  1885. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1886. GROUP BY inv.AmountEnable,c.DepCode,c.VenCode,a.ToWarehouseCode,c.OOCode,a.MUSER,a.InvCode,mopick.PickID,con.Enable,conv.Enable,conStock.Enable,conStocknew.Enable
  1887. ,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END,c.OODetailID,mopick.Sequence,lot.EATTRIBUTE2,
  1888. CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,
  1889. CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END,
  1890. CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END,
  1891. CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END,
  1892. CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END,
  1893. CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END,
  1894. CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END,
  1895. CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END,
  1896. CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END,
  1897. CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END,
  1898. CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END,
  1899. CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END,
  1900. CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END,a.TransSequence
  1901. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,VenCode,OOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,'false' AS CompleteVerification,UpdateStock,IsFillClose FROM #TempERP
  1902. SELECT Costre,TransSequence AS ODNSequence,Sequence,InvCode,Quantity,Amount,OODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,EATTRIBUTE2 as OutType
  1903. FROM #TempERP
  1904. DROP TABLE #TempERP";
  1905. sql = string.Format(sql, Identification, BusinessCode);
  1906. log.Debug("委外副产品入库ERP:" + sql);
  1907. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1908. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1909. string resultStr = "";
  1910. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOStockINByProductDocURL, Inputstr);
  1911. Result result = new Result();
  1912. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1913. log.Debug("委外副产品入库ERP返回值:" + result);
  1914. if (result.Success)
  1915. {
  1916. //try
  1917. //{
  1918. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1919. // foreach (var item in res)
  1920. // {
  1921. // JObject jo = (JObject)item;
  1922. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1923. // foreach (var detail in resdetail)
  1924. // {
  1925. // JObject det = (JObject)detail;
  1926. // 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()
  1927. // + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1928. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1929. // det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1930. // if (det["detailss"] != null)
  1931. // {
  1932. // JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  1933. // foreach (var details in resdetails)
  1934. // {
  1935. // JObject dets = (JObject)details;
  1936. // if (dets != null)
  1937. // {
  1938. // //直接回写
  1939. // string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1940. // FROM ICSWareHouseLotInfoLog a
  1941. // LEFT JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  1942. // LEFT JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'-'+c.Sequence
  1943. // WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{6}'";
  1944. // ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString()
  1945. // , dets["Sequence"].ToString(), BusinessCode);
  1946. // if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1947. // {
  1948. // throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"成品倒冲回写失败!";
  1949. // }
  1950. // }
  1951. // }
  1952. // }
  1953. // }
  1954. // }
  1955. //}
  1956. //catch (Exception ex)
  1957. //{
  1958. // log.Debug(ex.ToString());
  1959. // log.Debug(resultStr);
  1960. // throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  1961. //}
  1962. }
  1963. else
  1964. {
  1965. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1966. }
  1967. #endregion
  1968. }
  1969. catch (Exception)
  1970. {
  1971. throw;
  1972. }
  1973. }
  1974. /// <summary>
  1975. /// 副产品入库接口
  1976. /// </summary>
  1977. /// <param name="TransType"></param>
  1978. /// <param name="Identification"></param>
  1979. /// <param name="cmd"></param>
  1980. public static void MOStockINByProductNoTransDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1981. {
  1982. try
  1983. {
  1984. #region ERP
  1985. string sql = @"SELECT a.ToWarehouseCode+a.MUSER+a.LotNo AS Costre,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,a.MUSER,a.LotNo) AS Sequence,
  1986. a.ToWarehouseCode AS WarehouseCode,lot.MUSER AS LotMUSER,(select F_RealName from Sys_SRM_User s where s.F_Account=a.MUSER) AS MUSER,
  1987. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose
  1988. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,
  1989. 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,
  1990. ISNULL(ext.Version, '') AS Version,
  1991. ISNULL(ext.Brand, '') AS Brand,
  1992. ISNULL(ext.cFree1, '') AS cFree1,
  1993. ISNULL(ext.cFree2, '') AS cFree2,
  1994. ISNULL(ext.cFree3, '') AS cFree3,
  1995. ISNULL(ext.cFree4, '') AS cFree4,
  1996. ISNULL(ext.cFree5, '') AS cFree5,
  1997. ISNULL(ext.cFree6, '') AS cFree6,
  1998. ISNULL(ext.cFree7, '') AS cFree7,
  1999. ISNULL(ext.cFree8, '') AS cFree8,
  2000. ISNULL(ext.cFree9, '') AS cFree9,
  2001. ISNULL(ext.cFree10, '') AS cFree10,
  2002. conv.Enable AS CompleteVerification
  2003. INTO #TempERP
  2004. FROM ICSWareHouseLotInfoLog a
  2005. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2006. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2007. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2008. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2009. LEFT JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2010. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2011. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  2012. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  2013. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose001'
  2014. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  2015. GROUP BY a.LotNo,inv.AmountEnable,a.ToWarehouseCode,a.MUSER,lot.MUSER,a.InvCode,con.Enable,conv.Enable,conStock.Enable,conStocknew.Enable
  2016. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') ,
  2017. CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,
  2018. ISNULL(ext.Version, '') ,
  2019. ISNULL(ext.Brand, '') ,
  2020. ISNULL(ext.cFree1, '') ,
  2021. ISNULL(ext.cFree2, '') ,
  2022. ISNULL(ext.cFree3, ''),
  2023. ISNULL(ext.cFree4, ''),
  2024. ISNULL(ext.cFree5, ''),
  2025. ISNULL(ext.cFree6, ''),
  2026. ISNULL(ext.cFree7, ''),
  2027. ISNULL(ext.cFree8, ''),
  2028. ISNULL(ext.cFree9, ''),
  2029. ISNULL(ext.cFree10, '')
  2030. SELECT DISTINCT Costre,Sequence,WorkPoint,WarehouseCode AS WHCode,MUSER AS [UserName],LotMUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,'false' AS CompleteVerification,UpdateStock,IsFillClose
  2031. ,InvCode,Quantity,Amount,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  2032. --SELECT Costre,TransSequence,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  2033. --FROM #TempERP
  2034. DROP TABLE #TempERP";
  2035. sql = string.Format(sql, Identification, BusinessCode);
  2036. log.Debug("副产品入库ERP:" + sql);
  2037. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2038. string Inputstr = JsonConvert.SerializeObject(dt);
  2039. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOStockINByProductNoTransDocURL, Inputstr);
  2040. Result result = new Result();
  2041. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2042. log.Debug("副产品入库ERP返回值:" + result);
  2043. if (result.Success)
  2044. {
  2045. //try
  2046. //{
  2047. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2048. // foreach (var item in res)
  2049. // {
  2050. // JObject jo = (JObject)item;
  2051. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2052. // foreach (var detail in resdetail)
  2053. // {
  2054. // JObject det = (JObject)detail;
  2055. // 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()
  2056. // + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2057. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  2058. // det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2059. // if (det["detailss"] != null)
  2060. // {
  2061. // JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  2062. // foreach (var details in resdetails)
  2063. // {
  2064. // JObject dets = (JObject)details;
  2065. // if (dets != null)
  2066. // {
  2067. // //直接回写
  2068. // string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2069. // FROM ICSWareHouseLotInfoLog a
  2070. // LEFT JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  2071. // LEFT JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'-'+c.Sequence
  2072. // WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{6}'";
  2073. // ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString()
  2074. // , dets["Sequence"].ToString(), BusinessCode);
  2075. // if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  2076. // {
  2077. // throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"成品倒冲回写失败!";
  2078. // }
  2079. // }
  2080. // }
  2081. // }
  2082. // }
  2083. // }
  2084. //}
  2085. //catch (Exception ex)
  2086. //{
  2087. // log.Debug(ex.ToString());
  2088. // log.Debug(resultStr);
  2089. // throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  2090. //}
  2091. }
  2092. else
  2093. {
  2094. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2095. }
  2096. #endregion
  2097. }
  2098. catch (Exception)
  2099. {
  2100. throw;
  2101. }
  2102. }
  2103. #endregion
  2104. #region 开立的生产入库单
  2105. /// <summary>
  2106. /// 开立的生产入库单
  2107. /// </summary>
  2108. /// <param name="TransCode"></param>
  2109. /// <param name="TransSequence"></param>
  2110. /// <param name="Quantity"></param>
  2111. /// <param name="WorkPoint"></param>
  2112. /// <param name="cmd"></param>
  2113. public static void ManufactureReceive(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2114. {
  2115. try
  2116. {
  2117. string sql = @"DECLARE @Status VARCHAR(10)
  2118. SELECT @Status=c.Status FROM ICSInventoryLot a
  2119. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2120. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2121. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  2122. IF (@Status IS NULL)
  2123. BEGIN
  2124. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2125. RETURN
  2126. END
  2127. ELSE IF (@Status!='1')
  2128. BEGIN
  2129. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  2130. RETURN
  2131. END
  2132. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  2133. FROM ICSInventoryLot a
  2134. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2135. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2136. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  2137. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2138. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2139. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2140. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1' AND c.Quantity<c.RCVQuantity)
  2141. BEGIN
  2142. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  2143. END";
  2144. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2145. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2146. {
  2147. throw new Exception(language.GetNameByCode("WMSAPIInfo138"));//"生产入库单更新失败!");
  2148. }
  2149. }
  2150. catch (Exception)
  2151. {
  2152. throw;
  2153. }
  2154. }
  2155. /// <summary>
  2156. /// 开立的生产入库单
  2157. /// </summary>
  2158. /// <param name="TransType"></param>
  2159. /// <param name="Identification"></param>
  2160. /// <param name="cmd"></param>
  2161. public static void ManufactureReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2162. {
  2163. try
  2164. {
  2165. string checklotno = "";
  2166. string checksql = @"SELECT c.rcvcode,a.lotno FROM ICSInventoryLot a
  2167. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2168. INNER JOIN (select RCVCode,Sequence,WorkPoint FROM ICSManufactureReceive) c ON b.TransCode=c.RCVCode
  2169. AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2170. WHERE c.rcvcode in (select TransCode from ICSWareHouseLotInfoLog
  2171. where Identification='{0}' )
  2172. and a.lotno NOT IN (select LotNo from ICSWareHouseLotInfoLog where Identification='{0}' )";
  2173. checksql = string.Format(checksql, Identification);
  2174. DataTable dtt = DBHelper.SQlReturnData(checksql, cmd);
  2175. if (dtt.Rows.Count > 1)
  2176. {
  2177. // 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
  2178. foreach (DataRow row in dtt.Rows)
  2179. {
  2180. checklotno += row["lotno"].ToString() + ",";
  2181. }
  2182. checklotno = checklotno.TrimEnd(','); // 去除最后一个逗号
  2183. }
  2184. else if (dtt.Rows.Count == 1)
  2185. {
  2186. // 如果dtt的行数等于1,直接将lotno赋值给checklotno
  2187. checklotno = dtt.Rows[0]["lotno"].ToString();
  2188. }
  2189. string checkrcvcode = "";
  2190. string checknewsql = @"SELECT distinct c.rcvcode FROM ICSInventoryLot a
  2191. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2192. INNER JOIN (select RCVCode,Sequence,WorkPoint FROM ICSManufactureReceive) c ON b.TransCode=c.RCVCode
  2193. AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2194. WHERE c.rcvcode in (select TransCode from ICSWareHouseLotInfoLog
  2195. where Identification='{0}' )
  2196. and a.lotno NOT IN (select LotNo from ICSWareHouseLotInfoLog where Identification='{0}' )";
  2197. checknewsql = string.Format(checknewsql, Identification);
  2198. DataTable dttnew = DBHelper.SQlReturnData(checknewsql, cmd);
  2199. if (dttnew.Rows.Count > 1)
  2200. {
  2201. // 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
  2202. foreach (DataRow row in dttnew.Rows)
  2203. {
  2204. checkrcvcode += row["rcvcode"].ToString() + ",";
  2205. }
  2206. checkrcvcode = checkrcvcode.TrimEnd(','); // 去除最后一个逗号
  2207. }
  2208. else if (dttnew.Rows.Count == 1)
  2209. {
  2210. // 如果dtt的行数等于1,直接将lotno赋值给checklotno
  2211. checkrcvcode = dttnew.Rows[0]["rcvcode"].ToString();
  2212. }
  2213. #region ERP开立状态单据审核
  2214. string sql = @"DECLARE @quantity DECIMAL(38,4);
  2215. DECLARE @rcvquantity DECIMAL(38,4);
  2216. SELECT @quantity=SUM(Quantity),@rcvquantity=SUM(RCVQuantity) FROM ICSManufactureReceive b
  2217. WHERE b.RCVCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  2218. IF (@quantity<>@rcvquantity)
  2219. BEGIN
  2220. RAISERROR('" + language.GetNameByCode("WMSAPIInfo096") + @"',16,1);
  2221. RETURN
  2222. END
  2223. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  2224. INTO #NewTempERP
  2225. from ICSWareHouseLotInfoLog
  2226. WHERE Identification='{0}' AND ERPUpload='0'
  2227. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2228. FROM #NewTempERP a
  2229. INNER JOIN ICSManufactureReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2230. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2231. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  2232. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2233. DROP TABLE #NewTempERP";
  2234. sql = string.Format(sql, Identification, checklotno, checkrcvcode);
  2235. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2236. string Inputstr = JsonConvert.SerializeObject(dt);
  2237. //U9ICSManufactureReceiveURL
  2238. string resultStr = "";
  2239. if (DBHelper.IsU9())
  2240. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9ICSManufactureReceiveURL, Inputstr); }
  2241. else
  2242. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSManufactureReceiveURL, Inputstr);
  2243. Result result = new Result();
  2244. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2245. if (result.Success)
  2246. {
  2247. try
  2248. {
  2249. foreach (DataRow dr in dt.Rows)
  2250. {
  2251. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "",cmd, language, BusinessCode);
  2252. }
  2253. }
  2254. catch (Exception ex)
  2255. {
  2256. log.Debug(ex.ToString());
  2257. log.Debug(resultStr);
  2258. }
  2259. }
  2260. else
  2261. {
  2262. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2263. }
  2264. #endregion
  2265. }
  2266. catch (Exception)
  2267. {
  2268. throw;
  2269. }
  2270. }
  2271. #endregion
  2272. #region 返工工单
  2273. /// <summary>
  2274. /// 返工工单
  2275. /// </summary>
  2276. /// <param name="TransCode"></param>
  2277. /// <param name="TransSequence"></param>
  2278. /// <param name="Quantity"></param>
  2279. /// <param name="WorkPoint"></param>
  2280. /// <param name="cmd"></param>
  2281. public static void ReWorkReceiveMo(string LotNo, string Quantity, string WarehouseCode,
  2282. string LocationCode, string WorkPoint, String User, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  2283. {
  2284. try
  2285. {
  2286. string sql = @"DECLARE @Status VARCHAR(10)
  2287. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  2288. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2289. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  2290. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  2291. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2292. IF (@Status IS NULL)
  2293. BEGIN
  2294. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2295. RETURN
  2296. END
  2297. ELSE IF (@Status='3')
  2298. BEGIN
  2299. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  2300. RETURN
  2301. END
  2302. UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  2303. FROM ICSInventoryLot a
  2304. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2305. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  2306. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  2307. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2308. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2309. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2310. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  2311. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  2312. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.IssueQuantity>d.Quantity)
  2313. BEGIN
  2314. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  2315. END";
  2316. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2317. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2318. {
  2319. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));//"生产工单更新失败!");
  2320. }
  2321. }
  2322. catch (Exception)
  2323. {
  2324. throw;
  2325. }
  2326. }
  2327. /// <summary>
  2328. /// 返工工单
  2329. /// </summary>
  2330. /// <param name="TransType"></param>
  2331. /// <param name="Identification"></param>
  2332. /// <param name="cmd"></param>
  2333. public static void ReWorkReceiveMoERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  2334. {
  2335. try
  2336. {
  2337. #region ERP开立状态单据审核
  2338. String sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  2339. INTO #NewTempERP
  2340. from ICSWareHouseLotInfoLog
  2341. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  2342. 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,
  2343. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,d.PickID AS MODetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  2344. ,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,
  2345. 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
  2346. INTO #TempERP
  2347. FROM #NewTempERP a
  2348. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2349. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2350. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2351. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2352. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2353. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  2354. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  2355. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2356. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock007' AND a.WorkPoint=conStock.WorkPoint
  2357. GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,d.PickID,con.Enable,d.Sequence,conStock.Enable
  2358. ,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, ''),
  2359. 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, '')
  2360. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  2361. SELECT Costre,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  2362. FROM #TempERP
  2363. DROP TABLE #TempERP
  2364. DROP TABLE #NewTempERP";
  2365. sql = string.Format(sql, Identification,BusinessCode);
  2366. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2367. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2368. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSReWorkReceiveMoURL, Inputstr);
  2369. Result result = new Result();
  2370. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2371. if (result.Success)
  2372. {
  2373. try
  2374. {
  2375. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2376. foreach (var item in res)
  2377. {
  2378. JObject jo = (JObject)item;
  2379. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2380. foreach (var detail in resdetail)
  2381. {
  2382. JObject det = (JObject)detail;
  2383. string col = jo["WHCode"].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()
  2384. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2385. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  2386. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), col, cmd, language, BusinessCode);
  2387. }
  2388. }
  2389. }
  2390. catch (Exception ex)
  2391. {
  2392. log.Debug(ex.ToString());
  2393. log.Debug(resultStr);
  2394. }
  2395. }
  2396. else
  2397. {
  2398. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2399. }
  2400. #endregion
  2401. }
  2402. catch (Exception)
  2403. {
  2404. throw;
  2405. }
  2406. }
  2407. #endregion
  2408. }
  2409. }