PurchaseOrderController.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. using JCSoft.WX.Framework.Api;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.AspNetCore.Http;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using Common.Wechat;
  9. using Common;
  10. using System.Data.SqlClient;
  11. using ZcPeng.PublicLibrary;
  12. using PublicLibrary.Model;
  13. using Common.Model;
  14. using System.Data;
  15. using Newtonsoft.Json.Converters;
  16. using CoreEntity.Entity;
  17. using Newtonsoft.Json;
  18. using SupplierWeb.Codes.mvc;
  19. using Microsoft.Extensions.Caching.Memory;
  20. using SupplierWeb.Codes.Push;
  21. using CoreEntity.DAL;
  22. using LigerRM.Common;
  23. namespace SupplierWeb.Controllers
  24. {
  25. /// <summary>
  26. /// 订单物流汇总,明细,
  27. /// </summary>
  28. [Route("web/purchaseorder")]
  29. public class PurchaseOrderController : BaseController
  30. {
  31. public PurchaseOrderController(IMemoryCache cache, IApiClient client) : base(cache, client)
  32. {
  33. }
  34. ////查看采购单的发货状态,查看物流进度 已发货
  35. [AuthPermission]
  36. [HttpPost, Route("ordershipmentlist/{staffId}")]
  37. public JsonResult ordershipmentlist(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  38. string sortField, Int32 sortDirection, string[] sumFields,
  39. string staffId,
  40. [FromBody]dynamic data)
  41. {
  42. string userids;
  43. userids = getStaff("userid");
  44. string RoleId = getStaff("roleid");
  45. //判断参数是否合法
  46. if (string.IsNullOrEmpty(userids))
  47. {
  48. return Json(new
  49. {
  50. success = 0,
  51. msg = "没有登陆"
  52. });
  53. }
  54. int PushAccountId = Convert.ToInt32(userids);
  55. if (data != null)
  56. {
  57. //Newtonsoft.Json.Linq.JArray
  58. filters = data.filters.ToObject<QueryFilter[]>();
  59. pageIndex = data.pageIndex;
  60. pageSize = data.pageSize;
  61. sortField = data.sortField;
  62. sortDirection = data.sortDirection;
  63. sumFields = data.sumFields.ToObject<string[]>();
  64. }
  65. List<SqlParameter> parameters1 = new List<SqlParameter>();
  66. string filterstring = QueryFilter.getFilterSqlParam(filters, out parameters1, new PurOrderMTEx(), "A.");
  67. filterstring += " and exists (select PurOrderBillNo from " + Config.TablePrefix + "PurOrderShipment where PurOrderBillNo = A.BillNo) ";
  68. filterstring = filterstring.Replace("and A.StaffName", "and C.StaffName");
  69. filterstring = filterstring.Replace("and A.Contact", "and F.Contact");
  70. filterstring = filterstring.Replace("and A.BusinessName", "and E.BusinessName");
  71. string StaffDocId = StaffDocDAL.GetStaffId(userids);
  72. string purroleFilter = FilterRuleByPur.getRolePermFilter(RoleId, " and K.SaleManId = '" + StaffDocId + "' ");
  73. #region 获取订单
  74. DataTable dt = new DataTable();
  75. string result = string.Empty;
  76. string direct = " desc ";
  77. if (sortDirection != 1)
  78. direct = " asc";
  79. int start = (pageIndex - 1) * pageSize;
  80. int end = (start + 1 + pageSize);
  81. string commandText0 = "select * from (";
  82. string commandText1 =
  83. "select A.*,B.AccountRealName,C.StaffName,E.BusinessName,F.Contact,row_number() over" +
  84. "( order by A." + sortField + " " + direct + " ) as rownum" +
  85. " from PurOrderMT A " +
  86. " left join " + Config.TablePrefix + "Account B on A.SaleManId=B.PurStaffId" +
  87. " left join StaffDoc C on A.SaleManId=C.StaffId " +
  88. " left join supplyDoc D on A.SuppliersId=D.SuppliersId" +
  89. " left join BusinessDoc E on E.BusinessId=D.SuppliersId and E.Is_Supp = 'Y' " +
  90. " left join ContactDoc F on F.ContactId=A.K_ContactId" +
  91. //" left join ContactDoc F1 on F1.ContactId=A.OppContId" +
  92. " where 1=1 " +
  93. " and exists (select K.ContactId from K_contactsp K where K.ContactId = A.K_ContactId and K.EntId = A.EntId " +
  94. purroleFilter +
  95. ")" +
  96. filterstring +
  97. ")AAA";
  98. string commandText2 =
  99. " where AAA.rownum>" + start + " and AAA.rownum<" + end
  100. ;
  101. string commandText = commandText0 + commandText1 + commandText2;
  102. bool result1 = DataAccess.GetValues(commandText, ref dt, parameters1.ToArray(), out result);
  103. IList<PurOrderMTEx> users = new List<PurOrderMTEx>();
  104. if (dt != null && dt.Rows.Count > 0)
  105. {
  106. // 把DataTable转换为IList<UserInfo>
  107. users = ModelConvertHelper<PurOrderMTEx>.ConvertToModel(dt);
  108. }
  109. #endregion
  110. string resultrow;
  111. string commandTextCount = "select count(*) from (" + commandText1;
  112. long totalcount = DataAccess.GetRowCountDefine(commandTextCount, parameters1.ToArray(), out resultrow);
  113. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  114. {
  115. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  116. };
  117. var jsonData = JsonConvert.SerializeObject(users, timejson);
  118. return Json(new
  119. {
  120. items = JsonConvert.DeserializeObject(jsonData),
  121. sum = new { },
  122. totalCount = totalcount
  123. });
  124. }
  125. //订单明细
  126. [AuthPermission]
  127. [HttpPost, Route("orderdtshipmentlist/{staffId}")]
  128. public JsonResult orderdtshipmentlist(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  129. string sortField, Int32 sortDirection, string[] sumFields,
  130. string staffId,
  131. [FromBody]dynamic data)
  132. {
  133. string userids;
  134. userids = getStaffUserid(staffId);
  135. string RoleId = getStaff("roleid");
  136. //判断参数是否合法
  137. if (string.IsNullOrEmpty(userids))
  138. {
  139. return Json(new
  140. {
  141. items = new string[] { },
  142. sum = new { },
  143. totalCount = 0
  144. });
  145. }
  146. if (data != null)
  147. {
  148. //Newtonsoft.Json.Linq.JArray
  149. filters = data.filters.ToObject<QueryFilter[]>();
  150. pageIndex = data.pageIndex;
  151. pageSize = data.pageSize;
  152. sortField = data.sortField;
  153. sortDirection = data.sortDirection;
  154. sumFields = data.sumFields.ToObject<string[]>();
  155. }
  156. int PushAccountId = Convert.ToInt32(userids);
  157. //if (filters.Length == 0)
  158. //{
  159. // return Json(new
  160. // {
  161. // items = new string[] { },
  162. // sum = new { },
  163. // totalCount = 0
  164. // });
  165. //}
  166. List<SqlParameter> parameters1 = new List<SqlParameter>();
  167. string filterstring = QueryFilter.getFilterSqlParam(filters, out parameters1, new PurOrderDTEx(), "G.");
  168. string StaffDocId = StaffDocDAL.GetStaffId(userids);
  169. string purroleFilter = FilterRuleByPur.getRolePermFilter(RoleId, " and K.SaleManId = '" + StaffDocId + "' ");
  170. filterstring = filterstring.Replace("and G.GoodsName", "and H.GoodsName");
  171. filterstring = filterstring.Replace("and G.GoodsCode", "and H.GoodsCode");
  172. filterstring = filterstring.Replace("and G.StaffName", "and C.StaffName");
  173. filterstring = filterstring.Replace("and G.Contact", "and F.Contact");
  174. filterstring = filterstring.Replace("and G.BusinessName", "and E.BusinessName");
  175. #region 获取订单
  176. DataTable dt = new DataTable();
  177. string result = string.Empty;
  178. string direct = " desc ";
  179. if (sortDirection != 1)
  180. direct = " asc";
  181. int start = (pageIndex - 1) * pageSize;
  182. int end = (start + 1 + pageSize);
  183. string commandText0 = "select * from (";
  184. string commandText1 =
  185. "select G.*,A.OppContId,A.SuppliersId,B.AccountRealName,C.StaffName," +
  186. "E.BusinessName,F.Contact," +
  187. "H.GoodsName,H.GoodsCode,H.GoodsSpec,H.Manufacturer,X.k_kdcode," +
  188. "row_number() over" +
  189. "( order by G." + sortField + " " + direct + " ) as rownum" +
  190. " from PurOrderDT G " +
  191. " left join PurOrderMT A on G.BillNo = A.BillNo and A.EntId = G.EntId " +
  192. " left join GoodsDoc H on H.GoodsId=G.GoodsId and H.EntId = G.EntId " +
  193. " left join " + Config.TablePrefix + "Account B on A.SaleManId=B.PurStaffId" +
  194. " left join StaffDoc C on A.SaleManId=C.StaffId and C.EntId = A.EntId " +
  195. //" left join supplydoc D on A.SuppliersId=D.SuppliersId and D.EntId = A.EntId " +
  196. " left join BusinessDoc E on E.BusinessId=A.SuppliersId and E.Is_Supp = 'Y' and E.EntId = A.EntId " +
  197. " left join ContactDoc F on F.ContactId=A.K_ContactId and F.EntId = A.EntId " +
  198. //" left join ContactDoc F1 on F1.ContactId=A.OppContId" +
  199. "left join sup_PurShipmentOrderDT Z on G.BillNo = Z.BillNo and g.BillSn=z.BillSn left join sup_PurOrderShipment X on Z.ShipmentId=X.Id " +
  200. " where 1=1 " +
  201. "and exists (select K.ContactId from K_contactsp K where K.ContactId = A.K_ContactId and K.EntId = A.EntId " +
  202. purroleFilter +
  203. ")" +
  204. filterstring +
  205. ")AAA";
  206. string commandText2 =
  207. " where AAA.rownum>" + start + " and AAA.rownum<" + end
  208. ;
  209. string commandText = commandText0 + commandText1 + commandText2;
  210. if (!parameters1.Any())
  211. {
  212. return Json(new
  213. {
  214. items = new string[] { "" },
  215. sum = new { },
  216. totalCount = 0
  217. });
  218. }
  219. bool result1 = DataAccess.GetValues(commandText, ref dt, parameters1.ToArray(), out result);
  220. IList<PurOrderDTEx> users = new List<PurOrderDTEx>();
  221. if (dt != null && dt.Rows.Count > 0)
  222. {
  223. // 把DataTable转换为IList<UserInfo>
  224. users = ModelConvertHelper<PurOrderDTEx>.ConvertToModel(dt);
  225. }
  226. #endregion
  227. string resultrow;
  228. string commandTextCount = "select count(*) from (" + commandText1;
  229. long totalcount = DataAccess.GetRowCountDefine(commandTextCount, parameters1.ToArray(), out resultrow);
  230. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  231. {
  232. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  233. };
  234. var jsonData = JsonConvert.SerializeObject(users, timejson);
  235. return Json(new
  236. {
  237. items = JsonConvert.DeserializeObject(jsonData),
  238. sum = new { },
  239. totalCount = totalcount
  240. });
  241. }
  242. ////查询采购订单(生成的,提交的)未发货
  243. [AuthPermission]
  244. [HttpPost, Route("purchaseorderlist")]
  245. public JsonResult purchaseorderlist(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  246. string sortField, Int32 sortDirection, string[] sumFields,
  247. string staffId,
  248. [FromBody]dynamic data)
  249. {
  250. string userids;
  251. userids = getStaff("userid");
  252. string RoleId = getStaff("roleid");
  253. //判断参数是否合法
  254. if (string.IsNullOrEmpty(userids))
  255. {
  256. return Json(new
  257. {
  258. success = 0,
  259. msg = "没有登陆"
  260. });
  261. }
  262. int PushAccountId = Convert.ToInt32(userids);
  263. if (data != null)
  264. {
  265. //Newtonsoft.Json.Linq.JArray
  266. filters = data.filters.ToObject<QueryFilter[]>();
  267. pageIndex = data.pageIndex;
  268. pageSize = data.pageSize;
  269. sortField = data.sortField;
  270. sortDirection = data.sortDirection;
  271. sumFields = data.sumFields.ToObject<string[]>();
  272. }
  273. List<SqlParameter> parameters1 = new List<SqlParameter>();
  274. string filterstring = QueryFilter.getFilterSqlParam(filters, out parameters1, new PurOrderMTEx(), "A.");
  275. filterstring += " and not exists (select PurOrderBillNo from " + Config.TablePrefix + "PurOrderShipment where PurOrderBillNo = A.BillNo) ";
  276. filterstring = filterstring.Replace("and A.StaffName", "and C.StaffName");
  277. filterstring = filterstring.Replace("and A.Contact", "and F.Contact");
  278. filterstring = filterstring.Replace("and A.BusinessName", "and E.BusinessName");
  279. string StaffDocId = StaffDocDAL.GetStaffId(userids);
  280. string purroleFilter = FilterRuleByPur.getRolePermFilter(RoleId, " and K.SaleManId = '" + StaffDocId + "' ");
  281. #region 获取订单
  282. DataTable dt = new DataTable();
  283. string result = string.Empty;
  284. string direct = " desc ";
  285. if (sortDirection != 1)
  286. direct = " asc";
  287. int start = (pageIndex - 1) * pageSize;
  288. int end = (start + 1 + pageSize);
  289. string commandText0 = "select * from (";
  290. string commandText1 =
  291. "select A.*,B.AccountRealName,C.StaffName,E.BusinessName,F.Contact,row_number() over" +
  292. "( order by A." + sortField + " " + direct + " ) as rownum" +
  293. " from PurOrderMT A " +
  294. " left join " + Config.TablePrefix + "Account B on A.SaleManId=B.PurStaffId" +
  295. " left join StaffDoc C on A.SaleManId=C.StaffId and A.EntId = C.EntId " +
  296. //" left join supplyDoc D on A.SuppliersId=D.SuppliersId and A.EntId = D.EntId " +
  297. " left join BusinessDoc E on E.BusinessId=A.SuppliersId and E.Is_Supp = 'Y' and E.EntId = A.EntId " +
  298. " left join ContactDoc F on F.ContactId=A.K_ContactId and A.EntId = F.EntId " +
  299. //" left join ContactDoc F1 on F1.ContactId=A.OppContId" +
  300. " where 1=1 " +
  301. "and exists (select K.ContactId from K_contactsp K where A.K_ContactId = K.ContactId and K.EntId = A.EntId " +
  302. purroleFilter +
  303. ")" +
  304. filterstring +
  305. ")AAA";
  306. string commandText2 =
  307. " where AAA.rownum>" + start + " and AAA.rownum<" + end
  308. ;
  309. string commandText = commandText0 + commandText1 + commandText2;
  310. bool result1 = DataAccess.GetValues(commandText, ref dt, parameters1.ToArray(), out result);
  311. IList<PurOrderMTEx> users = new List<PurOrderMTEx>();
  312. if (dt != null && dt.Rows.Count > 0)
  313. {
  314. // 把DataTable转换为IList<UserInfo>
  315. users = ModelConvertHelper<PurOrderMTEx>.ConvertToModel(dt);
  316. }
  317. #endregion
  318. string resultrow;
  319. string commandTextCount = "select count(*) from (" + commandText1;
  320. long totalcount = DataAccess.GetRowCountDefine(commandTextCount, parameters1.ToArray(), out resultrow);
  321. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  322. {
  323. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  324. };
  325. var jsonData = JsonConvert.SerializeObject(users, timejson);
  326. return Json(new
  327. {
  328. items = JsonConvert.DeserializeObject(jsonData),
  329. sum = new { },
  330. totalCount = totalcount
  331. });
  332. }
  333. ////查询采购订单明细
  334. [AuthPermission]
  335. [HttpPost, Route("purchaseorderdtlist/{staffId}")]
  336. public JsonResult purchaseorderdtlist(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  337. string sortField, Int32 sortDirection, string[] sumFields,
  338. string staffId,
  339. [FromBody]dynamic data)
  340. {
  341. string userids;
  342. userids = getStaffUserid(staffId);
  343. string RoleId = getStaff("roleid");
  344. //判断参数是否合法
  345. if (string.IsNullOrEmpty(userids))
  346. {
  347. return Json(new
  348. {
  349. items = new string[] { },
  350. sum = new { },
  351. totalCount = 0
  352. });
  353. }
  354. if (data != null)
  355. {
  356. //Newtonsoft.Json.Linq.JArray
  357. filters = data.filters.ToObject<QueryFilter[]>();
  358. pageIndex = data.pageIndex;
  359. pageSize = data.pageSize;
  360. sortField = data.sortField;
  361. sortDirection = data.sortDirection;
  362. sumFields = data.sumFields.ToObject<string[]>();
  363. }
  364. int PushAccountId = Convert.ToInt32(userids);
  365. if (filters.Length == 0)
  366. {
  367. return Json(new
  368. {
  369. items = new string[] { },
  370. sum = new { },
  371. totalCount = 0
  372. });
  373. }
  374. List<SqlParameter> parameters1 = new List<SqlParameter>();
  375. string filterstring = QueryFilter.getFilterSqlParam(filters, out parameters1, new PurOrderDTEx(), "G.");
  376. filterstring = filterstring.Replace("and G.GoodsName", "and H.GoodsName");
  377. filterstring = filterstring.Replace("and G.GoodsCode", "and H.GoodsCode");
  378. filterstring = filterstring.Replace("and G.StaffName", "and C.StaffName");
  379. filterstring = filterstring.Replace("and G.Contact", "and F.Contact");
  380. filterstring = filterstring.Replace("and G.BusinessName", "and E.BusinessName");
  381. string StaffDocId = StaffDocDAL.GetStaffId(userids);
  382. string purroleFilter = FilterRuleByPur.getRolePermFilter(RoleId, " and K.SaleManId = '" + StaffDocId + "' ");
  383. #region 获取订单
  384. DataTable dt = new DataTable();
  385. string result = string.Empty;
  386. string direct = " desc ";
  387. if (sortDirection != 1)
  388. direct = " asc";
  389. int start = (pageIndex - 1) * pageSize;
  390. int end = (start + 1 + pageSize);
  391. string commandText0 = "select * from (";
  392. string commandText1 =
  393. "select G.*,A.OppContId,A.SuppliersId,B.AccountRealName,C.StaffName," +
  394. "E.BusinessName,F.Contact," +
  395. "H.GoodsName,H.GoodsCode,H.GoodsSpec,H.Manufacturer," +
  396. "row_number() over" +
  397. "( order by G." + sortField + " " + direct + " ) as rownum" +
  398. " from PurOrderDT G left join PurOrderMT A on G.BillNo = A.BillNo and A.EntId = G.EntId " +
  399. " left join GoodsDoc H on H.GoodsId=G.GoodsId and H.EntId = G.EntId " +
  400. " left join " + Config.TablePrefix + "Account B on A.SaleManId=B.PurStaffId" +
  401. " left join StaffDoc C on A.SaleManId=C.StaffId and A.EntId = C.EntId " +
  402. " left join supplydoc D on A.SuppliersId=D.SuppliersId and A.EntId = D.EntId " +
  403. " left join BusinessDoc E on E.BusinessId=D.SuppliersId and E.Is_Supp = 'Y' and E.EntId = D.EntId " +
  404. " left join ContactDoc F on F.ContactId=A.K_ContactId and A.EntId = F.EntId " +
  405. //" left join ContactDoc F1 on F1.ContactId=A.OppContId" +
  406. "and exists (select K.ContactId from K_contactsp K where A.K_ContactId = K.ContactId and K.EntId = A.EntId " +
  407. purroleFilter +
  408. ")" +
  409. " where 1=1 " +
  410. filterstring +
  411. ")AAA";
  412. string commandText2 =
  413. " where AAA.rownum>" + start + " and AAA.rownum<" + end
  414. ;
  415. string commandText = commandText0 + commandText1 + commandText2;
  416. bool result1 = DataAccess.GetValues(commandText, ref dt, parameters1.ToArray(), out result);
  417. IList<PurOrderDTEx> users = new List<PurOrderDTEx>();
  418. if (dt != null && dt.Rows.Count > 0)
  419. {
  420. // 把DataTable转换为IList<UserInfo>
  421. users = ModelConvertHelper<PurOrderDTEx>.ConvertToModel(dt);
  422. }
  423. #endregion
  424. string resultrow;
  425. string commandTextCount = "select count(*) from (" + commandText1;
  426. long totalcount = DataAccess.GetRowCountDefine(commandTextCount, parameters1.ToArray(), out resultrow);
  427. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  428. {
  429. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  430. };
  431. var jsonData = JsonConvert.SerializeObject(users, timejson);
  432. return Json(new
  433. {
  434. items = JsonConvert.DeserializeObject(jsonData),
  435. sum = new { },
  436. totalCount = totalcount
  437. });
  438. }
  439. ////查看采购单的退货汇总
  440. [AuthPermission]
  441. [HttpPost, Route("refund")]
  442. public ActionResult Refund(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  443. string sortField, Int32 sortDirection, string[] sumFields,
  444. [FromBody]dynamic data)
  445. {
  446. string userids;
  447. userids = getStaff("userid");
  448. string RoleId = getStaff("roleid");
  449. //判断参数是否合法
  450. if (string.IsNullOrEmpty(userids))
  451. {
  452. return Json(new
  453. {
  454. items = new string[] { },
  455. sum = new { },
  456. totalCount = 0
  457. });
  458. }
  459. if (data != null)
  460. {
  461. //Newtonsoft.Json.Linq.JArray
  462. filters = data.filters.ToObject<QueryFilter[]>();
  463. pageIndex = data.pageIndex;
  464. pageSize = data.pageSize;
  465. sortField = data.sortField;
  466. sortDirection = data.sortDirection;
  467. sumFields = data.sumFields.ToObject<string[]>();
  468. }
  469. List<SqlParameter> param = new List<SqlParameter>();
  470. string filterstring = QueryFilter.getFilterSqlParam(filters, out param, new PurOrderDTEx(), "A.");
  471. string ruleFilter = FilterTranslator.ruleSql(ref param);
  472. #region 获取订单
  473. DataTable dt = new DataTable();
  474. string result = string.Empty;
  475. string direct = " desc ";
  476. if (sortDirection != 1)
  477. direct = " asc";
  478. int start = (pageIndex - 1) * pageSize;
  479. int end = (start + 1 + pageSize);
  480. sortField = "A." + sortField;
  481. string commandText0 = "select * from (";
  482. string commandText1 =
  483. "select C.Contact as OppContact,B.OppContId,D.StaffName,B.SaleManId,A.*,row_number() over" +
  484. "( order by " + sortField + " " + direct + " ) as rownum" +
  485. " from GspOutMT A "+
  486. " left join PurNotesMT B on B.BillCode = A.K_BillCode and B.EntId = A.EntId" +
  487. " and A.RuleId = '5tx65yncahy1l91x'" +
  488. " left join ContactDoc C on B.OppContId = C.ContactId and B.EntId = C.EntId" +
  489. " left join StaffDoc D on D.STAFFID = B.SaleManId and D.EntId = B.EntId" +
  490. " where 1 = 1" +
  491. " and A.RuleId = @RuleId " +//5tx65yncahy1l91x
  492. filterstring +
  493. ruleFilter +
  494. ")AAA";
  495. string commandText2 =
  496. " where AAA.rownum>" + start + " and AAA.rownum<" + end
  497. ;
  498. string commandText = commandText0 + commandText1 + commandText2;
  499. param.Add(new SqlParameter("@RuleId", "5tx65yncahy1l91x"));
  500. bool result1 = DataAccess.GetValues(commandText, ref dt, param.ToArray(), out result);
  501. IList<GspOutMT> users = new List<GspOutMT>();
  502. if (dt != null && dt.Rows.Count > 0)
  503. {
  504. // 把DataTable转换为IList<UserInfo>
  505. users = ModelConvertHelper<GspOutMT>.ConvertToModel(dt);
  506. }
  507. #endregion
  508. string resultrow;
  509. string commandTextCount = "select count(*) from (" + commandText1;
  510. long totalcount = DataAccess.GetRowCountDefine(commandTextCount, param.ToArray(), out resultrow);
  511. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  512. {
  513. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  514. };
  515. var jsonData = JsonConvert.SerializeObject(users, timejson);
  516. return Json(new
  517. {
  518. items = JsonConvert.DeserializeObject(jsonData),
  519. sum = new { },
  520. totalCount = totalcount
  521. });
  522. }
  523. ////查看采购单的退回明细
  524. [AuthPermission]
  525. [HttpPost,Route("refunddt")]
  526. public ActionResult RefundDT(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  527. string sortField, Int32 sortDirection, string[] sumFields,
  528. [FromBody]dynamic data)
  529. {
  530. string userids;
  531. userids = getStaff("userid");
  532. string RoleId = getStaff("roleid");
  533. //判断参数是否合法
  534. if (string.IsNullOrEmpty(userids))
  535. {
  536. return Json(new
  537. {
  538. items = new string[] { },
  539. sum = new { },
  540. totalCount = 0
  541. });
  542. }
  543. if (data != null)
  544. {
  545. //Newtonsoft.Json.Linq.JArray
  546. filters = data.filters.ToObject<QueryFilter[]>();
  547. pageIndex = data.pageIndex;
  548. pageSize = data.pageSize;
  549. sortField = data.sortField;
  550. sortDirection = data.sortDirection;
  551. sumFields = data.sumFields.ToObject<string[]>();
  552. }
  553. List<SqlParameter> param = new List<SqlParameter>();
  554. string filterstring = QueryFilter.getFilterSqlParam(filters, out param, new PurOrderDTEx(), "A.");
  555. filterstring = filterstring.Replace("and A.GoodsName", "and E.GoodsName");
  556. filterstring = filterstring.Replace("and A.ApprovalNo", "and E1.ApprovalNo");
  557. string ruleFilter = FilterTranslator.ruleSql(ref param);
  558. #region 获取订单
  559. DataTable dt = new DataTable();
  560. string result = string.Empty;
  561. string direct = " desc ";
  562. if (sortDirection != 1)
  563. direct = " asc";
  564. int start = (pageIndex - 1) * pageSize;
  565. int end = (start + 1 + pageSize);
  566. sortField = "A." + sortField;
  567. sortField = sortField.Replace("A.PK", "concat(A.BillNo, '-', A.BillSn)");
  568. sortField = sortField.Replace("A.GoodsName", "E.GoodsName");
  569. sortField = sortField.Replace("A.ApprovalNo", "E1.ApprovalNo");
  570. string commandText0 = "select * from (";
  571. string commandText1 =
  572. "select concat(A.Billno,'-',A.BillSn) as PK," +
  573. //"C.Contact as OppContact,D.StaffName," +
  574. "B1.SaleManId," +
  575. "B1.OppContId," +
  576. "E.GoodsName," +
  577. "E1.ApprovalNo," +
  578. "A.*,row_number() over" +
  579. "( order by " + sortField + " " + direct + " ) as rownum" +
  580. " from GspOutDT A" +
  581. " left join GspOutMT A1 on A.BillNo = A1.BillNo and A.EntId = A1.EntId" +
  582. " and A1.RuleId = '5tx65yncahy1l91x' left join PurNotesMT B1 on B1.BillCode = A.RfBillCode and B1.EntId = A.EntId" +
  583. //" left join ContactDoc C on C.ContactId = B1.OppContId and C.EntId = B1.EntId" +
  584. //" left join StaffDoc D on D.STAFFID = B1.SaleManId and D.EntId = B1.EntId" +
  585. " left join GoodsDoc E on E.GoodsId = A.GoodsId and E.EntId = A.EntId" +
  586. " left join GoodsAttr E1 on E1.GoodsId = E.GoodsId and E1.EntId = E.EntId" +
  587. " where 1 = 1" +
  588. " and A1.RuleId = @RuleId " +//5tx65yncahy1l91x
  589. filterstring +
  590. ruleFilter +
  591. ")AAA";
  592. string commandText2 =
  593. " where AAA.rownum>" + start + " and AAA.rownum<" + end
  594. ;
  595. string commandText = commandText0 + commandText1 + commandText2;
  596. param.Add(new SqlParameter("@RuleId", "5tx65yncahy1l91x"));
  597. bool result1 = DataAccess.GetValues(commandText, ref dt, param.ToArray(), out result);
  598. IList<GspOutDT> users = new List<GspOutDT>();
  599. if (dt != null && dt.Rows.Count > 0)
  600. {
  601. // 把DataTable转换为IList<UserInfo>
  602. users = ModelConvertHelper<GspOutDT>.ConvertToModel(dt);
  603. }
  604. #endregion
  605. string resultrow;
  606. string commandTextCount = "select count(*) from (" + commandText1;
  607. long totalcount = DataAccess.GetRowCountDefine(commandTextCount, param.ToArray(), out resultrow);
  608. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  609. {
  610. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  611. };
  612. var jsonData = JsonConvert.SerializeObject(users, timejson);
  613. return Json(new
  614. {
  615. items = JsonConvert.DeserializeObject(jsonData),
  616. sum = new { },
  617. totalCount = totalcount
  618. });
  619. }
  620. }
  621. }