<?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-9">
            <h3>Billing Report - Payment Type Wise</h3>
          </div>
          <div class="col-md-3 text-right">
		<?php
		if(is_array($results) && count(array_filter($results))>0)
		{
		?>
			<a href="account/<?php echo $mgmtname;?>/exportpaytype<?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="account/<?php echo $mgmtname;?>/paytype">
         <table class="webforms sttbl bg-light my-0 table-responsive-sm">
          <tr>
			<td class="pr-0" width="20%">
		<select name="outletid" id="outletid" style="width:300px;">
		  <option value="">Select Outlet</option>
						<?php
						if(is_array($outletlist) && count(array_filter($outletlist))>0)
						{

							foreach($outletlist as $outletrow)
							{
								$sel_outlet="";
								if($this->input->get("outletid")==$outletrow->fld_id)
								{
									$sel_outlet = 'selected="selected"';
								}				
									?>
											<option value="<?php echo $outletrow->fld_id;?>" <?php echo $sel_outlet;?>><?php echo $outletrow->fld_name;?></option>
									<?php
								
							}
						}
						?> 
		  </select>
		  </td> 
  
		  <td class="pr-0" width="10%"><input type="text" name="fromdate" id="fromdate" value="<?php echo $fromdate;?>"   placeholder="From Date" class="datepicker" style="width:100px;"/></td>
           <td class="pr-0" width="10%"><input type="text" name="todate" id="todate"  value="<?php echo $todate;?>" placeholder="To Date" class="datepicker" style="width:100px;"/></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%">Serial</th>
                    	<th width="25%">Outlet</th>
                    	<th width="20%">Operator</th>
		<?php
			$arrpaytypes = array();
			$arrpaytypestotal = array();
			foreach(getpaymenttypes() as $vkey=>$kvalue)
			{
				echo '<th width="10%" class="text-right">' . $kvalue . '</th>';
				$arrpaytypes[$vkey] = $vkey;
				$arrpaytypestotal[$vkey] = 0;
			}
		?>                    	
                    	<th width="10%" class="text-right">Amount</th>
                    </tr>
                    </thead>
                    <tbody>
					<?php
					$grandtotal = 0;
					if(is_array($results) && count(array_filter($results))>0)
					{
						$rowindex = 0;
						foreach($results as $userid=>$row)
						{
							$rowindex++;
							$rowtotal = 0;
							
					?>
					
                    <tr <?php if($hightlightcls!="") { echo $hightlightcls; } ?> >
                    	<td class="text-center"><?php echo $rowindex;?>.</td>                    	
						 <td><?php echo $row['outlet'];?></td>              
						 <td><?php echo $row['operator'];?></td>
						 <?php
						 foreach($arrpaytypes as $vkey=>$kvalue)
						 {
							 if($row["sale"][$vkey])
							 {
								 $rowtotal += $row["sale"][$vkey];
								$arrpaytypestotal[$vkey] += $row["sale"][$vkey];
							}
						 ?>
                    	<td class="text-right"><?php if($row["sale"][$vkey]) { echo number_format($row["sale"][$vkey]); }?></td>
                    	<?php
						}
                    	?>
                    	<td class="text-right"><?php if($rowtotal>0) { echo number_format($rowtotal); } ?></td>              
                    </tr>
                    <?php
							$grandtotal += $rowtotal;
						}
					?>
					<tr>
						<td colspan="3"><strong>Total:</strong></td>
						<?php
						foreach($arrpaytypestotal as $newkey=>$newvalue)
						{
						?>
						<td class="text-right"><strong><?php echo number_format($newvalue); ?></strong></td>
						<?php
						}
						?>
						<td class="text-right"><strong><?php echo number_format($grandtotal);?></strong></td>
					</tr>
					<?php
					}
					else
					{
                    ?>
                    <tr><td colspan="13" style="text-align:center">Record not found!</td></tr>
                    <?php
					}
                    ?>
                    
                    
                    </tbody>
                </table>
                 
	         <div class="clearfix"></div>
          
        </div>
            
        </div>

