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

722 lines
43 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 (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,0 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,c.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,0 AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.DNDetailID,Enable AS UpdateTodoQuantity
  406. // INTO #TempERP
  407. // FROM ICSWareHouseLotInfoLog a
  408. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  409. // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  410. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  411. // WHERE a.Identification='{0}' AND ERPUpload='0'
  412. // GROUP BY c.VenCode,a.ToWarehouseCode,c.DNCode,a.MUSER,a.InvCode,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,Enable
  413. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  414. // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice
  415. // FROM #TempERP
  416. // DROP TABLE #TempERP";
  417. // sql = string.Format(sql, Identification);
  418. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  419. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  420. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DeliveryNoticeURL, Inputstr);
  421. // Result result = new Result();
  422. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  423. // if (result.Success)
  424. // {
  425. // try
  426. // {
  427. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  428. // foreach (var item in res)
  429. // {
  430. // JObject jo = (JObject)item;
  431. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  432. // foreach (var detail in resdetail)
  433. // {
  434. // JObject det = (JObject)detail;
  435. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd);
  436. // }
  437. // }
  438. // }
  439. // catch (Exception ex)
  440. // {
  441. // log.Debug(ex.ToString());
  442. // log.Debug(resultStr);
  443. // }
  444. // }
  445. // else
  446. // {
  447. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  448. // }
  449. // #endregion
  450. //}
  451. //catch (Exception)
  452. //{
  453. // throw;
  454. //}
  455. }
  456. #endregion
  457. #region 采购退货
  458. /// <summary>
  459. /// 采购退货
  460. /// </summary>
  461. /// <param name="TransCode"></param>
  462. /// <param name="TransSequence"></param>
  463. /// <param name="Quantity"></param>
  464. /// <param name="WorkPoint"></param>
  465. /// <param name="cmd"></param>
  466. public static void PurchaseReceiveDoctNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  467. {
  468. try
  469. {
  470. string sql = @"DECLARE @Status VARCHAR(10)
  471. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' AND DNType='2' AND WorkPoint='{1}'
  472. IF (@Status IS NULL)
  473. BEGIN
  474. RAISERROR('" + language.GetNameByCode("WMSAPIInfo085") + @"',16,1);
  475. RETURN
  476. END
  477. ELSE IF (@Status!='2')
  478. BEGIN
  479. RAISERROR('" + language.GetNameByCode("WMSAPIInfo086") + @"',16,1);
  480. RETURN
  481. END
  482. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  483. FROM ICSDeliveryNotice a
  484. WHERE a.DNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND DNType='2'
  485. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a
  486. WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.RCVQuantity AND DNType='2')
  487. BEGIN
  488. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  489. RETURN
  490. END";
  491. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  492. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  493. {
  494. throw new Exception(language.GetNameByCode("WMSAPIInfo088"));//"采购退货单更新失败!");
  495. }
  496. }
  497. catch (Exception)
  498. {
  499. throw;
  500. }
  501. }
  502. /// <summary>
  503. /// 采购退货接口
  504. /// </summary>
  505. /// <param name="TransType"></param>
  506. /// <param name="Identification"></param>
  507. /// <param name="cmd"></param>
  508. public static void PurchaseReceiveDoctNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  509. {
  510. try
  511. {
  512. #region ERP
  513. 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,
  514. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,Enable AS UpdateTodoQuantity
  515. ,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,
  516. 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
  517. INTO #TempERP
  518. FROM ICSWareHouseLotInfoLog a
  519. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  520. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  521. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  522. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  523. INNER JOIN ICSDeliveryNotice y ON a.TransCode=y.DNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  524. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  525. WHERE a.Identification='{0}' AND ERPUpload='0'
  526. GROUP BY y.VenCode,a.FromWarehouseCode,y.DNCode,a.MUSER,a.InvCode,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),Enable
  527. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  528. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  529. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,DNCode AS DNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  530. 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
  531. FROM #TempERP
  532. DROP TABLE #TempERP";
  533. sql = string.Format(sql, Identification);
  534. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  535. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  536. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReturnBackURL, Inputstr);
  537. Result result = new Result();
  538. result = JsonConvert.DeserializeObject<Result>(resultStr);
  539. if (result.Success)
  540. {
  541. try
  542. {
  543. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  544. foreach (var item in res)
  545. {
  546. JObject jo = (JObject)item;
  547. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  548. foreach (var detail in resdetail)
  549. {
  550. JObject det = (JObject)detail;
  551. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  552. det["DetailID"].ToString(), jo["RCVNEGCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  553. }
  554. }
  555. }
  556. catch (Exception ex)
  557. {
  558. log.Debug(ex.ToString());
  559. log.Debug(resultStr);
  560. }
  561. }
  562. else
  563. {
  564. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  565. }
  566. #endregion
  567. }
  568. catch (Exception)
  569. {
  570. throw;
  571. }
  572. }
  573. #endregion
  574. #region 开立红字入库
  575. /// <summary>
  576. /// 开立红字入库
  577. /// </summary>
  578. /// <param name="TransCode"></param>
  579. /// <param name="TransSequence"></param>
  580. /// <param name="Quantity"></param>
  581. /// <param name="WorkPoint"></param>
  582. /// <param name="cmd"></param>
  583. public static void PurchaseReceive(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  584. {
  585. try
  586. {
  587. string sql = @"DECLARE @Status VARCHAR(10)
  588. SELECT @Status=a.Status FROM ICSPurchaseReceive a
  589. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  590. IF (@Status IS NULL)
  591. BEGIN
  592. RAISERROR('" + language.GetNameByCode("WMSAPIInfo089") + @"',16,1);
  593. RETURN
  594. END
  595. ELSE IF (@Status!='1')
  596. BEGIN
  597. RAISERROR('" + language.GetNameByCode("WMSAPIInfo090") + @"',16,1);
  598. RETURN
  599. END
  600. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  601. FROM ICSPurchaseReceive a
  602. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  603. IF EXISTS(SELECT a.ID FROM ICSPurchaseReceive a
  604. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='2' AND a.Quantity<a.RCVQuantity)
  605. BEGIN
  606. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  607. RETURN
  608. END";
  609. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  610. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  611. {
  612. throw new Exception(language.GetNameByCode("WMSAPIInfo092"));//"红字入库单更新失败!");
  613. }
  614. }
  615. catch (Exception)
  616. {
  617. throw;
  618. }
  619. }
  620. /// <summary>
  621. /// 开立红字入库接口
  622. /// </summary>
  623. /// <param name="TransType"></param>
  624. /// <param name="Identification"></param>
  625. /// <param name="cmd"></param>
  626. public static void PurchaseReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  627. {
  628. try
  629. {
  630. #region ERP开立状态单据审核
  631. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  632. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  633. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  634. BEGIN
  635. RAISERROR('" + language.GetNameByCode("WMSAPIInfo093") + @"',16,1);
  636. RETURN
  637. END
  638. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  639. FROM ICSWareHouseLotInfoLog a
  640. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  641. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  642. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  643. WHERE a.Identification='{0}' AND ERPUpload='0'
  644. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  645. sql = string.Format(sql, Identification);
  646. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  647. string Inputstr = JsonConvert.SerializeObject(dt);
  648. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReceiveDoctNegativeURL, Inputstr);
  649. Result result = new Result();
  650. result = JsonConvert.DeserializeObject<Result>(resultStr);
  651. if (result.Success)
  652. {
  653. try
  654. {
  655. foreach (DataRow dr in dt.Rows)
  656. {
  657. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", cmd, language);
  658. }
  659. }
  660. catch (Exception ex)
  661. {
  662. log.Debug(ex.ToString());
  663. log.Debug(resultStr);
  664. }
  665. }
  666. else
  667. {
  668. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  669. }
  670. #endregion
  671. }
  672. catch (Exception)
  673. {
  674. throw;
  675. }
  676. }
  677. #endregion
  678. }
  679. }