Ranking.cshtml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. 
  2. @{
  3. ViewBag.Title = "Search Spin";
  4. Layout = "~/Views/Shared/_Layout.cshtml";
  5. }
  6. @using ReportWeb;
  7. @using ReportWeb.Models;
  8. @using SuperCms.Extensions;
  9. @model SearchModel
  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>Month</label>
  38. <div class='input-group'>
  39. <input type="text" class="form-control fromDate" id="fromDate">
  40. </div>
  41. </div>
  42. </div>
  43. <div class="col-md-4 col-sm-4 col-6">
  44. <div class="form-group">
  45. <label>Msisdn</label>
  46. <div class='input-group'>
  47. <input type="text" class="form-control" id="msisdn">
  48. </div>
  49. </div>
  50. </div>
  51. <div class="col-md-4 col-sm-4 col-12">
  52. <label>Action</label>
  53. <div class="form-group ">
  54. <button type="button" class="btn btn-primary btn-min-width "
  55. onclick="SearchHistory();" id="btnSearch">
  56. Search
  57. </button>
  58. <button type="button" class="btn btn-fill btn-warning" onclick="exportExcel()" id="btnExportExcel">
  59. <i class="icon-export"></i> Export Excel
  60. </button>
  61. </div>
  62. </div>
  63. </div>
  64. </form>
  65. </div>
  66. </div>
  67. </div>
  68. <div class="card">
  69. <div class="card-header">
  70. <h4 class="card-title">Spin Log</h4>
  71. </div>
  72. <div class="card-content collapse show">
  73. <h5 class="px-2">Remain spin: <span id="remainSpin"></span></h5>
  74. <div class="card-body">
  75. <table class="table table-striped table-bordered base-style" id="grid_detail">
  76. <thead>
  77. <tr>
  78. <th>No.</th>
  79. <th>Msisdn</th>
  80. <th>Total coin</th>
  81. <th>Month</th>
  82. <th>Package</th>
  83. <th>Last Update</th>
  84. </tr>
  85. </thead>
  86. <tbody id="gridbody1">
  87. @if (Model != null && Model.rankingCoin != null && Model.rankingCoin.Count > 0)
  88. {
  89. for (int i = 0; i < Model.rankingCoin.Count; i++)
  90. {
  91. var his = Model.rankingCoin[i];
  92. <tr>
  93. <td class="text-right">@(his.rank)</td>
  94. <td class="text-center">@his.msisdn</td>
  95. <td class="text-center">@his.total_coin</td>
  96. <td class="text-right">@his.start_time.Value.ToString("MM/yyyy")</td>
  97. <td class="text-right">@his.product_name</td>
  98. <td class="text-right">@his.last_update.Value.ToString("dd/MM/yyyy HH:mm:ss")</td>
  99. </tr>
  100. }
  101. }
  102. </tbody>
  103. </table>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. <div class="hidden">
  111. <div class="row">
  112. <div class="col-lg-12 mb-1">
  113. <div class="input-group">
  114. <div class="input-group-prepend">
  115. <span class="input-group-text">
  116. <span class="fa fa-calendar-o"></span>
  117. </span>
  118. </div>
  119. <input id="picker_from" class="form-control datepicker" type="date">
  120. </div>
  121. </div>
  122. <div class="col-lg-12">
  123. <div class="input-group">
  124. <div class="input-group-prepend">
  125. <span class="input-group-text">
  126. <span class="fa fa-calendar-o"></span>
  127. </span>
  128. </div>
  129. <input id="picker_to" class="form-control datepicker" type="date">
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. <!-- END: Content-->
  135. @section Scripts {
  136. <script src="~/admin-assets/js/scripts/tables/datatables/datatable-styling.min.js"></script>
  137. <script src="~/admin-assets/js/scripts/pickers/dateTime/bootstrap-datetime.min.js"></script>
  138. <script src="~/admin-assets/js/scripts/pickers/dateTime/pick-a-datetime.min.js"></script>
  139. <script>
  140. var opts = {
  141. lines: 8, // The number of lines to draw
  142. length: 5, // The length of each line
  143. width: 3, // The line thickness
  144. radius: 5, // The radius of the inner circle
  145. scale: 1, // Scales overall size of the spinner
  146. corners: 1, // Corner roundness (0..1)
  147. color: '#ffffff', // CSS color or array of colors
  148. fadeColor: 'transparent', // CSS color or array of colors
  149. speed: 1, // Rounds per second
  150. rotate: 0, // The rotation offset
  151. animation: 'spinner-line-fade-quick', // The CSS animation name for the lines
  152. direction: 1, // 1: clockwise, -1: counterclockwise
  153. zIndex: 2e9, // The z-index (defaults to 2000000000)
  154. className: 'spinner', // The CSS class to assign to the spinner
  155. //top: '50%', // Top position relative to parent
  156. //left: '50%', // Left position relative to parent
  157. shadow: '0 0 1px transparent', // Box-shadow for the lines
  158. //position: 'absolute' // Element positioning
  159. };
  160. var spinner = new Spinner(opts);
  161. function startSpinner(obj) {
  162. var target = document.getElementById(obj);
  163. $("#" + obj).prop("disabled", true);
  164. spinner.spin(target);
  165. }
  166. function stopSpinner(obj) {
  167. $("#" + obj).prop("disabled", false);
  168. if (spinner != undefined) {
  169. spinner.stop();
  170. }
  171. }
  172. //$( document ).ready(function() {
  173. // $("#timerange").datetimepicker({
  174. // format: "d/MM/YYYY hh:mm a - d/MM/YYYY hh:mm a"
  175. // })
  176. //});
  177. var tableDetail;
  178. function resetTableDetail() {
  179. tableDetail = $("#grid_detail").DataTable({
  180. orderCellsTop: true,
  181. fixedHeader: true
  182. });
  183. }
  184. function clearTable(table) {
  185. if (table != null && table != undefined) {
  186. table
  187. .clear()
  188. .destroy();
  189. }
  190. }
  191. resetTableDetail();
  192. function SearchHistory() {
  193. var msisdn = $("#msisdn").val();
  194. var fromDate = $("#fromDate").val();
  195. startSpinner('btnSearch');
  196. clearTable(tableDetail);
  197. $.ajax({
  198. url: subDomain + "/LuckySpin/GetRanking",
  199. data: {
  200. __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
  201. month: fromDate,
  202. msisdn: msisdn
  203. },
  204. type: "POST",
  205. success: function (data) {
  206. stopSpinner('btnSearch');
  207. console.log(data);
  208. if (data.error != "0") {
  209. console.log(data.content);
  210. swal("Warning", data.content, "warning");
  211. } else {
  212. updateGridRegInfo("gridbody1", data.model.rankingCoin);
  213. resetTableDetail();
  214. }
  215. },
  216. error: function (data) {
  217. stopSpinner('btnSearch');
  218. console.log(data);
  219. resetTableDetail();
  220. }
  221. })
  222. }
  223. function updateGridRegInfo(gridbody, val) {
  224. $("#" + gridbody).html("");
  225. console.log(val);
  226. var html = "";
  227. if (val != undefined) {
  228. for (var i = 0; i < val.length; i++) {
  229. var news = val[i];
  230. html += "<tr>";
  231. html += '<td class="text-right">' + news.rank + '</td>';
  232. html += "<td class='text-left'> " + news.msisdn + "</td> ";
  233. html += "<td class='text-right'> " + news.total_coin + "</td> ";
  234. html += "<td class='text-center'> " + moment(news.start_time).format("MM/YYYY") + "</td> ";
  235. html += "<td class='text-right'> " + news.product_name + "</td> ";
  236. html += "<td class='text-center'> " + moment(news.last_update).format("DD/MM/YYYY HH:mm:ss") + "</td> ";
  237. html += "</tr>";
  238. }
  239. }
  240. $("#" + gridbody).html(html);
  241. }
  242. function exportExcel() {
  243. console.log("Export data");
  244. startSpinner('btnExportExcel');
  245. var msisdn = $("#msisdn").val();
  246. var fromDate = $("#fromDate").val();
  247. $.ajax({
  248. url: subDomain + "/LuckySpin/RankingExport",
  249. data: {
  250. __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
  251. month: fromDate,
  252. msisdn: msisdn
  253. },
  254. type: "POST",
  255. xhr: function () {
  256. var xhr = new XMLHttpRequest();
  257. xhr.onreadystatechange = function () {
  258. if (xhr.readyState == 2) {
  259. if (xhr.status == 200) {
  260. xhr.responseType = "blob";
  261. console.log("blob");
  262. } else {
  263. xhr.responseType = "text";
  264. console.log("text");
  265. }
  266. }
  267. };
  268. return xhr;
  269. },
  270. success: function (data, status, xhr) {
  271. stopSpinner('btnExportExcel');
  272. let filename = "";
  273. let disposition = xhr.getResponseHeader('Content-Disposition');
  274. if (disposition && disposition.indexOf('attachment') !== -1) {
  275. let filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
  276. let matches = filenameRegex.exec(disposition);
  277. if (matches != null && matches[1]) filename = matches[1].replace(/['"]/g, '');
  278. }
  279. let a = document.createElement('a');
  280. let url = window.URL.createObjectURL(data);
  281. a.href = url;
  282. a.download = filename.replace('UTF-8', '');;
  283. document.body.append(a);
  284. a.click();
  285. a.remove();
  286. window.URL.revokeObjectURL(url);
  287. $("#overlay").fadeOut(300);
  288. },
  289. error: function (data) {
  290. stopSpinner('btnExportExcel');
  291. console.log(data);
  292. }
  293. })
  294. }
  295. $(document).ready(function () {
  296. $("#fromDate").datetimepicker({
  297. format: "MM/YYYY",
  298. defaultDate: moment().startOf('month')
  299. });
  300. });
  301. </script>
  302. }