<?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>
          <?php
          if($this->input->get("outletid")!="" && $this->input->get("fromdate")!="" && $this->input->get("todate")!="")
          {
          ?>
          <div class="col-md-12 text-right">
			<a href="<?php echo $config_base_url;?><?php echo "/?" . $_SERVER['QUERY_STRING'];?>&exporttype=csv" class="btn btn-info">Export CSV</a>
			<a href="<?php echo $config_base_url;?><?php echo "/?" . $_SERVER['QUERY_STRING'];?>&exporttype=pdf" class="btn btn-info">Export PDF</a>
          </div>
         <?php
			}
         ?>
          			
        </div>
        
        <div class="container_fluid mt-2 px-3">
		<form name="frmsearch" method="get" action="<?php echo $config_base_url;?>" 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" required>
			<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" class="datepicker" name="fromdate" id="fromdate" value="<?php echo $fromdate;?>"   placeholder="From Date"></td>
           <td class="pr-0" width="20%"><input type="text" class="datepicker" name="todate" id="todate"  value="<?php echo $todate;?>" placeholder="To Date"></td>
           <td>
           	<button class="btn btn-dark pt-0 pb-1 px-2" class="form-control">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="10%">Date</th> 
						<th width="20%">Bill No.</th>
						<th width="20%">Product</th>
                    	<th width="15%">Qty.</th>
                    	<th width="15%">MRP</th>
                    	<th width="15%">Sch. Rate</th>
                    	<th width="15%">Sch. Amount</th>
                    	<th width="15%">Time</th>
                    	<th width="15%">Customer Name</th>
                    	<th width="15%">Mobile</th>
                    	<th width="15%">Operator</th>
                    	<th width="15%">Remarks</th>
                    </tr>
                    </thead>
                    <tbody>
					<?php
					$totalamount = 0;
					//predata($results);
					if(is_array($results))
					{
						$rowindex = 0;
						foreach($results as $row)
						{
							$rowindex++;
							$subtotal = $row->fld_price * $row->fld_qty;
							


					?>
                    <tr>
						<td nowrap><?php echo date("d-m-Y", strtotime($row->fld_billdate));?></td>  
						<td><?php echo $row->fld_billno;?></td>
						<td><?php echo $row->product;?></td>
						<td><?php echo $row->fld_qty;?></td>						
						<td><?php echo $row->fld_mrp;?></td>              
						<td><?php echo $row->fld_price;?></td>              
						<td><?php echo $subtotal;?></td>              
						<td><?php echo date("d-m-Y H:i:s", strtotime($row->fld_datetime));?></td>              
						<td><?php echo $row->fld_name;?></td>           
						<td><?php echo $row->fld_mobile;?></td>           
						<td><?php echo $row->operatorname;?></td>           
						<td><?php echo $row->fld_remarks;?></td>           
                    </tr>
                    <?php
						$totalamount += $row->fld_netamount;
						
						}
					}
					else
					{
                    ?>
                    <tr><td colspan="12" style="text-align:center">Not data found, select another criteria!</td></tr>
                    <?php
					}
                    ?>
                    
                    
                    </tbody>
                </table>
                 
	         <div class="clearfix"></div>
          
        </div>
        <?php
			if(is_array($results))
			{
        ?>
        <div id="paginate" class="row">
			<?php echo $this->ajax_pagination->create_links(); ?>
        </div>
        <?php
			}
        ?>
            
        </div>

