Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cash): alert when no invoices are selected #937

Merged
merged 1 commit into from
Nov 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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();
}
};