Created
August 14, 2015 11:44
-
-
Save pnegri/89cb2798518c03050e74 to your computer and use it in GitHub Desktop.
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 | |
// Interest Example | |
$our_interest_rate = 2.50; | |
// When passing the interest to the customer, remember that the calculation must always be done with the | |
// base value (The total invoice or the invoice - transaction costs) (Transaction Costs = 4.5% + 30 cents for example) | |
$invoice_total = 100.0; | |
$installments = 12; | |
$installment_total = $invoice_total/$installments; | |
$factor = 1+($our_interest_rate/100); | |
echo "Invoice Total: {$invoice_total}\r\n"; | |
echo "=== HOW TO CALCULATE THE INVOICE TOTAL TO ALWAYS ALLOW ANTECIPATION (Just remember that antecipation is optional) ===\r\n"; | |
echo "Calculating Installments values to Present Date\r\n"; | |
$new_invoice_total = 0.0; | |
$antecipation_date = 30; | |
for ($i=1;$i<($installments+1);$i++) | |
{ | |
$period_factor = $i-($antecipation_date/30); | |
echo "- Installment {$i}x:\r\n"; | |
$installment_factor = pow($factor, $period_factor); | |
echo "-- Installment Factor : {$installment_factor}\r\n"; | |
$cost_to_financing_this_installment = $installment_total - ($installment_total/$installment_factor); | |
echo "-- Cost for financing this installment: {$cost_to_financing_this_installment}\r\n"; | |
$installment_total_antecipated = $installment_total - $cost_to_financing_this_installment; | |
echo "-- Installment total to receive: {$installment_total_antecipated}\r\n"; | |
$new_invoice_total += $installment_total_antecipated; | |
} | |
echo "Invoice amount to receive after payment antecipation interest: {$new_invoice_total}\r\n"; | |
echo "@@@\r\n"; | |
$include_interest_factor = $invoice_total / $new_invoice_total; | |
$invoice_total_with_included_interest = $include_interest_factor * $invoice_total; | |
echo "New invoice total with included interest: {$invoice_total_with_included_interest}\r\n"; | |
echo "\r\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment