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