Skip to content

Commit

Permalink
updated sample app to include taxrates and users
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Walsh committed Mar 8, 2017
1 parent 0f44ca7 commit a439c14
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 10 deletions.
15 changes: 14 additions & 1 deletion lib/entities/taxrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ var TaxRate = Entity.extend(TaxRateSchema, {
logger.debug('TaxRate::constructor');
this.Entity.apply(this, arguments);
},
initialize: function(data, options) {}
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);
}
console.log(this.TaxComponents.TaxComponent);
return this;
},
toXml: function() {
var taxrate = _.omit(this.toObject());
return this.application.js2xml(taxrate, 'TaxRate');
}
});


Expand Down
32 changes: 31 additions & 1 deletion sample_app/sample_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var express = require('express'),

function getXeroApp(session) {
var config = {
authorizeCallbackUrl: 'http://localhost:3100/access'
authorizeCallbackUrl: 'http://localhost:3100/access',
runscopeBucketId: 'ei635hnc0fem'
};

if (session) {
Expand Down Expand Up @@ -144,6 +145,34 @@ app.get('/organisations', function(req, res) {
})
});

app.get('/taxrates', function(req, res) {
authorizedOperation(req, res, '/taxrates', function(xeroApp) {
xeroApp.core.taxrates.getTaxRates()
.then(function(taxrates) {
res.render('taxrates', {
taxrates: taxrates,
active: {
taxrates: true
}
});
})
})
});

app.get('/users', function(req, res) {
authorizedOperation(req, res, '/users', function(xeroApp) {
xeroApp.core.users.getUsers()
.then(function(users) {
res.render('users', {
users: users,
active: {
users: true
}
});
})
})
});

app.get('/employees', function(req, res) {
authorizedOperation(req, res, '/employees', function(xeroApp) {
xeroApp.payroll.employees.getEmployees()
Expand Down Expand Up @@ -350,6 +379,7 @@ app.get('/invoices', function(req, res) {
authorizedOperation(req, res, '/invoices', function(xeroApp) {
xeroApp.core.invoices.getInvoices()
.then(function(invoices) {
console.log(invoices[0].Payments[0]);
res.render('invoices', {
invoices: invoices,
active: {
Expand Down
1 change: 1 addition & 0 deletions sample_app/views/index.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<li>Journals</li>
<li>Organisations</li>
<li>Payments</li>
<li>TaxRates</li>
<li>TrackingCategories (and TrackingOptions)</li>
<li>Users</li>
</ul>
Expand Down
42 changes: 34 additions & 8 deletions sample_app/views/invoices.handlebars
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<h3>Invoices</h3>
<table class="table table-bordered table-striped table-collapsed">
<table class="table table-bordered table-collapsed table-hover">
<thead>
<tr>
<td>Invoice Number</td>
<td>Date</td>
<td>Due Date</td>
<td>Status</td>
<td>Total</td>
<td></td>
<th>Invoice Number</th>
<th>Date</th>
<th>Due Date</th>
<th>Status</th>
<th>Total</th>
<th></th>
</tr>
</thead>
<tbody>
{{#each invoices}}
<tr>
<tr class="accordion-toggle" data-toggle="collapse" data-target="#{{this.InvoiceID}}">
{{#ifCond this.Type '==' 'ACCREC'}}
<td><a href="https://go.xero.com/AccountsReceivable/View.aspx?InvoiceID={{ this.InvoiceID }}" target="_blank">
{{#if this.InvoiceNumber}}
Expand All @@ -37,5 +38,30 @@
<td>{{ this.Total }}</td>
<td><a href="/emailinvoice?id={{ this.InvoiceID }}" class="btn btn-primary btn-xs">Email</a></td>
</tr>

{{#ifCond this.Payments.length '>' 0}}
<tr>
<td class="accordion-body collapse" id="{{this.InvoiceID}}">
<h5>Invoice Payments</h5>
<table class="table table-condensed">
<thead>
<th>Date</th>
<th>Amount</th>
<th>Reference</th>
</thead>
<tbody>
{{#each this.Payments as |payment|}}
<tr>
<td>{{payment.Date}}</td>
<td>{{payment.Amount}}</td>
<td>{{payment.Reference}}</td>
</tr>
{{/each}}
</tbody>
</table>
</td>
</tr>
{{/ifCond}}
{{/each}}
</tbody>
</table>
2 changes: 2 additions & 0 deletions sample_app/views/partials/nav.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
<li class="{{#if active.items}}active{{/if}}"><a href="/items">List Items</a></li>
<li class="{{#if active.journals}}active{{/if}}"><a href="/journals">List Journals</a></li>
<li class="{{#if active.payments}}active{{/if}}"><a href="/payments">List Payments</a></li>
<li class="{{#if active.taxrates}}active{{/if}}"><a href="/taxrates">List Tax Rates</a></li>
<li class="{{#if active.trackingcategories}}active{{/if}}"><a href="/trackingcategories">List Tracking Categories</a></li>
<li class="{{#if active.users}}active{{/if}}"><a href="/users">List Users</a></li>
</ul>
<h5>Payroll API - AU</h5>
<ul class="nav nav-sidebar">
Expand Down
29 changes: 29 additions & 0 deletions sample_app/views/taxrates.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<h3>Tax Rates</h3>
<table class="table table-bordered table-striped table-collapsed">
<thead>
<tr>
<td>Name</td>
<td>TaxType</td>
<td>DisplayTaxRate</td>
<td>EffectiveRate</td>
<td>Status</td>
<td>TaxComponent</td>
</tr>
</thead>
<tbody>
{{#each taxrates}}
<tr>
<td>{{ this.Name }}</td>
<td>{{ this.TaxType }}</td>
<td>{{ this.DisplayTaxRate }}</td>
<td>{{ this.EffectiveRate }}</td>
<td>{{ this.Status }}</td>
<td>
{{#each this.TaxComponents as |taxcomponentfield|}}
<p>{{taxcomponentfield.Rate}}</p>
{{/each}}
</td>
</tr>
{{/each}}
</tbody>
</table>
21 changes: 21 additions & 0 deletions sample_app/views/users.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<h3>Users</h3>
<table class="table table-bordered table-striped table-collapsed">
<thead>
<tr>
<td>Name</td>
<td>EmailAddress</td>
<td>IsSubscriber</td>
<td>OrganisationRole</td>
<td>UpdatedDateUTC</td>
</tr>
</thead>
{{#each users}}
<tr>
<td>{{ this.FirstName }} {{this.LastName}}</td>
<td>{{ this.EmailAddress }}</td>
<td>{{ this.IsSubscriber }}</td>
<td>{{ this.OrganisationRole }}</td>
<td>{{ this.UpdatedDateUTC }}</td>
</tr>
{{/each}}
</table>

0 comments on commit a439c14

Please sign in to comment.