<!DOCTYPE html>
<html lang="en">
<head>
<?php $this->load->view('includes/head'); ?>
</head>
<body>
  <div id="app">
    <div class="main-wrapper">
      <?php $this->load->view('includes/navbar'); ?>
      <!-- Main Content -->
      <div class="main-content">
        <section class="section">
          <div class="section-header">
            <div class="section-header-back">
              <a href="<?=base_url()?>" class="btn btn-icon"><i class="fas fa-arrow-left"></i></a>
            </div>
            <h1>
            <?=$this->lang->line('payments')?$this->lang->line('payments'):'Payments'?>
            </h1>
            <div class="section-header-breadcrumb">
              <div class="breadcrumb-item active"><a href="<?=base_url()?>"><?=$this->lang->line('dashboard')?$this->lang->line('dashboard'):'Dashboard'?></a></div>
              <div class="breadcrumb-item">
              <?=$this->lang->line('payments')?$this->lang->line('payments'):'Payments'?>
              </div>
            </div>
          </div>
          <div class="section-body">
            
            <div class="row">

                
                  <div class="col-md-12">
                    <div class="card card-primary">
                      <div class="card-body"> 
                        <div id="tool" class="row">
                          <?php if($this->ion_auth->is_admin()){ ?>
                            <select id='client' class="form-control col-md-4 mr-1">
                              <option value=""><?=$this->lang->line('select_clients')?$this->lang->line('select_clients'):'Select Clients'?></option>
                              <?php foreach($system_clients as $system_client){ ?>
                              <option value="<?=htmlspecialchars($system_client->id)?>"><?=htmlspecialchars($system_client->first_name)?> <?=htmlspecialchars($system_client->last_name)?></option>
                              <?php } ?>
                            </select>
                          <?php } ?>
                          <select id='project' class="form-control col-md-4 mr-1">
                            <option value=""><?=$this->lang->line('select_project')?$this->lang->line('select_project'):'Select Project'?></option>
                            <?php foreach($projects as $project){ ?>
                            <option value="<?=htmlspecialchars($project['id'])?>"><?=htmlspecialchars($project['title'])?></option>
                            <?php } ?>
                          </select>
                          <select id='status_filter' class="form-control col-md-3">
                            <option value="none"><?=$this->lang->line('select_status')?$this->lang->line('select_status'):'Select Status'?></option>
                            <option value="0">Due</option>
                            <option value="1">Paid</option>
                            <option value="2">Overdue</option>
                          </select>
                        </div>
                        <table class='table-striped' id='invoices_list'
                          data-toggle="table"
                          data-url="<?=base_url('invoices/get_payments')?>"
                          data-click-to-select="true"
                          data-side-pagination="server"
                          data-pagination="false"
                          data-page-list="[5, 10, 20, 50, 100, 200]"
                          data-search="true" data-show-columns="true"
                          data-show-refresh="false" data-trim-on-search="false"
                          data-sort-name="id" data-sort-order="DESC"
                          data-mobile-responsive="true"
                          data-toolbar="" data-show-export="false"
                          data-maintain-selected="true"
                          data-export-types='["txt","excel"]'
                          data-export-options='{
                            "fileName": "payments-list",
                            "ignoreColumn": ["state"] 
                          }'
                          data-query-params="queryParams">
                          <thead>
                            <tr>
                              
                              <?php if($this->ion_auth->is_admin()){ ?>
                                <th data-field="to_id" data-sortable="true"><?=$this->lang->line('clients')?$this->lang->line('clients'):'Clients'?></th>
                              <?php }else{ ?>
                                <th data-field="projects" data-sortable="false"><?=$this->lang->line('projects')?$this->lang->line('projects'):'Projects'?></th>
                              <?php } ?>

                              <th data-field="invoice_id" data-sortable="true"><?=$this->lang->line('invoice')?$this->lang->line('invoice'):'Invoice'?></th>

                              <th data-field="amount" data-sortable="true"><?=$this->lang->line('amount')?$this->lang->line('amount'):'Amount'?> - <?=get_currency('currency_code')?></th>

                              <th data-field="payment_type" data-sortable="true"><?=$this->lang->line('payment_type')?$this->lang->line('payment_type'):'Payment Type'?></th>
                              <th data-field="payment_date" data-sortable="true" data-visible="false"><?=$this->lang->line('payment_date')?$this->lang->line('payment_date'):'Payment Date'?></th>
                              <th data-field="status" data-sortable="true"><?=$this->lang->line('status')?$this->lang->line('status'):'Status'?></th>

                              <?php if($this->ion_auth->is_admin()){ ?>
                                <th data-field="action" data-sortable="true"><?=$this->lang->line('action')?$this->lang->line('action'):'Action'?></th>
                              <?php } ?>
                            </tr>
                          </thead>
                        </table>
                      </div>
                    </div>
                  </div>
              
          </div>
        </section>
      </div>
    
    <?php $this->load->view('includes/footer'); ?>
    </div>
  </div>

<?php $this->load->view('includes/js'); ?>
<script>
  function queryParams(p){
    return {
      "to_id": $('#client').val(),
      "items_id": $('#project').val(),
      "status": $('#status_filter').val(),
      limit:p.limit,
      sort:p.sort,
      order:p.order,
      offset:p.offset,
      search:p.search
    };
  }
  $('#tool').on('change',function(e){
    $('#invoices_list').bootstrapTable('refresh');
  });
</script>
</body>
</html>
