Skip to content

Commit

Permalink
[MODFISTO-477] - A new encumbrance is needed during FYRO for orders w…
Browse files Browse the repository at this point in the history
…ith "Re-encumber" = false (#402)
  • Loading branch information
Abdulkhakimov authored Mar 27, 2024
1 parent 437a830 commit d16ff00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ CREATE OR REPLACE FUNCTION ${myuniversity}_${mymodule}.calculate_planned_encumbr
input_fromFiscalYearId uuid := (_rollover_record->>'fromFiscalYearId')::uuid;
BEGIN

IF
NOT((_transaction->'encumbrance'->>'reEncumber')::boolean)
THEN
RETURN 0.0;
END IF;

SELECT sum((jsonb->'encumbrance'->>'initialAmountEncumbered')::decimal) INTO po_line_cost
FROM ${myuniversity}_${mymodule}.transaction
WHERE input_fromFiscalYearId=fiscalYearId AND ${myuniversity}_${mymodule}.to_btree_format(jsonb->'encumbrance'->>'sourcePoLineId')=_transaction->'encumbrance'->>'sourcePoLineId'
Expand Down Expand Up @@ -131,7 +137,10 @@ CREATE OR REPLACE FUNCTION ${myuniversity}_${mymodule}.rollover_order(_order_id
'initialAmountEncumbered', ${myuniversity}_${mymodule}.calculate_planned_encumbrance_amount(tr.jsonb, _rollover_record, true),
'amountAwaitingPayment', 0,
'amountExpended', 0,
'status', 'Unreleased'
'status', CASE WHEN (tr.jsonb->'encumbrance'->>'reEncumber')::boolean
THEN 'Unreleased'
ELSE 'Released'
END
),
'metadata', _rollover_record->'metadata' || jsonb_build_object('createdDate', to_char(clock_timestamp(),'YYYY-MM-DD"T"HH24:MI:SS.MSTZHTZM'))

Expand All @@ -140,7 +149,7 @@ CREATE OR REPLACE FUNCTION ${myuniversity}_${mymodule}.rollover_order(_order_id
LEFT JOIN ${myuniversity}_${mymodule}.fund fund ON fund.id = tr.fromFundId
WHERE ${myuniversity}_${mymodule}.to_btree_format(tr.jsonb->'encumbrance'->>'sourcePurchaseOrderId')=_order_id
AND tr.fiscalYearId=input_fromFiscalYearId
AND (tr.jsonb->'encumbrance'->>'reEncumber')::boolean AND tr.jsonb->'encumbrance'->>'orderStatus'='Open'
AND tr.jsonb->'encumbrance'->>'orderStatus'='Open'
AND (_rollover_record->>'rolloverType' <> 'Preview' OR (_rollover_record->>'rolloverType' = 'Preview' AND fund.ledgerId = input_ledgerId));

-- #9.1 calculate and add missing penny to appropriate temp transaction
Expand Down Expand Up @@ -708,7 +717,6 @@ CREATE OR REPLACE FUNCTION ${myuniversity}_${mymodule}.budget_encumbrances_rollo
WHERE tr.jsonb->>'transactionType' = 'Encumbrance'
AND tr.fiscalYearId = input_fromFiscalYearId
AND tr.jsonb->'encumbrance'->>'orderStatus' = 'Open'
AND (tr.jsonb->'encumbrance'->>'reEncumber')::boolean
AND ledger.id=input_ledgerId
GROUP BY order_id
ORDER BY date
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/db_scripts/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
{
"run": "after",
"snippetPath": "budget_encumbrances_rollover.sql",
"fromModuleVersion": "mod-finance-storage-8.6.0"
"fromModuleVersion": "mod-finance-storage-8.7.0"
},
{
"run": "after",
Expand Down

0 comments on commit d16ff00

Please sign in to comment.