summaryrefslogtreecommitdiff
path: root/sql/Pg-database.sql
blob: 16615c3f40884d754bcf61f299c4c16fa8b51ee1 (plain)
  1. defaults (
  2. setting_key text primary key,
  3. value text
  4. );
  5. \COPY defaults FROM stdin WITH DELIMITER |
  6. timeout|90 minutes
  7. sinumber|1
  8. sonumber|1
  9. yearend|1
  10. businessnumber|1
  11. version|1.2.0
  12. closedto|\N
  13. revtrans|1
  14. ponumber|1
  15. sqnumber|1
  16. rfqnumber|1
  17. audittrail|0
  18. vinumber|1
  19. employeenumber|1
  20. partnumber|1
  21. customernumber|1
  22. vendornumber|1
  23. glnumber|1
  24. projectnumber|1
  25. queue_payments|0
  26. poll_frequency|1
  27. rcptnumber|1
  28. paynumber|1
  29. separate_duties|1
  30. entity_control|A-00001
  31. batch_cc|B-11111
  32. \.
  33. COMMENT ON TABLE defaults IS $$
  34. Note that poll_frequency is in seconds. poll_frequency and queue_payments
  35. are not exposed via the admin interface as they are advanced features best
  36. handled via DBAs. Also, separate_duties is not yet included in the admin
  37. interface.$$;
  38. -- */
  39. -- batch stuff
  40. CREATE TABLE batch_class (
  41. id serial unique,
  42. class varchar primary key
  43. );
  44. insert into batch_class (id,class) values (1,'ap');
  45. insert into batch_class (id,class) values (2,'ar');
  46. insert into batch_class (id,class) values (3,'payment');
  47. insert into batch_class (id,class) values (4,'payment_reversal');
  48. insert into batch_class (id,class) values (5,'gl');
  49. insert into batch_class (id,class) values (6,'receipt');
  50. SELECT SETVAL('batch_class_id_seq',6);
  51. CREATE TABLE batch (
  52. id serial primary key,
  53. batch_class_id integer references batch_class(id) not null,
  54. control_code text,
  55. description text,
  56. default_date date not null,
  57. approved_on date default null,
  58. approved_by int references entity_employee(entity_id),
  59. created_by int references entity_employee(entity_id),
  60. locked_by int references session(session_id),
  61. created_on date default now()
  62. );
  63. COMMENT ON COLUMN batch.batch_class_id IS
  64. $$ Note that this field is largely used for sorting the vouchers. A given batch is NOT restricted to this type.$$;
  65. -- Although I am moving the primary key to voucher.id for now, as of 1.4, I
  66. -- would expect trans_id to be primary key
  67. CREATE TABLE voucher (
  68. trans_id int REFERENCES transactions(id) NOT NULL,
  69. batch_id int references batch(id) not null,
  70. id serial PRIMARY KEY,
  71. batch_class int references batch_class(id) not null
  72. );
  73. COMMENT ON COLUMN voucher.batch_class IS $$ This is the authoritative class of the
  74. voucher. $$;
  75. COMMENT ON COLUMN voucher.id IS $$ This is simply a surrogate key for easy reference.$$;
  76. CREATE TABLE acc_trans (
  77. trans_id int NOT NULL REFERENCES transactions(id),
  78. chart_id int NOT NULL REFERENCES chart (id),
  79. amount NUMERIC,
  80. transdate date DEFAULT current_date,
  81. source text,
  82. cleared bool DEFAULT 'f',
  83. fx_transaction bool DEFAULT 'f',
  84. project_id int,
  85. memo text,
  86. invoice_id int,
  87. approved bool default true,
  88. cleared_on date,
  89. reconciled_on date,
  90. voucher_id int references voucher(id),
  91. entry_id SERIAL PRIMARY KEY
  92. );
  93. CREATE INDEX acc_trans_voucher_id_idx ON acc_trans(voucher_id);
  94. --
  95. CREATE TABLE invoice (
  96. id serial PRIMARY KEY,
  97. trans_id int,
  98. parts_id int,
  99. description text,
  100. qty integer,
  101. allocated integer,
  102. sellprice NUMERIC,
  103. fxsellprice NUMERIC,
  104. discount numeric,
  105. assemblyitem bool DEFAULT 'f',
  106. unit varchar(5),
  107. project_id int,
  108. deliverydate date,
  109. serialnumber text,
  110. notes text
  111. );
  112. -- Added for Entity but can't be added due to order
  113. ALTER TABLE invoice_note ADD FOREIGN KEY (ref_key) REFERENCES invoice(id);
  114. --
  115. --
  116. -- THe following credit accounts are used for inventory adjustments.
  117. INSERT INTO entity (name, entity_class, control_code)
  118. values ('Inventory Entity', 1, 'AUTO-01');
  119. INSERT INTO company (legal_name, entity_id)
  120. values ('Inventory Entity', currval('entity_id_seq'));
  121. INSERT INTO entity_credit_account (entity_id, meta_number, entity_class)
  122. VALUES
  123. (currval('entity_id_seq'), '00000', 1);
  124. INSERT INTO entity_credit_account (entity_id, meta_number, entity_class)
  125. VALUES
  126. (currval('entity_id_seq'), '00000', 2);
  127. -- notes are from entity_note
  128. -- ssn, iban and bic are from entity_credit_account
  129. --
  130. -- The view below is broken. Disabling for now.
  131. CREATE VIEW employee AS
  132. SELECT s.salutation, p.first_name, p.last_name, ee.person_id, ee.entity_id, ee.startdate, ee.enddate, ee."role", ee.ssn, ee.sales, ee.manager_id, ee.employeenumber, ee.dob
  133. FROM person p
  134. JOIN entity_employee ee USING (entity_id)
  135. LEFT JOIN salutation s ON p.salutation_id = s.id;
  136. /*
  137. create view employee as
  138. SELECT
  139. ente.entity_id,
  140. 3,
  141. u.username,
  142. ente.startdate,
  143. ente.enddate,
  144. en.note,
  145. ente.ssn,
  146. eca.iban,
  147. eca.bic,
  148. ente.manager_id,
  149. ente.employeenumber,
  150. ente.dob
  151. FROM
  152. entity_employee ente
  153. JOIN
  154. entity_credit_account eca on (eca.entity_id = ente.entity_id)
  155. JOIN
  156. entity_note en on (en.entity_id = ente.entity_id)
  157. JOIN
  158. users u on (u.entity_id = ente.entity_id);
  159. */
  160. CREATE VIEW customer AS
  161. SELECT
  162. c.id,
  163. emd.entity_id,
  164. emd.entity_class,
  165. emd.discount,
  166. emd.taxincluded,
  167. emd.creditlimit,
  168. emd.terms,
  169. emd.meta_number as customernumber,
  170. emd.cc,
  171. emd.bcc,
  172. emd.business_id,
  173. emd.language_code,
  174. emd.pricegroup_id,
  175. emd.curr,
  176. emd.startdate,
  177. emd.enddate,
  178. eba.bic,
  179. eba.iban,
  180. ein.note as invoice_notes
  181. FROM entity_credit_account emd
  182. join entity_bank_account eba on emd.entity_id = eba.entity_id
  183. Left join entity_note ein on ein.ref_key = emd.entity_id
  184. join company c on c.entity_id = emd.entity_id
  185. where emd.entity_class = 2;
  186. CREATE VIEW vendor AS
  187. SELECT
  188. c.id,
  189. emd.entity_id,
  190. emd.entity_class,
  191. emd.discount,
  192. emd.taxincluded,
  193. emd.creditlimit,
  194. emd.terms,
  195. emd.meta_number as vendornumber,
  196. emd.cc,
  197. emd.bcc,
  198. emd.business_id,
  199. emd.language_code,
  200. emd.pricegroup_id,
  201. emd.curr,
  202. emd.startdate,
  203. emd.enddate,
  204. eba.bic,
  205. eba.iban,
  206. ein.note as
  207. invoice_notes
  208. FROM entity_credit_account emd
  209. LEFT join entity_bank_account eba on emd.entity_id = eba.entity_id
  210. left join entity_note ein on ein.ref_key = emd.entity_id
  211. join company c on c.entity_id = emd.entity_id
  212. where emd.entity_class = 1;
  213. COMMENT ON TABLE entity_credit_account IS $$ This is a metadata table for ALL entities in LSMB; it deprecates the use of customer and vendor specific tables (which were nearly identical and largely redundant), and replaces it with a single point of metadata. $$;
  214. COMMENT ON COLUMN entity_credit_account.entity_id IS $$ This is the relationship between entities and their metadata. $$;
  215. COMMENT ON COLUMN entity_credit_account.entity_class IS $$ A reference to entity_class, requiring that entity_credit_account only apply to vendors and customers, using the entity_class table as the Point Of Truth. $$;
  216. ALTER TABLE company ADD COLUMN sic_code varchar;
  217. --
  218. --
  219. -- COMMENT ON TABLE employee IS $$ Is a metadata table specific to employee $$;
  220. CREATE TABLE parts (
  221. id serial PRIMARY KEY,
  222. partnumber text,
  223. description text,
  224. unit varchar(5),
  225. listprice NUMERIC,
  226. sellprice NUMERIC,
  227. lastcost NUMERIC,
  228. priceupdate date DEFAULT current_date,
  229. weight numeric,
  230. onhand numeric DEFAULT 0,
  231. notes text,
  232. makemodel bool DEFAULT 'f',
  233. assembly bool DEFAULT 'f',
  234. alternate bool DEFAULT 'f',
  235. rop numeric, -- SC: ReOrder Point
  236. inventory_accno_id int,
  237. income_accno_id int,
  238. expense_accno_id int,
  239. bin text,
  240. obsolete bool DEFAULT 'f',
  241. bom bool DEFAULT 'f',
  242. image text,
  243. drawing text,
  244. microfiche text,
  245. partsgroup_id int,
  246. project_id int,
  247. avgcost NUMERIC
  248. );
  249. CREATE UNIQUE INDEX parts_partnumber_index_u ON parts (partnumber)
  250. WHERE obsolete is false;
  251. --
  252. CREATE TABLE assembly (
  253. id int,
  254. parts_id int,
  255. qty numeric,
  256. bom bool,
  257. adj bool,
  258. PRIMARY KEY (id, parts_id)
  259. );
  260. --
  261. CREATE TABLE ar (
  262. id int DEFAULT nextval ( 'id' ) PRIMARY KEY REFERENCES transactions(id),
  263. invnumber text,
  264. transdate date DEFAULT current_date,
  265. entity_id int REFERENCES entity(id),
  266. taxincluded bool,
  267. amount NUMERIC,
  268. netamount NUMERIC,
  269. paid NUMERIC,
  270. datepaid date,
  271. duedate date,
  272. invoice bool DEFAULT 'f',
  273. shippingpoint text,
  274. terms int2 DEFAULT 0,
  275. notes text,
  276. curr char(3),
  277. ordnumber text,
  278. person_id integer references entity_employee(entity_id),
  279. till varchar(20),
  280. quonumber text,
  281. intnotes text,
  282. department_id int default 0,
  283. shipvia text,
  284. language_code varchar(6),
  285. ponumber text,
  286. on_hold bool default false,
  287. reverse bool default false,
  288. approved bool default true,
  289. entity_credit_account int references entity_credit_account(id) not null,
  290. force_closed bool,
  291. description text
  292. );
  293. COMMENT ON COLUMN ar.entity_id IS $$ Used to be customer_id, but customer is now metadata. You need to push to entity $$;
  294. --
  295. CREATE TABLE ap (
  296. id int DEFAULT nextval ( 'id' ) PRIMARY KEY REFERENCES transactions(id),
  297. invnumber text,
  298. transdate date DEFAULT current_date,
  299. entity_id int REFERENCES entity(id),
  300. taxincluded bool DEFAULT 'f',
  301. amount NUMERIC,
  302. netamount NUMERIC,
  303. paid NUMERIC,
  304. datepaid date,
  305. duedate date,
  306. invoice bool DEFAULT 'f',
  307. ordnumber text,
  308. curr char(3),
  309. notes text,
  310. person_id integer references entity_employee(entity_id),
  311. till varchar(20),
  312. quonumber text,
  313. intnotes text,
  314. department_id int DEFAULT 0,
  315. shipvia text,
  316. language_code varchar(6),
  317. ponumber text,
  318. shippingpoint text,
  319. on_hold bool default false,
  320. approved bool default true,
  321. reverse bool default false,
  322. terms int2 DEFAULT 0,
  323. description text,
  324. force_closed bool,
  325. entity_credit_account int references entity_credit_account(id) NOT NULL
  326. );
  327. COMMENT ON COLUMN ap.entity_id IS $$ Used to be customer_id, but customer is now metadata. You need to push to entity $$;
  328. --
  329. CREATE TABLE taxmodule (
  330. taxmodule_id serial PRIMARY KEY,
  331. taxmodulename text NOT NULL
  332. );
  333. --
  334. CREATE TABLE taxcategory (
  335. taxcategory_id serial PRIMARY KEY,
  336. taxcategoryname text NOT NULL,
  337. taxmodule_id int NOT NULL,
  338. FOREIGN KEY (taxmodule_id) REFERENCES taxmodule (taxmodule_id)
  339. );
  340. --
  341. CREATE TABLE partstax (
  342. parts_id int,
  343. chart_id int,
  344. taxcategory_id int,
  345. PRIMARY KEY (parts_id, chart_id),
  346. FOREIGN KEY (parts_id) REFERENCES parts (id) on delete cascade,
  347. FOREIGN KEY (chart_id) REFERENCES chart (id),
  348. FOREIGN KEY (taxcategory_id) REFERENCES taxcategory (taxcategory_id)
  349. );
  350. --
  351. CREATE TABLE tax (
  352. chart_id int,
  353. rate numeric,
  354. taxnumber text,
  355. validto timestamp default 'infinity',
  356. pass integer DEFAULT 0 NOT NULL,
  357. taxmodule_id int DEFAULT 1 NOT NULL,
  358. FOREIGN KEY (chart_id) REFERENCES chart (id),
  359. FOREIGN KEY (taxmodule_id) REFERENCES taxmodule (taxmodule_id),
  360. PRIMARY KEY (chart_id, validto)
  361. );
  362. --
  363. CREATE TABLE customertax (
  364. customer_id int references entity_credit_account(id) on delete cascade,
  365. chart_id int,
  366. PRIMARY KEY (customer_id, chart_id)
  367. );
  368. --
  369. CREATE TABLE vendortax (
  370. vendor_id int references entity_credit_account(id) on delete cascade,
  371. chart_id int,
  372. PRIMARY KEY (vendor_id, chart_id)
  373. );
  374. --
  375. CREATE TABLE oe_class (
  376. id smallint unique check(id IN (1,2,3,4)),
  377. oe_class text primary key);
  378. INSERT INTO oe_class(id,oe_class) values (1,'Sales Order');
  379. INSERT INTO oe_class(id,oe_class) values (2,'Purchase Order');
  380. INSERT INTO oe_class(id,oe_class) values (3,'Quotation');
  381. INSERT INTO oe_class(id,oe_class) values (4,'RFQ');
  382. COMMENT ON TABLE oe_class IS $$ This could probably be done better. But I need to remove the customer_id/vendor_id relationship and instead rely on a classification $$;
  383. CREATE TABLE oe (
  384. id serial PRIMARY KEY,
  385. ordnumber text,
  386. transdate date default current_date,
  387. entity_id integer references entity(id),
  388. amount NUMERIC,
  389. netamount NUMERIC,
  390. reqdate date,
  391. taxincluded bool,
  392. shippingpoint text,
  393. notes text,
  394. curr char(3),
  395. person_id integer references person(id),
  396. closed bool default 'f',
  397. quotation bool default 'f',
  398. quonumber text,
  399. intnotes text,
  400. department_id int default 0,
  401. shipvia text,
  402. language_code varchar(6),
  403. ponumber text,
  404. terms int2 DEFAULT 0,
  405. oe_class_id int references oe_class(id) NOT NULL
  406. );
  407. --
  408. CREATE TABLE orderitems (
  409. id serial PRIMARY KEY,
  410. trans_id int,
  411. parts_id int,
  412. description text,
  413. qty numeric,
  414. sellprice NUMERIC,
  415. discount numeric,
  416. unit varchar(5),
  417. project_id int,
  418. reqdate date,
  419. ship numeric,
  420. serialnumber text,
  421. notes text
  422. );
  423. --
  424. CREATE TABLE exchangerate (
  425. curr char(3),
  426. transdate date,
  427. buy numeric,
  428. sell numeric,
  429. PRIMARY KEY (curr, transdate)
  430. );
  431. --
  432. --
  433. create table shipto (
  434. trans_id int,
  435. shiptoname varchar(64),
  436. shiptoaddress1 varchar(32),
  437. shiptoaddress2 varchar(32),
  438. shiptocity varchar(32),
  439. shiptostate varchar(32),
  440. shiptozipcode varchar(10),
  441. shiptocountry varchar(32),
  442. shiptocontact varchar(64),
  443. shiptophone varchar(20),
  444. shiptofax varchar(20),
  445. shiptoemail text,
  446. entry_id SERIAL PRIMARY KEY
  447. );
  448. -- SHIPTO really needs to be pushed into entities too
  449. --
  450. --
  451. CREATE TABLE project (
  452. id serial PRIMARY KEY,
  453. projectnumber text,
  454. description text,
  455. startdate date,
  456. enddate date,
  457. parts_id int,
  458. production numeric default 0,
  459. completed numeric default 0,
  460. customer_id int
  461. );
  462. --
  463. CREATE TABLE partsgroup (
  464. id serial PRIMARY KEY,
  465. partsgroup text
  466. );
  467. --
  468. CREATE TABLE status (
  469. trans_id int,
  470. formname text,
  471. printed bool default 'f',
  472. emailed bool default 'f',
  473. spoolfile text,
  474. PRIMARY KEY (trans_id, formname)
  475. );
  476. --
  477. CREATE TABLE department (
  478. id serial PRIMARY KEY,
  479. description text,
  480. role char(1) default 'P'
  481. );
  482. --
  483. -- department transaction table
  484. CREATE TABLE dpt_trans (
  485. trans_id int PRIMARY KEY,
  486. department_id int
  487. );
  488. --
  489. -- business table
  490. CREATE TABLE business (
  491. id serial PRIMARY KEY,
  492. description text,
  493. discount numeric
  494. );
  495. --
  496. -- SIC
  497. CREATE TABLE sic (
  498. code varchar(6) PRIMARY KEY,
  499. sictype char(1),
  500. description text
  501. );
  502. --
  503. CREATE TABLE warehouse (
  504. id serial PRIMARY KEY,
  505. description text
  506. );
  507. --
  508. CREATE TABLE inventory (
  509. entity_id integer references entity_employee(entity_id),
  510. warehouse_id int,
  511. parts_id int,
  512. trans_id int,
  513. orderitems_id int,
  514. qty numeric,
  515. shippingdate date,
  516. entry_id SERIAL PRIMARY KEY
  517. );
  518. --
  519. CREATE TABLE yearend (
  520. trans_id int PRIMARY KEY,
  521. transdate date
  522. );
  523. --
  524. CREATE TABLE partsvendor (
  525. entity_id int not null references entity_credit_account(id) on delete cascade,
  526. parts_id int,
  527. partnumber text,
  528. leadtime int2,
  529. lastcost NUMERIC,
  530. curr char(3),
  531. entry_id SERIAL PRIMARY KEY
  532. );
  533. --
  534. CREATE TABLE partscustomer (
  535. parts_id int,
  536. customer_id int not null references entity_credit_account(id) on delete cascade,
  537. pricegroup_id int,
  538. pricebreak numeric,
  539. sellprice NUMERIC,
  540. validfrom date,
  541. validto date,
  542. curr char(3),
  543. entry_id SERIAL PRIMARY KEY
  544. );
  545. -- How does partscustomer.customer_id relate here?
  546. --
  547. CREATE TABLE language (
  548. code varchar(6) PRIMARY KEY,
  549. description text
  550. );
  551. --
  552. CREATE TABLE audittrail (
  553. trans_id int,
  554. tablename text,
  555. reference text,
  556. formname text,
  557. action text,
  558. transdate timestamp default current_timestamp,
  559. person_id integer references person(id) not null,
  560. entry_id BIGSERIAL PRIMARY KEY
  561. );
  562. --
  563. CREATE TABLE translation (
  564. trans_id int,
  565. language_code varchar(6),
  566. description text,
  567. PRIMARY KEY (trans_id, language_code)
  568. );
  569. --
  570. CREATE TABLE user_preference (
  571. id int PRIMARY KEY REFERENCES users(id),
  572. language varchar(6) REFERENCES language(code),
  573. stylesheet text default 'ledgersmb.css' not null,
  574. printer text,
  575. dateformat text default 'yyyy-mm-dd' not null,
  576. numberformat text default '1000.00' not null
  577. );
  578. -- user_preference is here due to a dependency on language.code
  579. COMMENT ON TABLE user_preference IS
  580. $$ This table sets the basic preferences for formats, languages, printers, and user-selected stylesheets.$$;
  581. CREATE TABLE recurring (
  582. id int DEFAULT nextval ( 'id' ) PRIMARY KEY,
  583. reference text,
  584. startdate date,
  585. nextdate date,
  586. enddate date,
  587. repeat int2,
  588. unit varchar(6),
  589. howmany int,
  590. payment bool default 'f'
  591. );
  592. --
  593. CREATE TABLE recurringemail (
  594. id int,
  595. formname text,
  596. format text,
  597. message text,
  598. PRIMARY KEY (id, formname)
  599. );
  600. --
  601. CREATE TABLE recurringprint (
  602. id int,
  603. formname text,
  604. format text,
  605. printer text,
  606. PRIMARY KEY (id, formname)
  607. );
  608. --
  609. CREATE TABLE jcitems (
  610. id serial PRIMARY KEY,
  611. project_id int,
  612. parts_id int,
  613. description text,
  614. qty numeric,
  615. allocated numeric,
  616. sellprice NUMERIC,
  617. fxsellprice NUMERIC,
  618. serialnumber text,
  619. checkedin timestamp with time zone,
  620. checkedout timestamp with time zone,
  621. person_id integer references person(id) not null,
  622. notes text
  623. );
  624. INSERT INTO transactions (id, table_name) SELECT id, 'ap' FROM ap;
  625. INSERT INTO transactions (id, table_name) SELECT id, 'ar' FROM ap;
  626. INSERT INTO transactions (id, table_name) SELECT id, 'gl' FROM gl;
  627. CREATE OR REPLACE FUNCTION track_global_sequence() RETURNS TRIGGER AS
  628. $$
  629. BEGIN
  630. IF tg_op = 'INSERT' THEN
  631. INSERT INTO transactions (id, table_name)
  632. VALUES (new.id, TG_RELNAME);
  633. ELSEIF tg_op = 'UPDATE' THEN
  634. IF new.id = old.id THEN
  635. return new;
  636. ELSE
  637. UPDATE transactions SET id = new.id WHERE id = old.id;
  638. END IF;
  639. ELSE
  640. DELETE FROM transactions WHERE id = old.id;
  641. END IF;
  642. RETURN new;
  643. END;
  644. $$ LANGUAGE PLPGSQL;
  645. CREATE TRIGGER ap_track_global_sequence BEFORE INSERT OR UPDATE ON ap
  646. FOR EACH ROW EXECUTE PROCEDURE track_global_sequence();
  647. CREATE TRIGGER ar_track_global_sequence BEFORE INSERT OR UPDATE ON ar
  648. FOR EACH ROW EXECUTE PROCEDURE track_global_sequence();
  649. CREATE TRIGGER gl_track_global_sequence BEFORE INSERT OR UPDATE ON gl
  650. FOR EACH ROW EXECUTE PROCEDURE track_global_sequence();
  651. CREATE TABLE custom_table_catalog (
  652. table_id SERIAL PRIMARY KEY,
  653. extends TEXT,
  654. table_name TEXT
  655. );
  656. CREATE TABLE custom_field_catalog (
  657. field_id SERIAL PRIMARY KEY,
  658. table_id INT REFERENCES custom_table_catalog,
  659. field_name TEXT
  660. );
  661. INSERT INTO taxmodule (
  662. taxmodule_id, taxmodulename
  663. ) VALUES (
  664. 1, 'Simple'
  665. );
  666. create index acc_trans_trans_id_key on acc_trans (trans_id);
  667. create index acc_trans_chart_id_key on acc_trans (chart_id);
  668. create index acc_trans_transdate_key on acc_trans (transdate);
  669. create index acc_trans_source_key on acc_trans (lower(source));
  670. --
  671. create index ap_id_key on ap (id);
  672. create index ap_transdate_key on ap (transdate);
  673. create index ap_invnumber_key on ap (invnumber);
  674. create index ap_ordnumber_key on ap (ordnumber);
  675. create index ap_quonumber_key on ap (quonumber);
  676. --
  677. create index ar_id_key on ar (id);
  678. create index ar_transdate_key on ar (transdate);
  679. create index ar_invnumber_key on ar (invnumber);
  680. create index ar_ordnumber_key on ar (ordnumber);
  681. create index ar_quonumber_key on ar (quonumber);
  682. --
  683. create index assembly_id_key on assembly (id);
  684. --
  685. create index chart_id_key on chart (id);
  686. create unique index chart_accno_key on chart (accno);
  687. create index chart_category_key on chart (category);
  688. create index chart_link_key on chart (link);
  689. create index chart_gifi_accno_key on chart (gifi_accno);
  690. --
  691. create index customer_customer_id_key on customertax (customer_id);
  692. --
  693. create index exchangerate_ct_key on exchangerate (curr, transdate);
  694. --
  695. create unique index gifi_accno_key on gifi (accno);
  696. --
  697. create index gl_id_key on gl (id);
  698. create index gl_transdate_key on gl (transdate);
  699. create index gl_reference_key on gl (reference);
  700. create index gl_description_key on gl (lower(description));
  701. --
  702. create index invoice_id_key on invoice (id);
  703. create index invoice_trans_id_key on invoice (trans_id);
  704. --
  705. create index makemodel_parts_id_key on makemodel (parts_id);
  706. create index makemodel_make_key on makemodel (lower(make));
  707. create index makemodel_model_key on makemodel (lower(model));
  708. --
  709. create index oe_id_key on oe (id);
  710. create index oe_transdate_key on oe (transdate);
  711. create index oe_ordnumber_key on oe (ordnumber);
  712. create index orderitems_trans_id_key on orderitems (trans_id);
  713. create index orderitems_id_key on orderitems (id);
  714. --
  715. create index parts_id_key on parts (id);
  716. create index parts_partnumber_key on parts (lower(partnumber));
  717. create index parts_description_key on parts (lower(description));
  718. create index partstax_parts_id_key on partstax (parts_id);
  719. --
  720. --
  721. create index shipto_trans_id_key on shipto (trans_id);
  722. --
  723. create index project_id_key on project (id);
  724. create unique index projectnumber_key on project (projectnumber);
  725. --
  726. create index partsgroup_id_key on partsgroup (id);
  727. create unique index partsgroup_key on partsgroup (partsgroup);
  728. --
  729. create index status_trans_id_key on status (trans_id);
  730. --
  731. create index department_id_key on department (id);
  732. --
  733. create index partsvendor_parts_id_key on partsvendor (parts_id);
  734. --
  735. create index pricegroup_pricegroup_key on pricegroup (pricegroup);
  736. create index pricegroup_id_key on pricegroup (id);
  737. --
  738. create index audittrail_trans_id_key on audittrail (trans_id);
  739. --
  740. create index translation_trans_id_key on translation (trans_id);
  741. --
  742. create unique index language_code_key on language (code);
  743. --
  744. create index jcitems_id_key on jcitems (id);
  745. -- Popular some entity data
  746. INSERT INTO country(short_name,name) VALUES ('AC','Ascension Island');
  747. INSERT INTO country(short_name,name) VALUES ('AD','Andorra');
  748. INSERT INTO country(short_name,name) VALUES ('AE','United Arab Emirates');
  749. INSERT INTO country(short_name,name) VALUES ('AF','Afghanistan');
  750. INSERT INTO country(short_name,name) VALUES ('AG','Antigua and Barbuda');
  751. INSERT INTO country(short_name,name) VALUES ('AI','Anguilla');
  752. INSERT INTO country(short_name,name) VALUES ('AL','Albania');
  753. INSERT INTO country(short_name,name) VALUES ('AM','Armenia');
  754. INSERT INTO country(short_name,name) VALUES ('AN','Netherlands Antilles');
  755. INSERT INTO country(short_name,name) VALUES ('AO','Angola');
  756. INSERT INTO country(short_name,name) VALUES ('AQ','Antarctica');
  757. INSERT INTO country(short_name,name) VALUES ('AR','Argentina');
  758. INSERT INTO country(short_name,name) VALUES ('AS','American Samoa');
  759. INSERT INTO country(short_name,name) VALUES ('AT','Austria');
  760. INSERT INTO country(short_name,name) VALUES ('AU','Australia');
  761. INSERT INTO country(short_name,name) VALUES ('AW','Aruba');
  762. INSERT INTO country(short_name,name) VALUES ('AX','Aland Islands');
  763. INSERT INTO country(short_name,name) VALUES ('AZ','Azerbaijan');
  764. INSERT INTO country(short_name,name) VALUES ('BA','Bosnia and Herzegovina');
  765. INSERT INTO country(short_name,name) VALUES ('BB','Barbados');
  766. INSERT INTO country(short_name,name) VALUES ('BD','Bangladesh');
  767. INSERT INTO country(short_name,name) VALUES ('BE','Belgium');
  768. INSERT INTO country(short_name,name) VALUES ('BF','Burkina Faso');
  769. INSERT INTO country(short_name,name) VALUES ('BG','Bulgaria');
  770. INSERT INTO country(short_name,name) VALUES ('BH','Bahrain');
  771. INSERT INTO country(short_name,name) VALUES ('BI','Burundi');
  772. INSERT INTO country(short_name,name) VALUES ('BJ','Benin');
  773. INSERT INTO country(short_name,name) VALUES ('BM','Bermuda');
  774. INSERT INTO country(short_name,name) VALUES ('BN','Brunei Darussalam');
  775. INSERT INTO country(short_name,name) VALUES ('BO','Bolivia');
  776. INSERT INTO country(short_name,name) VALUES ('BR','Brazil');
  777. INSERT INTO country(short_name,name) VALUES ('BS','Bahamas');
  778. INSERT INTO country(short_name,name) VALUES ('BT','Bhutan');
  779. INSERT INTO country(short_name,name) VALUES ('BV','Bouvet Island');
  780. INSERT INTO country(short_name,name) VALUES ('BW','Botswana');
  781. INSERT INTO country(short_name,name) VALUES ('BY','Belarus');
  782. INSERT INTO country(short_name,name) VALUES ('BZ','Belize');
  783. INSERT INTO country(short_name,name) VALUES ('CA','Canada');
  784. INSERT INTO country(short_name,name) VALUES ('CC','Cocos (Keeling) Islands');
  785. INSERT INTO country(short_name,name) VALUES ('CD','Congo, Democratic Republic');
  786. INSERT INTO country(short_name,name) VALUES ('CF','Central African Republic');
  787. INSERT INTO country(short_name,name) VALUES ('CG','Congo');
  788. INSERT INTO country(short_name,name) VALUES ('CH','Switzerland');
  789. INSERT INTO country(short_name,name) VALUES ('CI','Cote D\'Ivoire (Ivory Coast)');
  790. INSERT INTO country(short_name,name) VALUES ('CK','Cook Islands');
  791. INSERT INTO country(short_name,name) VALUES ('CL','Chile');
  792. INSERT INTO country(short_name,name) VALUES ('CM','Cameroon');
  793. INSERT INTO country(short_name,name) VALUES ('CN','China');
  794. INSERT INTO country(short_name,name) VALUES ('CO','Colombia');
  795. INSERT INTO country(short_name,name) VALUES ('CR','Costa Rica');
  796. INSERT INTO country(short_name,name) VALUES ('CS','Czechoslovakia (former)');
  797. INSERT INTO country(short_name,name) VALUES ('CU','Cuba');
  798. INSERT INTO country(short_name,name) VALUES ('CV','Cape Verde');
  799. INSERT INTO country(short_name,name) VALUES ('CX','Christmas Island');
  800. INSERT INTO country(short_name,name) VALUES ('CY','Cyprus');
  801. INSERT INTO country(short_name,name) VALUES ('CZ','Czech Republic');
  802. INSERT INTO country(short_name,name) VALUES ('DE','Germany');
  803. INSERT INTO country(short_name,name) VALUES ('DJ','Djibouti');
  804. INSERT INTO country(short_name,name) VALUES ('DK','Denmark');
  805. INSERT INTO country(short_name,name) VALUES ('DM','Dominica');
  806. INSERT INTO country(short_name,name) VALUES ('DO','Dominican Republic');
  807. INSERT INTO country(short_name,name) VALUES ('DZ','Algeria');
  808. INSERT INTO country(short_name,name) VALUES ('EC','Ecuador');
  809. INSERT INTO country(short_name,name) VALUES ('EE','Estonia');
  810. INSERT INTO country(short_name,name) VALUES ('EG','Egypt');
  811. INSERT INTO country(short_name,name) VALUES ('EH','Western Sahara');
  812. INSERT INTO country(short_name,name) VALUES ('ER','Eritrea');
  813. INSERT INTO country(short_name,name) VALUES ('ES','Spain');
  814. INSERT INTO country(short_name,name) VALUES ('ET','Ethiopia');
  815. INSERT INTO country(short_name,name) VALUES ('FI','Finland');
  816. INSERT INTO country(short_name,name) VALUES ('FJ','Fiji');
  817. INSERT INTO country(short_name,name) VALUES ('FK','Falkland Islands (Malvinas)');
  818. INSERT INTO country(short_name,name) VALUES ('FM','Micronesia');
  819. INSERT INTO country(short_name,name) VALUES ('FO','Faroe Islands');
  820. INSERT INTO country(short_name,name) VALUES ('FR','France');
  821. INSERT INTO country(short_name,name) VALUES ('FX','France, Metropolitan');
  822. INSERT INTO country(short_name,name) VALUES ('GA','Gabon');
  823. INSERT INTO country(short_name,name) VALUES ('GB','Great Britain (UK)');
  824. INSERT INTO country(short_name,name) VALUES ('GD','Grenada');
  825. INSERT INTO country(short_name,name) VALUES ('GE','Georgia');
  826. INSERT INTO country(short_name,name) VALUES ('GF','French Guiana');
  827. INSERT INTO country(short_name,name) VALUES ('GH','Ghana');
  828. INSERT INTO country(short_name,name) VALUES ('GI','Gibraltar');
  829. INSERT INTO country(short_name,name) VALUES ('GL','Greenland');
  830. INSERT INTO country(short_name,name) VALUES ('GM','Gambia');
  831. INSERT INTO country(short_name,name) VALUES ('GN','Guinea');
  832. INSERT INTO country(short_name,name) VALUES ('GP','Guadeloupe');
  833. INSERT INTO country(short_name,name) VALUES ('GQ','Equatorial Guinea');
  834. INSERT INTO country(short_name,name) VALUES ('GR','Greece');
  835. INSERT INTO country(short_name,name) VALUES ('GS','S. Georgia and S. Sandwich Isls.');
  836. INSERT INTO country(short_name,name) VALUES ('GT','Guatemala');
  837. INSERT INTO country(short_name,name) VALUES ('GU','Guam');
  838. INSERT INTO country(short_name,name) VALUES ('GW','Guinea-Bissau');
  839. INSERT INTO country(short_name,name) VALUES ('GY','Guyana');
  840. INSERT INTO country(short_name,name) VALUES ('HK','Hong Kong');
  841. INSERT INTO country(short_name,name) VALUES ('HM','Heard and McDonald Islands');
  842. INSERT INTO country(short_name,name) VALUES ('HN','Honduras');
  843. INSERT INTO country(short_name,name) VALUES ('HR','Croatia (Hrvatska)');
  844. INSERT INTO country(short_name,name) VALUES ('HT','Haiti');
  845. INSERT INTO country(short_name,name) VALUES ('HU','Hungary');
  846. INSERT INTO country(short_name,name) VALUES ('ID','Indonesia');
  847. INSERT INTO country(short_name,name) VALUES ('IE','Ireland');
  848. INSERT INTO country(short_name,name) VALUES ('IL','Israel');
  849. INSERT INTO country(short_name,name) VALUES ('IM','Isle of Man');
  850. INSERT INTO country(short_name,name) VALUES ('IN','India');
  851. INSERT INTO country(short_name,name) VALUES ('IO','British Indian Ocean Territory');
  852. INSERT INTO country(short_name,name) VALUES ('IQ','Iraq');
  853. INSERT INTO country(short_name,name) VALUES ('IR','Iran');
  854. INSERT INTO country(short_name,name) VALUES ('IS','Iceland');
  855. INSERT INTO country(short_name,name) VALUES ('IT','Italy');
  856. INSERT INTO country(short_name,name) VALUES ('JE','Jersey');
  857. INSERT INTO country(short_name,name) VALUES ('JM','Jamaica');
  858. INSERT INTO country(short_name,name) VALUES ('JO','Jordan');
  859. INSERT INTO country(short_name,name) VALUES ('JP','Japan');
  860. INSERT INTO country(short_name,name) VALUES ('KE','Kenya');
  861. INSERT INTO country(short_name,name) VALUES ('KG','Kyrgyzstan');
  862. INSERT INTO country(short_name,name) VALUES ('KH','Cambodia');
  863. INSERT INTO country(short_name,name) VALUES ('KI','Kiribati');
  864. INSERT INTO country(short_name,name) VALUES ('KM','Comoros');
  865. INSERT INTO country(short_name,name) VALUES ('KN','Saint Kitts and Nevis');
  866. INSERT INTO country(short_name,name) VALUES ('KP','Korea (North)');
  867. INSERT INTO country(short_name,name) VALUES ('KR','Korea (South)');
  868. INSERT INTO country(short_name,name) VALUES ('KW','Kuwait');
  869. INSERT INTO country(short_name,name) VALUES ('KY','Cayman Islands');
  870. INSERT INTO country(short_name,name) VALUES ('KZ','Kazakhstan');
  871. INSERT INTO country(short_name,name) VALUES ('LA','Laos');
  872. INSERT INTO country(short_name,name) VALUES ('LB','Lebanon');
  873. INSERT INTO country(short_name,name) VALUES ('LC','Saint Lucia');
  874. INSERT INTO country(short_name,name) VALUES ('LI','Liechtenstein');
  875. INSERT INTO country(short_name,name) VALUES ('LK','Sri Lanka');
  876. INSERT INTO country(short_name,name) VALUES ('LR','Liberia');
  877. INSERT INTO country(short_name,name) VALUES ('LS','Lesotho');
  878. INSERT INTO country(short_name,name) VALUES ('LT','Lithuania');
  879. INSERT INTO country(short_name,name) VALUES ('LU','Luxembourg');
  880. INSERT INTO country(short_name,name) VALUES ('LV','Latvia');
  881. INSERT INTO country(short_name,name) VALUES ('LY','Libya');
  882. INSERT INTO country(short_name,name) VALUES ('MA','Morocco');
  883. INSERT INTO country(short_name,name) VALUES ('MC','Monaco');
  884. INSERT INTO country(short_name,name) VALUES ('MD','Moldova');
  885. INSERT INTO country(short_name,name) VALUES ('MG','Madagascar');
  886. INSERT INTO country(short_name,name) VALUES ('MH','Marshall Islands');
  887. INSERT INTO country(short_name,name) VALUES ('MK','F.Y.R.O.M. (Macedonia)');
  888. INSERT INTO country(short_name,name) VALUES ('ML','Mali');
  889. INSERT INTO country(short_name,name) VALUES ('MM','Myanmar');
  890. INSERT INTO country(short_name,name) VALUES ('MN','Mongolia');
  891. INSERT INTO country(short_name,name) VALUES ('MO','Macau');
  892. INSERT INTO country(short_name,name) VALUES ('MP','Northern Mariana Islands');
  893. INSERT INTO country(short_name,name) VALUES ('MQ','Martinique');
  894. INSERT INTO country(short_name,name) VALUES ('MR','Mauritania');
  895. INSERT INTO country(short_name,name) VALUES ('MS','Montserrat');
  896. INSERT INTO country(short_name,name) VALUES ('MT','Malta');
  897. INSERT INTO country(short_name,name) VALUES ('MU','Mauritius');
  898. INSERT INTO country(short_name,name) VALUES ('MV','Maldives');
  899. INSERT INTO country(short_name,name) VALUES ('MW','Malawi');
  900. INSERT INTO country(short_name,name) VALUES ('MX','Mexico');
  901. INSERT INTO country(short_name,name) VALUES ('MY','Malaysia');
  902. INSERT INTO country(short_name,name) VALUES ('MZ','Mozambique');
  903. INSERT INTO country(short_name,name) VALUES ('NA','Namibia');
  904. INSERT INTO country(short_name,name) VALUES ('NC','New Caledonia');
  905. INSERT INTO country(short_name,name) VALUES ('NE','Niger');
  906. INSERT INTO country(short_name,name) VALUES ('NF','Norfolk Island');
  907. INSERT INTO country(short_name,name) VALUES ('NG','Nigeria');
  908. INSERT INTO country(short_name,name) VALUES ('NI','Nicaragua');
  909. INSERT INTO country(short_name,name) VALUES ('NL','Netherlands');
  910. INSERT INTO country(short_name,name) VALUES ('NO','Norway');
  911. INSERT INTO country(short_name,name) VALUES ('NP','Nepal');
  912. INSERT INTO country(short_name,name) VALUES ('NR','Nauru');
  913. INSERT INTO country(short_name,name) VALUES ('NT','Neutral Zone');
  914. INSERT INTO country(short_name,name) VALUES ('NU','Niue');
  915. INSERT INTO country(short_name,name) VALUES ('NZ','New Zealand (Aotearoa)');
  916. INSERT INTO country(short_name,name) VALUES ('OM','Oman');
  917. INSERT INTO country(short_name,name) VALUES ('PA','Panama');
  918. INSERT INTO country(short_name,name) VALUES ('PE','Peru');
  919. INSERT INTO country(short_name,name) VALUES ('PF','French Polynesia');
  920. INSERT INTO country(short_name,name) VALUES ('PG','Papua New Guinea');
  921. INSERT INTO country(short_name,name) VALUES ('PH','Philippines');
  922. INSERT INTO country(short_name,name) VALUES ('PK','Pakistan');
  923. INSERT INTO country(short_name,name) VALUES ('PL','Poland');
  924. INSERT INTO country(short_name,name) VALUES ('PM','St. Pierre and Miquelon');
  925. INSERT INTO country(short_name,name) VALUES ('PN','Pitcairn');
  926. INSERT INTO country(short_name,name) VALUES ('PR','Puerto Rico');
  927. INSERT INTO country(short_name,name) VALUES ('PS','Palestinian Territory, Occupied');
  928. INSERT INTO country(short_name,name) VALUES ('PT','Portugal');
  929. INSERT INTO country(short_name,name) VALUES ('PW','Palau');
  930. INSERT INTO country(short_name,name) VALUES ('PY','Paraguay');
  931. INSERT INTO country(short_name,name) VALUES ('QA','Qatar');
  932. INSERT INTO country(short_name,name) VALUES ('RE','Reunion');
  933. INSERT INTO country(short_name,name) VALUES ('RO','Romania');
  934. INSERT INTO country(short_name,name) VALUES ('RS','Serbia');
  935. INSERT INTO country(short_name,name) VALUES ('RU','Russian Federation');
  936. INSERT INTO country(short_name,name) VALUES ('RW','Rwanda');
  937. INSERT INTO country(short_name,name) VALUES ('SA','Saudi Arabia');
  938. INSERT INTO country(short_name,name) VALUES ('SB','Solomon Islands');
  939. INSERT INTO country(short_name,name) VALUES ('SC','Seychelles');
  940. INSERT INTO country(short_name,name) VALUES ('SD','Sudan');
  941. INSERT INTO country(short_name,name) VALUES ('SE','Sweden');
  942. INSERT INTO country(short_name,name) VALUES ('SG','Singapore');
  943. INSERT INTO country(short_name,name) VALUES ('SH','St. Helena');
  944. INSERT INTO country(short_name,name) VALUES ('SI','Slovenia');
  945. INSERT INTO country(short_name,name) VALUES ('SJ','Svalbard & Jan Mayen Islands');
  946. INSERT INTO country(short_name,name) VALUES ('SK','Slovak Republic');
  947. INSERT INTO country(short_name,name) VALUES ('SL','Sierra Leone');
  948. INSERT INTO country(short_name,name) VALUES ('SM','San Marino');
  949. INSERT INTO country(short_name,name) VALUES ('SN','Senegal');
  950. INSERT INTO country(short_name,name) VALUES ('SO','Somalia');
  951. INSERT INTO country(short_name,name) VALUES ('SR','Suriname');
  952. INSERT INTO country(short_name,name) VALUES ('ST','Sao Tome and Principe');
  953. INSERT INTO country(short_name,name) VALUES ('SU','USSR (former)');
  954. INSERT INTO country(short_name,name) VALUES ('SV','El Salvador');
  955. INSERT INTO country(short_name,name) VALUES ('SY','Syria');
  956. INSERT INTO country(short_name,name) VALUES ('SZ','Swaziland');
  957. INSERT INTO country(short_name,name) VALUES ('TC','Turks and Caicos Islands');
  958. INSERT INTO country(short_name,name) VALUES ('TD','Chad');
  959. INSERT INTO country(short_name,name) VALUES ('TF','French Southern Territories');
  960. INSERT INTO country(short_name,name) VALUES ('TG','Togo');
  961. INSERT INTO country(short_name,name) VALUES ('TH','Thailand');
  962. INSERT INTO country(short_name,name) VALUES ('TJ','Tajikistan');
  963. INSERT INTO country(short_name,name) VALUES ('TK','Tokelau');
  964. INSERT INTO country(short_name,name) VALUES ('TM','Turkmenistan');
  965. INSERT INTO country(short_name,name) VALUES ('TN','Tunisia');
  966. INSERT INTO country(short_name,name) VALUES ('TO','Tonga');
  967. INSERT INTO country(short_name,name) VALUES ('TP','East Timor');
  968. INSERT INTO country(short_name,name) VALUES ('TR','Turkey');
  969. INSERT INTO country(short_name,name) VALUES ('TT','Trinidad and Tobago');
  970. INSERT INTO country(short_name,name) VALUES ('TV','Tuvalu');
  971. INSERT INTO country(short_name,name) VALUES ('TW','Taiwan');
  972. INSERT INTO country(short_name,name) VALUES ('TZ','Tanzania');
  973. INSERT INTO country(short_name,name) VALUES ('UA','Ukraine');
  974. INSERT INTO country(short_name,name) VALUES ('UG','Uganda');
  975. INSERT INTO country(short_name,name) VALUES ('UK','United Kingdom');
  976. INSERT INTO country(short_name,name) VALUES ('UM','US Minor Outlying Islands');
  977. INSERT INTO country(short_name,name) VALUES ('US','United States');
  978. INSERT INTO country(short_name,name) VALUES ('UY','Uruguay');
  979. INSERT INTO country(short_name,name) VALUES ('UZ','Uzbekistan');
  980. INSERT INTO country(short_name,name) VALUES ('VA','Vatican City State (Holy See)');
  981. INSERT INTO country(short_name,name) VALUES ('VC','Saint Vincent & the Grenadines');
  982. INSERT INTO country(short_name,name) VALUES ('VE','Venezuela');
  983. INSERT INTO country(short_name,name) VALUES ('VG','British Virgin Islands');
  984. INSERT INTO country(short_name,name) VALUES ('VI','Virgin Islands (U.S.)');
  985. INSERT INTO country(short_name,name) VALUES ('VN','Viet Nam');
  986. INSERT INTO country(short_name,name) VALUES ('VU','Vanuatu');
  987. INSERT INTO country(short_name,name) VALUES ('WF','Wallis and Futuna Islands');
  988. INSERT INTO country(short_name,name) VALUES ('WS','Samoa');
  989. INSERT INTO country(short_name,name) VALUES ('YE','Yemen');
  990. INSERT INTO country(short_name,name) VALUES ('YT','Mayotte');
  991. INSERT INTO country(short_name,name) VALUES ('YU','Yugoslavia (former)');
  992. INSERT INTO country(short_name,name) VALUES ('ZA','South Africa');
  993. INSERT INTO country(short_name,name) VALUES ('ZM','Zambia');
  994. INSERT INTO country(short_name,name) VALUES ('ZR','Zaire');
  995. INSERT INTO country(short_name,name) VALUES ('ZW','Zimbabwe');
  996. --
  997. CREATE FUNCTION del_yearend() RETURNS TRIGGER AS '
  998. begin
  999. delete from yearend where trans_id = old.id;
  1000. return NULL;
  1001. end;
  1002. ' language 'plpgsql';
  1003. -- end function
  1004. --
  1005. CREATE TRIGGER del_yearend AFTER DELETE ON gl FOR EACH ROW EXECUTE PROCEDURE del_yearend();
  1006. -- end trigger
  1007. --
  1008. CREATE FUNCTION del_department() RETURNS TRIGGER AS '
  1009. begin
  1010. delete from dpt_trans where trans_id = old.id;
  1011. return NULL;
  1012. end;
  1013. ' language 'plpgsql';
  1014. -- end function
  1015. --
  1016. CREATE TRIGGER del_department AFTER DELETE ON ar FOR EACH ROW EXECUTE PROCEDURE del_department();
  1017. -- end trigger
  1018. CREATE TRIGGER del_department AFTER DELETE ON ap FOR EACH ROW EXECUTE PROCEDURE del_department();
  1019. -- end trigger
  1020. CREATE TRIGGER del_department AFTER DELETE ON gl FOR EACH ROW EXECUTE PROCEDURE del_department();
  1021. -- end trigger
  1022. CREATE TRIGGER del_department AFTER DELETE ON oe FOR EACH ROW EXECUTE PROCEDURE del_department();
  1023. -- end trigger
  1024. --
  1025. CREATE FUNCTION del_exchangerate() RETURNS TRIGGER AS '
  1026. declare
  1027. t_transdate date;
  1028. t_curr char(3);
  1029. t_id int;
  1030. d_curr text;
  1031. begin
  1032. select into d_curr substr(value,1,3) from defaults where setting_key = ''curr'';
  1033. if TG_RELNAME = ''ar'' then
  1034. select into t_curr, t_transdate curr, transdate from ar where id = old.id;
  1035. end if;
  1036. if TG_RELNAME = ''ap'' then
  1037. select into t_curr, t_transdate curr, transdate from ap where id = old.id;
  1038. end if;
  1039. if TG_RELNAME = ''oe'' then
  1040. select into t_curr, t_transdate curr, transdate from oe where id = old.id;
  1041. end if;
  1042. if d_curr != t_curr then
  1043. select into t_id a.id from acc_trans ac
  1044. join ar a on (a.id = ac.trans_id)
  1045. where a.curr = t_curr
  1046. and ac.transdate = t_transdate
  1047. except select a.id from ar a where a.id = old.id
  1048. union
  1049. select a.id from acc_trans ac
  1050. join ap a on (a.id = ac.trans_id)
  1051. where a.curr = t_curr
  1052. and ac.transdate = t_transdate
  1053. except select a.id from ap a where a.id = old.id
  1054. union
  1055. select o.id from oe o
  1056. where o.curr = t_curr
  1057. and o.transdate = t_transdate
  1058. except select o.id from oe o where o.id = old.id;
  1059. if not found then
  1060. delete from exchangerate where curr = t_curr and transdate = t_transdate;
  1061. end if;
  1062. end if;
  1063. return old;
  1064. end;
  1065. ' language 'plpgsql';
  1066. -- end function
  1067. --
  1068. CREATE TRIGGER del_exchangerate BEFORE DELETE ON ar FOR EACH ROW EXECUTE PROCEDURE del_exchangerate();
  1069. -- end trigger
  1070. --
  1071. CREATE TRIGGER del_exchangerate BEFORE DELETE ON ap FOR EACH ROW EXECUTE PROCEDURE del_exchangerate();
  1072. -- end trigger
  1073. --
  1074. CREATE TRIGGER del_exchangerate BEFORE DELETE ON oe FOR EACH ROW EXECUTE PROCEDURE del_exchangerate();
  1075. -- end trigger
  1076. --
  1077. CREATE FUNCTION check_department() RETURNS TRIGGER AS '
  1078. declare
  1079. dpt_id int;
  1080. begin
  1081. if new.department_id = 0 then
  1082. delete from dpt_trans where trans_id = new.id;
  1083. return NULL;
  1084. end if;
  1085. select into dpt_id trans_id from dpt_trans where trans_id = new.id;
  1086. if dpt_id > 0 then
  1087. update dpt_trans set department_id = new.department_id where trans_id = dpt_id;
  1088. else
  1089. insert into dpt_trans (trans_id, department_id) values (new.id, new.department_id);
  1090. end if;
  1091. return NULL;
  1092. end;
  1093. ' language 'plpgsql';
  1094. -- end function
  1095. --
  1096. CREATE TRIGGER check_department AFTER INSERT OR UPDATE ON ar FOR EACH ROW EXECUTE PROCEDURE check_department();
  1097. -- end trigger
  1098. CREATE TRIGGER check_department AFTER INSERT OR UPDATE ON ap FOR EACH ROW EXECUTE PROCEDURE check_department();
  1099. -- end trigger
  1100. CREATE TRIGGER check_department AFTER INSERT OR UPDATE ON gl FOR EACH ROW EXECUTE PROCEDURE check_department();
  1101. -- end trigger
  1102. CREATE TRIGGER check_department AFTER INSERT OR UPDATE ON oe FOR EACH ROW EXECUTE PROCEDURE check_department();
  1103. -- end trigger
  1104. --
  1105. CREATE FUNCTION del_recurring() RETURNS TRIGGER AS '
  1106. BEGIN
  1107. DELETE FROM recurring WHERE id = old.id;
  1108. DELETE FROM recurringemail WHERE id = old.id;
  1109. DELETE FROM recurringprint WHERE id = old.id;
  1110. RETURN NULL;
  1111. END;
  1112. ' language 'plpgsql';
  1113. --end function
  1114. CREATE TRIGGER del_recurring AFTER DELETE ON ar FOR EACH ROW EXECUTE PROCEDURE del_recurring();
  1115. -- end trigger
  1116. CREATE TRIGGER del_recurring AFTER DELETE ON ap FOR EACH ROW EXECUTE PROCEDURE del_recurring();
  1117. -- end trigger
  1118. CREATE TRIGGER del_recurring AFTER DELETE ON gl FOR EACH ROW EXECUTE PROCEDURE del_recurring();
  1119. -- end trigger
  1120. --
  1121. CREATE FUNCTION avgcost(int) RETURNS FLOAT AS '
  1122. DECLARE
  1123. v_cost float;
  1124. v_qty float;
  1125. v_parts_id alias for $1;
  1126. BEGIN
  1127. SELECT INTO v_cost, v_qty SUM(i.sellprice * i.qty), SUM(i.qty)
  1128. FROM invoice i
  1129. JOIN ap a ON (a.id = i.trans_id)
  1130. WHERE i.parts_id = v_parts_id;
  1131. IF v_cost IS NULL THEN
  1132. v_cost := 0;
  1133. END IF;
  1134. IF NOT v_qty IS NULL THEN
  1135. IF v_qty = 0 THEN
  1136. v_cost := 0;
  1137. ELSE
  1138. v_cost := v_cost/v_qty;
  1139. END IF;
  1140. END IF;
  1141. RETURN v_cost;
  1142. END;
  1143. ' language 'plpgsql';
  1144. -- end function
  1145. --
  1146. CREATE FUNCTION lastcost(int) RETURNS FLOAT AS '
  1147. DECLARE
  1148. v_cost float;
  1149. v_parts_id alias for $1;
  1150. BEGIN
  1151. SELECT INTO v_cost sellprice FROM invoice i
  1152. JOIN ap a ON (a.id = i.trans_id)
  1153. WHERE i.parts_id = v_parts_id
  1154. ORDER BY a.transdate desc, a.id desc
  1155. LIMIT 1;
  1156. IF v_cost IS NULL THEN
  1157. v_cost := 0;
  1158. END IF;
  1159. RETURN v_cost;
  1160. END;
  1161. ' language plpgsql;
  1162. -- end function
  1163. --
  1164. CREATE OR REPLACE FUNCTION trigger_parts_short() RETURNS TRIGGER
  1165. AS
  1166. '
  1167. BEGIN
  1168. IF NEW.onhand >= NEW.rop THEN
  1169. NOTIFY parts_short;
  1170. END IF;
  1171. RETURN NEW;
  1172. END;
  1173. ' LANGUAGE PLPGSQL;
  1174. -- end function
  1175. CREATE TRIGGER parts_short AFTER UPDATE ON parts
  1176. FOR EACH ROW EXECUTE PROCEDURE trigger_parts_short();
  1177. -- end function
  1178. CREATE OR REPLACE FUNCTION add_custom_field (VARCHAR, VARCHAR, VARCHAR)
  1179. RETURNS BOOL AS
  1180. '
  1181. DECLARE
  1182. table_name ALIAS FOR $1;
  1183. new_field_name ALIAS FOR $2;
  1184. field_datatype ALIAS FOR $3;
  1185. BEGIN
  1186. EXECUTE ''SELECT TABLE_ID FROM custom_table_catalog
  1187. WHERE extends = '''''' || table_name || '''''' '';
  1188. IF NOT FOUND THEN
  1189. BEGIN
  1190. INSERT INTO custom_table_catalog (extends)
  1191. VALUES (table_name);
  1192. EXECUTE ''CREATE TABLE custom_''||table_name ||
  1193. '' (row_id INT PRIMARY KEY)'';
  1194. EXCEPTION WHEN duplicate_table THEN
  1195. -- do nothing
  1196. END;
  1197. END IF;
  1198. EXECUTE ''INSERT INTO custom_field_catalog (field_name, table_id)
  1199. VALUES ( '''''' || new_field_name ||'''''', (SELECT table_id FROM custom_table_catalog
  1200. WHERE extends = ''''''|| table_name || ''''''))'';
  1201. EXECUTE ''ALTER TABLE custom_''||table_name || '' ADD COLUMN ''
  1202. || new_field_name || '' '' || field_datatype;
  1203. RETURN TRUE;
  1204. END;
  1205. ' LANGUAGE PLPGSQL;
  1206. -- end function
  1207. CREATE OR REPLACE FUNCTION drop_custom_field (VARCHAR, VARCHAR)
  1208. RETURNS BOOL AS
  1209. '
  1210. DECLARE
  1211. table_name ALIAS FOR $1;
  1212. custom_field_name ALIAS FOR $2;
  1213. BEGIN
  1214. DELETE FROM custom_field_catalog
  1215. WHERE field_name = custom_field_name AND
  1216. table_id = (SELECT table_id FROM custom_table_catalog
  1217. WHERE extends = table_name);
  1218. EXECUTE ''ALTER TABLE custom_'' || table_name ||
  1219. '' DROP COLUMN '' || custom_field_name;
  1220. RETURN TRUE;
  1221. END;
  1222. ' LANGUAGE PLPGSQL;
  1223. -- end function
  1224. CREATE TABLE menu_node (
  1225. id serial NOT NULL,
  1226. label character varying NOT NULL,
  1227. parent integer,
  1228. "position" integer NOT NULL
  1229. );
  1230. --ALTER TABLE public.menu_node OWNER TO ledgersmb;
  1231. --
  1232. -- Name: menu_node_id_seq; Type: SEQUENCE SET; Schema: public; Owner: ledgersmb
  1233. --
  1234. SELECT pg_catalog.setval('menu_node_id_seq', 209, true);
  1235. --
  1236. -- Data for Name: menu_node; Type: TABLE DATA; Schema: public; Owner: ledgersmb
  1237. --
  1238. COPY menu_node (id, label, parent, "position") FROM stdin;
  1239. 205 Transaction Approval 0 5
  1240. 128 System 0 16
  1241. 190 Stylesheet 0 17
  1242. 191 Preferences 0 18
  1243. 192 New Window 0 19
  1244. 193 Logout 0 20
  1245. 206 Batches 205 1
  1246. 207 Drafts 205 2
  1247. 46 HR 0 6
  1248. 50 Order Entry 0 7
  1249. 63 Shipping 0 8
  1250. 67 Quotations 0 9
  1251. 73 General Journal 0 10
  1252. 77 Goods and Services 0 11
  1253. 0 Top-level \N 0
  1254. 1 AR 0 1
  1255. 2 Add Transaction 1 1
  1256. 144 Departments 128 8
  1257. 5 Transactions 4 1
  1258. 6 Outstanding 4 2
  1259. 7 AR Aging 4 3
  1260. 9 Taxable Sales 4 4
  1261. 10 Non-Taxable 4 5
  1262. 12 Add Customer 11 1
  1263. 13 Reports 11 2
  1264. 14 Search 13 1
  1265. 15 History 13 2
  1266. 16 Point of Sale 0 2
  1267. 17 Sale 16 1
  1268. 18 Open 16 2
  1269. 19 Receipts 16 3
  1270. 20 Close Till 16 4
  1271. 21 AP 0 3
  1272. 22 Add Transaction 21 1
  1273. 145 Add Department 144 1
  1274. 25 Transactions 24 1
  1275. 26 Outstanding 24 2
  1276. 27 AP Aging 24 3
  1277. 28 Taxable 24 4
  1278. 29 Non-taxable 24 5
  1279. 31 Add Vendor 30 1
  1280. 32 Reports 30 2
  1281. 33 Search 32 1
  1282. 34 History 32 2
  1283. 35 Cash 0 4
  1284. 36 Receipt 35 1
  1285. 38 Payment 35 3
  1286. 37 Receipts 35 2
  1287. 146 List Departments 144 2
  1288. 42 Receipts 41 1
  1289. 43 Payments 41 2
  1290. 44 Reconciliation 41 3
  1291. 147 Type of Business 128 9
  1292. 47 Employees 46 1
  1293. 48 Add Employee 47 1
  1294. 49 Search 47 2
  1295. 51 Sales Order 50 1
  1296. 52 Purchase Order 50 2
  1297. 53 Reports 50 3
  1298. 54 Sales Orders 53 1
  1299. 55 Purchase Orders 53 2
  1300. 57 Sales Orders 56 1
  1301. 58 Purchase Orders 56 2
  1302. 56 Generate 50 4
  1303. 60 Consolidate 50 5
  1304. 61 Sales Orders 60 1
  1305. 62 Purchase Orders 60 2
  1306. 64 Ship 63 1
  1307. 65 Receive 63 2
  1308. 66 Transfer 63 3
  1309. 68 Quotation 67 1
  1310. 69 RFQ 67 2
  1311. 70 Reports 67 3
  1312. 71 Quotations 70 1
  1313. 72 RFQs 70 2
  1314. 74 Journal Entry 73 1
  1315. 75 Adjust Till 73 2
  1316. 76 Reports 73 3
  1317. 78 Add Part 77 1
  1318. 79 Add Service 77 2
  1319. 80 Add Assembly 77 3
  1320. 81 Add Overhead 77 4
  1321. 82 Add Group 77 5
  1322. 83 Add Pricegroup 77 6
  1323. 84 Stock Assembly 77 7
  1324. 85 Reports 77 8
  1325. 86 All Items 85 1
  1326. 87 Parts 85 2
  1327. 88 Requirements 85 3
  1328. 89 Services 85 4
  1329. 90 Labor 85 5
  1330. 91 Groups 85 6
  1331. 92 Pricegroups 85 7
  1332. 93 Assembly 85 8
  1333. 94 Components 85 9
  1334. 95 Translations 77 9
  1335. 96 Description 95 1
  1336. 97 Partsgroup 95 2
  1337. 99 Add Project 98 1
  1338. 100 Add Timecard 98 2
  1339. 101 Generate 98 3
  1340. 102 Sales Orders 101 1
  1341. 103 Reports 98 4
  1342. 104 Search 103 1
  1343. 105 Transactions 103 2
  1344. 106 Time Cards 103 3
  1345. 107 Translations 98 5
  1346. 108 Description 107 1
  1347. 110 Chart of Accounts 109 1
  1348. 111 Trial Balance 109 2
  1349. 112 Income Statement 109 3
  1350. 113 Balance Sheet 109 4
  1351. 114 Inventory Activity 109 5
  1352. 117 Sales Invoices 116 1
  1353. 118 Sales Orders 116 2
  1354. 119 Checks 116 3
  1355. 120 Work Orders 116 4
  1356. 121 Quotations 116 5
  1357. 122 Packing Lists 116 6
  1358. 123 Pick Lists 116 7
  1359. 124 Purchase Orders 116 8
  1360. 125 Bin Lists 116 9
  1361. 126 RFQs 116 10
  1362. 127 Time Cards 116 11
  1363. 129 Audit Control 128 1
  1364. 130 Taxes 128 2
  1365. 131 Defaults 128 3
  1366. 132 Yearend 128 4
  1367. 133 Backup 128 5
  1368. 134 Send to File 133 1
  1369. 135 Send to Email 133 2
  1370. 136 Chart of Accounts 128 6
  1371. 137 Add Accounts 136 1
  1372. 138 List Accounts 136 2
  1373. 139 Add GIFI 136 3
  1374. 140 List GIFI 136 4
  1375. 141 Warehouses 128 7
  1376. 142 Add Warehouse 141 1
  1377. 143 List Warehouse 141 2
  1378. 148 Add Business 147 1
  1379. 149 List Businesses 147 2
  1380. 150 Language 128 10
  1381. 151 Add Language 150 1
  1382. 152 List Languages 150 2
  1383. 153 SIC 128 11
  1384. 154 Add SIC 153 1
  1385. 155 List SIC 153 2
  1386. 156 HTML Templates 128 12
  1387. 157 Income Statement 156 1
  1388. 158 Balance Sheet 156 2
  1389. 159 Invoice 156 3
  1390. 160 AR Transaction 156 4
  1391. 161 AP Transaction 156 5
  1392. 162 Packing List 156 6
  1393. 163 Pick List 156 7
  1394. 164 Sales Order 156 8
  1395. 165 Work Order 156 9
  1396. 166 Purchase Order 156 10
  1397. 167 Bin List 156 11
  1398. 168 Statement 156 12
  1399. 169 Quotation 156 13
  1400. 170 RFQ 156 14
  1401. 171 Timecard 156 15
  1402. 172 LaTeX Templates 128 13
  1403. 173 Invoice 172 1
  1404. 174 AR Transaction 172 2
  1405. 175 AP Transaction 172 3
  1406. 176 Packing List 172 4
  1407. 177 Pick List 172 5
  1408. 178 Sales Order 172 6
  1409. 179 Work Order 172 7
  1410. 180 Purchase Order 172 8
  1411. 181 Bin List 172 9
  1412. 182 Statement 172 10
  1413. 183 Check 172 11
  1414. 184 Receipt 172 12
  1415. 185 Quotation 172 13
  1416. 186 RFQ 172 14
  1417. 187 Timecard 172 15
  1418. 188 Text Templates 128 14
  1419. 189 POS Invoice 188 1
  1420. 198 AR Voucher 1 2
  1421. 3 Sales Invoice 1 3
  1422. 11 Customers 1 7
  1423. 4 Reports 1 6
  1424. 194 Credit Note 1 4
  1425. 195 Credit Invoice 1 5
  1426. 199 AP Voucher 21 2
  1427. 23 Vendor Invoice 21 3
  1428. 24 Reports 21 6
  1429. 30 Vendors 21 7
  1430. 196 Debit Note 21 4
  1431. 197 Debit Invoice 21 5
  1432. 200 Vouchers 35 5
  1433. 40 Transfer 35 6
  1434. 41 Reports 35 8
  1435. 45 Reconciliation 35 7
  1436. 203 Receipts 200 3
  1437. 204 Reverse Receipts 200 4
  1438. 201 Payments 200 1
  1439. 202 Reverse Payment 200 2
  1440. 98 Projects 0 12
  1441. 109 Reports 0 13
  1442. 115 Recurring Transactions 0 14
  1443. 116 Batch Printing 0 15
  1444. \.
  1445. --
  1446. -- Name: menu_node_parent_key; Type: CONSTRAINT; Schema: public; Owner: ledgersmb; Tablespace:
  1447. --
  1448. ALTER TABLE ONLY menu_node
  1449. ADD CONSTRAINT menu_node_parent_key UNIQUE (parent, "position");
  1450. --
  1451. -- Name: menu_node_pkey; Type: CONSTRAINT; Schema: public; Owner: ledgersmb; Tablespace:
  1452. --
  1453. ALTER TABLE ONLY menu_node
  1454. ADD CONSTRAINT menu_node_pkey PRIMARY KEY (id);
  1455. --
  1456. -- Name: menu_node_parent_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ledgersmb
  1457. --
  1458. ALTER TABLE ONLY menu_node
  1459. ADD CONSTRAINT menu_node_parent_fkey FOREIGN KEY (parent) REFERENCES menu_node(id);
  1460. CREATE TABLE menu_attribute (
  1461. node_id integer NOT NULL,
  1462. attribute character varying NOT NULL,
  1463. value character varying NOT NULL,
  1464. id serial NOT NULL
  1465. );
  1466. --
  1467. -- Name: menu_attribute_id_seq; Type: SEQUENCE SET; Schema: public; Owner: ledgersmb
  1468. --
  1469. SELECT pg_catalog.setval('menu_attribute_id_seq', 584, true);
  1470. --
  1471. -- Data for Name: menu_attribute; Type: TABLE DATA; Schema: public; Owner: ledgersmb
  1472. --
  1473. COPY menu_attribute (node_id, attribute, value, id) FROM stdin;
  1474. 26 outstanding 1 584
  1475. 205 menu 1 574
  1476. 206 module vouchers.pl 575
  1477. 206 action search_batch 576
  1478. 207 module drafts.pl 577
  1479. 207 action search 578
  1480. 1 menu 1 1
  1481. 2 module ar.pl 2
  1482. 2 action add 3
  1483. 3 action add 4
  1484. 3 module is.pl 5
  1485. 3 type invoice 6
  1486. 4 menu 1 7
  1487. 5 module ar.pl 8
  1488. 5 action search 9
  1489. 5 nextsub transactions 10
  1490. 6 module ar.pl 12
  1491. 6 action search 13
  1492. 6 nextsub transactions 14
  1493. 7 module rp.pl 15
  1494. 7 action report 16
  1495. 7 report ar_aging 17
  1496. 9 module rp.pl 21
  1497. 9 action report 22
  1498. 9 report tax_collected 23
  1499. 10 module rp.pl 24
  1500. 10 action report 25
  1501. 10 report nontaxable_sales 26
  1502. 11 menu 1 27
  1503. 12 module customer.pl 28
  1504. 12 action add 29
  1505. 13 menu 1 31
  1506. 14 module customer.pl 32
  1507. 14 action search 36
  1508. 15 module customer.pl 35
  1509. 15 db customer 37
  1510. 15 action history 33
  1511. 16 menu 1 38
  1512. 17 module ps.pl 39
  1513. 17 action add 40
  1514. 17 nextsub openinvoices 41
  1515. 18 action openinvoices 42
  1516. 18 module ps.pl 43
  1517. 19 module ps.pl 44
  1518. 19 action receipts 46
  1519. 20 module rc.pl 47
  1520. 20 action till_closing 48
  1521. 20 pos true 49
  1522. 21 menu 1 50
  1523. 22 action add 52
  1524. 22 module ap.pl 51
  1525. 23 action add 53
  1526. 23 type invoice 55
  1527. 23 module ir.pl 54
  1528. 24 menu 1 56
  1529. 25 action search 58
  1530. 25 nextsub transactions 59
  1531. 25 module ap.pl 57
  1532. 26 action search 61
  1533. 26 nextsub transactions 62
  1534. 26 module ap.pl 60
  1535. 27 module rp.pl 63
  1536. 27 action report 64
  1537. 28 module rp.pl 66
  1538. 28 action report 67
  1539. 28 report tax_collected 68
  1540. 27 report tax_paid 65
  1541. 29 module rp.pl 69
  1542. 29 action report 70
  1543. 29 report report 71
  1544. 30 menu 1 72
  1545. 31 module vendor.pl 73
  1546. 31 action add 74
  1547. 31 db vendor 75
  1548. 32 menu 1 76
  1549. 33 module vendor.pl 77
  1550. 33 action search 79
  1551. 33 db vendor 78
  1552. 34 module vendor.pl 80
  1553. 34 action history 81
  1554. 34 db vendor 82
  1555. 35 menu 1 83
  1556. 36 module payment.pl 84
  1557. 36 action payment 85
  1558. 36 type receipt 86
  1559. 37 module cp.pl 87
  1560. 38 module cp.pl 90
  1561. 38 action payment 91
  1562. 37 type receipt 89
  1563. 37 action payments 88
  1564. 38 type check 92
  1565. 194 module ar.pl 538
  1566. 194 action add 539
  1567. 40 module gl.pl 96
  1568. 40 action add 97
  1569. 40 transfer 1 98
  1570. 41 menu 1 99
  1571. 42 module rp.pl 100
  1572. 42 action report 101
  1573. 42 report receipts 102
  1574. 43 module rp.pl 103
  1575. 43 action report 104
  1576. 43 report payments 105
  1577. 45 module rc.pl 106
  1578. 45 action reconciliation 107
  1579. 44 module rc.pl 108
  1580. 44 action reconciliation 109
  1581. 44 report 1 110
  1582. 46 menu 1 111
  1583. 47 menu 1 112
  1584. 48 module employee.pl 113
  1585. 48 action add 114
  1586. 48 db employee 115
  1587. 49 module hr.pl 116
  1588. 49 db employee 118
  1589. 49 action search 117
  1590. 50 menu 1 119
  1591. 51 module oe.pl 120
  1592. 51 action add 121
  1593. 51 type sales_order 122
  1594. 52 module oe.pl 123
  1595. 52 action add 124
  1596. 52 type purchase_order 125
  1597. 53 menu 1 126
  1598. 54 module oe.pl 127
  1599. 54 type sales_order 129
  1600. 54 action search 128
  1601. 55 module oe.pl 130
  1602. 55 type purchase_order 132
  1603. 55 action search 131
  1604. 56 menu 1 133
  1605. 57 module oe.pl 134
  1606. 57 action search 136
  1607. 58 module oe.pl 137
  1608. 58 action search 139
  1609. 57 type generate_sales_order 135
  1610. 58 type generate_purchase_order 138
  1611. 60 menu 1 550
  1612. 61 module oe.pl 140
  1613. 61 action search 141
  1614. 62 module oe.pl 143
  1615. 62 action search 144
  1616. 62 type consolidate_purchase_order 145
  1617. 61 type consolidate_sales_order 142
  1618. 63 menu 1 146
  1619. 64 module oe.pl 147
  1620. 64 action search 148
  1621. 65 module oe.pl 150
  1622. 65 action search 151
  1623. 65 type consolidate_sales_order 152
  1624. 64 type receive_order 149
  1625. 66 module oe.pl 153
  1626. 66 action search_transfer 154
  1627. 67 menu 1 155
  1628. 68 module oe.pl 156
  1629. 68 action add 157
  1630. 69 module oe.pl 159
  1631. 69 action add 160
  1632. 68 type sales_quotation 158
  1633. 69 type request_quotation 161
  1634. 70 menu 1 162
  1635. 71 module oe.pl 163
  1636. 71 type sales_quotation 165
  1637. 71 action search 164
  1638. 72 module oe.pl 166
  1639. 72 action search 168
  1640. 72 type request_quotation 167
  1641. 73 menu 1 169
  1642. 74 module gl.pl 170
  1643. 74 action add 171
  1644. 75 module gl.pl 172
  1645. 75 action add_pos_adjust 174
  1646. 75 rowcount 3 175
  1647. 75 pos_adjust 1 176
  1648. 75 reference Adjusting Till: (Till) Source: (Source) 177
  1649. 75 descripton Adjusting till due to data entry error 178
  1650. 76 module gl.pl 180
  1651. 76 action search 181
  1652. 77 menu 1 182
  1653. 78 module ic.pl 183
  1654. 78 action add 184
  1655. 78 item part 185
  1656. 79 module ic.pl 186
  1657. 79 action add 187
  1658. 79 item service 188
  1659. 80 module ic.pl 189
  1660. 80 action add 190
  1661. 81 module ic.pl 192
  1662. 81 action add 193
  1663. 81 item part 194
  1664. 80 item labor 191
  1665. 82 action add 195
  1666. 82 module pe.pl 196
  1667. 83 action add 198
  1668. 83 module pe.pl 199
  1669. 83 type partsgroup 200
  1670. 82 type pricegroup 197
  1671. 84 module ic.pl 202
  1672. 84 action stock_assembly 203
  1673. 85 menu 1 204
  1674. 86 module ic.pl 205
  1675. 87 action search 206
  1676. 88 module ic.pl 211
  1677. 88 action requirements 212
  1678. 89 action search 213
  1679. 89 module ic.pl 214
  1680. 89 searchitems service 215
  1681. 87 searchitems part 210
  1682. 90 action search 216
  1683. 90 module ic.pl 217
  1684. 90 searchitems labor 218
  1685. 91 module pe.pl 221
  1686. 91 type pricegroup 222
  1687. 91 action search 220
  1688. 92 module pe.pl 224
  1689. 92 type partsgroup 225
  1690. 92 action search 223
  1691. 93 action search 226
  1692. 93 module ic.pl 227
  1693. 93 searchitems assembly 228
  1694. 94 action search 229
  1695. 94 module ic.pl 230
  1696. 94 searchitems component 231
  1697. 95 menu 1 232
  1698. 96 module pe.pl 233
  1699. 96 action translation 234
  1700. 96 translation description 235
  1701. 97 module pe.pl 236
  1702. 97 action translation 237
  1703. 97 translation partsgroup 238
  1704. 98 menu 1 239
  1705. 99 module pe.pl 240
  1706. 99 action add 241
  1707. 99 type project 242
  1708. 100 module jc.pl 243
  1709. 100 action add 244
  1710. 99 project project 245
  1711. 100 project project 246
  1712. 100 type timecard 247
  1713. 101 menu 1 248
  1714. 102 module pe.pl 249
  1715. 102 action project_sales_order 250
  1716. 103 menu 1 255
  1717. 104 module pe.pl 256
  1718. 104 type project 258
  1719. 104 action search 257
  1720. 105 action report 260
  1721. 105 report projects 261
  1722. 105 module rp.pl 262
  1723. 106 module jc.pl 263
  1724. 106 action search 264
  1725. 106 type timecard 265
  1726. 106 project project 266
  1727. 107 menu 1 268
  1728. 108 module pe.pl 269
  1729. 108 action translation 270
  1730. 108 translation project 271
  1731. 109 menu 1 272
  1732. 110 module ca.pl 273
  1733. 110 action chart_of_accounts 274
  1734. 111 action report 275
  1735. 111 module rp.pl 276
  1736. 111 report trial_balance 277
  1737. 112 action report 278
  1738. 112 module rp.pl 279
  1739. 112 report income_statement 280
  1740. 113 action report 281
  1741. 113 module rp.pl 282
  1742. 113 report balance_sheet 283
  1743. 114 action report 284
  1744. 114 module rp.pl 285
  1745. 114 report inv_activity 286
  1746. 115 action recurring_transactions 287
  1747. 115 module am.pl 288
  1748. 116 menu 1 289
  1749. 119 module bp.pl 290
  1750. 119 action search 291
  1751. 119 type check 292
  1752. 119 vc vendor 293
  1753. 117 module bp.pl 294
  1754. 117 action search 295
  1755. 117 vc customer 297
  1756. 118 module bp.pl 298
  1757. 118 action search 299
  1758. 118 vc customer 300
  1759. 118 type invoice 301
  1760. 117 type sales_order 296
  1761. 120 module bp.pl 302
  1762. 120 action search 303
  1763. 120 vc customer 304
  1764. 121 module bp.pl 306
  1765. 121 action search 307
  1766. 121 vc customer 308
  1767. 122 module bp.pl 310
  1768. 122 action search 311
  1769. 122 vc customer 312
  1770. 120 type work_order 305
  1771. 121 type sales_quotation 309
  1772. 122 type packing_list 313
  1773. 123 module bp.pl 314
  1774. 123 action search 315
  1775. 123 vc customer 316
  1776. 123 type pick_list 317
  1777. 124 module bp.pl 318
  1778. 124 action search 319
  1779. 124 vc vendor 321
  1780. 124 type purchase_order 320
  1781. 125 module bp.pl 322
  1782. 125 action search 323
  1783. 125 vc vendor 325
  1784. 126 module bp.pl 326
  1785. 126 action search 327
  1786. 126 vc vendor 329
  1787. 127 module bp.pl 330
  1788. 127 action search 331
  1789. 127 type timecard 332
  1790. 125 type bin_list 324
  1791. 126 type request_quotation 328
  1792. 127 vc employee 333
  1793. 128 menu 1 334
  1794. 129 module am.pl 337
  1795. 130 module am.pl 338
  1796. 131 module am.pl 339
  1797. 129 action audit_control 340
  1798. 130 taxes audit_control 341
  1799. 131 action defaults 342
  1800. 130 action taxes 343
  1801. 132 module am.pl 346
  1802. 132 action yearend 347
  1803. 133 menu 1 348
  1804. 134 module am.pl 349
  1805. 135 module am.pl 350
  1806. 134 action backup 351
  1807. 135 action backup 352
  1808. 134 media file 353
  1809. 135 media email 354
  1810. 137 module am.pl 355
  1811. 138 module am.pl 356
  1812. 139 module am.pl 357
  1813. 140 module am.pl 358
  1814. 137 action add_account 359
  1815. 138 action list_account 360
  1816. 139 action add_gifi 361
  1817. 140 action list_gifi 362
  1818. 141 menu 1 363
  1819. 142 module am.pl 364
  1820. 143 module am.pl 365
  1821. 142 action add_warehouse 366
  1822. 143 action list_warehouse 367
  1823. 145 module am.pl 368
  1824. 146 module am.pl 369
  1825. 145 action add_department 370
  1826. 146 action list_department 371
  1827. 147 menu 1 372
  1828. 148 module am.pl 373
  1829. 149 module am.pl 374
  1830. 148 action add_business 375
  1831. 149 action list_business 376
  1832. 150 menu 1 377
  1833. 151 module am.pl 378
  1834. 152 module am.pl 379
  1835. 151 action add_language 380
  1836. 152 action list_language 381
  1837. 153 menu 1 382
  1838. 154 module am.pl 383
  1839. 155 module am.pl 384
  1840. 154 action add_sic 385
  1841. 155 action list_sic 386
  1842. 156 menu 1 387
  1843. 157 module am.pl 388
  1844. 158 module am.pl 389
  1845. 159 module am.pl 390
  1846. 160 module am.pl 391
  1847. 161 module am.pl 392
  1848. 162 module am.pl 393
  1849. 163 module am.pl 394
  1850. 164 module am.pl 395
  1851. 165 module am.pl 396
  1852. 166 module am.pl 397
  1853. 167 module am.pl 398
  1854. 168 module am.pl 399
  1855. 169 module am.pl 400
  1856. 170 module am.pl 401
  1857. 171 module am.pl 402
  1858. 157 action list_templates 403
  1859. 158 action list_templates 404
  1860. 159 action list_templates 405
  1861. 160 action list_templates 406
  1862. 161 action list_templates 407
  1863. 162 action list_templates 408
  1864. 163 action list_templates 409
  1865. 164 action list_templates 410
  1866. 165 action list_templates 411
  1867. 166 action list_templates 412
  1868. 167 action list_templates 413
  1869. 168 action list_templates 414
  1870. 169 action list_templates 415
  1871. 170 action list_templates 416
  1872. 171 action list_templates 417
  1873. 157 template income_statement 418
  1874. 158 template balance_sheet 419
  1875. 159 template invoice 420
  1876. 160 template ar_transaction 421
  1877. 161 template ap_transaction 422
  1878. 162 template packing_list 423
  1879. 163 template pick_list 424
  1880. 164 template sales_order 425
  1881. 165 template work_order 426
  1882. 166 template purchase_order 427
  1883. 167 template bin_list 428
  1884. 168 template statement 429
  1885. 169 template quotation 430
  1886. 170 template rfq 431
  1887. 171 template timecard 432
  1888. 157 format HTML 433
  1889. 158 format HTML 434
  1890. 159 format HTML 435
  1891. 160 format HTML 436
  1892. 161 format HTML 437
  1893. 162 format HTML 438
  1894. 163 format HTML 439
  1895. 164 format HTML 440
  1896. 165 format HTML 441
  1897. 166 format HTML 442
  1898. 167 format HTML 443
  1899. 168 format HTML 444
  1900. 169 format HTML 445
  1901. 170 format HTML 446
  1902. 171 format HTML 447
  1903. 172 menu 1 448
  1904. 173 action list_templates 449
  1905. 174 action list_templates 450
  1906. 175 action list_templates 451
  1907. 176 action list_templates 452
  1908. 177 action list_templates 453
  1909. 178 action list_templates 454
  1910. 179 action list_templates 455
  1911. 180 action list_templates 456
  1912. 181 action list_templates 457
  1913. 182 action list_templates 458
  1914. 183 action list_templates 459
  1915. 184 action list_templates 460
  1916. 185 action list_templates 461
  1917. 186 action list_templates 462
  1918. 187 action list_templates 463
  1919. 173 module am.pl 464
  1920. 174 module am.pl 465
  1921. 175 module am.pl 466
  1922. 176 module am.pl 467
  1923. 177 module am.pl 468
  1924. 178 module am.pl 469
  1925. 179 module am.pl 470
  1926. 180 module am.pl 471
  1927. 181 module am.pl 472
  1928. 182 module am.pl 473
  1929. 183 module am.pl 474
  1930. 184 module am.pl 475
  1931. 185 module am.pl 476
  1932. 186 module am.pl 477
  1933. 187 module am.pl 478
  1934. 173 format LATEX 479
  1935. 174 format LATEX 480
  1936. 175 format LATEX 481
  1937. 176 format LATEX 482
  1938. 177 format LATEX 483
  1939. 178 format LATEX 484
  1940. 179 format LATEX 485
  1941. 180 format LATEX 486
  1942. 181 format LATEX 487
  1943. 182 format LATEX 488
  1944. 183 format LATEX 489
  1945. 184 format LATEX 490
  1946. 185 format LATEX 491
  1947. 186 format LATEX 492
  1948. 187 format LATEX 493
  1949. 173 template invoice 506
  1950. 174 template ar_transaction 507
  1951. 175 template ap_transaction 508
  1952. 176 template packing_list 509
  1953. 177 template pick_list 510
  1954. 178 template sales_order 511
  1955. 179 template work_order 512
  1956. 180 template purchase_order 513
  1957. 181 template bin_list 514
  1958. 182 template statement 515
  1959. 185 template quotation 518
  1960. 186 template rfq 519
  1961. 187 template timecard 520
  1962. 183 template check 516
  1963. 184 template receipt 517
  1964. 188 menu 1 521
  1965. 189 module am.pl 522
  1966. 189 action list_templates 523
  1967. 189 template pos_invoice 524
  1968. 189 format TEXT 525
  1969. 190 action display_stylesheet 526
  1970. 190 module am.pl 527
  1971. 191 module am.pl 528
  1972. 191 action config 529
  1973. 193 module login.pl 532
  1974. 193 action logout 533
  1975. 193 target _top 534
  1976. 192 menu 1 530
  1977. 192 new 1 531
  1978. 0 menu 1 535
  1979. 136 menu 1 536
  1980. 144 menu 1 537
  1981. 195 action add 540
  1982. 195 module is.pl 541
  1983. 196 action add 543
  1984. 196 module ap.pl 544
  1985. 197 action add 545
  1986. 197 module ir.pl 547
  1987. 196 type debit_note 549
  1988. 194 type credit_note 548
  1989. 195 type credit_invoice 542
  1990. 197 type debit_invoice 546
  1991. 36 account_class 1 551
  1992. 202 batch_type payment_reversal 570
  1993. 204 batch_type receipt_reversal 573
  1994. 200 menu 1 552
  1995. 198 action create_batch 554
  1996. 198 batch_type receivable 555
  1997. 198 module vouchers.pl 553
  1998. 199 module vouchers.pl 559
  1999. 199 action create_batch 560
  2000. 199 batch_type ap 561
  2001. 201 module vouchers.pl 562
  2002. 201 action create_batch 563
  2003. 203 module vouchers.pl 565
  2004. 203 action create_batch 566
  2005. 203 batch_type receipts 567
  2006. 202 module vouchers.pl 568
  2007. 202 action create_batch 569
  2008. 204 module vouchers.pl 571
  2009. 204 action create_batch 572
  2010. 201 batch_type payment 564
  2011. \.
  2012. --
  2013. -- Name: menu_attribute_id_key; Type: CONSTRAINT; Schema: public; Owner: ledgersmb; Tablespace:
  2014. --
  2015. ALTER TABLE ONLY menu_attribute
  2016. ADD CONSTRAINT menu_attribute_id_key UNIQUE (id);
  2017. --
  2018. -- Name: menu_attribute_pkey; Type: CONSTRAINT; Schema: public; Owner: ledgersmb; Tablespace:
  2019. --
  2020. ALTER TABLE ONLY menu_attribute
  2021. ADD CONSTRAINT menu_attribute_pkey PRIMARY KEY (node_id, attribute);
  2022. --
  2023. -- Name: menu_attribute_node_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ledgersmb
  2024. --
  2025. ALTER TABLE ONLY menu_attribute
  2026. ADD CONSTRAINT menu_attribute_node_id_fkey FOREIGN KEY (node_id) REFERENCES menu_node(id);
  2027. --
  2028. -- PostgreSQL database dump complete
  2029. --
  2030. --
  2031. CREATE TABLE menu_acl (
  2032. id serial NOT NULL,
  2033. role_name character varying,
  2034. acl_type character varying,
  2035. node_id integer,
  2036. CONSTRAINT menu_acl_acl_type_check CHECK ((((acl_type)::text = 'allow'::text) OR ((acl_type)::text = 'deny'::text)))
  2037. );
  2038. ALTER TABLE ONLY menu_acl
  2039. ADD CONSTRAINT menu_acl_pkey PRIMARY KEY (id);
  2040. ALTER TABLE ONLY menu_acl
  2041. ADD CONSTRAINT menu_acl_node_id_fkey FOREIGN KEY (node_id) REFERENCES menu_node(id);
  2042. --
  2043. -- PostgreSQL database dump complete
  2044. --
  2045. CREATE TYPE menu_item AS (
  2046. position int,
  2047. id int,
  2048. level int,
  2049. label varchar,
  2050. path varchar,
  2051. args varchar[]
  2052. );
  2053. CREATE OR REPLACE FUNCTION menu_generate() RETURNS SETOF menu_item AS
  2054. $$
  2055. DECLARE
  2056. item menu_item;
  2057. arg menu_attribute%ROWTYPE;
  2058. BEGIN
  2059. FOR item IN
  2060. SELECT n.position, n.id, c.level, n.label, c.path, '{}'
  2061. FROM connectby('menu_node', 'id', 'parent', 'position', '0',
  2062. 0, ',')
  2063. c(id integer, parent integer, "level" integer,
  2064. path text, list_order integer)
  2065. JOIN menu_node n USING(id)
  2066. LOOP
  2067. FOR arg IN
  2068. SELECT *
  2069. FROM menu_attribute
  2070. WHERE node_id = item.id
  2071. LOOP
  2072. item.args := item.args ||
  2073. (arg.attribute || '=' || arg.value)::varchar;
  2074. END LOOP;
  2075. RETURN NEXT item;
  2076. END LOOP;
  2077. END;
  2078. $$ language plpgsql;
  2079. CREATE OR REPLACE FUNCTION menu_children(in_parent_id int) RETURNS SETOF menu_item
  2080. AS $$
  2081. declare
  2082. item menu_item;
  2083. arg menu_attribute%ROWTYPE;
  2084. begin
  2085. FOR item IN
  2086. SELECT n.position, n.id, c.level, n.label, c.path, '{}'
  2087. FROM connectby('menu_node', 'id', 'parent', 'position',
  2088. in_parent_id, 1, ',')
  2089. c(id integer, parent integer, "level" integer,
  2090. path text, list_order integer)
  2091. JOIN menu_node n USING(id)
  2092. LOOP
  2093. FOR arg IN
  2094. SELECT *
  2095. FROM menu_attribute
  2096. WHERE node_id = item.id
  2097. LOOP
  2098. item.args := item.args ||
  2099. (arg.attribute || '=' || arg.value)::varchar;
  2100. END LOOP;
  2101. return next item;
  2102. end loop;
  2103. end;
  2104. $$ language plpgsql;
  2105. COMMENT ON FUNCTION menu_children(int) IS $$ This function returns all menu items which are children of in_parent_id (the only input parameter. $$;
  2106. CREATE OR REPLACE FUNCTION
  2107. menu_insert(in_parent_id int, in_position int, in_label text)
  2108. returns int
  2109. AS $$
  2110. DECLARE
  2111. new_id int;
  2112. BEGIN
  2113. UPDATE menu_node
  2114. SET position = position * -1
  2115. WHERE parent = in_parent_id
  2116. AND position >= in_position;
  2117. INSERT INTO menu_node (parent, position, label)
  2118. VALUES (in_parent_id, in_position, in_label);
  2119. SELECT INTO new_id currval('menu_node_id_seq');
  2120. UPDATE menu_node
  2121. SET position = (position * -1) + 1
  2122. WHERE parent = in_parent_id
  2123. AND position < 0;
  2124. RETURN new_id;
  2125. END;
  2126. $$ language plpgsql;
  2127. comment on function menu_insert(int, int, text) is $$
  2128. This function inserts menu items at arbitrary positions. The arguments are, in
  2129. order: parent, position, label. The return value is the id number of the menu
  2130. item created. $$;
  2131. CREATE VIEW menu_friendly AS
  2132. SELECT t."level", t.path, t.list_order, (repeat(' '::text, (2 * t."level")) || (n.label)::text) AS label, n.id, n."position" FROM (connectby('menu_node'::text, 'id'::text, 'parent'::text, 'position'::text, '0'::text, 0, ','::text) t(id integer, parent integer, "level" integer, path text, list_order integer) JOIN menu_node n USING (id));
  2133. --ALTER TABLE public.menu_friendly OWNER TO ledgersmb;
  2134. --
  2135. -- PostgreSQL database dump complete
  2136. --
  2137. CREATE AGGREGATE as_array (
  2138. BASETYPE = ANYELEMENT,
  2139. STYPE = ANYARRAY,
  2140. SFUNC = ARRAY_APPEND,
  2141. INITCOND = '{}'
  2142. );
  2143. CREATE AGGREGATE compound_array (
  2144. BASETYPE = ANYARRAY,
  2145. STYPE = ANYARRAY,
  2146. SFUNC = ARRAY_CAT,
  2147. INITCOND = '{}'
  2148. );
  2149. CREATE TABLE pending_reports (
  2150. id bigserial primary key not null,
  2151. report_id int,
  2152. scn int,
  2153. their_balance INT,
  2154. our_balance INT,
  2155. errorcode INT,
  2156. entered_by int references entity(id) not null,
  2157. corrections INT NOT NULL DEFAULT 0,
  2158. clear_time TIMESTAMP NOT NULL,
  2159. insert_time TIMESTAMPTZ NOT NULL DEFAULT now(),
  2160. ledger_id int REFERENCES acc_trans(entry_id),
  2161. overlook boolean not null default 'f'
  2162. );
  2163. CREATE TABLE report_corrections (
  2164. id serial primary key not null,
  2165. correction_id int not null default 1,
  2166. entry_in int references pending_reports(id) not null,
  2167. entered_by int not null,
  2168. reason text not null,
  2169. insert_time timestamptz not null default now()
  2170. );
  2171. CREATE INDEX company_name_gist__idx ON company USING gist(legal_name gist_trgm_ops);
  2172. CREATE INDEX location_address_one_gist__idx ON location USING gist(line_one gist_trgm_ops);
  2173. CREATE INDEX location_address_two_gist__idx ON location USING gist(line_two gist_trgm_ops);
  2174. CREATE INDEX location_address_three_gist__idx ON location USING gist(line_three gist_trgm_ops);
  2175. CREATE INDEX location_city_prov_gist_idx ON location USING gist(city gist_trgm_ops);
  2176. CREATE INDEX entity_name_gist_idx ON entity USING gist(name gist_trgm_ops);
  2177. CREATE TABLE pending_job (
  2178. id serial not null unique,
  2179. batch_class int references batch_class(id),
  2180. entered_by text REFERENCES users(username)
  2181. not null default SESSION_USER,
  2182. entered_at timestamp default now(),
  2183. batch_id int references batch(id),
  2184. completed_at timestamp,
  2185. success bool,
  2186. error_condition text,
  2187. CHECK (completed_at IS NULL OR success IS NOT NULL),
  2188. CHECK (success IS NOT FALSE OR error_condition IS NOT NULL)
  2189. );
  2190. COMMENT ON table pending_job IS
  2191. $$ Purpose: This table stores pending/queued jobs to be processed async.
  2192. Additionally, this functions as a log of all such processing for purposes of
  2193. internal audits, performance tuning, and the like. $$;
  2194. CREATE INDEX pending_job_batch_id_pending ON pending_job(batch_id) where success IS NULL;
  2195. CREATE INDEX pending_job_entered_by ON pending_job(entered_by);
  2196. CREATE OR REPLACE FUNCTION trigger_pending_job() RETURNS TRIGGER
  2197. AS
  2198. $$
  2199. BEGIN
  2200. IF NEW.success IS NULL THEN
  2201. NOTIFY job_entered;
  2202. END IF;
  2203. RETURN NEW;
  2204. END;
  2205. $$ LANGUAGE PLPGSQL;
  2206. CREATE TRIGGER notify_pending_jobs BEFORE INSERT OR UPDATE ON pending_job
  2207. FOR EACH ROW EXECUTE PROCEDURE trigger_pending_job();
  2208. CREATE TABLE payments_queue (
  2209. transactions numeric[],
  2210. batch_id int,
  2211. source text,
  2212. total numeric,
  2213. ar_ap_accno text,
  2214. cash_accno text,
  2215. payment_date date,
  2216. account_class int,
  2217. job_id int references pending_job(id)
  2218. DEFAULT currval('pending_job_id_seq')
  2219. );
  2220. CREATE INDEX payments_queue_job_id ON payments_queue(job_id);
  2221. COMMENT ON table payments_queue IS
  2222. $$ This is a holding table and hence not a candidate for normalization.
  2223. Jobs should be deleted from this table when they complete successfully.$$;
  2224. commit;