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

	/* get invoice */
	$order_id = intval($_REQUEST['idgtransaction']);
	if(!$order_id) exit(error_message('Invalid invoice ID!', false));
	
	/* retrieve order info */
	$order_fields = get_sql_fields('gestion_transactions');
	$res = sql("select {$order_fields} from {$order_from} and idgtransaction={$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('billeteries');
	$item_from = get_sql_from('billeteries');
	$res = sql("select {$item_fields} from {$item_from} and billeteries.link_out={$order_id}", $eo);
	while($row = db_fetch_assoc($res)){
		$row['LineTotal'] = str_replace('$', '', $row['account']);
		$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;
				}
			</style>
			
			<style>
				#imgentete
				{
					width: 160px;
					height: 160px;
					float: left;
				}
				
				#imgentete2
				{
					width: 80px;
					height: 80px;
					float: right;
				}
				
				#bas {
					position: fixed;
					bottom: 0;
					width: 100%;
				}
				
				#gras{
					font-weight: 700;
				}
				
				div #infoc{
					border: 2px solid black;
					border-radius: 10px;
					width: 100%;
					padding-left: 10px
				}
				
				.para{
					line-height: 20px;
				}
				
				.momo{
					background-color: gray;
					color: black;
				}
			</style>

		</head>

	<!-- entete info -->
		<div>
			<?php
				$logo_src = getUploadDir("") .$order["logo"];
				echo "<img id='imgentete' src=\"{$logo_src}\" />";
			?>
		</div>
		
		<div>
				<img id="imgentete2" src="images/iata.png" alt="IATA">
		</div>
		
			<h3 class="text-center"><?php echo $order['rs']; ?></h3>		
			<p class="text-center"><?php echo $order['description']; ?></p>

			
	<!-- entete info -->
	<hr>
<body>
	<a href="<?php echo PREPEND_PATH; ?>gestion_transactions_view.php?SelectedID=<?php echo urlencode($id) ?>" class="btn btn-info hidden-print btn-lg"><i class="glyphicon glyphicon-chevron-left"></i> <?php echo html_attr($Translation['Back']); ?></a>
	<button class="btn btn-primary hidden-print btn-lg hspacer-lg" type="button" id="sendToPrinter" onclick="window.print();"><i class="glyphicon glyphicon-print"></i> Imprimer</button>
</body>
<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['numero']; ?>/<?php echo $order['agent_init']; ?>/<?php echo date('Y');?>
                </h2>
            </center>
        </div>
		<h5><u>Infos client</u><br>
		<div id="infoc">
					<p class="para">
						Raison Sociale : <?php echo $order['raison_sociale']; ?><br>
						Nom & Prénom : <?php echo $order['nom_prenom']; ?><br>
						Adresse : <?php echo $order['adclient']; ?><br>
						Téléphone : <?php echo $order['telclient']; ?><br>
						Email : <?php echo $order['emclient']; ?>
					</p>
				</h5>
		</div>		
    </div>

</div>

<br><br>

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

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

            <td class="text-right">
                <?php echo $item['reste_a_payer']; ?>
            </td>
        <?php } ?>
    </tbody>

    <tfoot>


        <tr>
            <th colspan="5" class="text-right">TOTAL</th>
            <th class="text-right">
                <?php echo number_format($order_total + $order['Freight'], 0, ',', ' '); ?>
            </th>
        </tr>
    </tfoot>
</table>
<br><br><br>
<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> <?php echo $order['devise']; ?></b></span>

<br><br><br>

<h4>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;<?php echo $order['signataire']; ?></h4>

	<div id="bas">
		<p>
			<?php echo $order['termes']; ?>
		</p>
		<hr>
		<center>
			<h6><?php echo $order['footer_3']; ?></h6>
		</center>
	</div>

<?php

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

?>
