Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Fixes Issue 467 #538

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 12 additions & 0 deletions app/invoices/payment/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ import Ember from 'ember';
import PatientSubmodule from 'hospitalrun/mixins/patient-submodule';

export default AbstractEditController.extend(PatientSubmodule, {
closeModalAction: 'cleanup',
cancelAction: 'closeModal',
findPatientVisits: false,
invoiceController: Ember.inject.controller('invoices'),
newPayment: false,

actions: {
cleanup: function() {
var model = this.model;
this.model.validate().then(function() {
model.save();
Copy link
Member

Choose a reason for hiding this comment

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

This cleanup code should not save the model because the model should not be saved on the cancel action, it should only be saved when the user clicks on the update/add action which is already handled elsewhere in the controller.

}).catch(function() {
model.destroyRecord();
});
}
},

expenseAccountList: Ember.computed.alias('invoiceController.expenseAccountList'),
patientList: Ember.computed.alias('invoiceController.patientList'),

Expand Down
1 change: 1 addition & 0 deletions app/invoices/payment/template.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{#modal-dialog
closeModalAction=closeModalAction
isUpdateDisabled=isUpdateDisabled
title=title
updateButtonAction=updateButtonAction
Expand Down
18 changes: 14 additions & 4 deletions app/models/invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default AbstractModel.extend(DateFormat, NumberFormat, {
visit: DS.belongsTo('visit', {
async: false
}),
lastUnpaidStatus: DS.attr('string'),
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this status is necessary. See code comments below.

status: DS.attr('string'),
remarks: DS.attr('string'),
billDate: DS.attr('date'),
Expand Down Expand Up @@ -108,14 +109,23 @@ export default AbstractModel.extend(DateFormat, NumberFormat, {
patientResponsibility: Ember.computed.sum('patientResponsibilityTotals'),

paymentAmountChanged: function() {
var payments = this.get('payments'),
paidTotal = payments.reduce(function(previousValue, payment) {
var payments = this.get('payments');
Copy link
Member

Choose a reason for hiding this comment

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

I think this code block could be simplified to just keep track of if the payments are valid and then set the status to paid if remainingBalance <=0 and hasValidPayments === true. There really isn't a need to do anything if those conditions are untrue. There shouldn't be a need to reset the status back to the status it is already set to.

var hasValidPayments = false;
var paidTotal = payments.reduce(function(previousValue, payment) {
if (payment.get('isValid')) {
hasValidPayments = true;
return previousValue += this._getValidNumber(payment.get('amount'));
}.bind(this), 0);
}
}.bind(this), 0);
this.set('paidTotal', this._numberFormat(paidTotal, true));
var remainingBalance = this.get('remainingBalance');
if (remainingBalance <= 0) {
if (remainingBalance <= 0 && hasValidPayments) {
if (this.get('status') !== 'Paid') {
this.set('lastUnpaidStatus', this.get('status'));
}
this.set('status', 'Paid');
} else if (this.get('status') == 'Paid') {
this.set('status', this.get('lastUnpaidStatus'));
}
}.observes('payments.[]', '[email protected]'),

Expand Down