summaryrefslogtreecommitdiff
path: root/sql/modules/Company.sql
blob: c411885372bdedbab8d2628e1fb924ce737a4b17 (plain)
  1. -- BEGIN;
  2. CREATE TYPE company_search_result AS (
  3. entity_id int,
  4. company_id int,
  5. entity_credit_id int,
  6. meta_number text,
  7. entity_class int,
  8. legal_name text,
  9. sic_code text,
  10. business_type text,
  11. curr text
  12. );
  13. CREATE OR REPLACE FUNCTION company__search
  14. (in_account_class int, in_contact text, in_contact_info text[],
  15. in_meta_number text, in_address text, in_city text, in_state text,
  16. in_mail_code text, in_country text, in_date_from date, in_date_to date,
  17. in_business_id int, in_legal_name text)
  18. RETURNS SETOF company_search_result AS $$
  19. DECLARE
  20. out_row company_search_result;
  21. loop_count int;
  22. t_contact_info text[];
  23. BEGIN
  24. t_contact_info = in_contact_info;
  25. FOR out_row IN
  26. SELECT e.id, c.id, ec.id, ec.meta_number, ec.entity_class,
  27. c.legal_name, c.sic_code, b.description , ec.curr::text
  28. FROM entity e
  29. JOIN company c ON (e.id = c.entity_id)
  30. JOIN entity_credit_account ec ON (ec.entity_id = e.id)
  31. LEFT JOIN business b ON (ec.business_id = b.id)
  32. WHERE ec.entity_class = in_account_class
  33. AND (c.id IN (select company_id FROM company_to_contact
  34. WHERE contact LIKE ALL(t_contact_info))
  35. OR '' LIKE ALL(t_contact_info))
  36. AND (ec.meta_number = in_meta_number
  37. OR in_meta_number IS NULL)
  38. AND (c.legal_name like '%' || in_legal_name || '%'
  39. OR in_legal_name IS NULL)
  40. AND ((in_address IS NULL AND in_city IS NULL
  41. AND in_state IS NULL
  42. AND in_country IS NULL)
  43. OR (c.id IN
  44. (select company_id FROM company_to_location
  45. WHERE location_id IN
  46. (SELECT id FROM location
  47. WHERE line_one
  48. ilike '%' ||
  49. coalesce(in_address, '')
  50. || '%'
  51. AND city ILIKE
  52. '%' ||
  53. coalesce(in_city, '')
  54. || '%'
  55. AND state ILIKE
  56. '%' ||
  57. coalesce(in_state, '')
  58. || '%'
  59. AND mail_code ILIKE
  60. '%' ||
  61. coalesce(in_mail_code,
  62. '')
  63. || '%'
  64. AND country_id IN
  65. (SELECT id FROM country
  66. WHERE name LIKE '%' ||
  67. in_country ||'%'
  68. OR short_name
  69. ilike
  70. in_country)))))
  71. AND (ec.business_id =
  72. coalesce(in_business_id, ec.business_id)
  73. OR (ec.business_id IS NULL
  74. AND in_business_id IS NULL))
  75. AND (ec.startdate <= coalesce(in_date_to,
  76. ec.startdate)
  77. OR (ec.startdate IS NULL))
  78. AND (ec.enddate >= coalesce(in_date_from, ec.enddate)
  79. OR (ec.enddate IS NULL))
  80. LOOP
  81. RETURN NEXT out_row;
  82. END LOOP;
  83. END;
  84. $$ language plpgsql;
  85. CREATE OR REPLACE FUNCTION entity__save_notes(in_entity_id int, in_note text)
  86. RETURNS INT AS
  87. $$
  88. DECLARE out_id int;
  89. BEGIN
  90. -- TODO, change this to create vector too
  91. INSERT INTO entity_note (ref_key, note_class, entity_id, note, vector)
  92. VALUES (in_entity_id, 1, in_entity_id, in_note, '');
  93. SELECT currval('note_id_seq') INTO out_id;
  94. RETURN out_id;
  95. END;
  96. $$ LANGUAGE PLPGSQL;
  97. CREATE OR REPLACE FUNCTION eca__save_notes(in_credit_id int, in_note text)
  98. RETURNS INT AS
  99. $$
  100. DECLARE out_id int;
  101. BEGIN
  102. -- TODO, change this to create vector too
  103. INSERT INTO eca_note (ref_key, note_class, note, vector)
  104. VALUES (in_credit_id, 3, in_note, '');
  105. SELECT currval('note_id_seq') INTO out_id;
  106. RETURN out_id;
  107. END;
  108. $$ LANGUAGE PLPGSQL;
  109. CREATE OR REPLACE FUNCTION entity_credit_get_id_by_meta_number
  110. (in_meta_number text, in_account_class int)
  111. returns int AS
  112. $$
  113. DECLARE out_credit_id int;
  114. BEGIN
  115. SELECT id INTO out_credit_id
  116. FROM entity_credit_account
  117. WHERE meta_number = in_meta_number
  118. AND entity_class = in_account_class;
  119. RETURN out_credit_id;
  120. END;
  121. $$ LANGUAGE plpgsql;
  122. CREATE OR REPLACE FUNCTION entity_list_contact_class()
  123. RETURNS SETOF contact_class AS
  124. $$
  125. DECLARE out_row RECORD;
  126. BEGIN
  127. FOR out_row IN
  128. SELECT * FROM contact_class ORDER BY id
  129. LOOP
  130. RETURN NEXT out_row;
  131. END LOOP;
  132. END;
  133. $$ language plpgsql;
  134. CREATE TYPE entity_credit_search_return AS (
  135. legal_name text,
  136. id int,
  137. entity_id int,
  138. entity_class int,
  139. discount numeric,
  140. taxincluded bool,
  141. creditlimit numeric,
  142. terms int2,
  143. meta_number text,
  144. business_id int,
  145. language_code text,
  146. pricegroup_id int,
  147. curr char(3),
  148. startdate date,
  149. enddate date,
  150. ar_ap_account_id int,
  151. cash_account_id int,
  152. tax_id text,
  153. threshold numeric
  154. );
  155. CREATE TYPE entity_credit_retrieve AS (
  156. id int,
  157. entity_id int,
  158. entity_class int,
  159. discount numeric,
  160. taxincluded bool,
  161. creditlimit numeric,
  162. terms int2,
  163. meta_number text,
  164. business_id int,
  165. language_code text,
  166. pricegroup_id int,
  167. curr text,
  168. startdate date,
  169. enddate date,
  170. ar_ap_account_id int,
  171. cash_account_id int,
  172. threshold numeric,
  173. control_code text,
  174. credit_id int
  175. );
  176. COMMENT ON TYPE entity_credit_search_return IS
  177. $$ This may change in 1.4 and should not be relied upon too much $$;
  178. CREATE OR REPLACE FUNCTION entity_credit_get_id
  179. (in_entity_id int, in_entity_class int, in_meta_number text)
  180. RETURNS int AS $$
  181. DECLARE out_var int;
  182. BEGIN
  183. SELECT id INTO out_var FROM entity_credit_account
  184. WHERE entity_id = in_entity_id
  185. AND in_entity_class = entity_class
  186. AND in_meta_number = meta_number;
  187. RETURN out_var;
  188. END;
  189. $$ language plpgsql;
  190. CREATE OR REPLACE FUNCTION entity__list_credit
  191. (in_entity_id int, in_entity_class int)
  192. RETURNS SETOF entity_credit_retrieve AS
  193. $$
  194. DECLARE out_row entity_credit_retrieve;
  195. BEGIN
  196. FOR out_row IN
  197. SELECT c.id, e.id, ec.entity_class, ec.discount,
  198. ec.taxincluded, ec.creditlimit, ec.terms,
  199. ec.meta_number, ec.business_id, ec.language_code,
  200. ec.pricegroup_id, ec.curr, ec.startdate,
  201. ec.enddate, ec.ar_ap_account_id, ec.cash_account_id,
  202. ec.threshold, e.control_code, ec.id
  203. FROM company c
  204. JOIN entity e ON (c.entity_id = e.id)
  205. JOIN entity_credit_account ec ON (c.entity_id = ec.entity_id)
  206. WHERE e.id = in_entity_id
  207. AND ec.entity_class =
  208. CASE WHEN in_entity_class = 3 THEN 2
  209. WHEN in_entity_class IS NULL
  210. THEN ec.entity_class
  211. ELSE in_entity_class END
  212. LOOP
  213. RETURN NEXT out_row;
  214. END LOOP;
  215. END;
  216. $$ LANGUAGE PLPGSQL;
  217. CREATE OR REPLACE FUNCTION company_retrieve (in_entity_id int) RETURNS company AS
  218. $$
  219. DECLARE t_company company;
  220. BEGIN
  221. SELECT * INTO t_company FROM company WHERE entity_id = in_entity_id;
  222. RETURN t_company;
  223. END;
  224. $$ language plpgsql;
  225. CREATE TYPE company_billing_info AS (
  226. legal_name text,
  227. meta_number text,
  228. tax_id text,
  229. street1 text,
  230. street2 text,
  231. street3 text,
  232. city text,
  233. state text,
  234. mail_code text,
  235. country text
  236. );
  237. CREATE OR REPLACE FUNCTION company_get_billing_info (in_id int)
  238. returns company_billing_info as
  239. $$
  240. DECLARE out_var company_billing_info;
  241. t_id INT;
  242. BEGIN
  243. select c.legal_name, eca.meta_number, c.tax_id, a.line_one, a.line_two, a.line_three,
  244. a.city, a.state, a.mail_code, cc.name
  245. into out_var
  246. FROM company c
  247. JOIN entity_credit_account eca ON (eca.entity_id = c.entity_id)
  248. JOIN eca_to_location cl ON (eca.id = cl.credit_id)
  249. JOIN location a ON (a.id = cl.location_id)
  250. JOIN country cc ON (cc.id = a.country_id)
  251. WHERE eca.id = in_id AND location_class = 1;
  252. RETURN out_var;
  253. END;
  254. $$ language plpgsql;
  255. CREATE OR REPLACE FUNCTION company_save (
  256. in_id int, in_control_code text, in_entity_class int,
  257. in_name text, in_tax_id TEXT,
  258. in_entity_id int, in_sic_code text
  259. ) RETURNS INT AS $$
  260. DECLARE t_entity_id INT;
  261. t_company_id INT;
  262. t_control_code TEXT;
  263. BEGIN
  264. t_company_id := in_id;
  265. IF in_control_code IS NULL THEN
  266. t_control_code := setting_increment('company_control');
  267. ELSE
  268. t_control_code := in_control_code;
  269. END IF;
  270. IF in_entity_id IS NULL THEN
  271. IF in_id IS NULL THEN
  272. RAISE NOTICE 'in_id is null';
  273. SELECT id INTO t_company_id FROM company
  274. WHERE entity_id = (SELECT id FROM entity WHERE
  275. control_code = t_control_code);
  276. END IF;
  277. IF t_company_id IS NOT NULL THEN
  278. SELECT entity_id INTO t_entity_id FROM company
  279. WHERE id = t_company_id;
  280. END IF;
  281. ELSE
  282. t_entity_id := in_entity_id;
  283. END IF;
  284. IF t_entity_id IS NULL THEN
  285. INSERT INTO entity (name, entity_class, control_code)
  286. VALUES (in_name, in_entity_class, t_control_code);
  287. t_entity_id := currval('entity_id_seq');
  288. END IF;
  289. UPDATE company
  290. SET legal_name = in_name,
  291. tax_id = in_tax_id,
  292. sic_code = in_sic_code
  293. WHERE id = t_company_id;
  294. IF NOT FOUND THEN
  295. INSERT INTO company(entity_id, legal_name, tax_id, sic_code)
  296. VALUES (t_entity_id, in_name, in_tax_id, in_sic_code);
  297. END IF;
  298. RETURN t_entity_id;
  299. END;
  300. $$ LANGUAGE PLPGSQL;
  301. CREATE OR REPLACE FUNCTION entity_credit_save (
  302. in_credit_id int, in_entity_class int,
  303. in_entity_id int,
  304. in_discount numeric, in_taxincluded bool, in_creditlimit numeric,
  305. in_discount_terms int,
  306. in_terms int, in_meta_number varchar(32), in_business_id int,
  307. in_language varchar(6), in_pricegroup_id int,
  308. in_curr char, in_startdate date, in_enddate date,
  309. in_threshold NUMERIC,
  310. in_ar_ap_account_id int,
  311. in_cash_account_id int
  312. ) returns INT as $$
  313. DECLARE
  314. t_entity_class int;
  315. l_id int;
  316. BEGIN
  317. update entity_credit_account SET
  318. discount = in_discount,
  319. taxincluded = in_taxincluded,
  320. creditlimit = in_creditlimit,
  321. terms = in_terms,
  322. ar_ap_account_id = in_ar_ap_account_id,
  323. cash_account_id = in_cash_account_id,
  324. meta_number = in_meta_number,
  325. business_id = in_business_id,
  326. language_code = in_language,
  327. pricegroup_id = in_pricegroup_id,
  328. curr = in_curr,
  329. startdate = in_startdate,
  330. enddate = in_enddate,
  331. threshold = in_threshold,
  332. discount_terms = in_discount_terms
  333. where id = in_credit_id;
  334. IF FOUND THEN
  335. RETURN in_credit_id;
  336. ELSE
  337. INSERT INTO entity_credit_account (
  338. entity_id,
  339. entity_class,
  340. discount,
  341. taxincluded,
  342. creditlimit,
  343. terms,
  344. meta_number,
  345. business_id,
  346. language_code,
  347. pricegroup_id,
  348. curr,
  349. startdate,
  350. enddate,
  351. discount_terms,
  352. threshold,
  353. ar_ap_account_id,
  354. cash_account_id
  355. )
  356. VALUES (
  357. in_entity_id,
  358. in_entity_class,
  359. in_discount / 100,
  360. in_taxincluded,
  361. in_creditlimit,
  362. in_terms,
  363. in_meta_number,
  364. in_business_id,
  365. in_language,
  366. in_pricegroup_id,
  367. in_curr,
  368. in_startdate,
  369. in_enddate,
  370. in_discount_terms,
  371. in_threshold,
  372. in_ar_ap_account_id,
  373. in_cash_account_id
  374. );
  375. -- entity note class
  376. RETURN currval('entity_credit_account_id_seq');
  377. END IF;
  378. END;
  379. $$ language 'plpgsql';
  380. CREATE OR REPLACE FUNCTION company__list_locations(in_entity_id int)
  381. RETURNS SETOF location_result AS
  382. $$
  383. DECLARE out_row RECORD;
  384. BEGIN
  385. FOR out_row IN
  386. SELECT l.id, l.line_one, l.line_two, l.line_three, l.city,
  387. l.state, l.mail_code, c.name, lc.class
  388. FROM location l
  389. JOIN company_to_location ctl ON (ctl.location_id = l.id)
  390. JOIN location_class lc ON (ctl.location_class = lc.id)
  391. JOIN country c ON (c.id = l.country_id)
  392. WHERE ctl.company_id = (select id from company where entity_id = in_entity_id)
  393. ORDER BY lc.id, l.id, c.name
  394. LOOP
  395. RETURN NEXT out_row;
  396. END LOOP;
  397. END;
  398. $$ LANGUAGE PLPGSQL;
  399. CREATE TYPE contact_list AS (
  400. class text,
  401. description text,
  402. contact text
  403. );
  404. CREATE OR REPLACE FUNCTION company__list_contacts(in_entity_id int)
  405. RETURNS SETOF contact_list AS $$
  406. DECLARE out_row contact_list;
  407. BEGIN
  408. FOR out_row IN
  409. SELECT cl.class, c.description, c.contact
  410. FROM company_to_contact c
  411. JOIN contact_class cl ON (c.contact_class_id = cl.id)
  412. WHERE company_id =
  413. (select id FROM company
  414. WHERE entity_id = in_entity_id)
  415. LOOP
  416. return next out_row;
  417. END LOOP;
  418. END;
  419. $$ language plpgsql;
  420. CREATE OR REPLACE FUNCTION company__list_bank_account(in_entity_id int)
  421. RETURNS SETOF entity_bank_account AS
  422. $$
  423. DECLARE out_row entity_bank_account%ROWTYPE;
  424. BEGIN
  425. FOR out_row IN
  426. SELECT * from entity_bank_account where entity_id = in_entity_id
  427. LOOP
  428. RETURN NEXT out_row;
  429. END LOOP;
  430. END;
  431. $$ LANGUAGE PLPGSQL;
  432. CREATE OR REPLACE FUNCTION entity__save_bank_account
  433. (in_entity_id int, in_credit_id int, in_bic text, in_iban text)
  434. RETURNS int AS
  435. $$
  436. DECLARE out_id int;
  437. BEGIN
  438. INSERT INTO entity_bank_account(entity_id, bic, iban)
  439. VALUES(in_entity_id, in_bic, in_iban);
  440. SELECT CURRVAL('entity_bank_account_id_seq') INTO out_id ;
  441. IF in_credit_id IS NOT NULL THEN
  442. UPDATE entity_credit_account SET bank_account = out_id
  443. WHERE id = in_credit_id;
  444. END IF;
  445. RETURN out_id;
  446. END;
  447. $$ LANGUAGE PLPGSQL;
  448. CREATE OR REPLACE FUNCTION entity__save_bank_account
  449. (in_entity_id int, in_bic text, in_iban text)
  450. RETURNS int AS
  451. $$
  452. DECLARE out_id int;
  453. BEGIN
  454. INSERT INTO entity_bank_account(entity_id, bic, iban)
  455. VALUES(in_entity_id, in_bic, in_iban);
  456. SELECT CURRVAL('entity_bank_account_id_seq') INTO out_id ;
  457. RETURN out_id;
  458. END;
  459. $$ LANGUAGE PLPGSQL;
  460. CREATE OR REPLACE FUNCTION company__save_contact
  461. (in_entity_id int, in_contact_class int, in_description text, in_contact text)
  462. RETURNS INT AS
  463. $$
  464. DECLARE out_id int;
  465. BEGIN
  466. INSERT INTO company_to_contact(company_id, contact_class_id,
  467. description, contact)
  468. SELECT id, in_contact_class, in_description, in_contact FROM company
  469. WHERE entity_id = in_entity_id;
  470. RETURN 1;
  471. END;
  472. $$ LANGUAGE PLPGSQL;
  473. CREATE TYPE entity_note_list AS (
  474. id int,
  475. note_class int,
  476. note text
  477. );
  478. CREATE OR REPLACE FUNCTION company__list_notes(in_entity_id int)
  479. RETURNS SETOF entity_note AS
  480. $$
  481. DECLARE out_row record;
  482. BEGIN
  483. FOR out_row IN
  484. SELECT *
  485. FROM entity_note
  486. WHERE ref_key = in_entity_id
  487. ORDER BY created
  488. LOOP
  489. RETURN NEXT out_row;
  490. END LOOP;
  491. END;
  492. $$ LANGUAGE PLPGSQL;
  493. CREATE OR REPLACE FUNCTION eca__list_notes(in_credit_id int)
  494. RETURNS SETOF note AS
  495. $$
  496. DECLARE out_row record;
  497. t_entity_id int;
  498. BEGIN
  499. SELECT entity_id INTO t_entity_id
  500. FROM entity_credit_account
  501. WHERE id = in_credit_id;
  502. FOR out_row IN
  503. SELECT *
  504. FROM note
  505. WHERE (note_class = 3 and ref_key = in_credit_id) or
  506. (note_class = 1 and ref_key = t_entity_id)
  507. ORDER BY created
  508. LOOP
  509. RETURN NEXT out_row;
  510. END LOOP;
  511. END;
  512. $$ LANGUAGE PLPGSQL SECURITY DEFINER;
  513. REVOKE EXECUTE ON FUNCTION eca__list_notes(INT) FROM public;
  514. CREATE OR REPLACE FUNCTION company__next_id() returns bigint as $$
  515. select nextval('company_id_seq');
  516. $$ language 'sql';
  517. CREATE OR REPLACE FUNCTION company__location_save (
  518. in_entity_id int, in_location_id int,
  519. in_location_class int, in_line_one text, in_line_two text,
  520. in_city TEXT, in_state TEXT, in_mail_code text, in_country_code int,
  521. in_created date
  522. ) returns int AS $$
  523. BEGIN
  524. return _entity_location_save(
  525. in_entity_id, in_location_id,
  526. in_location_class, in_line_one, in_line_two,
  527. '', in_city , in_state, in_mail_code, in_country_code);
  528. END;
  529. $$ language 'plpgsql';
  530. create or replace function _entity_location_save(
  531. in_entity_id int, in_location_id int,
  532. in_location_class int, in_line_one text, in_line_two text,
  533. in_line_three text, in_city TEXT, in_state TEXT, in_mail_code text,
  534. in_country_code int
  535. ) returns int AS $$
  536. DECLARE
  537. l_row location;
  538. l_id INT;
  539. t_company_id int;
  540. BEGIN
  541. SELECT id INTO t_company_id
  542. FROM company WHERE entity_id = in_entity_id;
  543. DELETE FROM company_to_location
  544. WHERE company_id = t_company_id
  545. AND location_class = in_location_class
  546. AND location_id = in_location_id;
  547. SELECT location_save(in_line_one, in_line_two, in_line_three, in_city,
  548. in_state, in_mail_code, in_country_code)
  549. INTO l_id;
  550. INSERT INTO company_to_location
  551. (company_id, location_class, location_id)
  552. VALUES (t_company_id, in_location_class, l_id);
  553. RETURN l_id;
  554. END;
  555. $$ language 'plpgsql';
  556. create or replace function eca__location_save(
  557. in_credit_id int, in_location_id int,
  558. in_location_class int, in_line_one text, in_line_two text,
  559. in_line_three text, in_city TEXT, in_state TEXT, in_mail_code text,
  560. in_country_code int
  561. ) returns int AS $$
  562. DECLARE
  563. l_row location;
  564. l_id INT;
  565. BEGIN
  566. DELETE FROM eca_to_location
  567. WHERE credit_id = in_credit_id
  568. AND location_class = in_location_class
  569. AND location_id = in_location_id;
  570. SELECT location_save(in_line_one, in_line_two, in_line_three, in_city,
  571. in_state, in_mail_code, in_country_code)
  572. INTO l_id;
  573. INSERT INTO eca_to_location
  574. (credit_id, location_class, location_id)
  575. VALUES (in_credit_id, in_location_class, l_id);
  576. RETURN l_id;
  577. END;
  578. $$ language 'plpgsql';
  579. CREATE OR REPLACE FUNCTION company_get_billing_info (in_id int)
  580. returns company_billing_info as
  581. $$
  582. DECLARE out_var company_billing_info;
  583. t_id INT;
  584. BEGIN
  585. select c.legal_name, c.tax_id, a.line_one, a.line_two, a.line_three,
  586. a.city, a.state, a.mail_code, cc.name
  587. into out_var
  588. FROM company c
  589. JOIN entity_credit_account eca ON (eca.entity_id = c.entity_id)
  590. JOIN eca_to_location cl ON (eca.id = cl.credit_id)
  591. JOIN location a ON (a.id = cl.location_id)
  592. JOIN country cc ON (cc.id = a.country_id)
  593. WHERE eca.id = in_id AND location_class = 1;
  594. RETURN out_var;
  595. END;
  596. $$ language plpgsql;
  597. CREATE OR REPLACE FUNCTION eca__list_locations(in_entity_id int)
  598. RETURNS SETOF location_result AS
  599. $$
  600. DECLARE out_row RECORD;
  601. BEGIN
  602. FOR out_row IN
  603. SELECT l.id, l.line_one, l.line_two, l.line_three, l.city,
  604. l.state, l.mail_code, c.name, lc.class
  605. FROM location l
  606. JOIN eca_to_location ctl ON (ctl.location_id = l.id)
  607. JOIN location_class lc ON (ctl.location_class = lc.id)
  608. JOIN country c ON (c.id = l.country_id)
  609. WHERE ctl.credit_id = in_credit_id
  610. ORDER BY lc.id, l.id, c.name
  611. LOOP
  612. RETURN NEXT out_row;
  613. END LOOP;
  614. END;
  615. $$ LANGUAGE PLPGSQL;
  616. CREATE OR REPLACE FUNCTION eca__list_contacts(in_credit_id int)
  617. RETURNS SETOF contact_list AS $$
  618. DECLARE out_row contact_list;
  619. BEGIN
  620. FOR out_row IN
  621. SELECT cl.class, c.description, c.contact
  622. FROM eca_to_contact c
  623. JOIN contact_class cl ON (c.contact_class_id = cl.id)
  624. WHERE credit_id = in_credit_id
  625. LOOP
  626. return next out_row;
  627. END LOOP;
  628. END;
  629. $$ language plpgsql;
  630. CREATE OR REPLACE FUNCTION eca__save_contact
  631. (in_credit_id int, in_contact_class int, in_description text, in_contact text)
  632. RETURNS INT AS
  633. $$
  634. DECLARE out_id int;
  635. BEGIN
  636. INSERT INTO eca_to_contact(credit_id, contact_class_id,
  637. description, contact)
  638. VALUES (in_credit_id, in_contact_class, in_description, in_contact);
  639. RETURN 1;
  640. END;
  641. $$ LANGUAGE PLPGSQL;
  642. -- COMMIT;