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

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