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

medici

Package Overview
Dependencies
Maintainers
2
Versions
57
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.12.2 to 1.0.0

src/book.js

36

package.json
{
"name": "medici",
"version": "0.12.2",
"version": "1.0.0",
"description": "Simple double-entry accounting for Node + Mongoose",
"main": "index.js",
"main": "src/index.js",
"scripts": {
"test": "grunt test"
"test": "mocha"
},
"files": [
"src"
],
"repository": {
"type": "git",
"url": "http://github.com/jraede/medici"
"url": "http://github.com/koresar/medici"
},
"keywords": [
"double-entry",
"accounting",
"account",
"finance"
"finance",
"mongodb",
"mongoose"
],

@@ -23,22 +29,12 @@ "author": {

"bugs": {
"url": "https://github.com/jraede/medici/issues"
"url": "https://github.com/koresar/medici/issues"
},
"dependencies": {
"underscore": "~1.5.2",
"mongoose": "~3.8.0",
"q": "*",
"moment": "~2.5.1"
"mongoose": "^4.11.7"
},
"readme": "medici\n======\n\nDouble-entry accounting system for nodejs + mongoose\n",
"readmeFilename": "README.md",
"homepage": "https://github.com/jraede/medici",
"homepage": "https://github.com/koresar/medici",
"devDependencies": {
"should": "~2.1.1",
"grunt": "~0.4.2",
"grunt-exec": "~0.4.3",
"grunt-contrib-coffee": "~0.8.0",
"grunt-sed": "~0.1.1",
"grunt-contrib-watch": "~0.5.3",
"semver": "~2.2.1"
"mocha": "^3.5.0",
"should": "^11.2.1"
}
}

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

[![Build Status](https://travis-ci.org/jraede/medici.png?branch=master)](https://travis-ci.org/jraede/medici)
[![Build Status](https://travis-ci.org/koresar/medici.png?branch=master)](https://travis-ci.org/koresar/medici)

@@ -28,14 +28,19 @@ medici

var medici = require('medici');
```js
const {book} = require('medici');
// The first argument is the book name, which is used to determine which book the transactions and journals are queried from.
var myBook = new medici.book('MyBook');
// The first argument is the book name, which is used to determine which book the transactions and journals are queried from.
const myBook = new book('MyBook');
```
Now write an entry:
// You can specify a Date object as the second argument in the book.entry() method if you want the transaction to be for a different date than today
myBook.entry('Received payment').debit('Assets:Cash', 1000).credit('Income', 1000, {
client:'Joe Blow'
}).write().then(function(journal) { (do something with written journal)});
```js
// You can specify a Date object as the second argument in the book.entry() method if you want the transaction to be for a different date than today
myBook.entry('Received payment')
.debit('Assets:Cash', 1000)
.credit('Income', 1000, {client: 'Joe Blow'})
.write().then(function(journal) { });
```
You can continue to chain debits and credits to the journal object until you are finished. The `entry.debit()` and `entry.credit()` methods both have the same arguments: (account, amount, meta).

@@ -49,8 +54,10 @@

myBook.balance({
account:'Assets:Accounts Receivable',
client:'Joe Blow'
}).then(function(balance) {
console.log("Joe Blow owes me", balance);
});
```js
myBook.balance({
account:'Assets:Accounts Receivable',
client:'Joe Blow'
}).then((balance) => {
console.log("Joe Blow owes me", balance);
});
```

@@ -63,12 +70,14 @@ Note that the `meta` query parameters are on the same level as the default query parameters (account, _journal, start_date, end_date). Medici parses the query and automatically turns any values that do not match top-level schema properties into meta parameters.

var startDate = moment().subtract('months', 1).toDate(); // One month ago
var endDate = new Date(); //today
```js
const startDate = moment().subtract('months', 1).toDate(); // One month ago
const endDate = new Date(); //today
myBook.ledger({
account:'Income'
start_date:startDate
end_date:endDate
}).then(function(transactions) {
// Do something with the returned transaction documents
});
myBook.ledger({
account: 'Income',
start_date: startDate,
end_date: endDate
}).then((transactions) => {
// Do something with the returned transaction documents
});
```

@@ -80,10 +89,11 @@ ## Voiding Journal Entries

To void a journal entry, you can either call the `void(void_reason)` method on a Medici_Journal document, or use the `book.void(journal_id, void_reason)` method if you know the journal document's ID.
myBook.void("123456", "I made a mistake").then(function() {
// Do something after voiding
})
```js
myBook.void("123456", "I made a mistake").then(() => {
// Do something after voiding
})
```
If you do not specify a void reason, the system will set the memo of the new journal to the original journal's memo prepended with "[VOID]".

@@ -94,34 +104,46 @@ ## Document Schema

datetime:Date
memo:
type:String
default:''
_transactions:[
type:Schema.Types.ObjectId
ref:'Medici_Transaction'
]
book:String
voided:
type:Boolean
default:false
void_reason:String
```js
JournalSchema = {
datetime: Date,
memo: {
type: String,
default: ''
},
_transactions: [{
type: Schema.Types.ObjectId,
ref: 'Medici_Transaction'
}],
book: String,
voided: {
type: Boolean,
default: false
},
void_reason: String
}
```
Transactions are schemed as follows:
credit:Number
debit:Number
meta:Schema.Types.Mixed
datetime:Date
account_path:[String]
accounts:String
book:String
memo:String
_journal:
type:Schema.Types.ObjectId
ref:'Medici_Journal'
timestamp:Date
voided:
type:Boolean
default:false
void_reason:String
```js
TransactionSchema = {
credit: Number,
debit: Number,
meta: Schema.Types.Mixed,
datetime: Date,
account_path: [String],
accounts: String,
book: String,
memo: String,
_journal: {
type: Schema.Types.ObjectId,
ref:'Medici_Journal'
},
timestamp: Date,
voided: {
type: Boolean,
default: false
},
void_reason: String
}
```

@@ -138,23 +160,41 @@ Note that the `book`, `datetime`, `memo`, `voided`, and `void_reason` attributes are duplicates of their counterparts on the Journal document. These attributes will pretty much be needed on every transaction search, so they are added to the Transaction document to avoid having to populate the associated Journal every time.

_person:
type:Schema.Types.ObjectId
ref:'Person'
credit:Number
debit:Number
meta:Schema.Types.Mixed
datetime:Date
account_path:[String]
accounts:String
book:String
memo:String
_journal:
type:Schema.Types.ObjectId
ref:'Medici_Journal'
timestamp:Date
voided:
type:Boolean
default:false
void_reason:String
```js
MyTransactionSchema = {
_person: {
type:Schema.Types.ObjectId,
ref:'Person'
},
credit: Number,
debit: Number,
meta: Schema.Types.Mixed,
datetime: Date,
account_path: [String],
accounts: String,
book: String,
memo: String,
_journal: {
type: Schema.Types.ObjectId,
ref: 'Medici_Journal'
},
timestamp: Date,
voided: {
type: Boolean,
default: false
},
void_reason: String
}
```
Then when you query transactions using the `book.ledger()` method, you can specify the related documents to populate as the second argument. E.g., `book.ledger({account:'Assets:Accounts Receivable'}, ['_person']).then()...`
## Changelog
* **v1.0.0** _See [this PR](https://github.com/koresar/medici/pull/5) for more details_
* **BREAKING**: Dropped support of node.js v0.10, v0.12, v4, and io.js. Node.js >= v6 is supported only. This allowed to drop several production dependencies. Also, few bugs were automatically fixed.
* **BREAKING**: Upgraded `mongoose` to v4. This allows `medici` to be used with wider mongodb versions.
* Dropped production dependencies: `moment`, `q`, `underscore`.
* Dropped dev dependencies: `grunt`, `grunt-exec`, `grunt-contrib-coffee`, `grunt-sed`, `grunt-contrib-watch`, `semver`.
* No `.coffee` any more. Using node.js v6 compatible JavaScript only.
* There are no API changes.
* Fixed a [bug](https://github.com/koresar/medici/issues/4). Transaction meta data was not voided correctly.
* This module maintainer is now [koresar](https://github.com/koresar) instead of the original author [jraede](http://github.com/jraede).
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