From: blake Date: Tue, 31 Aug 2021 14:30:06 +0000 (-0500) Subject: LP1174498: Add a Payments by Billing Type Reporting View X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=8a7ba94e8a8967cac5bbd50d5ad992d48d554c4e;p=working%2FEvergreen.git LP1174498: Add a Payments by Billing Type Reporting View Fixed a bug where over payments cause duplicate rows. In other words: negative balanced bills would bug this logic. Also fixed the release note syntax. Signed-off-by: blake Signed-off-by: Jason Boyer --- diff --git a/Open-ILS/src/sql/Pg/080.schema.money.sql b/Open-ILS/src/sql/Pg/080.schema.money.sql index e25ba02f4c..3f69b37c67 100644 --- a/Open-ILS/src/sql/Pg/080.schema.money.sql +++ b/Open-ILS/src/sql/Pg/080.schema.money.sql @@ -873,7 +873,7 @@ BEGIN WHERE p.id = current_payment.id; -- If we don't do this then OPAC CC payments have no payment_ou IF NOT FOUND THEN - SELECT home_ou INTO payment_ou FROM actor.usr WHERE id = (SELECT accepting_usr FROM money.bnm_payment WHERE id = current_payment.id); + SELECT home_ou INTO payment_ou FROM actor.usr WHERE id = (SELECT accepting_usr FROM money.bnm_payment WHERE id = current_payment.id LIMIT 1); END IF; -- Were we looking at a billing from a previous step in the loop? @@ -913,7 +913,9 @@ BEGIN maintain_billing_remainder := FALSE; END IF; - RETURN NEXT current_result; + IF current_result.amount <> 0.0 THEN + RETURN NEXT current_result; + END IF; -- Done paying the billing rows when we run out of rows to pay (out of bounds) EXIT WHEN array_length(billing_id_used, 1) = billing_row_count; END IF; @@ -990,7 +992,9 @@ BEGIN billing_id_used = array_append( billing_id_used, current_billing_id ); END IF; - RETURN NEXT current_result; + IF current_result.amount <> 0.0 THEN + RETURN NEXT current_result; + END IF; IF continuing_payment_last_row THEN -- This should only occur when the account_adjustment's do not line up exactly with the billing -- So we are going to pay some other type of billing row with this odd account_adjustment @@ -1039,7 +1043,9 @@ BEGIN billing_id_used = array_append( billing_id_used, current_billing_id ); END IF; - RETURN NEXT current_result; + IF current_result.amount <> 0.0 THEN + RETURN NEXT current_result; + END IF; EXIT WHEN payment_remainder = 0.0; END LOOP; @@ -1079,7 +1085,7 @@ BEGIN WHERE p.id = current_payment.id; IF NOT FOUND THEN - SELECT home_ou INTO payment_ou FROM actor.usr WHERE id = (SELECT accepting_usr FROM money.bnm_payment WHERE id = current_payment.id); + SELECT home_ou INTO payment_ou FROM actor.usr WHERE id = (SELECT accepting_usr FROM money.bnm_payment WHERE id = current_payment.id LIMIT 1); END IF; payment_remainder = -current_payment.amount; -- invert @@ -1121,7 +1127,9 @@ BEGIN END IF; current_result.amount = -current_result.amount; - RETURN NEXT current_result; + IF current_result.amount <> 0.0 THEN + RETURN NEXT current_result; + END IF; -- Done paying the billing rows when we run out of rows to pay (out of bounds) EXIT WHEN billing_offset = billing_row_count + 1; END IF; @@ -1180,7 +1188,9 @@ BEGIN END IF; current_result.amount = -current_result.amount; - RETURN NEXT current_result; + IF current_result.amount <> 0.0 THEN + RETURN NEXT current_result; + END IF; EXIT WHEN payment_remainder = 0.0; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.money.materialized_payment_by_billing_type.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.money.materialized_payment_by_billing_type.sql index bda7d7b1c4..de84d20dc0 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.money.materialized_payment_by_billing_type.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.money.materialized_payment_by_billing_type.sql @@ -84,7 +84,7 @@ BEGIN WHERE p.id = current_payment.id; -- If we don't do this then OPAC CC payments have no payment_ou IF NOT FOUND THEN - SELECT home_ou INTO payment_ou FROM actor.usr WHERE id = (SELECT accepting_usr FROM money.bnm_payment WHERE id = current_payment.id); + SELECT home_ou INTO payment_ou FROM actor.usr WHERE id = (SELECT accepting_usr FROM money.bnm_payment WHERE id = current_payment.id LIMIT 1); END IF; -- Were we looking at a billing from a previous step in the loop? @@ -124,7 +124,9 @@ BEGIN maintain_billing_remainder := FALSE; END IF; - RETURN NEXT current_result; + IF current_result.amount <> 0.0 THEN + RETURN NEXT current_result; + END IF; -- Done paying the billing rows when we run out of rows to pay (out of bounds) EXIT WHEN array_length(billing_id_used, 1) = billing_row_count; END IF; @@ -201,7 +203,9 @@ BEGIN billing_id_used = array_append( billing_id_used, current_billing_id ); END IF; - RETURN NEXT current_result; + IF current_result.amount <> 0.0 THEN + RETURN NEXT current_result; + END IF; IF continuing_payment_last_row THEN -- This should only occur when the account_adjustment's do not line up exactly with the billing -- So we are going to pay some other type of billing row with this odd account_adjustment @@ -290,7 +294,7 @@ BEGIN WHERE p.id = current_payment.id; IF NOT FOUND THEN - SELECT home_ou INTO payment_ou FROM actor.usr WHERE id = (SELECT accepting_usr FROM money.bnm_payment WHERE id = current_payment.id); + SELECT home_ou INTO payment_ou FROM actor.usr WHERE id = (SELECT accepting_usr FROM money.bnm_payment WHERE id = current_payment.id LIMIT 1); END IF; payment_remainder = -current_payment.amount; -- invert @@ -332,7 +336,9 @@ BEGIN END IF; current_result.amount = -current_result.amount; - RETURN NEXT current_result; + IF current_result.amount <> 0.0 THEN + RETURN NEXT current_result; + END IF; -- Done paying the billing rows when we run out of rows to pay (out of bounds) EXIT WHEN billing_offset = billing_row_count + 1; END IF; @@ -391,7 +397,9 @@ BEGIN END IF; current_result.amount = -current_result.amount; - RETURN NEXT current_result; + IF current_result.amount <> 0.0 THEN + RETURN NEXT current_result; + END IF; EXIT WHEN payment_remainder = 0.0; diff --git a/docs/RELEASE_NOTES_NEXT/Reports/payments_by_billing_type.adoc b/docs/RELEASE_NOTES_NEXT/Reports/payments_by_billing_type.adoc index 954254f7d3..8bee39a649 100644 --- a/docs/RELEASE_NOTES_NEXT/Reports/payments_by_billing_type.adoc +++ b/docs/RELEASE_NOTES_NEXT/Reports/payments_by_billing_type.adoc @@ -1,11 +1,12 @@ -Payments by Billing Type Reporting Source Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +== Payments by Billing Type Reporting Source Added == + A new reporting source named Payments by Billing Type has been added that associates payments and billings and displays the amount of each payment applied to those billings. Tips for using this source: -.To show workstations associated with Payments, follow the source path Payment by Billing Type --> Payment ID and then pull the appropriate field from the relevant Detail table (Cash, Check, Credit Card). -.OPAC payments will show as accepted at the paying user's home library. In order for your report to show these payments, make sure the appropriate patron Organizational Unit is set in your report filter. -.Be careful when you build your report to distinguish between Billing Organizational Unit and Payment Organizational Unit - they can be, but do not have to be, the same. -.Due to the reporter's use of GROUP BY, it is recommended that you include the Billing ID in your report output in order to prevent the reporter from rolling up payment data into one line. + +. To show workstations associated with Payments, follow the source path Payment by Billing Type --> Payment ID and then pull the appropriate field from the relevant Detail table (Cash, Check, Credit Card). +. OPAC payments will show as accepted at the paying user's home library. In order for your report to show these payments, make sure the appropriate patron Organizational Unit is set in your report filter. +. Be careful when you build your report to distinguish between Billing Organizational Unit and Payment Organizational Unit - they can be, but do not have to be, the same. +. Due to the reporter's use of GROUP BY, it is recommended that you include the Billing ID in your report output in order to prevent the reporter from rolling up payment data into one line.