PayPlanController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using Common.Model;
  8. using CoreEntity.DAL;
  9. using CoreEntity.Entity;
  10. using JCSoft.WX.Framework.Api;
  11. using LigerRM.Common;
  12. using Microsoft.AspNetCore.Http;
  13. using Microsoft.AspNetCore.Mvc;
  14. using Microsoft.Extensions.Caching.Memory;
  15. using Newtonsoft.Json;
  16. using Newtonsoft.Json.Converters;
  17. using Newtonsoft.Json.Serialization;
  18. using PublicLibrary.Json;
  19. using PublicLibrary.Model;
  20. using SupplierWeb.Codes.mvc;
  21. using ZcPeng.PublicLibrary;
  22. namespace SupplierWeb.Controllers
  23. {
  24. [Route("web/payplan")]
  25. [ApiController]
  26. public class PayPlanController : BaseController
  27. {
  28. public PayPlanController(IMemoryCache cache, IApiClient client) : base(cache, client)
  29. {
  30. }
  31. ////添加内部管理人员账户,采购员账号
  32. [AuthPermission]
  33. [HttpPost, Route("add")]
  34. public JsonResult add([FromBody]dynamic data, Int32 IsDelete = 0
  35. )
  36. {
  37. string SaleManId = string.Empty;
  38. string ContactId = string.Empty;
  39. string SuppliersId = string.Empty;
  40. decimal PTaxAmount = 0;
  41. string Remark = string.Empty;
  42. string PayType = string.Empty;
  43. List<APGoodsMT> apgoodsmt = new List<APGoodsMT>(0);
  44. if (data != null)
  45. {
  46. //Newtonsoft.Json.Linq.JArray
  47. ContactId = data.ContactId;
  48. SuppliersId = data.SuppliersId;
  49. PTaxAmount = data.PTaxAmount;
  50. Remark = data.Remark;
  51. PayType = data.PayType;
  52. if (data.apgoodsmt != null)
  53. {
  54. var list = JsonConvert.SerializeObject(data.apgoodsmt);
  55. apgoodsmt = JsonConvert.DeserializeObject<List<APGoodsMT>>(list);
  56. }
  57. else
  58. apgoodsmt = new List<APGoodsMT> { };
  59. //apgoodsmt = data.apgoodsmt == null ? new List < APGoodsMT > { } : data.apgoodsmt.ToObject<List<APGoodsMT>>(); ;
  60. }
  61. string result = string.Empty;
  62. //采购员默认第一个单的采购
  63. Object obj = null;
  64. string result1 = "";
  65. APGoodsMT apgmt = null;
  66. if (apgoodsmt != null && apgoodsmt.Count > 0)
  67. {
  68. apgmt = apgoodsmt[0];
  69. var success1 = DataAccess.GetOneValue("select SaleManId from PurInMT where BillNo = " + apgoodsmt[0].BillNo, out obj, out result1);
  70. SaleManId = obj.ToString();
  71. }
  72. else {
  73. return Json(new
  74. {
  75. success = false,
  76. msg = "没有选择应付单据"
  77. });
  78. }
  79. //整单付款
  80. //一次只能选同一个供应商申请付款
  81. bool success = PlanMTDAL.addPayPlan(
  82. SaleManId, ContactId, SuppliersId,
  83. 0, Remark,
  84. PayType,
  85. apgoodsmt,
  86. out result,
  87. apgmt.EntId,
  88. apgmt.OrgId,
  89. apgmt.DeptId);
  90. return Json(new
  91. {
  92. success = success,
  93. msg = result,
  94. result1 = result1
  95. });
  96. }
  97. [HttpPost]
  98. [Route("getData")]
  99. public JsonResult GetData(string[] filters, Int32 pageIndex, Int32 pageSize,
  100. string sortField, Int32 sortDirection, string[] sumFields, [FromBody] dynamic data)
  101. {
  102. List<QueryFilter> filterList = new List<QueryFilter>();
  103. if (data != null)
  104. {
  105. if (data.filters.Count > 0)
  106. {
  107. var list = JsonConvert.SerializeObject(data.filters);
  108. filterList = JsonConvert.DeserializeObject<List<QueryFilter>>(list);
  109. }
  110. pageIndex = data.pageIndex;
  111. pageSize = data.pageSize;
  112. sortField = data.sortField;
  113. sortDirection = data.sortDirection;
  114. sumFields = data.sumFields.ToObject<string[]>();
  115. }
  116. var isAce = sortDirection == 0;
  117. var queryCondition = string.Empty;
  118. var param = new List<SqlParameter>(0);
  119. var start = (pageIndex - 1) * pageSize;
  120. var end = (start + 1 + pageSize);
  121. var dt = new DataTable();
  122. if (filterList != null)
  123. {
  124. queryCondition = QueryFilter.getFilterSqlParam(filterList.ToArray(), out param, new PlanMT(), "C.");
  125. }
  126. sortField = "C." + sortField;
  127. var sql =
  128. $"select * from " +
  129. $"(select *,row_number() over (order by " + sortField + " " + sortDirection + ") as rowNum " +
  130. $"from PlanMT C " +
  131. $"where 1 = 1 {queryCondition}" +
  132. $") R" +
  133. $" where rowNum > {start} and rowNum < {end}";
  134. DataAccess.GetValues(sql, ref dt, param.ToArray(), out var msg);
  135. IList<PlanMT> result = new List<PlanMT>();
  136. if (dt != null && dt.Rows.Count > 0)
  137. {
  138. result = ModelConvertHelper<PlanMT>.ConvertToModel(dt);
  139. }
  140. var jsonData = JsonConvert.SerializeObject(result);
  141. var countSql =
  142. $"select count(1) from " +
  143. $"(select * from PlanMT C " +
  144. $"where 1 = 1 {queryCondition}) R";
  145. var count = DataAccess.GetRowCountDefine(countSql, param.ToArray(), out var msg1);
  146. return Json(new
  147. {
  148. items = result,
  149. sum = new { },
  150. totalCount = count,
  151. msg
  152. });
  153. }
  154. [HttpPost]
  155. [Route("getDataBill")]
  156. public JsonResult GetDataBill(string[] filters, Int32 pageIndex, Int32 pageSize,
  157. string sortField, Int32 sortDirection, string[] sumFields, [FromBody] dynamic data)
  158. {
  159. List<QueryFilter> filterList = new List<QueryFilter>();
  160. if (data != null)
  161. {
  162. if (data.filters.Count > 0)
  163. {
  164. var list = JsonConvert.SerializeObject(data.filters);
  165. filterList = JsonConvert.DeserializeObject<List<QueryFilter>>(list);
  166. }
  167. pageIndex = data.pageIndex;
  168. pageSize = data.pageSize;
  169. sortField = data.sortField;
  170. sortDirection = data.sortDirection;
  171. sumFields = data.sumFields.ToObject<string[]>();
  172. }
  173. var isAce = sortDirection == 0;
  174. var queryCondition = string.Empty;
  175. var param = new List<SqlParameter>(0);
  176. var start = (pageIndex - 1) * pageSize;
  177. var end = (start + 1 + pageSize);
  178. var dt = new DataTable();
  179. if (filterList != null)
  180. {
  181. queryCondition = QueryFilter.getFilterSqlParam(filterList.ToArray(), out param, new PlanBillDT(), "C.");
  182. }
  183. sortField = "C." + sortField;
  184. var sql =
  185. $"select * from " +
  186. $"(select *,row_number() over (order by " + sortField + " " + sortDirection + ") as rowNum " +
  187. $"from PlanBillDT C " +
  188. $"where 1 = 1 {queryCondition}" +
  189. $") R" +
  190. $" where rowNum > {start} and rowNum < {end}";
  191. DataAccess.GetValues(sql, ref dt, param.ToArray(), out var msg);
  192. IList<PlanBillDT> result = new List<PlanBillDT>();
  193. if (dt != null && dt.Rows.Count > 0)
  194. {
  195. result = ModelConvertHelper<PlanBillDT>.ConvertToModel(dt);
  196. }
  197. var jsonData = JsonConvert.SerializeObject(result);
  198. var countSql =
  199. $"select count(1) from " +
  200. $"(select * from PlanBillDT C " +
  201. $"where 1 = 1 {queryCondition}) R";
  202. var count = DataAccess.GetRowCountDefine(countSql, param.ToArray(), out var msg1);
  203. return Json(new
  204. {
  205. items = result,
  206. sum = new { },
  207. totalCount = count,
  208. msg
  209. });
  210. }
  211. [HttpPost]
  212. [Route("getDataDT")]
  213. public JsonResult GetDataDT(string[] filters, Int32 pageIndex, Int32 pageSize,
  214. string sortField, Int32 sortDirection, string[] sumFields, [FromBody] dynamic data)
  215. {
  216. List<QueryFilter> filterList = new List<QueryFilter>();
  217. if (data != null)
  218. {
  219. if (data.filters.Count > 0)
  220. {
  221. var list = JsonConvert.SerializeObject(data.filters);
  222. filterList = JsonConvert.DeserializeObject<List<QueryFilter>>(list);
  223. }
  224. pageIndex = data.pageIndex;
  225. pageSize = data.pageSize;
  226. sortField = data.sortField;
  227. sortDirection = data.sortDirection;
  228. sumFields = data.sumFields.ToObject<string[]>();
  229. }
  230. var isAce = sortDirection == 0;
  231. var queryCondition = string.Empty;
  232. var param = new List<SqlParameter>(0);
  233. var start = (pageIndex - 1) * pageSize;
  234. var end = (start + 1 + pageSize);
  235. var dt = new DataTable();
  236. if (filterList != null)
  237. {
  238. queryCondition = QueryFilter.getFilterSqlParam(filterList.ToArray(), out param, new PlanGoodsDT(), "C.");
  239. }
  240. sortField = "C." + sortField;
  241. var sql =
  242. $"select * from " +
  243. $"(select *,row_number() over (order by " + sortField + " " + sortDirection + ") as rowNum " +
  244. $"from PlanGoodsDT C " +
  245. $"where 1 = 1 {queryCondition}" +
  246. $") R" +
  247. $" where rowNum > {start} and rowNum < {end}";
  248. DataAccess.GetValues(sql, ref dt, param.ToArray(), out var msg);
  249. IList<PlanGoodsDT> result = new List<PlanGoodsDT>();
  250. if (dt != null && dt.Rows.Count > 0)
  251. {
  252. result = ModelConvertHelper<PlanGoodsDT>.ConvertToModel(dt);
  253. }
  254. var jsonData = JsonConvert.SerializeObject(result);
  255. var countSql =
  256. $"select count(1) from " +
  257. $"(select * from PlanMT C " +
  258. $"where 1 = 1 {queryCondition}) R";
  259. var count = DataAccess.GetRowCountDefine(countSql, param.ToArray(), out var msg1);
  260. return Json(new
  261. {
  262. items = result,
  263. sum = new { },
  264. totalCount = count,
  265. msg
  266. });
  267. }
  268. }
  269. }