echo '<script>window.location = \'./operator_tijdsgebonden_prijzen\';</script>'; /* Exit het script, zodat er direct geredirect wordt. */ exit; } catch (Exception $e) { /* Foutmelding gevangen, sla deze op. */ $errorMessage = $e->getMessage(); } } /* Probeer onderstaande. */ try { /* Probeer de tijdsgebonden items op te halen. */ $time_mounted = Pricing::get_category_time(); /* Probeer de standaard prijs op te halen uit de database. */ $standard_price = Pricing::get_standard_price(); /* Probeer de gegevens van de categorie op te halen. */ $cat_info = Pricing::get_category(); } catch (Exception $e) { /* Foutmelding gevangen, kijken of er al 1 bestaat. */ if (!empty($errorMessage)) { /* Er bestaat al een foutmelding, dus voeg deze eraan toe. */ $errorMessage .= '<br />' . $e->getMessage(); } else { /* Nog geen foutmelding, dus sla deze op. */ $errorMessage = $e->getMessage(); } } } /* Array aanmaken die de nummers van dagen omzet naar de namen van dagen. */ $dagen = array(0 => 'Zondag', 1 => 'Maandag', 2 => 'Dinsdag', 3 => 'Woensdag', 4 => 'Donderdag', 5 => 'Vrijdag', 6 => 'Zaterdag'); ?> <style>
Pricing::edit_subscription_price(); /* Success bericht. */ $_SESSION['subscription']['success'] = 'De wijziging van de abonnement prijs is succesvol geplant, en wordt uitgevoerd wanneer de maand queue verwerkt wordt.'; /* Javascript gebruiken om de pagina te 'refreshen'. */ echo '<script>window.location = \'./operator_abonnement_prijs\';</script>'; /* Exit het script, zodat er direct geredirect wordt. */ exit; } catch (Exception $e) { /* Foutmelding gevangen, sla deze op. */ $errorMessage = $e->getMessage(); } } /* Probeer onderstaande. */ try { /* Probeer de prijs categorieen op te halen. */ $categories = Pricing::get_category(); /* Tel aantal categorieen. */ $categories_count = count($categories); } catch (Exception $e) { /* Foutmelding gevangen, kijken of er al 1 bestaat. */ if (!empty($errorMessage)) { /* Er bestaat al een foutmelding, dus voeg deze eraan toe. */ $errorMessage .= '<br />' . $e->getMessage(); } else { /* Nog geen foutmelding, dus sla deze op. */ $errorMessage = $e->getMessage(); } } } ?> <a><strong><i class="fa fa-sun-o"></i> Abonnement prijzen</strong></a>
/** * Calculcate price * @param int Start time timestamp * @param int End time timestamp * @param int Kilometres */ public function calculatePrice($userId, $startUts, $endUts, $kms) { $startDate = strftime('%F', $startUts); $endDate = strftime('%F', $endUts); $endDateMinusOneDay = strftime('%F', $endUts - 86400); $days = array(); $totalHours = 0; if ($startDate == $endDate) { $days[] = array('startHour' => $this->getHoursFromUts($startUts), 'endHour' => $this->getHoursFromUts($endUts), 'dayOfWeek' => strftime('%u', $startUts)); $totalHours += $this->getHoursFromUts($endUts) - $this->getHoursFromUts($startUts); // one day } elseif ($startDate == $endDateMinusOneDay) { $dayOfWeek = strftime('%u', $startUts); // hen over midnat $days[] = array('startHour' => $this->getHoursFromUts($startUts), 'endHour' => 24, 'dayOfWeek' => $dayOfWeek); $totalHours += 24 - $this->getHoursFromUts($startUts); $days[] = array('startHour' => 0, 'endHour' => $this->getHoursFromUts($endUts), 'dayOfWeek' => $dayOfWeek == 7 ? 1 : $dayOfWeek + 1); $totalHours += $this->getHoursFromUts($endUts) - 0; } else { error_log("too long period"); } // fordel kms foreach ($days as $key => $day) { $days[$key]['kms'] = $kms * ($day['endHour'] - $day['startHour']) / $totalHours; } // Define prices $startRate = 0; /* $pricingMondayFriday = array( 'A' => array('from' => 0, 'to' => 7, 'hourPrice' => 692, 'kmPrice' => 19.3), 'B' => array('from' => 7, 'to' => 15, 'hourPrice' => 644, 'kmPrice' => 17.9), 'C' => array('from' => 15, 'to' => 24, 'hourPrice' => 692, 'kmPrice' => 19.3), ); $pricingWeekend = array( 'A' => array('from' => 0, 'to' => 24, 'hourPrice' => 692, 'kmPrice' => 19.3), ); */ $pricingDefault = array('A' => array('from' => 0, 'to' => 24, 'hourPrice' => 0, 'kmPrice' => 0)); $pricing = array('1' => $pricingDefault, '2' => $pricingDefault, '3' => $pricingDefault, '4' => $pricingDefault, '5' => $pricingDefault, '6' => $pricingDefault, '7' => $pricingDefault); //error_log("calculatePrice (".__LINE__.") userId: " . print_r($this->_app->user->id,1)); $dbPricing = Pricing::where('user_id', $userId)->first(); if (!is_null($dbPricing)) { $obj = json_decode($dbPricing->json); if (is_object($obj)) { foreach ($obj as $dayOfWeek => $day) { if (is_object($day)) { foreach ($day as $daySection => $daySectionConf) { // daySection = A, B or C if (!isset($daySectionConf->active) || !$daySectionConf->active) { continue; } if (isset($daySectionConf->hour)) { $pricing[$dayOfWeek][$daySection]['from'] = intval($daySectionConf->hour); if ($daySection == 'A') { $pricing[$dayOfWeek][$daySection]['to'] = isset($day->B->active) && $day->B->active ? $day->B->hour : 24; } elseif ($daySection == 'B') { $pricing[$dayOfWeek][$daySection]['to'] = isset($day->C->active) && $day->C->active ? $day->C->hour : 24; } else { $pricing[$dayOfWeek][$daySection]['to'] = 24; } } if (isset($daySectionConf->hourlyRate)) { $pricing[$dayOfWeek][$daySection]['hourPrice'] = intval($daySectionConf->hourlyRate); } if (isset($daySectionConf->kmRate)) { $pricing[$dayOfWeek][$daySection]['kmPrice'] = floatval($daySectionConf->kmRate); } } } } if (isset($obj->baseRate)) { $startRate = intval($obj->baseRate); } } } $totalPrice = $startRate; foreach ($days as $day) { if ($day['endHour'] <= $day['startHour']) { exit("wrong time, line: " . __LINE__); } $startHour = $day['startHour']; $endHour = $day['endHour']; $dayOfWeek = $day['dayOfWeek']; $kms = $day['kms']; $startRate = ''; $endRate = ''; $prisstruktur = $pricing[$dayOfWeek]; foreach ($prisstruktur as $takstSymbol => $takst) { if ($takst['from'] <= $startHour && $startHour <= $takst['to']) { $startRate = $takstSymbol; } if ($takst['from'] <= $endHour && $endHour <= $takst['to']) { $endRate = $takstSymbol; } } $takstKombi = $startRate . $endRate; switch ($takstKombi) { case 'AA': case 'BB': case 'CC': $totalPrice += $this->getPriceOnePeriod($prisstruktur, $startHour, $endHour, substr($takstKombi, 0, 1), $kms); break; case 'AB': case 'BC': $firstTakst = substr($takstKombi, 0, 1); $secondTakst = substr($takstKombi, 1, 1); $firstKms = $kms * ($prisstruktur[$firstTakst]['to'] - $startHour) / ($endHour - $startHour); $secondKms = $kms * ($endHour - $prisstruktur[$secondTakst]['from']) / ($endHour - $startHour); $totalPrice += $this->getPriceOnePeriod($prisstruktur, $startHour, $prisstruktur[$firstTakst]['to'], $firstTakst, $firstKms); $totalPrice += $this->getPriceOnePeriod($prisstruktur, $prisstruktur[$secondTakst]['from'], $endHour, $secondTakst, $secondKms); break; case 'AC': $firstKms = $kms * ($prisstruktur['A']['to'] - $startHour) / ($endHour - $startHour); $secondKms = $kms * ($prisstruktur['b']['to'] - $prisstruktur['b']['from']) / ($endHour - $startHour); $thirdKms = $kms * ($endHour - $prisstruktur['C']['from']) / ($endHour - $startHour); $totalPrice += $this->getPriceOnePeriod($prisstruktur, $startHour, $prisstruktur['A']['to'], 'A', $firstKms); $totalPrice += $this->getPriceOnePeriod($prisstruktur, $prisstruktur['B']['from'], $prisstruktur['B']['to'], 'B', $secondKms); $totalPrice += $this->getPriceOnePeriod($prisstruktur, $prisstruktur['C']['from'], $endHour, 'C', $thirdKms); break; default: exit("invalid: {$takstKombi}"); break; } } $response = new \StdClass(); $response->price = $totalPrice; $response->priceRoundedZero = round($totalPrice); $response->priceRoundedTwo = round($totalPrice, 2); return $response; }