Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the unpaid invoice report based on the issue #6184 #6196

Merged

Conversation

mbayopanda
Copy link
Collaborator

@mbayopanda mbayopanda commented Dec 15, 2021

This PR is related to #6184

image

image

image

Close #6184

Copy link
Collaborator

@jmcameron jmcameron left a comment

Choose a reason for hiding this comment

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

It looks like you have addressed all the items in the issue. Looks good!

A few minor issues

  • The currency should default to the enterprise currency. See client/src/modules/reports/generate/avg_med_costs_per_patient/avg_med_costs_per_patient.js for an example -- especially in checkCachedConfiguration().
  • When you chose a debtor Group and put its name as subtitle, I suggest using a little larger font.
  • When you select a Service, there is no need to display a separate column for it since the totals column is the same (since you are only showing one service). However, you also need to add a subtitle for the service when you remove its column.

Copy link
Collaborator

@jniles jniles left a comment

Choose a reason for hiding this comment

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

This looks good so far! I just made a few comments.

@@ -24,6 +24,10 @@ function UnbalancedInvoicePaymentsConfigController($sce, Notify, SavedReports, A
vm.reportDetails = angular.copy(report);
};

vm.onSelectCurrency = currency => {
vm.reportDetails.currencyId = currency.id;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you make this default to the enterprise currency?

@@ -66,6 +66,7 @@ async function getUnbalancedInvoices(options) {
const params = [
new Date(options.dateFrom),
new Date(options.dateTo),
+options.currencyId,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is cool, but I really worry about this being NaN. What happens then? What does MySQL convert it to?

It would be much better to convert this explicitly to something.

@jniles
Copy link
Collaborator

jniles commented Jan 4, 2022

@mbayopanda if you can get these issues sorted out, we can try and include this report in the next release. I would like to do a release this Friday.

@mbayopanda
Copy link
Collaborator Author

@jmcameron @jniles changes landed

Copy link
Collaborator

@jniles jniles left a comment

Choose a reason for hiding this comment

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

Just two more comments:

  1. If the currency isn't the enterprise currency, we should warn about that on the report.
  2. One minor performance win.

Once you fix those feel free to merge this PR.

const vm = this;
const cache = new AppCache('configure_unpaid_invoice_payments');
const reportUrl = 'reports/finance/unpaid_invoice_payments';

vm.previewGenerated = false;
vm.reportDetails = {};
vm.reportDetails = {
currencyId : Session.enterprise.currency_id,
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@@ -980,11 +984,13 @@ CREATE PROCEDURE UnbalancedInvoicePaymentsTable(
CREATE TEMPORARY TABLE `unbalanced_invoices` AS (
SELECT BUID(ivc.uuid) as invoice_uuid , em.text AS debtorReference, debtor.text AS debtorName,
BUID(debtor.uuid) as debtorUuid,
balances.debit_equiv AS debit,
balances.credit_equiv AS credit, iv.date AS creation_date, balances.balance,
(balances.debit_equiv * IFNULL(GetExchangeRate(_enterpriseId, currencyId, dateTo), 1)) AS debit,
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like you can speed this up a lot by moving the GetExchangeRate(_enterpriseId, currencyId, dateTo) out of the SQL query. Like this:

DECLARE exchangeRate DOUBLE;

SET exchangeRate = (SELECT IFNULL(GetExchangeRate(_enterpriseId, currencyId, dateTo), 1));

  CREATE TEMPORARY TABLE `unbalanced_invoices` AS (
    SELECT BUID(ivc.uuid) as invoice_uuid , em.text AS debtorReference, debtor.text AS debtorName,
      BUID(debtor.uuid) as debtorUuid,
      (balances.debit_equiv * exchangeRate) AS debit,
       /* etc ... */

This has the advantage of speeding up the query since the GetExchangeRate() function doesn't depend on the data in the table. Instead of calling it 3X per row, we only call it a single time.

{{date dateFrom "DD/MM/YYYY"}} - {{date dateTo "DD/MM/YYYY"}}
</h5>
</h4>
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the currency is not the enterprise currency, we should show a warning that this is only temporary using this warning:

https://github.com/IMA-WorldHealth/bhima/blob/c7dd1f09205a7cd009ff86318c04630828fe1052/server/controllers/stock/reports/stock_expiration_report.handlebars#L36-L40

Copy link
Collaborator

@jniles jniles left a comment

Choose a reason for hiding this comment

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

Looks good to me!

bors r+

@@ -976,15 +981,19 @@ CREATE PROCEDURE UnbalancedInvoicePaymentsTable(
-- even though this column is called "balance", it is actually the amount remaining
-- on the invoice.

SET exchangeRate = (SELECT IFNULL(GetExchangeRate(_enterpriseId, currencyId, dateTo), 1));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Beautiful 👍

@bors
Copy link
Contributor

bors bot commented Jan 5, 2022

Build succeeded:

@bors bors bot merged commit f3820ed into Third-Culture-Software:master Jan 5, 2022
@mbayopanda mbayopanda deleted the update-unpaid-invoice-report branch January 24, 2022 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Updates for the Unpaid Invoices Report
3 participants