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