 <?php $__env->startSection('content'); ?>
<div class="content-wrapper merchant-right-side">
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>-->
        <!-- Content Header (Page header) -->
        <section class="content-header">
          
		<div class="btn btn-primary modalpopup" data-toggle="modal" data-target="#myModal">SEND</div>
    	<div class="pull-right">
    	     <a class="btn btn-primary" style="margin-right: 38px;" href="<?php echo url('merchant/inactive_tokens'); ?>">Inactive Coupons</a>
    		<a class="btn btn-primary" href="<?php echo url('merchant/addtokens'); ?>">Create New Coupon</a>

<!-- 			<?php echo $__env->make('includes.search', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?> -->
		</div><br><br>
         

           <?php echo $__env->make('includes.messages', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
        </section>

        <!-- Main content -->
        <section class="content">
        <div class="row">
            <div class="col-xs-12">
              <div class="box">
               
                <div class="box-body table-responsive no-padding">
                <?php if(count($data['rewards']) == 0): ?>
					<p class='notice'><?php echo trans('admin::users.pages.no_record_found'); ?></p>
				<?php else: ?> 
				<table class="table table-bordered table-striped">
				<thead>
				<tr>
				<th>S.No</th>
				<th>Select</th>
				<th>Coupon Name</th>
				<th>Issued</th>
				<th>Redeemed</th>
			
				<th>Location</th>
				<th>Timing</th>
				<th>Coupon Validity </th>
				<th>Valid days</th>
				<!-- <th>Expiry</th> -->
				<th>Sub Account Linking</th>
				 <th>Action</th>
				
				</tr></thead>
				<tbody>
				
				<?php /**/ $j=0 /**/ ?>
				 <?php foreach($data['rewards'] as $ad ): ?>
							<?php /**/ $class= ($ad->is_expired==1)?'Active':'Expired'/**/ ?>
							<?php $days=explode(',', $ad->valid_on);
							$day='';
							for($i=0; $i<count($days); $i++){
							if($days[$i]=='1'){
							$day=$day.'SUN, ';
							}
							if($days[$i]=='2'){
								$day=$day.'MON, ';
							}
							if($days[$i]=='3'){
								$day=$day.'TUE, ';
							}
							if($days[$i]=='4'){
								$day=$day.'WED, ';
							}
							if($days[$i]=='5'){
								$day=$day.'THU, ';
							}
							if($days[$i]=='6'){
								$day=$day.'FRI, ';
							}
							if($days[$i]=='7'){
								$day=$day.'SAT, ';
							}
							}
							$string=rtrim($day,', ');
							?>
			
				<tr>
				<td  align="center"><?php echo $j=$j+1; ?></td>
				<td align="center">
				
				<input tabindex="1" type="checkbox" name="selector[]" id="<?php echo $ad->id; ?>" value="<?php echo $ad->id; ?>" data-name="<?php echo $ad->name; ?>">

  				</td>
				<td><?php echo $ad->name; ?></td>
				<td><?php if($ad->temp_issue == 0): ?> 0 <?php else: ?> <?php echo $ad->temp_issue; ?> <?php endif; ?> <span>/</span><?php echo $ad->issue_limit; ?></td>
				<td><?php if($ad->temp_redeem == 0): ?> 0 <?php else: ?> <?php echo $ad->temp_redeem; ?> <?php endif; ?><span>/</span><?php echo $ad->redeem_limit; ?></td>
				<!--<td><?php echo $ad->points; ?></td>-->
				<td><?php echo $ad->location; ?></td>
				<td><?php $splittime=explode(',', $ad->timing);
				if($splittime[0]==00.01)
				{
				   $from='00.01 AM';
				}
				elseif ($splittime[0]==12.00) 
				{
					 $from='12.00 PM';
				}
				elseif($splittime[0]>12.00)
				{
				$from=$splittime[0]-12.00;
				
				$from=$from.' PM';
				}
				else{
				$from=$splittime[0].' AM';
				}
				if($splittime[1] == 23.59)
				{
					$to='11.59 PM';
				}
				elseif ($splittime[1]==12.00) {
					$to='12.00 PM';
				}
				elseif($splittime[1]>12.00)
				{
					$to=$splittime[1]-12.00;
					
					$to=$to.' PM';
					
				}
				else{
					$to=$splittime[1].' AM';
				}
		    	
				?><?php echo $from; ?> to <?php echo $to; ?></td>
				<td><?php echo $ad->validity; ?><?php if($ad->validity== 1): ?>  Day <?php else: ?> Days <?php endif; ?></td>
				<td><?php echo $string; ?></td>
				<td><a href="<?php echo url('merchant/editsubaccount/'.$ad->id); ?>" id=""><i class=""></i>Link</a></td>
				<!-- <td><?php echo $class; ?></td> -->
				<!--<td><a href="<?php echo url('merchant/edit/'.$ad->id.'/token'); ?>"><i class="fa fa-edit"></i> Active</a></td>-->
				<td><a href="<?php echo url('merchant/delete/token/'.$ad->id); ?>"><i class="fa fa-lock"></i> Deactivate</a></td>
				</tr>
				<?php endforeach; ?>
				</tbody>
				</table>

                  <?php endif; ?>

                </div><!-- /.box-body -->
              </div><!-- /.box -->
            </div>
          </div>
        </section><!-- /.content -->
      </div>
      <div id="myModal" class="modal fade" role="dialog">
      <div class="modal-dialog modal-lg">

        <!-- Modal content-->
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Send Coupons</h4>
          </div>
          <div class="modal-body">
            
            <?php echo Form::open(array('url'=>'merchant/confirm_sendToken','method'=>'POST','role'=>"form",
							'files'=>true,'id'=>'adds-add-form')); ?>

                <div class="form-group">
            		<label>Enter a mobile number/unique id of recipient:</label>
                  	<input type="text" class="form-control pull-right" name="mobile_no" id="mobile_no" maxlength="10" >
                </div>

                 <div class="form-group">


                 <center><label><br />OR</label></center>
                 </div>
                <div class="form-group">
            		<label>Select your Recipients:</label>
                  	<select class="form-control mobile_list" name="mobile_list" id="mobile_list" >
                  		<option  value="">Select Mobile Number</option>
                  		<?php foreach($data1 as $datas): ?>
                  		<option  value='<?php echo $datas->mobile; ?>'><?php echo $datas->name."(".$datas->mobile.")"; ?></option>
                  		<?php endforeach; ?>
                  	</select>
                </div>
                 <div class="form-group">
                 	<div>Coupons Selected</div>
                 	<div class="token_summary"></div>
                </div>
            
            <div class='message'></div>
          </div>
          <div class="modal-footer" style="text-align: center">
            <input type="submit" class="btn btn-primary register" value="SEND" id="register" onclick="return validateForm()">
          </div>
         <?php echo Form::close(); ?>

        </div>

      </div>
    </div>

<?php $__env->startSection('scripts'); ?>
<script>

	$('.modalpopup').click(function()
	{
		$('.token_summary').html("");
        $(':checkbox:checked').each(function()
        {
          	var name = $(this).attr('data-name');

        	$('.token_summary').prepend("<label class='inline username' style='width: 135px;display: inline-block !important;'>"+name+"</label><label class='radio-inline'><input type='text' name='issue_limit[] '   placeholder='Enter Number of uses ' style='margin-left: 134px;'  > <input type='text' class='inline custom_textbox' name='' style='display: none'></label><input type='hidden' name='token_id[]' value='"+$(this).val()+"' /><br>");
        });
        

	});

	$(document).on('click', '.multiple', function() 
	{
    	$(this).parents().find('.custom_textbox').css('display','inline-block');
	});
	

</script>

<script>
 function validateForm() {
    var x = document.forms["adds-add-form"]["mobile_no"].value;
    var y = document.forms["adds-add-form"]["mobile_list"].value;
  
    if (x == "" && y =="") {
        alert("Please Enter Mobile number or unique id");
        return false;

    }
   
  
}
</script>

	<script>
$('.token_summary').keypress(function (e) {
	if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
        return false;
    }
});
</script>

<?php $__env->stopSection(); ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.merchant-backend-layout', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>