Skip to content

Payment amount calculator based on two dates and ruleset

License

Notifications You must be signed in to change notification settings

akifrabbani/molek-php

Repository files navigation

Molek

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

Payment amount calculator based on two dates and ruleset.

Install

Via Composer

$ composer require akifrabbani/molek

Usage

$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);

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Payment amount calculator based on two dates and ruleset

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages