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.

2092 lines
154 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
12 months ago
1 year ago
2 months ago
1 year ago
2 months ago
1 year ago
2 months ago
1 year ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Linq;
  10. using System.Net.Http;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace ICSSoft.DataProject
  14. {
  15. /// <summary>
  16. /// 使用中
  17. /// 委外模块
  18. /// </summary>
  19. public class ICSOutsourcingService
  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 OutsourcingIssueDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string enableCode)
  32. {
  33. try
  34. {
  35. string sql = @"DECLARE @Status VARCHAR(10)
  36. SELECT @Status=b.Status FROM ICSOOPick a
  37. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  38. WHERE b.OOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}'
  39. IF (@Status IS NULL)
  40. BEGIN
  41. RAISERROR('" + language.GetNameByCode("WMSAPIInfo104") + @"',16,1);
  42. RETURN
  43. END
  44. ELSE IF (@Status!='2')
  45. BEGIN
  46. RAISERROR('" + language.GetNameByCode("WMSAPIInfo105") + @"',16,1);
  47. RETURN
  48. END
  49. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  50. FROM ICSOOPick a
  51. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  52. WHERE b.OOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}'
  53. IF EXISTS(SELECT a.ID FROM ICSOOPick a
  54. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  55. WHERE b.OOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' and b.WorkPoint='{1}' AND
  56. dbo.GetExcessQty(a.InvCode, b.Sequence+'~'+a.Sequence, b.OOCode, a.WorkPoint,'{4}')<a.IssueQuantity)
  57. BEGIN
  58. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  59. RETURN
  60. END";
  61. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence,enableCode);
  62. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  63. {
  64. throw new Exception(language.GetNameByCode("WMSAPIInfo107"));
  65. }
  66. }
  67. catch (Exception)
  68. {
  69. throw;
  70. }
  71. }
  72. /// <summary>
  73. /// 委外发料接口
  74. /// </summary>
  75. /// <param name="TransType"></param>
  76. /// <param name="Identification"></param>
  77. /// <param name="cmd"></param>
  78. public static void OutsourcingIssueDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  79. {
  80. try
  81. {
  82. #region ERP
  83. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  84. INTO #NewTempERP
  85. from ICSWareHouseLotInfoLog
  86. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '5'
  87. SELECT isnull(y.DepCode,'') + a.FromWarehouseCode + y.OOCode + a.MUSER AS Costre,
  88. y.DepCode,a.FromWarehouseCode AS WarehouseCode,y.OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.FromWarehouseCode,y.OOCode,x.PickID,a.InvCode) AS Sequence,
  89. 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
  90. ,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,
  91. 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
  92. , x.OODetailID
  93. INTO #TempERP
  94. FROM #NewTempERP a
  95. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  96. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  97. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  98. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  99. INNER JOIN ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint
  100. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  101. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  102. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  103. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  104. GROUP BY inv.AmountEnable,y.DepCode,a.FromWarehouseCode,y.OOCode,a.MUSER,a.InvCode,x.PickID,x.OODetailID,con.Enable,conv.Enable,conStock.Enable
  105. ,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, ''),
  106. 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, '')
  107. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock FROM #TempERP
  108. SELECT Costre,WarehouseCode AS WHCode,Sequence,InvCode,Quantity,Amount,PickID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,OODetailID as SourceLineID FROM #TempERP
  109. DROP TABLE #TempERP
  110. DROP TABLE #NewTempERP";
  111. sql = string.Format(sql, Identification);
  112. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  113. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  114. string resultStr = "";
  115. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["IsU9Api"]))
  116. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OutsourcingIssueDocURL, Inputstr); }
  117. else { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDocURL, Inputstr); }
  118. Result result = new Result();
  119. result = JsonConvert.DeserializeObject<Result>(resultStr);
  120. if (result.Success)
  121. {
  122. try
  123. {
  124. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  125. foreach (var item in res)
  126. {
  127. JObject jo = (JObject)item;
  128. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  129. foreach (var detail in resdetail)
  130. {
  131. JObject det = (JObject)detail;
  132. 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()
  133. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  134. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  135. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol,cmd, language, BusinessCode);
  136. }
  137. }
  138. }
  139. catch (Exception ex)
  140. {
  141. log.Debug(ex.ToString());
  142. log.Debug(resultStr);
  143. }
  144. }
  145. else
  146. {
  147. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  148. }
  149. #endregion
  150. }
  151. catch (Exception)
  152. {
  153. throw;
  154. }
  155. }
  156. #endregion
  157. #region 委外领料申请单生产发料
  158. /// <summary>
  159. /// 委外领料申请单生产发料
  160. /// </summary>
  161. /// <param name="TransCode"></param>
  162. /// <param name="TransSequence"></param>
  163. /// <param name="Quantity"></param>
  164. /// <param name="WorkPoint"></param>
  165. /// <param name="cmd"></param>
  166. public static void OOApply(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string enableCode)
  167. {
  168. try
  169. {
  170. string sql = @"DECLARE @Status VARCHAR(10)
  171. SELECT @Status=a.Status FROM ICSOApply a
  172. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  173. IF (@Status IS NULL)
  174. BEGIN
  175. RAISERROR('" + language.GetNameByCode("WMSAPIInfo108") + @"',16,1);
  176. RETURN
  177. END
  178. ELSE IF (@Status!='2')
  179. BEGIN
  180. RAISERROR('" + language.GetNameByCode("WMSAPIInfo109") + @"',16,1);
  181. RETURN
  182. END
  183. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  184. FROM ICSOApply a
  185. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  186. IF EXISTS(SELECT a.ID FROM ICSOApply a
  187. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND
  188. dbo.GetExcessQty(a.InvCode, a.Sequence, a.ApplyCode, a.WorkPoint,'{4}')<a.IssueQuantity)
  189. BEGIN
  190. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  191. RETURN
  192. END";
  193. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence,enableCode);
  194. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  195. {
  196. throw new Exception(language.GetNameByCode("WMSAPIInfo110"));
  197. }
  198. }
  199. catch (Exception)
  200. {
  201. throw;
  202. }
  203. }
  204. /// <summary>
  205. /// 委外领料申请单生产发料接口
  206. /// </summary>
  207. /// <param name="TransType"></param>
  208. /// <param name="Identification"></param>
  209. /// <param name="cmd"></param>
  210. public static void OOApplyERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  211. {
  212. try
  213. {
  214. #region ERP
  215. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  216. INTO #NewTempERP
  217. from ICSWareHouseLotInfoLog
  218. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '6'
  219. SELECT a.FromWarehouseCode+b.ApplyCode+a.MUSER AS Costre,a.FromWarehouseCode AS WarehouseCode,b.ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.ApplyCode,b.ApplyDetailID,a.InvCode) AS Sequence,
  220. 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
  221. ,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,
  222. 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
  223. INTO #TempERP
  224. FROM #NewTempERP a
  225. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  226. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  227. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  228. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  229. INNER JOIN ICSOApply b ON a.TransCode=b.ApplyCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  230. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  231. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  232. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  233. GROUP BY inv.AmountEnable,a.FromWarehouseCode,b.ApplyCode,a.MUSER,a.InvCode,b.ApplyDetailID,con.Enable,conv.Enable,conStock.Enable
  234. ,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, ''),
  235. 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, '')
  236. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock FROM #TempERP
  237. SELECT Costre,Sequence,InvCode,Quantity,Amount,ApplyDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  238. DROP TABLE #TempERP
  239. DROP TABLE #NewTempERP";
  240. sql = string.Format(sql, Identification);
  241. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  242. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  243. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOApplyURL, Inputstr);
  244. Result result = new Result();
  245. result = JsonConvert.DeserializeObject<Result>(resultStr);
  246. if (result.Success)
  247. {
  248. try
  249. {
  250. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  251. foreach (var item in res)
  252. {
  253. JObject jo = (JObject)item;
  254. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  255. foreach (var detail in resdetail)
  256. {
  257. JObject det = (JObject)detail;
  258. 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()
  259. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  260. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  261. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  262. }
  263. }
  264. }
  265. catch (Exception ex)
  266. {
  267. log.Debug(ex.ToString());
  268. log.Debug(resultStr);
  269. }
  270. }
  271. else
  272. {
  273. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  274. }
  275. #endregion
  276. }
  277. catch (Exception)
  278. {
  279. throw;
  280. }
  281. }
  282. #endregion
  283. #region 委外材料出库单生产发料
  284. /// <summary>
  285. /// 委外材料出库单生产发料
  286. /// </summary>
  287. /// <param name="TransCode"></param>
  288. /// <param name="TransSequence"></param>
  289. /// <param name="Quantity"></param>
  290. /// <param name="WorkPoint"></param>
  291. /// <param name="cmd"></param>
  292. public static void OOIssue(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  293. {
  294. try
  295. {
  296. string sql = @"DECLARE @Status VARCHAR(10)
  297. SELECT @Status=a.Status FROM ICSOIssue a
  298. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  299. IF (@Status IS NULL)
  300. BEGIN
  301. RAISERROR('" + language.GetNameByCode("WMSAPIInfo111") + @"',16,1);
  302. RETURN
  303. END
  304. ELSE IF (@Status!='1')
  305. BEGIN
  306. RAISERROR('" + language.GetNameByCode("WMSAPIInfo112") + @"',16,1);
  307. RETURN
  308. END
  309. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  310. FROM ICSOIssue a
  311. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  312. IF EXISTS(SELECT a.ID FROM ICSOIssue a
  313. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  314. BEGIN
  315. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  316. RETURN
  317. END";
  318. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  319. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  320. {
  321. throw new Exception(language.GetNameByCode("WMSAPIInfo113"));
  322. }
  323. }
  324. catch (Exception)
  325. {
  326. throw;
  327. }
  328. }
  329. /// <summary>
  330. /// 委外材料出库单生产发料接口
  331. /// </summary>
  332. /// <param name="TransType"></param>
  333. /// <param name="Identification"></param>
  334. /// <param name="cmd"></param>
  335. public static void OOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  336. {
  337. try
  338. {
  339. #region ERP开立状态单据审核
  340. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  341. INTO #NewTempERP
  342. from ICSWareHouseLotInfoLog
  343. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '7'
  344. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  345. INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  346. WHERE a.Identification='{0}' AND b.Quantity!=b.IssueQuantity)
  347. BEGIN
  348. RAISERROR('" + language.GetNameByCode("WMSAPIInfo095") + @"',16,1);
  349. RETURN
  350. END
  351. SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  352. FROM #NewTempERP a
  353. INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  354. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  355. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  356. GROUP BY b.IssueID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  357. DROP TABLE #NewTempERP";
  358. sql = string.Format(sql, Identification);
  359. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  360. string Inputstr = JsonConvert.SerializeObject(dt);
  361. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOIssueURL, Inputstr);
  362. Result result = new Result();
  363. result = JsonConvert.DeserializeObject<Result>(resultStr);
  364. if (result.Success)
  365. {
  366. try
  367. {
  368. foreach (DataRow dr in dt.Rows)
  369. {
  370. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  371. }
  372. }
  373. catch (Exception ex)
  374. {
  375. log.Debug(ex.ToString());
  376. log.Debug(resultStr);
  377. }
  378. }
  379. else
  380. {
  381. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  382. }
  383. #endregion
  384. }
  385. catch (Exception)
  386. {
  387. throw;
  388. }
  389. }
  390. #endregion
  391. #region 委外退料
  392. /// <summary>
  393. /// 委外退料
  394. /// </summary>
  395. /// <param name="TransCode"></param>
  396. /// <param name="TransSequence"></param>
  397. /// <param name="Quantity"></param>
  398. /// <param name="WorkPoint"></param>
  399. /// <param name="cmd"></param>
  400. public static void OutsourcingIssueDoNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint, string TransCode, string TransSequence, SqlCommand cmd, Dictionary<string, string> language)
  401. {
  402. try
  403. {
  404. string table = "";
  405. string sql = "";
  406. if (string.IsNullOrWhiteSpace(LogID))
  407. {
  408. string type = "";
  409. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  410. {
  411. table = "INNER JOIN ICSOOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint";
  412. type = "1";
  413. }
  414. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  415. {
  416. table = "INNER JOIN ICSOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
  417. type = "2";
  418. }
  419. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  420. {
  421. table = "INNER JOIN ICSOIssue e ON c.SourceDetailID=e.IssueDetailID AND c.WorkPoint=e.WorkPoint";
  422. type = "3";
  423. }
  424. else
  425. {
  426. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  427. }
  428. #region 新条码
  429. sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  430. FROM ICSInventoryLot a
  431. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  432. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  433. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  434. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  435. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  436. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  437. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  438. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  439. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND c.Quantity<c.IssueNegQuantity)
  440. BEGIN
  441. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  442. END
  443. UPDATE e SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  444. FROM ICSInventoryLot a
  445. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  446. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  447. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  448. {3}
  449. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  450. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  451. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  452. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  453. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  454. {3}
  455. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND e.IssueQuantity<0)
  456. BEGIN
  457. RAISERROR('" + language.GetNameByCode("WMSAPIInfo193") + @"',16,1);
  458. END";
  459. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type);
  460. #endregion
  461. }
  462. else
  463. {
  464. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  465. {
  466. table = @"INNER JOIN ICSOutsourcingOrder b ON a.TransCode=b.OOCode AND a.WorkPoint=b.WorkPoint
  467. INNER JOIN ICSOOPick c ON b.OODetailID = c.OODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
  468. }
  469. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  470. {
  471. table = "INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  472. }
  473. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  474. {
  475. table = "INNER JOIN ICSOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  476. }
  477. else
  478. {
  479. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  480. }
  481. #region 原条码
  482. //sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  483. // FROM ICSWareHouseLotInfoLog a
  484. // {3}
  485. // WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}'
  486. // IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
  487. // {3}
  488. // WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0)
  489. // BEGIN
  490. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo193") + @"',16,1);
  491. // END";
  492. sql = @"IF EXISTS(select * from ICSOApplyNegDetail where Quantity>='{2}' and OApplyNegCode='{5}' and Sequence='{6}')
  493. BEGIN
  494. UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  495. FROM ICSOApplyNegDetail c
  496. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  497. WHERE c.WorkPoint='{1}' and c.OApplyNegCode='{5}' and c.Sequence='{6}'
  498. END";
  499. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID, TransCode, TransSequence);
  500. #endregion
  501. }
  502. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  503. {
  504. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  505. }
  506. }
  507. catch (Exception)
  508. {
  509. throw;
  510. }
  511. }
  512. /// <summary>
  513. /// 委外退料接口
  514. /// </summary>
  515. /// <param name="TransType"></param>
  516. /// <param name="Identification"></param>
  517. /// <param name="cmd"></param>
  518. public static void OutsourcingIssueDoNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  519. {
  520. try
  521. {
  522. #region ERP
  523. string sql = string.Empty;
  524. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  525. {
  526. if (DBHelper.IsU9()) {
  527. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  528. INTO #NewTempERP
  529. from ICSWareHouseLotInfoLog
  530. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  531. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  532. INTO #NewDouTempERP
  533. from ICSWareHouseLotInfoLog
  534. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  535. SELECT y.DepCode+a.ToWarehouseCode+y.OOCode+a.MUSER AS Costre,y.DepCode,a.ToWarehouseCode AS WarehouseCode,y.OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.ToWarehouseCode,y.OOCode,x.PickID,a.InvCode) AS Sequence1,
  536. 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
  537. ,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,
  538. 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,y.Sequence
  539. INTO #TempERP
  540. FROM #NewTempERP a
  541. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  542. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  543. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  544. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  545. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  546. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  547. INNER JOIN ICSOOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
  548. INNER JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  549. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  550. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  551. GROUP BY inv.AmountEnable,y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,x.PickID,con.Enable,conStock.Enable
  552. ,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, ''),
  553. 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, ''),y.Sequence
  554. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  555. SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  556. DROP TABLE #TempERP
  557. DROP TABLE #NewTempERP
  558. DROP TABLE #NewDouTempERP"; }
  559. else { sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  560. INTO #NewTempERP
  561. from ICSWareHouseLotInfoLog
  562. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  563. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  564. INTO #NewDouTempERP
  565. from ICSWareHouseLotInfoLog
  566. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  567. SELECT y.DepCode+a.ToWarehouseCode+y.OOCode+a.MUSER AS Costre,y.DepCode,a.ToWarehouseCode AS WarehouseCode,y.OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.ToWarehouseCode,y.OOCode,x.PickID,a.InvCode) AS Sequence,
  568. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity/inv.EATTRIBUTE1) ELSE '0' END AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  569. ,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,
  570. 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
  571. INTO #TempERP
  572. FROM #NewTempERP a
  573. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  574. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  575. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  576. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  577. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  578. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  579. INNER JOIN ICSOOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
  580. INNER JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  581. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  582. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  583. GROUP BY inv.AmountEnable,y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,x.PickID,con.Enable,conStock.Enable
  584. ,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, ''),
  585. 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, ''),y.Sequence
  586. UNION ALL
  587. SELECT y.DepCode+a.ToWarehouseCode+y.OOCode+a.MUSER AS Costre,y.DepCode,a.ToWarehouseCode AS WarehouseCode,y.OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.ToWarehouseCode,y.OOCode,x.PickID,a.InvCode) AS Sequence,
  588. 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
  589. ,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,
  590. 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
  591. FROM #NewDouTempERP a
  592. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  593. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  594. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  595. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  596. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  597. INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint
  598. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  599. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  600. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  601. GROUP BY inv.AmountEnable,y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,x.PickID,con.Enable,conStock.Enable
  602. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  603. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  604. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  605. SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  606. DROP TABLE #TempERP
  607. DROP TABLE #NewTempERP
  608. DROP TABLE #NewDouTempERP"; }
  609. }
  610. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  611. {
  612. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  613. INTO #NewTempERP
  614. from ICSWareHouseLotInfoLog
  615. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  616. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  617. INTO #NewDouTempERP
  618. from ICSWareHouseLotInfoLog
  619. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  620. 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,
  621. 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,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  622. ,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,
  623. 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
  624. INTO #TempERP
  625. FROM #NewTempERP a
  626. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  627. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  628. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  629. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  630. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  631. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  632. INNER JOIN ICSOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint
  633. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  634. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  635. GROUP BY inv.AmountEnable,a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,z.ApplyDetailID,con.Enable,conStock.Enable
  636. ,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, ''),
  637. 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, '')
  638. UNION ALL
  639. 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,
  640. 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,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  641. ,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,
  642. 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
  643. FROM #NewDouTempERP a
  644. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  645. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  646. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  647. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  648. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  649. INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  650. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  651. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  652. GROUP BY inv.AmountEnable,a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,z.ApplyDetailID,con.Enable,conStock.Enable
  653. ,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, ''),
  654. 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, '')
  655. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  656. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  657. DROP TABLE #TempERP
  658. DROP TABLE #NewTempERP
  659. DROP TABLE #NewDouTempERP";
  660. }
  661. //根据材料出库单查询上游单据,根据上游单据生成红字材料出库
  662. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  663. {
  664. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  665. INTO #NewTempERP
  666. from ICSWareHouseLotInfoLog
  667. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  668. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  669. INTO #NewDouTempERP
  670. from ICSWareHouseLotInfoLog
  671. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  672. IF EXISTS(select * FROM #NewTempERP a
  673. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  674. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  675. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  676. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  677. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  678. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  679. INNER JOIN ICSOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  680. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  681. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  682. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  683. where m.ApplyDetailID<>null and z.ApplyDetailID=null)
  684. BEGIN
  685. RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
  686. RETURN
  687. END
  688. 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.OOCode) AS OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.InvCode) AS Sequence,
  689. 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,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  690. ,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,
  691. 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
  692. INTO #TempERP
  693. FROM #NewTempERP a
  694. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  695. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  696. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  697. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  698. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  699. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  700. INNER JOIN ICSOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  701. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  702. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  703. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  704. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  705. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  706. GROUP BY inv.AmountEnable,ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.MUSER,a.InvCode,m.PickID,m.ApplyDetailID,con.Enable,lot.Amount,lot.Quantity,conStock.Enable
  707. ,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, ''),
  708. 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, '')
  709. UNION ALL
  710. IF EXISTS(select * FROM #NewDouTempERP a
  711. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  712. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  713. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  714. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  715. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  716. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  717. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  718. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  719. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  720. where m.ApplyDetailID<>null and z.ApplyDetailID=null)
  721. BEGIN
  722. RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
  723. RETURN
  724. END
  725. 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.OOCode) AS OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.InvCode) AS Sequence,
  726. 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,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  727. ,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,
  728. 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
  729. FROM #NewDouTempERP a
  730. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  731. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  732. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  733. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  734. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  735. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  736. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  737. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  738. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  739. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  740. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  741. GROUP BY inv.AmountEnable,ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.MUSER,a.InvCode,m.PickID,m.ApplyDetailID,con.Enable,lot.Amount,lot.Quantity,conStock.Enable
  742. ,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, ''),
  743. 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, '')
  744. IF EXISTS(SELECT Costre FROM #TempERP WHERE SourceType='{0}')
  745. BEGIN
  746. RAISERROR('" + language.GetNameByCode("WMSAPIInfo116") + @"',16,1);
  747. END
  748. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  749. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  750. DROP TABLE #TempERP
  751. DROP TABLE #NewTempERP
  752. DROP TABLE #NewDouTempERP";
  753. }
  754. else
  755. {
  756. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  757. }
  758. sql = string.Format(sql, Identification);
  759. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  760. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  761. string resultStr = "";
  762. if (DBHelper.IsU9())
  763. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OutsourcingIssueDoNegativeURL, Inputstr);
  764. else
  765. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDoNegativeURL, Inputstr);
  766. Result result = new Result();
  767. result = JsonConvert.DeserializeObject<Result>(resultStr);
  768. if (result.Success)
  769. {
  770. try
  771. {
  772. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  773. foreach (var item in res)
  774. {
  775. JObject jo = (JObject)item;
  776. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  777. foreach (var detail in resdetail)
  778. {
  779. JObject det = (JObject)detail;
  780. 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()
  781. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  782. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  783. det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  784. }
  785. }
  786. //List<ICSERPReturnIssueNEG> negList = JsonConvert.DeserializeObject<List<ICSERPReturnIssueNEG>>(result.Data.ToString());
  787. //foreach (var neg in negList)
  788. //{
  789. // foreach (var detail in neg.details)
  790. // {
  791. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, detail.SourceDetailID, Identification, neg.ID, detail.DetailID, neg.IssueNEGCode, detail.Sequence, cmd);
  792. // }
  793. //}
  794. }
  795. catch (Exception ex)
  796. {
  797. log.Debug(ex.ToString());
  798. log.Debug(resultStr);
  799. }
  800. }
  801. else
  802. {
  803. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  804. }
  805. #endregion
  806. }
  807. catch (Exception)
  808. {
  809. throw;
  810. }
  811. }
  812. #endregion
  813. #region 委外到货
  814. /// <summary>
  815. /// 委外到货接口
  816. /// </summary>
  817. /// <param name="TransType"></param>
  818. /// <param name="Identification"></param>
  819. /// <param name="cmd"></param>
  820. public static void OutsourcingDeliveryNoticeERP(string ODNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  821. {
  822. try
  823. {
  824. #region ERP
  825. string sql = @"SELECT a.VenCode+a.DepCode+y.OOCode+a.MUSER AS Costre,a.VenCode,a.DepCode,y.OOCode,a.MUSER,a.MTIME,conStock.Enable AS CompleteVerification,
  826. a.Sequence,a.InvCode,a.Quantity,CASE invBat.AmountEnable WHEN '1' THEN a.Amount ELSE '0' END AS Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.OODetailID
  827. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  828. 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
  829. INTO #TempERP
  830. FROM ICSODeliveryNotice a
  831. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  832. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  833. INNER JOIN ICSOutsourcingOrder y ON a.OODetailID=y.OODetailID AND a.WorkPoint=y.WorkPoint
  834. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='CompleteVerification003'
  835. WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}'
  836. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,OOCode,MUSER AS [User],SYSDATETIME() AS MTime,CompleteVerification FROM #TempERP
  837. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,OODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  838. FROM #TempERP
  839. DROP TABLE #TempERP";
  840. sql = string.Format(sql, ODNCode, WorkPoint);
  841. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  842. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  843. string resultStr = HTTPHelper.HttpPost("委外到货", ERPUrl.ODeliveryNoticeURL, Inputstr);
  844. Result result = new Result();
  845. result = JsonConvert.DeserializeObject<Result>(resultStr);
  846. if (result.Success)
  847. {
  848. try
  849. {
  850. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  851. foreach (var item in res)
  852. {
  853. JObject jo = (JObject)item;
  854. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  855. foreach (var detail in resdetail)
  856. {
  857. JObject det = (JObject)detail;
  858. string ERPupdate = @"update ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}'
  859. where OODetailID='{4}' AND ODNType='1' AND ODNCode='{5}' and Sequence='{1}'";
  860. ERPupdate = string.Format(ERPupdate, jo["ODNCode"], det["Sequence"], jo["ID"], det["DetailID"], det["OODetailID"], ODNCode);
  861. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  862. {
  863. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  864. }
  865. }
  866. }
  867. }
  868. catch (Exception ex)
  869. {
  870. log.Debug(ex.ToString());
  871. log.Debug(resultStr);
  872. }
  873. }
  874. else
  875. {
  876. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  877. }
  878. #endregion
  879. }
  880. catch (Exception)
  881. {
  882. throw;
  883. }
  884. }
  885. #endregion
  886. #region 委外入库
  887. /// <summary>
  888. /// 委外入库
  889. /// </summary>
  890. /// <param name="TransCode"></param>
  891. /// <param name="TransSequence"></param>
  892. /// <param name="Quantity"></param>
  893. /// <param name="WorkPoint"></param>
  894. /// <param name="cmd"></param>
  895. public static void OutsourcingReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  896. {
  897. try
  898. {
  899. string sql = @"DECLARE @Status VARCHAR(10)
  900. SELECT @Status=c.Status FROM ICSInventoryLot a
  901. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  902. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  903. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  904. IF (@Status IS NULL)
  905. BEGIN
  906. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  907. RETURN
  908. END
  909. ELSE IF (@Status='3')
  910. BEGIN
  911. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  912. RETURN
  913. END
  914. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  915. FROM ICSInventoryLot a
  916. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  917. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  918. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  919. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  920. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  921. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  922. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.InQuantity)
  923. BEGIN
  924. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  925. END";
  926. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  927. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  928. {
  929. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  930. }
  931. }
  932. catch (Exception)
  933. {
  934. throw;
  935. }
  936. }
  937. /// <summary>
  938. /// 委外入库(奥美)
  939. /// </summary>
  940. /// <param name="LotNo"></param>
  941. /// <param name="Quantity"></param>
  942. /// <param name="WorkPoint"></param>
  943. /// <param name="cmd"></param>
  944. /// <param name="language"></param>
  945. public static void OutsourcingReceiveAMDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  946. {
  947. try
  948. {
  949. string sql = @"DECLARE @Status VARCHAR(10)
  950. SELECT @Status=c.Status FROM ICSInventoryLot a
  951. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  952. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  953. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  954. IF (@Status IS NULL)
  955. BEGIN
  956. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  957. RETURN
  958. END
  959. ELSE IF (@Status='3')
  960. BEGIN
  961. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  962. RETURN
  963. END
  964. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  965. FROM ICSInventoryLot a
  966. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  967. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  968. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  969. --IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  970. -- INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  971. -- INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  972. -- WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.InQuantity)
  973. --BEGIN
  974. -- RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  975. --END";
  976. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  977. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  978. {
  979. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  980. }
  981. }
  982. catch (Exception)
  983. {
  984. throw;
  985. }
  986. }
  987. /// <summary>
  988. /// 委外入库接口
  989. /// </summary>
  990. /// <param name="TransType"></param>
  991. /// <param name="Identification"></param>
  992. /// <param name="cmd"></param>
  993. public static void OutsourcingReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  994. {
  995. try
  996. {
  997. #region ERP
  998. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  999. INTO #NewTempERP
  1000. from ICSWareHouseLotInfoLog
  1001. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1002. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID,TransSequence,TransCode,FromWarehouseCode
  1003. INTO #NewDouTempERP
  1004. from ICSWareHouseLotInfoLog
  1005. WHERE Identification='{0}' AND TransType='13'
  1006. SELECT c.VenCode+a.ToWarehouseCode+c.OOCode+a.MUSER+f.ODNCode AS Costre,c.OODetailID+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, '')+
  1007. ISNULL(ext.cFree1, '')+ISNULL(ext.cFree2, '')+ISNULL(ext.cFree3, '')+ISNULL(ext.cFree4, '')+ISNULL(ext.cFree5, '')+ISNULL(ext.cFree6, '')+ISNULL(ext.cFree7, '')+ISNULL(ext.cFree8, '')+ISNULL(ext.cFree9, '')+ISNULL(ext.cFree10, '') AS Costre2,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.OOCode,c.OOID,f.ODNCode,f.ODNDetailID,a.MUSER,f.Sequence AS ODNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.OOCode,c.OODetailID,a.InvCode) AS Sequence,
  1008. 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,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.OODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose,conStockneww.Enable AS CompleteVerification
  1009. ,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,
  1010. 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,a.TransSequence
  1011. INTO #TempERP
  1012. FROM #NewTempERP a
  1013. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1014. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1015. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1016. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1017. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1018. INNER JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  1019. INNER JOIN ICSODeliveryNotice f ON g.OASNCode=f.OASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  1020. INNER JOIN ICSOutsourcingOrder c ON b.TransCode = c.OOCode
  1021. AND b.TransSequence = c.Sequence
  1022. AND f.OODetailID = c.OODetailID
  1023. AND b.WorkPoint = c.WorkPoint
  1024. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1025. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  1026. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
  1027. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose002'
  1028. INNER JOIN ICSConfiguration conStockneww ON a.WorkPoint=conStockneww.WorkPoint AND conStockneww.Code='CompleteVerification005'
  1029. GROUP BY conStockneww.Enable,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.OOCode,a.MUSER,f.ODNCode,f.ODNDetailID,f.Sequence,a.TransSequence,a.InvCode,c.OOID,c.OODetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable,conStock.Enable,conStocknew.Enable
  1030. ,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, ''),
  1031. 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, '')
  1032. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,OOCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,CompleteVerification,UpdateStock,IsFillClose FROM #TempERP
  1033. SELECT Costre,Costre2,Sequence,ODNSequence,TransSequence,InvCode,Quantity,Amount,OODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1034. FROM #TempERP
  1035. SELECT a.FromWarehouseCode AS WHCode,c.OODetailID+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
  1036. FROM #NewDouTempERP a
  1037. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1038. INNER JOIN ICSOutsourcingOrder b ON b.OOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  1039. INNER JOIN ICSOOPick c ON c.OODetailID=b.OODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  1040. INNER JOIN ICSExtension ext ON ext.ID=c.ExtensionID AND ext.WorkPoint=c.WorkPoint
  1041. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1042. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1043. INNER JOIN #TempERP te ON te.TransSequence=SUBSTRING(a.TransSequence,1,CHARINDEX('~',a.TransSequence)-1)
  1044. GROUP BY a.FromWarehouseCode,c.OODetailID,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, ''),
  1045. 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
  1046. DROP TABLE #TempERP
  1047. DROP TABLE #NewTempERP
  1048. DROP TABLE #NewDouTempERP";
  1049. sql = string.Format(sql, Identification, BusinessCode);
  1050. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1051. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "detailss", "Costre2");
  1052. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocURL, Inputstr);
  1053. Result result = new Result();
  1054. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1055. if (result.Success)
  1056. {
  1057. try
  1058. {
  1059. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1060. foreach (var item in res)
  1061. {
  1062. JObject jo = (JObject)item;
  1063. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1064. foreach (var detail in resdetail)
  1065. {
  1066. JObject det = (JObject)detail;
  1067. 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()
  1068. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1069. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1070. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1071. if (det["detailss"] != null)
  1072. {
  1073. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  1074. foreach (var details in resdetails)
  1075. {
  1076. JObject dets = (JObject)details;
  1077. if (dets != null)
  1078. {
  1079. //直接回写
  1080. string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1081. FROM ICSWareHouseLotInfoLog a
  1082. LEFT JOIN ICSOutsourcingOrder b ON a.TransCode=b.OOCode AND a.WorkPoint=b.WorkPoint
  1083. LEFT JOIN ICSOOPick c ON b.OODetailID=c.OODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  1084. WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode='{6}'";
  1085. ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString()
  1086. , dets["Sequence"].ToString(), BusinessCode);
  1087. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1088. {
  1089. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"委外倒冲回写失败!";
  1090. }
  1091. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, dets["ERPID"].ToString(),
  1092. // dets[" "].ToString(), dets["MRCVCode"].ToString(), dets["Sequence"].ToString(), allcol, cmd, language);
  1093. }
  1094. }
  1095. }
  1096. }
  1097. }
  1098. }
  1099. catch (Exception ex)
  1100. {
  1101. log.Debug(ex.ToString());
  1102. log.Debug(resultStr);
  1103. throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  1104. }
  1105. }
  1106. else
  1107. {
  1108. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1109. }
  1110. #endregion
  1111. }
  1112. catch (Exception)
  1113. {
  1114. throw;
  1115. }
  1116. }
  1117. public static void CreateOOArriveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode, string doctype)
  1118. {
  1119. try
  1120. {
  1121. #region ERP
  1122. string sql = @"
  1123. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1124. INTO #NewTempERP
  1125. from ICSWareHouseLotInfoLog
  1126. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1127. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID,TransSequence,TransCode,FromWarehouseCode
  1128. INTO #NewDouTempERP
  1129. from ICSWareHouseLotInfoLog
  1130. WHERE Identification='{0}' AND TransType='13'
  1131. SELECT c.VenCode+a.ToWarehouseCode+c.OOCode+a.MUSER+f.ODNCode AS Costre,c.OODetailID+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, '')+
  1132. ISNULL(ext.cFree1, '')+ISNULL(ext.cFree2, '')+ISNULL(ext.cFree3, '')+ISNULL(ext.cFree4, '')+ISNULL(ext.cFree5, '')+ISNULL(ext.cFree6, '')+ISNULL(ext.cFree7, '')+ISNULL(ext.cFree8, '')+ISNULL(ext.cFree9, '')+ISNULL(ext.cFree10, '') AS Costre2,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.OOCode,c.OOID,f.ODNCode,f.ODNDetailID,a.MUSER,f.Sequence AS ODNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.OOCode,c.OODetailID,a.InvCode) AS Sequence,
  1133. 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,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.OODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose,conStockneww.Enable AS CompleteVerification
  1134. ,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,
  1135. 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,a.TransSequence
  1136. ,'{2}' as DocTyppe,getdate() as DocDate,c.Sequence as srcDocPOLineNo
  1137. INTO #TempERP
  1138. FROM #NewTempERP a
  1139. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1140. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1141. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1142. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1143. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1144. INNER JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  1145. INNER JOIN ICSODeliveryNotice f ON g.OASNCode=f.OASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  1146. INNER JOIN ICSOutsourcingOrder c ON b.TransCode = c.OOCode
  1147. AND b.TransSequence = c.Sequence
  1148. AND f.OODetailID = c.OODetailID
  1149. AND b.WorkPoint = c.WorkPoint
  1150. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1151. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  1152. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
  1153. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose002'
  1154. INNER JOIN ICSConfiguration conStockneww ON a.WorkPoint=conStockneww.WorkPoint AND conStockneww.Code='CompleteVerification005'
  1155. GROUP BY conStockneww.Enable,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.OOCode,a.MUSER,f.ODNCode,f.ODNDetailID,f.Sequence,a.TransSequence,a.InvCode,c.OOID,c.OODetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable,conStock.Enable,conStocknew.Enable
  1156. ,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, ''),
  1157. 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, ''),c.Sequence
  1158. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,OOCode as POCode,ODNCode as DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,CompleteVerification,UpdateStock,IsFillClose,DocTyppe, DocDate, DocDate as ArrDate FROM #TempERP
  1159. SELECT Costre,Costre2,Sequence,ODNSequence as DNSequence,TransSequence,InvCode,Quantity,Amount,OODetailID as PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WarehouseCode AS WhCode,srcDocPOLineNo
  1160. FROM #TempERP
  1161. DROP TABLE #TempERP
  1162. DROP TABLE #NewTempERP
  1163. DROP TABLE #NewDouTempERP
  1164. ";
  1165. // select LotNo, WorkPoint, InvCode, ToWarehouseCode, MUSER, Quantity, TransSequence
  1166. //INTO #NewTempERP
  1167. //from ICSWareHouseLotInfoLog
  1168. //WHERE Identification = '{0}' AND ERPUpload = '0' AND BusinessCode = '{1}'
  1169. //SELECT c.VenCode + a.ToWarehouseCode + c.POCode + a.MUSER + CASE WHEN(LEN(f.DNID) >= 20) THEN '' ELSE f.DNCode END AS Costre, c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>= 20) THEN '' ELSE f.DNCode END AS DNCode, CASE WHEN(LEN(f.DNID) >= 20) THEN '1' ELSE '0' END AS HasDN,a.MUSER,CASE WHEN(LEN(f.DNID)>= 20) THEN '' ELSE f.Sequence END AS DNSequence, ROW_NUMBER() OVER(ORDER BY c.VenCode, a.ToWarehouseCode, c.POCode, c.PODetailID, a.InvCode) AS Sequence,
  1170. // 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,isnull((c.UnitPrice), 0) as UnitPrice,c.Currency,c.PODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose
  1171. // --,a.lotno AS Costre2
  1172. // ,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,
  1173. // 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,'{2}' as DocTyppe,getdate() as DocDate,c.Sequence as srcDocPOLineNo
  1174. // INTO #TempERP
  1175. // FROM #NewTempERP a
  1176. // INNER JOIN ICSInventoryLot lot ON a.LotNo = lot.LotNo AND a.WorkPoint = lot.WorkPoint
  1177. // INNER JOIN ICSExtension ext ON lot.ExtensionID = ext.ID AND lot.WorkPoint = ext.WorkPoint
  1178. // INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
  1179. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode = invBat.InvCode AND a.ToWarehouseCode = invBat.WHCode AND a.WorkPoint = invBat.WorkPoint
  1180. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
  1181. // INNER JOIN ICSASNDetail g ON a.LotNo = g.LotNo AND a.WorkPoint = g.WorkPoint
  1182. // INNER JOIN ICSDeliveryNotice f ON g.ASNCode = f.ASNCode AND g.WorkPoint = f.WorkPoint AND lot.ExtensionID = f.ExtensionID
  1183. // INNER JOIN ICSPurchaseOrder c ON b.TransCode = c.POCode AND b.TransSequence = c.Sequence AND f.PODetailID = c.PODetailID AND b.WorkPoint = c.WorkPoint
  1184. // INNER JOIN ICSConfiguration con ON con.Code = 'Stock001' AND a.WorkPoint = con.WorkPoint
  1185. // INNER JOIN ICSConfiguration conn ON a.WorkPoint = conn.WorkPoint AND conn.Code = 'Escrow001'
  1186. //INNER JOIN ICSConfiguration conStock ON a.WorkPoint = conStock.WorkPoint AND conStock.Code = 'UpdateStock001'
  1187. //INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint = conStocknew.WorkPoint AND conStocknew.Code = 'FillClose003'
  1188. // GROUP BY--a.LotNo,
  1189. // a.TransSequence,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>= 20) THEN '' ELSE f.DNCode END, f.DNID,a.MUSER,a.InvCode,CASE WHEN(LEN(f.DNID)>= 20) THEN '' ELSE f.Sequence END, c.PODetailID,isnull((c.UnitPrice), 0),c.Currency,con.Enable,conn.Enable,conStock.Enable,conStocknew.Enable
  1190. // ,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, ''),
  1191. // 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, ''),c.Sequence
  1192. // SELECT DISTINCT Costre, WorkPoint, VenCode, WarehouseCode AS WhCode, POCode, DNCode, MUSER AS[User],SYSDATETIME() AS MTime, Enable, UpdateTodoQuantity, UpdateStock, IsFillClose, DocTyppe, DocDate, DocDate as ArrDate FROM #TempERP
  1193. // SELECT Costre,
  1194. // --Costre2,
  1195. // Sequence,DNSequence,InvCode,Quantity,Amount,PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WarehouseCode AS WhCode,srcDocPOLineNo
  1196. // FROM #TempERP
  1197. //SELECT SUM(a.Quantity) AS Quantity--,a.LotNo AS Costre2,a.LotNo,
  1198. // FROM ICSWareHouseLotInfoLog a
  1199. // INNER JOIN ICSInventoryLot lot ON a.LotNo = lot.LotNo AND a.WorkPoint = lot.WorkPoint
  1200. // INNER JOIN ICSExtension ext ON lot.ExtensionID = ext.ID AND lot.WorkPoint = ext.WorkPoint
  1201. // INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
  1202. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode = invBat.InvCode AND a.ToWarehouseCode = invBat.WHCode AND a.WorkPoint = invBat.WorkPoint
  1203. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
  1204. // INNER JOIN ICSASNDetail g ON a.LotNo = g.LotNo AND a.WorkPoint = g.WorkPoint
  1205. // INNER JOIN ICSDeliveryNotice f ON g.ASNCode = f.ASNCode AND g.WorkPoint = f.WorkPoint AND lot.ExtensionID = f.ExtensionID
  1206. // INNER JOIN ICSPurchaseOrder c ON b.TransCode = c.POCode AND b.TransSequence = c.Sequence AND f.PODetailID = c.PODetailID AND b.WorkPoint = c.WorkPoint
  1207. // INNER JOIN #TempERP te ON te.Sequence=a.TransSequence
  1208. // WHERE a.Identification = '{0}' AND ERPUpload = '0' AND BusinessCode = '{1}'
  1209. // --GROUP BY a.LotNo
  1210. // SELECT DISTINCT HasDN FROM #TempERP
  1211. // DROP TABLE #TempERP
  1212. // DROP TABLE #NewTempERP
  1213. sql = string.Format(sql, Identification, BusinessCode, doctype);
  1214. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1215. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1216. //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
  1217. //var IsDNCode = ds.Tables[3];
  1218. //if (IsDNCode == null || IsDNCode.Rows.Count != 1)
  1219. //{
  1220. // throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种!
  1221. //}
  1222. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9CreatePOArrivURL, Inputstr);
  1223. Result result = new Result();
  1224. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1225. if (result.Success)
  1226. {
  1227. try
  1228. {
  1229. //JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1230. //foreach (var item in res)
  1231. //{
  1232. // JObject jo = (JObject)item;
  1233. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1234. // foreach (var detail in resdetail)
  1235. // {
  1236. // JObject det = (JObject)detail;
  1237. // string allcol = jo["cWhCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  1238. // + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1239. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1240. // det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1241. // }
  1242. //}
  1243. }
  1244. catch (Exception ex)
  1245. {
  1246. log.Debug(ex.ToString());
  1247. log.Debug(resultStr);
  1248. }
  1249. }
  1250. else
  1251. {
  1252. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1253. }
  1254. #endregion
  1255. }
  1256. catch (Exception)
  1257. {
  1258. throw;
  1259. }
  1260. }
  1261. #endregion
  1262. #region 审核的委外到货单
  1263. /// <summary>
  1264. /// 审核的委外到货单
  1265. /// </summary>
  1266. /// <param name="TransCode"></param>
  1267. /// <param name="TransSequence"></param>
  1268. /// <param name="Quantity"></param>
  1269. /// <param name="WorkPoint"></param>
  1270. /// <param name="cmd"></param>
  1271. public static void ODeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1272. {
  1273. try
  1274. {
  1275. string sql = @"
  1276. DECLARE @Status VARCHAR(10)
  1277. DECLARE @FStatus VARCHAR(10)
  1278. SELECT @Status=c.Status,@FStatus=c.EATTRIBUTE3 FROM ICSInventoryLot a
  1279. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1280. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1281. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  1282. IF (@Status IS NULL)
  1283. BEGIN
  1284. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1285. RETURN
  1286. END
  1287. ELSE IF (@Status='3')
  1288. BEGIN
  1289. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1290. RETURN
  1291. END
  1292. IF (@FStatus IS NULL)
  1293. BEGIN
  1294. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1295. FROM ICSInventoryLot a
  1296. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1297. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1298. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  1299. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1300. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1301. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1302. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1' AND c.Quantity<c.RCVQuantity)
  1303. BEGIN
  1304. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1305. END
  1306. END
  1307. ELSE
  1308. BEGIN
  1309. UPDATE d SET d.InQuantity=ISNULL(d.InQuantity,0)+'{2}'
  1310. FROM ICSInventoryLot a
  1311. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1312. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1313. INNER JOIN ICSOutsourcingOrder d ON c.OODetailID=d.OODetailID AND d.WorkPoint=c.WorkPoint
  1314. INNER JOIN ICSOOPick e ON d.EATTRIBUTE2=e.PICKID and d.WorkPoint=e.WorkPoint
  1315. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  1316. UPDATE e SET e.IssueQuantity=ISNULL(e.IssueQuantity,0)+'{2}'
  1317. FROM ICSInventoryLot a
  1318. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1319. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1320. INNER JOIN ICSOutsourcingOrder d ON c.OODetailID=d.OODetailID AND d.WorkPoint=c.WorkPoint
  1321. INNER JOIN ICSOOPick e ON d.EATTRIBUTE2=e.PICKID and d.WorkPoint=e.WorkPoint
  1322. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  1323. END";
  1324. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1325. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1326. {
  1327. throw new Exception(language.GetNameByCode("WMSAPIInfo117"));//"委外到货单更新失败!");
  1328. }
  1329. }
  1330. catch (Exception)
  1331. {
  1332. throw;
  1333. }
  1334. }
  1335. /// <summary>
  1336. /// 审核的委外到货单接口
  1337. /// </summary>
  1338. /// <param name="TransType"></param>
  1339. /// <param name="Identification"></param>
  1340. /// <param name="cmd"></param>
  1341. public static void ODeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1342. {
  1343. try
  1344. {
  1345. #region ERP
  1346. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  1347. INTO #NewTempERP
  1348. from ICSWareHouseLotInfoLog
  1349. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1350. SELECT c.VenCode+a.ToWarehouseCode+c.ODNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.ODNDetailID,a.InvCode) AS Sequence,
  1351. 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,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.ODNDetailID,con.Enable AS UpdateTodoQuantity,conn.Enable,conStock.Enable AS UpdateStock
  1352. ,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,
  1353. 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
  1354. INTO #TempERP
  1355. FROM #NewTempERP a
  1356. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1357. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1358. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1359. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1360. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1361. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1362. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1363. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  1364. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  1365. GROUP BY inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.ODNCode,a.MUSER,a.InvCode,c.ODNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable,conStock.Enable
  1366. ,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, ''),
  1367. 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, '')
  1368. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1369. SELECT Costre,Sequence,InvCode,Quantity,Amount,ODNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1370. FROM #TempERP
  1371. DROP TABLE #TempERP
  1372. DROP TABLE #NewTempERP";
  1373. sql = string.Format(sql, Identification,BusinessCode);
  1374. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1375. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1376. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ODeliveryNoticeInURL, Inputstr);
  1377. Result result = new Result();
  1378. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1379. if (result.Success)
  1380. {
  1381. try
  1382. {
  1383. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1384. foreach (var item in res)
  1385. {
  1386. JObject jo = (JObject)item;
  1387. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1388. foreach (var detail in resdetail)
  1389. {
  1390. JObject det = (JObject)detail;
  1391. 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()
  1392. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1393. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1394. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1395. }
  1396. }
  1397. }
  1398. catch (Exception ex)
  1399. {
  1400. log.Debug(ex.ToString());
  1401. log.Debug(resultStr);
  1402. }
  1403. }
  1404. else
  1405. {
  1406. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1407. }
  1408. #endregion
  1409. }
  1410. catch (Exception)
  1411. {
  1412. throw;
  1413. }
  1414. }
  1415. #endregion
  1416. #region 委外拒收
  1417. /// <summary>
  1418. /// 委外拒收
  1419. /// </summary>
  1420. /// <param name="TransCode"></param>
  1421. /// <param name="TransSequence"></param>
  1422. /// <param name="Quantity"></param>
  1423. /// <param name="WorkPoint"></param>
  1424. /// <param name="cmd"></param>
  1425. public static void OutsourcingRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1426. {
  1427. try
  1428. {
  1429. string sql = @"DECLARE @Status VARCHAR(10)
  1430. SELECT @Status=c.Status FROM ICSInventoryLot a
  1431. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1432. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1433. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  1434. IF (@Status IS NULL)
  1435. BEGIN
  1436. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1437. RETURN
  1438. END
  1439. ELSE IF (@Status='3')
  1440. BEGIN
  1441. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1442. RETURN
  1443. END
  1444. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1445. FROM ICSInventoryLot a
  1446. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1447. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1448. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  1449. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1450. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1451. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1452. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3' AND c.Quantity<c.RCVQuantity)
  1453. BEGIN
  1454. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1455. END";
  1456. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1457. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1458. {
  1459. throw new Exception(language.GetNameByCode("WMSAPIInfo118"));//"委外拒收单更新失败!");
  1460. }
  1461. }
  1462. catch (Exception)
  1463. {
  1464. throw;
  1465. }
  1466. }
  1467. /// <summary>
  1468. /// 委外拒收接口
  1469. /// </summary>
  1470. /// <param name="TransType"></param>
  1471. /// <param name="Identification"></param>
  1472. /// <param name="cmd"></param>
  1473. public static void OutsourcingRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1474. {
  1475. // try
  1476. // {
  1477. // #region ERP
  1478. // string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.ODNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,d.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.ODNCode,c.ODNDetailID,a.InvCode) AS Sequence,
  1479. // a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.ODNDetailID,Enable AS UpdateTodoQuantity
  1480. // ,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,
  1481. // 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
  1482. // INTO #TempERP
  1483. // FROM ICSWareHouseLotInfoLog a
  1484. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1485. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1486. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1487. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1488. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1489. // INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1490. // INNER JOIN ICSODeliveryNotice d ON c.OODetailID=d.ODNDetailID AND d.WorkPoint=c.WorkPoint
  1491. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1492. // WHERE a.Identification='{0}' AND ERPUpload='0'
  1493. // GROUP BY c.VenCode,a.ToWarehouseCode,c.ODNCode,d.ODNCode,a.MUSER,a.InvCode,d.ODNDetailID,c.ODNDetailID,isnull((c.UnitPrice),0),c.Currency,Enable
  1494. // ,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, ''),
  1495. // 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, '')
  1496. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,ODNCode AS DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint FROM #TempERP
  1497. //SELECT Costre,Sequence,InvCode,Quantity,Amount,ODNDetailID AS DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1498. // FROM #TempERP
  1499. // DROP TABLE #TempERP";
  1500. // sql = string.Format(sql, Identification);
  1501. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1502. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  1503. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateWPuArrivalVouchURL, Inputstr);
  1504. // Result result = new Result();
  1505. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  1506. // if (result.Success)
  1507. // {
  1508. // try
  1509. // {
  1510. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1511. // foreach (var item in res)
  1512. // {
  1513. // JObject jo = (JObject)item;
  1514. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1515. // foreach (var detail in resdetail)
  1516. // {
  1517. // JObject det = (JObject)detail;
  1518. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["OODetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  1519. // }
  1520. // }
  1521. // }
  1522. // catch (Exception ex)
  1523. // {
  1524. // log.Debug(ex.ToString());
  1525. // log.Debug(resultStr);
  1526. // }
  1527. // }
  1528. // else
  1529. // {
  1530. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1531. // }
  1532. // #endregion
  1533. // }
  1534. // catch (Exception)
  1535. // {
  1536. // throw;
  1537. // }
  1538. }
  1539. /// <summary>
  1540. /// 委外拒收接口
  1541. /// </summary>
  1542. /// <param name="TransType"></param>
  1543. /// <param name="Identification"></param>
  1544. /// <param name="cmd"></param>
  1545. public static void OutsourcingRejectDocInNewERP(string ODNCode, string OJDNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1546. {
  1547. try
  1548. {
  1549. #region ERP
  1550. string sql = @"SELECT a.VenCode+a.DepCode+x.ODNCode+a.MUSER AS Costre,a.VenCode,a.DepCode,x.ODNCode,a.MUSER,a.MTIME,
  1551. a.Sequence,a.InvCode,Sum(a.Quantity) AS Quantity,CASE invBat.AmountEnable WHEN '1' THEN a.Amount ELSE '0' END AS Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,x.ODNDetailID
  1552. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  1553. 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
  1554. INTO #TempERP
  1555. FROM ICSODeliveryNotice a
  1556. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1557. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  1558. INNER JOIN ICSODeliveryNotice x ON x.ODNDetailID=a.OODetailID AND a.WorkPoint=x.WorkPoint
  1559. WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}'
  1560. GROUP BY invBat.AmountEnable,a.VenCode,a.DepCode,invBat.AmountEnable,x.ODNCode,a.MUSER,a.MTIME,a.Sequence,a.InvCode,a.Amount,a.Quantity,a.UnitPrice,a.Currency,x.ODNDetailID,
  1561. a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(invBat.BatchEnable, ''),ISNULL(ext.BatchCode, ''),ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  1562. 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, '')
  1563. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  1564. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,ODNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1565. FROM #TempERP
  1566. DROP TABLE #TempERP";
  1567. sql = string.Format(sql, OJDNCode, WorkPoint);
  1568. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1569. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  1570. string resultStr = HTTPHelper.HttpPost("委外拒收", ERPUrl.CreateWPuArrivalVouchURL, Inputstr);
  1571. Result result = new Result();
  1572. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1573. if (result.Success)
  1574. {
  1575. try
  1576. {
  1577. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1578. foreach (var item in res)
  1579. {
  1580. JObject jo = (JObject)item;
  1581. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1582. foreach (var detail in resdetail)
  1583. {
  1584. JObject det = (JObject)detail;
  1585. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RJTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  1586. string ERPupdate = @"update ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}'
  1587. where OODetailID='{4}' AND ODNType='3' AND ODNCode='{5}' ";
  1588. ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], OJDNCode);
  1589. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1590. {
  1591. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  1592. }
  1593. }
  1594. }
  1595. }
  1596. catch (Exception ex)
  1597. {
  1598. log.Debug(ex.ToString());
  1599. log.Debug(resultStr);
  1600. }
  1601. }
  1602. else
  1603. {
  1604. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1605. }
  1606. #endregion
  1607. }
  1608. catch (Exception)
  1609. {
  1610. throw;
  1611. }
  1612. }
  1613. #endregion
  1614. #region 委外退货
  1615. /// <summary>
  1616. /// 委外退货
  1617. /// </summary>
  1618. /// <param name="TransCode"></param>
  1619. /// <param name="TransSequence"></param>
  1620. /// <param name="Quantity"></param>
  1621. /// <param name="WorkPoint"></param>
  1622. /// <param name="cmd"></param>
  1623. public static void OutsourcingReturnBack(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1624. {
  1625. try
  1626. {
  1627. string sql = @"DECLARE @Status VARCHAR(10)
  1628. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' AND ODNType='2' and WorkPoint='{1}'
  1629. IF (@Status IS NULL)
  1630. BEGIN
  1631. RAISERROR('" + language.GetNameByCode("WMSAPIInfo119") + @"',16,1);
  1632. RETURN
  1633. END
  1634. ELSE IF (@Status!='2')
  1635. BEGIN
  1636. RAISERROR('" + language.GetNameByCode("WMSAPIInfo120") + @"',16,1);
  1637. RETURN
  1638. END
  1639. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1640. FROM ICSODeliveryNotice a
  1641. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND ODNType='2'
  1642. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a
  1643. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.RCVQuantity AND ODNType='2')
  1644. BEGIN
  1645. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  1646. RETURN
  1647. END";
  1648. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  1649. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1650. {
  1651. throw new Exception(language.GetNameByCode("WMSAPIInfo121"));//"委外退货单更新失败!");
  1652. }
  1653. }
  1654. catch (Exception)
  1655. {
  1656. throw;
  1657. }
  1658. }
  1659. /// <summary>
  1660. /// 委外退货接口
  1661. /// </summary>
  1662. /// <param name="TransType"></param>
  1663. /// <param name="Identification"></param>
  1664. /// <param name="cmd"></param>
  1665. public static void OutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1666. {
  1667. try
  1668. {
  1669. #region ERP
  1670. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  1671. INTO #NewTempERP
  1672. from ICSWareHouseLotInfoLog
  1673. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  1674. SELECT y.VenCode+a.FromWarehouseCode+y.ODNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.ODNCode,y.ODNDetailID,a.InvCode) AS Sequence,
  1675. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(y.Amount/y.Quantity)) ELSE '0' END AS Amount, y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1676. ,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,
  1677. 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
  1678. INTO #TempERP
  1679. FROM #NewTempERP a
  1680. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1681. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1682. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1683. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1684. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  1685. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1686. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  1687. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1688. GROUP BY inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.ODNCode,a.MUSER,a.InvCode,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conv.Enable,conStock.Enable
  1689. ,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, ''),
  1690. 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, '')
  1691. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNCode AS ODNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,ODNCode AS SourceCode, SYSDATETIME() AS DocDate,'RCV25' as DocTypeCode FROM #TempERP
  1692. SELECT Costre,Sequence,InvCode,Quantity,Amount,ODNDetailID AS ODNRTDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1693. FROM #TempERP
  1694. DROP TABLE #TempERP
  1695. DROP TABLE #NewTempERP";
  1696. sql = string.Format(sql, Identification);
  1697. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1698. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1699. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReturnBackURL, Inputstr);
  1700. Result result = new Result();
  1701. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1702. if (result.Success)
  1703. {
  1704. try
  1705. {
  1706. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1707. foreach (var item in res)
  1708. {
  1709. JObject jo = (JObject)item;
  1710. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1711. foreach (var detail in resdetail)
  1712. {
  1713. JObject det = (JObject)detail;
  1714. 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()
  1715. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1716. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1717. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1718. }
  1719. }
  1720. }
  1721. catch (Exception ex)
  1722. {
  1723. log.Debug(ex.ToString());
  1724. log.Debug(resultStr);
  1725. }
  1726. }
  1727. else
  1728. {
  1729. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1730. }
  1731. #endregion
  1732. }
  1733. catch (Exception)
  1734. {
  1735. throw;
  1736. }
  1737. }
  1738. public static void U9OutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1739. {
  1740. try
  1741. {
  1742. #region ERP
  1743. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  1744. INTO #NewTempERP
  1745. from ICSWareHouseLotInfoLog
  1746. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  1747. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  1748. INNER JOIN ICSODeliveryNotice b ON a.TransCode=b.ODNCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1749. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  1750. BEGIN
  1751. RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',16,1);
  1752. RETURN
  1753. END
  1754. SELECT y.VenCode+a.FromWarehouseCode+y.ODNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.ODNCode,y.ODNDetailID,a.InvCode) AS Sequence,
  1755. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(y.Amount/y.Quantity)) ELSE '0' END AS Amount, y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1756. ,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,
  1757. 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
  1758. ,y.Sequence as oSequence INTO #TempERP
  1759. FROM #NewTempERP a
  1760. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1761. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1762. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1763. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1764. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  1765. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1766. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  1767. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1768. GROUP BY inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.ODNCode,a.MUSER,a.InvCode,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conv.Enable,conStock.Enable
  1769. ,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, ''),
  1770. 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, ''),y.Sequence
  1771. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNCode AS ODNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,ODNCode AS SourceCode, SYSDATETIME() AS DocDate,oSequence as Sequence,InvCode,Quantity,'RCV25' as DocTypeCode,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  1772. DROP TABLE #TempERP
  1773. DROP TABLE #NewTempERP";
  1774. sql = string.Format(sql, Identification);
  1775. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1776. string Inputstr = DataToJsonHelper.ToJson(ds.Tables[0]);
  1777. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OutsourcingReturnBackURL, Inputstr);
  1778. Result result = new Result();
  1779. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1780. if (result.Success)
  1781. {
  1782. try
  1783. {
  1784. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1785. foreach (var item in res)
  1786. {
  1787. JObject jo = (JObject)item;
  1788. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1789. foreach (var detail in resdetail)
  1790. {
  1791. JObject det = (JObject)detail;
  1792. 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()
  1793. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1794. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1795. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1796. }
  1797. }
  1798. }
  1799. catch (Exception ex)
  1800. {
  1801. log.Debug(ex.ToString());
  1802. log.Debug(resultStr);
  1803. }
  1804. }
  1805. else
  1806. {
  1807. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1808. }
  1809. #endregion
  1810. }
  1811. catch (Exception)
  1812. {
  1813. throw;
  1814. }
  1815. }
  1816. #endregion
  1817. #region 开立委外红字入库
  1818. /// <summary>
  1819. /// 开立委外红字入库
  1820. /// </summary>
  1821. /// <param name="TransCode"></param>
  1822. /// <param name="TransSequence"></param>
  1823. /// <param name="Quantity"></param>
  1824. /// <param name="WorkPoint"></param>
  1825. /// <param name="cmd"></param>
  1826. public static void OutsourcingReceiveDocNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1827. {
  1828. try
  1829. {
  1830. string sql = @"DECLARE @Status VARCHAR(10)
  1831. SELECT @Status=a.Status FROM ICSOutsourcingReceive a
  1832. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  1833. IF (@Status IS NULL)
  1834. BEGIN
  1835. RAISERROR('" + language.GetNameByCode("WMSAPIInfo122") + @"',16,1);
  1836. RETURN
  1837. END
  1838. ELSE IF (@Status!='1')
  1839. BEGIN
  1840. RAISERROR('" + language.GetNameByCode("WMSAPIInfo123") + @"',16,1);
  1841. RETURN
  1842. END
  1843. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1844. FROM ICSOutsourcingReceive a
  1845. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  1846. IF EXISTS(SELECT a.ID FROM ICSOutsourcingReceive a
  1847. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='2' AND a.Quantity<a.RCVQuantity)
  1848. BEGIN
  1849. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  1850. RETURN
  1851. END";
  1852. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  1853. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1854. {
  1855. throw new Exception(language.GetNameByCode("WMSAPIInfo124"));//"委外红字入库单更新失败!");
  1856. }
  1857. }
  1858. catch (Exception)
  1859. {
  1860. throw;
  1861. }
  1862. }
  1863. /// <summary>
  1864. /// 开立委外红字入库接口
  1865. /// </summary>
  1866. /// <param name="TransType"></param>
  1867. /// <param name="Identification"></param>
  1868. /// <param name="cmd"></param>
  1869. public static void OutsourcingReceiveDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1870. {
  1871. try
  1872. {
  1873. #region ERP开立状态单据审核
  1874. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  1875. INTO #NewTempERP
  1876. from ICSWareHouseLotInfoLog
  1877. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '12'
  1878. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  1879. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1880. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  1881. BEGIN
  1882. RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',16,1);
  1883. RETURN
  1884. END
  1885. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1886. FROM #NewTempERP a
  1887. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1888. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1889. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  1890. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1891. DROP TABLE #NewTempERP";
  1892. sql = string.Format(sql, Identification);
  1893. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1894. string Inputstr = JsonConvert.SerializeObject(dt);
  1895. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocNegativeURL, Inputstr);
  1896. Result result = new Result();
  1897. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1898. if (result.Success)
  1899. {
  1900. try
  1901. {
  1902. foreach (DataRow dr in dt.Rows)
  1903. {
  1904. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1905. }
  1906. }
  1907. catch (Exception ex)
  1908. {
  1909. log.Debug(ex.ToString());
  1910. log.Debug(resultStr);
  1911. }
  1912. }
  1913. else
  1914. {
  1915. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1916. }
  1917. #endregion
  1918. }
  1919. catch (Exception)
  1920. {
  1921. throw;
  1922. }
  1923. }
  1924. #endregion
  1925. }
  1926. }