<?php
if(basename($_SERVER['PHP_SELF']) == 'assetreport.php') 
  $cm=" class='current'";
include'header.php';
include'connection.php';
$custo=$conde='';
$dato=$datos=$Date;

// search for an item to be added to the chart
if(isset($_POST['search']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
		}
		
		if($custo)
		    $conde="AND `Location`='$custo'";
	
	    if($dato==$datos)
			$mpri="ON $dato";
		else
			$mpri="FROM $dato TO $datos";
                ?>
                
<div class="container-fluid main-content">
        <div class="page-title hidden-print">
          <h3 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
         Finance Report
          </h3>
  
    </div>
   <div class="row">
  <div class="col-lg-2 hidden-print">
   
  <ul class="list-group">
                  
			  <li class="list-group-item">
              <a href="paidreport.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Payment Report 1
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="paireport.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Payment Report 2
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="expenserepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Expenses Report 1
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="expereport.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Expenses Report 2
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="purcharepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Purchase Report
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="bankreport.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Bank Report
                </p>
              </a></li>
                  
			  <li class="list-group-item active">
              <a href="assetreport.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Asset Report
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="fsalerepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Finacial Statement
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="finrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Finacial Position
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="holdrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Withholding Report
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="cashrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Cashbox Report
                </p>
              </a></li>
              
              </ul>
  </div>
                    
           
           
    <form action="" method="post" class="form-horizontal "> 
        <div class="col-lg-10">
                  <div class="row">

				  <div class="col-lg-3"> </div>         

            <div class="col-lg-3 hidden-print" style="padding-left:50px;">
        <select class="form-control" name="custo">
				<option value='' selected='selected'>Select Location</option>
			 <?php
			            $loca=array();              $t=1;
			$dois=mysqli_query($conn, "SELECT `Location` FROM `assets` WHERE `Status`='0' AND `Location`!='' GROUP BY `Location` ORDER BY `Location` ASC");
			while($rois=mysqli_fetch_assoc($dois)){
				$caso=$rois['Location'];
				$loca[$t]=$caso;
				if($caso==$custo)
					$sli="selected='selected'";
				else
					$sli='';
			echo"<option value='$caso' $sli> $caso </option>";
			        $t++;
			}
			?>    
                            </select></div> 
							
                       <div class="col-lg-6 hidden-print">
                       
            <div class="col-lg-4"> 
           <div class="input-group date" data-provide="datepicker">
      <input class="form-control form-center" name="dato" type="text" value="<?php echo $dato ?>" onkeypress='return isNumberKey(event)' required>
	  <span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
			</div></div>


		  <div class="col-lg-4"> 
           <div class="input-group date" data-provide="datepicker">	
      <input class="form-control form-center" name="datos" type="text" value="<?php echo $datos ?>" onkeypress='return isNumberKey(event)' required>
	  <span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
              </div></div>                      
                       
                       <div class="col-lg-3">
                        <button class="btn  btn-primary btn-block" type="submit" name="search"><i class="lnr lnr-magnifier"></i> Search</button>
                   
					  </div>
                         </div> 
                      
                     
                  
            </form> 
             
               
            </div>
					<div class="divFooter"><center><u><b>ASSET REPORT ON <?php echo"$Date"; ?></b></u></center></div>
		 <div class="row">
            <div class="col-lg-12">
			 <span class="pull-right hidden-print">
			 &nbsp;&nbsp;<a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-printer"></i></a></span>
			 
			 <span class="pull-right hidden-print">
		&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" id="exporttable" class="hidden-print" title='Export to excell' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-line-spacing"></i></a></span>
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">

			 <table class="table table-striped table-hover" id="htmltable">     
                                      <thead>
                    <tr role="row">
    <th class="text-center" style='padding:1px; font-size:12px;'> No </th>
    <th class="text-center" style='padding:1px; font-size:12px;'> Location </th>
                     <?php
            $assety=$tta=$ttq=array();            $n=1;
    $doi=mysqli_query($conn, "SELECT `Asset` FROM `assetype` GROUP BY `Asset` ORDER BY `Number` ASC");
			while($roi=mysqli_fetch_assoc($doi)){
				$fna=$roi['Asset']; 
				$assety[$n]=$fna;
        echo"<th class='text-center' colspan='2' style='padding:1px; font-size:12px;'> $fna </th>";
                $n++;
			}
			?>
            <th class="text-center" colspan="2" style='padding:1px; font-size:12px;'> Total Asset </th>
						 </tr></thead><tbody>
						     
					<?php
	$stn="style='padding:1px; font-size:12px;'";
				
	    for($k=1; $k<$t; $k++){
	        $locat=$loca[$k];
	        $ta=$tq=0;
           
	 print("<tr><td $stn class='text-center'>$k</td><td $stn> $locat </td>");
	 
	        for($l=1; $l<$n; $l++){
	   $doc=mysqli_query($conn, "SELECT SUM(`Cost`) AS 'Amount', COUNT(DISTINCT(Asseno)) AS `Count` FROM `assets` WHERE `Location`='$locat' AND `Status`='0' AND `Type`='$assety[$l]'");
	   $roc=mysqli_fetch_assoc($doc);
	   $amo=$roc['Amount'];
	   $cou=$roc['Count'];
	$amoo=number_format($amo, 2);
	$couo=number_format($cou);
	$ta+=$amo;                      $tq+=$cou;
	$tta[$l]+=$amo;                 $ttq[$l]+=$cou;
	
	$stn="style='padding:1px; font-size:12px;'";
           
	 print("<td class='text-center' style='padding:1px; font-size:12px; color:blue;'> $couo&nbsp;</td><td class='text-right' $stn> $amoo&nbsp;</td>");
	        }				
		$ta=number_format($ta, 2);				
		$tq=number_format($tq);
	        print("<td class='text-center' style='padding:1px; font-size:12px; color:blue;'> $tq&nbsp;</td>
			<td class='text-right' $stn> $ta&nbsp;</td></tr>");
						}				
		$ta=number_format($ta, 2);				
		$tq=number_format($tq, 2);
		        ?>
                    </tbody><thead> 
<tr><th colspan='2' style='padding:1px; font-size:12px; text-align:center;'> TOTAL ASSET </th>
            <?php                   
                                            $ta=$tq=0;
            for($l=1; $l<$n; $l++){
                $sta=$tta[$l];                       $stq=$ttq[$l];	
	            $ta+=$sta;                           $tq+=$stq;			
		$sta=number_format($sta, 2);				
		$stq=number_format($stq);
	echo"<th style='padding:1px; font-size:12px; text-align:center; color:blue;'>$stq</th><th style='padding:1px; font-size:12px; text-align:right;'>$sta</th>";
            }				
		$ta=number_format($ta, 2);				
		$tq=number_format($tq);
            ?>
	<th class='text-center' style='padding:1px; font-size:12px; color:blue;'><?php echo $tq ?></th>
	<th class='text-right' style='padding:1px; font-size:12px;'><?php echo $ta ?></th></tr></thead></table>
                  
                                      
                
              </div>
            </div></div>
                  </div>                  
                <span class="pull-right hidden-print">
			 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-printer"></i></a></span>
      
   </div></div></div>  
   <?php
   include'footer.php';
   ?>