<?php
	$currDir = dirname(__FILE__);
	include("$currDir/nel.php");
	include("$currDir/defaultLang.php");
	include("$currDir/language.php");
	include("$currDir/lib.php");

	include_once("$currDir/header.php");

	/* grant access to all users who have access to the facture table */
	$order_from = get_sql_from('paiements');
	if(!$order_from) exit(error_message('Accès non autorisé!', false));

	/* get invoice */
	$order_id = intval($_REQUEST['id_paiement']);
	if(!$order_id) exit(error_message('ID facture invalide!', false));
	
	/* retrieve order info */
	$order_fields = get_sql_fields('paiements');
	$res = sql("select {$order_fields} from {$order_from} and id_paiement={$order_id}", $eo);
	if(!($order = db_fetch_assoc($res))) exit(error_message('Aucune facture disponible', false));
	
	//var_dump($order);
	
	/* retrieve order items */
	$items = array();
	$order_total = 0;
	$item_fields = get_sql_fields('etat_paiements');
	$item_from = get_sql_from('etat_paiements');
	$res = sql("select {$item_fields} from {$item_from} and etat_paiements.from_paiements={$order_id}", $eo);
	while($row = db_fetch_assoc($res)){
		$row['LineTotal'] = str_replace('$', '', $row['montant']) * $row['qte'];
		$etat_paiements[] = $row;
		$order_total += $row['LineTotal'];
	}
	
	//var_dump($etat_paiements);
	
	?>

<html>

<head>
    <title>Etat des paiements</title>
    <style type="text/css" media="print">
        input.imprimer {
            display: none;
        }

    </style>

</head>

<body>

    <form method="POST" action="">

        <input type="button" value="Imprimer" class="imprimer" name="bnom" onClick="javascript:window.print()">
    </form>

</body>

</html>


<h6>Honneur - Fraternité - Justice</h6>
<center>
    <h3>Ministère de l'Habitat de l'Urbanisme et de l'Aménagement du territoire</h3>
    <h4>Direction des Affaires Administratives et Financières</h4>
    <h4>Service du Personnel</h4>
    <center>
        <u>
            <h3>ETAT DES PAIEMENTS : TRAVAUX SPECIAUX PERSONNEL DU MHUAT</h3>
            <h5><?php echo $order['du']; ?> - <?php echo $order['au']; ?> <?php echo date('Y');?></h5>
        </u>
    </center>
</center>


<div class="row">
    <div class="col-sm-6">
        <!-- customer info 
			<h5>CLIENT : <?php echo $order['client']; ?></h5>
			<h5>ENTREPRISE : <?php echo $order['entreprise']; ?></h5>
			<h5>ADRESSE : <?php echo $order['adresse']; ?></h5>
			<h5>CONTACT : <?php echo $order['contact']; ?></h5>
			-->
    </div>
    <div class="col-sm-6 text-right">
        <!-- invoice info 
			<h1></h1>
			<h5>Nouakchott, le <?php echo $order['date']; ?></h5>
			-->

    </div>
</div>

<hr>

<!-- order etat_paiements -->
<table class="table table-striped table-bordered">
    <thead>
        <th class="text-center">N° ORDRE</th>
        <th class="text-center">MATRICULE</th>
        <th>NOM ET PRENOM</th>
        <th>FONCTION</th>
		<th class="text-center">N°COMPTE</th>
        <th class="text-center">BANQUE</th>
        <th class="text-center">MONTANT</th>
    </thead>

    <tbody>
        <?php foreach($etat_paiements as $i => $item){ ?>
        <tr>
            <td class="text-center"><?php echo ($i + 1); ?></td>
            <td><?php echo $item['matricule']; ?></td>
            <td><?php echo $item['nom_prenom']; ?></td>
            <td><?php echo $item['fonction']; ?></td>
            <td><?php echo $item['n_compte']; ?></td>
            <td><?php echo $item['banque']; ?></td>
            <td class="text-center"><?php echo number_format($item['montant'], 0, ',', ' '); ?></td>
            <!--<td class="text-center"><?php echo $item['qte']; ?></td>/-->
            <!--<td class="text-right"><?php echo number_format($item['montant'], 0, ',', ' '); ?></td>/-->
        </tr>
        <?php } ?>
    </tbody>

    <tfoot>


        <tr>
            <th colspan="6" class="text-right">TOTAL</th>
            <th class="text-right"> <?php echo number_format($order_total + $order['Freight'], 0, ',', ' '); ?></th>
        </tr>
    </tfoot>
</table>

<span id="in-words"><b>Arrêté le présent état de paiement à la somme de:</b></span>

<?php
include_once('nel.php');
echo enlettres("$order_total");
?>
<span id="in-words"><b> MRU</b></span>

<center>
    <span id="in-words" style="float: right;"><b>
            <h5>Le Secrétaire Général<br><?php echo $order['directeur']; ?></h5>
        </b></span>
</center>
<!--
	<center>
	<p>
		Numéro Téléphone : +222 37 66 39 34 | +213 780 01 12 81 | Email gérant : boubouttboullah@icloud.com<br>
		Email bureau : sbbs.impexp@gmail.com | RC : 102204/GU/23213/477 | NIF : 00621223
	</p>
	</center>
	-->
<!-- <span id="in-words" style="color: red;"><b>NB. AUCUNE SOMME PAYEE N'EST EN AUCUN CAS REMBOURSABLE</b></span> /-->

<?php

	include_once("$currDir/footer.php");

?>
