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

	/* get invoice */
	$order_id = intval($_REQUEST['idbon']);
	if(!$order_id) exit(error_message('Invalid invoice ID!', false));
	
	/* retrieve facturations info */
	$order_fields = get_sql_fields('bon_passage');
	$res = sql("select {$order_fields} from {$order_from} and idbon={$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('bon_passage');
	$item_from = get_sql_from('bon_passage');
	$res = sql("select {$item_fields} from {$item_from} and bon_passage.idbon={$order_id}", $eo);
	while($row = db_fetch_assoc($res)){
		$row['LineTotal'] = str_replace('$', '', $row['net_payer']);
		$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/marega.png" alt="edpto" style="width: 80px; float: right;">
		<h3>MAREGA VOYAGES</h3>
		<p>Tél. + 221 33 842 33 93 | 33 842 87 11</p>
		<p>Web. http://maregavoyages.com<br>Email. infos@maregavoyages.com</p>
		<hr>

<div class="row">
    <div class="col-sm-6 text-right">
        <!-- invoice info -->
        <h5>Date : <?php echo $order['date']; ?></h5>
        <h5>N°<?php echo $order['idbon']; ?></h5>
        <h5>PNR : <?php echo $order['pnr']; ?></h5>
    </div>
    <div class="col-sm-6">
        <!-- customer info -->
        <h1>BON DE PASSAGE</h1>
    </div>
	    <div class="col-sm-6">
        <!-- customer info -->
        <h5>Nous prions : <?php echo $order['nous_prions']; ?></h5>
        <h5>Au nom de : <?php echo $order['au_nom_de']; ?></h5>
        <h5>Sur le parcours : <?php echo $order['parcours']; ?></h5>
        <h5>Départ le : <?php echo $order['depart']; ?></h5>
        <h5>Retour le : <?php echo $order['retour']; ?></h5>
    </div>

</div>
<!-- order items -->
<table class="table table-striped table-bordered">
    <thead>
        <th class="text-center">#</th>
        <th class="text-center">TOTAL HT</th>
        <th class="text-center">COMMISSION</th>
        <th class="text-center">TOTAL TTC</th>
        <th class="text-center">FRAIS PTA</th>
        <th class="text-center">NET A PAYER</th>
        <th class="text-center">N° BILLET</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['total_ht']; ?></td>
            <td class="text-center"><?php echo $item['commissions']; ?></td>
            <td class="text-center"><?php echo $item['total_ttc']; ?></td>
            <td class="text-center"><?php echo $item['frais_pta']; ?></td>
            <td class="text-center"><?php echo $item['net_payer']; ?></td>
            <td class="text-center"><?php echo $item['num_billet']; ?></td>
        </tr>
        <?php } ?>
    </tbody>

    <tfoot></tfoot>
</table>
		<span id="in-words"><b>Arrêté à la somme de:</b></span>
		<?php
		include_once('nel.php');
		echo enlettres("$order_total");
		?>
		<span id="in-words"><b> franc CFA</b></span>
		<br><br><br>
		<center>
				<p><u>Cachet et Signature</u></p>
		</center>
	<div id="bas">
	<center>
		<p>
		<hr>
			32, Rue de Reims x Malick SY - BP : 7905 Médina Dakar - Tél : 00221 33 842 33 93 - 33 842 87 11<br>
			Fax : 00221 33 842 39 01 - Antenne Mermoz 2ème porte - Tél : 00221 33 824 48 89<br>
			http://www.maregavoyages.com - Email : infos@maregavoyages.com
		</p>
	</center>
	</div>

<?php

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

?>
