<?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 paiments table */
	$paiements_from = get_sql_from('paiements');
	if(!$paiements_from) exit(error_message('Access denied!', false));

	/* get invoice */
	$paiements_id = intval($_REQUEST['idpaiement']);
	if(!$paiements_id) exit(error_message('Invalid invoice ID!', false));
	
	/* retrieve paiements info */
	$paiements_fields = get_sql_fields('paiements');
	$res = sql("select {$paiements_fields} from {$paiements_from} and idpaiement={$paiements_id}", $eo);
	if(!($paiements = db_fetch_assoc($res))) exit(error_message('Invoice not found!', false));
	
	//var_dump($paiements);
	
	/* retrieve paiements items */
	$items = array();
	$paiements_total = 0;
	$item_fields = get_sql_fields('paiements');
	$item_from = get_sql_from('paiements');
	$res = sql("select {$item_fields} from {$item_from} and paiements.idpaiement={$paiements_id}", $eo);
	while($row = db_fetch_assoc($res)){
		$row['montant'] = str_replace('$', '', $row['montant']);
		$items[] = $row;
		$paiements_total += $row['montant'];
	}
	
	//var_dump($items);
	
	?>
<html>

		<head>
			<title></title>
			<style type="text/css" media="print">
				input.imprimer {
					display: none;
				}
		#bas {
				position: fixed;
			bottom: 0;
			width: 100%;
		}
			</style>

		</head>

<body>

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

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

</body>

	</html>
	
	<img id="img1" src="images/logo.jpg" alt="edpto" style="width: 80px; float: right;">
	<h3>GEIGROUPE</h3>

	<p>Tél. + 222 41 15 12 39</p>
	<p>Web. https://geigroupe.mr<br>Email. geigroupe@geigroupe.mr</p>
	<hr>

<div class="row">
    <div class="col-sm-6">
        <!-- customer info -->

        <div class="col-sm-6 text-right">
            <!-- invoice info -->
            <h5>Date,
                <?php echo $paiements['date_paiement']; 
            ?>
            </h5>
            <center>
                <h2>
                    FACTURE N°: <?php echo $paiements['code']; ?>/<?php echo date('Y');?>
                </h2>
            </center>
        </div>
        <br><br>
        <h5>CLIENT :
            <?php echo $paiements['nom_prenom']; ?>
        </h5>
        <h5>NATURE :
            <?php echo $paiements['type_paiement']; ?>
        </h5>
        <h5>BENEFICIAIRE :
            <?php echo $paiements['beneficiaire']; ?>
        </h5>
    </div>

</div>

<hr>

<!-- paiements items -->
<table class="table table-striped table-bpaiementsed">
    <thead>
        <th class="text-center">#</th>
        <th>MATRICULE</th>
        <th class="text-center">BANQUE</th>
        <th class="text-center">COMPTE</th>
        <th class="text-center">MONTANT</th>
    </thead>

    <tbody>
        <?php foreach($items as $i => $item){ ?>
        <tr>
            <td class="text-center">
                <?php echo ($i + 1); ?>
            </td>
            <td>
                <?php echo $item['matricule']; ?>
            </td>
            <td class="text-center">
                <?php echo $item['banque']; ?>
            </td>
            <td class="text-center">
                <?php echo $item['compte']; ?>
            </td>
            <td class="text-center">
                <?php echo number_format($item['montant'], 0, ',', ' '); ?>
            </td>
        </tr>

        <?php } ?>
    </tbody>

    <tfoot>

        <tr>
            <th colspan="4" class="text-right">TOTAL</th>
            <th class="text-right">
                <?php echo number_format($paiements['montant'], 0, ',', ' '); ?>
            </th>
        </tr>
    </tfoot>
</table>
<span id="in-words"><b>Arrêté la présente facture à la somme de:</b></span>
<?php
include_once('nel.php');
echo enlettres("$paiements_total");
?>
<span id="in-words"><b> fcfa</b></span>


	<div id="bas">
	<center>
		<p>
		<hr>
			Générale des Entreprises Informatique<br>
			Nouakchott - Mauritanie<br>
		</p>
	</center>
	</div>

<?php

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

?>
