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

// search for an item to be added to the chart
if(isset($_POST['search']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
			$p=1;
		}
		
		if($custo)
		    $conde="AND `Type`='$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 active">
              <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">
              <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 hidden-print" style="padding-left:50px;">
        
        
        
        
        
        </div><div class="col-lg-3">
			<select class="form-control" name="custo">
				<option value='' selected='selected'>Select Type</option>
			 <?php
			$dois=mysqli_query($conn, "SELECT `Type` FROM `expetype` WHERE `Type`!=''  GROUP BY `Type` ORDER BY `Type` ASC");
			while($rois=mysqli_fetch_assoc($dois)){
				$caso=$rois['Type'];
				if($caso==$custo)
					$sli="selected='selected'";
				else
					$sli='';
			echo"<option value='$caso' $sli> $caso </option>";
			}
			?>    
                            </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>
             <?php
$do=mysqli_query($conn, "SELECT *FROM `expetype` WHERE `Status`='0' AND `Type`!='' $conde GROUP BY `Type` ORDER BY `Type` ASC");
        $fo=mysqli_num_rows($do);
					?>
					<div class="divFooter"><center><u><b>EXPENSES REPORT <?php echo"$mpri"; ?></b></u></center></div>
		 <div class="row">
            <div class="col-lg-12">
             <span> &nbsp;&nbsp; Total Records Found : <b><?php echo" $fo " ?></b></span>
			 <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 class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix"><ul class="list-group" style="border:1px solid #ffffff; background-color:transparent; padding:0px;">

					<?php
	    $i=1;				$tot=$t=$k=0;
	while($ro=mysqli_fetch_assoc($do)){
	    $type=$ro['Type'];
	    
	    $doi=mysqli_query($conn, "SELECT `expenses`.`Expense`, SUM(`expenses`.`Amount`) AS 'Amo', SUM(`expenses`.`Holdings`) AS 'Hold' FROM `expenses` INNER JOIN `expetype` ON  `expenses`.`Expense` = `expetype`.`Expense` WHERE  `expenses`.`Status`='0' AND  `expenses`.`Date` BETWEEN '$dato' AND '$datos' AND `expetype`.`Type`='$type' GROUP BY  `expenses`.`Expense` ORDER BY  `expenses`.`Expense` ASC");
	   
	   if($foi=mysqli_num_rows($doi)){
echo"<li class='list-group-item active' style='width:100%; text-align:left; padding-left:40px; font-size:18px; margin-bottom:10px; border-radius:5px;'> $type </li>";
	    $sub=0;             $k++;
	            while($roi=mysqli_fetch_assoc($doi)){
	                $amo=$roi['Amo']+$roi['Hold'];
	                $expe=$roi['Expense'];
	                $amoo=number_format($amo);
	       echo"<li class='list' style='margin:0px 0px 0px 50px; padding:0px; height:10px;'> $expe : $amoo </li><br>";
	                    $tot+=$amo;
	                    $sub+=$amo;
	                    $t++;
	            }
	            echo"<span class='badge pull-right' style='margin:-25px 20px 0px 0px; font-size:14px; background-color:powderblue;'>".number_format($sub)."</span>";
						}
	}
if(!$t)
echo"<label class='text-danger' style='text-align:center; font-size:18px; padding-top:120px; float:center; padding-bottom:120px; width:100%;'> Report not available on selected date </label>";





              if($tot AND $k)
	echo"<br><br><li class='list-group-item active' style='width:100%; text-align:left; padding-left:40px; font-size:18px; margin-bottom:-1px; color:#000000; font-weight:bold; padding-top:5px; border-radius:5px;'> Total Amount <span class='badge pull-right' style='margin:2px 20px 0px 0px; font-size:16px; background-color:transparent; font-weight:bold; color:#000000;'>".number_format($tot)."</span></li>";
		?>
                  
                  
                                      
                
              </ul></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';
   ?>