<?php echo $this->extend('template/admin/main') ?>

<?php echo $this->section('content') ?>

<?php echo $this->include('common/message') ?>

<?php
    $sessiondata = \Config\Services::session(); 
  ?>

<div class="card mb-4">
    <div class="card-body">

     

      <form action="<?php echo base_url(route_to('date-singleagentrange'))?>" id="transaction" method="post" class="row g-3" accept-charset="utf-8" enctype="multipart/form-data">
								<?php echo $this->include('common/security') ?>

            <div class="col-12 col-md-6 col-lg-3">
                <?php echo $this->include('common/filter/daterangefrom') ?>
            </div>

            <div class="col-12 col-md-6 col-lg-3">
                <?php echo $this->include('common/filter/daterangeto') ?>
            </div>
            <input type="hidden" name="agentid" value="<?php echo $agentid; ?>">
            <div class="col-12 col-md-6 col-lg-3 mt-4 mb-2">
            <br>
                <button type="submit" class="btn btn-success"><?php echo lang("Localize.submit") ?></button>
            </div>

      </form>

      <h5 class="m-1">Total Income : <?php echo  $sessiondata->get('currency_symbol');?> <?php echo $totalMoney; ?></h5>
      <h5 class="m-1">Total Given Money : <?php echo  $sessiondata->get('currency_symbol');?> <?php echo $givenMoney; ?></h5>
      <h5 class="m-1">Total Due : <?php echo  $sessiondata->get('currency_symbol');?> <?php echo $dueMoney; ?></h5>

        <div class="table-responsive mt-3">
        <table class="table display table-bordered table-striped table-hover basic" id="agentpay">
          <thead>
            <tr>
              <th scope="col">#</th>
              <th scope="col"><?php echo lang("Localize.name") ?></th>
              <th scope="col"><?php echo lang("Localize.company") ?></th>
              <th scope="col"><?php echo lang('Localize.amount'); ?></th>
              <th scope="col"><?php echo lang('Localize.cancellation_fee'); ?></th>
              <th scope="col"><?php echo lang('Localize.available_balance'); ?></th>
              <th scope="col"><?php echo lang("Localize.status") ?> </th>
              <th scope="col">Detail</th>
             
            </tr>
          </thead>
          <tbody>
              
          <?php foreach ($payagent as $kye =>  $value) : ?>

            <tr>
              <th scope="row"><?php echo $kye+1 ;?></th>
              <td>
               
                  <?php echo $value->first_name; ?>
                  <?php echo $value->last_name; ?>
                
              </td>
              <td><?php echo !empty($value->company_name) ? esc($value->company_name) : '-'; ?></td>
              <td><?php echo esc($value->amount); ?></td>
              <td><?php echo !empty($value->cancel_amount) ? $value->cancel_amount : ""; ?></td>
              <td><?php echo $value->total_balance; ?></td>

              <td>
                <?php if ((int) ($value->status ?? 0) === 0) : ?>
                  <span class="badge bg-secondary">Pending</span>
                <?php elseif ((int) ($value->status ?? 0) === 1) : ?>
                  <span class="badge bg-success">Approved</span>
                <?php elseif ((int) ($value->status ?? 0) === 2) : ?>
                  <span class="badge bg-danger"><?php echo lang('Localize.rejected') ?: 'Rejected'; ?></span>
                <?php endif ?>
              </td>
              <td><?php
                  $detail = (string) ($value->detail ?? '');
                  if (strpos($detail, 'recharge balance') !== 0) {
                      $detail = str_replace('Refund (', 'Cancelation (', $detail);
                      $detail = preg_replace('/Cancel\s*amount\s*:/i', 'Fee Amount:', $detail);
                  }
                  echo esc($detail);
              ?></td>
        

             
              
            </tr>
              

          <?php endforeach ?>
          
          
          </tbody>
        </table>
        </div>

    </div>
</div>


<?php echo $this->endSection() ?>