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

include'header.php';

// Search for data by date
if(isset($_POST['search']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
				$p=1;
		}
		
		// add new classification
if(isset($_POST['saven']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
			$p=$_POST['p'];
		
		    $classi=$_POST['classi'];
		    $categ=$_POST['categ'];
	$so=mysqli_query($conn, "INSERT INTO `expetype` (`Date`, `Type`, `Expense`, `Status`) VALUES ('$Date', '$categ', '$classi', '0')");
		}
		
	// Delete a given service record
if(isset($_POST['delo']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
			$code=$_POST['code'];
				$p=$_POST['p'];
		
		$defe=mysqli_query($conn, "SELECT `Files` FROM `payment` WHERE `Invoice`='$code' AND `Action`='SUPPLIER'");
		        while($refe=mysqli_fetch_assoc($defe)){
		            $file=$refe['Files'];
		            unlink("files/$file");
		            }			
	$deles=mysqli_query($conn, "DELETE FROM `payment` WHERE `Invoice`='$code' AND `Action`='SUPPLIER' ORDER BY `Number` DESC LIMIT 11");
				
	$delex=mysqli_query($conn, "DELETE FROM `services` WHERE `Number`='$code' ORDER BY `Number` DESC LIMIT 1");
		}
		
		// Delete a single payment record
if(isset($_POST['pdele']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
			$code=$_POST['code'];
			$num=$_POST['num'];
			$pri=$_POST['pri']*$_POST['rti'];
				$p=$_POST['p'];
				$file=$_POST['file'];
		      unlink("files/$file");
		            
	$deles=mysqli_query($conn, "DELETE FROM `payment` WHERE `Number`='$num' AND `Action`='SUPPLIER' ORDER BY `Number` DESC LIMIT 1");
						
	$deles=mysqli_query($conn, "DELETE FROM `deposit` WHERE `Item`='PAYMENT' AND `Voucher`='$code' AND `Operation`='WITHDRAWAL' AND `Refer`='x2' AND `Amount`='$pri' ORDER BY `Number` DESC LIMIT 1");
						
	$deles=mysqli_query($conn, "UPDATE `expenses` SET `Invoice`='', `Classfy`='' WHERE `Service`='$code' AND `External`='1' AND `Amount`='$pri' AND `Type`='PAYMENT' AND `Classfy`='EXPENSE' ORDER BY `Number` DESC LIMIT 1");
		}
		
		// Edit a single payment record
if(isset($_POST['pedit']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
			$code=$_POST['code'];
			$num=$_POST['num'];
			$pri=$_POST['pri']*$_POST['rti'];
			$p=$_POST['p'];
			$rat=str_replace(',', '', $_POST['rat']);
			$prs=str_replace(',', '', $_POST['prs']);
			$dte=$_POST['dte'];
	$doi=mysqli_query($conn, "UPDATE `payment` SET `Date` = '$dte', `Amount`='$prs', `Rate` = '$rat' WHERE `Number`='$num' ORDER BY `Number` DESC");
	            $depo=$prs*$rat;
						
	$deles=mysqli_query($conn, "UPDATE `deposit` SET `Amount`='$depo' WHERE `Item`='PAYMENT' AND `Voucher`='$code' AND `Operation`='WITHDRAWAL' AND `Refer`='x2' AND `Amount`='$pri' ORDER BY `Number` DESC LIMIT 1");
						
	$deles=mysqli_query($conn, "UPDATE `expenses` SET `Amount`='$depo' WHERE `Service`='$code' AND `External`='1' AND `Amount`='$pri' AND `Type`='PAYMENT' AND `Classfy`='EXPENSE' ORDER BY `Number` DESC LIMIT 1");
		}
		
		
		// Delete a payment from payout ****************
	if(isset($_POST['sdele']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
			$code=$_POST['code'];
			$num=$_POST['num'];
			$p=$_POST['p'];	
			$sso=mysqli_query($conn, "UPDATE `expenses` SET `Classfy`='', `Invoice`='', `Payto`='', `Expense`='', `Service`='0' WHERE `Number`='$num'");
		}
		
    // Add a new service
if(isset($_POST['addo']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
		$name=str_replace("'", "`", $_POST['name']);
		$invo=str_replace("'", "`", $_POST['invo']);
		$purpo=str_replace("'", "`", $_POST['purpo']);
		$dati=$_POST['dati'];
			$p=$_POST['p'];
			$curre=$_POST['curre'];
			$amo=str_replace(',', '', $_POST['amo']);
			$vat=str_replace(',', '', $_POST['vat']);
			$holding=str_replace(',', '', $_POST['holding']);
			
	$doi=mysqli_query($conn, "SELECT `Rate` FROM `currency` WHERE `Code`='$curre' ORDER BY `Number` DESC");
			$roi=mysqli_fetch_assoc($doi);
				$rate=$roi['Rate'];
				
	$then=mysqli_query($conn, "INSERT INTO `services` (`Date`, `User`, `Item`, `Supplier`, `Amount`, `Invoice`, `Purpose`, `Status`, `Currency`, `Rate`, `Vat`, `Holdings`) VALUES ('$dati', '$loge', 'PAYMENT', '$name', '$amo', '$invo', '$purpo', '0', '$curre', '$rate', '$vat', '$holding')");
		}
		
		 // Update a given SUPPLIER
if(isset($_POST['updo']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
		$name=str_replace("'", "`", $_POST['name']);
		$invo=str_replace("'", "`", $_POST['invo']);
		$purpo=str_replace("'", "`", $_POST['purpo']);
		$dati=$_POST['dati'];
			$p=$_POST['p'];
			$curre=$_POST['curre'];
			$amo=str_replace(',', '', $_POST['amo']);
			$code=$_POST['code'];
			$vat=str_replace(',', '', $_POST['vat']);
			$holding=str_replace(',', '', $_POST['holding']);
			
	$doi=mysqli_query($conn, "SELECT `Rate` FROM `currency` WHERE `Code`='$curre' ORDER BY `Number` DESC");
			$roi=mysqli_fetch_assoc($doi);
				$rate=$roi['Rate'];
				
	$then=mysqli_query($conn, "UPDATE `services` SET `User`='$loge', `Supplier`='$name', `Invoice`='$invo', `Purpose`='$purpo', `Amount`='$amo', `Currency`='$curre', `Rate`='$rate', `Vat`='$vat', `Holdings`='$holding' WHERE `Number`='$code'");
	
		}

    // Add a payment to supplier
if(isset($_POST['addpa']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
			$date=$_POST['dati'];
			$amo=$_POST['amo'];
			$amo=str_replace(',', '', $_POST['amo']);
			$pline=$_POST['pline'];
			$invo=$_POST['invo'];
			$currency=$_POST['currency'];
			$count=$_POST['count'];
			$naso=$_POST['naso'];
			$accu=$_POST['accu'];
			$dest=$_POST['dest'];
			$p=$_POST['p'];
			$last_id=0;
			$s=1;

		$doi=mysqli_query($conn, "SELECT `Rate` FROM `currency` WHERE `Code`='$currency' ORDER BY `Number` DESC");
			$roi=mysqli_fetch_assoc($doi);
				$rate=$roi['Rate'];

			$pieces = explode("-", $pline);
				$pline = $pieces[0]; // piece1
				$cheno=$bank='';
				$pdate=$_POST['dati'];

	$temp1 = explode(".", $_FILES["file1"]["name"]);
$newfilename1 = round(microtime(true)) . '.' . end($temp1);
move_uploaded_file($_FILES["file1"]["tmp_name"], "files/" . $newfilename1);
	if(!end($temp1))
	    $newfilename1='';
			
		if($pline=='CHEQUE'){
			$cheno=$_POST['cheno'];
			$bank=$_POST['bank'];
			$pdate=$_POST['pda'];
			$classe=$_POST['classec'];
		}
		if($pline=='TRANSFER'){
			$cheno=$_POST['slino'];
			$bank=$_POST['bacco'];
			$pdate=$_POST['tda'];
			$classe=$_POST['classet'];
		}
		
		if($pline=='CHEQUE' OR $pline=='TRANSFER'){
	$doi=mysqli_query($conn, "SELECT `Number`, `Rate` FROM `baccount` WHERE `Account`='$bank' ORDER BY `Number` ASC");
				$roi=mysqli_fetch_assoc($doi);
					$acco=$roi['Number'];
					$dra=$roi['Rate'];
                        $ope="WITHDRAWAL";
                            $bra=0;
                        $source=$pline;
                $purpo="Service Provider Payment";
                        $depo=$amo;
					
$and=mysqli_query($conn, "INSERT INTO `deposit` (`Number`, `Date`, `Time`, `User`, `Item`, `Refer`, `Amount`, `Customer`, `Operation`, `Status`, `Valid`, `Account`, `Descri`, `Client`, `Voucher`, `Source`, `Record`, `Branche`, `Bank`, `Rate`) VALUES (NULL, '$pdate', '$Time', '$loge', 'PAYMENT', 'x2', '$depo', '$dest', '$ope', '0', '0', '$acco', '$purpo', '0', '$naso', '$source', '0', '$bra', '$bank', '$dra')");
    $last_id = mysqli_insert_id($conn);

    if($classe)
$cl=mysqli_query($conn, "INSERT INTO `expenses` (`Date`, `Time`, `User`, `Type`, `Purpose`, `Amount`, `Store`, `Payment`, `Payto`, `Status`, `Invoice`, `Classfy`, `Expense`, `Service`, `External`, `Rate`) VALUES ('$date', '$Time', '$loge', 'PAYMENT', '$purpo', '$depo', 'REMERA', '$pline', '$dest', '0', '$invo', 'EXPENSE', '$classe', '$naso', '1', '$rate')");
		}
		if($pline=='PAYOUT'){
			$payout=$_POST['payout'];
			$classe=$_POST['classe'];
			
	$sso=mysqli_query($conn, "UPDATE `expenses` SET `Classfy`='EXPENSE', `Invoice`='$invo', `Payto`='$dest', `Expense`='$classe', `Service`='$naso' WHERE `Number`='$payout'");
		}
		else{
		$purpo="Supplier payment";
		
	$so=mysqli_query($conn, "INSERT INTO `payment` (`Date`, `Time`, `User`, `Amount`, `Pline`, `Invoice`, `Status`, `Customer`, `Action`, `Descri`, `Destin`, `Cheno`, `Bname`, `Pdate`, `Container`, `Currency`, `Rate`, `Files`, `Linked`) VALUES ('$date', '$Time', '$loge', '$amo', '$pline', '$naso', '0', '$dest', 'SUPPLIER', '', '', '$cheno', '$bank', '$pdate', '', '$currency', '$rate', '$newfilename1', '$last_id')");
		}
		}


        if($dato==$datos)
			$mpri="ON $dato";
		else
			$mpri="FROM $dato TO $datos";
			
			$af="CREATE A NEW SERVICE";
?>

<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 active">
	  <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">
	  <a href="assets.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Assets Report
                </p>
              </a></li> 
                       
            </ul><br><br><br>
  </div>
  
  
  <?php 
  $supo=array();              $kt=1;
		$top=mysqli_query($conn, "SELECT `Supplier` FROM `services` WHERE `Status`='0' AND `Supplier`!='' GROUP BY `Supplier` ORDER BY `Date` DESC LIMIT 300");
		while($rop=mysqli_fetch_assoc($top)){
			$supo[$kt]=$rop['Supplier'];
			    $kt++;
					}
  include'transp.php';


  	echo"<div class='modal fade' id='Modal-Class' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true' 
		style='top:220px;'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content'>
      <div class='modal-header'>
        <h5 class='modal-title' id='exampleModalLabel'>ADD NEW CLASS 
		<label style='float:right; text-align:right;'><b> </b></label></h5>

      </div><form method='post' action=''>
      <div class='modal-body' style='height:120px;'>
      <div class='form-group' style='padding-top:20px;'>
      
       <div class='col-md-6 text-center'> 
<select class='form-control' name='categ' style='font-size:16px; height:34px;'>
<option value=''> Select Category </option>";

     $doi=mysqli_query($conn, "SELECT `Type` FROM `expetype` GROUP BY `Type` ORDER BY `Type` ASC");
			while($roi=mysqli_fetch_assoc($doi)){
				$fna=$roi['Type'];
	    echo"<option value='$fna'> $fna </option>";
			}
			
			
            echo"</select></div><div class='col-md-6 text-center'> 
    <input name='classi' class='form-control' type='text' style='text-align:left;'>        
            </div></div>
      </div><input type='hidden' name='p' value='$p'>
      <input type='hidden' name='dato' value='$dato'>
      <input type='hidden' name='datos' value='$datos'>
      <input type='hidden' name='custo' value='$custo'>
      <div class='modal-header text-right' style='margin-top:-10px; height:50px; padding-top:10px; border:0px solid blue;'>
        <button type='button' class='btn btn-sm btn-danger' data-dismiss='modal' style='width:80px;'> CANCEL </button>
        <button type='submit' name='saven' class='btn btn-sm btn-success' style='width:80px;'> SAVE </button>
      </div></form>
    </div>
  </div>
</div>";
?>
       
        <div class="col-lg-10">
                  <div class="row"><form action='' method='post'>
	<div class="col-lg-2 hidden-print" style="padding-left:40px; padding-right:0px;">

       <button class="btn btn-warning btn-block" type="button" data-toggle='modal' data-target='#Modaldis-0' style="font-size:12px;">CREATE NEW SERVICE</button>
		</div>
           <div class="col-lg-2" style="padding-right:60px;">

       <button class="btn btn-success btn-block" type="button" style="font-size:12px;" onclick="location.href='bulkpay.php';">BULK PAYMENT</button></div>

        <form action="" method="post" class="form-horizontal ">                  
    <div class="col-lg-8 hidden-print" style="padding-right:30px;">
                           
     <div class="col-lg-4 hidden-print"> 
     
			<select class="form-control" name="custo">
		<option value='' selected='selected'>SELECT A SUPPLIER</option>
			 <?php
$doix=mysqli_query($conn, "SELECT `Supplier` FROM `services` WHERE `Status`='0' AND `Supplier`!='' GROUP BY `Supplier` ORDER BY `Supplier` ASC");
			while($roix=mysqli_fetch_assoc($doix)){
				$desto=$roix['Supplier'];
				if($desto==$custo)
					$sle="selected='selected'";
				else
					$sle='';
			echo"<option value='$desto' $sle> $desto </option>";
			}
			?>    
                            </select>
			</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($custo)
            $conde="AND `Supplier` = '$custo'";
        
				if($p)
		$dok=mysqli_query($conn, "SELECT *FROM `services` WHERE `Status`='0' AND `Date` BETWEEN '$dato' AND '$datos' $conde ORDER BY `Date` ASC");
				else
		$dok=mysqli_query($conn, "SELECT *FROM (SELECT *FROM `services` WHERE `Status`='0' ORDER BY `Date` DESC LIMIT 15) SUB ORDER BY `Date` ASC");
				if($fo=mysqli_num_rows($dok)){
				?>
                 
            <div class="divFooter"><center><u><b>SUPPLIERS 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="3%" style='padding:1px; text-align:center'> No </th>
			<th style="adding:1px;"><div align='center'>&nbsp;&nbsp;&nbsp;&nbsp;DATE&nbsp;&nbsp;&nbsp;&nbsp;</th>
	        <th style='padding:1px;'><div align='center'> SUPPLIER </th>
			<th width='10%'><div align='center'> INVOICE No </th>
			    <th><div align='center'> PURPOSE </th>
				<th style='padding:1px;'><div align='center'> VAT </th>
				<th style='padding:1px;'><div align='center'> TAX </th>
				<th colspan='2' style='padding:1px;'>
				    <div align='center'> AMOUNT </th>
				<th style='padding:1px;'><div align='center'> PAID </th>
				<th colspan='2' style='padding:1px;'><div align='center'> BALANCE </th>
				<th colspan='3' class="hidden-print" 
	style='padding:1px; width:20px;'><div align='center'> OPTIONS </th>
                     </tr>
                    </thead>
                                        <tbody>
					<?php
					
					 $cat=$exp=array();            $s=1;
    $doi=mysqli_query($conn, "SELECT `Type` FROM `expetype` GROUP BY `Type` ORDER BY `Number` ASC");
			while($roi=mysqli_fetch_assoc($doi)){
				$fna=$roi['Type'];
            	$cat[$s]=$fna;  
            	$s++;
	    
	$doe=mysqli_query($conn, "SELECT `Expense` FROM `expetype` WHERE `Type`='$fna' GROUP BY `Expense` ORDER BY `Expense` ASC");
			while($roe=mysqli_fetch_assoc($doe)){
				$expe=$roe['Expense'];
                $exp[$s]=$expe;              $sp=$s;   	            $s++;                
			}
		}
		           
			
				$i++;			$tot=$tpa=$tba=$tva=$tta=0;
		while($rok=mysqli_fetch_assoc($dok)){
				$code=$rok['Number'];
				$dati=$rok['Date'];
				$name=$rok['Supplier'];
			$invo=$rok['Invoice'];
	$amo=($rok['Amount']*$rok['Rate']);			$amoo=number_format($amo, 2);
			$curre=$rok['Currency'];
			$curr=$rok['Currency'];
			$purpo=$rok['Purpose'];
			$tam=number_format($rok['Amount']);
			$vat=$rok['Vat'];                   $vato=number_format($vat, 2);
			$tax=$rok['Holdings'];               $taxo=number_format($tax, 2);
			$dst=$name;
			$us="RWF";
			$pay=0;
					
			// ************************* Paid Amount *************
    $sca=mysqli_query($conn, "SELECT SUM(`Amount`*`Rate`) AS 'Pay' FROM `payment` WHERE (`Invoice` = '$code' AND `Status`='0' AND `Action`='SUPPLIER') OR (`Invoice` = '$code' AND `Status`='0' AND `Action`='SUPPLIER' AND `Voucher`='$vous') ORDER BY `Number` ASC");
				$rca=mysqli_fetch_assoc($sca);
					$pay+=$rca['Pay'];
					
	$sso=mysqli_query($conn, "SELECT SUM(`Amount`) AS `Pas` FROM `expenses` WHERE `Service`='$code' AND `Status`='0' AND `External`='0'");
				$rso=mysqli_fetch_assoc($sso);
					$pay+=$rso['Pas'];
					
					$bal=$amo-$pay-$tax;							
					$btn=$clr="";
					
						if($pay)
						$lin="<a href='#' data-toggle='modal' data-target='#exampleModal$i'>";
					else
						$lin="";

					$balo=number_format($bal, 2);							
					$payo=number_format($pay, 2);
					$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'> $name </td><td style='$stl $clr'> $invo </td>
	<td style='$stl $clr'> $purpo </td>
	<td style='$stl $clr'><div align='right'> $vato </td>
	<td style='$stl $clr'><div align='right'> $taxo </td>
	<td style='$stl $clr'><div align='right'> $amoo </td>
	<td style='$stl $clr'> $us </td>
	<td style='$stl $clr'><div align='right'>$lin $payo </a></td>
	<td style='$stl $clr'><div align='right'> $balo </td>
	<td style='$stl $clr'>");
	
	$doin=mysqli_query($conn, "UPDATE `services` SET `Paid` = '$pay' WHERE `Number` = '$code' ORDER BY `Number` DESC");

    if($_SESSION['Cfr']){
	    $dbutn='submit';
	    $disa='';
	}
	else{
	    $dbutn='button';
	    $disa='disabled';
	}
	
	if($_SESSION['Cpd']){
	    $dbl='';
	}
	else{
	    $dbl='disabled';
	}
	
	$af="EDIT A GIVEN SERVICE";

	include'addpaid.php';            
	include'transp.php';              include'paymodal.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='Add a Payment' data-toggle='tooltip' data-placement='top'> 
	<div align='right'><button type='button' class='btn btn-xs btn-info hidden-print' style='height:18px; width:25px; padding:0px; margin:0px; margin-right:2px;' 
	data-toggle='modal' data-target='#exampleModalo$i'> &nbsp;<i class='lnr lnr-briefcase'></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-trash'></i>&nbsp; </button></td></tr>");
		$i++;				$tot+=$amo;             $tpa+=$pay;      
		$tba+=$bal;                     $tva+=$vat;             $tta+=$tax;
						}
			$tot=number_format($tot, 2);			
			$tpa=number_format($tpa, 2);					
			$tba=number_format($tba, 2);					
			$tva=number_format($tva, 2);					
			$tta=number_format($tta, 2);
						?>
						
                    </tbody>
					 <thead>
					<tr><th> </th><th colspan='4'><div align='center'> TOTAL AMOUNT </th>
					<th style="padding-right:1px;"><div align='right'><?php echo $tva ?></th>
					<th style="padding-right:1px;"><div align='right'><?php echo $tta ?></th>
					<th style="padding-right:1px;"><div align='right'><?php echo $tot ?></th>
					<th style="padding-right:1px; padding-left:1px;"><?php echo $us ?></th>
					<th style="padding-right:1px;"><div align='right'><?php echo $tpa ?></th>
					<th style="padding-right:1px;"><div align='right'><?php echo $tba ?></th></th>
					<th> </th><th colspan="3" 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';
   ?>