Coder Social home page Coder Social logo

payslip's Introduction

Employee monthly pay slip

Why built the solution the way

The solution is to develop small software: divide the whole application into self-contained components that each constitutes very few files (e.g. controller, service, data access, test, etc.)

There are top 3 benefits that the solution brings

  1. Keep the software complexity low
  2. Improves maintainability. Each file is relatively small and so is easier to understand and change
  3. Improves modularity. The separate modules are easier to test, implement or design.

Design solution made

Project Structure

The project structure is shown as per below.

src
+-- components     
|   +-- payslip   # Payslip calculation and format 
|   +-- tax       # Tax data access and tax calculation
+-- libs		  # Libraries
+-- app.js        # App entry point

Component layer

In each component, use the principle of SoC to layer the application.

Separate component code into layers: controller, services,and data access layer

Component

Tax calculation solution

The tax rate list only has 5 tax rate level, so we can compare annual salary with each tax rate in the tax rate list to calculate tax at each rate level. If salary is greater than the maximum income of the rate level, the tax at the rate level is (maximum income - start income) * rate. If salary is less than the start income of the rate level, the tax at the rate level is 0. If salary is between the start income and maximum income of the rate level, the tax at the rate level is (maximum income - start income) * rate. Then we add the tax amount at each rate level up to get annual income tax.

How to run code

  1. Install Node.js
  2. Unzip payslip.zip file into a folder
  3. Or download the project from Github
git clone https://github.com/Mattlu88/payslip.git
  1. Open a terminal or windows command and navigate to the directory where the project is unzipped or downloaded
  2. Install application
npm install
npm install -g .
  1. Run application
GenerateMonthlyPayslip "Mary Song" 60000

How to run tests

  1. Install testing framework Jest
npm install
  1. Run test
npm run test

Assumptions && trade-offs

  • Assumptions
    • The application can be run from command line from anywhere by GenerateMonthlyPayslip command on user's system
    • The employee name must be entered
    • The annual salary must be entered and must not be negative
    • The gross monthly income and monthly income tax are rounding to 2 decimal places if necessary
  • Trade-offs
    • The project is using functional programming approach, so a few core concepts are applied such as using pure function and avoiding mutable data or states.

payslip's People

Watchers

Fei Lu 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.