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 Third-Culture-Software#772.
  • Loading branch information
Jonathan Niles committed Nov 11, 2016
1 parent 98f0d4a commit e7a30ac
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 9 deletions.
15 changes: 8 additions & 7 deletions client/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
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 @@ -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"
},
Expand Down
9 changes: 9 additions & 0 deletions client/src/partials/cash/cash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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 e7a30ac

Please sign in to comment.