private function getPriceUmbrellas($FRate, $umbr, $map, $data1, $data2, $season)
 {
     $dt1 = $data1->format('y-m-d');
     $dt2 = $data2->format('y-m-d');
     if ($season) {
         $rates = $FRate->getRate($dt1, $dt2);
         // array di tariffe da considerare
         $period = date_diff($data1, $data2);
         $period = $period->format('%a') + 1;
         // periodo in giorni richiesto dal cliente
         $tar = count($rates);
         if ($tar > 0) {
             $price;
             foreach ($rates as $r) {
                 $price = 0;
                 $p1 = $period;
                 $x = 0;
                 $n = count($r);
                 while ($x < $n) {
                     $tp = $r[$x]->getPeriod();
                     if ($p1 - $tp >= 0) {
                         $price = $price + $r[$x]->getPrice();
                         $p1 = $p1 - $tp;
                     } else {
                         $x++;
                     }
                 }
                 $key = array_search($r, $rates);
                 $k = 0;
                 while ($k < $umbr) {
                     if ($map[$k]['line'] == $key && $map[$k]['status'] == 2) {
                         $map[$k]['price'] = $price;
                     } elseif ($map[$k]['status'] == 1) {
                         $map[$k]['price'] = NULL;
                     }
                     $k++;
                 }
             }
         } else {
             $control1 = $FRate->isInSeason($data1->format('y-m-d'));
             $control2 = $FRate->isInSeason($data2->format('y-m-d'));
             if ($control1 && $control2) {
                 $rates = $FRate->getOtherRate($dt1, $dt2);
                 // array di tariffe da considerare
                 $tar = count($rates);
                 if ($tar > 0) {
                     foreach ($rates as $r) {
                         $price = 0;
                         $currentDate = new DateTime('0000-00-00');
                         foreach ($r as $t) {
                             $ok = false;
                             $line = $t->getLine();
                             // fila a cui è applicata la tariffa
                             $sDate = $t->getStartPeriod();
                             // data inizio tariffa
                             $eDate = $t->getEndPeriod();
                             // data fine tariffa
                             $p = $t->getPeriod();
                             // periodo della tariffa
                             $tro = false;
                             // indica se la tariffa contiene la data iniziale o finale
                             if ($currentDate != $sDate) {
                                 $flag = false;
                                 $currentDate = $sDate;
                             }
                             if (!$flag) {
                                 if ($sDate <= $data1) {
                                     $period = date_diff($data1, $eDate);
                                     $period = $period->format('%a') + 1;
                                     // periodo in giorni
                                     $tro = true;
                                     $flag = true;
                                 }
                                 if ($data2 <= $eDate) {
                                     $period = date_diff($sDate, $data2);
                                     $tro = true;
                                     $period = $period->format('%a') + 1;
                                     // periodo in giorni
                                     $flag = true;
                                 }
                                 if (!$tro) {
                                     $period = date_diff($sDate, $eDate);
                                     $period = $period->format('%a') + 1;
                                     // periodo in giorni
                                     $flag = true;
                                 }
                                 $tro = false;
                             }
                             if ($sDate <= $data1) {
                                 $tro = true;
                                 while (!$ok) {
                                     if ($period - $p >= 0) {
                                         $price = $price + $t->getPrice();
                                         $period = $period - $p;
                                     } else {
                                         $ok = true;
                                     }
                                 }
                             }
                             // fine if
                             if ($data2 <= $eDate) {
                                 $tro = true;
                                 while (!$ok) {
                                     if ($period - $p >= 0) {
                                         $price = $price + $t->getPrice();
                                         $period = $period - $p;
                                     } else {
                                         $ok = true;
                                     }
                                 }
                             }
                             // fine if
                             if (!$tro) {
                                 while (!$ok) {
                                     if ($period - $p >= 0) {
                                         $price = $price + $t->getPrice();
                                         $period = $period - $p;
                                     } else {
                                         $ok = true;
                                     }
                                 }
                             }
                             // fine if
                         }
                         // fine foreach interno
                         $x = 0;
                         while ($x < $umbr) {
                             if ($map[$x]['line'] == $line && $map[$x]['status'] == 2) {
                                 $map[$x]['price'] = $price;
                             } elseif ($map[$x]['status'] == 1) {
                                 $map[$x]['price'] = NULL;
                             }
                             $x++;
                         }
                     }
                     // fine foreach esterno
                 }
             } else {
                 $i = 0;
                 while ($i < $umbr) {
                     $map[$i]['status'] = 1;
                     $map[$i]['paid'] = NULL;
                     $map[$i]['price'] = NULL;
                     $i++;
                 }
             }
         }
     } else {
         $FRate = new FRate();
         $seasonRates = $FRate->getSeasonRates();
         $k = 0;
         while ($k < $umbr) {
             $line = $map[$k]['line'];
             $map[$k]['price'] = $seasonRates["{$line}"]->getPrice();
             $k++;
         }
     }
     return $map;
 }
 private function getPrice($umb, $sdate, $edate, $season)
 {
     if (!$season) {
         $FRate = new FRate();
         $sd = $sdate->format('y-m-d');
         $ed = $edate->format('y-m-d');
         $rates = $FRate->getRateByLine($sd, $ed, $umb->getRow());
         // array di tariffe
         $tar = count($rates);
         $period = date_diff($sdate, $edate);
         $period = $period->format('%a') + 1;
         // periodo da considerare
         if ($tar > 0) {
             $price = 0;
             $p1 = $period;
             $x = 0;
             while ($x < $tar) {
                 $tp = $rates[$x]->getPeriod();
                 if ($p1 - $tp >= 0) {
                     $price = $price + $rates[$x]->getPrice();
                     $p1 = $p1 - $tp;
                 } else {
                     $x++;
                 }
             }
         } else {
             $rates = $FRate->getOtherRateByLine($sd, $ed, $umb->getRow());
             $price = 0;
             $currentDate = new DateTime('0000-00-00');
             foreach ($rates as $r) {
                 $ok = false;
                 $line = $umb->getRow();
                 // fila a cui è applicata la tariffa
                 $sDate = $r->getStartPeriod();
                 // data inizio tariffa
                 $eDate = $r->getEndPeriod();
                 // data fine tariffa
                 $p = $r->getPeriod();
                 // periodo della tariffa
                 $tro = false;
                 // indica se la tariffa contiene la data iniziale o finale
                 if ($currentDate != $sDate) {
                     $flag = false;
                     $currentDate = $sDate;
                 }
                 if (!$flag) {
                     if ($sDate <= $sdate) {
                         $period = date_diff($sdate, $eDate);
                         $period = $period->format('%a') + 1;
                         // periodo in giorni
                         $tro = true;
                         $flag = true;
                     }
                     if ($edate <= $eDate) {
                         $period = date_diff($sDate, $edate);
                         $tro = true;
                         $period = $period->format('%a') + 1;
                         // periodo in giorni
                         $flag = true;
                     }
                     if (!$tro) {
                         $period = date_diff($sDate, $eDate);
                         $period = $period->format('%a') + 1;
                         // periodo in giorni
                         $flag = true;
                     }
                     $tro = false;
                 }
                 if ($sDate <= $sdate) {
                     $tro = true;
                     while (!$ok) {
                         if ($period - $p >= 0) {
                             $price = $price + $t->getPrice();
                             $period = $period - $p;
                         } else {
                             $ok = true;
                         }
                     }
                 }
                 // fine if
                 if ($edate <= $eDate) {
                     $tro = true;
                     while (!$ok) {
                         if ($period - $p >= 0) {
                             $price = $price + $t->getPrice();
                             $period = $period - $p;
                         } else {
                             $ok = true;
                         }
                     }
                 }
                 // fine if
                 if (!$tro) {
                     while (!$ok) {
                         if ($period - $p >= 0) {
                             $price = $price + $t->getPrice();
                             $period = $period - $p;
                         } else {
                             $ok = true;
                         }
                     }
                 }
                 // fine if
             }
             // fine foreach interno
         }
     } else {
         $FRate = new FRate();
         $seasonRates = $FRate->getSeasonRates();
         $price = $seasonRates[$umb->getRow()]->getPrice();
     }
     return $price;
 }