<!-- Main Content -->

<div class="page-wrapper">

    <div class="container-fluid pt-25">

    	<div class="row">

    		<div class="col-md-12">

    			<div class="alert alert-success alert-dismissible" role="alert" <?php if($this->session->flashdata('message')==''){ ?> style="display:none" <?php } ?> >

          			<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>

          			<?php echo $this->session->flashdata('message'); ?>

        		</div>

    		</div>

    	</div>
    	<?php if($this->admin_type=='superadmin' || (in_array('11.1', $this->authority))){ ?>
	        <div class="row">

	            <div class="col-sm-12">

	                <div class="panel panel-default card-view">

	                    <div class="panel-heading">

	                        <div class="pull-left">

	                            <h6 class="panel-title txt-dark">Add Coupon</h6>

	                        </div>

	                        <div class="clearfix"></div>

	                    </div>

	                    <div class="panel-wrapper collapse in">

	                        <div class="panel-body">

	                            <form id="couponForm" action="<?php echo base_url(A."/addCoupon"); ?>" method="POST">
	                                <div class="row">
	                                    <div class="form-group col-md-3">
	                                        <label class="control-label">Coupon Code</label>
	                                        <input type="text" class="form-control" name="coupon_code" placeholder="Enter Coupon Code" />
	                                    </div>
	                                    <div class="form-group col-md-3">
	                                        <label class="control-label">Coupon Amount</label>
	                                        <input type="text" class="form-control" name="coupon_amount" placeholder="Enter Coupon Amount"/>
	                                    </div>
	                                    <div class="form-group col-md-3">
	                                        <label class="control-label">Coupon Type</label>
	                                        <select class="form-control" name="coupon_type">
	                                            <option value="0">$</option>
	                                            <option value="1">%</option>
	                                        </select>
	                                    </div>
	                                    <div class="form-group col-md-3">
	                                        <label class="control-label">Coupon Quantity</label>
	                                        <input type="text" class="form-control" name="coupon_quantity" placeholder="Enter Coupon Quantity" />
	                                    </div>
	                                    <div class="form-group col-md-3">
	                                        <label class="control-label">Cart Amount</label>
	                                        <input type="text" class="form-control" name="cart_amount" placeholder="Enter Min Cart Amount" />
	                                    </div>
	                                    <div class="form-group col-md-3">
	                                        <label class="control-label">Expiry Date</label>
	                                        <div class="input-group date" id="datetimepicker2">
	                                            <input type="text" class="form-control" name="coupon_expiry_date" placeholder="Enter Coupon Expiry Date">
	                                            <span class="input-group-addon">
	                                                <span class="fa fa-calendar"></span>
	                                            </span>
	                                        </div>
	                                    </div>
	                                    <?php //$product = $this->common->getData('products',array(),array('product_name','productid')); ?>
	                                    <!-- <div class="form-group col-md-3">
	                                        <label class="control-label">Product</label>
	                                        <select class="form-control select2" name="productid[]" multiple>
	                                        	<option value="">Select Product</option>
	                                        	<?php if(isset($product) && !empty($product)){ foreach($product as $key=>$value) : ?>
	                                        		<option value="<?php echo $value['productid']; ?>"><?php echo $value['product_name']; ?></option>
	                                        	<?php endforeach; } ?>
	                                        </select>
	                                    </div> -->
	                                    <!-- <div class="form-group col-md-3 mt-20">
	                                    	<input type="checkbox" name="send_newsletter" id="checkNewsletter" value="1" class="mt-10" />
	                                        <label class="control-label">Sent to subscriber</label>
	                                    </div> -->
	                                    <!-- <div class="form-group col-md-3 mt-20" id="newsletterContent" style="display:none;">
	                                        <label class="control-label">Content</label>
	                                    	<textarea class="form-control" name="content"></textarea>
	                                    </div> -->
	                                    <div class="form-group col-md-3 "><br>
	                                        <button type="submit" class="btn btn-success btn-anim">
	                                            <i class="icon-rocket"></i><span class="btn-text">Add Coupon</span>
	                                        </button>
	                                    </div>
	                                </div>
	                                <div class="row">
	                                </div>
	                            </form>

	                        </div>

	                    </div>

	                </div>  

	            </div>

	        </div>
	    <?php } ?>
		<!-- Row -->
		<?php if($this->admin_type=='superadmin' || (in_array('11', $this->authority))){ ?>
			<div class="row">

				<div class="col-sm-12">

					<div class="panel panel-default card-view">

						<div class="panel-heading">

							<div class="pull-left">

								<h6 class="panel-title txt-dark">Coupon List</h6>

							</div>

							<div class="pull-right">

								<a href="<?php echo base_url(A."/downloadCouponExcel"); ?>" class="btn btn-info">Export <i class="fa fa-file-pdf-o" style="color:#fff;"></i></a>

							</div>

							<div class="clearfix"></div>

						</div>

						<div class="panel-wrapper collapse in">

							<div class="panel-body">
								<div class="table-wrap">

									<div class="table-responsive">

										<table id="datable_1" class="table table-hover display  pb-30" >

											<thead>

								                <tr>

								                  <th>SR.No.</th>

	                                              <th>Coupon Code</th>

								                  <th>Coupon Type</th>

	                                              <th>Amount</th>

	                                              <th>Quantity</th>
	                                              <th>Product</th>

	                                              <th>Cart Amount</th>

	                                              <th>Coupon Date</th>

								                  <th>Expiry Date</th>

								                  <th>Action</th>

								                </tr>

								            </thead>



								            <tbody>

								                <?php if(!empty($coupon)){ foreach ($coupon as $key => $value): ?>

								                <tr id="<?php echo "coupon_".$value['id']; ?>">

								                  <td><?php echo $key+1; ?></td>

	                                              <td><?php echo $value['coupon_code']; ?></td>

	                                              <td><?php echo ($value['coupon_type']==0)?'$':'%'; ?></td>

	                                              <td><?php echo $value['coupon_amount']; ?></td>

								                  <td><?php echo $value['coupon_quantity']; ?></td>
								                  <td>
								                  	<?php $cp = explode(',', $value['productid']);
								                  		if($cp){ foreach ($cp as $key1 => $value1) {
								                  			$p = $this->common->getsData('products',array('productid'=>$value1),'product_name'); 
								                  			echo (isset($p['product_name']))?$p['product_name'].' | ':'';
								                  		} }
								                  	?>
								                  </td>

								                  <td><?php echo $value['cart_amount']; ?></td>

	                                              <td><?php echo $value['coupon_current_date']; ?></td>

								                  <td><?php echo $value['coupon_expiry_date']; ?></td>
								                  <td>
								                  	<?php if($this->admin_type=='superadmin' || (in_array('11.3', $this->authority))){ ?>
								                    	<a href="javascript:void(0)" class="text-inverse coupon_delete" data-table="coupon" data-id="<?php echo $value['id']; ?>">
								                    		<button class="btn btn-danger btn-icon-anim btn-square">
								                    			<i class="fa fa-trash fa-lg"></i>
								                    		</button>
								                    	</a>
								                    <?php } ?>
								                  </td>

								                </tr>

								                <?php endforeach; } ?>

								            </tbody>

										</table>

									</div>

								</div>
							</div>

						</div>

					</div>	

				</div>

			</div>
		<?php } ?>

		<!-- /Row -->

	</div>

<script type="text/javascript">

	var site_url = "<?php echo base_url(); ?>";

	var urlLink = "<?php echo A; ?>";


    $(".coupon_delete").on("click",function(){

	    var id = $(this).attr('data-id');

	    var table = $(this).attr('data-table');

	    var ok = confirm("Are you sure to Delete this Coupon?");

	    if (ok) {

	        $.ajax({

	            url: site_url+urlLink+'/deleteCoupon',

	            type:'POST',

	            data:'id='+id+'&table='+table,

	            success: function(data){

	                if(data==1)

	                {

	                    location.reload();

	                }

	            },

	        });

	    }

	});

    $('#checkNewsletter').on('click', function () {
    	var td = this.checked ? '1' : '0';
    	if(td==1){
    		$('#newsletterContent').css('display','block');
    	}else{
    		$('#newsletterContent').css('display','none');
    	}
    });

</script>
<style>
	.select2-container--default.select2-container--focus .select2-selection--multiple{height:auto;}
</style>