<?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('gestion_primes');
	if(!$order_from) exit(error_message('Accès non autorisé!', false));

	/* get invoice */
	$order_id = intval($_REQUEST['idgestion_prime']);
	if(!$order_id) exit(error_message('ID facture invalide!', false));
	
	/* retrieve order info */
	$order_fields = get_sql_fields('gestion_primes');
	$res = sql("select {$order_fields} from {$order_from} and idgestion_prime={$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('dossier_individuel');
	$item_from = get_sql_from('dossier_individuel');
	$res = sql("select {$item_fields} from {$item_from} and dossier_individuel.option_prime={$order_id}", $eo);
	while($row = db_fetch_assoc($res)){
		$row['LineTotal'] = str_replace('$', '', $row['prime']) * $row['qty'];
		$dossier_individuel[] = $row;
		$order_total += $row['LineTotal'];
	}
	
	//var_dump($gestion_primes);
	
	?>

<html>

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

        .imprimer {
            display: none;
        }

    </style>

</head>

<body>
    <h4><a class="imprimer" href="gestion_primes_view.php">Retour</a></h4>

    <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['mois']; ?> - <?php echo date('Y');?></h5>
        </u>
    </center>
</center>


<div class="row">
    <div class="col-sm-6">

    </div>
    <div class="col-sm-6 text-right">

    </div>
</div>

<hr>

<!-- order dossier_individuel -->
<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($dossier_individuel 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['compte']; ?></td>
            <td><?php echo $item['banque']; ?></td>
            <td class="text-center"><?php echo number_format($item['LineTotal'], 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['total'], 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['signataire']; ?></h5>
        </b></span>
</center>


<?php

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

?>
