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

939 lines
58 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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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
2 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
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. #region 审核的到货单
  269. /// <summary>
  270. /// 审核的到货单
  271. /// </summary>
  272. /// <param name="TransCode"></param>
  273. /// <param name="TransSequence"></param>
  274. /// <param name="Quantity"></param>
  275. /// <param name="WorkPoint"></param>
  276. /// <param name="cmd"></param>
  277. public static void DeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  278. {
  279. try
  280. {
  281. string sql = @"DECLARE @Status VARCHAR(10)
  282. SELECT @Status=c.Status FROM ICSInventoryLot a
  283. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  284. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  285. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  286. IF (@Status IS NULL)
  287. BEGIN
  288. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  289. RETURN
  290. END
  291. ELSE IF (@Status='3')
  292. BEGIN
  293. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  294. RETURN
  295. END
  296. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  297. FROM ICSInventoryLot a
  298. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  299. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  300. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  301. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  302. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  303. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  304. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1' AND c.Quantity<c.RCVQuantity)
  305. BEGIN
  306. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  307. END";
  308. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  309. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  310. {
  311. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  312. }
  313. }
  314. catch (Exception)
  315. {
  316. throw;
  317. }
  318. }
  319. /// <summary>
  320. /// 审核的到货单接口
  321. /// </summary>
  322. /// <param name="TransType"></param>
  323. /// <param name="Identification"></param>
  324. /// <param name="cmd"></param>
  325. public static void DeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  326. {
  327. try
  328. {
  329. #region SAP
  330. string IsSuccess = "";
  331. string ErrorMessage = "";
  332. string sql = @" select Distinct A.DNCode,A.WorkPoint from ICSDeliveryNotice A
  333. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.DNCode AND B.WorkPoint=A.WorkPoint
  334. where B.Identification='{0}' AND BusinessCode='2'";
  335. sql = string.Format(sql, Identification);
  336. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  337. if (dt.Rows.Count > 1)
  338. {
  339. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  340. }
  341. for (int i = 0; i < dt.Rows.Count; i++)
  342. {
  343. string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSDeliveryNotice
  344. where DNCode='{0}' and WorkPoint='{1}'
  345. GROUP BY DNCode,WorkPoint";
  346. chksql = string.Format(chksql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  347. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  348. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["RCVQuantity"]))
  349. {
  350. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo203"), chkdt.Rows[0]["Quantity"].ToString(), chkdt.Rows[0]["RCVQuantity"].ToString()));//单次提交数量卡控(必须整单提交)
  351. }
  352. sql = @"select A.DNCode,SUM(A.RCVQuantity) AS RCVQuantity,B.BatchCode from ICSDeliveryNotice A
  353. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  354. WHERE DNCode='{0}' AND A.WorkPoint='{1}'
  355. GROUP BY A.DNCode,B.BatchCode";
  356. sql = string.Format(sql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  357. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  358. if (Sapdt.Rows.Count == 0)
  359. {
  360. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo205"), dt.Rows[i]["DNCode"].ToString()));//单据查询失败
  361. }
  362. SAPCalBackJYHGD.ZWMS_SK_WS_RUKU Client = new SAPCalBackJYHGD.ZWMS_SK_WS_RUKU();
  363. SAPCalBackJYHGD.ZWMS_SK_WS_RUKU1 Info = new SAPCalBackJYHGD.ZWMS_SK_WS_RUKU1();
  364. Info.NEWID = Identification;
  365. Info.PRUEFLOS = Sapdt.Rows[0]["DNCode"].ToString();
  366. Info.L_LME = System.Decimal.Round(Convert.ToDecimal(Sapdt.Rows[0]["RCVQuantity"].ToString()), 3);
  367. Info.SERNP = Sapdt.Rows[0]["BatchCode"].ToString();
  368. Info.Z_GERNR = new SAPCalBackJYHGD.ZWEBS_GERNR[1];
  369. SAPCalBackJYHGD.ZWMS_SK_WS_RUKUResponse result = new SAPCalBackJYHGD.ZWMS_SK_WS_RUKUResponse();
  370. result = Client.CallZWMS_SK_WS_RUKU(Info);
  371. if (result.Z_NULL == "N")
  372. {
  373. ErrorMessage += result.L_MESSAGE;
  374. }
  375. }
  376. if (IsSuccess == "N")
  377. {
  378. throw new Exception(ErrorMessage);
  379. }
  380. #endregion
  381. }
  382. catch (Exception)
  383. {
  384. throw;
  385. }
  386. }
  387. #endregion
  388. #region 采购拒收
  389. /// <summary>
  390. /// 采购拒收
  391. /// </summary>
  392. /// <param name="TransCode"></param>
  393. /// <param name="TransSequence"></param>
  394. /// <param name="Quantity"></param>
  395. /// <param name="WorkPoint"></param>
  396. /// <param name="cmd"></param>
  397. public static void PurchaseRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  398. {
  399. try
  400. {
  401. string sql = @"DECLARE @Status VARCHAR(10)
  402. SELECT @Status=c.Status FROM ICSInventoryLot a
  403. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  404. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  405. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  406. IF (@Status IS NULL)
  407. BEGIN
  408. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  409. RETURN
  410. END
  411. ELSE IF (@Status='3')
  412. BEGIN
  413. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  414. RETURN
  415. END
  416. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  417. FROM ICSInventoryLot a
  418. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  419. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  420. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  421. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  422. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  423. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  424. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3' AND c.Quantity<c.RCVQuantity)
  425. BEGIN
  426. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  427. END";
  428. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  429. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  430. {
  431. throw new Exception(language.GetNameByCode("WMSAPIInfo084"));//"拒收单更新失败!");
  432. }
  433. }
  434. catch (Exception)
  435. {
  436. throw;
  437. }
  438. }
  439. /// <summary>
  440. /// 采购拒收接口
  441. /// </summary>
  442. /// <param name="TransType"></param>
  443. /// <param name="Identification"></param>
  444. /// <param name="cmd"></param>
  445. public static void PurchaseRejectDocInNewERP(string DNCode, string JDNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  446. {
  447. //try
  448. //{
  449. // #region ERP
  450. // 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,
  451. // 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
  452. // ,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,
  453. // 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
  454. // INTO #TempERP
  455. // FROM ICSWareHouseLotInfoLog a
  456. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  457. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  458. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  459. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  460. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  461. // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  462. // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
  463. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  464. // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  465. // WHERE a.Identification='{0}' AND ERPUpload='0'
  466. // 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
  467. // ,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, ''),
  468. // 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, '')
  469. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
  470. // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  471. // FROM #TempERP
  472. // DROP TABLE #TempERP";
  473. // sql = string.Format(sql, Identification);
  474. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  475. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  476. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  477. // Result result = new Result();
  478. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  479. // if (result.Success)
  480. // {
  481. // try
  482. // {
  483. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  484. // foreach (var item in res)
  485. // {
  486. // JObject jo = (JObject)item;
  487. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  488. // foreach (var detail in resdetail)
  489. // {
  490. // JObject det = (JObject)detail;
  491. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  492. // }
  493. // }
  494. // }
  495. // catch (Exception ex)
  496. // {
  497. // log.Debug(ex.ToString());
  498. // log.Debug(resultStr);
  499. // }
  500. // }
  501. // else
  502. // {
  503. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  504. // }
  505. // #endregion
  506. //}
  507. //catch (Exception)
  508. //{
  509. // throw;
  510. //}
  511. try
  512. {
  513. #region ERP
  514. string sql = @"SELECT a.VenCode+a.DepCode+a.DNCode+a.MUSER AS Costre,a.VenCode,a.DepCode,a.DNCode,a.MUSER,a.MTIME,
  515. a.Sequence,a.InvCode,Sum(x.Quantity) AS Quantity,a.Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.DNDetailID
  516. ,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,
  517. 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
  518. INTO #TempERP
  519. FROM ICSDeliveryNotice a
  520. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  521. INNER JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  522. INNER JOIN ICSDeliveryNotice x ON a.DNDetailID=x.PODetailID AND a.WorkPoint=x.WorkPoint
  523. WHERE a.DNCode='{0}' AND a.WorkPoint='{1}'
  524. 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,
  525. a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(invBat.BatchEnable, ''),ISNULL(ext.BatchCode, ''),ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  526. 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, '')
  527. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  528. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,DNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  529. FROM #TempERP
  530. DROP TABLE #TempERP";
  531. sql = string.Format(sql, DNCode, WorkPoint);
  532. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  533. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  534. string resultStr = HTTPHelper.HttpPost("采购拒收", ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  535. Result result = new Result();
  536. result = JsonConvert.DeserializeObject<Result>(resultStr);
  537. if (result.Success)
  538. {
  539. try
  540. {
  541. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  542. foreach (var item in res)
  543. {
  544. JObject jo = (JObject)item;
  545. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  546. foreach (var detail in resdetail)
  547. {
  548. JObject det = (JObject)detail;
  549. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RJTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  550. string ERPupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}'
  551. where PODetailID='{4}' AND DNType='3' AND DNCode='{5}' ";
  552. ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], JDNCode);
  553. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  554. {
  555. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  556. }
  557. }
  558. }
  559. }
  560. catch (Exception ex)
  561. {
  562. log.Debug(ex.ToString());
  563. log.Debug(resultStr);
  564. }
  565. }
  566. else
  567. {
  568. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  569. }
  570. #endregion
  571. }
  572. catch (Exception)
  573. {
  574. throw;
  575. }
  576. }
  577. /// <summary>
  578. /// 采购拒收接口
  579. /// </summary>
  580. /// <param name="TransType"></param>
  581. /// <param name="Identification"></param>
  582. /// <param name="cmd"></param>
  583. public static void PurchaseRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  584. {
  585. //try
  586. //{
  587. // #region ERP
  588. // 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,
  589. // 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
  590. // ,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,
  591. // 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
  592. // INTO #TempERP
  593. // FROM ICSWareHouseLotInfoLog a
  594. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  595. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  596. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  597. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  598. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  599. // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  600. // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
  601. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  602. // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  603. // WHERE a.Identification='{0}' AND ERPUpload='0'
  604. // 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
  605. // ,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, ''),
  606. // 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, '')
  607. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
  608. // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  609. // FROM #TempERP
  610. // DROP TABLE #TempERP";
  611. // sql = string.Format(sql, Identification);
  612. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  613. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  614. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  615. // Result result = new Result();
  616. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  617. // if (result.Success)
  618. // {
  619. // try
  620. // {
  621. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  622. // foreach (var item in res)
  623. // {
  624. // JObject jo = (JObject)item;
  625. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  626. // foreach (var detail in resdetail)
  627. // {
  628. // JObject det = (JObject)detail;
  629. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  630. // }
  631. // }
  632. // }
  633. // catch (Exception ex)
  634. // {
  635. // log.Debug(ex.ToString());
  636. // log.Debug(resultStr);
  637. // }
  638. // }
  639. // else
  640. // {
  641. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  642. // }
  643. // #endregion
  644. //}
  645. //catch (Exception)
  646. //{
  647. // throw;
  648. //}
  649. }
  650. #endregion
  651. #region 采购退货
  652. /// <summary>
  653. /// 采购退货
  654. /// </summary>
  655. /// <param name="TransCode"></param>
  656. /// <param name="TransSequence"></param>
  657. /// <param name="Quantity"></param>
  658. /// <param name="WorkPoint"></param>
  659. /// <param name="cmd"></param>
  660. public static void PurchaseReceiveDoctNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  661. {
  662. try
  663. {
  664. string sql = @"DECLARE @Status VARCHAR(10)
  665. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' AND DNType='2' AND WorkPoint='{1}'
  666. IF (@Status IS NULL)
  667. BEGIN
  668. RAISERROR('" + language.GetNameByCode("WMSAPIInfo085") + @"',16,1);
  669. RETURN
  670. END
  671. ELSE IF (@Status!='2')
  672. BEGIN
  673. RAISERROR('" + language.GetNameByCode("WMSAPIInfo086") + @"',16,1);
  674. RETURN
  675. END
  676. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  677. FROM ICSDeliveryNotice a
  678. WHERE a.DNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND DNType='2'
  679. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a
  680. WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.RCVQuantity AND DNType='2')
  681. BEGIN
  682. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  683. RETURN
  684. END";
  685. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  686. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  687. {
  688. throw new Exception(language.GetNameByCode("WMSAPIInfo088"));//"采购退货单更新失败!");
  689. }
  690. }
  691. catch (Exception)
  692. {
  693. throw;
  694. }
  695. }
  696. /// <summary>
  697. /// 采购退货接口
  698. /// </summary>
  699. /// <param name="TransType"></param>
  700. /// <param name="Identification"></param>
  701. /// <param name="cmd"></param>
  702. public static void PurchaseReceiveDoctNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  703. {
  704. try
  705. {
  706. #region SAP
  707. string IsSuccess = "";
  708. string ErrorMessage = "";
  709. string sql = @" select Distinct A.DNCode,A.WorkPoint from ICSDeliveryNotice A
  710. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.DNCode AND B.WorkPoint=A.WorkPoint
  711. where B.Identification='{0}' AND BusinessCode='3'";
  712. sql = string.Format(sql, Identification);
  713. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  714. if (dt.Rows.Count > 1)
  715. {
  716. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  717. }
  718. for (int i = 0; i < dt.Rows.Count; i++)
  719. {
  720. string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSDeliveryNotice
  721. where DNCode='{0}' and WorkPoint='{1}'
  722. GROUP BY DNCode,WorkPoint";
  723. chksql = string.Format(chksql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  724. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  725. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["RCVQuantity"]))
  726. {
  727. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo203"), chkdt.Rows[0]["Quantity"].ToString(), chkdt.Rows[0]["RCVQuantity"].ToString()));//单次提交数量卡控(必须整单提交)
  728. }
  729. SAPCallBackDoc.ZWMS_SK_WS_PZ Client = new SAPCallBackDoc.ZWMS_SK_WS_PZ();
  730. SAPCallBackDoc.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDoc.ZWMS_SK_WS_PZ1();
  731. Info.NEWID = Identification;
  732. Info.DANJU = dt.Rows[i]["DNCode"].ToString();
  733. Info.STATE = "0";
  734. List<SAPCallBackDoc.ZWMS_PZ> ItemList = new List<SAPCallBackDoc.ZWMS_PZ>();
  735. Info.Z_GERNR = new SAPCallBackDoc.ZWEBS_GERNR[1];
  736. Info.Z_FLAG = new SAPCallBackDoc.ZWEB_RETURN[1];
  737. sql = @"select A.DNCode,A.Sequence,A.Quantity,A.RCVQuantity,B.BatchCode from ICSDeliveryNotice A
  738. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  739. WHERE DNCode='{0}' AND A.WorkPoint='{1}'";
  740. sql = string.Format(sql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  741. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  742. foreach (DataRow dr in Sapdt.Rows)
  743. {
  744. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["RCVQuantity"].ToString()))
  745. {
  746. SAPCallBackDoc.ZWMS_PZ Item = new SAPCallBackDoc.ZWMS_PZ();
  747. Item.DANJU = dr["DNCode"].ToString();
  748. Item.POSNR = dr["Sequence"].ToString();
  749. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  750. Item.SERNP = dr["BatchCode"].ToString();
  751. ItemList.Add(Item);
  752. }
  753. }
  754. if (ItemList.Count > 0)
  755. {
  756. Info.Z_ITEM = ItemList.ToArray();
  757. SAPCallBackDoc.ZWMS_SK_WS_PZResponse result = new SAPCallBackDoc.ZWMS_SK_WS_PZResponse();
  758. result = Client.CallZWMS_SK_WS_PZ(Info);
  759. if (result.Z_NULL == "N")
  760. {
  761. foreach (SAPCallBackDoc.ZWEB_RETURN resultItem in result.Z_FLAG)
  762. {
  763. IsSuccess = "N";
  764. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  765. }
  766. }
  767. }
  768. }
  769. if (IsSuccess == "N")
  770. {
  771. throw new Exception(ErrorMessage);
  772. }
  773. #endregion
  774. }
  775. catch (Exception)
  776. {
  777. throw;
  778. }
  779. }
  780. #endregion
  781. #region 开立红字入库
  782. /// <summary>
  783. /// 开立红字入库
  784. /// </summary>
  785. /// <param name="TransCode"></param>
  786. /// <param name="TransSequence"></param>
  787. /// <param name="Quantity"></param>
  788. /// <param name="WorkPoint"></param>
  789. /// <param name="cmd"></param>
  790. public static void PurchaseReceive(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  791. {
  792. try
  793. {
  794. string sql = @"DECLARE @Status VARCHAR(10)
  795. SELECT @Status=a.Status FROM ICSPurchaseReceive a
  796. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  797. IF (@Status IS NULL)
  798. BEGIN
  799. RAISERROR('" + language.GetNameByCode("WMSAPIInfo089") + @"',16,1);
  800. RETURN
  801. END
  802. ELSE IF (@Status!='1')
  803. BEGIN
  804. RAISERROR('" + language.GetNameByCode("WMSAPIInfo090") + @"',16,1);
  805. RETURN
  806. END
  807. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  808. FROM ICSPurchaseReceive a
  809. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  810. IF EXISTS(SELECT a.ID FROM ICSPurchaseReceive a
  811. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='2' AND a.Quantity<a.RCVQuantity)
  812. BEGIN
  813. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  814. RETURN
  815. END";
  816. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  817. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  818. {
  819. throw new Exception(language.GetNameByCode("WMSAPIInfo092"));//"红字入库单更新失败!");
  820. }
  821. }
  822. catch (Exception)
  823. {
  824. throw;
  825. }
  826. }
  827. /// <summary>
  828. /// 开立红字入库接口
  829. /// </summary>
  830. /// <param name="TransType"></param>
  831. /// <param name="Identification"></param>
  832. /// <param name="cmd"></param>
  833. public static void PurchaseReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  834. {
  835. try
  836. {
  837. #region ERP开立状态单据审核
  838. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  839. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  840. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  841. BEGIN
  842. RAISERROR('" + language.GetNameByCode("WMSAPIInfo093") + @"',16,1);
  843. RETURN
  844. END
  845. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  846. FROM ICSWareHouseLotInfoLog a
  847. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  848. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  849. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  850. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '4'
  851. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  852. sql = string.Format(sql, Identification);
  853. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  854. string Inputstr = JsonConvert.SerializeObject(dt);
  855. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReceiveDoctNegativeURL, Inputstr);
  856. Result result = new Result();
  857. result = JsonConvert.DeserializeObject<Result>(resultStr);
  858. if (result.Success)
  859. {
  860. try
  861. {
  862. foreach (DataRow dr in dt.Rows)
  863. {
  864. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  865. }
  866. }
  867. catch (Exception ex)
  868. {
  869. log.Debug(ex.ToString());
  870. log.Debug(resultStr);
  871. }
  872. }
  873. else
  874. {
  875. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  876. }
  877. #endregion
  878. }
  879. catch (Exception)
  880. {
  881. throw;
  882. }
  883. }
  884. #endregion
  885. }
  886. }