No manca ho preso l'intero codice aggiornato dal tuo link .Manca questo nel get_diff_Date
il risultato total è
PHP:
["total"]=> float(450)
mentre dovrebbe essere 310
No manca ho preso l'intero codice aggiornato dal tuo link .Manca questo nel get_diff_Date
["total"]=> float(450)
Array
(
[calcolo] => Array
(
[13] => Array
(
[0] => stdClass Object
(
[id] => 2
[struttura] => 1
[room_id] => 2
[price_sun] => 8
[price_mon] => 8
[price_tue] => 5
[price_wed] => 10
[price_thu] => 6
[price_fri] => 5
[price_sat] => 22
[price] => Array
(
[operation] => Array
(
[plus] => Array
(
[custom] => 0
[normal] => 13
)
[minus] => Array
(
[sconto] => 0
[type] => percentage
[ship_0] => 1
)
)
[total] => 13
[per_night] => 6.5
)
[custom] => Array
(
)
[date] => Array
(
[in] => 2019-01-28
[out] => 2019-01-29
)
)
)
[15] => Array
(
[0] => stdClass Object
(
[id] => 3
[struttura] => 2
[room_id] => 3
[price_sun] => 5
[price_mon] => 10
[price_tue] => 5
[price_wed] => 5
[price_thu] => 4
[price_fri] => 1
[price_sat] => 11
[price] => Array
(
[operation] => Array
(
[plus] => Array
(
[custom] => 0
[normal] => 15
)
[minus] => Array
(
[sconto] => 0
[type] => percentage
[ship_0] => 1
)
)
[total] => 15
[per_night] => 7.5
)
[custom] => Array
(
)
[date] => Array
(
[in] => 2019-01-28
[out] => 2019-01-29
)
)
)
[100] => Array
(
[0] => stdClass Object
(
[id] => 4
[struttura] => 3
[room_id] => 1
[price_sun] => 50
[price_mon] => 50
[price_tue] => 50
[price_wed] => 50
[price_thu] => 50
[price_fri] => 50
[price_sat] => 55
[price] => Array
(
[operation] => Array
(
[plus] => Array
(
[custom] => 0
[normal] => 100
)
[minus] => Array
(
[sconto] => 0
[type] => percentage
[ship_0] => 1
)
)
[total] => 100
[per_night] => 50
)
[custom] => Array
(
)
[date] => Array
(
[in] => 2019-01-28
[out] => 2019-01-29
)
)
)
[120] => Array
(
[0] => stdClass Object
(
[id] => 6
[struttura] => 2
[room_id] => 4
[price_sun] => 60
[price_mon] => 60
[price_tue] => 60
[price_wed] => 60
[price_thu] => 60
[price_fri] => 60
[price_sat] => 60
[price] => Array
(
[operation] => Array
(
[plus] => Array
(
[custom] => 0
[normal] => 120
)
[minus] => Array
(
[sconto] => 0
[type] => percentage
[ship_0] => 1
)
)
[total] => 120
[per_night] => 60
)
[custom] => Array
(
)
[date] => Array
(
[in] => 2019-01-28
[out] => 2019-01-29
)
)
)
[170] => Array
(
[0] => stdClass Object
(
[id] => 7
[struttura] => 4
[room_id] => 1
[price_sun] => 25
[price_mon] => 25
[price_tue] => 25
[price_wed] => 25
[price_thu] => 25
[price_fri] => 25
[price_sat] => 25
[price] => Array
(
[operation] => Array
(
[plus] => Array
(
[custom] => 120
[normal] => 50
)
[minus] => Array
(
[sconto] => 0
[type] => percentage
[ship_0] => 1
)
)
[total] => 170
[per_night] => 85
)
[custom] => Array
(
[0] => stdClass Object
(
[id] => 10
[ref_room] => 7
[room_id] => 1
[certain_date] => 2019-01-28
[price] => 60
)
[1] => stdClass Object
(
[id] => 11
[ref_room] => 7
[room_id] => 1
[certain_date] => 2019-01-29
[price] => 60
)
)
[date] => Array
(
[in] => 2019-01-28
[out] => 2019-01-29
)
)
)
[254] => Array
(
[0] => stdClass Object
(
[id] => 5
[struttura] => 2
[room_id] => 2
[price_sun] => 58
[price_mon] => 59
[price_tue] => 55
[price_wed] => 65
[price_thu] => 66
[price_fri] => 20
[price_sat] => 25
[price] => Array
(
[operation] => Array
(
[plus] => Array
(
[custom] => 140
[normal] => 114
)
[minus] => Array
(
[sconto] => 0
[type] => percentage
[ship_0] => 1
)
)
[total] => 254
[per_night] => 127
)
[custom] => Array
(
[0] => stdClass Object
(
[id] => 6
[ref_room] => 5
[room_id] => 2
[certain_date] => 2019-01-28
[price] => 70
)
[1] => stdClass Object
(
[id] => 7
[ref_room] => 5
[room_id] => 2
[certain_date] => 2019-01-29
[price] => 70
)
)
[date] => Array
(
[in] => 2019-01-28
[out] => 2019-01-29
)
)
)
[310] => Array
(
[0] => stdClass Object
(
[id] => 1
[struttura] => 1
[room_id] => 1
[price_sun] => 70
[price_mon] => 70
[price_tue] => 70
[price_wed] => 70
[price_thu] => 70
[price_fri] => 70
[price_sat] => 70
[price] => Array
(
[operation] => Array
(
[plus] => Array
(
[custom] => 170
[normal] => 140
)
[minus] => Array
(
[sconto] => 0
[type] => percentage
[ship_0] => 1
)
)
[total] => 310
[per_night] => 155
)
[custom] => Array
(
[0] => stdClass Object
(
[id] => 1
[ref_room] => 1
[room_id] => 1
[certain_date] => 2019-01-28
[price] => 80
)
[1] => stdClass Object
(
[id] => 2
[ref_room] => 1
[room_id] => 1
[certain_date] => 2019-01-29
[price] => 90
)
)
[date] => Array
(
[in] => 2019-01-28
[out] => 2019-01-29
)
)
)
)
[room] => Array
(
[0] => stdClass Object
(
[id] => 1
[struttura] => 1
[room_id] => 1
[price_sun] => 70
[price_mon] => 70
[price_tue] => 70
[price_wed] => 70
[price_thu] => 70
[price_fri] => 70
[price_sat] => 70
)
[1] => stdClass Object
(
[id] => 2
[struttura] => 1
[room_id] => 2
[price_sun] => 8
[price_mon] => 8
[price_tue] => 5
[price_wed] => 10
[price_thu] => 6
[price_fri] => 5
[price_sat] => 22
)
[2] => stdClass Object
(
[id] => 3
[struttura] => 2
[room_id] => 3
[price_sun] => 5
[price_mon] => 10
[price_tue] => 5
[price_wed] => 5
[price_thu] => 4
[price_fri] => 1
[price_sat] => 11
)
[3] => stdClass Object
(
[id] => 4
[struttura] => 3
[room_id] => 1
[price_sun] => 50
[price_mon] => 50
[price_tue] => 50
[price_wed] => 50
[price_thu] => 50
[price_fri] => 50
[price_sat] => 55
)
[4] => stdClass Object
(
[id] => 5
[struttura] => 2
[room_id] => 2
[price_sun] => 58
[price_mon] => 59
[price_tue] => 55
[price_wed] => 65
[price_thu] => 66
[price_fri] => 20
[price_sat] => 25
)
[5] => stdClass Object
(
[id] => 6
[struttura] => 2
[room_id] => 4
[price_sun] => 60
[price_mon] => 60
[price_tue] => 60
[price_wed] => 60
[price_thu] => 60
[price_fri] => 60
[price_sat] => 60
)
[6] => stdClass Object
(
[id] => 7
[struttura] => 4
[room_id] => 1
[price_sun] => 25
[price_mon] => 25
[price_tue] => 25
[price_wed] => 25
[price_thu] => 25
[price_fri] => 25
[price_sat] => 25
)
)
[options] => Array
(
[0] => stdClass Object
(
[id] => 1
[ref_room] => 1
[room_id] => 1
[certain_date] => 2019-01-28
[price] => 80
)
[1] => stdClass Object
(
[id] => 2
[ref_room] => 1
[room_id] => 1
[certain_date] => 2019-01-29
[price] => 90
)
[2] => stdClass Object
(
[id] => 3
[ref_room] => 2
[room_id] => 2
[certain_date] => 2019-01-14
[price] => 35
)
[3] => stdClass Object
(
[id] => 4
[ref_room] => 3
[room_id] => 3
[certain_date] => 2019-01-23
[price] => 22
)
[4] => stdClass Object
(
[id] => 5
[ref_room] => 4
[room_id] => 1
[certain_date] => 2019-01-22
[price] => 50
)
[5] => stdClass Object
(
[id] => 6
[ref_room] => 5
[room_id] => 2
[certain_date] => 2019-01-28
[price] => 70
)
[6] => stdClass Object
(
[id] => 7
[ref_room] => 5
[room_id] => 2
[certain_date] => 2019-01-29
[price] => 70
)
[7] => stdClass Object
(
[id] => 8
[ref_room] => 5
[room_id] => 2
[certain_date] => 2019-01-30
[price] => 50
)
[8] => stdClass Object
(
[id] => 9
[ref_room] => 7
[room_id] => 1
[certain_date] => 2019-01-27
[price] => 50
)
[9] => stdClass Object
(
[id] => 10
[ref_room] => 7
[room_id] => 1
[certain_date] => 2019-01-28
[price] => 60
)
[10] => stdClass Object
(
[id] => 11
[ref_room] => 7
[room_id] => 1
[certain_date] => 2019-01-29
[price] => 60
)
)
[data_post] => Array
(
[room] => 1
[start_date] => 2019-01-28
[end_date] => 2019-01-29
)
)
Ti posto l'output, che altro non fa presa una collection di dati calcola i prezzi e li ordina per il più basso....
Es. in room il prezzo per tutti i giorni della settimana è di 70 euro.
In room_custom_price per il giorno 2019-08-27 ed il giorno 2019-08-28 ho impostato rispettivamente i prezzi di 80euro e 90euro.
Quindi il calcolo dovrebbe essere :
1 notte a 70
2 notte a 70
3 notte a 80
4 notte a 90
Totale 310 Euro mentre la funzione mi calcola un totale di 450 Euro
[date] => Array
(
[in] => 2019-01-28
[out] => 2019-01-29
)
[id] => 1
[struttura] => 1
[room_id] => 1
[price_sun] => 70
[price_mon] => 70
[price_tue] => 70
[price_wed] => 70
[price_thu] => 70
[price_fri] => 70
[price_sat] => 70
[price] => Array
(
[operation] => Array
(
[plus] => Array
(
[custom] => 170
[normal] => 140
)
[minus] => Array
(
[sconto] => 0
[type] => percentage
[ship_0] => 1
)
)
[total] => 310
[per_night] => 155
)
[custom] => Array
(
[0] => stdClass Object
(
[id] => 1
[ref_room] => 1
[room_id] => 1
[certain_date] => 2019-01-28
[price] => 80
)
[1] => stdClass Object
(
[id] => 2
[ref_room] => 1
[room_id] => 1
[certain_date] => 2019-01-29
[price] => 90
)
)
//valore 140 valore 170 = 310
$data->price['custom']+$data->price['normale'] = X
No anzi hai sollevato un fattore che non avevo considerato, quindi assolutamente ben venute le osservazioni...il fatto che abbia messo in discussione da neofita il risultato è che non avevo compreso l'esistenza della funzione che calcola i due price.
<?php
require_once 'myUtils/show_vars.php';
/* ---------------------------------------- */
$room = "1";
$start_date = "2019-08-26"; // data di arrivo
$end_date = "2019-08-30"; // data di partenza
roomPriceCalc($room, $start_date, $end_date);
echo "<h3>TOTAL PRICE : ".$totPrice."</h3>";
/* ---------------------------------------- */
function roomPriceCalc($room, $start_date, $end_date)
{
global $totPrice, $roomPrices;
$date_in = new DateTime($start_date); // data arrivo
$date_out = new DateTime($end_date); // data partenza
$nights = $date_out->diff($date_in); // numero di pernottamenti
$nights = $nights->d;
echo "<br />data di arrivo : " .$start_date
. "<br />data di partenza : ".$end_date
. "<br />pernottamenti : " .$nights
. "<br /><br />";
/* ---------------------------------------- connessione al db */
$hostname = "localhost";
$pass = "PASSWORD";
$muser = "USER";
$db = "DB";
//$mysqli = new mysqli($hostname, $muser, $pass, $db);
//if (mysqli_connect_errno()) { die("Failed to connect to MySQL: " . mysqli_connect_error() ); }
/* ---------------------------------------- legge il prezzo standard della camera */
$query = "SELECT price_sun, price_mon, price_tue, price_wed, price_thu, price_fri, price_sat"
. " FROM room"
. " WHERE id = ".$room;
//$stdPrices = $mysqli->query($query)->fetch_all(MYSQLI_NUM); // prezzi elencati da domenica = 0 a sabato = 6
$stdPrices = array(90, 10, 20, 30, 40, 50, 60);
echo "<h3>Room standard prices</h3>".show_var( $stdPrices )."<br />";
/* ---------------------------------------- legge lo sconto standard della camera */
$query = "SELECT rebate_sun, rebate_mon, rebate_tue, rebate_wed, rebate_thu, rebate_fri, rebate_sat"
. " FROM room"
. " WHERE id = ".$room;
//$stdRebates = $mysqli->query($query)->fetch_all(MYSQLI_NUM); // sconti elencati da domenica = 0 a sabato = 6
$stdRebates = array(9, 0, 0, 0, 4, 5, 6);
echo "<h3>Room standard rebates</h3>".show_var( $stdRebates )."<br />";
/* ---------------------------------------- crea la tabella dei prezzi e sconti per periodo */
$dtAdd = 0;
$roomPrices = array();
for ($dt=0; $dt<$nights; $dt++)
{
$day = $date_in->modify("+".$dtAdd." day");
$df = $day->format("Y-m-d");
$num = $day->format('w');
$roomPrices[$df]["date"] = $df; // giorno esaminato
$roomPrices[$df]["label"] = $day->format('l'); // giorno
$roomPrices[$df]["wDay"] = $num; // numero del giorno, da domenica = 0 a sabato = 6
$roomPrices[$df]["stdPrice"] = $stdPrices[$num]; // prezzo standard dalla tabella "room"
$roomPrices[$df]["stdRebate"] = $stdRebates[$num]; // sconto standard dalla tabella "room"
$roomPrices[$df]["cusPrice"] = 0; // prezzo custom dalla tabella "room_custom_price"
$roomPrices[$df]["cusRebate"] = 0; // sconto custom dalla tabella "room_custom_price"
$dtAdd = 1;
}
echo "<h3>Room prices - step 1</h3>".show_var( $roomPrices )."<br />";
/* ---------------------------------------- legge il prezzo e lo sconto custom del periodo per la camera */
$query = "SELECT certain_date, price, rebate"
. " FROM room_custom_price"
. " WHERE room_id = ".$room
. " AND (certain_date BETWEEN '".$start_date."' AND '".$end_date."')"
. " ORDER BY certain_date ASC";
//$cusPrices = $mysqli->query($query)->fetch_all(MYSQLI_ASSOC); // prezzi custom elencati per data
$cusPrices = array(
0 => array( "certain_date" => "2019-08-28", "price" => 111 , "rebate" => 0 ),
1 => array( "certain_date" => "2019-08-29", "price" => 222 , "rebate" => 5 ),
2 => array( "certain_date" => "2019-08-30", "price" => 333 , "rebate" => 8 ) );
echo "<h3>Custom prices</h3>".show_var( $cusPrices )."<br />";
/* ---------------------------------------- aggiorna la tabella con il prezzo e lo sconto custom */
foreach ($cusPrices as $k=>$items)
{
$df = $items["certain_date"]; // riprende la data per aggiornare la tabella
if ( !empty( $roomPrices[$df] ) )
{
$roomPrices[$df]["cusPrice"] = $items["price"]; // prezzo custom dalla tabella "room_custom_price"
$roomPrices[$df]["cusRebate"] = $items["rebate"]; // sconto custom dalla tabella "room_custom_price"
}
}
echo "<h3>Room prices - step 2</h3>".show_var( $roomPrices )."<br />";
/* ---------------------------------------- calcola il prezzo finale */
$totPrice = 0;
foreach ($roomPrices as $df=>$items)
{
$Rebate = $Rebate = $items["stdRebate"]; // sceglie lo sconto da applicare
if ( !empty( $items["cusRebate"] ) ) $Rebate = $items["cusRebate"]; // prevale lo sconto custom
if ( empty( $Rebate ) ) { $roomPrices[$df]["stdFinal"] = $items["stdPrice"]; }
else { $roomPrices[$df]["stdFinal"] = round( $items["stdPrice"] * (1 - $Rebate / 100), 2 ); }
$Rebate = 0;
if ( !empty( $items["cusRebate"] ) ) $Rebate = $items["cusRebate"]; // applica lo sconto custom sul prezzo custom
if ( empty( $Rebate ) ) { $roomPrices[$df]["cusFinal"] = $items["cusPrice"]; }
else { $roomPrices[$df]["cusFinal"] = round( $items["cusPrice"] * (1 - $Rebate / 100), 2 ); }
$roomPrices[$df]["totFinal"] = $roomPrices[$df]["stdFinal"]; // sceglie il prezzp da applicare, prevale custom
if ( !empty( $roomPrices[$df]["cusFinal"] ) ) { $roomPrices[$df]["totFinal"] = $roomPrices[$df]["cusFinal"]; }
$totPrice += $roomPrices[$df]["totFinal"];
}
echo "<h3>Room prices - step 3</h3>".show_var( $roomPrices )."<br />";
return;
}
?>
$nomecamera=array( ...
foreach ($result as $prezzo=>$strutture){
foreach ($strutture as $chiave=>$valore){
echo $prezzo .' '.$valore['struttura'].' '.$valore['room_id'].' '.$valore['price']['total'].' '.$valore['price']['operation']['plus']['normal'].' '.$valore['price']['operation']['plus']['custom'].'<br>';
}
}
function print_($my_array,$class='table-info',$primary_class='container-fluid'){
echo '<script>function toggle_this(data){var element = document.getElementsByClassName(data);for(var i in element){element[i].classList.toggle(\'d-none\');}}</script>';
echo '<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" type="text/css" rel="stylesheet" />';
echo '<div class="'.$primary_class.'"><div class="row"><div class="col-md-12"> ';
my_print_r($my_array,$class);
echo '</div></div></div>';
}
function my_print_r($my_array,$class="table-primary") {
if(is_object($my_array))$my_array=get_object_vars($my_array);
if (is_array($my_array)) {
echo "<table class='table ".$class." table-bordered' width=100%>";
$id_collapsemaster=random_string('alnum',24);
echo '<tr><td colspan=2 ><b style="cursor: pointer;" onclick="toggle_this(\''.$id_collapsemaster.'\')">ARRAY</b></td></tr>';
foreach ($my_array as $k => $v) {
echo '<tr class="'.$id_collapsemaster.' d-none">
<td valign="top" style="width:40px;">';
$id_collapse=random_string('alnum',24);
echo '<b style="cursor: pointer;" onclick="toggle_this(\''.$id_collapse.'\')">' . $k . '</strong></td><td class="'.$id_collapse.'">';
my_print_r($v,$class);
echo "</td></tr>";
}
echo "</table>";
return;
}
echo $my_array;
}
//prima iterazione -> carica css e funzione js
print_(['foo'=>'bar','foo1'=>['bar','uno']]);
//seconda iterazione
my_print_r(['foo'=>'bar','foo1'=>['bar','uno']]);
foreach ($result as $prezzo=>$strutture){
while($row = $result->fetch_assoc()) {
$query = "SELECT price_sun, price_mon, price_tue, price_wed, price_thu, price_fri, price_sat"
. " FROM room"
. " WHERE id = ".$room;
//$stdPrices = $mysqli->query($query)->fetch_all(MYSQLI_NUM); // prezzi elencati da domenica = 0 a sabato = 6
$stdPrices = array(90, 10, 20, 30, 40, 50, 60);
echo "<h3>Room standard prices</h3>".show_var( $stdPrices )."<br />";
$query = "SELECT price_sun, price_mon, price_tue, price_wed, price_thu, price_fri, price_sat"
. " FROM room"
. " WHERE id = ".$room;
$result = $mysqli->query($query);// prezzi elencati da domenica = 0 a sabato = 6
while($row = $result->fetch_assoc()) {
extract($row);
$stdPrices = array($row["price_sun"],$row["price_mon"],$row["price_tue"],$row["price_wed"],$row["price_thu"],$row["price_fri"],$row["price_sat"]);
}
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once 'test2.php';
/* ---------------------------------------- */
$room = "1";
$start_date = "2019-08-26"; // data di arrivo
$end_date = "2019-08-30"; // data di partenza
roomPriceCalc($room, $start_date, $end_date);
echo "<h3>TOTAL PRICE : ".$totPrice."</h3>";
/* ---------------------------------------- */
function roomPriceCalc($room, $start_date, $end_date)
{
global $totPrice, $roomPrices;
$date_in = new DateTime($start_date); // data arrivo
$date_out = new DateTime($end_date); // data partenza
$nights = $date_out->diff($date_in); // numero di pernottamenti
$nights = $nights->d;
echo "<br />data di arrivo : " .$start_date
. "<br />data di partenza : ".$end_date
. "<br />pernottamenti : " .$nights
. "<br /><br />";
/* ---------------------------------------- connessione al db */
$hostname = "HOST";
$pass = "PASSWORD";
$muser = "USERDB";
$db = "DB";
$mysqli = new mysqli($hostname, $muser, $pass, $db);
if (mysqli_connect_errno()) { die("Failed to connect to MySQL: " . mysqli_connect_error() ); }
/* ---------------------------------------- legge il prezzo standard della camera */
$query = "SELECT price_sun, price_mon, price_tue, price_wed, price_thu, price_fri, price_sat"
. " FROM room"
. " WHERE id = ".$room;
$result = $mysqli->query($query);// prezzi elencati da domenica = 0 a sabato = 6
while($row = $result->fetch_assoc()) {
extract($row);
$stdPrices = array($row["price_sun"],$row["price_mon"],$row["price_tue"],$row["price_wed"],$row["price_thu"],$row["price_fri"],$row["price_sat"]);
}
echo "<h3>Room standard prices</h3>".show_var( $stdPrices )."<br />";
/* ---------------------------------------- legge lo sconto standard della camera */
$query2 = "SELECT rebate_sun, rebate_mon, rebate_tue, rebate_wed, rebate_thu, rebate_fri, rebate_sat FROM room WHERE id =$room";
$result2 = $mysqli->query($query2);// prezzi elencati da domenica = 0 a sabato = 6
while($row2 = $result2->fetch_assoc()) {
extract($row2);
$stdRebates = array($row2["rebate_sun"],$row2["rebate_mon"],$row2["rebate_tue"],$row2["rebate_wed"],$row2["rebate_thu"],$row2["rebate_fri"],$row2["rebate_sat"]);
}
//$stdRebates = array(9, 0, 0, 0, 4, 5, 6);
echo "<h3>Room standard rebates</h3>".show_var( $stdRebates )."<br />";
/* ---------------------------------------- crea la tabella dei prezzi e sconti per periodo */
$dtAdd = 0;
$roomPrices = array();
for ($dt=0; $dt<$nights; $dt++)
{
$day = $date_in->modify("+".$dtAdd." day");
$df = $day->format("Y-m-d");
$num = $day->format('w');
$roomPrices[$df]["date"] = $df; // giorno esaminato
$roomPrices[$df]["label"] = $day->format('l'); // giorno
$roomPrices[$df]["wDay"] = $num; // numero del giorno, da domenica = 0 a sabato = 6
$roomPrices[$df]["stdPrice"] = $stdPrices[$num]; // prezzo standard dalla tabella "room"
$roomPrices[$df]["stdRebate"] = $stdRebates[$num]; // sconto standard dalla tabella "room"
$roomPrices[$df]["cusPrice"] = 0; // prezzo custom dalla tabella "room_custom_price"
$roomPrices[$df]["cusRebate"] = 0; // sconto custom dalla tabella "room_custom_price"
$dtAdd = 1;
}
echo "<h3>Room prices - step 1</h3>".show_var( $roomPrices )."<br />";
/* ---------------------------------------- legge il prezzo e lo sconto custom del periodo per la camera */
$query3 = "SELECT certain_date, price, rebate"
. " FROM room_custom_price"
. " WHERE room_id = ".$room
. " AND (certain_date BETWEEN '".$start_date."' AND '".$end_date."')"
. " ORDER BY certain_date ASC";
$result3 = $mysqli->query($query3);// prezzi elencati da domenica = 0 a sabato = 6
while($row3 = $result3->fetch_assoc()) {
extract($row3);
$cusPrices[] = array("certain_date" => $row3["certain_date"],"price" => $row3["price"] ,"rebate" => $row3["rebate"]);
}
echo "<h3>Custom prices</h3>".show_var( $cusPrices )."<br />";
/* ---------------------------------------- aggiorna la tabella con il prezzo e lo sconto custom */
foreach ($cusPrices as $k=>$items)
{
$df = $items["certain_date"]; // riprende la data per aggiornare la tabella
if ( !empty( $roomPrices[$df] ) )
{
$roomPrices[$df]["cusPrice"] = $items["price"]; // prezzo custom dalla tabella "room_custom_price"
$roomPrices[$df]["cusRebate"] = $items["rebate"]; // sconto custom dalla tabella "room_custom_price"
}
}
echo "<h3>Room prices - step 2</h3>".show_var( $roomPrices )."<br />";
/* ---------------------------------------- calcola il prezzo finale */
$totPrice = 0;
foreach ($roomPrices as $df=>$items)
{
$Rebate = $Rebate = $items["stdRebate"]; // sceglie lo sconto da applicare
if ( !empty( $items["cusRebate"] ) ) $Rebate = $items["cusRebate"]; // prevale lo sconto custom
if ( empty( $Rebate ) ) { $roomPrices[$df]["stdFinal"] = $items["stdPrice"]; }
else { $roomPrices[$df]["stdFinal"] = round( $items["stdPrice"] * (1 - $Rebate / 100), 2 ); }
$Rebate = 0;
if ( !empty( $items["cusRebate"] ) ) $Rebate = $items["cusRebate"]; // applica lo sconto custom sul prezzo custom
if ( empty( $Rebate ) ) { $roomPrices[$df]["cusFinal"] = $items["cusPrice"]; }
else { $roomPrices[$df]["cusFinal"] = round( $items["cusPrice"] * (1 - $Rebate / 100), 2 ); }
$roomPrices[$df]["totFinal"] = $roomPrices[$df]["stdFinal"]; // sceglie il prezzp da applicare, prevale custom
if ( !empty( $roomPrices[$df]["cusFinal"] ) ) { $roomPrices[$df]["totFinal"] = $roomPrices[$df]["cusFinal"]; }
$totPrice += $roomPrices[$df]["totFinal"];
}
echo "<h3>Room prices - step 3</h3>".show_var( $roomPrices )."<br />";
return;
}
?>
$totPrice = 0;
foreach ($roomPrices as $df=>$items)
{
$Rebate = $Rebate = $items["stdRebate"]; // sceglie lo sconto da applicare
modifica con
$Rebate = $items["stdRebate"]; // sceglie lo sconto da applicare
Notice: Undefined variable: cusPrices in /home/bedcom/public_html/test.php on line 121
Warning: Invalid argument supplied for foreach() in /home/bedcom/public_html/test2.php on line 8
Notice: Undefined variable: cusPrices in /home/bedcom/public_html/test.php on line 127
Warning: Invalid argument supplied for foreach() in /home/bedcom/public_html/test.php on line 127
/* ---------------------------------------- legge il prezzo e lo sconto custom del periodo per la camera */
$query3 = "SELECT certain_date, price, rebate"
. " FROM room_custom_price"
. " WHERE room_id = ".$room
. " AND (certain_date BETWEEN '".$start_date."' AND '".$end_date."')"
. " ORDER BY certain_date ASC";
$result3 = $mysqli->query($query3);// prezzi elencati da domenica = 0 a sabato = 6
if ($result3->num_rows > 0) {
while($row3 = $result3->fetch_assoc()) {
extract($row3);
$cusPrices[] = array("certain_date" => $row3["certain_date"],"price" => $row3["price"] ,"rebate" => $row3["rebate"]);
}
echo "<h3>Custom prices</h3>".show_var( $cusPrices )."<br />";
/* ---------------------------------------- aggiorna la tabella con il prezzo e lo sconto custom */
foreach ($cusPrices as $k=>$items)
{
$df = $items["certain_date"]; // riprende la data per aggiornare la tabella
if ( !empty( $roomPrices[$df] ) )
{
$roomPrices[$df]["cusPrice"] = $items["price"]; // prezzo custom dalla tabella "room_custom_price"
$roomPrices[$df]["cusRebate"] = $items["rebate"]; // sconto custom dalla tabella "room_custom_price"
}
}
echo "<h3>Room prices - step 2</h3>".show_var( $roomPrices )."<br />";
}
/* ---------------------------------------- calcola il prezzo finale */