<?php
include("../librerias/php/header.php");
//include("../librerias/php/arrays/imagenes_items.php"); // solo las imagenes principales
#
 
#
 
  $id_vendedor = $_POST['id_vendedor'];
  $mes = $_POST['mes'];
  $ano = $_POST['ano'];

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo "Informe De Comisiones $mes/$ano ";  ?></title>
<style type="text/css">

body {
	margin-left: 10px;
	margin-top: 10px;
	margin-right: 10px;
	margin-bottom: 10px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #000000;
}
a:hover {
	text-decoration: none;
	color: #FF0000;
}
a:active {
	text-decoration: none;
	color: #000000;
}

</style>
<link href="../css/estilos.css" rel="stylesheet" type="text/css" />
</head>

<body onload="javascript:window.print()">






 
  <table width="770" border="0" cellspacing="2" cellpadding="2">
    <tr>
      <td width="300" align="left" valign="middle">
  <fieldset >
  
  
  
  <table width="100%" border="0" cellspacing="2" cellpadding="2">
    <tr>
      <td   align="left" class="arial14bold"  >
	  <?php 
	  
 
	echo "$razon_social_pyme"; 
	echo "<br>RUT $rut_pyme Giro: $giro_pyme";
	echo "<br>$direccion_pyme - $comuna_pyme";
	echo "<br>Fonos: $fono_pyme - Mail: $email_pyme";

	//echo "<img src='qr.png' width='50' height='50'>";
  
  
  ?></td>
  
  
      <td   align="right" class="arial14bold"  >
      
      
 <img src="../../home/<?php echo $rut_pyme_singuion;?>/almacen_pyme/logo.png"   />	 
  
  </td>
  
  
  
  
    </tr>
  </table>
  
  
  
  
  
  </fieldset>
  </td>

    </tr>
</table>





















 
<table width="770" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="300" align="left" valign="middle">
<fieldset>  
  
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td   width="70"  align="left" class="arial14bold"  >
<?php  
echo "<img src='qr.png' width='50' height='50' >";
?>
</td>
<td  width="0" align="center" class="arial14bold"  >
<?php 
echo "<span  class='arial16bold'>$nombre_modulo Nº ".number_format($folio,0,",",".")."</span>";
echo "<br><span  class='arial12bold'>Fecha Ingreso: $fecha_solicitud</span>";
?>
</td>
</tr>
</table>


</fieldset>
</tr>
</table>


<?php
  if($id_vendedor=='T'){
    $filtro_vendedor='';
    $nombre_vendedor = " Todos los vendedores";

  }else{
    $filtro_vendedor= " and id_vendedor='$id_vendedor' ";
    $sql = EjecutarSql( "select paterno, nombres from tbl_empleados where id_empleado='$id_vendedor'");
    while($r= ListarSql($sql)){
      $nombre_vendedor= $r['nombres'].' '.$r['paterno'];
    }
  }




$sql = "select porc_comision,porc_comision_meta,meta_mensual from tbl_empleados where id_empleado='$id_vendedor'";
$rsl=mysql_query($sql,$link_sistema);
$pcom=mysql_result($rsl,0,0);
$pcom_meta=mysql_result($rsl,0,1);
$meta_mensual=mysql_result($rsl,0,2);


?> 




  <table width="770" border="0" cellspacing="2" cellpadding="2">
    <tr>
      <td width="0" align="left" valign="middle">
  <fieldset >
<legend class="arial12bold">Ventas:  <?php echo $nombre_vendedor;?></legend>




    <table >
                                    <thead>
                                        <tr>
                                            <th class="col-xs-1">DOCUMENTO</th>
                                            <th class="col-xs-1">FECHA</th>
                                            <th class="col-xs-2">CLIENTE</th>
                                            <th class="col-xs-2">NETO</th>
                                            <th class="col-xs-2">COMISIÓN</th>
                                        </tr>
                                    </thead>
                                    <tbody>
          <?php 




 
 
  
 

#
$sql = "select sum(neto) from tbl_ventas where fecha_facturacion like '%/$mes/$ano' $filtro_vendedor and estado='PR'";
$rsl=mysql_query($sql,$link_sistema);
$neto_fv=mysql_result($rsl,0,0);

#
$sql = "select sum(neto) from tbl_ventas_boleta where fecha_facturacion like '%/$mes/$ano' $filtro_vendedor and estado='PR'";
$rsl=mysql_query($sql,$link_sistema);
$neto_bv=mysql_result($rsl,0,0);

#
$sql = "select sum(neto) from tbl_ventas_credito where fecha_facturacion like '%/$mes/$ano' $filtro_vendedor and estado='PR'";
$rsl=mysql_query($sql,$link_sistema);
$neto_nc=mysql_result($rsl,0,0);

$neto=($neto_fv+$neto_bv)-$neto_nc;


if($neto>=$meta_mensual){
  $comision_porcentaje=$pcom_meta;
}else{
  $comision_porcentaje=$pcom;
}
#
$sql = "select * from tbl_ventas where fecha_facturacion like '%/$mes/$ano' $filtro_vendedor and  estado='PR' order by  folio_factura asc";
$result_1=EjecutarSql($sql);
while($row_1 = mysql_fetch_array($result_1)) {
  $i++;
  #
  $id=utf8_encode($row_1["id"]);
  $folio=utf8_encode($row_1["folio"]);
  $folio_factura=utf8_encode($row_1["folio_factura"]);
  $fecha_facturacion=utf8_encode($row_1["fecha_facturacion"]);
   $razon_social=utf8_encode($row_1["razon_social"]);
   
$neto=utf8_encode($row_1["neto"]);

  $comision_pesos=round( ($neto*$comision_porcentaje)/100 );

  $suma_subtotal=$suma_subtotal+$neto;
     

  
  
  
  print "<tr  >";
  print "<td class='col-xs-1'>Fact.$folio_factura</td>";
  print "<td class='col-xs-1'>$fecha_facturacion</td>";
  print "<td class='col-xs-2'><small>".substr($razon_social,0,25)."</small></td>";
  print "<td class='col-xs-2'><small>$ $simb".@number_format($neto,0,",",".")."</td>";
 
  print "<td class='col-xs-2'><small>$ ".@number_format($comision_pesos,0,",",".")."&nbsp;&nbsp;&nbsp; ( ".@number_format($comision_porcentaje,0,",",".")." % )</td>";  
  print "</tr>";
}//FIN FACTURAS




// INICIO BOLETAS


$sql = "select * from tbl_ventas_boleta where 
fecha_facturacion like '%/$mes/$ano' $filtro_vendedor order by folio_factura asc";
$result_1=EjecutarSql($sql);
while($row_1 = ListarSql($result_1)) {
  $i++;
  #
  $id=utf8_encode($row_1["id"]);
  $folio=utf8_encode($row_1["folio"]);
  $folio_factura=utf8_encode($row_1["folio_factura"]);
  $fecha_facturacion=utf8_encode($row_1["fecha_facturacion"]);
   $razon_social=utf8_encode($row_1["razon_social"]);  
  $neto=utf8_encode($row_1["neto"]);

  $comision_pesos=round( ($neto*$comision_porcentaje)/100 );

  $suma_subtotal=$suma_subtotal+$neto;
   

  
  
  
  print "<tr  >";
  print "<td class='col-xs-1'>Bol.$folio_factura</td>";
  print "<td class='col-xs-1'>$fecha_facturacion</td>";
  print "<td class='col-xs-2'><small>".substr($razon_social,0,30)."</small></td>";
  print "<td class='col-xs-2'><small>$ $simb".@number_format($neto,0,",",".")."</td>";
 
  print "<td class='col-xs-2'><small>$ ".@number_format($comision_pesos,0,",",".")."&nbsp;&nbsp;&nbsp; ( ".@number_format($comision_porcentaje,0,",",".")." % )</td>";  
  print "</tr>";
}
        

//FIN BOLETAS




// inicio notas credito

$sql = "select * from tbl_ventas_credito where 
fecha_facturacion like '%/$mes/$ano' $filtro_vendedor order by folio_notacredito asc";
$result_1=EjecutarSql($sql);
while($row_1 = ListarSql($result_1)) {
  $i++;
  #
   
   
  $folio_notacredito=utf8_encode($row_1["folio_notacredito"]);
  $fecha_facturacion=utf8_encode($row_1["fecha_facturacion"]);
   $razon_social=utf8_encode($row_1["razon_social"]);  
  $neto=utf8_encode($row_1["neto"]);

  $comision_pesos=round( ($neto*$comision_porcentaje)/100 );

  $suma_subtotal=$suma_subtotal-$neto;
   

  
  
  
  print "<tr  >";
  print "<td class='col-xs-1'>N.C.$folio_notacredito</td>";
  print "<td class='col-xs-1'>$fecha_facturacion</td>";
  print "<td class='col-xs-2'><small>".substr($razon_social,0,30)."</small></td>";
  print "<td class='col-xs-2'><small>-$ $simb".@number_format($neto,0,",",".")."</td>";
 
  print "<td class='col-xs-2'><small>-$ ".@number_format($comision_pesos,0,",",".")."&nbsp;&nbsp;&nbsp; ( ".@number_format($comision_porcentaje,0,",",".")." % )</td>"; 
  print "</tr>";
}

// fin notas credito

$suma_monto_comision=round(  ($suma_subtotal*$comision_porcentaje)/100  );

          ?>
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <td class='col-xs-1'>&nbsp;</td>
                                            <td class='col-xs-1'>&nbsp;</td>
                                            <td class='col-xs-2'><b>TOTALES</b></td>
                                            <td class='col-xs-2'><b><?php echo "$ ".number_format($suma_subtotal,0,",","."); ?></b></td>
                                            
                                            <td class='col-xs-2'><b><?php echo "$ ".number_format($suma_monto_comision,0,",",".")."&nbsp;&nbsp;&nbsp;( ".number_format($comision_porcentaje,0,",",".")."% )"; ?></b></td>
                                        </tr>
                                    </tfoot>                                    
                                </table>


  </fieldset>
</td>
    </tr>
</table> 













 
 
 
 


 
 
 
  <table width="770" border="0" cellspacing="2" cellpadding="2">
    <tr>
      <td width="0" align="left" valign="middle">
  <fieldset >
<legend class="arial12bold">REGISTRO DE IMPRESIÓN:</legend>
  <table width="100%" border="0" cellpadding="2" cellspacing="0" bordercolor="#999999" style="border-collapse:collapse;">
 
	  <?php 
 
 
	echo '  <tr bgcolor="#FFFFFF" class="arial12">';
	
 
	
	echo '<td width="0" align="left" valign="middle">';	
	echo "Fecha: $fecha_actual &nbsp;&nbsp; | &nbsp;&nbsp; Hora: $hora_actual &nbsp;&nbsp; | &nbsp;&nbsp; Usuario: $usuario_sistema";
	
	
	echo '</td>';	
	
	echo '</tr>';
	$glosa
 
		
		 ?>  
 	 
</table>  
  
  </fieldset>
</td>
    </tr>
</table> 



</body>
</html>
<?php
include("../../librerias/php/footer.php");
?>
