Skip to content

Commit

Permalink
refactored directories to clean up the structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Walsh committed Mar 14, 2017
1 parent 71c2f6e commit 3edb1d0
Show file tree
Hide file tree
Showing 40 changed files with 325 additions and 525 deletions.
2 changes: 1 addition & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Core(application, options) {
this._application = application;

_.each(HELPERS, function(entityHelper, id) {
var instance = new(require('./entity_helpers/' + entityHelper.file))(application);
var instance = new(require('./entity_helpers/accounting/' + entityHelper.file))(application);
Object.defineProperty(self, id, {
get: function() { return instance }
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger')
Entity = require('../entity'),
logger = require('../../logger')

var AccountSchema = new Entity.SchemaObject({
Code: { type: String, toObject: 'always' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger'),
Entity = require('../entity'),
logger = require('../../logger'),
dateformat = require('dateformat'),
fs = require('fs')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger'),
Entity = require('../entity'),
logger = require('../../logger'),
ContactSchema = require('./contact').ContactSchema,
Contact = require('./contact'),
LineItemSchema = require('./shared').LineItemSchema
LineItemSchema = require('../shared').LineItemSchema

var BankTransactionSchema = new Entity.SchemaObject({
Type: { type: String, toObject: 'always' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger'),
Entity = require('../entity'),
logger = require('../../logger'),
ContactSchema = require('./contact').ContactSchema,
Contact = require('./contact'),
LineItemSchema = require('./shared').LineItemSchema
LineItemSchema = require('../shared').LineItemSchema

var BankTransferSchema = new Entity.SchemaObject({
FromBankAccount: {
Expand Down
12 changes: 6 additions & 6 deletions lib/entities/contact.js → lib/entities/accounting/contact.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger'),
AddressSchema = require('./shared').AddressSchema,
PhoneSchema = require('./shared').PhoneSchema,
ContactPersonSchema = require('./shared').ContactPerson,
PaymentTermSchema = require('./shared').PaymentTermSchema,
Entity = require('../entity'),
logger = require('../../logger'),
AddressSchema = require('../shared').AddressSchema,
PhoneSchema = require('../shared').PhoneSchema,
ContactPersonSchema = require('../shared').ContactPerson,
PaymentTermSchema = require('../shared').PaymentTermSchema,
dateformat = require('dateformat')

var BatchPaymentSchema = new Entity.SchemaObject({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger'),
Entity = require('../entity'),
logger = require('../../logger'),
ContactSchema = require('./contact').ContactSchema,
Contact = require('./contact'),
PaymentSchema = require('./shared').PaymentSchema
PaymentSchema = require('../shared').PaymentSchema

var TrackingCategoryOptionsSchema = new Entity.SchemaObject({
TrackingCategoryID: { type: String, toObject: 'hasValue' },
Expand Down
4 changes: 2 additions & 2 deletions lib/entities/item.js → lib/entities/accounting/item.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger')
Entity = require('../entity'),
logger = require('../../logger');

var ItemDetailSchema = new Entity.SchemaObject({
UnitPrice: { type: Number, toObject: 'hasValue' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger')
Entity = require('../entity'),
logger = require('../../logger');

var TrackingCategorySchema = new Entity.SchemaObject({
TrackingCategoryID: { type: String },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger'),
AddressSchema = require('./shared').AddressSchema,
PhoneSchema = require('./shared').PhoneSchema,
ExternalLinkSchema = require('./shared').ExternalLinkSchema,
PaymentTermSchema = require('./shared').PaymentTermSchema
Entity = require('../entity'),
logger = require('../../logger'),
AddressSchema = require('../shared').AddressSchema,
PhoneSchema = require('../shared').PhoneSchema,
ExternalLinkSchema = require('../shared').ExternalLinkSchema,
PaymentTermSchema = require('../shared').PaymentTermSchema

var OrganisationSchema = new Entity.SchemaObject({
APIKey: { type: String },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger'),
PaymentSchema = require('./shared').PaymentSchema
Entity = require('../entity'),
logger = require('../../logger'),
PaymentSchema = require('../shared').PaymentSchema

var Payment = Entity.extend(PaymentSchema, {
constructor: function(application, data, options) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger');
Entity = require('../entity'),
logger = require('../../logger');

var TaxRateSchema = new Entity.SchemaObject({
Name: { type: String, toObject: 'always' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger'),
TrackingOptionSchema = require('./shared').TrackingOptionSchema;
Entity = require('../entity'),
logger = require('../../logger'),
TrackingOptionSchema = require('../shared').TrackingOptionSchema;

var TrackingCategorySchema = new Entity.SchemaObject({
TrackingCategoryID: { type: String, toObject: 'always' },
Expand Down
53 changes: 53 additions & 0 deletions lib/entities/accounting/trackingoption.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var _ = require('lodash'),
Entity = require('../entity'),
logger = require('../../logger'),
dateformat = require('dateformat'),
fs = require('fs')

var AttachmentSchema = new Entity.SchemaObject({
AttachmentID: { type: String, toObject: 'never' },
FileName: { type: String, toObject: 'always' },
Url: { type: String, toObject: 'always' },
MimeType: { type: String, toObject: 'always' },
ContentLength: { type: Number, toObject: 'always' }
});


var Attachment = Entity.extend(AttachmentSchema, {
constructor: function(application, data, options) {
logger.debug('Attachment::constructor');
this.Entity.apply(this, arguments);
},
initialize: function(data, options) {},
getContent: function(ownerPath) {
return this.application.core.attachments.getContent(ownerPath, this.FileName);
},
save: function(ownerPath, streamOrFilePath) {
var self = this;
var path = ownerPath + '/Attachments/' + this.FileName;

var base64string = base64_encode(streamOrFilePath);
console.log(base64string);
console.log(path);

return this.application.postEntity(path, base64string, { type: this.MimeType })
.then(function(ret) {
console.log(ret);
return ret.response.Attachments.Attachment;
})
.catch(function(err) {
console.log(err);
})

function base64_encode(file) {
// read binary data
var bitmap = fs.readFileSync(file);
// convert binary data to base64 encoded string
return new Buffer(bitmap).toString('base64');
}
}
});


module.exports = Attachment;
module.exports.AttachmentSchema = AttachmentSchema;
4 changes: 2 additions & 2 deletions lib/entities/user.js → lib/entities/accounting/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger')
Entity = require('../entity'),
logger = require('../../logger');

var UserSchema = new Entity.SchemaObject({
UserID: {
Expand Down
4 changes: 2 additions & 2 deletions lib/entities/payitems.js → lib/entities/payroll/payitems.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger')
Entity = require('../entity'),
logger = require('../../logger')

var EarningTypeSchema = new Entity.SchemaObject({
EarningsType: { type: String },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger'),
ExternalLinkSchema = require('./shared').ExternalLinkSchema
Entity = require('../entity'),
logger = require('../../logger'),
ExternalLinkSchema = require('../shared').ExternalLinkSchema

var AddressSchema = new Entity.SchemaObject({
StreetAddress: { type: String },
Expand Down
85 changes: 85 additions & 0 deletions lib/entities/payroll/timesheet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
var _ = require('lodash'),
Entity = require('../entity'),
logger = require('../../logger')


var TimesheetLineSchema = new Entity.SchemaObject({
EarningsTypeID: { type: String },
TrackingItemID: { type: String },
NumberOfUnits: { type: Array, arrayType: Number, toObject: 'always' }
});

var TimesheetSchema = new Entity.SchemaObject({
EmployeeID: { type: String, toObject: 'hasValue' },
StartDate: { type: Date, toObjectTransform: Entity.dateToString, toObject: 'hasValue' },
EndDate: { type: Date, toObjectTransform: Entity.dateToString, toObject: 'hasValue' },
TimesheetLines: { type: Array, arrayType: TimesheetLineSchema, toObject: 'always' },
Status: { type: String, toObject: 'hasValue' },
TimesheetID: { type: String, toObject: 'hasValue' },
Hours: { type: Number, toObject: 'hasValue' }
});

var Timesheet = Entity.extend(TimesheetSchema, {
constructor: function(application, data, options) {
logger.debug('Timesheet::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, 'TimesheetLines'));
if (obj.TimesheetLines) {
var items = this.application.asArray(obj.TimesheetLines.TimesheetLine);
_.each(items, function(item) {

var index = self.TimesheetLines.push({ EarningsTypeID: item.EarningsTypeID }) - 1;
var addedNumberOfUnit = self.TimesheetLines[index];
_.each(item.NumberOfUnits.NumberOfUnit, function(unit) {
addedNumberOfUnit.NumberOfUnits.push(unit);
})

})
}

return this;
},
toXml: function() {
var timesheet = _.omit(this.toObject(), 'TimesheetLines');
Object.assign(timesheet, { TimesheetLines: [] });
_.forEach(this.TimesheetLines, function(timesheetline) {
timesheet.TimesheetLines.push({ TimesheetLine: _.pick(timesheetline.toObject(), 'EarningsTypeID', 'TrackingItemID') });
var addedTimesheetLine = _.last(timesheet.TimesheetLines).TimesheetLine;
addedTimesheetLine.NumberOfUnits = { NumberOfUnit: [] };
_.each(timesheetline.NumberOfUnits, function(num) {
addedTimesheetLine.NumberOfUnits.NumberOfUnit.push(num);
})

})

return this.application.js2xml(timesheet, 'Timesheet');
},
save: function(options) {
var self = this
var xml = '<Timesheets>' + this.toXml() + '</Timesheets>';
var path, method;
if (this.TimesheetID) {
path = 'Timesheets/' + this.TimesheetID;
method = 'post'
} else {
path = 'Timesheets';
method = 'post'
}
return this.application.putOrPostEntity(method, path, xml, { entityPath: 'Timesheets.Timesheet', entityConstructor: function(data) { return self.application.payroll.timesheets.newTimesheet(data) }, api: 'payroll' });
}

});


module.exports = Timesheet;
module.exports.TimesheetSchema = TimesheetSchema;
Loading

0 comments on commit 3edb1d0

Please sign in to comment.