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

1152 lines
69 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
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
4 months ago
2 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
4 months ago
4 months ago
2 years ago
9 months ago
9 months ago
2 years ago
9 months ago
4 months ago
3 years ago
3 years ago
3 years ago
9 months ago
9 months ago
3 years ago
9 months ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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, string BusinessCode)
  152. {
  153. try
  154. {
  155. #region ERP
  156. string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.POCode+a.MUSER+CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS DNCode,CASE WHEN(LEN(f.DNID)>=20) THEN '1' ELSE '0' END AS HasDN,a.MUSER,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.Sequence END AS DNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.POCode,c.PODetailID,a.InvCode) AS Sequence,
  157. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.PODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable
  158. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  159. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  160. INTO #TempERP
  161. FROM ICSWareHouseLotInfoLog a
  162. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  163. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  164. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  165. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  166. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  167. INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  168. INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint
  169. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  170. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  171. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  172. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  173. GROUP BY c.VenCode,a.ToWarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END,f.DNID,a.MUSER,a.InvCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.Sequence END,c.PODetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable
  174. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  175. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  176. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,POCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity FROM #TempERP
  177. SELECT Costre,Sequence,DNSequence,InvCode,Quantity,Amount,PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  178. FROM #TempERP
  179. SELECT HasDN FROM #TempERP
  180. DROP TABLE #TempERP";
  181. sql = string.Format(sql, Identification, BusinessCode);
  182. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  183. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  184. var IsDNCode = ds.Tables[2];
  185. if (IsDNCode == null || IsDNCode.Rows.Count != 1)
  186. {
  187. throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种!
  188. }
  189. string dncode = Convert.ToString(IsDNCode.Rows[0]["HasDN"]);
  190. if (dncode.Equals(""))
  191. {
  192. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DeliveryNoticeURL, Inputstr);
  193. Result result = new Result();
  194. result = JsonConvert.DeserializeObject<Result>(resultStr);
  195. if (result.Success)
  196. {
  197. try
  198. {
  199. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  200. foreach (var item in res)
  201. {
  202. JObject jo = (JObject)item;
  203. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  204. foreach (var detail in resdetail)
  205. {
  206. JObject det = (JObject)detail;
  207. string allcol = jo["cWhCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  208. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  209. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  210. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  211. }
  212. }
  213. }
  214. catch (Exception ex)
  215. {
  216. log.Debug(ex.ToString());
  217. log.Debug(resultStr);
  218. }
  219. }
  220. else
  221. {
  222. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  223. }
  224. }
  225. else
  226. {
  227. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseOrderURL, Inputstr);
  228. Result result = new Result();
  229. result = JsonConvert.DeserializeObject<Result>(resultStr);
  230. if (result.Success)
  231. {
  232. try
  233. {
  234. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  235. foreach (var item in res)
  236. {
  237. JObject jo = (JObject)item;
  238. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  239. foreach (var detail in resdetail)
  240. {
  241. JObject det = (JObject)detail;
  242. string allcol = jo["cWhCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  243. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  244. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
  245. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  246. }
  247. }
  248. }
  249. catch (Exception ex)
  250. {
  251. log.Debug(ex.ToString());
  252. log.Debug(resultStr);
  253. }
  254. }
  255. else
  256. {
  257. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  258. }
  259. }
  260. #endregion
  261. }
  262. catch (Exception)
  263. {
  264. throw;
  265. }
  266. }
  267. #endregion
  268. /// <summary>
  269. /// 审核的到货单(货柜)
  270. /// </summary>
  271. /// <param name="TransCode"></param>
  272. /// <param name="TransSequence"></param>
  273. /// <param name="Quantity"></param>
  274. /// <param name="WorkPoint"></param>
  275. /// <param name="cmd"></param>
  276. public static void DeliveryNoticeInForHG(string DocNO, string TransLine, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string quantity)
  277. {
  278. try
  279. {
  280. decimal iquantity = Convert.ToDecimal(quantity);
  281. string sql = @" IF EXISTS (SELECT ID FROM ICSDeliveryNotice WHERE RCVQuantity=Quantity AND DNCode='{0}' AND Sequence='{1}' and WorkPoint='{2}' )
  282. BEGIN
  283. RAISERROR('" + language.GetNameByCode("WMSAPIInfo471") + @"',16,1);
  284. RETURN
  285. END;
  286. UPDATE ICSDeliveryNotice set RCVQuantity=RCVQuantity+{3}
  287. Where DNCode='{0}' AND Sequence='{1}' and WorkPoint='{2}'";
  288. sql = string.Format(sql, DocNO, TransLine, WorkPoint, iquantity);
  289. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  290. {
  291. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  292. }
  293. }
  294. catch (Exception)
  295. {
  296. throw;
  297. }
  298. }
  299. #region 审核的到货单
  300. /// <summary>
  301. /// 审核的到货单
  302. /// </summary>
  303. /// <param name="TransCode"></param>
  304. /// <param name="TransSequence"></param>
  305. /// <param name="Quantity"></param>
  306. /// <param name="WorkPoint"></param>
  307. /// <param name="cmd"></param>
  308. public static void DeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  309. {
  310. try
  311. {
  312. string sql = @"DECLARE @Status VARCHAR(10)
  313. SELECT @Status=c.Status FROM ICSInventoryLot a
  314. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  315. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  316. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  317. IF (@Status IS NULL)
  318. BEGIN
  319. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  320. RETURN
  321. END
  322. ELSE IF (@Status='3')
  323. BEGIN
  324. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  325. RETURN
  326. END
  327. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  328. FROM ICSInventoryLot a
  329. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  330. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  331. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  332. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  333. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  334. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  335. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1' AND c.Quantity<c.RCVQuantity)
  336. BEGIN
  337. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  338. END";
  339. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  340. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  341. {
  342. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  343. }
  344. }
  345. catch (Exception)
  346. {
  347. throw;
  348. }
  349. }
  350. /// <summary>
  351. /// 审核的到货单接口(平库,传给SAP单据行总数)
  352. /// </summary>
  353. /// <param name="TransType"></param>
  354. /// <param name="Identification"></param>
  355. /// <param name="cmd"></param>
  356. public static void DeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  357. {
  358. try
  359. {
  360. #region SAP(检验合格单为两层结构 一行对应一个序列号)
  361. string IsSuccess = "";
  362. string ErrorMessage = "";
  363. string sql = @" select A.DNCode,A.WorkPoint,SUM(B.Quantity) AS Quantity from ICSDeliveryNotice A
  364. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.DNCode AND B.WorkPoint=A.WorkPoint
  365. where B.Identification='{0}' AND BusinessCode='2'
  366. GROUP BY A.DNCode,A.WorkPoint";
  367. sql = string.Format(sql, Identification);
  368. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  369. //if (dt.Rows.Count > 1)
  370. //{
  371. // throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  372. //}
  373. log.Info("采购上架传入SAP数据:" + JsonConvert.SerializeObject(dt));
  374. for (int i = 0; i < dt.Rows.Count; i++)
  375. {
  376. log.Info("采购上架传入SAP数据:" + JsonConvert.SerializeObject(dt.Rows));
  377. string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSDeliveryNotice
  378. where DNCode='{0}' and WorkPoint='{1}'
  379. GROUP BY DNCode,WorkPoint";
  380. chksql = string.Format(chksql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  381. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  382. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["RCVQuantity"]))
  383. {
  384. return;
  385. }
  386. sql = @"select A.DNCode,
  387. CASE WHEN SUM(Convert(decimal(18,6),A.SAPSequence)) IS NULL THEN SUM(A.RCVQuantity)
  388. ELSE SUM(Convert(decimal(18,6),A.SAPSequence)) END AS RCVQuantity,B.BatchCode,A.WHCode from ICSDeliveryNotice A
  389. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  390. WHERE DNCode='{0}' AND A.WorkPoint='{1}'
  391. GROUP BY A.DNCode,B.BatchCode,A.WHCode";
  392. sql = string.Format(sql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  393. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  394. if (Sapdt.Rows.Count == 0)
  395. {
  396. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo205"), dt.Rows[i]["DNCode"].ToString()));//单据查询失败
  397. }
  398. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU Client = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU();
  399. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1 Info = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1();
  400. Info.NEWID = Identification;
  401. Info.PRUEFLOS = Sapdt.Rows[0]["DNCode"].ToString();
  402. Info.L_LME = System.Decimal.Round(Convert.ToDecimal(Sapdt.Rows[0]["RCVQuantity"].ToString()), 3);
  403. Info.SERNP = Sapdt.Rows[0]["BatchCode"].ToString();
  404. Info.LGORT = Sapdt.Rows[0]["WHCode"].ToString(); ;//仓库
  405. Info.Z_GERNR = new SAPCallBackJYHGDVPN.ZWEBS_GERNR[0];
  406. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse result = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse();
  407. result = Client.CallZWMS_SK_WS_RUKU(Info);
  408. if (result.Z_NULL == "N")
  409. {
  410. IsSuccess = "N";
  411. ErrorMessage += result.L_MESSAGE;
  412. log.Error("采购上架失败数据:" + JsonConvert.SerializeObject(dt.Rows) + "," + ErrorMessage);
  413. break;
  414. }
  415. }
  416. if (IsSuccess == "N")
  417. {
  418. throw new Exception(ErrorMessage);
  419. }
  420. #endregion
  421. }
  422. catch (Exception)
  423. {
  424. throw;
  425. }
  426. }
  427. /// <summary>
  428. /// 审核的到货单接口(货柜,传给SAP本次入库数量)
  429. /// </summary>
  430. /// <param name="TransType"></param>
  431. /// <param name="Identification"></param>
  432. /// <param name="cmd"></param>
  433. public static void DeliveryNoticeInERPHG(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  434. {
  435. try
  436. {
  437. #region SAP(检验合格单为两层结构 一行对应一个序列号)
  438. string IsSuccess = "";
  439. string ErrorMessage = "";
  440. string sql = @" select A.DNCode,A.WorkPoint,SUM(B.Quantity) AS Quantity from ICSDeliveryNotice A
  441. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.DNCode AND B.WorkPoint=A.WorkPoint
  442. where B.Identification='{0}' AND BusinessCode='2'
  443. GROUP BY A.DNCode,A.WorkPoint";
  444. sql = string.Format(sql, Identification);
  445. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  446. if (dt.Rows.Count > 1)
  447. {
  448. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  449. }
  450. for (int i = 0; i < dt.Rows.Count; i++)
  451. {
  452. string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSDeliveryNotice
  453. where DNCode='{0}' and WorkPoint='{1}'
  454. GROUP BY DNCode,WorkPoint";
  455. chksql = string.Format(chksql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  456. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  457. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["RCVQuantity"]))
  458. {
  459. return;
  460. }
  461. sql = @"select A.DNCode,SUM(A.RCVQuantity) AS RCVQuantity,B.BatchCode,A.WHCode from ICSDeliveryNotice A
  462. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  463. WHERE DNCode='{0}' AND A.WorkPoint='{1}'
  464. GROUP BY A.DNCode,B.BatchCode,A.WHCode";
  465. sql = string.Format(sql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  466. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  467. if (Sapdt.Rows.Count == 0)
  468. {
  469. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo205"), dt.Rows[i]["DNCode"].ToString()));//单据查询失败
  470. }
  471. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU Client = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU();
  472. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1 Info = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1();
  473. Info.NEWID = Identification;
  474. Info.PRUEFLOS = Sapdt.Rows[0]["DNCode"].ToString();
  475. Info.L_LME = System.Decimal.Round(Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString()), 3);
  476. Info.SERNP = Sapdt.Rows[0]["BatchCode"].ToString();
  477. Info.LGORT = Sapdt.Rows[0]["WHCode"].ToString(); ;//仓库
  478. Info.Z_GERNR = new SAPCallBackJYHGDVPN.ZWEBS_GERNR[0];
  479. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse result = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse();
  480. result = Client.CallZWMS_SK_WS_RUKU(Info);
  481. if (result.Z_NULL == "N")
  482. {
  483. IsSuccess = "N";
  484. ErrorMessage += result.L_MESSAGE;
  485. }
  486. }
  487. if (IsSuccess == "N")
  488. {
  489. throw new Exception(ErrorMessage);
  490. }
  491. #endregion
  492. }
  493. catch (Exception)
  494. {
  495. throw;
  496. }
  497. }
  498. #endregion
  499. #region 叉车采购入库
  500. /// <summary>
  501. /// 叉车采购入库
  502. /// </summary>
  503. /// <param name="TransCode"></param>
  504. /// <param name="TransSequence"></param>
  505. /// <param name="Quantity"></param>
  506. /// <param name="WorkPoint"></param>
  507. /// <param name="cmd"></param>
  508. public static void DeliveryNoticeForkLift(string ContainerCode, SqlCommand cmd, Dictionary<string, string> language)
  509. {
  510. try
  511. {
  512. string lotsql = @" select A.LotNo,C.Quantity,B.WorkPoint from ICSContainerLot A
  513. LEFT JOIN ICSContainer B ON B.ID=A.ContainerID AND B.WorkPoint=A.WorkPoint
  514. LEFT JOIN ICSInventoryLot C ON C.LotNo=A.LotNo AND C.WorkPoint=A.WorkPoint
  515. where B.ContainerCode='{0}'";
  516. lotsql = string.Format(lotsql, ContainerCode);
  517. DataTable lotdt = DBHelper.SQlReturnData(lotsql, cmd);
  518. if (lotdt.Rows.Count == 0)
  519. {
  520. throw new Exception("托盘号不存在或者尚未绑定条码!");
  521. }
  522. foreach (DataRow dr in lotdt.Rows)
  523. {
  524. string sql = @" UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  525. FROM ICSInventoryLot a
  526. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  527. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  528. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  529. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  530. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  531. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  532. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1' AND c.Quantity<c.RCVQuantity)
  533. BEGIN
  534. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  535. END";
  536. sql = string.Format(sql, dr["LotNo"].ToString(), dr["WorkPoint"].ToString(), dr["Quantity"].ToString());
  537. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  538. {
  539. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  540. }
  541. }
  542. }
  543. catch (Exception)
  544. {
  545. throw;
  546. }
  547. }
  548. #endregion
  549. #region 采购拒收
  550. /// <summary>
  551. /// 采购拒收
  552. /// </summary>
  553. /// <param name="TransCode"></param>
  554. /// <param name="TransSequence"></param>
  555. /// <param name="Quantity"></param>
  556. /// <param name="WorkPoint"></param>
  557. /// <param name="cmd"></param>
  558. public static void PurchaseRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  559. {
  560. try
  561. {
  562. string sql = @"DECLARE @Status VARCHAR(10)
  563. SELECT @Status=c.Status FROM ICSInventoryLot a
  564. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  565. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  566. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  567. IF (@Status IS NULL)
  568. BEGIN
  569. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  570. RETURN
  571. END
  572. ELSE IF (@Status='3')
  573. BEGIN
  574. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  575. RETURN
  576. END
  577. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  578. FROM ICSInventoryLot a
  579. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  580. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  581. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  582. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  583. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  584. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  585. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3' AND c.Quantity<c.RCVQuantity)
  586. BEGIN
  587. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  588. END";
  589. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  590. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  591. {
  592. throw new Exception(language.GetNameByCode("WMSAPIInfo084"));//"拒收单更新失败!");
  593. }
  594. }
  595. catch (Exception)
  596. {
  597. throw;
  598. }
  599. }
  600. /// <summary>
  601. /// 采购拒收接口
  602. /// </summary>
  603. /// <param name="TransType"></param>
  604. /// <param name="Identification"></param>
  605. /// <param name="cmd"></param>
  606. public static void PurchaseRejectDocInNewERP(string DNCode, string JDNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  607. {
  608. //try
  609. //{
  610. // #region ERP
  611. // 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,
  612. // 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
  613. // ,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,
  614. // 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
  615. // INTO #TempERP
  616. // FROM ICSWareHouseLotInfoLog a
  617. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  618. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  619. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  620. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  621. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  622. // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  623. // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
  624. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  625. // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  626. // WHERE a.Identification='{0}' AND ERPUpload='0'
  627. // 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
  628. // ,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, ''),
  629. // 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, '')
  630. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
  631. // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  632. // FROM #TempERP
  633. // DROP TABLE #TempERP";
  634. // sql = string.Format(sql, Identification);
  635. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  636. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  637. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  638. // Result result = new Result();
  639. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  640. // if (result.Success)
  641. // {
  642. // try
  643. // {
  644. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  645. // foreach (var item in res)
  646. // {
  647. // JObject jo = (JObject)item;
  648. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  649. // foreach (var detail in resdetail)
  650. // {
  651. // JObject det = (JObject)detail;
  652. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  653. // }
  654. // }
  655. // }
  656. // catch (Exception ex)
  657. // {
  658. // log.Debug(ex.ToString());
  659. // log.Debug(resultStr);
  660. // }
  661. // }
  662. // else
  663. // {
  664. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  665. // }
  666. // #endregion
  667. //}
  668. //catch (Exception)
  669. //{
  670. // throw;
  671. //}
  672. try
  673. {
  674. #region ERP
  675. string sql = @"SELECT a.VenCode+a.DepCode+a.DNCode+a.MUSER AS Costre,a.VenCode,a.DepCode,a.DNCode,a.MUSER,a.MTIME,
  676. a.Sequence,a.InvCode,Sum(x.Quantity) AS Quantity,a.Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.DNDetailID
  677. ,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,
  678. 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
  679. INTO #TempERP
  680. FROM ICSDeliveryNotice a
  681. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  682. INNER JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  683. INNER JOIN ICSDeliveryNotice x ON a.DNDetailID=x.PODetailID AND a.WorkPoint=x.WorkPoint
  684. WHERE a.DNCode='{0}' AND a.WorkPoint='{1}'
  685. 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,
  686. a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(invBat.BatchEnable, ''),ISNULL(ext.BatchCode, ''),ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  687. 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, '')
  688. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  689. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,DNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  690. FROM #TempERP
  691. DROP TABLE #TempERP";
  692. sql = string.Format(sql, DNCode, WorkPoint);
  693. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  694. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  695. string resultStr = HTTPHelper.HttpPost("采购拒收", ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  696. Result result = new Result();
  697. result = JsonConvert.DeserializeObject<Result>(resultStr);
  698. if (result.Success)
  699. {
  700. try
  701. {
  702. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  703. foreach (var item in res)
  704. {
  705. JObject jo = (JObject)item;
  706. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  707. foreach (var detail in resdetail)
  708. {
  709. JObject det = (JObject)detail;
  710. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RJTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  711. string ERPupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}'
  712. where PODetailID='{4}' AND DNType='3' AND DNCode='{5}' ";
  713. ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], JDNCode);
  714. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  715. {
  716. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  717. }
  718. }
  719. }
  720. }
  721. catch (Exception ex)
  722. {
  723. log.Debug(ex.ToString());
  724. log.Debug(resultStr);
  725. }
  726. }
  727. else
  728. {
  729. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  730. }
  731. #endregion
  732. }
  733. catch (Exception)
  734. {
  735. throw;
  736. }
  737. }
  738. /// <summary>
  739. /// 采购拒收接口
  740. /// </summary>
  741. /// <param name="TransType"></param>
  742. /// <param name="Identification"></param>
  743. /// <param name="cmd"></param>
  744. public static void PurchaseRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  745. {
  746. //try
  747. //{
  748. // #region ERP
  749. // 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,
  750. // 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
  751. // ,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,
  752. // 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
  753. // INTO #TempERP
  754. // FROM ICSWareHouseLotInfoLog a
  755. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  756. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  757. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  758. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  759. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  760. // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  761. // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
  762. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  763. // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  764. // WHERE a.Identification='{0}' AND ERPUpload='0'
  765. // GROUP BY c.VenCode,a.ToWarehouseCode,c.DNCode,d.DNCode,a.MUSER,a.InvCode,d.DNDetailID,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conv.Enable
  766. // ,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, ''),
  767. // 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, '')
  768. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
  769. // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  770. // FROM #TempERP
  771. // DROP TABLE #TempERP";
  772. // sql = string.Format(sql, Identification);
  773. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  774. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  775. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  776. // Result result = new Result();
  777. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  778. // if (result.Success)
  779. // {
  780. // try
  781. // {
  782. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  783. // foreach (var item in res)
  784. // {
  785. // JObject jo = (JObject)item;
  786. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  787. // foreach (var detail in resdetail)
  788. // {
  789. // JObject det = (JObject)detail;
  790. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  791. // }
  792. // }
  793. // }
  794. // catch (Exception ex)
  795. // {
  796. // log.Debug(ex.ToString());
  797. // log.Debug(resultStr);
  798. // }
  799. // }
  800. // else
  801. // {
  802. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  803. // }
  804. // #endregion
  805. //}
  806. //catch (Exception)
  807. //{
  808. // throw;
  809. //}
  810. }
  811. #endregion
  812. #region 采购退货
  813. /// <summary>
  814. /// 采购退货
  815. /// </summary>
  816. /// <param name="TransCode"></param>
  817. /// <param name="TransSequence"></param>
  818. /// <param name="Quantity"></param>
  819. /// <param name="WorkPoint"></param>
  820. /// <param name="cmd"></param>
  821. public static void PurchaseReceiveDoctNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  822. {
  823. try
  824. {
  825. string sql = @"DECLARE @Status VARCHAR(10)
  826. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' AND DNType='2' AND WorkPoint='{1}'
  827. IF (@Status IS NULL)
  828. BEGIN
  829. RAISERROR('" + language.GetNameByCode("WMSAPIInfo085") + @"',16,1);
  830. RETURN
  831. END
  832. ELSE IF (@Status!='2')
  833. BEGIN
  834. RAISERROR('" + language.GetNameByCode("WMSAPIInfo086") + @"',16,1);
  835. RETURN
  836. END
  837. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  838. FROM ICSDeliveryNotice a
  839. WHERE a.DNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND DNType='2'
  840. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a
  841. WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.RCVQuantity AND DNType='2')
  842. BEGIN
  843. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  844. RETURN
  845. END";
  846. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  847. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  848. {
  849. throw new Exception(language.GetNameByCode("WMSAPIInfo088"));//"采购退货单更新失败!");
  850. }
  851. }
  852. catch (Exception)
  853. {
  854. throw;
  855. }
  856. }
  857. /// <summary>
  858. /// 采购退货(货柜)
  859. /// </summary>
  860. /// <param name="TransCode"></param>
  861. /// <param name="TransSequence"></param>
  862. /// <param name="Quantity"></param>
  863. /// <param name="WorkPoint"></param>
  864. /// <param name="cmd"></param>
  865. public static void PurchaseReceiveDoctNegativeHG(string TransCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  866. {
  867. try
  868. {
  869. string sql = @" IF EXISTS (SELECT ID FROM ICSDeliveryNotice WHERE RCVQuantity=Quantity AND DNCode='{0}' AND WorkPoint='{1}' )
  870. BEGIN
  871. RAISERROR('" + language.GetNameByCode("WMSAPIInfo471") + @"',16,1);
  872. RETURN
  873. END;
  874. UPDATE ICSDeliveryNotice SET RCVQuantity=Quantity
  875. WHERE DNCode='{0}' AND WorkPoint='{1}'";
  876. sql = string.Format(sql, TransCode, WorkPoint);
  877. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  878. {
  879. throw new Exception(language.GetNameByCode("WMSAPIInfo088"));//"采购退货单更新失败!");
  880. }
  881. }
  882. catch (Exception)
  883. {
  884. throw;
  885. }
  886. }
  887. /// <summary>
  888. /// 采购退货接口
  889. /// </summary>
  890. /// <param name="TransType"></param>
  891. /// <param name="Identification"></param>
  892. /// <param name="cmd"></param>
  893. public static void PurchaseReceiveDoctNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  894. {
  895. try
  896. {
  897. #region SAP(三层结构)
  898. string IsSuccess = "";
  899. string ErrorMessage = "";
  900. string sql = @" select A.DNCode,A.WorkPoint,SUM(B.Quantity) AS Quantity from ICSDeliveryNotice A
  901. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.DNCode AND B.WorkPoint=A.WorkPoint
  902. where B.Identification='{0}' AND BusinessCode='3'
  903. GROUP BY A.DNCode,A.WorkPoint";
  904. sql = string.Format(sql, Identification);
  905. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  906. if (dt.Rows.Count > 1)
  907. {
  908. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  909. }
  910. for (int i = 0; i < dt.Rows.Count; i++)
  911. {
  912. string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSDeliveryNotice
  913. where DNCode='{0}' and WorkPoint='{1}'
  914. GROUP BY DNCode,WorkPoint";
  915. chksql = string.Format(chksql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  916. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  917. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) == Convert.ToDecimal(chkdt.Rows[0]["RCVQuantity"]))
  918. {
  919. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  920. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  921. Info.NEWID = Identification;
  922. Info.DANJU = dt.Rows[i]["DNCode"].ToString();
  923. Info.STATE = "0";
  924. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  925. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  926. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  927. sql = @"select A.DNCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.RCVQuantity
  928. ,ISNULL(B.BatchCode,'') AS BatchCode from ICSDeliveryNotice A
  929. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  930. WHERE DNCode='{0}' AND A.WorkPoint='{1}'";
  931. sql = string.Format(sql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  932. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  933. foreach (DataRow dr in Sapdt.Rows)
  934. {
  935. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["RCVQuantity"].ToString()))
  936. {
  937. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  938. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  939. Item.DANJU = dr["DNCode"].ToString();
  940. Item.POSNR = dr["SAPSequence"].ToString();
  941. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString()), 3);
  942. ItemList.Add(Item);
  943. if (dr["BatchCode"].ToString() != "")
  944. {
  945. ItemLine.DANJU = dr["DNCode"].ToString();
  946. ItemLine.POSNR = dr["SAPSequence"].ToString();
  947. ItemLine.MATNR = dr["InvCode"].ToString();
  948. ItemLine.GERNR = dr["BatchCode"].ToString();
  949. ItemLineList.Add(ItemLine);
  950. }
  951. }
  952. }
  953. if (ItemList.Count > 0)
  954. {
  955. Info.Z_ITEM = ItemList.ToArray();
  956. if (ItemLineList.Count > 0)
  957. {
  958. Info.Z_GERNR = ItemLineList.ToArray();
  959. }
  960. else
  961. {
  962. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  963. }
  964. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  965. result = Client.CallZWMS_SK_WS_PZ(Info);
  966. if (result.Z_NULL == "N")
  967. {
  968. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  969. {
  970. IsSuccess = "N";
  971. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  972. }
  973. }
  974. }
  975. }
  976. }
  977. if (IsSuccess == "N")
  978. {
  979. throw new Exception(ErrorMessage);
  980. }
  981. #endregion
  982. }
  983. catch (Exception)
  984. {
  985. throw;
  986. }
  987. }
  988. #endregion
  989. #region 开立红字入库
  990. /// <summary>
  991. /// 开立红字入库
  992. /// </summary>
  993. /// <param name="TransCode"></param>
  994. /// <param name="TransSequence"></param>
  995. /// <param name="Quantity"></param>
  996. /// <param name="WorkPoint"></param>
  997. /// <param name="cmd"></param>
  998. public static void PurchaseReceive(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  999. {
  1000. try
  1001. {
  1002. string sql = @"DECLARE @Status VARCHAR(10)
  1003. SELECT @Status=a.Status FROM ICSPurchaseReceive a
  1004. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  1005. IF (@Status IS NULL)
  1006. BEGIN
  1007. RAISERROR('" + language.GetNameByCode("WMSAPIInfo089") + @"',16,1);
  1008. RETURN
  1009. END
  1010. ELSE IF (@Status!='1')
  1011. BEGIN
  1012. RAISERROR('" + language.GetNameByCode("WMSAPIInfo090") + @"',16,1);
  1013. RETURN
  1014. END
  1015. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1016. FROM ICSPurchaseReceive a
  1017. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  1018. IF EXISTS(SELECT a.ID FROM ICSPurchaseReceive a
  1019. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='2' AND a.Quantity<a.RCVQuantity)
  1020. BEGIN
  1021. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  1022. RETURN
  1023. END";
  1024. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  1025. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1026. {
  1027. throw new Exception(language.GetNameByCode("WMSAPIInfo092"));//"红字入库单更新失败!");
  1028. }
  1029. }
  1030. catch (Exception)
  1031. {
  1032. throw;
  1033. }
  1034. }
  1035. /// <summary>
  1036. /// 开立红字入库接口
  1037. /// </summary>
  1038. /// <param name="TransType"></param>
  1039. /// <param name="Identification"></param>
  1040. /// <param name="cmd"></param>
  1041. public static void PurchaseReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1042. {
  1043. try
  1044. {
  1045. #region ERP开立状态单据审核
  1046. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  1047. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1048. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  1049. BEGIN
  1050. RAISERROR('" + language.GetNameByCode("WMSAPIInfo093") + @"',16,1);
  1051. RETURN
  1052. END
  1053. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1054. FROM ICSWareHouseLotInfoLog a
  1055. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1056. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1057. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  1058. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '4'
  1059. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  1060. sql = string.Format(sql, Identification);
  1061. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1062. string Inputstr = JsonConvert.SerializeObject(dt);
  1063. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReceiveDoctNegativeURL, Inputstr);
  1064. Result result = new Result();
  1065. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1066. if (result.Success)
  1067. {
  1068. try
  1069. {
  1070. foreach (DataRow dr in dt.Rows)
  1071. {
  1072. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1073. }
  1074. }
  1075. catch (Exception ex)
  1076. {
  1077. log.Debug(ex.ToString());
  1078. log.Debug(resultStr);
  1079. }
  1080. }
  1081. else
  1082. {
  1083. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1084. }
  1085. #endregion
  1086. }
  1087. catch (Exception)
  1088. {
  1089. throw;
  1090. }
  1091. }
  1092. #endregion
  1093. }
  1094. }