Skip to content

Commit

Permalink
feat(reports): extra data toggles for Open Debtors
Browse files Browse the repository at this point in the history
This commit implements two extra toggles for the Open Debtors report:
 1. Show Unverified Transactions - includes the Posting Journal in
 query.
 2. Show Columns for Last Dates of Invoicing and Payment - includes
 extra columns for the last payment date and last invoice date.

This is part of the refactor of the Open Debtors report.  The date limit
still remains to be implemented.
  • Loading branch information
jniles committed Aug 14, 2017
1 parent 7244d53 commit 5311cf5
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 53 deletions.
1 change: 1 addition & 0 deletions client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@
"ON_PURCHASE": "On Purchase",
"OTHER": "Other",
"ORDER": "Order",
"ORDER_BY": "Order By",
"PARENT_ACCOUNT": "Parent Account",
"PASSIVE": "Passive",
"PASSWORD": "Password",
Expand Down
11 changes: 8 additions & 3 deletions client/src/i18n/en/report.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@
"INCOME_REPORT": "Incomes Report",
"MONTHLY_BALANCE": "Monthly Balance",
"OPEN_DEBTORS": {
"DESCRIPTION": "This report shows indebted debtors",
"DESCRIPTION": "This report shows the debtors that have a standing debt with the institution, and gives some control over the sort order. For advanced analysis, the report can add in the last invoice date and last payment date, as well as limit the scope of the search by a date.",
"TITLE": "Debtors with Unpaid Debts",
"TREE": "Open Debtors"
"TREE": "Open Debtors",
"SHOW_DATE_LIMIT" : "Enable Date Limit",
"SHOW_DETAILED_VIEW" : "Include Columns for Last Dates of Invoicing and Payment",
"SHOW_DETAILED_VIEW_HELP" : "Enabling this option will include the last date the debtor paid and the last date they were invoiced. This is useful for understanding when they were at the institution. However, it will make the query take slightly longer.",
"SHOW_UNVERIFIED_TRANSACTIONS" : "Include Unverified Transactions",
"SHOW_UNVERIFIED_TRANSACTIONS_HELP" : "Enabling this option includes records from the Posting Journal which have not been audited by the accountant as well as records from the General Ledger the accountant has verified. This view must be treated as a projection until the accountant has approved the Posting Journal transactions and moved them to the General Ledger."
},
"OPENING_BALANCE": "Opening Balance",
"ORDER": {
Expand Down Expand Up @@ -115,4 +120,4 @@
"VIEW_ARCHIVE": "Archives"
}
}
}
}
1 change: 1 addition & 0 deletions client/src/i18n/fr/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@
"ORIGIN_VILLAGE": "Village d'Origine",
"ORIGIN_SECTOR": "Secteur d'Origine",
"ORDER": "Ordre",
"ORDER_BY": "Trier Par",
"PARENT_ACCOUNT": "Compte parent",
"PASSIVE": "Passive",
"PASSWORD": "Mot de passe",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@ angular.module('bhima.controllers')
.controller('open_debtorsController', OpenDebtorsConfigController);

OpenDebtorsConfigController.$inject = [
'$sce', 'NotifyService', 'BaseReportService', 'AppCache', 'reportData', '$state', '$translate',
'$sce', 'NotifyService', 'BaseReportService', 'AppCache', 'reportData', '$state', 'OpenDebtorsReportService',
];

function OpenDebtorsConfigController($sce, Notify, SavedReports, AppCache, reportData, $state, $translate) {
function OpenDebtorsConfigController($sce, Notify, SavedReports, AppCache, reportData, $state, OpenDebtorsReports) {
var vm = this;
var cache = new AppCache('configure_open_debtors');
var reportUrl = 'reports/finance/debtors/open';

vm.previewGenerated = false;
vm.reportDetails = {};

// default values for the report
vm.reportDetails = {
showDetailedView : 0,
showUnverifiedTransactions : 0,
limitDate : 0,
};

// bind service variables for rendering the dropdown
vm.orders = OpenDebtorsReports.orders;
vm.ASC = OpenDebtorsReports.ASC;
vm.DESC = OpenDebtorsReports.DESC;

// the date input is hidden by default
vm.showDateLimit = false;

checkCachedConfiguration();

Expand All @@ -20,25 +34,6 @@ function OpenDebtorsConfigController($sce, Notify, SavedReports, AppCache, repor
vm.previewResult = null;
};

vm.columnOrder = [
{
label : $translate.instant('REPORT.ORDER.LAST_PAYMENT'),
value : 'payment-date',
},
{
label : $translate.instant('REPORT.ORDER.LAST_INVOICE'),
value : 'invoice-date',
},
{
label : $translate.instant('REPORT.ORDER.PATIENT_NAME'),
value : 'patient-name',
},
{
label : $translate.instant('REPORT.ORDER.TOTAL_DEBT'),
value : 'debt',
},
];

vm.requestSaveAs = function requestSaveAs() {
var options = {
url : reportUrl,
Expand All @@ -55,9 +50,6 @@ function OpenDebtorsConfigController($sce, Notify, SavedReports, AppCache, repor

vm.preview = function preview(form) {
if (form.$invalid) { return; }

var orderBy = vm.reportDetails.orderBy? '-asc' : '-desc';
vm.reportDetails.order += orderBy;

// update cached configuration
cache.reportDetails = angular.copy(vm.reportDetails);
Expand All @@ -79,4 +71,4 @@ function OpenDebtorsConfigController($sce, Notify, SavedReports, AppCache, repor
vm.reportDetails = angular.copy(cache.reportDetails);
}
}
}
}
79 changes: 61 additions & 18 deletions client/src/modules/reports/generate/open_debtors/open_debtors.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<div ng-show="!ReportConfigCtrl.previewGenerated">
<div class="row">
<div class="col-md-12">
<div class="col-md-6">
<h3 class="text-capitalize" translate>REPORT.OPEN_DEBTORS.TITLE</h3>
<p class="text-info" translate>REPORT.OPEN_DEBTORS.DESCRIPTION</p>
</div>
Expand All @@ -24,33 +24,76 @@ <h3 class="text-capitalize" translate>REPORT.OPEN_DEBTORS.TITLE</h3>
<form name="ConfigForm" bh-submit="ReportConfigCtrl.preview(ConfigForm)" novalidate>


<div class="form-group">
<div class="form-group" ng-class="{'has-error' : ConfigForm.order.$invalid && ConfigForm.$submitted}">
<label class="control-label" translate>
FORM.PLACEHOLDERS.COLUMN
FORM.LABELS.ORDER_BY
</label>

<ui-select
name="column"
name="order"
ng-model="ReportConfigCtrl.reportDetails.order">
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.COLUMN' | translate }}"><span>{{$select.selected.label}}</span></ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="column.value as column in (ReportConfigCtrl.columnOrder | filter:$select.search ) track by column.value">
<span ng-bind-html="column.label | highlight:$select.search"></span>
<ui-select-match placeholder="{{ 'FORM.LABELS.ORDER_BY' | translate }}">
<span>
<i class="fa" ng-class="{
'fa-caret-down': $select.selected.direction === ReportConfigCtrl.DESC,
'fa-caret-up' : $select.selected.direction === ReportConfigCtrl.ASC
}" aria-hidden="true"></i>
<strong translate class="text-capitalize">{{$select.selected.label}}</strong>
</span>
</ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="column.value as column in (ReportConfigCtrl.orders | filter:$select.search)">
<i class="fa" ng-class="{
'fa-caret-down': column.direction === ReportConfigCtrl.DESC,
'fa-caret-up' : column.direction === ReportConfigCtrl.ASC
}" aria-hidden="true"></i>
<span ng-bind-html="column.label | translate | highlight:$select.search" class="text-capitalize"></span>
</ui-select-choices>
</ui-select>
<div class="help-block" ng-messages="ConfigForm.order.$error" ng-show="ConfigForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>

<div class="checkbox"
ng-class="{'has-error' : ConfigForm.limitDate.$invalid && ConfigForm.$submitted}">
<label class="control-label">
<input type="checkbox" name="limitDate" ng-model="ReportConfigCtrl.limitDate" ng-true-value="1" ng-false-value="0">
<span translate>REPORT.OPEN_DEBTORS.SHOW_DATE_LIMIT</span>
</label>
</div>

<!-- TODO - put the date picker limit here -->

<div class="checkbox"
ng-class="{'has-error' : ConfigForm.showDetailedView.$invalid && ConfigForm.$submitted}">
<label class="control-label">
<input type="checkbox" name="showDetailedView" ng-model="ReportConfigCtrl.reportDetails.showDetailedView" ng-true-value="1" ng-false-value="0">
<span translate>REPORT.OPEN_DEBTORS.SHOW_DETAILED_VIEW</span>
</label>

<!-- error handling text -->
<div class="help-block" ng-messages="ConfigForm.order.$error" ng-show="ConfigForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>

<!-- shows the help text to let users know what is going on -->
<p class="help-block" translate>REPORT.OPEN_DEBTORS.SHOW_DETAILED_VIEW_HELP</p>
</div>

<div class="form-group">
<div class="radio">
<label class="radio-inline">
<input type="radio" name="orderBy" id="asc" ng-model="ReportConfigCtrl.reportDetails.orderBy" ng-value="true">
<span translate>REPORT.BY_ASC</span>
</label>
<div class="checkbox"
ng-class="{'has-error' : ConfigForm.showUnverifiedTransactions.$invalid && ConfigForm.$submitted}">
<label class="control-label">
<input type="checkbox" name="showUnverifiedTransactions" ng-model="ReportConfigCtrl.reportDetails.showUnverifiedTransactions" ng-true-value="1" ng-false-value="0">
<span translate>REPORT.OPEN_DEBTORS.SHOW_UNVERIFIED_TRANSACTIONS</span>
</label>

<label class="radio-inline">
<input type="radio" name="orderBy" id="desc" ng-model="ReportConfigCtrl.reportDetails.orderBy" ng-value="false">
<span translate>REPORT.BY_DESC</span>
</label>
<!-- error handling text -->
<div class="help-block" ng-messages="ConfigForm.order.$error" ng-show="ConfigForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>

<!-- shows the help text to let users know what is going on -->
<p class="help-block" translate>REPORT.OPEN_DEBTORS.SHOW_UNVERIFIED_TRANSACTIONS_HELP</p>
</div>

<bh-loading-button loading-state="ConfigForm.$loading">
Expand All @@ -61,4 +104,4 @@ <h3 class="text-capitalize" translate>REPORT.OPEN_DEBTORS.TITLE</h3>
</div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
angular.module('bhima.services')
.service('OpenDebtorsReportService', OpenDebtorsReportService);

/**
* @class OpenDebtorsReportService
*
* @description
* An object that contains keys/properties relevant to rendering the Open
* Debtors Report.
*/
function OpenDebtorsReportService() {
var service = this;

var ASC = 1;
var DESC = 0;

service.ASC = ASC;
service.DESC = DESC;

service.orders = [{
label : 'REPORT.ORDER.LAST_PAYMENT',
value : 'payment-date-asc',
direction : ASC,
}, {
label : 'REPORT.ORDER.LAST_PAYMENT',
value : 'payment-date-desc',
direction : DESC,
}, {
label : 'REPORT.ORDER.LAST_INVOICE',
value : 'invoice-date-asc',
direction : ASC,
}, {
label : 'REPORT.ORDER.LAST_INVOICE',
value : 'invoice-date-desc',
direction : DESC,
}, {
label : 'REPORT.ORDER.PATIENT_NAME',
value : 'patient-name-asc',
direction : ASC,
}, {
label : 'REPORT.ORDER.PATIENT_NAME',
value : 'patient-name-desc',
direction : DESC,
}, {
label : 'REPORT.ORDER.TOTAL_DEBT',
value : 'debt-asc',
direction : ASC,
}, {
label : 'REPORT.ORDER.TOTAL_DEBT',
value : 'debt-desc',
direction : DESC,
}];

return service;
}
6 changes: 3 additions & 3 deletions client/src/modules/templates/bhDatePicker.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<div class="modal-body" style="margin: auto;">
<div
class="well well-sm"
uib-datepicker
ng-model="$ctrl.selected"
uib-datepicker
ng-model="$ctrl.selected"
datepicker-options="$ctrl.options">
</div>
</div>
Expand All @@ -23,4 +23,4 @@
</div>
</div>

</form>
</form>
18 changes: 15 additions & 3 deletions server/controllers/finance/reports/debtors/openDebtors.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ const db = require('../../../../lib/db');
// path to the template to render
const TEMPLATE = './server/controllers/finance/reports/debtors/openDebtors.handlebars';

// converts '0' to false and '1' to true.
// defaults to false
function convertToBoolean(numberString) {
if (numberString) {
return Boolean(Number(numberString));
}

return false;
}

/**
* Actually builds the open debtor report.
*/
Expand Down Expand Up @@ -69,9 +79,10 @@ function build(req, res, next) {
function requestOpenDebtors(params) {
const verifiedSource = 'general_ledger';

const showDetailedView = params.showDetailedView || false;
const showUnverifiedTransactions = params.showUnverifiedTransactions || false;
const limitDate = params.limitDate || false;
// parameter parsing
const showDetailedView = convertToBoolean(params.showDetailedView);
const showUnverifiedTransactions = convertToBoolean(params.showUnverifiedTransactions);
const limitDate = convertToBoolean(params.limitDate);
const reportDateLimit = params.reportDateLimit;

// TODO(@jniles) respect the ordering in the open debtors field.
Expand Down Expand Up @@ -142,6 +153,7 @@ function buildDebtQuery(showDetailedView, source, dateCondition) {
HAVING SUM(debit_equiv - credit_equiv) > 0
ORDER by SUM(debit_equiv - credit_equiv)
`;

return query;
}

Expand Down

0 comments on commit 5311cf5

Please sign in to comment.