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.

499 lines
35 KiB

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="TransType"></param>
  81. /// <param name="Identification"></param>
  82. /// <param name="cmd"></param>
  83. public static void SalesShipmentDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  84. {
  85. try
  86. {
  87. #region ERP
  88. 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,
  89. 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
  90. ,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,
  91. 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
  92. INTO #TempERP
  93. FROM ICSWareHouseLotInfoLog a
  94. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  95. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  96. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  97. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  98. INNER JOIN ICSSDN b ON a.TransCode=b.SDNCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  99. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  100. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  101. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1' AND a.BusinessCode = '19'
  102. GROUP BY inv.AmountEnable,b.CusCode,a.FromWarehouseCode,b.SDNCode,a.MUSER,a.InvCode,b.SDNDetailID,con.Enable,conStock.Enable
  103. ,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, ''),
  104. 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, '')
  105. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  106. SELECT Costre,Sequence,InvCode,Quantity,Amount,SDNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  107. DROP TABLE #TempERP";
  108. sql = string.Format(sql, Identification);
  109. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  110. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  111. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesDeliveryNoticeURL, Inputstr);
  112. Result result = new Result();
  113. result = JsonConvert.DeserializeObject<Result>(resultStr);
  114. if (result.Success)
  115. {
  116. try
  117. {
  118. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  119. foreach (var item in res)
  120. {
  121. JObject jo = (JObject)item;
  122. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  123. foreach (var detail in resdetail)
  124. {
  125. JObject det = (JObject)detail;
  126. 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()
  127. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  128. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  129. det["DetailID"].ToString(), jo["SSDCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language,BusinessCode);
  130. }
  131. }
  132. }
  133. catch (Exception ex)
  134. {
  135. log.Debug(ex.ToString());
  136. log.Debug(resultStr);
  137. }
  138. }
  139. else
  140. {
  141. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  142. }
  143. #endregion
  144. }
  145. catch (Exception)
  146. {
  147. throw;
  148. }
  149. }
  150. public static void U9SalesShipmentDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  151. {
  152. try
  153. {
  154. #region ERP
  155. 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,
  156. 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
  157. ,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,
  158. 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
  159. INTO #TempERP
  160. FROM ICSWareHouseLotInfoLog a
  161. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  162. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  163. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  164. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  165. INNER JOIN ICSSDN b ON a.TransCode=b.SDNCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  166. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  167. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  168. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1' AND a.BusinessCode = '19'
  169. GROUP BY inv.AmountEnable,b.CusCode,a.FromWarehouseCode,b.SDNCode,a.MUSER,a.InvCode,b.SDNDetailID,con.Enable,conStock.Enable
  170. ,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, ''),
  171. 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
  172. 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
  173. DROP TABLE #TempERP";
  174. sql = string.Format(sql, Identification);
  175. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  176. string Inputstr = DataToJsonHelper.ToJson(ds.Tables[0]);
  177. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9SalesShipDocURL, Inputstr);
  178. Result result = new Result();
  179. result = JsonConvert.DeserializeObject<Result>(resultStr);
  180. if (result.Success)
  181. {
  182. try
  183. {
  184. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  185. foreach (var item in res)
  186. {
  187. JObject jo = (JObject)item;
  188. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  189. foreach (var detail in resdetail)
  190. {
  191. JObject det = (JObject)detail;
  192. 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()
  193. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  194. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  195. det["DetailID"].ToString(), jo["SSDCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  196. }
  197. }
  198. }
  199. catch (Exception ex)
  200. {
  201. log.Debug(ex.ToString());
  202. log.Debug(resultStr);
  203. }
  204. }
  205. else
  206. {
  207. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  208. }
  209. #endregion
  210. }
  211. catch (Exception)
  212. {
  213. throw;
  214. }
  215. }
  216. #endregion
  217. #region 销售退货
  218. /// <summary>
  219. /// 销售退货
  220. /// </summary>
  221. /// <param name="TransCode"></param>
  222. /// <param name="TransSequence"></param>
  223. /// <param name="Quantity"></param>
  224. /// <param name="WorkPoint"></param>
  225. /// <param name="cmd"></param>
  226. public static void SalesShipmentDocNegative(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  227. {
  228. try
  229. {
  230. string sql = @"DECLARE @Status VARCHAR(10)
  231. SELECT @Status=c.Status FROM ICSInventoryLot a
  232. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  233. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  234. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
  235. IF (@Status IS NULL)
  236. BEGIN
  237. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  238. RETURN
  239. END
  240. ELSE IF (@Status!='2')
  241. BEGIN
  242. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  243. RETURN
  244. END
  245. UPDATE c SET SDNQuantity=ISNULL(SDNQuantity,0)+'{2}'
  246. FROM ICSInventoryLot a
  247. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  248. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  249. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
  250. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  251. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  252. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  253. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2' AND c.Quantity<c.SDNQuantity)
  254. BEGIN
  255. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  256. END";
  257. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  258. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  259. {
  260. throw new Exception("销售退货单更新失败!");
  261. }
  262. }
  263. catch (Exception)
  264. {
  265. throw;
  266. }
  267. }
  268. /// <summary>
  269. /// 销售退货接口
  270. /// </summary>
  271. /// <param name="TransType"></param>
  272. /// <param name="Identification"></param>
  273. /// <param name="cmd"></param>
  274. public static void SalesShipmentDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  275. {
  276. try
  277. {
  278. #region ERP
  279. 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,
  280. 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
  281. ,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,
  282. 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
  283. INTO #TempERP
  284. FROM ICSWareHouseLotInfoLog a
  285. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  286. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  287. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  288. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  289. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  290. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  291. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  292. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  293. WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2' AND BusinessCode='{1}'
  294. GROUP BY inv.AmountEnable,c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,con.Enable,conStock.Enable
  295. ,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, ''),
  296. 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, '')
  297. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  298. 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
  299. DROP TABLE #TempERP";
  300. sql = string.Format(sql, Identification,BusinessCode);
  301. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  302. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  303. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, Inputstr);
  304. Result result = new Result();
  305. result = JsonConvert.DeserializeObject<Result>(resultStr);
  306. if (result.Success)
  307. {
  308. try
  309. {
  310. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  311. foreach (var item in res)
  312. {
  313. JObject jo = (JObject)item;
  314. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  315. foreach (var detail in resdetail)
  316. {
  317. JObject det = (JObject)detail;
  318. 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()
  319. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  320. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  321. det["DetailID"].ToString(), jo["SDNNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  322. }
  323. }
  324. }
  325. catch (Exception ex)
  326. {
  327. log.Debug(ex.ToString());
  328. log.Debug(resultStr);
  329. }
  330. }
  331. else
  332. {
  333. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  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,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
  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. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  418. WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2' AND BusinessCode='{1}'
  419. GROUP BY inv.AmountEnable,c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,Enable,conStock.Enable
  420. ,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, ''),
  421. 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, '')
  422. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  423. 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
  424. DROP TABLE #TempERP";
  425. sql = string.Format(sql, Identification,BusinessCode);
  426. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  427. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  428. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, Inputstr);
  429. Result result = new Result();
  430. result = JsonConvert.DeserializeObject<Result>(resultStr);
  431. if (result.Success)
  432. {
  433. try
  434. {
  435. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  436. foreach (var item in res)
  437. {
  438. JObject jo = (JObject)item;
  439. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  440. foreach (var detail in resdetail)
  441. {
  442. JObject det = (JObject)detail;
  443. 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()
  444. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  445. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  446. det["DetailID"].ToString(), jo["SDNNEGCode"].ToString(), det["Sequence"].ToString(), allcol,cmd, language, BusinessCode);
  447. }
  448. }
  449. }
  450. catch (Exception ex)
  451. {
  452. log.Debug(ex.ToString());
  453. log.Debug(resultStr);
  454. }
  455. }
  456. else
  457. {
  458. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  459. }
  460. #endregion
  461. }
  462. catch (Exception)
  463. {
  464. throw;
  465. }
  466. }
  467. #endregion
  468. }
  469. }