0.1.4 • Published 10 years ago
node-mrr v0.1.4
node-mrr
Import transactions into a Redis cache and calculates a MRR value for a given period. Requires at least node
Index
Install
npm install -g node-mrr
Usage
Simple example using the moment library to calculate an MRR value.
var moment = require('moment');
var MRR = require('node-mrr');
// First you want to set up the log level and the cache key for redis
MRR.setup({log: 'info', cache: 'this-cache-key'});
// Now create a new transaction
var transaction = MRR.transactionTemplate();
// Set a unique id for this transaction
transaction.id = 'some-unique-id';
// The total amount of the transaction
transaction.amount = 120;
// Set a fee if any
transaction.fee = 12;
// Set the amount of months this transaction covers, in this case
// we are having a 12 month subscription
transaction.months = 12;
// Set a useful description
transaction.description = '12 month subscription for John Doe';
// Now set the date of the transaction
transaction.date = moment().subtract(10, 'months').format();
// We are all set to import this transaction
MRR.importTransactions([transaction], function callback(err) {
// Do something with the error
});
// Set the start and end period that we want to see our MRR of
var start = moment().format();
var end = moment().subtract(30, 'days').format();
// Now we can calculate the MRR, ignoring the fees
MRR.calculateMRR(true, start, end, function callback(err, mrr, list) {
// The list parameter contains all the transactions used for this calculation
// The mrr parameter contains a raw number of the MRR
console.log('The MRR of the given period is', mrr);
});
This will display:
The MRR of the given period is 10