Last active
August 16, 2016 14:53
-
-
Save blacklizard/f90aa250b483f85fa358e888f15bd5ac to your computer and use it in GitHub Desktop.
prorate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// dummy data | |
$start = new DateTime('-9 month'); | |
$expiry = new DateTime("+3 month"); | |
$package_a = 399; | |
$package_b = 699; | |
// expiry day does not count thus the substrction of one day | |
$days = ($expiry->diff($start)->format("%a")) - 1; | |
$remaining_days = ($expiry->diff(new DateTime("NOW"))->format("%a")) - 1; | |
// $payable containes the amount that need to be paid | |
$payable = round($package_b - ( | |
$package_a - ( | |
($package_a / $days) * ($days - $remaining_days)) | |
) , 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment