[Bug 33756] New: Wrong calculation of total amount spent?
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33756 Bug ID: 33756 Summary: Wrong calculation of total amount spent? Change sponsored?: --- Product: Koha Version: unspecified Hardware: All OS: All Status: NEW Severity: minor Priority: P5 - low Component: Acquisitions Assignee: koha-bugs@lists.koha-community.org Reporter: katrin.fischer@bsz-bw.de QA Contact: testopia@bugs.koha-community.org I am trying to work out something in acquisitions and stumbled on this bit: https://git.koha-community.org/Koha-community/Koha/src/branch/master/C4/Budg... # Get all the budgets totals in as few queries as possible my $hr_budget_spent = $dbh->selectall_hashref(q| SELECT aqorders.budget_id, aqbudgets.budget_parent_id, SUM( | . C4::Acquisition::get_rounding_sql(qq|COALESCE(unitprice_tax_included, ecost_tax_included)|) . q| * quantity ) AS budget_spent FROM aqorders JOIN aqbudgets USING (budget_id) WHERE quantityreceived > 0 AND datecancellationprinted IS NULL GROUP BY budget_id, budget_parent_id |, 'budget_id'); If the amount is spent, I feel multiplying by quantity is incorrect. It should be quantityreceived. I am not sure yet where this is used and how it manifests. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33756 Emmi Takkinen <emmi.takkinen@koha-suomi.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |emmi.takkinen@koha-suomi.fi --- Comment #1 from Emmi Takkinen <emmi.takkinen@koha-suomi.fi> --- It's used at least in page "Funds for budget..." (/cgi-bin/koha/admin/aqbudgets.pl?budget_period_id=[budget_period_id]). Sums in columns "Base-level spent" and "Total spent" are currently counted based on how many items have been ordered, not how many items are already received and how much this has costed. So the sums are too high. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33756 Emmi Takkinen <emmi.takkinen@koha-suomi.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |emmi.takkinen@koha-suomi.fi |ity.org | Status|NEW |ASSIGNED -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33756 Mathieu Saby <mathsabypro@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |mathsabypro@gmail.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33756 Emmi Takkinen <emmi.takkinen@koha-suomi.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #183111|0 |1 is obsolete| | --- Comment #3 from Emmi Takkinen <emmi.takkinen@koha-suomi.fi> --- Created attachment 185209 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=185209&action=edit Bug 33756: Use aqorders.quantityreceived to calculate total amount spent We currently use aqorders.quantity to calculate how much funds have been spent for orders. This leads to situation where sum doesn't match the amount which has been already spented. This patch changes this by using quantityreceived column instead of quantity column to calculate spented funds. This test plan assumes that you already have budgets and orders in your database. To test: 1. Find an existing fund where some of the ordered items have been received and look up their budget_id. Use this report if needed: SELECT budget_id, budget_code FROM aqbudgets WHERE budget_id IN( SELECT budget_id FROM aqorders WHERE quantity != quantityreceived AND quantityreceived > 0) 2. Set syspref CalculateFundValuesIncludingTax as "Exclude". 3. Add following report to your report library: SELECT SUM(quantity), SUM(quantityreceived), SUM(unitprice_tax_excluded * quantity) AS "Budget spent by quantity", SUM(unitprice_tax_excluded * quantityreceived) AS "Budget spent by quantity received" FROM aqorders WHERE budget_id= [budget_id from step 1.] 3. Search your chosen budget from Funds page (/cgi-bin/koha/admin/aqbudgets.pl). 4. Compare funds tables "Base-level spent" and "Total spent" columns with report results. => Note that both column values match value in reports "Budget spent by quantity" columns value. 5. Apply this patch. 6. Refresh funds table. => Note that now column values match value in reports "Budget spent by quantity received" columns value. Also prove that t/db_dependent/Budgets.t and t/db_dependent/Budgets/CloneBudgetHierarchy.t still pass. Sponsored-by: Koha-Suomi Oy -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33756 --- Comment #4 from Emmi Takkinen <emmi.takkinen@koha-suomi.fi> --- Fixed a typo in test plan. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33756 --- Comment #5 from Mathieu Saby <mathsabypro@gmail.com> --- I am trying to test, but your report SELECT budget_id, budget_code FROM aqbudgets WHERE budget_id IN( SELECT budget_id FROM aqorders WHERE quantity != quantityreceived AND quantityreceived > 0) never seems to give any result. It seem logical, since when a partial reception is made for a book ordered in multiple copies, Koha create a new order line. In which situation is the condition (quantity != quantityreceived AND quantityreceived > 0) supposed to return true ? I did not test further for the moment. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33756 --- Comment #6 from Emmi Takkinen <emmi.takkinen@koha-suomi.fi> --- (In reply to Mathieu Saby from comment #5)
I am trying to test, but your report
SELECT budget_id, budget_code FROM aqbudgets WHERE budget_id IN( SELECT budget_id FROM aqorders WHERE quantity != quantityreceived AND quantityreceived > 0)
never seems to give any result. It seem logical, since when a partial reception is made for a book ordered in multiple copies, Koha create a new order line.
In which situation is the condition (quantity != quantityreceived AND quantityreceived > 0) supposed to return true ?
I did not test further for the moment.
It should return orders where quantity a.k.a. how many items has been ordered within a single order doesn't yet match the quantity of received items. Condition quantityreceived > 0 then leaves out those orders where none of the ordered items hasn't yet been received. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33756 --- Comment #7 from Mathieu Saby <mathsabypro@gmail.com> --- Thanks, I will give another look at the end of the month. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33756 --- Comment #8 from Emmi Takkinen <emmi.takkinen@koha-suomi.fi> --- Looking this some more I noticed that sub GetBudgetSpent also multiplies by quantity. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33756 Emmi Takkinen <emmi.takkinen@koha-suomi.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #185209|0 |1 is obsolete| | --- Comment #9 from Emmi Takkinen <emmi.takkinen@koha-suomi.fi> --- Created attachment 188621 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=188621&action=edit Bug 33756: Use aqorders.quantityreceived to calculate total amount spent We currently use aqorders.quantity to calculate how much funds have been spent for orders. This leads to situation where sum doesn't match the amount which has been already spented. This patch changes this by using quantityreceived column instead of quantity column to calculate spented funds. This test plan assumes that you already have budgets and orders in your database. To test: 1. Find an existing fund where some of the ordered items have been received and look up their budget_id. Use this report if needed: SELECT budget_id, budget_period_id, budget_code FROM aqbudgets WHERE budget_id IN( SELECT budget_id FROM aqorders WHERE quantity != quantityreceived AND quantityreceived > 0) 2. Set syspref CalculateFundValuesIncludingTax as "Exclude". 3. Add following report to your report library: SELECT SUM(quantity), SUM(quantityreceived), SUM(unitprice_tax_excluded * quantity) AS "Budget spent by quantity", SUM(unitprice_tax_excluded * quantityreceived) AS "Budget spent by quantity received" FROM aqorders WHERE budget_id= [budget_id from step 1.] 3. Search your chosen budget from Funds page navigate to address /cgi-bin/koha/admin/aqbudgets.pl?budget_period_id=[budget_period_id from step 1.] and then filter table with budget_code from step 1. 4. Compare funds tables "Base-level spent" and "Total spent" columns with report results. => Note that both column values match value in reports "Budget spent by quantity" columns value. 5. Apply this patch. 6. Refresh funds table. => Note that now column values match value in reports "Budget spent by quantity received" columns value. Also prove that t/db_dependent/Budgets.t and t/db_dependent/Budgets/CloneBudgetHierarchy.t still pass. Sponsored-by: Koha-Suomi Oy -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33756 --- Comment #10 from Emmi Takkinen <emmi.takkinen@koha-suomi.fi> --- I improved test plan a bit, it now clearly states from which page you should search your budget. I also checked sub GetBudgetSpent more closely and should it also use quantityreceived instead of quantity, but I think it's best if someone more knowledgeable could also take a look and maybe we can solve possible issues with in another bug. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33756 --- Comment #11 from Mathieu Saby <mathsabypro@gmail.com> --- Thanks, I won't have time to retest it, but I hope someone else will be able to. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33756 Michaela Sieber <michaela.sieber@kit.edu> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=42598 -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org