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

x_atrix , he implementado el código que tan amablemente me has pasado, también lo he remirado varias veces para intertar cogerlo pues trabajas con clases y yo aún no llego a tanto.
Fijate en las líneas comentadas con mayúsculas pues me dan error y no se por que.
Código PHP:
<?php

$desde 
$_GET['FDesde'];
$hasta $_GET["FHasta"];
                                                      
$precioAlta $row_ConsultaHabitaciones['intPrecio_Alta']; 
$precioMedia $row_ConsultaHabitaciones['intPrecio_Media'];
$precioBaja $row_ConsultaHabitaciones['intPrecio_Baja']; 
$PrecioEspecial $row_ConsultaHabitaciones['intPrecio_Especial'];


class 
Temporadas {

    protected 
$temporadas = []; // ESTA LÍNEA ME DA ERROR

    
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 = [
    [
'13/01''10/03'],
    [
'07/04''14/06'],
    [
'01/09''26/11']
];  
// ESTA LÍNEA ME DA ERROR

$temporadaMedia = [
    [
'11/03''26/03'],
    [
'15/06''31/07'],
    [
'27/11''14/12']
];  
// ESTA LÍNEA ME DA ERROR

$temporadaAlta = [
    [
'27/03''06/04'],
    [
'01/08''31/08'],
    [
'01/08''31/08']
];  
// ESTA LÍNEA ME DA ERROR

$especial = [
    [
'01/01''12/01']
];  
// ESTA LÍNEA ME DA ERROR

// 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;
?>
Los valores de estas fechas vienen en español (d-m-Y):
$desde = $_GET['FDesde'];
$hasta = $_GET["FHasta"];

Muchísimas gracias y un saludo: manyblue

Última edición por manyblue; 14/01/2016 a las 02:26