Skip to content

Commit

Permalink
refactor(Recovery capacity report)
Browse files Browse the repository at this point in the history
- Add days of the week
- Add a summary at the bottom of percentage of recovery
  • Loading branch information
lomamech committed Jan 26, 2022
1 parent 2b79fd7 commit 364a49e
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
2 changes: 2 additions & 0 deletions client/src/i18n/en/table.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"LABEL": "Filter"
},
"FIRST_NAME": "First Name",
"FREQUENCY": "Frequency",
"PROFESSION": "Job Title",
"GENDER": "Gender",
"GRADE": "Grade",
Expand Down Expand Up @@ -236,6 +237,7 @@
},
"SOURCE": "Source",
"STATUS": "Status",
"SUMMARY": "Summary",
"SUPPLIER": "Supplier",
"TAXABLE": "Taxable",
"TAXABLE_BASE_SALARY": "Taxable Base Salary",
Expand Down
2 changes: 2 additions & 0 deletions client/src/i18n/fr/table.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"LABEL": "Filtre"
},
"FIRST_NAME": "Prénom",
"FREQUENCY": "Fréquence",
"FIXED_CHARGES": "Charges fixes",
"PROFESSION": "Profession",
"GENDER": "Genre",
Expand Down Expand Up @@ -234,6 +235,7 @@
},
"SOURCE": "Source",
"STATUS": "État",
"SUMMARY": "Sommaire",
"SUPPLIER": "Fournisseur",
"TAXABLE": "Imposable",
"TAXABLE_BASE_SALARY": "Base Imposable",
Expand Down
56 changes: 56 additions & 0 deletions server/controllers/finance/reports/recovery_capacity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ async function report(req, res, next) {
const formatedDateFrom = moment(dateFrom).format('YYYY-MM-DD');
const formatedDateTo = moment(dateTo).format('YYYY-MM-DD');

const daysWeek = [
'FORM.LABELS.WEEK_DAYS.SUNDAY',
'FORM.LABELS.WEEK_DAYS.MONDAY',
'FORM.LABELS.WEEK_DAYS.TUESDAY',
'FORM.LABELS.WEEK_DAYS.WEDNESDAY',
'FORM.LABELS.WEEK_DAYS.THURSDAY',
'FORM.LABELS.WEEK_DAYS.FRIDAY',
'FORM.LABELS.WEEK_DAYS.SATURDAY',
];

const includeUnpostedValues = qs.includeUnpostedValues ? Number(qs.includeUnpostedValues) : 0;

let generalTable = `
Expand Down Expand Up @@ -165,6 +175,51 @@ async function report(req, res, next) {
const getExchangeRateData = await Exchange.getExchangeRate(enterprise.id, currencyId, new Date(dateTo));
const exchangeRate = getExchangeRateData.rate || 1;

// Get the day of the week
// Get summary of recover indicating %
let rowLength = 0;

let greenAbove70 = 0;
let yellowBetwen60And70 = 0;
let redLess60 = 0;

let greenAbove70Percent = 0;
let yellowBetwen60And70Percent = 0;
let redLess60Percent = 0;

rows.forEach(row => {
const numDays = moment(row.date).day();
row.dayOfWeek = daysWeek[numDays];

rowLength += 1;

if (row.recovery_capacity >= 0.7) {
greenAbove70 += 1;
}

if (row.recovery_capacity >= 0.6 && row.recovery_capacity < 7) {
yellowBetwen60And70 += 1;
}

if (row.recovery_capacity < 0.6) {
redLess60 += 1;
}
});

greenAbove70Percent = greenAbove70 / rowLength;
yellowBetwen60And70Percent = yellowBetwen60And70 / rowLength;
redLess60Percent = redLess60 / rowLength;

const summary = {
greenAbove70,
yellowBetwen60And70,
redLess60,
greenAbove70Percent,
yellowBetwen60And70Percent,
redLess60Percent,
rowLength,
};

const result = await rpt.render({
dateFrom,
dateTo,
Expand All @@ -173,6 +228,7 @@ async function report(req, res, next) {
rows,
totals,
includeUnpostedValues,
summary,
});

res.set(result.headers).send(result.report);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<tbody>
{{#each rows as | row |}}
<tr>
<td>{{date row.date}}</td>
<td>{{translate dayOfWeek}}, {{date row.date}}</td>
<td style="width: 10em;" class="text-right">{{row.registrations}}</td>
<td class="text-right">{{debcred (multiply row.total_invoiced ../exchangeRate) ../currencyId}}</td>
<td class="text-right">{{debcred (multiply row.avg_cost ../exchangeRate) ../currencyId}}</td>
Expand Down Expand Up @@ -88,6 +88,50 @@
</tr>
</tfoot>
</table>
<br>
<table class="table table-striped table-condensed table-report table-bordered" style="width: 50%; float: right; margin-bottom: 1.5%">
<tr>
<th colspan="3">{{translate 'TABLE.COLUMNS.SUMMARY'}}</th>
</tr>
<tr>
<td></td>
<td>
<span>
<strong> {{translate 'TABLE.COLUMNS.PERCENT'}} </strong>
</span>
</td>
<td>
<span>
<strong> {{translate 'TABLE.COLUMNS.FREQUENCY'}} </strong>
</span>
</td>
</tr>
<tr>
<td width="60%">
<span>
<strong> {{translate 'REPORT.RECOVERY_CAPACITY.RECOVERY_CAPACITY'}} &gt; 70% </strong>
</span>
</td>
<td width="20%"> {{ summary.greenAbove70 }} </td>
<td class="bg-success text-success text-right" width="20%">
<strong>{{ percentage summary.greenAbove70Percent }}</strong>
</td>
</tr>
<tr>
<td>
<strong><span>60% &lt; {{translate 'REPORT.RECOVERY_CAPACITY.RECOVERY_CAPACITY'}} &lt;&equals; 70%</span></strong>
</td>
<td> {{ summary.yellowBetwen60And70 }} </td>
<td class="bg-warning text-warning text-right"> <strong>{{ percentage summary.yellowBetwen60And70Percent }}</strong> </td>
</tr>
<tr>
<td>
<strong><span>{{translate 'REPORT.RECOVERY_CAPACITY.RECOVERY_CAPACITY'}} &lt;&equals; 60%</span></strong>
</td>
<td> {{ summary.redLess60 }} </td>
<td class="bg-danger text-danger text-right"> {{ percentage summary.redLess60Percent }} </td>
</tr>
</table>
</div>
</div>
</div>
Expand Down

0 comments on commit 364a49e

Please sign in to comment.