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() { // recupero dati dal client global $config; $view = new VAdmin(); $flag = true; // var per la correttezza input $nameClient = ucfirst($view->getNameClient()); // nome $surnameClient = ucfirst($view->getSurnameClient()); // cognome $ssnClient = strtoupper($view->getSSNClient()); // codice fiscale $phoneClient = $view->getPhoneClient(); // numero telefonico cliente $sdate = $view->getStartDate(); // data inizio rent $edate = $view->getEndDate(); // data fine rent $row = intval($view->getRow()); // fila ombrellone $number = intval($view->getNumber()); // numero ombrellone $price = intval($view->getPriceRent()); // prezzo $is_paid = $view->is_paid(); // true se è pagato if ($is_paid == "0" || $is_paid == "1") { $is_paid = boolval($is_paid); } else { $flag = false; } $season = false; // variabile che indica la stagione $FRate = new FRate(); //$seasonRates = $FRate->getSeasonRates(); // torna la tariffa stagionale(array) $seasonStart = new DateTime($config['season_start']); $seasonEnd = new DateTime($config['season_end']); $t = clone $seasonStart; $t->add(new DateInterval('P20D')); if ($sdate == 'STAGIONE' && $edate == 'STAGIONE') { $today = new DateTime('now'); if ($today <= $t) { $sdate = $seasonStart; $edate = $seasonEnd; $season = true; } } else { try { $sdate = new DateTime($sdate); $edate = new DateTime($edate); $t1 = clone $edate; $t1 = $t1->add(new DateInterval('P10D')); if ($sdate <= $t && $t1 >= $seasonEnd) { $sdate = $seasonStart; $edate = $seasonEnd; $season = true; } } catch (Exception $e) { $flag = false; } } $FUmbrella = new FUmbrella(); $umb = $FUmbrella->loadUmbrella($row, $number); if (!$umb) { $flag = false; } if (!$season) { try { if ($sdate < new DateTime('yesterday') || $edate < new DateTime('yesterday')) { $flag = false; } if ($edate < $sdate) { $flag = false; } if ($sdate < $seasonStart || $edate > $seasonEnd) { $flag = false; } } catch (Exception $e) { $flag = false; } } try { $person = new DPerson($nameClient, $surnameClient, $ssnClient, $phoneClient); $DRent = new DRent($person, $umb, $is_paid, $price, $sdate, $edate); $FUmb = new FUmbrella(); if (!$FUmb->isFree($sdate->format('y-m-d'), $edate->format('y-m-d'), $umb)) { // contr se l'omb è libero $flag = false; } } catch (Exception $e) { $flag = false; } if ($flag) { $FPerson = new FPerson(); if (!$FPerson->loadClient($ssnClient)) { // se il cliente non è registrato $FPerson->saveClient($person); } // codice per salvare la prenotazione $FRent = new FRent(); $FRent->saveRent($DRent); // salvo la prenotazione nel db echo '0'; } else { echo 'error'; } }