Skip to content

Commit

Permalink
Merge #3624
Browse files Browse the repository at this point in the history
3624: feat(reports): filter locked clients r=jeremielodi a=jniles

This commit adds a filter for locked clients to the Annual Clients
Report, allowing administrators to prevent the display of debtor groups
in the report.

A bug was also discovered with the currency select and is now fixed.

Closes #3386.

![filterlockedclients](https://user-images.githubusercontent.com/896472/53697987-33eddb80-3dd7-11e9-9cf5-f0dcf1edaaa2.PNG)


Co-authored-by: Jonathan Niles <jonathanwniles@gmail.com>
  • Loading branch information
bors[bot] and jniles committed Mar 5, 2019
2 parents e07d226 + 22fed42 commit 004d31e
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 23 deletions.
4 changes: 3 additions & 1 deletion client/src/i18n/en/report.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
"CHART_OF_ACCOUNTS": "Chart of Accounts",
"CLIENTS": {
"TITLE" : "Annual Clients Report",
"DESCRIPTION": "This report displays all the debtor groups, their account balances at the beginning of the fiscal year, the debits and credits to their accounts, and their ending balances."
"DESCRIPTION": "This report displays all the debtor groups, their account balances at the beginning of the fiscal year, the debits and credits to their accounts, and their ending balances.",
"HIDE_LOCKED_CLIENTS" : "Hide Locked Clients",
"HIDE_LOCKED_CLIENTS_HELP_TEXT" : "Selecting yes will filter out all locked clients from the report. By default, the value is no."
},
"CLOSING_BALANCE": "Closing Balance",
"CONFIGURATION": "Report Configuration",
Expand Down
4 changes: 3 additions & 1 deletion client/src/i18n/fr/report.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@
},
"CLIENTS" : {
"TITLE" : "Rapport Annuel des Clients",
"DESCRIPTION" : "Ce rapport affiche tous les groupes de débiteurs, leurs soldes de compte au début de l'exercice, les soldes actuels et leurs soldes de clôture."
"DESCRIPTION" : "Ce rapport affiche tous les groupes de débiteurs, leurs soldes de compte au début de l'exercice, les soldes actuels et leurs soldes de clôture.",
"HIDE_LOCKED_CLIENTS" : "Masquer les clients verrouillés",
"HIDE_LOCKED_CLIENTS_HELP_TEXT" : "Si vous sélectionnez oui, tous les clients verrouillés seront filtrés dans le rapport. Par défaut, la valeur est non."
},
"UNPAID_INVOICE_PAYMENTS_REPORT": {
"TITLE": "Rapport de Factures Non-Payées",
Expand Down
3 changes: 0 additions & 3 deletions client/src/js/components/bhCurrencySelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ function bhCurrencySelect(Currencies) {
$ctrl.valid = true;

$ctrl.label = $ctrl.label || 'FORM.LABELS.CURRENCY';

// default to noop() if an onChange() method was not passed in
$ctrl.onChange = $ctrl.onChange || angular.noop;
};

$ctrl.valueChange = () => {
Expand Down
16 changes: 8 additions & 8 deletions client/src/modules/enterprises/enterprises.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@
<div class="form-group">
<div class="enterprise-logo-editing">
<div class="logo" ng-if="!EnterpriseCtrl.enterprise.logo">
<span ng-if="!EnterpriseCtrl.hasThumbnail">
<span ng-if="!EnterpriseCtrl.hasThumbnail">
<i class="fa fa-3x fa-file-image-o"></i>
</span>
<span ng-if="EnterpriseCtrl.hasThumbnail">
<span ng-if="EnterpriseCtrl.hasThumbnail">
<img ngf-thumbnail="{{ 'EnterpriseCtrl.thumbnail' }}" style="width: 100px !important; height: 100px !important;">
</span>
</div>
<div class="logo" ng-if="EnterpriseCtrl.enterprise.logo">
<span ng-if="!EnterpriseCtrl.hasThumbnail">
<span ng-if="!EnterpriseCtrl.hasThumbnail">
<img ng-src="{{ EnterpriseCtrl.enterprise.logo }}" style="width: 100px !important; height: 100px !important;" onError="this.src='assets/empty.png';" >
</span>
<span ng-if="EnterpriseCtrl.hasThumbnail">
<span ng-if="EnterpriseCtrl.hasThumbnail">
<img ngf-thumbnail="{{ 'EnterpriseCtrl.thumbnail' }}" style="width: 100px !important; height: 100px !important;">
</span>
</div>
Expand All @@ -61,11 +61,11 @@
<label data-method="upload-logo" class="btn btn-default">
<i class="fa fa-edit"></i> <span translate>ENTERPRISE.UPDATE_LOGO</span>
<input
type="file"
accept="image/*"
type="file"
accept="image/*"
ng-model="EnterpriseCtrl.file"
ngf-max-size="2MB"
ngf-select="EnterpriseCtrl.setThumbnail($file)"
ngf-max-size="2MB"
ngf-select="EnterpriseCtrl.setThumbnail($file)"
style="display: none;">
</label>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ <h3 class="text-capitalize" translate>REPORT.CLIENTS.TITLE</h3>
on-change="ReportConfigCtrl.onSelectCurrency(currencyId)">
</bh-currency-select>

<bh-yes-no-radios
label="REPORT.CLIENTS.HIDE_LOCKED_CLIENTS"
value="ReportConfigCtrl.reportDetails.hideLockedClients"
help-text="REPORT.CLIENTS.HIDE_LOCKED_CLIENTS_HELP_TEXT"
on-change-callback="ReportConfigCtrl.onHideLockedClientsToggle(value)">
</bh-yes-no-radios>

<!--preview-->
<bh-loading-button loading-state="ConfigForm.$loading">
<span translate>REPORT.UTIL.PREVIEW</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function AnnualClientsReportController($state, $sce, Notify, AppCache, SavedRepo

vm.reportDetails = {
currencyId : Session.enterprise.currency_id,
hideLockedClients : 0,
};

checkCachedConfiguration();
Expand All @@ -30,8 +31,12 @@ function AnnualClientsReportController($state, $sce, Notify, AppCache, SavedRepo
vm.reportDetails.fiscalId = fiscal.id;
};

vm.onSelectCurrency = currency => {
vm.reportDetails.currencyId = currency.id;
vm.onSelectCurrency = currencyId => {
vm.reportDetails.currencyId = currencyId;
};

vm.onHideLockedClientsToggle = hideLockedClients => {
vm.reportDetails.hideLockedClients = hideLockedClients;
};

vm.requestSaveAs = function requestSaveAs() {
Expand Down Expand Up @@ -69,7 +74,7 @@ function AnnualClientsReportController($state, $sce, Notify, AppCache, SavedRepo

function checkCachedConfiguration() {
if (cache.reportDetails) {
vm.reportDetails = angular.copy(cache.reportDetails);
angular.merge(vm.reportDetails, cache.reportDetails);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ function annualClientsReport(req, res, next) {

// fire the SQL for the report
const fiscalYearId = req.query.fiscalId;
const { currencyId } = req.query;
const { currencyId, hideLockedClients } = req.query;

// convert to an integer
const shouldHideLockedClients = Number(hideLockedClients);

const data = {
isEnterpriseCurrency : parseInt(currencyId, 10) === req.session.enterprise.currency_id,
Expand All @@ -50,8 +53,8 @@ function annualClientsReport(req, res, next) {
_.extend(data, { fiscalYear, rate });

return Promise.all([
getDebtorGroupMovements(fiscalYearId, currencyId, rate),
getTotalsFooter(fiscalYearId, currencyId, rate),
getDebtorGroupMovements(fiscalYearId, currencyId, rate, shouldHideLockedClients),
getTotalsFooter(fiscalYearId, currencyId, rate, shouldHideLockedClients),
]);
})
.then(([rows, footer]) => {
Expand All @@ -72,7 +75,8 @@ function annualClientsReport(req, res, next) {
* debtor group's accounts. The currency and exchange rate are used to convert
* the values into the correct currency rendering.
*/
function getDebtorGroupMovements(fiscalYearId, currencyId, rate) {
function getDebtorGroupMovements(fiscalYearId, currencyId, rate, hideLockedClients = 0) {
const hiddenClientsCondition = ' AND dg.locked = 0 ';
const sql = `
SELECT ac.number AS accountNumber, dg.name AS groupName,
IFNULL(SUM(IF(p.number = 0, pt.debit - pt.credit, 0)), 0) * ${rate} AS openingBalance,
Expand All @@ -85,7 +89,7 @@ function getDebtorGroupMovements(fiscalYearId, currencyId, rate) {
LEFT JOIN period_total pt ON dg.account_id = pt.account_id
LEFT JOIN account ac ON ac.id = pt.account_id
LEFT JOIN period p ON p.id = pt.period_id
WHERE pt.fiscal_year_id = ?
WHERE pt.fiscal_year_id = ? ${hideLockedClients ? hiddenClientsCondition : ''}
GROUP BY pt.account_id;
`;

Expand All @@ -99,7 +103,8 @@ function getDebtorGroupMovements(fiscalYearId, currencyId, rate) {
* This function computes the sum of all the values from the table of debtors
* groups.
*/
function getTotalsFooter(fiscalYearId, currencyId, rate) {
function getTotalsFooter(fiscalYearId, currencyId, rate, hideLockedClients = 0) {
const hiddenClientsCondition = ' AND dg.locked = 0 ';
const sql = `
SELECT ac.number AS accountNumber, ac.label AS accountLabel,
IFNULL(SUM(IF(p.number = 0, pt.debit - pt.credit, 0)), 0) * ${rate} AS openingBalance,
Expand All @@ -112,7 +117,7 @@ function getTotalsFooter(fiscalYearId, currencyId, rate) {
LEFT JOIN period_total pt ON dg.account_id = pt.account_id
LEFT JOIN account ac ON ac.id = pt.account_id
LEFT JOIN period p ON p.id = pt.period_id
WHERE pt.fiscal_year_id = ?;
WHERE pt.fiscal_year_id = ? ${hideLockedClients ? hiddenClientsCondition : ''};
`;

return db.one(sql, fiscalYearId);
Expand Down

0 comments on commit 004d31e

Please sign in to comment.