Ver Mensaje Individual
  #21 (permalink)  
Antiguo 15/01/2016, 02:15
Avatar de manyblue
manyblue
 
Fecha de Ingreso: marzo-2008
Mensajes: 329
Antigüedad: 16 años
Puntos: 10
Respuesta: Organizar Precios y Temporadas

Me explota por un lado jajajajaja, que torpe soy.

Se llega a esta página desde el enlace:

hoteles_usuario_reserva_previa.php?recordID=<?php echo $row_ConsultaHabitaciones['id_Habitacion']; ?>&refHotel=<?php echo $row_ConsultaHabitaciones['refHotel']; ?>&FDesde=<?php echo $_GET['FDesde']; ?>&FHasta=<?php echo $_GET['FHasta']; ?>&idProvincia=<?php echo $row_DatosDatosConsulta['idProvincia']; ?>&idHotel=<?php echo $row_ConsultaHabitaciones['refHotel']; ?>

Es decir, le estoy pasando:
recordID = idHabitacion
refHotel = idHotel
FDesde
Fhasta
idProvincia

Código PHP:
<?php

list($dia$mes$anno) = explode('-'$_GET['FDesde']);
$desde "$dia-$mes"
list(
$dia$mes$anno) = explode('-'$_GET['FHasta']);
$hasta"$dia-$mes";

$precioAlta $row_ConsultaHabitaciones['intPrecio_Alta']; //viene de tabla habitaciones
$precioMedia $row_ConsultaHabitaciones['intPrecio_Media'];
$precioBaja $row_ConsultaHabitaciones['intPrecio_Baja']; 
$PrecioEspecial $row_ConsultaHabitaciones['intPrecio_Especial'];
 
list(
$dia$mes$anno) = explode('-'$_GET['FDesde']);
$desde "$dia-$mes"
list(
$dia$mes$anno) = explode('-'$_GET['FHasta']);
$hasta"$dia-$mes";

class 
Temporadas {
 
    protected 
$temporadas = array(); 

 
    protected 
$acumulador 0.0;
 
    public function 
__construct($baja$media$alta$especial) {
        
$this->temporadas['baja']      = $baja;
        
$this->temporadas['media']     = $media;
        
$this->temporadas['alta']      = $alta;
        
$this->temporadas['especial']  = $especial;
    }
 
    protected function 
esTemporada($temporada$dia) {
        foreach(
$this->temporadas[$temporada] as $rango) {
            
$desde $this->getTime($rango[0]);
            
$hasta $this->getTime($rango[1]);
 
            if (
$dia >= $desde && $dia <= $hasta) {
                return 
true;
            }
        }
 
        return 
false;
    }
 
    public function 
esTemporadaBaja($dia) {
        return 
$this->esTemporada('baja'$dia);
    }
 
    public function 
esTemporadaMedia($dia) {
        return 
$this->esTemporada('media'$dia);
    }
 
    public function 
esTemporadaAlta($dia) {
        return 
$this->esTemporada('alta'$dia);
    }
 
    public function 
esEspecial($dia) {
        return 
$this->esTemporada('especial'$dia);
    }
 
    public function 
acumular($precio) {
        
$this->acumulador += floatval($precio);
    }
 
    public function 
precioTotal() {
        return 
$this->acumulador;
    }
 
    public function 
getTime($dia) {
        
// Cambia el orden para strtotime, es mm/dd/yyyy

        
list($dia$mes) = explode('/'$dia);
        return 
strtotime($mes '/' $dia '/' date('Y'));
    }
}
 
 
// Temporada Baja = 13/01 al 10/03  -  07/04 al 14/06  -  01/09 al 26/11

// Temporada Media =  11/03 al 26/03  -  15/06 al 31/07  -  27/11 al 14/12

// Temporada Alta = 27/03 al 06/04  -  01/08 al 31/08  -  01/08 al 31/08

$temporadaBaja = array(
    array(
'13-01''10-03'),
    array(
'07-04''14-06'),
    array(
'01-09''26-11')
);

$temporadaMedia = array(
    array(
'11-03''26-03'),
    array(
'15-06''31-07'),
    array(
'27-11''14-12')
);

$temporadaAlta = array(
    array(
'27-03''06-04'),
    array(
'01-08''31-08'),
    array(
'01-08''31-08')
);

$especial = array(
    array(
'01-01''12-01')
);
 
// Precios por temporada

$precioBaja     number_format(10.002) . ' €';
$precioMedia    number_format(15.502) . ' €';
$precioAlta     number_format(19.992) . ' €';
$precioEspecial number_format5.952) . ' €';
 
$helper = new Temporadas($temporadaBaja$temporadaMedia$temporadaAlta$especial);
 
// Fechas seleccionadas

$inicio $helper->getTime('30/08');
$final  $helper->getTime('04/09');
 
echo <<<TABLE
<table width="50%" border="1">
    <thead>
    <tr>
        <th>Fecha (dd/mm/yyyy)</th>
        <th>Temporada</th>
        <th>Precio</th>
    </tr>
    </thead>
    <tbody>
TABLE;
 
for (
$i $inicio$i $final$i += 60 60 24) {
    echo 
'<tr>';
 
    if (
$helper->esEspecial($i)) {
        
// Acumular precio

        
$helper->acumular($precioEspecial);
        echo 
"<td>".date('d/m/Y',$i)."</td><td>Precio Especial</td><td>$precioEspecial</td>";
 
    } else if (
$helper->esTemporadaAlta($i)) {
        
// Acumular precio

        
$helper->acumular($precioAlta);
        echo 
"<td>".date('d/m/Y',$i)."</td><td>Temporada Alta</td><td>$precioAlta</td>";
 
    } else if (
$helper->esTemporadaMedia($i)) {
        
// Acumular precio

        
$helper->acumular($precioMedia);
        echo 
"<td>".date('d/m/Y',$i)."</td><td>Temporada Media</td><td>$precioMedia</td>";
 
    } else if (
$helper->esTemporadaBaja($i)) {
        
// Acumular precio

        
$helper->acumular($precioBaja);
        echo 
"<td>".date('d/m/Y',$i)."</td><td>Temporada baja</td><td>$precioBaja</td>";
 
    }
 
    echo 
'</tr>';
}
 
$total number_format($helper->precioTotal(), 2) . ' €';
 
echo <<<ENDTABLE
    <tr>
        <td colspan='2'><b>TOTAL:</b></td>
        <td>$total</td>
    </tr>
    </tbody>
</table>
ENDTABLE;
?>
Al poner tu código me salta error:
Notice: Undefined offset: 1 in C:\wamp\www\WEBRESPONSIVERESERVAS\hoteles_usuario_ reserva_previa.php on line 265

Esta línea:
list($dia, $mes) = explode('/', $dia);

Muchísimas gracias, aunque aún no he resuelto el tema.Un saludo: manyblue