Ver Mensaje Individual
  #23 (permalink)  
Antiguo 15/01/2016, 06:41
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

Bueno, logré que funcionara el codigo de x_atrix quedando 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="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;
?>
Esto dá como resultado:
Código HTML:
Reserva Habitación: Nº 1 de: Hotel San Telmo
Desde el: 18-01-2016  Hasta el: 23-01-2016
Fecha (dd/mm/yyyy)         Temporada         Precio               
30/08/2016Temporada Alta19.99 €
31/08/2016Temporada Alta19.99 €
01/09/2016Temporada baja10.00 €
02/09/2016Temporada baja10.00 €
03/09/2016Temporada baja10.00 €             
TOTAL:         69.98 €
Me gustaría que fuera un poco más como esto:
Código HTML:
Reserva Habitación: Nº 1 de: Hotel San Telmo
Desde el: 18-01-2016  Hasta el: 23-01-2016
Días Totales: 6 días
Fecha Factura: 15-01-2016
Cliente:  Pepe Lo que Sea                                                      
Precio/Día: 30 €   Temporada: Baja
Sub Total: 180 €
17% IGIC: 30.6 €
Total: 210.6 €                                                                                                            
el código que tenía con tabla temporadas es este:
Código PHP:
<?php 

$desde 
= $_GET['FDesde'];
$hasta = $_GET["FHasta"];
$new_desde = date( "m-d", strtotime($desde));
$new_Hasta = date( "m-d", strtotime($hasta));

// 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

// DATOS FACTURACIÓN //

do {
    
$dateDesde = date("m-d", strtotime($row_ConsultaPrecios['dateDesde']));
$dateHasta = date("m-d", strtotime($row_ConsultaPrecios['dateHasta']));
$NombreTemporada = $row_ConsultaPrecios['strNombreTemporada'];
$PrecioTemporada = $row_ConsultaPrecios['intPrecio'];

if((
$dateDesde <= $new_desde) && ($dateHasta >= $new_Hasta) && ($row_ConsultaPrecios['strNombreTemporada'] = "Baja")):
  
$PrecioHabitacion = $row_ConsultaPrecios['intPrecio'];
   
$Temporada = $NombreTemporada;
elseif((
$dateDesde <= $new_desde) && ($dateHasta >= $new_Hasta) && ($row_ConsultaPrecios['strNombreTemporada'] = "Media")):
  
$PrecioHabitacion = $row_ConsultaPrecios['intPrecio'];
   
$Temporada = $NombreTemporada;
elseif((
$dateDesde <= $new_desde) && ($dateHasta >= $new_Hasta) && ($row_ConsultaPrecios['strNombreTemporada'] = "Alta")):
  
$PrecioHabitacion = $row_ConsultaPrecios['intPrecio'];
   
$Temporada = $NombreTemporada;
endif;

} while (
$row_ConsultaPrecios = mysql_fetch_assoc($ConsultaPrecios));


// DIFERENCIA DE DIAS ENTRE Fdesde HASTA Fhasta //
$inicio = strtotime($_GET['FDesde']);
$fin = strtotime($_GET["FHasta"]);
$dateDiff = $fin - $inicio;
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
// CALCULOS FACTURACIÓN //
echo "<strong>Precio/Día:</strong> ".$PrecioHabitacion." €"."&nbsp;&nbsp;&nbsp;<strong>Temporada:</strong> ".$Temporada;
echo 
"<br />";
echo 
"<strong>Sub Total:</strong> ".$SubTotal = $PrecioHabitacion * $dateDiffTotal." €";
echo 
"<br />";
$Impuesto = $row_ConsultaHabitaciones['intValor_Impuesto']; 
$NombreImpuesto = $row_ConsultaHabitaciones['strNombre_Impuesto'];
$Impuestos = (($Impuesto * $SubTotal) / 100);
echo 
"<strong>".$Impuesto."% ".$NombreImpuesto.":</strong> ".$row_ConsultaPrecios['strNombreTemporada'].$Impuestos." €";
echo 
"<br />";
echo 
"<strong>Total:</strong> ".$Total = $Impuestos + $SubTotal." €";

?>
Un saludo y mil gracias: Manyblue