Skip to content

Commit

Permalink
fix(cash): use patient name in description
Browse files Browse the repository at this point in the history
The cash payments module now uses the patient's name instead of the
username in the description. This allows the journal to filter on the
patient name instead of redundant data.
  • Loading branch information
Jonathan Niles authored and sfount committed Dec 3, 2016
1 parent abc42cc commit 3aa2658
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
20 changes: 10 additions & 10 deletions client/src/js/services/CashService.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@ CashService.$inject = [
*/
function CashService(Modal, Api, Exchange, Session, moment, $http, util) {
var service = new Api('/cash/');
var baseUrl = '/cash/';
var urlCheckin = '/cash/checkin/';


// templates for descriptions
var TRANSFER_DESCRIPTION = 'Transfer Voucher / :date / :user';
var PAYMENT_DESCRIPTION = 'Cash Payment/ :date / :user';
var CAUTION_DESCRIPTION = 'Caution Payment / :date / :user';
var TRANSFER_DESCRIPTION = 'Transfer Voucher / :date / :name';
var PAYMENT_DESCRIPTION = 'Cash Payment/ :date / :name';
var CAUTION_DESCRIPTION = 'Caution Payment / :date / :name';

// custom methods
service.create = create;
service.getTransferRecord = getTransferRecord;
service.calculateDisabledIds = calculateDisabledIds;
service.formatCashDescription = formatCashDescription;
service.formatFilterParameters = formatFilterParameters;
service.openCancelCashModal = openCancelCashModal;
service.checkCashPayment = checkCashPayment;
service.checkCashPayment = checkCashPayment;

/**
* Cash Payments can be made to multiple invoices. This function loops
Expand Down Expand Up @@ -75,8 +74,6 @@ function CashService(Modal, Api, Exchange, Session, moment, $http, util) {
data.items = allocatePaymentAmounts(data);
}

data.description = formatCashDescription(payment.date, payment.is_caution);

// remove data.invoices property before submission to the server
delete data.invoices;

Expand All @@ -87,12 +84,15 @@ function CashService(Modal, Api, Exchange, Session, moment, $http, util) {
/*
* Nicely format the cash payment description
*/
function formatCashDescription(date, isCaution) {
function formatCashDescription(patient, payment) {
var isCaution = payment.is_caution;
var date = payment.date;

var tmpl = isCaution ? CAUTION_DESCRIPTION : PAYMENT_DESCRIPTION;

return tmpl
.replace(':date', moment(date).format('YYYY-MM-DD'))
.replace(':user', Session.user.display_name);
.replace(':name', patient.display_name);
}

/**
Expand Down
18 changes: 11 additions & 7 deletions client/src/partials/cash/cash.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,14 @@ function CashController(Cash, Cashboxes, AppCache, Currencies, Exchange, Session
vm.patient = patient;

Patient.balance(vm.patient.debtor_uuid)
.then(function (balance) {
/**
* balance < 0 means that enterprise must money to the patient (creditor balance)
* multiply by -1 means we want work with positive value if the patient has a creditor balance
*/
vm.patientBalance = balance * -1;
});
.then(function (balance) {
/**
* balance < 0 means that enterprise must money to the patient (creditor balance)
* multiply by -1 means we want work with positive value if the patient has a creditor balance
*/
vm.patientBalance = balance * -1;
})
.catch(Notify.handleError);
}

// caches the cashbox
Expand Down Expand Up @@ -159,6 +160,9 @@ function CashController(Cash, Cashboxes, AppCache, Currencies, Exchange, Session
return Notify.danger('CASH.VOUCHER.NO_INVOICES_ASSIGNED');
}

// format the cash payment description
vm.payment.description = Cash.formatCashDescription(vm.patient, vm.payment);

// submit the cash payment
if (hasCaution) {
return Modals.confirm('CASH.CONFIRM_PAYMENT_WHEN_CAUTION')
Expand Down

0 comments on commit 3aa2658

Please sign in to comment.