@extends('merch_layouts.merch_master')
@section('page-title') 
    Merchant | Transactions
@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">Sales from <strong><span class="text-success">{{ $merchant->fullname }}</span></strong> to Customers</div>
        <div class="panel-body">
            <div class="" style="padding-bottom: 10px;">
                <button id="transactions-download-xlsx" class="btn btn-success btn-sm"><i class="fa fa-file-excel-o"></i> Download XLSX</button>
                <button id="transactions-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/transactions') !!}">
                  <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="transactionsTable"></div>
        </div>
        <div class="panel-footer"></div>
    </div>
</div>
</div>
            
            



@endsection
@section('page-js')

<script src="{!! url('public/theme_assets/vendor/tabulator/js/tabulator.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("#transactionsTable", {
        ajaxURL: "transactions/all",
        paginationSize: 15,
        layout: "fitColumns",
        pagination: "remote",
        selectable: false,
        printAsHtml: true,
        ajaxLoaderLoading: $('#logo_spinner').html(),
        columns: [
            
            // {
            //     title: "Merchant",
            //     field: "fullname",
            //     sorter: "string",
            // },
            {
                title: "Merchant Phone",
                field: "msisdn",
                sorter: "string",
                // formatter: cellDesign,
                // formatter:link,
            },
            {
                title: "Amount",
                field: "amount",
                sorter: "number",
            },
            // {
            //     title: "Payment Method",
            //     field: "payment_method",
            //     sorter: "string",
            // },
            
            {
                title: "Status",
                field: "status",
                sorter: "string",
                formatter: statusDesign,
            }, 
                        
            {
                title: "Date",
                field: "created_at",
                sorter: "string",
            },
        ],

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

    });
</script>

@endsection
