Payment amount calculator based on two dates and ruleset.
Via Composer
$ composer require akifrabbani/molek
$start = new DateTime("2019-07-20 08:00:00");
$end = new DateTime("2019-09-20 23:00:00");
// Rule for every hour is RM 1.
$ruleset = [
'base_price' => 0,
'operation_hours' => [
'start' => '08:00',
'end' => '20:00'
],
'first' => [
[
'type' => 'minute',
'duration' => 15,
'price' => 0
],
[
'type' => 'hour',
'duration' => 1,
'price' => 4,
'days' => ['sat', 'sun'],
'dates' => [
'2019-07-11'
]
],
[
'type' => 'hour',
'duration' => 1,
'price' => 2,
'days' => ['mon', 'tue', 'wed', 'thu', 'fri']
] ],
'normal' => [
[
'type' => 'hour',
'interval' => 1,
'price' => 1,
'days' => ['mon', 'tue', 'wed', 'thu', 'fri']
],
[
'type' => 'hour',
'interval' => 1,
'price' => 1.5,
'days' => ['sat', 'sun'],
'dates' => [
'2019-07-11'
]
]
],
'max' => [
[
'type' => 'hour',
'duration' => 8,
'price' => 10,
'days' => ['mon', 'tue', 'wed', 'thu', 'fri']
],
[
'type' => 'hour',
'duration' => 8,
'price' => 15,
'days' => ['sat', 'sun'],
'dates' => [
'2019-07-11'
]
]
]
];
$molek = new AkifRabbani\Molek\Molek($ruleset);
echo "Price is RM " . $molek->calculate($start, $end);
- Akif Rabbani (https://github.com/akifrabbani)
- Mohd Hafizuddin M Marzuki (https://github.com/apih)
The MIT License (MIT). Please see License File for more information.