Coder Social home page Coder Social logo

boddhisattva / sales_tax Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 1.05 MB

This is a program that calculates sales tax and prints receipt details as part of a purchase of a set of Items

Elixir 100.00%
sales-tax elixir exunit functional-programming

sales_tax's Introduction

About

Based on the given problem statement this is a program that calculates sales tax and prints out a receipt which has the pricing details(including tax) related to the purchase of each item. One can read more about design decisions based on which how this app is built from this section. You can see how a purchase receipt looks like from the sample program output section.

Code related design decisions

  • The entities related to the problem domain are - Line Item, Receipt, Shopping Cart and Tax
  • The different modules used with regard to the application are meant to serve a specific purpose or in other words have a single responsibility. A little more about the purpose of each module is given below:
    • SalesTax - This module is the entrypoint of the command line application. It's responsible to call other relevant modules in order to generate receipt details related to a purchase
    • ReceiptCsvParser - This module is a CSV parser for a file that contains information about the items to be purchased
    • Item - This module maintains information specific to each Item
    • ShoppingCart - This module is used to maintain shopping cart information
    • Sales Tax Calculator - This module is used to calculate sales tax for an item
    • ReceiptGenerator - This module is used to generate receipt details based on a purchase of items

Other implementation details

  • Have used typespecs and some of the module attributes like moduledoc and doc as a source of app related documentation
  • For Code Style and formatting have used Elixir's built in formatter and Credo

Assumptions

  • The program accepts Comma Separated Values(CSV) as input. Hence I've made use of a CsvParser to read CSV data.
  • The CSV files are to be placed in the input directory inorder to be read by the program
  • Price is a positive number
  • Product quantity is a positive integer.
  • Products having the keyword "imported" are identified as imported items
  • Products exempted from basic sales tax are based on pre defined keywords corresponding to the product name

Usage

Dependencies

  • Elixir 1.7
  • Please refer to mix.exs for the other dependencies

Setup

  • Run mix deps.get from a project's root directory to install the related dependencies.

Running the program

From the projects root directory, please follow the below steps in order to run the program:

  • Build an escript(an executable that can be invoked from the command line.) for the project on any machine that has Erlang/OTP installed with the command: mix escript.build

  • Running the executable - In order to run the executable we need to provide an input filename. Sample input files are already included under the input directory. The command for running the executable with a sample input file is:

    ./sales_tax --filename=input/shopping_basket1.csv

Running the tests

  • One can run the tests from the project's root directory with the command mix test

Program Output

  • Below is a sample program output run against the command ./sales_tax --filename=input/shopping_basket3.csv
1, imported bottle of perfume, 32.19
1, bottle of perfume, 20.89
1, packet of headache pills, 9.75
1, imported box of chocolates, 11.85

Sales Taxes: 6.7
Total: 74.68

Scope for further improvements

  • Replacing Float related usage with Decimal
  • Get a list of items exempt from basic sales tax based on user input
  • Incorporate more taxes related to a product like GST etc.,

Feedback

sales_tax's People

Contributors

boddhisattva avatar

Watchers

 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.