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

	/* get invoice */
	$order_id = intval($_REQUEST['iddevis']);
	if(!$order_id) exit(error_message('Invalid quotation ID!', false));
	
	/* retrieve order info */
	$order_fields = get_sql_fields('devis');
	$res = sql("select {$order_fields} from {$order_from} and iddevis={$order_id}", $eo);
	if(!($order = db_fetch_assoc($res))) exit(error_message('Quotation not found!', false));
	
	//var_dump($order);
	
	/* retrieve order items */
	$items = array();
	$order_total = 0;
	$item_fields = get_sql_fields('detail_devis');
	$item_from = get_sql_from('detail_devis');
	$res = sql("select {$item_fields} from {$item_from} and detail_devis.devisid={$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);
	
	?>
	<br>
	<br>
	<br>
	<br>
	<br>
	<br>
	<br>
	<br>
	<br>
	<br>
	<br>
	<br>
<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="PRINT" class="imprimer" name="bnom" onClick="javascript:window.print()">
</form>

</body>
 
</html>

	<div class="row">
		<div class="col-sm-6">
			<!-- customer info -->
			<h5>CUSTOMER: <?php echo $order['client']; ?></h5>
			<h5>WORK REQUIRED: <?php echo $order['travaux']; ?></h5>
		</div>
		<div class="col-sm-6 text-right">
			<!-- invoice info -->
			<h1></h1>
			<h5>DATE: <?php echo $order['date']; ?></h5>
			<h5>No. <?php echo $order['numero']; ?></h5>
		</div>
	</div>
	
	<hr>
	
	<!-- order items -->
	<table class="table table-striped table-bordered">
		<thead>
			<th class="text-center">#</th>
			<th>DESCRIPTION</th>
			<th class="text-center">UNIT PRICE</th>
			<th class="text-center">QUANTITY</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 $item['prixunitaire']; ?></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>

	
	<?php

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

?>
