<?php
if(basename($_SERVER['PHP_SELF']) == 'assets.php') 
  $fn=" class='current'";
$custo=$conde=$condi='';
include'connection.php';
$dato=$datos=$Date;
$dati=$purc=$Date;
$p=$i=$pto=0;

include'header.php';

// Search for data by date
if(isset($_POST['search']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
				$p=1;
		}
		
	// Delete a given service record
if(isset($_POST['delo']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
			$code=$_POST['code'];
				$p=$_POST['p'];
				
	$delex=mysqli_query($conn, "DELETE FROM `assets` WHERE `Number`='$code' ORDER BY `Number` DESC LIMIT 1");	
		}
		
    // Add a new service
if(isset($_POST['addo']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
		$name=str_replace("'", "`", $_POST['name']);
		$num=str_replace("'", "`", $_POST['num']);
		$serio=str_replace("'", "`", $_POST['serio']);
		$sup=str_replace("'", "`", $_POST['sup']);
		        $dati=$_POST['dati'];
		        $purc=$_POST['purc'];
			    $classi=$_POST['classi'];
			    $p=$_POST['p'];
			    
			$loco=$_POST['loco'];
			$amo=str_replace(',', '', $_POST['amo']);
			$rate=str_replace(',', '', $_POST['rate']);
			
$sek=mysqli_query($conn, "SELECT `Asseno` FROM `assets` WHERE `Asseno`='$num'");
		if($fek=mysqli_num_rows($sek))
		    $pto=30;
		else{
	$then=mysqli_query($conn, "INSERT INTO `assets` (`Date`, `User`, `Asseno`, `Description`, `Serial`, `Location`, `Purchase`, `Supplier`, `Cost`, `Rate`, `Status`, `Type`) VALUES ('$dati', '$loge', '$num', '$name', '$serio', '$loco', '$purc', '$sup', '$amo', '$rate', '0', '$classi')");
	        $pto=40;
		    }
		}
		
		 // Update a given SUPPLIERer
if(isset($_POST['updo']))
		{
		$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
		$name=str_replace("'", "`", $_POST['name']);
		$num=str_replace("'", "`", $_POST['num']);
		$serio=str_replace("'", "`", $_POST['serio']);
		$sup=str_replace("'", "`", $_POST['sup']);
		        $dati=$_POST['dati'];
		        $purc=$_POST['purc'];
			    $classi=$_POST['classi'];
			    $p=$_POST['p'];
			    
			$loco=$_POST['loco'];
			$code=$_POST['code'];
			$amo=str_replace(',', '', $_POST['amo']);
			$rate=str_replace(',', '', $_POST['rate']);
				
	$then=mysqli_query($conn, "UPDATE `assets` SET `Date`='$dati', `User`='$loge', `Asseno`='$num', `Description`='$name', `Serial`='$serio', `Location`='$loco', `Purchase`='$purc', `Supplier`='$sup', `Cost`='$amo', `Rate`='$rate', `Type`='$classi' WHERE `Number`='$code'");
		}

        if($dato==$datos)
			$mpri="ON $dato";
		else
			$mpri="FROM $dato TO $datos";
?>

<div class="container-fluid main-content">
        <div class="page-title hidden-xs hidden-print">
          <h2 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
         Finance
          </h2>
                 </div>
     
        <div class="row">
  <div class="col-lg-2 hidden-print">
   
   <ul class="list-group">  

    <li class="list-group-item">
	  <a href="salesrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Sales Report
                </p>
              </a></li> 

    <li class="list-group-item">
	  <a href="purchase.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Purchase Orders
                </p>
              </a></li>   

    <li class="list-group-item">
	  <a href="trans.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Service Providers
                </p>
              </a></li> 

    <li class="list-group-item">
	  <a href="experepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Payout/Expenses
                </p>
              </a></li>  

    <li class="list-group-item">
	  <a href="zreport.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Daily Z-Report
                </p>
              </a></li>   

    <li class="list-group-item">
	  <a href="taxrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;VAT/TAX Report
                </p>
              </a></li>   

    <li class="list-group-item active">
	  <a href="assets.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Assets Report
                </p>
              </a></li> 
                       
            </ul><br><br><br>
  </div>
  
  
  <?php
  include'asset.php';
?>
       
        <div class="col-lg-10">
                  <div class="row"><form action='' method='post'>
	<div class="col-lg-3 hidden-print" style="padding-left:50px; padding-right:50px;">

       <button class="btn btn-warning btn-block" type="button" data-toggle='modal' data-target='#Modaldis-0' stle="font-size:13px;">CREATE NEW ASSET</button>
		</div>
           <div class="col-lg-1" style="padding-left:40px;"></div>

        <form action="" method="post" class="form-horizontal ">                  
    <div class="col-lg-8 hidden-print" style="padding-right:50px;">
                           
     <div class="col-lg-4 hidden-print"> 
      <input class="form-control" name="custo" type="text" value="<?php echo $custo ?>" id="porter">
			</div>      
			
             <div class="col-lg-3"> 
           <div class="input-group date" data-provide="datepicker">
      <input class="form-control form-center" id="from" 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-3"> 
           <div class="input-group date" data-provide="datepicker">	
      <input class="form-control form-center" id="to" 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-2"><?php echo"<input type='hidden' name='pg' value='$pg'>"; ?>
                        <button class="btn  btn-primary btn-block" type="submit" name="search"><i class="lnr lnr-magnifier"></i> Search</button>
                   
					  </div>
                         </div></form>               
            </div>
               <?php
				
				if($pto==40)
echo"<center><div class='alert alert-success' style='width:90%; text-align:center; float:center; color: #ffffff; border-radius:5px; padding:2px; height:25px; background-color:green;'><i class='lnr lnr-checkmark-circle'></i> &nbsp;&nbsp; <button class='close' data-dismiss='alert' type='button'>&times;</button> Asset is registered successfull. </div></center>";

		
		    if($pto==30)
echo"<center><div class='alert alert-danger' style='width:90%; text-align:center; float:center; color: #ffffff; border-radius:5px; padding:2px; height:25px; background-color:red;'><i class='lnr lnr-checkmark-circle'></i> &nbsp;&nbsp; <button class='close' data-dismiss='alert' type='button'>&times;</button> Asset <b>$num</b> is not registered, it was already recorded. </div></center>";
		
        if($custo)
            $condi="AND (`Description` LIKE '%$custo%' OR `Supplier` LIKE '%$custo%' OR `Asseno` LIKE '%$custo%' OR `Serial` LIKE '%$custo%')";
        
				if($p)
	$dok=mysqli_query($conn, "SELECT *FROM `assets` WHERE `Status`='0' AND `Purchase` BETWEEN '$dato' AND '$datos' $conde ORDER BY `Date` ASC");
				else
		$dok=mysqli_query($conn, "SELECT *FROM `assets` WHERE `Status`='0' ORDER BY `Number` DESC LIMIT 20");
				if($fo=mysqli_num_rows($dok)){
		?>
                 
            <div class="divFooter"><center><u><b>ASSET 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;
			 <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">

		<table class="table table-striped table-hover">     
                                      <thead>
                    <tr role="row">
                <th width="1%" style='padding:1px; text-align:center'> No </th>
		<th style='padding:1px;' width='7%'><div align='center'> DATE </th>
	   <th style='padding:1px;'><div align='center'> USER </th>
			    <th style='padding:1px;'><div align='center'> NUMBER </th>
			    <th style='padding:1px;'><div align='center'> NAME </th>
				<th style='padding:1px;'><div align='center'> SERIAL </th>
				<th style='padding:1px;'><div align='center'> LOCATION </th>
		<th style='padding:1px;'><div align='center'> PURCHASE </th>
				<th style='padding:1px;'><div align='center'> KEPPER`S&nbsp;Name </th>
				<th style='padding:1px;'><div align='center'> COST </th>
				<th colspan='2' style='padding:1px;'><div align='center'> RATE </th>
				<th colspan='2' class="hidden-print" 
	style='padding:1px; width:20px;'><div align='center'> # </th>
                     </tr>
                    </thead>
                                        <tbody>
					<?php
				$i++;			$tot=$tpa=$tba=0;
		while($rok=mysqli_fetch_assoc($dok)){
				$code=$rok['Number'];
				$dati=$rok['Date'];
				$sup=$rok['Supplier'];
		    	$num=$rok['Asseno'];
		    	$name=$rok['Description'];
	$amo=$rok['Cost'];			$amoo=number_format($amo, 2);
	$rate=$rok['Rate'];             $rateo=number_format($rate, 2);
	
			$loco=$rok['Location'];
			$serio=$rok['Serial'];
			$purc=$rok['Purchase'];
			$user=$rok['User'];
			$type=$rok['Type'];
			
	$sek=mysqli_query($conn, "SELECT `Asseno` FROM `assets` WHERE `Asseno`='$num' AND `Number`!='$code'");
		if($fek=mysqli_num_rows($sek))
			$stl="padding:1px; font-size:12px; color:red;";
		else
			$stl="padding:1px; font-size:12px;";

	print("<tr><td style='$stl $clr'><div align='right'>&nbsp;$i&nbsp;</td>
	<td style='$stl $clr'><div align='center'> $dati </td>
	<td style='$stl $clr'> $user </td><td style='$stl $clr'> $num </td>
	<td style='$stl $clr'> $name </td><td style='$stl $clr'> $serio </td>
	<td style='$stl $clr'> $loco </td>
	<td style='$stl $clr'><div align='center'> $purc </a></td>
	<td style='$stl $clr'> $sup </td><td style='$stl $clr' class='text-right'> $amoo </td><td style='$stl $clr' class='text-right'> $rateo% </td>
	<td style='$stl $clr'>");

    if($_SESSION['Cfr']){
	    $dbutn='submit';
	    $disa='';
	}
	else{
	   // $dbutn='button';
	   // $disa='disabled';
	    $dbutn='submit';
	    $disa='';
	}

                            include'asset.php';              
	echo"<div class='modal fade' id='modal-$i' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true' 
		style='top:120px;'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content text-left'>
      <div class='modal-header'>
        <h5 class='modal-title' id='exampleModalLabel'>DELETE CONFIRMATION 
		<label class='text-right pull-right'> $name &nbsp;&nbsp;&nbsp;&nbsp; $amoo$curre</label></h5>

      </div>
      <div class='modal-body' style='height:60px;'>
        <h5 style='color:#ff0033'>Are you sure you want to delete this record?</h5>
      </div><form method='post' action=''><input type='hidden' name='code' value='$code'>
      <input type='hidden' name='datos' value='$datos'><input type='hidden' name='p' value='$p'>
	  <input type='hidden' name='dato' value='$dato'><input type='hidden' name='custo' value='$custo'>
      <div class='modal-header' style='height:50px; padding:10px; border:0px solid blue; text-align:right'>
        <button type='button' class='btn btn-sm btn-success' data-dismiss='modal'>&nbsp;NO&nbsp;</button>
        <button type='$dbutn' name='delo' class='btn btn-sm btn-danger' $disa data-toggle='tooltip' data-placement='top'>YES</button>
      </div></form>
    </div>
  </div>
</div>";

	print("</td><td class='hidden-print' style='padding:0px; width:20px;'><div title='Edit a Supplier' data-toggle='tooltip' data-placement='top' 
	align='right'><button type='submit' class='btn btn-xs btn-warning hidden-print' style='height:18px; width:25px; padding:0px; margin:0px; margin-right:2px;' 
	data-toggle='modal' data-target='#Modaldis-$i'> &nbsp;<i class='lnr lnr-pencil'></i>&nbsp; </button></td>
	
	<td class='hidden-print' style='padding:0px; width:20px;'><div title='Delete a SUPPLIERer' data-toggle='tooltip' data-placement='top'>
	<div align='right'><button type='button' class='btn btn-xs btn-danger hidden-print' style='height:18px; width:25px; padding:0px; margin:0px; margin-right:2px;' 
	data-toggle='modal' data-target='#modal-$i'> &nbsp;<i class='lnr lnr-briefcase'></i>&nbsp; </button></td></tr>");
		$i++;				$tot+=$amo;            
						}
			$tot=number_format($tot, 2);
						?>
						
                    </tbody>
					 <thead>
					<tr><th> </th><th colspan='4'>
					    <div align='center'> Total Amount </th>
					<th colspan='2' style="padding-right:1px;"><div align='right'> </th>
					<th style="padding-right:1px; padding-left:1px;"> </th>
					<th style="padding-right:1px;"><div align='right'> </th>
					<th style="padding-right:1px;"><div align='right'><?php echo $tot ?></th></th>
					<th> </th><th colspan="2" class='hidden-print'>
					    <div align='center'> -- </th></tr>
                  </table>

								</div></div>
								<span class="pull-right hidden-print">
			 <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><br><br><br>  

			<?php
				}
				else{
						echo"<div class='row'>
            <div class='col-lg-12' style='margin-top:-20px;'>
             <span> &nbsp;&nbsp; Total Records Found : <b> 0 </b></span>
            <div class='widget-container fluid-height clearfix'>
            <div class='widget-content padded clearfix'>
			<br><br><br><br><br><br>
	<div style='text-align:center; font-size:24px; color:#ff9999'>Report not available on selected date </div><br><br><br><br><br><br>";
					}
			
					?>
                                      
                
              </div>
            </div></div>
                  </div>
   <?php
   include'footer.php';
   ?>