爱思开
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.

411 lines
26 KiB

2 years ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Linq;
  10. using System.Net.Http;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace ICSSoft.DataProject
  14. {
  15. /// <summary>
  16. /// 使用中
  17. /// 销售模块
  18. /// </summary>
  19. public class ICSSalesService
  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 SalesShipmentDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  32. {
  33. try
  34. {
  35. string sql = @"DECLARE @Status VARCHAR(10)
  36. SELECT @Status=a.Status FROM ICSSDN a
  37. WHERE a.SDNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='1'
  38. IF (@Status IS NULL)
  39. BEGIN
  40. RAISERROR('" + language.GetNameByCode("WMSAPIInfo139") + @"',16,1);
  41. RETURN
  42. END
  43. ELSE IF (@Status!='2')
  44. BEGIN
  45. RAISERROR('" + language.GetNameByCode("WMSAPIInfo140") + @"',16,1);
  46. RETURN
  47. END
  48. UPDATE a SET SDNQuantity=ISNULL(SDNQuantity,0)+'{2}'
  49. FROM ICSSDN a
  50. WHERE a.SDNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='1'
  51. IF EXISTS(SELECT a.ID FROM ICSSDN a
  52. WHERE a.SDNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='1' AND a.Quantity<a.SDNQuantity)
  53. BEGIN
  54. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  55. RETURN
  56. END";
  57. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  58. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  59. {
  60. throw new Exception(language.GetNameByCode("WMSAPIInfo141"));//"销售领料单更新失败!");
  61. }
  62. }
  63. catch (Exception)
  64. {
  65. throw;
  66. }
  67. }
  68. /// <summary>
  69. /// 销售出库接口
  70. /// </summary>
  71. /// <param name="TransType"></param>
  72. /// <param name="Identification"></param>
  73. /// <param name="cmd"></param>
  74. public static void SalesShipmentDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  75. {
  76. try
  77. {
  78. #region ERP
  79. string sql = @"SELECT b.CusCode+a.FromWarehouseCode+b.SDNCode+a.MUSER AS Costre,b.CusCode,a.FromWarehouseCode AS WarehouseCode,b.SDNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY b.CusCode,a.FromWarehouseCode,b.SDNCode,b.SDNDetailID,a.InvCode) AS Sequence,
  80. a.InvCode,SUM(a.Quantity) AS Quantity,isnull(SUM(a.Quantity*lot.Amount/lot.Quantity),0) AS Amount,b.SDNDetailID,Enable AS UpdateTodoQuantity
  81. ,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,
  82. 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
  83. INTO #TempERP
  84. FROM ICSWareHouseLotInfoLog a
  85. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  86. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  87. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  88. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  89. INNER JOIN ICSSDN b ON a.TransCode=b.SDNCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  90. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  91. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1' AND (a.BusinessCode = '19' OR a.BusinessCode = '105')
  92. GROUP BY b.CusCode,a.FromWarehouseCode,b.SDNCode,a.MUSER,a.InvCode,b.SDNDetailID,Enable
  93. ,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, ''),
  94. 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, '')
  95. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  96. SELECT Costre,Sequence,InvCode,Quantity,Amount,SDNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  97. DROP TABLE #TempERP";
  98. sql = string.Format(sql, Identification);
  99. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  100. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  101. string str = Inputstr;
  102. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesDeliveryNoticeURL, Inputstr);
  103. Result result = new Result();
  104. result = JsonConvert.DeserializeObject<Result>(resultStr);
  105. if (result.Success)
  106. {
  107. try
  108. {
  109. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  110. foreach (var item in res)
  111. {
  112. JObject jo = (JObject)item;
  113. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  114. foreach (var detail in resdetail)
  115. {
  116. JObject det = (JObject)detail;
  117. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  118. det["DetailID"].ToString(), jo["SSDCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  119. }
  120. }
  121. }
  122. catch (Exception ex)
  123. {
  124. log.Debug(ex.ToString());
  125. log.Debug(resultStr);
  126. }
  127. }
  128. else
  129. {
  130. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  131. }
  132. #endregion
  133. }
  134. catch (Exception)
  135. {
  136. throw;
  137. }
  138. }
  139. #endregion
  140. #region 销售退货
  141. /// <summary>
  142. /// 销售退货
  143. /// </summary>
  144. /// <param name="TransCode"></param>
  145. /// <param name="TransSequence"></param>
  146. /// <param name="Quantity"></param>
  147. /// <param name="WorkPoint"></param>
  148. /// <param name="cmd"></param>
  149. public static void SalesShipmentDocNegative(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  150. {
  151. try
  152. {
  153. string sql = @"DECLARE @Status VARCHAR(10)
  154. SELECT @Status=c.Status FROM ICSInventoryLot a
  155. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  156. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  157. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
  158. IF (@Status IS NULL)
  159. BEGIN
  160. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  161. RETURN
  162. END
  163. ELSE IF (@Status!='2')
  164. BEGIN
  165. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  166. RETURN
  167. END
  168. UPDATE c SET SDNQuantity=ISNULL(SDNQuantity,0)+'{2}'
  169. FROM ICSInventoryLot a
  170. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  171. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  172. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
  173. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  174. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  175. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  176. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2' AND c.Quantity<c.SDNQuantity)
  177. BEGIN
  178. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  179. END";
  180. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  181. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  182. {
  183. throw new Exception("销售退货单更新失败!");
  184. }
  185. }
  186. catch (Exception)
  187. {
  188. throw;
  189. }
  190. }
  191. /// <summary>
  192. /// 销售退货接口
  193. /// </summary>
  194. /// <param name="TransType"></param>
  195. /// <param name="Identification"></param>
  196. /// <param name="cmd"></param>
  197. public static void SalesShipmentDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  198. {
  199. try
  200. {
  201. #region ERP
  202. string sql = @"SELECT c.CusCode+a.ToWarehouseCode+c.SDNCode+a.MUSER AS Costre,c.CusCode,a.ToWarehouseCode AS WarehouseCode,c.SDNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.CusCode,a.ToWarehouseCode,c.SDNCode,c.SDNDetailID,a.InvCode) AS Sequence,
  203. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*lot.Amount/lot.Quantity) AS Amount,c.SDNDetailID,Enable AS UpdateTodoQuantity
  204. ,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,
  205. 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
  206. INTO #TempERP
  207. FROM ICSWareHouseLotInfoLog a
  208. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  209. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  210. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  211. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  212. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  213. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  214. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  215. WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2'
  216. GROUP BY c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,Enable
  217. ,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, ''),
  218. 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, '')
  219. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  220. SELECT Costre,Sequence,InvCode,Quantity,Amount,SDNDetailID AS SDNRTDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  221. DROP TABLE #TempERP";
  222. sql = string.Format(sql, Identification);
  223. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  224. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  225. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, Inputstr);
  226. Result result = new Result();
  227. result = JsonConvert.DeserializeObject<Result>(resultStr);
  228. if (result.Success)
  229. {
  230. try
  231. {
  232. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  233. foreach (var item in res)
  234. {
  235. JObject jo = (JObject)item;
  236. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  237. foreach (var detail in resdetail)
  238. {
  239. JObject det = (JObject)detail;
  240. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  241. det["DetailID"].ToString(), jo["SDNNEGCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  242. }
  243. }
  244. }
  245. catch (Exception ex)
  246. {
  247. log.Debug(ex.ToString());
  248. log.Debug(resultStr);
  249. }
  250. }
  251. else
  252. {
  253. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  254. }
  255. #endregion
  256. }
  257. catch (Exception)
  258. {
  259. throw;
  260. }
  261. }
  262. #endregion
  263. #region 销售退货-原条码
  264. /// <summary>
  265. /// 销售退货-原条码
  266. /// </summary>
  267. /// <param name="TransCode"></param>
  268. /// <param name="TransSequence"></param>
  269. /// <param name="Quantity"></param>
  270. /// <param name="WorkPoint"></param>
  271. /// <param name="cmd"></param>
  272. public static void SalesReturnBackIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  273. {
  274. try
  275. {
  276. string sql = @"DECLARE @Status VARCHAR(10)
  277. SELECT @Status=sdn.Status FROM ICSSDN sdn
  278. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  279. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  280. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SDNCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
  281. IF (@Status IS NULL)
  282. BEGIN
  283. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  284. RETURN
  285. END
  286. ELSE IF (@Status!='2')
  287. BEGIN
  288. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  289. RETURN
  290. END
  291. UPDATE sdn SET SDNQuantity=ISNULL(SDNQuantity,0)+'{4}'
  292. FROM ICSSDN sdn
  293. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  294. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  295. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SDNCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
  296. IF EXISTS(SELECT a.LotNo FROM ICSSDN sdn
  297. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  298. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  299. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SDNCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2' AND sdn.Quantity<sdn.SDNQuantity)
  300. BEGIN
  301. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  302. END";
  303. sql = string.Format(sql, LotNo, WorkPoint, TransCode, TransSequence, Quantity);
  304. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  305. {
  306. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  307. }
  308. }
  309. catch (Exception)
  310. {
  311. throw;
  312. }
  313. }
  314. /// <summary>
  315. /// 销售退货-原条码接口
  316. /// </summary>
  317. /// <param name="TransType"></param>
  318. /// <param name="Identification"></param>
  319. /// <param name="cmd"></param>
  320. public static void SalesReturnBackInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  321. {
  322. try
  323. {
  324. #region ERP
  325. string sql = @"SELECT c.CusCode+a.ToWarehouseCode+c.SDNCode+a.MUSER AS Costre,c.CusCode,a.ToWarehouseCode AS WarehouseCode,c.SDNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.CusCode,a.ToWarehouseCode,c.SDNCode,c.SDNDetailID,a.InvCode) AS Sequence,
  326. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*lot.Amount/lot.Quantity) AS Amount,c.SDNDetailID,Enable AS UpdateTodoQuantity
  327. ,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,
  328. 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
  329. INTO #TempERP
  330. FROM ICSWareHouseLotInfoLog a
  331. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  332. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  333. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  334. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  335. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  336. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  337. WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2'
  338. GROUP BY c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,Enable
  339. ,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, ''),
  340. 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, '')
  341. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  342. SELECT Costre,Sequence,InvCode,Quantity,Amount,SDNDetailID AS SDNRTDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  343. DROP TABLE #TempERP";
  344. sql = string.Format(sql, Identification);
  345. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  346. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  347. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, Inputstr);
  348. Result result = new Result();
  349. result = JsonConvert.DeserializeObject<Result>(resultStr);
  350. if (result.Success)
  351. {
  352. try
  353. {
  354. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  355. foreach (var item in res)
  356. {
  357. JObject jo = (JObject)item;
  358. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  359. foreach (var detail in resdetail)
  360. {
  361. JObject det = (JObject)detail;
  362. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  363. det["DetailID"].ToString(), jo["SDNNEGCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  364. }
  365. }
  366. }
  367. catch (Exception ex)
  368. {
  369. log.Debug(ex.ToString());
  370. log.Debug(resultStr);
  371. }
  372. }
  373. else
  374. {
  375. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  376. }
  377. #endregion
  378. }
  379. catch (Exception)
  380. {
  381. throw;
  382. }
  383. }
  384. #endregion
  385. }
  386. }