-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
16 changed files
with
462 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...nt/src/modules/reports/generate/account_report_multiple/account_report_multiple.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
client/src/modules/reports/generate/account_report_multiple/account_report_multiple.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.