<input type="hidden" id="baseurl" value="<?php echo base_url(); ?>" >
<div class="row">
    <div class="col-md-12">
        <div class="hs_heading medium">
            <h3>Offers (<?php if(!empty($all_offers)){ echo count($all_offers); }else{ echo 0; } ?>) <a href="#add_offer" class="btn" data-toggle="modal">Add new</a></h3>
        </div>
        <div class="hs_datatable_wrapper">
            <table class="hs_datatable table table-bordered">
                <thead>
                    <tr>
                        <th>#</th> 
                        <th>Offer Heading</th>
						<th>Offer Description</th>
						<th>Offer Create Date</th>
						<th>Offer Expire Date</th>
						<th>Offer Image</th>
						<th>Coupen Code</th>
						<th>Coupen Uses Limit</th>
						<th>Disscount Type </th>
						<th>Status</th>
						<th>Action</th>
						<th>Disscount Amount </th>
						<th>Apply discount To</th>
						<th>Discounted Product</th>
                    </tr>
                </thead>
                <tbody>
				<?php 
				  $i= 0;
				  if(!empty($all_offers)){
				foreach($all_offers  as $offer){ ?>
					<tr>
						<td><?php echo ++$i; ?></td>
						<td><?php echo $offer->offer_heading; ?></td>
						<td><?php echo $offer->offer_description; ?></td>
						<td><?php echo $offer->create_at; ?></td>
						<td><?php $date = $offer->coupen_expire_date;;
								  echo date('d M Y', strtotime($date));
									//echo $offer->coupen_expire_date; ?></td>
						<td>
							<div class="product_simg">
								 <img src="<?php echo base_url().$offer->offer_image; ?>" alt="icon">
							</div> 
						</td>
						
						<td><?php echo $offer->coupen_code; ?></td>
						<td><?php echo $offer->coupen_uses_limt; ?></td>
						<td><?php if($offer->discount_type == 1){
									  echo 'Percentage';
								  }else{
									  echo 'Flat';
								  } 
						?></td>
						<td>
							<label class="switch">
								<input id="offerstatus_<?php echo $offer->offer_id; ?>" onclick="update_offer_status(<?php echo $offer->offer_id; ?>);"   type="checkbox" value="" <?php if($offer->offer_status == 1){ echo "checked"; } ?> >
								<span class="slider"></span>
							</label>
						</td>
						<td width="200">
							<a  class="btn" title="Edit" data-name="Business Statistics" onclick="edit_offers(<?php echo $offer->offer_id; ?>)"><i class="fa fa-pencil" aria-hidden="true"></i></a>
							 <a  href="<?php echo base_url().'admin/delete_offer/'.$offer->offer_id; ?>" class="btn" title="Delete" onclick="return delete_confirmation()"><i class="fa fa-trash" aria-hidden="true"></i></a>
						</td>
						<td><?php echo $offer->discount_amount; ?></td>
						<td><?php echo $offer->apply_discount_to; ?></td>
						<td>
						<?php
						if($offer->discounted_product !=0){
							if(!empty($all_products)){
								foreach($all_products as $prod){
									  if($offer->discounted_product == $prod[prod_id]){
											echo  $prod['prod_name'];
									  }  
								  }
							}else{
								echo 'None';
							}
						}else{ 
							echo 'None';

						} ?></td>
					</tr>
			    <?php
				 }
				} 
				?>	
				</tbody>
            </table>
        </div>
    </div>
</div>

<br>
<br>
<br>
<br>


<!-- add offer popup start -->
<div class="modal_box">
<div id="add_offer" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title"><span>Add</span> Offer</h4>
            </div>
            <div class="modal-body">
			<input type="hidden" id="baseurl" value="<?php echo base_url(); ?>" >
			<form method="post" enctype="multipart/form-data" id="add_offer_form">
                <div class="hs_input">
                    <label>Offer Heading</label>
                    <input type="text" class="form-control add_cate_form" name="offer_heading" id="offer_heading" value="">
                </div>
				<div class="hs_input">
                    <label>Offer Description</label>
                    <textarea rows="4" class="form-control" name="offer_descr" id="offer_descr"></textarea>
                </div>
				<div class="hs_input">
                    <label>Offer Image</label>
                    <input type="file" class="form-control add_cate_form" name="offer_image" id="offer_image" value="">
                </div>
				
				<div class="hs_input">
                    <label>Coupen Code</label>
                    <input type="text" class="form-control add_cate_form" name="coupen_code" id="coupen_code" value="">
                </div>
				<div class="hs_input">
                    <label>Coupen Uses Limit</label>
                    <input type="Number" class="form-control add_cate_form" name="coupen_uses_limit" id="coupen_uses_limit" value="" min="1">
                </div>
				<div class="hs_input">
					<label>Discount Type</label>
						<select class="form-control" id="discount_type" name="discount_type">
						<option value="0">Select Type</option>
						<option value="1">Percentage</option>	 
						<option value="2">Flat</option>
						</select>
				</div>
				<div class="hs_input">
                    <label>Discount Amount</label>
                    <input type="text" class="form-control add_cate_form" name="discount_amount" id="discount_amount" value="">
                </div>
				<div class="hs_input">
					<label>Apply Discount To </label>
						<select class="form-control" id="apply_discount_to" name="apply_discount_to">
						<option value="Total_amount">Total Amount</option>	 
						<option value="single_product">Product</option>
						</select> 
				</div>
				<div class="hs_input">
					<label>Dicounted Product</label>
						<select class="form-control" id="discounted_product" name="discounted_product" disabled>
						<option value="0">Select Product</option>
							<?php if(!empty($all_products)){
								  foreach($all_products as $prod){
									echo '<option value="'.$prod['prod_id'].'">'.$prod['prod_name'].'</option>';
								  }
								} ?> 
						</select>
				</div>
				<div class="hs_input">
                    <label>Coupen Expire Date</label>
                    <input type="Date" class="form-control add_cate_form" name="coupen_expire_date" id="coupen_expire_date" value="">
                </div>
				<div class="hs_input">
				  <button type="submit" id="add"  class="btn">Add</button>
                </div>
            </div>
			</form>
        </div>
    </div>
</div>
</div>
<!-- add offer popup end -->
	
<!-- update offer popup start -->
<div class="modal_box">
<div id="update_offer" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title"><span>Update</span> Offer</h4>
            </div>
            <div class="modal-body">
			<input type="hidden" id="baseurl" value="<?php echo base_url(); ?>" >
			<form method="post" enctype="multipart/form-data" id="update_offer_form">
                <div class="hs_input">
                    <label>Offer Heading</label>
                    <input type="text" class="form-control add_cate_form" name="up_offer_heading" id="up_offer_heading" value="">
                </div>
				<div class="hs_input">
                    <label>Offer Description</label>
                    <textarea rows="4" class="form-control" name="up_offer_descr" id="up_offer_descr"></textarea>
                </div>
				<div class="hs_input">
                    <label>Offer Image</label>
                    <input type="file" class="form-control add_cate_form" name="up_offer_image" id="up_offer_image" value="">
                </div>
				<div class="hs_input">
                    <label>Coupen Code</label>
                    <input type="text" class="form-control add_cate_form" name="up_coupen_code" id="up_coupen_code" value="">
                </div>
				<div class="hs_input">
                    <label>Coupen Uses Limit</label>
                    <input type="Number" class="form-control add_cate_form" name="up_coupen_uses_limit" id="up_coupen_uses_limit" value="" min="1">
                </div>
				<div class="hs_input">
					<label>Discount Type</label>
						<select class="form-control" id="up_discount_type" name="up_discount_type">
						<option value="0">Select Type</option>
						<option value="1">Percentage</option>	 
						<option value="2">Flat</option>
						</select>
				</div>
				<div class="hs_input">
                    <label>Discount Amount</label>
                    <input type="text" class="form-control add_cate_form" name="up_discount_amount" id="up_discount_amount" value="">
                </div>
				<div class="hs_input">
					<label>Apply Discount To </label>
						<select class="form-control" id="up_apply_discount_to" name="up_apply_discount_to">
						<option value="Total_amount">Total Amount</option>	 
						<option value="single_product">Product</option>
						</select> 
				</div>
				<div class="hs_input">
					<label>Dicounted Product</label>
						<select class="form-control" id="up_discounted_product" name="up_discounted_product" disabled>
						<option value="0">Select Product</option>
							<?php if(!empty($all_products)){
								  foreach($all_products as $prod){
									echo '<option value="'.$prod['prod_id'].'">'.$prod['prod_name'].'</option>';
								  }
								} ?> 
						</select>
				</div>
				<div class="hs_input">
                    <label>Coupen Expire Date</label>
                    <input type="Date" class="form-control add_cate_form" name="up_coupen_expire_date" id="up_coupen_expire_date" value="">
                </div>
				 
            </div>
			<div class="hs_input">
				<input type="hidden" value="" name="old_offer_id" id="old_offer_id">
				<button type="submit" id="add"  class="btn">Update</button>
			</div>
            </div>
			</form>
        </div>
    </div>
</div>
</div>
<!-- update offer popup end -->	
 <!-- page body end -->
	
	
	