Skip to content

Commit

Permalink
feat(reports): enable date limit in Open Debtors
Browse files Browse the repository at this point in the history
This commit adds in the date limit option for the Open Debtors report.
The date limit allows a user to only scan records newer than a certain
date.
  • Loading branch information
jniles committed Aug 14, 2017
1 parent 5311cf5 commit ea6823b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 18 deletions.
3 changes: 2 additions & 1 deletion client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@
"COUNTRY": "Enter country",
"CREDITOR": "Enter creditor",
"DEBTOR": "Enter debtor",
"DEBTOR_GROUP": "Enter debtor group",
"DEBTOR_GROUP": "Enter a Debtor Group",
"DATE" : "Enter a Date",
"PATIENT_GROUP": "Enter patient group",
"DESCRIPTION": "Enter description",
"DOCUMENT_NAME": "Enter document name",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/en/report.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"TITLE": "Debtors with Unpaid Debts",
"TREE": "Open Debtors",
"SHOW_DATE_LIMIT" : "Enable Date Limit",
"DATE_LIMIT_HELP" : "The date limit will only scan records from this date to the present.",
"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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ angular.module('bhima.controllers')

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

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

vm.DATE_FORMAT = bhConstants.dates.format;

vm.previewGenerated = false;

vm.dateOptions = {
maxDate : new Date(),
};

// default values for the report
vm.reportDetails = {
showDetailedView : 0,
Expand Down Expand Up @@ -49,7 +57,7 @@ function OpenDebtorsConfigController($sce, Notify, SavedReports, AppCache, repor
};

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

// update cached configuration
cache.reportDetails = angular.copy(vm.reportDetails);
Expand All @@ -58,14 +66,14 @@ function OpenDebtorsConfigController($sce, Notify, SavedReports, AppCache, repor
.then(function (result) {
vm.previewGenerated = true;
vm.previewResult = $sce.trustAsHtml(result);

// reset form validation
form.$setPristine();
form.$setUntouched();
})
.catch(Notify.handleError);
};

vm.onSelectPeriod = function onSelectPeriod(period){
vm.reportDetails.date = period.end_date;
};

function checkCachedConfiguration() {
if (cache.reportDetails) {
vm.reportDetails = angular.copy(cache.reportDetails);
Expand Down
40 changes: 31 additions & 9 deletions client/src/modules/reports/generate/open_debtors/open_debtors.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ <h3 class="text-capitalize" translate>REPORT.OPEN_DEBTORS.TITLE</h3>
<div class="panel-body">
<form name="ConfigForm" bh-submit="ReportConfigCtrl.preview(ConfigForm)" novalidate>


<div class="form-group" ng-class="{'has-error' : ConfigForm.order.$invalid && ConfigForm.$submitted}">
<label class="control-label" translate>
FORM.LABELS.ORDER_BY
Expand Down Expand Up @@ -57,12 +56,37 @@ <h3 class="text-capitalize" translate>REPORT.OPEN_DEBTORS.TITLE</h3>
<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">
<input type="checkbox" name="limitDate" ng-model="ReportConfigCtrl.reportDetails.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 ng-if="ReportConfigCtrl.reportDetails.limitDate">
<div class="form-group" ng-class="{'has-error' : ConfigForm.reportDateLimit.$invalid && ConfigForm.$submitted}">
<label class="control-label" translate>
FORM.LABELS.DATE
</label>

<input
name="reportDateLimit"
type="text"
class="form-control"
placeholder="{{ 'FORM.PLACEHOLDERS.DATE' | translate }}"
uib-datepicker-popup="{{ ::ReportConfigCtrl.DATE_FORMAT }}"
ng-model="ReportConfigCtrl.reportDetails.reportDateLimit"
is-open="focus"
ng-focus="focus=true"
datepicker-options="ReportConfigCtrl.dateOptions"
show-button-bar="false"
required>

<!-- validation/error messages for date input -->
<div class="help-block" ng-messages="ConfigForm.reportDateLimit.$error" ng-show="ConfigForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>
<p class="help-block" translate>REPORT.OPEN_DEBTORS.DATE_LIMIT_HELP</p>
</div>

<div class="checkbox"
ng-class="{'has-error' : ConfigForm.showDetailedView.$invalid && ConfigForm.$submitted}">
Expand All @@ -75,11 +99,10 @@ <h3 class="text-capitalize" translate>REPORT.OPEN_DEBTORS.TITLE</h3>
<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>

<p class="help-block" translate>REPORT.OPEN_DEBTORS.SHOW_DETAILED_VIEW_HELP</p>

<div class="checkbox"
ng-class="{'has-error' : ConfigForm.showUnverifiedTransactions.$invalid && ConfigForm.$submitted}">
<label class="control-label">
Expand All @@ -91,11 +114,10 @@ <h3 class="text-capitalize" translate>REPORT.OPEN_DEBTORS.TITLE</h3>
<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>

<p class="help-block" translate>REPORT.OPEN_DEBTORS.SHOW_UNVERIFIED_TRANSACTIONS_HELP</p>

<bh-loading-button loading-state="ConfigForm.$loading">
<span translate>REPORT.UTIL.PREVIEW</span>
</bh-loading-button>
Expand Down
4 changes: 2 additions & 2 deletions server/controllers/finance/reports/debtors/openDebtors.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function requestOpenDebtors(params) {
const showDetailedView = convertToBoolean(params.showDetailedView);
const showUnverifiedTransactions = convertToBoolean(params.showUnverifiedTransactions);
const limitDate = convertToBoolean(params.limitDate);
const reportDateLimit = params.reportDateLimit;
const reportDateLimit = new Date(params.reportDateLimit);

// TODO(@jniles) respect the ordering in the open debtors field.
const ordering = parseOrdering(params.order);
Expand All @@ -97,7 +97,7 @@ function requestOpenDebtors(params) {
const source = showUnverifiedTransactions ? unverifiedSource : verifiedSource;

// ONLY show transactions after a certain date (just show this week for example)
const dateCondition = limitDate ? `AND DATE(trans_date) > DATE(${reportDateLimit})` : '';
const dateCondition = limitDate ? `AND DATE(trans_date) >= DATE(${db.escape(reportDateLimit)})` : '';

const debtorQuery = buildDebtQuery(showDetailedView, source, dateCondition);

Expand Down

0 comments on commit ea6823b

Please sign in to comment.