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.

3675 lines
273 KiB

4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
6 days ago
6 days ago
6 days 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,string TransID)
  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.id='{5}' 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.id='{5}' 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. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, enableCode, TransID);
  63. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  64. {
  65. throw new Exception(language.GetNameByCode("WMSAPIInfo127"));//"生产领料单更新失败!");
  66. }
  67. }
  68. catch (Exception)
  69. {
  70. throw;
  71. }
  72. }
  73. /// <summary>
  74. /// 生产发料
  75. /// </summary>
  76. /// <param name="TransCode"></param>
  77. /// <param name="TransSequence"></param>
  78. /// <param name="Quantity"></param>
  79. /// <param name="WorkPoint"></param>
  80. /// <param name="cmd"></param>
  81. public static void AMMOIssueDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string enableCode)
  82. {
  83. try
  84. {
  85. string cheksql = @"select c.EATTRIBUTE1 FROM ICSMOPick a
  86. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  87. INNER JOIN ICSInventory c on a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  88. WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}' and c.AmountEnable='1'";
  89. cheksql = string.Format(cheksql, TransCode, WorkPoint, Quantity, TransSequence, enableCode);
  90. DataTable dt = DBHelper.SQlReturnData(cheksql, cmd);
  91. if (dt.Rows.Count > 0)
  92. {
  93. Quantity = (decimal.Parse(Quantity) * decimal.Parse(dt.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  94. }
  95. string sql = @"DECLARE @Status VARCHAR(10)
  96. SELECT @Status=b.ERPStatus FROM ICSMOPick a
  97. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  98. WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}'
  99. IF (@Status IS NULL)
  100. BEGIN
  101. RAISERROR('" + language.GetNameByCode("WMSAPIInfo125") + @"',16,1);
  102. RETURN
  103. END
  104. ELSE IF (@Status!='2')
  105. BEGIN
  106. RAISERROR('" + language.GetNameByCode("WMSAPIInfo126") + @"',16,1);
  107. RETURN
  108. END
  109. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  110. FROM ICSMOPick a
  111. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  112. WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}'
  113. --IF EXISTS(SELECT a.ID FROM ICSMOPick a
  114. --INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  115. --WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' and a.WorkPoint='{1}'
  116. -- AND (dbo.GetExcessQty(a.InvCode, b.Sequence+'~'+a.Sequence, b.MOCode, a.WorkPoint,'{4}'))<a.IssueQuantity)
  117. --BEGIN
  118. --RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  119. --RETURN
  120. --END
  121. ";
  122. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, enableCode);
  123. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  124. {
  125. throw new Exception(language.GetNameByCode("WMSAPIInfo127"));//"生产领料单更新失败!");
  126. }
  127. }
  128. catch (Exception)
  129. {
  130. throw;
  131. }
  132. }
  133. /// <summary>
  134. /// 生产发料接口
  135. /// </summary>
  136. /// <param name="TransType"></param>
  137. /// <param name="Identification"></param>
  138. /// <param name="cmd"></param>
  139. public static void MOIssueDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode,string VenCode)
  140. {
  141. try
  142. {
  143. #region ERP
  144. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
  145. INTO #NewTempERP
  146. from ICSWareHouseLotInfoLog
  147. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '{1}'
  148. SELECT isnull(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,CAST(SUBSTRING(a.TransSequence, CHARINDEX('~', a.TransSequence) + 1, LEN(a.TransSequence)) AS INT) AS TransSequence,
  149. 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,conWhCode.Enable AS ErpWhCode
  150. ,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,
  151. 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
  152. ,'1'as DocTypeCode,inv.InvRate
  153. INTO #TempERP
  154. FROM #NewTempERP a
  155. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  156. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  157. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  158. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  159. INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
  160. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence and a.transid=x.id AND x.WorkPoint=y.WorkPoint
  161. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  162. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  163. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  164. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  165. GROUP BY conWhCode.Enable,a.TransSequence,inv.AmountEnable,y.DepCode,a.FromWarehouseCode,y.MOCode,a.MUSER,a.InvCode,x.PickID,x.MODetailID,con.Enable,conv.Enable,conStock.Enable,inv.InvRate
  166. ,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, ''),
  167. 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, '')
  168. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock FROM #TempERP
  169. SELECT TransSequence AS SubLineNO,WarehouseCode AS WHCode,Costre,'{2}' AS Vender,Sequence,InvCode,InvRate,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,PickID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  170. DROP TABLE #TempERP
  171. DROP TABLE #NewTempERP";
  172. sql = string.Format(sql, Identification, BusinessCode, VenCode);
  173. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  174. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  175. string resultStr = "";
  176. //if (DBHelper.IsU9())
  177. //{
  178. // resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOIssueDocURL, Inputstr);
  179. //}
  180. //else
  181. //{
  182. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueDocURL, Inputstr);
  183. //}
  184. Result result = new Result();
  185. result = JsonConvert.DeserializeObject<Result>(resultStr);
  186. if (result.Success)
  187. {
  188. try
  189. {
  190. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  191. foreach (var item in res)
  192. {
  193. JObject jo = (JObject)item;
  194. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  195. foreach (var detail in resdetail)
  196. {
  197. JObject det = (JObject)detail;
  198. 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()
  199. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  200. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  201. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol,cmd, language, BusinessCode);
  202. }
  203. }
  204. }
  205. catch (Exception ex)
  206. {
  207. log.Debug(ex.ToString());
  208. log.Debug(resultStr);
  209. }
  210. }
  211. else
  212. {
  213. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  214. }
  215. #endregion
  216. }
  217. catch (Exception)
  218. {
  219. throw;
  220. }
  221. }
  222. /// <summary>
  223. /// 达翔生产发料接口
  224. /// </summary>
  225. /// <param name="TransType"></param>
  226. /// <param name="Identification"></param>
  227. /// <param name="cmd"></param>
  228. public static void DXMOIssueDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  229. {
  230. try
  231. {
  232. #region ERP
  233. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
  234. INTO #NewTempERP
  235. from ICSWareHouseLotInfoLog
  236. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '13'
  237. SELECT isnull(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,
  238. 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
  239. ,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,
  240. 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
  241. ,'1'as DocTypeCode
  242. INTO #TempERP
  243. FROM #NewTempERP a
  244. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  245. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  246. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  247. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  248. INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
  249. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence and a.transid=x.id AND x.WorkPoint=y.WorkPoint
  250. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  251. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  252. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  253. GROUP BY inv.AmountEnable,y.DepCode,a.FromWarehouseCode,y.MOCode,a.MUSER,a.InvCode,x.PickID,x.MODetailID,con.Enable,conv.Enable,conStock.Enable
  254. ,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, ''),
  255. 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, '')
  256. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock FROM #TempERP
  257. 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
  258. DROP TABLE #TempERP
  259. DROP TABLE #NewTempERP";
  260. sql = string.Format(sql, Identification);
  261. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  262. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  263. string resultStr = "";
  264. //if (DBHelper.IsU9())
  265. //{
  266. // resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOIssueDocURL, Inputstr);
  267. //}
  268. //else
  269. //{
  270. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DXMOIssueDocURL, Inputstr);
  271. //}
  272. Result result = new Result();
  273. result = JsonConvert.DeserializeObject<Result>(resultStr);
  274. if (result.Success)
  275. {
  276. try
  277. {
  278. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  279. foreach (var item in res)
  280. {
  281. JObject jo = (JObject)item;
  282. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  283. foreach (var detail in resdetail)
  284. {
  285. JObject det = (JObject)detail;
  286. 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()
  287. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  288. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  289. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  290. }
  291. }
  292. }
  293. catch (Exception ex)
  294. {
  295. log.Debug(ex.ToString());
  296. log.Debug(resultStr);
  297. }
  298. }
  299. else
  300. {
  301. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  302. }
  303. #endregion
  304. }
  305. catch (Exception)
  306. {
  307. throw;
  308. }
  309. }
  310. #endregion
  311. #region 补料申请单生产发料
  312. /// <summary>
  313. /// 补料申请单生产发料
  314. /// </summary>
  315. /// <param name="TransCode"></param>
  316. /// <param name="TransSequence"></param>
  317. /// <param name="Quantity"></param>
  318. /// <param name="WorkPoint"></param>
  319. /// <param name="cmd"></param>
  320. public static void MOReplenishment(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string enableCode)
  321. {
  322. try
  323. {
  324. string sql = @"DECLARE @Status VARCHAR(10)
  325. SELECT @Status=a.Status FROM ICSMOReplenishment a
  326. WHERE a.ReplenishmentCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  327. IF (@Status IS NULL)
  328. BEGIN
  329. RAISERROR('" + language.GetNameByCode("WMSAPIInfo128") + @"',16,1);
  330. RETURN
  331. END
  332. ELSE IF (@Status!='2')
  333. BEGIN
  334. RAISERROR('" + language.GetNameByCode("WMSAPIInfo129") + @"',16,1);
  335. RETURN
  336. END
  337. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  338. FROM ICSMOReplenishment a
  339. WHERE a.ReplenishmentCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  340. IF EXISTS(SELECT a.ID FROM ICSMOReplenishment a
  341. WHERE a.ReplenishmentCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}'
  342. AND (dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{4}',2,2,''))<a.IssueQuantity)
  343. -- AND (dbo.GetExcessQty(a.InvCode, a.Sequence, a.ReplenishmentCode, a.WorkPoint,'{4}'))<a.IssueQuantity)
  344. BEGIN
  345. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  346. RETURN
  347. END";
  348. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence,enableCode);
  349. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  350. {
  351. throw new Exception(language.GetNameByCode("WMSAPIInfo130"));//"领料申请单更新失败!");
  352. }
  353. }
  354. catch (Exception)
  355. {
  356. throw;
  357. }
  358. }
  359. /// <summary>
  360. /// 补料申请单生产发料接口
  361. /// </summary>
  362. /// <param name="TransType"></param>
  363. /// <param name="Identification"></param>
  364. /// <param name="cmd"></param>
  365. public static void MOReplenishmentERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  366. {
  367. try
  368. {
  369. #region ERP
  370. string sql = @"SELECT a.FromWarehouseCode+b.ReplenishmentCode+ISNULL(c.DepCode,'')+a.MUSER AS Costre,a.FromWarehouseCode AS WarehouseCode,b.ReplenishmentCode,ISNULL(c.DepCode,'')AS DepCode,b.SourceCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.ReplenishmentCode,b.ReplenishmentDetailID,a.InvCode) AS Sequence,
  371. 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,conWhCode.Enable AS ErpWhCode
  372. ,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,
  373. 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
  374. INTO #TempERP
  375. FROM ICSWareHouseLotInfoLog a
  376. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  377. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  378. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  379. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  380. INNER JOIN ICSMOReplenishment b ON a.TransCode=b.ReplenishmentCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  381. LEFT JOIN ICSMO c ON b.SourceCode=c.MOCode AND b.SourceSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  382. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  383. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  384. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  385. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  386. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '49'
  387. GROUP BY conWhCode.Enable,c.DepCode,inv.AmountEnable,a.FromWarehouseCode,b.ReplenishmentCode,b.SourceCode,a.MUSER,a.InvCode,b.ReplenishmentDetailID,con.Enable,conv.Enable,conStock.Enable
  388. ,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, ''),
  389. 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, '')
  390. SELECT DISTINCT Costre,WorkPoint,ISNULL(DepCode,'') AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ReplenishmentCode AS SourceCode,SourceCode AS IssueCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock FROM #TempERP
  391. SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ReplenishmentDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  392. DROP TABLE #TempERP";
  393. sql = string.Format(sql, Identification);
  394. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  395. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  396. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOReplenishmentURL, Inputstr);
  397. Result result = new Result();
  398. result = JsonConvert.DeserializeObject<Result>(resultStr);
  399. if (result.Success)
  400. {
  401. try
  402. {
  403. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  404. foreach (var item in res)
  405. {
  406. JObject jo = (JObject)item;
  407. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  408. foreach (var detail in resdetail)
  409. {
  410. JObject det = (JObject)detail;
  411. 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()
  412. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  413. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  414. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  415. }
  416. }
  417. }
  418. catch (Exception ex)
  419. {
  420. log.Debug(ex.ToString());
  421. log.Debug(resultStr);
  422. }
  423. }
  424. else
  425. {
  426. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  427. }
  428. #endregion
  429. }
  430. catch (Exception)
  431. {
  432. throw;
  433. }
  434. }
  435. #endregion
  436. #region 领料申请单生产发料
  437. /// <summary>
  438. /// 领料申请单生产发料
  439. /// </summary>
  440. /// <param name="TransCode"></param>
  441. /// <param name="TransSequence"></param>
  442. /// <param name="Quantity"></param>
  443. /// <param name="WorkPoint"></param>
  444. /// <param name="cmd"></param>
  445. public static void MOApply(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string enableCode, string TransID)
  446. {
  447. try
  448. {
  449. string sql = @"DECLARE @Status VARCHAR(10)
  450. SELECT @Status=a.Status FROM ICSMOApply a
  451. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{5}'
  452. IF (@Status IS NULL)
  453. BEGIN
  454. RAISERROR('" + language.GetNameByCode("WMSAPIInfo128") + @"',16,1);
  455. RETURN
  456. END
  457. ELSE IF (@Status!='2')
  458. BEGIN
  459. RAISERROR('" + language.GetNameByCode("WMSAPIInfo129") + @"',16,1);
  460. RETURN
  461. END
  462. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  463. FROM ICSMOApply a
  464. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{5}'
  465. IF EXISTS(SELECT a.ID FROM ICSMOApply a
  466. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.id='{5}' and a.WorkPoint='{1}'
  467. AND (dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{4}',2,2,''))<a.IssueQuantity)
  468. BEGIN
  469. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  470. RETURN
  471. END";
  472. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, enableCode, TransID);
  473. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  474. {
  475. throw new Exception(language.GetNameByCode("WMSAPIInfo130"));//"领料申请单更新失败!");
  476. }
  477. }
  478. catch (Exception)
  479. {
  480. throw;
  481. }
  482. }
  483. /// <summary>
  484. /// 领料申请单生产发料接口
  485. /// </summary>
  486. /// <param name="TransType"></param>
  487. /// <param name="Identification"></param>
  488. /// <param name="cmd"></param>
  489. public static void MOApplyERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  490. {
  491. try
  492. {
  493. #region ERP
  494. string sql = string.Empty;
  495. string Checksql = string.Empty;
  496. Checksql = @"SELECT a.F_Id
  497. FROM Sys_SRM_ItemsDetail a
  498. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  499. WHERE b.F_EnCode='BatchInOutErp' AND a.F_ItemCode='BatchOut' AND a.F_EnabledMark='1'";
  500. Checksql = string.Format(Checksql);
  501. DataTable dtdao = DBHelper.SQlReturnData(Checksql, cmd);
  502. if (dtdao.Rows.Count > 0 && dtdao != null)
  503. {
  504. string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.IssueQuantity) AS ISSQty,a.transCode from ICSMOApply b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.ApplyCode AND a.WorkPoint=b.WorkPoint
  505. where a.Identification='{0}' GROUP BY a.transCode";
  506. checksql = string.Format(checksql, Identification);
  507. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  508. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  509. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  510. string trancode = chekdt.Rows[0]["transCode"].ToString();
  511. if (SUMQty - ISSQty == 0)
  512. {
  513. string pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
  514. INTO #NewTempERP
  515. from ICSWareHouseLotInfoLog
  516. WHERE TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '14' and EATTRIBUTE1<>'1'
  517. SELECT (CASE WHEN isnull(conWhCode.Enable,0)='0' then a.FromWarehouseCode ELSE '' END)+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,
  518. 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,conWhCode.Enable AS ErpWhCode
  519. ,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,
  520. 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
  521. ,b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode,b.EATTRIBUTE7 as Project,b.EATTRIBUTE as Dep,a.transcode as HcFree4,b.EATTRIBUTE5 as HcFree2,b.EATTRIBUTE8 as HcFree3,b.EATTRIBUTE3 as HcFree1
  522. INTO #TempERP
  523. FROM #NewTempERP a
  524. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  525. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  526. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  527. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  528. INNER JOIN ICSMOApply b ON a.TransCode=b.ApplyCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint
  529. LEFT JOIN ICSMO c ON b.SourceCode=c.MOCode AND b.SourceSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  530. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  531. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  532. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  533. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  534. GROUP BY inv.AmountEnable,conWhCode.Enable,a.FromWarehouseCode,b.ApplyCode,b.SourceCode,c.DepCode,a.MUSER,a.InvCode,b.ApplyDetailID,con.Enable,conv.Enable,conStock.Enable
  535. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  536. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, ''),b.EATTRIBUTE2,b.EATTRIBUTE4,b.EATTRIBUTE,b.EATTRIBUTE7,a.transcode,b.EATTRIBUTE5 ,b.EATTRIBUTE8,b.EATTRIBUTE3
  537. SELECT DISTINCT Costre,WorkPoint,ISNULL(DepCode,'') AS DepCode,CASE WHEN isnull(ErpWhCode,0)='0' then WarehouseCode ELSE '' END AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,ISNULL(SourceCode,'') AS IssueCode ,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,DocType,ClientCode,HcFree4,HcFree2,HcFree3,HcFree1 FROM #TempERP
  538. SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ApplyDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Project,Dep FROM #TempERP
  539. DROP TABLE #TempERP
  540. DROP TABLE #NewTempERP";
  541. pnsql = string.Format(pnsql, trancode);
  542. DataSet dss = DBHelper.SQlReturnDataSet(pnsql, cmd);
  543. string Inputstrr = DataToJsonHelper.DataSetToJson(dss, "details", "Costre");
  544. string resultStrr = "";
  545. if (DBHelper.IsU9())
  546. { resultStrr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherOutDocURL, Inputstrr); }
  547. else
  548. { resultStrr = HTTPHelper.HttpPost(TransType, ERPUrl.MOApplyURL, Inputstrr); }
  549. Result result = new Result();
  550. result = JsonConvert.DeserializeObject<Result>(resultStrr);
  551. if (result.Success)
  552. {
  553. try
  554. {
  555. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  556. foreach (var item in res)
  557. {
  558. JObject jo = (JObject)item;
  559. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  560. foreach (var detail in resdetail)
  561. {
  562. JObject det = (JObject)detail;
  563. 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()
  564. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  565. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  566. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  567. }
  568. }
  569. }
  570. catch (Exception ex)
  571. {
  572. log.Debug(ex.ToString());
  573. log.Debug(resultStrr);
  574. }
  575. }
  576. else
  577. {
  578. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  579. }
  580. }
  581. }
  582. else
  583. {
  584. if (DBHelper.IsPNU9())
  585. {
  586. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
  587. INTO #NewTempERP
  588. from ICSWareHouseLotInfoLog
  589. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '14'
  590. SELECT (CASE WHEN isnull(conWhCode.Enable,0)='0' then a.FromWarehouseCode ELSE '' END)+b.ApplyCode+a.MUSER+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,
  591. 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,conWhCode.Enable AS ErpWhCode
  592. ,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,
  593. 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
  594. ,b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode,b.EATTRIBUTE7 as Project,b.EATTRIBUTE as Dep,a.transcode as HcFree4,b.EATTRIBUTE5 as HcFree2,b.EATTRIBUTE8 as HcFree3,b.EATTRIBUTE3 as HcFree1
  595. INTO #TempERP
  596. FROM #NewTempERP a
  597. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  598. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  599. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  600. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  601. INNER JOIN ICSMOApply b ON a.TransCode=b.ApplyCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint
  602. LEFT JOIN ICSMO c ON b.SourceCode=c.MOCode AND b.SourceSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  603. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  604. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  605. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  606. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  607. GROUP BY inv.AmountEnable,conWhCode.Enable,a.FromWarehouseCode,b.ApplyCode,b.SourceCode,c.DepCode,a.MUSER,a.InvCode,b.ApplyDetailID,con.Enable,conv.Enable,conStock.Enable
  608. ,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, ''),
  609. 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,a.transcode,b.EATTRIBUTE5 ,b.EATTRIBUTE8,b.EATTRIBUTE3
  610. SELECT DISTINCT Costre,WorkPoint,ISNULL(DepCode,'') AS DepCode,CASE WHEN isnull(ErpWhCode,0)='0' then WarehouseCode ELSE '' END AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,'' AS IssueCode ,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,DocType,ClientCode,HcFree4,HcFree2,HcFree3,HcFree1 FROM #TempERP
  611. SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ApplyDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Project,Dep FROM #TempERP
  612. DROP TABLE #TempERP
  613. DROP TABLE #NewTempERP";
  614. }
  615. else
  616. {
  617. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
  618. INTO #NewTempERP
  619. from ICSWareHouseLotInfoLog
  620. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '14'
  621. SELECT (CASE WHEN isnull(conWhCode.Enable,0)='0' then a.FromWarehouseCode ELSE '' END)+b.ApplyCode+a.MUSER+ISNULL(b.SourceCode,'')+ISNULL(c.DepCode,'') AS Costre,b.ApplyID,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,
  622. 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,conWhCode.Enable AS ErpWhCode
  623. ,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,
  624. 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
  625. ,b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode,b.EATTRIBUTE7 as Project,b.EATTRIBUTE as Dep,a.transcode as HcFree4,b.EATTRIBUTE5 as HcFree2,b.EATTRIBUTE8 as HcFree3,b.EATTRIBUTE3 as HcFree1
  626. INTO #TempERP
  627. FROM #NewTempERP a
  628. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  629. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  630. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  631. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  632. INNER JOIN ICSMOApply b ON a.TransCode=b.ApplyCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint
  633. LEFT JOIN ICSMO c ON b.SourceCode=c.MOCode AND b.SourceSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  634. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  635. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  636. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  637. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  638. GROUP BY b.ApplyID,inv.AmountEnable,conWhCode.Enable,a.FromWarehouseCode,b.ApplyCode,b.SourceCode,c.DepCode,a.MUSER,a.InvCode,b.ApplyDetailID,con.Enable,conv.Enable,conStock.Enable
  639. ,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, ''),
  640. 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,a.transcode,b.EATTRIBUTE5 ,b.EATTRIBUTE8,b.EATTRIBUTE3
  641. SELECT DISTINCT Costre,WorkPoint,ISNULL(DepCode,'') AS DepCode,CASE WHEN isnull(ErpWhCode,0)='0' then WarehouseCode ELSE '' END AS WHCode,'' AS SourceType,ApplyID AS SourceCode,ISNULL(SourceCode,'') AS IssueCode ,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,DocType,ClientCode,HcFree4,HcFree2,HcFree3,HcFree1 FROM #TempERP
  642. SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ApplyDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Project,Dep FROM #TempERP
  643. DROP TABLE #TempERP
  644. DROP TABLE #NewTempERP";
  645. }
  646. //,ClientCode,HcFree4,HcFree2,HcFree3,HcFree1
  647. sql = string.Format(sql, Identification);
  648. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  649. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  650. string resultStr = "";
  651. if (DBHelper.IsU9())
  652. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherOutDocURL, Inputstr); }
  653. else
  654. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOApplyURL, Inputstr); }
  655. Result result = new Result();
  656. result = JsonConvert.DeserializeObject<Result>(resultStr);
  657. if (result.Success)
  658. {
  659. try
  660. {
  661. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  662. foreach (var item in res)
  663. {
  664. JObject jo = (JObject)item;
  665. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  666. foreach (var detail in resdetail)
  667. {
  668. JObject det = (JObject)detail;
  669. 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()
  670. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  671. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  672. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  673. }
  674. }
  675. }
  676. catch (Exception ex)
  677. {
  678. log.Debug(ex.ToString());
  679. log.Debug(resultStr);
  680. }
  681. }
  682. else
  683. {
  684. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  685. }
  686. }
  687. #endregion
  688. }
  689. catch (Exception)
  690. {
  691. throw;
  692. }
  693. }
  694. #endregion
  695. #region 材料出库单生产发料
  696. /// <summary>
  697. /// 材料出库单生产发料
  698. /// </summary>
  699. /// <param name="TransCode"></param>
  700. /// <param name="TransSequence"></param>
  701. /// <param name="Quantity"></param>
  702. /// <param name="WorkPoint"></param>
  703. /// <param name="cmd"></param>
  704. public static void MOIssue(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string enableCode,string TransID)
  705. {
  706. try
  707. {
  708. string sql = @"DECLARE @Status VARCHAR(10)
  709. SELECT @Status=a.Status FROM ICSMOIssue a
  710. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.id='{4}' AND a.WorkPoint='{1}'
  711. IF (@Status IS NULL)
  712. BEGIN
  713. RAISERROR('" + language.GetNameByCode("WMSAPIInfo131") + @"',16,1);
  714. RETURN
  715. END
  716. ELSE IF (@Status!='1')
  717. BEGIN
  718. RAISERROR('" + language.GetNameByCode("WMSAPIInfo132") + @"',16,1);
  719. RETURN
  720. END
  721. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  722. FROM ICSMOIssue a
  723. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.id='{4}' AND a.WorkPoint='{1}'
  724. IF EXISTS(SELECT a.ID FROM ICSMOIssue a
  725. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.id='{4}'
  726. AND dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{5}',2,2,'')<a.IssueQuantity)
  727. BEGIN
  728. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  729. RETURN
  730. END";
  731. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID, enableCode);
  732. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  733. {
  734. throw new Exception(language.GetNameByCode("WMSAPIInfo133"));//"材料出库单更新失败!");
  735. }
  736. }
  737. catch (Exception)
  738. {
  739. throw;
  740. }
  741. }
  742. /// <summary>
  743. /// 材料出库单生产发料接口
  744. /// </summary>
  745. /// <param name="TransType"></param>
  746. /// <param name="Identification"></param>
  747. /// <param name="cmd"></param>
  748. public static void MOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  749. {
  750. try
  751. {
  752. #region ERP开立状态单据审核
  753. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  754. INTO #NewTempERP
  755. from ICSWareHouseLotInfoLog
  756. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '15'
  757. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  758. INNER JOIN ICSMOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  759. WHERE a.Identification='{0}' AND b.Quantity>b.IssueQuantity)
  760. BEGIN
  761. RAISERROR('" + language.GetNameByCode("WMSAPIInfo094") + @"',16,1);
  762. RETURN
  763. END
  764. SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity
  765. ,conStock.Enable AS UpdateStock,a.WorkPoint
  766. FROM #NewTempERP a
  767. INNER JOIN ICSMOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  768. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  769. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  770. GROUP BY b.IssueID,a.MUSER,con.Enable
  771. ,conStock.Enable,a.WorkPoint
  772. DROP TABLE #NewTempERP";
  773. sql = string.Format(sql, Identification);
  774. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  775. string Inputstr = JsonConvert.SerializeObject(dt);
  776. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOIssueURL, Inputstr);
  777. Result result = new Result();
  778. result = JsonConvert.DeserializeObject<Result>(resultStr);
  779. if (result.Success)
  780. {
  781. try
  782. {
  783. foreach (DataRow dr in dt.Rows)
  784. {
  785. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "",cmd, language, BusinessCode);
  786. }
  787. }
  788. catch (Exception ex)
  789. {
  790. log.Debug(ex.ToString());
  791. log.Debug(resultStr);
  792. }
  793. }
  794. else
  795. {
  796. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  797. }
  798. #endregion
  799. }
  800. catch (Exception)
  801. {
  802. throw;
  803. }
  804. }
  805. /// <summary>
  806. /// U9超额领料单接口 审核改创建
  807. /// </summary>
  808. /// <param name="TransType"></param>
  809. /// <param name="Identification"></param>
  810. /// <param name="cmd"></param>
  811. public static void U9MOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  812. {
  813. try
  814. {
  815. #region ERP
  816. // IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  817. // INNER JOIN ICSMOIssue b ON a.TransCode= b.IssueCode AND a.TransSequence= b.Sequence AND a.WorkPoint= b.WorkPoint
  818. // WHERE a.Identification= '{0}' AND b.Quantity! = b.IssueQuantity)
  819. // BEGIN
  820. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo094") + @"', 16, 1);
  821. // RETURN
  822. //END
  823. string sql = @"
  824. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  825. INTO #NewTempERP
  826. from ICSWareHouseLotInfoLog
  827. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '15'
  828. SELECT --a.FromWarehouseCode+
  829. 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,
  830. 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
  831. ,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,
  832. 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
  833. ,b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode,b.EATTRIBUTE5 as SuperCollarMessage
  834. INTO #TempERP
  835. FROM #NewTempERP a
  836. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  837. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  838. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  839. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  840. INNER JOIN ICSMoIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  841. LEFT JOIN ICSMO c ON b.SourceCode=c.MOCode AND b.SourceSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  842. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  843. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  844. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  845. GROUP BY inv.AmountEnable,a.FromWarehouseCode,b.IssueCode,b.SourceCode,c.DepCode,a.MUSER,a.InvCode,b.IssueDetailID,con.Enable,conv.Enable,conStock.Enable
  846. ,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, ''),
  847. 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.EATTRIBUTE5
  848. SELECT DISTINCT Costre,WorkPoint,ISNULL(DepCode,'') AS DepCode,'' AS SourceType,ISNULL(SourceCode,'') AS SourceCode,ISNULL(SourceCode,'') AS IssueCode ,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock, '18' as DocTypeCode,ClientCode,SuperCollarMessage FROM #TempERP -- WarehouseCode AS WHCode ,IssueCode AS SourceCode
  849. 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
  850. DROP TABLE #TempERP
  851. DROP TABLE #NewTempERP";
  852. sql = string.Format(sql, Identification);
  853. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  854. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  855. string resultStr = "";
  856. //resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOApplyURL, Inputstr);
  857. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOIssueDocURL, Inputstr);
  858. Result result = new Result();
  859. result = JsonConvert.DeserializeObject<Result>(resultStr);
  860. if (result.Success)
  861. {
  862. try
  863. {
  864. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  865. foreach (var item in res)
  866. {
  867. JObject jo = (JObject)item;
  868. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  869. foreach (var detail in resdetail)
  870. {
  871. JObject det = (JObject)detail;
  872. 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()
  873. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  874. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  875. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  876. }
  877. }
  878. }
  879. catch (Exception ex)
  880. {
  881. log.Debug(ex.ToString());
  882. log.Debug(resultStr);
  883. }
  884. }
  885. else
  886. {
  887. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  888. }
  889. #endregion
  890. }
  891. catch (Exception)
  892. {
  893. throw;
  894. }
  895. }
  896. #endregion
  897. #region 生产退料
  898. /// <summary>
  899. /// 生产退料
  900. /// </summary>
  901. /// <param name="TransCode"></param>
  902. /// <param name="TransSequence"></param>
  903. /// <param name="Quantity"></param>
  904. /// <param name="WorkPoint"></param>
  905. /// <param name="cmd"></param>
  906. public static void MOIssueDocNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  907. {
  908. try
  909. {
  910. string table = "";
  911. string table1 = "";
  912. string sql = "";
  913. string sqlMOIssueDocNegativeIssueDH = "";
  914. string quantitySql = "c.Quantity";
  915. if (string.IsNullOrWhiteSpace(LogID))
  916. {
  917. string type = "";
  918. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  919. {
  920. table = "INNER JOIN ICSMOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint";
  921. type = "1";
  922. quantitySql = "dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn017', c.Quantity,1,2,'')";
  923. }
  924. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  925. {
  926. table = "INNER JOIN ICSMOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
  927. type = "2";
  928. quantitySql = "dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn018', c.Quantity,1,2,'')";
  929. }
  930. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  931. {
  932. table = "INNER JOIN ICSMOIssue e ON c.SourceDetailID=e.IssueDetailID AND c.WorkPoint=e.WorkPoint";
  933. table1 = " INNER JOIN ICSMOIssue ee ON c.SourceDetailID=ee.IssueDetailID AND c.WorkPoint=ee.WorkPoint " +
  934. " INNER JOIN icsmopick e ON e.pickid = ee.pickid";
  935. type = "3";
  936. quantitySql = "dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn019', c.Quantity,1,2,'')";
  937. //东辉退料单 修改工单子件数量
  938. sqlMOIssueDocNegativeIssueDH = @" UPDATE e SET e.IssueQuantity=ISNULL(e.IssueQuantity,0)-'{2}'
  939. FROM ICSInventoryLot a
  940. INNER JOIN ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
  941. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode = c.ApplyNegCode AND b.TransSequence = c.Sequence AND b.WorkPoint = c.WorkPoint
  942. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode = d.ApplyNegCode AND c.WorkPoint = d.WorkPoint
  943. {5}
  944. WHERE a.LotNo = '{0}' AND a.WorkPoint = '{1}' AND d.Type = '{4}' and ISNULL(e.IssueQuantity,0)> 0";
  945. sqlMOIssueDocNegativeIssueDH = string.Format(sqlMOIssueDocNegativeIssueDH, LotNo, WorkPoint, Quantity, table, type, table1);
  946. }
  947. else
  948. {
  949. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  950. }
  951. #region 新条码
  952. sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  953. FROM ICSInventoryLot a
  954. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  955. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  956. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  957. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  958. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  959. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  960. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  961. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  962. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND {6}<c.IssueNegQuantity)
  963. BEGIN
  964. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  965. END
  966. -- UPDATE e SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  967. -- FROM ICSInventoryLot a
  968. -- INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  969. -- INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  970. -- INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  971. -- {3}
  972. -- WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  973. {5}
  974. -- IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  975. -- INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  976. -- INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  977. -- INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  978. -- {3}
  979. -- WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND e.IssueQuantity<0)
  980. -- BEGIN
  981. -- RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  982. -- END";
  983. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type, sqlMOIssueDocNegativeIssueDH, quantitySql);
  984. #endregion
  985. }
  986. else
  987. {
  988. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  989. {
  990. table = @"INNER JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  991. INNER JOIN ICSMOPick c ON b.MODetailID = c.MODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
  992. }
  993. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  994. {
  995. table = "INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  996. }
  997. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  998. {
  999. table = "INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  1000. }
  1001. else
  1002. {
  1003. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  1004. }
  1005. #region 原条码
  1006. sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  1007. FROM ICSWareHouseLotInfoLog a
  1008. {3}
  1009. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}'
  1010. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
  1011. {3}
  1012. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0)
  1013. BEGIN
  1014. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  1015. END";
  1016. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID);
  1017. #endregion
  1018. }
  1019. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1020. {
  1021. throw new Exception(language.GetNameByCode("WMSAPIInfo134"));//"生产退料单更新失败!");
  1022. }
  1023. }
  1024. catch (Exception)
  1025. {
  1026. throw;
  1027. }
  1028. }
  1029. /// <summary>
  1030. /// 生产退料(奥美专用)
  1031. /// </summary>
  1032. /// <param name="TransCode"></param>
  1033. /// <param name="TransSequence"></param>
  1034. /// <param name="Quantity"></param>
  1035. /// <param name="WorkPoint"></param>
  1036. /// <param name="cmd"></param>
  1037. public static void AMMOIssueDocNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint,string TransCode,string TransSequence, SqlCommand cmd, Dictionary<string, string> language)
  1038. {
  1039. try
  1040. {
  1041. string table = "";
  1042. string sql = "";
  1043. if (string.IsNullOrWhiteSpace(LogID))
  1044. {
  1045. string type = "";
  1046. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  1047. {
  1048. table = "INNER JOIN ICSMOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint";
  1049. type = "1";
  1050. }
  1051. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  1052. {
  1053. table = "INNER JOIN ICSMOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
  1054. type = "2";
  1055. }
  1056. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1057. {
  1058. table = "INNER JOIN ICSMOIssue e ON c.SourceDetailID=e.IssueDetailID AND c.WorkPoint=e.WorkPoint";
  1059. type = "3";
  1060. }
  1061. else
  1062. {
  1063. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  1064. }
  1065. #region 新条码
  1066. sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  1067. FROM ICSInventoryLot a
  1068. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1069. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1070. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  1071. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  1072. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1073. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1074. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1075. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  1076. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND c.Quantity<c.IssueNegQuantity)
  1077. BEGIN
  1078. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  1079. END
  1080. UPDATE e SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  1081. FROM ICSInventoryLot a
  1082. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1083. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1084. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  1085. {3}
  1086. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  1087. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1088. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1089. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1090. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  1091. {3}
  1092. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND e.IssueQuantity<0)
  1093. BEGIN
  1094. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  1095. END";
  1096. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type);
  1097. #endregion
  1098. }
  1099. else
  1100. {
  1101. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  1102. {
  1103. table = @"INNER JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  1104. INNER JOIN ICSMOPick c ON b.MODetailID = c.MODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
  1105. }
  1106. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  1107. {
  1108. table = "INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  1109. }
  1110. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1111. {
  1112. table = "INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  1113. }
  1114. else
  1115. {
  1116. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  1117. }
  1118. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  1119. {
  1120. #region 原条码
  1121. sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  1122. FROM ICSWareHouseLotInfoLog a
  1123. {3}
  1124. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' and b.MoCode='{5}' AND b.Sequence='{6}'
  1125. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
  1126. {3}
  1127. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0 and b.MoCode='{5}' AND b.Sequence='{6}')
  1128. BEGIN
  1129. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  1130. END";
  1131. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID, TransCode, TransSequence);
  1132. }
  1133. else
  1134. {
  1135. sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  1136. FROM ICSWareHouseLotInfoLog a
  1137. {3}
  1138. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}'
  1139. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
  1140. {3}
  1141. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0)
  1142. BEGIN
  1143. RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
  1144. END";
  1145. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID, TransCode, TransSequence);
  1146. }
  1147. #endregion
  1148. }
  1149. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1150. {
  1151. throw new Exception(language.GetNameByCode("WMSAPIInfo134"));//"生产退料单更新失败!");
  1152. }
  1153. }
  1154. catch (Exception)
  1155. {
  1156. throw;
  1157. }
  1158. }
  1159. /// <summary>
  1160. /// 生产退料接口
  1161. /// </summary>
  1162. /// <param name="TransType"></param>
  1163. /// <param name="Identification"></param>
  1164. /// <param name="cmd"></param>
  1165. public static void MOIssueDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1166. {
  1167. try
  1168. {
  1169. #region ERP
  1170. string sql = string.Empty;
  1171. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  1172. {
  1173. sql = @"select LotNo,a.WorkPoint,InvCode,ToWarehouseCode,a.MUSER,Quantity,con.Enable,conStock.Enable AS conStockEnable
  1174. INTO #NewTempERP
  1175. from ICSWareHouseLotInfoLog a
  1176. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1177. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1178. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  1179. select LotNo,a.WorkPoint,InvCode,ToWarehouseCode,a.MUSER,Quantity,LogID,con.Enable,conStock.Enable AS conStockEnable
  1180. INTO #NewDouTempERP
  1181. from ICSWareHouseLotInfoLog a
  1182. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1183. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1184. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  1185. 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,
  1186. a.InvCode,inv.InvRate,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,a.Enable AS UpdateTodoQuantity,a.conStockEnable AS UpdateStock
  1187. ,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,
  1188. 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
  1189. INTO #TempERP
  1190. FROM #NewTempERP a
  1191. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1192. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1193. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1194. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1195. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1196. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1197. INNER JOIN ICSMOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
  1198. INNER JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1199. GROUP BY inv.AmountEnable,y.DepCode,a.ToWarehouseCode,y.MOCode,a.MUSER,a.InvCode,inv.InvRate,lot.Amount,lot.Quantity,x.PickID,x.MODetailID,a.Enable,a.conStockEnable
  1200. ,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, ''),
  1201. 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, '')
  1202. UNION ALL
  1203. 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,
  1204. a.InvCode,inv.InvRate,SUM(a.Quantity) AS Quantity,0 AS Amount,x.PickID AS SourceDetailID,a.Enable AS UpdateTodoQuantity,a.conStockEnable AS UpdateStock
  1205. ,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,
  1206. 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
  1207. FROM #NewDouTempERP a
  1208. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1209. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1210. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1211. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1212. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1213. INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
  1214. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  1215. GROUP BY y.DepCode,a.ToWarehouseCode,y.MOCode,a.MUSER,a.InvCode,inv.InvRate,x.PickID,x.MODetailID,a.Enable,a.conStockEnable
  1216. ,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, ''),
  1217. 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, '')
  1218. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1219. SELECT Costre,Sequence,InvCode,InvRate,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ,WarehouseCode AS WHCode FROM #TempERP
  1220. DROP TABLE #TempERP
  1221. DROP TABLE #NewTempERP
  1222. DROP TABLE #NewDouTempERP";
  1223. }
  1224. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  1225. {
  1226. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  1227. INTO #NewTempERP
  1228. from ICSWareHouseLotInfoLog
  1229. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  1230. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  1231. INTO #NewDouTempERP
  1232. from ICSWareHouseLotInfoLog
  1233. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  1234. 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,
  1235. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1236. ,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,
  1237. 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
  1238. INTO #TempERP
  1239. FROM #NewTempERP a
  1240. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1241. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1242. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1243. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1244. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1245. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1246. INNER JOIN ICSMOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint
  1247. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1248. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1249. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,con.Enable,conStock.Enable
  1250. ,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, ''),
  1251. 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, '')
  1252. UNION ALL
  1253. 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,
  1254. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1255. ,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,
  1256. 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
  1257. FROM #NewDouTempERP a
  1258. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1259. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1260. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1261. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1262. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1263. INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  1264. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1265. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1266. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,con.Enable,conStock.Enable
  1267. ,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, ''),
  1268. 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, '')
  1269. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1270. 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
  1271. DROP TABLE #TempERP
  1272. DROP TABLE #NewTempERP
  1273. DROP TABLE #NewDouTempERP";
  1274. }
  1275. //根据材料出库单查询上游单据,根据上游单据生成红字材料出库
  1276. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1277. {
  1278. sql = @"
  1279. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  1280. INTO #NewTempERP
  1281. from ICSWareHouseLotInfoLog
  1282. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  1283. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  1284. INTO #NewDouTempERP
  1285. from ICSWareHouseLotInfoLog
  1286. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  1287. IF EXISTS(select * FROM #NewTempERP a
  1288. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1289. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1290. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1291. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1292. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1293. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1294. INNER JOIN ICSMOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1295. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1296. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1297. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1298. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1299. where m.ApplyDetailID<>null and z.ApplyDetailID=null)
  1300. BEGIN
  1301. RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
  1302. RETURN
  1303. END
  1304. IF EXISTS(select * FROM #NewDouTempERP a
  1305. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1306. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1307. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1308. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1309. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1310. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1311. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1312. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1313. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1314. where m.ApplyDetailID<>null and z.ApplyDetailID=null)
  1315. BEGIN
  1316. RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
  1317. RETURN
  1318. END
  1319. 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,
  1320. 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
  1321. ,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,
  1322. 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
  1323. ,m.issuecode as DocCode,m.Sequence as DocLineNo
  1324. INTO #TempERP
  1325. FROM #NewTempERP a
  1326. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1327. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1328. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1329. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1330. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1331. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1332. INNER JOIN ICSMOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1333. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1334. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1335. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1336. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1337. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1338. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,con.Enable,conStock.Enable
  1339. ,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, ''),
  1340. 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, '')
  1341. UNION ALL
  1342. 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,
  1343. 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
  1344. ,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,
  1345. 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
  1346. ,m.issuecode as DocCode,m.Sequence as DocLineNo
  1347. FROM #NewDouTempERP 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 ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1353. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1354. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1355. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1356. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1357. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1358. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1359. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,con.Enable,conStock.Enable
  1360. ,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, ''),
  1361. 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, '')
  1362. IF EXISTS(SELECT Costre FROM #TempERP WHERE SourceType='{0}')
  1363. BEGIN
  1364. RAISERROR('" + language.GetNameByCode("WMSAPIInfo135") + @"',16,1);
  1365. END
  1366. SELECT DISTINCT Costre+isnull(MOCode,'')+isnull(DocCode,'') as Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock,DocCode,'19' as DocTypeCode FROM #TempERP
  1367. SELECT Costre+isnull(MOCode,'')+isnull(DocCode,'') as 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
  1368. DROP TABLE #TempERP
  1369. DROP TABLE #NewTempERP
  1370. DROP TABLE #NewDouTempERP";
  1371. }
  1372. else
  1373. {
  1374. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  1375. }
  1376. sql = string.Format(sql, Identification);
  1377. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1378. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1379. string resultStr = "";
  1380. if (DBHelper.IsU9())
  1381. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOIssueDocNegativeURL, Inputstr); }
  1382. else
  1383. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueDocNegativeURL, Inputstr); }
  1384. Result result = new Result();
  1385. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1386. if (result.Success)
  1387. {
  1388. try
  1389. {
  1390. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1391. foreach (var item in res)
  1392. {
  1393. JObject jo = (JObject)item;
  1394. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1395. foreach (var detail in resdetail)
  1396. {
  1397. JObject det = (JObject)detail;
  1398. 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()
  1399. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1400. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1401. det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1402. }
  1403. }
  1404. }
  1405. catch (Exception ex)
  1406. {
  1407. log.Debug(ex.ToString());
  1408. log.Debug(resultStr);
  1409. }
  1410. }
  1411. else
  1412. {
  1413. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1414. }
  1415. #endregion
  1416. }
  1417. catch (Exception)
  1418. {
  1419. throw;
  1420. }
  1421. }
  1422. /// <summary>
  1423. /// 生产退料接口
  1424. /// </summary>
  1425. /// <param name="TransType"></param>
  1426. /// <param name="Identification"></param>
  1427. /// <param name="cmd"></param>
  1428. public static void DXMOIssueDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode,string IsDx)
  1429. {
  1430. try
  1431. {
  1432. #region ERP
  1433. string sql = string.Empty;
  1434. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
  1435. {
  1436. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  1437. INTO #NewTempERP
  1438. from ICSWareHouseLotInfoLog
  1439. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  1440. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  1441. INTO #NewDouTempERP
  1442. from ICSWareHouseLotInfoLog
  1443. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  1444. 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,
  1445. 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
  1446. ,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,
  1447. 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
  1448. INTO #TempERP
  1449. FROM #NewTempERP a
  1450. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1451. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1452. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1453. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1454. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1455. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1456. INNER JOIN ICSMOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
  1457. INNER JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1458. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1459. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1460. 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
  1461. ,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, ''),
  1462. 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, '')
  1463. UNION ALL
  1464. 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,
  1465. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1466. ,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,
  1467. 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
  1468. FROM #NewDouTempERP a
  1469. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1470. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1471. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1472. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1473. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1474. INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
  1475. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  1476. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1477. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1478. GROUP BY y.DepCode,a.ToWarehouseCode,y.MOCode,a.MUSER,a.InvCode,x.PickID,x.MODetailID,con.Enable,conStock.Enable
  1479. ,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, ''),
  1480. 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, '')
  1481. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1482. 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
  1483. DROP TABLE #TempERP
  1484. DROP TABLE #NewTempERP
  1485. DROP TABLE #NewDouTempERP";
  1486. }
  1487. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  1488. {
  1489. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  1490. INTO #NewTempERP
  1491. from ICSWareHouseLotInfoLog
  1492. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  1493. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  1494. INTO #NewDouTempERP
  1495. from ICSWareHouseLotInfoLog
  1496. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  1497. 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,
  1498. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1499. ,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,
  1500. 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
  1501. INTO #TempERP
  1502. FROM #NewTempERP a
  1503. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1504. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1505. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1506. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1507. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1508. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1509. INNER JOIN ICSMOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint
  1510. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1511. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1512. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,con.Enable,conStock.Enable
  1513. ,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, ''),
  1514. 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, '')
  1515. UNION ALL
  1516. 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,
  1517. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1518. ,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,
  1519. 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
  1520. FROM #NewDouTempERP a
  1521. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1522. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1523. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1524. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1525. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1526. INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  1527. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1528. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1529. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,con.Enable,conStock.Enable
  1530. ,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, ''),
  1531. 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, '')
  1532. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1533. 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
  1534. DROP TABLE #TempERP
  1535. DROP TABLE #NewTempERP
  1536. DROP TABLE #NewDouTempERP";
  1537. }
  1538. //根据材料出库单查询上游单据,根据上游单据生成红字材料出库
  1539. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1540. {
  1541. sql = @"
  1542. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  1543. INTO #NewTempERP
  1544. from ICSWareHouseLotInfoLog
  1545. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  1546. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  1547. INTO #NewDouTempERP
  1548. from ICSWareHouseLotInfoLog
  1549. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  1550. IF EXISTS(select * FROM #NewTempERP a
  1551. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1552. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1553. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1554. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1555. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1556. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1557. INNER JOIN ICSMOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1558. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1559. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1560. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1561. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1562. where m.ApplyDetailID<>null and z.ApplyDetailID=null)
  1563. BEGIN
  1564. RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
  1565. RETURN
  1566. END
  1567. IF EXISTS(select * FROM #NewDouTempERP a
  1568. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1569. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1570. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1571. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1572. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1573. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1574. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1575. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1576. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1577. where m.ApplyDetailID<>null and z.ApplyDetailID=null)
  1578. BEGIN
  1579. RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
  1580. RETURN
  1581. END
  1582. 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,
  1583. 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
  1584. ,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,
  1585. 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
  1586. ,m.issuecode as DocCode,m.Sequence as DocLineNo
  1587. INTO #TempERP
  1588. FROM #NewTempERP a
  1589. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1590. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1591. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1592. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1593. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1594. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1595. INNER JOIN ICSMOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1596. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1597. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1598. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1599. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1600. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1601. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,con.Enable,conStock.Enable
  1602. ,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, ''),
  1603. 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, '')
  1604. UNION ALL
  1605. 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,
  1606. 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
  1607. ,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,
  1608. 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
  1609. ,m.issuecode as DocCode,m.Sequence as DocLineNo
  1610. FROM #NewDouTempERP a
  1611. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1612. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1613. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1614. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1615. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1616. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1617. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1618. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1619. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1620. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1621. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1622. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,con.Enable,conStock.Enable
  1623. ,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, ''),
  1624. 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, '')
  1625. IF EXISTS(SELECT Costre FROM #TempERP WHERE SourceType='{0}')
  1626. BEGIN
  1627. RAISERROR('" + language.GetNameByCode("WMSAPIInfo135") + @"',16,1);
  1628. END
  1629. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock,DocCode,'19' as DocTypeCode FROM #TempERP
  1630. 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
  1631. DROP TABLE #TempERP
  1632. DROP TABLE #NewTempERP
  1633. DROP TABLE #NewDouTempERP";
  1634. }
  1635. else
  1636. {
  1637. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  1638. }
  1639. sql = string.Format(sql, Identification);
  1640. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1641. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1642. string resultStr = "";
  1643. if (DBHelper.IsU9())
  1644. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOIssueDocNegativeURL, Inputstr); }
  1645. else
  1646. {
  1647. if (IsDx == "1")
  1648. {
  1649. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DXNewMOIssueDocNegativeURL, Inputstr);
  1650. }
  1651. else
  1652. {
  1653. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DXMOIssueDocNegativeURL, Inputstr);
  1654. }
  1655. }
  1656. Result result = new Result();
  1657. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1658. if (result.Success)
  1659. {
  1660. try
  1661. {
  1662. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1663. foreach (var item in res)
  1664. {
  1665. JObject jo = (JObject)item;
  1666. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1667. foreach (var detail in resdetail)
  1668. {
  1669. JObject det = (JObject)detail;
  1670. 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()
  1671. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1672. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1673. det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1674. }
  1675. }
  1676. }
  1677. catch (Exception ex)
  1678. {
  1679. log.Debug(ex.ToString());
  1680. log.Debug(resultStr);
  1681. }
  1682. }
  1683. else
  1684. {
  1685. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1686. }
  1687. #endregion
  1688. }
  1689. catch (Exception)
  1690. {
  1691. throw;
  1692. }
  1693. }
  1694. #endregion
  1695. #region 生产入库
  1696. /// <summary>
  1697. /// 生产入库
  1698. /// </summary>
  1699. /// <param name="TransCode"></param>
  1700. /// <param name="TransSequence"></param>
  1701. /// <param name="Quantity"></param>
  1702. /// <param name="WorkPoint"></param>
  1703. /// <param name="cmd"></param>
  1704. public static void ManufactureReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1705. {
  1706. try
  1707. {
  1708. string sql = @"DECLARE @Status VARCHAR(10)
  1709. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  1710. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1711. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1712. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1713. IF (@Status IS NULL)
  1714. BEGIN
  1715. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1716. RETURN
  1717. END
  1718. ELSE IF (@Status='3')
  1719. BEGIN
  1720. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1721. RETURN
  1722. END
  1723. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1724. FROM ICSInventoryLot a
  1725. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1726. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1727. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1728. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1729. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1730. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1731. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1732. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn011', c.Quantity,1,2,'')<c.RCVQuantity)
  1733. BEGIN
  1734. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1735. END";
  1736. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1737. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1738. {
  1739. throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
  1740. }
  1741. }
  1742. catch (Exception)
  1743. {
  1744. throw;
  1745. }
  1746. }
  1747. /// <summary>
  1748. /// 生产入库(奥美专用)
  1749. /// </summary>
  1750. /// <param name="TransCode"></param>
  1751. /// <param name="TransSequence"></param>
  1752. /// <param name="Quantity"></param>
  1753. /// <param name="WorkPoint"></param>
  1754. /// <param name="cmd"></param>
  1755. public static void ManufactureReceiveDocAM(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1756. {
  1757. try
  1758. {
  1759. string cheksql = @"select d.EATTRIBUTE1 FROM ICSInventoryLot a
  1760. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1761. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1762. INNER JOIN ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1763. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and d.AmountEnable='1'";
  1764. cheksql = string.Format(cheksql, LotNo, WorkPoint);
  1765. DataTable dt = DBHelper.SQlReturnData(cheksql, cmd);
  1766. if (dt.Rows.Count > 0)
  1767. {
  1768. Quantity = (decimal.Parse(Quantity) * decimal.Parse(dt.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  1769. }
  1770. string sql = @"DECLARE @Status VARCHAR(10)
  1771. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  1772. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1773. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1774. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1775. IF (@Status IS NULL)
  1776. BEGIN
  1777. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1778. RETURN
  1779. END
  1780. ELSE IF (@Status='3')
  1781. BEGIN
  1782. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1783. RETURN
  1784. END
  1785. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1786. FROM ICSInventoryLot a
  1787. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1788. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1789. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1790. --IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1791. -- INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1792. -- INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1793. -- WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1794. -- AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn001', '{0}')<c.RCVQuantity)
  1795. --BEGIN
  1796. -- RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1797. --END";
  1798. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1799. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1800. {
  1801. throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
  1802. }
  1803. }
  1804. catch (Exception)
  1805. {
  1806. throw;
  1807. }
  1808. }
  1809. /// <summary>
  1810. /// 生产入库接口
  1811. /// </summary>
  1812. /// <param name="TransType"></param>
  1813. /// <param name="Identification"></param>
  1814. /// <param name="cmd"></param>
  1815. public static void ManufactureReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1816. {
  1817. try
  1818. {
  1819. #region ERP
  1820. string sql = "";
  1821. string outwhcode = "";
  1822. DataTable flag = null;
  1823. string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'";
  1824. flag = DBHelper.SQlReturnData(enablesql, cmd);
  1825. if (DBHelper.IsU9()) { sql = @"SELECT ISNULL(c.DepCode,'')+a.ToWarehouseCode+c.MOCode+a.MUSER AS Costre,
  1826. 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
  1827. + CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END
  1828. + CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END
  1829. + CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END
  1830. + CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END
  1831. + CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END
  1832. + CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END
  1833. + CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END
  1834. + CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END
  1835. + CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END
  1836. + CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END
  1837. + CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS Costre2,lot.EATTRIBUTE2,
  1838. 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,
  1839. 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
  1840. ,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END AS ProjectCode,
  1841. 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,
  1842. CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END AS Version,
  1843. CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END AS Brand,
  1844. CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END AS cFree1,
  1845. CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END AS cFree2,
  1846. CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END AS cFree3,
  1847. CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END AS cFree4,
  1848. CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END AS cFree5,
  1849. CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END AS cFree6,
  1850. CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END AS cFree7,
  1851. CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END AS cFree8,
  1852. CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END AS cFree9,
  1853. CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS cFree10,
  1854. conv.Enable AS CompleteVerification,a.TransSequence
  1855. INTO #TempERP
  1856. FROM ICSWareHouseLotInfoLog a
  1857. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1858. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1859. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1860. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1861. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1862. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1863. INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
  1864. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1865. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  1866. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  1867. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose001'
  1868. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1869. GROUP BY inv.AmountEnable,c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,c.MODetailID,con.Enable,conv.Enable,conStock.Enable,conStocknew.Enable
  1870. ,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END,lot.EATTRIBUTE2,
  1871. CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,
  1872. CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END,
  1873. CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END,
  1874. CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END,
  1875. CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END,
  1876. CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END,
  1877. CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END,
  1878. CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END,
  1879. CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END,
  1880. CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END,
  1881. CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END,
  1882. CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END,
  1883. CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END,a.TransSequence
  1884. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,IsFillClose FROM #TempERP
  1885. 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
  1886. FROM #TempERP
  1887. 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
  1888. FROM ICSWareHouseLotInfoLog a
  1889. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1890. INNER JOIN ICSMO b ON b.MOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  1891. INNER JOIN ICSMOPick c ON c.MODetailID=b.MODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  1892. INNER JOIN ICSExtension ext ON ext.ID=c.ExtensionID AND ext.WorkPoint=c.WorkPoint
  1893. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1894. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1895. INNER JOIN #TempERP te ON te.TransSequence=SUBSTRING(a.TransSequence,1,CHARINDEX('~',a.TransSequence)-1)
  1896. WHERE a.Identification='{0}' AND a.TransType='12'
  1897. 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, ''),
  1898. 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
  1899. DROP TABLE #TempERP"; }
  1900. else { sql = @"SELECT ISNULL(c.DepCode,'')+a.ToWarehouseCode+c.MOCode+a.MUSER AS Costre,
  1901. ISNULL(c.MODetailID,'')+ISNULL(a.TransCode,'')+ISNULL(a.TransSequence,'')+ISNULL(c.DepCode,'')+ISNULL(a.ToWarehouseCode,'')+ISNULL(c.MOCode,'')+ISNULL(a.MUSER,'')+ISNULL(a.InvCode,'')
  1902. +ISNULL(a.WorkPoint,'')+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
  1903. + CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END
  1904. + CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END
  1905. + CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END
  1906. + CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END
  1907. + CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END
  1908. + CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END
  1909. + CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END
  1910. + CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END
  1911. + CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END
  1912. + CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END
  1913. + CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS Costre2,ISNULL(c.EATTRIBUTE30,'') AS EATTRIBUTE30,
  1914. 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,conWhCode.Enable AS ErpWhCode,
  1915. 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
  1916. ,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END AS ProjectCode,
  1917. 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,
  1918. CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END AS Version,
  1919. CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END AS Brand,
  1920. CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END AS cFree1,
  1921. CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END AS cFree2,
  1922. CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END AS cFree3,
  1923. CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END AS cFree4,
  1924. CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END AS cFree5,
  1925. CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END AS cFree6,
  1926. CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END AS cFree7,
  1927. CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END AS cFree8,
  1928. CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END AS cFree9,
  1929. CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS cFree10,
  1930. conv.Enable AS CompleteVerification,a.TransSequence,lot.eattribute10 as Reason,a.TransCode,a.ToWarehouseCode
  1931. INTO #TempERP
  1932. FROM ICSWareHouseLotInfoLog a
  1933. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1934. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1935. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1936. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1937. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1938. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1939. INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
  1940. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1941. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  1942. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  1943. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose001'
  1944. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1945. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1946. GROUP BY c.EATTRIBUTE30,a.TransCode,conWhCode.Enable,inv.AmountEnable,c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,c.MODetailID,con.Enable,conv.Enable,conStock.Enable,conStocknew.Enable
  1947. ,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END,
  1948. CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,
  1949. CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END,
  1950. CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END,
  1951. CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END,
  1952. CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END,
  1953. CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END,
  1954. CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END,
  1955. CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END,
  1956. CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END,
  1957. CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END,
  1958. CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END,
  1959. CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END,
  1960. CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END,a.TransSequence,lot.eattribute10
  1961. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,EATTRIBUTE30,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,IsFillClose FROM #TempERP
  1962. SELECT Costre,Costre2,Sequence,InvCode,Quantity,Amount,MODetailID,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Reason
  1963. FROM #TempERP
  1964. SELECT a.EATTRIBUTE3,a.FromWarehouseCode AS WHCode,c.MODetailID+te.TransCode+te.TransSequence+te.DepCode+te.ToWarehouseCode+te.MOCode+te.MUSER+te.InvCode
  1965. +te.WorkPoint+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(a.Quantity) as Quantity,SUM((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
  1966. FROM ICSWareHouseLotInfoLog a
  1967. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1968. INNER JOIN ICSMO b ON b.MOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  1969. INNER JOIN ICSMOPick c ON c.MODetailID=b.MODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  1970. INNER JOIN ICSExtension ext ON ext.ID=lot.ExtensionID AND ext.WorkPoint=lot.WorkPoint
  1971. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1972. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1973. INNER JOIN #TempERP te ON te.TransSequence=SUBSTRING(a.TransSequence,1,CHARINDEX('~',a.TransSequence)-1) and c.MODetailID+a.EATTRIBUTE3=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
  1974. WHERE a.Identification='{0}' AND a.TransType='12' and a.businesscode ='61'
  1975. GROUP BY te.DepCode,te.ToWarehouseCode,te.MOCode,te.MUSER,te.InvCode
  1976. ,te.WorkPoint,te.TransCode,te.TransSequence,a.EATTRIBUTE3,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, ''),
  1977. 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
  1978. DROP TABLE #TempERP"; }
  1979. sql = string.Format(sql, Identification, BusinessCode);
  1980. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1981. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre","detailss", "Costre2");
  1982. string resultStr = "";
  1983. if (DBHelper.IsU9())
  1984. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOStockINByProductDocURL, Inputstr); }
  1985. else { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ManufactureReceiveDocURL, Inputstr); }
  1986. log.Debug("ERP成品入库单返回:"+ resultStr);
  1987. Result result = new Result();
  1988. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1989. if (result.Success)
  1990. {
  1991. try
  1992. {
  1993. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1994. {
  1995. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1996. from ICSWareHouseLotInfoLog
  1997. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  1998. newsql = string.Format(newsql, Identification, BusinessCode);
  1999. DataTable dt = DBHelper.SQlReturnData(newsql, cmd);
  2000. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2001. foreach (var item in res)
  2002. {
  2003. JObject jo = (JObject)item;
  2004. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2005. foreach (var detail in resdetail)
  2006. {
  2007. JObject det = (JObject)detail;
  2008. 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()
  2009. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2010. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  2011. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2012. if (det["detailss"] != null)
  2013. {
  2014. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  2015. foreach (var details in resdetails)
  2016. {
  2017. JObject dets = (JObject)details;
  2018. if (dets != null)
  2019. {
  2020. //for (int i = 0; i < dt.Rows.Count; i++)
  2021. //{
  2022. //派纳倒冲排除仓库逻辑
  2023. string whsql = @"SELECT b.F_ItemCode,b.F_ItemName FROM Sys_SRM_Items a
  2024. INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  2025. where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1' and b.F_ItemCode='{0}'";
  2026. whsql = string.Format(whsql, dets["WHCode"].ToString());
  2027. DataTable dtt = DBHelper.SQlReturnData(whsql, cmd);
  2028. if (dtt.Rows.Count > 0 && dtt != null)
  2029. {
  2030. //if (!dtt.Rows[0]["F_ItemCode"].ToString().Equals(dets["WHCode"].ToString()))
  2031. //{
  2032. // ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["INVCode"].ToString(),
  2033. // dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  2034. // dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), "", "",
  2035. // "", "", "", "", "",
  2036. // "", "", "", "", "", "",
  2037. // "", cmd, language);
  2038. //}
  2039. //回写已领数量
  2040. sql = @"UPDATE ICSMOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + dets["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  2041. sql = String.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  2042. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2043. {
  2044. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  2045. }
  2046. }
  2047. else
  2048. {
  2049. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["INVCode"].ToString(),
  2050. dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  2051. dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), "", "",
  2052. "", "", "", "", "",
  2053. "", "", "", "", "", "",
  2054. "", cmd, language);
  2055. //回写已领数量
  2056. sql = @"UPDATE ICSMOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + dets["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  2057. sql = String.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  2058. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2059. {
  2060. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  2061. }
  2062. }
  2063. }
  2064. }
  2065. }
  2066. }
  2067. }
  2068. }
  2069. else
  2070. {
  2071. if (result.Data != null)
  2072. {
  2073. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2074. foreach (var item in res)
  2075. {
  2076. JObject jo = (JObject)item;
  2077. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2078. foreach (var detail in resdetail)
  2079. {
  2080. JObject det = (JObject)detail;
  2081. log.Debug("111");
  2082. string allcol = jo["cWhCode"]==null? jo["WHCode"].ToString(): 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()
  2083. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2084. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  2085. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2086. log.Debug("222");
  2087. if (det["detailss"] != null)
  2088. {
  2089. log.Debug("333");
  2090. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  2091. foreach (var details in resdetails)
  2092. {
  2093. JObject dets = (JObject)details;
  2094. if (dets != null)
  2095. {
  2096. //直接回写
  2097. string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2098. FROM ICSWareHouseLotInfoLog a
  2099. LEFT JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  2100. LEFT JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  2101. WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='61'";
  2102. ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["DetailID"].ToString(), dets["MRCVCode"].ToString()
  2103. , dets["Sequence"].ToString(), BusinessCode);
  2104. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  2105. {
  2106. log.Error("倒冲回写sql:" + ERPupdate);
  2107. //throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"成品倒冲回写失败!";
  2108. }
  2109. }
  2110. }
  2111. }
  2112. }
  2113. }
  2114. }
  2115. }
  2116. }
  2117. catch (Exception ex)
  2118. {
  2119. log.Debug(ex.ToString());
  2120. log.Debug(resultStr);
  2121. throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  2122. }
  2123. }
  2124. else
  2125. {
  2126. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2127. }
  2128. #endregion
  2129. }
  2130. catch (Exception)
  2131. {
  2132. throw;
  2133. }
  2134. }
  2135. #endregion
  2136. #region 副产品入库
  2137. /// <summary>
  2138. /// 副产品入库
  2139. /// </summary>
  2140. /// <param name="TransCode"></param>
  2141. /// <param name="TransSequence"></param>
  2142. /// <param name="Quantity"></param>
  2143. /// <param name="WorkPoint"></param>
  2144. /// <param name="cmd"></param>
  2145. public static void MOStockINByProductDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2146. {
  2147. try
  2148. {
  2149. string sql = @"DECLARE @Status VARCHAR(10)
  2150. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  2151. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2152. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  2153. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  2154. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2155. IF (@Status IS NULL)
  2156. BEGIN
  2157. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2158. RETURN
  2159. END
  2160. ELSE IF (@Status='3')
  2161. BEGIN
  2162. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  2163. RETURN
  2164. END
  2165. UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  2166. FROM ICSInventoryLot a
  2167. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2168. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  2169. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  2170. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2171. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2172. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2173. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  2174. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  2175. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2176. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn014', c.Quantity,1,2,'')<c.RCVQuantity)
  2177. BEGIN
  2178. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  2179. END";
  2180. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2181. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2182. {
  2183. throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
  2184. }
  2185. }
  2186. catch (Exception)
  2187. {
  2188. throw;
  2189. }
  2190. }
  2191. /// <summary>
  2192. /// 委外副产品入库
  2193. /// </summary>
  2194. /// <param name="TransCode"></param>
  2195. /// <param name="TransSequence"></param>
  2196. /// <param name="Quantity"></param>
  2197. /// <param name="WorkPoint"></param>
  2198. /// <param name="cmd"></param>
  2199. public static void OOStockINByProductDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2200. {
  2201. try
  2202. {
  2203. string sql = @"DECLARE @Status VARCHAR(10)
  2204. SELECT @Status=c.Status FROM ICSInventoryLot a
  2205. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2206. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.WorkPoint=c.WorkPoint
  2207. INNER JOIN ICSOOPick d ON c.OODetailID=d.OODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  2208. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2209. IF (@Status IS NULL)
  2210. BEGIN
  2211. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2212. RETURN
  2213. END
  2214. ELSE IF (@Status='3')
  2215. BEGIN
  2216. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  2217. RETURN
  2218. END
  2219. UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  2220. FROM ICSInventoryLot a
  2221. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2222. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.WorkPoint=c.WorkPoint
  2223. INNER JOIN ICSOOPick d ON c.OODetailID=d.OODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  2224. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2225. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2226. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2227. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.WorkPoint=c.WorkPoint
  2228. INNER JOIN ICSOOPick d ON c.OODetailID=d.OODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  2229. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2230. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn007', c.Quantity,1,1,'')<c.InQuantity)
  2231. BEGIN
  2232. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  2233. END";
  2234. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2235. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2236. {
  2237. throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
  2238. }
  2239. }
  2240. catch (Exception)
  2241. {
  2242. throw;
  2243. }
  2244. }
  2245. /// <summary>
  2246. /// 联副产品入库(奥美专用)
  2247. /// </summary>
  2248. /// <param name="LotNo"></param>
  2249. /// <param name="Quantity"></param>
  2250. /// <param name="WorkPoint"></param>
  2251. /// <param name="cmd"></param>
  2252. /// <param name="language"></param>
  2253. public static void MOStockINByProductAMDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2254. {
  2255. try
  2256. {
  2257. //条码表类型为19(无源头副产品条码),则不作数量卡控
  2258. string checkSql = @"SELECT Type FROM ICSInventoryLot WHERE LotNo='{0}'";
  2259. checkSql = string.Format(checkSql, LotNo);
  2260. string type = DBHelper.ExecuteScalar(checkSql, cmd).ToString();
  2261. if ("19".Equals(type))
  2262. {
  2263. return;
  2264. }
  2265. string sql = @"DECLARE @Status VARCHAR(10)
  2266. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  2267. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2268. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  2269. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  2270. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2271. IF (@Status IS NULL)
  2272. BEGIN
  2273. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2274. RETURN
  2275. END
  2276. ELSE IF (@Status='3')
  2277. BEGIN
  2278. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  2279. RETURN
  2280. END
  2281. UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  2282. FROM ICSInventoryLot a
  2283. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2284. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  2285. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  2286. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2287. DECLARE @MoTypeValue VARCHAR(50)
  2288. DECLARE @QtyBeyond DECIMAL(18,4)=9999
  2289. SELECT @MoTypeValue=c.EATTRIBUTE1 FROM ICSInventoryLot a
  2290. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2291. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  2292. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  2293. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2294. IF(@MoTypeValue='0')--
  2295. BEGIN
  2296. select
  2297. -- @QtyBeyond = cast( isnull(h.BL,0)*d.Quantity AS DECIMAL(18,4))
  2298. @QtyBeyond = 9999
  2299. from ICSInventoryLot a
  2300. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2301. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint AND c.MOStatus<>'3'
  2302. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  2303. left join
  2304. (
  2305. select MinBL as BL ,MODetailID from (
  2306. select a.MODetailID,
  2307. min(ALLBL)*max(isnull(F_Define1,0)/100.0) as MinBL
  2308. from (
  2309. select a.MODetailID ,
  2310. case when a.Quantity =0 then 0 when a.IssueQuantity=0 then 0 else a.IssueQuantity/a.Quantity end as ALLBL
  2311. from dbo.ICSMOPick a
  2312. inner join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  2313. where a.EATTRIBUTE1<>'1' and a.IssueQuantity>0 )a
  2314. left join Sys_SRM_ItemsDetail flag on flag.F_ItemCode='GDCS0001'
  2315. group by MODetailID )a
  2316. ) h on d.MODetailID=h.MODetailID
  2317. left join ICSExtension e on d.ExtensionID=e.ID and a.WorkPoint=e.WorkPoint
  2318. WHERE 1=1 AND a.LotNo='{0}' AND a.WorkPoint='{1}'
  2319. END
  2320. ELSE IF(@MoTypeValue='1')--
  2321. BEGIN
  2322. select
  2323. -- @QtyBeyond = cast( isnull(h.BL,0)*d.Quantity AS DECIMAL(18,4))
  2324. @QtyBeyond = 9999
  2325. from ICSInventoryLot a
  2326. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2327. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint AND c.MOStatus<>'3'
  2328. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  2329. left join
  2330. (
  2331. select case when Flag>0 then ( case when PSLNUM>MLNUM then MLNUM else PSLNUM end) else PSLNUM end as BL ,MODetailID from (
  2332. select a.MODetailID,
  2333. 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,
  2334. 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,
  2335. sum(Flag) as Flag
  2336. from (
  2337. select a.MODetailID ,
  2338. case when SUBSTRING(b.ClassCode, 1, 2) IN ('01','04','05') then a.Quantity else 0 end PSLYL,
  2339. case when SUBSTRING(b.ClassCode, 1, 2) IN ('01','04','05') then a.IssueQuantity else 0 end PSLLSS,
  2340. case when SUBSTRING(b.ClassCode, 1, 2) IN ('03') then a.Quantity else 0 end MLYL,
  2341. case when SUBSTRING(b.ClassCode, 1, 2) IN ('03') then a.IssueQuantity else 0 end MLLSS,
  2342. case when SUBSTRING(b.ClassCode, 1, 2) IN ('03') then 1 else 0 end Flag
  2343. from dbo.ICSMOPick a
  2344. inner join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  2345. where a.EATTRIBUTE1 <> '1')a
  2346. left join Sys_SRM_ItemsDetail flag on flag.F_ItemCode='GDCS0001'
  2347. group by MODetailID )a
  2348. ) h on d.MODetailID=h.MODetailID
  2349. left join ICSExtension e on d.ExtensionID=e.ID and a.WorkPoint=e.WorkPoint
  2350. WHERE 1=1 AND a.LotNo='{0}' AND a.WorkPoint='{1}'
  2351. END
  2352. ELSE
  2353. BEGIN
  2354. RAISERROR(' {0} ',16,1);
  2355. END
  2356. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2357. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2358. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  2359. INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
  2360. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2361. AND @QtyBeyond<d.IssueQuantity)
  2362. BEGIN
  2363. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  2364. END
  2365. ";
  2366. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2367. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2368. {
  2369. throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
  2370. }
  2371. }
  2372. catch (Exception)
  2373. {
  2374. throw;
  2375. }
  2376. }
  2377. /// <summary>
  2378. /// 副产品入库接口
  2379. /// </summary>
  2380. /// <param name="TransType"></param>
  2381. /// <param name="Identification"></param>
  2382. /// <param name="cmd"></param>
  2383. public static void MOStockINByProductDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2384. {
  2385. try
  2386. {
  2387. #region ERP
  2388. string sql = @"SELECT ISNULL(c.DepCode,'')+a.ToWarehouseCode+c.MOCode+a.MUSER AS Costre,
  2389. c.DepCode,a.ToWarehouseCode AS WarehouseCode,c.MOCode,a.MUSER,mopick.Sequence,lot.EATTRIBUTE2,
  2390. 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
  2391. ,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END AS ProjectCode,
  2392. 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,
  2393. CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END AS Version,
  2394. CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END AS Brand,
  2395. CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END AS cFree1,
  2396. CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END AS cFree2,
  2397. CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END AS cFree3,
  2398. CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END AS cFree4,
  2399. CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END AS cFree5,
  2400. CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END AS cFree6,
  2401. CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END AS cFree7,
  2402. CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END AS cFree8,
  2403. CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END AS cFree9,
  2404. CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS cFree10,
  2405. conv.Enable AS CompleteVerification,a.TransSequence
  2406. INTO #TempERP
  2407. FROM ICSWareHouseLotInfoLog a
  2408. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2409. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2410. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2411. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2412. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2413. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  2414. INNER JOIN ICSMOPick mopick ON mopick.MODetailID=c.MODetailID AND b.TransSequence=c.Sequence+'~'+mopick.Sequence AND mopick.WorkPoint=c.WorkPoint
  2415. INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
  2416. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2417. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  2418. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  2419. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose001'
  2420. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  2421. GROUP BY inv.AmountEnable,c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,mopick.PickID,con.Enable,conv.Enable,conStock.Enable,conStocknew.Enable
  2422. ,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END,c.MODetailID,mopick.Sequence,lot.EATTRIBUTE2,
  2423. CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,
  2424. CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END,
  2425. CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END,
  2426. CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END,
  2427. CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END,
  2428. CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END,
  2429. CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END,
  2430. CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END,
  2431. CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END,
  2432. CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END,
  2433. CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END,
  2434. CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END,
  2435. CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END,a.TransSequence
  2436. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,'false' AS CompleteVerification,UpdateStock,IsFillClose FROM #TempERP
  2437. 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
  2438. FROM #TempERP
  2439. DROP TABLE #TempERP";
  2440. sql = string.Format(sql, Identification, BusinessCode);
  2441. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2442. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2443. string resultStr = "";
  2444. if (DBHelper.IsU9())
  2445. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOStockINByProductDocURL, Inputstr); }
  2446. else { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOStockINByProductDocURL, Inputstr); }
  2447. Result result = new Result();
  2448. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2449. if (result.Success)
  2450. {
  2451. //try
  2452. //{
  2453. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2454. // foreach (var item in res)
  2455. // {
  2456. // JObject jo = (JObject)item;
  2457. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2458. // foreach (var detail in resdetail)
  2459. // {
  2460. // JObject det = (JObject)detail;
  2461. // 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()
  2462. // + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2463. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  2464. // det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2465. // if (det["detailss"] != null)
  2466. // {
  2467. // JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  2468. // foreach (var details in resdetails)
  2469. // {
  2470. // JObject dets = (JObject)details;
  2471. // if (dets != null)
  2472. // {
  2473. // //直接回写
  2474. // string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2475. // FROM ICSWareHouseLotInfoLog a
  2476. // LEFT JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  2477. // LEFT JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'-'+c.Sequence
  2478. // WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{6}'";
  2479. // ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString()
  2480. // , dets["Sequence"].ToString(), BusinessCode);
  2481. // if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  2482. // {
  2483. // throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"成品倒冲回写失败!";
  2484. // }
  2485. // }
  2486. // }
  2487. // }
  2488. // }
  2489. // }
  2490. //}
  2491. //catch (Exception ex)
  2492. //{
  2493. // log.Debug(ex.ToString());
  2494. // log.Debug(resultStr);
  2495. // throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  2496. //}
  2497. }
  2498. else
  2499. {
  2500. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2501. }
  2502. #endregion
  2503. }
  2504. catch (Exception)
  2505. {
  2506. throw;
  2507. }
  2508. }
  2509. /// <summary>
  2510. /// 委外副产品入库接口
  2511. /// </summary>
  2512. /// <param name="TransType"></param>
  2513. /// <param name="Identification"></param>
  2514. /// <param name="cmd"></param>
  2515. public static void OOStockINByProductDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2516. {
  2517. try
  2518. {
  2519. #region ERP
  2520. string sql = @"SELECT ISNULL(c.DepCode,'')+a.ToWarehouseCode+c.OOCode+a.MUSER AS Costre,c.VenCode,
  2521. c.DepCode,a.ToWarehouseCode AS WarehouseCode,c.OOCode,a.MUSER,mopick.Sequence,lot.EATTRIBUTE2,
  2522. 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
  2523. ,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END AS ProjectCode,
  2524. 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,
  2525. CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END AS Version,
  2526. CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END AS Brand,
  2527. CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END AS cFree1,
  2528. CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END AS cFree2,
  2529. CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END AS cFree3,
  2530. CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END AS cFree4,
  2531. CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END AS cFree5,
  2532. CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END AS cFree6,
  2533. CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END AS cFree7,
  2534. CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END AS cFree8,
  2535. CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END AS cFree9,
  2536. CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS cFree10,
  2537. conv.Enable AS CompleteVerification,a.TransSequence
  2538. INTO #TempERP
  2539. FROM ICSWareHouseLotInfoLog a
  2540. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2541. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2542. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2543. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2544. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2545. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.WorkPoint=c.WorkPoint
  2546. INNER JOIN ICSOOPick mopick ON mopick.OODetailID=c.OODetailID AND b.TransSequence=c.Sequence+'~'+mopick.Sequence AND mopick.WorkPoint=c.WorkPoint
  2547. INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
  2548. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2549. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  2550. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  2551. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose001'
  2552. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  2553. 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
  2554. ,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END,c.OODetailID,mopick.Sequence,lot.EATTRIBUTE2,
  2555. CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,
  2556. CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END,
  2557. CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END,
  2558. CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END,
  2559. CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END,
  2560. CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END,
  2561. CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END,
  2562. CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END,
  2563. CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END,
  2564. CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END,
  2565. CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END,
  2566. CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END,
  2567. CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END,a.TransSequence
  2568. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,VenCode,OOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,'false' AS CompleteVerification,UpdateStock,IsFillClose FROM #TempERP
  2569. 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
  2570. FROM #TempERP
  2571. DROP TABLE #TempERP";
  2572. sql = string.Format(sql, Identification, BusinessCode);
  2573. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2574. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2575. string resultStr = "";
  2576. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOStockINByProductDocURL, Inputstr);
  2577. Result result = new Result();
  2578. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2579. if (result.Success)
  2580. {
  2581. //try
  2582. //{
  2583. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2584. // foreach (var item in res)
  2585. // {
  2586. // JObject jo = (JObject)item;
  2587. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2588. // foreach (var detail in resdetail)
  2589. // {
  2590. // JObject det = (JObject)detail;
  2591. // 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()
  2592. // + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2593. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  2594. // det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2595. // if (det["detailss"] != null)
  2596. // {
  2597. // JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  2598. // foreach (var details in resdetails)
  2599. // {
  2600. // JObject dets = (JObject)details;
  2601. // if (dets != null)
  2602. // {
  2603. // //直接回写
  2604. // string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2605. // FROM ICSWareHouseLotInfoLog a
  2606. // LEFT JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  2607. // LEFT JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'-'+c.Sequence
  2608. // WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{6}'";
  2609. // ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString()
  2610. // , dets["Sequence"].ToString(), BusinessCode);
  2611. // if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  2612. // {
  2613. // throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"成品倒冲回写失败!";
  2614. // }
  2615. // }
  2616. // }
  2617. // }
  2618. // }
  2619. // }
  2620. //}
  2621. //catch (Exception ex)
  2622. //{
  2623. // log.Debug(ex.ToString());
  2624. // log.Debug(resultStr);
  2625. // throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  2626. //}
  2627. }
  2628. else
  2629. {
  2630. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2631. }
  2632. #endregion
  2633. }
  2634. catch (Exception)
  2635. {
  2636. throw;
  2637. }
  2638. }
  2639. /// <summary>
  2640. /// 副产品入库接口
  2641. /// </summary>
  2642. /// <param name="TransType"></param>
  2643. /// <param name="Identification"></param>
  2644. /// <param name="cmd"></param>
  2645. public static void MOStockINByProductNoTransDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2646. {
  2647. try
  2648. {
  2649. #region ERP
  2650. string sql = @"SELECT a.ToWarehouseCode+a.MUSER+a.LotNo AS Costre,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,a.MUSER,a.LotNo) AS Sequence,
  2651. a.ToWarehouseCode AS WarehouseCode,lot.MUSER,
  2652. 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
  2653. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,
  2654. 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,
  2655. ISNULL(ext.Version, '') AS Version,
  2656. ISNULL(ext.Brand, '') AS Brand,
  2657. ISNULL(ext.cFree1, '') AS cFree1,
  2658. ISNULL(ext.cFree2, '') AS cFree2,
  2659. ISNULL(ext.cFree3, '') AS cFree3,
  2660. ISNULL(ext.cFree4, '') AS cFree4,
  2661. ISNULL(ext.cFree5, '') AS cFree5,
  2662. ISNULL(ext.cFree6, '') AS cFree6,
  2663. ISNULL(ext.cFree7, '') AS cFree7,
  2664. ISNULL(ext.cFree8, '') AS cFree8,
  2665. ISNULL(ext.cFree9, '') AS cFree9,
  2666. ISNULL(ext.cFree10, '') AS cFree10,
  2667. conv.Enable AS CompleteVerification
  2668. INTO #TempERP
  2669. FROM ICSWareHouseLotInfoLog a
  2670. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2671. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2672. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2673. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2674. LEFT JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2675. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2676. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
  2677. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  2678. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose001'
  2679. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  2680. GROUP BY a.LotNo,inv.AmountEnable,a.ToWarehouseCode,lot.MUSER,a.InvCode,con.Enable,conv.Enable,conStock.Enable,conStocknew.Enable
  2681. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') ,
  2682. CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,
  2683. ISNULL(ext.Version, '') ,
  2684. ISNULL(ext.Brand, '') ,
  2685. ISNULL(ext.cFree1, '') ,
  2686. ISNULL(ext.cFree2, '') ,
  2687. ISNULL(ext.cFree3, ''),
  2688. ISNULL(ext.cFree4, ''),
  2689. ISNULL(ext.cFree5, ''),
  2690. ISNULL(ext.cFree6, ''),
  2691. ISNULL(ext.cFree7, ''),
  2692. ISNULL(ext.cFree8, ''),
  2693. ISNULL(ext.cFree9, ''),
  2694. ISNULL(ext.cFree10, '')
  2695. SELECT DISTINCT Costre,Sequence,WorkPoint,WarehouseCode AS WHCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,'false' AS CompleteVerification,UpdateStock,IsFillClose
  2696. ,InvCode,Quantity,Amount,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  2697. --SELECT Costre,TransSequence,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  2698. --FROM #TempERP
  2699. DROP TABLE #TempERP";
  2700. sql = string.Format(sql, Identification, BusinessCode);
  2701. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2702. string Inputstr = JsonConvert.SerializeObject(dt);
  2703. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOStockINByProductNoTransDocURL, Inputstr);
  2704. Result result = new Result();
  2705. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2706. if (result.Success)
  2707. {
  2708. //try
  2709. //{
  2710. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2711. // foreach (var item in res)
  2712. // {
  2713. // JObject jo = (JObject)item;
  2714. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2715. // foreach (var detail in resdetail)
  2716. // {
  2717. // JObject det = (JObject)detail;
  2718. // 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()
  2719. // + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2720. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  2721. // det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2722. // if (det["detailss"] != null)
  2723. // {
  2724. // JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  2725. // foreach (var details in resdetails)
  2726. // {
  2727. // JObject dets = (JObject)details;
  2728. // if (dets != null)
  2729. // {
  2730. // //直接回写
  2731. // string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2732. // FROM ICSWareHouseLotInfoLog a
  2733. // LEFT JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
  2734. // LEFT JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'-'+c.Sequence
  2735. // WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{6}'";
  2736. // ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString()
  2737. // , dets["Sequence"].ToString(), BusinessCode);
  2738. // if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  2739. // {
  2740. // throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"成品倒冲回写失败!";
  2741. // }
  2742. // }
  2743. // }
  2744. // }
  2745. // }
  2746. // }
  2747. //}
  2748. //catch (Exception ex)
  2749. //{
  2750. // log.Debug(ex.ToString());
  2751. // log.Debug(resultStr);
  2752. // throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  2753. //}
  2754. }
  2755. else
  2756. {
  2757. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2758. }
  2759. #endregion
  2760. }
  2761. catch (Exception)
  2762. {
  2763. throw;
  2764. }
  2765. }
  2766. #endregion
  2767. #region 开立的生产入库单
  2768. /// <summary>
  2769. /// 开立的生产入库单
  2770. /// </summary>
  2771. /// <param name="TransCode"></param>
  2772. /// <param name="TransSequence"></param>
  2773. /// <param name="Quantity"></param>
  2774. /// <param name="WorkPoint"></param>
  2775. /// <param name="cmd"></param>
  2776. public static void ManufactureReceive(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2777. {
  2778. try
  2779. {
  2780. string sql = @"DECLARE @Status VARCHAR(10)
  2781. SELECT @Status=c.Status FROM ICSInventoryLot a
  2782. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2783. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2784. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  2785. IF (@Status IS NULL)
  2786. BEGIN
  2787. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2788. RETURN
  2789. END
  2790. ELSE IF (@Status!='1')
  2791. BEGIN
  2792. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  2793. RETURN
  2794. END
  2795. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  2796. FROM ICSInventoryLot a
  2797. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2798. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2799. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  2800. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2801. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2802. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2803. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1' --AND c.Quantity<c.RCVQuantity
  2804. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn013', c.Quantity,1,2,'')<c.RCVQuantity
  2805. )
  2806. BEGIN
  2807. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  2808. END";
  2809. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2810. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2811. {
  2812. throw new Exception(language.GetNameByCode("WMSAPIInfo138"));//"生产入库单更新失败!");
  2813. }
  2814. }
  2815. catch (Exception)
  2816. {
  2817. throw;
  2818. }
  2819. }
  2820. /// <summary>
  2821. /// 开立的生产入库单
  2822. /// </summary>
  2823. /// <param name="TransType"></param>
  2824. /// <param name="Identification"></param>
  2825. /// <param name="cmd"></param>
  2826. public static DataTable ManufactureReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2827. {
  2828. try
  2829. {
  2830. string checklotno = "";
  2831. // string checksql = @"SELECT c.rcvcode,a.lotno FROM ICSInventoryLot a
  2832. //INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2833. //INNER JOIN (select RCVCode,Sequence,WorkPoint FROM ICSManufactureReceive) c ON b.TransCode=c.RCVCode
  2834. //AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2835. //WHERE c.rcvcode in (select TransCode from ICSWareHouseLotInfoLog
  2836. //where Identification='{0}' )
  2837. //and a.lotno NOT IN (select LotNo from ICSWareHouseLotInfoLog where Identification='{0}' )";
  2838. // checksql = string.Format(checksql, Identification);
  2839. // DataTable dtt = DBHelper.SQlReturnData(checksql, cmd);
  2840. // if (dtt.Rows.Count > 1)
  2841. // {
  2842. // // 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
  2843. // foreach (DataRow row in dtt.Rows)
  2844. // {
  2845. // checklotno += row["lotno"].ToString() + ",";
  2846. // }
  2847. // checklotno = checklotno.TrimEnd(','); // 去除最后一个逗号
  2848. // }
  2849. // else if (dtt.Rows.Count == 1)
  2850. // {
  2851. // // 如果dtt的行数等于1,直接将lotno赋值给checklotno
  2852. // checklotno = dtt.Rows[0]["lotno"].ToString();
  2853. // }
  2854. string checkrcvcode = "";
  2855. //string checknewsql = @"SELECT distinct c.rcvcode FROM ICSInventoryLot a
  2856. //INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2857. //INNER JOIN (select RCVCode,Sequence,WorkPoint FROM ICSManufactureReceive) c ON b.TransCode=c.RCVCode
  2858. //AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2859. //WHERE c.rcvcode in (select TransCode from ICSWareHouseLotInfoLog
  2860. //where Identification='{0}' )
  2861. //and a.lotno NOT IN (select LotNo from ICSWareHouseLotInfoLog where Identification='{0}' )";
  2862. //checknewsql = string.Format(checknewsql, Identification);
  2863. //DataTable dttnew = DBHelper.SQlReturnData(checknewsql, cmd);
  2864. //if (dttnew.Rows.Count > 1)
  2865. //{
  2866. // // 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
  2867. // foreach (DataRow row in dttnew.Rows)
  2868. // {
  2869. // checkrcvcode += row["rcvcode"].ToString() + ",";
  2870. // }
  2871. // checkrcvcode = checkrcvcode.TrimEnd(','); // 去除最后一个逗号
  2872. //}
  2873. //else if (dttnew.Rows.Count == 1)
  2874. //{
  2875. // // 如果dtt的行数等于1,直接将lotno赋值给checklotno
  2876. // checkrcvcode = dttnew.Rows[0]["rcvcode"].ToString();
  2877. //}
  2878. #region ERP开立状态单据审核
  2879. string checkksql = @"SELECT c.rcvcode,a.lotno FROM ICSInventoryLot a
  2880. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2881. INNER JOIN (select rcvcode,Sequence,WorkPoint FROM ICSManufactureReceive) c ON b.TransCode=c.rcvcode
  2882. AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2883. left join ICSWareHouseLotInfo d on a.lotno=d.lotno and a.WorkPoint=d.WorkPoint
  2884. WHERE c.rcvcode in (select TransCode from ICSWareHouseLotInfoLog
  2885. where Identification='{0}' )
  2886. and d.lotno is null";
  2887. checkksql = string.Format(checkksql, Identification);
  2888. DataTable dtt = DBHelper.SQlReturnData(checkksql, cmd);
  2889. if (dtt.Rows.Count > 1)
  2890. {
  2891. // 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中1111111111111111111
  2892. foreach (DataRow row in dtt.Rows)
  2893. {
  2894. checklotno += row["lotno"].ToString() + ",";
  2895. }
  2896. checklotno = checklotno.TrimEnd(','); // 去除最后一个逗号
  2897. }
  2898. else if (dtt.Rows.Count == 1)
  2899. {
  2900. // 如果dtt的行数等于1,直接将lotno赋值给checklotno
  2901. checklotno = dtt.Rows[0]["lotno"].ToString();
  2902. }
  2903. string sql = string.Empty;
  2904. string ccsql = @"SELECT a.F_Id
  2905. FROM Sys_SRM_ItemsDetail a
  2906. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  2907. WHERE b.F_EnCode='BatchInOutErp' AND a.F_ItemCode='BatchIn' AND a.F_EnabledMark='1'";
  2908. ccsql = string.Format(ccsql);
  2909. DataTable dtdao = DBHelper.SQlReturnData(ccsql, cmd);
  2910. if (dtdao.Rows.Count > 0 && dtdao != null)
  2911. {
  2912. #region 原逻辑
  2913. // string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.RcvQuantity) AS ISSQty,a.transCode from ICSManufactureReceive b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.RCVCode AND a.WorkPoint=b.WorkPoint
  2914. // where a.Identification='{0}' GROUP BY a.transCode";
  2915. // checksql = string.Format(checksql, Identification);
  2916. // DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  2917. // for (int i = 0; i < chekdt.Rows.Count; i++)
  2918. // {
  2919. // decimal SUMQty = Convert.ToDecimal(chekdt.Rows[i]["SUMQty"]);
  2920. // decimal ISSQty = Convert.ToDecimal(chekdt.Rows[i]["ISSQty"]);
  2921. // string trancode = chekdt.Rows[i]["transCode"].ToString();
  2922. // if (SUMQty - ISSQty == 0)
  2923. // {
  2924. // string pnsql = @"
  2925. // select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  2926. // INTO #NewTempERP
  2927. // from ICSWareHouseLotInfoLog
  2928. // WHERE TransCode='{0}' AND ERPUpload='0'
  2929. // SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2930. // FROM #NewTempERP a
  2931. // INNER JOIN ICSManufactureReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2932. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2933. // INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  2934. // GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2935. //DROP TABLE #NewTempERP";
  2936. // pnsql = string.Format(pnsql, trancode);
  2937. // DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  2938. // string Inputstr = JsonConvert.SerializeObject(dt);
  2939. // //U9ICSManufactureReceiveURL
  2940. // string resultStr = "";
  2941. // log.Debug("入库单审核传入参数:" + Inputstr);
  2942. // if (DBHelper.IsU9())
  2943. // {
  2944. // log.Debug("入库单审核URL:" + ERPUrl.U9ICSManufactureReceiveURL);
  2945. // resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9ICSManufactureReceiveURL, Inputstr);
  2946. // }
  2947. // else
  2948. // resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSManufactureReceiveURL, Inputstr);
  2949. // Result result = new Result();
  2950. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  2951. // if (result.Success)
  2952. // {
  2953. // try
  2954. // {
  2955. // foreach (DataRow dr in dt.Rows)
  2956. // {
  2957. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2958. // }
  2959. // }
  2960. // catch (Exception ex)
  2961. // {
  2962. // log.Debug(ex.ToString());
  2963. // log.Debug(resultStr);
  2964. // }
  2965. // }
  2966. // else
  2967. // {
  2968. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2969. // }
  2970. // }
  2971. // }
  2972. #endregion
  2973. string pnsql = @"
  2974. select DISTINCT a.LotNo,a.WorkPoint,a.InvCode,a.ToWarehouseCode,a.MUSER,a.Quantity,a.TransCode,a.TransSequence
  2975. INTO #NewTempERP
  2976. from ICSWareHouseLotInfoLog a
  2977. inner join ICSManufactureReceive b ON a.TransCode=b.RCVCode AND a.WorkPoint=b.WorkPoint
  2978. where a.Identification='{0}' AND ERPUpload='0'
  2979. GROUP BY a.LotNo,a.WorkPoint,a.InvCode,a.ToWarehouseCode,a.MUSER,a.Quantity,a.TransCode,a.TransSequence
  2980. HAVING SUM(b.Quantity)=SUM(b.RcvQuantity)
  2981. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2982. FROM #NewTempERP a
  2983. INNER JOIN ICSManufactureReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2984. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2985. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  2986. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2987. DROP TABLE #NewTempERP
  2988. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2989. FROM #NewTempERP a
  2990. INNER JOIN ICSManufactureReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2991. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2992. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  2993. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2994. DROP TABLE #NewTempERP";
  2995. pnsql = string.Format(pnsql, Identification);
  2996. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  2997. if (dt.Rows.Count>0&&dt!=null)
  2998. {
  2999. string Inputstr = JsonConvert.SerializeObject(dt);
  3000. //U9ICSManufactureReceiveURL
  3001. string resultStr = "";
  3002. log.Debug("入库单审核传入参数:" + Inputstr);
  3003. if (DBHelper.IsU9())
  3004. {
  3005. log.Debug("入库单审核URL:" + ERPUrl.U9ICSManufactureReceiveURL);
  3006. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9ICSManufactureReceiveURL, Inputstr);
  3007. }
  3008. else
  3009. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSManufactureReceiveURL, Inputstr);
  3010. Result result = new Result();
  3011. result = JsonConvert.DeserializeObject<Result>(resultStr);
  3012. if (result.Success)
  3013. {
  3014. try
  3015. {
  3016. foreach (DataRow dr in dt.Rows)
  3017. {
  3018. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  3019. }
  3020. }
  3021. catch (Exception ex)
  3022. {
  3023. log.Debug(ex.ToString());
  3024. log.Debug(resultStr);
  3025. }
  3026. }
  3027. else
  3028. {
  3029. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  3030. }
  3031. }
  3032. }
  3033. else
  3034. {
  3035. sql = @"DECLARE @quantity DECIMAL(38,4);
  3036. DECLARE @rcvquantity DECIMAL(38,4);
  3037. SELECT @quantity=SUM(Quantity),@rcvquantity=SUM(RCVQuantity) FROM ICSManufactureReceive b
  3038. WHERE b.RCVCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  3039. IF (@quantity<>@rcvquantity)
  3040. BEGIN
  3041. RAISERROR('" + language.GetNameByCode("WMSAPIInfo096") + @"',16,1);
  3042. RETURN
  3043. END
  3044. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  3045. INTO #NewTempERP
  3046. from ICSWareHouseLotInfoLog
  3047. WHERE Identification='{0}' AND ERPUpload='0'
  3048. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  3049. FROM #NewTempERP a
  3050. INNER JOIN ICSManufactureReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  3051. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  3052. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  3053. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  3054. DROP TABLE #NewTempERP";
  3055. sql = string.Format(sql, Identification, checklotno, checkrcvcode);
  3056. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3057. string Inputstr = JsonConvert.SerializeObject(dt);
  3058. //U9ICSManufactureReceiveURL
  3059. string resultStr = "";
  3060. log.Debug("入库单审核传入参数:" + Inputstr);
  3061. if (DBHelper.IsU9())
  3062. {
  3063. log.Debug("入库单审核URL:" + ERPUrl.U9ICSManufactureReceiveURL);
  3064. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9ICSManufactureReceiveURL, Inputstr);
  3065. }
  3066. else
  3067. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSManufactureReceiveURL, Inputstr);
  3068. Result result = new Result();
  3069. result = JsonConvert.DeserializeObject<Result>(resultStr);
  3070. if (result.Success)
  3071. {
  3072. try
  3073. {
  3074. foreach (DataRow dr in dt.Rows)
  3075. {
  3076. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  3077. }
  3078. }
  3079. catch (Exception ex)
  3080. {
  3081. log.Debug(ex.ToString());
  3082. log.Debug(resultStr);
  3083. }
  3084. }
  3085. else
  3086. {
  3087. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  3088. }
  3089. }
  3090. #endregion
  3091. DataTable chekdtt = new DataTable();
  3092. chekdtt.Columns.Add("checklotno", typeof(string));
  3093. DataRow newrow = chekdtt.NewRow();
  3094. newrow["checklotno"] = checklotno;
  3095. chekdtt.Rows.Add(newrow);
  3096. string aaaa = JsonConvert.SerializeObject(chekdtt);
  3097. return chekdtt;
  3098. }
  3099. catch (Exception)
  3100. {
  3101. throw;
  3102. }
  3103. }
  3104. #endregion
  3105. #region 产成品入库单(咖博士)
  3106. /// <summary>
  3107. /// 更新产成品入库单
  3108. /// </summary>
  3109. /// <param name="LotNo"></param>
  3110. /// <param name="Quantity"></param>
  3111. /// <param name="WorkPoint"></param>
  3112. /// <param name="cmd"></param>
  3113. /// <param name="language"></param>
  3114. public static void ManufactureMESReceive(string LotNo, string Quantity, string WorkPoint, string TransCode, SqlCommand cmd, Dictionary<string, string> language)
  3115. {
  3116. try
  3117. {
  3118. string sql = @"DECLARE @Status VARCHAR(10)
  3119. SELECT @Status=c.Status FROM ICSInventoryLot a
  3120. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3121. INNER JOIN ICSMO mo ON mo.MOCode=b.TransCode AND mo.Sequence=b.TransSequence AND mo.WorkPoint=b.WorkPoint
  3122. INNER JOIN ICSManufactureReceive c ON c.SourceCode=mo.MOCode AND c.SourceSequence=mo.Sequence AND c.WorkPoint=mo.WorkPoint
  3123. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
  3124. IF (@Status IS NULL)
  3125. BEGIN
  3126. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  3127. RETURN
  3128. END
  3129. ELSE IF (@Status!='1')
  3130. BEGIN
  3131. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  3132. RETURN
  3133. END
  3134. UPDATE c SET c.RCVQuantity=ISNULL(c.RCVQuantity,0)+'{2}'
  3135. FROM ICSInventoryLot a
  3136. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3137. INNER JOIN ICSMO mo ON mo.MOCode=b.TransCode AND mo.Sequence=b.TransSequence AND mo.WorkPoint=b.WorkPoint
  3138. INNER JOIN ICSManufactureReceive c ON c.SourceCode=mo.MOCode AND c.SourceSequence=mo.Sequence AND c.WorkPoint=mo.WorkPoint
  3139. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1' AND c.RCVCode='{3}'
  3140. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  3141. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3142. INNER JOIN ICSMO mo ON mo.MOCode=b.TransCode AND mo.Sequence=b.TransSequence AND mo.WorkPoint=b.WorkPoint
  3143. INNER JOIN ICSManufactureReceive c ON c.SourceCode=mo.MOCode AND c.SourceSequence=mo.Sequence AND c.WorkPoint=mo.WorkPoint
  3144. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1' AND c.RCVCode='{3}'
  3145. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn013', c.Quantity,1,2,'')<c.RCVQuantity)
  3146. BEGIN
  3147. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  3148. END";
  3149. sql = string.Format(sql, LotNo, WorkPoint, Quantity, TransCode);
  3150. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3151. {
  3152. throw new Exception(language.GetNameByCode("WMSAPIInfo138"));//"生产入库单更新失败!");
  3153. }
  3154. }
  3155. catch (Exception)
  3156. {
  3157. throw;
  3158. }
  3159. }
  3160. /// <summary>
  3161. /// 完工报告单入库调用ERP接口
  3162. /// </summary>
  3163. /// <param name="TransType"></param>
  3164. /// <param name="Identification"></param>
  3165. /// <param name="cmd"></param>
  3166. /// <param name="language"></param>
  3167. /// <param name="BusinessCode"></param>
  3168. public static void ManufactureMESReceiveERP(string TransType, string Identification, string TransCode, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  3169. {
  3170. try
  3171. {
  3172. string checklotno = "";
  3173. string checksql = @"SELECT c.rcvcode,a.lotno FROM ICSInventoryLot a
  3174. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3175. INNER JOIN (select RCVCode,Sequence,WorkPoint FROM ICSManufactureReceive) c ON b.TransCode=c.RCVCode
  3176. AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  3177. left join ICSWareHouseLotInfo d on a.lotno=d.lotno and a.WorkPoint=d.WorkPoint
  3178. WHERE c.rcvcode in (select TransCode from ICSWareHouseLotInfoLog
  3179. where Identification='{0}' )
  3180. and d.lotno is null";
  3181. checksql = string.Format(checksql, Identification);
  3182. DataTable dtt = DBHelper.SQlReturnData(checksql, cmd);
  3183. if (dtt.Rows.Count > 1)
  3184. {
  3185. // 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
  3186. foreach (DataRow row in dtt.Rows)
  3187. {
  3188. checklotno += row["lotno"].ToString() + ",";
  3189. }
  3190. checklotno = checklotno.TrimEnd(','); // 去除最后一个逗号
  3191. }
  3192. else if (dtt.Rows.Count == 1)
  3193. {
  3194. // 如果dtt的行数等于1,直接将lotno赋值给checklotno
  3195. checklotno = dtt.Rows[0]["lotno"].ToString();
  3196. }
  3197. string checkrcvcode = "";
  3198. string checknewsql = @"SELECT distinct c.rcvcode FROM ICSInventoryLot a
  3199. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3200. INNER JOIN (select RCVCode,Sequence,WorkPoint FROM ICSManufactureReceive) c ON b.TransCode=c.RCVCode
  3201. AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  3202. left join ICSWareHouseLotInfo d on a.lotno=d.lotno and a.WorkPoint=d.WorkPoint
  3203. WHERE c.rcvcode in (select TransCode from ICSWareHouseLotInfoLog
  3204. where Identification='{0}' )
  3205. and d.lotno is null";
  3206. checknewsql = string.Format(checknewsql, Identification);
  3207. DataTable dttnew = DBHelper.SQlReturnData(checknewsql, cmd);
  3208. if (dttnew.Rows.Count > 1)
  3209. {
  3210. // 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
  3211. foreach (DataRow row in dttnew.Rows)
  3212. {
  3213. checkrcvcode += row["rcvcode"].ToString() + ",";
  3214. }
  3215. checkrcvcode = checkrcvcode.TrimEnd(','); // 去除最后一个逗号
  3216. }
  3217. else if (dttnew.Rows.Count == 1)
  3218. {
  3219. // 如果dtt的行数等于1,直接将lotno赋值给checklotno
  3220. checkrcvcode = dttnew.Rows[0]["rcvcode"].ToString();
  3221. }
  3222. #region 完工报告单入库创建ERP成品入库单
  3223. string sql = @"DECLARE @quantity DECIMAL(38,4);
  3224. DECLARE @rcvquantity DECIMAL(38,4);
  3225. SELECT @quantity=SUM(Quantity),@rcvquantity=SUM(RCVQuantity) FROM ICSManufactureReceive b
  3226. WHERE b.RCVCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  3227. IF (@quantity<>@rcvquantity)
  3228. BEGIN
  3229. RAISERROR('" + language.GetNameByCode("WMSAPIInfo096") + @"',16,1);
  3230. RETURN
  3231. END
  3232. select a.WorkPoint,a.ToWarehouseCode,b.RCVID,b.RCVDetailID,a.MUSER,GETDATE() AS MTIME,a.InvCode,a.Quantity,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,mo.Amount,mo.MODetailID,b.RCVID+a.WorkPoint AS Costre
  3233. INTO #NewTempERP
  3234. from ICSWareHouseLotInfoLog a
  3235. INNER JOIN ICSMO mo ON mo.MOCode=a.TransCode AND mo.Sequence=a.TransSequence AND mo.WorkPoint=a.WorkPoint
  3236. INNER JOIN ICSManufactureReceive b ON b.SourceCode=mo.MOCode AND b.Sequence=mo.Sequence AND b.WorkPoint=mo.WorkPoint AND b.RCVCode='{3}'
  3237. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  3238. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
  3239. WHERE a.Identification='{0}' AND a.ERPUpload='0'
  3240. SELECT DISTINCT Costre,WorkPoint,ToWarehouseCode AS WHCode,RCVID AS MOCode,MUSER AS [User],MTime,UpdateStock,UpdateTodoQuantity FROM #NewTempERP
  3241. SELECT Costre,RCVDetailID AS Sequence,InvCode,SUM(Quantity) AS Quantity,Amount,RCVDetailID AS MODetailID FROM #NewTempERP
  3242. GROUP BY Costre,RCVDetailID,InvCode,Quantity,Amount,RCVDetailID
  3243. DROP TABLE #NewTempERP";
  3244. sql = string.Format(sql, Identification, checklotno, checkrcvcode, TransCode);
  3245. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  3246. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  3247. log.Debug("完工报告单入库调用ERP接口传参:" + Environment.NewLine + Inputstr);
  3248. string resultStr = "";
  3249. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSManufactureReceiveCreateURL, Inputstr);
  3250. Result result = new Result();
  3251. result = JsonConvert.DeserializeObject<Result>(resultStr);
  3252. if (result.Success)
  3253. {
  3254. try
  3255. {
  3256. foreach (DataRow dr in ds.Tables[0].Rows)
  3257. {
  3258. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  3259. }
  3260. }
  3261. catch (Exception ex)
  3262. {
  3263. log.Debug(ex.ToString());
  3264. log.Debug(resultStr);
  3265. }
  3266. }
  3267. else
  3268. {
  3269. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  3270. }
  3271. #endregion
  3272. }
  3273. catch (Exception)
  3274. {
  3275. throw;
  3276. }
  3277. }
  3278. #endregion
  3279. #region 返工工单
  3280. /// <summary>
  3281. /// 返工工单
  3282. /// </summary>
  3283. /// <param name="TransCode"></param>
  3284. /// <param name="TransSequence"></param>
  3285. /// <param name="Quantity"></param>
  3286. /// <param name="WorkPoint"></param>
  3287. /// <param name="cmd"></param>
  3288. public static void ReWorkReceiveMo(string LotNo, string Quantity, string WarehouseCode,
  3289. string LocationCode, string WorkPoint, String User, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  3290. {
  3291. try
  3292. {
  3293. string sql = @"DECLARE @Status VARCHAR(10)
  3294. SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
  3295. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3296. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  3297. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  3298. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  3299. IF (@Status IS NULL)
  3300. BEGIN
  3301. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  3302. RETURN
  3303. END
  3304. ELSE IF (@Status='3')
  3305. BEGIN
  3306. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  3307. RETURN
  3308. END
  3309. UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  3310. FROM ICSInventoryLot a
  3311. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3312. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  3313. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  3314. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  3315. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  3316. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3317. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  3318. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  3319. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  3320. AND d.IssueQuantity>dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn015', c.Quantity,1,2,''))
  3321. BEGIN
  3322. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  3323. END";
  3324. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  3325. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3326. {
  3327. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));//"生产工单更新失败!");
  3328. }
  3329. }
  3330. catch (Exception)
  3331. {
  3332. throw;
  3333. }
  3334. }
  3335. /// <summary>
  3336. /// 返工工单
  3337. /// </summary>
  3338. /// <param name="TransType"></param>
  3339. /// <param name="Identification"></param>
  3340. /// <param name="cmd"></param>
  3341. public static void ReWorkReceiveMoERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  3342. {
  3343. try
  3344. {
  3345. #region ERP开立状态单据审核
  3346. String sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  3347. INTO #NewTempERP
  3348. from ICSWareHouseLotInfoLog
  3349. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  3350. 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,
  3351. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,d.PickID AS MODetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  3352. ,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,
  3353. 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
  3354. INTO #TempERP
  3355. FROM #NewTempERP a
  3356. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3357. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3358. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3359. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3360. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3361. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  3362. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  3363. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  3364. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock007' AND a.WorkPoint=conStock.WorkPoint
  3365. GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,d.PickID,con.Enable,d.Sequence,conStock.Enable
  3366. ,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, ''),
  3367. 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, '')
  3368. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  3369. SELECT Costre,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  3370. FROM #TempERP
  3371. DROP TABLE #TempERP
  3372. DROP TABLE #NewTempERP";
  3373. sql = string.Format(sql, Identification,BusinessCode);
  3374. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  3375. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  3376. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSReWorkReceiveMoURL, Inputstr);
  3377. Result result = new Result();
  3378. result = JsonConvert.DeserializeObject<Result>(resultStr);
  3379. if (result.Success)
  3380. {
  3381. try
  3382. {
  3383. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  3384. foreach (var item in res)
  3385. {
  3386. JObject jo = (JObject)item;
  3387. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  3388. foreach (var detail in resdetail)
  3389. {
  3390. JObject det = (JObject)detail;
  3391. 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()
  3392. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  3393. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
  3394. det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), col, cmd, language, BusinessCode);
  3395. }
  3396. }
  3397. }
  3398. catch (Exception ex)
  3399. {
  3400. log.Debug(ex.ToString());
  3401. log.Debug(resultStr);
  3402. }
  3403. }
  3404. else
  3405. {
  3406. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  3407. }
  3408. #endregion
  3409. }
  3410. catch (Exception)
  3411. {
  3412. throw;
  3413. }
  3414. }
  3415. #endregion
  3416. }
  3417. }