Skip to content

Commit

Permalink
fix(reports): Month Consumption PDF fixes
Browse files Browse the repository at this point in the history
Fixes the monthly consumption PDF report to render nicely with borders
and respecting the orientation provided by the client.

Partially addresses #2480.
  • Loading branch information
jniles committed May 13, 2020
1 parent c548214 commit 9961b9b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
{{> head title="REPORT.MONTHLY_CONSUMPTION.TITLE" }}

<body>

<div class="container">
<body class="container-fluid">
{{> header}}

<!-- body -->
<div class="row">
<div class="col-xs-12">
<!-- page title -->
<h2 class="text-center text-uppercase">
{{translate 'REPORT.MONTHLY_CONSUMPTION.TITLE'}}
</h2>

<h3 class="text-center">
{{ fiscalYear }} : {{ translate params.periodFromKey }} - {{ translate params.periodToKey }}
</h3>
<h4 class="text-center text-uppercase">{{translate 'REPORT.MONTHLY_CONSUMPTION.TITLE'}}</h4>

<h4 class="text-center">
{{ depot }}
{{ fiscalYear }} : {{ translate params.periodFromKey }} - {{ translate params.periodToKey }}
<br />
{{depot}}
</h4>

<table class="table-striped table-condensed table-report table-bordered">
<table class="table table-striped table-condensed table-report table-bordered">
<thead>
<tr style="background-color:#ddd;">
<th class="text-center" style="width: 3%;"> {{translate 'FORM.LABELS.NR'}}</th>
Expand All @@ -34,30 +28,24 @@
</thead>

<tbody>
{{#if dataDisplay}}
{{#each inventories}}
<tr>
<td class="text-center"> {{ add @index 1}} </td>
<td> {{ inventory_text }} </td>
{{#each monthlyConsumption}}
<td class="text-right">
{{#if quantity}}
<strong> {{ quantity }} </strong>
{{/if}}
</td>
{{/each}}
<td class="text-right"> <strong> {{ total }} </strong> </td>
</tr>
{{/each}}
{{#each inventories}}
<tr>
<td class="text-center">{{ add @index 1}}</td>
<td>{{ inventory_text }}</td>
{{#each monthlyConsumption}}
<td class="text-right">
{{#if quantity}}{{ quantity }}{{/if}}
</td>
{{/each}}
<td class="text-right"> <strong> {{ total }} </strong> </td>
</tr>
{{else}}
<tr>
<th class="text-center" colspan="{{ spanColumn }}"> <strong> {{translate 'STOCK.NO_DATA'}} </strong> </th>
<th class="text-center" colspan="{{ spanColumn }}"> {{translate 'STOCK.NO_DATA'}} </th>
</tr>
{{/if}}
{{/each}}
</tbody>
</table>
</div>
</div>

</div>
</body>
10 changes: 4 additions & 6 deletions server/controllers/stock/reports/stock/monthly_consumption.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ exports.report = report;
const DEFAULT_PARAMS = {
csvKey : 'monthlyConsumption',
filename : 'TREE.MONTHLY_CONSUMPTION',
orientation : 'landscape',
footerRight : '[page] / [toPage]',
orientation : 'portrait',
};

/**
Expand Down Expand Up @@ -47,8 +46,8 @@ async function report(req, res, next) {
JOIN inventory AS iv ON iv.uuid = sc.inventory_uuid
JOIN period AS p ON p.id = sc.period_id
JOIN fiscal_year AS f ON f.id = p.fiscal_year_id
JOIN depot AS d ON d.uuid = sc.depot_uuid
WHERE sc.period_id >= ? AND sc.period_id <= ? AND d.uuid = ? ORDER BY iv.text ASC;
JOIN depot AS d ON d.uuid = sc.depot_uuid
WHERE sc.period_id >= ? AND sc.period_id <= ? AND d.uuid = ? ORDER BY iv.text ASC;
`;

const sqlAggregat = `
Expand Down Expand Up @@ -80,10 +79,9 @@ async function report(req, res, next) {
data.depot = params.depot_text;
data.inventories = inventories;

data.dataDisplay = inventories.length ? 1 : 0;
data.spanColumn = data.periods.length + 3;

if (data.dataDisplay) {
if (inventories.length > 0) {
data.inventories.forEach(item => {
item.monthlyConsumption = [];
item.total = 0;
Expand Down

0 comments on commit 9961b9b

Please sign in to comment.