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

436 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
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 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
2 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, string BusinessCode)
  75. {
  76. try
  77. {
  78. #region SAP
  79. string IsSuccess = "";
  80. string ErrorMessage = "";
  81. string sql = @" select Distinct A.SDNCode,A.WorkPoint from ICSSDN A
  82. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.SDNCode AND B.WorkPoint=A.WorkPoint
  83. where B.Identification='{0}' AND BusinessCode='19'";
  84. sql = string.Format(sql, Identification);
  85. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  86. if (dt.Rows.Count > 1)
  87. {
  88. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  89. }
  90. for (int i = 0; i < dt.Rows.Count; i++)
  91. {
  92. string chksql = @"select SUM(Quantity) AS Quantity,SUM(SDNQuantity) AS SDNQuantity from ICSSDN
  93. where SDNCode='{0}' and WorkPoint='{1}'
  94. GROUP BY SDNCode,WorkPoint";
  95. chksql = string.Format(chksql, dt.Rows[i]["SDNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  96. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  97. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["SDNQuantity"]))
  98. {
  99. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo203"), chkdt.Rows[0]["Quantity"].ToString(), chkdt.Rows[0]["SDNQuantity"].ToString()));//单次提交数量卡控(必须整单提交)
  100. }
  101. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ Client = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ();
  102. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1 Info = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1();
  103. List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD> headlist = new List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD>();
  104. SAPCallBackDispatchVPN.ZWMS_DO_HEAD head = new SAPCallBackDispatchVPN.ZWMS_DO_HEAD();
  105. head.VBELN = dt.Rows[i]["SDNCode"].ToString();
  106. headlist.Add(head);
  107. Info.T_HEAD = headlist.ToArray();
  108. List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM> ItemList = new List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM>();
  109. Info.T_GERNR = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR[1];
  110. Info.T_RETURN = new SAPCallBackDispatchVPN.ZWMS_DO_RETURN[1];
  111. sql = @" select A.SDNCode,A.Sequence,A.Quantity,A.SDNQuantity,B.BatchCode from ICSSDN A
  112. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  113. WHERE SDNCode='{0}' AND A.WorkPoint='{1}'";
  114. sql = string.Format(sql, dt.Rows[i]["SDNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  115. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  116. foreach (DataRow dr in Sapdt.Rows)
  117. {
  118. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["SDNQuantity"].ToString()))
  119. {
  120. SAPCallBackDispatchVPN.ZWMS_DO_ITEM Item = new SAPCallBackDispatchVPN.ZWMS_DO_ITEM();
  121. Item.VBELN = dr["SDNCode"].ToString();
  122. Item.POSNR = dr["Sequence"].ToString();
  123. Item.LFIMG = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  124. Item.SERAIL = dr["BatchCode"].ToString();
  125. ItemList.Add(Item);
  126. }
  127. }
  128. if (ItemList.Count > 0)
  129. {
  130. Info.T_ITEM = ItemList.ToArray();
  131. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse result = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse();
  132. result = Client.CallZWMS_SK_DO_GZ(Info);
  133. foreach (SAPCallBackDispatchVPN.ZWMS_DO_RETURN resultItem in result.T_RETURN)
  134. {
  135. if (resultItem.ZFLG == "N")
  136. {
  137. IsSuccess = "N";
  138. ErrorMessage += resultItem.ZMESS + "/r/n";
  139. }
  140. }
  141. }
  142. }
  143. if (IsSuccess == "N")
  144. {
  145. throw new Exception(ErrorMessage);
  146. }
  147. #endregion
  148. }
  149. catch (Exception)
  150. {
  151. throw;
  152. }
  153. }
  154. #endregion
  155. #region 销售退货
  156. /// <summary>
  157. /// 销售退货
  158. /// </summary>
  159. /// <param name="TransCode"></param>
  160. /// <param name="TransSequence"></param>
  161. /// <param name="Quantity"></param>
  162. /// <param name="WorkPoint"></param>
  163. /// <param name="cmd"></param>
  164. public static void SalesShipmentDocNegative(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  165. {
  166. try
  167. {
  168. string sql = @"DECLARE @Status VARCHAR(10)
  169. SELECT @Status=c.Status 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 (@Status IS NULL)
  174. BEGIN
  175. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  176. RETURN
  177. END
  178. --ELSE IF (@Status!='2')
  179. --BEGIN
  180. -- RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  181. -- RETURN
  182. --END
  183. UPDATE c SET SDNQuantity=ISNULL(SDNQuantity,0)+'{2}'
  184. FROM ICSInventoryLot a
  185. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  186. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  187. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
  188. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  189. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  190. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  191. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2' AND c.Quantity<c.SDNQuantity)
  192. BEGIN
  193. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  194. END";
  195. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  196. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  197. {
  198. throw new Exception("销售退货单更新失败!");
  199. }
  200. }
  201. catch (Exception)
  202. {
  203. throw;
  204. }
  205. }
  206. /// <summary>
  207. /// 销售退货接口
  208. /// </summary>
  209. /// <param name="TransType"></param>
  210. /// <param name="Identification"></param>
  211. /// <param name="cmd"></param>
  212. public static void SalesShipmentDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  213. {
  214. try
  215. {
  216. #region SAP
  217. string IsSuccess = "";
  218. string ErrorMessage = "";
  219. string sql = @" select Distinct A.SDNCode,A.WorkPoint from ICSSDN A
  220. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.SDNCode AND B.WorkPoint=A.WorkPoint
  221. where B.Identification='{0}' AND BusinessCode='18'";
  222. sql = string.Format(sql, Identification);
  223. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  224. if (dt.Rows.Count > 1)
  225. {
  226. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  227. }
  228. for (int i = 0; i < dt.Rows.Count; i++)
  229. {
  230. string chksql = @"select SUM(Quantity) AS Quantity,SUM(SDNQuantity) AS SDNQuantity from ICSSDN
  231. where SDNCode='{0}' and WorkPoint='{1}'
  232. GROUP BY SDNCode,WorkPoint";
  233. chksql = string.Format(chksql, dt.Rows[i]["SDNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  234. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  235. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["SDNQuantity"]))
  236. {
  237. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo203"), chkdt.Rows[0]["Quantity"].ToString(), chkdt.Rows[0]["SDNQuantity"].ToString()));//单次提交数量卡控(必须整单提交)
  238. }
  239. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ Client = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ();
  240. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1 Info = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1();
  241. List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD> headlist = new List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD>();
  242. SAPCallBackDispatchVPN.ZWMS_DO_HEAD head = new SAPCallBackDispatchVPN.ZWMS_DO_HEAD();
  243. head.VBELN = dt.Rows[i]["SDNCode"].ToString();
  244. headlist.Add(head);
  245. Info.T_HEAD = headlist.ToArray();
  246. List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM> ItemList = new List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM>();
  247. Info.T_GERNR = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR[1];
  248. Info.T_RETURN = new SAPCallBackDispatchVPN.ZWMS_DO_RETURN[1];
  249. sql = @" select A.SDNCode,A.Sequence,A.Quantity,A.SDNQuantity,B.BatchCode from ICSSDN A
  250. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  251. WHERE SDNCode='{0}' AND A.WorkPoint='{1}'";
  252. sql = string.Format(sql, dt.Rows[i]["SDNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  253. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  254. foreach (DataRow dr in Sapdt.Rows)
  255. {
  256. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["SDNQuantity"].ToString()))
  257. {
  258. SAPCallBackDispatchVPN.ZWMS_DO_ITEM Item = new SAPCallBackDispatchVPN.ZWMS_DO_ITEM();
  259. Item.VBELN = dr["SDNCode"].ToString();
  260. Item.POSNR = dr["Sequence"].ToString();
  261. Item.LFIMG = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  262. Item.SERAIL = dr["BatchCode"].ToString();
  263. ItemList.Add(Item);
  264. }
  265. }
  266. if (ItemList.Count > 0)
  267. {
  268. Info.T_ITEM = ItemList.ToArray();
  269. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse result = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse();
  270. result = Client.CallZWMS_SK_DO_GZ(Info);
  271. foreach (SAPCallBackDispatchVPN.ZWMS_DO_RETURN resultItem in result.T_RETURN)
  272. {
  273. if (resultItem.ZFLG == "N")
  274. {
  275. IsSuccess = "N";
  276. ErrorMessage += resultItem.ZMESS + "/r/n";
  277. }
  278. }
  279. }
  280. }
  281. if (IsSuccess == "N")
  282. {
  283. throw new Exception(ErrorMessage);
  284. }
  285. #endregion
  286. }
  287. catch (Exception)
  288. {
  289. throw;
  290. }
  291. }
  292. #endregion
  293. #region 销售退货-原条码
  294. /// <summary>
  295. /// 销售退货-原条码
  296. /// </summary>
  297. /// <param name="TransCode"></param>
  298. /// <param name="TransSequence"></param>
  299. /// <param name="Quantity"></param>
  300. /// <param name="WorkPoint"></param>
  301. /// <param name="cmd"></param>
  302. public static void SalesReturnBackIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  303. {
  304. try
  305. {
  306. string sql = @"DECLARE @Status VARCHAR(10)
  307. SELECT @Status=sdn.Status FROM ICSSDN sdn
  308. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  309. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  310. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SDNCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
  311. IF (@Status IS NULL)
  312. BEGIN
  313. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  314. RETURN
  315. END
  316. ELSE IF (@Status!='2')
  317. BEGIN
  318. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  319. RETURN
  320. END
  321. UPDATE sdn SET SDNQuantity=ISNULL(SDNQuantity,0)+'{4}'
  322. FROM ICSSDN sdn
  323. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  324. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  325. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SDNCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
  326. IF EXISTS(SELECT a.LotNo FROM ICSSDN sdn
  327. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  328. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  329. 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)
  330. BEGIN
  331. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  332. END";
  333. sql = string.Format(sql, LotNo, WorkPoint, TransCode, TransSequence, Quantity);
  334. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  335. {
  336. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  337. }
  338. }
  339. catch (Exception)
  340. {
  341. throw;
  342. }
  343. }
  344. /// <summary>
  345. /// 销售退货-原条码接口
  346. /// </summary>
  347. /// <param name="TransType"></param>
  348. /// <param name="Identification"></param>
  349. /// <param name="cmd"></param>
  350. public static void SalesReturnBackInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  351. {
  352. try
  353. {
  354. #region ERP
  355. 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,
  356. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,c.SDNDetailID,Enable AS UpdateTodoQuantity
  357. ,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,
  358. 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
  359. INTO #TempERP
  360. FROM ICSWareHouseLotInfoLog a
  361. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  362. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  363. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  364. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  365. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  366. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  367. WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2' AND BusinessCode='{1}'
  368. GROUP BY c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,Enable
  369. ,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, ''),
  370. 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, '')
  371. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  372. 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
  373. DROP TABLE #TempERP";
  374. sql = string.Format(sql, Identification, BusinessCode);
  375. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  376. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  377. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, Inputstr);
  378. Result result = new Result();
  379. result = JsonConvert.DeserializeObject<Result>(resultStr);
  380. if (result.Success)
  381. {
  382. try
  383. {
  384. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  385. foreach (var item in res)
  386. {
  387. JObject jo = (JObject)item;
  388. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  389. foreach (var detail in resdetail)
  390. {
  391. JObject det = (JObject)detail;
  392. 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()
  393. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  394. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  395. det["DetailID"].ToString(), jo["SDNNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  396. }
  397. }
  398. }
  399. catch (Exception ex)
  400. {
  401. log.Debug(ex.ToString());
  402. log.Debug(resultStr);
  403. }
  404. }
  405. else
  406. {
  407. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  408. }
  409. #endregion
  410. }
  411. catch (Exception)
  412. {
  413. throw;
  414. }
  415. }
  416. #endregion
  417. }
  418. }