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