Ranking.cshtml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. <th>Action</th>
  85. </tr>
  86. </thead>
  87. <tbody id="gridbody1">
  88. @if (Model != null && Model.rankingCoin != null && Model.rankingCoin.Count > 0)
  89. {
  90. for (int i = 0; i < Model.rankingCoin.Count; i++)
  91. {
  92. var his = Model.rankingCoin[i];
  93. <tr>
  94. <td class="text-right">@(his.rank)</td>
  95. <td class="text-center">@his.msisdn</td>
  96. <td class="text-center">@his.total_coin</td>
  97. <td class="text-right">@his.start_time.Value.ToString("MM/yyyy")</td>
  98. <td class="text-right">@his.product_name</td>
  99. <td class="text-right">@his.last_update.Value.ToString("dd/MM/yyyy HH:mm:ss")</td>
  100. <td class="text-center">
  101. @if (i == 0)
  102. {
  103. if (his.status == 0)
  104. {
  105. <button id="btn-add-money" class="btn btn-danger" onclick="addMoney(@his.id);">
  106. <i class="fa fa-money"></i> Add Money
  107. </button>
  108. }
  109. else if (his.status == 1)
  110. {
  111. <span>Processing</span>
  112. }
  113. else if (his.status == 2)
  114. {
  115. <span>Processed</span>
  116. } else {
  117. <span>Not ready</span>
  118. }
  119. }
  120. </td>
  121. </tr>
  122. }
  123. }
  124. </tbody>
  125. </table>
  126. </div>
  127. </div>
  128. </div>
  129. </div>
  130. </div>
  131. </div>
  132. <div class="hidden">
  133. <div class="row">
  134. <div class="col-lg-12 mb-1">
  135. <div class="input-group">
  136. <div class="input-group-prepend">
  137. <span class="input-group-text">
  138. <span class="fa fa-calendar-o"></span>
  139. </span>
  140. </div>
  141. <input id="picker_from" class="form-control datepicker" type="date">
  142. </div>
  143. </div>
  144. <div class="col-lg-12">
  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_to" class="form-control datepicker" type="date">
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. <!-- END: Content-->
  157. @section Scripts {
  158. <script src="~/admin-assets/js/scripts/tables/datatables/datatable-styling.min.js"></script>
  159. <script src="~/admin-assets/js/scripts/pickers/dateTime/bootstrap-datetime.min.js"></script>
  160. <script src="~/admin-assets/js/scripts/pickers/dateTime/pick-a-datetime.min.js"></script>
  161. <script>
  162. var opts = {
  163. lines: 8, // The number of lines to draw
  164. length: 5, // The length of each line
  165. width: 3, // The line thickness
  166. radius: 5, // The radius of the inner circle
  167. scale: 1, // Scales overall size of the spinner
  168. corners: 1, // Corner roundness (0..1)
  169. color: '#ffffff', // CSS color or array of colors
  170. fadeColor: 'transparent', // CSS color or array of colors
  171. speed: 1, // Rounds per second
  172. rotate: 0, // The rotation offset
  173. animation: 'spinner-line-fade-quick', // The CSS animation name for the lines
  174. direction: 1, // 1: clockwise, -1: counterclockwise
  175. zIndex: 2e9, // The z-index (defaults to 2000000000)
  176. className: 'spinner', // The CSS class to assign to the spinner
  177. //top: '50%', // Top position relative to parent
  178. //left: '50%', // Left position relative to parent
  179. shadow: '0 0 1px transparent', // Box-shadow for the lines
  180. //position: 'absolute' // Element positioning
  181. };
  182. var spinner = new Spinner(opts);
  183. function startSpinner(obj) {
  184. var target = document.getElementById(obj);
  185. $("#" + obj).prop("disabled", true);
  186. spinner.spin(target);
  187. }
  188. function stopSpinner(obj) {
  189. $("#" + obj).prop("disabled", false);
  190. if (spinner != undefined) {
  191. spinner.stop();
  192. }
  193. }
  194. //$( document ).ready(function() {
  195. // $("#timerange").datetimepicker({
  196. // format: "d/MM/YYYY hh:mm a - d/MM/YYYY hh:mm a"
  197. // })
  198. //});
  199. var tableDetail;
  200. function resetTableDetail() {
  201. tableDetail = $("#grid_detail").DataTable({
  202. orderCellsTop: true,
  203. fixedHeader: true
  204. });
  205. }
  206. function clearTable(table) {
  207. if (table != null && table != undefined) {
  208. table
  209. .clear()
  210. .destroy();
  211. }
  212. }
  213. resetTableDetail();
  214. function SearchHistory() {
  215. var msisdn = $("#msisdn").val();
  216. var fromDate = $("#fromDate").val();
  217. startSpinner('btnSearch');
  218. clearTable(tableDetail);
  219. $.ajax({
  220. url: subDomain + "/LuckySpin/GetRanking",
  221. data: {
  222. __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
  223. month: fromDate,
  224. msisdn: msisdn
  225. },
  226. type: "POST",
  227. success: function (data) {
  228. stopSpinner('btnSearch');
  229. console.log(data);
  230. if (data.error != "0") {
  231. console.log(data.content);
  232. swal("Warning", data.content, "warning");
  233. } else {
  234. updateGridRegInfo("gridbody1", data.model.rankingCoin);
  235. resetTableDetail();
  236. }
  237. },
  238. error: function (data) {
  239. stopSpinner('btnSearch');
  240. console.log(data);
  241. resetTableDetail();
  242. }
  243. })
  244. }
  245. function updateGridRegInfo(gridbody, val) {
  246. $("#" + gridbody).html("");
  247. console.log(val);
  248. var html = "";
  249. if (val != undefined) {
  250. for (var i = 0; i < val.length; i++) {
  251. var news = val[i];
  252. html += "<tr>";
  253. html += '<td class="text-right">' + news.rank + '</td>';
  254. html += "<td class='text-left'> " + news.msisdn + "</td> ";
  255. html += "<td class='text-right'> " + news.total_coin + "</td> ";
  256. html += "<td class='text-center'> " + moment(news.start_time).format("MM/YYYY") + "</td> ";
  257. html += "<td class='text-right'> " + news.product_name + "</td> ";
  258. html += "<td class='text-center'> " + moment(news.last_update).format("DD/MM/YYYY HH:mm:ss") + "</td> ";
  259. html += "<td class='text-center'>"
  260. + (i == 0 ? (news.status == 0 ? "<button id='btn-add-money' class='btn btn-danger btn-sm' onclick='addMoney(" + news.id + ");'><i class='fa fa-money'></i> Add Money</span>" : news.status == 1 ? "Processing" : news.status == 2 ? "Processed" : "Not ready") : "")
  261. + "</td>";
  262. html += "</tr>";
  263. }
  264. }
  265. $("#" + gridbody).html(html);
  266. }
  267. function exportExcel() {
  268. console.log("Export data");
  269. startSpinner('btnExportExcel');
  270. var msisdn = $("#msisdn").val();
  271. var fromDate = $("#fromDate").val();
  272. $.ajax({
  273. url: subDomain + "/LuckySpin/RankingExport",
  274. data: {
  275. __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
  276. month: fromDate,
  277. msisdn: msisdn
  278. },
  279. type: "POST",
  280. xhr: function () {
  281. var xhr = new XMLHttpRequest();
  282. xhr.onreadystatechange = function () {
  283. if (xhr.readyState == 2) {
  284. if (xhr.status == 200) {
  285. xhr.responseType = "blob";
  286. console.log("blob");
  287. } else {
  288. xhr.responseType = "text";
  289. console.log("text");
  290. }
  291. }
  292. };
  293. return xhr;
  294. },
  295. success: function (data, status, xhr) {
  296. stopSpinner('btnExportExcel');
  297. let filename = "";
  298. let disposition = xhr.getResponseHeader('Content-Disposition');
  299. if (disposition && disposition.indexOf('attachment') !== -1) {
  300. let filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
  301. let matches = filenameRegex.exec(disposition);
  302. if (matches != null && matches[1]) filename = matches[1].replace(/['"]/g, '');
  303. }
  304. let a = document.createElement('a');
  305. let url = window.URL.createObjectURL(data);
  306. a.href = url;
  307. a.download = filename.replace('UTF-8', '');;
  308. document.body.append(a);
  309. a.click();
  310. a.remove();
  311. window.URL.revokeObjectURL(url);
  312. $("#overlay").fadeOut(300);
  313. },
  314. error: function (data) {
  315. stopSpinner('btnExportExcel');
  316. console.log(data);
  317. }
  318. })
  319. }
  320. $(document).ready(function () {
  321. $("#fromDate").datetimepicker({
  322. format: "MM/YYYY",
  323. defaultDate: moment().startOf('month')
  324. });
  325. });
  326. function addMoney(id) {
  327. startSpinner("btn-add-money");
  328. swal({
  329. title: "Are you sure?",
  330. text: "System will add money automatically!",
  331. icon: "warning",
  332. buttons: [
  333. 'No!',
  334. 'Yes!'
  335. ],
  336. dangerMode: true,
  337. }).then(function (isConfirm) {
  338. console.log(isConfirm);
  339. if (isConfirm) {
  340. $.ajax({
  341. url: subDomain + "/LuckySpin/AddMoneyRanking",
  342. data: {
  343. __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val(),
  344. id: id
  345. },
  346. type: "POST",
  347. success: function (data) {
  348. stopSpinner('btnSearch');
  349. console.log(data);
  350. if (data.error != "0") {
  351. console.log(data.content);
  352. swal("Warning", data.content, "warning");
  353. } else {
  354. swal("Success!", data.content, "success");
  355. SearchHistory();
  356. }
  357. },
  358. error: function (data) {
  359. stopSpinner('btnSearch');
  360. console.log(data);
  361. resetTableDetail();
  362. }
  363. })
  364. } else {
  365. stopSpinner("btn-add-money");
  366. }
  367. })
  368. }
  369. </script>
  370. }