Skip to content

Commit

Permalink
feat(cash): implement client delete record
Browse files Browse the repository at this point in the history
This commit implements the client-side for deleting a cash record.  It
simply adds a new value to the dropdown that can be clicked to remove
the record.

TODO - add end-to-end tests.

Closes #2159.
  • Loading branch information
jniles committed Oct 13, 2017
1 parent 144d9f7 commit 5c500b6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 20 deletions.
4 changes: 3 additions & 1 deletion client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"CONNECTION": "Connexion",
"CSV_EXPORT": "Export CSV",
"DELETE": "Delete",
"DELETE_RECORD": "Delete Record",
"DISMISS": "Dismiss",
"EDIT": "Edit",
"EDIT_PERMISSIONS": "Permission",
Expand Down Expand Up @@ -154,7 +155,8 @@
"UPDATE_SUCCESS": "Updated successfully",
"UPLOAD_PICTURE_FAILED": "The selected file is not an picture",
"VIEW_BEGINNING_BALANCE": "View Beginning Balance",
"VIEW_CLOSING_BALANCE": "View Closing Balance"
"VIEW_CLOSING_BALANCE": "View Closing Balance",
"DELETE_RECORD_SUCCESS": "Successfully deleted the record."
},
"LABELS": {
"ABBREVIATION": "Abbreviation",
Expand Down
4 changes: 3 additions & 1 deletion client/src/i18n/fr/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"CONNECTION": "Connexion",
"CSV_EXPORT": "Exporter en CSV",
"DELETE": "Supprimer",
"DELETE_RECORD": "Supprimer Enregistrement",
"DISMISS": "Rejeter",
"EDIT": "Editer",
"EDIT_PERMISSIONS": "Editer permission",
Expand Down Expand Up @@ -154,7 +155,8 @@
"VIEW_CLOSING_BALANCE": "Aperçue de la balance de cloture",
"UNPOSTED_TRANSACTION": "Transactions non-posté ne sont pas affichées",
"TRANSACTIONS": "Transactions",
"ROWS": "enregistrements"
"ROWS": "enregistrements",
"DELETE_RECORD_SUCCESS": "Supprimèe la transaction avec succès."
},
"LABELS": {
"ABBREVIATION": "Abbreviation",
Expand Down
24 changes: 21 additions & 3 deletions client/src/modules/cash/cash.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ angular.module('bhima.services')
.service('CashService', CashService);

CashService.$inject = [
'$uibModal', 'PrototypeApiService', 'ExchangeRateService', 'SessionService', 'moment', '$translate',
'FilterService', 'appcache', 'PeriodService', 'LanguageService', '$httpParamSerializer',
'$uibModal', 'PrototypeApiService', 'ExchangeRateService', 'SessionService',
'moment', '$translate', 'FilterService', 'appcache', 'PeriodService',
'LanguageService', '$httpParamSerializer',
];

/**
Expand All @@ -13,7 +14,10 @@ CashService.$inject = [
* @description
* A service to interact with the server-side /cash API.
*/
function CashService(Modal, Api, Exchange, Session, moment, $translate, Filters, AppCache, Periods, Languages, $httpParamSerializer) {
function CashService(
Modal, Api, Exchange, Session, moment, $translate, Filters, AppCache, Periods,
Languages, $httpParamSerializer
) {
var service = new Api('/cash/');
var urlCheckin = '/cash/checkin/';

Expand All @@ -22,6 +26,7 @@ function CashService(Modal, Api, Exchange, Session, moment, $translate, Filters,

// custom methods
service.create = create;
service.remove = remove;
service.calculateDisabledIds = calculateDisabledIds;
service.formatCashDescription = formatCashDescription;
service.openCancelCashModal = openCancelCashModal;
Expand Down Expand Up @@ -98,6 +103,19 @@ function CashService(Modal, Api, Exchange, Session, moment, $translate, Filters,
});
}

/**
* @method remove
*
* @description
* This function removes a cash payment from the database via the transaction
* delete route.
*/
function remove(uuid) {
var url = '/transactions/'.concat(uuid);
return service.$http.delete(url)
.then(service.util.unwrapHttpResponse);
}

/**
* @method calculateDisabledIds
*
Expand Down
20 changes: 17 additions & 3 deletions client/src/modules/cash/payments/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function CashPaymentRegistryController(
) {
var vm = this;

// Background color for make the difference between the valid and cancel paiement
// background color for make the difference between the valid and canceled payment
var reversedBackgroundColor = { 'background-color' : '#ffb3b3' };
var regularBackgroundColor = { 'background-color' : 'none' };
var cacheKey = 'payment-grid';
Expand All @@ -45,6 +45,7 @@ function CashPaymentRegistryController(
vm.cancelCash = cancelCash;
vm.openColumnConfigModal = openColumnConfigModal;
vm.clearGridState = clearGridState;
vm.deleteCashPayment = deleteCashPayment;
vm.download = Cash.download;

columnDefs = [{
Expand Down Expand Up @@ -115,7 +116,7 @@ function CashPaymentRegistryController(
function clearGridState() {
state.clearGridState();
$state.reload();
};
}

function handleError(error) {
vm.hasError = true;
Expand All @@ -128,7 +129,7 @@ function CashPaymentRegistryController(
Modal.openSearchCashPayment(filtersSnapshot)
.then(function (changes) {
Cash.filters.replaceFilters(changes);

Cash.cacheFilters();
vm.latestViewFilters = Cash.filters.formatView();

Expand Down Expand Up @@ -203,5 +204,18 @@ function CashPaymentRegistryController(
gridColumns.openConfigurationModal();
}

// this function deletes the
function deleteCashPayment(entity) {
Cash.remove(entity.uuid)
.then(function () {
Notify.success('FORM.INFO.DELETE_RECORD_SUCCESS');

// load() has it's own error handling. The absence of return below is
// explicit.
load(Cash.filters.formatHTTP(true));
})
.catch(Notify.handleError);
}

startup();
}
32 changes: 20 additions & 12 deletions client/src/modules/cash/payments/templates/action.cell.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@
<span class="caret"></span>
</a>

<ul data-action="{{ rowRenderIndex}}" class="dropdown-menu-right" uib-dropdown-menu>
<ul data-action="{{ row.entity.reference }}" class="dropdown-menu-right" uib-dropdown-menu>
<li>
<a data-method="receipt" ng-click="grid.appScope.openReceiptModal(row.entity.uuid)" data-link-receipt="{{ ::row.entity.uuid }}" href>
<a href data-method="receipt" ng-click="grid.appScope.openReceiptModal(row.entity.uuid)">
<i class="fa fa-file-pdf-o"></i> <span translate>TABLE.COLUMNS.RECEIPT</span>
</a>
</li>
<li class="divider"></li>
<li>
<a ui-sref="patientRegistry({ filters : { key : 'display_name', value : row.entity.patientName }})" data-method="viewPatient" href>
<i class="fa fa-user"></i> <span translate>REPORT.VIEW_PATIENT</span>
</a>
</li>
<li ng-show="!row.entity.is_caution">
<a data-method="viewInvoice" ui-sref="invoiceRegistry({ filters : { key : 'cash_uuid', value : row.entity.uuid }})" href>
<span class="fa fa-file-text-o"></span> <span translate>REPORT.VIEW_INVOICE</span>
</a>
</li>
<li class="divider"></li>
<li>
<a href
id="{{row.entity.reference}}"
data-method="cancel"
ng-click="grid.appScope.cancelCash(row.entity)"
ng-hide="row.entity._hasCreditNote">
Expand All @@ -23,15 +34,12 @@
<span class="text-danger"><i class="fa fa-ban"></i> <span translate>FORM.LABELS.CANCELED</span></span>
</a>
</li>
<li class="divider"></li>
<li>
<a ui-sref="patientRegistry({ filters : { key : 'display_name', value : row.entity.patientName }})" data-method="viewPatient" href>
<i class="fa fa-user"></i> <span translate>REPORT.VIEW_PATIENT</span>
</a>
</li>
<li ng-show="!row.entity.is_caution">
<a data-method="viewInvoice" ui-sref="invoiceRegistry({ filters : { key : 'cash_uuid', value : row.entity.uuid }})" href>
<span class="fa fa-file-text-o"></span> <span translate>REPORT.VIEW_INVOICE</span>

<li ng-hide="row.entity._hasCreditNote">
<a href
data-method="delete"
ng-click="grid.appScope.deleteCashPayment(row.entity)">
<span class="text-danger"><i class="fa fa-trash"></i> <span translate>FORM.BUTTONS.DELETE_RECORD</span></span>
</a>
</li>
<li class="divider"></li>
Expand Down

0 comments on commit 5c500b6

Please sign in to comment.