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.

1355 lines
101 KiB

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