Skip to content

Commit

Permalink
fix(report): account report uses ent currency
Browse files Browse the repository at this point in the history
This commit fixes account report to use the enterprise currency in
rendering totals.  It also migrates the account selection to a ui-select
for good measure.  Finally, the loading indicator on the form is now
  hooked up.

Partially fixes #924.
  • Loading branch information
Jonathan Niles authored and sfount committed Nov 27, 2016
1 parent c8156f4 commit aaada58
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 122 deletions.
20 changes: 8 additions & 12 deletions client/src/partials/reports/modals/report_accounts.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ angular.module('bhima.controllers')
.controller('report_accountsController', ReportAccountsConfigController);

ReportAccountsConfigController.$inject = [
'$state', '$uibModalInstance', 'AccountService', 'NotifyService', 'LanguageService', 'BaseReportService', 'reportDetails'
'$state', '$uibModalInstance', 'AccountService', 'NotifyService', 'LanguageService', 'BaseReportService', 'reportDetails', 'bhConstants'
];

/**
Expand All @@ -12,39 +12,36 @@ ReportAccountsConfigController.$inject = [
* This controller is responsible for the configuration of the ReportAccounts report modal. All report
* settings are sent to the server to generate a report document.
*/
function ReportAccountsConfigController($state, ModalInstance, Accounts, Notify, Languages, SavedReports, reportDetails) {
function ReportAccountsConfigController($state, ModalInstance, Accounts, Notify, Languages, SavedReports, reportDetails, bhConstants) {
var vm = this;
var report = reportDetails;

// expose to the view
vm.generate = generate;
vm.cancel = ModalInstance.dismiss;
vm.report = report;
vm.bhConstants = bhConstants;

//Default value for General Ledger
// default value for General Ledger
vm.source = 1;

vm.reportSource = [
{id: 1, label : 'FORM.LABELS.GENERAL_LEDGER'},
{id: 2, label : 'FORM.LABELS.POSTING_JOURNAL'},
{id: 2, label : 'FORM.LABELS.POSTING_JOURNAL'},
{id: 3, label : 'FORM.LABELS.ALL'}
];


Accounts.read(null, { detailed: 1, is_auxiliary: 0})
Accounts.read()
.then(function (accounts) {
accounts.forEach(function (account) {
account.hrlabel = account.number + ' ' + account.label;
});

vm.accounts = accounts;
})
.catch(Notify.handleError);

function generate(form) {
var url = 'reports/finance/account';
if (form.$invalid) { return; }

var url = 'reports/finance/account';

var options = {
account_id : vm.account.id,
account_label : vm.account.label,
Expand All @@ -58,7 +55,6 @@ function ReportAccountsConfigController($state, ModalInstance, Accounts, Notify,

return SavedReports.requestPDF(url, report, options)
.then(function (result) {
vm.$loading = false;
ModalInstance.dismiss();
$state.reload();
});
Expand Down
111 changes: 57 additions & 54 deletions client/src/partials/reports/modals/report_accounts.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,70 @@
</div>

<form name="ConfigForm" bh-submit="ReportConfigCtrl.generate(ConfigForm)" bh-form-defaults novalidate>
<div class="modal-body">
<div class="form-group"
ng-class="{ 'has-error' : ConfigForm.$submitted && ConfigForm.label.$invalid }">
<label class="control-label">{{ "FORM.LABELS.LABEL" | translate }}</label>
<input class="form-control" id="label" name="label" ng-model="ReportConfigCtrl.label" autocomplete="off" required />
<div class="modal-body">
<div class="form-group"
ng-class="{ 'has-error' : ConfigForm.$submitted && ConfigForm.label.$invalid }">
<label class="control-label">{{ "FORM.LABELS.LABEL" | translate }}</label>
<input class="form-control" name="label" ng-model="ReportConfigCtrl.label" required />

<div class="help-block" ng-messages="ConfigForm.label.$error" ng-show="ConfigForm.$submitted">
<div ng-messages-include="partials/templates/messages.tmpl.html"></div>
<div class="help-block" ng-messages="ConfigForm.label.$error" ng-show="ConfigForm.$submitted">
<div ng-messages-include="partials/templates/messages.tmpl.html"></div>
</div>
</div>
</div>

<!-- account selection -->
<div class="form-group"
ng-class="{ 'has-error' : ConfigForm.$submitted && ConfigForm.account.$invalid }">
<label class="control-label">
<span class="fa fa-briefcase"></span> {{ 'FORM.SELECT.ACCOUNT' | translate }}
</label>
<select
class="form-control"
name="account"
ng-model="ReportConfigCtrl.account"
ng-options="account as account.hrlabel for account in ReportConfigCtrl.accounts track by account.id"
required>
<option value="" disabled>{{ "FORM.SELECT.ACCOUNT" | translate }}</option>
</select>
<div class="help-block" ng-messages="ConfigForm.account.$error" ng-show="ConfigForm.$submitted">
<div ng-messages-include="partials/templates/messages.tmpl.html"></div>
<!-- account selection -->
<div class="form-group"
ng-class="{ 'has-error' : ConfigForm.$submitted && ConfigForm.account.$invalid }">
<label class="control-label">
<span class="fa fa-briefcase"></span> {{ 'FORM.SELECT.ACCOUNT' | translate }}
</label>

<ui-select
name="account"
ng-model="ReportConfigCtrl.account"
required>
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.ACCOUNT' | translate }}">
<strong>{{$select.selected.number}}</strong> <span>{{$select.selected.label}}</span>
</ui-select-match>
<ui-select-choices
ui-select-focus-patch
ui-disable-choice="account.type_id === ReportConfigCtrl.bhConstants.accounts.TITLE"
repeat="account in ReportConfigCtrl.accounts | filter:$select.search">
<strong ng-bind-html="account.number | highlight:$select.search"></strong>
<span ng-bind-html="account.label | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>
<div class="help-block" ng-messages="ConfigForm.account.$error" ng-show="ConfigForm.$submitted">
<div ng-messages-include="partials/templates/messages.tmpl.html"></div>
</div>
</div>
</div>

<div class="form-group"
ng-class="{ 'has-error' : ConfigForm.$submitted && ConfigForm.source.$invalid }">
<label class="control-label">
<i class="fa fa-briefcase"></i> {{ "FORM.SELECT.SOURCE" | translate }}
</label>
<select
class="form-control"
name="source"
ng-model="ReportConfigCtrl.source"
ng-options="source as (source.label | translate) for source in ReportConfigCtrl.reportSource track by source.id"
required>
<option value="" disabled>{{ "FORM.SELECT.SOURCE" | translate }}<option>
</select>
<div class="help-block" ng-messages="ConfigForm.source.$error" ng-show="ConfigForm.$submitted">
<div ng-messages-include="partials/templates/messages.tmpl.html"></div>
<div class="form-group"
ng-class="{ 'has-error' : ConfigForm.$submitted && ConfigForm.source.$invalid }">
<label class="control-label">
<i class="fa fa-briefcase"></i> {{ "FORM.SELECT.SOURCE" | translate }}
</label>
<select
class="form-control"
name="source"
ng-model="ReportConfigCtrl.source"
ng-options="source as (source.label | translate) for source in ReportConfigCtrl.reportSource track by source.id"
required>
<option value="" disabled>{{ "FORM.SELECT.SOURCE" | translate }}<option>
</select>
<div class="help-block" ng-messages="ConfigForm.source.$error" ng-show="ConfigForm.$submitted">
<div ng-messages-include="partials/templates/messages.tmpl.html"></div>
</div>
</div>
</div>
</div>

<div class="modal-footer">
<button
type="button"
class="btn btn-default"
ng-click="ReportConfigCtrl.cancel()"
data-method="cancel">
{{ "FORM.BUTTONS.CANCEL" | translate }}
</button>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="ReportConfigCtrl.cancel()" data-method="cancel">
{{ "FORM.BUTTONS.CANCEL" | translate }}
</button>

<bh-loading-button loading-state="ReportConfigCtrl.$loading"
ng-disabled="ConfigForm.$invalid">
{{ "FORM.BUTTONS.GENERATE" | translate }}
</bh-loading-button>
</div>
<bh-loading-button loading-state="ConfigForm.$loading">
{{ "FORM.BUTTONS.GENERATE" | translate }}
</bh-loading-button>
</div>
</form>
48 changes: 19 additions & 29 deletions server/controllers/finance/reports/reportAccounts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ const db = require('../../../../lib/db');
const TEMPLATE = './server/controllers/finance/reports/reportAccounts/report.handlebars';
const BadRequest = require('../../../../lib/errors/BadRequest');


/**
* @method document
*
* @description
* generate Report of accounts as a document
*/
function document(req, res, next) {

let report;

let params = req.query;
Expand All @@ -23,7 +21,6 @@ function document(req, res, next) {
throw new BadRequest('Account ID missing', 'ERRORS.BAD_REQUEST');
}


try {
report = new ReportManager(TEMPLATE, req.session, params);
} catch(e) {
Expand All @@ -47,12 +44,10 @@ function document(req, res, next) {

accounts.forEach(function (account) {
sum.debit += account.debit;
sum.credit += account.credit;
sum.credit += account.credit;
sum.balance = sum.debit - sum.credit;
});



return report.render({ accounts, title, sum });

})
Expand All @@ -67,54 +62,49 @@ function document(req, res, next) {
/**
* @function queryReportAccount
* This feature select all transactions for a specific account
*/
function queryReportAccount(accountId, source){
*/
function queryReportAccount(accountId, source) {
source = parseInt(source);
let sql;

if(source === 1){

let sql = `
if (source === 1) {
sql = `
SELECT general_ledger.trans_id, BUID(general_ledger.entity_uuid) AS entity_uuid, general_ledger.description,
general_ledger.trans_date, general_ledger.debit_equiv as debit, general_ledger.credit_equiv as credit
FROM general_ledger
WHERE general_ledger.account_id = ?
GROUP BY general_ledger.trans_id
ORDER BY general_ledger.trans_date ASC;`;

return db.exec(sql, [accountId]);

} else if(source === 2) {

let sql = `
ORDER BY general_ledger.trans_date ASC;
`;
} else if (source === 2) {
sql = `
SELECT posting_journal.trans_id, BUID(posting_journal.entity_uuid) AS entity_uuid, posting_journal.description,
posting_journal.trans_date, posting_journal.debit_equiv as debit, posting_journal.credit_equiv as credit
FROM posting_journal
WHERE posting_journal.account_id = ?
GROUP BY posting_journal.trans_id
ORDER BY posting_journal.trans_date ASC;`;

return db.exec(sql, [accountId]);

} else if(source === 3){
let sql = `
ORDER BY posting_journal.trans_date ASC;
`;
} else if (source === 3) {
sql = `
SELECT transaction.trans_id, transaction.entity_uuid, transaction.description, transaction.trans_date, sum(transaction.credit_equiv) as credit, sum(transaction.debit_equiv) as debit
FROM(
SELECT posting_journal.trans_id, BUID(posting_journal.entity_uuid) AS entity_uuid, posting_journal.description,
posting_journal.trans_date, posting_journal.debit_equiv, posting_journal.credit_equiv
FROM posting_journal
WHERE posting_journal.account_id = ?
UNION
UNION
SELECT general_ledger.trans_id, BUID(general_ledger.entity_uuid) AS entity_uuid, general_ledger.description,
general_ledger.trans_date, general_ledger.debit_equiv, general_ledger.credit_equiv
FROM general_ledger
WHERE general_ledger.account_id = ?
) as transaction
GROUP BY transaction.trans_id
ORDER BY transaction.trans_date ASC;`;

return db.exec(sql, [accountId, accountId]);
GROUP BY transaction.trans_id
ORDER BY transaction.trans_date ASC;
`;
}

return db.exec(sql, [accountId, accountId]);
}

exports.document = document;
31 changes: 13 additions & 18 deletions server/controllers/finance/reports/reportAccounts/report.handlebars
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{{> head title="REPORT.ACCOUNT" }}

<body>

{{> header }}

<h3 class="text-center text-uppercase"><strong>{{translate "REPORT.ACCOUNT"}}</strong></h3>
<h4 class="text-center"><strong>{{ title.accountNumber }}</strong></h4>
<h4 class="text-center text-uppercase"><strong>{{ title.accountLabel}}</strong></h4>

<section>
<table class="table table-condensed table-striped table-report table-bordered">
<thead>
<tr class="text-capitalize text-center" style="background-color: #ddd;">
<th style="width: 15%;">{{translate "TABLE.COLUMNS.TRANSACTION_ID" }}</th>
<th style="width: 15%;">{{translate "TABLE.COLUMNS.TRANSACTION" }}</th>
<th style="width: 15%;">{{translate "TABLE.COLUMNS.DATE" }}</th>
<th style="width: 40%;">{{translate "TABLE.COLUMNS.DESCRIPTION" }}</th>
<th style="width: 15%;">{{translate "TABLE.COLUMNS.DEBIT" }}</th>
Expand All @@ -25,36 +24,32 @@
<td>{{this.trans_id}}</td>
<td>{{date this.date}}</td>
<td>{{this.description}}</td>
<td>{{currency this.debit currency_id}}</td>
<td>{{currency this.credit currency_id}}</td>
</tr>
{{else}}
<tr>
<td colspan="5" class="text-center">
{{translate "TABLE.COLUMNS.EMPTY"}}
</td>
<td>{{currency this.debit ../metadata.enterprise.currency_id}}</td>
<td>{{currency this.credit ../metadata.enterprise.currency_id}}</td>
</tr>
{{else}}
{{> emptyTable columns=5}}
{{/each}}
</tbody>
<tfoot>
<tr style="background-color: #ddd;">
<td colspan="3"><strong>{{translate "FORM.LABELS.TOTAL" }}</strong></td>
<td><strong>{{currency sum.debit currency_id}}</strong></td>
<td><strong>{{currency sum.credit currency_id}}</strong></td>
</tr>
<td><strong>{{currency sum.debit metadata.enterprise.currency_id}}</strong></td>
<td><strong>{{currency sum.credit metadata.enterprise.currency_id}}</strong></td>
</tr>
</tfoot>
</table>
</table>
<table class="table table-condensed">
<tr>
<th colspan="5" class="text-right">
<strong>{{translate "FORM.LABELS.BALANCE" }} {{currency sum.balance currency_id}}</strong>
<strong>{{translate "FORM.LABELS.BALANCE" }} {{currency sum.balance metadata.enterprise.currency_id}}</strong>
</th>
</tr>
<tr>
<th colspan="5" class="text-right">
<i>{{translate "TABLE.COLUMNS.DATA_SOURCE" }} : {{translate title.source }}</i>
</th>
</tr>
</tr>
</table>
</section>
</body>
</body>
Loading

0 comments on commit aaada58

Please sign in to comment.