<style type="text/css">
<!--
div.zone
{
    border: solid 0.5mm red;
    border-radius: 2mm;
    padding: 1mm;
    background-color: #FFF;
    color: #440000;
}
div.zone_over
{
    width: 30mm;
    height: 20mm;
    
}
.bordeado
{
	border: solid 0.5mm #eee;
	border-radius: 1mm;
	padding: 0mm;
	font-size:12px;
}
.table {
  border-spacing: 0;
  border-collapse: collapse;
}
.table-bordered td, .table-bordered th {
  padding: 3px;
  text-align: left;
  vertical-align: top;
}
.table-bordered {
  border: 0px solid #eee;
  border-collapse: separate;
  
  -webkit-border-radius: 4px;
     -moz-border-radius: 4px;
          border-radius: 4px;
}
.left{
	border-left: 1px solid #eee;
	
}
.top{
	border-top: 1px solid #eee;
}
.bottom{
	border-bottom: 1px solid #eee;
}
table.page_footer {width: 100%; border: none; background-color: white; padding: 2mm;border-collapse:collapse; border: none;}

-->
</style>
<page backtop="20mm" backbottom="15mm" backleft="15mm" backright="15mm" style="font-size: 13px; font-family: helvetica" backimg="">
	<?php 
	$title_report='Reporte de utilidades';
	include('page_header_footer.php');
	
	?>

	
	<div style='border-bottom: 3px solid #2ecc71;padding-bottom:10px'>
		
	</div>

	
	
	
  
    <table class="table-bordered" style="width:100%;" cellspacing=0>
        <tr>
			<th class='top bottom'  style="width: 12%;text-align:center">Factura Nº</th>
            <th class='top bottom'  style="width: 40%;">Cliente</th>
            <th class='top bottom'  style="width: 12%;text-align:center">Fecha</th>
            <th class='top bottom'  style="width: 12%;text-align:right">T. Costo</th>
			<th class='top bottom'  style="width: 12%;text-align:right">T. Venta</th>
			<th class='top bottom'  style="width: 12%;text-align:right">T. Utilidad</th>
            
        </tr>
		<?php
		$sumador_subtotal=0;
		$sumador_costo=0;
		$sumador_total=0;
		while($row=mysqli_fetch_array($query)){
			$sale_number=$row['sale_number'];
			$customer_id=$row['customer_id'];
			$sql_customer=mysqli_query($con,"select name from customers where id='".$customer_id."'");
			$rw_customer=mysqli_fetch_array($sql_customer);
			$customer_name=isset($rw_customer['name'])?$rw_customer['name']:'';
			$date_added=$row['sale_date'];
			$user_fullname=$row['fullname'];
			$subtotal=$row['subtotal'];
			$tax=$row['tax'];
			$total=$row['total'];
			$total_costo=$row['total_cost'];
			$total_utilidad=$subtotal-$total_costo;
			$sumador_costo+=$total_costo;
			$sumador_subtotal+=$subtotal;
			$sumador_total+=$total_utilidad;
			
			
			list($date,$hora)=explode(" ",$date_added);
			list($Y,$m,$d)=explode("-",$date);
			$fecha=$d."-".$m."-".$Y;
			
			?>
				<tr>
					<td class='bottom' style="width: 12%;text-align:center"><?php echo $sale_number;?></td>
					<td class='bottom' style="width: 40%;"><?php echo $customer_name;?></td>
					<td class='bottom' style="width: 12%;text-align:center"><?php echo $fecha;?></td>
					<td class='bottom' style="width: 12%;text-align:right"><?php echo number_format($total_costo,$currency_format['precision_currency'],$currency_format['decimal_separator'],$currency_format['thousand_separator']);?></td>
					<td class='bottom' style="width: 12%;text-align:right"><?php echo number_format($subtotal,$currency_format['precision_currency'],$currency_format['decimal_separator'],$currency_format['thousand_separator']);?></td>
					<td class='bottom' style="width: 12%;text-align:right"><?php echo number_format($total_utilidad,$currency_format['precision_currency'],$currency_format['decimal_separator'],$currency_format['thousand_separator']);?></td>
				</tr>
			<?php 
		}
		
		?>
		<tr>
				<td colspan=3 style='text-align:right;border-top:3px solid #2ecc71;padding:4px;padding-top:4px;font-size:14px'><strong>Totales <?php echo $moneda;?></strong></td>
				<td style='text-align:right;border-top:3px solid #2ecc71;padding:4px;padding-top:4px;font-size:14px'><?php echo number_format($sumador_costo,$currency_format['precision_currency'],$currency_format['decimal_separator'],$currency_format['thousand_separator']);?></td>
				<td style='text-align:right;border-top:3px solid #2ecc71;padding:4px;padding-top:4px;font-size:14px'><?php echo number_format($sumador_subtotal,$currency_format['precision_currency'],$currency_format['decimal_separator'],$currency_format['thousand_separator']);?></td>
				<td style='text-align:right;border-top:3px solid #2ecc71;padding:4px;padding-top:4px;font-size:14px'><?php echo number_format($sumador_total,$currency_format['precision_currency'],$currency_format['decimal_separator'],$currency_format['thousand_separator']);?></td>
		</tr>
	 </table>
</page>

