Skip to content

Commit

Permalink
fix(cash): alert when no invoices are selected
Browse files Browse the repository at this point in the history
This commit introduces a check to verify that invoices are being paid
against when a user submits the cash form.  If there are no invoices, a
danger notification is emitted telling the user to add some invoices and
no HTTP request is sent.

Previous, this would be validated on the server - the client no longer
even needs to make the HTTP request.

Closes #772.
  • Loading branch information
Jonathan Niles authored and sfount committed Nov 25, 2016
1 parent 659e844 commit cd1fe74
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
5 changes: 3 additions & 2 deletions client/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,16 @@
"LINK" : "Click here to add it.",
"MISSING" : "Don't see your cashbox?",
"TRANSFER" : "Transfer Funds",
"NO_CASHBOX_SELECTED" : "You have no selected a cashbox. Please select a cashbox to continue",
"NO_INVOICES_ASSIGNED" : "You have not assigned any invoices! Please assign at least one invoice to the payment.",
"NO_CASHBOX_SELECTED" : "You have no selected a cashbox. Please select a cashbox to continue.",
"SELECTED" : "Selected cash"
},
"DEBTOR_INVOICES" : "Debtor Invoices",
"RECEIPTS_TITLE" : "Cash Payment Receipt",
"REPORT" : "Report",
"SLIP" : "Cash Voucher",
"TITLE" : "Cash Window",
"SELECTED" : "Selected Invoices"
"SELECTED" : "Selected Invoices"
}
},
"CASHBOX": {
Expand Down
3 changes: 2 additions & 1 deletion client/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@
"CURRENT_CASHBOX" : "Caisse auxilliare courant",
"LINK" : "Cliquez ici pour l'ajouter.",
"MISSING" : "Vous ne trouvez pas votre caisse?",
"NO_CASHBOX_SELECTED" : "Vous avez pas sélectionné une caisse. S'il vous plaît choisir une caisse pour continuer",
"NO_INVOICES_ASSIGNED" : "Vous n'avez pas sélectionné des factures! S'il vous plaît choisir des factures pour continuer.",
"NO_CASHBOX_SELECTED" : "Vous n'avez pas sélectionné une caisse. S'il vous plaît choisir une caisse pour continuer.",
"SELECTED" : "Selectionnée",
"TRANSFER" : "Transférer Fonds"
},
Expand Down
13 changes: 10 additions & 3 deletions client/src/partials/cash/cash.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,24 @@ function CashController(Cash, Cashboxes, AppCache, Currencies, Exchange, Session
vm.payment.cashbox_id = vm.cashbox.id;

// patient invoices are covered by caution
var hascaution = vm.slip && vm.patientBalance > 0;
var hasCaution = vm.slip && vm.patientBalance > 0;
var isCaution = Number(vm.payment.is_caution);
var hasInvoices = vm.payment.invoices && vm.payment.invoices.length > 0;

// if the this is not a caution payment, but no invoices are selected,
// raise an error.
if (!isCaution && !hasInvoices) {
return Notify.danger('CASH.VOUCHER.NO_INVOICES_ASSIGNED');
}

// submit the cash payment
if (hascaution) {
if (hasCaution) {
return Modals.confirm('CASH.CONFIRM_PAYMENT_WHEN_CAUTION')
.then(function (ans) {
if (!ans) { return; }
return submitPayment(form);
})
.catch(Notify.handleError);

} else {
return submitPayment(form);
}
Expand Down
25 changes: 25 additions & 0 deletions test/end-to-end/cash/cash.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,31 @@ describe('Cash Payments', function () {
$('[data-action="close"]').click();
});

it('should block invoice payments without invoices', function () {

// select the proper patient
components.findPatient.findByName(mockCautionPayment.patientName);

// we will leave the date input as default

// select the proper is caution type
var cautionOption = element(by.css('[data-caution-option="0"]'));
cautionOption.click();

// select the FC currency from the currency select
components.currencySelect.set(1);

// enter the amount to pay for a caution
components.currencyInput.set(mockCautionPayment.amount);

// click the submit button
FU.buttons.submit();

// expect a danger notification
components.notification.hasDanger();
components.findPatient.reset();
});

it('should make a payment against previous invoices', function () {
var gridId = 'debtorInvoicesGrid';

Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/shared/components/bhCurrencyInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
// it might be clearer to do this in two steps.
var root = element(id ? by.id(id) : by.css(this.selector));
var elm = root.element(by.model('$ctrl.model'));
elm.sendKeys(value);
elm.clear().sendKeys(value);
},

/**
Expand Down
4 changes: 4 additions & 0 deletions test/end-to-end/shared/components/bhFindPatient.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,9 @@ module.exports = {
// submit the id to the server
var submit = element(by.css('[data-find-patient-submit]'));
submit.click();
},

reset : function reset() {
$('[ng-click="$ctrl.reset()"]').click();
}
};

0 comments on commit cd1fe74

Please sign in to comment.