xero-node
Advanced tools
Comparing version 2.4.0 to 2.5.0
@@ -9,3 +9,2 @@ var _ = require('lodash'), | ||
Payroll = require('./payroll'), | ||
xml2js = require('xml2js'), | ||
events = require('events'); | ||
@@ -134,14 +133,10 @@ | ||
var payload = { xml: body }; | ||
var contentType; | ||
if (options.contentType) { | ||
payload = body; | ||
contentType = options.contentType; | ||
} | ||
var payload = body; | ||
var contentType = options.contentType || 'application/json'; | ||
self.oa[method](url, self.options.accessToken, self.options.accessSecret, payload, contentType, function(err, data, res) { | ||
if (err && data && data.indexOf('oauth_problem') >= 0) { | ||
data = JSON.parse(data); | ||
if (err && data && data['ErrorNumber'] >= 0) { | ||
var errObj = new Error(method.toUpperCase() + ' call failed with: ' + err.statusCode); | ||
errObj.data = qs.parse(data); | ||
errObj.data = data; | ||
reject(errObj); | ||
@@ -152,28 +147,20 @@ callback && callback(errObj); | ||
self.xml2js(data) | ||
.then(function(obj) { | ||
if (err) { | ||
var exception = ""; | ||
if (obj.ApiException) | ||
exception = obj.ApiException; | ||
else if (obj.Response.ErrorNumber) | ||
exception = obj.Response; | ||
var errObj = new Error(method.toUpperCase() + ' call failed with: ' + err.statusCode + ' and exception: ' + JSON.stringify(exception, null, 2)); | ||
reject(errObj); | ||
callback && callback(errObj); | ||
} else { | ||
var ret = { response: obj.Response, res: res }; | ||
if (options.entityConstructor) { | ||
ret.entities = self.convertEntities(obj.Response, options); | ||
} | ||
resolve(ret); | ||
callback && callback(null, obj, res, ret.entities); | ||
} | ||
if (err) { | ||
var exception = ""; | ||
if (data.ApiException) | ||
exception = data.ApiException; | ||
else if (data.ErrorNumber) | ||
exception = data; | ||
var errObj = new Error(method.toUpperCase() + ' call failed with: ' + err.statusCode + ' and exception: ' + JSON.stringify(exception, null, 2)); | ||
reject(errObj); | ||
callback && callback(errObj); | ||
} else { | ||
}) | ||
.catch(function(err) { | ||
console.error(err); | ||
reject(err); | ||
callback && callback(err); | ||
}) | ||
var ret = { response: data, res: res }; | ||
if (options.entityConstructor) { | ||
ret.entities = self.convertEntities(data, options); | ||
} | ||
resolve(ret); | ||
callback && callback(null, data, res, ret.entities); | ||
} | ||
@@ -183,8 +170,6 @@ }); | ||
.catch(function(err) { | ||
console.log(err); | ||
if (err && err.data) { | ||
var dataParts = qs.parse(err.data); | ||
var errObj = new Error(method.toUpperCase() + ' call failed with: ' + err.statusCode); | ||
errObj.data = dataParts; | ||
errObj.data = data; | ||
reject(errObj); | ||
@@ -210,2 +195,5 @@ callback && callback(errObj); | ||
self.oa.delete(url, self.options.accessToken, self.options.accessSecret, function(err, data, res) { | ||
if (data) | ||
data = JSON.parse(data); | ||
if (options.stream && !err) { | ||
@@ -215,5 +203,5 @@ // Already done | ||
} | ||
if (err && data && data.indexOf('oauth_problem') >= 0) { | ||
if (err && data && data['ErrorNumber'] >= 0) { | ||
var errObj = new Error('DELETE call failed with: ' + err.statusCode); | ||
errObj.data = qs.parse(data); | ||
errObj.data = data; | ||
reject(errObj); | ||
@@ -236,22 +224,14 @@ callback && callback(errObj); | ||
self.xml2js(data) | ||
.then(function(obj) { | ||
var ret = { response: obj.Response, res: res }; | ||
resolve(ret); | ||
callback && callback(null, obj, res); | ||
}) | ||
.catch(function(err) { | ||
console.error(err); | ||
reject(err); | ||
callback && callback(err); | ||
}) | ||
var ret = { response: data, res: res }; | ||
resolve(ret); | ||
callback && callback(null, data, res); | ||
}, { stream: options.stream }); | ||
}) | ||
.catch(function(err) { | ||
console.log(err); | ||
if (err && err.data) { | ||
var dataParts = qs.parse(err.data); | ||
var errObj = new Error('DELETE call failed with: ' + err.statusCode); | ||
errObj.data = dataParts; | ||
errObj.data = data; | ||
reject(errObj); | ||
@@ -280,4 +260,7 @@ callback && callback(errObj); | ||
if (options.format) | ||
if (options.format) { | ||
self.oa._headers['Accept'] = 'application/' + options.format; | ||
} else { | ||
self.oa._headers['Accept'] = 'application/json'; | ||
} | ||
@@ -292,8 +275,6 @@ self.checkExpiry() | ||
.catch(function(err) { | ||
console.log(err); | ||
if (err && err.data) { | ||
var dataParts = qs.parse(err.data); | ||
var errObj = new Error('GET call failed with: ' + err.statusCode); | ||
errObj.data = dataParts; | ||
errObj.data = data; | ||
reject(errObj); | ||
@@ -331,2 +312,4 @@ callback && callback(errObj); | ||
self.oa.get(url, self.options.accessToken, self.options.accessSecret, function(err, data, res) { | ||
data = JSON.parse(data) | ||
if (options.stream && !err) { | ||
@@ -337,6 +320,4 @@ // Already done | ||
if (err && data) { | ||
var dataParts = qs.parse(data); | ||
var errObj = new Error('GET call failed with: ' + err.statusCode); | ||
errObj.data = dataParts; | ||
errObj.data = data; | ||
reject(errObj); | ||
@@ -347,35 +328,28 @@ callback && callback(errObj); | ||
self.xml2js(data) | ||
.then(function(obj) { | ||
var ret = { response: obj.Response, res: res }; | ||
if (err) { | ||
var errObj = new Error('GET call failed with: ' + err.statusCode + ' and exception: ' + JSON.stringify(obj.ApiException, null, 2)); | ||
reject(errObj); | ||
callback && callback(errObj); | ||
return; | ||
} | ||
if (options.pager && options.pager.callback) { | ||
options.pager.callback(err, ret, function(err, result) { | ||
result = _.defaults({}, result, { recordCount: 0, stop: false }); | ||
if (!result.stop) | ||
getResource(result.nextOffset || ++offset); | ||
else | ||
done(); | ||
}) | ||
return; | ||
} | ||
var ret = { response: data, res: res }; | ||
if (err) { | ||
var errObj = new Error('GET call failed with: ' + err.statusCode + ' and exception: ' + JSON.stringify(data.ApiException, null, 2)); | ||
reject(errObj); | ||
callback && callback(errObj); | ||
return; | ||
} | ||
done(); | ||
if (options.pager && options.pager.callback) { | ||
options.pager.callback(err, ret, function(err, result) { | ||
result = _.defaults({}, result, { recordCount: 0, stop: false }); | ||
if (!result.stop) | ||
getResource(result.nextOffset || ++offset); | ||
else | ||
done(); | ||
}) | ||
return; | ||
} | ||
function done() { | ||
resolve(ret); | ||
callback && callback(null, obj, res); | ||
} | ||
}) | ||
.catch(function(err) { | ||
console.error(err); | ||
reject(err); | ||
callback && callback(err); | ||
}) | ||
done(); | ||
function done() { | ||
resolve(ret); | ||
callback && callback(null, data, res); | ||
} | ||
}, { stream: options.stream }); | ||
@@ -400,8 +374,6 @@ | ||
.catch(function(err) { | ||
console.log(err); | ||
if (err && err.data) { | ||
var dataParts = qs.parse(err.data); | ||
var errObj = new Error('GET call failed with: ' + err.statusCode); | ||
errObj.data = dataParts; | ||
errObj.data = data; | ||
reject(errObj); | ||
@@ -422,6 +394,4 @@ callback && callback(errObj); | ||
if (err && data) { | ||
var dataParts = qs.parse(data); | ||
var errObj = new Error('GET call failed with: ' + err.statusCode); | ||
errObj.data = dataParts; | ||
errObj.data = data; | ||
reject(errObj); | ||
@@ -468,3 +438,3 @@ callback && callback(errObj); | ||
var entities = []; | ||
var entitiesTop = _.deepResult(obj, options.entityPath); | ||
var entitiesTop = obj[options.entityPath]; | ||
if (!entitiesTop) | ||
@@ -546,20 +516,9 @@ return []; | ||
}, | ||
xml2js: function(xml) { | ||
var parser = new xml2js.Parser({ | ||
explicitArray: false, | ||
valueProcessors: [xml2js.processors.parseBooleans] | ||
}); | ||
return new Promise(function(resolve, reject) { | ||
parser.parseString(xml, function(err, result) { | ||
if (err) return reject(err); | ||
resolve(result); | ||
}); | ||
}); | ||
convertDate: function(d) { | ||
if (typeof d.getDate === 'function') { | ||
return d.toISOString().split("T")[0] | ||
} else { | ||
return d | ||
} | ||
}, | ||
js2xml: function(obj, rootName) { | ||
var builder = new xml2js.Builder({ rootName: rootName, headless: true }); | ||
var obj = builder.buildObject(obj); | ||
return obj; | ||
}, | ||
checkExpiry: function() { | ||
@@ -569,6 +528,6 @@ | ||
* CheckExpiry is a helper function that will compare the current token expiry to the current time. | ||
* | ||
* | ||
* As there is potential for a time difference, instead of waiting all the way until the current time | ||
* has passed the expiry time, we instead add 3 minutes to the current time, and use that as a comparison. | ||
* | ||
* | ||
* This ensures that if the token is 'nearing' the expiry, it'll attempt to be refreshed. | ||
@@ -581,3 +540,3 @@ */ | ||
if (checkTime >= expiry) { | ||
console.log("Refreshing Access Token"); | ||
return this.refreshAccessToken(); | ||
@@ -596,3 +555,3 @@ } else { | ||
constructor: function(config) { | ||
console.log('PrivateApplication::constructor'); | ||
Application.call(this, Object.assign({}, config, { type: 'private' })); | ||
@@ -621,3 +580,3 @@ }, | ||
constructor: function(options) { | ||
console.log('RequireAuthorizationApplication::constructor'); | ||
Application.call(this, options); | ||
@@ -697,8 +656,8 @@ }, | ||
setOptions: function(options) { | ||
console.log("Setting options"); | ||
if (this.options.accessToken) { | ||
if (options.accessToken !== this.options.accessToken) { | ||
if (this.eventEmitter) { | ||
console.log("Emitting event"); | ||
this.eventEmitter.emit('xeroTokenUpdate', options); | ||
@@ -716,3 +675,3 @@ } | ||
constructor: function(config) { | ||
console.log('PublicApplication::constructor'); | ||
RequireAuthorizationApplication.call(this, Object.assign({}, config, { type: 'public' })); | ||
@@ -737,3 +696,3 @@ }, | ||
constructor: function(config) { | ||
console.log('PartnerApplication::constructor'); | ||
RequireAuthorizationApplication.call(this, Object.assign({}, config, { type: 'partner' })); | ||
@@ -781,2 +740,2 @@ }, | ||
module.exports.PartnerApplication = PartnerApplication; | ||
module.exports.Application = Application; | ||
module.exports.Application = Application; |
@@ -27,3 +27,3 @@ var _ = require('lodash') | ||
var self = this; | ||
console.log('Core::constructor'); | ||
this._application = application; | ||
@@ -50,2 +50,2 @@ | ||
module.exports = Core; | ||
module.exports = Core; |
@@ -1,56 +0,62 @@ | ||
var _ = require('lodash'), | ||
Entity = require('../entity') | ||
'use strict'; | ||
var AccountSchema = new Entity.SchemaObject({ | ||
Code: { type: String, toObject: 'always' }, | ||
Name: { type: String, toObject: 'always' }, | ||
Type: { type: String, toObject: 'always' }, | ||
BankAccountNumber: { type: String, toObject: 'always' }, | ||
Status: { type: String, toObject: 'never' }, | ||
Description: { type: String, toObject: 'always' }, | ||
BankAccountType: { type: String, toObject: 'hasValue' }, | ||
CurrencyCode: { type: String, toObject: 'never' }, | ||
TaxType: { type: String, toObject: 'always' }, | ||
EnablePaymentsToAccount: { type: Boolean, toObject: 'always' }, | ||
ShowInExpenseClaims: { type: Boolean, toObject: 'always' }, | ||
AccountID: { type: String, toObject: 'always' }, | ||
Class: { type: String, toObject: 'never' }, | ||
SystemAccount: { type: String, toObject: 'never' }, | ||
ReportingCode: { type: String, toObject: 'never' }, | ||
ReportingCodeName: { type: String, toObject: 'never' }, | ||
HasAttachments: { type: Boolean, toObject: 'always' }, | ||
UpdatedDateUTC: { type: String, toObject: 'hasValue' } | ||
const Entity = require('../entity'); | ||
const AccountSchema = Entity.SchemaObject({ | ||
Code: { type: String, toObject: 'always' }, | ||
Name: { type: String, toObject: 'always' }, | ||
Type: { type: String, toObject: 'always' }, | ||
BankAccountNumber: { type: String, toObject: 'always' }, | ||
Status: { type: String, toObject: 'never' }, | ||
Description: { type: String, toObject: 'always' }, | ||
BankAccountType: { type: String, toObject: 'hasValue' }, | ||
CurrencyCode: { type: String, toObject: 'never' }, | ||
TaxType: { type: String, toObject: 'always' }, | ||
EnablePaymentsToAccount: { type: Boolean, toObject: 'always' }, | ||
ShowInExpenseClaims: { type: Boolean, toObject: 'always' }, | ||
AccountID: { type: String, toObject: 'always' }, | ||
Class: { type: String, toObject: 'never' }, | ||
SystemAccount: { type: String, toObject: 'never' }, | ||
ReportingCode: { type: String, toObject: 'never' }, | ||
ReportingCodeName: { type: String, toObject: 'never' }, | ||
HasAttachments: { type: Boolean, toObject: 'always' }, | ||
UpdatedDateUTC: { type: Date, toObject: 'never' }, | ||
}); | ||
var Account = Entity.extend(AccountSchema, { | ||
constructor: function(application, data, options) { | ||
console.log('Account::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function(data, options) {}, | ||
toXml: function() { | ||
var account = _.omit(this.toObject()); | ||
return this.application.js2xml(account, 'Account'); | ||
}, | ||
getAttachments: function(options) { | ||
return this.application.core.attachments.getAttachments('Accounts/' + this.AccountID, options) | ||
}, | ||
save: function(options) { | ||
var self = this; | ||
var xml = '<Accounts>' + this.toXml() + '</Accounts>'; | ||
var path, method; | ||
if (this.AccountID) { | ||
path = 'Accounts/' + this.AccountID; | ||
method = 'post' | ||
} else { | ||
path = 'Accounts'; | ||
method = 'put' | ||
} | ||
return this.application.putOrPostEntity(method, path, xml, { entityPath: 'Accounts.Account', entityConstructor: function(data) { return self.application.core.accounts.newAccount(data) } }) | ||
const Account = Entity.extend(AccountSchema, { | ||
constructor: function(...args) { | ||
this.Entity.apply(this, args); | ||
}, | ||
initialize: function(data, options) {}, | ||
getAttachments: function(options) { | ||
return this.application.core.attachments.getAttachments( | ||
'Accounts/' + this.AccountID, | ||
options | ||
); | ||
}, | ||
save: function(options) { | ||
var self = this; | ||
var path, method; | ||
if (this.AccountID) { | ||
path = 'Accounts/' + this.AccountID; | ||
method = 'post'; | ||
} else { | ||
path = 'Accounts'; | ||
method = 'put'; | ||
} | ||
return this.application.putOrPostEntity( | ||
method, | ||
path, | ||
JSON.stringify(self), | ||
{ | ||
entityPath: 'Accounts', | ||
entityConstructor: function(data) { | ||
return self.application.core.accounts.newAccount(data); | ||
}, | ||
} | ||
); | ||
}, | ||
}); | ||
module.exports = Account; | ||
module.exports.Account = Account; | ||
module.exports.AccountSchema = AccountSchema; |
@@ -5,3 +5,3 @@ var _ = require('lodash'), | ||
var AttachmentSchema = new Entity.SchemaObject({ | ||
var AttachmentSchema = Entity.SchemaObject({ | ||
AttachmentID: { type: String, toObject: 'never' }, | ||
@@ -15,6 +15,5 @@ FileName: { type: String, toObject: 'always' }, | ||
var Attachment = Entity.extend(AttachmentSchema, { | ||
constructor: function(application, data, options) { | ||
console.log('Attachment::constructor'); | ||
this.Entity.apply(this, arguments); | ||
@@ -43,3 +42,3 @@ }, | ||
options.contentType = this.MimeType; | ||
options.entityPath = 'Attachments.Attachment'; | ||
options.entityPath = 'Attachments'; | ||
options.entityConstructor = function(data) { | ||
@@ -54,3 +53,3 @@ return self.application.core.attachments.newAttachment(data); | ||
module.exports = Attachment; | ||
module.exports.Attachment = Attachment; | ||
module.exports.AttachmentSchema = AttachmentSchema; |
@@ -1,87 +0,71 @@ | ||
var _ = require('lodash'), | ||
Entity = require('../entity'), | ||
ContactSchema = require('./contact').ContactSchema, | ||
Contact = require('./contact'), | ||
LineItemSchema = require('../shared').LineItemSchema | ||
'use strict'; | ||
var BankTransactionSchema = new Entity.SchemaObject({ | ||
Type: { type: String, toObject: 'always' }, | ||
Contact: { type: ContactSchema, toObject: 'always' }, | ||
LineItems: { type: Array, arrayType: LineItemSchema, toObject: 'always' }, | ||
BankAccount: { | ||
type: { | ||
AccountID: { type: String, toObject: 'always' } | ||
}, | ||
toObject: 'always' | ||
const _ = require('lodash'); | ||
const Entity = require('../entity'); | ||
const ContactSchema = require('./contact').ContactSchema; | ||
const LineItemSchema = require('../shared').LineItemSchema; | ||
const BankTransactionSchema = Entity.SchemaObject({ | ||
Type: { type: String, toObject: 'always' }, | ||
Contact: { type: ContactSchema, toObject: 'always' }, | ||
LineItems: { type: Array, arrayType: LineItemSchema, toObject: 'always' }, | ||
BankAccount: { | ||
type: { | ||
AccountID: { type: String, toObject: 'always' }, | ||
}, | ||
IsReconciled: { type: Boolean, toObject: 'always' }, | ||
Date: { type: String, toObject: 'always' }, | ||
Reference: { type: String, toObject: 'always' }, | ||
CurrencyCode: { type: String, toObject: 'always' }, | ||
CurrencyRate: { type: String, toObject: 'hasValue' }, | ||
Url: { type: String, toObject: 'always' }, | ||
Status: { type: String, toObject: 'always' }, | ||
LineAmountTypes: { type: String, toObject: 'always' }, | ||
SubTotal: { type: Number }, | ||
TotalTax: { type: Number }, | ||
Total: { type: Number }, | ||
BankTransactionID: { type: String }, | ||
PrepaymentID: { type: String }, | ||
OverpaymentID: { type: String }, | ||
UpdatedDateUTC: { type: Date, toObject: 'never' }, | ||
HasAttachments: { type: Boolean, toObject: 'always' }, | ||
FullyPaidOnDate: { type: Date } | ||
toObject: 'always', | ||
}, | ||
IsReconciled: { type: Boolean, toObject: 'always' }, | ||
Date: { type: Date, toObject: 'always' }, | ||
Reference: { type: String, toObject: 'always' }, | ||
CurrencyCode: { type: String, toObject: 'always' }, | ||
CurrencyRate: { type: String, toObject: 'hasValue' }, | ||
Url: { type: String, toObject: 'always' }, | ||
Status: { type: String, toObject: 'always' }, | ||
LineAmountTypes: { type: String, toObject: 'always' }, | ||
SubTotal: { type: Number }, | ||
TotalTax: { type: Number }, | ||
Total: { type: Number }, | ||
BankTransactionID: { type: String }, | ||
PrepaymentID: { type: String }, | ||
OverpaymentID: { type: String }, | ||
UpdatedDateUTC: { type: Date, toObject: 'never' }, | ||
HasAttachments: { type: Boolean, toObject: 'always' }, | ||
FullyPaidOnDate: { type: Date }, | ||
}); | ||
var BankTransaction = Entity.extend(BankTransactionSchema, { | ||
constructor: function(application, data, options) { | ||
console.log('BankTransaction::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function(data, options) {}, | ||
changes: function(options) { | ||
return this._super(options); | ||
}, | ||
_toObject: function(options) { | ||
return this._super(options); | ||
}, | ||
getAttachments: function(options) { | ||
return this.application.core.attachments.getAttachments('BankTransactions/' + this.BankTransactionID, options) | ||
}, | ||
fromXmlObj: function(obj) { | ||
var self = this; | ||
Object.assign(self, _.omit(obj, 'LineItems', 'Contact')); | ||
if (obj.LineItems) { | ||
this.extractArray(obj.LineItems.LineItem, this.LineItems); | ||
} | ||
if (obj.Contact) | ||
Object.assign(self.Contact, new Contact(self.application).fromXmlObj(obj.Contact)) | ||
return this; | ||
}, | ||
toXml: function() { | ||
var transaction = _.omit(this.toObject(), 'Contact', 'LineItems'); | ||
transaction.BankAccount = this.BankAccount.toObject(); | ||
transaction.Contact = this.Contact.toObject(); | ||
transaction.LineItems = []; | ||
this.LineItems.forEach(function(lineItem) { | ||
transaction.LineItems.push({ LineItem: lineItem.toObject() }); | ||
}); | ||
return this.application.js2xml(transaction, 'BankTransaction'); | ||
}, | ||
save: function() { | ||
var self = this; | ||
var xml = '<BankTransactions>' + this.toXml() + '</BankTransactions>'; | ||
var path, method; | ||
if (this.BankTransactionID) { | ||
path = 'BankTransactions/' + this.BankTransactionID; | ||
method = 'post' | ||
} else { | ||
path = 'BankTransactions'; | ||
method = 'put' | ||
} | ||
return this.application.putOrPostEntity(method, path, xml, { entityPath: 'BankTransactions.BankTransaction', entityConstructor: function(data) { return self.application.core.bankTransactions.newBankTransaction(data) } }) | ||
const BankTransaction = Entity.extend(BankTransactionSchema, { | ||
constructor: function(...args) { | ||
this.Entity.apply(this, args); | ||
}, | ||
getAttachments: function(options) { | ||
return this.application.core.attachments.getAttachments( | ||
`BankTransactions/${this.BankTransactionID}`, | ||
options | ||
); | ||
}, | ||
save: function() { | ||
const self = this; | ||
let path = ''; | ||
let method = ''; | ||
if (this.BankTransactionID) { | ||
path = `BankTransactions/${this.BankTransactionID}`; | ||
method = 'post'; | ||
} else { | ||
path = 'BankTransactions'; | ||
method = 'put'; | ||
} | ||
return this.application.putOrPostEntity( | ||
method, | ||
path, | ||
JSON.stringify(self), | ||
{ | ||
entityPath: 'BankTransactions', | ||
entityConstructor: data => | ||
self.application.core.bankTransactions.newBankTransaction(data), | ||
} | ||
); | ||
}, | ||
}); | ||
module.exports = BankTransaction; | ||
module.exports.BankTransaction = BankTransaction; |
@@ -7,3 +7,3 @@ var _ = require('lodash'), | ||
var BankTransferSchema = new Entity.SchemaObject({ | ||
var BankTransferSchema = Entity.SchemaObject({ | ||
FromBankAccount: { | ||
@@ -25,3 +25,3 @@ type: { | ||
}, | ||
Date: { type: String, toObject: 'always' }, | ||
Date: { type: Date, toObject: 'always' }, | ||
Amount: { type: String, toObject: 'always' }, | ||
@@ -33,3 +33,3 @@ BankTransferID: { type: String, toObject: 'hasValue' }, | ||
HasAttachments: { type: Boolean, toObject: 'hasValue' }, | ||
CreatedDateUTC: { type: String, toObject: 'hasValue' } | ||
CreatedDateUTC: { type: Date, toObject: 'hasValue' } | ||
}); | ||
@@ -39,3 +39,3 @@ | ||
constructor: function(application, data, options) { | ||
console.log('BankTransfer::constructor'); | ||
this.Entity.apply(this, arguments); | ||
@@ -50,24 +50,13 @@ }, | ||
}, | ||
fromXmlObj: function(obj) { | ||
Object.assign(this, obj); | ||
return this; | ||
}, | ||
getAttachments: function(options) { | ||
return this.application.core.attachments.getAttachments('BankTransfers/' + this.BankTransferID, options) | ||
}, | ||
toXml: function() { | ||
var transaction = _.omit(this.toObject()); | ||
transaction.FromBankAccount = this.FromBankAccount.toObject(); | ||
transaction.ToBankAccount = this.ToBankAccount.toObject(); | ||
return this.application.js2xml(transaction, 'BankTransfer'); | ||
}, | ||
save: function() { | ||
var self = this; | ||
var xml = '<BankTransfers>' + this.toXml() + '</BankTransfers>'; | ||
//JWalsh 22 February 2017 | ||
//Only PUT is supported (beta), no POST.. | ||
return this.application.putOrPostEntity('put', 'BankTransfers', xml, { entityPath: 'BankTransfers.BankTransfer', entityConstructor: function(data) { return self.application.core.bankTransfers.newBankTransfer(data) } }); | ||
return this.application.putOrPostEntity('put', 'BankTransfers', JSON.stringify(self), { entityPath: 'BankTransfers', entityConstructor: function(data) { return self.application.core.bankTransfers.newBankTransfer(data) } }); | ||
} | ||
}); | ||
module.exports = BankTransfer; | ||
module.exports.BankTransfer = BankTransfer; |
var _ = require('lodash'), | ||
Entity = require('../entity') | ||
var BrandingThemeSchema = new Entity.SchemaObject({ | ||
var BrandingThemeSchema = Entity.SchemaObject({ | ||
BrandingThemeID: { type: String }, | ||
Name: { type: String }, | ||
SortOrder: { type: String }, | ||
CreatedDateUTC: { type: String } | ||
CreatedDateUTC: { type: Date } | ||
}); | ||
@@ -13,3 +13,3 @@ | ||
constructor: function(application, data, options) { | ||
console.log('BrandingTheme::constructor'); | ||
this.Entity.apply(this, arguments); | ||
@@ -21,2 +21,2 @@ }, | ||
module.exports = BrandingTheme; | ||
module.exports.BrandingTheme = BrandingTheme; |
@@ -1,156 +0,133 @@ | ||
var _ = require('lodash'), | ||
Entity = require('../entity'), | ||
AddressSchema = require('../shared').AddressSchema, | ||
PhoneSchema = require('../shared').PhoneSchema, | ||
ContactPersonSchema = require('../shared').ContactPerson, | ||
PaymentTermSchema = require('../shared').PaymentTermSchema; | ||
'use strict'; | ||
var BatchPaymentSchema = new Entity.SchemaObject({ | ||
BankAccountNumber: { type: String }, | ||
BankAccountName: { type: String }, | ||
Details: { type: String } | ||
}); | ||
const Entity = require('../entity'); | ||
const AddressSchema = require('../shared').AddressSchema; | ||
const PhoneSchema = require('../shared').PhoneSchema; | ||
const ContactPersonSchema = require('../shared').ContactPerson; | ||
const PaymentTermSchema = require('../shared').PaymentTermSchema; | ||
var ContactSchema = new Entity.SchemaObject({ | ||
ContactID: { type: String, toObject: 'hasValue' }, | ||
ContactNumber: { type: String, toObject: 'hasValue', validators: { maxLength: 50 } }, | ||
AccountNumber: { type: String, toObject: 'hasValue', validators: { maxLength: 50 } }, | ||
ContactStatus: { type: String }, | ||
Name: { type: String, toObject: 'always', validators: { required: true, maxLength: 255 } }, | ||
FirstName: { type: String, toObject: 'always', validators: { maxLength: 255 } }, | ||
LastName: { type: String, toObject: 'always', validators: { maxLength: 255 } }, | ||
EmailAddress: { type: String, toObject: 'hasValue' }, | ||
SkypeUserName: { type: String, toObject: 'hasValue' }, | ||
ContactPersons: [ContactPersonSchema], | ||
BankAccountDetails: { type: String, toObject: 'hasValue' }, | ||
TaxNumber: { type: String, validators: { maxLength: 50 } }, | ||
AccountsReceivableTaxType: { type: String, toObject: 'hasValue' }, | ||
AccountsPayableTaxType: { type: String, toObject: 'hasValue' }, | ||
Addresses: { type: Array, arrayType: AddressSchema, toObject: 'always' }, | ||
Phones: { type: Array, arrayType: PhoneSchema, toObject: 'always' }, | ||
UpdatedDateUTC: { type: Date, toObject: 'never' }, | ||
IsSupplier: { type: Boolean, toObject: 'hasValue' }, | ||
IsCustomer: { type: Boolean, toObject: 'hasValue' }, | ||
DefaultCurrency: { type: String, toObject: 'hasValue' }, | ||
XeroNetworkKey: { type: String, toObject: 'never' }, | ||
SalesDefaultAccountCode: { type: String, toObject: 'never' }, | ||
PurchasesDefaultAccountCode: { type: String, toObject: 'never' }, | ||
//The following properties are only retrieved on GET requests for specific contacts or with pagination | ||
ContactGroups: { type: String }, | ||
Website: { type: String, toObject: 'hasValue' }, | ||
BatchPayments: { type: BatchPaymentSchema, toObject: 'hasValue', readOnly: 'true' }, | ||
Discount: { type: String, toObject: 'hasValue' }, | ||
Balances: { | ||
type: { | ||
AccountsReceivable: { | ||
Outstanding: { type: Number }, | ||
Overdue: { type: Number } | ||
}, | ||
AccountsPayable: { | ||
Outstanding: { type: Number }, | ||
Overdue: { type: Number } | ||
} | ||
}, | ||
toObject: 'hasValue' | ||
}, | ||
PaymentTerms: { | ||
type: { | ||
Bills: PaymentTermSchema, | ||
Sales: PaymentTermSchema | ||
}, | ||
toObject: 'hasValue' | ||
} | ||
const BatchPaymentSchema = Entity.SchemaObject({ | ||
BankAccountNumber: { type: String }, | ||
BankAccountName: { type: String }, | ||
Details: { type: String }, | ||
}); | ||
var Contact = Entity.extend(ContactSchema, { | ||
constructor: function(application, data, options) { | ||
console.log('Contact::constructor'); | ||
this.Entity.apply(this, arguments); | ||
const ContactSchema = Entity.SchemaObject({ | ||
ContactID: { type: String, toObject: 'hasValue' }, | ||
ContactNumber: { | ||
type: String, | ||
toObject: 'hasValue', | ||
validators: { maxLength: 50 }, | ||
}, | ||
AccountNumber: { | ||
type: String, | ||
toObject: 'hasValue', | ||
validators: { maxLength: 50 }, | ||
}, | ||
ContactStatus: { type: String, toObject: 'hasValue' }, | ||
Name: { | ||
type: String, | ||
toObject: 'always', | ||
validators: { required: true, maxLength: 255 }, | ||
}, | ||
FirstName: { | ||
type: String, | ||
toObject: 'always', | ||
validators: { maxLength: 255 }, | ||
}, | ||
LastName: { | ||
type: String, | ||
toObject: 'always', | ||
validators: { maxLength: 255 }, | ||
}, | ||
EmailAddress: { type: String, toObject: 'hasValue' }, | ||
SkypeUserName: { type: String, toObject: 'hasValue' }, | ||
ContactPersons: [ContactPersonSchema], | ||
BankAccountDetails: { type: String, toObject: 'hasValue' }, | ||
TaxNumber: { type: String, validators: { maxLength: 50 } }, | ||
AccountsReceivableTaxType: { type: String, toObject: 'hasValue' }, | ||
AccountsPayableTaxType: { type: String, toObject: 'hasValue' }, | ||
Addresses: { type: Array, arrayType: AddressSchema, toObject: 'always' }, | ||
Phones: { type: Array, arrayType: PhoneSchema, toObject: 'always' }, | ||
UpdatedDateUTC: { type: Date, toObject: 'never' }, | ||
IsSupplier: { type: Boolean, toObject: 'hasValue' }, | ||
IsCustomer: { type: Boolean, toObject: 'hasValue' }, | ||
DefaultCurrency: { type: String, toObject: 'hasValue' }, | ||
XeroNetworkKey: { type: String, toObject: 'never' }, | ||
SalesDefaultAccountCode: { type: String, toObject: 'never' }, | ||
PurchasesDefaultAccountCode: { type: String, toObject: 'never' }, | ||
// The following properties are only retrieved on GET requests for specific contacts or with pagination | ||
ContactGroups: { type: String }, | ||
Website: { type: String, toObject: 'hasValue' }, | ||
BatchPayments: { | ||
type: BatchPaymentSchema, | ||
toObject: 'hasValue', | ||
readOnly: 'true', | ||
}, | ||
Discount: { type: String, toObject: 'hasValue' }, | ||
Balances: { | ||
type: { | ||
AccountsReceivable: { | ||
Outstanding: { type: Number }, | ||
Overdue: { type: Number }, | ||
}, | ||
AccountsPayable: { | ||
Outstanding: { type: Number }, | ||
Overdue: { type: Number }, | ||
}, | ||
}, | ||
initialize: function(data, options) {}, | ||
changes: function(options) { | ||
return this._super(options); | ||
toObject: 'hasValue', | ||
}, | ||
PaymentTerms: { | ||
type: { | ||
Bills: PaymentTermSchema, | ||
Sales: PaymentTermSchema, | ||
}, | ||
_toObject: function(options) { | ||
return this._super(options); | ||
}, | ||
fromXmlObj: function(obj) { | ||
var self = this; | ||
Object.assign(self, _.omit(obj, 'Addresses', 'Phones', 'ContactPersons', 'BatchPayments', 'PaymentTerms')); | ||
if (obj.Addresses) { | ||
this.extractArray(obj.Addresses.Address, this.Addresses); | ||
} | ||
if (obj.Phones) { | ||
this.extractArray(obj.Phones.Phone, this.Phones); | ||
} | ||
if (obj.ContactPersons) { | ||
this.extractArray(obj.ContactPersons.ContactPerson, this.ContactPersons); | ||
} | ||
toObject: 'hasValue', | ||
}, | ||
}); | ||
return this; | ||
}, | ||
toXml: function() { | ||
var contact = _.omit(this.toObject(), 'Addresses', 'Phones', 'ContactPersons', 'BatchPayments', 'PaymentTerms'); | ||
const Contact = Entity.extend(ContactSchema, { | ||
constructor: function(...args) { | ||
this.Entity.apply(this, args); | ||
}, | ||
changes: function(options) { | ||
return this._super(options); | ||
}, | ||
_toObject: function(options) { | ||
return this._super(options); | ||
}, | ||
getAttachments: function(options) { | ||
return this.application.core.attachments.getAttachments( | ||
`Contacts/${this.ContactID}`, | ||
options | ||
); | ||
}, | ||
save: function() { | ||
const self = this; | ||
let path = ''; | ||
let method = ''; | ||
/** | ||
* JWalsh 21-02-2017 | ||
* Updated to remove the lodash isEmpty function as the BatchPayments object was being populated with a bunch | ||
* of data during construction and the object was never Empty. This meant that the toXML function was entering an infinite | ||
* loop and causing the SDK to crash. | ||
* | ||
* Instead, I'm now just testing the individual elements within the object to see if they are populated. | ||
*/ | ||
if (this.BatchPayments && (this.BatchPayments.BankAccountNumber || this.BatchPayments.BankAccountName || this.BatchPayments.Details)) | ||
contact.BatchPayments = this.BatchPayments; | ||
if (this.ContactID) { | ||
path = `Contacts/${this.ContactID}`; | ||
method = 'post'; | ||
} else { | ||
path = 'Contacts'; | ||
method = 'put'; | ||
} | ||
if (this.PaymentTerms && | ||
(this.PaymentTerms.Bills && (this.PaymentTerms.Bills.Day || this.PaymentTerms.Bills.Type)) || | ||
(this.PaymentTerms.Sales && (this.PaymentTerms.Sales.Day || this.PaymentTerms.Sales.Type)) | ||
) { | ||
contact.PaymentTerms = this.PaymentTerms; | ||
} | ||
if (!_.isEmpty(this.Addresses)) { | ||
contact.Addresses = []; | ||
_.forEach(this.Addresses, function(address) { | ||
contact.Addresses.push({ Address: address.toObject() }) | ||
}) | ||
} | ||
if (!_.isEmpty(this.Phones)) { | ||
contact.Phones = []; | ||
_.forEach(this.Phones, function(phone) { | ||
contact.Phones.push({ Phone: phone.toObject() }) | ||
}) | ||
} | ||
if (!_.isEmpty(this.ContactPersons)) { | ||
contact.ContactPersons = []; | ||
_.forEach(this.ContactPersons, function(contactPerson) { | ||
contact.ContactPersons.push({ ContactPerson: contactPerson.toObject() }) | ||
}) | ||
} | ||
return this.application.js2xml(contact, 'Contact'); | ||
}, | ||
getAttachments: function(options) { | ||
return this.application.core.attachments.getAttachments('Contacts/' + this.ContactID, options) | ||
}, | ||
save: function() { | ||
var self = this; | ||
var xml = '<Contacts>' + this.toXml() + '</Contacts>'; | ||
var path, method; | ||
if (this.ContactID) { | ||
path = 'Contacts/' + this.ContactID; | ||
method = 'post' | ||
} else { | ||
path = 'Contacts'; | ||
method = 'put' | ||
} | ||
return this.application.putOrPostEntity(method, path, xml, { entityPath: 'Contacts.Contact', entityConstructor: function(data) { return self.application.core.contacts.newContact(data) } }) | ||
} | ||
return this.application.putOrPostEntity( | ||
method, | ||
path, | ||
JSON.stringify(self), | ||
{ | ||
entityPath: 'Contacts', | ||
entityConstructor: data => | ||
self.application.core.contacts.newContact(data), | ||
} | ||
); | ||
}, | ||
}); | ||
module.exports = Contact; | ||
module.exports.ContactSchema = ContactSchema; | ||
module.exports.Contact = Contact; | ||
module.exports.ContactSchema = ContactSchema; |
@@ -5,3 +5,3 @@ var _ = require('lodash'), | ||
var CreditNoteContactSchema = new Entity.SchemaObject({ | ||
var CreditNoteContactSchema = Entity.SchemaObject({ | ||
ContactID: { type: String }, | ||
@@ -11,3 +11,3 @@ Name: { type: String } | ||
var CreditNoteInvoiceType = new Entity.SchemaObject({ | ||
var CreditNoteInvoiceType = Entity.SchemaObject({ | ||
InvoiceID: { type: String }, | ||
@@ -17,5 +17,5 @@ InvoiceNumber: { type: String } | ||
var CreditNoteAllocationsSchema = new Entity.SchemaObject({ | ||
var CreditNoteAllocationsSchema = Entity.SchemaObject({ | ||
AppliedAmount: { type: Number }, | ||
Date: { type: String }, | ||
Date: { type: Date }, | ||
Invoice: { | ||
@@ -27,3 +27,3 @@ type: CreditNoteInvoiceType, | ||
var CreditNoteSchema = new Entity.SchemaObject({ | ||
var CreditNoteSchema = Entity.SchemaObject({ | ||
CreditNoteID: { type: String }, | ||
@@ -34,3 +34,3 @@ Contact: { | ||
}, | ||
Date: { type: String, toObject: 'always' }, | ||
Date: { type: Date, toObject: 'always' }, | ||
Status: { type: String, toObject: 'hasValue' }, | ||
@@ -41,7 +41,6 @@ LineAmountTypes: { type: String }, | ||
Total: { type: Number }, | ||
UpdatedDateUTC: { type: String }, | ||
UpdatedDateUTC: { type: Date, toObject: 'never' }, | ||
CurrencyCode: { type: String }, | ||
FullyPaidOnDate: { type: String }, | ||
FullyPaidOnDate: { type: Date }, | ||
Type: { type: String, toObject: 'always' }, | ||
CreditNoteID: { type: String }, | ||
CreditNoteNumber: { type: String }, | ||
@@ -56,3 +55,3 @@ CurrencyRate: { type: Number }, | ||
constructor: function(application, data, options) { | ||
console.log('CreditNote::constructor'); | ||
this.Entity.apply(this, arguments); | ||
@@ -70,24 +69,4 @@ }, | ||
}, | ||
fromXmlObj: function(obj) { | ||
var self = this; | ||
Object.assign(self, _.omit(obj, 'LineItems')); | ||
if (obj.LineItems) { | ||
this.extractArray(obj.LineItems.LineItem, this.LineItems); | ||
} | ||
return this; | ||
}, | ||
toXml: function() { | ||
var creditNote = _.omit(this.toObject(), 'LineItems'); | ||
Object.assign(creditNote, { LineItems: { LineItem: [] } }); | ||
_.forEach(this.LineItems, function(lineItem) { | ||
creditNote.LineItems.LineItem.push(lineItem.toObject()); | ||
}); | ||
return this.application.js2xml(creditNote, 'CreditNote'); | ||
}, | ||
save: function(options) { | ||
var self = this; | ||
var xml = '<CreditNotes>' + this.toXml() + '</CreditNotes>'; | ||
var path, method; | ||
@@ -106,3 +85,3 @@ | ||
//Adding other options for saving purposes | ||
options.entityPath = 'CreditNotes.CreditNote'; | ||
options.entityPath = 'CreditNotes'; | ||
options.entityConstructor = function(data) { | ||
@@ -112,23 +91,15 @@ return self.application.core.creditNotes.newCreditNote(data) | ||
return this.application.putOrPostEntity(method, path, xml, options); | ||
return this.application.putOrPostEntity(method, path, JSON.stringify(self), options); | ||
}, | ||
saveAllocations: function(allocations) { | ||
var self = this; | ||
var xml = '<Allocations>'; | ||
var path, method; | ||
path = 'CreditNotes/' + this.CreditNoteID + "/Allocations"; | ||
method = 'put'; | ||
_.each(allocations, function(allocation) { | ||
xml += "<Allocation>"; | ||
xml += "<AppliedAmount>" + allocation.AppliedAmount + "</AppliedAmount>"; | ||
xml += "<Invoice>"; | ||
xml += "<InvoiceID>" + allocation.InvoiceID + "</InvoiceID>"; | ||
xml += "</Invoice>"; | ||
xml += "</Allocation>"; | ||
}); | ||
var payload = { | ||
Allocations: allocations | ||
}; | ||
xml += "</Allocations>"; | ||
var path, method; | ||
path = 'CreditNotes/' + this.CreditNoteID + "/Allocations"; | ||
method = 'put' | ||
return this.application.putOrPostEntity(method, path, xml, {}); | ||
return this.application.putOrPostEntity(method, path, JSON.stringify(payload), {}); | ||
}, | ||
@@ -138,2 +109,2 @@ }); | ||
module.exports = CreditNote; | ||
module.exports.CreditNote = CreditNote; |
var _ = require('lodash'), | ||
Entity = require('../entity') | ||
var CurrencySchema = new Entity.SchemaObject({ | ||
var CurrencySchema = Entity.SchemaObject({ | ||
Code: { type: String }, | ||
@@ -11,3 +11,3 @@ Description: { type: String } | ||
constructor: function(application, data, options) { | ||
console.log('Currency::constructor'); | ||
this.Entity.apply(this, arguments); | ||
@@ -19,2 +19,2 @@ }, | ||
module.exports = Currency; | ||
module.exports.Currency = Currency; |
@@ -1,109 +0,90 @@ | ||
var _ = require('lodash'), | ||
Entity = require('../entity'), | ||
ContactSchema = require('./contact').ContactSchema, | ||
Contact = require('./contact'), | ||
PaymentSchema = require('../shared').PaymentSchema, | ||
LineItemSchema = require('../shared').LineItemSchema; | ||
'use strict'; | ||
var InvoiceSchema = new Entity.SchemaObject({ | ||
Type: { type: String, toObject: 'hasValue' }, | ||
Contact: { type: ContactSchema, toObject: 'hasValue' }, | ||
LineItems: { type: Array, arrayType: LineItemSchema, toObject: 'hasValue' }, | ||
Date: { type: String, toObject: 'hasValue' }, | ||
DueDate: { type: String, toObject: 'hasValue' }, | ||
LineAmountTypes: { type: String, toObject: 'hasValue' }, | ||
InvoiceNumber: { type: String, toObject: 'hasValue' }, | ||
Reference: { type: String, toObject: 'hasValue' }, | ||
BrandingThemeID: { type: String, toObject: 'hasValue' }, | ||
Url: { type: String, toObject: 'hasValue' }, | ||
CurrencyCode: { type: String, toObject: 'hasValue' }, | ||
CurrencyRate: { type: Number, toObject: 'hasValue' }, | ||
Status: { type: String, toObject: 'hasValue' }, | ||
SentToContact: { type: Boolean, toObject: 'hasValue' }, | ||
ExpectedPaymentDate: { type: Date, toObject: 'hasValue' }, | ||
PlannedPaymentDate: { type: Date, toObject: 'hasValue' }, | ||
SubTotal: { type: Number, toObject: 'hasValue' }, | ||
TotalTax: { type: Number, toObject: 'hasValue' }, | ||
Total: { type: Number, toObject: 'hasValue' }, | ||
TotalDiscount: { type: String, toObject: 'hasValue' }, | ||
InvoiceID: { type: String, toObject: 'hasValue' }, | ||
HasAttachments: { type: Boolean, toObject: 'hasValue' }, | ||
Payments: { type: Array, arrayType: PaymentSchema, toObject: 'hasValue' }, | ||
AmountDue: { type: Number, toObject: 'hasValue' }, | ||
AmountPaid: { type: Number, toObject: 'hasValue' }, | ||
FullyPaidOnDate: { type: Date, toObject: 'hasValue' }, | ||
AmountCredited: { type: Number, toObject: 'hasValue' }, | ||
UpdatedDateUTC: { type: Date, toObject: 'hasValue' } | ||
//CreditNotes: {type: Array, arrayType: CreditNoteSchema, toObject: 'always'}, | ||
//Prepayments: {type: Array, arrayType: PrepaymentsSchema, toObject: 'always'}, | ||
//Overpayments: {type: Array, arrayType: OverpaymentsSchema, toObject: 'always'}, | ||
const Entity = require('../entity'); | ||
const ContactSchema = require('./contact').ContactSchema; | ||
const PaymentSchema = require('../shared').PaymentSchema; | ||
const LineItemSchema = require('../shared').LineItemSchema; | ||
const InvoiceSchema = Entity.SchemaObject({ | ||
Type: { type: String, toObject: 'hasValue' }, | ||
Contact: { type: ContactSchema, toObject: 'always' }, | ||
LineItems: { type: Array, arrayType: LineItemSchema, toObject: 'hasValue' }, | ||
Date: { type: Date, toObject: 'always' }, | ||
DueDate: { type: Date, toObject: 'always' }, | ||
LineAmountTypes: { type: String, toObject: 'hasValue' }, | ||
InvoiceNumber: { type: String, toObject: 'hasValue' }, | ||
Reference: { type: String, toObject: 'hasValue' }, | ||
BrandingThemeID: { type: String, toObject: 'hasValue' }, | ||
Url: { type: String, toObject: 'hasValue' }, | ||
CurrencyCode: { type: String, toObject: 'hasValue' }, | ||
CurrencyRate: { type: Number, toObject: 'hasValue' }, | ||
Status: { type: String, toObject: 'hasValue' }, | ||
SentToContact: { type: Boolean, toObject: 'hasValue' }, | ||
ExpectedPaymentDate: { type: Date, toObject: 'hasValue' }, | ||
PlannedPaymentDate: { type: Date, toObject: 'hasValue' }, | ||
SubTotal: { type: Number, toObject: 'hasValue' }, | ||
TotalTax: { type: Number, toObject: 'hasValue' }, | ||
Total: { type: Number, toObject: 'hasValue' }, | ||
TotalDiscount: { type: String, toObject: 'hasValue' }, | ||
InvoiceID: { type: String, toObject: 'hasValue' }, | ||
HasAttachments: { type: Boolean, toObject: 'hasValue' }, | ||
Payments: { type: Array, arrayType: PaymentSchema, toObject: 'hasValue' }, | ||
AmountDue: { type: Number, toObject: 'hasValue' }, | ||
AmountPaid: { type: Number, toObject: 'hasValue' }, | ||
FullyPaidOnDate: { type: Date, toObject: 'hasValue' }, | ||
AmountCredited: { type: Number, toObject: 'hasValue' }, | ||
UpdatedDateUTC: { type: Date, toObject: 'never' }, | ||
// CreditNotes: {type: Array, arrayType: CreditNoteSchema, toObject: 'always'}, | ||
// Prepayments: {type: Array, arrayType: PrepaymentsSchema, toObject: 'always'}, | ||
// Overpayments: {type: Array, arrayType: OverpaymentsSchema, toObject: 'always'}, | ||
}); | ||
var Invoice = Entity.extend(InvoiceSchema, { | ||
constructor: function(application, data, options) { | ||
console.log('Invoice::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function(data, options) {}, | ||
changes: function(options) { | ||
return this._super(options); | ||
}, | ||
_toObject: function(options) { | ||
return this._super(options); | ||
}, | ||
fromXmlObj: function(obj) { | ||
var self = this; | ||
Object.assign(self, _.omit(obj, 'LineItems', 'Payments')); | ||
if (obj.LineItems) { | ||
this.extractArray(obj.LineItems.LineItem, this.LineItems); | ||
} | ||
const Invoice = Entity.extend(InvoiceSchema, { | ||
constructor: function(...args) { | ||
this.Entity.apply(this, args); | ||
}, | ||
changes: function(options) { | ||
return this._super(options); | ||
}, | ||
_toObject: function(options) { | ||
return this._super(options); | ||
}, | ||
getAttachments: function(options) { | ||
return this.application.core.attachments.getAttachments( | ||
`Invoices/${this.InvoiceID}`, | ||
options | ||
); | ||
}, | ||
save: function(opts) { | ||
const self = this; | ||
let path = ''; | ||
let method = ''; | ||
if (obj.Payments) { | ||
this.extractArray(obj.Payments.Payment, this.Payments); | ||
} | ||
const options = opts || {}; | ||
return this; | ||
}, | ||
toXml: function() { | ||
var invoice = _.omit(this.toObject(), 'LineItems', 'Payments', 'CreditNotes', 'InvoiceID', 'HasAttachments', 'AmountDue', 'AmountPaid', 'FullyPaidOnDate', 'AmountCredited', 'UpdatedDateUTC'); | ||
Object.assign(invoice, { LineItems: { LineItem: [] } }); | ||
_.forEach(this.LineItems, function(lineItem) { | ||
invoice.LineItems.LineItem.push(lineItem.toObject()); | ||
}); | ||
if (this.InvoiceID) { | ||
path = `Invoices/${this.InvoiceID}`; | ||
method = 'post'; | ||
} else { | ||
path = 'Invoices'; | ||
method = 'put'; | ||
} | ||
return this.application.js2xml(invoice, 'Invoice'); | ||
// Adding other options for saving purposes | ||
options.entityPath = 'Invoices'; | ||
options.entityConstructor = function(data) { | ||
return self.application.core.invoices.newInvoice(data); | ||
}; | ||
}, | ||
getAttachments: function(options) { | ||
return this.application.core.attachments.getAttachments('Invoices/' + this.InvoiceID, options) | ||
}, | ||
save: function(options) { | ||
var self = this; | ||
var xml = '<Invoices>' + this.toXml() + '</Invoices>'; | ||
var path, method; | ||
options = options || {}; | ||
if (this.InvoiceID) { | ||
path = 'Invoices/' + this.InvoiceID; | ||
method = 'post' | ||
} else { | ||
path = 'Invoices'; | ||
method = 'put' | ||
} | ||
//Adding other options for saving purposes | ||
options.entityPath = 'Invoices.Invoice'; | ||
options.entityConstructor = function(data) { | ||
return self.application.core.invoices.newInvoice(data) | ||
}; | ||
return this.application.putOrPostEntity(method, path, xml, options); | ||
} | ||
return this.application.putOrPostEntity( | ||
method, | ||
path, | ||
JSON.stringify(self), | ||
options | ||
); | ||
}, | ||
}); | ||
module.exports = Invoice; | ||
module.exports.Invoice = Invoice; | ||
module.exports.InvoiceSchema = InvoiceSchema; | ||
module.exports.LineItemSchema = LineItemSchema; | ||
module.exports.LineItemSchema = LineItemSchema; |
var _ = require('lodash'), | ||
Entity = require('../entity') | ||
var InvoiceReminderSchema = new Entity.SchemaObject({ | ||
var InvoiceReminderSchema = Entity.SchemaObject({ | ||
Enabled: { type: Boolean } | ||
@@ -10,3 +10,3 @@ }); | ||
constructor: function(application, data, options) { | ||
console.log('InvoiceReminder::constructor'); | ||
this.Entity.apply(this, arguments); | ||
@@ -18,2 +18,2 @@ }, | ||
module.exports = InvoiceReminder; | ||
module.exports.InvoiceReminder = InvoiceReminder; |
var _ = require('lodash'), | ||
Entity = require('../entity') | ||
var ItemDetailSchema = new Entity.SchemaObject({ | ||
var ItemDetailSchema = Entity.SchemaObject({ | ||
UnitPrice: { type: Number, toObject: 'hasValue' }, | ||
@@ -11,3 +11,3 @@ AccountCode: { type: String, toObject: 'hasValue' }, | ||
}); | ||
var ItemSchema = new Entity.SchemaObject({ | ||
var ItemSchema = Entity.SchemaObject({ | ||
Code: { type: String, toObject: 'always', validators: { maxLength: 30 } }, | ||
@@ -25,3 +25,3 @@ InventoryAssetAccountCode: { type: String, toObject: 'hasValue' }, | ||
QuantityOnHand: { type: String, toObject: 'hasValue' }, | ||
UpdatedDateUTC: { type: String, toObject: 'hasValue' }, | ||
UpdatedDateUTC: { type: Date, toObject: 'never' }, | ||
ItemID: { type: String, toObject: 'always' } | ||
@@ -32,13 +32,8 @@ }); | ||
constructor: function(application, data, options) { | ||
console.log('Item::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function(data, options) {}, | ||
toXml: function() { | ||
var item = _.omit(this.toObject()); | ||
return this.application.js2xml(item, 'Item'); | ||
}, | ||
save: function(options) { | ||
var self = this; | ||
var xml = '<Items>' + this.toXml() + '</Items>'; | ||
var path, method; | ||
@@ -52,3 +47,3 @@ if (this.ItemID) { | ||
} | ||
return this.application.putOrPostEntity(method, path, xml, { entityPath: 'Items.Item', entityConstructor: function(data) { return self.application.core.items.newItem(data) } }); | ||
return this.application.putOrPostEntity(method, path, JSON.stringify(self), { entityPath: 'Items', entityConstructor: function(data) { return self.application.core.items.newItem(data) } }); | ||
} | ||
@@ -58,3 +53,3 @@ }); | ||
module.exports = Item; | ||
module.exports.Item = Item; | ||
module.exports.ItemSchema = ItemSchema; |
var _ = require('lodash'), | ||
Entity = require('../entity') | ||
var TrackingCategorySchema = new Entity.SchemaObject({ | ||
var TrackingCategorySchema = Entity.SchemaObject({ | ||
TrackingCategoryID: { type: String }, | ||
@@ -11,3 +11,3 @@ Name: { type: String }, | ||
var JournalLineSchema = new Entity.SchemaObject({ | ||
var JournalLineSchema = Entity.SchemaObject({ | ||
JournalLineID: { type: String, searchType: 'guid' }, | ||
@@ -26,3 +26,3 @@ AccountID: { type: String, searchType: 'guid' }, | ||
var JournalSchema = new Entity.SchemaObject({ | ||
var JournalSchema = Entity.SchemaObject({ | ||
JournalID: { type: String, searchType: 'guid' }, | ||
@@ -40,3 +40,3 @@ JournalDate: { type: Date }, | ||
constructor: function(application, data, options) { | ||
console.log('Journal::constructor'); | ||
this.Entity.apply(this, arguments); | ||
@@ -50,11 +50,2 @@ }, | ||
return this._super(options); | ||
}, | ||
fromXmlObj: function(obj) { | ||
var self = this; | ||
Object.assign(self, _.omit(obj, 'JournalLines')); | ||
if (obj.JournalLines) { | ||
this.extractArray(obj.JournalLines.JournalLine, this.JournalLines); | ||
} | ||
return this; | ||
} | ||
@@ -64,3 +55,3 @@ }); | ||
module.exports = Journal; | ||
module.exports.Journal = Journal; | ||
module.exports.JournalSchema = JournalSchema; |
@@ -1,114 +0,88 @@ | ||
var _ = require('lodash'), | ||
Entity = require('../entity'), | ||
TrackingCategory = require('./trackingcategory'); | ||
'use strict'; | ||
var ManualJournalLineSchema = new Entity.SchemaObject({ | ||
LineAmount: { | ||
type: Number, | ||
toObject: 'hasValue' | ||
}, | ||
AccountCode: { | ||
type: String, | ||
toObject: 'hasValue' | ||
}, | ||
Description: { | ||
type: String, | ||
toObject: 'hasValue' | ||
}, | ||
TaxType: { | ||
type: String, | ||
toObject: 'hasValue' | ||
}, | ||
Tracking: [TrackingCategory.TrackingCategorySchema] | ||
const Entity = require('../entity'); | ||
const TrackingCategory = require('./trackingcategory'); | ||
const ManualJournalLineSchema = new Entity.SchemaObject({ | ||
LineAmount: { | ||
type: Number, | ||
toObject: 'hasValue', | ||
}, | ||
AccountCode: { | ||
type: String, | ||
toObject: 'hasValue', | ||
}, | ||
Description: { | ||
type: String, | ||
toObject: 'hasValue', | ||
}, | ||
TaxType: { | ||
type: String, | ||
toObject: 'hasValue', | ||
}, | ||
Tracking: [TrackingCategory.TrackingCategorySchema], | ||
}); | ||
var ManualJournalSchema = new Entity.SchemaObject({ | ||
Narration: { | ||
type: String, | ||
toObject: 'hasValue' | ||
}, | ||
Date: { | ||
type: String, | ||
toObject: 'hasValue' | ||
}, | ||
LineAmountTypes: { | ||
type: String, | ||
toObject: 'hasValue' | ||
}, | ||
Status: { | ||
type: String, | ||
toObject: 'hasValue' | ||
}, | ||
Url: { | ||
type: String, | ||
toObject: 'hasValue' | ||
}, | ||
ShowOnCashBasisReports: { | ||
type: Boolean, | ||
toObject: 'hasValue' | ||
}, | ||
JournalLines: { | ||
type: Array, | ||
arrayType: ManualJournalLineSchema, | ||
toObject: 'hasValue' | ||
} | ||
const ManualJournalSchema = new Entity.SchemaObject({ | ||
Narration: { | ||
type: String, | ||
toObject: 'hasValue', | ||
}, | ||
Date: { | ||
type: Date, | ||
toObject: 'hasValue', | ||
}, | ||
LineAmountTypes: { | ||
type: String, | ||
toObject: 'hasValue', | ||
}, | ||
Status: { | ||
type: String, | ||
toObject: 'hasValue', | ||
}, | ||
Url: { | ||
type: String, | ||
toObject: 'hasValue', | ||
}, | ||
ShowOnCashBasisReports: { | ||
type: Boolean, | ||
toObject: 'hasValue', | ||
}, | ||
JournalLines: { | ||
type: Array, | ||
arrayType: ManualJournalLineSchema, | ||
toObject: 'hasValue', | ||
}, | ||
}); | ||
var ManualJournal = Entity.extend(ManualJournalSchema, { | ||
constructor: function(application, data, options) { | ||
console.log('ManualJournal::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function(data, options) {}, | ||
changes: function(options) { | ||
return this._super(options); | ||
}, | ||
_toObject: function(options) { | ||
return this._super(options); | ||
}, | ||
fromXmlObj: function(obj) { | ||
var self = this; | ||
Object.assign(self, _.omit(obj, 'JournalLines')); | ||
if (obj.JournalLines) { | ||
this.extractArray(obj.JournalLines.JournalLine, this.JournalLines); | ||
} | ||
const ManualJournal = Entity.extend(ManualJournalSchema, { | ||
constructor: function(application, data, options) { | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function(data, options) {}, | ||
save: function() { | ||
const self = this; | ||
let path; | ||
let method; | ||
if (this.JournalID) { | ||
path = `ManualJournals/${this.JournalID}`; | ||
method = 'post'; | ||
} else { | ||
path = 'ManualJournals'; | ||
method = 'put'; | ||
} | ||
return this; | ||
}, | ||
toXml: function() { | ||
var manualJournal = _.omit(this.toObject(), 'JournalLines'); | ||
Object.assign(manualJournal, { | ||
JournalLines: { | ||
JournalLine: [] | ||
} | ||
}); | ||
this.JournalLines.forEach(function(journalLine) { | ||
manualJournal.JournalLines.JournalLine.push(journalLine.toObject()); | ||
}); | ||
return this.application.js2xml(manualJournal, 'ManualJournal'); | ||
}, | ||
save: function() { | ||
var self = this; | ||
var xml = '<ManualJournals>' + this.toXml() + '</ManualJournals>'; | ||
var path, method; | ||
if (this.JournalID) { | ||
path = 'ManualJournals/' + this.JournalID; | ||
method = 'post' | ||
} else { | ||
path = 'ManualJournals'; | ||
method = 'put' | ||
} | ||
return this.application.putOrPostEntity(method, path, xml, { | ||
entityPath: 'ManualJournals.ManualJournal', | ||
entityConstructor: function(data) { | ||
return self.application.core.manualjournals.newManualJournal(data) | ||
} | ||
}) | ||
} | ||
return this.application.putOrPostEntity( | ||
method, | ||
path, | ||
JSON.stringify(self), | ||
{ | ||
entityPath: 'ManualJournals', | ||
entityConstructor: data => | ||
self.application.core.manualjournals.newManualJournal(data), | ||
} | ||
); | ||
}, | ||
}); | ||
module.exports = ManualJournal; | ||
module.exports = ManualJournal; |
@@ -1,80 +0,60 @@ | ||
var _ = require('lodash'), | ||
Entity = require('../entity'), | ||
AddressSchema = require('../shared').AddressSchema, | ||
PhoneSchema = require('../shared').PhoneSchema, | ||
ExternalLinkSchema = require('../shared').ExternalLinkSchema, | ||
PaymentTermSchema = require('../shared').PaymentTermSchema | ||
'use strict'; | ||
var OrganisationSchema = new Entity.SchemaObject({ | ||
APIKey: { type: String }, | ||
Name: { type: String }, | ||
LegalName: { type: String }, | ||
PaysTax: { type: Boolean }, | ||
Version: { type: String }, | ||
OrganisationType: { type: String }, | ||
BaseCurrency: { type: String }, | ||
CountryCode: { type: String }, | ||
IsDemoCompany: { type: Boolean }, | ||
OrganisationStatus: { type: String }, | ||
RegistrationNumber: { type: String }, | ||
TaxNumber: { type: String }, | ||
FinancialYearEndDay: { type: Number }, | ||
FinancialYearEndMonth: { type: Number }, | ||
SalesTaxBasis: { type: String }, | ||
SalesTaxPeriod: { type: String }, | ||
DefaultSalesTax: { type: String }, | ||
DefaultPurchasesTax: { type: String }, | ||
PeriodLockDate: { type: Date }, | ||
EndOfYearLockDate: { type: Date }, | ||
CreatedDateUTC: { type: Date }, | ||
Timezone: { type: String }, | ||
OrganisationEntityType: { type: String }, | ||
ShortCode: { type: String }, | ||
LineOfBusiness: { type: String }, | ||
Addresses: { type: Array, arrayType: AddressSchema, toObject: 'always' }, | ||
Phones: { type: Array, arrayType: PhoneSchema, toObject: 'always' }, | ||
ExternalLinks: [ExternalLinkSchema], | ||
PaymentTerms: { | ||
Bills: PaymentTermSchema, | ||
Sales: PaymentTermSchema | ||
} | ||
const Entity = require('../entity'); | ||
const AddressSchema = require('../shared').AddressSchema; | ||
const PhoneSchema = require('../shared').PhoneSchema; | ||
const ExternalLinkSchema = require('../shared').ExternalLinkSchema; | ||
const PaymentTermSchema = require('../shared').PaymentTermSchema; | ||
const OrganisationSchema = Entity.SchemaObject({ | ||
APIKey: { type: String }, | ||
Name: { type: String }, | ||
LegalName: { type: String }, | ||
PaysTax: { type: Boolean }, | ||
Version: { type: String }, | ||
OrganisationType: { type: String }, | ||
BaseCurrency: { type: String }, | ||
CountryCode: { type: String }, | ||
IsDemoCompany: { type: Boolean }, | ||
OrganisationStatus: { type: String }, | ||
RegistrationNumber: { type: String }, | ||
TaxNumber: { type: String }, | ||
FinancialYearEndDay: { type: Number }, | ||
FinancialYearEndMonth: { type: Number }, | ||
SalesTaxBasis: { type: String }, | ||
SalesTaxPeriod: { type: String }, | ||
DefaultSalesTax: { type: String }, | ||
DefaultPurchasesTax: { type: String }, | ||
PeriodLockDate: { type: Date }, | ||
EndOfYearLockDate: { type: Date }, | ||
CreatedDateUTC: { type: Date }, | ||
Timezone: { type: String }, | ||
OrganisationEntityType: { type: String }, | ||
ShortCode: { type: String }, | ||
LineOfBusiness: { type: String }, | ||
Addresses: { type: Array, arrayType: AddressSchema, toObject: 'always' }, | ||
Phones: { type: Array, arrayType: PhoneSchema, toObject: 'always' }, | ||
ExternalLinks: { | ||
type: Array, | ||
arrayType: ExternalLinkSchema, | ||
toObject: 'always', | ||
}, | ||
PaymentTerms: { | ||
Bills: PaymentTermSchema, | ||
Sales: PaymentTermSchema, | ||
}, | ||
}); | ||
var Organisation = Entity.extend(OrganisationSchema, { | ||
constructor: function(application, data, options) { | ||
console.log('Organisation::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function(data, options) {}, | ||
changes: function(options) { | ||
return this._super(options); | ||
}, | ||
_toObject: function(options) { | ||
return this._super(options); | ||
}, | ||
fromXmlObj: function(obj) { | ||
var self = this; | ||
Object.assign(self, _.omit(obj, 'Addresses', 'Phones', 'ExternalLinks')); | ||
if (obj.Addresses) { | ||
_.each(obj.Addresses.Address, function(address) { | ||
self.Addresses.push(address); | ||
}) | ||
} | ||
if (obj.Phones) { | ||
_.each(obj.Phones.Phone, function(phone) { | ||
self.Phones.push(phone); | ||
}) | ||
} | ||
if (obj.ExternalLinks) { | ||
_.each(obj.ExternalLinks.ExternalLink, function(externalLink) { | ||
self.ExternalLinks.push(externalLink); | ||
}) | ||
} | ||
return this; | ||
} | ||
const Organisation = Entity.extend(OrganisationSchema, { | ||
constructor: function(...args) { | ||
this.Entity.apply(this, args); | ||
}, | ||
changes: function(options) { | ||
return this._super(options); | ||
}, | ||
_toObject: function(options) { | ||
return this._super(options); | ||
}, | ||
}); | ||
module.exports = Organisation; | ||
module.exports.Organisation = Organisation; |
@@ -7,13 +7,8 @@ var _ = require('lodash'), | ||
constructor: function(application, data, options) { | ||
console.log('Payment::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function(data, options) {}, | ||
toXml: function() { | ||
var payment = _.omit(this.toObject()); | ||
return this.application.js2xml(payment, 'Payment'); | ||
}, | ||
save: function(options) { | ||
var self = this; | ||
var xml = '<Payments>' + this.toXml() + '</Payments>'; | ||
var path, method; | ||
@@ -27,4 +22,4 @@ if (this.PaymentID) { | ||
} | ||
return this.application.putOrPostEntity(method, path, xml, { | ||
entityPath: 'Payments.Payment', | ||
return this.application.putOrPostEntity(method, path, JSON.stringify(self), { | ||
entityPath: 'Payments', | ||
entityConstructor: function(data) { | ||
@@ -38,2 +33,2 @@ return self.application.core.payments.newPayment(data); | ||
module.exports = Payment; | ||
module.exports.Payment = Payment; |
var _ = require('lodash'), | ||
Entity = require('../entity') | ||
var ReportSchema = new Entity.SchemaObject({ | ||
var ReportSchema = Entity.SchemaObject({ | ||
ReportID: { type: String, toObject: 'always' }, | ||
@@ -9,12 +9,12 @@ ReportName: { type: String, toObject: 'always' }, | ||
ReportTitles: { type: Array, arrayType: ReportTitleSchema, toObject: 'always' }, | ||
ReportDate: { type: String, toObject: 'always' }, | ||
UpdatedDateUTC: { type: String, toObject: 'always' }, | ||
ReportDate: { type: Date, toObject: 'always' }, | ||
UpdatedDateUTC: { type: Date, toObject: 'always' }, | ||
Rows: { type: Array, arrayType: ReportRowSchema, toObject: 'always' } | ||
}); | ||
var ReportTitleSchema = new Entity.SchemaObject({ | ||
var ReportTitleSchema = Entity.SchemaObject({ | ||
ReportTitle: { type: String, toObject: 'always' } | ||
}); | ||
var ReportRowSchema = new Entity.SchemaObject({ | ||
var ReportRowSchema = Entity.SchemaObject({ | ||
RowType: { type: String, toObject: 'always' }, | ||
@@ -25,3 +25,3 @@ Title: { type: String, toObject: 'always' }, | ||
var ReportCellSchema = new Entity.SchemaObject({ | ||
var ReportCellSchema = Entity.SchemaObject({ | ||
Value: { type: String, toObject: 'always' }, | ||
@@ -31,3 +31,3 @@ Attributes: { type: Array, arrayType: ReportAttributeSchema, toObject: 'always' } | ||
var ReportAttributeSchema = new Entity.SchemaObject({ | ||
var ReportAttributeSchema = Entity.SchemaObject({ | ||
Value: { type: String, toObject: 'always' }, | ||
@@ -39,58 +39,9 @@ Id: { type: String, toObject: 'always' } | ||
constructor: function(application, data, options) { | ||
console.log('Report::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function(data, options) {}, | ||
fromXmlObj: function(obj) { | ||
var self = this; | ||
Object.assign(self, _.omit(obj, 'Rows', 'Cells', 'ReportTitles')); | ||
if (obj.ReportTitles) { | ||
this.extractArray(obj.ReportTitles.ReportTitle, this.ReportTitles); | ||
} | ||
if (hasMoreRows(obj)) { | ||
//Loop through the rows to find the next level down | ||
obj.Rows.Row.forEach(function(level1Row) { | ||
if (hasMoreRows(level1Row)) { | ||
var level2RowsArray = []; | ||
level1Row.Rows.Row.forEach(function(level2row) { | ||
level2row.Cells ? level2row.Cells = extractCells(level2row) : false; | ||
level2RowsArray.push(level2row); | ||
}); | ||
level1Row.Rows = level2RowsArray; | ||
} | ||
level1Row.Cells ? level1Row.Cells = extractCells(level1Row) : false; | ||
self.Rows.push(level1Row); | ||
}); | ||
} else { | ||
//No more rows, but we should check for cells in this row | ||
if (obj.Rows && obj.Rows.Row && obj.Rows.Row.Cells && obj.Rows.Row.Cells.Cell && obj.Rows.Row.Cells.Cell.length > 0) { | ||
obj.Rows.Row.Cells = extractCells(obj.Rows.Row); | ||
self.Rows.push(obj.Rows.Row); | ||
} | ||
} | ||
return this; | ||
function hasMoreRows(obj) { | ||
return obj.Rows && obj.Rows.Row && obj.Rows.Row.length >= 0; | ||
} | ||
function extractCells(row) { | ||
var cells = []; | ||
if (row.Cells) { | ||
row.Cells.Cell.forEach(function(cell) { | ||
cells.push(cell); | ||
}); | ||
row.Cells = cells; | ||
} | ||
return cells; | ||
} | ||
} | ||
initialize: function(data, options) {} | ||
}); | ||
module.exports = Report; | ||
module.exports.Report = Report; | ||
module.exports.ReportSchema = ReportSchema; |
var _ = require('lodash'), | ||
Entity = require('../entity') | ||
var TaxRateSchema = new Entity.SchemaObject({ | ||
var TaxRateSchema = Entity.SchemaObject({ | ||
Name: { type: String, toObject: 'always' }, | ||
@@ -19,3 +19,3 @@ TaxType: { type: String, toObject: 'always' }, | ||
var TaxComponentSchema = new Entity.SchemaObject({ | ||
var TaxComponentSchema = Entity.SchemaObject({ | ||
Name: { type: String, toObject: 'always' }, | ||
@@ -29,25 +29,8 @@ Rate: { type: String, toObject: 'always' }, | ||
constructor: function(application, data, options) { | ||
console.log('TaxRate::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function(data, options) {}, | ||
fromXmlObj: function(obj) { | ||
var self = this; | ||
_.extend(self, _.omit(obj, 'TaxComponents')); | ||
if (obj.TaxComponents) { | ||
this.extractArray(obj.TaxComponents.TaxComponent, this.TaxComponents); | ||
} | ||
return this; | ||
}, | ||
toXml: function() { | ||
var taxRate = _.omit(this.toObject(), 'TaxComponents'); | ||
Object.assign(taxRate, { TaxComponents: [] }); | ||
_.forEach(this.TaxComponents, function(taxComponent) { | ||
taxRate.TaxComponents.push({ TaxComponent: taxComponent }) | ||
}) | ||
return this.application.js2xml(taxRate, 'TaxRate'); | ||
}, | ||
save: function(options) { | ||
var self = this; | ||
var xml = '<TaxRates>' + this.toXml() + '</TaxRates>'; | ||
var path = 'TaxRates', | ||
@@ -60,3 +43,3 @@ method; | ||
} | ||
return this.application.putOrPostEntity(method, path, xml, { entityPath: 'TaxRates.TaxRate', entityConstructor: function(data) { return self.application.core.taxRates.newTaxRate(data) } }); | ||
return this.application.putOrPostEntity(method, path, JSON.stringify(self), { entityPath: 'TaxRates', entityConstructor: function(data) { return self.application.core.taxRates.newTaxRate(data) } }); | ||
}, | ||
@@ -70,4 +53,4 @@ delete: function(options) { | ||
module.exports = TaxRate; | ||
module.exports.TaxRate = TaxRate; | ||
module.exports.TaxRateSchema = TaxRateSchema; | ||
module.exports.TaxComponentSchema = TaxComponentSchema; |
@@ -5,7 +5,7 @@ var _ = require('lodash'), | ||
var TrackingCategorySchema = new Entity.SchemaObject({ | ||
var TrackingCategorySchema = Entity.SchemaObject({ | ||
TrackingCategoryID: { type: String, toObject: 'always' }, | ||
Name: { type: String, toObject: 'always' }, | ||
Status: { type: String, toObject: 'always' }, | ||
Options: { type: Array, arrayType: TrackingOptionSchema, toObject: 'always', readOnly: 'true' } | ||
Options: { type: Array, arrayType: TrackingOptionSchema, toObject: 'always' } | ||
}); | ||
@@ -15,3 +15,3 @@ | ||
constructor: function(application, data, options) { | ||
console.log('TrackingCategory::constructor'); | ||
this.Entity.apply(this, arguments); | ||
@@ -26,24 +26,4 @@ }, | ||
}, | ||
fromXmlObj: function(obj) { | ||
var self = this; | ||
Object.assign(self, _.omit(obj, 'Options')); | ||
if (obj.Options) { | ||
this.extractArray(obj.Options.Option, this.Options); | ||
} | ||
return this; | ||
}, | ||
toXml: function() { | ||
var trackingCategory = _.omit(this.toObject(), 'Options'); | ||
// Options cannot be saved using this endpoint, they must use the specific /options endpoint | ||
// Object.assign(trackingCategory, { Options: [] }); | ||
// _.forEach(this.Options, function(option) { | ||
// trackingCategory.Options.push({ Option: option.toObject() }) | ||
// }) | ||
return this.application.js2xml(trackingCategory, 'TrackingCategory'); | ||
}, | ||
save: function(options) { | ||
var self = this; | ||
var xml = '<TrackingCategories>' + this.toXml() + '</TrackingCategories>'; | ||
var path, method; | ||
@@ -57,27 +37,6 @@ if (this.TrackingCategoryID) { | ||
} | ||
return this.application.putOrPostEntity(method, path, xml, { entityPath: 'TrackingCategories.TrackingCategory', entityConstructor: function(data) { return self.application.core.trackingCategories.newTrackingCategory(data) } }); | ||
return this.application.putOrPostEntity(method, path, JSON.stringify(self), { entityPath: 'TrackingCategories', entityConstructor: function(data) { return self.application.core.trackingCategories.newTrackingCategory(data) } }); | ||
}, | ||
saveTrackingOptions: function(trackingOptions, trackingOptionID) { | ||
var self = this; | ||
var xml = '<Options>'; | ||
if (_.isArray(trackingOptions)) { | ||
_.each(trackingOptions, function(option) { | ||
xml += "<Option>"; | ||
if (option.Name) | ||
xml += "<Name>" + option.Name + "</Name>"; | ||
if (option.Status) | ||
xml += "<Status>" + option.Status + "</Status>"; | ||
xml += "</Option>"; | ||
}); | ||
} else if (trackingOptions.Name != undefined) { | ||
xml += "<Option>"; | ||
xml += "<Name>" + trackingOptions.Name + "</Name>"; | ||
if (trackingOptions.Status) | ||
xml += "<Status>" + trackingOptions.Status + "</Status>"; | ||
xml += "</Option>"; | ||
} | ||
xml += "</Options>"; | ||
var path, method; | ||
@@ -91,3 +50,11 @@ if (trackingOptionID) { | ||
} | ||
return this.application.putOrPostEntity(method, path, xml, { entityPath: 'Options.Option', entityConstructor: function(data) { return self.application.core.trackingCategories.newTrackingOption(data) } }); | ||
if (!_.isArray(trackingOptions)) | ||
trackingOptions = [trackingOptions]; | ||
var payload = { | ||
Options: trackingOptions | ||
}; | ||
return this.application.putOrPostEntity(method, path, JSON.stringify(payload), { entityPath: 'Options', entityConstructor: function(data) { return self.application.core.trackingCategories.newTrackingOption(data) } }); | ||
}, | ||
@@ -100,3 +67,3 @@ deleteTrackingOption: function(trackingOptionID) { | ||
module.exports = TrackingCategory; | ||
module.exports.TrackingCategory = TrackingCategory; | ||
module.exports.TrackingCategorySchema = TrackingCategorySchema; |
@@ -7,3 +7,3 @@ var _ = require('lodash'), | ||
constructor: function(application, data, options) { | ||
console.log('TrackingOption::constructor'); | ||
this.Entity.apply(this, arguments); | ||
@@ -23,2 +23,2 @@ }, | ||
module.exports = TrackingOption; | ||
module.exports.TrackingOption = TrackingOption; |
var _ = require('lodash'), | ||
Entity = require('../entity'); | ||
var UserSchema = new Entity.SchemaObject({ | ||
var UserSchema = Entity.SchemaObject({ | ||
UserID: { | ||
@@ -40,14 +40,10 @@ type: String, | ||
constructor: function(application, data, options) { | ||
console.log('User::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function(data, options) {}, | ||
toXml: function() { | ||
var user = _.omit(this.toObject()); | ||
return this.application.js2xml(user, 'User'); | ||
} | ||
initialize: function(data, options) {} | ||
}); | ||
module.exports = User; | ||
module.exports.User = User; | ||
module.exports.UserSchema = UserSchema; |
@@ -1,63 +0,58 @@ | ||
var extend = require('../misc/extend'), | ||
_ = require('lodash'), | ||
util = require('util'), | ||
qs = require('querystring'), | ||
SchemaObject = require('../schemaobject/schemaobject'); | ||
'use strict'; | ||
const extend = require('../misc/extend'); | ||
const _ = require('lodash'); | ||
const SchemaObject = require('../schemaobject/schemaobject'); | ||
module.exports.SchemaObject = SchemaObject; | ||
module.exports.dateToString = function(value) { | ||
return value.toISOString(); | ||
} | ||
module.exports.extend = function(schema, classProps, staticProps) { | ||
schema.extend = extend; | ||
var Entity = schema.extend({ | ||
constructor: function(application, data, options) { | ||
this._application = application; | ||
options = options || {}; | ||
this.options = options; | ||
schema.call(this, data); | ||
wrap(this); | ||
this._schemaToObject = this.toObject; | ||
this.toObject = this._toObject; | ||
_.isFunction(this.initialize) && this.initialize(options); | ||
}, | ||
_toObject: function(options) { | ||
return this._schemaToObject(options); | ||
}, | ||
makeError: function(code, message, data) { | ||
return { code: code, data: data, message: message }; | ||
}, | ||
changes: function(options) { | ||
return _.clone(this.tracking._changes); | ||
}, | ||
fromXmlObj: function(obj) { | ||
return Object.assign(this, obj); | ||
}, | ||
extractArray: function(src, dest) { | ||
var items = this.asArray(src); | ||
_.each(items, function(item) { | ||
dest.push(item); | ||
}) | ||
module.exports.dateToString = value => value.toISOString(); | ||
}, | ||
asArray: function(obj) { | ||
if (_.isArray(obj)) | ||
return obj; | ||
else if (!_.isUndefined(obj)) | ||
return [obj]; | ||
}, | ||
}) | ||
module.exports.extend = (schema, classProps, staticProps) => { | ||
schema.extend = extend; | ||
const Entity = schema.extend({ | ||
constructor: function(application, data, options) { | ||
this._application = application; | ||
options = options || {}; | ||
this.options = options; | ||
schema.call(this, data); | ||
wrap(this); | ||
this._schemaToObject = this.toObject; | ||
this.toObject = this._toObject; | ||
_.isFunction(this.initialize) && this.initialize(options); | ||
}, | ||
_toObject: function(options) { | ||
return this._schemaToObject(options); | ||
}, | ||
makeError: function(code, message, data) { | ||
return { code: code, data: data, message: message }; | ||
}, | ||
changes: function(options) { | ||
return _.clone(this.tracking._changes); | ||
}, | ||
fromXmlObj: function(obj) { | ||
return Object.assign(this, obj); | ||
}, | ||
extractArray: function(src, dest) { | ||
var items = this.asArray(src); | ||
_.each(items, function(item) { | ||
dest.push(item); | ||
}); | ||
}, | ||
asArray: function(obj) { | ||
if (_.isArray(obj)) return obj; | ||
else if (!_.isUndefined(obj)) return [obj]; | ||
}, | ||
}); | ||
return Entity.extend(Object.assign(classProps, { Entity: Entity }), staticProps); | ||
return Entity.extend(Object.assign(classProps, { Entity }), staticProps); | ||
}; | ||
} | ||
function wrap(that) { | ||
Object.defineProperties(that, { | ||
application: { | ||
get: function() { | ||
return that._application; | ||
} | ||
} | ||
}) | ||
Object.defineProperties(that, { | ||
application: { | ||
get: function() { | ||
return that._application; | ||
}, | ||
}, | ||
}); | ||
} |
var _ = require('lodash'), | ||
Entity = require('../entity') | ||
Entity = require('../entity'), | ||
EarningsRateSchema = require('../shared').EarningsRateSchema, | ||
DeductionTypeSchema = require('../shared').DeductionTypeSchema, | ||
ReimbursementTypeSchema = require('../shared').ReimbursementTypeSchema, | ||
LeaveTypeSchema = require('../shared').LeaveTypeSchema, | ||
PayItemsSchema = require('../shared').PayItemsSchema | ||
var EarningTypeSchema = new Entity.SchemaObject({ | ||
EarningsType: { type: String }, | ||
ExpenseAccountCode: { type: String }, | ||
EarningsCategory: { type: String }, | ||
RateType: { type: String }, | ||
TypeOfUnits: { type: String }, | ||
EarningRateID: { type: String }, | ||
Multiple: { type: Number }, | ||
DoNotAccrueTimeOff: { type: Boolean }, | ||
IsSupplemental: { type: Boolean }, | ||
Amount: { type: Number } | ||
}); | ||
var BenefitTypeSchema = new Entity.SchemaObject({ | ||
BenefitType: { type: String }, | ||
BenefitCategory: { type: String }, | ||
LiabilityAccountCode: { type: String }, | ||
ExpenseAccountCode: { type: String }, | ||
BenefitTypeID: { type: String }, | ||
StandardAmount: { type: Number }, | ||
CompanyMax: { type: Number }, | ||
Percentage: { type: Number }, | ||
ShowBalanceOnPaystub: { type: Boolean } | ||
}); | ||
var DeductionTypeSchema = new Entity.SchemaObject({ | ||
DeductionType: { type: String }, | ||
DeductionCategory: { type: String }, | ||
CalculationType: { type: String }, | ||
LiabilityAccountCode: { type: String }, | ||
DeductionTypeID: { type: String }, | ||
StandardAmount: { type: Number }, | ||
CompanyMax: { type: Number } | ||
}); | ||
var ReimbursementTypeSchema = new Entity.SchemaObject({ | ||
DeductionType: { type: String }, | ||
ExpenseOfLiabilityAccountCode: { type: String }, | ||
ReimbursementTypeID: { type: String } | ||
}); | ||
var TimeOffTypeSchema = new Entity.SchemaObject({ | ||
TimeOffType: { type: String }, | ||
TimeOffCategory: { type: String }, | ||
LiabilityAccountCode: { type: String }, | ||
ExpenseAccountCode: { type: String }, | ||
TimeOffTypeID: { type: String }, | ||
ShowBalanceToEmployee: { type: Boolean } | ||
}); | ||
var PayItemsSchema = new Entity.SchemaObject({ | ||
EarningsTypes: [EarningTypeSchema], | ||
BenefitTypes: [BenefitTypeSchema], | ||
DeductionTypes: [DeductionTypeSchema], | ||
ReimbursementTypes: [ReimbursementTypeSchema], | ||
TimeOffTypes: [TimeOffTypeSchema] | ||
}); | ||
var PayItems = Entity.extend(PayItemsSchema, { | ||
constructor: function(application, data, options) { | ||
console.log('PayItems::constructor'); | ||
this.Entity.apply(this, arguments); | ||
@@ -75,31 +21,126 @@ }, | ||
return this._super(options); | ||
} | ||
}); | ||
var EarningsRate = Entity.extend(EarningsRateSchema, { | ||
constructor: function(application, data, options) { | ||
logger.debug('EarningsRates::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
fromXmlObj: function(obj) { | ||
var self = this; | ||
Object.assign(self, _.omit(obj, 'BenefitTypes', 'EarningsTypes', 'ReimbursementTypes', 'DeductionTypes', 'TimeOffTypes')); | ||
if (obj.BenefitTypes) { | ||
this.extractArray(obj.BenefitTypes.BenefitType, this.BenefitTypes); | ||
} | ||
if (obj.EarningsTypes) { | ||
this.extractArray(obj.EarningsTypes.EarningsType, this.EarningsTypes); | ||
} | ||
if (obj.ReimbursementTypes) { | ||
this.extractArray(obj.ReimbursementTypes.ReimbursementType, this.ReimbursementTypes); | ||
} | ||
if (obj.TimeOffTypes) { | ||
this.extractArray(obj.TimeOffTypes.TimeOffTypes, this.TimeOffTypes); | ||
} | ||
initialize: function(data, options) {}, | ||
save: function(options) { | ||
return saveObj(this, 'EarningsRate', options) | ||
}, | ||
delete: function(options) { | ||
return this.save({ delete: true }) | ||
} | ||
}); | ||
if (obj.DeductionTypes) { | ||
this.extractArray(obj.DeductionTypes.DeductionType, this.DeductionTypes); | ||
} | ||
var DeductionType = Entity.extend(DeductionTypeSchema, { | ||
constructor: function(application, data, options) { | ||
logger.debug('DeductionType::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function(data, options) {}, | ||
save: function(options) { | ||
return saveObj(this, 'DeductionType', options) | ||
}, | ||
delete: function(options) { | ||
return this.save({ delete: true }) | ||
} | ||
}); | ||
return this; | ||
var ReimbursementType = Entity.extend(ReimbursementTypeSchema, { | ||
constructor: function(application, data, options) { | ||
logger.debug('ReimbursementType::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
toXml: function() { | ||
initialize: function(data, options) {}, | ||
save: function(options) { | ||
return saveObj(this, 'ReimbursementType', options) | ||
}, | ||
delete: function(options) { | ||
return this.save({ delete: true }) | ||
} | ||
}); | ||
var LeaveType = Entity.extend(LeaveTypeSchema, { | ||
constructor: function(application, data, options) { | ||
logger.debug('LeaveType::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function(data, options) {}, | ||
save: function(options) { | ||
return saveObj(this, 'LeaveType', options) | ||
}, | ||
delete: function(options) { | ||
return this.save({ delete: true }) | ||
} | ||
}); | ||
/** | ||
* Jordan Walsh - May 2017 | ||
* These two functions manage the serialisation and deserialisation of the different object types in the PayItems endpoint. | ||
* | ||
* Currently this endpoint functions in an odd way. Instead of having 5 different endpoints, the objects all exist on one. | ||
* | ||
* When data is not supplied to the endpoint on updates, the data is removed from the back end. | ||
* | ||
* In an effort to streamline the process for the SDK user, they can work with single objects, and any data not supplied by | ||
* the SDK consumer is automatically restored to it's original state in the back end. | ||
* | ||
* If the PayItems endpoint changes behaviour in future, these two functions will need to be updated. | ||
*/ | ||
module.exports = PayItems; | ||
function fromXmlObj(obj, objType, options) { | ||
var options = options || {}; | ||
var payItem = _.omit(obj.toObject()); | ||
var self = obj; | ||
var xml = ''; | ||
var currentID = payItem[objType + 'ID'] || ''; | ||
if (currentID === '') { | ||
//This is a new earnings rate, so we can generate the XML now | ||
xml = self.application.js2xml(payItem, objType) | ||
} | ||
return self.application.payroll.payitems[`get${objType}s`]() | ||
.then(function(existingPayItems) { | ||
existingPayItems.forEach(function(existingPayItem) { | ||
if (existingPayItem[objType + 'ID'] === currentID) { | ||
if (options.delete === true) { | ||
//we need to remove the current object | ||
existingPayItem = null; | ||
} else { | ||
//we're doing an update so merge the current object | ||
_.merge(existingPayItem, payItem) | ||
} | ||
} | ||
if (existingPayItem) | ||
xml += self.application.js2xml(existingPayItem.toJSON(), objType) | ||
}) | ||
return xml; | ||
}) | ||
.catch(function(err) { | ||
return err; | ||
}) | ||
} | ||
function saveObj(obj, objType, options) { | ||
var self = obj; | ||
return fromXmlObj(obj, objType, options).then(function(entityXml) { | ||
var xml = `<PayItems><${objType}s>` + entityXml + `</${objType}s></PayItems>`; | ||
var path = 'PayItems'; | ||
var method = 'post' | ||
return self.application.putOrPostEntity(method, path, xml, { entityPath: `PayItems.${objType}s.${objType}`, entityConstructor: function(data) { return self.application.payroll.payitems[`new${objType}`](data) }, api: 'payroll' }) | ||
}) | ||
} | ||
module.exports.LeaveType = LeaveType | ||
module.exports.ReimbursementType = ReimbursementType | ||
module.exports.DeductionType = DeductionType | ||
module.exports.EarningsRate = EarningsRate | ||
module.exports.PayItems = PayItems |
@@ -5,4 +5,4 @@ var _ = require('lodash'), | ||
var TimesheetLineSchema = new Entity.SchemaObject({ | ||
EarningsTypeID: { type: String }, | ||
var TimesheetLineSchema = Entity.SchemaObject({ | ||
EarningsRateID: { type: String }, | ||
TrackingItemID: { type: String }, | ||
@@ -12,3 +12,3 @@ NumberOfUnits: { type: Array, arrayType: Number, toObject: 'always' } | ||
var TimesheetSchema = new Entity.SchemaObject({ | ||
var TimesheetSchema = Entity.SchemaObject({ | ||
EmployeeID: { type: String, toObject: 'hasValue' }, | ||
@@ -25,3 +25,3 @@ StartDate: { type: Date, toObjectTransform: Entity.dateToString, toObject: 'hasValue' }, | ||
constructor: function(application, data, options) { | ||
console.log('Timesheet::constructor'); | ||
this.Entity.apply(this, arguments); | ||
@@ -43,3 +43,3 @@ }, | ||
/* | ||
/* | ||
if (obj.TimesheetLines) { | ||
@@ -49,3 +49,3 @@ var items = this.application.asArray(obj.TimesheetLines.TimesheetLine); | ||
var index = self.TimesheetLines.push({ EarningsTypeID: item.EarningsTypeID }) - 1; | ||
var index = self.TimesheetLines.push({ EarningsRateID: item.EarningsRateID }) - 1; | ||
var addedNumberOfUnit = self.TimesheetLines[index]; | ||
@@ -66,3 +66,3 @@ _.each(item.NumberOfUnits.NumberOfUnit, function(unit) { | ||
_.forEach(this.TimesheetLines, function(timesheetline) { | ||
timesheet.TimesheetLines.push({ TimesheetLine: _.pick(timesheetline.toObject(), 'EarningsTypeID', 'TrackingItemID') }); | ||
timesheet.TimesheetLines.push({ TimesheetLine: _.pick(timesheetline.toObject(), 'EarningsRateID', 'TrackingItemID') }); | ||
var addedTimesheetLine = _.last(timesheet.TimesheetLines).TimesheetLine; | ||
@@ -95,3 +95,3 @@ addedTimesheetLine.NumberOfUnits = { NumberOfUnit: [] }; | ||
module.exports = Timesheet; | ||
module.exports.TimesheetSchema = TimesheetSchema; | ||
module.exports.Timesheet = Timesheet; | ||
module.exports.TimesheetSchema = TimesheetSchema; |
var Entity = require('./entity') | ||
module.exports.AddressSchema = new Entity.SchemaObject({ | ||
/** | ||
* ACCOUNTING API SHARED SCHEMAS | ||
*/ | ||
var AddressDetailsSchema = Entity.SchemaObject({ | ||
AddressLine1: { type: String, toObject: 'always' }, | ||
@@ -14,5 +18,9 @@ AddressLine2: { type: String, toObject: 'always' }, | ||
AddressType: { type: String, toObject: 'always' } | ||
}) | ||
module.exports.AddressSchema = Entity.SchemaObject({ | ||
Address: { type: AddressDetailsSchema, toObject: 'always' } | ||
}); | ||
module.exports.PhoneSchema = new Entity.SchemaObject({ | ||
module.exports.PhoneSchema = Entity.SchemaObject({ | ||
PhoneNumber: { type: String, toObject: 'always' }, | ||
@@ -24,7 +32,11 @@ PhoneAreaCode: { type: String, toObject: 'always' }, | ||
module.exports.ExternalLinkSchema = new Entity.SchemaObject({ | ||
LinkType: { type: String }, | ||
Url: { type: String } | ||
const ExternalLinkDetailsSchema = Entity.SchemaObject({ | ||
LinkType: { type: String, toObject: 'always' }, | ||
Url: { type: String, toObject: 'always' }, | ||
}); | ||
module.exports.ExternalLinkSchema = Entity.SchemaObject({ | ||
ExternalLink: { type: ExternalLinkDetailsSchema, toObject: 'always' }, | ||
}); | ||
module.exports.ContactPerson = new Entity.SchemaObject({ | ||
@@ -37,3 +49,3 @@ FirstName: { type: String, toObject: 'always' }, | ||
module.exports.PaymentTermSchema = new Entity.SchemaObject({ | ||
module.exports.PaymentTermSchema = Entity.SchemaObject({ | ||
Day: { type: Number }, | ||
@@ -43,3 +55,3 @@ Type: { type: String } | ||
module.exports.BrandingScheme = new Entity.SchemaObject({ | ||
module.exports.BrandingScheme = Entity.SchemaObject({ | ||
BrandingThemeID: { type: String }, | ||
@@ -51,3 +63,3 @@ Name: { type: String }, | ||
var InvoiceIDSchema = new Entity.SchemaObject({ | ||
var InvoiceIDSchema = Entity.SchemaObject({ | ||
InvoiceID: { type: String, toObject: 'hasValue' }, | ||
@@ -57,3 +69,3 @@ InvoiceNumber: { type: String, toObject: 'hasValue' } | ||
var CreditNoteIDSchema = new Entity.SchemaObject({ | ||
var CreditNoteIDSchema = Entity.SchemaObject({ | ||
CreditNoteID: { type: String, toObject: 'hasValue' }, | ||
@@ -63,3 +75,3 @@ CreditNoteNumber: { type: String, toObject: 'hasValue' } | ||
var AccountIDorCodeSchema = new Entity.SchemaObject({ | ||
var AccountIDorCodeSchema = Entity.SchemaObject({ | ||
AccountID: { type: String, toObject: 'hasValue' }, | ||
@@ -69,7 +81,7 @@ Code: { type: String, toObject: 'hasValue' } | ||
module.exports.PaymentSchema = new Entity.SchemaObject({ | ||
module.exports.PaymentSchema = Entity.SchemaObject({ | ||
Invoice: { type: InvoiceIDSchema, toObject: 'always' }, | ||
CreditNote: { type: CreditNoteIDSchema, toObject: 'always' }, | ||
Account: { type: AccountIDorCodeSchema, toObject: 'always' }, | ||
Date: { type: String, toObject: 'always' }, | ||
Date: { type: Date, toObject: 'always' }, | ||
CurrencyRate: { type: Number, toObject: 'hasValue' }, | ||
@@ -81,6 +93,6 @@ Amount: { type: Number, toObject: 'hasValue' }, | ||
PaymentType: { type: String, toObject: 'hasValue' }, | ||
UpdatedDateUTC: { type: String, toObject: 'hasValue' } | ||
UpdatedDateUTC: { type: Date, toObject: 'never' } | ||
}); | ||
module.exports.TrackingOptionSchema = new Entity.SchemaObject({ | ||
module.exports.TrackingOptionSchema = Entity.SchemaObject({ | ||
TrackingOptionID: { type: String, toObject: 'always' }, | ||
@@ -91,3 +103,3 @@ Name: { type: String, toObject: 'always' }, | ||
var TrackingCategoryOptionsSchema = new Entity.SchemaObject({ | ||
var TrackingCategoryOptionsSchema = Entity.SchemaObject({ | ||
TrackingCategoryID: { type: String, toObject: 'hasValue' }, | ||
@@ -98,8 +110,7 @@ Name: { type: String, toObject: 'hasValue' }, | ||
var TrackingCategorySchema = new Entity.SchemaObject({ | ||
var TrackingCategorySchema = Entity.SchemaObject({ | ||
TrackingCategory: { type: TrackingCategoryOptionsSchema, toObject: 'hasValue' } | ||
}); | ||
module.exports.LineItemSchema = new Entity.SchemaObject({ | ||
LineItemID: { type: String }, | ||
module.exports.LineItemSchema = Entity.SchemaObject({ | ||
Description: { type: String }, | ||
@@ -115,2 +126,63 @@ Quantity: { type: Number }, | ||
DiscountRate: { type: Number } | ||
}); | ||
}); | ||
/** | ||
* PAYROLL API SHARED SCHEMAS | ||
*/ | ||
var EarningsRateSchema = Entity.SchemaObject({ | ||
EarningsRateID: { type: String, toObject: 'always' }, | ||
Name: { type: String, toObject: 'always' }, | ||
AccountCode: { type: String, toObject: 'always' }, | ||
TypeOfUnits: { type: String, toObject: 'always' }, | ||
IsExemptFromTax: { type: Boolean, toObject: 'always' }, | ||
IsExemptFromSuper: { type: Boolean, toObject: 'always' }, | ||
EarningsType: { type: String, toObject: 'always' }, | ||
RateType: { type: String, toObject: 'always' }, | ||
RatePerUnit: { type: String, toObject: 'hasValue' }, | ||
Multiplier: { type: Number, toObject: 'hasValue' }, | ||
AccrueLeave: { type: Boolean, toObject: 'hasValue' }, | ||
Amount: { type: Number, toObject: 'always' }, | ||
UpdatedDateUTC: { type: Date, toObject: 'never' } | ||
}); | ||
var DeductionTypeSchema = Entity.SchemaObject({ | ||
DeductionTypeID: { type: String, toObject: 'always' }, | ||
DeductionCategory: { type: String, toObject: 'always' }, | ||
Name: { type: String, toObject: 'always' }, | ||
AccountCode: { type: String, toObject: 'hasValue' }, | ||
ReducesTax: { type: Boolean, toObject: 'hasValue' }, | ||
ReducesSuper: { type: Boolean, toObject: 'hasValue' }, | ||
UpdatedDateUTC: { type: Date, toObject: 'never' } | ||
}); | ||
var ReimbursementTypeSchema = Entity.SchemaObject({ | ||
ReimbursementTypeID: { type: String, toObject: 'always' }, | ||
Name: { type: 'String', toObject: 'always' }, | ||
AccountCode: { type: String, toObject: 'hasValue' }, | ||
UpdatedDateUTC: { type: Date, toObject: 'never' } | ||
}); | ||
var LeaveTypeSchema = Entity.SchemaObject({ | ||
LeaveTypeID: { type: String, toObject: 'always' }, | ||
Name: { type: String, toObject: 'always' }, | ||
TypeOfUnits: { type: String, toObject: 'always' }, | ||
NormalEntitlement: { type: String, toObject: 'hasValue' }, | ||
LeaveLoadingRate: { type: String, toObject: 'hasValue' }, | ||
IsPaidLeave: { type: Boolean, toObject: 'always' }, | ||
ShowOnPayslip: { type: Boolean, toObject: 'always' }, | ||
UpdatedDateUTC: { type: Date, toObject: 'never' } | ||
}); | ||
var PayItemsSchema = Entity.SchemaObject({ | ||
EarningsRates: [EarningsRateSchema], | ||
DeductionTypes: [DeductionTypeSchema], | ||
ReimbursementTypes: [ReimbursementTypeSchema], | ||
LeaveTypes: [LeaveTypeSchema] | ||
}); | ||
module.exports.PayItemsSchema = PayItemsSchema | ||
module.exports.LeaveTypeSchema = LeaveTypeSchema | ||
module.exports.ReimbursementTypeSchema = ReimbursementTypeSchema | ||
module.exports.DeductionTypeSchema = DeductionTypeSchema | ||
module.exports.EarningsRateSchema = EarningsRateSchema |
@@ -1,36 +0,37 @@ | ||
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
Account = require('../../entities/accounting/account'), | ||
util = require('util') | ||
'use strict'; | ||
var Accounts = EntityHelper.extend({ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'Account', entityPlural: 'Accounts' }, options)); | ||
}, | ||
newAccount: function(data, options) { | ||
return new Account(this.application, data, options) | ||
}, | ||
getAccount: function(id, modifiedAfter) { | ||
return this.getAccounts({ id: id, modifiedAfter: modifiedAfter }) | ||
.then(function(accounts) { | ||
return _.first(accounts); | ||
}) | ||
}, | ||
deleteAccount: function(id) { | ||
var options = { | ||
id: id | ||
}; | ||
return this.deleteEntities(options); | ||
}, | ||
saveAccounts: function(accounts, options) { | ||
return this.saveEntities(accounts, options) | ||
}, | ||
getAccounts: function(options) { | ||
var self = this; | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityConstructor = function(data) { return self.newAccount(data) }; | ||
return this.getEntities(clonedOptions) | ||
} | ||
}) | ||
const _ = require('lodash'); | ||
const EntityHelper = require('../entity_helper'); | ||
const Account = require('../../entities/accounting/account').Account; | ||
const util = require('util'); | ||
const Accounts = EntityHelper.extend({ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'Accounts' }, options)); | ||
}, | ||
newAccount: function(data, options) { | ||
return new Account(this.application, data, options) | ||
}, | ||
getAccount: function(id, modifiedAfter) { | ||
return this.getAccounts({ id, modifiedAfter }).then(function(accounts) { | ||
return _.first(accounts); | ||
}) | ||
}, | ||
deleteAccount: function(id) { | ||
const options = { | ||
id, | ||
}; | ||
return this.deleteEntities(options); | ||
}, | ||
saveAccounts: function(accounts, options) { | ||
return this.saveEntities(accounts, options); | ||
}, | ||
getAccounts: function(options) { | ||
let self = this; | ||
let clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityConstructor = function(data) { return self.newAccount(data) }; | ||
return this.getEntities(clonedOptions) | ||
} | ||
}); | ||
module.exports = Accounts; |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
Attachment = require('../../entities/accounting/attachment'), | ||
Attachment = require('../../entities/accounting/attachment').Attachment, | ||
util = require('util') | ||
@@ -8,3 +8,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'Attachment', entityPlural: 'Attachments' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'Attachments' }, options)); | ||
}, | ||
@@ -29,2 +29,3 @@ newAttachment: function(data, options) { | ||
var clonedOptions = Object.assign({}, options, { path: ownerPath + '/Attachments' }); | ||
clonedOptions.entityPath = 'Attachments'; | ||
clonedOptions.entityConstructor = function(data) { return self.newAttachment(data) }; | ||
@@ -31,0 +32,0 @@ return this.getEntities(clonedOptions); |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
BankTransaction = require('../../entities/accounting/banktransaction'), | ||
BankTransaction = require('../../entities/accounting/banktransaction').BankTransaction, | ||
util = require('util') | ||
@@ -8,3 +8,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'BankTransaction', entityPlural: 'BankTransactions' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'BankTransactions' }, options)); | ||
}, | ||
@@ -11,0 +11,0 @@ newBankTransaction: function(data, options) { |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
BankTransfer = require('../../entities/accounting/banktransfer'), | ||
BankTransfer = require('../../entities/accounting/banktransfer').BankTransfer, | ||
util = require('util') | ||
@@ -8,3 +8,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'BankTransfer', entityPlural: 'BankTransfers' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'BankTransfers' }, options)); | ||
}, | ||
@@ -11,0 +11,0 @@ newBankTransfer: function(data, options) { |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
BrandingTheme = require('../../entities/accounting/brandingtheme'), | ||
BrandingTheme = require('../../entities/accounting/brandingtheme').BrandingTheme, | ||
util = require('util') | ||
@@ -8,3 +8,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'BrandingTheme', entityPlural: 'BrandingThemes' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'BrandingThemes' }, options)); | ||
}, | ||
@@ -11,0 +11,0 @@ getBrandingThemes: function(options, callback) { |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
Contact = require('../../entities/accounting/contact'), | ||
Contact = require('../../entities/accounting/contact').Contact, | ||
util = require('util') | ||
@@ -8,3 +8,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'Contact', entityPlural: 'Contacts' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'Contacts' }, options)); | ||
}, | ||
@@ -29,3 +29,3 @@ newContact: function(data, options) { | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityPath = 'Contacts.Contact'; | ||
clonedOptions.entityPath = 'Contacts'; | ||
clonedOptions.entityConstructor = function(data) { return self.newContact(data) }; | ||
@@ -32,0 +32,0 @@ return clonedOptions; |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
CreditNote = require('../../entities/accounting/creditnote'), | ||
CreditNote = require('../../entities/accounting/creditnote').CreditNote, | ||
util = require('util') | ||
@@ -8,3 +8,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'CreditNote', entityPlural: 'CreditNotes' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'CreditNotes' }, options)); | ||
}, | ||
@@ -11,0 +11,0 @@ newCreditNote: function(data, options) { |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
Currency = require('../../entities/accounting/currency'), | ||
Currency = require('../../entities/accounting/currency').Currency, | ||
util = require('util') | ||
@@ -8,3 +8,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'Currency', entityPlural: 'Currencies' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'Currencies' }, options)); | ||
}, | ||
@@ -11,0 +11,0 @@ getCurrencies: function(options, callback) { |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
InvoiceReminder = require('../../entities/accounting/invoicereminder'), | ||
InvoiceReminder = require('../../entities/accounting/invoicereminder').InvoiceReminder, | ||
util = require('util') | ||
@@ -8,3 +8,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'InvoiceReminder', entityPlural: 'InvoiceReminders' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'InvoiceReminders' }, options)); | ||
}, | ||
@@ -11,0 +11,0 @@ getInvoiceReminders: function(options, callback) { |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
Invoice = require('../../entities/accounting/invoice'), | ||
Invoice = require('../../entities/accounting/invoice').Invoice, | ||
util = require('util') | ||
@@ -8,3 +8,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'Invoice', entityPlural: 'Invoices' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'Invoices' }, options)); | ||
}, | ||
@@ -24,6 +24,3 @@ newInvoice: function(data, options) { | ||
getInvoices: function(options) { | ||
var self = this; | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityConstructor = function(data) { return self.newInvoice(data) }; | ||
return this.getEntities(clonedOptions) | ||
return this.getEntities(this.setUpOptions(options)) | ||
}, | ||
@@ -36,3 +33,3 @@ saveInvoices: function(invoices, options) { | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityPath = 'Invoices.Invoice'; | ||
clonedOptions.entityPath = 'Invoices'; | ||
clonedOptions.entityConstructor = function(data) { return self.newInvoice(data) }; | ||
@@ -39,0 +36,0 @@ return clonedOptions; |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
Item = require('../../entities/accounting/item'), | ||
Item = require('../../entities/accounting/item').Item, | ||
util = require('util') | ||
@@ -8,3 +8,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'Item', entityPlural: 'Items' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'Items' }, options)); | ||
}, | ||
@@ -38,3 +38,3 @@ newItem: function(data, options) { | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityPath = 'Items.Item'; | ||
clonedOptions.entityPath = 'Items'; | ||
clonedOptions.entityConstructor = function(data) { return self.newItem(data) }; | ||
@@ -41,0 +41,0 @@ return clonedOptions; |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
Journal = require('../../entities/accounting/journal'), | ||
Journal = require('../../entities/accounting/journal').Journal, | ||
util = require('util') | ||
@@ -28,3 +28,3 @@ | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityPath = 'Journals.Journal'; | ||
clonedOptions.entityPath = 'Journals'; | ||
var recordCount | ||
@@ -31,0 +31,0 @@ if (clonedOptions.pager) { |
@@ -9,3 +9,2 @@ var _ = require('lodash'), | ||
EntityHelper.call(this, application, Object.assign({ | ||
entityName: 'ManualJournal', | ||
entityPlural: 'ManualJournals' | ||
@@ -32,3 +31,3 @@ }, options)); | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityPath = 'ManualJournals.ManualJournal'; | ||
clonedOptions.entityPath = 'ManualJournals'; | ||
clonedOptions.entityConstructor = function(data) { | ||
@@ -41,2 +40,2 @@ return self.application.core.manualjournals.newManualJournal(data) | ||
module.exports = ManualJournals; | ||
module.exports = ManualJournals; |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
Organisation = require('../../entities/accounting/organisation'), | ||
Organisation = require('../../entities/accounting/organisation').Organisation, | ||
util = require('util') | ||
@@ -8,3 +8,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'Organisation', entityPlural: 'Organisations' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'Organisations' }, options)); | ||
}, | ||
@@ -11,0 +11,0 @@ getOrganisations: function(options, callback) { |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
Payment = require('../../entities/accounting/payment'), | ||
Payment = require('../../entities/accounting/payment').Payment, | ||
util = require('util') | ||
@@ -8,3 +8,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'Payment', entityPlural: 'Payments' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'Payments' }, options)); | ||
}, | ||
@@ -32,3 +32,3 @@ newPayment: function(data, options) { | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityPath = 'Payments.Payment'; | ||
clonedOptions.entityPath = 'Payments'; | ||
clonedOptions.entityConstructor = function(data) { return self.newPayment(data) }; | ||
@@ -35,0 +35,0 @@ return clonedOptions; |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
Report = require('../../entities/accounting/report'), | ||
Report = require('../../entities/accounting/report').Report, | ||
util = require('util') | ||
@@ -8,3 +8,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'Report', entityPlural: 'Reports' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'Reports' }, options)); | ||
}, | ||
@@ -11,0 +11,0 @@ create: function(data, options) { |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
TaxRate = require('../../entities/accounting/taxrate'), | ||
TaxRate = require('../../entities/accounting/taxrate').TaxRate, | ||
util = require('util') | ||
@@ -8,3 +8,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'TaxRate', entityPlural: 'TaxRates' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'TaxRates' }, options)); | ||
}, | ||
@@ -20,3 +20,3 @@ newTaxRate: function(data, options) { | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityPath = 'TaxRates.TaxRate'; | ||
clonedOptions.entityPath = 'TaxRates'; | ||
clonedOptions.entityConstructor = function(data) { return self.newTaxRate(data) }; | ||
@@ -23,0 +23,0 @@ return clonedOptions; |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
TrackingCategory = require('../../entities/accounting/trackingcategory'), | ||
TrackingOption = require('../../entities/accounting/trackingoption'), | ||
TrackingCategory = require('../../entities/accounting/trackingcategory').TrackingCategory, | ||
TrackingOption = require('../../entities/accounting/trackingoption').TrackingOption, | ||
util = require('util') | ||
@@ -9,3 +9,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'TrackingCategory', entityPlural: 'TrackingCategories' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'TrackingCategories' }, options)); | ||
}, | ||
@@ -27,3 +27,3 @@ newTrackingCategory: function(data, options) { | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityPath = 'TrackingCategories.TrackingCategory'; | ||
clonedOptions.entityPath = 'TrackingCategories'; | ||
clonedOptions.entityConstructor = function(data) { return self.newTrackingCategory(data) }; | ||
@@ -30,0 +30,0 @@ return this.getEntities(clonedOptions); |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
User = require('../../entities/accounting/user'), | ||
User = require('../../entities/accounting/user').User, | ||
util = require('util') | ||
@@ -8,3 +8,3 @@ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'User', entityPlural: 'Users' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'Users' }, options)); | ||
}, | ||
@@ -27,3 +27,3 @@ newUser: function(data, options) { | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityPath = 'Users.User'; | ||
clonedOptions.entityPath = 'Users'; | ||
clonedOptions.entityConstructor = function(data) { return self.newUser(data) }; | ||
@@ -30,0 +30,0 @@ return this.getEntities(clonedOptions) |
@@ -8,3 +8,3 @@ var extend = require('../misc/extend'), | ||
var self = this; | ||
console.log('EntityHelper::constructor'); | ||
this._application = application; | ||
@@ -23,16 +23,17 @@ this._options = options || {}; | ||
saveEntities: function(entities, options) { | ||
console.log('EntityHelper::saveEntities'); | ||
options = options || {}; | ||
if (!_.isArray(entities)) | ||
var payload = {}; | ||
if (!_.isArray(entities)) { | ||
entities = [entities]; | ||
} | ||
var entitiesXml = _.map(entities, function(entity) { | ||
return entity.toXml(); | ||
}).join(''); | ||
payload[this._options.entityPlural] = entities; | ||
var xml = '<' + this._options.entityPlural + '>' + entitiesXml + '</' + this._options.entityPlural + '>'; | ||
return this.application.putOrPostPostEntities(options.method || 'put', this._options.entityPlural, xml, options); | ||
return this.application.putOrPostPostEntities(options.method || 'put', this._options.entityPlural, JSON.stringify(payload), options); | ||
}, | ||
getEntities: function(options) { | ||
console.log('EntityHelper::getEntities'); | ||
var self = this; | ||
@@ -50,6 +51,6 @@ options = options || {}; | ||
if (options.deleteEntity) { | ||
console.log('EntityHelper::getEntities - deleting entities from: ' + path); | ||
return this.application.deleteEntities(path, clonedOptions); | ||
} else { | ||
console.log('EntityHelper::getEntities - retrieving entities from: ' + path); | ||
return this.application.getEntities(path, clonedOptions); | ||
@@ -60,3 +61,3 @@ } | ||
deleteEntities: function(options) { | ||
console.log('EntityHelper::deleteEntities - deleting entities'); | ||
options = options || {}; | ||
@@ -75,2 +76,2 @@ options.deleteEntity = true; | ||
}) | ||
module.exports = EntityHelper; | ||
module.exports = EntityHelper; |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
PayItemsObject = require('../../entities/payroll/payitems'), | ||
EarningsType = require('../../entities/payroll/payitems').EarningsType, | ||
BenefitType = require('../../entities/payroll/payitems').BenefitType, | ||
PayItemsObject = require('../../entities/payroll/payitems').PayItems, | ||
EarningsRate = require('../../entities/payroll/payitems').EarningsRate, | ||
DeductionType = require('../../entities/payroll/payitems').DeductionType, | ||
ReimbursementType = require('../../entities/payroll/payitems').ReimbursementType, | ||
TimeOffType = require('../../entities/payroll/payitems').TimeOffType, | ||
LeaveType = require('../../entities/payroll/payitems').LeaveType, | ||
util = require('util') | ||
@@ -15,3 +14,3 @@ | ||
entityPlural: 'PayItems', | ||
path: 'Payitems' | ||
path: 'PayItems' | ||
}, options)); | ||
@@ -22,17 +21,54 @@ }, | ||
}, | ||
newEarningType: function(data, options) { | ||
return new EarningsType(this.application, data, options) | ||
/*Earnings Rates*/ | ||
newEarningsRate: function(data, options) { | ||
return new EarningsRate(this.application, data, options) | ||
}, | ||
deleteEarningsRate: function(id) { | ||
return deletePayItem(this, 'EarningsRate', id) | ||
}, | ||
getEarningsRate: function(id) { | ||
return findPayItems(this, 'EarningsRate', { payItemID: id }) | ||
}, | ||
getEarningsRates: function(options) { | ||
return findPayItems(this, 'EarningsRate', options) | ||
}, | ||
/*Deduction Types*/ | ||
newDeductionType: function(data, options) { | ||
return new DeductionType(this.application, data, options) | ||
}, | ||
newBenefitType: function(data, options) { | ||
return new BenefitType(this.application, data, options) | ||
deleteDeductionType: function(id) { | ||
return deletePayItem(this, 'DeductionType', id) | ||
}, | ||
getDeductionType: function(id) { | ||
return findPayItems(this, 'DeductionType', { payItemID: id }) | ||
}, | ||
getDeductionTypes: function(options) { | ||
return findPayItems(this, 'DeductionType', options) | ||
}, | ||
/*Reimbursement Types*/ | ||
newReimbursementType: function(data, options) { | ||
return new ReimbursementType(this.application, data, options) | ||
}, | ||
newTimeOffType: function(data, options) { | ||
return new TimeOffType(this.application, data, options) | ||
deleteReimbursementType: function(id) { | ||
return deletePayItem(this, 'ReimbursementType', id) | ||
}, | ||
getReimbursementType: function(id) { | ||
return findPayItems(this, 'ReimbursementType', { payItemID: id }) | ||
}, | ||
getReimbursementTypes: function(options) { | ||
return findPayItems(this, 'ReimbursementType', options) | ||
}, | ||
/*Leave Types*/ | ||
newLeaveType: function(data, options) { | ||
return new LeaveType(this.application, data, options) | ||
}, | ||
deleteLeaveType: function(id) { | ||
return deletePayItem(this, 'LeaveType', id) | ||
}, | ||
getLeaveType: function(id) { | ||
return findPayItems(this, 'LeaveType', { payItemID: id }) | ||
}, | ||
getLeaveTypes: function(options) { | ||
return findPayItems(this, 'LeaveType', options) | ||
}, | ||
getPayItems: function(options) { | ||
@@ -46,2 +82,41 @@ var self = this; | ||
function findPayItems(obj, objType, options) { | ||
options = options || {}; | ||
if (options.id) { | ||
options.payItemID = options.id | ||
delete options.id | ||
} | ||
return obj.getPayItems(options) | ||
.then(function(payItems) { | ||
if (options && options.payItemID) { | ||
let array = payItems[0][`${objType}s`].toArray() | ||
let data = {} | ||
data[`${objType}ID`] = options.payItemID | ||
return _.find(array, data) | ||
} else { | ||
return payItems[0][`${objType}s`] | ||
} | ||
}) | ||
} | ||
function deletePayItem(obj, objType, id) { | ||
var self = obj; | ||
return self[`get${objType}s`]() | ||
.then(function(payItems) { | ||
let array = payItems.toArray(); | ||
let data = {} | ||
data[`${objType}ID`] = id | ||
let found = _.find(array, data) | ||
if (found) { | ||
//Convert the JSON into a PayItem object so it can be deleted. | ||
return self[`new${objType}`](found).delete() | ||
} else { | ||
return Promise.reject('ID not found.') | ||
} | ||
}) | ||
} | ||
module.exports = PayItems; |
var _ = require('lodash'), | ||
EntityHelper = require('../entity_helper'), | ||
Timesheet = require('../../entities/payroll/timesheet'), | ||
Timesheet = require('../../entities/payroll/timesheet').Timesheet, | ||
util = require('util') | ||
@@ -5,0 +5,0 @@ |
@@ -1,89 +0,36 @@ | ||
var _ = require('lodash') | ||
'use strict'; | ||
const _ = require('lodash'); | ||
/* Courtesy Backbone.extend */ | ||
module.exports = function (protoProps, staticProps) | ||
{ | ||
var ctor = function () { }, inherits = function (parent, protoProps, staticProps) | ||
{ | ||
var child, _super = parent.prototype, fnTest = /xyz/.test(function () { xyz; }) ? /\b_super\b/ : /.*/; | ||
const extend = function(protoProps, staticProps) { | ||
const parent = this; | ||
let child; | ||
// The constructor function for the new subclass is either defined by you | ||
// (the "constructor" property in your `extend` definition), or defaulted | ||
// by us to simply call the parent's constructor. | ||
if (protoProps && protoProps.hasOwnProperty('constructor')) | ||
{ | ||
child = protoProps.constructor; | ||
} else | ||
{ | ||
child = function () { parent.apply(this, arguments); }; | ||
} | ||
// The constructor function for the new subclass is either defined by you | ||
// (the "constructor" property in your `extend` definition), or defaulted | ||
// by us to simply call the parent constructor. | ||
if (protoProps && _.has(protoProps, 'constructor')) { | ||
child = protoProps.constructor; | ||
} else { | ||
child = function() { | ||
return parent.apply(this, arguments); | ||
}; | ||
} | ||
// Inherit class (static) properties from parent. | ||
Object.assign(child, parent); | ||
// Add static properties to the constructor function, if supplied. | ||
_.extend(child, parent, staticProps); | ||
// Set the prototype chain to inherit from `parent`, without calling | ||
// `parent`'s constructor function. | ||
ctor.prototype = parent.prototype; | ||
child.prototype = new ctor(); | ||
// Set the prototype chain to inherit from `parent`, without calling | ||
// `parent`'s constructor function and add the prototype properties. | ||
child.prototype = _.create(parent.prototype, protoProps); | ||
child.prototype.constructor = child; | ||
// Add prototype properties (instance properties) to the subclass, | ||
// if supplied. | ||
if (protoProps) | ||
{ | ||
Object.assign(child.prototype, protoProps); | ||
// Set a convenience property in case the parent's prototype is needed | ||
// later. | ||
child.__super__ = parent.prototype; | ||
// Copy the properties over onto the new prototype | ||
for (var name in protoProps) | ||
{ | ||
// Check if we're overwriting an existing function | ||
if (typeof protoProps[name] == "function" && typeof _super[name] == "function" && fnTest.test(protoProps[name])) | ||
{ | ||
child.prototype[name] = (function (name, fn) | ||
{ | ||
var wrapper = function () | ||
{ | ||
var tmp = this._super; | ||
return child; | ||
}; | ||
// Add a new ._super() method that is the same method | ||
// but on the super-class | ||
this._super = _super[name]; | ||
// The method only need to be bound temporarily, so we | ||
// remove it when we're done executing | ||
var ret; | ||
try | ||
{ | ||
ret = fn.apply(this, arguments); | ||
} finally | ||
{ | ||
this._super = tmp; | ||
} | ||
return ret; | ||
}; | ||
//we must move properties from old function to new | ||
for (var prop in fn) | ||
{ | ||
wrapper[prop] = fn[prop]; | ||
delete fn[prop]; | ||
} | ||
return wrapper; | ||
})(name, protoProps[name]); | ||
} | ||
} | ||
} | ||
// Add static properties to the constructor function, if supplied. | ||
if (staticProps) Object.assign(child, staticProps); | ||
// Correctly set child's `prototype.constructor`. | ||
child.prototype.constructor = child; | ||
// Set a convenience property in case the parent's prototype is needed later. | ||
child.__super__ = parent.prototype; | ||
return child; | ||
}; | ||
return inherits(this, protoProps, staticProps); | ||
} | ||
module.exports = extend; |
@@ -33,3 +33,3 @@ var crypto = require('crypto'), | ||
this._headers = { | ||
"Accept": "*/*", | ||
"Accept": "application/json", | ||
"Connection": "close", | ||
@@ -208,3 +208,3 @@ }; | ||
url = url.split("runscope.net")[1].replace(/^/, "https://api.xero.com"); | ||
console.log("validation " + url); | ||
} catch (e) { | ||
@@ -518,5 +518,3 @@ //do nothing. This error only occurs if runscope isn't in the url. | ||
if (typeof post_body != "string" && !isReadableStream(post_body)) { | ||
post_content_type = "application/x-www-form-urlencoded" | ||
extra_params = post_body; | ||
post_body = null; | ||
post_content_type = "application/json" | ||
} | ||
@@ -609,2 +607,2 @@ | ||
return test instanceof EventEmitter && typeof test.read === 'function'; | ||
} | ||
} |
@@ -14,4 +14,4 @@ /* | ||
*/ | ||
var hexcase = 1; /* hex output format. 0 - lowercase; 1 - uppercase */ | ||
var b64pad = "="; /* base-64 pad character. "=" for strict RFC compliance */ | ||
var hexcase = 1; /* hex output format. 0 - lowercase; 1 - uppercase */ | ||
var b64pad = "="; /* base-64 pad character. "=" for strict RFC compliance */ | ||
@@ -22,18 +22,19 @@ /* | ||
*/ | ||
function hex_sha1(s) { return rstr2hex(rstr_sha1(str2rstr_utf8(s))); } | ||
function b64_sha1(s) { return rstr2b64(rstr_sha1(str2rstr_utf8(s))); } | ||
function hex_sha1(s) { return rstr2hex(rstr_sha1(str2rstr_utf8(s))); } | ||
function b64_sha1(s) { return rstr2b64(rstr_sha1(str2rstr_utf8(s))); } | ||
function any_sha1(s, e) { return rstr2any(rstr_sha1(str2rstr_utf8(s)), e); } | ||
function hex_hmac_sha1(k, d) | ||
{ return rstr2hex(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); } | ||
function b64_hmac_sha1(k, d) | ||
{ return rstr2b64(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); } | ||
function any_hmac_sha1(k, d, e) | ||
{ return rstr2any(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d)), e); } | ||
function hex_hmac_sha1(k, d) { return rstr2hex(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); } | ||
function b64_hmac_sha1(k, d) { return rstr2b64(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); } | ||
function any_hmac_sha1(k, d, e) { return rstr2any(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d)), e); } | ||
/* | ||
* Perform a simple self-test to see if the VM is working | ||
*/ | ||
function sha1_vm_test() | ||
{ | ||
return hex_sha1("abc").toLowerCase() == "a9993e364706816aba3e25717850c26c9cd0d89d"; | ||
function sha1_vm_test() { | ||
return hex_sha1("abc").toLowerCase() == "a9993e364706816aba3e25717850c26c9cd0d89d"; | ||
} | ||
@@ -44,5 +45,4 @@ | ||
*/ | ||
function rstr_sha1(s) | ||
{ | ||
return binb2rstr(binb_sha1(rstr2binb(s), s.length * 8)); | ||
function rstr_sha1(s) { | ||
return binb2rstr(binb_sha1(rstr2binb(s), s.length * 8)); | ||
} | ||
@@ -53,16 +53,15 @@ | ||
*/ | ||
function rstr_hmac_sha1(key, data) | ||
{ | ||
var bkey = rstr2binb(key); | ||
if(bkey.length > 16) bkey = binb_sha1(bkey, key.length * 8); | ||
function rstr_hmac_sha1(key, data) { | ||
var bkey = rstr2binb(key); | ||
if (bkey.length > 16) bkey = binb_sha1(bkey, key.length * 8); | ||
var ipad = Array(16), opad = Array(16); | ||
for(var i = 0; i < 16; i++) | ||
{ | ||
ipad[i] = bkey[i] ^ 0x36363636; | ||
opad[i] = bkey[i] ^ 0x5C5C5C5C; | ||
} | ||
var ipad = Array(16), | ||
opad = Array(16); | ||
for (var i = 0; i < 16; i++) { | ||
ipad[i] = bkey[i] ^ 0x36363636; | ||
opad[i] = bkey[i] ^ 0x5C5C5C5C; | ||
} | ||
var hash = binb_sha1(ipad.concat(rstr2binb(data)), 512 + data.length * 8); | ||
return binb2rstr(binb_sha1(opad.concat(hash), 512 + 160)); | ||
var hash = binb_sha1(ipad.concat(rstr2binb(data)), 512 + data.length * 8); | ||
return binb2rstr(binb_sha1(opad.concat(hash), 512 + 160)); | ||
} | ||
@@ -73,15 +72,13 @@ | ||
*/ | ||
function rstr2hex(input) | ||
{ | ||
try { hexcase } catch(e) { hexcase=0; } | ||
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; | ||
var output = ""; | ||
var x; | ||
for(var i = 0; i < input.length; i++) | ||
{ | ||
x = input.charCodeAt(i); | ||
output += hex_tab.charAt((x >>> 4) & 0x0F) | ||
+ hex_tab.charAt( x & 0x0F); | ||
} | ||
return output; | ||
function rstr2hex(input) { | ||
try { hexcase } catch (e) { hexcase = 0; } | ||
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; | ||
var output = ""; | ||
var x; | ||
for (var i = 0; i < input.length; i++) { | ||
x = input.charCodeAt(i); | ||
output += hex_tab.charAt((x >>> 4) & 0x0F) + | ||
hex_tab.charAt(x & 0x0F); | ||
} | ||
return output; | ||
} | ||
@@ -92,20 +89,17 @@ | ||
*/ | ||
function rstr2b64(input) | ||
{ | ||
try { b64pad } catch(e) { b64pad=''; } | ||
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
var output = ""; | ||
var len = input.length; | ||
for(var i = 0; i < len; i += 3) | ||
{ | ||
var triplet = (input.charCodeAt(i) << 16) | ||
| (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0) | ||
| (i + 2 < len ? input.charCodeAt(i+2) : 0); | ||
for(var j = 0; j < 4; j++) | ||
{ | ||
if(i * 8 + j * 6 > input.length * 8) output += b64pad; | ||
else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F); | ||
function rstr2b64(input) { | ||
try { b64pad } catch (e) { b64pad = ''; } | ||
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
var output = ""; | ||
var len = input.length; | ||
for (var i = 0; i < len; i += 3) { | ||
var triplet = (input.charCodeAt(i) << 16) | | ||
(i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0) | | ||
(i + 2 < len ? input.charCodeAt(i + 2) : 0); | ||
for (var j = 0; j < 4; j++) { | ||
if (i * 8 + j * 6 > input.length * 8) output += b64pad; | ||
else output += tab.charAt((triplet >>> 6 * (3 - j)) & 0x3F); | ||
} | ||
} | ||
} | ||
return output; | ||
return output; | ||
} | ||
@@ -116,49 +110,45 @@ | ||
*/ | ||
function rstr2any(input, encoding) | ||
{ | ||
var divisor = encoding.length; | ||
var remainders = Array(); | ||
var i, q, x, quotient; | ||
function rstr2any(input, encoding) { | ||
var divisor = encoding.length; | ||
var remainders = Array(); | ||
var i, q, x, quotient; | ||
/* Convert to an array of 16-bit big-endian values, forming the dividend */ | ||
var dividend = Array(Math.ceil(input.length / 2)); | ||
for(i = 0; i < dividend.length; i++) | ||
{ | ||
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1); | ||
} | ||
/* Convert to an array of 16-bit big-endian values, forming the dividend */ | ||
var dividend = Array(Math.ceil(input.length / 2)); | ||
for (i = 0; i < dividend.length; i++) { | ||
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1); | ||
} | ||
/* | ||
* Repeatedly perform a long division. The binary array forms the dividend, | ||
* the length of the encoding is the divisor. Once computed, the quotient | ||
* forms the dividend for the next step. We stop when the dividend is zero. | ||
* All remainders are stored for later use. | ||
*/ | ||
while(dividend.length > 0) | ||
{ | ||
quotient = Array(); | ||
x = 0; | ||
for(i = 0; i < dividend.length; i++) | ||
{ | ||
x = (x << 16) + dividend[i]; | ||
q = Math.floor(x / divisor); | ||
x -= q * divisor; | ||
if(quotient.length > 0 || q > 0) | ||
quotient[quotient.length] = q; | ||
/* | ||
* Repeatedly perform a long division. The binary array forms the dividend, | ||
* the length of the encoding is the divisor. Once computed, the quotient | ||
* forms the dividend for the next step. We stop when the dividend is zero. | ||
* All remainders are stored for later use. | ||
*/ | ||
while (dividend.length > 0) { | ||
quotient = Array(); | ||
x = 0; | ||
for (i = 0; i < dividend.length; i++) { | ||
x = (x << 16) + dividend[i]; | ||
q = Math.floor(x / divisor); | ||
x -= q * divisor; | ||
if (quotient.length > 0 || q > 0) | ||
quotient[quotient.length] = q; | ||
} | ||
remainders[remainders.length] = x; | ||
dividend = quotient; | ||
} | ||
remainders[remainders.length] = x; | ||
dividend = quotient; | ||
} | ||
/* Convert the remainders to the output string */ | ||
var output = ""; | ||
for(i = remainders.length - 1; i >= 0; i--) | ||
output += encoding.charAt(remainders[i]); | ||
/* Convert the remainders to the output string */ | ||
var output = ""; | ||
for (i = remainders.length - 1; i >= 0; i--) | ||
output += encoding.charAt(remainders[i]); | ||
/* Append leading zero equivalents */ | ||
var full_length = Math.ceil(input.length * 8 / | ||
(Math.log(encoding.length) / Math.log(2))) | ||
for(i = output.length; i < full_length; i++) | ||
output = encoding[0] + output; | ||
/* Append leading zero equivalents */ | ||
var full_length = Math.ceil(input.length * 8 / | ||
(Math.log(encoding.length) / Math.log(2))) | ||
for (i = output.length; i < full_length; i++) | ||
output = encoding[0] + output; | ||
return output; | ||
return output; | ||
} | ||
@@ -170,36 +160,33 @@ | ||
*/ | ||
function str2rstr_utf8(input) | ||
{ | ||
var output = ""; | ||
var i = -1; | ||
var x, y; | ||
function str2rstr_utf8(input) { | ||
var output = ""; | ||
var i = -1; | ||
var x, y; | ||
while(++i < input.length) | ||
{ | ||
/* Decode utf-16 surrogate pairs */ | ||
x = input.charCodeAt(i); | ||
y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0; | ||
if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) | ||
{ | ||
x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF); | ||
i++; | ||
while (++i < input.length) { | ||
/* Decode utf-16 surrogate pairs */ | ||
x = input.charCodeAt(i); | ||
y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0; | ||
if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) { | ||
x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF); | ||
i++; | ||
} | ||
/* Encode output as utf-8 */ | ||
if (x <= 0x7F) | ||
output += String.fromCharCode(x); | ||
else if (x <= 0x7FF) | ||
output += String.fromCharCode(0xC0 | ((x >>> 6) & 0x1F), | ||
0x80 | (x & 0x3F)); | ||
else if (x <= 0xFFFF) | ||
output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), | ||
0x80 | ((x >>> 6) & 0x3F), | ||
0x80 | (x & 0x3F)); | ||
else if (x <= 0x1FFFFF) | ||
output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), | ||
0x80 | ((x >>> 12) & 0x3F), | ||
0x80 | ((x >>> 6) & 0x3F), | ||
0x80 | (x & 0x3F)); | ||
} | ||
/* Encode output as utf-8 */ | ||
if(x <= 0x7F) | ||
output += String.fromCharCode(x); | ||
else if(x <= 0x7FF) | ||
output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F), | ||
0x80 | ( x & 0x3F)); | ||
else if(x <= 0xFFFF) | ||
output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), | ||
0x80 | ((x >>> 6 ) & 0x3F), | ||
0x80 | ( x & 0x3F)); | ||
else if(x <= 0x1FFFFF) | ||
output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), | ||
0x80 | ((x >>> 12) & 0x3F), | ||
0x80 | ((x >>> 6 ) & 0x3F), | ||
0x80 | ( x & 0x3F)); | ||
} | ||
return output; | ||
return output; | ||
} | ||
@@ -210,18 +197,16 @@ | ||
*/ | ||
function str2rstr_utf16le(input) | ||
{ | ||
var output = ""; | ||
for(var i = 0; i < input.length; i++) | ||
output += String.fromCharCode( input.charCodeAt(i) & 0xFF, | ||
(input.charCodeAt(i) >>> 8) & 0xFF); | ||
return output; | ||
function str2rstr_utf16le(input) { | ||
var output = ""; | ||
for (var i = 0; i < input.length; i++) | ||
output += String.fromCharCode(input.charCodeAt(i) & 0xFF, | ||
(input.charCodeAt(i) >>> 8) & 0xFF); | ||
return output; | ||
} | ||
function str2rstr_utf16be(input) | ||
{ | ||
var output = ""; | ||
for(var i = 0; i < input.length; i++) | ||
output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, | ||
input.charCodeAt(i) & 0xFF); | ||
return output; | ||
function str2rstr_utf16be(input) { | ||
var output = ""; | ||
for (var i = 0; i < input.length; i++) | ||
output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, | ||
input.charCodeAt(i) & 0xFF); | ||
return output; | ||
} | ||
@@ -233,10 +218,9 @@ | ||
*/ | ||
function rstr2binb(input) | ||
{ | ||
var output = Array(input.length >> 2); | ||
for(var i = 0; i < output.length; i++) | ||
output[i] = 0; | ||
for(var i = 0; i < input.length * 8; i += 8) | ||
output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32); | ||
return output; | ||
function rstr2binb(input) { | ||
var output = Array(input.length >> 2); | ||
for (var i = 0; i < output.length; i++) | ||
output[i] = 0; | ||
for (var i = 0; i < input.length * 8; i += 8) | ||
output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32); | ||
return output; | ||
} | ||
@@ -247,8 +231,7 @@ | ||
*/ | ||
function binb2rstr(input) | ||
{ | ||
var output = ""; | ||
for(var i = 0; i < input.length * 32; i += 8) | ||
output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF); | ||
return output; | ||
function binb2rstr(input) { | ||
var output = ""; | ||
for (var i = 0; i < input.length * 32; i += 8) | ||
output += String.fromCharCode((input[i >> 5] >>> (24 - i % 32)) & 0xFF); | ||
return output; | ||
} | ||
@@ -259,44 +242,41 @@ | ||
*/ | ||
function binb_sha1(x, len) | ||
{ | ||
/* append padding */ | ||
x[len >> 5] |= 0x80 << (24 - len % 32); | ||
x[((len + 64 >> 9) << 4) + 15] = len; | ||
function binb_sha1(x, len) { | ||
/* append padding */ | ||
x[len >> 5] |= 0x80 << (24 - len % 32); | ||
x[((len + 64 >> 9) << 4) + 15] = len; | ||
var w = Array(80); | ||
var a = 1732584193; | ||
var b = -271733879; | ||
var c = -1732584194; | ||
var d = 271733878; | ||
var e = -1009589776; | ||
var w = Array(80); | ||
var a = 1732584193; | ||
var b = -271733879; | ||
var c = -1732584194; | ||
var d = 271733878; | ||
var e = -1009589776; | ||
for(var i = 0; i < x.length; i += 16) | ||
{ | ||
var olda = a; | ||
var oldb = b; | ||
var oldc = c; | ||
var oldd = d; | ||
var olde = e; | ||
for (var i = 0; i < x.length; i += 16) { | ||
var olda = a; | ||
var oldb = b; | ||
var oldc = c; | ||
var oldd = d; | ||
var olde = e; | ||
for(var j = 0; j < 80; j++) | ||
{ | ||
if(j < 16) w[j] = x[i + j]; | ||
else w[j] = bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1); | ||
var t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)), | ||
safe_add(safe_add(e, w[j]), sha1_kt(j))); | ||
e = d; | ||
d = c; | ||
c = bit_rol(b, 30); | ||
b = a; | ||
a = t; | ||
for (var j = 0; j < 80; j++) { | ||
if (j < 16) w[j] = x[i + j]; | ||
else w[j] = bit_rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1); | ||
var t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)), | ||
safe_add(safe_add(e, w[j]), sha1_kt(j))); | ||
e = d; | ||
d = c; | ||
c = bit_rol(b, 30); | ||
b = a; | ||
a = t; | ||
} | ||
a = safe_add(a, olda); | ||
b = safe_add(b, oldb); | ||
c = safe_add(c, oldc); | ||
d = safe_add(d, oldd); | ||
e = safe_add(e, olde); | ||
} | ||
return Array(a, b, c, d, e); | ||
a = safe_add(a, olda); | ||
b = safe_add(b, oldb); | ||
c = safe_add(c, oldc); | ||
d = safe_add(d, oldd); | ||
e = safe_add(e, olde); | ||
} | ||
return Array(a, b, c, d, e); | ||
} | ||
@@ -308,8 +288,7 @@ | ||
*/ | ||
function sha1_ft(t, b, c, d) | ||
{ | ||
if(t < 20) return (b & c) | ((~b) & d); | ||
if(t < 40) return b ^ c ^ d; | ||
if(t < 60) return (b & c) | (b & d) | (c & d); | ||
return b ^ c ^ d; | ||
function sha1_ft(t, b, c, d) { | ||
if (t < 20) return (b & c) | ((~b) & d); | ||
if (t < 40) return b ^ c ^ d; | ||
if (t < 60) return (b & c) | (b & d) | (c & d); | ||
return b ^ c ^ d; | ||
} | ||
@@ -320,6 +299,5 @@ | ||
*/ | ||
function sha1_kt(t) | ||
{ | ||
return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 : | ||
(t < 60) ? -1894007588 : -899497514; | ||
function sha1_kt(t) { | ||
return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 : | ||
(t < 60) ? -1894007588 : -899497514; | ||
} | ||
@@ -331,7 +309,6 @@ | ||
*/ | ||
function safe_add(x, y) | ||
{ | ||
var lsw = (x & 0xFFFF) + (y & 0xFFFF); | ||
var msw = (x >> 16) + (y >> 16) + (lsw >> 16); | ||
return (msw << 16) | (lsw & 0xFFFF); | ||
function safe_add(x, y) { | ||
var lsw = (x & 0xFFFF) + (y & 0xFFFF); | ||
var msw = (x >> 16) + (y >> 16) + (lsw >> 16); | ||
return (msw << 16) | (lsw & 0xFFFF); | ||
} | ||
@@ -342,9 +319,8 @@ | ||
*/ | ||
function bit_rol(num, cnt) | ||
{ | ||
return (num << cnt) | (num >>> (32 - cnt)); | ||
function bit_rol(num, cnt) { | ||
return (num << cnt) | (num >>> (32 - cnt)); | ||
} | ||
exports.HMACSHA1= function(key, data) { | ||
return b64_hmac_sha1(key, data); | ||
exports.HMACSHA1 = function(key, data) { | ||
return b64_hmac_sha1(key, data); | ||
} |
@@ -6,3 +6,3 @@ var _ = require('lodash') | ||
payitems: { file: 'payitems' }, | ||
employees: { file: 'payroll_employees' } | ||
employees: { file: 'employees' } | ||
}; | ||
@@ -12,3 +12,3 @@ | ||
var self = this; | ||
console.log('Payroll::constructor'); | ||
this._application = application; | ||
@@ -15,0 +15,0 @@ |
@@ -196,3 +196,11 @@ var _ = require('lodash'); | ||
if (_.isString(value)) { | ||
value = Date.parse(value); | ||
var parsed = Date.parse(value); | ||
if (!parsed) { | ||
//Try to convert from the Xero JSON Response e.g. /Date(1494671492303+0000)/ | ||
let d = value.substr(1).slice(0, -1); //remove the first and last character e.g. the slashes | ||
parsed = eval(`new ${d}`) | ||
} | ||
value = parsed; | ||
} | ||
@@ -278,3 +286,3 @@ | ||
} else if (_.isObject(properties.type) && _.size(properties.type)) { | ||
properties.objectType = new SchemaObject(properties.type); | ||
properties.objectType = SchemaObject(properties.type); | ||
properties.type = 'object'; | ||
@@ -293,2 +301,23 @@ } | ||
this.toArray = function(options) { | ||
// Create new Array to hold elements. | ||
var array = []; | ||
// Loop through each element, clone if necessary. | ||
_.each(this, function(element) { | ||
// Call toObject() method if defined (this allows us to return primitive objects instead of SchemaObjects). | ||
if (_.isObject(element) && _.isFunction(element.toObject)) { | ||
element = element.toObject(options); | ||
// If is nonSchemaType object, shallow clone so that properties modification don't have an affect on the original object. | ||
} else if (_.isObject(element)) { | ||
element = _.clone(element); | ||
} | ||
array.push(element); | ||
}); | ||
return array; | ||
} | ||
if (this._properties.arrayType) { | ||
@@ -319,23 +348,3 @@ this._properties.arrayType = normalizeProperties(this._properties.arrayType); | ||
}; | ||
SchemaArray.prototype.toArray = function(options) { | ||
// Create new Array to hold elements. | ||
var array = []; | ||
// Loop through each element, clone if necessary. | ||
_.each(this, function(element) { | ||
// Call toObject() method if defined (this allows us to return primitive objects instead of SchemaObjects). | ||
if (_.isObject(element) && _.isFunction(element.toObject)) { | ||
element = element.toObject(options); | ||
// If is non-SchemaType object, shallow clone so that properties modification don't have an affect on the original object. | ||
} else if (_.isObject(element)) { | ||
element = _.clone(element); | ||
} | ||
array.push(element); | ||
}); | ||
return array; | ||
}; | ||
// Represents an object with typed indexes. | ||
@@ -354,5 +363,7 @@ var SchemaObject = function(schema) { | ||
// Define getters/setters based off of schema. | ||
_.each(schema, function(properties, index) { | ||
if (!properties) { | ||
throw new Error("properties not defined") | ||
} | ||
// Normalize properties to allow for various shorthand declarations. | ||
@@ -454,3 +465,3 @@ schema[index] = properties = normalizeProperties(properties); | ||
case 'oneOf': | ||
if (!_.contains(settings, value)) | ||
if (!_.includes(settings, value)) | ||
addError({ path: makePath(index), type: 'oneOf', error: 'Not one of the allowed values' }); | ||
@@ -481,4 +492,2 @@ break; | ||
} | ||
} | ||
@@ -550,3 +559,3 @@ | ||
// Built in method to clone array to native type | ||
getObj[index] = value.toArray(); | ||
getObj[index] = value.toArray(options); | ||
if (_.isEmpty(getObj[index])) | ||
@@ -605,3 +614,2 @@ delete getObj[index]; | ||
init = false; | ||
return self; | ||
} | ||
@@ -608,0 +616,0 @@ }; |
{ | ||
"name": "xero-node", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "Xero API Wrapper for all application types", | ||
@@ -14,3 +14,3 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"test": "yarn && nyc mocha --recursive" | ||
"test": "yarn && nyc mocha" | ||
}, | ||
@@ -25,8 +25,7 @@ "keywords": [ | ||
"follow-redirects": "^1.2.3", | ||
"lodash": "^4.17.4", | ||
"uuid": "^3.0.1", | ||
"xml2js": "^0.4.17" | ||
"lodash": "^4.17.4" | ||
}, | ||
"readmeFilename": "README.md", | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"eslint": "^4.3.0", | ||
@@ -42,5 +41,5 @@ "eslint-config-airbnb-base": "^11.3.1", | ||
"prettier": "^1.5.3", | ||
"chai": "^3.5.0", | ||
"sinon": "^1.17.7", | ||
"zombie": "^5.0.5" | ||
"zombie": "^5.0.5", | ||
"uuid": "^3.0.1" | ||
}, | ||
@@ -47,0 +46,0 @@ "engines": { |
@@ -206,2 +206,4 @@ xero-node (alpha) | ||
- [x] Remove log4js | ||
- [x] Remove xml2js dependency | ||
- [x] Remove console.log | ||
- [ ] Throw exceptions with good messaging | ||
@@ -214,2 +216,8 @@ - [ ] Remove lodash | ||
* 2.5.0 | ||
- Merged [PR#65](https://github.com/XeroAPI/xero-node/pull/65) - Removed xml2js and instead use only application/json as a content-type. | ||
- Refactored e2e tests to be modular and easier to maintain | ||
- Fixed various linting and code styling issues | ||
- Updated extend.js to latest version of Backbone | ||
- Updated Date variables in all schemas to be Date Objects instead of strings. | ||
* 2.4.0 | ||
@@ -216,0 +224,0 @@ - Merged [PR#64](https://github.com/XeroAPI/xero-node/pull/64) - Updated accountingtests.js to pass ESlint rules. |
@@ -9,3 +9,4 @@ { | ||
"xeroPassword": "XXXXXXXXXX", | ||
"xeroUsername": "foo@example.com" | ||
"xeroUsername": "foo@example.com", | ||
"selectedAppId" : "some-app-id" | ||
}, | ||
@@ -24,4 +25,5 @@ "private": { | ||
"xeroPassword": "XXXXXXXXXX", | ||
"xeroUsername": "foo@example.com" | ||
"xeroUsername": "foo@example.com", | ||
"selectedAppId" : "some-app-id" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 8 instances in 1 package
566641
2
125
8554
429
5
14
4
- Removeduuid@^3.0.1
- Removedxml2js@^0.4.17
- Removedsax@1.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedxml2js@0.4.23(transitive)
- Removedxmlbuilder@11.0.1(transitive)