summaryrefslogtreecommitdiff
path: root/sql/modules/Customer.sql
blob: 317405b0c8f427e1694cd2fc33810b69939578df (plain)
  1. BEGIN;
  2. CREATE OR REPLACE FUNCTION customer_location_save (
  3. in_entity_id int,
  4. in_location_class int, in_line_one text, in_line_two text,
  5. in_line_three text,
  6. in_city TEXT, in_state text, in_mail_code text, in_country_id int
  7. ) returns int AS $$
  8. BEGIN
  9. return _entity_location_save(
  10. in_entity_id, NULL,
  11. in_location_class, in_line_one, in_line_two, in_line_three,
  12. in_city, in_state, in_mail_code, in_country_id);
  13. END;
  14. $$ language 'plpgsql';
  15. /* Disabling until we can work on this a little more.
  16. CREATE OR REPLACE FUNCTION customer_search(in_pattern TEXT) returns setof customer_search_return as $$
  17. -- searches customer name, account number, street address, city, state,
  18. -- other location-based stuff
  19. declare
  20. v_row customer_search_return;
  21. query text;
  22. begin
  23. for v_row in select c.legal_name, v.* from customer v
  24. join company c on c.entity_id = v.entity_id
  25. join entity e on e.id = v.entity_id
  26. join company_to_location ctl on c.id = ctl.company_id
  27. join location l on l.id = ctl.location_id
  28. where l.line_one % in_pattern
  29. OR l.line_two % in_pattern
  30. OR l.line_three % in_pattern
  31. OR l.city_province % in_pattern
  32. OR c.legal_name % in_pattern
  33. OR e.name % in_pattern
  34. LOOP
  35. RETURN NEXT v_row;
  36. END LOOP;
  37. RETURN;
  38. end;
  39. $$ language 'plpgsql';
  40. */
  41. COMMIT;