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.

1185 lines
78 KiB

1 year ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Linq;
  10. using System.Net.Http;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace ICSSoft.DataProject
  14. {
  15. /// <summary>
  16. /// 使用中
  17. /// 采购模块
  18. /// </summary>
  19. public class ICSPurchaseService
  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="TransType"></param>
  27. /// <param name="Identification"></param>
  28. /// <param name="cmd"></param>
  29. public static void DeliveryNoticeERP(string DNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  30. {
  31. try
  32. {
  33. #region ERP
  34. string sql = @"SELECT a.VenCode+a.DepCode+y.POCode+a.MUSER AS Costre,a.VenCode,a.DepCode,y.POCode,a.MUSER,a.MTIME,
  35. a.Sequence,a.InvCode,a.Quantity,CASE invBat.AmountEnable WHEN '1' THEN a.Amount ELSE '0' END AS Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.PODetailID
  36. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  37. 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
  38. INTO #TempERP
  39. FROM ICSDeliveryNotice a
  40. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  41. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  42. INNER JOIN ICSPurchaseOrder y ON a.PODetailID=y.PODetailID AND a.WorkPoint=y.WorkPoint
  43. WHERE a.DNCode='{0}' AND a.WorkPoint='{1}'
  44. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,POCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  45. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,PODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  46. FROM #TempERP
  47. DROP TABLE #TempERP";
  48. sql = string.Format(sql, DNCode, WorkPoint);
  49. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  50. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  51. string resultStr = HTTPHelper.HttpPost("采购到货", ERPUrl.CreatePOArrivURL, Inputstr);
  52. Result result = new Result();
  53. result = JsonConvert.DeserializeObject<Result>(resultStr);
  54. if (result.Success)
  55. {
  56. try
  57. {
  58. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  59. foreach (var item in res)
  60. {
  61. JObject jo = (JObject)item;
  62. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  63. foreach (var detail in resdetail)
  64. {
  65. JObject det = (JObject)detail;
  66. string ERPupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}'
  67. where PODetailID='{4}' AND DNType='1' AND DNCode='{5}' and Sequence='{1}'";
  68. ERPupdate = string.Format(ERPupdate, jo["DNCode"], det["Sequence"], jo["ID"], det["DetailID"], det["PODetailID"],DNCode);
  69. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  70. {
  71. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  72. }
  73. }
  74. }
  75. }
  76. catch (Exception ex)
  77. {
  78. log.Debug(ex.ToString());
  79. log.Debug(resultStr);
  80. }
  81. }
  82. else
  83. {
  84. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  85. }
  86. #endregion
  87. }
  88. catch (Exception)
  89. {
  90. throw;
  91. }
  92. }
  93. #endregion
  94. #region 采购入库
  95. /// <summary>
  96. /// 采购入库
  97. /// </summary>
  98. /// <param name="TransCode"></param>
  99. /// <param name="TransSequence"></param>
  100. /// <param name="Quantity"></param>
  101. /// <param name="WorkPoint"></param>
  102. /// <param name="cmd"></param>
  103. public static void PurchaseReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  104. {
  105. try
  106. {
  107. string sql = @"DECLARE @Status VARCHAR(10)
  108. SELECT @Status=c.Status FROM ICSInventoryLot a
  109. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  110. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  111. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  112. IF (@Status IS NULL)
  113. BEGIN
  114. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  115. RETURN
  116. END
  117. ELSE IF (@Status='3')
  118. BEGIN
  119. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  120. RETURN
  121. END
  122. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  123. FROM ICSInventoryLot a
  124. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  125. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  126. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  127. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  128. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  129. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  130. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.InQuantity)
  131. BEGIN
  132. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  133. END";
  134. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  135. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  136. {
  137. throw new Exception(language.GetNameByCode("WMSAPIInfo104"));//"采购入库单更新失败!");
  138. }
  139. }
  140. catch (Exception)
  141. {
  142. throw;
  143. }
  144. }
  145. /// <summary>
  146. /// 采购入库接口
  147. /// </summary>
  148. /// <param name="TransType"></param>
  149. /// <param name="Identification"></param>
  150. /// <param name="cmd"></param>
  151. public static void PurchaseReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  152. {
  153. try
  154. {
  155. #region ERP
  156. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence
  157. INTO #NewTempERP
  158. from ICSWareHouseLotInfoLog
  159. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  160. SELECT c.VenCode+a.ToWarehouseCode+c.POCode+a.MUSER+CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS Costre,a.lotno AS Costre2,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS DNCode,CASE WHEN(LEN(f.DNID)>=20) THEN '1' ELSE '0' END AS HasDN,a.MUSER,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.Sequence END AS DNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.POCode,c.PODetailID,a.InvCode) AS Sequence,
  161. 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,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.PODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose
  162. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  163. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  164. INTO #TempERP
  165. FROM #NewTempERP a
  166. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  167. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  168. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  169. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  170. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  171. INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  172. INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  173. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  174. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  175. INNER JOIN ICSConfiguration conn ON a.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  176. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
  177. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose003'
  178. GROUP BY a.LotNo,a.TransSequence,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END,f.DNID,a.MUSER,a.InvCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.Sequence END,c.PODetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable,conStock.Enable,conStocknew.Enable
  179. ,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, ''),
  180. 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, '')
  181. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,POCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,UpdateStock,IsFillClose FROM #TempERP
  182. SELECT Costre,Costre2,Sequence,DNSequence,InvCode,Quantity,Amount,PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  183. FROM #TempERP
  184. SELECT a.LotNo,SUM(a.Quantity) AS Quantity,a.LotNo AS Costre2
  185. FROM ICSWareHouseLotInfoLog a
  186. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  187. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  188. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  189. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  190. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  191. INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  192. INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  193. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  194. INNER JOIN #TempERP te ON te.Sequence=a.TransSequence
  195. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  196. GROUP BY a.LotNo
  197. SELECT DISTINCT HasDN FROM #TempERP
  198. DROP TABLE #TempERP
  199. DROP TABLE #NewTempERP";
  200. sql = string.Format(sql, Identification, BusinessCode);
  201. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  202. //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  203. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
  204. var IsDNCode = ds.Tables[3];
  205. if (IsDNCode == null || IsDNCode.Rows.Count != 1)
  206. {
  207. throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种!
  208. }
  209. string dncode = Convert.ToString(IsDNCode.Rows[0]["HasDN"]);
  210. if (dncode.Equals(""))
  211. {
  212. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DeliveryNoticeURL, Inputstr);
  213. Result result = new Result();
  214. result = JsonConvert.DeserializeObject<Result>(resultStr);
  215. if (result.Success)
  216. {
  217. try
  218. {
  219. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  220. foreach (var item in res)
  221. {
  222. JObject jo = (JObject)item;
  223. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  224. foreach (var detail in resdetail)
  225. {
  226. JObject det = (JObject)detail;
  227. 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()
  228. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  229. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  230. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  231. }
  232. }
  233. }
  234. catch (Exception ex)
  235. {
  236. log.Debug(ex.ToString());
  237. log.Debug(resultStr);
  238. }
  239. }
  240. else
  241. {
  242. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  243. }
  244. }
  245. else
  246. {
  247. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseOrderURL, Inputstr);
  248. Result result = new Result();
  249. result = JsonConvert.DeserializeObject<Result>(resultStr);
  250. if (result.Success)
  251. {
  252. try
  253. {
  254. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  255. foreach (var item in res)
  256. {
  257. JObject jo = (JObject)item;
  258. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  259. foreach (var detail in resdetail)
  260. {
  261. JObject det = (JObject)detail;
  262. 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()
  263. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  264. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
  265. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  266. }
  267. }
  268. }
  269. catch (Exception ex)
  270. {
  271. log.Debug(ex.ToString());
  272. log.Debug(resultStr);
  273. }
  274. }
  275. else
  276. {
  277. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  278. }
  279. }
  280. #endregion
  281. }
  282. catch (Exception)
  283. {
  284. throw;
  285. }
  286. }
  287. /// <summary>
  288. /// 创建标准收货单U9(采购)
  289. /// </summary>
  290. /// <param name="TransType"></param>
  291. /// <param name="Identification"></param>
  292. /// <param name="cmd"></param>
  293. public static void CreatePOArriveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode,string doctype)
  294. {
  295. try
  296. {
  297. #region ERP
  298. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence
  299. INTO #NewTempERP
  300. from ICSWareHouseLotInfoLog
  301. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  302. SELECT c.VenCode+a.ToWarehouseCode+c.POCode+a.MUSER+CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS DNCode,CASE WHEN(LEN(f.DNID)>=20) THEN '1' ELSE '0' END AS HasDN,a.MUSER,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.Sequence END AS DNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.POCode,c.PODetailID,a.InvCode) AS Sequence,
  303. 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,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.PODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose
  304. --,a.lotno AS Costre2
  305. ,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,
  306. 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 ,'{2}' as DocTyppe,getdate() as DocDate,c.Sequence as srcDocPOLineNo
  307. INTO #TempERP
  308. FROM #NewTempERP a
  309. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  310. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  311. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  312. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  313. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  314. INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  315. INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  316. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  317. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  318. INNER JOIN ICSConfiguration conn ON a.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  319. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
  320. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose003'
  321. GROUP BY-- a.LotNo,
  322. a.TransSequence,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END,f.DNID,a.MUSER,a.InvCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.Sequence END,c.PODetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable,conStock.Enable,conStocknew.Enable
  323. ,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, ''),
  324. 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, ''),c.Sequence
  325. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WhCode,POCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,UpdateStock,IsFillClose,DocTyppe, DocDate, DocDate as ArrDate FROM #TempERP
  326. SELECT Costre,
  327. --Costre2,
  328. Sequence,DNSequence,InvCode,Quantity,Amount,PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WarehouseCode AS WhCode,srcDocPOLineNo
  329. FROM #TempERP
  330. SELECT SUM(a.Quantity) AS Quantity--,a.LotNo AS Costre2,a.LotNo,
  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.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  336. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  337. INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  338. INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  339. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  340. INNER JOIN #TempERP te ON te.Sequence=a.TransSequence
  341. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  342. --GROUP BY a.LotNo
  343. SELECT DISTINCT HasDN FROM #TempERP
  344. DROP TABLE #TempERP
  345. DROP TABLE #NewTempERP";
  346. sql = string.Format(sql, Identification, BusinessCode,doctype);
  347. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  348. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  349. //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
  350. var IsDNCode = ds.Tables[3];
  351. if (IsDNCode == null || IsDNCode.Rows.Count != 1)
  352. {
  353. throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种!
  354. }
  355. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9CreatePOArrivURL, Inputstr);
  356. Result result = new Result();
  357. result = JsonConvert.DeserializeObject<Result>(resultStr);
  358. if (result.Success)
  359. {
  360. try
  361. {
  362. //JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  363. //foreach (var item in res)
  364. //{
  365. // JObject jo = (JObject)item;
  366. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  367. // foreach (var detail in resdetail)
  368. // {
  369. // JObject det = (JObject)detail;
  370. // string allcol = jo["cWhCode"].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()
  371. // + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  372. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
  373. // det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  374. // }
  375. //}
  376. }
  377. catch (Exception ex)
  378. {
  379. log.Debug(ex.ToString());
  380. log.Debug(resultStr);
  381. }
  382. }
  383. else
  384. {
  385. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  386. }
  387. #endregion
  388. }
  389. catch (Exception)
  390. {
  391. throw;
  392. }
  393. }
  394. #endregion
  395. #region 审核的到货单
  396. /// <summary>
  397. /// 审核的到货单
  398. /// </summary>
  399. /// <param name="TransCode"></param>
  400. /// <param name="TransSequence"></param>
  401. /// <param name="Quantity"></param>
  402. /// <param name="WorkPoint"></param>
  403. /// <param name="cmd"></param>
  404. public static void DeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  405. {
  406. try
  407. {
  408. string sql = @"DECLARE @Status VARCHAR(10)
  409. SELECT @Status=c.Status FROM ICSInventoryLot a
  410. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  411. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  412. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  413. IF (@Status IS NULL)
  414. BEGIN
  415. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  416. RETURN
  417. END
  418. ELSE IF (@Status='3')
  419. BEGIN
  420. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  421. RETURN
  422. END
  423. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  424. FROM ICSInventoryLot a
  425. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  426. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  427. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  428. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  429. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  430. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  431. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1' AND c.Quantity<c.RCVQuantity)
  432. BEGIN
  433. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  434. END";
  435. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  436. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  437. {
  438. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  439. }
  440. }
  441. catch (Exception)
  442. {
  443. throw;
  444. }
  445. }
  446. /// <summary>
  447. /// 审核的到货单接口
  448. /// </summary>
  449. /// <param name="TransType"></param>
  450. /// <param name="Identification"></param>
  451. /// <param name="cmd"></param>
  452. public static DataTable DeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  453. {
  454. try
  455. {
  456. DataTable dtablee = new DataTable();
  457. string checklotno = "";
  458. string checksql = @"SELECT c.dncode,a.lotno FROM ICSInventoryLot a
  459. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  460. INNER JOIN (select dncode,Sequence,WorkPoint FROM ICSDeliveryNotice) c ON b.TransCode=c.dncode
  461. AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  462. WHERE c.dncode in (select TransCode from ICSWareHouseLotInfoLog
  463. where Identification='{0}' )
  464. and a.lotno NOT IN (select LotNo from ICSWareHouseLotInfo)";
  465. checksql = string.Format(checksql, Identification);
  466. DataTable dtt = DBHelper.SQlReturnData(checksql, cmd);
  467. if (dtt.Rows.Count > 1)
  468. {
  469. // 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
  470. foreach (DataRow row in dtt.Rows)
  471. {
  472. checklotno += row["lotno"].ToString() + ",";
  473. }
  474. checklotno = checklotno.TrimEnd(','); // 去除最后一个逗号
  475. }
  476. else if (dtt.Rows.Count == 1)
  477. {
  478. // 如果dtt的行数等于1,直接将lotno赋值给checklotno
  479. checklotno = dtt.Rows[0]["lotno"].ToString();
  480. }
  481. string checkrcvcode = "";
  482. string checknewsql = @"SELECT distinct c.DNCode FROM ICSInventoryLot a
  483. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  484. INNER JOIN (select DNCode,Sequence,WorkPoint FROM ICSDeliveryNotice) c ON b.TransCode=c.DNCode
  485. AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  486. WHERE c.DNCode in (select TransCode from ICSWareHouseLotInfoLog
  487. where Identification='{0}' )
  488. and a.lotno NOT IN (select LotNo from ICSWareHouseLotInfo)";
  489. checknewsql = string.Format(checknewsql, Identification);
  490. DataTable dttnew = DBHelper.SQlReturnData(checknewsql, cmd);
  491. if (dttnew.Rows.Count > 1)
  492. {
  493. // 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
  494. foreach (DataRow row in dttnew.Rows)
  495. {
  496. checkrcvcode += row["DNCode"].ToString() + ",";
  497. }
  498. checkrcvcode = checkrcvcode.TrimEnd(','); // 去除最后一个逗号
  499. }
  500. else if (dttnew.Rows.Count == 1)
  501. {
  502. // 如果dtt的行数等于1,直接将lotno赋值给checklotno
  503. checkrcvcode = dttnew.Rows[0]["DNCode"].ToString();
  504. }
  505. #region ERP
  506. log.Debug("11111111");
  507. string sql = @"
  508. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  509. INTO #NewTempERP
  510. from ICSWareHouseLotInfoLog
  511. WHERE Identification='{0}' AND ERPUpload='0'
  512. SELECT c.VenCode+a.ToWarehouseCode+c.DNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.DNCode ,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.DNDetailID,a.InvCode) AS Sequence,
  513. 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,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.DNDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  514. ,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,
  515. 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
  516. INTO #TempERP
  517. FROM #NewTempERP a
  518. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  519. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  520. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  521. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  522. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  523. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  524. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  525. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  526. GROUP BY inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.DNCode,c.DNID,a.MUSER,a.InvCode,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conStock.Enable
  527. ,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, ''),
  528. 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, '')
  529. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  530. SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  531. FROM #TempERP
  532. DROP TABLE #TempERP
  533. DROP TABLE #NewTempERP";
  534. sql = string.Format(sql, Identification,checklotno, checkrcvcode);
  535. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  536. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  537. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DeliveryNoticeURL, Inputstr);
  538. Result result = new Result();
  539. result = JsonConvert.DeserializeObject<Result>(resultStr);
  540. if (result.Success)
  541. {
  542. try
  543. {
  544. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  545. foreach (var item in res)
  546. {
  547. JObject jo = (JObject)item;
  548. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  549. foreach (var detail in resdetail)
  550. {
  551. log.Debug("2222222");
  552. JObject det = (JObject)detail;
  553. 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()
  554. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  555. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  556. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  557. log.Debug("33333333");
  558. }
  559. }
  560. }
  561. catch (Exception ex)
  562. {
  563. log.Debug(ex.ToString());
  564. log.Debug(resultStr);
  565. }
  566. }
  567. else
  568. {
  569. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  570. }
  571. //sql= @" SELECT {1},{2} FROM ICSDeliveryNotice b
  572. // WHERE b.DNCode + b.WorkPoint IN(SELECT a.TransCode + a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification = '{0}'
  573. // and SUM(Quantity)<>SUM(RCVQuantity))";
  574. //sql = string.Format(sql, Identification, checklotno, checkrcvcode);
  575. log.Debug("4444444");
  576. DataTable chekdt = new DataTable();
  577. chekdt.Columns.Add("checkrcvcode", typeof(string));
  578. chekdt.Columns.Add("checklotno", typeof(string));
  579. DataRow newrow = chekdt.NewRow();
  580. newrow["checkrcvcode"] = checkrcvcode;
  581. newrow["checklotno"] = checklotno;
  582. chekdt.Rows.Add(newrow);
  583. string aaaa = JsonConvert.SerializeObject(chekdt);
  584. return chekdt;
  585. #endregion
  586. }
  587. catch (Exception)
  588. {
  589. throw;
  590. }
  591. }
  592. #endregion
  593. #region 采购拒收
  594. /// <summary>
  595. /// 采购拒收
  596. /// </summary>
  597. /// <param name="TransCode"></param>
  598. /// <param name="TransSequence"></param>
  599. /// <param name="Quantity"></param>
  600. /// <param name="WorkPoint"></param>
  601. /// <param name="cmd"></param>
  602. public static void PurchaseRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  603. {
  604. try
  605. {
  606. string sql = @"DECLARE @Status VARCHAR(10)
  607. SELECT @Status=c.Status FROM ICSInventoryLot a
  608. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  609. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  610. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  611. IF (@Status IS NULL)
  612. BEGIN
  613. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  614. RETURN
  615. END
  616. ELSE IF (@Status='3')
  617. BEGIN
  618. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  619. RETURN
  620. END
  621. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  622. FROM ICSInventoryLot a
  623. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  624. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  625. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  626. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  627. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  628. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  629. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3' AND c.Quantity<c.RCVQuantity)
  630. BEGIN
  631. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  632. END";
  633. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  634. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  635. {
  636. throw new Exception(language.GetNameByCode("WMSAPIInfo084"));//"拒收单更新失败!");
  637. }
  638. }
  639. catch (Exception)
  640. {
  641. throw;
  642. }
  643. }
  644. /// <summary>
  645. /// 采购拒收接口
  646. /// </summary>
  647. /// <param name="TransType"></param>
  648. /// <param name="Identification"></param>
  649. /// <param name="cmd"></param>
  650. public static void PurchaseRejectDocInNewERP(string DNCode, string JDNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  651. {
  652. //try
  653. //{
  654. // #region ERP
  655. // string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.DNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,d.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.DNCode,c.DNDetailID,a.InvCode) AS Sequence,
  656. // a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.DNDetailID,con.Enable AS UpdateTodoQuantity
  657. // ,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,
  658. // 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,conv.Enable AS VerificationEnable
  659. // INTO #TempERP
  660. // FROM ICSWareHouseLotInfoLog a
  661. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  662. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  663. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  664. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  665. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  666. // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  667. // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
  668. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  669. // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  670. // WHERE a.Identification='{0}' AND ERPUpload='0'
  671. // GROUP BY c.VenCode,a.ToWarehouseCode,c.DNCode,d.DNCode,a.MUSER,lot.Amount,lot.Quantity,a.InvCode,d.DNDetailID,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conv.Enable
  672. // ,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, ''),
  673. // 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, '')
  674. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
  675. // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  676. // FROM #TempERP
  677. // DROP TABLE #TempERP";
  678. // sql = string.Format(sql, Identification);
  679. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  680. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  681. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  682. // Result result = new Result();
  683. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  684. // if (result.Success)
  685. // {
  686. // try
  687. // {
  688. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  689. // foreach (var item in res)
  690. // {
  691. // JObject jo = (JObject)item;
  692. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  693. // foreach (var detail in resdetail)
  694. // {
  695. // JObject det = (JObject)detail;
  696. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  697. // }
  698. // }
  699. // }
  700. // catch (Exception ex)
  701. // {
  702. // log.Debug(ex.ToString());
  703. // log.Debug(resultStr);
  704. // }
  705. // }
  706. // else
  707. // {
  708. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  709. // }
  710. // #endregion
  711. //}
  712. //catch (Exception)
  713. //{
  714. // throw;
  715. //}
  716. try
  717. {
  718. #region ERP
  719. string sql = @"SELECT ISNULL(a.VenCode,'')+ISNULL(a.DepCode,'')+ISNULL(x.DNCode,'')+ISNULL(a.MUSER,'') AS Costre,a.VenCode,ISNULL(a.DepCode,'') AS DepCode,x.DNCode,a.MUSER,a.MTIME,
  720. a.Sequence,a.InvCode,Sum(a.Quantity) AS Quantity,CASE invBat.AmountEnable WHEN '1' THEN a.Amount ELSE '0' END AS Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,x.DNDetailID
  721. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  722. 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
  723. INTO #TempERP
  724. FROM ICSDeliveryNotice a
  725. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  726. INNER JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  727. INNER JOIN ICSDeliveryNotice x ON x.DNDetailID=a.PODetailID AND a.WorkPoint=x.WorkPoint
  728. WHERE a.DNCode='{0}' AND a.WorkPoint='{1}'
  729. GROUP BY a.VenCode,a.DepCode,x.DNCode,a.MUSER,a.MTIME,a.Sequence,invBat.AmountEnable,a.InvCode,a.Amount,a.Quantity,a.UnitPrice,a.Currency,x.DNDetailID,
  730. a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(invBat.BatchEnable, ''),ISNULL(ext.BatchCode, ''),ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  731. 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, '')
  732. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  733. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,DNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  734. FROM #TempERP
  735. DROP TABLE #TempERP";
  736. sql = string.Format(sql, JDNCode, WorkPoint);
  737. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  738. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  739. string resultStr = HTTPHelper.HttpPost("采购拒收", ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  740. Result result = new Result();
  741. result = JsonConvert.DeserializeObject<Result>(resultStr);
  742. if (result.Success)
  743. {
  744. try
  745. {
  746. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  747. foreach (var item in res)
  748. {
  749. JObject jo = (JObject)item;
  750. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  751. foreach (var detail in resdetail)
  752. {
  753. JObject det = (JObject)detail;
  754. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RJTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  755. string ERPupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}'
  756. where PODetailID='{4}' AND DNType='3' AND DNCode='{5}' ";
  757. ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], JDNCode);
  758. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  759. {
  760. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  761. }
  762. }
  763. }
  764. }
  765. catch (Exception ex)
  766. {
  767. log.Debug(ex.ToString());
  768. log.Debug(resultStr);
  769. }
  770. }
  771. else
  772. {
  773. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  774. }
  775. #endregion
  776. }
  777. catch (Exception)
  778. {
  779. throw;
  780. }
  781. }
  782. /// <summary>
  783. /// 采购拒收接口
  784. /// </summary>
  785. /// <param name="TransType"></param>
  786. /// <param name="Identification"></param>
  787. /// <param name="cmd"></param>
  788. public static void PurchaseRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  789. {
  790. //try
  791. //{
  792. // #region ERP
  793. // string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.DNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,d.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.DNCode,c.DNDetailID,a.InvCode) AS Sequence,
  794. // a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.DNDetailID,con.Enable AS UpdateTodoQuantity
  795. // ,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,
  796. // 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,conv.Enable AS VerificationEnable
  797. // INTO #TempERP
  798. // FROM ICSWareHouseLotInfoLog a
  799. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  800. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  801. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  802. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  803. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  804. // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  805. // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
  806. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  807. // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  808. // WHERE a.Identification='{0}' AND ERPUpload='0'
  809. // GROUP BY c.VenCode,a.ToWarehouseCode,c.DNCode,d.DNCode,a.MUSER,a.InvCode,d.DNDetailID,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conv.Enable
  810. // ,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, ''),
  811. // 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, '')
  812. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
  813. // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  814. // FROM #TempERP
  815. // DROP TABLE #TempERP";
  816. // sql = string.Format(sql, Identification);
  817. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  818. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  819. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  820. // Result result = new Result();
  821. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  822. // if (result.Success)
  823. // {
  824. // try
  825. // {
  826. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  827. // foreach (var item in res)
  828. // {
  829. // JObject jo = (JObject)item;
  830. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  831. // foreach (var detail in resdetail)
  832. // {
  833. // JObject det = (JObject)detail;
  834. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  835. // }
  836. // }
  837. // }
  838. // catch (Exception ex)
  839. // {
  840. // log.Debug(ex.ToString());
  841. // log.Debug(resultStr);
  842. // }
  843. // }
  844. // else
  845. // {
  846. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  847. // }
  848. // #endregion
  849. //}
  850. //catch (Exception)
  851. //{
  852. // throw;
  853. //}
  854. }
  855. #endregion
  856. #region 采购退货
  857. /// <summary>
  858. /// 采购退货
  859. /// </summary>
  860. /// <param name="TransCode"></param>
  861. /// <param name="TransSequence"></param>
  862. /// <param name="Quantity"></param>
  863. /// <param name="WorkPoint"></param>
  864. /// <param name="cmd"></param>
  865. public static void PurchaseReceiveDoctNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  866. {
  867. try
  868. {
  869. string sql = @"DECLARE @Status VARCHAR(10)
  870. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' AND DNType='2' AND WorkPoint='{1}'
  871. IF (@Status IS NULL)
  872. BEGIN
  873. RAISERROR('" + language.GetNameByCode("WMSAPIInfo085") + @"',16,1);
  874. RETURN
  875. END
  876. ELSE IF (@Status!='2')
  877. BEGIN
  878. RAISERROR('" + language.GetNameByCode("WMSAPIInfo086") + @"',16,1);
  879. RETURN
  880. END
  881. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  882. FROM ICSDeliveryNotice a
  883. WHERE a.DNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND DNType='2'
  884. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a
  885. WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.RCVQuantity AND DNType='2')
  886. BEGIN
  887. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  888. RETURN
  889. END";
  890. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  891. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  892. {
  893. throw new Exception(language.GetNameByCode("WMSAPIInfo088"));//"采购退货单更新失败!");
  894. }
  895. }
  896. catch (Exception)
  897. {
  898. throw;
  899. }
  900. }
  901. /// <summary>
  902. /// 采购退货接口
  903. /// </summary>
  904. /// <param name="TransType"></param>
  905. /// <param name="Identification"></param>
  906. /// <param name="cmd"></param>
  907. public static void PurchaseReceiveDoctNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  908. {
  909. try
  910. {
  911. #region ERP
  912. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  913. INTO #NewTempERP
  914. from ICSWareHouseLotInfoLog
  915. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '3'
  916. SELECT y.VenCode+a.FromWarehouseCode+y.DNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.DNCode,y.DNDetailID,a.InvCode) AS Sequence,
  917. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(y.Amount/y.Quantity)) ELSE '0' END AS Amount,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  918. ,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,
  919. 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
  920. INTO #TempERP
  921. FROM #NewTempERP a
  922. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  923. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  924. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  925. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  926. INNER JOIN ICSDeliveryNotice y ON a.TransCode=y.DNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  927. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  928. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  929. GROUP BY inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.DNCode,a.MUSER,a.InvCode,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conStock.Enable
  930. ,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, ''),
  931. 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, '')
  932. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,DNCode AS DNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  933. SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID AS DNRTDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  934. FROM #TempERP
  935. DROP TABLE #TempERP
  936. DROP TABLE #NewTempERP";
  937. sql = string.Format(sql, Identification);
  938. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  939. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  940. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReturnBackURL, Inputstr);
  941. Result result = new Result();
  942. result = JsonConvert.DeserializeObject<Result>(resultStr);
  943. if (result.Success)
  944. {
  945. try
  946. {
  947. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  948. foreach (var item in res)
  949. {
  950. JObject jo = (JObject)item;
  951. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  952. foreach (var detail in resdetail)
  953. {
  954. JObject det = (JObject)detail;
  955. 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()
  956. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  957. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  958. det["DetailID"].ToString(), jo["RCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol,cmd, language,BusinessCode);
  959. }
  960. }
  961. }
  962. catch (Exception ex)
  963. {
  964. log.Debug(ex.ToString());
  965. log.Debug(resultStr);
  966. }
  967. }
  968. else
  969. {
  970. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  971. }
  972. #endregion
  973. }
  974. catch (Exception)
  975. {
  976. throw;
  977. }
  978. }
  979. #endregion
  980. #region 开立红字入库
  981. /// <summary>
  982. /// 开立红字入库
  983. /// </summary>
  984. /// <param name="TransCode"></param>
  985. /// <param name="TransSequence"></param>
  986. /// <param name="Quantity"></param>
  987. /// <param name="WorkPoint"></param>
  988. /// <param name="cmd"></param>
  989. public static void PurchaseReceive(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  990. {
  991. try
  992. {
  993. string sql = @"DECLARE @Status VARCHAR(10)
  994. SELECT @Status=a.Status FROM ICSPurchaseReceive a
  995. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  996. IF (@Status IS NULL)
  997. BEGIN
  998. RAISERROR('" + language.GetNameByCode("WMSAPIInfo089") + @"',16,1);
  999. RETURN
  1000. END
  1001. ELSE IF (@Status!='1')
  1002. BEGIN
  1003. RAISERROR('" + language.GetNameByCode("WMSAPIInfo090") + @"',16,1);
  1004. RETURN
  1005. END
  1006. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1007. FROM ICSPurchaseReceive a
  1008. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  1009. IF EXISTS(SELECT a.ID FROM ICSPurchaseReceive a
  1010. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='2' AND a.Quantity<a.RCVQuantity)
  1011. BEGIN
  1012. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  1013. RETURN
  1014. END";
  1015. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  1016. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1017. {
  1018. throw new Exception(language.GetNameByCode("WMSAPIInfo092"));//"红字入库单更新失败!");
  1019. }
  1020. }
  1021. catch (Exception)
  1022. {
  1023. throw;
  1024. }
  1025. }
  1026. /// <summary>
  1027. /// 开立红字入库接口
  1028. /// </summary>
  1029. /// <param name="TransType"></param>
  1030. /// <param name="Identification"></param>
  1031. /// <param name="cmd"></param>
  1032. public static void PurchaseReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1033. {
  1034. try
  1035. {
  1036. #region ERP开立状态单据审核
  1037. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  1038. INTO #NewTempERP
  1039. from ICSWareHouseLotInfoLog
  1040. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '4'
  1041. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  1042. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1043. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  1044. BEGIN
  1045. RAISERROR('" + language.GetNameByCode("WMSAPIInfo093") + @"',16,1);
  1046. RETURN
  1047. END
  1048. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1049. FROM #NewTempERP a
  1050. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1051. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1052. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  1053. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1054. DROP TABLE #NewTempERP";
  1055. sql = string.Format(sql, Identification);
  1056. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1057. string Inputstr = JsonConvert.SerializeObject(dt);
  1058. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReceiveDoctNegativeURL, Inputstr);
  1059. Result result = new Result();
  1060. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1061. if (result.Success)
  1062. {
  1063. try
  1064. {
  1065. foreach (DataRow dr in dt.Rows)
  1066. {
  1067. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1068. }
  1069. }
  1070. catch (Exception ex)
  1071. {
  1072. log.Debug(ex.ToString());
  1073. log.Debug(resultStr);
  1074. }
  1075. }
  1076. else
  1077. {
  1078. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1079. }
  1080. #endregion
  1081. }
  1082. catch (Exception)
  1083. {
  1084. throw;
  1085. }
  1086. }
  1087. #endregion
  1088. }
  1089. }