Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

medici

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

medici - npm Package Compare versions

Comparing version 0.11.0 to 0.11.1

5

index.js

@@ -32,3 +32,6 @@ var Q, Schema, book, entry, err, journalSchema, mongoose, transactionSchema, _;

},
timestamp: Date,
timestamp: {
type: Date,
"default": Date.now
},
voided: {

@@ -35,0 +38,0 @@ type: Boolean,

67

lib/book.js

@@ -1,2 +0,2 @@

var Book, Q, entry, mongoose, _;
var Book, Q, entry, mongoose, util, _;

@@ -9,2 +9,4 @@ mongoose = require('mongoose');

util = require('util');
Q = require('q');

@@ -131,2 +133,65 @@

Book.prototype.balanceAfterTransaction = function(_id, accounts) {
var deferred, query,
_this = this;
deferred = Q.defer();
query = {
account: accounts
};
query = this.parseQuery(query);
this.transactionModel.findById(_id, function(err, res) {
var dateQuery, group, match;
if (err) {
return deferred.reject(err);
}
if (!res) {
return deferred.reject(new Error('Transaction not found'));
}
dateQuery = {
$or: [
{
'datetime': {
$lt: res.datetime
}
}, {
'datetime': res.datetime,
'timestamp': {
$lte: res.timestamp
}
}
]
};
match = {
$match: {
$and: [query, dateQuery]
}
};
group = {
$group: {
_id: '1',
credit: {
$sum: '$credit'
},
debit: {
$sum: '$debit'
}
}
};
return _this.transactionModel.aggregate(match, group, function(err, result) {
var total;
if (err) {
return deferred.reject(err);
} else {
result = result.shift();
if (result == null) {
return deferred.resolve(0);
}
total = result.credit - result.debit;
return deferred.resolve(total);
}
});
});
return deferred.promise;
};
Book.prototype.ledger = function(query, populate) {

@@ -133,0 +198,0 @@ var deferred, pagination, pop, q, _i, _len,

{
"name": "medici",
"version": "0.11.0",
"version": "0.11.1",
"description": "Simple double-entry accounting for Node + Mongoose",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -31,2 +31,3 @@ var medici, moment, mongoose;

return book.entry('Test Entry 2', moment().subtract('days', 3).toDate()).debit('Assets:Receivable', 700).credit('Income:Rent', 700).commit().then(function(journal) {
_this.journal2 = journal;
journal.memo.should.equal('Test Entry 2');

@@ -107,3 +108,3 @@ journal._transactions.length.should.equal(2);

});
return it('should give you a paginated ledger when requested', function(done) {
it('should give you a paginated ledger when requested', function(done) {
var book;

@@ -123,2 +124,16 @@ book = new medici.book('MyBook');

});
return it('should give you the balance after a specific transaction', function(done) {
var book,
_this = this;
book = new medici.book('MyBook');
return book.balanceAfterTransaction(this.journal._transactions[0], 'Assets').then(function(balance) {
balance.should.equal(-1200);
return book.balanceAfterTransaction(_this.journal2._transactions[1], 'Income').then(function(balance) {
balance.should.equal(700);
return done();
});
}, function(err) {
return done(err);
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc