Skip to content

Commit

Permalink
Merge #3159
Browse files Browse the repository at this point in the history
3159: feat(accounts reports) report on transtions for multiple accounts r=jniles a=jeremielodi

closes #3103 

Co-authored-by: jeremielodi <[email protected]>
  • Loading branch information
bors[bot] and jeremielodi committed Sep 27, 2018
2 parents c18e190 + 0fda952 commit 61e09ac
Show file tree
Hide file tree
Showing 16 changed files with 462 additions and 12 deletions.
4 changes: 4 additions & 0 deletions client/src/i18n/en/report.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
"WARN_MULTIPLE": "N.B. This report concerns an income/ expense account and spans multiple fiscal years. Income/ expense accounts are cleared to 0 at the beginning of every fiscal year, the cumulative balance displayed is for the transactions within this period of time. It is recommended to use this statement within a single fiscal year.",
"WARN_CURRENCY": "Attention! You are using a currency other than the enterprise currency. Values on this report are subject to change with changes to the exchange rate and should not be considered final. Please save a report in the enterprise currency for long term reference."
},
"REPORT_ACCOUNTS_MULTIPLE": {
"TITLE": "Multiple Accounts Report",
"DESCRIPTION": "This report shows all transactions for a group of accounts given a set time period."
},
"INCOME_EXPENSE_REPORT": {
"TITLE": "Income Expense Report",
"DESCRIPTION": "Show the list of incomes and expenses accured inside the enterprise"
Expand Down
3 changes: 2 additions & 1 deletion client/src/i18n/en/tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
"REFERENCE_GROUP" : "Reference Group",
"REGISTER_SUPPLIER" : "Supplier Management",
"REPORTS" : "Reports",
"REPORT_ACCOUNTS" : "Account Statement Report",
"REPORT_ACCOUNTS" : "Simple Account Statement Report",
"REPORTS_MULTIPLE_ACCOUNTS" : "Multiple Accounts Statement Report",
"ROOT" : "Root",
"RUBRIC_MANAGEMENT" : "Rubrics Management",
"INVOICES" : "Invoices",
Expand Down
5 changes: 5 additions & 0 deletions client/src/i18n/fr/report.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
"WARN_MULTIPLE": "N.B. Ce rapport concerne des comptes de produits / charges et s'étend sur plusieurs années fiscales. Les comptes de produits / charges sont remis à 0 au début de chaque exercice financier, le solde cumulatif affiché est destiné aux transactions dans ce délai. Il est recommandé d'utiliser cette déclaration au cours d'un exercice financier unique.",
"WARN_CURRENCY" : "Attention! Vous utilisez une devise autre que la devise de l'entreprise. Les valeurs de ce rapport sont susceptibles d'être modifiées en fonction du taux de change et ne doivent pas être considérées comme définitives. Veuillez enregistrer un rapport dans la devise de l'entreprise pour référence à long terme."
},

"REPORT_ACCOUNTS_MULTIPLE": {
"TITLE": "Rapports de comptes multiple",
"DESCRIPTION": "Ce rapport affiche toutes les transactions sur un groupe des comptes pour une période donnée"
},
"INCOME_EXPENSE_REPORT": {
"TITLE": "Rapport des Comptes d'exploitation",
"DESCRIPTION": "Afficher la liste des revenus et des dépenses pris en charge dans l'entreprise"
Expand Down
3 changes: 2 additions & 1 deletion client/src/i18n/fr/tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
"PURCHASE":"Effectuer Achat",
"PURCHASE_REGISTRY":"Registre des achats",
"REPORTS":"Rapports",
"REPORT_ACCOUNTS":"Rapport de comptes",
"REPORT_ACCOUNTS":"Rapport de comptes simple",
"REPORTS_MULTIPLE_ACCOUNTS" : "Rapport de comptes multiple",
"REFERENCE":"Référence",
"REFERENCE_GROUP":"Groupe de référence",
"REGISTER_SUPPLIER":"Fournisseurs",
Expand Down
6 changes: 6 additions & 0 deletions client/src/js/components/bhAccountSelectMultiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ angular.module('bhima.components')
bindings : {
accountIds : '<',
onSelectCallback : '&',
onChange : '&',
disable : '<?',
required : '<?',
accountTypeId : '<?',
Expand Down Expand Up @@ -135,6 +136,11 @@ function AccountSelectController(Accounts, AppCache, $timeout, bhConstants, $sco
$scope[$ctrl.name].$bhValue = $item.id;
};

// fires the onChange bound to the component boundary
$ctrl.handleChange = ($model) => {
$ctrl.onChange({ id : $model });
};

/*
// removes the accounts from localstorage
function removeCachedAccounts() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
angular.module('bhima.controllers')
.controller('account_report_multipleController', AccountReportMultipleConfigController);

AccountReportMultipleConfigController.$inject = [
'$sce', 'NotifyService', 'BaseReportService', 'AppCache', 'reportData',
'$state', 'moment', 'SessionService',
];

function AccountReportMultipleConfigController(
$sce, Notify, SavedReports, AppCache, reportData, $state,
Moment, Session
) {
const vm = this;
const cache = new AppCache('configure_account_report_multiple');
const reportUrl = 'reports/finance/account_report_multiple';
vm.previewGenerated = false;


vm.reportDetails = {
currency_id : Session.enterprise.currency_id,
accountIds : [],
};

vm.dateInterval = 1;

checkCachedConfiguration();

vm.selectAccount = function selectAccount(account) {
vm.reportDetails.accountIds.push(account.id);
};

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

vm.setCurrency = function setCurrency(currencyId) {
vm.reportDetails.currency_id = currencyId;
};

// the selected account number has changed
// maybe the user has removed a selected account
vm.onChangeAccounts = function onChangeAccounts(accountId) {
vm.reportDetails.accountIds = vm.reportDetails.accountIds.filter(id => {
return id !== accountId;
});
};

vm.requestSaveAs = function requestSaveAs() {
parseDateInterval(vm.reportDetails);

const options = {
url : reportUrl,
report : reportData,
reportOptions : sanitiseDateStrings(vm.reportDetails),
};

return SavedReports.saveAsModal(options)
.then(() => {
$state.go('reportsBase.reportsArchive', { key : options.report.report_key });
})
.catch(Notify.handleError);
};

vm.preview = function preview(form) {
if (form.$invalid) {
Notify.danger('FORM.ERRORS.RECORD_ERROR');
return 0;
}

parseDateInterval(vm.reportDetails);

// update cached configuration
cache.reportDetails = angular.copy(vm.reportDetails);

const sendDetails = sanitiseDateStrings(vm.reportDetails);

return SavedReports.requestPreview(reportUrl, reportData.id, sendDetails)
.then(result => {
vm.previewGenerated = true;
vm.previewResult = $sce.trustAsHtml(result);
})
.catch(Notify.handleError);
};

function sanitiseDateStrings(options) {
const sanitisedOptions = angular.copy(options);
sanitisedOptions.dateTo = Moment(sanitisedOptions.dateTo).format('YYYY-MM-DD');
sanitisedOptions.dateFrom = Moment(sanitisedOptions.dateFrom).format('YYYY-MM-DD');
return sanitisedOptions;
}

// @TODO validation on dates - this should be done through a 'period select' component
function parseDateInterval(reportDetails) {
if (!vm.dateInterval) {
delete reportDetails.dateTo;
delete reportDetails.dateFrom;
}
}

function checkCachedConfiguration() {
if (cache.reportDetails) {
vm.reportDetails = angular.copy(cache.reportDetails);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<bh-report-preview
ng-if="ReportConfigCtrl.previewGenerated"
source-document="ReportConfigCtrl.previewResult"
on-clear-callback="ReportConfigCtrl.clearPreview()"
on-save-callback="ReportConfigCtrl.requestSaveAs()">
</bh-report-preview>

<div ng-show="!ReportConfigCtrl.previewGenerated">
<div class="row">
<div class="col-md-12">
<h3 class="text-capitalize" translate>REPORT.REPORT_ACCOUNTS_MULTIPLE.TITLE</h3>
<p class="text-info" translate>REPORT.REPORT_ACCOUNTS_MULTIPLE.DESCRIPTION</p>
</div>
</div>

<div class="row" style="margin-top : 10px">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<span translate>REPORT.UTIL.OPTIONS</span>
</div>

<div class="panel-body">
<form name="ConfigForm" bh-submit="ReportConfigCtrl.preview(ConfigForm)" novalidate>
<bh-account-select-multiple
id="account-id"
account-ids="ReportConfigCtrl.reportDetails.accountIds"
label="FORM.SELECT.ACCOUNTS"
name="account"
on-select-callback="ReportConfigCtrl.selectAccount(account)"
on-change="ReportConfigCtrl.onChangeAccounts(id)"
exclude-title-accounts="true"
required="true">
</bh-account-select-multiple>

<!-- Date interval -->
<!-- @TODO this should use a component that callback with well defined dates -->
<bh-date-interval
date-from="ReportConfigCtrl.reportDetails.dateFrom"
date-to="ReportConfigCtrl.reportDetails.dateTo"
required="true"
validation-trigger="ConfigForm.$submitted">
</bh-date-interval>

<!-- the currency to be used in the footer -->
<bh-currency-select
currency-id="ReportConfigCtrl.reportDetails.currency_id"
on-change="ReportConfigCtrl.setCurrency(currency)">
</bh-currency-select>

<bh-loading-button loading-state="ConfigForm.$loading">
<span translate>REPORT.UTIL.PREVIEW</span>
</bh-loading-button>
</form>
</div>
</div>
</div>
</div>
</div>
1 change: 1 addition & 0 deletions client/src/modules/reports/reports.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ angular.module('bhima.routes')
const SUPPORTED_REPORTS = [
'cash_report',
'account_report',
'account_report_multiple',
'balance_sheet_report',
'income_expense',
'aged_debtors',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
<ui-select
multiple
name="accounts"
ng-model="$ctrl.accounts"
ng-model="$ctrl.accountIds"
on-select = "$ctrl.onSelect($item, $model)"
on-remove = "$ctrl.handleChange($model)"
ng-required="$ctrl.required">
<ui-select-match placeholder="{{ ::'FORM.PLACEHOLDERS.ACCOUNT' | translate }}">
<span><strong>{{$select.selected.number}}</strong> {{$select.selected.label}}</span>
<span><strong>{{$item.number}}</strong> {{$item.label}}</span>
</ui-select-match>
<ui-select-choices
ui-select-focus-patch
Expand Down
1 change: 1 addition & 0 deletions server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ exports.configure = function configure(app) {
app.get('/reports/finance/balance', financeReports.balance.document);
app.get('/reports/finance/balance_sheet', financeReports.balanceSheet.document);
app.get('/reports/finance/account_report', financeReports.reportAccounts.document);
app.get('/reports/finance/account_report_multiple', financeReports.reportAccountsMultiple.document);
app.get('/reports/finance/journal', financeReports.journal.postingReport);
app.get('/reports/finance/account_statement', financeReports.accountStatement.report);
app.get('/reports/finance/clientsReport', financeReports.clientsReport.document);
Expand Down
3 changes: 1 addition & 2 deletions server/controllers/finance/accounts/extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ function getOpeningBalanceForDate(accountId, date, includeMaxDate = true) {
return getFiscalYearForDate(date)

// 1. Sum period totals up to the current required period
.then(fiscalYearId =>
getPeriodAccountBalanceUntilDate(accountId, date, fiscalYearId))
.then(fiscalYearId => getPeriodAccountBalanceUntilDate(accountId, date, fiscalYearId))

// 2. Fetch the current dates period
.then((previousPeriodClosing) => {
Expand Down
1 change: 1 addition & 0 deletions server/controllers/finance/reports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exports.income_expense = require('./income_expense');
exports.journal = require('./journal');
exports.balance = require('./balance');
exports.reportAccounts = require('./reportAccounts');
exports.reportAccountsMultiple = require('./reportAccountsMultiple');
exports.generalLedger = require('./generalLedger');
exports.clientsReport = require('./clientsReport');
exports.creditors = require('./creditors');
Expand Down
9 changes: 5 additions & 4 deletions server/controllers/finance/reports/reportAccounts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ function document(req, res, next) {
const params = req.query;
params.user = req.session.user;
params.enterprise_id = req.session.enterprise.id;
params.isEnterpriseCurrency =
(req.session.enterprise.currency_id === Number(params.currency_id));
params.isEnterpriseCurrency = (req.session.enterprise.currency_id === Number(params.currency_id));

try {
report = new ReportManager(TEMPLATE, req.session, params);
Expand Down Expand Up @@ -131,8 +130,7 @@ function getGeneralLedgerSQL(options) {
(balance * rate) AS exchangedBalance, @cumsum := (balance * rate) + @cumsum AS cumsum
`;

const columns = options.isEnterpriseCurrency ?
enterpriseCurrencyColumns : nonEnterpriseCurrencyColumns;
const columns = options.isEnterpriseCurrency ? enterpriseCurrencyColumns : nonEnterpriseCurrencyColumns;


const sql = `
Expand Down Expand Up @@ -262,3 +260,6 @@ function getAccountTransactions(options, openingBalance = 0) {
}

exports.document = document;
exports.getGeneralLedgerSQL = getGeneralLedgerSQL;
exports.getTotalsSQL = getTotalsSQL;
exports.getAccountTransactions = getAccountTransactions;
Loading

0 comments on commit 61e09ac

Please sign in to comment.