pgsql/investigations/ar-reciept.sql
authorEdward <edward@roojs.com>
Tue, 4 Feb 2014 07:17:29 +0000 (15:17 +0800)
committerEdward <edward@roojs.com>
Tue, 4 Feb 2014 07:17:29 +0000 (15:17 +0800)
pgsql/investigations/ar-reciept.sql

index 6e9aa21..3866877 100644 (file)
@@ -24,7 +24,8 @@ CREATE OR REPLACE FUNCTION x_ar_verify_reciept(i_aropen_id integer)
 AS $BODY$
 DECLARE    
     _ar RECORD;
-    
+    _r RECORD;
+
     v_sales_accnt_id INTEGER;
     v_ar_accnt_id INTEGER;
     v_credit_accnt_id INTEGER;
@@ -80,56 +81,37 @@ BEGIN
     -- 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..