<?php
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DF30000.inc");
include("DF80000.php");
include("JQUERY.inc");
$mes = 0;
$dia = 0;
$anio = 0;
//function cambioCelda(celda){
//echo "hola";
//}
?>

<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>


<style type="text/css">
    <!--
    .Estilo2 {color: #000099}

    BODY {
        scrollbar-face-color:#000000; scrollbar-highlight-color: ; scrollbar-shadow-color: ; scrollbar-3dlight-color:#000000; 
        scrollbar-arrow-color: ; scrollbar-track-color: ; scrollbar-darkshadow-color:#000000;
    }
    -->
</style>
<link href="css/estilo1.css" rel="stylesheet" type="text/css">
<style type="text/css">
    <!--
    .Estilo3 {
      
        font-size: 14px;
    }
    .Estilo13 {
        
        font-size: 11px;
        font-weight: bold;
    }
    .Estilo5 {font-size: 16px}
    .Estilo16 {
        font-size: 18px;
        font-weight: bold;
    }

    -->
</style>

<body>

    <div align="center">
        <form name="form1" id="form1" method="post" action="">
            <table width="486" border="0" align="center">
                <tr>
                    <th colspan="2"><span class="Estilo5">CHART DE OCUPACI&Oacute;N X CUARTO</span></th>
                </tr>
                <tr>
                    <th width="344"> <input name="r1" type="radio" value="ffecllegada" tabindex="1">
                        PERIODO</th>
                    <th width="132"><input name="r1" type="radio" value="ncto" tabindex="2">
                        HABITACI&Oacute;N</th>
                </tr>
                <tr>
                    <td><div align="center">
                            <?php $fech = (isset($_POST['t1'])) ? $_POST['t1'] : date('d/m/Y'); ?>
                            <input name="t1" type="text" class="thcons datefrom" id="t1" size="15"  readonly onBlur="valFecha(this)" value="<?= $fech ?>"
                            <?php
                            if (isset($_POST['t1'])) {
                                echo 'value="' . $_POST['t1'] . '"';
                            } else {
                                echo 'value="' . date('d/m/Y') . '"';
                            }
                            ?>
                                   >
                            &nbsp;
                        <!--    <input name="reset2"  value=" ... " id="bot1" type="image" src="logos/cal4.jpg"/>
                            --><span class="Estilo16">/</span>


                            <input name="t2" type="text" class="thcons dateto" id="t2" size="15" readonly onBlur="valFecha(this)" value="<?php
                            $tmt = mktime($mes, $dia, $anio);
                            $eft = $tmt + 604800; // Eso me dar�a el timestamp de la fecha sumada 120 minutos. 
                            $fecha = date("d/m/Y", $eft);
                            echo $fecha;
                            ?>"			 				
                                   <?php
                                   if (isset($_POST['t2'])) {
                                       echo 'value="' . $fecha . '"';
                                   } else {
                                       echo 'value="' . $fecha . '"';
                                   }
                                   ?>>
                            &nbsp;
                   <!--    <input name="reset" value=" ... " id="bot2" type="image" src="logos/cal4.jpg"/>
                            -->		
                        </div></td>
                    <td><div align="center">
                            <input name="s3" type="text" id="s3" onBlur="may(this)" size="15"/>
                        </div></td>
                </tr>
                <tr>
                    <td colspan="2"><div align="center">
                            <?php
                            include("DE10000.php");
                            ?>
                            <?php
                            $inicio = (isset($_POST['t1'])) ? $_POST['t1'] : "0";
                            $final = (isset($_POST['t2'])) ? $_POST['t2'] : "0";
                            ?> 
                            <input name="Submit" type="submit" class="original" value="Buscar" />
                    <!--	  <input name="bot4" type="button" class="bot_WsW" onClick="openpage('valeryus69000_IM.php?fec=<?php echo "" . $inicio . ""; ?>&fec2=<?php echo "" . $final . ""; ?>','_self')" value="Pdf"/>
                          input name="imprimir" type="button" class="original" value="Imprimir" onClick="envia('rec_disponibilidad_IM.php?fec=<?php //echo "".$inicio.""; ?>&fec2=<?php //echo "".$final.""; ?>','_self')"/>
                            <input name="bot4" type="button" class="bot_WsW" onClick="envia('valeryus69000_IME.php?fec=<?php //echo "".$inicio.""; ?>&fec2=<?php //echo "".$final.""; ?>','_self')" value="Excel"/-->
                        </div></td>
<?php
if (!isset($_POST['t1'])) {


    $f = mysqli_query($con ,"select n_reg,ffecllegada,ffecsalida,fnumcto,cancelado,status,fmuncto,fnumctos from valeryus19 where chart='0'");
    while ($r = mysqli_fetch_array($f)) {
        $d = mysqli_query($con ,"insert into chart set n_reg='" . $r['n_reg'] . "', ffecllegada='" . $r['ffecllegada'] . "', "
                . "ffecsalida='" . $r['ffecsalida'] . "', fnumcto='" . $r['fnumcto'] . "', cancelado='" . $r['cancelado'] . "',"
                . " status='" . $r['status'] . "', fmuncto='" . $r['fmuncto'] . "'");
        $s = mysqli_query($con ,"update valeryus19 set chart='1' where n_reg='" . $r['n_reg'] . "'");
    }

    $i = mysqli_query($con ,"SELECT n_reg, ffecllegada, ffecsalida, fnumcto, cancelado, status, fmuncto, extra1, fnumctos from valeryus19 where chart='1'");
    while ($y = mysqli_fetch_array($i)) {
        $u = mysqli_query($con ,"UPDATE chart set ffecllegada='" . $y['ffecllegada'] . "', ffecsalida='" . $y['ffecsalida'] . "', fnumcto='" . $y['fnumcto'] . "',
			           cancelado='" . $y['cancelado'] . "', status='" . $y['status'] . "', fmuncto='" . $y['fmuncto'] . "', extra1='" . $y['extra1'] . "', fnumctos='" . $y['fnumctos'] . "' 
			           where n_reg='" . $y['n_reg'] . "'");
    }
}
?>
                </tr>
            </table>
        </form>
    </div>
    <div align="center">
        <form name="frm1" id="frm1" method="post" action="" >
            <input name="botf1" type="hidden" value="
                    <?php
                    if (!isset($_POST['t1'])) {
                        echo date('d/m/Y');
                    } else {
                        echo $_POST['t1'];
                    }
                    ?>">
            <input name="botf2" type="hidden" value="
<?php
if (!isset($_POST['t1'])) {
    echo date('d/m/Y');
} else {
    echo $_POST['t2'];
}
?>">
            <?php
            if (isset($_POST['t1'])) {
                $fec = $_POST['t1'];
                include('DF20000.php');
                $ffecllegada = $f_m;
                $fec = $_POST['t2'];
                include('DF20000.php');
                $ffecsalida = $f_m;
            }
            ?>
            <table width="713" border='1' bordercolor="#FFFFFF" bordercolordark="#FFFFFF">
                <tr>
                    <th  colspan="61"><span class="Estilo2 Estilo3">CHART DE OCUPACI&Oacute;N X CUARTO</span></th>
                </tr>

                <tr>
                    <th width="104"><div align="center">HABITACI&Oacute;N</div>          </th>        <div align="center"></div>                
                <th width="593" colspan="60">FECHA
                    </tr>
                <tr>
                    <th>&nbsp; </th>

                   <?php
                   if (isset($_POST['t1'])) {
                       $fec = $_POST['t1'];
                       include('DF20000.php');
                       $ffecllegada = $f_m;
                       $fec = $_POST['t2'];
                       include('DF20000.php');
                       $ffecsalida = $f_m;

                       while (dateCmp($ffecllegada, $ffecsalida) <= 0) {
                           echo "<td><div class='Estilo13'> " . whatDay($ffecllegada) . " " . chfecha($ffecllegada, 'Y-m-d', 'dd') . "</div></td>";

                           $ffecllegada = addDay($ffecllegada, 1);
                       }
                   }
                   ?>        
                </tr>
                    <?php
                    $ocupadas = array();
                    $disponibles = array();
$totales=array();
                    if (isset($_POST['t1'])) {
                        $fec = $_POST['t1'];
                        include('DF20000.php');
                        $ffecllegada = $f_m;
                        $fec = $_POST['t2'];
                        include('DF20000.php');
                        $ffecsalida = $f_m;



                        $query = "folios, tipos";
                        $from = " FROM valeryus05 ";

                        $select = " SELECT descripcion,totalcuartos";
                        $col = 1;
                        //echo dateCmp($ffecllegada,$ffecsalida);
                        while (dateCmp($ffecllegada, $ffecsalida) <= 0) {
                            $select.="," . "ocu" . $col;
                            //    $select.=","."tipos".$col;

                            $from.=" left outer join (SELECT COALESCE(count(n_reg),0) as ocu$col,ftipocto   
                            FROM valeryus19 where ffecllegada <= '$ffecllegada' 
                           and  ffecsalida>='$ffecllegada'
                            and cancelado='0' and extra1='0' 
                            and ffecllegada>'2015-01-01' and (status='HUESPED' or status='RESERVA INDIVIDUAL' or status='RESERVA GRUPO') group by ftipocto) as dia$col on dia$col.ftipocto=descripcion 
                           ";
                            $col++;
                            $ffecllegada = addDay($ffecllegada, 1);
                        }
                        $query = $select . $from . " where descripcion<>'MAESTRA' ";
                        $sql = mysqli_query($con ,$query);
                      
                        ?>		

                    <?php   $tot=0;
                    $fila=0;
                     $filant=0;
                    while ($reg = mysqli_fetch_array($sql)) {
                        $filant=fila;
           $ocup=0;
           $disp=0;
          
                        echo "<tr>";
                        echo "<td style=' ;'><div align='center'>" . $reg['descripcion'] . "&nbsp</div></td>";


                        for ($i = 1; $i < $col; $i++) {
                            $disponib=(intval($reg['totalcuartos']) - intval($reg['ocu' . $i]));
                            echo "<td>&nbsp" . $reg['totalcuartos'] . "-" .intval($reg['ocu' . $i]) . "=" .$disponib  . "</td>";
                          
                                $ocupadas[$i]+=$reg['ocu' . $i];
                              $disponibles[$i]+=$disponib;
                            
                              
                                 $tot+=$reg['totalcuartos'];
                        }

                        ///out
                        //$sqb2=mysqli_query($con ,"SELECT n_reg FROM chart where ffecllegada <= '$ffecllegada' and  fecha_real>'$ffecllegada' and fmuncto= '".$reg['ncto']."'and cancelado='0' and ffecllegada>'2013-04-01'");
                        //while ($reb2= mysqli_fetch_array($sqb2)) {
                        //echo "<div style='background:#FF9933; color:#000000; font-size:12px'>Folio:". $reb2["n_reg"] ."</div>";
                        //}
                        echo "</tr>";
                       $ocupadas[]=$ocup;
                       $disponibles[]=$disp;
                       $fila++;
                    }
                      print_r($disponibles);
                    
                    echo "<tr>";
                        echo "<td style=' ;'><div align='center'>TOTAL&nbsp</div></td>";


                        for ($i = 1; $i < $col; $i++) {
                            
                            
                            echo "<td>OC:$ocupadas[$i]<br/>DIS:$disponibles[$i]<br/>TOT:".($ocupadas[$i]+$disponibles[$i])."<br/></td>";
                        
                            
                            
                            
                        }

                        ///out
                        //$sqb2=mysqli_query($con ,"SELECT n_reg FROM chart where ffecllegada <= '$ffecllegada' and  fecha_real>'$ffecllegada' and fmuncto= '".$reg['ncto']."'and cancelado='0' and ffecllegada>'2013-04-01'");
                        //while ($reb2= mysqli_fetch_array($sqb2)) {
                        //echo "<div style='background:#FF9933; color:#000000; font-size:12px'>Folio:". $reb2["n_reg"] ."</div>";
                        //}
                        echo "</tr>";
                    
                    
                    
                }
                mysqli_close($con);
                echo $tot;
                ?>    
            </table>
            <table>
                <tr><td></td><td></td><td></td></tr>

            </table>
            
        </form>   
    </div>
</body>
</html>