diff --git a/brmbar3/schema/0010-shop-sell-for-cash.sql b/brmbar3/schema/0010-shop-sell-for-cash.sql index 12e0b9d..86fcf9c 100644 --- a/brmbar3/schema/0010-shop-sell-for-cash.sql +++ b/brmbar3/schema/0010-shop-sell-for-cash.sql @@ -63,10 +63,17 @@ DECLARE v_cost NUMERIC; v_profit NUMERIC; v_transaction_id public.transactions.id%TYPE; + v_item_currency_id public.accounts.currency%TYPE; BEGIN + -- Get item's currency + SELECT currency + INTO v_item_currency_id + FROM public.accounts + WHERE id=i_item_id; + -- Get the buy and sell rates from the stored functions - v_buy_rate := public.find_buy_rate(i_item_id, i_target_currency_id); - v_sell_rate := public.find_sell_rate(i_item_id, i_target_currency_id); + v_buy_rate := public.find_buy_rate(v_item_currency_id, i_target_currency_id); + v_sell_rate := public.find_sell_rate(v_item_currency_id, i_target_currency_id); -- Calculate cost and profit v_cost := i_amount * v_sell_rate;