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

Vamos a terminarlo de pulir pues hay datos que son dinámicos y no estáticos OK.

1) Tu código me queda 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($row_ConsultaHabitaciones['intPrecio_Baja'], 2) . ' €';
$precioMedia    number_format($row_ConsultaHabitaciones['intPrecio_Media'], 2) . ' €';
$precioAlta     number_format($row_ConsultaHabitaciones['intPrecio_Alta'], 2) . ' €';
$precioEspecial number_format($row_ConsultaHabitaciones['intPrecio_Especial'], 2) . ' €';
 
$helper = new Temporadas($temporadaBaja$temporadaMedia$temporadaAlta$especial);
 
// Fechas seleccionadas

$inicio $helper->getTime($desde);
$final  $helper->getTime($hasta);
 
 
for (
$i $inicio$i $final$i += 60 60 24) {
  
 
    if (
$helper->esEspecial($i)) {
        
// Acumular precio

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

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

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

        
$helper->acumular($precioBaja);
         
"<td>".date('d/m/Y',$i)."</td><td>Temporada baja</td><td>$precioBaja</td>";
 
    }
 
    
}
 
$total number_format($helper->precioTotal(), 2);
 


// DIFERENCIA DE DIAS ENTRE Fdesde HASTA Fhasta //
$inicio strtotime($_GET['FDesde']);
$fin strtotime($_GET["FHasta"]);
$dateDiff $fin $inicio;
?>

<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)))." 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> ".number_format($Impuestos2)." €";
echo 
"<br />";
echo 
"<strong>TOTAL:</strong> ".number_format($Total $Impuestos $total2)." €";
?>
2) Resultado del código anterior:
Reserva Habitación: Nº 1 de: Hotel El Galeon
Desde el: 18-01-2016 Hasta el: 20-01-2016
Días Totales: 2 días
Fecha Factura: 17-01-2016
Cliente: Manyblue
SUB TOTAL: 80.00 €
17% IGIC: 13.60 €
TOTAL: 93.60 €
3) Los días seleccionados:
Corresponden todos a temporada baja y el $precioBaja = $row_ConsultaHabitaciones['intPrecio_Baja'] = 30 €
4) Resultado que debería dar:
mi SUBTOTAL = tu $total deberia ser 60 € no 80 €
5) Resultado debería ser esto:
Reserva Habitación: Nº 1 de: Hotel El Galeon
Desde el: 18-01-2016 Hasta el: 20-01-2016
Días Totales: 2 días
Fecha Factura: 17-01-2016
Cliente: Manyblue
SUB TOTAL: 60.00 €
17% IGIC: 7.8 €
TOTAL: 67.8 €
Que te parece ?? es lo que te quería decir, los cálculos parecen no ser correctos.
Muchísimas gracias por tus aportes y un saludo: Manyblue

Última edición por manyblue; 17/01/2016 a las 04:45