Exemplo n.º 1
0
function getPrice($area, $detail)
{
    if ($detail == "High") {
        $price = getHighPrice($area);
    } else {
        $price = getStandardPrice($area);
    }
    return number_format($price, 2);
}
/**
 * berechnet einen preis eines zimmers über einen bestimmten zeitraum
 */
function calculatePrice($zimmer_id, $from, $to)
{
    global $link;
    global $root;
    include_once $root . "/include/datumFunctions.php";
    $gesamtpreis = 0;
    $tagVon = getTagFromSQLDate($from);
    $monatVon = getMonatFromSQLDate($from);
    $jahrVon = getJahrFromSQLDate($from);
    $tagBis = getTagFromSQLDate($to);
    $monatBis = getMonatFromSQLDate($to);
    $jahrBis = getJahrFromSQLDate($to);
    $anzahlTage = numberOfDays($monatVon, $tagVon, $jahrVon, $monatBis, $tagBis, $jahrBis);
    //durchlaufe jeden einzelnen tag und lese den preis dazu aus:
    for ($i = 1; $i <= $anzahlTage; $i++) {
        //$date erzeugen:
        //wieviel tage hat der derzeitige monat?
        $anzahlTageDesMonats = getNumberOfDays($monatVon, $jahrVon);
        if ($tagVon + 1 < $anzahlTageDesMonats) {
            $tagVon++;
        } else {
            $tagVon = 1;
            $monatVon++;
        }
        if ($monatVon >= 12) {
            $monatVon = 1;
            $jahrVon++;
        }
        $preis = 0;
        $preis = getPriceOfDate($zimmer_id, $tagVon, $monatVon, $jahrVon, $tagBis, $monatBis, $jahrBis, $link);
        if (empty($preis) || $preis == 0) {
            $preis = getStandardPrice($zimmer_id, $link);
        }
        $gesamtpreis += $preis;
    }
    return $gesamtpreis;
}