I've made this function for "counting" how many days are in selected period on x price.
Lets say that an renting object has "x" seasons and every season has it's own price.
User selects some other Y period for renting (spending hollidays in rented object)
Now, total period should be calculated from this function, but it is not calculating right.
Here is function
Code: Select all
<?
ponuda("03/01/2007", "03/12/2007", "2");
function ponuda($start_date, $end_date, $objekt)
{
$broj_dana_u_periodu = array();
$start_date_reserv = strtotime($start_date);
$end_date_reserv = strtotime($end_date);
$sezone = array( '03/21/2007-03/31/2007','03/11/2007-03/20/2007', '03/01/2007-03/10/2007', '02/01/2007-02/09/2007', '02/10/2007-02/28/2007');
$cijene = array(57,20,15,35,48);
for($i = 0; $i < count($sezone); $i++)
{
$temp = explode("-", $sezone[$i]);
$temp[0] = round(strtotime($temp[0]) / 86400);
$temp[1] = round(strtotime($temp[1]) / 86400);
$broj_dana_u_periodu[] = $temp[0] . "-" . $temp[1];
}
$dif_days_reserv = round(($end_date_reserv - $start_date_reserv) / 86400);
if($dif_days_reserv > 0)
{
$poc_dan = date("d" , $start_date_reserv);
$poc_mj = date("m" , $start_date_reserv);
$poc_datum = $poc_mj . "/" . $poc_dan . "/" . date("Y" , $start_date_reserv);
$poc_datum = round(strtotime($poc_datum) / 86400);
$kraj_dan = date("d" , $end_date_reserv);
$kraj_mj = date("m" , $end_date_reserv);
$kraj_datum = $kraj_mj . "/" . $kraj_dan . "/" . date("Y" , $end_date_reserv);
$kraj_datum = round(strtotime($kraj_datum) / 86400)-1;
for($i = $poc_datum; $i <= $kraj_datum; $i++)
{
for($j = 0; $j < count($broj_dana_u_periodu); $j++)
{
$sez = explode("-", $broj_dana_u_periodu[$j]);
if(($i >= $sez[0]) && ($i <= $sez[1]))
{
$brojanje_cijena[$j]++;
}
}
}
}
for($i = 0; $i < count($brojanje_cijena); $i++)
{
if(($brojanje_cijena[$i] != 0) && ($cijene[$i] != 0))
{
$ukupno += $brojanje_cijena[$i] * $cijene[$i];
$rezultat .= $brojanje_cijena[$i] . " days at " . $cijene[$i] . " = " . $brojanje_cijena[$i] * $cijene[$i] . " €<br>";
}
}
echo $rezultat;
echo $ukupno;
}
?>1 day(s) at 20€ = 20
10 day(s) at 15€ = 150
Total = 170€
and I'm getting result on
1 day(s) at 20€ = 20
Total = 20€
If somebody can help me find this bug because I'll get mad with it.
Spend last 2 days on this with no result!!
regards
ddragas