PrizeWinner.cshtml 15 KB

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