Report.cshtml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. 
  2. @{
  3. ViewBag.Title = "Report";
  4. Layout = "~/Views/Shared/_Layout.cshtml";
  5. }
  6. @using ReportWeb;
  7. @using ReportWeb.Models;
  8. @using SuperCms.Extensions;
  9. @model List<DailyReport>
  10. @{
  11. var listService = Context.Session.GetComplexData<List<Services>>("listService");
  12. Users user = Context.Session.GetComplexData<Users>("user");
  13. }
  14. <!-- BEGIN: Content-->
  15. <div class="app-content content">
  16. <div class="content-wrapper">
  17. <div class="content-body">
  18. <div class="card">
  19. <div class="card-header">
  20. <h4 class="card-title">Search</h4>
  21. <a class="heading-elements-toggle"><i class="fa fa-ellipsis-v font-medium-3"></i></a>
  22. <div class="heading-elements">
  23. <ul class="list-inline mb-0">
  24. <li><a data-action="collapse"><i class="ft-minus"></i></a></li>
  25. <li><a data-action="reload"><i class="ft-rotate-cw"></i></a></li>
  26. <li><a data-action="expand"><i class="ft-maximize"></i></a></li>
  27. <li><a data-action="close"><i class="ft-x"></i></a></li>
  28. </ul>
  29. </div>
  30. </div>
  31. <div class="card-content collapse show">
  32. <div class="card-body">
  33. <form class="form">
  34. <div class="row">
  35. <div class="col-md-4 col-sm-4 col-6">
  36. <div class="form-group">
  37. <label>Service</label>
  38. <div class='input-group'>
  39. <input type="hidden" value="@ViewBag.ServiceId" id="svIdSearch" />
  40. <select class="form-control" id="service_id">
  41. @if (listService != null)
  42. {
  43. if (user.role == Common.UserRole.Admin)
  44. {
  45. foreach (Services sv in listService)
  46. {
  47. <option value="@sv.id">@sv.sv_name</option>
  48. }
  49. }
  50. else
  51. {
  52. foreach (Services sv in listService)
  53. {
  54. if (sv.sv_code.StartsWith("LUCKYCALL"))
  55. {
  56. <option value="@sv.id">@sv.sv_name</option>
  57. }
  58. }
  59. }
  60. }
  61. </select>
  62. </div>
  63. </div>
  64. </div>
  65. <div class="col-md-4 col-sm-4 col-6">
  66. <div class="form-group">
  67. <label>From</label>
  68. <div class='input-group'>
  69. <input type="text" class="form-control fromDate" id="fromDate">
  70. </div>
  71. </div>
  72. </div>
  73. <div class="col-md-4 col-sm-4 col-6">
  74. <div class="form-group">
  75. <label>To</label>
  76. <div class='input-group'>
  77. <input type="text" class="form-control toDate" id="toDate">
  78. </div>
  79. </div>
  80. </div>
  81. <div class="col-md-4 col-sm-4 col-12">
  82. <div class="form-group " style="margin-top: 10px">
  83. <button type="button" class="btn btn-primary btn-min-width "
  84. onclick="SearchHistory();" id="btnSearch">
  85. Search
  86. </button>
  87. <button type="button" class="btn btn-fill btn-warning" onclick="exportExcel()" id="btnExportExcel">
  88. <i class="icon-export"></i> Export Excel
  89. </button>
  90. </div>
  91. </div>
  92. </div>
  93. </form>
  94. </div>
  95. </div>
  96. </div>
  97. <div class="card">
  98. <div class="card-header">
  99. <h4 class="card-title">Report</h4>
  100. </div>
  101. <div class="card-content collapse show">
  102. <div class="card-body ">
  103. <table class="table table-striped table-bordered base-style">
  104. <thead>
  105. <tr>
  106. <th>No.</th>
  107. <th>Report date</th>
  108. <th>Revenue</th>
  109. <th>Revenue Buy</th>
  110. <th>Paid money</th>
  111. <th>Count sub</th>
  112. <th>Register new</th>
  113. <th>Deactive</th>
  114. </tr>
  115. </thead>
  116. <tbody id="gridbody2">
  117. @if (Model != null && Model.Count > 0)
  118. {
  119. for (int i = 0; i < Model.Count; i++)
  120. {
  121. var his = Model[i];
  122. <tr>
  123. <td class="text-right">@(i + 1)</td>
  124. <td class="text-center">@his.report_date</td>
  125. <td class="text-right">@his.revenue</td>
  126. <td class="text-right">@his.revenue_buy</td>
  127. <td class="text-right">@his.paid_money</td>
  128. <td class="text-right">@his.count_active</td>
  129. <td class="text-right">@his.count_reg</td>
  130. <td class="text-right">@his.count_deactive</td>
  131. </tr>
  132. }
  133. }
  134. </tbody>
  135. </table>
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. </div>
  141. </div>
  142. <div class="hidden">
  143. <div class="row">
  144. <div class="col-lg-12 mb-1">
  145. <div class="input-group">
  146. <div class="input-group-prepend">
  147. <span class="input-group-text">
  148. <span class="fa fa-calendar-o"></span>
  149. </span>
  150. </div>
  151. <input id="picker_from" class="form-control datepicker" type="date">
  152. </div>
  153. </div>
  154. <div class="col-lg-12">
  155. <div class="input-group">
  156. <div class="input-group-prepend">
  157. <span class="input-group-text">
  158. <span class="fa fa-calendar-o"></span>
  159. </span>
  160. </div>
  161. <input id="picker_to" class="form-control datepicker" type="date">
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. <!-- END: Content-->
  167. @section Scripts {
  168. <script src="~/admin-assets/js/scripts/tables/datatables/datatable-styling.min.js"></script>
  169. <script src="~/admin-assets/js/scripts/pickers/dateTime/bootstrap-datetime.min.js"></script>
  170. <script src="~/admin-assets/js/scripts/pickers/dateTime/pick-a-datetime.min.js"></script>
  171. <script>
  172. var dataTable = $(".base-style").DataTable({ "paging": 0 });
  173. var opts = {
  174. lines: 8, // The number of lines to draw
  175. length: 5, // The length of each line
  176. width: 3, // The line thickness
  177. radius: 5, // The radius of the inner circle
  178. scale: 1, // Scales overall size of the spinner
  179. corners: 1, // Corner roundness (0..1)
  180. color: '#ffffff', // CSS color or array of colors
  181. fadeColor: 'transparent', // CSS color or array of colors
  182. speed: 1, // Rounds per second
  183. rotate: 0, // The rotation offset
  184. animation: 'spinner-line-fade-quick', // The CSS animation name for the lines
  185. direction: 1, // 1: clockwise, -1: counterclockwise
  186. zIndex: 2e9, // The z-index (defaults to 2000000000)
  187. className: 'spinner', // The CSS class to assign to the spinner
  188. //top: '50%', // Top position relative to parent
  189. //left: '50%', // Left position relative to parent
  190. shadow: '0 0 1px transparent', // Box-shadow for the lines
  191. //position: 'absolute' // Element positioning
  192. };
  193. var spinner = new Spinner(opts);
  194. function startSpinner(obj) {
  195. var target = document.getElementById(obj);
  196. $("#" + obj).prop("disabled", true);
  197. spinner.spin(target);
  198. }
  199. function stopSpinner(obj) {
  200. $("#" + obj).prop("disabled", false);
  201. if (spinner != undefined) {
  202. spinner.stop();
  203. }
  204. }
  205. //$( document ).ready(function() {
  206. // $("#timerange").datetimepicker({
  207. // format: "d/MM/YYYY hh:mm a - d/MM/YYYY hh:mm a"
  208. // })
  209. //});
  210. function SearchHistory() {
  211. if (dataTable != null && dataTable != undefined) {
  212. dataTable
  213. .clear()
  214. .destroy();
  215. }
  216. var service_id = $("#service_id").val();
  217. var fromDate = $("#fromDate").val();
  218. var toDate = $("#toDate").val();
  219. startSpinner('btnSearch');
  220. $.ajax({
  221. url: subDomain + "/Admin/GetReport",
  222. data: {
  223. fromDate: fromDate,
  224. toDate: toDate,
  225. service_id: service_id
  226. },
  227. type: "POST",
  228. success: function (data) {
  229. stopSpinner('btnSearch');
  230. console.log(data);
  231. if (data.error != "0") {
  232. console.log(data.content);
  233. //setTimeout(function () {
  234. // showModal('message-dialog');
  235. // $('#message-content').html(data.content.split("\n").join("<br />"));
  236. //}, 1000);
  237. } else {
  238. updateGridCharge("gridbody2", data.dailyReport);
  239. console.log("format table");
  240. dataTable = $(".base-style").DataTable({ "paging": 0 });
  241. }
  242. },
  243. error: function (data) {
  244. stopSpinner('btnSearch');
  245. console.log(data.error);
  246. }
  247. })
  248. }
  249. function updateGridCharge(gridbody, val) {
  250. $("#" + gridbody).html("");
  251. console.log(val);
  252. var html = "";
  253. if (val != undefined) {
  254. for (var i = 0; i < val.length; i++) {
  255. var news = val[i];
  256. html += "<tr>";
  257. html += "<td scope = 'row'> " + (i + 1) + "</td>";
  258. html += "<td class='text-center'> " + news.report_date + "</td> ";
  259. html += "<td class='text-right'> " + news.revenue + "</td> ";
  260. html += "<td class='text-right'> " + news.revenue_buy + "</td> ";
  261. html += "<td class='text-right'> " + news.paid_money + "</td> ";
  262. html += "<td class='text-right'> " + news.count_active + "</td> ";
  263. html += "<td class='text-right'> " + news.count_reg + "</td> ";
  264. html += "<td class='text-right'> " + news.count_deactive + "</td> ";
  265. html += "</tr>";
  266. }
  267. }
  268. $("#" + gridbody).html(html);
  269. }
  270. function exportExcel() {
  271. console.log("Export data");
  272. startSpinner('btnExportExcel');
  273. var service_id = $("#service_id").val();
  274. var fromDate = $("#fromDate").val();
  275. var toDate = $("#toDate").val();
  276. $.ajax({
  277. url: subDomain + "/Admin/ReportExport",
  278. data: {
  279. __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
  280. fromDate: fromDate,
  281. toDate: toDate,
  282. service_id: service_id
  283. },
  284. type: "POST",
  285. xhr: function () {
  286. var xhr = new XMLHttpRequest();
  287. xhr.onreadystatechange = function () {
  288. if (xhr.readyState == 2) {
  289. if (xhr.status == 200) {
  290. xhr.responseType = "blob";
  291. console.log("blob");
  292. } else {
  293. xhr.responseType = "text";
  294. console.log("text");
  295. }
  296. }
  297. };
  298. return xhr;
  299. },
  300. success: function (data, status, xhr) {
  301. stopSpinner('btnExportExcel');
  302. let filename = "";
  303. let disposition = xhr.getResponseHeader('Content-Disposition');
  304. if (disposition && disposition.indexOf('attachment') !== -1) {
  305. let filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
  306. let matches = filenameRegex.exec(disposition);
  307. if (matches != null && matches[1]) filename = matches[1].replace(/['"]/g, '');
  308. }
  309. let a = document.createElement('a');
  310. let url = window.URL.createObjectURL(data);
  311. a.href = url;
  312. a.download = filename.replace('UTF-8', '');;
  313. document.body.append(a);
  314. a.click();
  315. a.remove();
  316. window.URL.revokeObjectURL(url);
  317. $("#overlay").fadeOut(300);
  318. },
  319. error: function (data) {
  320. stopSpinner('btnExportExcel');
  321. console.log(data);
  322. }
  323. })
  324. }
  325. $(document).ready(function () {
  326. $("#fromDate").datetimepicker({
  327. format: "DD/MM/YYYY",
  328. defaultDate: moment().add(-30, 'days')
  329. });
  330. $("#toDate").datetimepicker({
  331. format: "DD/MM/YYYY",
  332. defaultDate: moment().startOf('day')
  333. });
  334. // if select sv id
  335. var svId = $("#svIdSearch").val();
  336. if (svId != null && svId != "") {
  337. $("#service_id").val(svId);
  338. SearchHistory();
  339. }
  340. });
  341. </script>
  342. }