纽威
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.

410 lines
25 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 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,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'
  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 resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesDeliveryNoticeURL, Inputstr);
  102. Result result = new Result();
  103. result = JsonConvert.DeserializeObject<Result>(resultStr);
  104. if (result.Success)
  105. {
  106. try
  107. {
  108. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  109. foreach (var item in res)
  110. {
  111. JObject jo = (JObject)item;
  112. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  113. foreach (var detail in resdetail)
  114. {
  115. JObject det = (JObject)detail;
  116. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  117. det["DetailID"].ToString(), jo["SSDCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  118. }
  119. }
  120. }
  121. catch (Exception ex)
  122. {
  123. log.Debug(ex.ToString());
  124. log.Debug(resultStr);
  125. }
  126. }
  127. else
  128. {
  129. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  130. }
  131. #endregion
  132. }
  133. catch (Exception)
  134. {
  135. throw;
  136. }
  137. }
  138. #endregion
  139. #region 销售退货
  140. /// <summary>
  141. /// 销售退货
  142. /// </summary>
  143. /// <param name="TransCode"></param>
  144. /// <param name="TransSequence"></param>
  145. /// <param name="Quantity"></param>
  146. /// <param name="WorkPoint"></param>
  147. /// <param name="cmd"></param>
  148. public static void SalesShipmentDocNegative(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  149. {
  150. try
  151. {
  152. string sql = @"DECLARE @Status VARCHAR(10)
  153. SELECT @Status=c.Status FROM ICSInventoryLot a
  154. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  155. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  156. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
  157. IF (@Status IS NULL)
  158. BEGIN
  159. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  160. RETURN
  161. END
  162. ELSE IF (@Status!='2')
  163. BEGIN
  164. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  165. RETURN
  166. END
  167. UPDATE c SET SDNQuantity=ISNULL(SDNQuantity,0)+'{2}'
  168. FROM ICSInventoryLot a
  169. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  170. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  171. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
  172. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  173. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  174. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  175. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2' AND c.Quantity<c.SDNQuantity)
  176. BEGIN
  177. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  178. END";
  179. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  180. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  181. {
  182. throw new Exception("销售退货单更新失败!");
  183. }
  184. }
  185. catch (Exception)
  186. {
  187. throw;
  188. }
  189. }
  190. /// <summary>
  191. /// 销售退货接口
  192. /// </summary>
  193. /// <param name="TransType"></param>
  194. /// <param name="Identification"></param>
  195. /// <param name="cmd"></param>
  196. public static void SalesShipmentDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  197. {
  198. try
  199. {
  200. #region ERP
  201. 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,
  202. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,c.SDNDetailID,Enable AS UpdateTodoQuantity
  203. ,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,
  204. 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
  205. INTO #TempERP
  206. FROM ICSWareHouseLotInfoLog a
  207. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  208. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  209. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  210. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  211. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  212. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  213. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  214. WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2'
  215. GROUP BY c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,Enable
  216. ,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, ''),
  217. 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, '')
  218. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  219. 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
  220. DROP TABLE #TempERP";
  221. sql = string.Format(sql, Identification);
  222. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  223. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  224. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, Inputstr);
  225. Result result = new Result();
  226. result = JsonConvert.DeserializeObject<Result>(resultStr);
  227. if (result.Success)
  228. {
  229. try
  230. {
  231. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  232. foreach (var item in res)
  233. {
  234. JObject jo = (JObject)item;
  235. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  236. foreach (var detail in resdetail)
  237. {
  238. JObject det = (JObject)detail;
  239. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  240. det["DetailID"].ToString(), jo["SDNNEGCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  241. }
  242. }
  243. }
  244. catch (Exception ex)
  245. {
  246. log.Debug(ex.ToString());
  247. log.Debug(resultStr);
  248. }
  249. }
  250. else
  251. {
  252. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  253. }
  254. #endregion
  255. }
  256. catch (Exception)
  257. {
  258. throw;
  259. }
  260. }
  261. #endregion
  262. #region 销售退货-原条码
  263. /// <summary>
  264. /// 销售退货-原条码
  265. /// </summary>
  266. /// <param name="TransCode"></param>
  267. /// <param name="TransSequence"></param>
  268. /// <param name="Quantity"></param>
  269. /// <param name="WorkPoint"></param>
  270. /// <param name="cmd"></param>
  271. public static void SalesReturnBackIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  272. {
  273. try
  274. {
  275. string sql = @"DECLARE @Status VARCHAR(10)
  276. SELECT @Status=sdn.Status FROM ICSSDN sdn
  277. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  278. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  279. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SDNCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
  280. IF (@Status IS NULL)
  281. BEGIN
  282. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  283. RETURN
  284. END
  285. ELSE IF (@Status!='2')
  286. BEGIN
  287. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  288. RETURN
  289. END
  290. UPDATE sdn SET SDNQuantity=ISNULL(SDNQuantity,0)+'{4}'
  291. FROM ICSSDN sdn
  292. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  293. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  294. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SDNCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
  295. IF EXISTS(SELECT a.LotNo FROM ICSSDN sdn
  296. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  297. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  298. 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)
  299. BEGIN
  300. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  301. END";
  302. sql = string.Format(sql, LotNo, WorkPoint, TransCode, TransSequence, Quantity);
  303. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  304. {
  305. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  306. }
  307. }
  308. catch (Exception)
  309. {
  310. throw;
  311. }
  312. }
  313. /// <summary>
  314. /// 销售退货-原条码接口
  315. /// </summary>
  316. /// <param name="TransType"></param>
  317. /// <param name="Identification"></param>
  318. /// <param name="cmd"></param>
  319. public static void SalesReturnBackInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  320. {
  321. try
  322. {
  323. #region ERP
  324. 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,
  325. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,c.SDNDetailID,Enable AS UpdateTodoQuantity
  326. ,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,
  327. 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
  328. INTO #TempERP
  329. FROM ICSWareHouseLotInfoLog a
  330. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  331. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  332. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  333. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  334. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  335. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  336. WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2'
  337. GROUP BY c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,Enable
  338. ,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, ''),
  339. 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, '')
  340. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  341. 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
  342. DROP TABLE #TempERP";
  343. sql = string.Format(sql, Identification);
  344. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  345. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  346. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, Inputstr);
  347. Result result = new Result();
  348. result = JsonConvert.DeserializeObject<Result>(resultStr);
  349. if (result.Success)
  350. {
  351. try
  352. {
  353. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  354. foreach (var item in res)
  355. {
  356. JObject jo = (JObject)item;
  357. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  358. foreach (var detail in resdetail)
  359. {
  360. JObject det = (JObject)detail;
  361. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  362. det["DetailID"].ToString(), jo["SDNNEGCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  363. }
  364. }
  365. }
  366. catch (Exception ex)
  367. {
  368. log.Debug(ex.ToString());
  369. log.Debug(resultStr);
  370. }
  371. }
  372. else
  373. {
  374. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  375. }
  376. #endregion
  377. }
  378. catch (Exception)
  379. {
  380. throw;
  381. }
  382. }
  383. #endregion
  384. }
  385. }