Ejemplo n.º 1
0
 public function openSeason()
 {
     global $config;
     $seasonStart = $config['season_start'];
     $seasonEnd = $config['season_end'];
     if ($seasonStart == 'closed' && ($seasonEnd = 'closed')) {
         // recupero dati
         $view = new VAdmin();
         //echo count(explode('%',$view->getRatesString()));
         $umbrella_rows = $view->getUmbrellaRows();
         $palm_rows = $view->getPalmRows();
         $umbrella_number = $view->getUmbrellaNumber();
         $palm_number = $view->getPalmNumber();
         $rates = $view->getRatesString();
         $n_sdate = $view->getNSDate();
         $n_edate = $view->getNEDate();
         $boolean = $this->controlDataPlant($umbrella_rows, $palm_rows, $umbrella_number, $palm_number);
         if ($boolean) {
             $tot = $umbrella_rows + $palm_rows;
             $ArrayRates = $this->controlDataRate($rates, $n_sdate, $n_edate, $tot);
             if ($ArrayRates) {
                 $FRate = new FRate();
                 $FUmbrella = new FUmbrella();
                 //$rates = $this->getRateArray($ArrayRates,$n_sdate,$n_edate,$tot); // calcolo le tariffe da salvare
                 //salvo le tariffe nel db
                 /*foreach($rates as $rat)
                 		{
                 			foreach($rat as $r)
                 					$FRate->saveRate($r);
                 		}*/
                 //calcolo i nuovi ombrelloni
                 $map = $this->getNewMap($palm_rows, $palm_number, $umbrella_rows, $umbrella_number);
                 /*
                  * salvo gli ombrelloni nel db
                  */
                 foreach ($map as $u) {
                     $FUmbrella->saveUmbrella($u);
                 }
                 // salvo l'input nel file
                 $UFile = new UFile();
                 $UFile->saveLine(10, "'{$n_sdate}';", 'Includes/config.inc.php');
                 $UFile->saveLine(12, "'{$n_edate}';", 'Includes/config.inc.php');
                 $config['season_start'] = $n_sdate;
                 $config['season_end'] = $n_edate;
                 return $this->getMap();
             } else {
                 return $view->fetch('season_start_error.tpl');
             }
         } else {
             return $view->fetch('season_start_error.tpl');
         }
     } else {
         return $view->fetch('season_start_error.tpl');
     }
 }
Ejemplo n.º 2
0
 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
 }
Ejemplo n.º 3
0
 public function getRentBySSN($ssn)
 {
     global $config;
     $start = $config['season_start'];
     $end = $config['season_end'];
     if ($start != "closed" && $end != "closed") {
         $Fu = new FUmbrella();
         $Fp = new FPerson();
         $query = "SELECT * FROM rent WHERE \n\t\t\t(startDate>='{$start}' AND endDate<='{$end}') AND SSNOwner = '{$ssn}'";
         $temp = $this->query($query);
         if ($temp) {
             $results = array();
             foreach ($temp as $t) {
                 $umb = $Fu->loadUmbrella($t['linUmb'], $t['numUmb']);
                 $person = $Fp->getOwnerBySSN($t['SSNOwner']);
                 $startD = new DateTime($t['startDate']);
                 $endD = new DateTime($t['endDate']);
                 if ($t['state'] == 1) {
                     $state = true;
                 } else {
                     $state = false;
                 }
                 $results[] = new DRent($person, $umb, $state, intval($t['price']), $startD, $endD);
             }
         } else {
             throw new Exception("Query Failed getRentBySSN FRent");
         }
         return $results;
     } else {
         return false;
     }
 }
Ejemplo n.º 4
0
 public function deleteRent()
 {
     global $config;
     // lettura valori
     $view = new VAdmin();
     $row = intval($view->getRow());
     // fila
     $number = intval($view->getNumber());
     // numero
     $sdate = $view->getStartDate();
     // data di inizio
     $edate = $view->getEndDate();
     // data di fine
     $periodsdate = $view->getPeriodSdate();
     $periodedate = $view->getPeriodEdate();
     $flag = true;
     $FRate = new FRate();
     $FRent = new FRent();
     $season = false;
     if ($periodsdate == 'STAGIONE' && $periodedate == 'STAGIONE') {
         //$seasonRates = $FRate->getSeasonRates(); // tariffa stagionale
         $periodsdate = new DateTime($config['season_start']);
         $periodedate = new DateTime($config['season_end']);
         $season = true;
     } else {
         try {
             $periodsdate = new DateTime($periodsdate);
             $periodedate = new DateTime($periodedate);
         } catch (Exception $e) {
             $flag = false;
         }
     }
     if ($flag) {
         try {
             $sdate = new DateTime($sdate);
             $edate = new DateTime($edate);
         } catch (Exception $e) {
             $flag = false;
         }
     }
     if ($flag) {
         $Fumb = new FUmbrella();
         $umb = $Fumb->loadUmbrella($row, $number);
         if (!$umb) {
             $flag = false;
         }
     }
     if ($flag) {
         if ($FRent->is_Rent($umb, $sdate) == 0) {
             $flag = false;
         }
     }
     if ($flag) {
         $bool = $FRent->deleteRent($umb, $sdate);
         // cancello
         if (!$bool) {
             echo 'error';
         } else {
             $numRent = count($FRent->getRentByPeriod($periodsdate, $periodedate, $umb));
             if ($numRent > 0) {
                 echo '0';
             } else {
                 /*$season = false;
                   if($sdate == $seasonStart && $edate== $seasonEnd) // se la tariffa è stagionale
                   $season = true;*/
                 $price = $this->getPrice($umb, $periodsdate, $periodedate, $season);
                 // calcolo il prezzo dell'ombrellone
                 $lenght = strlen("{$price}");
                 echo "1{$lenght}" . "{$price}";
             }
         }
     } else {
         echo 'error';
     }
     // da modificare la risposta
 }
Ejemplo n.º 5
0
 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');
     }
 }