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.

3676 lines
273 KiB

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