Code Monkey home page Code Monkey logo

accounting's Introduction

Accounting Version Build Status SensioLabsInsight

Accounting lib is your modern comp(t)anion for general accounting in PHP.

Validators

Vat

The lib provides 2 Vat validators:

  • VatValidator: for all knwon Vat numbers systems.
  • ViesValidator: for european Vat numbers only.

Formatters

Vat

TODO

IBAN

TODO

Operations

Pain point

Accounting operations are sometimes subjected to bugs. Why? Because they're made of sets of arithmetic computations, but if they use mathematics, it's with their own rules about rounding results, managing currencies specific number of fraction digits and so on... this is why you should use this lib ;)

Benefits

  • Computations are made in the exact order you want (damn, don't compute this tax before this operation!).
  • Number of fractions of each currency is respected.
  • Rounding rules are applied the right way in each computation.
  • Last but not least, you can develop you own sets of operations and apply them like computation templates. You just have to decorate your results after that, pretty easy ;)

Example

$resultsSet = new OperationSetResult(array(
    'discount_rate' => new Percentage(10),   // Our special discount rate for that lucky guy
    'vat_rate'      => new Percentage(19.6), // French VAT rate
));

$f  = new Factory();
$os = new OperationSet(
    array(
        'price_discounted' => new Operation(
            new Reference\Reference('price_excl_taxes'),
            Operation::MINORATE,
            new Reference\Reference('discount_rate')
        ),
        'price_incl_taxes' => new Operation(
            $f->value(new Reference\Reference('price_discounted')),
            Operation::MAJORATE,
            new Reference\Reference('vat_rate')
        ),
    ),
    $resultsSet
);

$os
    ->getResultsSet()
    ->add(new Price(100, 'EUR'), 'price_excl_taxes');
$os->compute();

echo sprintf("%s\n", $os->getResultsSet());
discount_rate: 10%
vat_rate: 19.6%
price_excl_taxes: 100€
price_discounted: 100€ minorate by 10% => 90€ \ 10€
price_incl_taxes: 90€ majorate by 19.6% => 107.64€ \ 17.64€

Same thing but with Japan Yen (0 decimal fractions currency)

[...]

$os
    ->getResultsSet()
    ->add(new Price(100, 'EUR'), 'price_excl_taxes');
$os->compute();

echo sprintf("%s\n", $os->getResultsSet());
discount_rate: 10%
vat_rate: 19.6%
price_excl_taxes: 100¥JP
price_discounted: 100¥JP minorate by 10% => 90¥JP \ 10¥JP
price_incl_taxes: 90¥JP majorate by 19.6% => 108¥JP \ 18¥JP

Twig extension

You have to define this extension as service:

<service id="rezzza.accounting.twig.extension.iban" class="Rezzza\Accounting\Twig\Extension\IbanExtension" public="false">
    <tag name="twig.extension" />
</service>
{{ "FR1337133713371337133713371"|iban }}
{{ "FR133  7133713371337133713371"|iban }}

{# will output FR13 3713 3713 3713 3713 3713 371 #}

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.