爱思开
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.

732 lines
45 KiB

2 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)
  152. {
  153. try
  154. {
  155. #region ERP
  156. string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.POCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.POCode,a.MUSER,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,Enable AS UpdateTodoQuantity
  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 ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  168. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  169. WHERE a.Identification='{0}' AND ERPUpload='0'
  170. GROUP BY c.VenCode,a.ToWarehouseCode,c.POCode,a.MUSER,a.InvCode,c.PODetailID,isnull((c.UnitPrice),0),c.Currency,Enable
  171. ,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, ''),
  172. 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, '')
  173. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,POCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  174. SELECT Costre,Sequence,InvCode,Quantity,Amount,PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  175. FROM #TempERP
  176. DROP TABLE #TempERP";
  177. sql = string.Format(sql, Identification);
  178. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  179. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  180. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseOrderURL, Inputstr);
  181. Result result = new Result();
  182. result = JsonConvert.DeserializeObject<Result>(resultStr);
  183. if (result.Success)
  184. {
  185. try
  186. {
  187. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  188. foreach (var item in res)
  189. {
  190. JObject jo = (JObject)item;
  191. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  192. foreach (var detail in resdetail)
  193. {
  194. JObject det = (JObject)detail;
  195. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
  196. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  197. }
  198. }
  199. }
  200. catch (Exception ex)
  201. {
  202. log.Debug(ex.ToString());
  203. log.Debug(resultStr);
  204. }
  205. }
  206. else
  207. {
  208. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  209. }
  210. #endregion
  211. }
  212. catch (Exception)
  213. {
  214. throw;
  215. }
  216. }
  217. #endregion
  218. #region 审核的到货单
  219. /// <summary>
  220. /// 审核的到货单
  221. /// </summary>
  222. /// <param name="TransCode"></param>
  223. /// <param name="TransSequence"></param>
  224. /// <param name="Quantity"></param>
  225. /// <param name="WorkPoint"></param>
  226. /// <param name="cmd"></param>
  227. public static void DeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  228. {
  229. try
  230. {
  231. string sql = @"DECLARE @Status VARCHAR(10)
  232. SELECT @Status=c.Status FROM ICSInventoryLot a
  233. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  234. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  235. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  236. IF (@Status IS NULL)
  237. BEGIN
  238. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  239. RETURN
  240. END
  241. ELSE IF (@Status='3')
  242. BEGIN
  243. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  244. RETURN
  245. END
  246. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  247. FROM ICSInventoryLot a
  248. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  249. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  250. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  251. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  252. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  253. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  254. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1' AND c.Quantity<c.RCVQuantity)
  255. BEGIN
  256. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  257. END";
  258. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  259. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  260. {
  261. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  262. }
  263. }
  264. catch (Exception)
  265. {
  266. throw;
  267. }
  268. }
  269. /// <summary>
  270. /// 审核的到货单接口
  271. /// </summary>
  272. /// <param name="TransType"></param>
  273. /// <param name="Identification"></param>
  274. /// <param name="cmd"></param>
  275. public static void DeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  276. {
  277. try
  278. {
  279. #region ERP
  280. 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.DNCode,c.DNDetailID,a.InvCode) AS Sequence,
  281. 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.DNDetailID,Enable AS UpdateTodoQuantity
  282. ,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,
  283. 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
  284. INTO #TempERP
  285. FROM ICSWareHouseLotInfoLog a
  286. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  287. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  288. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  289. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  290. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  291. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  292. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  293. WHERE a.Identification='{0}' AND ERPUpload='0'
  294. GROUP BY c.VenCode,a.ToWarehouseCode,c.DNCode,a.MUSER,a.InvCode,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,Enable
  295. ,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, ''),
  296. 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, '')
  297. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  298. SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  299. FROM #TempERP
  300. DROP TABLE #TempERP";
  301. sql = string.Format(sql, Identification);
  302. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  303. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  304. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DeliveryNoticeURL, Inputstr);
  305. Result result = new Result();
  306. result = JsonConvert.DeserializeObject<Result>(resultStr);
  307. if (result.Success)
  308. {
  309. try
  310. {
  311. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  312. foreach (var item in res)
  313. {
  314. JObject jo = (JObject)item;
  315. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  316. foreach (var detail in resdetail)
  317. {
  318. JObject det = (JObject)detail;
  319. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  320. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  321. }
  322. }
  323. }
  324. catch (Exception ex)
  325. {
  326. log.Debug(ex.ToString());
  327. log.Debug(resultStr);
  328. }
  329. }
  330. else
  331. {
  332. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  333. }
  334. #endregion
  335. }
  336. catch (Exception)
  337. {
  338. throw;
  339. }
  340. }
  341. #endregion
  342. #region 采购拒收
  343. /// <summary>
  344. /// 采购拒收
  345. /// </summary>
  346. /// <param name="TransCode"></param>
  347. /// <param name="TransSequence"></param>
  348. /// <param name="Quantity"></param>
  349. /// <param name="WorkPoint"></param>
  350. /// <param name="cmd"></param>
  351. public static void PurchaseRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  352. {
  353. try
  354. {
  355. string sql = @"DECLARE @Status VARCHAR(10)
  356. SELECT @Status=c.Status FROM ICSInventoryLot a
  357. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  358. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  359. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  360. IF (@Status IS NULL)
  361. BEGIN
  362. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  363. RETURN
  364. END
  365. ELSE IF (@Status='3')
  366. BEGIN
  367. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  368. RETURN
  369. END
  370. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  371. FROM ICSInventoryLot a
  372. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  373. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  374. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  375. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  376. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  377. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  378. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3' AND c.Quantity<c.RCVQuantity)
  379. BEGIN
  380. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  381. END";
  382. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  383. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  384. {
  385. throw new Exception(language.GetNameByCode("WMSAPIInfo084"));//"拒收单更新失败!");
  386. }
  387. }
  388. catch (Exception)
  389. {
  390. throw;
  391. }
  392. }
  393. /// <summary>
  394. /// 采购拒收接口
  395. /// </summary>
  396. /// <param name="TransType"></param>
  397. /// <param name="Identification"></param>
  398. /// <param name="cmd"></param>
  399. public static void PurchaseRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  400. {
  401. try
  402. {
  403. #region ERP
  404. 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,
  405. 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,Enable AS UpdateTodoQuantity
  406. ,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,
  407. 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
  408. INTO #TempERP
  409. FROM ICSWareHouseLotInfoLog a
  410. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  411. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  412. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  413. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  414. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  415. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  416. INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
  417. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  418. WHERE a.Identification='{0}' AND ERPUpload='0'
  419. GROUP BY c.VenCode,a.ToWarehouseCode,c.DNCode,d.DNCode,a.MUSER,a.InvCode,d.DNDetailID,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,Enable
  420. ,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, ''),
  421. 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, '')
  422. SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint FROM #TempERP
  423. SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  424. FROM #TempERP
  425. DROP TABLE #TempERP";
  426. sql = string.Format(sql, Identification);
  427. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  428. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  429. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  430. Result result = new Result();
  431. result = JsonConvert.DeserializeObject<Result>(resultStr);
  432. if (result.Success)
  433. {
  434. try
  435. {
  436. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  437. foreach (var item in res)
  438. {
  439. JObject jo = (JObject)item;
  440. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  441. foreach (var detail in resdetail)
  442. {
  443. JObject det = (JObject)detail;
  444. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  445. }
  446. }
  447. }
  448. catch (Exception ex)
  449. {
  450. log.Debug(ex.ToString());
  451. log.Debug(resultStr);
  452. }
  453. }
  454. else
  455. {
  456. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  457. }
  458. #endregion
  459. }
  460. catch (Exception)
  461. {
  462. throw;
  463. }
  464. }
  465. #endregion
  466. #region 采购退货
  467. /// <summary>
  468. /// 采购退货
  469. /// </summary>
  470. /// <param name="TransCode"></param>
  471. /// <param name="TransSequence"></param>
  472. /// <param name="Quantity"></param>
  473. /// <param name="WorkPoint"></param>
  474. /// <param name="cmd"></param>
  475. public static void PurchaseReceiveDoctNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  476. {
  477. try
  478. {
  479. string sql = @"DECLARE @Status VARCHAR(10)
  480. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' AND DNType='2' AND WorkPoint='{1}'
  481. IF (@Status IS NULL)
  482. BEGIN
  483. RAISERROR('" + language.GetNameByCode("WMSAPIInfo085") + @"',16,1);
  484. RETURN
  485. END
  486. ELSE IF (@Status!='2')
  487. BEGIN
  488. RAISERROR('" + language.GetNameByCode("WMSAPIInfo086") + @"',16,1);
  489. RETURN
  490. END
  491. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  492. FROM ICSDeliveryNotice a
  493. WHERE a.DNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND DNType='2'
  494. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a
  495. WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.RCVQuantity AND DNType='2')
  496. BEGIN
  497. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  498. RETURN
  499. END";
  500. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  501. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  502. {
  503. throw new Exception(language.GetNameByCode("WMSAPIInfo088"));//"采购退货单更新失败!");
  504. }
  505. }
  506. catch (Exception)
  507. {
  508. throw;
  509. }
  510. }
  511. /// <summary>
  512. /// 采购退货接口
  513. /// </summary>
  514. /// <param name="TransType"></param>
  515. /// <param name="Identification"></param>
  516. /// <param name="cmd"></param>
  517. public static void PurchaseReceiveDoctNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  518. {
  519. try
  520. {
  521. #region ERP
  522. 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,
  523. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*lot.Amount/lot.Quantity) AS Amount,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,Enable AS UpdateTodoQuantity
  524. ,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,
  525. 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
  526. INTO #TempERP
  527. FROM ICSWareHouseLotInfoLog a
  528. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  529. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  530. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  531. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  532. INNER JOIN ICSDeliveryNotice y ON a.TransCode=y.DNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  533. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  534. WHERE a.Identification='{0}' AND ERPUpload='0' AND ( a.BusinessCode = '105' OR a.BusinessCode = '3')
  535. GROUP BY y.VenCode,a.FromWarehouseCode,y.DNCode,a.MUSER,a.InvCode,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),Enable
  536. ,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, ''),
  537. 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, '')
  538. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,DNCode AS DNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  539. 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
  540. FROM #TempERP
  541. DROP TABLE #TempERP";
  542. sql = string.Format(sql, Identification);
  543. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  544. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  545. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReturnBackURL, Inputstr);
  546. Result result = new Result();
  547. result = JsonConvert.DeserializeObject<Result>(resultStr);
  548. if (result.Success)
  549. {
  550. try
  551. {
  552. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  553. foreach (var item in res)
  554. {
  555. JObject jo = (JObject)item;
  556. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  557. foreach (var detail in resdetail)
  558. {
  559. JObject det = (JObject)detail;
  560. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  561. det["DetailID"].ToString(), jo["RCVNEGCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  562. }
  563. }
  564. }
  565. catch (Exception ex)
  566. {
  567. log.Debug(ex.ToString());
  568. log.Debug(resultStr);
  569. }
  570. }
  571. else
  572. {
  573. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  574. }
  575. #endregion
  576. }
  577. catch (Exception)
  578. {
  579. throw;
  580. }
  581. }
  582. #endregion
  583. #region 开立红字入库
  584. /// <summary>
  585. /// 开立红字入库
  586. /// </summary>
  587. /// <param name="TransCode"></param>
  588. /// <param name="TransSequence"></param>
  589. /// <param name="Quantity"></param>
  590. /// <param name="WorkPoint"></param>
  591. /// <param name="cmd"></param>
  592. public static void PurchaseReceive(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  593. {
  594. try
  595. {
  596. string sql = @"DECLARE @Status VARCHAR(10)
  597. SELECT @Status=a.Status FROM ICSPurchaseReceive a
  598. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  599. IF (@Status IS NULL)
  600. BEGIN
  601. RAISERROR('" + language.GetNameByCode("WMSAPIInfo089") + @"',16,1);
  602. RETURN
  603. END
  604. ELSE IF (@Status!='1')
  605. BEGIN
  606. RAISERROR('" + language.GetNameByCode("WMSAPIInfo090") + @"',16,1);
  607. RETURN
  608. END
  609. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  610. FROM ICSPurchaseReceive a
  611. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  612. IF EXISTS(SELECT a.ID FROM ICSPurchaseReceive a
  613. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='2' AND a.Quantity<a.RCVQuantity)
  614. BEGIN
  615. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  616. RETURN
  617. END";
  618. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  619. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  620. {
  621. throw new Exception(language.GetNameByCode("WMSAPIInfo092"));//"红字入库单更新失败!");
  622. }
  623. }
  624. catch (Exception)
  625. {
  626. throw;
  627. }
  628. }
  629. /// <summary>
  630. /// 开立红字入库接口
  631. /// </summary>
  632. /// <param name="TransType"></param>
  633. /// <param name="Identification"></param>
  634. /// <param name="cmd"></param>
  635. public static void PurchaseReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  636. {
  637. try
  638. {
  639. #region ERP开立状态单据审核
  640. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  641. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  642. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  643. BEGIN
  644. RAISERROR('" + language.GetNameByCode("WMSAPIInfo093") + @"',16,1);
  645. RETURN
  646. END
  647. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  648. FROM ICSWareHouseLotInfoLog a
  649. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  650. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  651. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  652. WHERE a.Identification='{0}' AND ERPUpload='0' AND (a.BusinessCode = '4' OR a.BusinessCode = '105')
  653. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  654. sql = string.Format(sql, Identification);
  655. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  656. string Inputstr = JsonConvert.SerializeObject(dt);
  657. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReceiveDoctNegativeURL, Inputstr);
  658. Result result = new Result();
  659. result = JsonConvert.DeserializeObject<Result>(resultStr);
  660. if (result.Success)
  661. {
  662. try
  663. {
  664. foreach (DataRow dr in dt.Rows)
  665. {
  666. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", cmd, language);
  667. }
  668. }
  669. catch (Exception ex)
  670. {
  671. log.Debug(ex.ToString());
  672. log.Debug(resultStr);
  673. }
  674. }
  675. else
  676. {
  677. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  678. }
  679. #endregion
  680. }
  681. catch (Exception)
  682. {
  683. throw;
  684. }
  685. }
  686. #endregion
  687. }
  688. }