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.

560 lines
38 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year 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 chekksql = @"select c.EATTRIBUTE1 FROM ICSSDN a
  36. // INNER JOIN ICSInventory c on a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  37. // WHERE a.Sequence='{2}' AND a.SDNCode='{0}' AND a.WorkPoint='{1}' and c.AmountEnable='1'";
  38. //chekksql = string.Format(chekksql, TransCode, WorkPoint, TransSequence);
  39. //DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  40. //if (dta.Rows.Count > 0)
  41. //{
  42. // Quantity = (decimal.Parse(Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  43. //}
  44. string sql = @"DECLARE @Status VARCHAR(10)
  45. SELECT @Status=a.Status FROM ICSSDN a
  46. WHERE a.SDNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='1'
  47. IF (@Status IS NULL)
  48. BEGIN
  49. RAISERROR('" + language.GetNameByCode("WMSAPIInfo139") + @"',16,1);
  50. RETURN
  51. END
  52. ELSE IF (@Status!='2')
  53. BEGIN
  54. RAISERROR('" + language.GetNameByCode("WMSAPIInfo140") + @"',16,1);
  55. RETURN
  56. END
  57. UPDATE a SET SDNQuantity=ISNULL(SDNQuantity,0)+'{2}'
  58. FROM ICSSDN a
  59. WHERE a.SDNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='1'
  60. IF EXISTS(SELECT a.ID FROM ICSSDN a
  61. WHERE a.SDNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='1' AND a.Quantity<a.SDNQuantity)
  62. BEGIN
  63. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  64. RETURN
  65. END";
  66. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  67. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  68. {
  69. throw new Exception(language.GetNameByCode("WMSAPIInfo141"));//"销售领料单更新失败!");
  70. }
  71. }
  72. catch (Exception)
  73. {
  74. throw;
  75. }
  76. }
  77. /// <summary>
  78. /// 销售出库
  79. /// </summary>
  80. /// <param name="TransCode"></param>
  81. /// <param name="TransSequence"></param>
  82. /// <param name="Quantity"></param>
  83. /// <param name="WorkPoint"></param>
  84. /// <param name="cmd"></param>
  85. public static void AMSalesShipmentDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  86. {
  87. try
  88. {
  89. //string chekksql = @"select c.EATTRIBUTE1 FROM ICSSDN a
  90. // INNER JOIN ICSInventory c on a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  91. // WHERE a.Sequence='{2}' AND a.SDNCode='{0}' AND a.WorkPoint='{1}' and c.AmountEnable='1'";
  92. //chekksql = string.Format(chekksql, TransCode, WorkPoint, TransSequence);
  93. //DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  94. //if (dta.Rows.Count > 0)
  95. //{
  96. // Quantity = (decimal.Parse(Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  97. //}
  98. string sql = @"DECLARE @Status VARCHAR(10)
  99. SELECT @Status=a.Status FROM ICSSDN a
  100. WHERE a.SDNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='1'
  101. IF (@Status IS NULL)
  102. BEGIN
  103. RAISERROR('" + language.GetNameByCode("WMSAPIInfo139") + @"',16,1);
  104. RETURN
  105. END
  106. ELSE IF (@Status!='2')
  107. BEGIN
  108. RAISERROR('" + language.GetNameByCode("WMSAPIInfo140") + @"',16,1);
  109. RETURN
  110. END
  111. UPDATE a SET SDNQuantity=ISNULL(SDNQuantity,0)+'{2}'
  112. FROM ICSSDN a
  113. WHERE a.SDNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='1'
  114. IF EXISTS(SELECT a.ID FROM ICSSDN a
  115. WHERE a.SDNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='1' AND a.Quantity<a.SDNQuantity)
  116. BEGIN
  117. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  118. RETURN
  119. END";
  120. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  121. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  122. {
  123. throw new Exception(language.GetNameByCode("WMSAPIInfo141"));//"销售领料单更新失败!");
  124. }
  125. }
  126. catch (Exception)
  127. {
  128. throw;
  129. }
  130. }
  131. /// <summary>
  132. /// 销售出库接口
  133. /// </summary>
  134. /// <param name="TransType"></param>
  135. /// <param name="Identification"></param>
  136. /// <param name="cmd"></param>
  137. public static void SalesShipmentDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  138. {
  139. try
  140. {
  141. #region ERP
  142. 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,
  143. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount, b.SDNDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  144. ,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,
  145. 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
  146. INTO #TempERP
  147. FROM ICSWareHouseLotInfoLog a
  148. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  149. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  150. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  151. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  152. INNER JOIN ICSSDN b ON a.TransCode=b.SDNCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  153. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  154. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  155. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1' AND a.BusinessCode = '19'
  156. GROUP BY inv.AmountEnable,b.CusCode,a.FromWarehouseCode,b.SDNCode,a.MUSER,a.InvCode,b.SDNDetailID,con.Enable,conStock.Enable
  157. ,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, ''),
  158. 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, '')
  159. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  160. SELECT Costre,Sequence,InvCode,Quantity,Amount,SDNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  161. DROP TABLE #TempERP";
  162. sql = string.Format(sql, Identification);
  163. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  164. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  165. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesDeliveryNoticeURL, Inputstr);
  166. Result result = new Result();
  167. result = JsonConvert.DeserializeObject<Result>(resultStr);
  168. if (result.Success)
  169. {
  170. try
  171. {
  172. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  173. foreach (var item in res)
  174. {
  175. JObject jo = (JObject)item;
  176. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  177. foreach (var detail in resdetail)
  178. {
  179. JObject det = (JObject)detail;
  180. string allcol = jo["WHCode"].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()
  181. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  182. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  183. det["DetailID"].ToString(), jo["SSDCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language,BusinessCode);
  184. }
  185. }
  186. }
  187. catch (Exception ex)
  188. {
  189. log.Debug(ex.ToString());
  190. log.Debug(resultStr);
  191. }
  192. }
  193. else
  194. {
  195. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  196. }
  197. #endregion
  198. }
  199. catch (Exception)
  200. {
  201. throw;
  202. }
  203. }
  204. public static void U9SalesShipmentDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  205. {
  206. try
  207. {
  208. #region ERP
  209. 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,
  210. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount, b.SDNDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  211. ,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,
  212. 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 ,b.SOCode,b.SOSequence as SrcDocSubLineNo
  213. INTO #TempERP
  214. FROM ICSWareHouseLotInfoLog a
  215. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  216. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  217. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  218. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  219. INNER JOIN ICSSDN b ON a.TransCode=b.SDNCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  220. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  221. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  222. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1' AND a.BusinessCode = '19'
  223. GROUP BY inv.AmountEnable,b.CusCode,a.FromWarehouseCode,b.SDNCode,a.MUSER,a.InvCode,b.SDNDetailID,con.Enable,conStock.Enable
  224. ,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, ''),
  225. 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, ''),b.SOCode,b.SOSequence
  226. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SOCode AS SDNCode,SrcDocSubLineNo,MUSER AS [User],SYSDATETIME() AS ShipDate,'ST1' as ShipDocTypeCode ,cast(0 as bit) as SOIsConsign,UpdateTodoQuantity,UpdateStock,InvCode,Quantity,Amount,SDNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  227. DROP TABLE #TempERP";
  228. sql = string.Format(sql, Identification);
  229. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  230. string Inputstr = DataToJsonHelper.ToJson(ds.Tables[0]);
  231. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9SalesShipDocURL, Inputstr);
  232. Result result = new Result();
  233. result = JsonConvert.DeserializeObject<Result>(resultStr);
  234. if (result.Success)
  235. {
  236. try
  237. {
  238. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  239. foreach (var item in res)
  240. {
  241. JObject jo = (JObject)item;
  242. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  243. foreach (var detail in resdetail)
  244. {
  245. JObject det = (JObject)detail;
  246. string allcol = jo["WHCode"].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()
  247. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  248. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  249. det["DetailID"].ToString(), jo["SSDCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  250. }
  251. }
  252. }
  253. catch (Exception ex)
  254. {
  255. log.Debug(ex.ToString());
  256. log.Debug(resultStr);
  257. }
  258. }
  259. else
  260. {
  261. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  262. }
  263. #endregion
  264. }
  265. catch (Exception)
  266. {
  267. throw;
  268. }
  269. }
  270. #endregion
  271. #region 销售退货
  272. /// <summary>
  273. /// 销售退货
  274. /// </summary>
  275. /// <param name="TransCode"></param>
  276. /// <param name="TransSequence"></param>
  277. /// <param name="Quantity"></param>
  278. /// <param name="WorkPoint"></param>
  279. /// <param name="cmd"></param>
  280. public static void SalesShipmentDocNegative(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  281. {
  282. try
  283. {
  284. string sql = @"DECLARE @Status VARCHAR(10)
  285. SELECT @Status=c.Status FROM ICSInventoryLot a
  286. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  287. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  288. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
  289. IF (@Status IS NULL)
  290. BEGIN
  291. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  292. RETURN
  293. END
  294. ELSE IF (@Status!='2')
  295. BEGIN
  296. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  297. RETURN
  298. END
  299. UPDATE c SET SDNQuantity=ISNULL(SDNQuantity,0)+'{2}'
  300. FROM ICSInventoryLot a
  301. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  302. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  303. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
  304. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  305. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  306. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  307. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2' AND c.Quantity<c.SDNQuantity)
  308. BEGIN
  309. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  310. END";
  311. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  312. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  313. {
  314. throw new Exception("销售退货单更新失败!");
  315. }
  316. }
  317. catch (Exception)
  318. {
  319. throw;
  320. }
  321. }
  322. /// <summary>
  323. /// 销售退货接口
  324. /// </summary>
  325. /// <param name="TransType"></param>
  326. /// <param name="Identification"></param>
  327. /// <param name="cmd"></param>
  328. public static void SalesShipmentDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  329. {
  330. try
  331. {
  332. #region ERP
  333. 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,
  334. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,c.SDNDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  335. ,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,
  336. 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
  337. INTO #TempERP
  338. FROM ICSWareHouseLotInfoLog a
  339. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  340. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  341. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  342. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  343. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  344. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  345. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  346. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  347. WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2' AND BusinessCode='{1}'
  348. GROUP BY inv.AmountEnable,c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,con.Enable,conStock.Enable
  349. ,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, ''),
  350. 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, '')
  351. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  352. 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
  353. DROP TABLE #TempERP";
  354. sql = string.Format(sql, Identification,BusinessCode);
  355. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  356. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  357. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, Inputstr);
  358. Result result = new Result();
  359. result = JsonConvert.DeserializeObject<Result>(resultStr);
  360. if (result.Success)
  361. {
  362. try
  363. {
  364. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  365. foreach (var item in res)
  366. {
  367. JObject jo = (JObject)item;
  368. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  369. foreach (var detail in resdetail)
  370. {
  371. JObject det = (JObject)detail;
  372. string allcol = jo["WHCode"].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()
  373. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  374. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  375. det["DetailID"].ToString(), jo["SDNNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  376. }
  377. }
  378. }
  379. catch (Exception ex)
  380. {
  381. log.Debug(ex.ToString());
  382. log.Debug(resultStr);
  383. }
  384. }
  385. else
  386. {
  387. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  388. }
  389. #endregion
  390. }
  391. catch (Exception)
  392. {
  393. throw;
  394. }
  395. }
  396. #endregion
  397. #region 销售退货-原条码
  398. /// <summary>
  399. /// 销售退货-原条码
  400. /// </summary>
  401. /// <param name="TransCode"></param>
  402. /// <param name="TransSequence"></param>
  403. /// <param name="Quantity"></param>
  404. /// <param name="WorkPoint"></param>
  405. /// <param name="cmd"></param>
  406. public static void SalesReturnBackIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  407. {
  408. try
  409. {
  410. string sql = @"DECLARE @Status VARCHAR(10)
  411. SELECT @Status=sdn.Status FROM ICSSDN sdn
  412. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  413. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  414. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SDNCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
  415. IF (@Status IS NULL)
  416. BEGIN
  417. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  418. RETURN
  419. END
  420. ELSE IF (@Status!='2')
  421. BEGIN
  422. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  423. RETURN
  424. END
  425. UPDATE sdn SET SDNQuantity=ISNULL(SDNQuantity,0)+'{4}'
  426. FROM ICSSDN sdn
  427. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  428. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  429. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SDNCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
  430. IF EXISTS(SELECT a.LotNo FROM ICSSDN sdn
  431. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  432. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  433. 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)
  434. BEGIN
  435. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  436. END";
  437. sql = string.Format(sql, LotNo, WorkPoint, TransCode, TransSequence, Quantity);
  438. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  439. {
  440. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  441. }
  442. }
  443. catch (Exception)
  444. {
  445. throw;
  446. }
  447. }
  448. /// <summary>
  449. /// 销售退货-原条码接口
  450. /// </summary>
  451. /// <param name="TransType"></param>
  452. /// <param name="Identification"></param>
  453. /// <param name="cmd"></param>
  454. public static void SalesReturnBackInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  455. {
  456. try
  457. {
  458. #region ERP
  459. 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,
  460. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,c.SDNDetailID,Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  461. ,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,
  462. 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
  463. INTO #TempERP
  464. FROM ICSWareHouseLotInfoLog a
  465. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  466. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  467. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  468. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  469. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  470. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  471. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  472. WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2' AND BusinessCode='{1}'
  473. GROUP BY inv.AmountEnable,c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,Enable,conStock.Enable
  474. ,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, ''),
  475. 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, '')
  476. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  477. 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
  478. DROP TABLE #TempERP";
  479. sql = string.Format(sql, Identification,BusinessCode);
  480. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  481. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  482. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, Inputstr);
  483. Result result = new Result();
  484. result = JsonConvert.DeserializeObject<Result>(resultStr);
  485. if (result.Success)
  486. {
  487. try
  488. {
  489. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  490. foreach (var item in res)
  491. {
  492. JObject jo = (JObject)item;
  493. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  494. foreach (var detail in resdetail)
  495. {
  496. JObject det = (JObject)detail;
  497. string allcol = jo["WHCode"].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()
  498. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  499. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  500. det["DetailID"].ToString(), jo["SDNNEGCode"].ToString(), det["Sequence"].ToString(), allcol,cmd, language, BusinessCode);
  501. }
  502. }
  503. }
  504. catch (Exception ex)
  505. {
  506. log.Debug(ex.ToString());
  507. log.Debug(resultStr);
  508. }
  509. }
  510. else
  511. {
  512. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  513. }
  514. #endregion
  515. }
  516. catch (Exception)
  517. {
  518. throw;
  519. }
  520. }
  521. #endregion
  522. }
  523. }