pgsql/investigations/ar-cash.sql
authorEdward <edward@roojs.com>
Wed, 5 Feb 2014 06:39:52 +0000 (14:39 +0800)
committerEdward <edward@roojs.com>
Wed, 5 Feb 2014 06:39:52 +0000 (14:39 +0800)
pgsql/investigations/ar-cash.sql

index f22cfc9..047bcc3 100644 (file)
@@ -49,7 +49,7 @@ BEGIN
         RAISE EXCEPTION 'not a valid apply id..';
     END IF;
     
-    IF _ar.aropen_journalnumber IS NULL THEN
+    IF _ar.arapply_journalnumber IS NULL THEN
         RAISE EXCEPTION 'not a valid apply id..';
     END IF;
 
@@ -95,8 +95,7 @@ BEGIN
     SELECT
             gltrans_id,
             gltrans_amount,
-            ROUND( _ar.aropen_amount / _ar.aropen_curr_rate, 3 ) - ROUND(gltrans_amount, 3),
-            v_diff
+            ROUND( _ar.arapply_applied / _citem.cashrcpt_curr_rate, 3 ) - ROUND(gltrans_amount, 3)
     INTO
             v_gl_id,
             v_gltrans_amount,
@@ -105,21 +104,11 @@ BEGIN
             gltrans
     
     WHERE
-            CASE WHEN _ar.aropen_applyto IS NULL OR _ar.aropen_applyto = '' THEN
-                gltrans_docnumber  = _ar.aropen_docnumber
-                AND
-                gltrans_doctype = 'CM'
-            ELSE
-                gltrans_docnumber = _ar.aropen_applyto
-                AND
-                gltrans_doctype = 'IN'
-            END
-        AND
             gltrans_accnt_id = v_ar_accnt_id
         AND
             gltrans_source = 'A/R'
         AND
-            gltrans_journalnumber = _ar.aropen_journalnumber;
+            gltrans_journalnumber = _ar.arapply_journalnumber;
             
 
     IF NOT FOUND THEN