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