Skip to content

Commit

Permalink
adding recursion to reports parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Walsh committed Mar 15, 2017
1 parent ef39849 commit 7e612c3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
53 changes: 49 additions & 4 deletions lib/entities/accounting/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,61 @@ var Report = Entity.extend(ReportSchema, {
fromXmlObj: function(obj) {
var self = this;
Object.assign(self, _.omit(obj, 'Rows', 'Cells'));


if (hasMoreRows(obj)) {
logger.debug("Top Level");
obj.Rows.Row.forEach(function(thisRow) {

if (hasMoreRows(thisRow)) {
logger.debug("2nd Level");
thisRow.Rows.Row.forEach(function(anotherRow) {

if (hasMoreRows(anotherRow)) {
logger.debug("3rd Level");
anotherRow.Rows.Row.forEach(function(lastRow) {

if (hasMoreRows(lastRow)) {
logger.debug("You're kidding");
}

});
}

});
}

});
}


if (obj.Rows) {
_.each(obj.Rows.Row, function(row) {
_.each(row.Cells.Cell, function(cell) {
console.log(cell);
});
obj.Rows.Row.forEach(function(row) {
row.Cells ? row.Cells = extractCells(row) : false;
self.Rows.push(row);
});
}

return this;

function extractRows(obj) {

}

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;
}
}
});

Expand Down
19 changes: 18 additions & 1 deletion test/accountingtests.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,26 @@ describe('reporting tests', function() {
expect(report.ReportName).to.equal('Balance Sheet');
expect(report.Rows).to.have.length.greaterThan(0);
report.Rows.forEach(function(row) {
console.log(row);
expect(row.RowType).to.be.oneOf(['Header', 'Section', 'Row', 'SummaryRow']);
expect(row.Cells).to.have.length.greaterThan(0);

//Each row can have some cells, each cell should have some data.
if (row.Cells) {
expect(row.Cells).to.have.length.greaterThan(0);
row.Cells.forEach(function(cell) {
//each cell can either be a string or an object
expect(cell).to.not.equal(undefined);
expect(cell).to.satisfy(function(c) { return typeof c === "string" || typeof c === "object" });
});
}


if (row.Rows) {
//This row has nested rows
}

});

done();
})
.catch(function(err) {
Expand Down

0 comments on commit 7e612c3

Please sign in to comment.