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