<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>

      <div class="main my-0">
        <div class="row mt-3 mx-0">
          <div class="col-md-6">
            <h3><?php echo $pgheading;?></h3>
          </div>
          <div class="col-md-5 text-right">
            &nbsp;
          </div>
        </div>

         <?php
			if($this->session->flashdata("message")!="" && $this->session->flashdata("alerttype")!="")
			{
         ?>
         <div class="text-center my-4">
			 <span class="alert <?php echo $this->session->flashdata("alerttype");?>"><?php echo $this->session->flashdata("message");?></span>
         </div>
         <?php
			}
         ?>
        
        <div class="container_fluid mt-2 px-3">
		<form name="frmgeneral" method="post" action="account/<?php echo $mgmtname;?>/exportcsv" enctype="multipart/form-data" onsubmit="return checkform();">
        <table class="webforms mt-0 table-responsive-sm">
		<tr>
          <td width="20%"><label>Select Warehouse(s):</label></td>
          <td width="80%">
		  <?php
			if(is_array($warehouselist))
			{
				?>
				<div class="row">
					<div class="col-md-12 mb-3"><label class="container-checkbox horzbox">
					<input type="checkbox" name="checkallwh" class="checkallwh" id="checkallwh" value="all">Check ALL Warehouses
					<span class="checkmark leftchkbx"></span>
					</label>
					</div>
					
				<?php
				foreach($warehouselist as $row)
				{		
					$tpindex++;
					?>
					<div class="col-md-4"><label class="container-checkbox horzbox checkboxwh">
					<input type="checkbox" name="warehouseids[]" class="checkboxwh" id="warehouseids<?php echo $tpindex;?>" value="<?php echo $row->fld_id ;?>"><?php echo $row->fld_name ;?>
					<span class="checkmark leftchkbx"></span>
					</label>
					</div>
					<?php
				}
				?>
				</div>
				<?php
			}		  
			?>
		  </td>
         </tr>
		<tr>
          <td width="20%"><label>Select Outlet(s):</label></td>
          <td width="80%">
		  <?php
			if(is_array($outletlist))
			{
				?>
				<div class="row">
					<div class="col-md-12 mb-3"><label class="container-checkbox horzbox">
					<input type="checkbox" name="checkallol" class="checkallol" id="checkallol" value="all">Check ALL Warehouses
					<span class="checkmark leftchkbx"></span>
					</label>
					</div>					
				<?php
				foreach($outletlist as $row)
				{		
					$tpindex++;
					?>
					<div class="col-md-4"><label class="container-checkbox horzbox">
					<input type="checkbox" name="outletids[]" class="checkboxol" id="outletids<?php echo $tpindex;?>" value="<?php echo $row->fld_id ;?>"><?php echo $row->fld_name ;?>
					<span class="checkmark leftchkbx"></span>
					</label>
					</div>
					<?php
				}
				?>
				</div>
				<?php
			}		  
			?>
		  </td>
         </tr>
		 <tr>
             <td></td>
             <td><button class="btn btn-primary" id="submit">Export Data</button></td>
         </tr>
         </table>
         </form> 
	         <div class="clearfix"></div>          
        </div>
       </div>
<script>
 $(document).on('change', '.checkallwh', function () {
   if($(this).prop('checked')) {
      $('.checkboxwh').prop('checked', true)
   }else {
      $('.checkboxwh').prop('checked', false);
   }
})
 $(document).on('change', '.checkallol', function () {
   if($(this).prop('checked')) {
      $('.checkboxol').prop('checked', true)
   }else {
      $('.checkboxol').prop('checked', false);
   }
})

function checkform()
{	
	if($(":checkbox[name='warehouseids[]']").is(":checked"))
	{
		return true;
	}
	else if($(":checkbox[name='outletids[]']").is(":checked"))
	{
		return true;
	}
	else
	{
		alert("Please select at least single entry");
		return false;
	}
}
</script>
