PHP - Temporadas Precios

 
Vista:
sin imagen de perfil

Temporadas Precios

Publicado por Armando (14 intervenciones) el 14/01/2016 09:36:42
Tengo este código que me está dando 5 errores y no se por que, los errores están comentados:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?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.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;
?>
Alguien me puede echar una mano ??
Muchísimas gracias de antemano.
Un saludo: Manyblue
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro
Val: 1.634
Plata
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Temporadas Precios

Publicado por Alejandro (838 intervenciones) el 14/01/2016 17:15:16
  • Alejandro se encuentra ahora conectado en el
  • chat de PHP
Me parece que lo que quieres es usar arrays
1
2
3
4
5
6
7
protected $temporadas = array();
 
$temporadaBaja = array(
    array('13/01', '10/03'),
    array('07/04', '14/06'),
    array('01/09', '26/11')
);
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Temporadas Precios

Publicado por Manyblue (14 intervenciones) el 14/01/2016 19:43:17
Si por la versión de php, lo miro y te digo.
Saludos y gracias: Manyblue
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Temporadas Precios

Publicado por Manyblue (14 intervenciones) el 17/01/2016 11:33:52
Bueno, el código me va quedando así:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?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:<?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 = number_format($row_ConsultaHabitaciones['intValor_Impuesto'], 2);
$NombreImpuesto = $row_ConsultaHabitaciones['strNombre_Impuesto'];
$Impuestos = (($Impuesto * $total) / 100);
echo "<strong>SUB TOTAL:</strong> ".$total." €";
echo "<br />";
echo "<strong>".$Impuesto."% ".$NombreImpuesto.":</strong> ".number_format($Impuestos, 2)." €";
echo "<br />";
echo "<strong>TOTAL:</strong> ".number_format($Total = $Impuestos + $total, 2)." €";
?>
1) 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.00% IGIC: 13.60 €
TOTAL: 93.60 €
2) Los días seleccionados:
Corresponden todos a temporada baja y el $precioBaja = $row_ConsultaHabitaciones['intPrecio_Baja'] = 30 €
3) 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.00% IGIC: 7.8 €
TOTAL: 67.8 €
¿En que me equivoco?
Un saludo y mil gracias: Manyblue
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar