public function rent() { global $config; $maxUmb = $config['max']; $FUmbrella = new FUmbrella(); $USession = new USession(); $view = new VRent(); $row = intval($view->getRow()); $number = intval($view->getNumber()); $start = $view->getStartDate(); $end = $view->getEndDate(); $owner = new DPerson($USession->getValue('name'), $USession->getValue('surname'), $USession->getValue('ssn'), $USession->getValue('phone')); $flag = true; $FRate = new FRate(); $FRent = new FRent(); $today = new DateTime('now'); $numUmb = $FRent->getNumRent($USession->getValue('ssn'), $today->format('y-m-d')); $season = false; //$seasonRate = $FRate->getSeasonRates(); // tariffa stagionale $startSeason = new DateTime($config['season_start']); $endSeason = new DateTime($config['season_end']); try { if ($start == 'STAGIONE' && $end == 'STAGIONE') { $t = clone $startSeason; $end = $endSeason; $t->add(new DateInterval('P20D')); // data massima per stagionale if ($today > $t) { $start = $today; } else { $start = $startSeason; $season = true; } } else { $start = new DateTime($start); $end = new DateTime($end); if ($start < new DateTime('yesterday') || $end < new DateTime('yesterday')) { $flag = false; } } $FUmbrella = new FUmbrella(); $umbrella = $FUmbrella->loadUmbrella($row, $number); if (!$umbrella) { $flag = false; } if (!$FUmbrella->isFree($start->format('y-m-d'), $end->format('y-m-d'), $umbrella)) { $flag = false; } if (!($FRate->isInSeason($start->format('y-m-d')) && $FRate->isInSeason($end->format('y-m-d')))) { $flag = false; } if ($end < $start) { $flag = false; } if ($numUmb >= $maxUmb) { $flag = false; } } catch (Exception $e) { $flag = false; } if ($flag) { $t = clone $startSeason; $t->add(new DateInterval('P20D')); // data entro la quale è stagionale $t1 = clone $end; $t1->add(new DateInterval('P10D')); if ($start <= $t && $t1 >= $endSeason) { $season = true; } if (!$season) { $rates = $FRate->getRateByLine($start->format('y-m-d'), $end->format('y-m-d'), $umbrella->getRow()); // array di tariffe da considerare $period = date_diff($start, $end); $period = $period->format('%a') + 1; // periodo in giorni richiesto dal cliente $tar = count($rates); if ($tar > 0) { // il peirodo scelto appartiene ad una sola tariffa(periodo) $this->getRateArray($rates, $period, $start, $owner, $umbrella); } else { $rates = $FRate->getOtherRateByLine($start->format('y-m-d'), $end->format('y-m-d'), $umbrella->getRow()); foreach ($rates as $r) { $f = true; if ($r[0]->getStartPeriod() <= $start) { $period = date_diff($start, $r[0]->getEndPeriod()); $period = $period->format('%a') + 1; $this->getRateArray($r, $period, $start, $owner, $umbrella); $f = false; } if ($end <= $r[0]->getEndPeriod()) { $period = date_diff($r[0]->getStartPeriod(), $end); $period = $period->format('%a') + 1; $this->getRateArray($r, $period, $r[0]->getStartPeriod(), $owner, $umbrella); $f = false; } if ($f) { $period = date_diff($r[0]->getStartPeriod(), $r[0]->getEndPeriod()); $period = $period->format('%a') + 1; $this->getRateArray($r, $period, $r[0]->getStartPeriod(), $owner, $umbrella); } } // fine foreach } // fine else echo '0'; } else { $price = $seasonRate[$umbrella->getRow()]->getPrice(); $Rent = new DRent($owner, $umbrella, false, $price, new DateTime($config['season_start']), new DateTime($config['season_end'])); $FRent->saveRent($Rent); echo '0'; } } else { echo 'error'; } // codice se nel caso i dati arrivati sono sbagliati }
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'); } }