<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$addpmtr = "";
if($this->input->get("outletid"))
{
	$addpmtr = "?search=".$this->input->get("search")."&outletid=".$this->input->get("outletid")."&fromdate=".$fromdate."&todate=".$todate;
}



?>
      <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-6 text-right">
		<?php
			if($this->input->get("fromdate")!="" && $this->input->get("todate")!="")
			{
		?>
            <a href="account/report/<?php echo $tasktype;?>?exporttype=pdf&<?php echo $_SERVER['QUERY_STRING'];?>" class="btn btn-info">Export PDF</a>
        <?php
			}
        ?>
          </div>
        </div>
        
        <div class="container_fluid mt-2 px-3">
		<form name="frmsearch" method="get" action="<?php echo base_url().'account/report/'.$tasktype;?>" autocomplete="off">
         <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="outletid" id="outletid" >
		  <option value="">All Outlet</option>
						<?php
						if(is_array($outletlist) && count(array_filter($outletlist))>0)
						{

							foreach($outletlist as $billerrow)
							{
								$sel_biller="";
								if(decodeValue($this->input->get("outletid"))==$billerrow->fld_id)
								{
									$sel_biller= 'selected="selected"';
								}				
									?>
											<option value="<?php echo encodeValue($billerrow->fld_id);?>" <?php echo $sel_biller;?>><?php echo $billerrow->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%">Outlet Name</th>
                    	<th width="10%"class="text-center">Number of Invoices</th>
                    	<th width="10%" class="text-right">Amount</th>
                    	
                    </tr>
                    </thead>
                    <tbody>
					<?php
					$totalamount = 0;
					
					if(is_array($results) && count(array_filter($results))>0)
					{
						$rowindex = 0;
						foreach($results as $row)
						{
							$rowindex++;
							
//if($addpmtr=="")
//{
	$addpmtr = "?search=".$this->input->get("search")."&outletid=".encodeValue($row->fld_outletid)."&fromdate=".$fromdate."&todate=".$todate;
//}				

					?>
                    <tr>
						<td ><?php echo $rowindex;?>.</td>                    	       
						        
						<td ><a href="account/report/billersale/<?php echo $addpmtr;?>"><?php echo $row->outletname;?></a></td>            
						<td class="text-center"><a href="account/report/invoices/<?php echo $addpmtr;?>"><?php echo $row->totalinvocies;?></a></td>            
						<td class="text-right"><?php echo $row->totalamt;?></td>            
					
                    </tr>
                    <?php
						$totalamount += $row->totalamt;
						
						}
					?>
                    <tr>
						          
						<th colspan="3" class="text-right ">&nbsp;</th>					
						<th class="text-right">Total: <h5 class="btn btn-primary"><?php echo number_format($totalamount,2);?></h5></th>
						
                    </tr>
					<?php							
					}
					else
					{
                    ?>
                    <tr><td colspan="4" 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>
