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