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

595 lines
35 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
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
1 year 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 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year 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(updatesql, 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. else
  319. {
  320. Info.T_GERNR = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR[1];
  321. }
  322. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse result = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse();
  323. result = Client.CallZWMS_SK_DO_GZ(Info);
  324. foreach (SAPCallBackDispatchVPN.ZWMS_DO_RETURN resultItem in result.T_RETURN)
  325. {
  326. if (resultItem.ZFLG == "N")
  327. {
  328. IsSuccess = "N";
  329. ErrorMessage += resultItem.ZMESS + "/r/n";
  330. }
  331. }
  332. }
  333. }
  334. }
  335. if (IsSuccess == "N")
  336. {
  337. throw new Exception(ErrorMessage);
  338. }
  339. #endregion
  340. }
  341. catch (Exception)
  342. {
  343. throw;
  344. }
  345. }
  346. #endregion
  347. #region 销售退货-原条码
  348. /// <summary>
  349. /// 销售退货-原条码
  350. /// </summary>
  351. /// <param name="TransCode"></param>
  352. /// <param name="TransSequence"></param>
  353. /// <param name="Quantity"></param>
  354. /// <param name="WorkPoint"></param>
  355. /// <param name="cmd"></param>
  356. public static void SalesReturnBackIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  357. {
  358. try
  359. {
  360. string sql = @"DECLARE @Status VARCHAR(10)
  361. SELECT @Status=sdn.Status FROM ICSSDN sdn
  362. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  363. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  364. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SDNCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
  365. IF (@Status IS NULL)
  366. BEGIN
  367. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  368. RETURN
  369. END
  370. --ELSE IF (@Status!='2')
  371. --BEGIN
  372. --RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  373. --RETURN
  374. --END
  375. UPDATE sdn SET SDNQuantity=ISNULL(SDNQuantity,0)+'{4}'
  376. 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'
  380. IF EXISTS(SELECT a.LotNo FROM ICSSDN sdn
  381. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  382. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  383. 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)
  384. BEGIN
  385. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  386. END";
  387. sql = string.Format(sql, LotNo, WorkPoint, TransCode, TransSequence, Quantity);
  388. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  389. {
  390. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  391. }
  392. }
  393. catch (Exception)
  394. {
  395. throw;
  396. }
  397. }
  398. ///// <summary>
  399. ///// 销售退货-原条码接口
  400. ///// </summary>
  401. ///// <param name="TransType"></param>
  402. ///// <param name="Identification"></param>
  403. ///// <param name="cmd"></param>
  404. //public static void SalesReturnBackInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  405. //{
  406. // try
  407. // {
  408. // #region ERP
  409. // 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,
  410. // a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,c.SDNDetailID,Enable AS UpdateTodoQuantity
  411. // ,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,
  412. // 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
  413. // INTO #TempERP
  414. // FROM ICSWareHouseLotInfoLog a
  415. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  416. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  417. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  418. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  419. // INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  420. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  421. // WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2' AND BusinessCode='{1}'
  422. // GROUP BY c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,Enable
  423. // ,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, ''),
  424. // 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, '')
  425. // SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  426. // 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
  427. // DROP TABLE #TempERP";
  428. // sql = string.Format(sql, Identification, BusinessCode);
  429. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  430. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  431. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, Inputstr);
  432. // Result result = new Result();
  433. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  434. // if (result.Success)
  435. // {
  436. // try
  437. // {
  438. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  439. // foreach (var item in res)
  440. // {
  441. // JObject jo = (JObject)item;
  442. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  443. // foreach (var detail in resdetail)
  444. // {
  445. // JObject det = (JObject)detail;
  446. // 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()
  447. // + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  448. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  449. // det["DetailID"].ToString(), jo["SDNNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  450. // }
  451. // }
  452. // }
  453. // catch (Exception ex)
  454. // {
  455. // log.Debug(ex.ToString());
  456. // log.Debug(resultStr);
  457. // }
  458. // }
  459. // else
  460. // {
  461. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  462. // }
  463. // #endregion
  464. // }
  465. // catch (Exception)
  466. // {
  467. // throw;
  468. // }
  469. //}
  470. /// <summary>
  471. /// 销售退货-原条码接口
  472. /// </summary>
  473. /// <param name="TransType"></param>
  474. /// <param name="Identification"></param>
  475. /// <param name="cmd"></param>
  476. public static void SalesReturnBackInERP(string TransCode, string Identification, SqlCommand cmd, Dictionary<string, string> language, string workPoint)
  477. {
  478. try
  479. {
  480. #region SAP(三层结构)
  481. string IsSuccess = "";
  482. string ErrorMessage = "";
  483. string sql = "";
  484. //string sql = @" select Distinct A.SDNCode,A.WorkPoint from ICSSDN A
  485. // LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.SDNCode AND B.WorkPoint=A.WorkPoint
  486. // where B.Identification='{0}' AND BusinessCode='44'";
  487. //sql = string.Format(sql, Identification);
  488. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  489. //if (dt.Rows.Count > 1)
  490. //{
  491. // throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  492. //}
  493. //for (int i = 0; i < dt.Rows.Count; i++)
  494. //{
  495. string chksql = @"select SUM(Quantity) AS Quantity,SUM(SDNQuantity) AS SDNQuantity from ICSSDN
  496. where SDNCode='{0}' and WorkPoint='{1}'
  497. GROUP BY SDNCode,WorkPoint";
  498. chksql = string.Format(chksql, TransCode, workPoint);
  499. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  500. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) == Convert.ToDecimal(chkdt.Rows[0]["SDNQuantity"]))
  501. {
  502. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ Client = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ();
  503. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1 Info = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1();
  504. List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD> headlist = new List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD>();
  505. SAPCallBackDispatchVPN.ZWMS_DO_HEAD head = new SAPCallBackDispatchVPN.ZWMS_DO_HEAD();
  506. head.VBELN = TransCode;
  507. headlist.Add(head);
  508. Info.T_HEAD = headlist.ToArray();
  509. List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM> ItemList = new List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM>();
  510. List<SAPCallBackDispatchVPN.ZWMS_DO_GERNR> ItemLineList = new List<SAPCallBackDispatchVPN.ZWMS_DO_GERNR>();
  511. Info.T_RETURN = new SAPCallBackDispatchVPN.ZWMS_DO_RETURN[1];
  512. sql = @" select A.SDNCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.SDNQuantity
  513. ,ISNULL(B.BatchCode,'') AS BatchCode from ICSSDN A
  514. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  515. WHERE SDNCode='{0}' AND A.WorkPoint='{1}'";
  516. sql = string.Format(sql, TransCode, workPoint);
  517. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  518. foreach (DataRow dr in Sapdt.Rows)
  519. {
  520. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["SDNQuantity"].ToString()))
  521. {
  522. SAPCallBackDispatchVPN.ZWMS_DO_ITEM Item = new SAPCallBackDispatchVPN.ZWMS_DO_ITEM();
  523. SAPCallBackDispatchVPN.ZWMS_DO_GERNR ItemLine = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR();
  524. Item.VBELN = dr["SDNCode"].ToString();
  525. Item.POSNR = dr["SAPSequence"].ToString();
  526. Item.LFIMG = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  527. ItemList.Add(Item);
  528. if (dr["BatchCode"].ToString() != "")
  529. {
  530. ItemLine.VBELN = dr["SDNCode"].ToString();
  531. ItemLine.POSNR = dr["SAPSequence"].ToString();
  532. ItemLine.GERNR = dr["BatchCode"].ToString();
  533. ItemLineList.Add(ItemLine);
  534. }
  535. }
  536. }
  537. if (ItemList.Count > 0)
  538. {
  539. Info.T_ITEM = ItemList.ToArray();
  540. if (ItemLineList.Count > 0)
  541. {
  542. Info.T_GERNR = ItemLineList.ToArray();
  543. }
  544. else
  545. {
  546. Info.T_GERNR = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR[1];
  547. }
  548. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse result = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse();
  549. result = Client.CallZWMS_SK_DO_GZ(Info);
  550. foreach (SAPCallBackDispatchVPN.ZWMS_DO_RETURN resultItem in result.T_RETURN)
  551. {
  552. if (resultItem.ZFLG == "N")
  553. {
  554. IsSuccess = "N";
  555. ErrorMessage += resultItem.ZMESS + "/r/n";
  556. }
  557. }
  558. }
  559. }
  560. //}
  561. if (IsSuccess == "N")
  562. {
  563. throw new Exception(ErrorMessage);
  564. }
  565. #endregion
  566. }
  567. catch (Exception)
  568. {
  569. throw;
  570. }
  571. }
  572. #endregion
  573. }
  574. }