From e7a30acba70da60b6530ad1f28a5e2f7fa8a0997 Mon Sep 17 00:00:00 2001 From: Jonathan Niles Date: Fri, 11 Nov 2016 12:13:14 +0100 Subject: [PATCH] fix(cash): alert when no invoices are selected 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. --- client/src/i18n/en.json | 15 +++++------ client/src/i18n/fr.json | 3 ++- client/src/partials/cash/cash.js | 9 +++++++ test/end-to-end/cash/cash.spec.js | 25 +++++++++++++++++++ .../shared/components/bhCurrencyInput.js | 2 +- .../shared/components/bhFindPatient.js | 4 +++ 6 files changed, 49 insertions(+), 9 deletions(-) diff --git a/client/src/i18n/en.json b/client/src/i18n/en.json index 1ade3d32f0..0579b67fe8 100644 --- a/client/src/i18n/en.json +++ b/client/src/i18n/en.json @@ -114,15 +114,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" + "DEBTOR_INVOICES" : "Debtor Invoices", + "RECEIPTS_TITLE" : "Cash Payment Receipt", + "REPORT" : "Report", + "SLIP" : "Cash Voucher", + "TITLE" : "Cash Window", + "SELECTED" : "Selected Invoices" } }, "CASHBOX": { diff --git a/client/src/i18n/fr.json b/client/src/i18n/fr.json index 6297f4cfbb..f45654073e 100644 --- a/client/src/i18n/fr.json +++ b/client/src/i18n/fr.json @@ -120,7 +120,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" }, diff --git a/client/src/partials/cash/cash.js b/client/src/partials/cash/cash.js index 4e298b8fce..faa7a4e05f 100644 --- a/client/src/partials/cash/cash.js +++ b/client/src/partials/cash/cash.js @@ -139,6 +139,15 @@ function CashController(Cash, Cashboxes, AppCache, Currencies, Exchange, Session // add in the cashbox id vm.payment.cashbox_id = vm.cashbox.id; + 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 return Cash.create(vm.payment) .then(function (response) { diff --git a/test/end-to-end/cash/cash.spec.js b/test/end-to-end/cash/cash.spec.js index bf2ae028c4..eab0579f26 100644 --- a/test/end-to-end/cash/cash.spec.js +++ b/test/end-to-end/cash/cash.spec.js @@ -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'; diff --git a/test/end-to-end/shared/components/bhCurrencyInput.js b/test/end-to-end/shared/components/bhCurrencyInput.js index 10fafe7fb9..55e3325e51 100644 --- a/test/end-to-end/shared/components/bhCurrencyInput.js +++ b/test/end-to-end/shared/components/bhCurrencyInput.js @@ -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); }, /** diff --git a/test/end-to-end/shared/components/bhFindPatient.js b/test/end-to-end/shared/components/bhFindPatient.js index 850ff6b0f9..62e1f1b74f 100644 --- a/test/end-to-end/shared/components/bhFindPatient.js +++ b/test/end-to-end/shared/components/bhFindPatient.js @@ -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(); } };