DBA Data[Home] [Help]

APPS.FV_CROSS_DOC_REF SQL Statements

The following lines contain the word 'select', 'insert', 'update' or 'delete':

Line: 122

	SELECT ph.po_header_id,pl.po_line_id,pll.line_location_id
	FROM po_headers ph,po_lines pl,po_line_locations pll
	WHERE ph.po_header_id = pl.po_header_id
	AND pl.po_line_id = pll.po_line_id
	AND vendor_id = vp_vendor_id
	AND vendor_site_id = vp_vendor_site_id
	AND ph.po_header_id = NVL(vp_po_header_id,ph.po_header_id)
	AND TRUNC(ph.creation_date) = nvl(vp_po_date,TRUNC(ph.creation_date))
	AND ph.agent_id = nvl(vp_buyer,ph.agent_id)
	AND NOT EXISTS(SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
	UNION
	SELECT ph.po_header_id,pl.po_line_id,pll.line_location_id
	FROM po_headers ph,po_lines pl,po_line_locations pll
	WHERE ph.po_header_id = pl.po_header_id
	AND pl.po_line_id = pll.po_line_id
	AND vendor_id = vp_vendor_id
	AND vendor_site_id = vp_vendor_site_id
	AND ph.po_header_id = NVL(vp_po_header_id,ph.po_header_id)
	AND TRUNC(ph.creation_date) = nvl(vp_po_date,TRUNC(ph.creation_date))
	AND ph.agent_id = nvl(vp_buyer,ph.agent_id)
	AND  EXISTS(SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id
		    AND po_header_id = ph.po_header_id AND po_line_id = pl.po_line_id);
Line: 147

	SELECT ph.po_header_id,pl.po_line_id, pll.line_location_id
	FROM po_headers ph,po_lines pl,po_line_locations pll
	WHERE ph.po_header_id = pl.po_header_id
	AND pl.po_line_id = pll.po_line_id
	AND EXISTS(SELECT   prh.requisition_header_id,prl.requisition_line_id
		FROM po_requisition_headers prh,po_requisition_lines prl
		WHERE prh.requisition_header_id = prl.requisition_header_id
		AND authorization_status = 'APPROVED'
		AND prl.line_location_id = pll.line_location_id
		AND prl.suggested_vendor_location = vp_supplier_site
		AND prl.suggested_vendor_name = vp_supplier_name
		AND prh.requisition_header_id = NVL(vp_requisition_header_id,prh.requisition_header_id)
		AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date))
     UNION
	SELECT  rh.requisition_header_id,rh.requisition_line_id
	FROM (SELECT DISTINCT  prh.requisition_header_id,
		prl.requisition_line_id,prl.line_location_id
		FROM po_requisition_headers prh,po_requisition_lines prl
		WHERE prl.requisition_header_id = prh.requisition_header_id
		AND authorization_status = 'APPROVED'
		AND prh.requisition_header_id = NVL(vp_requisition_header_id,prh.requisition_header_id)
		AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date))) rh,
	po_line_locations plx,po_headers ph
	WHERE  plx.line_location_id = rh.line_location_id
	AND plx.po_header_id = ph.po_header_id
	AND ph.vendor_id = vp_vendor_id
	AND rh.line_location_id = pll.line_location_id
	AND ph.vendor_site_id = vp_vendor_site_id
	AND NOT EXISTS (SELECT 1 FROM po_vendors pv,po_requisition_lines prl,po_vendor_sites pvs
          WHERE prl.suggested_vendor_name = pv.vendor_name
          AND prl.suggested_vendor_location = pvs.vendor_site_code
          AND prl.requisition_line_id = rh.requisition_line_id ));
Line: 184

		SELECT ph.po_header_id,pll.po_line_id,pll.line_location_id
			FROM po_headers ph,po_line_locations pll
		WHERE ph.po_header_id = pll.po_header_id
		AND vendor_id = vp_vendor_id
		AND vendor_site_id = vp_vendor_site_id
		AND NOT EXISTS(SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
		AND EXISTS (SELECT 1 FROM rcv_transactions rt
		    WHERE rt.po_header_id = ph.po_header_id
		    AND rt.po_line_id = pll.po_line_id
		    AND rt.po_line_location_id = pll.line_location_id
		    AND EXISTS (SELECT 1 from rcv_shipment_headers rsh
		       WHERE rsh.shipment_header_id = rt.shipment_header_id
		       AND rsh.shipment_header_id = NVL(vp_shipment_header_id,rsh.shipment_header_id)
		       AND TRUNC(rsh.creation_date) = NVL(vp_rec_date,TRUNC(rsh.creation_date))))
			UNION
		SELECT ph.po_header_id,pll.po_line_id ,pll.line_location_id
			FROM po_headers ph,po_line_locations pll
		WHERE ph.po_header_id = pll.po_header_id
		AND vendor_id = vp_vendor_id
		AND vendor_site_id = vp_vendor_site_id
		AND EXISTS (SELECT 1 FROM fv_doc_cr_temp  fst
		   WHERE fst.po_header_id = ph.po_header_id
		   AND fst.po_line_id = pll.po_line_id
		   AND fst.po_line_location_id = pll.line_location_id
                   AND fst.session_id = vp_session_id)
		AND EXISTS (SELECT 1 FROM rcv_transactions rt
		    WHERE rt.po_header_id = ph.po_header_id
		    AND rt.po_line_id = pll.po_line_id
		    AND rt.po_line_location_id = pll.line_location_id
		    AND EXISTS (SELECT 1 from rcv_shipment_headers rsh
		       WHERE rsh.shipment_header_id = rt.shipment_header_id
		       AND rsh.shipment_header_id = NVL(vp_shipment_header_id,rsh.shipment_header_id)
		       AND TRUNC(rsh.creation_date) = NVL(vp_rec_date,TRUNC(rsh.creation_date))));
Line: 220

	SELECT ph.po_header_id,pll.po_line_id,pll.line_location_id FROM po_headers ph,po_line_locations pll
	WHERE ph.po_header_id = pll.po_header_id
	 AND vendor_id = vp_vendor_id
	 AND vendor_site_id = vp_vendor_site_id
	 AND NOT EXISTS(SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
	 AND (EXISTS (SELECT 1 FROM po_distributions pd
	   WHERE pd.po_header_id = ph.po_header_id
	   AND pd.line_location_id = pll.line_location_id
	   AND EXISTS (SELECT 1 FROM ap_invoice_distributions ia
	    WHERE ia.po_distribution_id= pd.po_distribution_id
	    AND EXISTS (SELECT 1 FROM ap_invoices ap
	     WHERE invoice_id = ia.invoice_id
	     AND invoice_id = NVL(vp_invoice_id,invoice_id)
	     AND TRUNC(ap.invoice_date) = NVL(vp_invoice_date,TRUNC(ap.invoice_date))
	     AND invoice_type_lookup_code = NVL(vp_invoice_type,invoice_type_lookup_code)
	     AND invoice_amount = nvl(vp_invoice_amount,invoice_amount))))
	     OR EXISTS (SELECT 1 FROM rcv_transactions rt
		WHERE rt.po_header_id = ph.po_header_id
		AND rt.po_line_location_id = pll.line_location_id
		AND EXISTS (SELECT 1 FROM ap_invoice_distributions ia
		 WHERE ia.rcv_transaction_id= rt.transaction_id
		 AND EXISTS (SELECT 1 FROM ap_invoices ap
		  WHERE invoice_id = ia.invoice_id
		  AND invoice_id = NVL(vp_invoice_id,invoice_id)
		  AND TRUNC(ap.invoice_date) = NVL(vp_invoice_date,TRUNC(ap.invoice_date))
		  AND invoice_type_lookup_code = nvl(vp_invoice_type,invoice_type_lookup_code)
		  AND invoice_amount = nvl(vp_invoice_amount,invoice_amount)))))
	UNION
	SELECT ph.po_header_id,pll.po_line_id ,pll.line_location_id FROM po_headers ph,po_line_locations pll
	WHERE vendor_id = vp_vendor_id
	AND ph.po_header_id = pll.po_header_id
	AND vendor_site_id = vp_vendor_site_id
	AND EXISTS (SELECT 1 FROM fv_doc_cr_temp  fst
	 WHERE fst.po_header_id = ph.po_header_id
	 AND fst.po_line_id = pll.po_line_id
	 AND fst.po_line_location_id = pll.line_location_id
	 AND fst.session_id = vp_session_id)
	 AND (EXISTS (SELECT 1 FROM po_distributions pd
	  WHERE pd.po_header_id = ph.po_header_id
	  AND pd.line_location_id = pll.line_location_id
	  AND EXISTS (SELECT 1 FROM ap_invoice_distributions ia
	   WHERE ia.po_distribution_id= pd.po_distribution_id
	   AND EXISTS (SELECT 1 FROM ap_invoices ap
	    WHERE invoice_id = ia.invoice_id
	    AND invoice_id = NVL(vp_invoice_id,invoice_id)
	    AND TRUNC(ap.invoice_date) =NVL(vp_invoice_date,TRUNC(ap.invoice_date))
	    AND invoice_type_lookup_code =NVL(vp_invoice_type,invoice_type_lookup_code)
	    AND invoice_amount = nvl(vp_invoice_amount,invoice_amount))))
	    OR EXISTS (SELECT 1 FROM rcv_transactions rt
	     WHERE rt.po_header_id = ph.po_header_id
	     AND rt.po_line_location_id = pll.line_location_id
	     AND EXISTS (SELECT 1 FROM ap_invoice_distributions ia
	      WHERE ia.rcv_transaction_id= rt.transaction_id
	      AND EXISTS (SELECT 1 FROM ap_invoices ap
	       WHERE invoice_id = ia.invoice_id
	       AND invoice_id = NVL(vp_invoice_id,invoice_id)
	       AND TRUNC(ap.invoice_date) = nvl(vp_invoice_date,TRUNC(ap.invoice_date))
	       AND invoice_type_lookup_code = nvl(vp_invoice_type,invoice_type_lookup_code)
	       AND invoice_amount = nvl(vp_invoice_amount,invoice_amount)))));
Line: 283

      SELECT ph.po_header_id,pll.po_line_id,pll.line_location_id
	FROM po_headers ph,po_line_locations pll
	WHERE ph.po_header_id = pll.po_header_id
	AND vendor_id = vp_vendor_id
	AND vendor_site_id = vp_vendor_site_id
	AND NOT EXISTS(SELECT 1 FROM fv_doc_cr_temp
                       WHERE session_id = vp_session_id)
	AND EXISTS (SELECT   1 from po_distributions pd
	 WHERE pd.po_header_id = ph.po_header_id
	 AND pd.line_location_id = pll.line_location_id
	 AND (EXISTS (SELECT 1 FROM ap_invoice_distributions aid
	   WHERE aid.po_distribution_id = pd.po_distribution_id
	   AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
	    WHERE aip.invoice_id = aid.invoice_id
	    AND EXISTS (SELECT 1 FROM ap_checks ac
	     WHERE ac.check_id = aip.check_id
	     AND ac.check_id =  NVL(vp_check_id,ac.check_id)
	     AND TRUNC(ac.check_date) = NVL(vp_check_date,TRUNC(ac.check_date))
	     AND ac.amount = nvl(vp_amount,ac.amount)
	     AND NVL(ac.treasury_pay_number,-1) =NVL(vp_treasury_pay_number,NVL(ac.treasury_pay_number,-1))
	     AND (TRUNC(ac.treasury_pay_date) = TRUNC(vp_treasury_pay_date)
                  OR vp_treasury_pay_date IS NULL)))))
	    OR EXISTS (SELECT   1 from rcv_transactions rt
	    WHERE rt.po_header_id = ph.po_header_id
	    AND rt.po_line_location_id = pll.line_location_id
	    AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
	     WHERE aid.rcv_transaction_id = rt.transaction_id
	     AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
	      WHERE aip.invoice_id = aid.invoice_id
	      AND EXISTS (SELECT 1 FROM ap_checks ac
	       WHERE ac.check_id = aip.check_id
	       AND ac.check_id =  NVL(vp_check_id,ac.check_id)
	       AND TRUNC(ac.check_date) = NVL(vp_check_date,TRUNC(ac.check_date))
	       AND ac.amount = nvl(vp_amount,ac.amount)
	       AND NVL(ac.treasury_pay_number,-1) =NVL(vp_treasury_pay_number,NVL(ac.treasury_pay_number,-1))
	       AND (TRUNC(ac.treasury_pay_date) = TRUNC(vp_treasury_pay_date)
                    OR vp_treasury_pay_date IS NULL))))))
      UNION
	SELECT ph.po_header_id,pll.po_line_id,pll.line_location_id
	FROM po_headers ph,po_line_locations pll
	WHERE ph.po_header_id = pll.po_header_id
	AND EXISTS (SELECT 1 FROM fv_doc_cr_temp  fst
	 WHERE fst.po_header_id = ph.po_header_id
	 AND fst.po_line_id = pll.po_line_id
         AND fst.po_line_location_id = pll.line_location_id
         AND fst.session_id = vp_session_id)
	AND vendor_id = vp_vendor_id
	AND vendor_site_id = vp_vendor_site_id
	AND EXISTS (SELECT   1 from po_distributions pd
	 WHERE pd.po_header_id = ph.po_header_id
	 AND pd.line_location_id = pll.line_location_id
	 AND (EXISTS (SELECT 1 FROM ap_invoice_distributions aid
	      WHERE aid.po_distribution_id = pd.po_distribution_id
	      AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
	       WHERE aip.invoice_id = aid.invoice_id
	       AND EXISTS (SELECT 1 FROM ap_checks ac
	        WHERE ac.check_id = aip.check_id
		AND ac.check_id =  NVL(vp_check_id,ac.check_id)
		AND TRUNC(ac.check_date) = NVL(vp_check_date,TRUNC(ac.check_date))
		AND ac.amount = nvl(vp_amount,ac.amount)
		AND NVL(ac.treasury_pay_number,-1) =NVL(vp_treasury_pay_number,NVL(ac.treasury_pay_number,-1))
		AND (TRUNC(ac.treasury_pay_date) = TRUNC(vp_treasury_pay_date)
                      OR vp_treasury_pay_date IS NULL)))))
	OR EXISTS (SELECT   1 from rcv_transactions rt
	    WHERE rt.po_header_id = ph.po_header_id
	    AND rt.po_line_location_id = pll.line_location_id
	    AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
		WHERE aid.rcv_transaction_id = rt.transaction_id
		AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
	         WHERE aip.invoice_id = aid.invoice_id
		 AND EXISTS (SELECT 1 FROM ap_checks ac
		  WHERE ac.check_id = aip.check_id
		  AND ac.check_id =  NVL(vp_check_id,ac.check_id)
		  AND TRUNC(ac.check_date) = NVL(vp_check_date,TRUNC(ac.check_date))
		  AND ac.amount = nvl(vp_amount,ac.amount)
		  AND NVL(ac.treasury_pay_number,-1) =NVL(vp_treasury_pay_number,NVL(ac.treasury_pay_number,-1))
	          AND (TRUNC(ac.treasury_pay_date) = TRUNC(vp_treasury_pay_date)
                       OR vp_treasury_pay_date IS NULL))))));
Line: 364

     DELETE FROM fv_doc_cr_temp
	WHERE session_id = vp_session_id;
Line: 369

	      DELETE FROM fv_doc_cr_temp
		WHERE session_id = vp_session_id;
Line: 374

		     INSERT INTO fv_doc_cr_temp (po_header_id,po_line_id,po_line_location_id,session_id)
		     VALUES (req_rec.po_header_id,req_rec.po_line_id,req_rec.line_location_id,vp_session_id);
Line: 378

		    DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 386

    	    DELETE FROM fv_doc_cr_temp
	    WHERE session_id = vp_session_id;
Line: 391

	       INSERT INTO fv_doc_cr_temp (po_header_id,po_line_id,po_line_location_id,session_id)
		 VALUES(po_rec.po_header_id,po_rec.po_line_id,po_rec.line_location_id,vp_session_id);
Line: 395

	        DELETE FROM fv_doc_cr_temp
		 WHERE session_id = vp_session_id;
Line: 405

	          DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 409

	              INSERT INTO fv_doc_cr_temp (po_header_id,po_line_id,po_line_location_id,session_id)
		      VALUES (rec_rec.po_header_id,rec_rec.po_line_id,rec_rec.line_location_id,vp_session_id);
Line: 413

			   DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 422

	          DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 426

	               INSERT INTO fv_doc_cr_temp (po_header_id,po_line_id,po_line_location_id,session_id)
			VALUES (inv_rec.po_header_id,inv_rec.po_line_id,inv_rec.line_location_id,vp_session_id);
Line: 430

		     DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 440

	        DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 444

	             INSERT INTO fv_doc_cr_temp (po_header_id,po_line_id,po_line_location_id,session_id)
		     VALUES (pay_rec.po_header_id,pay_rec.po_line_id,pay_rec.line_location_id,vp_session_id);
Line: 448

		   DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 469

	SELECT prh.requisition_header_id ,prl.requisition_line_id
	FROM po_requisition_headers  prh,po_requisition_lines  prl,po_line_locations pll,po_headers ph
	WHERE 	prh.requisition_header_id =prl.requisition_header_id
	AND pll.line_location_id = prl.line_location_id
        AND ph.po_header_id = pll.po_header_id
	AND ph.vendor_id = vp_vendor_id
	AND ph.vendor_site_id = vp_vendor_site_id
	AND ph.po_header_id = NVL(vp_po_header_id,ph.po_header_id)
	AND TRUNC(ph.creation_date) = NVL(vp_po_date,TRUNC(ph.creation_date))
	AND ph.agent_id = nvl(vp_buyer,ph.agent_id)
	AND NOT EXISTS(SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
		UNION
	SELECT prh.requisition_header_id ,prl.requisition_line_id
	FROM po_requisition_headers  prh,po_requisition_lines  prl,po_line_locations pll,po_headers ph
	WHERE 	prh.requisition_header_id = prl.requisition_header_id
	AND pll.line_location_id = prl.line_location_id
        AND ph.po_header_id = pll.po_header_id
	AND ph.vendor_id = vp_vendor_id
	AND ph.vendor_site_id = vp_vendor_site_id
	AND ph.po_header_id = NVL(vp_po_header_id,ph.po_header_id)
	AND TRUNC(ph.creation_date) = NVL(vp_po_date,TRUNC(ph.creation_date))
	AND ph.agent_id = nvl(vp_buyer,ph.agent_id)
	AND EXISTS (SELECT 1 FROM fv_doc_cr_temp  fst
		 WHERE  fst.requisition_header_id = prh.requisition_header_id
		 AND  requisition_line_id = prl.requisition_line_id
		 AND fst.session_id = vp_session_id);
Line: 500

	SELECT   prh.requisition_header_id,prl.requisition_line_id
		FROM po_requisition_headers prh,po_requisition_lines prl
		WHERE prh.requisition_header_id = prl.requisition_header_id
		AND prh.requisition_header_id = NVL(vp_requisition_header_id,prh.requisition_header_id)
		AND authorization_status = 'APPROVED'
		AND prl.suggested_vendor_location = vp_supplier_site
		AND prl.suggested_vendor_name = vp_supplier_name
		AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date))
     UNION
	SELECT  rh.requisition_header_id,rh.requisition_line_id
	FROM (SELECT DISTINCT  prh.requisition_header_id,
		prl.requisition_line_id,prl.line_location_id
		FROM po_requisition_headers prh,po_requisition_lines prl
		WHERE prl.requisition_header_id = prh.requisition_header_id
		AND prh.requisition_header_id = NVL(vp_requisition_header_id,prh.requisition_header_id)
		AND authorization_status = 'APPROVED'
		AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date))) rh,
	po_line_locations plx,po_headers ph
	WHERE  plx.line_location_id = rh.line_location_id
	AND plx.po_header_id = ph.po_header_id
	AND ph.vendor_id = vp_vendor_id
	AND ph.vendor_site_id = vp_vendor_site_id
	AND NOT EXISTS (SELECT 1 FROM po_vendors pv,po_requisition_lines prl,po_vendor_sites pvs
          WHERE prl.suggested_vendor_name = pv.vendor_name
          AND prl.suggested_vendor_location = pvs.vendor_site_code
          AND prl.requisition_line_id = rh.requisition_line_id );
Line: 531

	SELECT requisition_header_id,prl.requisition_line_id FROM po_requisition_lines prl
	WHERE NOT EXISTS(SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
	AND (EXISTS (SELECT 1 FROM po_req_distributions prd
		WHERE prd.requisition_line_id = prl.requisition_line_id
		AND EXISTS (SELECT 1 FROM rcv_transactions rt,po_headers ph
		   WHERE rt.po_header_id = ph.po_header_id
		   AND rt.req_distribution_id = prd.distribution_id
		   AND ph.vendor_site_id = vp_vendor_site_id
		   AND 	EXISTS (SELECT 1 FROM rcv_shipment_headers rsh
		   	WHERE rsh.vendor_id = vp_vendor_id
		    	AND rsh.shipment_header_id = rt.shipment_header_id
   		    	AND rsh.shipment_header_id = NVL(vp_shipment_header_id,rsh.shipment_header_id)
			AND TRUNC(rsh.creation_date) = NVL(vp_rec_date,TRUNC(rsh.creation_date)))))
	   OR EXISTS (SELECT 1 FROM po_distributions pd
		WHERE pd.line_location_id = prl.line_location_id
		AND EXISTS (SELECT 1 FROM rcv_transactions rt,po_headers ph
		   WHERE rt.po_header_id = ph.po_header_id
		   AND rt.po_line_location_id = pd.line_location_id
		   AND ph.vendor_site_id = vp_vendor_site_id
		   AND 	EXISTS (SELECT 1 FROM rcv_shipment_headers rsh
		   	WHERE rsh.vendor_id = vp_vendor_id
		    	AND rsh.shipment_header_id = rt.shipment_header_id
   		    	AND rsh.shipment_header_id = NVL(vp_shipment_header_id,rsh.shipment_header_id)
			AND TRUNC(rsh.creation_date) = NVL(vp_rec_date,TRUNC(rsh.creation_date))))))

			UNION
	SELECT requisition_header_id,prl.requisition_line_id   FROM po_requisition_lines prl
	WHERE  EXISTS(SELECT 1 FROM fv_doc_cr_temp
		WHERE requisition_header_id = prl.requisition_header_id
		AND  requisition_line_id = prl.requisition_line_id
		AND  session_id = vp_session_id)
	AND (EXISTS (SELECT 1 FROM po_req_distributions prd
		WHERE prd.requisition_line_id = prl.requisition_line_id
		AND EXISTS (SELECT 1 FROM rcv_transactions rt,po_headers ph
		   WHERE rt.po_header_id = ph.po_header_id
		   AND rt.req_distribution_id = prd.distribution_id
		   AND ph.vendor_site_id = vp_vendor_site_id
		   AND 	EXISTS (SELECT 1 FROM rcv_shipment_headers rsh
		   	WHERE rsh.vendor_id = vp_vendor_id
		    	AND rsh.shipment_header_id = rt.shipment_header_id
   		    	AND rsh.shipment_header_id = NVL(vp_shipment_header_id,rsh.shipment_header_id)
			AND TRUNC(rsh.creation_date) = NVL(vp_rec_date,TRUNC(rsh.creation_date)))))
	   OR EXISTS (SELECT 1 FROM po_distributions pd
		WHERE pd.line_location_id = prl.line_location_id
		AND EXISTS (SELECT 1 FROM rcv_transactions rt,po_headers ph
		   WHERE rt.po_header_id = ph.po_header_id
		   AND rt.po_line_location_id = pd.line_location_id
		   AND ph.vendor_site_id = vp_vendor_site_id
		   AND 	EXISTS (SELECT 1 FROM rcv_shipment_headers rsh
		   	WHERE rsh.vendor_id = vp_vendor_id
		    	AND rsh.shipment_header_id = rt.shipment_header_id
   		    	AND rsh.shipment_header_id = NVL(vp_shipment_header_id,rsh.shipment_header_id)
			AND TRUNC(rsh.creation_date) = NVL(vp_rec_date,TRUNC(rsh.creation_date))))));
Line: 590

	SELECT prl.requisition_header_id,prl.requisition_line_id FROM po_requisition_lines prl
	WHERE  NOT EXISTS(SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
	AND EXISTS (SELECT 1 FROM po_req_distributions prd
	    WHERE prd.requisition_line_id = prl.requisition_line_id
	    AND EXISTS (SELECT 1 FROM po_distributions pd
	        WHERE pd.req_distribution_id = prd.distribution_id
	        AND (EXISTS (SELECT 1 FROM ap_invoice_distributions aid
	 		WHERE aid.po_distribution_id= pd.po_distribution_id
			AND EXISTS (SELECT 1 FROM ap_invoices ai
			    WHERE ai.invoice_id = aid.invoice_id
			    AND ai.vendor_id = vp_vendor_id
 	                    AND ai.vendor_site_id = vp_vendor_site_id
			    AND ai.invoice_id = NVL(vp_invoice_id,invoice_id)
			    AND TRUNC(ai.invoice_date) = nvl(vp_invoice_date,TRUNC(ai.invoice_date))
			    AND ai.invoice_type_lookup_code = nvl(vp_invoice_type,invoice_type_lookup_code)
			    AND ai.invoice_amount = nvl(vp_invoice_amount,invoice_amount)))
	            OR EXISTS (SELECT 1 FROM po_line_locations pll
	             	WHERE  pll.line_location_id  = pd.line_location_id
	               	AND EXISTS ( SELECT 1 FROM rcv_transactions rt
	               	    WHERE rt.po_line_location_id = pll.line_location_id
	                    AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
	                        WHERE aid.rcv_transaction_id = rt.transaction_id
	                	AND EXISTS (SELECT 1 FROM ap_invoices ai
				    WHERE ai.invoice_id = aid.invoice_id
				    AND ai.vendor_id = vp_vendor_id
 	                            AND ai.vendor_site_id = vp_vendor_site_id
				    AND ai.invoice_id = NVL(vp_invoice_id,invoice_id)
				    AND TRUNC(ai.invoice_date) = nvl(vp_invoice_date,TRUNC(ai.invoice_date))
				    AND ai.invoice_type_lookup_code = nvl(vp_invoice_type,invoice_type_lookup_code)
				    AND ai.invoice_amount = nvl(vp_invoice_amount,invoice_amount))))))))
		UNION
	SELECT prl.requisition_header_id,prl.requisition_line_id FROM po_requisition_lines prl
	WHERE   EXISTS(SELECT 1 FROM fv_doc_cr_temp
	  WHERE requisition_header_id = prl.requisition_header_id
	  AND  requisition_line_id = prl.requisition_line_id
	  AND session_id = vp_session_id)
	  AND EXISTS (SELECT 1 FROM po_req_distributions prd
            WHERE prd.requisition_line_id = prl.requisition_line_id
	    AND EXISTS (SELECT 1 FROM po_distributions pd
	     WHERE pd.req_distribution_id = prd.distribution_id
	     AND (EXISTS (SELECT 1 FROM ap_invoice_distributions aid
	      WHERE aid.po_distribution_id= pd.po_distribution_id
	      AND EXISTS (SELECT 1 FROM ap_invoices ai
		WHERE ai.invoice_id = aid.invoice_id
		AND ai.vendor_id = vp_vendor_id
 		AND ai.vendor_site_id = vp_vendor_site_id
		AND ai.invoice_id = NVL(vp_invoice_id,invoice_id)
		AND trunc(ai.invoice_date) = nvl(vp_invoice_date,trunc(ai.invoice_date))
		AND ai.invoice_type_lookup_code = NVL(vp_invoice_type,invoice_type_lookup_code)
                AND ai.invoice_amount = nvl(vp_invoice_amount,invoice_amount)))
                OR EXISTS (SELECT 1 FROM po_line_locations pll
		   WHERE pll.line_location_id  = pd.line_location_id
               	   AND EXISTS (SELECT 1 FROM rcv_transactions rt
		    WHERE rt.po_line_location_id = pll.line_location_id
                    AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
		     WHERE aid.rcv_transaction_id = rt.transaction_id
		     AND EXISTS (SELECT 1 FROM ap_invoices ai
		      WHERE ai.invoice_id = aid.invoice_id
		      AND ai.vendor_id = vp_vendor_id
 		      AND ai.vendor_site_id = vp_vendor_site_id
		      AND ai.invoice_id = NVL(vp_invoice_id,invoice_id)
		      AND TRUNC(ai.invoice_date) = NVL(vp_invoice_date,TRUNC(ai.invoice_date))
		      AND ai.invoice_type_lookup_code =NVL(vp_invoice_type,invoice_type_lookup_code)
		      AND ai.invoice_amount = nvl(vp_invoice_amount,invoice_amount))))))));
Line: 658

	SELECT prl.requisition_header_id,prl.requisition_line_id FROM po_requisition_lines prl
	WHERE   NOT EXISTS(SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
	AND EXISTS (SELECT 1 FROM po_req_distributions prd WHERE prd.requisition_line_id = prl.requisition_line_id
	AND EXISTS (SELECT 1 FROM po_distributions pd
	 WHERE pd.req_distribution_id = prd.distribution_id
	 AND (EXISTS (SELECT 1 FROM ap_invoice_distributions aid
	  WHERE aid.po_distribution_id = pd.po_distribution_id
	  AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
	   WHERE aip.invoice_id = aid.invoice_id
	   AND EXISTS (SELECT 1 FROM ap_checks ac
	    WHERE ac.check_id = aip.check_id
	    AND ac.vendor_id = vp_vendor_id
	    AND ac.vendor_site_id = vp_vendor_site_id
	    AND ac.check_id =  NVL(vp_check_id,ac.check_id)
	    AND ac.check_date = NVL(vp_check_date,ac.check_date)
            AND ac.amount = nvl(vp_amount,ac.amount)
	    AND NVL(ac.treasury_pay_number,-1) =NVL(vp_treasury_pay_number,NVL(ac.treasury_pay_number,-1))
 	    AND (TRUNC(ac.treasury_pay_date) = TRUNC(vp_treasury_pay_date)
		 OR vp_treasury_pay_date IS NULL))))
	    OR EXISTS (SELECT 1 FROM po_line_locations pll
	     WHERE  pll.line_location_id  = pd.line_location_id
	     AND EXISTS (SELECT 1 FROM rcv_transactions rt
	      WHERE rt.po_line_location_id = pll.line_location_id
              AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
               WHERE aid.rcv_transaction_id = rt.transaction_id
	       AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
	        WHERE aip.invoice_id = aid.invoice_id
	        AND EXISTS (SELECT 1 FROM ap_checks ac
		 WHERE ac.check_id = aip.check_id
		 AND ac.vendor_id = vp_vendor_id
		 AND ac.vendor_site_id = vp_vendor_site_id
		 AND ac.check_id =  NVL(vp_check_id,ac.check_id)
		 AND ac.check_date = NVL(vp_check_date,ac.check_date)
	         AND ac.amount = nvl(vp_amount,ac.amount)
		 AND NVL(ac.treasury_pay_number,-1) = NVL(vp_treasury_pay_number,NVL(ac.treasury_pay_number,-1))
 		 AND (TRUNC(ac.treasury_pay_date) = TRUNC(vp_treasury_pay_date)
                      OR vp_treasury_pay_date IS NULL)))))))))
				UNION
		SELECT prl.requisition_header_id,prl.requisition_line_id  FROM po_requisition_lines prl
		WHERE EXISTS(SELECT 1 FROM fv_doc_cr_temp
		     WHERE requisition_header_id = prl.requisition_header_id
		     AND  requisition_line_id = prl.requisition_line_id
		     AND session_id = vp_session_id)
		AND EXISTS (SELECT 1 FROM po_req_distributions prd
		 WHERE prd.requisition_line_id = prl.requisition_line_id
		 AND EXISTS (SELECT 1 FROM po_distributions pd
		  WHERE pd.req_distribution_id = prd.distribution_id
		  AND (EXISTS (SELECT 1 FROM ap_invoice_distributions aid
 		   WHERE aid.po_distribution_id = pd.po_distribution_id
	           AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
		    WHERE aip.invoice_id = aid.invoice_id
		    AND EXISTS (SELECT 1 FROM ap_checks ac
		     WHERE ac.check_id = aip.check_id
		     AND ac.check_id =  NVL(vp_check_id,ac.check_id)
		     AND ac.check_date = NVL(vp_check_date,ac.check_date)
		     AND ac.amount = nvl(vp_amount,ac.amount)
		     AND NVL(ac.treasury_pay_number,-1) =NVL(vp_treasury_pay_number,NVL(ac.treasury_pay_number,-1))
	   	     AND (TRUNC(ac.treasury_pay_date) = TRUNC(vp_treasury_pay_date)
                         OR vp_treasury_pay_date IS NULL))))
		   OR EXISTS (SELECT 1 FROM po_line_locations pll
		    WHERE  pll.line_location_id  = pd.line_location_id
		    AND EXISTS (SELECT 1 FROM rcv_transactions rt
		     WHERE rt.po_line_location_id = pll.line_location_id
		     AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
		      WHERE aid.rcv_transaction_id = rt.transaction_id
		      AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
		       WHERE aip.invoice_id = aid.invoice_id
		       AND EXISTS (SELECT 1 FROM ap_checks ac
			WHERE ac.check_id = aip.check_id
			AND ac.vendor_id = vp_vendor_id
			AND ac.vendor_site_id = vp_vendor_site_id
			AND ac.check_id =  NVL(vp_check_id,ac.check_id)
			AND ac.check_date = NVL(vp_check_date,ac.check_date)
			AND ac.amount = nvl(vp_amount,ac.amount)
			AND NVL(ac.treasury_pay_number,-1) =NVL(vp_treasury_pay_number,NVL(ac.treasury_pay_number,-1))
 			AND (TRUNC(ac.treasury_pay_date) = TRUNC(vp_treasury_pay_date)
			     OR vp_treasury_pay_date IS NULL)))))))));
Line: 737

        DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 742

	      DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 746

		  INSERT INTO fv_doc_cr_temp (requisition_header_id,requisition_line_id,session_id )
			      VALUES (req_rec.requisition_header_id,req_rec.requisition_line_id,vp_session_id );
Line: 750

		DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 762

	      INSERT INTO fv_doc_cr_temp (requisition_header_id ,requisition_line_id,session_id)
			VALUES (po_rec.requisition_header_id,po_rec.requisition_line_id,vp_session_id );
Line: 766

	      DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 775

              DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 779

	          INSERT INTO fv_doc_cr_temp (requisition_header_id ,requisition_line_id,session_id)
				VALUES (rec_rec.requisition_header_id,rec_rec.requisition_line_id,vp_session_id );
Line: 783

		   DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 793

              DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 797

	          INSERT INTO fv_doc_cr_temp (requisition_header_id ,requisition_line_id,session_id)
	   		      VALUES (inv_rec.requisition_header_id,inv_rec.requisition_line_id,vp_session_id);
Line: 802

                  DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 810

	    DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 814

	          INSERT INTO fv_doc_cr_temp (requisition_header_id ,requisition_line_id,session_id)
			VALUES (pay_rec.requisition_header_id,pay_rec.requisition_line_id,vp_session_id );
Line: 818

		   DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 839

     SELECT shipment_header_id FROM fv_receipt_master_v frm
     WHERE shipment_header_id = NVL(vp_shipment_header_id,shipment_header_id)
     AND TRUNC(receipt_date) = NVL(vp_rec_date,TRUNC(receipt_date))
     AND vendor_id = vp_vendor_id
     AND  vendor_site_id = vp_vendor_site_id;
Line: 847

    SELECT rsh.shipment_header_id FROM rcv_shipment_headers rsh
          WHERE EXISTS (SELECT 1 FROM rcv_transactions rt
          	WHERE rt.shipment_header_id = rsh.shipment_header_id
          	AND EXISTS (select 1 FROM po_headers ph
	     	    WHERE ph.po_header_id = rt.po_header_id
	   	    AND vendor_id = vp_vendor_id
		    AND vendor_site_id = vp_vendor_site_id
		    AND ph.po_header_id = NVL(vp_po_header_id,ph.po_header_id)
		    AND TRUNC(ph.creation_date) = nvl(vp_po_date,TRUNC(ph.creation_date))
		    AND ph.agent_id = NVL(vp_buyer,ph.agent_id)))
		AND NOT EXISTS(SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
			UNION
	SELECT shipment_header_id FROM rcv_shipment_headers rsh
          WHERE EXISTS (SELECT 1 FROM rcv_transactions rt
          	WHERE rt.shipment_header_id = rsh.shipment_header_id
          	AND EXISTS (select 1 FROM po_headers ph
	     	    WHERE ph.po_header_id = rt.po_header_id
	   	    AND vendor_id = vp_vendor_id
		    AND vendor_site_id = vp_vendor_site_id
		    AND ph.po_header_id = NVL(vp_po_header_id,ph.po_header_id)
		    AND TRUNC(ph.creation_date) = nvl(vp_po_date,TRUNC(ph.creation_date))
		    AND ph.agent_id = NVL(vp_buyer,ph.agent_id)))
     	       AND  EXISTS(SELECT 1 FROM fv_doc_cr_temp
		   WHERE shipment_header_id = rsh.shipment_header_id
		   AND session_id = vp_session_id);
Line: 874

  SELECT rsh.shipment_header_id FROM rcv_shipment_headers rsh
	 WHERE  rsh.vendor_id = vp_vendor_id
	 AND NOT EXISTS (SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
	 AND EXISTS(SELECT 1 FROM rcv_transactions rt,po_headers ph
	     WHERE ph.po_header_id = rt.po_header_id
	     AND rt.shipment_header_id = rsh.shipment_header_id
	     AND ph.vendor_site_id = vp_vendor_site_id
	     AND (EXISTS (SELECT 1 FROM po_req_distributions prd
	          WHERE prd.distribution_id = rt.req_distribution_id
	          AND EXISTS (SELECT 1 FROM po_requisition_lines prl,po_requisition_headers prh
	              WHERE prl.requisition_header_id = prh.requisition_header_id
		      AND prl.requisition_line_id  = prd.requisition_line_id
      		      AND prh.requisition_header_id = NVL(vp_requisition_header_id ,prh.requisition_header_id)
      		      AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date))))
	       OR EXISTS (SELECT 1 FROM po_requisition_lines prl ,po_requisition_headers prh
	              WHERE prl.requisition_header_id = prh.requisition_header_id
		      AND prl.line_location_id  = rt.po_line_location_id
      		      AND prh.requisition_header_id = NVL(vp_requisition_header_id ,prh.requisition_header_id)
      		      AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date)))))

	UNION
	SELECT shipment_header_id FROM rcv_shipment_headers rsh
	 WHERE  rsh.vendor_id = vp_vendor_id
	 AND  EXISTS (SELECT 1 FROM fv_doc_cr_temp fdct
		WHERE fdct.shipment_header_id = rsh.shipment_header_id
		AND fdct.session_id = vp_session_id)
	 AND EXISTS(SELECT 1 FROM rcv_transactions rt,po_headers ph
	     WHERE rt.po_header_id = ph.po_header_id
	     AND rt.shipment_header_id = rsh.shipment_header_id
	     AND ph.vendor_site_id = vp_vendor_site_id
	     AND (EXISTS (SELECT 1 FROM po_req_distributions prd
	          WHERE prd.distribution_id = rt.req_distribution_id
	          AND EXISTS (SELECT 1 FROM po_requisition_lines prl ,po_requisition_headers prh
	              WHERE prl.requisition_header_id = prh.requisition_header_id
		      AND prl.requisition_line_id  = prd.requisition_line_id
      		      AND prh.requisition_header_id = NVL(vp_requisition_header_id ,prh.requisition_header_id)
	              AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date))))
	       OR EXISTS (SELECT 1 FROM po_requisition_lines prl ,po_requisition_headers prh
	              WHERE prl.requisition_header_id = prh.requisition_header_id
		      AND prl.line_location_id  = rt.po_line_location_id
      		      AND prh.requisition_header_id = NVL(vp_requisition_header_id ,prh.requisition_header_id)
	              AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date)))));
Line: 922

	SELECT shipment_header_id FROM rcv_shipment_headers rsh
  	WHERE vendor_id = vp_vendor_id
	AND NOT EXISTS(SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
	AND EXISTS (SELECT 1 FROM rcv_transactions rt,po_headers ph
	    WHERE ph.po_header_id = rt.po_header_id
            AND rt.shipment_header_id = rsh.shipment_header_id
	    AND ph.vendor_site_id = vp_vendor_site_id
	    AND EXISTS (SELECT 1 FROM po_distributions pd WHERE pd.line_location_id = rt.po_line_location_id
	    	AND EXISTS (SELECT 1 FROM ap_invoice_distributions ia
	    	    WHERE ia.po_distribution_id= pd.po_distribution_id
		    AND EXISTS (SELECT 1 FROM ap_invoices ap
			WHERE invoice_id = ia.invoice_id
			AND invoice_id = NVL(vp_invoice_id,invoice_id)
			AND TRUNC(ap.invoice_date) = nvl(vp_invoice_date,TRUNC(ap.invoice_date))
			AND invoice_type_lookup_code = nvl(vp_invoice_type,invoice_type_lookup_code)
			AND invoice_amount = nvl(vp_invoice_amount,invoice_amount)))))
		UNION
	SELECT shipment_header_id FROM rcv_shipment_headers rsh
	WHERE vendor_id = vp_vendor_id
	AND  EXISTS(SELECT 1 FROM fv_doc_cr_temp
		WHERE shipment_header_id = rsh.shipment_header_id
		AND session_id = vp_session_id)
	AND EXISTS (SELECT 1 FROM rcv_transactions rt ,po_headers ph
	    WHERE rt.po_header_id = ph.po_header_id
	    AND rt.shipment_header_id = rsh.shipment_header_id
	    AND ph.vendor_site_id = vp_vendor_site_id
	    AND EXISTS (SELECT 1 FROM po_distributions pd WHERE pd.line_location_id = rt.po_line_location_id
	    	AND EXISTS (SELECT 1 FROM ap_invoice_distributions ia
	    	    WHERE ia.po_distribution_id= pd.po_distribution_id
		    AND EXISTS (SELECT 1 FROM ap_invoices ap
			WHERE invoice_id = ia.invoice_id
			AND invoice_id = NVL(vp_invoice_id,invoice_id)
			AND TRUNC(ap.invoice_date) = nvl(vp_invoice_date,TRUNC(ap.invoice_date))
			AND invoice_type_lookup_code = nvl(vp_invoice_type,invoice_type_lookup_code)
			AND invoice_amount = nvl(vp_invoice_amount,invoice_amount)))));
Line: 960

	SELECT shipment_header_id FROM rcv_shipment_headers rsh
	WHERE vendor_id = vp_vendor_id
	AND NOT EXISTS(SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
	AND EXISTS (SELECT 1 FROM rcv_transactions rt,po_headers ph
     	    WHERE rt.po_header_id = ph.po_header_id
	    AND rt.shipment_header_id = rsh.shipment_header_id
     	    AND ph.vendor_site_id = vp_vendor_site_id
	    AND EXISTS (SELECT 1  FROM po_distributions pd WHERE pd.line_location_id = rt.po_line_location_id
	    	AND EXISTS( SELECT 1 FROM ap_invoice_distributions aid
		WHERE aid.po_distribution_id= pd.po_distribution_id
		AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
		    WHERE aip.invoice_id = aid.invoice_id
		    AND EXISTS (SELECT 1 FROM ap_checks ac
			WHERE ac.check_id = aip.check_id
			AND ac.check_id =  NVL(vp_check_id,ac.check_id)
			AND TRUNC(ac.check_date) = NVL(vp_check_date,TRUNC(ac.check_date))
			AND ac.amount = nvl(vp_amount,ac.amount)
			AND NVL(ac.treasury_pay_number,-1) = nvl(vp_treasury_pay_number,NVL(ac.treasury_pay_number,-1))
			AND (TRUNC(ac.treasury_pay_date) = TRUNC(vp_treasury_pay_date) OR vp_treasury_pay_date IS NULL))))))
	   UNION
	SELECT shipment_header_id FROM rcv_shipment_headers rsh
  	WHERE vendor_id = vp_vendor_id
	AND EXISTS(SELECT 1 FROM fv_doc_cr_temp
		WHERE shipment_header_id = rsh.shipment_header_id
		AND session_id = vp_session_id)
	AND EXISTS (SELECT 1 FROM rcv_transactions rt,po_headers ph
     	    WHERE rt.po_header_id = ph.po_header_id
	    AND rt.shipment_header_id = rsh.shipment_header_id
     	    AND ph.vendor_site_id = vp_vendor_site_id
	    AND EXISTS (SELECT 1  FROM po_distributions pd
                WHERE pd.line_location_id = rt.po_line_location_id
	    	AND EXISTS( SELECT 1 FROM ap_invoice_distributions aid
		WHERE aid.po_distribution_id= pd.po_distribution_id
		AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
		    WHERE aip.invoice_id = aid.invoice_id
		    AND EXISTS (SELECT 1 FROM ap_checks ac
			WHERE ac.check_id = aip.check_id
			AND ac.check_id =  NVL(vp_check_id,ac.check_id)
			AND TRUNC(ac.check_date) = NVL(vp_check_date,TRUNC(ac.check_date))
			AND ac.amount = nvl(vp_amount,ac.amount)
			AND NVL(ac.treasury_pay_number,-1) = NVL(vp_treasury_pay_number,NVL(ac.treasury_pay_number,-1))
			AND (TRUNC(ac.treasury_pay_date) = TRUNC(vp_treasury_pay_date) OR vp_treasury_pay_date IS NULL))))));
Line: 1006

      DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1010

         DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1014

             INSERT INTO fv_doc_cr_temp (shipment_header_id,session_id)
				VALUES (rec_rec.shipment_header_id,vp_session_id);
Line: 1018

	   DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1029

            INSERT INTO fv_doc_cr_temp (shipment_header_id,session_id)
			VALUES	  (po_rec.shipment_header_id,vp_session_id);
Line: 1033

          DELETE from fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1041

        DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1045

             INSERT INTO fv_doc_cr_temp (shipment_header_id,session_id)
			VALUES (req_rec.shipment_header_id,vp_session_id);
Line: 1049

          DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1058

        DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1062

           INSERT INTO fv_doc_cr_temp (shipment_header_id,session_id)
			VALUES (inv_rec.shipment_header_id,vp_session_id);
Line: 1066

           DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1076

      DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1080

          INSERT INTO fv_doc_cr_temp (shipment_header_id,session_id)
		VALUES (pay_rec.shipment_header_id,vp_session_id);
Line: 1084

        DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1106

   SELECT invoice_id FROM ap_invoices ai
   WHERE vendor_id = vp_vendor_id
   AND vendor_site_id = vp_vendor_site_id
   AND NOT EXISTS (SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
   AND (EXISTS (SELECT 1 FROM ap_invoice_distributions aid
	WHERE aid.invoice_id = ai.invoice_id
	AND EXISTS (SELECT 1 FROM po_distributions pd
	    WHERE pd.po_distribution_id = aid.po_distribution_id
	    AND EXISTS(SELECT 1 FROM po_req_distributions prd
		WHERE prd.distribution_id = pd.req_distribution_id
		AND EXISTS (SELECT 1 FROM po_requisition_lines prl
		    WHERE prl.requisition_line_id = prd.requisition_line_id
		    AND EXISTS (SELECT 1 FROM po_requisition_headers prh
			WHERE prh.requisition_header_id = prl.requisition_header_id
			AND prh.requisition_header_id = NVL(vp_requisition_header_id,prh.requisition_header_id )
			AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date))))))
	OR EXISTS (SELECT 1 FROM rcv_transactions rt
	           WHERE rt.transaction_id = aid.rcv_transaction_id
	           AND EXISTS (SELECT 1 FROM po_line_locations pll
	           	WHERE rt.po_line_location_id = pll.line_location_id
	           	AND EXISTS(SELECT 1 FROM po_distributions pd
	           	      WHERE pd.line_location_id = pll.line_location_id
	           	      AND EXISTS (SELECT 1 FROM po_req_distributions prd
			WHERE prd.distribution_id = pd.req_distribution_id
			AND EXISTS (SELECT 1 FROM po_requisition_lines prl
				WHERE prl.requisition_line_id = prd.requisition_line_id
				AND EXISTS (SELECT 1 FROM po_requisition_headers prh
					WHERE prh.requisition_header_id = prl.requisition_header_id
					AND prh.requisition_header_id =     NVL(vp_requisition_header_id,prh.requisition_header_id )
					AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date))))))))))
     UNION
   SELECT invoice_id FROM ap_invoices ai
   WHERE vendor_id = vp_vendor_id
   AND vendor_site_id = vp_vendor_site_id
   AND  EXISTS (SELECT 1 FROM fv_doc_cr_temp
          WHERE invoice_id= ai.invoice_id
	  AND session_id = vp_session_id)
   AND (EXISTS (SELECT 1 FROM ap_invoice_distributions aid
	WHERE aid.invoice_id = ai.invoice_id
	AND EXISTS (SELECT 1 FROM po_distributions pd
	   WHERE pd.po_distribution_id = aid.po_distribution_id
	   AND EXISTS(SELECT 1 FROM po_req_distributions prd
	     WHERE prd.distribution_id = pd.req_distribution_id
	     AND EXISTS (SELECT 1 FROM po_requisition_lines prl
		WHERE prl.requisition_line_id = prd.requisition_line_id
		AND EXISTS (SELECT 1 FROM po_requisition_headers prh
		   WHERE prh.requisition_header_id = prl.requisition_header_id
		   AND prh.requisition_header_id =NVL(vp_requisition_header_id,prh.requisition_header_id )
		   AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date))))))
	OR EXISTS (SELECT 1 FROM rcv_transactions rt
	           WHERE rt.transaction_id = aid.rcv_transaction_id
	           AND EXISTS (SELECT 1 FROM po_line_locations pll
	           	WHERE rt.po_line_location_id = pll.line_location_id
	           	AND EXISTS(SELECT 1 FROM po_distributions pd
	           	      WHERE pd.line_location_id = pll.line_location_id
	           	      AND EXISTS (SELECT 1 FROM po_req_distributions prd
			WHERE prd.distribution_id = pd.req_distribution_id
			AND EXISTS (SELECT 1 FROM po_requisition_lines prl
				WHERE prl.requisition_line_id = prd.requisition_line_id
				AND EXISTS (SELECT 1 FROM po_requisition_headers prh
					WHERE prh.requisition_header_id = prl.requisition_header_id
					AND prh.requisition_header_id =     NVL(vp_requisition_header_id,prh.requisition_header_id )
					AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date))))))))));
Line: 1173

   SELECT invoice_id FROM ap_invoices ai
   WHERE vendor_id = vp_vendor_id
   AND vendor_site_id = vp_vendor_site_id
   AND NOT EXISTS (SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
   AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
		WHERE aid.invoice_id = ai.invoice_id
		AND EXISTS (SELECT 1 FROM po_distributions pd
			WHERE pd.po_distribution_id = aid.po_distribution_id
   			AND EXISTS(SELECT 1 FROM po_headers ph
			WHERE ph.po_header_id = pd.po_header_id
			AND ph.po_header_id = NVL(vp_po_header_id,ph.po_header_id )
			AND TRUNC(ph.creation_date) = NVL( vp_po_date,TRUNC(ph.creation_date))))
	        OR EXISTS (SELECT 1 FROM rcv_transactions rt
			WHERE rt.transaction_id = aid.rcv_transaction_id
   			AND EXISTS(SELECT 1 FROM po_headers ph
			WHERE ph.po_header_id = rt.po_header_id
			AND ph.po_header_id = NVL(vp_po_header_id,rt.po_header_id )
			AND TRUNC(ph.creation_date) = NVL( vp_po_date,TRUNC(ph.creation_date)))))
	UNION
   SELECT invoice_id FROM ap_invoices ai
   WHERE vendor_id = vp_vendor_id
   AND vendor_site_id = vp_vendor_site_id
   AND  EXISTS (SELECT 1 FROM fv_doc_cr_temp
	WHERE invoice_id = ai.invoice_id
        AND session_id = vp_session_id)
   AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
		WHERE aid.invoice_id = ai.invoice_id
		AND EXISTS (SELECT 1 FROM po_distributions pd
			WHERE pd.po_distribution_id = aid.po_distribution_id
   			AND EXISTS(SELECT 1 FROM po_headers ph
			WHERE ph.po_header_id = pd.po_header_id
			AND ph.po_header_id = NVL(vp_po_header_id,ph.po_header_id )
			AND TRUNC(ph.creation_date) = NVL( vp_po_date,TRUNC(ph.creation_date))))
	        OR EXISTS (SELECT 1 FROM rcv_transactions rt
			WHERE rt.transaction_id = aid.rcv_transaction_id
   			AND EXISTS(SELECT 1 FROM po_headers ph
			WHERE ph.po_header_id = rt.po_header_id
			AND ph.po_header_id = NVL(vp_po_header_id,rt.po_header_id )
			AND TRUNC(ph.creation_date) = NVL( vp_po_date,TRUNC(ph.creation_date)))));
Line: 1219

   SELECT invoice_id FROM ap_invoices ai
	   WHERE vendor_id = vp_vendor_id
	   AND vendor_site_id = vp_vendor_site_id
	   AND NOT EXISTS (SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
	   AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
		WHERE aid.invoice_id = ai.invoice_id
		AND (EXISTS (SELECT 1 FROM rcv_transactions rt
		    WHERE rt.transaction_id = aid.rcv_transaction_id
		    AND EXISTS(SELECT 1 FROM rcv_shipment_headers rsh
			WHERE rt.shipment_header_id = rsh.shipment_header_id
			AND rsh.shipment_header_id = NVL(vp_shipment_header_id,rsh.shipment_header_id )
			AND TRUNC(rsh.creation_date) = NVL( vp_rec_date,TRUNC(rsh.creation_date))))
		OR EXISTS (SELECT 1 FROM po_distributions pd
		    WHERE pd.po_distribution_id = aid.po_distribution_id
		    AND EXISTS(SELECT 1 FROM rcv_shipment_lines rsl,rcv_shipment_headers rsh
			WHERE rsl.po_line_location_id = pd.line_location_id
			AND rsl.shipment_header_id = rsh.shipment_header_id
			AND rsh.shipment_header_id = NVL(vp_shipment_header_id,rsh.shipment_header_id )
			AND TRUNC(rsh.creation_date) = NVL( vp_rec_date,TRUNC(rsh.creation_date))))))
	UNION
	 SELECT invoice_id FROM ap_invoices ai
	   WHERE vendor_id = vp_vendor_id
	   AND vendor_site_id = vp_vendor_site_id
	   AND  EXISTS (SELECT 1 FROM fv_doc_cr_temp
                WHERE invoice_id = ai.invoice_id
		AND session_id = vp_session_id)
	   AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
		WHERE aid.invoice_id = ai.invoice_id
		AND (EXISTS (SELECT 1 FROM rcv_transactions rt
		    WHERE rt.transaction_id = aid.rcv_transaction_id
		    AND EXISTS(SELECT 1 FROM rcv_shipment_headers rsh
			WHERE rt.shipment_header_id = rsh.shipment_header_id
			AND rsh.shipment_header_id = NVL(vp_shipment_header_id,rsh.shipment_header_id )
			AND TRUNC(rsh.creation_date) = NVL( vp_rec_date,TRUNC(rsh.creation_date))))
		OR EXISTS (SELECT 1 FROM po_distributions pd
		    WHERE pd.po_distribution_id = aid.po_distribution_id
		    AND EXISTS(SELECT 1 FROM rcv_shipment_lines rsl,rcv_shipment_headers rsh
			WHERE rsl.po_line_location_id = pd.line_location_id
			AND rsl.shipment_header_id = rsh.shipment_header_id
			AND rsh.shipment_header_id = NVL(vp_shipment_header_id,rsh.shipment_header_id )
			AND TRUNC(rsh.creation_date) = NVL( vp_rec_date,TRUNC(rsh.creation_date))))));
Line: 1265

  SELECT invoice_id FROM ap_invoices
	   WHERE vendor_id = vp_vendor_id
	   AND vendor_site_id = vp_vendor_site_id
	   AND  invoice_id = NVL(vp_invoice_id,invoice_id)
	   AND invoice_type_lookup_code = NVL(vp_invoice_type,invoice_type_lookup_code)
	   AND invoice_amount = NVL(vp_invoice_amount,invoice_amount)
	   AND   TRUNC(invoice_date) = NVL(TRUNC(vp_invoice_date), TRUNC(invoice_date)) ;
Line: 1275

 SELECT invoice_id FROM ap_invoices ai
	   WHERE vendor_id = vp_vendor_id
	   AND vendor_site_id = vp_vendor_site_id
	   AND NOT EXISTS (SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
           AND EXISTS ( SELECT 1 FROM ap_invoice_payments aip
		WHERE aip.invoice_id = ai.invoice_id
		AND EXISTS (SELECT 1 FROM ap_checks ac
		    WHERE ac.check_id = aip.check_id
		    AND ac.check_id =  NVL(vp_check_id,ac.check_id)
		    AND TRUNC(ac.check_date) = NVL(vp_check_date,TRUNC(ac.check_date))
		    AND ac.amount = nvl(vp_amount,ac.amount)
		    AND NVL(ac.treasury_pay_number,-1) = nvl(vp_treasury_pay_number,NVL(ac.treasury_pay_number,-1))
		    AND (TRUNC(ac.treasury_pay_date) = TRUNC(vp_treasury_pay_date) OR vp_treasury_pay_date IS NULL)
				))
UNION
 SELECT invoice_id FROM ap_invoices ai
	   WHERE vendor_id = vp_vendor_id
	   AND vendor_site_id = vp_vendor_site_id
	   AND  EXISTS (SELECT 1 FROM fv_doc_cr_temp
		WHERE invoice_id = ai.invoice_id
		AND session_id = vp_session_id)
           AND EXISTS ( SELECT 1 FROM ap_invoice_payments aip
		WHERE aip.invoice_id = ai.invoice_id
		AND EXISTS (SELECT 1 FROM ap_checks ac
			WHERE ac.check_id = aip.check_id
			AND ac.check_id =  NVL(vp_check_id,ac.check_id)
			AND TRUNC(ac.check_date) = NVL(vp_check_date,TRUNC(ac.check_date))
			AND ac.amount = nvl(vp_amount,ac.amount)
			AND NVL(ac.treasury_pay_number,-1) = nvl(vp_treasury_pay_number,NVL(ac.treasury_pay_number,-1))
			AND (TRUNC(ac.treasury_pay_date) = TRUNC(vp_treasury_pay_date) OR vp_treasury_pay_date IS NULL)
					));
Line: 1310

     DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1318

            INSERT INTO fv_doc_cr_temp (invoice_id,session_id)
			VALUES (inv_rec.invoice_id,vp_session_id);
Line: 1322

	   DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1333

             INSERT INTO fv_doc_cr_temp (invoice_id,session_id)
			VALUES  (po_rec.invoice_id,vp_session_id);
Line: 1337

               DELETE from fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1345

          DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1349

              INSERT INTO fv_doc_cr_temp (invoice_id,session_id)
					VALUES (req_rec.invoice_id,vp_session_id);
Line: 1353

             DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1361

          DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1365

               INSERT INTO fv_doc_cr_temp (invoice_id,session_id)
				VALUES (rec_rec.invoice_id,vp_session_id);
Line: 1369

	     DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1379

           DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1383

               INSERT INTO fv_doc_cr_temp (invoice_id,session_id)
			VALUES (pay_rec.invoice_id,vp_session_id);
Line: 1387

               DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1409

   SELECT check_id FROM ap_checks ac
   WHERE vendor_id = vp_vendor_id
   AND vendor_site_id = vp_vendor_site_id
   AND NOT EXISTS (SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
   AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
       WHERE aip.check_id = ac.check_id
       AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
	   WHERE aid.invoice_id = aip.invoice_id
	   AND (EXISTS (SELECT 1 FROM po_distributions pd
		WHERE pd.po_distribution_id = aid.po_distribution_id
		AND EXISTS(SELECT 1 FROM po_req_distributions prd
			WHERE prd.distribution_id = pd.req_distribution_id
			AND EXISTS (SELECT 1 FROM po_requisition_lines prl
				WHERE prl.requisition_line_id = prd.requisition_line_id
				AND EXISTS (SELECT 1 FROM po_requisition_headers prh
				    WHERE prh.requisition_header_id = prl.requisition_header_id
				    AND prh.requisition_header_id = NVL(vp_requisition_header_id,prh.requisition_header_id )
				    AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date))))))
		OR EXISTS (SELECT 1 FROM rcv_transactions rt
			WHERE rt.transaction_id = aid.rcv_transaction_id
			AND EXISTS (SELECT 1 FROM po_line_locations pll
			    WHERE pll.line_location_id = rt.po_line_location_id
			    AND EXISTS (SELECT 1 FROM  po_distributions pd
			        WHERE pd.line_location_id = pll.line_location_id
				AND EXISTS(SELECT 1 FROM po_req_distributions prd
				    WHERE prd.distribution_id = pd.req_distribution_id
				    AND EXISTS (SELECT 1 FROM po_requisition_lines prl
					WHERE prl.requisition_line_id = prd.requisition_line_id
					AND EXISTS (SELECT 1 FROM po_requisition_headers prh
				    	  WHERE prh.requisition_header_id = prl.requisition_header_id
				    	  AND prh.requisition_header_id =     NVL(vp_requisition_header_id,prh.requisition_header_id )
				          AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date)))))))))))

UNION
   SELECT check_id FROM ap_checks ac
   WHERE vendor_id = vp_vendor_id
   AND vendor_site_id = vp_vendor_site_id
   AND EXISTS (SELECT 1 FROM fv_doc_cr_temp
		WHERE check_id = ac.check_id
		AND session_id = vp_session_id)
      AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
       WHERE aip.check_id = ac.check_id
       AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
	   WHERE aid.invoice_id = aip.invoice_id
	   AND (EXISTS (SELECT 1 FROM po_distributions pd
		WHERE pd.po_distribution_id = aid.po_distribution_id
		AND EXISTS(SELECT 1 FROM po_req_distributions prd
			WHERE prd.distribution_id = pd.req_distribution_id
			AND EXISTS (SELECT 1 FROM po_requisition_lines prl
				WHERE prl.requisition_line_id = prd.requisition_line_id
				AND EXISTS (SELECT 1 FROM po_requisition_headers prh
				    WHERE prh.requisition_header_id = prl.requisition_header_id
				    AND prh.requisition_header_id = NVL(vp_requisition_header_id,prh.requisition_header_id )
				    AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date))))))
		OR EXISTS (SELECT 1 FROM rcv_transactions rt
			WHERE rt.transaction_id = aid.rcv_transaction_id
			AND EXISTS (SELECT 1 FROM po_line_locations pll
			    WHERE pll.line_location_id = rt.po_line_location_id
			    AND EXISTS (SELECT 1 FROM  po_distributions pd
			        WHERE pd.line_location_id = pll.line_location_id
				AND EXISTS(SELECT 1 FROM po_req_distributions prd
				    WHERE prd.distribution_id = pd.req_distribution_id
				    AND EXISTS (SELECT 1 FROM po_requisition_lines prl
					WHERE prl.requisition_line_id = prd.requisition_line_id
					AND EXISTS (SELECT 1 FROM po_requisition_headers prh
				    	  WHERE prh.requisition_header_id = prl.requisition_header_id
				    	  AND prh.requisition_header_id =     NVL(vp_requisition_header_id,prh.requisition_header_id )
				          AND TRUNC(prh.creation_date) = NVL(vp_req_date,TRUNC(prh.creation_date)))))))))));
Line: 1480

	SELECT check_id FROM ap_checks ac
	 WHERE  vendor_id =  vp_vendor_id
	 AND vendor_site_id = vp_vendor_site_id
	 AND NOT EXISTS (SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
	 AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
	      WHERE aip.check_id = ac.check_id
 	      AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
		    WHERE aid.invoice_id = aip.invoice_id
		    AND (EXISTS (SELECT 1 FROM po_distributions pd
			   WHERE pd.po_distribution_id = aid.po_distribution_id
			   AND EXISTS(SELECT 1 FROM po_headers ph
				WHERE ph.po_header_id = pd.po_header_id
				AND ph.po_header_id = NVL(vp_po_header_id,ph.po_header_id )
				AND TRUNC(ph.creation_date) = NVL( vp_po_date,TRUNC(ph.creation_date))))
		        OR EXISTS (SELECT 1 FROM rcv_transactions rt
			   WHERE rt.transaction_id = aid.rcv_transaction_id
			   AND EXISTS(SELECT 1 FROM po_headers ph
				WHERE ph.po_header_id = rt.po_header_id
				AND ph.po_header_id = NVL(vp_po_header_id,ph.po_header_id )
				AND TRUNC(ph.creation_date) = NVL( vp_po_date,TRUNC(ph.creation_date)))))))

	UNION
	SELECT check_id FROM ap_checks ac
         WHERE  vendor_id =  vp_vendor_id
	 AND vendor_site_id = vp_vendor_site_id
	 AND  EXISTS (SELECT 1 FROM fv_doc_cr_temp
		WHERE  check_id= ac.check_id
		AND session_id = vp_session_id)
	 AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
	      WHERE aip.check_id = ac.check_id
 	      AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
		    WHERE aid.invoice_id = aip.invoice_id
		    AND (EXISTS (SELECT 1 FROM po_distributions pd
			   WHERE pd.po_distribution_id = aid.po_distribution_id
			   AND EXISTS(SELECT 1 FROM po_headers ph
				WHERE ph.po_header_id = pd.po_header_id
				AND ph.po_header_id = NVL(vp_po_header_id,ph.po_header_id )
				AND TRUNC(ph.creation_date) = NVL( vp_po_date,TRUNC(ph.creation_date))))
		        OR EXISTS (SELECT 1 FROM rcv_transactions rt
			   WHERE rt.transaction_id = aid.rcv_transaction_id
			   AND EXISTS(SELECT 1 FROM po_headers ph
				WHERE ph.po_header_id = rt.po_header_id
				AND ph.po_header_id = NVL(vp_po_header_id,ph.po_header_id )
				AND TRUNC(ph.creation_date) = NVL( vp_po_date,TRUNC(ph.creation_date)))))));
Line: 1528

	SELECT check_id FROM ap_checks ac
	 WHERE  vendor_id =  vp_vendor_id
	 AND vendor_site_id = vp_vendor_site_id
	 AND NOT EXISTS (SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
	 AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
	        WHERE aip.check_id = ac.check_id
	 	AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
		    WHERE aid.invoice_id = aip.invoice_id
		    AND EXISTS (SELECT 1 FROM po_distributions pd WHERE pd.po_distribution_id = aid.po_distribution_id
		    	AND EXISTS( SELECT 1 FROM rcv_transactions rt
			      WHERE rt.po_line_location_id = pd.line_location_id
			      AND EXISTS(SELECT 1 FROM rcv_shipment_headers rsh
					WHERE rt.shipment_header_id = rsh.shipment_header_id
					AND rsh.shipment_header_id = NVL(vp_shipment_header_id,rsh.shipment_header_id )
					AND TRUNC(rsh.creation_date) = NVL( vp_rec_date,TRUNC(rsh.creation_date)))))))
	UNION
	SELECT check_id FROM ap_checks ac
	 WHERE  vendor_id =  vp_vendor_id
	 AND vendor_site_id = vp_vendor_site_id
	 AND  EXISTS (SELECT 1 FROM fv_doc_cr_temp
		WHERE check_id = ac.check_id
		AND session_id = vp_session_id)
	 AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
	        WHERE aip.check_id = ac.check_id
	 	AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
		    WHERE aid.invoice_id = aip.invoice_id
		    AND EXISTS (SELECT 1 FROM po_distributions pd WHERE pd.po_distribution_id = aid.po_distribution_id
		    	AND EXISTS( SELECT 1 FROM rcv_transactions rt
			      WHERE rt.po_line_location_id = pd.line_location_id
			      AND EXISTS(SELECT 1 FROM rcv_shipment_headers rsh
					WHERE rt.shipment_header_id = rsh.shipment_header_id
					AND rsh.shipment_header_id = NVL(vp_shipment_header_id,rsh.shipment_header_id )
					AND TRUNC(rsh.creation_date) = NVL( vp_rec_date,TRUNC(rsh.creation_date)))))));
Line: 1566

      SELECT check_id FROM ap_checks ac
	   WHERE  vendor_id =  vp_vendor_id
		 AND vendor_site_id = vp_vendor_site_id
		 AND NOT EXISTS (SELECT 1 FROM fv_doc_cr_temp WHERE session_id = vp_session_id)
	         AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
		             WHERE aip.check_id = ac.check_id
			     AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
			         WHERE aid.invoice_id = aip.invoice_id
			         AND EXISTS (SELECT 1 FROM ap_invoices ai
			  	     WHERE  ai.invoice_id = aid.invoice_id
			  	     AND invoice_type_lookup_code = NVL(vp_invoice_type,invoice_type_lookup_code)
				     AND ai.invoice_id = NVL(vp_invoice_id,ai.invoice_id )
				     AND ai.invoice_amount = NVL(vp_invoice_amount,ai.invoice_amount)
				     AND TRUNC(ai.invoice_date) = NVL( vp_invoice_date,TRUNC(ai.invoice_date)))))
	UNION
	SELECT check_id FROM ap_checks ac
	   WHERE  vendor_id =  vp_vendor_id
		 AND vendor_site_id = vp_vendor_site_id
		 AND  EXISTS (SELECT 1 FROM fv_doc_cr_temp
			WHERE check_id = ac.check_id
			AND session_id = vp_session_id)
	         AND EXISTS (SELECT 1 FROM ap_invoice_payments aip
		     WHERE aip.check_id = ac.check_id
		     AND EXISTS (SELECT 1 FROM ap_invoice_distributions aid
			WHERE aid.invoice_id = aip.invoice_id
			AND EXISTS (SELECT 1 FROM ap_invoices ai
			    WHERE  ai.invoice_id = aid.invoice_id
			    AND invoice_type_lookup_code = NVL(vp_invoice_type,invoice_type_lookup_code)
			    AND ai.invoice_id = NVL(vp_invoice_id,ai.invoice_id )
			    AND ai.invoice_amount = NVL(vp_invoice_amount,ai.invoice_amount)
			    AND TRUNC(ai.invoice_date) = NVL(    TRUNC(vp_invoice_date),TRUNC(ai.invoice_date)))));
Line: 1600

	SELECT check_id FROM ap_checks ac
		WHERE vendor_id =  vp_vendor_id
		AND vendor_site_id = vp_vendor_site_id
		AND ac.check_id =  NVL(vp_check_id,ac.check_id)
		AND ac.check_date = NVL(vp_check_date,ac.check_date)
		AND ac.amount = nvl(vp_amount,ac.amount)
		AND  (TRUNC(ac.treasury_pay_date) = TRUNC(vp_treasury_pay_date) OR vp_treasury_pay_date IS NULL)
		AND  NVL(ac.treasury_pay_number,-1) = NVL(vp_treasury_pay_number,NVL(ac.treasury_pay_number,-1));
Line: 1611

	DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1616

	   DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1620

	       INSERT INTO fv_doc_cr_temp (check_id,session_id)
			VALUES (pay_rec.check_id,vp_session_id);
Line: 1624

	     DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1635

                INSERT INTO fv_doc_cr_temp (check_id,session_id)
			VALUES	  (po_rec.check_id,vp_session_id);
Line: 1639

	       DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1647

          DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1651

               INSERT INTO fv_doc_cr_temp (check_id,session_id)
			VALUES (req_rec.check_id,vp_session_id);
Line: 1655

	       DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1663

              DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1667

  		  INSERT INTO fv_doc_cr_temp (check_id,session_id)
				VALUES (rec_rec.check_id,vp_session_id);
Line: 1671

		   DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1680

              DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;
Line: 1684

 		   INSERT INTO fv_doc_cr_temp (check_id,session_id)
				VALUES (inv_rec.check_id,vp_session_id);
Line: 1688

		   DELETE FROM fv_doc_cr_temp WHERE session_id = vp_session_id;