PHP Classes

How to Calculate the Commissions of Financial Operations using the PHP Commission Calculator From CSV File: Get transactions from file and compute commissions

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 34 All time: 11,026 This week: 206Up
Version License PHP version Categories
commission-calculato 1.0MIT/X Consortium ...8PHP 5, Finances, PHP 8
Description 

Author

This package can get transactions from files and compute commissions.

It can read a file in CSV file with the amounts of financial transactions like withdrawals and deposits.

The package can process all the transactions and return the result of calculating the total amount of commissions using rates defined in specific classes that can handle operations which each type of supported transaction type.

Picture of Maniruzzaman Akash
  Performance   Level  
Name: Maniruzzaman Akash <contact>
Classes: 19 packages by
Country: Bangladesh Bangladesh
Age: 28
All time rank: 320244 in Bangladesh Bangladesh
Week rank: 200 Up4 in Bangladesh Bangladesh Up
Innovation award
Innovation award
Nominee: 7x

Example

<?php

use App\CommissionTask\Currency\CurrencyContainer;
use
App\CommissionTask\Currency\Currency;
use
App\CommissionTask\File\CsvReader;
use
App\CommissionTask\Mapper\TransactionItems;
use
App\CommissionTask\Transaction\Transaction;

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

/**
 * Get the filename form cmd and run.
 *
 * @example
 * ```sh
 * php script.php
 * input.csv
 * ```
 */
$fileName = fgets(STDIN);

try {
   
// Handle File from terminal
   
$csvData = file_get_contents(__DIR__ . '/' . trim($fileName));
   
$csvReader = new CsvReader();
   
$csvReader->setRows($csvData);

   
/**
     * Add some currencies.
     *
     * We can also process this from Currencies class.
     * To make the process simpler we've added it
     */
   
$baseCurrency = new Currency();
   
$baseCurrency->setCurrency('EUR');

   
$currencyUsd = new Currency();
   
$currencyUsd->setCurrency('USD');

   
$currencyJpy = new Currency();
   
$currencyJpy->setCurrency('JPY')
        ->
setDecimals(0);

   
$currencyData = CurrencyContainer::getInstance();
   
$currencyData->add($baseCurrency)
        ->
add($currencyUsd)
        ->
add($currencyJpy);

   
// Map transaction data into TransactionItem object.
   
$transactionItems = new TransactionItems();
   
$transactionItems->setItems($csvReader->getRows());

   
// Process transaction
   
$transaction = new Transaction($transactionItems);
   
$transaction->processBulk();
    echo
"\n";
    echo
implode("\r\n", $transaction->responses);
    echo
"\n";
} catch (\
Exception $e) {
    echo
'Something went wrong processing. Error: ' . $e->getMessage();
}


Details

Commission calculator

A simple commission calculator for transaction - Withdraw, Deposit using PHP-8.x - Problem

Requirements

- PHP >= 8.0

How to start

Clone the repository

git clone https://github.com/ManiruzzamanAkash/commission-calculator.git

Go to that folder

cd commission-calculator

Install composer dependencies

composer install

PHPUnit Test

I've added total 33 tests, and 37 assertions for testing codebase.

composer run phpunit

Run PHP-CS

composer run test-cs

Run both PHPUnit + PHP-CS

composer run test

PHPUnit Test Demo

Run project

From terminal, you can run this command to get the result of input.csv's datasets.

input.csv - I've stored some real data in this file for testing commission.

php script.php
input.csv

Run Live

Run with Custom Data

Create a file sample.csv at project root -

Put some data's there and save, eg:

2014-12-31,4,private,withdraw,1200.00,EUR
2015-01-01,4,private,withdraw,1000.00,EUR
2016-01-05,4,private,withdraw,1000.00,EUR
2016-01-05,1,private,deposit,200.00,EUR

Now test our script from terminal

php script
sample.csv

  Files folder image Files (40)  
File Role Description
Files folder imagesrc (9 directories)
Files folder imagetests (4 directories)
Accessible without login Plain text file .php-cs-fixer.php Example Example script
Accessible without login Plain text file .phpunit.result.cache Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file input.csv Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file problem.MD Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file script.php Example Example script

  Files folder image Files (40)  /  src  
File Role Description
Files folder imageAbstracts (3 files)
Files folder imageCommission (1 file)
Files folder imageCore (1 file)
Files folder imageCurrency (5 files)
Files folder imageFile (1 file)
Files folder imageInterfaces (2 files)
Files folder imageMapper (2 files)
Files folder imageTraits (4 files)
Files folder imageTransaction (1 file, 2 directories)

  Files folder image Files (40)  /  src  /  Abstracts  
File Role Description
  Plain text file AbstractFileReader.php Class Class source
  Plain text file AbstractObjectMapper.php Class Class source
  Plain text file AbstractTransaction.php Class Class source

  Files folder image Files (40)  /  src  /  Commission  
File Role Description
  Plain text file Commission.php Class Class source

  Files folder image Files (40)  /  src  /  Core  
File Role Description
  Plain text file DateHelper.php Class Class source

  Files folder image Files (40)  /  src  /  Currency  
File Role Description
  Plain text file Calculator.php Class Class source
  Plain text file Conversion.php Class Class source
  Plain text file ConversionRate.php Class Class source
  Plain text file Currency.php Class Class source
  Plain text file CurrencyContainer.php Class Class source

  Files folder image Files (40)  /  src  /  File  
File Role Description
  Plain text file CsvReader.php Class Class source

  Files folder image Files (40)  /  src  /  Interfaces  
File Role Description
  Plain text file CommissionInterface.php Class Class source
  Plain text file TransactionsInterface.php Class Class source

  Files folder image Files (40)  /  src  /  Mapper  
File Role Description
  Plain text file TransactionItem.php Class Class source
  Plain text file TransactionItems.php Class Class source

  Files folder image Files (40)  /  src  /  Traits  
File Role Description
  Plain text file CommissionTrait.php Class Class source
  Plain text file MoneyFormatterTrait.php Class Class source
  Plain text file SingletonTrait.php Class Class source
  Plain text file TransactionTrait.php Class Class source

  Files folder image Files (40)  /  src  /  Transaction  
File Role Description
Files folder imageDeposit (1 file)
Files folder imageWithdraw (2 files)
  Plain text file Transaction.php Class Class source

  Files folder image Files (40)  /  src  /  Transaction  /  Deposit  
File Role Description
  Plain text file Deposit.php Class Class source

  Files folder image Files (40)  /  src  /  Transaction  /  Withdraw  
File Role Description
  Plain text file WeeklyWithdraw.php Class Class source
  Plain text file Withdraw.php Class Class source

  Files folder image Files (40)  /  tests  
File Role Description
Files folder imageCommission (1 file)
Files folder imageCore (1 file)
Files folder imageCurrency (4 files)
Files folder imageTransaction (3 files)

  Files folder image Files (40)  /  tests  /  Commission  
File Role Description
  Plain text file CommissionTest.php Class Class source

  Files folder image Files (40)  /  tests  /  Core  
File Role Description
  Plain text file DateHelperTest.php Class Class source

  Files folder image Files (40)  /  tests  /  Currency  
File Role Description
  Plain text file CalculatorTest.php Class Class source
  Plain text file ConversionRateTest.php Class Class source
  Plain text file CurrencyContainerTest.php Class Class source
  Plain text file CurrencyTest.php Class Class source

  Files folder image Files (40)  /  tests  /  Transaction  
File Role Description
  Plain text file DepositTest.php Class Class source
  Plain text file TransactionAutomationTest.php Class Class source
  Plain text file WithdrawTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:34
This week:0
All time:11,026
This week:206Up