Comparing version 0.7.1 to 0.9.0
256
index.js
@@ -1,58 +0,33 @@ | ||
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var Q, Schema, book, entry, err, journalSchema, mongoose, transactionSchema, _; | ||
var Q, Schema, book, entry, err, journalSchema, mongoose, transactionSchema, _; | ||
entry = require('./lib/entry'); | ||
entry = require('./lib/entry'); | ||
book = require('./lib/book'); | ||
book = require('./lib/book'); | ||
mongoose = require('mongoose'); | ||
mongoose = require('mongoose'); | ||
Schema = mongoose.Schema; | ||
Schema = mongoose.Schema; | ||
Q = require('q'); | ||
Q = require('q'); | ||
_ = require('underscore'); | ||
_ = require('underscore'); | ||
try { | ||
mongoose.model('Medici_Transaction'); | ||
} catch (_error) { | ||
err = _error; | ||
transactionSchema = new Schema({ | ||
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, | ||
_original_journal: Schema.Types.ObjectId | ||
}); | ||
mongoose.model('Medici_Transaction', transactionSchema); | ||
} | ||
journalSchema = new Schema({ | ||
try { | ||
mongoose.model('Medici_Transaction'); | ||
} catch (_error) { | ||
err = _error; | ||
transactionSchema = new Schema({ | ||
credit: Number, | ||
debit: Number, | ||
meta: Schema.Types.Mixed, | ||
datetime: Date, | ||
memo: { | ||
type: String, | ||
"default": '' | ||
account_path: [String], | ||
accounts: String, | ||
book: String, | ||
memo: String, | ||
_journal: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'Medici_Journal' | ||
}, | ||
_transactions: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: 'Medici_Transaction' | ||
} | ||
], | ||
book: String, | ||
timestamp: Date, | ||
voided: { | ||
@@ -62,96 +37,119 @@ type: Boolean, | ||
}, | ||
void_reason: String | ||
void_reason: String, | ||
_original_journal: Schema.Types.ObjectId | ||
}); | ||
mongoose.model('Medici_Transaction', transactionSchema); | ||
} | ||
journalSchema.methods["void"] = function(book, reason) { | ||
var deferred, trans_id, voidTransaction, voids, _i, _len, _ref, | ||
_this = this; | ||
deferred = Q.defer(); | ||
if (this.voided === true) { | ||
deferred.reject(new Error('Journal already voided')); | ||
journalSchema = new Schema({ | ||
datetime: Date, | ||
memo: { | ||
type: String, | ||
"default": '' | ||
}, | ||
_transactions: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: 'Medici_Transaction' | ||
} | ||
this.voided = true; | ||
if (reason == null) { | ||
this.void_reason = ''; | ||
], | ||
book: String, | ||
voided: { | ||
type: Boolean, | ||
"default": false | ||
}, | ||
void_reason: String | ||
}); | ||
journalSchema.methods.getTransactionModel = function() { | ||
return mongoose.model('Medici_Transaction'); | ||
}; | ||
journalSchema.methods["void"] = function(book, reason) { | ||
var deferred, trans_id, voidTransaction, voids, _i, _len, _ref, | ||
_this = this; | ||
deferred = Q.defer(); | ||
if (this.voided === true) { | ||
deferred.reject(new Error('Journal already voided')); | ||
} | ||
this.voided = true; | ||
if (reason == null) { | ||
this.void_reason = ''; | ||
} else { | ||
this.void_reason = reason; | ||
} | ||
voidTransaction = function(trans_id) { | ||
var d; | ||
d = Q.defer(); | ||
_this.getTransactionModel().findByIdAndUpdate(trans_id, { | ||
voided: true, | ||
void_reason: _this.void_reason | ||
}, function(err, trans) { | ||
if (err) { | ||
console.error('Failed to void transaction:', err); | ||
return d.reject(err); | ||
} else { | ||
return d.resolve(trans); | ||
} | ||
}); | ||
return d.promise; | ||
}; | ||
voids = []; | ||
_ref = this._transactions; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
trans_id = _ref[_i]; | ||
voids.push(voidTransaction(trans_id)); | ||
} | ||
Q.all(voids).then(function(transactions) { | ||
var key, meta, newMemo, trans, val, valid_fields, _j, _len1; | ||
if (_this.void_reason) { | ||
newMemo = _this.void_reason; | ||
} else { | ||
this.void_reason = reason; | ||
} | ||
console.log('VOID REASON IS:', this.void_reason); | ||
voidTransaction = function(trans_id) { | ||
var d; | ||
d = Q.defer(); | ||
mongoose.model('Medici_Transaction').findByIdAndUpdate(trans_id, { | ||
voided: true, | ||
void_reason: _this.void_reason | ||
}, function(err, trans) { | ||
if (err) { | ||
console.error('Failed to void transaction:', err); | ||
return d.reject(err); | ||
} else { | ||
return d.resolve(trans); | ||
} | ||
}); | ||
return d.promise; | ||
}; | ||
voids = []; | ||
_ref = this._transactions; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
trans_id = _ref[_i]; | ||
voids.push(voidTransaction(trans_id)); | ||
} | ||
Q.all(voids).then(function(transactions) { | ||
var key, meta, newMemo, trans, val, valid_fields, _j, _len1; | ||
if (_this.void_reason) { | ||
newMemo = _this.void_reason; | ||
if (_this.memo.substr(0, 6) === '[VOID]') { | ||
newMemo = _this.memo.replace('[VOID]', '[UNVOID]'); | ||
} else if (_this.memo.substr(0, 8) === '[UNVOID]') { | ||
newMemo = _this.memo.replace('[UNVOID]', '[REVOID]'); | ||
} else if (_this.memo.substr(0, 8) === '[REVOID]') { | ||
newMemo = _this.memo.replace('[REVOID]', '[UNVOID]'); | ||
} else { | ||
if (_this.memo.substr(0, 6) === '[VOID]') { | ||
newMemo = _this.memo.replace('[VOID]', '[UNVOID]'); | ||
} else if (_this.memo.substr(0, 8) === '[UNVOID]') { | ||
newMemo = _this.memo.replace('[UNVOID]', '[REVOID]'); | ||
} else if (_this.memo.substr(0, 8) === '[REVOID]') { | ||
newMemo = _this.memo.replace('[REVOID]', '[UNVOID]'); | ||
} else { | ||
newMemo = '[VOID] ' + _this.memo; | ||
} | ||
newMemo = '[VOID] ' + _this.memo; | ||
} | ||
entry = book.entry(newMemo, null, _this._id); | ||
valid_fields = ['credit', 'debit', 'account_path', 'accounts', 'datetime', 'book', 'memo', 'timestamp', 'voided', 'void_reason', '_original_journal']; | ||
for (_j = 0, _len1 = transactions.length; _j < _len1; _j++) { | ||
trans = transactions[_j]; | ||
trans = trans.toObject(); | ||
meta = {}; | ||
for (key in trans) { | ||
val = trans[key]; | ||
if (key === '_id' || key === '_journal') { | ||
continue; | ||
} | ||
if (valid_fields.indexOf(key) === -1) { | ||
meta[key] = val; | ||
} | ||
} | ||
entry = book.entry(newMemo, null, _this._id); | ||
valid_fields = ['credit', 'debit', 'account_path', 'accounts', 'datetime', 'book', 'memo', 'timestamp', 'voided', 'void_reason', '_original_journal']; | ||
for (_j = 0, _len1 = transactions.length; _j < _len1; _j++) { | ||
trans = transactions[_j]; | ||
trans = trans.toObject(); | ||
meta = {}; | ||
for (key in trans) { | ||
val = trans[key]; | ||
if (key === '_id' || key === '_journal') { | ||
continue; | ||
} | ||
if (trans.credit) { | ||
entry.debit(trans.account_path, trans.credit, meta); | ||
if (valid_fields.indexOf(key) === -1) { | ||
meta[key] = val; | ||
} | ||
if (trans.debit) { | ||
entry.credit(trans.account_path, trans.debit, meta); | ||
} | ||
console.log('did credit or debit'); | ||
} | ||
return entry.commit().then(function(entry) { | ||
return deferred.resolve(entry); | ||
}, function(err) { | ||
return deferred.reject(err); | ||
}); | ||
if (trans.credit) { | ||
entry.debit(trans.account_path, trans.credit, meta); | ||
} | ||
if (trans.debit) { | ||
entry.credit(trans.account_path, trans.debit, meta); | ||
} | ||
} | ||
return entry.commit().then(function(entry) { | ||
return deferred.resolve(entry); | ||
}, function(err) { | ||
return deferred.reject(err); | ||
}); | ||
return deferred.promise; | ||
}; | ||
}, function(err) { | ||
return deferred.reject(err); | ||
}); | ||
return deferred.promise; | ||
}; | ||
mongoose.model('Medici_Journal', journalSchema); | ||
mongoose.model('Medici_Journal', journalSchema); | ||
module.exports = { | ||
book: book | ||
}; | ||
}).call(this); | ||
module.exports = { | ||
book: book | ||
}; |
@@ -14,2 +14,4 @@ var Book, Q, entry, mongoose, _; | ||
this.name = name; | ||
this.transactionModel = mongoose.model('Medici_Transaction'); | ||
this.journalModel = mongoose.model('Medici_Journal'); | ||
} | ||
@@ -61,3 +63,3 @@ | ||
} | ||
keys = _.keys(mongoose.model('Medici_Transaction').schema.paths); | ||
keys = _.keys(this.transactionModel.schema.paths); | ||
for (key in query) { | ||
@@ -99,3 +101,3 @@ val = query[key]; | ||
}; | ||
mongoose.model('Medici_Transaction').aggregate(match, group, function(err, result) { | ||
this.transactionModel.aggregate(match, group, function(err, result) { | ||
var total; | ||
@@ -123,3 +125,3 @@ if (err) { | ||
query = this.parseQuery(query); | ||
q = mongoose.model('Medici_Transaction').find(query); | ||
q = this.transactionModel.find(query); | ||
if (populate) { | ||
@@ -145,3 +147,3 @@ for (_i = 0, _len = populate.length; _i < _len; _i++) { | ||
deferred = Q.defer(); | ||
mongoose.model('Medici_Journal').findById(journal_id, function(err, journal) { | ||
this.journalModel.findById(journal_id, function(err, journal) { | ||
if (err) { | ||
@@ -162,4 +164,5 @@ return deferred.reject(err); | ||
var deferred; | ||
console.log('Listing accounts'); | ||
deferred = Q.defer(); | ||
mongoose.model('Medici_Transaction').find({ | ||
this.transactionModel.find({ | ||
book: this.name | ||
@@ -169,2 +172,3 @@ }).distinct('accounts', function(err, results) { | ||
if (err) { | ||
console.error(err); | ||
return deferred.reject(err); | ||
@@ -183,2 +187,3 @@ } else { | ||
} | ||
console.log('resolving'); | ||
return deferred.resolve(_.uniq(final)); | ||
@@ -185,0 +190,0 @@ } |
{ | ||
"name": "medici", | ||
"version": "0.7.1", | ||
"version": "0.9.0", | ||
"description": "Simple double-entry accounting for Node + Mongoose", | ||
@@ -28,8 +28,12 @@ "main": "index.js", | ||
"mongoose": "~3.8.0", | ||
"q":"*" | ||
"q": "*" | ||
}, | ||
"readme": "medici\n======\n\nDouble-entry accounting system for nodejs + mongoose\n", | ||
"readmeFilename": "README.md", | ||
"_id": "medici@0.1.0", | ||
"_from": "medici@" | ||
"homepage": "https://github.com/jraede/medici", | ||
"devDependencies": { | ||
"should": "~2.1.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
37204
13
561
2
1