Giter Club home page Giter Club logo

tax-calculator's Introduction

tax-calculator

A little CLI to calculate income tax.

Setup

To use the CLI you need to build it from source. To do so you need a Rust toolchain. The easiest way to get one is to use rustup.

Once rust is installed you can run the CLI with Cargo:

$ cargo run
   ...
tax-calculator 0.1.0
Chris Connelly <[email protected]>

USAGE:
    tax-calculator <year> <gross_income>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <year>
    <gross_income>

Usage

The CLI requires two positional arguments:

  1. A tax year, specified as the starting year (e.g. 2018 would represent the 2018-2019 tax year). Tax schedules are defined for years 2018, 2017, 2016, and 2015.
  2. A gross income.

Positional arguments can be given to cargo run after a --, for example:

$ cargo run -- 2018 £43,500
    ...
Tax Year: 2018-2019
Gross Salary: £43,500.00

Personal Allowance: £11,850.00

Taxable Income: £31,650.00

Starter rate: £2,000.00 @ 0.19 = £380.00
Basic rate: £10,149.00 @ 0.2 = £2,029.80
Intermediate rate: £19,429.00 @ 0.21 = £4,080.09
Higher rate: £72.00 @ 0.4 = £28.80

Total Tax Due: £6,518.69

Implementation

The CLI entrypoint is implemented in src/main.rs along with most of the argument handling and output formatting.

src/lib.rs defines the public API of the crate and sets up the tax schedules for the years given in the task.

src/gbp.rs contains a minimal implementation of a data type for GBP amounts with impls for idiomatic usage in formatting, parsing, and arithmetic (though only the operators required for the task have been implemented).

src/tax.rs defines structs and methods for working with tax, in particular a tax::Schedule struct representing the income tax schedule for a particular year including the tax free allowance and income tax bands.

You can view the project's documentation with:

$ cargo doc --no-deps --open

Tests

The project has no tests as such, however several of the documentation examples contain assertions to demonstrate return values etc. These assertions are then executed when cargo tests the documentation. These can be run using:

$ cargo test

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.