AS $BODY$
DECLARE
_ar RECORD;
-
+ _r RECORD;
+
v_sales_accnt_id INTEGER;
v_ar_accnt_id INTEGER;
v_credit_accnt_id INTEGER;
-- looking for (123 (discrep) ,135,153);
-- alterntaive case - an invoice is to/from accnt id 150/149 (direct ship?);
-
SELECT
- --araccnt_freight_accnt_id
- araccnt_ar_accnt_id -- 153
- -- araccnt_prepaid_accnt_id ,
- -- araccnt_deferred_accnt_id ,
- -- araccnt_discount_accnt_id ,
-
- INTO
- v_ar_accnt_id
- FROM
- araccnt
- ORDER BY
- araccnt_id ASC
- LIMIT 1;
+ --araccnt_freight_accnt_id
+ araccnt_ar_accnt_id -- 153
+ -- araccnt_prepaid_accnt_id ,
+ -- araccnt_deferred_accnt_id ,
+ -- araccnt_discount_accnt_id ,
-
-
- SELECT
- salesaccnt_sales_accnt_id, --135
- salesaccnt_credit_accnt_id -- 121
- -- salesaccnt_cos_accnt_id
- INTO
- v_sales_accnt_id,
- v_credit_accnt_id
- -- v_cos_accnt_id
- FROM
- salesaccnt
- ORDER BY
- salesaccnt_id ASC
- LIMIT 1;
+ INTO
+ v_ar_accnt_id
+ FROM
+ araccnt
+ ORDER BY
+ araccnt_id ASC
+ LIMIT 1;
- -- find the cash reciept..
-
SELECT
- cashrcpt_amount,
- cashrcpt_curr_rate,
- cashrcpt_amount / cashrcpt_curr_rate
- INTO
- v_c_amount,
- v_c_rate,
- v_c_base_amount
- from
- cashrcpt
- where
- 'Unapplied from C-' || cashrcpt_docnumber = _ar.aropen_notes
- LIMIT 1;
-
+ salesaccnt_sales_accnt_id, --135
+ salesaccnt_credit_accnt_id -- 121
+ -- salesaccnt_cos_accnt_id
+ INTO
+ v_sales_accnt_id,
+ v_credit_accnt_id
+ -- v_cos_accnt_id
+ FROM
+ salesaccnt
+ ORDER BY
+ salesaccnt_id ASC
+ LIMIT 1;
+
-- we now have the base amount..