delboy1978uk/expenses

A money in money out thing

v2.1.9 2017-12-15 19:31 UTC

This package is auto-updated.

Last update: 2024-12-04 21:56:27 UTC


README

Build Status Code Coverage Scrutinizer Code Quality
A simple service for storing money in and money out.

Installation

Install the package using composer:

composer require delboy1978uk/expenses

Database Setup

Create a migrant-cfg.php based on vendor/delboy1978uk/common/migrant-cfg.php.dist and add delboy1978uk/expenses in the packages section. Then run:

migrant migrate

Common Package Registration

Expenses works with delboy1978uk/common, which has a Doctrine Entity Manager and a Pimple DIC. Register with the Del\Expenses\ExpensesPackage to the container.

use Del\Common\ContainerService;
use Del\Expenses\ExpensesPackage;

$package = new ExpensesPackage();
ContainerService::getInstance()->registerToContainer($package);

The Expenses Service

$container = ContainerService::getInstance()->getContainer();
$svc = $container['service.expenses'];

Service Methods

$svc->createIncomeFromArray($data);
$svc->createExpenditureFromArray($data);
$svc->createExpenseClaimFromArray($data);
$svc->toArray($entity);
$svc->saveIncome($entity);
$svc->saveExpenditure($entity);
$svc->saveExpenseClaim($entity);
$svc->deleteIncome($entity);
$svc->deleteExpenditure($entity);
$svc->deleteExpenseClaim($entity);
$svc->deleteEntry($entity);
$svc->findByCriteria($criteria);
$svc->findIncomeById($id);
$svc->findExpenditureById($id);
$svc->findExpenseClaimById($id);
$svc->findExpenseClaimById($id);
$svc->saveIncome($income);
$svc->saveExpenditure($expenditure);
$svc->saveExpenseClaim($claim);

Entities

There are three types of entity, which all extend abstract class Entry, Income, Expenditure, and Expense Claim. Income and Expenditure are enough for a sole trader, someone with a limited company can use a ExpenseClaim entity to make an Expenditure that came out your own pocket that you can claim back from the business. All in order to figure out your taxable pay. An EntryInterface has the following methods:

$entity->getId();
$entity->getUserId();
$entity->getDate();
$entity->getAmount();
$entity->getDescription();
$entity->getNote();
$entity->getCategory();
$entity->getType();

Criteria

Searching the DB is simple using a Criteria object:

use Del\Expenses\Criteria\EntryCriteria;

$criteria = new Criteria();
$criteria->setUserId(42);
$criteria->setType('IN'); // also OUT or CLAIM
$criteria->setOrder(Criteria::ORDER_DATE);
$criteria->setLimit(25);
$criteria->setOffset(74);

$results = $svc->findByCriteria($criteria);