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