Code Monkey home page Code Monkey logo

credit-calc's Introduction

Credit Calculator

Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads

Calculation of the loan repayment schedule with the possibility of specifying early repayment payments. Both the annuity repayment order and the differentiated one are supported.

All monetary values in the package are integers and represent the sum with cents.

Installation

Сomposer: composer require kostikpenzin/credit-calc

Using

require __DIR__ . '/../vendor/autoload.php';

use CreditCalc\Calculator;
use CreditCalc\CreditParams;
use CreditCalc\UnexpectedPayment;
use CreditCalc\RepaymentSchedule;

$params = new CreditParams(new DateTime('2023-10-31 00:00:00'), 100000000, 990, 12, CreditParams::DURATION_MONTH);
$unexpectedPayments = [
    new UnexpectedPayment(10000000, new DateTime('2023-12-15 00:00:00'), UnexpectedPayment::LESS_PAYMENT),
    new UnexpectedPayment(3565411, new DateTime('2023-01-13 00:00:00'), UnexpectedPayment::LESS_LOAN_PERIOD),
    new UnexpectedPayment(15000000, new DateTime('2023-02-29 00:00:00'), UnexpectedPayment::LESS_LOAN_PERIOD),
];

$calculator = new Calculator;

// we consider the repayment schedule with annuity payments
// So that there are differentiated payments, we specify Calculator::TYPE_DIFFERENTIAL as the third parameter

/** @var RepaymentSchedule $schedule Payment schedule */
$schedule = $calculator->calculate($params, $unexpectedPayments, Calculator::TYPE_ANNUITY);
foreach ($schedule as $repayment) {
    /** @var DateTime $date Date of the next payment period */
    $date = $repayment->getDate()->format('d.m.Y');

    /** @var int $payment The amount of the next payment */
    $payment = $repayment->getPayment();

    /** @var int $percents Interest on the next payment */
    $percents = $repayment->getPercents();

    /** @var int $body The body of the loan for the next payment */
    $body = $repayment->getBody();

    /** @var int $body Loan balance after payment */
    $balance = $repayment->getBalance();
}

/** @var int $total Get the amount of all loan payments */
$total = $schedule->calculateTotalPayments();

/** @var int $overpayment Get the amount of overpayment on the loan */
$overpayment = $schedule->calculateOverpayment();

/** @var int $requestedSum Get the loan amount */
$requestedSum = $schedule->getCreditParams()->getRequestedSum();

/** @var string psk The full cost of the loan as a percentage per annum with rounding up to 3 digits */
$psk = $schedule->calculateTotalCost();

credit-calc's People

Contributors

kostikpenzin avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.