GithubHelp home page GithubHelp logo

node-ledger's Introduction

node-ledger

Simple library to work with accounting ledger.

Features

  • Adapters
  • Double entry
  • Multi currencies

Quickstart

const { Ledger } = require('node-ledger')

(async () => {
  let ledger = new Ledger(); // default using Memory adapter

  await ledger.populate([
    {
      code: 'assets',
      children: [
        { code: 'assets:cash', currency: 'USD' },
        { code: 'assets:bank', currency: 'USD' },
      ],
    },
    {
      code: 'equity',
      children: [
        { code: 'equity:initial', currency: 'USD' },
      ],
    },
    {
      code: 'liabilities',
      children: [
        { code: 'liabilities:debt', currency: 'USD' },
      ],
    },
    {
      code: 'income',
      children: [
        { code: 'income:trading', currency: 'USD' },
      ],
    },
    {
      code: 'expenses',
      children: [
        { code: 'expenses:purchasing', currency: 'USD' },
      ],
    },
  ]);

  // Got initial capital for your business
  await ledger.post({
    date: new Date(),
    desc: 'Initial capital',
    entries: [
      { code: 'assets:bank', db: 1000 },
      { code: 'equity:initial', cr: 1000 },
    ],
  });

  // Purchasing items
  await ledger.post({
    date: new Date(),
    desc: 'Purchase items',
    entries: [
      { code: 'liability:debt', cr: 150 },
      { code: 'expenses:purchasing', db: 150 },
    ],
  });

  // Get bank account
  let bank = await ledger.getAccount('assets:bank');

  // Get bank balance
  let { db, cr } = await bank.getBalance();

  // Get transactions of bank
  let entries = await bank.getEntries();

  // Get all transactions happened in your business
  let entries = await ledger.getEntries();
})();

API

Ledger

Ledger is the main class you would use. Ledger is a root account (extended from Account), so methods apply to account are apply to this class also.

Ledger({ adapter = new Memory() } = {})

async Ledger#init (coa = [])

async Ledger#post ({ date = new Date(), posted, desc = '', entries = [ { code, db, cr } ] })

async Ledger#getAccount (code)

async Ledger#getEntries ()

Ledger implement #getEntries() differently from Account. Method will return all entries happened.

Account

Account({ code, currency = '', parent } = {})

async Account#addChild (account)

async Account#removeChild (account)

async Account#getParent ()

async Account#getChild (code)

async Account#getChildren ()

async Account#getTransactions ()

async Account#getBalance ()

How to create adapter

Implement class with several methods as follow:

#_connect ({ code, currency, parent })

#_disconnect ({ code })

#_get (code)

#_findByParent (parent)

#_post ({ trace, posted, date, desc, entries })

#_transactions ({ code } = {})

#_balance (code)

node-ledger's People

Contributors

reekoheek avatar victorkariuki 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.