Skip to content

Commit

Permalink
Updated Open Debtors report
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcameron committed Jan 4, 2022
1 parent 22f637a commit 5ae5bed
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ angular.module('bhima.controllers')
.controller('open_debtorsController', OpenDebtorsConfigController);

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


Expand All @@ -15,8 +15,8 @@ OpenDebtorsConfigController.$inject = [
* to see debtors with unpaid debts.
*/
function OpenDebtorsConfigController(
$sce, Notify, SavedReports, AppCache, reportData, $state, OpenDebtorsReports,
bhConstants
$sce, Notify, SavedReports, AppCache, Session, reportData,
$state, OpenDebtorsReports, bhConstants,
) {
const vm = this;
const cache = new AppCache('configure_open_debtors');
Expand Down Expand Up @@ -45,16 +45,18 @@ function OpenDebtorsConfigController(
vm.ASC = OpenDebtorsReports.ASC;
vm.DESC = OpenDebtorsReports.DESC;

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

checkCachedConfiguration();

vm.clearPreview = function clearPreview() {
vm.previewGenerated = false;
vm.previewResult = null;
};

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

vm.requestSaveAs = function requestSaveAs() {
const options = {
url : reportUrl,
Expand Down Expand Up @@ -91,5 +93,11 @@ function OpenDebtorsConfigController(
if (cache.reportDetails) {
vm.reportDetails = angular.copy(cache.reportDetails);
}

// Set the defaults
if (!angular.isDefined(vm.reportDetails.currencyId)) {
vm.reportDetails.currencyId = Session.enterprise.currency_id;
}
vm.reportDetails.enterpriseCurrencyId = Session.enterprise.currency_id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ <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.reportDetails.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>
Expand Down Expand Up @@ -119,6 +124,11 @@ <h3 class="text-capitalize" translate>REPORT.OPEN_DEBTORS.TITLE</h3>

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

<bh-currency-select
currency-id="ReportConfigCtrl.reportDetails.currencyId"
on-change="ReportConfigCtrl.onSelectCurrency(currency)" >
</bh-currency-select>

<bh-loading-button loading-state="ConfigForm.$loading">
<span translate>REPORT.UTIL.PREVIEW</span>
</bh-loading-button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@
<h4 class="text-center text-uppercase">
{{#if details.limitDate}}{{date details.reportDateLimit}} - {{/if}}
{{date this.timestamp }}
</h4>
</h4>
{{#unless enterpriseCurrency}}
{{#if showReciprocalRate}}
<h5 class="text-center">
{{ translate 'FORM.LABELS.EXCHANGE_RATE' }}: {{currency reciprocalRate enterpriseCurrencyId}} {{translate 'FORM.INFO.PER'}} {{ currencySymbol }}
</h5>
{{else}}
<h5 class="text-center">
{{ translate 'FORM.LABELS.EXCHANGE_RATE' }}: {{currency rate currencyId}} {{translate 'FORM.INFO.PER'}} {{ enterpriseCurrencySymbol }}
</h5>
{{/if}}
{{/unless}}

<!-- margin is the cell size -->
<section>
Expand Down
24 changes: 23 additions & 1 deletion server/controllers/finance/reports/debtors/openDebtors.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ function build(req, res, next) {

const metadata = _.clone(req.session);

qs.enterpriseId = metadata.enterprise.id;
qs.enterpriseCurrencySymbol = metadata.enterprise.currencySymbol;

let report;

try {
Expand Down Expand Up @@ -87,10 +90,18 @@ function requestOpenDebtors(params) {
const showUnverifiedTransactions = convertToBoolean(params.showUnverifiedTransactions);
const limitDate = convertToBoolean(params.limitDate);
const reportDateLimit = new Date(params.reportDateLimit);
const currencyId = parseInt(params.currencyId, 10);
const enterpriseId = parseInt(params.enterpriseId, 10);
const enterpriseCurrencyId = parseInt(params.enterpriseCurrencyId, 10);
const enterpriseCurrency = params.currencyId === params.enterpriseCurrencyId;

// TODO(@jniles) respect the ordering in the open debtors field.
const ordering = parseOrdering(params.order);

const exchangeRateQuery = `
SELECT GetExchangeRate(?, ?, NOW()) AS rate
`;

const unverifiedSource = `
(SELECT entity_uuid, reference_uuid, trans_date, credit_equiv, debit_equiv from general_ledger
UNION ALL
Expand Down Expand Up @@ -118,9 +129,20 @@ function requestOpenDebtors(params) {
limitDate,
reportDateLimit,
},
currencyId,
currencySymbol : params.currencySymbol,
enterpriseCurrencyId,
enterpriseCurrencySymbol : params.enterpriseCurrencySymbol,
enterpriseCurrency,
};

return db.exec(debtorQuery)
return db.one(exchangeRateQuery, [enterpriseId, currencyId])
.then((exRate) => {
debtorReport.rate = exRate.rate ? exRate.rate : 1;
debtorReport.reciprocalRate = 1.0 / debtorReport.rate;
debtorReport.showReciprocalRate = debtorReport.rate < 1.0;
return db.exec(debtorQuery);
})
.then((debtorsDebts) => {
debtorReport.debtors = debtorsDebts;
return db.one(aggregateQuery);
Expand Down
5 changes: 4 additions & 1 deletion test/integration/reports/finance/open_debtors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const RenderingTests = require('../rendering');
const target = '/reports/finance/debtors/open';
const options = {
currencyId : 1,
};

describe(`(${target}) Open Debtors`, RenderingTests(target));
describe(`(${target}) Open Debtors`, RenderingTests(target, null, options));

0 comments on commit 5ae5bed

Please sign in to comment.