示例#1
0
 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';
     }
 }