<?php //print_r($usertype);exit; ?>
    <section class="content-header">
      <h1>
        Unpaid Invoices
      </h1>
      <ol class="breadcrumb">
        <li><a href="<?php echo base_url().'admin';?>"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">List</li>
      </ol>
    </section>

    <section class="content">
      <div class="row">
        <?php echo $this->utility->showMsg();?>
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              <h3 class="box-title">Management</h3>
              
              </div>
               
              <div></div>
            <!-- /.box-header -->
            <div class="box-body table-responsive">
            <?php if(count($orders) < 500){?>
              <a target="_blank" href="<?php echo base_url().'admin/order/download_membership/'; ?>"><input type="button" class="btn btn-info" value="Download Membership Invoice First 500" id="download"></a>
            <?php }elseif(count($orders) > 500 && count($orders) < 1000){?>
              <a target="_blank" href="<?php echo base_url().'admin/order/download_membership/'; ?>"><input type="button" class="btn btn-info" value="Download Membership Invoice First 500" id="download"></a>
              <a target="_blank" href="<?php echo base_url().'admin/order/download_membership/1'; ?>"><input type="button" class="btn btn-info" value="Download Membership Invoice Next 500" id="download"></a>
            <?php }elseif(count($orders) > 1000 && count($orders) < 1500){?>
              <a target="_blank" href="<?php echo base_url().'admin/order/download_membership/'; ?>"><input type="button" class="btn btn-info" value="Download Membership Invoice First 500" id="download"></a>
              <a target="_blank" href="<?php echo base_url().'admin/order/download_membership/1'; ?>"><input type="button" class="btn btn-info" value="Download Membership Invoice Next 500" id="download"></a>
              <a target="_blank" href="<?php echo base_url().'admin/order/download_membership/2'; ?>"><input type="button" class="btn btn-info" value="Download Membership Invoice Next 500" id="download"></a>
            <?php } ?>  
            <a target="_blank" href="<?php echo base_url().'admin/order/download_booking/'; ?>"><input type="button" class="btn btn-info" value="Download Booking Invoice" id="download"></a>
            <h4>Membership Unpaid Orders</h4>

              <table id="example2" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>#</th>
                  <th>Order No.</th>
                  <th>Date</th>
                  <th>Total(&euro;)</th>
                  <th>Payment Method</th>
                  <?php if($this->session->userdata('admin_id')=='19624' || $this->session->userdata('admin_id')=='25267'){ ?>
                  <th>Members username</th>
                  <th>Mobile number</th>
                  <?php } ?>
        				  <th>Is renew</th>
                </tr>
                </thead>
                 <?php if(count($orders)>0)
                {?>
                <tbody>
               <?php
                $i=1;
                $member_total = 0;
                foreach ($orders as $data) 
                {
                  $member_total += $data['total_sum'];
                  $numberDetails = getValue('feu_userdetails',array('user_id'=>$data['user_id']));
                  $userPhones = getValue('usr_phones',array('user_id'=>$data['user_id']));
                  $number = '';
                  if($numberDetails['mobile_number'] != '')
                  {
                    if(strpos($numberDetails['mobile_number'],'+') === false)
                    {
                      $number = '+'.$numberDetails['mobile_number'];
                    }
                    else
                    {
                      $number = $numberDetails['mobile_number'];
                    }
                  }
                  elseif($userPhones)
                  {
                    if(strpos($userPhones['mobile_number'],'+') === false)
                    {
                      $number = '+'.$userPhones['mobile_number'];
                    }
                    else
                    {
                      $number = $userPhones['mobile_number'];
                    }
                  }
                ?>
                <tr>
                    <td><?php echo $i;?></td>
                    <td><?php echo $data['order_id_masked']; ?></td>
                    <td><?php echo date('d-m-Y H:i:s',$data['created']); ?></td>
                    <td><?php echo number_format($data['total_sum']/100,2,',','.');  ?></td>
                    <td><?php if($data['payment_method_id']==12){ echo 'Bank Transfer'; } elseif($data['payment_method_id']==13){ echo 'Saferpay'; } elseif($data['payment_method_id']==14){ echo 'Stripe'; } else{ echo 'Pay By Bank'; } ?></td>
                    <?php if($this->session->userdata('admin_id')=='19624' || $this->session->userdata('admin_id')=='25267'){ ?>
                    <td><a target="_blank" href="<?php echo base_url();?>admin/users/edit/<?php echo base64_encode($data['user_id']);?>"><?php echo $data['username']; ?></a></td>
                    <td><?php if($number!='+0'){ echo $number; } ?></td>
                    <?php } ?>
          					<td><?php if($data['is_renewed']==1){ echo 'Renew';} else{ echo ''; } ?></td>
                </tr>

               <?php $i++; } ?>

                </tbody>
                <?php } ?>
                <tfoot>
               
                </tfoot>
              </table>
              <span style="margin-bottom: 100px; display: block; font-weight: bold !important; font-size: 15px;">Total Membership Amount: <?php echo number_format($member_total/100, 2,',', '.'); ?></span>


              <span style="display:block; margin-bottom: 100px;"></span>


              <h4>Booking Unpaid Orders</h4>
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>#</th>
                  <th>Order No.</th>
                  <th>Date</th>
                  <th>Total(&euro;)</th>
                  <th>Payment Method</th>
                  <?php if($this->session->userdata('admin_id')=='19624' || $this->session->userdata('admin_id')=='25267'){ ?>
                  <th>Members username</th>
                  <th>Mobile number</th>
                  <?php } ?>
                  <th>Total Reminders</th>
                  <th>Last Remind Date</th>
                </tr>
                </thead>
                 <?php if(count($booking_orders)>0)
                {?>
                <tbody>
               <?php
                $i=1;
                $booking_total = 0;
                foreach ($booking_orders as $data) 
                {
                  $booking_total += $data['total_sum'];
                  $numberDetails = getValue('feu_userdetails',array('user_id'=>$data['user_id']));
                  $userPhones = getValue('usr_phones',array('user_id'=>$data['user_id']));
                  $number = '';
                  if($numberDetails['mobile_number'] != '')
                  {
                    if(strpos($numberDetails['mobile_number'],'+') === false)
                    {
                      $number = '+'.$numberDetails['mobile_number'];
                    }
                    else
                    {
                      $number = $numberDetails['mobile_number'];
                    }
                  }
                  elseif($userPhones)
                  {
                    if(strpos($userPhones['mobile_number'],'+') === false)
                    {
                      $number = '+'.$userPhones['mobile_number'];
                    }
                    else
                    {
                      $number = $userPhones['mobile_number'];
                    }
                  }
                ?>
                <tr>
                    <td><?php echo $i;?></td>
                    <td><?php echo $data['order_id_masked']; ?></td>
                    <td><?php echo date('d-m-Y H:i:s',$data['created']); ?></td>
                    <td><?php echo number_format($data['total_sum']/100,2,',','.');  ?></td>
                    <td><?php if($data['payment_method_id']==12){ echo 'Bank Transfer'; } elseif($data['payment_method_id']==13){ echo 'Saferpay'; } elseif($data['payment_method_id']==14){ echo 'Stripe'; } else{ echo 'Pay By Bank'; } ?></td>
                    <?php if($this->session->userdata('admin_id')=='19624' || $this->session->userdata('admin_id')=='25267'){ ?>
                    <td><a target="_blank" href="<?php echo base_url();?>admin/users/edit/<?php echo base64_encode($data['user_id']);?>"><?php echo $data['username']; ?></a></td>
                    <td><?php if($number!='+0'){ echo $number; } ?></td>
                    <?php } ?>
                    <td><?php echo $data['reminder']; ?></td>
                    <td><?php echo $data['reminder_date']; ?></td>
                </tr>

               <?php $i++; } ?>

                </tbody>
                <?php } ?>
                <tfoot>
               
                </tfoot>
              </table>
              <span style="margin-bottom: 100px; display: block; font-weight: bold !important; font-size: 15px;">Total Booking Amount: <?php echo number_format($booking_total/100, 2,',', '.'); ?></span>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    

    
<script>
  $(function () {
    $("#example1").DataTable();
    $("#example2").DataTable();
  });
</script>