 <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark">My Payout Details</h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="<?php echo base_url() ?>admin/admin/dashboard">Dashboard</a></li>
              <li class="breadcrumb-item"><a href="#">Payout</a></li>
              <li class="breadcrumb-item active">My Payout Details</li>

            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->
    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="card card-default">
          <div class="card-header">
            <h3 class="card-title">View All Payout Details</h3>
          </div>
            <!-- /.card-header -->
            <div class="card-body">
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>ID</th>
                  <th>Year</th>
                  <th>Month</th>
                  <th>Payment Details</th>
                  <th>Pending Payment</th>
                </tr>
                </thead>
                <tbody>
                <?php $i=1; foreach ($all_salary as $salary):
                $ttl_amt = 0;
                foreach ($salary->payout as $payout) 
                {
                  $ttl_amt += $payout->pay_amount;
                }
                ?>
                <tr>
                  <td><?php echo $i ?></td>
                  <td><?php echo date('Y', strtotime($salary->pay_date)); ?></td>
                  <td><?php echo date('M', strtotime($salary->pay_date)); ?></td>
                  <td>
                    <button data-toggle="modal" data-target="#pay_details<?php echo $salary->pay_id; ?>" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i> View Details</button>
                  </td>
                  <td><b>&#8377; <?php echo $tlt_atm = user()->employee_pay_value - $ttl_amt ; ?></b></td>
                </tr>
                <?php $i++; ?>
                <?php endforeach; ?>
                </tbody>
              </table>
            </div>
          </div>
      </div>
    </section>
  </div>

<?php $i=1; foreach ($all_salary as $salary):?>
  <div class="modal fade" id="pay_details<?php echo $salary->pay_id; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLabel">Payment Details for <b><?php echo $cur_date;?></b></h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <table class="table table-bordered table-striped">
            <tr>
              <th>No</th>
              <th>Note</th>
              <th>Date</th>
              <th>Mode</th>
              <th>Amount</th>
            </tr>
            <?php 
            if($salary->payout)
            {
              $ttl_pay = 0;
              $ttl_ded = 0;
              $ttl_salary =0;

              $a =1; foreach ($salary->payout as $payout): 
              if($payout->pay_is_advance == 1)
              {
                $ttl_adv += $payout->pay_amount;
              }

              if($payout->pay_is_advance == 2)
              {
                $ttl_ded += $payout->pay_amount;
              }
              
              if($payout->pay_is_advance == 0)
              {
                $ttl_salary += $payout->pay_amount;
              }
              ?>
                <tr>
                  <td><?php echo $a; ?></td>
                  <td width="30%"><small><?php echo $payout->pay_note; ?></small></td>
                  <td><?php echo date('d-m-Y', strtotime($payout->pay_date)); ?></td>
                  <td>
                    <?php if($payout->pay_is_advance == 1)
                      {
                        echo '<b class="text-primary">Advance</b>';
                      }
                      elseif($payout->pay_is_advance == 2)
                      {
                        echo '<b class="text-danger">Deduction</b>'; 
                      }
                      else
                      {
                        echo '<b class="text-success">Salary</b>';
                      }
                    ?>
                  </td>
                  <td>&#8377;<?php echo $payout->pay_amount; ?></td>
                </tr>
              <?php $a++; endforeach ?>
              <tr>
                <th colspan="3"></th>
                <th>Main Salary</th>
                <th>&#8377;<?php echo user()->employee_pay_value; ?></th>
              </tr>
              <tr>
                <th colspan="3"></th>
                <th>Total Adv.</th>
                <th>&#8377;<?php echo $ttl_adv; ?></th>
              </tr>
              
              <tr>
                <th colspan="3"></th>
                <th>Deduction</th>
                <th>-&#8377;<?php echo $ttl_ded; ?></th>
              </tr>
              <tr>
                <th colspan="3"></th>
                <th>Final Payment</th>
                <th>&#8377;<?php echo $ttl_salary; ?></th>
              </tr>
            <?php }else{?>
              <tr>
                <td colspan="5" class="text-center">No Data Found</td>
              </tr>
            <?php }?>
          </table>
        </div>
      </div>
    </div>
  </div>
<?php endforeach; ?>


