Git Product home page Git Product logo

tax-calculator's Introduction

A set of interfaces and methods to clean up your application's tax calculations

Latest Version on Packagist Software License Build Status SensioLabsInsight Quality Score Total Downloads

A set of interfaces and methods to clean up your application's tax calculations. The TaxCalculation class allows you to do calculations with plain numbers and objects that implement the HasTax interface on the fly.

use Spatie\TaxCalculator\TaxCalculation;

$items = $myCart->getItems(); // Should return an array of items that implement `HasTax`

TaxCalculation::fromCollection($items)->basePrice(); // 10.00
TaxCalculation::fromCollection($items)->taxPrice(); // 2.10
TaxCalculation::fromCollection($items)->taxedPrice(); // 12.10

$delivery = TaxCalculation::fromTaxedPrice(7.50, 0.21);

TaxCalculation::fromCollection($items)->add($delivery)->taxedPrice(); // 19.60

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Postcardware

You're free to use this package (it's MIT-licensed), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

The best postcards will get published on the open source page on our website.

Installation

You can install the package via composer:

composer require spatie/tax-calculator

Usage

Interfaces

The interfaces are provided so you can keep working with your domain objects instead of having to pass around floats everywhere. However, they're not strictly necessary to do calculations.

Spatie\TaxCalculator\HasTax

public function basePrice(): float;
public function taxedPrice(): float;
public function taxPrice(): float;
  • basePrice: The item's price excluding taxes
  • taxedPrice: The item's price including taxes
  • taxPrice: The item's tax amount (= taxedPrice() - basePrice())

Spatie\TaxCalculator\HasTaxWithRate

public function taxRate(): float;

HasTaxWithRate extends HasTax, and also has a taxRate method. This is useful for items that have a fixed tax rate, but can't be used on collections that contain items with various rates.

Traits

Spatie\TaxCalculator\Traits\HasTaxWithRate

The HasTaxWithRate trait provides default implementations of taxPrice and taxedPrice, since they can be deducted by a simple multiplication of basePrice and taxRate.

Calculations

...

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

About Spatie

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

License

The MIT License (MIT). Please see License File for more information.

tax-calculator's People

Contributors

sebastiandedeyne avatar adrianmrn avatar freekmurze avatar zenginechris avatar peter279k avatar

Watchers

James Cloos avatar  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.