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

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