示例#1
0
 public function getMap()
 {
     global $config;
     $USession = new USession();
     $view = new VRent();
     $start = $view->getStartDate();
     $end = $view->getEndDate();
     $b = true;
     $FRate = new FRate();
     $FRent = new FRent();
     $to = new DateTime('now');
     //$seasonRates = $FRate->getSeasonRates(); // torna la tariffa stagionale(array)
     $numUmb = $FRent->getNumRent($USession->getValue('ssn'), $to->format('y-m-d'));
     $seasonStart = new DateTime($config['season_start']);
     $seasonEnd = new DateTime($config['season_end']);
     $v = true;
     if ($start == 'STAGIONE' && $end == 'STAGIONE') {
         $t = clone $seasonStart;
         $end = $seasonEnd;
         $t->add(new DateInterval('P20D'));
         if ($to > $t) {
             $start = $to;
         } else {
             $start = $seasonStart;
             $v = false;
         }
     } else {
         try {
             $start = new DateTime($start);
             $end = new DateTime($end);
             if ($start < new DateTime('yesterday') || $end < new DateTime('yesterday')) {
                 $b = false;
             }
             if ($end < $start) {
                 $b = false;
             }
         } catch (Exception $e) {
             $b = false;
         }
         if ($b) {
             $t = clone $seasonStart;
             $t->add(new DateInterval('P20D'));
             // data entro la quale è stagionale
             $t1 = clone $end;
             $t1->add(new DateInterval('P10D'));
             if ($start <= $t && $t1 >= $seasonEnd) {
                 $start = $seasonStart;
                 $end = $seasonEnd;
                 $v = false;
             }
         }
     }
     if ($b) {
         $USession = new USession();
         $FUmbrella = new FUmbrella();
         $data1 = new DateTime($start->format('y-m-d'));
         $data2 = new DateTime($end->format('y-m-d'));
         $dt1 = $data1->format('y-m-d');
         $dt2 = $data2->format('y-m-d');
         $owner = $USession->getValue('ssn');
         $rentUmb = $FUmbrella->loadRentUmbrellaByperiod($dt1, $dt2);
         // ho gli ombrelloni occupati
         $allUmb = $FUmbrella->loadUmbrellas();
         // ho tutti gli ombrelloni
         $map = array();
         /*
          * calcolo della piantina: calcolo di ombrelloni liberi e occupati in
          * un dato periodo temporale.
          */
         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[2] == 1) {
                             // se è pagato
                             $umbrella['paid'] = "true";
                         } else {
                             $umbrella['paid'] = "false";
                         }
                     } else {
                         $umbrella['status'] = 1;
                         $umbrella['paid'] = NULL;
                     }
                 }
             }
             if (!$b) {
                 $umbrella['status'] = 2;
                 $umbrella['paid'] = NULL;
             }
             $map[] = $umbrella;
         }
         $umbr = count($map);
         /*
          * assegnazione numenro di fila agli ombrelloni
          */
         $numLine = $map[$umbr - 1]['place']->getRow();
         // numero di file della piantina
         $numCol = $map[$umbr - 1]['place']->getNumber();
         // numero colonne
         $i = 0;
         $k = 1;
         while ($i < $umbr) {
             $map[$i]['line'] = $k;
             if ($map[$i]['place']->getNumber() == $numCol) {
                 $k++;
             }
             $i++;
         }
         $map = $this->getPriceUmbrellas($FRate, $umbr, $map, $data1, $data2, $v);
         // calcola prezzo
         $view->setData('map', $map);
         $view->setData('numUmb', $numUmb);
         $view->setData('maxUmb', $config['max']);
         $html = $view->fetch('plant.tpl');
         echo $html;
     } else {
         echo 'error';
     }
 }
示例#2
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');
     }
 }