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

	/* get invoice */
	$order_id = intval($_REQUEST['idcaisse_journaliere']);
	if(!$order_id) exit(error_message('Invalid invoice ID!', false));
	
	/* retrieve facturations info */
	$order_fields = get_sql_fields('caisse_journaliere');
	$res = sql("select {$order_fields} from {$order_from} and idcaisse_journaliere={$order_id}", $eo);
	if(!($order = db_fetch_assoc($res))) exit(error_message('Invoice not found!', false));
	
	/* total colonne montant */
	$items = array();
	$order_total = 0;
	$item_fields = get_sql_fields('item_caisse_journaliere');
	$item_from = get_sql_from('item_caisse_journaliere');
	$res = sql("select {$item_fields} from {$item_from} and item_caisse_journaliere.link_out={$order_id}", $eo);
	while($row = db_fetch_assoc($res)){
		$row['LineTotal'] = str_replace('$', '', $row['commission']);
		$items[] = $row;
		$order_total += $row['LineTotal'];
	}
	/*
	==total colonne achats==
	$items = array();
	$order_total1 = 0;
	$item_fields = get_sql_fields('item_caisse_journaliere');
	$item_from = get_sql_from('item_caisse_journaliere');
	$res = sql("select {$item_fields} from {$item_from} and item_caisse_journaliere.link_out={$order_id}", $eo);
	while($row = db_fetch_assoc($res)){
		$row['LineTotal1'] = str_replace('$', '', $row['achats']);
		$items[] = $row;
		$order_total1 += $row['LineTotal1'];
	}
	
	== total colonne ventes==
	$items = array();
	$order_total2 = 0;
	$item_fields = get_sql_fields('item_caisse_journaliere');
	$item_from = get_sql_from('item_caisse_journaliere');
	$res = sql("select {$item_fields} from {$item_from} and item_caisse_journaliere.link_out={$order_id}", $eo);
	while($row = db_fetch_assoc($res)){
		$row['LineTotal2'] = str_replace('$', '', $row['ventes']);
		$items[] = $row;
		$order_total2 += $row['LineTotal2'];
	}
	*/
	?>
	<!-- 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/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>
	
	<div class="row">
		<div class="col-sm-6">
			<!-- customer info -->
			<h2>CAISSE JOURNALIERE</h2>
		</div>
		<div class="col-sm-6 text-right">
			<!-- invoice info -->
			<h5>Date : <?php echo $order['date']; ?></h5>
			<h5>N°<?php echo $order['idcaisse_journaliere']; ?></h5>
		</div>
	</div>
	<!-- order items -->
	<table class="table table-striped table-bordered">
		<thead>
			<th class="text-center">#</th>
			<th>N°ORDRE</th>
			<th>NOM ET PRENOM</th>
			<th class="text-center">P. JUSTIFICATIVE</th>
			<th class="text-center">DESTINATION</th>
			<th class="text-center">COMPAGNIE/AGENCE</th>
			<th class="text-center">PRIX HT</th>
			<th class="text-center">COMMISSION</th>
			<th class="text-center">PRIX TTC</th>
			<th class="text-center">OBSERVATION</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['iditem_caisse_journaliere']; ?></td>
				<td><?php echo $item['nom_prenom']; ?></td>
				<td class="text-center"><?php echo $item['justificatif']; ?></td>
				<td class="text-center"><?php echo $item['destination']; ?></td>
				<td class="text-center"><?php echo $item['compagnie']; ?></td>
				<td class="text-center"><?php echo $item['prix_ht']; ?></td>
				<td class="text-center"><?php echo $item['commission']; ?></td>
				<td class="text-center"><?php echo $item['prix_ttc']; ?></td>
				<td class="text-center"><?php echo $item['observations']; ?></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> 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");

?>
