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

	/* get invoice */
	$order_id = intval($_REQUEST['iddecompte']);
	if(!$order_id) exit(error_message('Invalid invoice ID!', false));
	
	/* retrieve facturations info */
	$order_fields = get_sql_fields('decomptes');
	$res = sql("select {$order_fields} from {$order_from} and iddecompte={$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('details_decompte');
	$item_from = get_sql_from('details_decompte');
	$res = sql("select {$item_fields} from {$item_from} and details_decompte.to_decomptes={$order_id}", $eo);
	while($row = db_fetch_assoc($res)){
		$row['LineTotal'] = str_replace('$', '', $row['salaire_moyen']) * $row['pourcentage'] * $row['coef'] / 100;
		$items[] = $row;
		$order_total += $row['LineTotal'];
	}
	//var_dump($items);
	
	?>
	
	<html>
<head>
	<title></title>
<style type="text/css" media="print">
input.imprimer
{
display:none;
}
</style>
 
</head>
 
<body>

<form method="POST" action="">
 
<input type="button" value="Imprimer" class="imprimer" name="bnom" onClick="javascript:window.print()">
</form>

</body>
 
</html>
	
	<br>
	<br>
	<br>
	<br>
	<br>
	<br>



	<div class="row">
		<div class="col-sm-6">
			<!-- customer info -->
			<h5><u>NOM ET PRENOM :</u> &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp;&ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp;<?php echo $order['nom_prenom']; ?></h5>
			<h5><u>NNI :</u> &ensp; &ensp; &ensp; &ensp; &ensp;&ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp;&ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp;<?php echo $order['nni']; ?></h5>
			<h5><u>N° COMPTE & BANQUE :</u>&ensp; &ensp; &ensp;&ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp;<?php echo $order['num_cpte']; ?></h5>
			<h5><u>DATE D'ENGAGEMENT :</u> &ensp; &ensp; &ensp;&ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp;<?php echo $order['date_recrutement']; ?></h5>
			<h5><u>DATE DE DEPART :</u> &ensp; &ensp; &ensp; &ensp; &ensp; &ensp;&ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp;<?php echo $order['date_depart']; ?></h5>
			<h5><u>ANCIENNETE :</u> &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp;&ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp;<?php echo $order['anciennete']; ?> ANS</h5>
			<h5><u>SALAIRE MENSUEL MOYEN :</u> &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp; &ensp;<?php echo $order['salaire_m_m']; ?> NUM</h5>
		</div>
		<div class="col-sm-6 text-right">
			<!-- invoice info 
			<h5>Fait à Nouakchott le : <?php echo $order['date_demande_c']; ?></h5>
			-->
		</div>
	</div>
	
	<hr>
	
	<!-- order items -->
	<table class="table table-striped table-bordered">
		<thead>
			<th>TRANCHES</th>
			<th class="text-center">PERIODES</th>
			<th class="text-center">POURCENTAGE</th>
			<th class="text-center">COEFFICIENT PONDERATION</th>
			<th class="text-center">SALAIRE MOYEN</th>
			<th class="text-center">MONTANT</th>
		</thead>
		
		<tbody>
			<?php foreach($items as $i => $item){ ?>
				<tr>
					<td><?php echo $item['tranches']; ?></td>
					<td><?php echo $item['periodes']; ?></td>
					<td class="text-center"><?php echo $item['pourcentage']; ?></td>
					<td class="text-center"><?php echo $item['coef']; ?></td>
					<td class="text-center"><?php echo number_format($item['salaire_moyen'], 0, ',', ' '); ?></td>
					<td class="text-center"><?php echo number_format($item['montant'], 0, ',', ' '); ?></td>
				</tr>
			<?php } ?>
		</tbody>
		
		<tfoot>


			<tr>
				<th colspan="5" class="text-right">TOTAL DE L'INDEMNITE DE RETRAITE</th>
				<th class="text-right"> <?php echo number_format($order_total + $order['Freight'], 0, ',', ' '); ?></th>
			</tr>
			
			<tr>
				<th colspan="5" class="text-right">UN MOIS DE PREAVIS</th>
				<th class="text-right"> <?php echo number_format($item['mois_preavis'], 0, ',', ' '); ?></th>
			</tr>
			
			<tr>
				<th colspan="5" class="text-right">UN MOIS DE CONGE</th>
				<th class="text-right"> <?php echo number_format($item['mois_conge'], 0, ',', ' '); ?></th>
			</tr>
			
			<tr>
				<th colspan="5" class="text-right">TOTAL DES DROITS A ALLOUER EN NOUVELLE OUGUIYAS</th>
				<th class="text-right"> <?php echo number_format($order_total + $item['mois_conge'] + $item['mois_preavis'], 0, ',', ' '); ?></th>
			</tr>
			
		</tfoot>
	</table>

	<?php

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

?>
