纽威
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.

943 lines
61 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years 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,a.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}' ";
  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 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,
  157. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.PODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable
  158. ,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,
  159. 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
  160. INTO #TempERP
  161. FROM ICSWareHouseLotInfoLog a
  162. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  163. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  164. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  165. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  166. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  167. INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  168. INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint
  169. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  170. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  171. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  172. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  173. GROUP BY 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
  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, '')
  176. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,POCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity FROM #TempERP
  177. SELECT Costre,Sequence,DNSequence,InvCode,Quantity,Amount,PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  178. FROM #TempERP
  179. SELECT HasDN FROM #TempERP
  180. DROP TABLE #TempERP";
  181. sql = string.Format(sql, Identification, BusinessCode);
  182. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  183. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  184. var IsDNCode = ds.Tables[2];
  185. if (IsDNCode == null || IsDNCode.Rows.Count != 1)
  186. {
  187. throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种!
  188. }
  189. string dncode = Convert.ToString(IsDNCode.Rows[0]["HasDN"]);
  190. if (dncode.Equals(""))
  191. {
  192. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DeliveryNoticeURL, Inputstr);
  193. Result result = new Result();
  194. result = JsonConvert.DeserializeObject<Result>(resultStr);
  195. if (result.Success)
  196. {
  197. try
  198. {
  199. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  200. foreach (var item in res)
  201. {
  202. JObject jo = (JObject)item;
  203. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  204. foreach (var detail in resdetail)
  205. {
  206. JObject det = (JObject)detail;
  207. 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()
  208. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  209. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  210. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  211. }
  212. }
  213. }
  214. catch (Exception ex)
  215. {
  216. log.Debug(ex.ToString());
  217. log.Debug(resultStr);
  218. }
  219. }
  220. else
  221. {
  222. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  223. }
  224. }
  225. else
  226. {
  227. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseOrderURL, Inputstr);
  228. Result result = new Result();
  229. result = JsonConvert.DeserializeObject<Result>(resultStr);
  230. if (result.Success)
  231. {
  232. try
  233. {
  234. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  235. foreach (var item in res)
  236. {
  237. JObject jo = (JObject)item;
  238. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  239. foreach (var detail in resdetail)
  240. {
  241. JObject det = (JObject)detail;
  242. 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()
  243. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  244. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
  245. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  246. }
  247. }
  248. }
  249. catch (Exception ex)
  250. {
  251. log.Debug(ex.ToString());
  252. log.Debug(resultStr);
  253. }
  254. }
  255. else
  256. {
  257. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  258. }
  259. }
  260. #endregion
  261. }
  262. catch (Exception)
  263. {
  264. throw;
  265. }
  266. }
  267. #endregion
  268. #region 审核的到货单
  269. /// <summary>
  270. /// 审核的到货单
  271. /// </summary>
  272. /// <param name="TransCode"></param>
  273. /// <param name="TransSequence"></param>
  274. /// <param name="Quantity"></param>
  275. /// <param name="WorkPoint"></param>
  276. /// <param name="cmd"></param>
  277. public static void DeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  278. {
  279. try
  280. {
  281. string sql = @"DECLARE @Status VARCHAR(10)
  282. SELECT @Status=c.Status FROM ICSInventoryLot a
  283. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  284. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  285. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  286. IF (@Status IS NULL)
  287. BEGIN
  288. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  289. RETURN
  290. END
  291. ELSE IF (@Status='3')
  292. BEGIN
  293. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  294. RETURN
  295. END
  296. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  297. FROM ICSInventoryLot a
  298. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  299. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  300. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  301. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  302. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  303. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  304. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1' AND c.Quantity<c.RCVQuantity)
  305. BEGIN
  306. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  307. END";
  308. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  309. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  310. {
  311. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  312. }
  313. }
  314. catch (Exception)
  315. {
  316. throw;
  317. }
  318. }
  319. /// <summary>
  320. /// 审核的到货单接口
  321. /// </summary>
  322. /// <param name="TransType"></param>
  323. /// <param name="Identification"></param>
  324. /// <param name="cmd"></param>
  325. public static void DeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  326. {
  327. try
  328. {
  329. #region ERP
  330. string sql = @"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,
  331. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.DNDetailID,Enable AS UpdateTodoQuantity
  332. ,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,
  333. 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
  334. INTO #TempERP
  335. FROM ICSWareHouseLotInfoLog a
  336. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  337. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  338. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  339. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  340. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  341. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  342. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  343. WHERE a.Identification='{0}' AND ERPUpload='0'
  344. GROUP BY c.VenCode,a.ToWarehouseCode,c.DNCode,c.DNID,a.MUSER,a.InvCode,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,Enable
  345. ,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, ''),
  346. 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, '')
  347. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  348. SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  349. FROM #TempERP
  350. DROP TABLE #TempERP";
  351. sql = string.Format(sql, Identification,BusinessCode);
  352. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  353. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  354. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DeliveryNoticeURL, Inputstr);
  355. Result result = new Result();
  356. result = JsonConvert.DeserializeObject<Result>(resultStr);
  357. if (result.Success)
  358. {
  359. try
  360. {
  361. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  362. foreach (var item in res)
  363. {
  364. JObject jo = (JObject)item;
  365. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  366. foreach (var detail in resdetail)
  367. {
  368. JObject det = (JObject)detail;
  369. 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()
  370. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  371. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  372. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  373. }
  374. }
  375. }
  376. catch (Exception ex)
  377. {
  378. log.Debug(ex.ToString());
  379. log.Debug(resultStr);
  380. }
  381. }
  382. else
  383. {
  384. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  385. }
  386. #endregion
  387. }
  388. catch (Exception)
  389. {
  390. throw;
  391. }
  392. }
  393. #endregion
  394. #region 采购拒收
  395. /// <summary>
  396. /// 采购拒收
  397. /// </summary>
  398. /// <param name="TransCode"></param>
  399. /// <param name="TransSequence"></param>
  400. /// <param name="Quantity"></param>
  401. /// <param name="WorkPoint"></param>
  402. /// <param name="cmd"></param>
  403. public static void PurchaseRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  404. {
  405. try
  406. {
  407. string sql = @"DECLARE @Status VARCHAR(10)
  408. SELECT @Status=c.Status FROM ICSInventoryLot a
  409. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  410. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  411. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  412. IF (@Status IS NULL)
  413. BEGIN
  414. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  415. RETURN
  416. END
  417. ELSE IF (@Status='3')
  418. BEGIN
  419. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  420. RETURN
  421. END
  422. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  423. FROM ICSInventoryLot a
  424. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  425. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  426. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  427. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  428. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  429. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  430. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3' AND c.Quantity<c.RCVQuantity)
  431. BEGIN
  432. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  433. END";
  434. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  435. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  436. {
  437. throw new Exception(language.GetNameByCode("WMSAPIInfo084"));//"拒收单更新失败!");
  438. }
  439. }
  440. catch (Exception)
  441. {
  442. throw;
  443. }
  444. }
  445. /// <summary>
  446. /// 采购拒收接口
  447. /// </summary>
  448. /// <param name="TransType"></param>
  449. /// <param name="Identification"></param>
  450. /// <param name="cmd"></param>
  451. public static void PurchaseRejectDocInNewERP(string DNCode, string JDNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  452. {
  453. //try
  454. //{
  455. // #region ERP
  456. // 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,
  457. // 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
  458. // ,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,
  459. // 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
  460. // INTO #TempERP
  461. // FROM ICSWareHouseLotInfoLog a
  462. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  463. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  464. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  465. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  466. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  467. // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  468. // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
  469. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  470. // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  471. // WHERE a.Identification='{0}' AND ERPUpload='0'
  472. // 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
  473. // ,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, ''),
  474. // 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, '')
  475. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
  476. // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  477. // FROM #TempERP
  478. // DROP TABLE #TempERP";
  479. // sql = string.Format(sql, Identification);
  480. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  481. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  482. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  483. // Result result = new Result();
  484. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  485. // if (result.Success)
  486. // {
  487. // try
  488. // {
  489. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  490. // foreach (var item in res)
  491. // {
  492. // JObject jo = (JObject)item;
  493. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  494. // foreach (var detail in resdetail)
  495. // {
  496. // JObject det = (JObject)detail;
  497. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  498. // }
  499. // }
  500. // }
  501. // catch (Exception ex)
  502. // {
  503. // log.Debug(ex.ToString());
  504. // log.Debug(resultStr);
  505. // }
  506. // }
  507. // else
  508. // {
  509. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  510. // }
  511. // #endregion
  512. //}
  513. //catch (Exception)
  514. //{
  515. // throw;
  516. //}
  517. try
  518. {
  519. #region ERP
  520. string sql = @"SELECT a.VenCode+a.DepCode+a.DNCode+a.MUSER AS Costre,a.VenCode,a.DepCode,a.DNCode,a.MUSER,a.MTIME,
  521. a.Sequence,a.InvCode,Sum(x.Quantity) AS Quantity,a.Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.DNDetailID
  522. ,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,
  523. 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
  524. INTO #TempERP
  525. FROM ICSDeliveryNotice a
  526. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  527. INNER JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  528. INNER JOIN ICSDeliveryNotice x ON a.DNDetailID=x.PODetailID AND a.WorkPoint=x.WorkPoint
  529. WHERE a.DNCode='{0}' AND a.WorkPoint='{1}'
  530. GROUP BY a.VenCode,a.DepCode,a.DNCode,a.MUSER,a.MTIME,a.Sequence,a.InvCode,a.Amount,a.Quantity,a.UnitPrice,a.Currency,a.DNDetailID,
  531. a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(invBat.BatchEnable, ''),ISNULL(ext.BatchCode, ''),ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  532. 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, '')
  533. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  534. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,DNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  535. FROM #TempERP
  536. DROP TABLE #TempERP";
  537. sql = string.Format(sql, DNCode, WorkPoint);
  538. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  539. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  540. string resultStr = HTTPHelper.HttpPost("采购拒收", ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  541. Result result = new Result();
  542. result = JsonConvert.DeserializeObject<Result>(resultStr);
  543. if (result.Success)
  544. {
  545. try
  546. {
  547. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  548. foreach (var item in res)
  549. {
  550. JObject jo = (JObject)item;
  551. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  552. foreach (var detail in resdetail)
  553. {
  554. JObject det = (JObject)detail;
  555. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RJTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  556. string ERPupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}'
  557. where PODetailID='{4}' AND DNType='3' AND DNCode='{5}' ";
  558. ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], JDNCode);
  559. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  560. {
  561. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  562. }
  563. }
  564. }
  565. }
  566. catch (Exception ex)
  567. {
  568. log.Debug(ex.ToString());
  569. log.Debug(resultStr);
  570. }
  571. }
  572. else
  573. {
  574. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  575. }
  576. #endregion
  577. }
  578. catch (Exception)
  579. {
  580. throw;
  581. }
  582. }
  583. /// <summary>
  584. /// 采购拒收接口
  585. /// </summary>
  586. /// <param name="TransType"></param>
  587. /// <param name="Identification"></param>
  588. /// <param name="cmd"></param>
  589. public static void PurchaseRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  590. {
  591. //try
  592. //{
  593. // #region ERP
  594. // 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,
  595. // 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
  596. // ,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,
  597. // 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
  598. // INTO #TempERP
  599. // FROM ICSWareHouseLotInfoLog a
  600. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  601. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  602. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  603. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  604. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  605. // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  606. // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
  607. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  608. // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  609. // WHERE a.Identification='{0}' AND ERPUpload='0'
  610. // 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
  611. // ,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, ''),
  612. // 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, '')
  613. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
  614. // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  615. // FROM #TempERP
  616. // DROP TABLE #TempERP";
  617. // sql = string.Format(sql, Identification);
  618. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  619. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  620. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  621. // Result result = new Result();
  622. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  623. // if (result.Success)
  624. // {
  625. // try
  626. // {
  627. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  628. // foreach (var item in res)
  629. // {
  630. // JObject jo = (JObject)item;
  631. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  632. // foreach (var detail in resdetail)
  633. // {
  634. // JObject det = (JObject)detail;
  635. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  636. // }
  637. // }
  638. // }
  639. // catch (Exception ex)
  640. // {
  641. // log.Debug(ex.ToString());
  642. // log.Debug(resultStr);
  643. // }
  644. // }
  645. // else
  646. // {
  647. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  648. // }
  649. // #endregion
  650. //}
  651. //catch (Exception)
  652. //{
  653. // throw;
  654. //}
  655. }
  656. #endregion
  657. #region 采购退货
  658. /// <summary>
  659. /// 采购退货
  660. /// </summary>
  661. /// <param name="TransCode"></param>
  662. /// <param name="TransSequence"></param>
  663. /// <param name="Quantity"></param>
  664. /// <param name="WorkPoint"></param>
  665. /// <param name="cmd"></param>
  666. public static void PurchaseReceiveDoctNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  667. {
  668. try
  669. {
  670. string sql = @"DECLARE @Status VARCHAR(10)
  671. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' AND DNType='2' AND WorkPoint='{1}'
  672. IF (@Status IS NULL)
  673. BEGIN
  674. RAISERROR('" + language.GetNameByCode("WMSAPIInfo085") + @"',16,1);
  675. RETURN
  676. END
  677. ELSE IF (@Status!='2')
  678. BEGIN
  679. RAISERROR('" + language.GetNameByCode("WMSAPIInfo086") + @"',16,1);
  680. RETURN
  681. END
  682. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  683. FROM ICSDeliveryNotice a
  684. WHERE a.DNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND DNType='2'
  685. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a
  686. WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.RCVQuantity AND DNType='2')
  687. BEGIN
  688. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  689. RETURN
  690. END";
  691. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  692. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  693. {
  694. throw new Exception(language.GetNameByCode("WMSAPIInfo088"));//"采购退货单更新失败!");
  695. }
  696. }
  697. catch (Exception)
  698. {
  699. throw;
  700. }
  701. }
  702. /// <summary>
  703. /// 采购退货接口
  704. /// </summary>
  705. /// <param name="TransType"></param>
  706. /// <param name="Identification"></param>
  707. /// <param name="cmd"></param>
  708. public static void PurchaseReceiveDoctNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  709. {
  710. try
  711. {
  712. #region ERP
  713. string sql = @"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,
  714. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(y.Amount/y.Quantity)) AS Amount,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,Enable AS UpdateTodoQuantity
  715. ,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,
  716. 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
  717. INTO #TempERP
  718. FROM ICSWareHouseLotInfoLog a
  719. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  720. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  721. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  722. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  723. INNER JOIN ICSDeliveryNotice y ON a.TransCode=y.DNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  724. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  725. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '3'
  726. GROUP BY y.VenCode,a.FromWarehouseCode,y.DNCode,a.MUSER,a.InvCode,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),Enable
  727. ,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, ''),
  728. 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, '')
  729. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,DNCode AS DNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  730. 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
  731. FROM #TempERP
  732. DROP TABLE #TempERP";
  733. sql = string.Format(sql, Identification);
  734. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  735. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  736. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReturnBackURL, Inputstr);
  737. Result result = new Result();
  738. result = JsonConvert.DeserializeObject<Result>(resultStr);
  739. if (result.Success)
  740. {
  741. try
  742. {
  743. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  744. foreach (var item in res)
  745. {
  746. JObject jo = (JObject)item;
  747. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  748. foreach (var detail in resdetail)
  749. {
  750. JObject det = (JObject)detail;
  751. 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()
  752. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  753. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  754. det["DetailID"].ToString(), jo["RCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol,cmd, language,BusinessCode);
  755. }
  756. }
  757. }
  758. catch (Exception ex)
  759. {
  760. log.Debug(ex.ToString());
  761. log.Debug(resultStr);
  762. }
  763. }
  764. else
  765. {
  766. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  767. }
  768. #endregion
  769. }
  770. catch (Exception)
  771. {
  772. throw;
  773. }
  774. }
  775. #endregion
  776. #region 开立红字入库
  777. /// <summary>
  778. /// 开立红字入库
  779. /// </summary>
  780. /// <param name="TransCode"></param>
  781. /// <param name="TransSequence"></param>
  782. /// <param name="Quantity"></param>
  783. /// <param name="WorkPoint"></param>
  784. /// <param name="cmd"></param>
  785. public static void PurchaseReceive(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  786. {
  787. try
  788. {
  789. string sql = @"DECLARE @Status VARCHAR(10)
  790. SELECT @Status=a.Status FROM ICSPurchaseReceive a
  791. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  792. IF (@Status IS NULL)
  793. BEGIN
  794. RAISERROR('" + language.GetNameByCode("WMSAPIInfo089") + @"',16,1);
  795. RETURN
  796. END
  797. ELSE IF (@Status!='1')
  798. BEGIN
  799. RAISERROR('" + language.GetNameByCode("WMSAPIInfo090") + @"',16,1);
  800. RETURN
  801. END
  802. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  803. FROM ICSPurchaseReceive a
  804. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  805. IF EXISTS(SELECT a.ID FROM ICSPurchaseReceive a
  806. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='2' AND a.Quantity<a.RCVQuantity)
  807. BEGIN
  808. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  809. RETURN
  810. END";
  811. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  812. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  813. {
  814. throw new Exception(language.GetNameByCode("WMSAPIInfo092"));//"红字入库单更新失败!");
  815. }
  816. }
  817. catch (Exception)
  818. {
  819. throw;
  820. }
  821. }
  822. /// <summary>
  823. /// 开立红字入库接口
  824. /// </summary>
  825. /// <param name="TransType"></param>
  826. /// <param name="Identification"></param>
  827. /// <param name="cmd"></param>
  828. public static void PurchaseReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  829. {
  830. try
  831. {
  832. #region ERP开立状态单据审核
  833. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  834. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  835. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  836. BEGIN
  837. RAISERROR('" + language.GetNameByCode("WMSAPIInfo093") + @"',16,1);
  838. RETURN
  839. END
  840. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  841. FROM ICSWareHouseLotInfoLog a
  842. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  843. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  844. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  845. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '4'
  846. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  847. sql = string.Format(sql, Identification);
  848. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  849. string Inputstr = JsonConvert.SerializeObject(dt);
  850. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReceiveDoctNegativeURL, Inputstr);
  851. Result result = new Result();
  852. result = JsonConvert.DeserializeObject<Result>(resultStr);
  853. if (result.Success)
  854. {
  855. try
  856. {
  857. foreach (DataRow dr in dt.Rows)
  858. {
  859. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  860. }
  861. }
  862. catch (Exception ex)
  863. {
  864. log.Debug(ex.ToString());
  865. log.Debug(resultStr);
  866. }
  867. }
  868. else
  869. {
  870. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  871. }
  872. #endregion
  873. }
  874. catch (Exception)
  875. {
  876. throw;
  877. }
  878. }
  879. #endregion
  880. }
  881. }