<?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('piece_reglements');
	if(!$order_from) exit(error_message('Access denied!', false));

	/* get invoice */
	$order_id = intval($_REQUEST['idpiece']);
	if(!$order_id) exit(error_message('Invalid invoice ID!', false));
	
	/* retrieve facturations info */
	$order_fields = get_sql_fields('piece_reglements');
	$res = sql("select {$order_fields} from {$order_from} and idpiece={$order_id}", $eo);
	if(!($order = db_fetch_assoc($res))) exit(error_message('Invoice not found!', false));
	
	
	//var_dump($order);
	
	/* retrieve order items */
	$items = array();
	$order_total = 0;
	$item_fields = get_sql_fields('piece_reglements');
	$item_from = get_sql_from('piece_reglements');
	$res = sql("select {$item_fields} from {$item_from} and piece_reglements.idpiece={$order_id}", $eo);
	while($row = db_fetch_assoc($res)){
		$row['LineTotal'] = str_replace('$', '', $row['montant']);
		$items[] = $row;
		$order_total += $row['LineTotal'];
	}

	
	//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 -->
        <h1>PIECE DE REGLEMENT</h1>
    </div>
	    <div class="col-sm-6">
        <!-- customer info -->
        <h5>Bénéficiaire : <?php echo $order['beneficiaire']; ?></h5>
        <h5>Opération : <?php echo $order['operation']; ?></h5>
        <h5>Imputation : <?php echo $order['imputation']; ?></h5>
    </div>
    <div class="col-sm-6 text-right">
        <!-- invoice info -->
        <h5>Date : <?php echo $order['date']; ?></h5>
        <h5>N°<?php echo $order['idpiece']; ?></h5>
        <center>
            <bold>
                <h2>Montant en CFA : <?php echo $order['montant']; ?></h2>
            </bold>
        </center>
    </div>
</div>

<hr>

<!-- order items -->
<table class="table table-striped table-bordered">
    <thead>
        <th class="text-center">#</th>
        <th>BANQUE</th>
        <th>COMPTE</th>
        <th>N° CHEQUE</th>
        <th>DATE DU CHEQUE</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 class="text-center"><?php echo $item['banque']; ?></td>
            <td class="text-center"><?php echo $item['compte']; ?></td>
            <td class="text-center"><?php echo $item['num_cheque']; ?></td>
            <td class="text-center"><?php echo $item['date_cheque']; ?></td>
            <td class="text-center"><?php echo $item['montant']; ?></td>
        </tr>
        <?php } ?>
    </tbody>

    <tfoot>

    </tfoot>
</table>
<span id="in-words"><b>Arrêté le présent règlement à la somme de:</b></span>
<?php
include_once('nel.php');
echo enlettres("$order_total");
?>
<span id="in-words"><b> fcfa</b></span>
<br><br><br><br>
<center>
        <p><u>ETABLISSEMENT</u>&emsp;&emsp;<u>ENREGISTREMENT ET VERIFICATION</u>&emsp;&emsp;&emsp;<u>AUTORISATION</u>&emsp;&emsp;&emsp;<u>PAIEMENT</u></p>
        <br><br>
		<p><u>CAISSE</u>&emsp;&emsp;&emsp;<u>LE CHEF D'AGENCE</u>&emsp;&emsp;&emsp;<u>LE DIRECTEUR GENERAL</u>&emsp;&emsp;&emsp;<u>BENEFICIAIRE</u></p>
</center>
	<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");

?>
