SearchSpin.cshtml 17 KB

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