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

	/* get invoice */
	$order_id = intval($_REQUEST['idfacture']);
	if(!$order_id) exit(error_message('Invalid invoice ID!', false));
	
	/* retrieve order info */
	$order_fields = get_sql_fields('facture');
	$res = sql("select {$order_fields} from {$order_from} and idfacture={$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('detail_facture');
	$item_from = get_sql_from('detail_facture');
	$res = sql("select {$item_fields} from {$item_from} and detail_facture.factureid={$order_id}", $eo);
	while($row = db_fetch_assoc($res)){
		$row['LineTotal'] = str_replace('$', '', $row['prixunitaire']) * $row['quantite'];
		$items[] = $row;
		$order_total += $row['LineTotal'];
	}
	
	//var_dump($items);
	
	?>
		<!-- bouton impression -->
	<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: 180px; float: left;">

	<center>

			<h1 id="grd">MAREGA VOYAGES</h1>
	<p>RIB / SN079 01101 251019900377 60 BANQUE ISLAMIQUE DU SENEGAL</p>
	</center>
	<hr>

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

        <div class="col-sm-6 text-right">
            <!-- invoice info -->
            <h5>DATE :
                <?php echo $order['date']; 
            ?>
            </h5>
            <center>
                <h2>
                    <?php echo $order['type']; ?>  N° <?php echo $order['num_facture']; ?>/<?php echo date('Y');?>
                </h2>                
				<h5>
                    <?php echo $order['agent']; ?>
                </h5>
            </center>
        </div>
<br><br><br>
        <h5>FOURNISSEUR :
            <?php echo $order['client']; ?>
        </h5>
        <h5>TELEPHONE :
            <?php echo $order['societe']; ?>
        </h5>
        <h5>OBJET :
            <?php echo $order['travaux']; ?>
        </h5>        
		
		<h5>VALIDITE :
            <?php echo $order['terme_reglement']; ?>
        </h5>
    </div>

</div>

<br><br><br>

<!-- order items -->
<table class="table table-striped table-bordered">
    <thead>
        <th class="text-center">#</th>
        <th>DESIGNATION</th>
        <th class="text-center">PRIX UNITAIRE</th>
        <th class="text-center">QUANTITE</th>
        <th class="text-center">TOTAL</th>
    </thead>

    <tbody>
        <?php foreach($items as $i => $item){ ?>
        <tr>
            <td class="text-center">
                <?php echo ($i + 1); ?>
            </td>
            <td>
                <?php echo $item['designation']; ?>
            </td>
            <td class="text-center">
                <?php echo number_format($item['prixunitaire'], 0, ',', ' '); ?>
            </td>
            <td class="text-center">
                <?php echo $item['quantite']; ?>
            </td>
            <td class="text-right">
                <?php echo number_format($item['LineTotal'], 0, ',', ' '); ?>
            </td>
        </tr>
        <?php } ?>
    </tbody>

    <tfoot>


        <tr>
            <th colspan="4" 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é à la somme de:</b></span>
<?php
include_once('nel.php');
echo enlettres("$order_total");
?>
<span id="in-words"><b> fcfa</b></span>


<p>

<h4>NB</h4>

<?php echo $order['termes']; ?>

</p>


<center>

<h3><?php echo $order['signataire']; ?></h3>

</center>



	<div id="bas">
	<center>
		<p>
		<hr>
			R.C SNDKR 2003-B-14877 - NINEA 23507502B2 - LIC N°006215/23/09/02 - Code IATA : 722 00 12232<br>
			Société Unipersonnel à Responsabilité Limitée au Capital de 1 000 000 de Francs CFA<br>
			Siège Social 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>
			https://groupemarega.com - Email : infos@groupemarega.com
		</p>
	</center>
	</div>

<?php

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

?>
