Ver Mensaje Individual
  #7 (permalink)  
Antiguo 14/01/2016, 05:40
x_atrix
 
Fecha de Ingreso: enero-2016
Mensajes: 71
Antigüedad: 8 años, 4 meses
Puntos: 14
Respuesta: Organizar Precios y Temporadas

Hola,

Te da error por la version de PHP.
Prueba con esto otro:
Código PHP:
<?php

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

// Los rangos los espera segun tus comentarios. dd/mm
$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'),
    
// ['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;
Prueba esto en una pagina php sola.

En casos un poco mas complejos las clases te dan claridad al código, para algo sencillito añaden complejidad innecesaria.