public function getMap() { global $config; $VAdmin = new VAdmin(); if ($config['season_end'] != "closed" && $config['season_start'] != "closed") { $FUmbrella = new FUmbrella(); $data1 = new DateTime('now'); $dt = $data1->format('y-m-d'); $rentUmb = $FUmbrella->loadRentUmbrellaByperiod($dt, $dt); // ho gli ombrelloni occupati $allUmb = $FUmbrella->loadUmbrellas(); // ho tutti gli ombrelloni $map = array(); foreach ($allUmb as $u) { $b = false; $c1 = array_search($u, $allUmb); $umbrella['place'] = $u; foreach ($rentUmb as $r) { $c2 = $r[0] . ',' . $r[1]; if ($c1 == $c2) { $b = true; $umbrella['status'] = 1; } } if (!$b) { $umbrella['status'] = 2; } $map[] = $umbrella; } // calcolo tariffa complessiva $FRate = new FRate(); $rates = $FRate->getRate($dt, $dt); // array di tariffe da considerare $period = date_diff($data1, $data1); $period = $period->format('%d') + 1; // periodo in giorni richiesto dal cliente $map = $this->getPriceUmbrellas($rates, $map, $period); // calcola prezzo $VAdmin->setData('map', $map); $html = $VAdmin->fetch('plant.tpl'); $VAdmin->setData('plant', $html); return $VAdmin->fetch('map_manage.tpl'); } else { return $VAdmin->fetch("admin_season_closed.tpl"); } }
private function getPrice($umb, $sdate, $edate, $season) { if (!$season) { $FRate = new FRate(); $sd = $sdate->format('y-m-d'); $ed = $edate->format('y-m-d'); $rates = $FRate->getRateByLine($sd, $ed, $umb->getRow()); // array di tariffe $tar = count($rates); $period = date_diff($sdate, $edate); $period = $period->format('%a') + 1; // periodo da considerare if ($tar > 0) { $price = 0; $p1 = $period; $x = 0; while ($x < $tar) { $tp = $rates[$x]->getPeriod(); if ($p1 - $tp >= 0) { $price = $price + $rates[$x]->getPrice(); $p1 = $p1 - $tp; } else { $x++; } } } else { $rates = $FRate->getOtherRateByLine($sd, $ed, $umb->getRow()); $price = 0; $currentDate = new DateTime('0000-00-00'); foreach ($rates as $r) { $ok = false; $line = $umb->getRow(); // fila a cui è applicata la tariffa $sDate = $r->getStartPeriod(); // data inizio tariffa $eDate = $r->getEndPeriod(); // data fine tariffa $p = $r->getPeriod(); // periodo della tariffa $tro = false; // indica se la tariffa contiene la data iniziale o finale if ($currentDate != $sDate) { $flag = false; $currentDate = $sDate; } if (!$flag) { if ($sDate <= $sdate) { $period = date_diff($sdate, $eDate); $period = $period->format('%a') + 1; // periodo in giorni $tro = true; $flag = true; } if ($edate <= $eDate) { $period = date_diff($sDate, $edate); $tro = true; $period = $period->format('%a') + 1; // periodo in giorni $flag = true; } if (!$tro) { $period = date_diff($sDate, $eDate); $period = $period->format('%a') + 1; // periodo in giorni $flag = true; } $tro = false; } if ($sDate <= $sdate) { $tro = true; while (!$ok) { if ($period - $p >= 0) { $price = $price + $t->getPrice(); $period = $period - $p; } else { $ok = true; } } } // fine if if ($edate <= $eDate) { $tro = true; while (!$ok) { if ($period - $p >= 0) { $price = $price + $t->getPrice(); $period = $period - $p; } else { $ok = true; } } } // fine if if (!$tro) { while (!$ok) { if ($period - $p >= 0) { $price = $price + $t->getPrice(); $period = $period - $p; } else { $ok = true; } } } // fine if } // fine foreach interno } } else { $FRate = new FRate(); $seasonRates = $FRate->getSeasonRates(); $price = $seasonRates[$umb->getRow()]->getPrice(); } return $price; }
private function getPriceUmbrellas($FRate, $umbr, $map, $data1, $data2, $season) { $dt1 = $data1->format('y-m-d'); $dt2 = $data2->format('y-m-d'); if ($season) { $rates = $FRate->getRate($dt1, $dt2); // array di tariffe da considerare $period = date_diff($data1, $data2); $period = $period->format('%a') + 1; // periodo in giorni richiesto dal cliente $tar = count($rates); if ($tar > 0) { $price; foreach ($rates as $r) { $price = 0; $p1 = $period; $x = 0; $n = count($r); while ($x < $n) { $tp = $r[$x]->getPeriod(); if ($p1 - $tp >= 0) { $price = $price + $r[$x]->getPrice(); $p1 = $p1 - $tp; } else { $x++; } } $key = array_search($r, $rates); $k = 0; while ($k < $umbr) { if ($map[$k]['line'] == $key && $map[$k]['status'] == 2) { $map[$k]['price'] = $price; } elseif ($map[$k]['status'] == 1) { $map[$k]['price'] = NULL; } $k++; } } } else { $control1 = $FRate->isInSeason($data1->format('y-m-d')); $control2 = $FRate->isInSeason($data2->format('y-m-d')); if ($control1 && $control2) { $rates = $FRate->getOtherRate($dt1, $dt2); // array di tariffe da considerare $tar = count($rates); if ($tar > 0) { foreach ($rates as $r) { $price = 0; $currentDate = new DateTime('0000-00-00'); foreach ($r as $t) { $ok = false; $line = $t->getLine(); // fila a cui è applicata la tariffa $sDate = $t->getStartPeriod(); // data inizio tariffa $eDate = $t->getEndPeriod(); // data fine tariffa $p = $t->getPeriod(); // periodo della tariffa $tro = false; // indica se la tariffa contiene la data iniziale o finale if ($currentDate != $sDate) { $flag = false; $currentDate = $sDate; } if (!$flag) { if ($sDate <= $data1) { $period = date_diff($data1, $eDate); $period = $period->format('%a') + 1; // periodo in giorni $tro = true; $flag = true; } if ($data2 <= $eDate) { $period = date_diff($sDate, $data2); $tro = true; $period = $period->format('%a') + 1; // periodo in giorni $flag = true; } if (!$tro) { $period = date_diff($sDate, $eDate); $period = $period->format('%a') + 1; // periodo in giorni $flag = true; } $tro = false; } if ($sDate <= $data1) { $tro = true; while (!$ok) { if ($period - $p >= 0) { $price = $price + $t->getPrice(); $period = $period - $p; } else { $ok = true; } } } // fine if if ($data2 <= $eDate) { $tro = true; while (!$ok) { if ($period - $p >= 0) { $price = $price + $t->getPrice(); $period = $period - $p; } else { $ok = true; } } } // fine if if (!$tro) { while (!$ok) { if ($period - $p >= 0) { $price = $price + $t->getPrice(); $period = $period - $p; } else { $ok = true; } } } // fine if } // fine foreach interno $x = 0; while ($x < $umbr) { if ($map[$x]['line'] == $line && $map[$x]['status'] == 2) { $map[$x]['price'] = $price; } elseif ($map[$x]['status'] == 1) { $map[$x]['price'] = NULL; } $x++; } } // fine foreach esterno } } else { $i = 0; while ($i < $umbr) { $map[$i]['status'] = 1; $map[$i]['paid'] = NULL; $map[$i]['price'] = NULL; $i++; } } } } else { $FRate = new FRate(); $seasonRates = $FRate->getSeasonRates(); $k = 0; while ($k < $umbr) { $line = $map[$k]['line']; $map[$k]['price'] = $seasonRates["{$line}"]->getPrice(); $k++; } } return $map; }
public function rent() { $VRent = new VRent(); global $config; if ($config['season_end'] != "closed" && $config['season_start'] != "closed") { $USession = new USession(); $FUmbrella = new FUmbrella(); $data1 = new DateTime('now'); $dt = $data1->format('y-m-d'); $owner = $USession->getValue('ssn'); $rentUmb = $FUmbrella->loadRentUmbrellaByperiod($dt, $dt); // ho gli ombrelloni occupati $allUmb = $FUmbrella->loadUmbrellas(); // ho tutti gli ombrelloni $map = array(); foreach ($allUmb as $u) { $b = false; $c1 = array_search($u, $allUmb); $umbrella['place'] = $u; foreach ($rentUmb as $r) { $c2 = $r[0] . ',' . $r[1]; if ($c1 == $c2) { $b = true; if ($r[3] == $owner) { $sdate = new DateTime($r[4]); $edate = new DateTime($r[5]); $umbrella['sdate'] = $sdate->format('d-m-y'); $umbrella['edate'] = $edate->format('d-m-y'); $umbrella['price'] = $r[6]; $umbrella['status'] = 0; if ($r[0] == 1) { // se è pagato $umbrella['paid'] = true; } else { $umbrella['paid'] = NULL; } } else { $umbrella['status'] = 1; $umbrella['paid'] = NULL; } } } if (!$b) { $umbrella['status'] = 2; $umbrella['paid'] = NULL; } $map[] = $umbrella; } // calcolo tariffa complessiva $FRate = new FRate(); $rates = $FRate->getRate($dt, $dt); // array di tariffe da considerare $period = date_diff($data1, $data1); $period = $period->format('%a') + 1; // periodo in giorni richiesto dal cliente $map = $this->getPriceUmbrellas($rates, $map, $period); // calcolo il prezzo $VRent->setData('map', $map); $VRent->setData('maxUmb', $config['max']); $html = $VRent->fetch('plant.tpl'); $VRent->setData('plant', $html); return $VRent->fetch('rent.tpl'); } else { return $VRent->fetch('user_season_closed.tpl'); } }