summaryrefslogtreecommitdiff
path: root/sql/modules/chart.sql
blob: 4575bc69e68f0fa8bfd0b7ea887e68b7211c817f (plain)
  1. CREATE OR REPLACE FUNCTION chart_list_cash(in_account_class int)
  2. RETURNS SETOF chart AS
  3. $$
  4. DECLARE resultrow record;
  5. link_string text;
  6. BEGIN
  7. IF in_account_class = 1 THEN
  8. link_string := '%AR_paid%';
  9. ELSE
  10. link_string := '%AP_paid%';
  11. END IF;
  12. FOR resultrow IN
  13. SELECT * FROM chart
  14. WHERE link LIKE link_string
  15. ORDER BY accno
  16. LOOP
  17. return next resultrow;
  18. END LOOP;
  19. END;
  20. $$ language plpgsql;
  21. COMMENT ON FUNCTION chart_list_cash(in_account_class int) IS
  22. $$ This function returns the cash account acording with in_account_class which must be 1 or 2 $$;
  23. CREATE OR REPLACE FUNCTION chart_get_ar_ap(in_account_class int)
  24. RETURNS SETOF chart AS
  25. $$
  26. DECLARE out_row chart%ROWTYPE;
  27. BEGIN
  28. IF in_account_class NOT IN (1, 2) THEN
  29. RAISE EXCEPTION 'Bad Account Type';
  30. END IF;
  31. FOR out_row IN
  32. SELECT * FROM chart
  33. WHERE link = CASE WHEN in_account_class = 1 THEN 'AP'
  34. WHEN in_account_class = 2 THEN 'AR'
  35. END
  36. LOOP
  37. RETURN NEXT out_row;
  38. END LOOP;
  39. END;
  40. $$ LANGUAGE PLPGSQL;
  41. COMMENT ON FUNCTION chart_get_ar_ap(in_account_class int) IS
  42. $$ This function returns the cash account acording with in_account_class which must be 1 or 2 $$;