

CREATE TABLE project_members (
  prj_id bigint NOT NULL,
  pe_id bigint NOT NULL,
  jcat_id bigint DEFAULT NULL,
  prjmem_added date NOT NULL DEFAULT '0000-00-00',
  prjmem_pe_id bigint NOT NULL,
  prjmem_hourlyrate decimal(12,2),
  PRIMARY KEY (prj_id, pe_id)
);

--
-- alter all autoincrement columns to be non-autoincrement
-- (handled by sequences from now on)
--

alter table billing_methods modify column bmt_id bigint not null;
alter table bills modify column bill_id bigint not null;
alter table companies modify column cpn_id bigint not null;
alter table companycat modify column ccat_id bigint not null;
alter table countries modify column ctr_id bigint not null;
alter table currencies modify column curr_id bigint not null;
alter table jobcat modify column jcat_id bigint not null;
alter table languages modify column lng_id bigint not null;
alter table operationcat modify column opcat_id bigint not null;
alter table operations modify column op_id bigint not null;
alter table personcat modify column pecat_id bigint not null;
alter table persons modify column pe_id bigint not null;
alter table projectcat modify column prjcat_id bigint not null;
alter table projects modify column prj_id bigint not null;
alter table projectstatus modify column prjstat_id bigint not null;
alter table quotations modify column quot_id bigint not null;
alter table users modify column usr_id bigint not null;

ALTER TABLE bills ADD COLUMN bill_footer VARCHAR(255) DEFAULT NULL;
ALTER TABLE quotations ADD COLUMN quot_footer VARCHAR(255) DEFAULT NULL;
ALTER TABLE project_members ADD COLUMN prjmem_hourlyrate decimal(12,2);
ALTER TABLE projects ADD COLUMN cpn_id_issuebill BIGINT DEFAULT NULL;
alter table projects add columnt prj_prj_id bigint default NULL;

CREATE TABLE config (
	cfg_id bigint(20) NOT NULL auto_increment,
	cfg_key varchar(60) NOT NULL,
	cfg_value varchar(200) NOT NULL,
	Primary Key (cfg_id)
);

CREATE TABLE userconfig (
	cfg_id bigint NOT NULL,
	usr_id bigint NOT NULL,
	cfg_value varchar(200) NOT NULL,
	Primary Key (cfg_id, usr_id)
);

CREATE TABLE config_cfg_id_seq (
  id int(10) unsigned NOT NULL auto_increment,
  PRIMARY KEY  (id)
) TYPE=MyISAM;

DELETE FROM config_cfg_id_seq;
INSERT INTO config_cfg_id_seq (id) SELECT max(cfg_id) + 1 FROM config;

CREATE TABLE expenses (
    exp_id bigint NOT NULL,
    exp_date date NOT NULL,
    pe_id bigint NOT NULL,
    prj_id bigint NOT NULL,
    exp_desc blob NOT NULL,
    exp_sum decimal(12,2) NOT NULL,
    curr_id smallint NOT NULL,
    exp_sum_foreign decimal(12,2) DEFAULT NULL,
    curr_id_foreign smallint DEFAULT NULL,
    exp_exchange_rate decimal(12,5) DEFAULT NULL,
    bill_id bigint DEFAULT NULL,
    Primary Key (exp_id)
);

CREATE TABLE expenses_exp_id_seq (
  id int(10) unsigned NOT NULL auto_increment,
  PRIMARY KEY  (id)
) TYPE=MyISAM;

DELETE FROM expenses_exp_id_seq;
INSERT INTO expenses_exp_id_seq (id) SELECT max(exp_id) + 1 FROM expenses;


INSERT INTO config (cfg_key, cfg_value) VALUES ('BILL_PDF_FOOTER', 'Payable within 30 days');
INSERT INTO config (cfg_key, cfg_value) VALUES ('BILL_PDF_HEADER', 'Invoice %s / %s');
INSERT INTO config (cfg_key, cfg_value) VALUES ('BILL_PDF_TOTALHOURS', 'Total number of hours billed: %s h between %s and %s');
INSERT INTO config (cfg_key, cfg_value) VALUES ('DATEFORMAT_LONG', '%A, %d. %B %Y');
INSERT INTO config (cfg_key, cfg_value) VALUES ('DATEFORMAT_SHORT', '%d.%m.%Y (%a)');
INSERT INTO config (cfg_key, cfg_value) VALUES ('DEFAULTBMT', '3');
INSERT INTO config (cfg_key, cfg_value) VALUES ('DEFAULTCOUNTRY', '1');
INSERT INTO config (cfg_key, cfg_value) VALUES ('DEFAULTCURRENCY', '2');
INSERT INTO config (cfg_key, cfg_value) VALUES ('DEFAULTLANGUAGE', '3');
INSERT INTO config (cfg_key, cfg_value) VALUES ('DEFAULTPHOTO', 'nofoto.jpg');
INSERT INTO config (cfg_key, cfg_value) VALUES ('DEFAULT_SKIN', 'decent');
INSERT INTO config (cfg_key, cfg_value) VALUES ('FINGRAPH_HEIGHT', '200');
INSERT INTO config (cfg_key, cfg_value) VALUES ('FINGRAPH_WIDTH', '420');
INSERT INTO config (cfg_key, cfg_value) VALUES ('GRAPHSHOWCPNNAMELENGHT', '25');
INSERT INTO config (cfg_key, cfg_value) VALUES ('GRAPH_HEIGHT', '250');
INSERT INTO config (cfg_key, cfg_value) VALUES ('GRAPH_OPCAT_ANGLE', '55');
INSERT INTO config (cfg_key, cfg_value) VALUES ('GRAPH_OPCAT_STYLE', '3');
INSERT INTO config (cfg_key, cfg_value) VALUES ('GRAPH_PDF_HEIGHT', '600');
INSERT INTO config (cfg_key, cfg_value) VALUES ('GRAPH_PDF_WIDTH', '1000');
INSERT INTO config (cfg_key, cfg_value) VALUES ('GRAPH_WIDTH', '600');
INSERT INTO config (cfg_key, cfg_value) VALUES ('IMAGETYPE', 'png');
INSERT INTO config (cfg_key, cfg_value) VALUES ('LETTERHEAD_COMPANY_CITY', 'Milano');
INSERT INTO config (cfg_key, cfg_value) VALUES ('LETTERHEAD_COMPANY_EMAIL', 'donkey@phpaga.sourceforge.net');
INSERT INTO config (cfg_key, cfg_value) VALUES ('LETTERHEAD_COMPANY_FULLLOCATION', '99099 - Milano (MI), Italy');
INSERT INTO config (cfg_key, cfg_value) VALUES ('LETTERHEAD_COMPANY_NAME', 'phpaga Enterprises');
INSERT INTO config (cfg_key, cfg_value) VALUES ('LETTERHEAD_COMPANY_PHONE', 'Tel. +39 0000 00000000');
INSERT INTO config (cfg_key, cfg_value) VALUES ('LETTERHEAD_COMPANY_STREET', 'Viale Camilleri 2002');
INSERT INTO config (cfg_key, cfg_value) VALUES ('LETTERHEAD_COMPANY_TAXNR', 'P.IVA 00110022003');
INSERT INTO config (cfg_key, cfg_value) VALUES ('LETTERHEAD_FOOTER', 'KINKY BANK di Milano, ABI 0123 - CAB 98976 - c/c 12340987');
INSERT INTO config (cfg_key, cfg_value) VALUES ('LETTERHEAD_LOGO_FILE', '/data/webs/phpaga/logos/lanthaler-it.jpg');
INSERT INTO config (cfg_key, cfg_value) VALUES ('LETTERHEAD_OWNER_PERSONALTAXNR', 'Cod. fisc. ABCZYX00A11B123Q');
INSERT INTO config (cfg_key, cfg_value) VALUES ('LOCATION_FORMAT', '%ZIP - %CITY (%REGION), %COUNTRY');
INSERT INTO config (cfg_key, cfg_value) VALUES ('MHRSGRAPH_HEIGHT', '120');
INSERT INTO config (cfg_key, cfg_value) VALUES ('MHRSGRAPH_SMALL_HEIGHT', '75');
INSERT INTO config (cfg_key, cfg_value) VALUES ('MHRSGRAPH_SMALL_WIDTH', '550');
INSERT INTO config (cfg_key, cfg_value) VALUES ('MHRSGRAPH_WIDTH', '600');
INSERT INTO config (cfg_key, cfg_value) VALUES ('MIN_LOGIN_LEN', '1');
INSERT INTO config (cfg_key, cfg_value) VALUES ('MIN_PASSWD_LEN', '2');
INSERT INTO config (cfg_key, cfg_value) VALUES ('OPDESC_OVERLIB', 'true');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PDFSHOWBILLDESCLENGHT', '80');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PDFSHOWOPDESCLENGHT', '120');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PDFSHOWQUOTATIONDESCLENGHT', '80');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PDF_BORDER_LEFT', '50');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PDF_BORDER_TOP', '50');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PDF_DOCFORMAT', 'a4');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PDF_FONT_SIZE_HEADER', '14.0');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PDF_FONT_SIZE_NORMAL', '12.0');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PDF_FONT_SIZE_SMALL', '8.0');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PDF_LOGOWIDTH', '150');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PDF_PRINT_LETTERHEAD_DEFAULT', 'true');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PENAME_FORMAT', '%LASTNAME, %FIRSTNAME');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PRHGRAPH_GANTT_COLOR_BACKGROUND', 'white');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PRHGRAPH_GANTT_COLOR_BAR', 'black');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PRHGRAPH_GANTT_COLOR_CLOSED', 'darkblue');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PRHGRAPH_GANTT_COLOR_HEADERBAR_BACKGROUND', '#14996e');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PRHGRAPH_GANTT_COLOR_HEADERBAR_DIVIDER', '#666666');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PRHGRAPH_GANTT_COLOR_HEADERBAR_TEXT', 'white');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PRHGRAPH_GANTT_COLOR_OPEN', 'darkgreen');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PRHGRAPH_GANTT_COLOR_OVERDUE', 'darkred');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PRHGRAPH_GANTT_COLOR_UNDEFINED', 'white');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PRHGRAPH_GANTT_FRAME', 'false');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PRHGRAPH_GANTT_WIDTH', '800');
INSERT INTO config (cfg_key, cfg_value) VALUES ('PRHGRAPH_GANTT_WIDTH_HEADERBAR_DIVIDER', '2');
INSERT INTO config (cfg_key, cfg_value) VALUES ('QUOTATION_PDF_FOOTER', 'Expires 30 days from issue.');
INSERT INTO config (cfg_key, cfg_value) VALUES ('QUOTATION_PDF_HEADER', 'Quotation %s / %s');
INSERT INTO config (cfg_key, cfg_value) VALUES ('SEPARATOR_DECIMALS', ',');
INSERT INTO config (cfg_key, cfg_value) VALUES ('SEPARATOR_THOUSANDS', '.');
INSERT INTO config (cfg_key, cfg_value) VALUES ('SHORTLOCATION_FORMAT', '%CITY, %REGION');
INSERT INTO config (cfg_key, cfg_value) VALUES ('SHOWBPP', '19');
INSERT INTO config (cfg_key, cfg_value) VALUES ('SHOWCPNPP', '25');
INSERT INTO config (cfg_key, cfg_value) VALUES ('SHOWLASTOPERATIONS', '8');
INSERT INTO config (cfg_key, cfg_value) VALUES ('SHOWOPDESCLENGHT', '60');
INSERT INTO config (cfg_key, cfg_value) VALUES ('SHOWOPPP', '19');
INSERT INTO config (cfg_key, cfg_value) VALUES ('SHOWPEPP', '25');
INSERT INTO config (cfg_key, cfg_value) VALUES ('SHOWPRJPP', '25');
INSERT INTO config (cfg_key, cfg_value) VALUES ('SHOWUPP', '19');
INSERT INTO config (cfg_key, cfg_value) VALUES ('TEMPLATESET', 'phpaga');
INSERT INTO config (cfg_key, cfg_value) VALUES ('OPDESC_OVERLIB_BGCOLOR', '#000000');
INSERT INTO config (cfg_key, cfg_value) VALUES ('OPDESC_OVERLIB_FGCOLOR', '#ffcc00');
INSERT INTO config (cfg_key, cfg_value) VALUES ('OPDESC_OVERLIB_TEXTCOLOR', '#000000');
INSERT INTO config (cfg_key, cfg_value) VALUES ('OPDESC_OVERLIB_TEXTFONT', 'helvetica, sans-serif');
INSERT INTO config (cfg_key, cfg_value) VALUES ('MHRSGRAPH_WEEKLY_AVG_HOURS', '40');
INSERT INTO config (cfg_key, cfg_value) VALUES ('MHRSGRAPH_WEEKLY_AVG_LINECOLOR', '#888888');

-- End of script
