
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:
Alguien me puede echar una mano ??
Muchísimas gracias de antemano.
Un saludo: Manyblue
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;
?>
Muchísimas gracias de antemano.
Un saludo: Manyblue
Valora esta pregunta


0