<?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-12">
            <h3><?php echo $pgheading;?></h3>
          </div>
         
        </div>
        
        <div class="container_fluid mt-2 px-3">
		<form name="frmsearch" method="get" action="<?php echo $page_url;?>/">
         <table class="webforms sttbl bg-light my-0 table-responsive-sm">
          <tr>
           <td class="pr-0" width="20%"><input type="text" name="search" size="20" value="<?php echo $this->input->get("search");?>" placeholder="search "></td>
<td class="pr-0" width="20%">
		<select name="warehouseid" id="warehouseid" >
		  <option value="">All Warehouese</option>
						<?php
						if(is_array($warehouselist) && count(array_filter($warehouselist))>0)
						{

							foreach($warehouselist as $warehouserow)
							{
								$sel_warehouse="";
								if(decodeValue($this->input->get("warehouseid"))==$warehouserow->fld_id)
								{
									$sel_warehouse = 'selected="selected"';
								}				
									?>
											<option value="<?php echo encodeValue($warehouserow->fld_id);?>" <?php echo $sel_warehouse;?>><?php echo $warehouserow->fld_name;?></option>
									<?php
								
							}
						}
						?> 
		  </select>
		  </td>			
		<td class="pr-0" width="20%">
		<select name="outletid" id="outletid" >
		  <option value="">Select Outlet</option>
						<?php
						if(is_array($outletlist) && count(array_filter($outletlist))>0)
						{

							foreach($outletlist as $outletrow)
							{
								$sel_outlet="";
								if(decodeValue($this->input->get("outletid"))==$outletrow->fld_id)
								{
									$sel_outlet = 'selected="selected"';
								}				
									?>
											<option value="<?php echo encodeValue($outletrow->fld_id);?>" <?php echo $sel_outlet;?>><?php echo $outletrow->fld_name;?></option>
									<?php
								
							}
						}
						?> 
		  </select>
		  </td>	

           <td class="pr-0" width="20%"><input type="text" name="fromdate" id="fromdate" value="<?php echo $fromdate;?>"   placeholder="From Date" class="datepicker" /></td>
           <td class="pr-0" width="20%"><input type="text" name="todate" id="todate"  value="<?php echo $todate;?>" placeholder="To Date" class="datepicker"/></td>		  
           <td>
           	<button class="btn btn-dark pt-0 pb-1 px-2">Go</button>
           </td>
          </tr>
         </table>
       </form>
         <?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
			}
         ?>
         
         <table class="table mt-2 table-responsive-sm">
	
                <thead>
                	<tr>
                    	<th width="5%">SRNo.</th>                    	                 	
                    	<th width="10%">Challan NO.</th>
                    	<th width="10%">Challan Date</th>                 	
                    	<th width="15%">Warehouse</th>                	
                    	<th width="15%">Outlet</th>
                    	<th width="20%" class="text-left">Product</th>
                    	<th width="10%" class="text-right">QTY</th>


                    	
                    </tr>
                    </thead>
                    <tbody>
					<?php
					$totalqty = 0;
					$totalprice = 0;
					$totalproductamount = 0;
					if(is_array($results) && count(array_filter($results))>0)
					{
						$rowindex = 0;
						foreach($results as $row)
						{
							$rowindex++;
							$productamount =($row->qty*$row->fld_price)


					?>
                    <tr>
						<td class="text-center"><?php echo $rowindex;?>.</td>
						<td><?php echo $row->fld_refno;?></td>
						<td><?php if($row->fld_refdate!="") { echo date("d-M-Y", strtotime($row->fld_refdate)); }?></td>
						<td><?php echo $row->warehousename;?></td>					
						<td align="left"><?php echo $row->outletname;?></td>
						<td align="left"><?php echo $row->productname;?></td>
						<td align="right"><?php echo round($row->qty);?></td>

						
                    </tr>
                    <?php
						$totalqty += $row->qty;
				
						}
					?>
                    <tr>
						          
						<th colspan="6" class="text-right">Total:</th>
						<th class="text-right"><?php echo round($totalqty,2);?></th>
						
                    </tr>
					<?php							
					}
					else
					{
                    ?>
                    <tr><td colspan="7" style="text-align:center">Record not found!</td></tr>
                    <?php
					}
                    ?>
                    
                    
                    </tbody>
                </table>
                 
	         <div class="clearfix"></div>
          
        </div>
        <div id="paginate" class="row">
			<?php echo $this->ajax_pagination->create_links(); ?>
        </div>
            
        </div>
<?php
if($this->input->get("outletid")!="")
{
	$outletid  = $this->input->get("outletid");
	$billerval  = $this->input->get("billerid");
?>
<script>

	getoutletbiller('<?php echo base_url();?>','<?php echo $outletid;?>','<?php echo $billerval;?>');

</script>
<?php
}
?>