Skip to content

Commit

Permalink
feat(bhReceipt): implement receipt component
Browse files Browse the repository at this point in the history
This commit implements a receipt-rendering component that opens the
receipt modal when a link is clicked.  It supports three values:
 1. value - the ID or UUID for the receipt
 2. displayValue - whatever you would like to show.
 3. type - a string denoting what kind of receipt it is.

A prototype implementation is found on the cash registry page.

I thought there was an issue for this, but cannot find it.
  • Loading branch information
jniles committed Oct 27, 2017
1 parent d927538 commit 00a208e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
34 changes: 34 additions & 0 deletions client/src/js/components/bhReceipt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var bhReceiptTemplate =
'<a ng-click="$ctrl.open()" href="">{{ $ctrl.displayValue }}</a>';

angular.module('bhima.components')
.component('bhReceipt', {
template : bhReceiptTemplate,
controller : bhReceiptController,
bindings : {
value : '<',
displayValue : '<',
type : '@',
},
});

bhReceiptController.$inject = ['ReceiptModal', '$log'];

function bhReceiptController(ReceiptModal, $log) {
var $ctrl = this;

$ctrl.$onInit = function $onInit() {
// make sure the receipt type exists before it is clicked
var hasCallbackFn = ReceiptModal[$ctrl.type];
if (!hasCallbackFn) {
$log.warn('Warning: Cannot find '
.concat($ctrl.type)
.concat(' in ReceiptModalService.'));
}
};

$ctrl.open = function open() {
ReceiptModal[$ctrl.type]($ctrl.value);
};
}

11 changes: 4 additions & 7 deletions client/src/modules/cash/payments/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ angular.module('bhima.controllers')
// dependencies injection
CashPaymentRegistryController.$inject = [
'CashService', 'bhConstants', 'NotifyService', 'SessionService', 'uiGridConstants',
'ReceiptModal', 'ModalService', 'GridSortingService', '$state', 'FilterService',
'ModalService', 'GridSortingService', '$state', 'FilterService',
'GridColumnService', 'GridStateService', 'ModalService',
];

Expand All @@ -15,8 +15,8 @@ CashPaymentRegistryController.$inject = [
* print and search utilities for the registry.`j
*/
function CashPaymentRegistryController(
Cash, bhConstants, Notify, Session, uiGridConstants, Receipt, Modal, Sorting,
$state, Filters, Columns, GridState, Modals
Cash, bhConstants, Notify, Session, uiGridConstants, Modal, Sorting, $state,
Filters, Columns, GridState, Modals
) {
var vm = this;

Expand All @@ -35,9 +35,6 @@ function CashPaymentRegistryController(
vm.enterprise = Session.enterprise;
vm.bhConstants = bhConstants;

// bind the cash payments receipt
vm.openReceiptModal = Receipt.cash;

// expose to the view
vm.search = search;
vm.onRemoveFilter = onRemoveFilter;
Expand Down Expand Up @@ -79,7 +76,7 @@ function CashPaymentRegistryController(
// @TODO(jniles): This is temporary, as it doesn't take into account USD payments
aggregationType : uiGridConstants.aggregationTypes.sum,
aggregationHideLabel : true,
footerCellClass: 'text-right',
footerCellClass : 'text-right',
}, {
field : 'cashbox_label',
displayName : 'TABLE.COLUMNS.CASHBOX',
Expand Down
6 changes: 2 additions & 4 deletions client/src/modules/cash/payments/templates/reference.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<div class="ui-grid-cell-contents text-action">
<a ng-click="grid.appScope.openReceiptModal(row.entity.uuid)" href>
{{ row.entity.reference }}
</a>
<div class="ui-grid-cell-contents">
<bh-receipt value="row.entity.uuid" display-value="row.entity.reference" type="cash">
</div>

0 comments on commit 00a208e

Please sign in to comment.