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

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