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