Skip to content

Commit

Permalink
fix(reports): Open Debtors respects order param
Browse files Browse the repository at this point in the history
This commit fixes a bug with the Open Debtors report where the report
did not respect the ordering parameter.  It also refactors the ordering
to have more succinct code as well as a clearer select by combining last
invoice and last payment into a simpler "last transaction".
  • Loading branch information
jniles committed Aug 14, 2017
1 parent ea6823b commit 118e6df
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 150 deletions.
7 changes: 3 additions & 4 deletions client/src/i18n/en/report.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@
},
"OPENING_BALANCE": "Opening Balance",
"ORDER": {
"LAST_INVOICE": "Date of last invoice",
"LAST_PAYMENT": "Date of last payment",
"PATIENT_NAME": "Nom du patient",
"TOTAL_DEBT": "Total Debts"
"LAST_TRANSACTION": "Date of Last Transaction",
"PATIENT_NAME": "Patient Name",
"TOTAL_DEBT": "Total Debt"
},
"OVER_NINETY_DAYS": "Over 90 Days",
"PERIOD_START": "Start",
Expand Down
174 changes: 89 additions & 85 deletions client/src/i18n/en/tree.json
Original file line number Diff line number Diff line change
@@ -1,85 +1,89 @@
{"TREE":{"ACCOUNT":"Account",
"ACCOUNT_STATEMENT":"Account Statement",
"ADMIN":"Admin",
"AGED_CREDITORS":"Aged Debts",
"BALANCE":"Balance",
"BALANCE_SHEET":"Balance Sheet",
"BALANCE_REPORT":"Balance of accounts",
"BILLING_SERVICES":"Billing Services",
"CASH_REPORT" : "Cash Report",
"CASHBOX_MANAGEMENT":"Cashbox Management",
"CASHFLOW":"Cashflow",
"CASHFLOW_BY_SERVICE":"Cashflow by Service",
"CASH_PAYMENT_REGISTRY":"Cash Payment Registry",
"CASH_WINDOW":"Cash Window",
"COMPLEX_JOURNAL_VOUCHER":"Journal Vouchers",
"COST_CENTER_MGMT":"Cost Center Management",
"CREDIT_NOTE":"Credit note",
"CREDITOR_GROUP":"Creditor Group Management",
"CURRENCY":"Currency",
"CUSTOMER_DEBTS":"Customer Debts",
"DEBTOR_GROUP":"Debtor Group Management",
"DEPOTS":"Depots Management",
"EMPLOYEE":"Employee",
"EMPLOYEE_REGISTRY" : "Employees registry",
"ENTERPRISE":"Enterprise",
"EXCHANGE":"Exchange Rate",
"FINANCE":"Finance",
"FISCAL_YEAR":"Fiscal Year",
"FONCTION":"Job titles management",
"GENERAL_LEDGER":"General Ledger",
"GRADE_EMPLOYERS":"Grade Employees",
"HOSPITAL":"Hospital",
"INCOME_EXPENSE":"Income and Expenses",
"INVENTORY":"Inventory",
"INVENTORY_CONFIGURATION":"Configurations",
"INVENTORY_GROUP":"Group",
"INVENTORY_LIST":"List",
"INVENTORY_MANAGEMENT":"Inventory Management",
"INVENTORY_TYPE":"Type",
"INVENTORY_UNIT":"Dosage Form",
"INVENTORY_VIEW":"Stock",
"INVOICE_REGISTRY":"Invoice Registry",
"JOURNAL_VOUCHER":"Journal Voucher",
"LOCATION":"Locations Management",
"PAYROLL":"Payroll",
"PATIENT_DOCUMENT":"Patient Documents",
"PATIENT_GRP":"Patient Groups",
"PATIENT_GRP_ASSIGNMENT":"Patient Group Assignment",
"PATIENT_INVOICE":"Patient Invoice",
"PATIENT_RECORDS":"Patient Records",
"PATIENT_REGISTRATION":"Patient Registration",
"PATIENT_REGISTRATIONS":"Patient Registrations",
"PATIENT_REGISTRY":"Patients Registry",
"PHARMACY":"Pharmacy Management",
"POSTED_JOURNAL":"Posted Journal",
"POSTING_JOURNAL":"Posting Journal",
"PRICE_LIST":"Price List",
"PROJECT":"Projects",
"PURCHASE_ORDER":"Purchase Order",
"PURCHASE":"Purchase",
"PURCHASE_REGISTRY":"Purchase Registry",
"PURCHASING":"Purchasing",
"REFERENCE":"Reference",
"REFERENCE_GROUP":"Reference Group",
"REGISTER_SUPPLIER":"Supplier",
"REPORTS":"Reports",
"REPORT_ACCOUNTS":"Report accounts",
"ROOT":"Root",
"RUBRIC_MANAGEMENT":"Rubrics Management",
"INVOICES":"Invoices",
"SECTION_BILAN":"Bilan section",
"SECTION_RESULTAT":"Result Section",
"SERVICE":"Services",
"SIMPLE_VOUCHER":"Simple Voucher",
"STOCK": "Stock",
"STOCK_INVENTORY":"Inventories in Stock",
"STOCK_REPORT": "[Stock] Inventories",
"STOCK_INVENTORY_REPORT":"[Stock] Inventory Report",
"STOCK_LOTS":"Stock Lots",
"STOCK_MOVEMENTS":"Stock Movements",
"SUBSIDY":"Subsidy Management",
"TRANSACTION_TYPE":"Transaction Types",
"USERS":"Users",
"VOUCHER_REGISTRY":"Voucher Registry",
"AGED_DEBTORS":"Aged Debtors"}}
{
"TREE": {
"ACCOUNT":"Account",
"ACCOUNT_STATEMENT":"Account Statement",
"ADMIN":"Admin",
"AGED_CREDITORS":"Aged Debts",
"BALANCE":"Balance",
"BALANCE_SHEET":"Balance Sheet",
"BALANCE_REPORT":"Balance of accounts",
"BILLING_SERVICES":"Billing Services",
"CASH_REPORT" : "Cash Report",
"CASHBOX_MANAGEMENT":"Cashbox Management",
"CASHFLOW":"Cashflow",
"CASHFLOW_BY_SERVICE":"Cashflow by Service",
"CASH_PAYMENT_REGISTRY":"Cash Payment Registry",
"CASH_WINDOW":"Cash Window",
"COMPLEX_JOURNAL_VOUCHER":"Journal Vouchers",
"COST_CENTER_MGMT":"Cost Center Management",
"CREDIT_NOTE":"Credit note",
"CREDITOR_GROUP":"Creditor Group Management",
"CURRENCY":"Currency",
"CUSTOMER_DEBTS":"Customer Debts",
"DEBTOR_GROUP":"Debtor Group Management",
"DEPOTS":"Depots Management",
"EMPLOYEE":"Employee",
"EMPLOYEE_REGISTRY" : "Employees registry",
"ENTERPRISE":"Enterprise",
"EXCHANGE":"Exchange Rate",
"FINANCE":"Finance",
"FISCAL_YEAR":"Fiscal Year",
"FONCTION":"Job titles management",
"GENERAL_LEDGER":"General Ledger",
"GRADE_EMPLOYERS":"Grade Employees",
"HOSPITAL":"Hospital",
"INCOME_EXPENSE":"Income and Expenses",
"INVENTORY":"Inventory",
"INVENTORY_CONFIGURATION":"Configurations",
"INVENTORY_GROUP":"Group",
"INVENTORY_LIST":"List",
"INVENTORY_MANAGEMENT":"Inventory Management",
"INVENTORY_TYPE":"Type",
"INVENTORY_UNIT":"Dosage Form",
"INVENTORY_VIEW":"Stock",
"INVOICE_REGISTRY":"Invoice Registry",
"JOURNAL_VOUCHER":"Journal Voucher",
"LOCATION":"Locations Management",
"PAYROLL":"Payroll",
"PATIENT_DOCUMENT":"Patient Documents",
"PATIENT_GRP":"Patient Groups",
"PATIENT_GRP_ASSIGNMENT":"Patient Group Assignment",
"PATIENT_INVOICE":"Patient Invoice",
"PATIENT_RECORDS":"Patient Records",
"PATIENT_REGISTRATION":"Patient Registration",
"PATIENT_REGISTRATIONS":"Patient Registrations",
"PATIENT_REGISTRY":"Patients Registry",
"PHARMACY":"Pharmacy Management",
"POSTED_JOURNAL":"Posted Journal",
"POSTING_JOURNAL":"Posting Journal",
"PRICE_LIST":"Price List",
"PROJECT":"Projects",
"PURCHASE_ORDER":"Purchase Order",
"PURCHASE":"Purchase",
"PURCHASE_REGISTRY":"Purchase Registry",
"PURCHASING":"Purchasing",
"REFERENCE":"Reference",
"REFERENCE_GROUP":"Reference Group",
"REGISTER_SUPPLIER":"Supplier",
"REPORTS":"Reports",
"REPORT_ACCOUNTS":"Report accounts",
"ROOT":"Root",
"RUBRIC_MANAGEMENT":"Rubrics Management",
"INVOICES":"Invoices",
"SECTION_BILAN":"Bilan section",
"SECTION_RESULTAT":"Result Section",
"SERVICE":"Services",
"SIMPLE_VOUCHER":"Simple Voucher",
"STOCK": "Stock",
"STOCK_INVENTORY":"Inventories in Stock",
"STOCK_REPORT": "[Stock] Inventories",
"STOCK_INVENTORY_REPORT":"[Stock] Inventory Report",
"STOCK_LOTS":"Stock Lots",
"STOCK_MOVEMENTS":"Stock Movements",
"SUBSIDY":"Subsidy Management",
"TRANSACTION_TYPE":"Transaction Types",
"USERS":"Users",
"VOUCHER_REGISTRY":"Voucher Registry",
"AGED_DEBTORS":"Aged Debtors"
}
}
1 change: 1 addition & 0 deletions client/src/i18n/fr/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@
"DEBTOR": "Entrer un debiteur",
"DEBTOR_GROUP": "Entrer un groupe debiteur",
"PATIENT_GROUP": "Entrer un groupe de patients",
"DATE": "Entrer la Date",
"DESCRIPTION": "Entrer une description",
"DOCUMENT_NAME": "Entrer le nom du document",
"EMAIL": "Entrer l'adresse e-mail",
Expand Down
13 changes: 6 additions & 7 deletions client/src/i18n/fr/report.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,16 @@
"MONTHLY_BALANCE":"Balance mensuelle",
"OPEN_DEBTORS":{
"DESCRIPTION":"Ce rapport affiche les débiteurs endettés",
"TITLE":"Débiteurs endettés",
"TITLE":"Débiteurs endettés",
"TREE":"Dettes des Débiteurs"
},
"OPENING_BALANCE": "Balance d'ouverture",
"ORDER": {
"LAST_INVOICE": "Date de la dernière facture",
"LAST_PAYMENT": "Date du dernier paiement",
"PATIENT_NAME": "Nom du patient",
"TOTAL_DEBT": "Total des dettes"
"LAST_TRANSACTION": "Date de la Dernière Transaction",
"PATIENT_NAME": "Nom du Patient",
"TOTAL_DEBT": "Total des Dettes"
},
"OVER_NINETY_DAYS": "Plus de 90 jours",
"OVER_NINETY_DAYS": "Plus de 90 Jours",
"PERIOD_START": "Debut",
"PERIOD_STOP": "Fin",
"PRODUCED_BY": "Produit par",
Expand Down Expand Up @@ -115,4 +114,4 @@
"VIEW_ARCHIVE":"Archives"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ OpenDebtorsConfigController.$inject = [
'bhConstants',
];


/**
* @class OpenDebtorsConfigController
*
* @description
* This controller powers the Open Debtors report. The Open Debtors report allows a user
* to see debtors with unpaid debts.
*/
function OpenDebtorsConfigController($sce, Notify, SavedReports, AppCache, reportData, $state, OpenDebtorsReports,
bhConstants) {
var vm = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,12 @@ function OpenDebtorsReportService() {
service.DESC = DESC;

service.orders = [{
label : 'REPORT.ORDER.LAST_PAYMENT',
value : 'payment-date-asc',
label : 'REPORT.ORDER.LAST_TRANSACTION',
value : 'transaction-date-asc',
direction : ASC,
}, {
label : 'REPORT.ORDER.LAST_PAYMENT',
value : 'payment-date-desc',
direction : DESC,
}, {
label : 'REPORT.ORDER.LAST_INVOICE',
value : 'invoice-date-asc',
direction : ASC,
}, {
label : 'REPORT.ORDER.LAST_INVOICE',
value : 'invoice-date-desc',
label : 'REPORT.ORDER.LAST_TRANSACTION',
value : 'transaction-date-desc',
direction : DESC,
}, {
label : 'REPORT.ORDER.PATIENT_NAME',
Expand Down
57 changes: 15 additions & 42 deletions server/controllers/finance/reports/debtors/openDebtors.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function requestOpenDebtors(params) {
// ONLY show transactions after a certain date (just show this week for example)
const dateCondition = limitDate ? `AND DATE(trans_date) >= DATE(${db.escape(reportDateLimit)})` : '';

const debtorQuery = buildDebtQuery(showDetailedView, source, dateCondition);
const debtorQuery = buildDebtQuery(showDetailedView, source, dateCondition, ordering);

const aggregateQuery = `
SELECT COUNT(DISTINCT(entity_uuid)) as numDebtors, SUM(debit_equiv - credit_equiv) as balance
Expand Down Expand Up @@ -130,7 +130,7 @@ function requestOpenDebtors(params) {

// ONLY select rows with an entity
// ONLY show debtors with a debt above 0
function buildDebtQuery(showDetailedView, source, dateCondition) {
function buildDebtQuery(showDetailedView, source, dateCondition, ordering) {
// Include complex parameters depending on detailed view Boolean requirements
const complexParameters = showDetailedView ?
', MAX(invoice.date) as latestInvoiceDate, MAX(cash.date) as latestCashDate ' :
Expand All @@ -151,52 +151,25 @@ function buildDebtQuery(showDetailedView, source, dateCondition) {
${dateCondition}
GROUP BY entity_uuid
HAVING SUM(debit_equiv - credit_equiv) > 0
ORDER by SUM(debit_equiv - credit_equiv)
ORDER BY ${ordering}
`;

return query;
}

const orderMap = {
'transaction-date-asc' : 'trans_date ASC',
'transaction-date-desc' : 'trans_date DESC',
'debt-desc' : 'balance DESC, trans_date DESC',
'debt-asc' : 'balance ASC, trans_date DESC',
'patient-name-desc' : 'patient.display_name DESC',
'patient-name-asc' : 'patient.display_name ASC',
};

const DEFAULT_ORDER = 'debt-desc';

function parseOrdering(orderParameter) {
let ordering;
switch (orderParameter) {
case 'payment-date-asc':
ordering = 'lastPaymentDate ASC';
break;

case 'payment-date-desc':
ordering = 'lastPaymentDate DESC';
break;

case 'invoice-date-asc':
ordering = 'lastInvoiceDate ASC';
break;

case 'invoice-date-desc':
ordering = 'lastInvoiceDate DESC';
break;

case 'debt-desc':
ordering = 'ledger.balance DESC';
break;

case 'patient-name-desc':
ordering = 'patient.display_name DESC';
break;

case 'patient-name-asc':
ordering = 'patient.display_name ASC';
break;

case 'debt-asc':
ordering = 'ledger.balance ASC';
break;

default:
ordering = 'cash.date ASC';
break;
}
return ordering;
return orderMap[orderParameter] || orderMap[DEFAULT_ORDER];
}

exports.report = build;

0 comments on commit 118e6df

Please sign in to comment.