I am not sure how much of this rewrite is correct.
I believe I identified a number of places where currency conversions
were missing. As well, I have cut out some IF branches.
My comments are verbose at the moment to help me figure out what is
going on.
I have also added a second function acq.current_fund_allocation, which
returns the total amount of money allocated to the current fund.
This allows the acq.transfer_fund to determine if it is trying to
transfer more money than is currently available.
A few more sanity checks have also been added. And, the currency
conversion is done strictly from the database now. It seems
inconsistent to me to convert between old_fund and new_fund according to
a rate defined outside of this funciton but to convert between the funds
and the funding sources with values from acq.exchange_rate
(sitka) [RT18248] Working on getting rollover to work
In the process of figuring out how to make rollover work with my
modified transfer_fund function.
Need to print out the values trying to be transferred back to the
funding source via RAISE EXCEPTION
(sitka) [RT18248] Fixing asq.transfer_fund function
The function has to be broken up into parts. One for transfering funds
and one for returning funds to funding sources. This work so far has
created the code for transfering between funds. The acq.fund_allocation
table needs to be updated to have fund_amount and conversion_ratio
fields added. fund_amount will allow the funds to display their total
without fluctuating depending on the worth of the funding source
currency and conversion ratio is good to have for accounting purposes.
(sitka) [RT18248]
Fixed transfer_fund. It was using an amount to return to the funding
source based on the amount allocated by the funding source. But, it was
converting this amount to the currency of the fund. So, if the exchange
rate changes, then athe amount allocated to the fund will change for the
transfer when it should stay constant.
To do this, we add a fund_amount field to the acq.fund_allocation table.
This amount is stored in the curecny of the fund, which will allow us to
determine how much money is in a fund even when the exchange rates
change.
This commit also adds the fuction acq.return_funds_to_source. This is
used when funds are returned to a funding source without then
transferring them to another fund. This can happen when rolling over
acqusitions at year end depending on the options chosen.
(sitka) [RT18248] Added updates for rollover functions
Added updates for the acq.rollover_funds_by_org_unit and
acq.rollover_funds_by_org_tree functions, so they use the new
acq.return_funds_to_source function when appropriate.
As well, aded a commented out DROP line to remove the old version of the
acq.transfer_fund function.
(sitka) [RT18248] Tracked down all old transfer_fund references
This code modifies the upgrade to the acq.rollover_by_org_unit and
acq.rollover_by_org_tree to use acq.return_funds_to_source rather than
acq.transfer_fund. As well, it modifies all old versions of transfer
fund because the new version has new parameters.
(sitka) [RT18248] Fixing stuff via pgTap
A number of syntax errors presented themselves when using pgTap to test
the changes. These have been fixed.
(sitka) [RT18248] Fixing rollover
The transfer_fund function needed and still needs work. But, the
current version is working. It needs to be modified, so we can tell the
difference between potential transfers and real transfers.
The rollover_funds_by_org_tree function needed to be updated to use the
spent total when doing year end and only transferring encumbered funds.
By using the spent total, it now returns that amount to the funding
source. We do not use the combined total because that includes the
encumbered funds and we want those to stay with the current fund so the
library can choose to move them manually to the new fund if the
encumberance is set to rollover, or do something else with them if they
are set to stay.