summaryrefslogtreecommitdiff
path: root/sql/modules/Vendor.sql
blob: 6676643bd7bd80344f8cae394cd5e14e510c88fd (plain)
  1. BEGIN;
  2. -- TODO: Move indexes to Pg-database
  3. /* Disabling until we can do some more refactoring here.
  4. CREATE OR REPLACE FUNCTION vendor_search(in_name TEXT, in_address TEXT,
  5. in_city_prov TEXT)
  6. RETURNS SETOF vendor_search_return AS $$
  7. -- searches vendor name, account number, street address, city, state,
  8. -- other location-based stuff
  9. declare
  10. v_row vendor_search_return;
  11. query text;
  12. begin
  13. for v_row in select c.legal_name, v.* from vendor v
  14. join company c on c.entity_id = v.entity_id
  15. join entity e on e.id = v.entity_id
  16. join company_to_location ctl on c.id = ctl.company_id
  17. join location l on l.id = ctl.location_id
  18. where (
  19. l.line_one % in_address
  20. OR l.line_two % in_address
  21. OR l.line_three % in_address
  22. )
  23. OR l.city_province % in_city_prov
  24. OR (
  25. c.legal_name % in_name
  26. OR e.name % in_name
  27. )
  28. LOOP
  29. RETURN NEXT v_row;
  30. END LOOP;
  31. RETURN;
  32. end;
  33. $$ language 'plpgsql';
  34. */
  35. COMMIT;