dev-master
9999999-dev https://github.com/francescotrucchia/cashflowLibrary to manage cashflow
MIT
The Requires
- php >=5.3.0
Wallogit.com
2017 © Pedro Peláez
Library to manage cashflow
Cashflow library is a set of php classes useful for manage cashflow operation as income, outcome and recurrent entries., (*1)
``` php <?php, (*2)
require_once DIR.'/../vendor/autoload.php';, (*3)
use Cashflow\Cashflow; use Cashflow\Outcome; use Cashflow\Income;, (*4)
$entries = [ [new \Cashflow\Income(), new \DateTime(date('Y/06/10')), 'Balance', 1000], [new \Cashflow\Expense(), new \DateTime(date('Y/06/11')), 'Credit card', 100], [new \Cashflow\Recurrent(new \Cashflow\Income()), new \DateTime(date('Y/1/10')), 'Salary', 1500, new \DateInterval('P1M'), new \DateTime(date('Y/12/31'))], [new \Cashflow\Recurrent(new \Cashflow\Expense()), new \DateTime(date('Y/1/12')), 'Rent', 500, new \DateInterval('P1M'), new \DateTime(date('Y/12/31'))], ];, (*5)
$cashflow = new Cashflow(new \DateTime(date('Y/1/1')), new \DateTime(date('Y/12/30'))); $cashflow->import($entries); $cashflow->order();, (*6)
$mask = "|%-10.10s |%-30.30s |%15s |%15s |\n";, (*7)
$output = sprintf($mask, 'Date', 'Name', 'Flow', 'Balance');, (*8)
foreach($cashflow->getRows() as $row){ $cashflow->updateAmount($row, $row->getSign()); $output .= sprintf( $mask, $row->getDate()->format('Y-m-d'), $row->getName(), $row->getSign()*$row->getAmount(), $cashflow->getAmount() ); }, (*9)
$output .= PHP_EOL. sprintf('Total income: %s'.PHP_EOL, money_format('%.2n', $cashflow->getTotaleIncome())). sprintf('Total expense: %s'.PHP_EOL, money_format('%.2n', $cashflow->getTotalExpense())). sprintf('Profit: %s'.PHP_EOL, money_format('%.2n', $cashflow->getBalance()));, (*10)
echo $output;, (*11)
```, (*12)
Library to manage cashflow
MIT