    <div class="row" style="padding:0px; margin:0px;"><button type='button' class="btn btn-xs btn-warning hidden-print pull-right" data-toggle="modal" data-target="#xcModalp" style="width:120px; margin:-10px 40px; 0px 0px;"> <i class="lnr lnr-plus-circle"></i>&nbsp;ADD TAX </button></div><hr><form action="" method="post"><div class="col-lg-8 text-center">
   
    
    <?php 	
// ***********************Add tax modal ************************************************
	echo"<div class='modal fade' id='xcModalp' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true'>
  <div class='modal-dialog' role='document'><div class='modal-content'><div class='modal-header text-left'>
        <h5 class='modal-title' id='exampleModalLabel'><b> ADD TAX </b><span class='pull-right'> $dest </span></h5>

      </div><form action='' method='post'>
      <div class='modal-body text-left' style='height:240px;'>
			<div class='row'>
		<div class='col-md-12'>
			<div class='col-md-6'><br>&nbsp;&nbsp;&nbsp;TAX TYPE <br>
		   <select class='form-control' name='tax' required>
				<option value='' selected='selected'>SELECT TAX TYPE </option>";
			 
		$doi=mysqli_query($conn, "SELECT *FROM `fcost` WHERE `Status`='2' ORDER BY `Name` ASC");
			while($roi=mysqli_fetch_assoc($doi)){
				$fna=$roi['Name'];
				$nuo=$roi['Number'];
				$tax="$nuo?$fna";
			echo"<option value='$tax'> $fna </option>";
			}
		
		   echo"</select>
            </div>


	<div class='col-md-3 col-xs-7' style='padding-right:0px;'><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AMOUNT <br>
	<input name='amo' class='form-control text-right' type='text' onkeyup='format(this);' onkeypress='return isNumberKey(event)' title='AMOUNT' data-toggle='tooltip' data-placement='top' required>
  </div>

	<div class='col-md-3 col-xs-5' style='padding-left:0px;'><br><br>
		   <select class='form-control' name='rats' title='Currency' data-toggle='tooltip' data-placement='top' style='margin-left:0px; padding-left:5px; padding-right:2px;' required><option value='' selected='selected'>Currency</option>";
		
			$doi=mysqli_query($conn, "SELECT `Code`, `Rate` FROM `currency` WHERE `Code`!='' ORDER BY `Code` ASC");
			while($roi=mysqli_fetch_assoc($doi)){
				$fna=$roi['Code'];
				$rase=$roi['Rate'];
				if($curre==$fna)
				    $s="selected";
				else
				    $s='';
				$rte=number_format($rase, 2);
			echo"<option value='$rase' $s> $fna @ $rte </option>";
			}
		
		   echo"</select></span>
            </div>

			</div></div><div class='row'><div class='col-md-12 col-xs-12'>
			
		<div class='col-md-12 col-xs-12'>&nbsp;&nbsp;&nbsp;ACCOUNT NUMBER <br>
	<select class='form-control' name='acco' style='height:30px; padding:0px;' required><option value='' selected='selected'>SELECT ACCOUNT</option>";
			
	$doi=mysqli_query($conn, "SELECT `Number`, `Account`, `Bank` FROM `baccount` ORDER BY `Account` ASC");
			while($roi=mysqli_fetch_assoc($doi)){
				$fna=$roi['Account'];
				$bank=$roi['Bank'];
				$nuo=$roi['Number'];
				$cco="$nuo?$fna";
			echo"<option value='$cco'> $fna &nbsp; [$bank]</option>";
			}
			
		echo"</select></div></div></div>
			
		<div class='row'><div class='col-md-12 col-xs-12'>	
			<div class='col-md-12 col-xs-12'><textarea class='form-control' name='descri' style='height:60px; font-size:14px;' placeholder='Decription ...'></textarea></div>
	    </div></div></div><hr>
      
      <input type='hidden' name='name' value='$name'>
      <input type='hidden' name='dati' value='$dati'>
      <input type='hidden' name='vous' value='$vous'>
      <input type='hidden' name='invo' value='$invo'>
	  <input type='hidden' name='dato' value='$dato'>
	  <input type='hidden' name='datos' value='$datos'>
	  <input type='hidden' name='custo' value='$custo'>
	  
      <div class='modal-footer' style='margin-top:-10px; height:50px; padding-top:5px; border:0px solid blue;'>
      <div class='col-md-2 col-xs-2'> </div><div class='col-md-3 col-xs-3'>
      <input name='dase' class='form-control date' data-provide='datepicker' type='text' style='text-align:center; height:32px;' value='$Date'>
      </div>
      
      <div class='col-md-7 col-xs-7'>
        <button type='button' class='btn btn-sm btn-danger' data-dismiss='modal' style='width:95px;'><i class='lnr lnr-cross-circle'></i> CANCEL </button>
        <button type='submit' name='addco' class='btn btn-sm btn-success' style='width:95px;'><i class='lnr lnr-checkmark-circle'></i> SAVE </button></div></form></div>
    </div>
  </div>
</div>";

// *********************** Add tax to container **********************
?>


	
<div class="col-lg-12 text-center" style="border:1px solid #D8D7D6; 
border-radius:5px; height:300px; overflow-y:auto; padding:0px; margin:0px 10px 20px 8px;">   
                  
    <?php

				$to=0;
	$sek=mysqli_query($conn, "SELECT `loading`.`Number`,`loading`.`Cost`,`loading`.`Amount`,`loading`.`Date`, `loading`.`Descri`, `loading`.`Rate`, `loading`.`Currency`, `loading`.`Account`, `fcost`.`Name` FROM `loading` INNER JOIN `fcost` ON `loading`.`Cost` = `fcost`.`Number` WHERE `loading`.`Voucher`='$vous' AND `loading`.`Status`='2' ORDER BY `loading`.`Number` DESC");
	    if($fek=mysqli_num_rows($sek)){
    echo"<table class='table table-striped table-hover' style='float:center; width:99%'>     
        <thead><tr role='row'><th width='1%'><div align='center'> No </th>
        <th width='80px'><div align='center'>Date</th><th> Cost&nbsp;Name </th>
		<th> Description </th><th class='text-center'> Account </th><th class='text-center'> Amount </th><th class='text-center'> Value </th><th class='text-center'> # </th>
		</tr></thead><tbody>";
		        
			$n=$i=1;			  $stn="style='padding:1px; font-size:11px;'";						
		while($rek=mysqli_fetch_assoc($sek)){
			$num=$rek['Number'];
			$amo=$rek['Amount'];				$amoo=number_format($amo, 2);
			$dte=$rek['Date'];
			$cuso=$rek['Name'];	
			$desc=$rek['Descri'];
			$ras=$rek['Rate'];                  $raso=number_format($ras, 2);
			$cur=$rek['Currency'];
			$val=$amo*$ras;                    $valo=number_format($val, 2);
			$acco=$rek['Account'];
			$x="&nbsp;x&nbsp;";
			
		$doi=mysqli_query($conn, "SELECT `Account`, `Bank` FROM `baccount` WHERE `Number`='$acco' ORDER BY `Account` ASC");
			$roi=mysqli_fetch_assoc($doi);
				$fna=$roi['Account'];
				$bank=$roi['Bank'];

	echo"<tr title='$cosu' data-toggle='tooltip' data-placement='top' style='height:22px;'><td class='text-center' $stn> $n </td><td class='text-center' $stn> $dte </td><td class='text-left' $stn> $cuso </td><td class='text-left' $stn> $desc </td><td class='text-left' $stn>
		<a href='#' data-placement='top' data-toggle='modal' data-target='#accoModal$n'> $fna/$bank </a></td><td class='text-right' $stn> $raso$x$amoo </td><td class='text-right' $stn> $valo </td><td class='text-center' $stn>
	
	
	
	<div class='modal fade' id='xtModal$n' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true'>
  <div class='modal-dialog' role='document'><div class='modal-content'><div class='modal-header text-left'>
        <h5 class='modal-title' id='exampleModalLabel'>DELETE CONFIRMATION <span class='pull-right'> $cuso: RWF$valo </span></h5>

      </div><form action='' method='post'>
      <div class='modal-body text-left' style='height:40px;'>
  <h5 style='color:#ff0033'>Are you sure you want to delete this record ?</h5>
      </div><input type='hidden' name='code' value='$code'>
	    <input type='hidden' name='dato' value='$dato'>
	    <input type='hidden' name='datos' value='$datos'>
	    <input type='hidden' name='custo' value='$custo'>
	    <input type='hidden' name='invo' value='$invo'>
	    <input type='hidden' name='dati' value='$dati'>
	    <input type='hidden' name='name' value='$name'>
	    <input type='hidden' name='num' value='$num'>
	    <input type='hidden' name='vous' value='$vous'>
	    <input type='hidden' name='amo' value='$amo'>
	    <input type='hidden' name='ras' value='$ras'>
	    <input type='hidden' name='dte' value='$dte'>
	    <input type='hidden' name='acco' value='$acco'>
      <div class='modal-footer' style='margin-top:-10px; height:50px; padding-top:5px; border:0px solid blue;'>
        <button type='button' class='btn btn-sm btn-success' data-dismiss='modal'>&nbsp;NO&nbsp;</button>
        <button type='submit' name='deleco' class='btn btn-sm btn-danger'>YES</button>
      </div></form>
    </div>
  </div>
</div>";

// *********************** Change Account Number ************************************************
		echo"<div class='modal fade' id='accoModal$n' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true'>
  <div class='modal-dialog' role='document'><div class='modal-content'><div class='modal-header text-left'>
        <h5 class='modal-title' id='exampleModalLabel'>CHANGE ACCOUNT <span class='pull-right'> $cuso: RWF$valo </span></h5>

      </div><form action='' method='post'>
      <div class='modal-body text-left' style='height:100px;'>
			<div class='row'><input type='hidden' name='code' value='$code'>
	    <input type='hidden' name='dato' value='$dato'>
	    <input type='hidden' name='datos' value='$datos'>
	    <input type='hidden' name='custo' value='$custo'>
	    <input type='hidden' name='invo' value='$invo'>
	    <input type='hidden' name='dati' value='$dati'>
	    <input type='hidden' name='name' value='$name'>
	    <input type='hidden' name='num' value='$num'>
	    <input type='hidden' name='vous' value='$vous'>
	    <input type='hidden' name='amo' value='$amo'>
	    <input type='hidden' name='ras' value='$ras'>
	    <input type='hidden' name='dte' value='$dte'>
	    <input type='hidden' name='acco' value='$acco'>
		<div class='col-md-12'>
			<div class='col-md-4 text-right' style='padding-top:30px;'><b> ACCOUNT No </b>
            </div>


	<div class='col-md-7'><br><select class='form-control' name='account' style='height:30px; padding:0px;' required><option value='' selected='selected'>SELECT ACCOUNT</option>";
			
	$doi=mysqli_query($conn, "SELECT `Number`, `Account`, `Bank` FROM `baccount` WHERE `Number`!='$acco' ORDER BY `Account` ASC");
			while($roi=mysqli_fetch_assoc($doi)){
				$fna=$roi['Account'];
				$bank=$roi['Bank'];
				$nuo=$roi['Number'];
				$cco="$nuo?$fna";
			echo"<option value='$cco'> $fna &nbsp; [$bank]</option>";
			}
			
		echo"</select>

</div>

			</div></div></div><hr>
		<input type='hidden' name='custo' value='$custo'><input type='hidden' name='vous' value='$vous'>
	  <input type='hidden' name='dato' value='$dato'><input type='hidden' name='datos' value='$datos'><input type='hidden' name='p' value='$p'>
      <div class='modal-footer' style='margin-top:-10px; height:50px; padding-top:5px; 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='upco' class='btn btn-sm btn-success' style='width:80px;'> UPDATE </button>
      </div></form>
    </div>
  </div>
</div>";
	
	
        if($_SESSION['Cfr'])
	echo"<button type='button' class='btn btn-xs btn-default text-danger hidden-print' style='height:18px; padding:0px; margin:0px; width:10px; border:0px; background-color:transparent; margin-right:10px;' data-toggle='modal' data-target='#xtModal$n'>&nbsp;&nbsp;<i class='lnr lnr-trash'></i>&nbsp;&nbsp;</button>";
	
	echo"</td></tr>";

		$n++;				$i++;					$to+=($amo*$ras);
		}
		
		while($n<=10){
		    echo"<tr style='height:22px;'><td colspan='8'> </td></tr>";
		        $n++;
		        }
		    
							$too=number_format($to, 2);
							$toco=number_format($to+$tot, 2);
							$balo=number_format($tva-$to, 2);
	echo"</tbody></table>";
	        }
	    else
	echo"<center><div class='text-success' style='padding-top:120px; font-size:18px; padding-bottom:122px;'><a href=''  data-toggle='modal' data-target='#xcModalp'>You can now start adding taxes</a></div></center>";

    echo"</div>";
    
        if($to AND $i>2)
    echo"<table width='100%' style='margin-top:-10px;'><tr><th> </th><th colspan='2' class='text-center'> &nbsp; </th><th class='text-right' style='padding-right:1px; font-size:16px;'> $too </th><th width='5%'> </th></tr></table><br><br>";
    
    $gco=number_format($ttax+$tvat+$to, 2);
    $gto=number_format($tba+$ttax+$tvat+$to, 2);
    
        ?>
    </div><div class="col-lg-4 text-center"><br>
    <span class="badge badge-info text-danger" style="width:80%; font-size:16px; height:26px;padding-top:6px;"> PURCHASE SUMMARY 
    </span><br><br><div align="right">
        <table width='90%' style="margin-right:20px; font-size:16px;"><tr>
    <td width='60%' align='right'> Purchase :</td><td align='right'><?php echo $tbao ?></td> 
        </tr><tr>
    <td width='60%' align='right'> Taxes Paid :</td><td align='right'><?php echo $ttaxo ?></td> 
        </tr><tr>
    <td width='60%' align='right'> Vat Inward :</td><td align='right'><?php echo $tvato ?></td> 
        </tr><tr>
    <td width='60%' align='right'> Other Cost :</td><td align='right'><?php echo $too ?></td> 
        </tr><tr>
    <td width='60%' align='right'> Total Cost :</td><td align='right'><?php echo $gco ?></td> 
        </tr><tr>
    <td colspan='2'><div align='right'><hr width='90%' style='float:right'>
    </div></td></tr>
    
    <tr><td width='60%' align='right'><b> Total Amount :
    <?php
    if($fek)
    echo"<br><br><font color='blue'></font> Tax Balance : </font>";
    ?></td>
    <td align='right'><b><?php echo $gto ?> 
    <?php
    if($fek)
    echo"<br><br><font color='blue'> $balo </font>";
    ?></td> 
        </tr></table> </div>
    </div></div>