Skip to content

Commit

Permalink
fix(invoice): use invoicing fees
Browse files Browse the repository at this point in the history
During a name change, we accidentally started ignoring invoicing fees in
our invoicing procedures.  This corrects the mistake and updates all
names to be "invoicing fees" from "billing services".  It also updates
the tests to reflect these changes.
  • Loading branch information
jniles committed Apr 30, 2018
1 parent 59ed5c3 commit 7182346
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions client/src/modules/invoices/templates/grid/code.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- TODO Design and implement custom typeahead template -->
<input
class="form-control"
autocomplete="off"
ng-model="row.entity.inventory_uuid"
typeahead-editable="false"
typeahead-append-to-body="true"
Expand Down
2 changes: 2 additions & 0 deletions client/src/modules/templates/bhFindPatient.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
ng-if="$ctrl.selected == $ctrl.options.findById"
ng-keypress="$ctrl.onKeyPress($event)"
translate-attr="{ 'placeholder': '{{$ctrl.selected.placeholder}}' }"
autocomplete="off"
ng-required="$ctrl.required">

<!-- search by Name -->
Expand All @@ -48,6 +49,7 @@
typeahead-template-url="/modules/templates/patientList.tmpl.html"
typeahead-on-select="$ctrl.submit($item)"
translate-attr="{ 'placeholder': '{{$ctrl.selected.placeholder}}' }"
autocomplete="off"
ng-required="$ctrl.required">

<!-- submit button for search by ID -->
Expand Down
32 changes: 16 additions & 16 deletions server/controllers/finance/invoice/patientInvoice.create.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = createInvoice;
/**
* POST /invoices
*
* The function is responsible for billing a patient and calculating the total
* The function is responsible for invoicing a patient and calculating the total
* due on their invoice. It will create a record in the `invoice` table.
*
* Up to three additional tables may be affected:
Expand All @@ -33,23 +33,23 @@ module.exports = createInvoice;
* 1. First, the total sum of the invoice items are recorded as sent from the
* client. The Patient Invoice module is allowed to edit the item costs as it
* sees fit, so we use the POSTed costs.
* 2. Next, each billing service is added to the invoice by writing records to
* the `invoice_invoicing_fee` table. The cost of each billing service is
* determined by multiplying the billing service's value (as a percentage) to
* 2. Next, each invoicing fee is added to the invoice by writing records to
* the `invoice_invoicing_fee` table. The cost of each invoicing fee is
* determined by multiplying the invoicing fee's value (as a percentage) to
* the total invoice cost.
* 3. Finally, the subsidy for the bill is determined. NOTE - as of #343, we
* are only allowing a single subsidy per invoice. The array of subsidies is
* treated identically to the invoicing_fees, except that it subtracts from
* the total bill amount.
*
* @todo - change the API to pass in only an array of billingService and subsidy
* @todo - change the API to pass in only an array of invoicingFee and subsidy
* ids.
*/
function createInvoice(invoiceDetails) {
const transaction = db.transaction();
const invoiceUuid = db.bid(invoiceDetails.uuid || uuid());

const billingServices = processBillingServices(invoiceUuid, invoiceDetails.billingServices);
const invoicingFees = processInvoicingFees(invoiceUuid, invoiceDetails.invoicingFees);
const subsidies = processSubsidies(invoiceUuid, invoiceDetails.subsidies);
const items = processInvoiceItems(invoiceUuid, invoiceDetails.items);

Expand All @@ -59,8 +59,8 @@ function createInvoice(invoiceDetails) {
transaction.addQuery('CALL StageInvoice(?)', [invoice]);
items.forEach(item =>
transaction.addQuery('CALL StageInvoiceItem(?)', [item]));
billingServices.forEach(billingService =>
transaction.addQuery('CALL StageBillingService(?)', [billingService]));
invoicingFees.forEach(invoicingFee =>
transaction.addQuery('CALL StageInvoicingFee(?)', [invoicingFee]));
subsidies.forEach(subsidy =>
transaction.addQuery('CALL StageSubsidy(?)', [subsidy]));

Expand All @@ -85,7 +85,7 @@ function processInvoice(invoiceUuid, invoice) {

// cleanup details not directly tied to invoice
delete invoice.items;
delete invoice.billingServices;
delete invoice.invoicingFees;
delete invoice.subsidies;
delete invoice.reference;

Expand All @@ -98,22 +98,22 @@ function processInvoice(invoiceUuid, invoice) {
}

/**
* @method processBillingServices
* @method processInvoicingFees
*
* @description
* Maps an array of billing service ids into billing service ids and invoice
* Maps an array of invoicing fee ids into invoicing fee ids and invoice
* UUID tuples.
*
* @param {Buffer} invoiceUuid - the binary invoice UUID
* @param {Array|Undefined} subsidiesDetails - an array of billing service ids
* @param {Array|Undefined} subsidiesDetails - an array of invoicing fee ids
* if they exist.
* @returns {Array} - a possibly empty array billing service ids and invoice UUID pairs.
* @returns {Array} - a possibly empty array invoicing fee ids and invoice UUID pairs.
*
* @private
*/
function processBillingServices(invoiceUuid, billingServiceDetails) {
const billingServices = billingServiceDetails || [];
return billingServices.map(billingServiceId => [billingServiceId, invoiceUuid]);
function processInvoicingFees(invoiceUuid, invoicingFeeDetails) {
const invoicingFees = invoicingFeeDetails || [];
return invoicingFees.map(invoicingFeeId => [invoicingFeeId, invoiceUuid]);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions test/integration/patientInvoice.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint no-unused-expressions:"off" */
/* global expect, agent */

const helpers = require('./helpers');
Expand Down Expand Up @@ -284,8 +285,8 @@ function InvoicingFeeScenario() {
// ensure the data in the database is correct
const invoice = res.body;

// this is the invoice cost ($100) + 20% ($20) of billing service
expect(invoice.cost).to.equal(100);
// this is the invoice cost ($100) + 20% ($20) of invoicing fee
expect(invoice.cost).to.equal(120);
expect(invoice.items).to.have.length(2);
})
.catch(helpers.handler);
Expand Down

0 comments on commit 7182346

Please sign in to comment.