<div class="content-wrapper">
 <section class="content-header">
  <h1>
    <?= $page_title ?>
    <small><?= $page_desc ?></small>
  </h1>
  <ol class="breadcrumb">
   <li><a href="<?= base_url() ?>"><i class="fa fa-star-o" aria-hidden="true"></i>Home</a></li>
   <li><?= $menu ?></li>
   <li class="active"><?= $sub_menu ?></li>
 </ol>
</section>
<section class="content">
  <div class="row">
  <div class="col-sm-12">
    <?php if($this->session->flashdata('message')) { 
      $flashdata = $this->session->flashdata('message'); ?>
      <div class="alert alert-<?= $flashdata['class'] ?>">
       <button class="close" data-dismiss="alert" type="button">×</button>
       <?= $flashdata['message'] ?>
     </div>
   <?php } ?>
  </div>
  
  <?php if($this->session->userdata['user_type'] == 1){ ?>
   <div class="col-sm-12">
    <div class="box box-warning">
     <div class="box-header with-border">
       <h3 class="box-title">Transaction Management</h3>
     </div>
     <div class="box-body">
        <form role="form" id="cmpyPayDetlsForm" action="<?=base_url('Payment/getPayDetails')?>" method="post" class="validate" data-parsley-validate="" enctype="multipart/form-data">
          <div class="col-sm-12">
            <div class="form-group">
             <label>Select Company</label>
             <select name="company_id" class="form-control required" data-parsley-trigger="change" 
              onchange="getCmpyPayDetls()" dmClick="0" required>
               <option selected disabled>Select Company</option>
               <?php 
                 if(!empty($company_data)){
                   foreach ($company_data as $company) {
                     $chkFlg = ($company_id == $company->company_id)?'selected':'';
                     echo '<option value="'.$company->company_id.'" '.$chkFlg.'>
                            '.$company->company_name.
                          '</option>';
                   } 
                 }
               ?>
             </select> 
           </div>
          </div>
        </form>
      </div>
    </div>
   </div>
  <?php } ?>

  <?php if(!empty($payment_details)){ ?>
   <div class="col-sm-12">
    <div class="box box-warning">
      <div class="box-header with-border">
       <h3 class="box-title">Transaction Charges</h3>
      </div>
      <div class="box-body">
        <div class="col-sm-12">
          <div class="col-sm-6">
            <div class="col-sm-5">Booking Charge</div>
            <div class="col-sm-1">
              <span style="padding-right:30px;">:</span><strong><?= $payment_details->booking_charge ?></strong>
            </div>
          </div>
          <div class="col-sm-6">
            <div class="col-sm-5">SMS Charge</div>
            <div class="col-sm-1">
              <span style="padding-right:30px;">:</span><strong><?=$payment_details->sms_charge?></strong>
            </div>
          </div>
        </div>
        <div class="col-sm-12">
          <div class="col-sm-6">
            <div class="col-sm-5">Notification Charge</div>
            <div class="col-sm-1">
              <span style="padding-right:30px;">:</span><strong><?= $payment_details->push_charge ?></strong>
            </div>
          </div>
          <div class="col-sm-6">
            <div class="col-sm-5">Report Charge</div>
            <div class="col-sm-1">
              <span style="padding-right:30px;">:</span><strong><?= $payment_details->report_charge ?></strong>
            </div>
          </div>
        </div>
      </div>
      <br>
      <div class="box-header with-border">
        <h3 class="box-title">Payment Details</h3>
      </div>
      <div class="box-body">
        <div class="col-sm-12">
          <div class="col-sm-6">
            <div class="col-sm-5">Booking Count</div>
            <div class="col-sm-1">
              <span style="padding-right:30px;">:</span><strong><?= $payment_details->booking_count ?></strong>
            </div>
          </div>
          <div class="col-sm-6">
            <div class="col-sm-5">SMS Send</div>
            <div class="col-sm-1">
              <span style="padding-right:30px;">:</span><strong><?= $payment_details->sms_count ?></strong>
            </div>
          </div>
        </div>
        <div class="col-sm-12">
          <div class="col-sm-6">
            <div class="col-sm-5">Notification Send</div>
            <div class="col-sm-1">
              <span style="padding-right:30px;">:</span><strong><?=$payment_details->push_count?></strong>
            </div>
          </div>
          <div class="col-sm-6">
            <div class="col-sm-5">Report Generated</div>
            <div class="col-sm-1">
              <span style="padding-right:30px;">:</span><strong><?= $payment_details->report_count ?></strong>
            </div>
          </div>
        </div>
        <div class="col-sm-12" style="padding-top:10px;">
          <div class="col-sm-6">
            <div class="col-sm-5">Total Earning</div>
            <div class="col-sm-1">
              <span style="padding-right:30px;">:</span><strong><?= $payment_details->total_earnings ?></strong>
            </div>
          </div>
          <div class="col-sm-6">
            <div class="col-sm-5">Total Paid</div>
            <div class="col-sm-1">
              <span style="padding-right:30px;">:</span><strong><?= $payment_details->paid_amount ?></strong>
            </div>
          </div>
        </div>
        <div class="col-sm-12" style="padding-top:10px;">
          <div class="col-sm-6">
            <div class="col-sm-5">Last Payment On</div>
            <div class="col-sm-5" style="padding-left:0px;">
              <strong><?= (!empty($payment_details->last_paid_date))?date('d-M-Y G:i',$payment_details->last_paid_date):'' ?></strong>
            </div>
          </div>
        </div>
        <div class="col-sm-12">
          <div class="col-sm-6">
            <div class="col-sm-5">Outstanding Amount</div>
            <div class="col-sm-1">
              <span style="padding-right:30px;">:</span><strong><?= $payment_details->outstanding_amount ?></strong>
            </div>
          </div>
        </div>
        <?php if($this->session->userdata['user_type'] !=1 && $payment_details->outstanding_amount > 0){ ?>
          <div class="col-sm-12" style="padding-left: 47px;margin-top: 10px;">
            <button type="submit" class="btn btn-success">Pay Now</button>
          </div>
        <?php } ?>
      </div>

      <?php if($this->session->userdata['user_type'] !=1 && !empty($broker_pay_details)){ ?>
        <br>
        <div class="box-header with-border">
          <h3 class="box-title">Broker Payment Details</h3>
        </div>
        <?php 
        $count = 1;
        foreach($broker_pay_details AS $brk_data){ 
          $brk_data['broker_id'] = encode_param($brk_data['broker_id']); ?>
          <div class="box-body">
            <b class="box-title" style="padding-left:20px;padding-bottom:10px;">
              <?= $count ?>.<span style="padding-left:10px;"><?= $brk_data['broker_name'] ?></span>
            </b>
            <div class="col-sm-12" style="padding-top:10px;">
              <div class="col-sm-6">
                <div class="col-sm-5">Total Booking Received</div>
                <div class="col-sm-1">
                  <span style="padding-right:30px;">:</span><strong id="all_trans_count_<?= $brk_data['broker_id'] ?>"><?= $brk_data['all_trans_count'] ?></strong>
                </div>
              </div>
              <div class="col-sm-6">
                <div class="col-sm-5">Total Booking Processed</div>
                <div class="col-sm-1">
                  <span style="padding-right:30px;">:</span><strong id="pro_trans_count_<?= $brk_data['broker_id'] ?>"><?= $brk_data['pro_trans_count'] ?></strong>
                </div>
              </div>
            </div>
            <div class="col-sm-12">
              <div class="col-sm-6">
                <div class="col-sm-5">Total Paid Bookings </div>
                <div class="col-sm-1">
                  <span style="padding-right:30px;">:</span><strong id="tot_paid_booking_<?= $brk_data['broker_id'] ?>"><?= $brk_data['pro_trans_count'] - $brk_data['pending_trans_count'] ?>
                    </strong>
                </div>
              </div>
              <div class="col-sm-6">
                <div class="col-sm-5">Bookings To Be Paid</div>
                <div class="col-sm-1">
                  <span style="padding-right:30px;">:</span><strong id="pending_trans_count_<?= $brk_data['broker_id'] ?>"><?= $brk_data['pending_trans_count'] ?></strong>
                </div>
              </div>
            </div>
            <div class="col-sm-12" style="padding-top:10px;">
              <div class="col-sm-2" style="padding-left:31px;">
                Last Payment Date
              </div>
              <div class="col-sm-10">
                <span style="padding-left:45px;padding-right:30px;">:</span><strong id="brkPayDate_<?= $brk_data['broker_id'] ?>" >
                  <?= (empty($brk_data['last_paid_date']))?' -- ':date('d-M-Y',strtotime($brk_data['last_paid_date'])) ?></strong>
              </div>
            </div>
            <div class="col-sm-12" style="padding-top:10px;">
              <div class="col-sm-3" style="padding-left:31px;top:7px;">
                Update Last Payment Date
              </div>
              <div class="col-sm-3">
                <div class="input-group date" data-provide="datepicker">
                  <input id="datepicker" type="text" class="form-control required" data-parsley-trigger="change" data-parsley-minlength="2" required="" name="payment_date_<?= $brk_data['broker_id'] ?>" placeholder="Pick Last Paid Date" autocomplete="off">
                  <div class="input-group-addon">
                    <i class="fa fa-calendar"></i>
                  </div>
                </div>
              </div>
            <div class="col-sm-2" style="padding-bottom:10px;padding-left:30px;">
              <button id="updateBrkPayDate_<?= $brk_data['broker_id'] ?>" type="submit" class="btn btn-info" broker_id="<?= $brk_data['broker_id'] ?>">Update</button>
            </div>
            </div><!-- 
            <div class="col-sm-12" style="padding-bottom:10px;padding-left:48px;">
              <button id="updateBrkPayDate_<?= $brk_data['broker_id'] ?>" type="submit" class="btn btn-info" broker_id="<?= $brk_data['broker_id'] ?>">Update</button>
            </div> -->
          </div>
          <?php 
              $count++;
            } ?>
        </div>
      <?php } ?>
    </div>
  </div>
  <?php } ?>
  </div>
 </section>
</div>