<?php //print_r($usertype);exit; ?>
    <section class="content-header">
      <h1>
        Events
      </h1>
      <ol class="breadcrumb">
        <li><a href="<?php echo base_url().'admin';?>"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class=""><a href="<?php echo base_url().'admin/event';?>">Event</a></li>
        <li class="active">Guest 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">Guest List</h3>
              <a target="_blank" href="<?php echo base_url().'admin/event/download_guestlist/'.$this->uri->segment(4); ?>"><input type="button" class="btn btn-info" value="Download CSV" id="download"></a>
                <a class="btn btn-primary margin-right pull-right" href="<?php echo base_url()?>admin/event/add">Add</a>
                <a class="btn btn-primary margin-right pull-right send" href="javascript:void(0)">Send Bulk SMS</a>
              </div>
               
              <div></div>
            <!-- /.box-header -->
            <div class="box-body table-responsive">
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <!-- <th>#</th> -->
                  <th>Username</th>
                  <?php if($this->session->userdata('admin_id')=='19624' ){ ?>
                  <th>Email</th>
                  <?php } ?>
                  <th>Member status(Payment Status)</th>
                  <th>Booking Order Number</th>
                  <th>Booking date</th>
                  <th>Checkin date</th>
                  <th>Drink package</th>
                  <th>No. of cape</th>
                  <th>Ceremonial</th>
                  <th>Extra Wish</th>
                  <th>Room Category</th>
                  <th>Extra Night</th>
                  <th>Extras</th>
                  <th>Total Amount</th>
                  <th>Total Booking Amount</th>
                  <th>Rest Payment At Arrival</th>
                  <th>Details Checked</th>
                  <th>Booking Payment Status</th>
                  <th>Checkin Payment Status</th>
                  <th>Checkin Payment Method</th>
                  <th>No. Of Reminder Send</th>
                  <th>Last Reminder Send Date</th>
                  <th>Action</th>
                </tr>
                </thead>
                 <?php if(count($guestlist)>0)
                {?>
                <tbody>
               <?php
                $i=1;
                $url = [];
                $party_address = '';
                foreach ($guestlist as $data) 
                {
                  $additional = number_format($data['additional'],2,',','.');
                  if($additional == 0){
                    if($data['drinking_package']==2){
                      $additional = number_format($data['summury'],2,',','.');
                    }
                  }
                ?>
                <tr>
                    <!-- <td><?php echo $i;?></td> -->
                    <td><?php echo $data['username']; ?></td>
                    <?php if($this->session->userdata('admin_id')=='19624' ){ ?>
                    <td><?php echo $data['email']; ?></td>
                    <?php } ?>
                    <!-- <td><?php if($data['member_status']==4) { echo 'Premium'; } else { echo 'Basic';} ?></td> -->
                    <td><?php echo $data['usersmembership']; ?></td>
                    <td>
                      <a href="<?php echo base_url('admin/order/view/'.base64_encode($data['order_id'])); ?>" target="_blank"><?php echo 'CE-'.$data['order_id']; ?>
                      <?php if($data['is_exchanged'] == 1){
                        echo ' (Exchanged Order)';
                      } ?>
                      </a></td>
                    <td><?php echo date('Y-m-d',$data['book_date']); ?></td>
                    <td><?php echo $data['confirmed']; ?></td>
                    <td><?php if($data['drinking_package']==1) { echo 'Basic'; } elseif($data['drinking_package']==2) { echo 'Premium';} else { echo ''; }?></td>
                    <td><?php echo $data['cape']; ?></td>
                    <td><?php if($data['ceremonial']==1) { echo 'Accepted'; } ?></td>
                    <td><?php echo $data['extra_wish']; ?></td>
                    <td><?php echo $data['room_category']; ?></td>
                    <td><?php echo trim($data['dates'],','); ?></td>
                    <td><?php echo number_format($data['additional'],2,',','.'); ?></td>
                    <td><?php echo number_format($data['summury'],2,',','.'); ?></td>
                    <td>
                    <?php 
                    if($data['is_recomended'] == 1) {
                      $setting = getValue('sys_settings', array('key'=>'reservation_fee'));
                      $reservation_charge = $setting ? $setting['value'] : 0;
                      $reservation_total = ' (40% Deposit)';
                      echo number_format(($data['total_sum']/100),2,',','.'). $reservation_total; 
                    } else {
                      echo number_format(($data['total_sum']/100),2,',','.');
                    } 
                    ?>
                    </td>
                    <td>
                    <?php 
                    if($data['is_recomended'] == 1) {
                      echo number_format(($data['reservation_rest_amount']/100),2,',','.');
                    } 
                    ?>
                    </td>
                    <td><?php if($data['details_check']==1) { echo 'Yes'; } else { echo 'No';}?></td>
                    <td><?php if($data['payed']==1) { echo 'Paid'; }else{ echo 'Unpaid';} ?></td>
                    <td><?php if($data['checkin_payed']==1) { echo 'Paid'; }else{ echo 'Unpaid';} ?></td>
                    <td><?php if($data['checkin_payment_method_id']==1){ echo 'Saferpay'; } elseif($data['checkin_payment_method_id']==3){ echo 'Premium account so not to be paid'; } elseif($data['checkin_payment_method_id']==2){ echo 'Bank Transfer'; } else{ echo 'Bank Transfer'; }?></td>
                    <td><?php echo $data['totalreminder']; ?></td>
                    <td><?php echo $data['remind_date']; ?></td>
                    <td>
                      <a href="<?php echo base_url();?>admin/event/delete_guest/<?php echo base64_encode($data['order_id']);?>/<?php echo str_replace('/','-',uri_string()); ?>" title="Delete" onclick="return confirm('Are you sure to delete ?');"><span class="fa fa-ban"></span></a>
          					  <?php if($data['payed']==1) { 
                        if($data['mobile_number']!='' && $data['mobile_number']!=0){ ?>
                      <a href="<?php echo base_url();?>admin/event/sendSMS/<?php echo base64_encode($data['user_id']);?>/<?php echo base64_encode($data['event_id']);?>/<?php echo str_replace('/','-',uri_string()); ?>" title="Send SMS" onclick="return confirm('Are you sure to send SMS ?');"><span class="fa fa-phone"></span></a>
          					  <?php }else{ ?>
                      <a href="<?php echo base_url();?>admin/event/sendReminder/<?php echo base64_encode($data['user_id']);?>/<?php echo base64_encode($data['event_id']);?>/<?php echo str_replace('/','-',uri_string()); ?>" title="Mobile verification reminder" onclick="return confirm('Are you sure to send mobile verification reminder ?');"><span class="fa fa-check-circle"></span></a>
                      <?php } } else{ ?>
                      <a href="<?php echo base_url();?>admin/event/reminder/<?php echo base64_encode($data['order_id']);?>/<?php echo str_replace('/','-',uri_string()); ?>" title="Remind by email" onclick="return confirm('Are you sure to send reminder ?');"><span class="fa fa-envelope"></span></a>
                      <?php } ?>
                    </td>
                </tr>
                  <?php if(($data['mobile_number']!='' && $data['mobile_number']!=0) && $data['party_address']!=''){ 
                    $url[] = $data['mobile_number']; 
                    $party_address = $data['party_address'];
                  } ?>
               <?php $i++; } ?>

                </tbody>
                <?php } ?>
                <tfoot>
               
                </tfoot>
              </table>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <form id="sms_frm" action="<?php echo base_url().'admin/event/sendBulkSMS';?>" method="post" style="display:none;">
      <input type="hidden" name="url" value="<?php echo implode(',',$url); ?>">
      <input type="hidden" name="party_address" value="<?php echo $party_address; ?>">
      <input type="hidden" name="uri" value="<?php echo str_replace('/','-',uri_string()); ?>">
    </form>

    
<script>
  $(function () {
    $("#example1").DataTable({
        order: [[ 4, 'asc' ]]
    } );
    $('.send').click(function(){
      $('#sms_frm').submit();
    })
  });
</script>