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

Ya lo he cogido, eres un fenómeno así que muchísimas gracias por tus molestias.
El código quedaría así:
Código PHP:
<?php

$desde 
= date('d/m', strtotime($_GET['FDesde']));
$hasta = date('d/m', strtotime($_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 = 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.00, 2) . ' €';
$precioMedia    = number_format(15.50, 2) . ' €';
$precioAlta     = number_format(19.99, 2) . ' €';
$precioEspecial = number_format( 5.95, 2) . ' €';
 
$helper = new Temporadas($temporadaBaja, $temporadaMedia, $temporadaAlta, $especial);
 
// Fechas seleccionadas

$inicio = $helper->getTime('30/08');
$final  = $helper->getTime('04/09');
 
echo <<<TABLE
<table width="100%" border="1">

     <thead>
      <tr>
        <strong>Temporadas y Precios</strong>
      </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
    </tbody>
</table>
ENDTABLE;

// DIFERENCIA DE DIAS ENTRE Fdesde HASTA Fhasta //
$inicio = strtotime($_GET['FDesde']);
$fin = strtotime($_GET["FHasta"]);
$dateDiff = $fin - $inicio;
?>
<br />
<img src="imagenes/paypal.jpg">
<br /><br />
<strong>Reserva Habitación: Nº <?php echo $row_ConsultaHabitaciones['intNumero_Habitacion']; ?> de: <?php echo $row_DatosDatosConsulta['strNombre']; ?></strong>
<br />
<strong>Desde el:</strong> <?php if(isset($_GET['FDesde'])) echo $_GET['FDesde']; ?>&nbsp;&nbsp;<strong>Hasta el:</strong> <?php if(isset($_GET["FHasta"])) echo $_GET["FHasta"]; ?>
<br />

<?php
echo "<strong>Días Totales:</strong> ".($dateDiffTotal = floor($dateDiff/(60*60*24))+1)." días";
echo 
"<br />"; 
?>
<strong>Fecha Factura:</strong> <?php echo date("d-m-Y");?><br />
<strong>Cliente:</strong> 
<?php echo ObtenerNombreUsuario($row_DatosDatosConsulta['refUsuario']); ?>
<?php 
echo ObtenerAlellidosUsuario($row_DatosDatosConsulta['refUsuario']); ?>
<br />

<?php
$Impuesto 
= $row_ConsultaHabitaciones['intValor_Impuesto']; 
$NombreImpuesto = $row_ConsultaHabitaciones['strNombre_Impuesto'];
$Impuestos = (($Impuesto * $total) / 100);
echo 
"<strong>Sub Total:</strong> ".$total." €";
echo 
"<br />";
echo 
"<strong>".$Impuesto."% ".$NombreImpuesto.":</strong> ".$row_ConsultaPrecios['strNombreTemporada'].$Impuestos." €";
echo 
"<br />";
echo 
"<strong>Total:</strong> ".$Total = $Impuestos + $total." €";
?>
Ahora debo alimentar dinámicamente esto:
Código PHP:
$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')); 
y esto:
Código PHP:
$precioBaja     = number_format(10.00, 2) . ' €';
$precioMedia    = number_format(15.50, 2) . ' €';
$precioAlta     = number_format(19.99, 2) . ' €';
$precioEspecial = number_format( 5.95, 2) . ' €'; 
En relación a cada hotel (así un usuario que tenga suscritos 3 hoteles podrá decidir temporadas diferentes por hotel) por lo que debo crear una tabla tbl_temporadas_hoteles en la que esten los campos:
idTemporada
refHotel
precioBaja
precioMedia
precioAlta
precioEspecial
NombreTemporada
diaDesde
diaHasta
¿Que es lo que piensas?

Y otra cosa, ¿que sería esto?:
Código PHP:
// Fechas seleccionadas
$inicio = $helper->getTime('30/08');
$final  = $helper->getTime('04/09'); 
Un saludo: Armando