<?
session_start();
require('../valtiempoinact.php');
require("../conectar.php");
require("libFormato.php");
$fi=$_GET["fechaini"];
$ff=$_GET["fechafin"];
function convierte($fi,$ff){
    $ano = substr($fi, 0, 4);
    $mes = substr($fi, 5, 2);
    $dia = substr($fi, 8,2);
    $ano2 = substr($ff, 0, 4);
    $mes2 = substr($ff, 5, 2);
    $dia2 = substr($ff, 8,2);
switch ($mes){
   case 1:
   $meses="Enero";
   break;
   case 2:
   $meses="Febrero";
   break;
   case 3:
   $meses="Marzo";
   break;
   case 4:
   $meses="Abril";
   break;
   case 5:
   $meses="Mayo";
   break;
   case 6:
   $meses="Junio";
   break;
   case 7:
   $meses="Julio";
   break;
   case 8:
   $meses="Agosto";
   break;
   case 9:
   $meses="Septiembre";
   break;
   case 10:
   $meses="Octubre";
   break;
   case 11:
   $meses="Noviembre";
   break;
   case 12:
   $meses="Diciembre";
   break;
  }
 switch ($mes2){
   case 1:
   $meses2="Enero";
   break;
   case 2:
   $meses2="Febrero";
   break;
   case 3:
   $meses2="Marzo";
   break;
   case 4:
   $meses2="Abril";
   break;
   case 5:
   $meses2="Mayo";
   break;
   case 6:
   $meses2="Junio";
   break;
   case 7:
   $meses2="Julio";
   break;
   case 8:
   $meses2="Agosto";
   break;
   case 9:
   $meses2="Septiembre";
   break;
   case 10:
   $meses2="Octubre";
   break;
   case 11:
   $meses2="Noviembre";
   break;
   case 12:
   $meses2="Diciembre";
   break;
  }
$periodo=$dia." de ".$meses." del ".$ano." <b>al</b> ".$dia2." de ".$meses2." del ".$ano2;  
return $periodo;
}
?>
<!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>
<script language="javascript" src="js/jquery-1.2.6.min.js"></script>
<script>
function validapago(pago,accion)
{
var ch=document.getElementById('val'+accion).checked;
var checado;
if(ch==true){checado="s";}else{checado="";}
 $.post("valpagoadmon.php", {pago:pago,valor:checado}, function(data){
	 $("#validado"+accion).html(data);
	 });
}
</script>
	     <style>
.dts{border-collapse:collapse;font-family:arial;font-size:11px;width:100%;}
.categoria{position:relative;width:260px;padding-top:3px;padding-bottom:3px;text-align:center;font-size:11px;font-family:arial;background:#FFFFFF;border-bottom:1px solid #BDBDBD;border-top:1px solid #BDBDBD;color:#848484;}
.categoriaB{position:relative;width:260px;padding-top:3px;padding-bottom:3px;text-align:center;font-size:11px;font-family:arial;background:#FFFFFF;border-bottom:1px solid #BDBDBD;border-top:1px solid #BDBDBD;color:#000000;}
.tr1{background:#D8D8D8;}
.tr2{background:#F2F2F2;}
.dts{border-collapse:collapse;font-family:arial;font-size:9px;width:100%;}
.lineadiv{border-right:solid 1px #000000;border-left:solid 1px #000000;border-bottom:solid 1px #000000;color:#000000;}
.fondop{background-color:#F9F263;}
.fondor{background-color:#C6E06D;}
.fondod{background-color:#A9D0F5;}
	     </style>
	 </head>
	 <body>

		   <center>
	         <table class="dts">
				 <tr class="categoriaB">
						     <td colspan='26' align="center" class="tds">INGRESOS PERIODO <?echo convierte($fi,$ff);?></td>
					</tr>
				 <tr class="categoriaB">
				   <td colspan="6"></td>
				   <td align="center" colspan="2" class="lineadiv" style="background-color:rgb(103, 214, 143)"><b>PROPIEDAD</b></td>
				   <td colspan="5"></td><td align="center" colspan="2" class="lineadiv" style="background-color:rgb(103, 214, 143)"><b>TOTAL PAGADAS</b></td>
				   <td colspan="3"></td>
				   </tr>
				 <tr class="categoriaB">
				     <td align="center" class="lineadiv"><b>No</b></td>
				     <td align="center" class="lineadiv"><b>Fecha</b></td>
					 <td align="center" class="lineadiv"><b>Turno</b></td>
					 <td align="center" class="lineadiv"><b>Coord</b></td>
					 <td align="center" class="lineadiv"><b>Ejecutivo</b></td>
					 <td align="center" class="lineadiv"><b>Recibio</b></td>
					 <td align="center" class="lineadiv"><b>Edificio</b></td>
					 <td align="center" class="lineadiv"><b>Departamento</b></td>
					 <td align="center" class="lineadiv"><b>Medio</b></td>
					 <td align="center" class="lineadiv"><b>Submedio</b></td>
					 <td align="center" class="lineadiv"><b>A. Paterno</b></td>
					 <td align="center" class="lineadiv"><b>A. Materno</b></td>
					 <td align="center" class="lineadiv"><b>Nombre</b></td>
					 <td align="center" class="lineadiv"><b>Forma de Pago</b></td>
					 <td align="center" class="lineadiv"><b>Concepto</b></td>
					 <td align="center" class="lineadiv"><b>Dolares</b></td>
					 <td align="center" class="lineadiv"><b>Pesos</b></td>
					 <td align="center" class="lineadiv"><b>Numero Noches</b></td>
					 <td align="center" class="lineadiv"><b>$ Noches</b></td>
					 <td align="center" class="lineadiv"><b>Numero Sem</b></td>
					 <td align="center" class="lineadiv"><b>$ Sem</b></td>
					 <td align="center" class="lineadiv"><b>Numero Mes</b></td>
					 <td align="center" class="lineadiv"><b>$ Mes</b></td>
					 <td align="center" class="lineadiv"><b>Numero Aņos</b></td>
					 <td align="center" class="lineadiv"><b>$ Aņos</b></td>
					 <td align="center" class="lineadiv"><b>Tipo de Cambio</b></td>
					 <td align="center" class="lineadiv"><b>Comp.</b></td>
					 <td align="center" class="lineadiv"><b>Valido</b></td>
				 </tr>
				 <?
				    $sql="SELECT p.id_renta,p.comprobante,p.usu_val,p.id_pago,p.fecha as fecha,p.concepto as concepto,p.formapago as fpago, p.monto as cantidad, p.tipo_moneda as moneda, p.divisa as divisa, p.f_entrada as entrada, p.f_salida as salida,p.valadmon,p.id_concepto, c.nombre as propiedad, d.clave as clave, e.nombre as nombre, e.a_pat as apat,e.turno FROM pagos as p  INNER JOIN complejo as cm ON p.propiedad=cm.id_complejo INNER JOIN complejo as c ON p.propiedad=c.id_complejo INNER JOIN  departamentos as d ON p.clave=d.id_departamento INNER JOIN empleados as e ON p.id_emp=e.id_empleado WHERE p.fecha between '$fi' and '$ff' and valadmon='s' and concepto NOT IN('DEPOSITO','IMPUESTOS') order by p.fecha asc";
					$re=mysql_query($sql);
					$k=1;
					$f=1;
					while($ls=mysql_fetch_array($re)){
					if($f==1){$f=2;}else{$f=1;}
					     if($ls['valadmon']=='s'){$ch="checked";$img="<img src='images/emok.png' width='15' height='15' border='0'>";}else{$ch="";$img="";}
						 $renta="select pa.id_renta,r.id_cliente,r.id_coordinador,r.id_ejecutivo,r.medio,r.submedio,c.a_pat,c.a_mat,c.nombre from pagos as pa INNER JOIN renta r ON pa.id_renta=r.id_renta 	
						 INNER JOIN clientes c ON r.id_cliente=c.id_cliente where pa.id_renta='$ls[id_renta]'";
						 $ejerenta=mysql_query($renta);
						 $rta=mysql_fetch_array($ejerenta);
						 $cliente=$rta['a_pat']." ".$rta['a_mat']." ".$rta['nombre'];
						 $nomcliente=htmlentities($cliente);
						 $idcliente=$rta['id_cliente'];
						 $idrenta=$rta['id_renta'];
						 $coordi=$rta['id_coordinador'];
						 $ejec=$rta['id_ejecutivo'];
						 
						 //medio y submedio
						 $sqlmed="select canal from medio where id='$rta[medio]'";
						 $ejemed=mysql_query($sqlmed);
						 $med=mysql_fetch_array($ejemed);
						 $medio=$med['canal'];
						 
						 $sqlsubmed="select subcanal from submedio where idsubmedio='$rta[submedio]'";
						 $ejesubmed=mysql_query($sqlsubmed);
						 $submed=mysql_fetch_array($ejesubmed);
						 $submedio=$submed['subcanal'];
					 
						 //coordi
						 $coor="SELECT concat(nombre,' ',a_pat,' ',a_mat) as coor FROM empleados WHERE id_empleado='$coordi'";
						 $qc=mysql_query($coor);
						 $c=mysql_fetch_array($qc);
						 $coordinador=$c["coor"];
						 //ejecutivo
						 $eje="SELECT concat(nombre,' ',a_pat,' ',a_mat) as ejecutivo FROM empleados WHERE id_empleado='$ejec'";
						 $qe=mysql_query($eje);
						 $ej=mysql_fetch_array($qe);
						 $ejecutivo=$ej["ejecutivo"];
						 
						 $select="SELECT nombre, a_pat FROM empleados WHERE id_empleado='$ls[usu_val]'";
						 $q=mysql_query($select);
						 $e=mysql_fetch_array($q);
						 $admonval=$e["nombre"]." ".$e["a_pat"];
					    ?>
						 <tr class="tr<?echo $f;?>">
						     <td class="lineadiv"><?echo $k;?></td>
						     <td class="lineadiv"><?echo $ls['fecha'];?></td>
							 <td class="lineadiv"><?echo $ls['turno'];?></td>
							 <td class="lineadiv"><?echo $coordinador;?></td>
							 <td class="lineadiv"><?echo $ejecutivo;?></td>
						     <td class="lineadiv"><?echo htmlentities($ls['nombre'])." ".htmlentities($ls['apat'])?></td>
							 <td class="lineadiv"><?echo $ls['propiedad'];?></td>
							 <td class="lineadiv"><?echo $ls['clave'];?></td>
							 <td class="lineadiv"><?echo $medio;?></td>
							 <td class="lineadiv"><?echo $submedio;?></td>
							 <td class="lineadiv"><a href="regmodificar2.php?idcliente=<?echo$idcliente;?>&idrenta=<?echo$idrenta;?>" target="_blank"><?echo$rta['a_pat'];?></a></td>
							 <td class="lineadiv"><a href="regmodificar2.php?idcliente=<?echo$idcliente;?>&idrenta=<?echo$idrenta;?>" target="_blank"><?echo$rta['a_mat'];?></a></td>
							 <td class="lineadiv"><a href="regmodificar2.php?idcliente=<?echo$idcliente;?>&idrenta=<?echo$idrenta;?>" target="_blank"><?echo$rta['nombre'];?></a></td>
							 <td class="lineadiv">
							 <?
							 if($ls['fpago']=="EFECTIVO" && $ls['moneda']=="MXN"){$mon="EP";
							 }elseif($ls['fpago']=="EFECTIVO" && $ls['moneda']=="USD"){$mon="ED";}else{$mon=$ls['fpago'];}
							 echo $mon;
							 ?></td>
						     <td class="lineadiv"><?echo $ls['concepto'];?></td>
							 <td class="lineadiv" style="background-color:rgb(241, 217, 90)"><?if($ls['moneda']=="USD"){echo "<b>".Moneda($ls['cantidad'])."</b>";$totalUSD=$totalUSD+$ls['cantidad'];}?></td>
							 <td class="lineadiv" style="background-color:rgb(241, 217, 90)"><?if($ls['moneda']=="MXN"){echo "<b>".Moneda($ls['cantidad'])."<b>";$totalMXN=$totalMXN+$ls['cantidad'];}?></td>
							 <?
							 $con="select c.no_dias as noche,c.no_sem as sem,c.no_meses as mes,c.no_anios as ano,c.tarifa,c.id_departamento from pagos as pa INNER JOIN conceptos c ON pa.id_concepto=c.id_concepto where pa.id_concepto='$ls[id_concepto]' and pa.concepto='RENTA' and pa.propiedad=c.id_complejo and pa.clave=id_departamento";
							 $co=mysql_query($con);
							 $nsma=mysql_fetch_array($co);
							 $noche=$nsma['noche'];
							 $sem=$nsma['sem'];
							 $mes=$nsma['mes'];
							 $ano=$nsma['ano'];
							 
							 
							 if($mes==1){$campo="mes";}
							 if($mes>=2 && $mes<=4){$campo="2a4";}
							 if($mes>=5 && $mes<=8){$campo="5a8";}
							 
							 $tarifa=$nsma['tarifa'];
                             if($tarifa=="ta"){$tar="tarifa_alta";}
							 if($tarifa=="tm"){$tar="tarifa_media";}
							 if($tarifa=="tb"){$tar="tarifa_baja";}	
							 if($tarifa=="tmb"){$tar="tarifa_muybaja";}
							 $t="select * from $tar where id_departamento='$nsma[id_departamento]'";
							 $ta=mysql_query($t);
							 $costo=mysql_fetch_array($ta);
							 if($noche!=0){$cnoche=$costo['noche'];}else{$cnoche=0;}
							 if($sem!=0){$csem=$costo['semana'];}else{$csem=0;}
							 if($mes!=0){$cmes=$costo[$campo];}else{$cmes=0;}
							 if($ano!=0){$cano=$costo['anual'];}else{$cano=0;}
							 ?>
							 <!--<td><? echo "depto-".$nsma['id_departamento'];?></td>
							 <td><? echo $nsma['tarifa'];?></td>-->
							 <td class="lineadiv"><?echo $noche;?></td>
							 <td class="lineadiv"><?echo $cnoche?></td>
							 <td class="lineadiv"><?echo $sem;?></td>
							 <td class="lineadiv"><?echo $csem;?></td>
							 <td class="lineadiv"><?echo $mes;?></td>
							 <td class="lineadiv"><?echo $cmes;?></td>
							 <td class="lineadiv"><?echo $ano;?></td>
							 <td class="lineadiv"><?echo $cano;?></td>
						     <td align="right" class="lineadiv"><font style="float:left">$</font><?echo $ls['divisa']?></td>
						     <td class="lineadiv" align="center"><?if($ls["comprobante"]==""){echo "";}else{?><a href="<?echo $ls["comprobante"];?>" target="_blank"><img src="images/zoom.png" width="18" height="18" border='0' style="margin-left:-5px;" alt="Ver comprobante"></a><?}?></td>
							 <td class="lineadiv"><?echo $admonval?></td>
						 </tr>
						<?
						$k++;
					}?>
					<tr class="trb"><td colspan="15" class="lineadiv"></td><td class="lineadiv"><b><?echo Moneda($totalUSD);?></b></td><td class="lineadiv"><b><?echo Moneda($totalMXN);?></b></td><td colspan="11" class="lineadiv"></td></tr>
					<?if($k==1){
					    ?>
						<tr class="trb">
						     <td colspan='13' align="center">No se encontraron pagos nuevos por el concepto de RENTA</td>
						 </tr>
						<?
					}
					?>
		     </table>
			 <br>
			 <br>
			 <br>
			 <br>
			 <br>
			</center>

	 </body>
</html>	