Skip to content

Commit

Permalink
Added support for 9 reports.
Browse files Browse the repository at this point in the history
  '1': 'BalanceSheet',
  '2': 'TrialBalance',
  '3': 'ProfitAndLoss',
  '4': 'BankStatement',
  '5': 'BudgetSummary',
  '6': 'ExecutiveSummary',
  '7': 'BankSummary',
  '8': 'AgedReceivablesByContact',
  '9': 'AgedPayablesByContact'

The missing ones are the 1099 report (US Only) and the GST/BAS report (AU/NZ).  These will be added in a subsequent feature release.
  • Loading branch information
Jordan Walsh committed Mar 15, 2017
1 parent b1c644a commit bf11e67
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 29 deletions.
13 changes: 8 additions & 5 deletions lib/entities/accounting/report.js
Expand Up @@ -6,10 +6,10 @@ var ReportSchema = new Entity.SchemaObject({
ReportID: { type: String, toObject: 'always' },
ReportName: { type: String, toObject: 'always' },
ReportType: { type: String, toObject: 'always' },
ReportTitles: [ReportTitleSchema],
ReportTitles: { type: Array, arrayType: ReportTitleSchema, toObject: 'always' },
ReportDate: { type: String, toObject: 'always' },
UpdatedDateUTC: { type: String, toObject: 'always' },
Rows: [ReportRowSchema]
Rows: { type: Array, arrayType: ReportRowSchema, toObject: 'always' }
});

var ReportTitleSchema = new Entity.SchemaObject({
Expand All @@ -19,12 +19,12 @@ var ReportTitleSchema = new Entity.SchemaObject({
var ReportRowSchema = new Entity.SchemaObject({
RowType: { type: String, toObject: 'always' },
Title: { type: String, toObject: 'always' },
Cells: [ReportCellSchema]
Cells: { type: Array, arrayType: ReportCellSchema, toObject: 'always' }
});

var ReportCellSchema = new Entity.SchemaObject({
Value: { type: String, toObject: 'always' },
Attributes: [ReportAttributeSchema]
Attributes: { type: Array, arrayType: ReportAttributeSchema, toObject: 'always' }
});

var ReportAttributeSchema = new Entity.SchemaObject({
Expand All @@ -43,7 +43,10 @@ var Report = Entity.extend(ReportSchema, {
Object.assign(self, _.omit(obj, 'Rows', 'Cells', 'ReportTitles'));

if (obj.ReportTitles) {
this.extractArray(obj.ReportTitles.ReportTitle, this.ReportTitles);
var reportTitles = this.application.asArray(obj.ReportTitles.ReportTitle);
_.each(reportTitles, function(reportTitle) {
self.ReportTitles.push(reportTitle);
})
}

if (hasMoreRows(obj)) {
Expand Down
87 changes: 75 additions & 12 deletions sample_app/index.js
Expand Up @@ -79,6 +79,17 @@ var exphbs = exphbs.create({
default:
return options.inverse(this);
}
},
debug: function(optionalValue) {
console.log("Current Context");
console.log("====================");
console.log(this);

if (optionalValue) {
console.log("Value");
console.log("====================");
console.log(optionalValue);
}
}
}
});
Expand Down Expand Up @@ -462,18 +473,70 @@ app.get('/reports', function(req, res) {

data.active[selectedReport.toLowerCase()] = true;

xeroClient.core.reports.generateReport({
id: selectedReport
})
.then(function(report) {
console.log(report);
data.report = report;
res.render('reports', data);
})
.catch(function(err) {
handleErr(err, req, res, 'reports');
})

/**
* We may need some dependent data:
*
* BankStatement - requires a BankAccountId
* AgedReceivablesByContact - requires a ContactId
* AgedPayablesByContact - requires a ContactId
*
*/

if (selectedReport == 'BankStatement') {
xeroClient.core.accounts.getAccounts({ where: 'Type=="BANK"' })
.then(function(accounts) {
xeroClient.core.reports.generateReport({
id: selectedReport,
params: {
bankAccountID: accounts[0].AccountID
}
})
.then(function(report) {
data.report = report.toObject();
data.colspan = data.report.Rows[0].Cells.length;
res.render('reports', data);
})
.catch(function(err) {
handleErr(err, req, res, 'reports');
});
})
.catch(function(err) {
handleErr(err, req, res, 'reports');
});
} else if (selectedReport == 'AgedReceivablesByContact' || selectedReport == 'AgedPayablesByContact') {
xeroClient.core.contacts.getContacts()
.then(function(contacts) {
xeroClient.core.reports.generateReport({
id: selectedReport,
params: {
contactID: contacts[0].ContactID
}
})
.then(function(report) {
data.report = report.toObject();
data.colspan = data.report.Rows[0].Cells.length;
res.render('reports', data);
})
.catch(function(err) {
handleErr(err, req, res, 'reports');
});
})
.catch(function(err) {
handleErr(err, req, res, 'reports');
});
} else {
xeroClient.core.reports.generateReport({
id: selectedReport
})
.then(function(report) {
data.report = report.toObject();
data.colspan = data.report.Rows[0].Cells.length;
res.render('reports', data);
})
.catch(function(err) {
handleErr(err, req, res, 'reports');
});
}

} else {
res.render('index', {
Expand Down
55 changes: 44 additions & 11 deletions sample_app/views/reports.handlebars
@@ -1,21 +1,54 @@
<h3>{{report.ReportName}}</h3>

{{#each report.ReportTitles as |reportTitle|}}
<center>
<h5>{{reportTitle}}</h5>
</center>
{{/each}}
<br/>
<p>Report Date: {{report.ReportDate}}</p>
{{#if report.Rows}}
<table class="table table-bordered table-striped table-collapsed">
{{#each report.Rows}}
<tr>
{{#if this.Cells}}
{{#each this.Cells}}
<td>{{this.Value}}</td>
<table class="table table-bordered table-collapsed">
{{#each report.Rows as |row|}}

{{#ifCond row.RowType '==' 'Header'}}
<tr>
{{#each row.Cells as |cell|}}
<th>{{cell.Value}}</th>
{{/each}}
{{else}}
<td/>
{{/if}}
</tr>
</tr>
{{/ifCond}}

{{#ifCond row.RowType '!=' 'Header'}}

<tr>
<td colspan="{{../colspan}}"><strong>{{row.Title}}</strong></td>
</tr>

{{#if row.Rows}}
{{#each row.Rows as |thisRow|}}
<tr>
{{#if this.Cells}}
{{#each this.Cells as |thisCell|}}
{{#if thisCell.Value}}
<td>&nbsp;&nbsp;&nbsp;&nbsp;{{thisCell.Value}}</td>
{{else}}
{{#if thisCell.length}}
{{#each thisCell}}
<td><strong>{{this.Value}}</strong></td>
{{/each}}
{{else}}
<td>&nbsp;</td>
{{/if}}
{{/if}}
{{/each}}
{{/if}}
</tr>
{{/each}}
{{/if}}

{{/ifCond}}


{{/each}}
</table>
{{/if}}
2 changes: 1 addition & 1 deletion test/accountingtests.js
Expand Up @@ -411,7 +411,7 @@ describe('reporting tests', function() {

})

describe.skip('regression tests', function() {
describe('regression tests', function() {
var InvoiceID = "";
var PaymentID = "";

Expand Down

0 comments on commit bf11e67

Please sign in to comment.