Skip to content

Commit

Permalink
feat(invoices): add CSV and PDF download links
Browse files Browse the repository at this point in the history
This commit adds a dropdown menu with two links - the CSV downloader and
the PDF downloader.  Both of these use the server-side download at the
moment.  We could easily switch the CSV exporter to use the client-side
exporter.  It also removes the bhPrintButton in doing so.

Partially addresses #1749.
  • Loading branch information
jniles committed Jun 5, 2017
1 parent 798237d commit cf2ff2e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 24 deletions.
2 changes: 1 addition & 1 deletion client/src/i18n/en/downloads.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{"DOWNLOADS":{"JSON":"Download as JSON",
"PDF":"Download as PDF",
"CSV":"Download as CSV"}}
"CSV":"Download as CSV"}}
15 changes: 14 additions & 1 deletion client/src/modules/invoices/patientInvoice.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ angular.module('bhima.services')

PatientInvoiceService.$inject = [
'$uibModal', 'SessionService', 'PrototypeApiService', 'FilterService', 'appcache', 'PeriodService',
'$httpParamSerializer', 'LanguageService',
];

/**
Expand All @@ -13,7 +14,7 @@ PatientInvoiceService.$inject = [
* This service wraps the /invoices URL and all CRUD on the underlying tables
* takes place through this service.
*/
function PatientInvoiceService(Modal, Session, Api, Filters, AppCache, Periods) {
function PatientInvoiceService(Modal, Session, Api, Filters, AppCache, Periods, $httpParamSerializer, Languages) {
var service = new Api('/invoices/');

var invoiceFilters = new Filters();
Expand Down Expand Up @@ -174,5 +175,17 @@ function PatientInvoiceService(Modal, Session, Api, Filters, AppCache, Periods)
invoiceFilters.loadCache(filterCache.filters || {});
};

// downloads a type of report based on the
service.download = function download(type) {
var filterOpts = invoiceFilters.formatHTTP();
var defaultOpts = { renderer : type, lang : Languages.key };

// combine options
var options = angular.merge(defaultOpts, filterOpts);

// return serialized options
return $httpParamSerializer(options);
};

return service;
}
61 changes: 45 additions & 16 deletions client/src/modules/invoices/registry/registry.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,64 @@
</ol>

<div class="toolbar">

<div class="toolbar-item">
<div uib-dropdown data-action="open-menu">
<a class="btn btn-default" uib-dropdown-toggle>
<span class="fa fa-bars"></span> <span class="hidden-xs" translate>FORM.LABELS.MENU</span> <span class="caret"></span>
</a>

<ul uib-dropdown-menu role="menu" class="dropdown-menu-right">
<!--
<li role="menuitem">
<a href data-method="configure" ng-click="InvoiceRegistryCtrl.openColumnConfigModal()">
<i class="fa fa-columns"></i> <span translate>FORM.LABELS.COLUMNS</span>
</a>
</li>
<li role="separator" class="divider"></li>
<li role="menuitem">
<a href data-method="save-state" ng-click="InvoiceRegistryCtrl.saveGridState()">
<i class="fa fa-save"></i> <span translate>FORM.BUTTONS.SAVE_GRID_CONFIGURATION</span>
</a>
</li>
<li role="menuitem">
<a href data-method="clear-state" ng-click="InvoiceRegistryCtrl.clearGridState()">
<i class="fa fa-close"></i> <span translate>FORM.BUTTONS.CLEAR_GRID_CONFIGURATION</span>
</a>
</li>
-->

<li role="separator" class="divider"></li>
<li role="menuitem">
<a ng-href="/reports/finance/invoices/?{{ InvoiceRegistryCtrl.download('pdf') }}" download="{{ 'INVOICE_REGISTRY.TITLE' | translate }}">
<span class="fa fa-file-pdf-o"></span> <span translate>DOWNLOADS.PDF</span>
</a>
</li>
<li role="menuitem">
<a ng-href="/reports/finance/invoices/?{{ InvoiceRegistryCtrl.download('csv') }}" download="{{ 'INVOICE_REGISTRY.TITLE' | translate }}">
<span class="fa fa-file-excel-o"></span> <span translate>DOWNLOADS.CSV</span>
</a>
</li>
</ul>
</div>
</div>

<div class="toolbar-item">
<button
ng-click="InvoiceRegistryCtrl.search()"
data-method="search"
class="btn btn-default">
<span class="fa fa-search"></span> <span translate>FORM.BUTTONS.SEARCH</span>
<span class="fa fa-search"></span> <span class="hidden-xs" translate>FORM.BUTTONS.SEARCH</span>
</button>
</div>

<div class="toolbar-item">
<bh-pdf-print pdf-url="/reports/finance/invoices"
options="InvoiceRegistryCtrl.filters">
</bh-pdf-print>
</div>

<div class="toolbar-item">
<bh-renderer-dropdown
report-url="/reports/finance/invoices"
report-options="InvoiceRegistryCtrl.filters">
</bh-renderer-dropdown>
</div>
</div>
</div>
</div>

<div class="flex-util bh-filter-bar">
<bh-filters
style="max-width:90%"
filters="InvoiceRegistryCtrl.latestViewFilters"
on-remove-filter="InvoiceRegistryCtrl.onRemoveFilter(filter)">
</bh-filters>
Expand All @@ -49,7 +79,6 @@
ui-grid-auto-resize
ui-grid-resize-columns
ui-grid-move-columns>

<bh-grid-loading-indicator
loading-state="InvoiceRegistryCtrl.loading"
empty-state="InvoiceRegistryCtrl.uiGridOptions.data.length === 0"
Expand Down
9 changes: 3 additions & 6 deletions client/src/modules/invoices/registry/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ angular.module('bhima.controllers')
InvoiceRegistryController.$inject = [
'PatientInvoiceService', 'bhConstants', 'NotifyService', 'SessionService',
'ReceiptModal', 'uiGridConstants', 'ModalService', 'CashService',
'GridSortingService', '$state', 'FilterService',
'GridSortingService',
];

/**
Expand All @@ -14,7 +14,7 @@ InvoiceRegistryController.$inject = [
*/
function InvoiceRegistryController(
Invoices, bhConstants, Notify, Session, Receipt, uiGridConstants,
ModalService, Cash, Sorting, $state, Filters
ModalService, Cash, Sorting
) {
var vm = this;

Expand All @@ -24,16 +24,13 @@ function InvoiceRegistryController(

var columnDefs;

var filter = new Filters();
vm.filter = filter;

vm.search = search;
vm.openReceiptModal = Receipt.invoice;
vm.creditNoteReceipt = Receipt.creditNote;
vm.onRemoveFilter = onRemoveFilter;
vm.creditNote = creditNote;
vm.bhConstants = bhConstants;
vm.filterBarHeight = {};
vm.download = Invoices.download;

// track if module is making a HTTP request for invoices
vm.loading = false;
Expand Down

0 comments on commit cf2ff2e

Please sign in to comment.