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.

1486 lines
107 KiB

3 weeks 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,string TransID, string CourierCode)
  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.id='{4}' 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.id='{4}' 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.id='{4}' 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, TransID, CourierCode);
  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 ERP
  79. string sql = @"--+b.SOCode
  80. SELECT b.CusCode+a.FromWarehouseCode+b.SDNCode+a.MUSER AS Costre
  81. ,a.TransCode+a.TransSequence+b.CusCode+a.FromWarehouseCode+b.SDNCode+b.SOCode+a.MUSER AS Costre2
  82. ,b.CusCode,a.FromWarehouseCode AS WarehouseCode,b.SDNCode,b.SOCode,b.SOSequence,a.MUSER,ROW_NUMBER() OVER (ORDER BY b.CusCode,a.FromWarehouseCode,b.SDNCode,b.SDNDetailID,a.InvCode) AS Sequence,
  83. 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,conWhCode.Enable AS ErpWhCode
  84. ,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,
  85. 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
  86. ,b.SDNID
  87. INTO #TempERP
  88. FROM ICSWareHouseLotInfoLog a
  89. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  90. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  91. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  92. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  93. INNER JOIN ICSSDN b ON a.TransCode=b.SDNCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint
  94. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  95. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  96. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  97. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1' AND a.BusinessCode = '{1}'
  98. GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,b.SDNID,b.CusCode,a.FromWarehouseCode,b.SDNCode,b.SOCode,b.SOSequence,a.MUSER,a.InvCode,b.SDNDetailID,con.Enable,conStock.Enable
  99. ,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, ''),
  100. 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, '')
  101. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock,SDNID FROM #TempERP
  102. SELECT Costre,Costre2,Sequence,SOCode,SOSequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Amount,SDNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  103. SELECT a.LotNo,a.Quantity,lot.ExpirationDate,b.EATTRIBUTE3 AS TrackingNO,
  104. a.TransCode+a.TransSequence+b.CusCode+a.FromWarehouseCode+b.SDNCode+b.SOCode+a.MUSER AS Costre2
  105. FROM ICSWareHouseLotInfoLog a
  106. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  107. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  108. INNER JOIN ICSSDN b ON a.TransCode=b.SDNCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint
  109. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1' AND a.BusinessCode = '{1}'
  110. DROP TABLE #TempERP";//--分组去除了SOCode SOSequence;(重新加上了,改为表体中)
  111. sql = string.Format(sql, Identification, BusinessCode);
  112. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  113. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  114. //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
  115. log.Debug("销售发货ERP接口传参:" + Environment.NewLine + Inputstr);
  116. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesDeliveryNoticeURL, Inputstr);
  117. Result result = new Result();
  118. result = JsonConvert.DeserializeObject<Result>(resultStr);
  119. if (result.Success)
  120. {
  121. try
  122. {
  123. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  124. foreach (var item in res)
  125. {
  126. JObject jo = (JObject)item;
  127. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  128. foreach (var detail in resdetail)
  129. {
  130. JObject det = (JObject)detail;
  131. 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()
  132. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  133. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  134. det["DetailID"].ToString(), jo["SSDCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language,BusinessCode);
  135. }
  136. }
  137. }
  138. catch (Exception ex)
  139. {
  140. log.Debug(ex.ToString());
  141. log.Debug(resultStr);
  142. }
  143. }
  144. else
  145. {
  146. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  147. }
  148. #endregion
  149. }
  150. catch (Exception)
  151. {
  152. throw;
  153. }
  154. }
  155. public static void U9SalesShipmentDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  156. {
  157. try
  158. {
  159. #region ERP
  160. 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,
  161. 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
  162. ,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,
  163. 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,b.EATTRIBUTE2 as PrivateDescSeg3
  164. INTO #TempERP
  165. FROM ICSWareHouseLotInfoLog a
  166. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  167. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  168. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  169. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  170. INNER JOIN ICSSDN b ON a.TransCode=b.SDNCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  171. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  172. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  173. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1' AND a.BusinessCode = '19'
  174. GROUP BY inv.AmountEnable,b.CusCode,a.FromWarehouseCode,b.SDNCode,a.MUSER,a.InvCode,b.SDNDetailID,con.Enable,conStock.Enable
  175. ,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, ''),
  176. 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,b.EATTRIBUTE2
  177. 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,PrivateDescSeg3 FROM #TempERP
  178. DROP TABLE #TempERP";
  179. sql = string.Format(sql, Identification);
  180. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  181. string Inputstr = DataToJsonHelper.ToJson(ds.Tables[0]);
  182. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9SalesShipDocURL, Inputstr);
  183. Result result = new Result();
  184. result = JsonConvert.DeserializeObject<Result>(resultStr);
  185. if (result.Success)
  186. {
  187. try
  188. {
  189. if (result.Data.ToString() != "")
  190. {
  191. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  192. foreach (var item in res)
  193. {
  194. JObject jo = (JObject)item;
  195. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  196. foreach (var detail in resdetail)
  197. {
  198. JObject det = (JObject)detail;
  199. 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()
  200. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  201. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  202. det["DetailID"].ToString(), jo["SSDCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  203. }
  204. }
  205. }
  206. }
  207. catch (Exception ex)
  208. {
  209. log.Debug(ex.ToString());
  210. log.Debug(resultStr);
  211. }
  212. }
  213. else
  214. {
  215. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  216. }
  217. #endregion
  218. }
  219. catch (Exception)
  220. {
  221. throw;
  222. }
  223. }
  224. #endregion
  225. #region 销售出库-出库单
  226. /// <summary>
  227. /// 销售出库-出库单
  228. /// </summary>
  229. /// <param name="TransCode"></param>
  230. /// <param name="TransSequence"></param>
  231. /// <param name="Quantity"></param>
  232. /// <param name="WorkPoint"></param>
  233. /// <param name="cmd"></param>
  234. public static void SalesShipmentOutDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string TransID, string CourierCode)
  235. {
  236. try
  237. {
  238. string sql = string.Empty;
  239. if (string.IsNullOrWhiteSpace(TransID))
  240. {
  241. sql = @"DECLARE @Status VARCHAR(10)
  242. SELECT @Status=a.Status FROM ICSSSD a
  243. WHERE a.SSDCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='1'
  244. IF (@Status IS NULL)
  245. BEGIN
  246. RAISERROR('" + language.GetNameByCode("WMSAPIInfo139") + @"',16,1);
  247. RETURN
  248. END
  249. ELSE IF (@Status!='1')
  250. BEGIN
  251. RAISERROR('" + language.GetNameByCode("WMSAPIInfo140") + @"',16,1);
  252. RETURN
  253. END
  254. UPDATE a SET SSDQuantity=ISNULL(SSDQuantity,0)+'{2}',EATTRIBUTE3='{5}'
  255. FROM ICSSSD a
  256. WHERE a.SSDCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='1'
  257. IF EXISTS(SELECT a.ID FROM ICSSSD a
  258. WHERE a.SSDCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='1' AND a.Quantity<a.SSDQuantity)
  259. BEGIN
  260. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  261. RETURN
  262. END";
  263. }
  264. else
  265. {
  266. sql = @"DECLARE @Status VARCHAR(10)
  267. SELECT @Status=a.Status FROM ICSSSD a
  268. WHERE a.SSDCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}' AND a.Type='1'
  269. IF (@Status IS NULL)
  270. BEGIN
  271. RAISERROR('" + language.GetNameByCode("WMSAPIInfo139") + @"',16,1);
  272. RETURN
  273. END
  274. ELSE IF (@Status!='1')
  275. BEGIN
  276. RAISERROR('" + language.GetNameByCode("WMSAPIInfo140") + @"',16,1);
  277. RETURN
  278. END
  279. UPDATE a SET SSDQuantity=ISNULL(SSDQuantity,0)+'{2}',EATTRIBUTE3='{5}'
  280. FROM ICSSSD a
  281. WHERE a.SSDCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}' AND a.Type='1'
  282. IF EXISTS(SELECT a.ID FROM ICSSSD a
  283. WHERE a.SSDCode='{0}' AND a.Sequence='{3}' and a.id='{4}' and a.WorkPoint='{1}' AND a.Type='1' AND a.Quantity<a.SSDQuantity)
  284. BEGIN
  285. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  286. RETURN
  287. END";
  288. }
  289. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID, CourierCode);
  290. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  291. {
  292. throw new Exception(language.GetNameByCode("WMSAPIInfo141"));//"销售领料单更新失败!");
  293. }
  294. }
  295. catch (Exception)
  296. {
  297. throw;
  298. }
  299. }
  300. /// <summary>
  301. /// 销售出库-出库单接口
  302. /// </summary>
  303. /// <param name="TransType"></param>
  304. /// <param name="Identification"></param>
  305. /// <param name="cmd"></param>
  306. public static void SalesShipmentDocOutERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode,string UserCode)
  307. {
  308. string Inputstr2 = "";
  309. string resultStr = "";
  310. Result result = new Result();
  311. try
  312. {
  313. string sql = "";
  314. #region ERP开立状态单据审核
  315. if (DBHelper.IsPNU9())
  316. {
  317. sql = @"SELECT b.CusCode+a.FromWarehouseCode+b.SSDCode+a.MUSER AS Costre
  318. ,a.TransCode+a.TransSequence+b.CusCode+a.FromWarehouseCode+b.SSDCode+a.MUSER AS Costre2
  319. ,b.CusCode,a.FromWarehouseCode AS WarehouseCode,b.SSDCode,b.Sequence,a.MUSER,
  320. 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.SSDDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  321. ,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,
  322. 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
  323. INTO #TempERP
  324. FROM ICSWareHouseLotInfoLog a
  325. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  326. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  327. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  328. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  329. INNER JOIN ICSSSD b ON a.TransCode=b.SSDCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  330. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  331. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  332. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  333. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode = '55' AND b.Type='1'
  334. GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,b.CusCode,a.FromWarehouseCode,b.SSDCode,b.Sequence,a.MUSER,a.InvCode,b.SSDDetailID,con.Enable,conStock.Enable
  335. ,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, ''),
  336. 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, '')
  337. SELECT DISTINCT Costre,WorkPoint,SSDCode AS DocNo,0 AS ID FROM #TempERP
  338. SELECT Costre,Costre2,Sequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Quantity AS IssuedQuantity,Amount,SSDDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  339. SELECT a.LotNo,a.Quantity,lot.ExpirationDate,b.EATTRIBUTE3 AS TrackingNO,
  340. a.TransCode+a.TransSequence+b.CusCode+a.FromWarehouseCode+b.SSDCode+b.SDNCode+a.MUSER AS Costre2
  341. FROM ICSWareHouseLotInfoLog a
  342. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  343. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  344. INNER JOIN ICSSSD b ON a.TransCode=b.SSDCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint
  345. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1' AND a.BusinessCode = '{1}'
  346. DROP TABLE #TempERP";
  347. sql = string.Format(sql, Identification, BusinessCode);
  348. string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.SSDQuantity) AS ISSQty,a.transCode from ICSSSD b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.SSDCode AND a.WorkPoint=b.WorkPoint
  349. where a.Identification='{0}' GROUP BY a.transCode";
  350. checksql = string.Format(checksql, Identification);
  351. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  352. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  353. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  354. string trancode = chekdt.Rows[0]["transCode"].ToString();
  355. if (SUMQty - ISSQty == 0)
  356. {
  357. string pnsql = @"SELECT b.SSDCode AS Costre
  358. ,a.TransCode+a.TransSequence+b.CusCode+a.FromWarehouseCode+b.SSDCode+a.MUSER AS Costre2
  359. ,b.CusCode,a.FromWarehouseCode AS WarehouseCode,b.SSDCode,b.Sequence,a.MUSER,
  360. 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.SSDDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  361. ,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,
  362. 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
  363. INTO #TempERP
  364. FROM ICSWareHouseLotInfoLog a
  365. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  366. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  367. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  368. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  369. INNER JOIN ICSSSD b ON a.TransCode=b.SSDCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  370. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  371. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  372. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  373. WHERE a.TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '55' AND b.Type='1' and a.EATTRIBUTE1<>'1'
  374. GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,b.CusCode,a.FromWarehouseCode,b.SSDCode,b.Sequence,a.MUSER,a.InvCode,b.SSDDetailID,con.Enable,conStock.Enable
  375. ,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, ''),
  376. 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, '')
  377. SELECT DISTINCT Costre,WorkPoint,SSDCode AS DocNo,0 AS ID,1 AS IsEnd FROM #TempERP
  378. SELECT Costre,Sequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Quantity AS IssuedQuantity,Amount,SSDDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  379. DROP TABLE #TempERP";
  380. pnsql = string.Format(pnsql, trancode);
  381. DataSet ds = DBHelper.SQlReturnDataSet(pnsql, cmd);
  382. string Inputstr = DataToJsonHelper.DataSetToJson2(ds, "details", "Costre");
  383. Inputstr2 = Inputstr;
  384. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SMShipURL, Inputstr);
  385. //sql = string.Format(sql, Identification);
  386. ////DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  387. //DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  388. ////string Inputstr = JsonConvert.SerializeObject(dt);
  389. //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
  390. //string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PNSalesDeliveryNoticeOutURL, Inputstr);
  391. //Result result = new Result();
  392. result = JsonConvert.DeserializeObject<Result>(resultStr);
  393. if (result.Success)
  394. {
  395. try
  396. {
  397. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  398. foreach (var item in res)
  399. {
  400. JObject jo = (JObject)item;
  401. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  402. foreach (var detail in resdetail)
  403. {
  404. // JObject det = (JObject)detail;
  405. // string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1',Quantity='{6}'
  406. // FROM ICSWareHouseLotInfoLog a
  407. // INNER JOIN ICSSSD c ON a.TransCode=c.SSDCOde AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  408. //INNER JOIN ICSInventoryLot lot on a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  409. //INNER JOIN ICSExtension d ON lot.ExtensionID=d.id and lot.WorkPoint=d.WorkPoint
  410. // WHERE c.SSDCode='{0}' AND a.BusinessCode ='{7}' AND d.BatchCode='{8}' AND lot.InvCode='{1}'";
  411. // ERPupdate = string.Format(ERPupdate);
  412. // if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  413. // {
  414. // throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
  415. // }
  416. }
  417. }
  418. }
  419. catch (Exception ex)
  420. {
  421. log.Debug(ex.ToString());
  422. log.Debug(resultStr);
  423. }
  424. }
  425. else
  426. {
  427. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  428. }
  429. }
  430. else
  431. {
  432. string newchecksql = @"select DISTINCT b.Quantity AS CountQty,b.SSDQuantity AS CountISSQty,a.transCode,a.transSequence from ICSSSD b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.SSDCode and a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  433. where a.Identification='{0}' and BusinessCode='55'";
  434. newchecksql = string.Format(newchecksql, Identification);
  435. DataTable newchekdt = DBHelper.SQlReturnData(newchecksql, cmd);
  436. for (int i = 0; i < newchekdt.Rows.Count; i++)
  437. {
  438. decimal CountQty = Convert.ToDecimal(newchekdt.Rows[i]["CountQty"]);
  439. decimal CountISSQty = Convert.ToDecimal(newchekdt.Rows[i]["CountISSQty"]);
  440. string Counttrancode = newchekdt.Rows[i]["transCode"].ToString();
  441. string CounttransSequence = newchekdt.Rows[i]["transSequence"].ToString();
  442. if (CountQty - CountISSQty == 0)
  443. {
  444. string pnsql = @"SELECT b.SSDCode AS Costre
  445. ,a.TransCode+a.TransSequence+b.CusCode+a.FromWarehouseCode+b.SSDCode+a.MUSER AS Costre2
  446. ,b.CusCode,a.FromWarehouseCode AS WarehouseCode,b.SSDCode,b.Sequence,a.MUSER,
  447. 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.SSDDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  448. ,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,
  449. 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
  450. INTO #TempERP
  451. FROM ICSWareHouseLotInfoLog a
  452. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  453. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  454. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  455. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  456. INNER JOIN ICSSSD b ON a.TransCode=b.SSDCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  457. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  458. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  459. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  460. WHERE a.TransCode='{0}' and a.TransSequence='{1}' AND ERPUpload='0' AND BusinessCode = '55' AND b.Type='1' and a.EATTRIBUTE1<>'1'
  461. GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,b.CusCode,a.FromWarehouseCode,b.SSDCode,b.Sequence,a.MUSER,a.InvCode,b.SSDDetailID,con.Enable,conStock.Enable
  462. ,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, ''),
  463. 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, '')
  464. SELECT DISTINCT Costre,WorkPoint,SSDCode AS DocNo,0 AS ID,0 AS IsEnd FROM #TempERP
  465. SELECT Costre,Sequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Quantity AS IssuedQuantity,Amount,SSDDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  466. DROP TABLE #TempERP";
  467. pnsql = string.Format(pnsql, Counttrancode, CounttransSequence);
  468. DataSet ds = DBHelper.SQlReturnDataSet(pnsql, cmd);
  469. string Inputstr = DataToJsonHelper.DataSetToJson2(ds, "details", "Costre");
  470. Inputstr2 = Inputstr;
  471. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SMShipURL, Inputstr);
  472. //sql = string.Format(sql, Identification);
  473. ////DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  474. //DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  475. ////string Inputstr = JsonConvert.SerializeObject(dt);
  476. //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
  477. //string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PNSalesDeliveryNoticeOutURL, Inputstr);
  478. //Result result = new Result();
  479. result = JsonConvert.DeserializeObject<Result>(resultStr);
  480. if (result.Success)
  481. {
  482. try
  483. {
  484. }
  485. catch (Exception ex)
  486. {
  487. log.Debug(ex.ToString());
  488. log.Debug(resultStr);
  489. }
  490. }
  491. else
  492. {
  493. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  494. }
  495. }
  496. }
  497. }
  498. }
  499. else
  500. {
  501. //审核销售出库单接口是否分批提交 1为是 0为否
  502. string ssql = @"select F_EnabledMark from Sys_SRM_Items where F_EnCode='allin' and F_EnabledMark='1'";
  503. DataTable dt = DBHelper.SQlReturnData(ssql, cmd);
  504. if (dt.Rows.Count == 0)
  505. {
  506. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
  507. INTO #NewTempERP
  508. from ICSWareHouseLotInfoLog
  509. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '55'
  510. IF EXISTS(SELECT b.ID FROM ICSSSD b
  511. WHERE b.SSDCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  512. AND b.Quantity!=b.SSDQuantity and b.type='1')
  513. BEGIN
  514. RAISERROR('" + language.GetNameByCode("WMSAPIInfo529") + @"',16,1);
  515. RETURN
  516. END
  517. SELECT a.TransCode AS Costre,b.SSDID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint,b.CusCode
  518. FROM #NewTempERP a
  519. INNER JOIN ICSSSD b ON a.TransCode=b.SSDCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint and b.type='1'
  520. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  521. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  522. GROUP BY b.SSDID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint,a.TransCode,b.CusCode
  523. SELECT DISTINCT a.TransCode AS Costre,a.TransCode+a.TransSequence+a.InvCode AS Costre2,a.InvCode FROM #NewTempERP a
  524. SELECT DISTINCT a.TransCode+a.TransSequence+a.InvCode AS Costre2,a.LotNo,lot.ExpirationDate,'' AS TrackingNO
  525. FROM #NewTempERP a
  526. INNER JOIN ICSInventoryLot lot ON lot.LotNo=a.lotNo AND lot.WorkPoint=a.WorkPoint
  527. INNER JOIN ICSSSD b ON b.SSDCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  528. LEFT JOIN ICSSDN sdn ON sdn.SDNCode=b.SDNCode AND sdn.WorkPoint=b.WorkPoint
  529. ORDER BY Costre2,a.LotNo,lot.ExpirationDate
  530. DROP TABLE #NewTempERP";
  531. sql = string.Format(sql, Identification);
  532. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  533. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  534. //string Inputstr = JsonConvert.SerializeObject(dt);
  535. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
  536. Inputstr2 = Inputstr;
  537. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesDeliveryNoticeOutURL, Inputstr);
  538. result = JsonConvert.DeserializeObject<Result>(resultStr);
  539. if (result.Success)
  540. {
  541. try
  542. {
  543. foreach (DataRow dr in ds.Tables[0].Rows)
  544. {
  545. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  546. }
  547. }
  548. catch (Exception ex)
  549. {
  550. log.Debug(ex.ToString());
  551. log.Debug(resultStr);
  552. }
  553. }
  554. else
  555. {
  556. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  557. }
  558. }
  559. else
  560. {
  561. //判断数量 数量满足再调用erp接口,不满足数量只走wms逻辑
  562. string checksql = @"select SUM(Quantity) AS SUMQty,SUM(SSDQuantity) AS ISSQty,SSDCode AS transCode from ICSSSD
  563. where SSDCode in (select top 1 TransCode from ICSWareHouseLotInfoLog where Identification='{0}' AND BusinessCode='55')
  564. GROUP BY SSDCode";
  565. checksql = string.Format(checksql, Identification);
  566. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  567. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  568. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  569. string trancode = chekdt.Rows[0]["transCode"].ToString();
  570. if (SUMQty - ISSQty == 0)
  571. {
  572. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
  573. INTO #NewTempERP
  574. from ICSWareHouseLotInfoLog
  575. WHERE TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '55'
  576. SELECT DISTINCT a.TransCode AS Costre,b.SSDID AS ID,'{1}' AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint,b.CusCode
  577. FROM #NewTempERP a
  578. INNER JOIN ICSSSD b ON a.TransCode=b.SSDCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint and b.type='1'
  579. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  580. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  581. GROUP BY b.SSDID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint,a.TransCode,b.CusCode
  582. SELECT DISTINCT a.TransCode AS Costre,a.TransCode+a.TransSequence+a.InvCode AS Costre2,a.InvCode FROM #NewTempERP a
  583. SELECT DISTINCT a.TransCode+a.TransSequence+a.InvCode AS Costre2,a.LotNo,lot.ExpirationDate,'' AS TrackingNO
  584. FROM #NewTempERP a
  585. INNER JOIN ICSInventoryLot lot ON lot.LotNo=a.lotNo AND lot.WorkPoint=a.WorkPoint
  586. INNER JOIN ICSSSD b ON b.SSDCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  587. LEFT JOIN ICSSDN sdn ON sdn.SDNCode=b.SDNCode AND sdn.WorkPoint=b.WorkPoint
  588. ORDER BY Costre2,a.LotNo,lot.ExpirationDate
  589. DROP TABLE #NewTempERP";
  590. sql = string.Format(sql, trancode, UserCode);
  591. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  592. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  593. //string Inputstr = JsonConvert.SerializeObject(dt);
  594. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
  595. Inputstr2 = Inputstr;
  596. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesDeliveryNoticeOutURL, Inputstr);
  597. result = JsonConvert.DeserializeObject<Result>(resultStr);
  598. if (result.Success)
  599. {
  600. try
  601. {
  602. foreach (DataRow dr in ds.Tables[0].Rows)
  603. {
  604. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  605. }
  606. }
  607. catch (Exception ex)
  608. {
  609. log.Debug(ex.ToString());
  610. log.Debug(resultStr);
  611. }
  612. }
  613. else
  614. {
  615. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  616. }
  617. }
  618. }
  619. }
  620. #endregion
  621. }
  622. catch (Exception)
  623. {
  624. //DataTable WHtable = ICSControlModeService.GetJHWHCode();
  625. //if (WHtable == null)
  626. //{
  627. throw;
  628. //}
  629. //else
  630. //{
  631. // ICSControlModeService.InsertErrLog(ERPUrl.SalesDeliveryNoticeOutURL, Inputstr2, result.Message, JObject.Parse(Inputstr2)["UserCode"]?.ToString(), JObject.Parse(Inputstr2)["OrgCode"]?.ToString(),cmd);
  632. //}
  633. }
  634. }
  635. /// <summary>
  636. /// 晶华销售出库-出库单接口
  637. /// </summary>
  638. /// <param name="TransType"></param>
  639. /// <param name="Identification"></param>
  640. /// <param name="cmd"></param>
  641. public static void JHSalesShipmentDocOutERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode, string UserCode)
  642. {
  643. string Inputstr2 = "";
  644. string resultStr = "";
  645. Result result = new Result();
  646. try
  647. {
  648. string sql = "";
  649. #region ERP开立状态单据审核
  650. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
  651. INTO #NewTempERP
  652. from ICSWareHouseLotInfoLog
  653. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '55-1'
  654. IF EXISTS(SELECT b.ID FROM ICSSSD b
  655. WHERE b.SSDCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  656. AND b.Quantity!=b.SSDQuantity)
  657. BEGIN
  658. RAISERROR('" + language.GetNameByCode("WMSAPIInfo100") + @"',16,1);
  659. RETURN
  660. END
  661. SELECT b.SSDID AS ID,ISNULL((SELECT top 1
  662. b.F_ItemCode
  663. FROM Sys_SRM_Items a
  664. LEFT JOIN Sys_SRM_ItemsDetail b ON a.F_Id = b.F_ItemId
  665. WHERE a.F_EnCode = 'sallerCodeGroup'),a.MUSER) AS [UserCode],a.WorkPoint AS OrgCode
  666. FROM #NewTempERP a
  667. INNER JOIN ICSSSD b ON a.TransCode=b.SSDCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  668. GROUP BY b.SSDID,a.MUSER,a.WorkPoint
  669. DROP TABLE #NewTempERP";
  670. sql = string.Format(sql, Identification);
  671. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  672. string Inputstr = JsonConvert.SerializeObject(dt);
  673. Inputstr = Inputstr.Replace("[", "").Replace("]", "");
  674. Inputstr2 = Inputstr;
  675. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.JHSalesDeliveryNoticeOutURL, Inputstr);
  676. //Result result = new Result();
  677. result = JsonConvert.DeserializeObject<Result>(resultStr);
  678. if (result.Success)
  679. {
  680. try
  681. {
  682. foreach (DataRow dr in dt.Rows)
  683. {
  684. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  685. }
  686. }
  687. catch (Exception ex)
  688. {
  689. log.Debug(ex.ToString());
  690. log.Debug(resultStr);
  691. }
  692. }
  693. else
  694. {
  695. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  696. }
  697. #endregion
  698. }
  699. catch (Exception)
  700. {
  701. //DataTable WHtable = ICSControlModeService.GetJHWHCode();
  702. //if (WHtable == null)
  703. //{
  704. throw;
  705. //}
  706. //else
  707. //{
  708. // ICSControlModeService.InsertErrLog(ERPUrl.JHSalesDeliveryNoticeOutURL, Inputstr2, resultStr, JObject.Parse(Inputstr2)["UserCode"]?.ToString(), JObject.Parse(Inputstr2)["OrgCode"]?.ToString(), cmd);
  709. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  710. //}
  711. }
  712. }
  713. #endregion
  714. #region 销售出库-红字出库单
  715. /// <summary>
  716. /// 销售出库-红字出库单
  717. /// </summary>
  718. /// <param name="TransCode"></param>
  719. /// <param name="TransSequence"></param>
  720. /// <param name="Quantity"></param>
  721. /// <param name="WorkPoint"></param>
  722. /// <param name="cmd"></param>
  723. public static void SalesShipmentOutRedDocNegative(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  724. {
  725. try
  726. {
  727. string sql = @"DECLARE @Status VARCHAR(10)
  728. SELECT @Status=c.Status FROM ICSInventoryLot a
  729. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  730. INNER JOIN ICSSSD c ON b.TransCode=c.SSDCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  731. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
  732. IF (@Status IS NULL)
  733. BEGIN
  734. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  735. RETURN
  736. END
  737. ELSE IF (@Status!='1')
  738. BEGIN
  739. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  740. RETURN
  741. END
  742. UPDATE c SET SSDQuantity=ISNULL(SSDQuantity,0)+'{2}'
  743. FROM ICSInventoryLot a
  744. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  745. INNER JOIN ICSSSD c ON b.TransCode=c.SSDCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  746. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'";
  747. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  748. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  749. {
  750. throw new Exception("销售出库单更新失败!");
  751. }
  752. }
  753. catch (Exception)
  754. {
  755. throw;
  756. }
  757. }
  758. /// <summary>
  759. /// 销售出库红字出库单-原条码
  760. /// </summary>
  761. /// <param name="TransCode"></param>
  762. /// <param name="TransSequence"></param>
  763. /// <param name="Quantity"></param>
  764. /// <param name="WorkPoint"></param>
  765. /// <param name="cmd"></param>
  766. public static void SalesShipmentOutRedYuanDocIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  767. {
  768. try
  769. {
  770. string sql = @"DECLARE @Status VARCHAR(10)
  771. SELECT @Status=sdn.Status FROM ICSSSD sdn
  772. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  773. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  774. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SSDCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
  775. IF (@Status IS NULL)
  776. BEGIN
  777. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  778. RETURN
  779. END
  780. ELSE IF (@Status!='1')
  781. BEGIN
  782. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  783. RETURN
  784. END
  785. UPDATE sdn SET SSDQuantity=ISNULL(SSDQuantity,0)+'{4}'
  786. FROM ICSSSD sdn
  787. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  788. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  789. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SSDCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
  790. IF EXISTS(SELECT a.LotNo FROM ICSSSD sdn
  791. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  792. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  793. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SSDCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2' AND sdn.Quantity<sdn.SSDQuantity)
  794. BEGIN
  795. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  796. END";
  797. sql = string.Format(sql, LotNo, WorkPoint, TransCode, TransSequence, Quantity);
  798. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  799. {
  800. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  801. }
  802. }
  803. catch (Exception)
  804. {
  805. throw;
  806. }
  807. }
  808. /// <summary>
  809. /// 销售出库-红字出库单接口
  810. /// </summary>
  811. /// <param name="TransType"></param>
  812. /// <param name="Identification"></param>
  813. /// <param name="cmd"></param>
  814. public static void SalesShipmentDocOutRedERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  815. {
  816. try
  817. {
  818. string sql = string.Empty;
  819. if (DBHelper.IsPNU9())
  820. {
  821. sql = @"SELECT b.CusCode+a.ToWarehouseCode+b.SSDCode+a.MUSER AS Costre
  822. ,a.TransCode+a.TransSequence+b.CusCode+a.ToWarehouseCode+b.SSDCode+a.MUSER AS Costre2
  823. ,b.CusCode,a.ToWarehouseCode AS WarehouseCode,b.SSDCode,b.Sequence,a.MUSER,
  824. 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.SSDDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  825. ,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,
  826. 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
  827. INTO #TempERP
  828. FROM ICSWareHouseLotInfoLog a
  829. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  830. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  831. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  832. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  833. INNER JOIN ICSSSD b ON a.TransCode=b.SSDCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  834. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  835. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  836. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  837. WHERE a.Identification='{0}' AND ERPUpload='0' and BusinessCode='56' AND b.Type='2'
  838. GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,b.CusCode,a.ToWarehouseCode,b.SSDCode,b.Sequence,a.MUSER,a.InvCode,b.SSDDetailID,con.Enable,conStock.Enable
  839. ,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, ''),
  840. 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, '')
  841. SELECT DISTINCT Costre,WorkPoint,SSDCode AS DocNo,0 AS ID FROM #TempERP
  842. SELECT Costre,Costre2,Sequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Quantity AS RcvQuantity,Amount,SSDDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  843. DROP TABLE #TempERP
  844. ";
  845. sql = string.Format(sql, Identification);
  846. //DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  847. //string Inputstr = DataToJsonHelper.DataSetToJson2(ds, "details", "Costre");
  848. string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.SSDQuantity) AS ISSQty,a.transCode from ICSSSD b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.SSDCode AND a.WorkPoint=b.WorkPoint
  849. where a.Identification='{0}' GROUP BY a.transCode";
  850. checksql = string.Format(checksql, Identification);
  851. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  852. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  853. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  854. string trancode = chekdt.Rows[0]["transCode"].ToString();
  855. if (SUMQty - ISSQty == 0)
  856. {
  857. string pnsql = @"SELECT b.CusCode+a.ToWarehouseCode+b.SSDCode+a.MUSER AS Costre
  858. ,a.TransCode+a.TransSequence+b.CusCode+a.ToWarehouseCode+b.SSDCode+a.MUSER AS Costre2
  859. ,b.CusCode,a.ToWarehouseCode AS WarehouseCode,b.SSDCode,b.Sequence,a.MUSER,
  860. 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.SSDDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  861. ,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,
  862. 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
  863. INTO #TempERP
  864. FROM ICSWareHouseLotInfoLog a
  865. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  866. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  867. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  868. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  869. INNER JOIN ICSSSD b ON a.TransCode=b.SSDCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  870. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  871. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  872. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  873. WHERE a.TransCode='{0}' AND ERPUpload='0' and BusinessCode='56' AND b.Type='2' and a.EATTRIBUTE1<>'1'
  874. GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,b.CusCode,a.ToWarehouseCode,b.SSDCode,b.Sequence,a.MUSER,a.InvCode,b.SSDDetailID,con.Enable,conStock.Enable
  875. ,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, ''),
  876. 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, '')
  877. SELECT DISTINCT Costre,WorkPoint,SSDCode AS DocNo,0 AS ID FROM #TempERP
  878. SELECT Costre,Costre2,Sequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Quantity AS RcvQuantity,Amount,SSDDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  879. DROP TABLE #TempERP
  880. ";
  881. pnsql = string.Format(pnsql, trancode);
  882. DataSet ds = DBHelper.SQlReturnDataSet(pnsql, cmd);
  883. string Inputstr = DataToJsonHelper.DataSetToJson2(ds, "details", "Costre");
  884. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.RMAToRCVURL, Inputstr);
  885. Result result = new Result();
  886. //sql = string.Format(sql, Identification);
  887. ////DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  888. //DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  889. ////string Inputstr = JsonConvert.SerializeObject(dt);
  890. //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
  891. //string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PNSalesDeliveryNoticeOutURL, Inputstr);
  892. //Result result = new Result();
  893. result = JsonConvert.DeserializeObject<Result>(resultStr);
  894. if (result.Success)
  895. {
  896. try
  897. {
  898. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  899. foreach (var item in res)
  900. {
  901. JObject jo = (JObject)item;
  902. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  903. foreach (var detail in resdetail)
  904. {
  905. // JObject det = (JObject)detail;
  906. // string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1',Quantity='{6}'
  907. // FROM ICSWareHouseLotInfoLog a
  908. // INNER JOIN ICSSSD c ON a.TransCode=c.SSDCOde AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  909. //INNER JOIN ICSInventoryLot lot on a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  910. //INNER JOIN ICSExtension d ON lot.ExtensionID=d.id and lot.WorkPoint=d.WorkPoint
  911. // WHERE c.SSDCode='{0}' AND a.BusinessCode ='{7}' AND d.BatchCode='{8}' AND lot.InvCode='{1}'";
  912. // ERPupdate = string.Format(ERPupdate);
  913. // if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  914. // {
  915. // throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
  916. // }
  917. }
  918. }
  919. }
  920. catch (Exception ex)
  921. {
  922. log.Debug(ex.ToString());
  923. log.Debug(resultStr);
  924. }
  925. }
  926. else
  927. {
  928. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  929. }
  930. }
  931. }
  932. else
  933. {
  934. #region ERP开立状态单据审核
  935. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
  936. INTO #NewTempERP
  937. from ICSWareHouseLotInfoLog
  938. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '{1}'
  939. IF EXISTS(SELECT b.ID FROM ICSSSD b
  940. WHERE b.SSDCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  941. AND b.Quantity!=b.SSDQuantity and b.type='2')
  942. BEGIN
  943. RAISERROR('" + language.GetNameByCode("WMSAPIInfo529") + @"',16,1);
  944. RETURN
  945. END
  946. SELECT b.SSDCode AS SDNRTCode, b.SSDID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  947. FROM #NewTempERP a
  948. INNER JOIN ICSSSD b ON a.TransCode=b.SSDCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint and b.type='2'
  949. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  950. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  951. GROUP BY b.SSDCode,b.SSDID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  952. DROP TABLE #NewTempERP";
  953. sql = string.Format(sql, Identification, BusinessCode);
  954. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  955. string Inputstr = JsonConvert.SerializeObject(dt);
  956. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesDeliveryNoticeOutRedURL, Inputstr);
  957. Result result = new Result();
  958. result = JsonConvert.DeserializeObject<Result>(resultStr);
  959. if (result.Success)
  960. {
  961. try
  962. {
  963. foreach (DataRow dr in dt.Rows)
  964. {
  965. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  966. }
  967. }
  968. catch (Exception ex)
  969. {
  970. log.Debug(ex.ToString());
  971. log.Debug(resultStr);
  972. }
  973. }
  974. else
  975. {
  976. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  977. }
  978. #endregion
  979. }
  980. }
  981. catch (Exception)
  982. {
  983. throw;
  984. }
  985. }
  986. #endregion
  987. #region 销售退货
  988. /// <summary>
  989. /// 销售退货
  990. /// </summary>
  991. /// <param name="TransCode"></param>
  992. /// <param name="TransSequence"></param>
  993. /// <param name="Quantity"></param>
  994. /// <param name="WorkPoint"></param>
  995. /// <param name="cmd"></param>
  996. public static void SalesShipmentDocNegative(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  997. {
  998. try
  999. {
  1000. string sql = @"DECLARE @Status VARCHAR(10)
  1001. SELECT @Status=c.Status FROM ICSInventoryLot a
  1002. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1003. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1004. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
  1005. IF (@Status IS NULL)
  1006. BEGIN
  1007. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1008. RETURN
  1009. END
  1010. ELSE IF (@Status!='2')
  1011. BEGIN
  1012. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  1013. RETURN
  1014. END
  1015. UPDATE c SET SDNQuantity=ISNULL(SDNQuantity,0)+'{2}'
  1016. FROM ICSInventoryLot a
  1017. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1018. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1019. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
  1020. --退
  1021. UPDATE d SET SoQuantity=ISNULL(SoQuantity,0)-'{2}'
  1022. FROM ICSInventoryLot a
  1023. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1024. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1025. inner join ICSSO d on c.socode=d.socode and c.SoSequence=d.Sequence
  1026. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
  1027. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1028. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1029. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1030. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
  1031. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn020', c.Quantity,1,3,'')<c.SDNQuantity)
  1032. BEGIN
  1033. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  1034. END";
  1035. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1036. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1037. {
  1038. throw new Exception("销售退货单更新失败!");
  1039. }
  1040. }
  1041. catch (Exception)
  1042. {
  1043. throw;
  1044. }
  1045. }
  1046. /// <summary>
  1047. /// 销售退货接口
  1048. /// </summary>
  1049. /// <param name="TransType"></param>
  1050. /// <param name="Identification"></param>
  1051. /// <param name="cmd"></param>
  1052. public static void SalesShipmentDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1053. {
  1054. try
  1055. {
  1056. string sql = "";
  1057. DataTable flag = null;
  1058. string enablesql = @"select * from ICSConfiguration where code = 'RTDisReturn' and enable = '1'";
  1059. flag = DBHelper.SQlReturnData(enablesql, cmd);
  1060. #region ERP
  1061. if (flag != null && flag.Rows.Count > 0)
  1062. {
  1063. sql = @"
  1064. IF EXISTS(SELECT b.ID FROM ICSSDN b
  1065. WHERE b.SDNCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1066. AND b.Quantity!=b.SDNQuantity AND b.Type='2')
  1067. BEGIN
  1068. RAISERROR('退',16,1);
  1069. RETURN
  1070. END
  1071. 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,
  1072. 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,conWhCode.Enable AS ErpWhCode
  1073. ,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,
  1074. 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
  1075. ,c.SDNID
  1076. INTO #TempERP
  1077. FROM ICSWareHouseLotInfoLog a
  1078. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1079. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1080. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1081. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1082. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1083. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1084. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1085. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  1086. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1087. WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2' AND BusinessCode='{1}'
  1088. GROUP BY conWhCode.Enable,inv.AmountEnable,c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,con.Enable,conStock.Enable
  1089. ,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, ''),
  1090. ISNULL(ext.cFree1, ''),c.SDNID,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, '')
  1091. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock,SDNID as SDNRTID FROM #TempERP
  1092. SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,SDNDetailID AS SDNRTDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  1093. DROP TABLE #TempERP";
  1094. }
  1095. else
  1096. {
  1097. 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,
  1098. 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,conWhCode.Enable AS ErpWhCode
  1099. ,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,
  1100. 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
  1101. ,c.SDNID
  1102. INTO #TempERP
  1103. FROM ICSWareHouseLotInfoLog a
  1104. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1105. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1106. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1107. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1108. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1109. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1110. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1111. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  1112. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1113. WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2' AND BusinessCode='{1}'
  1114. GROUP BY inv.AmountEnable,conWhCode.Enable,c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,con.Enable,conStock.Enable
  1115. ,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, ''),
  1116. ISNULL(ext.cFree1, ''),c.SDNID,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, '')
  1117. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock,SDNID as SDNRTID FROM #TempERP
  1118. SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,SDNDetailID AS SDNRTDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  1119. DROP TABLE #TempERP";
  1120. }
  1121. sql = string.Format(sql, Identification,BusinessCode);
  1122. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1123. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1124. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, Inputstr);
  1125. Result result = new Result();
  1126. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1127. if (result.Success)
  1128. {
  1129. try
  1130. {
  1131. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1132. foreach (var item in res)
  1133. {
  1134. JObject jo = (JObject)item;
  1135. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1136. foreach (var detail in resdetail)
  1137. {
  1138. JObject det = (JObject)detail;
  1139. 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()
  1140. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1141. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1142. det["DetailID"].ToString(), jo["SDNNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1143. }
  1144. }
  1145. }
  1146. catch (Exception ex)
  1147. {
  1148. log.Debug(ex.ToString());
  1149. log.Debug(resultStr);
  1150. }
  1151. }
  1152. else
  1153. {
  1154. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  1155. }
  1156. #endregion
  1157. }
  1158. catch (Exception)
  1159. {
  1160. throw;
  1161. }
  1162. }
  1163. public static void U9SalesShipmentDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1164. {
  1165. try
  1166. {
  1167. #region ERP
  1168. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  1169. INNER JOIN ICSSDN b ON a.TransCode=b.SDNCode AND a.WorkPoint=b.WorkPoint
  1170. WHERE a.Identification='{0}' AND b.Quantity!=b.SDNQuantity)
  1171. BEGIN
  1172. RAISERROR('退',16,1);
  1173. RETURN
  1174. END
  1175. 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,
  1176. 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
  1177. ,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,
  1178. 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
  1179. INTO #TempERP
  1180. FROM ICSWareHouseLotInfoLog a
  1181. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1182. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1183. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1184. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1185. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1186. INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1187. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1188. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  1189. WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2' AND BusinessCode='{1}'
  1190. GROUP BY inv.AmountEnable,c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,con.Enable,conStock.Enable
  1191. ,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, ''),
  1192. 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, '')
  1193. SELECT DISTINCT WorkPoint,CusCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP -- Costre,WarehouseCode AS WHCode,
  1194. --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
  1195. DROP TABLE #TempERP";
  1196. sql = string.Format(sql, Identification, BusinessCode);
  1197. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1198. //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1199. string Inputstr = JsonConvert.SerializeObject(ds.Tables[0]);
  1200. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, Inputstr);
  1201. Result result = new Result();
  1202. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1203. if (result.Success)
  1204. {
  1205. try
  1206. {
  1207. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1208. foreach (var item in res)
  1209. {
  1210. JObject jo = (JObject)item;
  1211. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1212. foreach (var detail in resdetail)
  1213. {
  1214. JObject det = (JObject)detail;
  1215. 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()
  1216. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1217. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1218. det["DetailID"].ToString(), jo["SDNNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1219. }
  1220. }
  1221. }
  1222. catch (Exception ex)
  1223. {
  1224. log.Debug(ex.ToString());
  1225. log.Debug(resultStr);
  1226. }
  1227. }
  1228. else
  1229. {
  1230. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1231. }
  1232. #endregion
  1233. }
  1234. catch (Exception)
  1235. {
  1236. throw;
  1237. }
  1238. }
  1239. #endregion
  1240. #region 销售退货-原条码
  1241. /// <summary>
  1242. /// 销售退货-原条码
  1243. /// </summary>
  1244. /// <param name="TransCode"></param>
  1245. /// <param name="TransSequence"></param>
  1246. /// <param name="Quantity"></param>
  1247. /// <param name="WorkPoint"></param>
  1248. /// <param name="cmd"></param>
  1249. public static void SalesReturnBackIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1250. {
  1251. try
  1252. {
  1253. string sql = @"DECLARE @Status VARCHAR(10)
  1254. SELECT @Status=sdn.Status FROM ICSSDN sdn
  1255. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  1256. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1257. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SDNCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
  1258. IF (@Status IS NULL)
  1259. BEGIN
  1260. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1261. RETURN
  1262. END
  1263. ELSE IF (@Status!='2')
  1264. BEGIN
  1265. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  1266. RETURN
  1267. END
  1268. UPDATE sdn SET SDNQuantity=ISNULL(SDNQuantity,0)+'{4}'
  1269. FROM ICSSDN sdn
  1270. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  1271. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1272. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SDNCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
  1273. IF EXISTS(SELECT a.LotNo FROM ICSSDN sdn
  1274. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
  1275. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1276. 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)
  1277. BEGIN
  1278. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  1279. END";
  1280. sql = string.Format(sql, LotNo, WorkPoint, TransCode, TransSequence, Quantity);
  1281. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1282. {
  1283. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  1284. }
  1285. }
  1286. catch (Exception)
  1287. {
  1288. throw;
  1289. }
  1290. }
  1291. /// <summary>
  1292. /// 销售退货-原条码接口
  1293. /// </summary>
  1294. /// <param name="TransType"></param>
  1295. /// <param name="Identification"></param>
  1296. /// <param name="cmd"></param>
  1297. public static void SalesReturnBackInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1298. {
  1299. try
  1300. {
  1301. #region ERP
  1302. string sql = @"SELECT c.CusCode+a.FromWarehouseCode+c.SDNCode+a.MUSER AS Costre,c.CusCode,a.FromWarehouseCode AS WarehouseCode,c.SDNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.CusCode,a.FromWarehouseCode,c.SDNCode,c.SDNDetailID,a.InvCode) AS Sequence,
  1303. 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,conWhCode.Enable AS ErpWhCode
  1304. ,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,
  1305. 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
  1306. INTO #TempERP
  1307. FROM ICSWareHouseLotInfoLog a
  1308. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1309. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1310. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1311. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1312. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1313. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1314. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  1315. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1316. WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2' AND BusinessCode='{1}'
  1317. GROUP BY conWhCode.Enable,inv.AmountEnable,c.CusCode,a.FromWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,con.Enable,conStock.Enable
  1318. ,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, ''),
  1319. 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, '')
  1320. SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock,ErpWhCode FROM #TempERP
  1321. SELECT Costre,Sequence,InvCode,Quantity,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,Amount,SDNDetailID AS SDNRTDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  1322. DROP TABLE #TempERP";
  1323. sql = string.Format(sql, Identification,BusinessCode);
  1324. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1325. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1326. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, Inputstr);
  1327. Result result = new Result();
  1328. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1329. if (result.Success)
  1330. {
  1331. try
  1332. {
  1333. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1334. foreach (var item in res)
  1335. {
  1336. JObject jo = (JObject)item;
  1337. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1338. foreach (var detail in resdetail)
  1339. {
  1340. JObject det = (JObject)detail;
  1341. 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()
  1342. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1343. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1344. det["DetailID"].ToString(), jo["SDNNEGCode"].ToString(), det["Sequence"].ToString(), allcol,cmd, language, BusinessCode);
  1345. }
  1346. }
  1347. }
  1348. catch (Exception ex)
  1349. {
  1350. log.Debug(ex.ToString());
  1351. log.Debug(resultStr);
  1352. }
  1353. }
  1354. else
  1355. {
  1356. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1357. }
  1358. #endregion
  1359. }
  1360. catch (Exception)
  1361. {
  1362. throw;
  1363. }
  1364. }
  1365. #endregion
  1366. }
  1367. }