@extends('merch_layouts.merch_master')
@section('page-title') 
    Merchant | Dealer Top Ups
@endsection
@section('page-css')
<link href="{!! url('public/theme_assets/vendor/tabulator/css/bootstrap/tabulator_bootstrap.css') !!}" type="text/css" rel="stylesheet">
@endsection
@section('page-content')
<div class="row">

<div class="col-md-12">
    <div class="hpanel hblue">
        <div class="panel-heading hbuilt">Top Ups received from Dealers</div>
        <div class="panel-body">
            <div class="" style="padding-bottom: 10px;">
              <button id="dealertopups-download-xlsx" class="btn btn-success btn-sm"><i class="fa fa-file-excel-o"></i> Download XLSX</button>
              <button id="dealertopups-download-pdf" class="btn btn-danger btn-sm"><i class="fa fa-file-pdf-o"></i> Download PDF</button>
            </div>
            <div class="pull-right">
                <form method="GET" action="{!! url('merchant/dealertransactions') !!}">
                  <div class="col-md-12 form-group pull-right top_search" style="background: cornflowerblue;">
                    <div class="input-group">
                      <input type="text" name="keyword" class="form-control" id="keywordField" placeholder="Keyword here.. ">
                      
                    </div>
                  </div>
                </form>
            </div>
            <div id="dealerTopsTable"></div>
        </div>
        <div class="panel-footer"></div>
    </div>
</div>
</div>
            
            



@endsection
@section('page-js')

<script src="{!! url('public/vendor/tabulator-master/dist/js/tabulator.min.js') !!}"></script>
<script src="{!! url('public/theme_assets/vendor/tabulator/js/xlsx.full.min.js') !!}"></script>
<script src="{!! url('public/theme_assets/vendor/tabulator/js/jspdf.min.js') !!}"></script>
<script src="{!! url('public/theme_assets/vendor/tabulator/js/jspdf.plugin.autotable.js') !!}"></script>


<script>
    function statusDesign (cell, formatterParams){
      var value = cell.getValue();
      // if(value === 'Approved'){
      if(value.includes('Success')){
        return "<span style='color:#3FB449; font-weight:bold;'>" + value + "</span>";
      }
      else if(value.includes('Failed')){
        return "<span style='color:#3FB449; font-weight:bold;'>" + value + "</span>";
      }
      else{
            return "<span style='color:#E4A11B;'>" + value + "</span>";
      }
    }
    var table = new Tabulator("#dealerTopsTable", {
        ajaxURL: "dealertransactions/all",
        paginationSize: 15,
        layout: "fitColumns",
        pagination: "remote",
        selectable: false,
        printAsHtml: true,
        ajaxLoaderLoading: $('#logo_spinner').html(),
        columns: [
            
            {
                title: "Dealer",
                field: "name",
                sorter: "string",
            },
            {
                title: "Dealer Phone",
                field: "phone",
                sorter: "string",
            },
            {
                title: "Amount",
                field: "amount",
                sorter: "number",
            },
            
            {
                title: "Status",
                field: "status",
                sorter: "string",
                formatter: statusDesign,
            }, 
                        
            {
                title: "Date",
                field: "created_at",
                sorter: "string",
            },
        ],

        rowClick:function(e, row){
            var userID = row.getData().id;
        },
    });
    document.getElementById("dealertopups-download-xlsx").addEventListener("click", function(){
      table.download("xlsx", "dealertopups-list.xlsx", {sheetName:"Sheet 1"});
    });
        //trigger download of data.pdf file
    document.getElementById("dealertopups-download-pdf").addEventListener("click", function(){
      table.download("pdf", "dealertopups-list.pdf", {
          orientation:"portrait", //set page orientation to portrait
          title:"Click Mobile - Dealer Top Ups", //add title to report
      });
    });
    $('#keywordField').on('keyup', function(){
      console.log('up');
      var keyword = $(this).val();
      table.setData("dealertransactions/all?keyword=" + keyword);

    });
</script>

@endsection
