Skip to content

Commit

Permalink
fix(vouchers): rework prise en charge
Browse files Browse the repository at this point in the history
This commit cleans up the prise en charge voucher tool with refactors
from other modules.  It additionally adds in human readable description
text automatically on tool submission.

Closes #1956.
  • Loading branch information
jniles committed Sep 16, 2017
1 parent bf7ad45 commit a63f89d
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 60 deletions.
1 change: 1 addition & 0 deletions client/src/i18n/en/vouchers.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"TRANSFER_DESCRIPTION": "Transfer: From {{ fromAccount }} to {{ toAccount }} for {{ amount }} {{ symbol }}",
"CONVENTION_PAYMENT_DESCRIPTION": "Convention Payment: Payment for {{ numInvoices }} invoice(s) by {{ debtorGroupName }}.",
"CONVENTION_INVOICES":"Convention - Invoices payment",
"SUPPORT_PAYMENT_DESCRIPTION":"Debt transfer from {{ patientName }} ({{ patientReference}}) for {{ numInvoices }} invoice(s) {{ invoiceReferences }}.",
"SUPPORT_FORM":"Patients Support - Form",
"SUPPORT_TEXT":"When the above two fields are filled in, we will look for open debts for the patient to assign to the \"Support Patient\" Account.",
"IMPORT_TRANSACTION":"Import transactions",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/fr/vouchers.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"CASHFLOW_OPTION":"Option pour le flux de trésorerie physique",
"CONVENTION_INVOICES":"Convention - Paiement factures",
"CONVENTION_PAYMENT_DESCRIPTION": "Convention Paiement Factures: Paiement pour {{ numInvoices }} factures(s) par {{ debtorGroupName }}.",
"SUPPORT_PAYMENT_DESCRIPTION":"Prise en charge de {{ patientName }} ({{ patientReference}}) pour {{ numInvoices }} facture(s) {{ invoiceReferences }}.",
"TRANSFER_DESCRIPTION": "Transfert: De {{ fromAccount }} à {{ toAccount }} pour {{ amount }} {{ symbol }}",
"SUPPORT_FORM":"Prise en Charge des patients",
"SUPPORT_TEXT":"Lorsque les deux champs ci-dessus sont remplis, Les dettes du patient apparaissent en vue qu'une \"Prise en Charge\" puissent être attribue à un Compte.",
Expand Down
121 changes: 64 additions & 57 deletions client/src/modules/vouchers/toolkit/support_patient/support_patient.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,43 @@
angular.module('bhima.controllers')
.controller('SupportPatientKitController', SupportPatientKitController);

// DI definition
SupportPatientKitController.$inject = [
'$uibModalInstance', 'NotifyService', 'SessionService', 'data', 'bhConstants',
'DebtorService', 'VoucherToolkitService'
'$uibModalInstance', 'NotifyService', 'SessionService', 'bhConstants', 'DebtorService', '$translate',
'VoucherToolkitService',
];

// Import transaction rows for a Support Patient
function SupportPatientKitController(Instance, Notify, Session, Data, bhConstants, Debtors, ToolKits) {
function SupportPatientKitController(Instance, Notify, Session, bhConstants, Debtors, $translate, ToolKits) {
var vm = this;

var MAX_DECIMAL_PRECISION = bhConstants.precision.MAX_DECIMAL_PRECISION;

// global variables
vm.enterprise = Session.enterprise;
vm.gridOptions = {};
vm.tool = Data;
vm.patientInvoice = false;

// expose to the view
vm.selectPatientInvoices = selectPatientInvoices;
vm.close = Instance.close;
vm.import = submit;
vm.loadInvoice = loadInvoice;
vm.onSelectAccount = onSelectAccount;

// helper aggregation function
function aggregate(sum, row) {
return sum + row.balance;
}

// get debtor group invoices
function selectPatientInvoices(debtorId) {
function selectPatientInvoices(debtorUuid) {
// load patient invoices
vm.debtorUuid = debtorId;
vm.debtorUuid = debtorUuid;

Debtors.invoices(debtorId, { balanced: 0 })
Debtors.invoices(debtorUuid, { balanced : 0 })
.then(function (invoices) {
vm.gridOptions.data = invoices || [];

// total amount
vm.totalInvoices = vm.gridOptions.data.reduce(function (current, previous) {
return current + previous.balance;
}, 0);
var totals = invoices.reduce(aggregate, 0);

// make sure we are always within precision
vm.totalInvoices = Number.parseFloat(vm.totalInvoices.toFixed(MAX_DECIMAL_PRECISION));
vm.gridOptions.data = invoices || [];

vm.invoices = data;
// make sure we are always within precision
vm.totalInvoices = Number.parseFloat(totals.toFixed(MAX_DECIMAL_PRECISION));
})
.catch(Notify.handleError);
}
Expand Down Expand Up @@ -83,10 +77,10 @@ function SupportPatientKitController(Instance, Notify, Session, Data, bhConstant
row.credit = invoice.balance;

// this is needed for a nice display in the grid
row.entity = formatEntity(result.patient);
row.entity = { label : result.patient.text, type: 'D', uuid : result.patient.debtor_uuid };

// @FIXME(sfount) this was included in legacy format invoice code - it should either be derived from
// the database or ommitted
// the database or omitted
invoice.document_type = 'VOUCHERS.COMPLEX.PATIENT_INVOICE';
row.document = invoice;

Expand All @@ -97,47 +91,49 @@ function SupportPatientKitController(Instance, Notify, Session, Data, bhConstant
return rows;
}

// format entity
function formatEntity(patient) {
return {
label : patient.text,
type : 'D',
uuid : patient.debtor_uuid,
};
}

/* ================ Invoice grid parameters ===================== */
vm.gridOptions.appScopeProvider = vm;
vm.gridOptions.enableFiltering = true;
vm.gridOptions.onRegisterApi = onRegisterApi;
vm.gridOptions.fastWatch = true;
vm.gridOptions.flatEntityAccess = true;

vm.gridOptions.columnDefs = [
{ field: 'reference', displayName: 'TABLE.COLUMNS.REFERENCE', headerCellFilter: 'translate' },
{ field: 'date', cellFilter: 'date', displayName: 'TABLE.COLUMNS.BILLING_DATE', headerCellFilter: 'translate', enableFiltering: false },
{ field : 'balance',
displayName : 'TABLE.COLUMNS.BALANCE',
headerCellFilter : 'translate',
cellClass : 'text-right',
enableFiltering : false,
cellTemplate : '/modules/templates/grid/balance.cell.html',
},
];

vm.gridOptions = {
appScopeProvider : vm,
enableFiltering : true,
fastWatch : true,
flatEntityAccess : true,
enableSelectionBatchEvent : false,
onRegisterApi : onRegisterApi,
};

vm.gridOptions.columnDefs = [{
field : 'reference',
displayName : 'TABLE.COLUMNS.REFERENCE',
headerCellFilter : 'translate',
}, {
field : 'date',
cellFilter : 'date',
displayName : 'TABLE.COLUMNS.BILLING_DATE',
headerCellFilter : 'translate',
enableFiltering : false,
}, {
field : 'balance',
type : 'number',
displayName : 'TABLE.COLUMNS.BALANCE',
headerCellFilter : 'translate',
enableFiltering : true,
cellFilter : 'currency:'.concat(Session.enterprise.currency_id),
cellClass : 'text-right',
}];

function onRegisterApi(gridApi) {
vm.gridApi = gridApi;
vm.gridApi.selection.on.rowSelectionChanged(null, rowSelectionCallback);
vm.gridApi.selection.on.rowSelectionChangedBatch(null, rowSelectionCallback);
}

// called whenever the selection changes in the ui-grid
function rowSelectionCallback() {
vm.selectedRows = vm.gridApi.selection.getSelectedRows();
vm.totalSelected = vm.selectedRows.reduce(function (current, previous) {
return current + previous.balance;
}, 0);
var selected = vm.gridApi.selection.getSelectedRows();
var aggregation = selected.reduce(aggregate, 0);

vm.totalSelected = Number.parseFloat(vm.totalSelected.toFixed(MAX_DECIMAL_PRECISION));
vm.hasSelectedRows = selected.length > 0;
vm.totalSelected = Number.parseFloat(aggregation.toFixed(MAX_DECIMAL_PRECISION));
}

/* ================ End Invoice grid parameters ===================== */
Expand All @@ -146,16 +142,27 @@ function SupportPatientKitController(Instance, Notify, Session, Data, bhConstant
function submit(form) {
if (form.$invalid) { return; }

var selected = vm.gridApi.selection.getSelectedRows();

var bundle = generateTransactionRows({
account_id : vm.account_id,
patient : vm.patient,
invoices : vm.selectedRows,
invoices : selected,
});

var invoiceRefs = selected.map(function (i) { return i.reference; }).join(', ');

var msg = $translate.instant('VOUCHERS.GLOBAL.SUPPORT_PAYMENT_DESCRIPTION', {
patientName : vm.patient.display_name,
patientReference : vm.patient.reference,
invoiceReferences : invoiceRefs,
});

Instance.close({
rows : bundle,
patient : vm.patient,
type_id : bhConstants.transactionType.SUPPORT_INCOME, // Patient Support ID
description : msg,
type_id : bhConstants.transactionType.SUPPORT_INCOME,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
</bh-account-select>

<bh-find-patient
suppress-reset="false"
on-search-complete="ToolCtrl.loadInvoice(patient)"
on-register-api="ToolCtrl.onRegisterApiCallback(api)"
validation-trigger="ToolForm.$submitted"
Expand All @@ -36,7 +35,7 @@
</div>

<p ng-show="!ToolCtrl.debtorUuid" class="text-info">
<i class="fa fa-info-circle"></i> <span translate> VOUCHERS.GLOBAL.SUPPORT_TEXT </span>
<i class="fa fa-info-circle"></i> <span translate>VOUCHERS.GLOBAL.SUPPORT_TEXT</span>
</p>

<div ng-show="ToolCtrl.debtorUuid" class="text-right">
Expand All @@ -55,7 +54,7 @@
FORM.BUTTONS.CANCEL
</button>

<bh-loading-button loading-state="ToolForm.$loading" disabled="ToolCtrl.$invalid || !ToolCtrl.selectedRows.length">
<bh-loading-button loading-state="ToolForm.$loading" disabled="!ToolCtrl.hasSelectedRows">
<span translate>FORM.BUTTONS.SUBMIT</span>
</bh-loading-button>
</div>
Expand Down

0 comments on commit a63f89d

Please sign in to comment.