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.

1402 lines
103 KiB

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