1.0.1 • Published 3 years ago

saas-bill v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Simple SAAS billing engine

Here is a set of function to calculate service due date according to service usage timeline, tariffs, and payments.

It's simple and it does not care about:

  • currency
  • taxes
  • service had to be disabled because of negative balance but it was not (service stopped because of overdue payment continues to collect debt)

Quick start

npm i saas-bill --save

const { getPaymentDue } = require('saas-bill')();

const timeline = [
    {action: "start", date: "2020-01-02"},
]
const tariff = [
    {action: "start", date: "2020-01-02", price: 10000, days: 30.41, creditLimit: 10000},
];
const payments = [
    {date: "2020-01-02", sum: 10000},
];
const due = getPaymentDue(
    timeline,
    tariff,
    payments
);
console.log(due) // to be "2020-03-02"

or

const { getPaymentDue } = require('saas-bill')();
const timeline = [
    {action: "start", date: "2020-01-02"},
    {action: "stop", date: "2020-01-15"},
]
const tariff = [
    {action: "start", date: "2020-01-02", price: 10000, days: 30.41},
];
const payments = [
    {date: "2020-01-02", sum: 10000},
];
const due = getPaymentDue(
    timeline,
    tariff,
    payments
);
console.log(due) // to be "2020-01-04" (service timeline stop date)

Timeline record

FieldMeaning
action"start" or "stop" ("start" can be omitted) of service work period
datedate of "start" (inclusive) or "stop" (exclusive, service does not work in stop day)

Tariff record

FieldMeaning
action"start" (can be omitted)
datetariff activation day
priceprice per period
daysnumber of days in period (30.41 is average month length)
creditLimitcredit limit

Payment record

FieldMeaning
sumSum of payment
datedate of payment