/*==============================================================*/
/* DBMS name:      MySQL 4.11                                   */
/* Created on:     01/02/2005 3:57:28 PM                        */
/*==============================================================*/


alter table accessProfileRoles
   drop foreign key FK_accessProfile1;

alter table accessProfileRoles
   drop foreign key FK_systemModule1;

alter table company
   drop foreign key FK_serverFile1;

alter table companyData
   drop foreign key FK_company3;

alter table companyDepartment
   drop foreign key FK_company1;

alter table currencyChangeRate
   drop foreign key FK_currency3;

alter table currencyChangeRate
   drop foreign key FK_currency4;

alter table currencyChangeRate
   drop foreign key FK_employee8;

alter table employee
   drop foreign key FK_infEmployeeType;

alter table employeeAccessProfile
   drop foreign key FK_accessProfile2;

alter table employeeAccessProfile
   drop foreign key FK_employee3;

alter table employeeAccessProfile
   drop foreign key FK_project7;

alter table employeeCompany
   drop foreign key FK_company2;

alter table employeeCompany
   drop foreign key FK_companyDepartment1;

alter table employeeCompany
   drop foreign key FK_employee5;

alter table employeeData
   drop foreign key FK_employee1;

alter table employeeUser
   drop foreign key FK_employee2;

alter table paymentRequest
   drop foreign key FK_currency8;

alter table paymentRequest
   drop foreign key FK_employee13;

alter table paymentRequest
   drop foreign key FK_paymentRequestState1;

alter table paymentRequest
   drop foreign key FK_paymentType1;

alter table paymentRequest
   drop foreign key FK_project12;

alter table paymentRequest
   drop foreign key FK_provider2;

alter table paymentRequest
   drop foreign key FK_serverFile4;

alter table paymentRequestDetails
   drop foreign key FK_paymentRequest1;

alter table paymentRequestDetails
   drop foreign key FK_projectActivity4;

alter table paymentRequestDetails
   drop foreign key FK_projectParcel2;

alter table paymentRequestDetails
   drop foreign key FK_projectSubParcel1;

alter table paymentRequestDetails
   drop foreign key FK_projectTask3;

alter table paymentRequestStateHistory
   drop foreign key FK_paymentRequest2;

alter table paymentRequestStateHistory
   drop foreign key FK_paymentRequestState2;

alter table paymentRequestStateHistory
   drop foreign key Fk_employee14;

alter table project
   drop foreign key FK_currency1;

alter table project
   drop foreign key FK_serverFile2;

alter table projectActivity
   drop foreign key FK_currency5;

alter table projectActivity
   drop foreign key FK_employee9;

alter table projectActivity
   drop foreign key FK_project8;

alter table projectInfo
   drop foreign key FK_project2;

alter table projectParcel
   drop foreign key FK_currency7;

alter table projectParcel
   drop foreign key FK_employee11;

alter table projectParcel
   drop foreign key FK_project10;

alter table projectParcel
   drop foreign key FK_projectActivity2;

alter table projectParcel
   drop foreign key FK_projectTask1;

alter table projectPhoto
   drop foreign key FK_project1;

alter table projectPhoto
   drop foreign key FK_serverFile3;

alter table projectSubParcel
   drop foreign key FK_currency9;

alter table projectSubParcel
   drop foreign key FK_employee12;

alter table projectSubParcel
   drop foreign key FK_project11;

alter table projectSubParcel
   drop foreign key FK_projectActivity3;

alter table projectSubParcel
   drop foreign key FK_projectParcel1;

alter table projectSubParcel
   drop foreign key FK_projectTask2;

alter table projectTask
   drop foreign key FK_currency6;

alter table projectTask
   drop foreign key FK_employee10;

alter table projectTask
   drop foreign key FK_project9;

alter table projectTask
   drop foreign key FK_projectActivity1;

alter table projectTaskHelper
   drop foreign key FK_projectActivityHelper1;

alter table providerData
   drop foreign key FK_provider1;

alter table salesClient
   drop foreign key FK_employee6;

alter table salesClientData
   drop foreign key FK_salesClient1;

alter table salesClientData
   drop foreign key FK_salesContact2;

alter table salesClientData
   drop foreign key FK_salesContactMedia2;

alter table salesClientUnit
   drop foreign key FK_employee7;

alter table salesClientUnit
   drop foreign key FK_project13;

alter table salesClientUnit
   drop foreign key FK_salesClient2;

alter table salesClientUnit
   drop foreign key FK_salesClientState1;

alter table salesClientUnit
   drop foreign key FK_salesContact1;

alter table salesClientUnit
   drop foreign key FK_salesContactMedia1;

alter table salesClientUnit
   drop foreign key FK_salesPaymentPlan1;

alter table salesClientUnit
   drop foreign key FK_salesUnit1;

alter table salesClientUnitReject
   drop foreign key FK_salesClientUnit1;

alter table salesClientUnitReject
   drop foreign key FK_salesClinet3;

alter table salesClientUnitReject
   drop foreign key FK_salesRejectOption1;

alter table salesContact
   drop foreign key FK_project5;

alter table salesContactMedia
   drop foreign key FK_project6;

alter table salesPaymentPlan
   drop foreign key FK_project4;

alter table salesPaymentPlan
   drop foreign key FK_salesPaymentPlanType1;

alter table salesUnit
   drop foreign key FK_currency2;

alter table salesUnit
   drop foreign key FK_project3;

alter table salesUnit
   drop foreign key FK_salesUnitState1;

alter table salesUnit
   drop foreign key FK_salesUnitType1;

alter table salesUnit1
   drop foreign key FK_salesUnit2;

alter table serverFile
   drop foreign key FK_employee4;

alter table serverFile
   drop foreign key FK_serverFileType1;

drop index AP_name on accessProfile;

drop index AP_unique on accessProfile;

drop index APR_idAccessProfile on accessProfileRoles;

drop index APR_idSystemModule on accessProfileRoles;

drop index APR_roles on accessProfileRoles;

drop index APR_unique on accessProfileRoles;

drop index COMP_unique on company;

drop index COMPD_unique on companyData;

drop index COMPDEP_unique on companyDepartment;

drop index CURR_name on currency;

drop index CURCHRT_unique on currencyChangeRate;

drop index EMP_idEmployeeType on employee;

drop index EMP_unique on employee;

drop index EAP_idAccessProfile on employeeAccessProfile;

drop index EAP_idEmployee on employeeAccessProfile;

drop index EAP_unique on employeeAccessProfile;

drop index EMPLCOMP_unique on employeeCompany;

drop index ED_idEmployee on employeeData;

drop index EMPT_unique on employeeType;

drop index EU_idEmployee on employeeUser;

drop index EU_unique on employeeUser;

drop index PAYREQ_unique on paymentRequest;

drop index PAYREQDET_unique on paymentRequestDetails;

drop index PRQST_unique on paymentRequestState;

drop index paymentRequestStateHistory_unique on paymentRequestStateHistory;

drop index PRJACT_unique on projectActivity;

drop index PRJPRCL_unique on projectParcel;

drop index PRJSUBPRCL_unique on projectSubParcel;

drop index PRJTSK_unique on projectTask;

drop index PROV_unique on provider;

drop index PROVD_unique on providerData;

drop index SLS_CS_name on salesClientState;

drop index SERV_FL_idEmployee on serverFile;

drop index SERV_FL_idServerFileType on serverFile;

drop index SERV_FL_unique on serverFile;

drop index SMOD_unique on systemModule;

drop table if exists accessProfile;

drop table if exists accessProfileRoles;

drop table if exists company;

drop table if exists companyData;

drop table if exists companyDepartment;

drop table if exists currency;

drop table if exists currencyChangeRate;

drop table if exists employee;

drop table if exists employeeAccessProfile;

drop table if exists employeeCompany;

drop table if exists employeeData;

drop table if exists employeeType;

drop table if exists employeeUser;

drop table if exists paymentRequest;

drop table if exists paymentRequestDetails;

drop table if exists paymentRequestState;

drop table if exists paymentRequestStateHistory;

drop table if exists paymentType;

drop table if exists project;

drop table if exists projectActivity;

drop table if exists projectActivityHelper;

drop table if exists projectInfo;

drop table if exists projectParcel;

drop table if exists projectPhoto;

drop table if exists projectSubParcel;

drop table if exists projectTask;

drop table if exists projectTaskHelper;

drop table if exists provider;

drop table if exists providerData;

drop table if exists salesClient;

drop table if exists salesClientData;

drop table if exists salesClientState;

drop table if exists salesClientUnit;

drop table if exists salesClientUnitReject;

drop table if exists salesContact;

drop table if exists salesContactMedia;

drop table if exists salesPaymentPlan;

drop table if exists salesPaymentPlanType;

drop table if exists salesRejectOption;

drop table if exists salesUnit;

drop table if exists salesUnit1;

drop table if exists salesUnitState;

drop table if exists salesUnitType;

drop table if exists serverFile;

drop table if exists serverFileType;

drop table if exists systemModule;

/*==============================================================*/
/* Table: accessProfile                                         */
/*==============================================================*/
create table accessProfile
(
   idAccessProfile                int                            not null AUTO_INCREMENT,
   name                           varchar(255)                   not null,
   primary key (idAccessProfile)
)
type = InnoDB;

INSERT INTO accessProfile VALUES("1", "Administrador");

/*==============================================================*/
/* Index: AP_unique                                             */
/*==============================================================*/
create unique index AP_unique on accessProfile
(
   name
);

/*==============================================================*/
/* Index: AP_name                                               */
/*==============================================================*/
create index AP_name on accessProfile
(
   name,
   idAccessProfile
);

/*==============================================================*/
/* Table: accessProfileRoles                                    */
/*==============================================================*/
create table accessProfileRoles
(
   idAccessProfile                int                            not null,
   idSystemModule                 int                            not null,
   roles                          varchar(255)                   not null
)
type = InnoDB;

INSERT INTO accessProfileRoles VALUES("1", "100", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "101", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "102", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "103", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "104", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "105", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "106", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "107", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "108", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "109", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "110", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "111", "create,modify,delete,viewShort,viewFull");

INSERT INTO accessProfileRoles VALUES("1", "200", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "201", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "203", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "204", "create,modify,delete,viewShort,viewFull");

INSERT INTO accessProfileRoles VALUES("1", "300", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "301", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "302", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "303", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "304", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "305", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "306", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "310", "create,modify,delete,viewShort,viewFull");

INSERT INTO accessProfileRoles VALUES("1", "1000", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "1010", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "1020", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "1030", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "1031", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "1032", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "1040", "create,modify,delete,viewShort,viewFull");
INSERT INTO accessProfileRoles VALUES("1", "1050", "create,modify,delete,viewShort,viewFull");

/*==============================================================*/
/* Index: APR_unique                                            */
/*==============================================================*/
create unique index APR_unique on accessProfileRoles
(
   idAccessProfile,
   idSystemModule
);

/*==============================================================*/
/* Index: APR_idAccessProfile                                   */
/*==============================================================*/
create index APR_idAccessProfile on accessProfileRoles
(
   idAccessProfile
);

/*==============================================================*/
/* Index: APR_idSystemModule                                    */
/*==============================================================*/
create index APR_idSystemModule on accessProfileRoles
(
   idSystemModule
);

/*==============================================================*/
/* Index: APR_roles                                             */
/*==============================================================*/
create index APR_roles on accessProfileRoles
(
   roles
);

/*==============================================================*/
/* Table: company                                               */
/*==============================================================*/
create table company
(
   idCompany                      int                            not null AUTO_INCREMENT,
   idServerFile                   int,
   name                           varchar(255)                   not null,
   primary key (idCompany)
)
type = InnoDB;

/*==============================================================*/
/* Index: COMP_unique                                           */
/*==============================================================*/
create unique index COMP_unique on company
(
   name
);

/*==============================================================*/
/* Table: companyData                                           */
/*==============================================================*/
create table companyData
(
   idCompany                      int                            not null,
   documentNumber                 varchar(255),
   address                        varchar(255),
   address1                       varchar(255),
   address2                       varchar(255),
   city                           varchar(255),
   state                          varchar(255),
   postalCode                     varchar(255),
   phone1                         varchar(255),
   phone2                         varchar(255),
   phone3                         varchar(255),
   email                          varchar(255)
)
type = InnoDB;

/*==============================================================*/
/* Index: COMPD_unique                                          */
/*==============================================================*/
create unique index COMPD_unique on companyData
(
   idCompany
);

/*==============================================================*/
/* Table: companyDepartment                                     */
/*==============================================================*/
create table companyDepartment
(
   idCompanyDepartment            int                            not null AUTO_INCREMENT,
   idCompany                      int                            not null,
   name                           varchar(255)                   not null,
   primary key (idCompanyDepartment)
)
type = InnoDB;

/*==============================================================*/
/* Index: COMPDEP_unique                                        */
/*==============================================================*/
create unique index COMPDEP_unique on companyDepartment
(
   name,
   idCompany
);

/*==============================================================*/
/* Table: currency                                              */
/*==============================================================*/
create table currency
(
   idCurrency                     int                            not null AUTO_INCREMENT,
   name                           varchar(64)                    not null,
   primary key (idCurrency)
)
type = InnoDB;


/*!40000 ALTER TABLE `currency` DISABLE KEYS */;
LOCK TABLES `currency` WRITE;
INSERT INTO `currency` VALUES (1,'Pesos'),(3,'UDI'),(2,'USD');
UNLOCK TABLES;
/*!40000 ALTER TABLE `currency` ENABLE KEYS */;

/*==============================================================*/
/* Index: CURR_name                                             */
/*==============================================================*/
create index CURR_name on currency
(
   name,
   idCurrency
);

/*==============================================================*/
/* Table: currencyChangeRate                                    */
/*==============================================================*/
create table currencyChangeRate
(
   idCurrencyFrom                 int                            not null,
   idCurrencyTo                   int                            not null,
   idEmployee                     int,
   value                          double                         not null,
   dateRegistration               datetime                       not null
)
type = InnoDB;

/*==============================================================*/
/* Index: CURCHRT_unique                                        */
/*==============================================================*/
create unique index CURCHRT_unique on currencyChangeRate
(
   idCurrencyFrom,
   idCurrencyTo,
   dateRegistration
);

/*==============================================================*/
/* Table: employee                                              */
/*==============================================================*/
create table employee
(
   idEmployee                     int                            not null AUTO_INCREMENT,
   idEmployeeType                 int                            not null,
   nameFirst                      varchar(255)                   not null,
   nameFirst1                     varchar(255)                   not null,
   nameLast                       varchar(255)                   not null,
   nameLast1                      varchar(255)                   not null,
   documentNumber                 varchar(255)                   not null,
   dateRegistered                 date                           not null,
   dateBirthday                   date,
   primary key (idEmployee)
)
type = InnoDB;

INSERT INTO employee VALUES("1", "1", "Admin", "", "Admin", "", "YAVI771214FM9",now(),"1980/05/10");

/*==============================================================*/
/* Index: EMP_unique                                            */
/*==============================================================*/
create unique index EMP_unique on employee
(
   documentNumber
);

/*==============================================================*/
/* Index: EMP_idEmployeeType                                    */
/*==============================================================*/
create index EMP_idEmployeeType on employee
(
   idEmployeeType
);

/*==============================================================*/
/* Table: employeeAccessProfile                                 */
/*==============================================================*/
create table employeeAccessProfile
(
   idEmployee                     int                            not null,
   idAccessProfile                int                            not null,
   idProject                      int
)
type = InnoDB;

INSERT INTO employeeAccessProfile VALUES("1", "1", NULL);

/*==============================================================*/
/* Index: EAP_unique                                            */
/*==============================================================*/
create unique index EAP_unique on employeeAccessProfile
(
   idEmployee,
   idAccessProfile,
   idProject
);

/*==============================================================*/
/* Index: EAP_idEmployee                                        */
/*==============================================================*/
create index EAP_idEmployee on employeeAccessProfile
(
   idEmployee
);

/*==============================================================*/
/* Index: EAP_idAccessProfile                                   */
/*==============================================================*/
create index EAP_idAccessProfile on employeeAccessProfile
(
   idAccessProfile
);

/*==============================================================*/
/* Table: employeeCompany                                       */
/*==============================================================*/
create table employeeCompany
(
   idEmployee                     int                            not null,
   idCompany                      int                            not null,
   idCompanyDepartment            int                            not null
)
type = InnoDB;

/*==============================================================*/
/* Index: EMPLCOMP_unique                                       */
/*==============================================================*/
create unique index EMPLCOMP_unique on employeeCompany
(
   idEmployee
);

/*==============================================================*/
/* Table: employeeData                                          */
/*==============================================================*/
create table employeeData
(
   idEmployee                     int                            not null,
   address                        varchar(255)                   not null,
   address1                       varchar(255)                   not null,
   address2                       varchar(255)                   not null,
   city                           varchar(255)                   not null,
   state                          varchar(255)                   not null,
   postalCode                     varchar(255)                   not null,
   phone1                         varchar(255)                   not null,
   phone2                         varchar(255)                   not null,
   phone3                         varchar(255)                   not null,
   email                          varchar(255)                   not null
)
type = InnoDB;

/*==============================================================*/
/* Index: ED_idEmployee                                         */
/*==============================================================*/
create unique index ED_idEmployee on employeeData
(
   idEmployee
);

/*==============================================================*/
/* Table: employeeType                                          */
/*==============================================================*/
create table employeeType
(
   idEmployeeType                 int                            not null AUTO_INCREMENT,
   name                           varchar(255)                   not null,
   primary key (idEmployeeType)
)
type = InnoDB;

INSERT INTO employeeType (idEmployeeType, name) VALUES (1, 'Interno');
INSERT INTO employeeType (idEmployeeType, name) VALUES (2, 'Externo');
/*==============================================================*/
/* Index: EMPT_unique                                           */
/*==============================================================*/
create unique index EMPT_unique on employeeType
(
   name
);

/*==============================================================*/
/* Table: employeeUser                                          */
/*==============================================================*/
create table employeeUser
(
   idEmployee                     int                            not null,
   username                       varchar(255)                   not null,
   password                       varchar(255)                   not null,
   roles                          varchar(255)                   not null
)
type = InnoDB;

INSERT INTO employeeUser VALUES("1", "admin", "admin", "");


/*==============================================================*/
/* Index: EU_unique                                             */
/*==============================================================*/
create unique index EU_unique on employeeUser
(
   username
);

/*==============================================================*/
/* Index: EU_idEmployee                                         */
/*==============================================================*/
create unique index EU_idEmployee on employeeUser
(
   idEmployee
);

/*==============================================================*/
/* Table: paymentRequest                                        */
/*==============================================================*/
create table paymentRequest
(
   idPaymentRequest               int                            not null AUTO_INCREMENT,
   idPaymentRequestState          int                            not null,
   idEmployee                     int,
   idProject                      int                            not null,
   idProvider                     int                            not null,
   idServerFile                   int,
   idPaymentType                  int,
   idCurrency                     int,
   dateRegistered                 datetime                       not null,
   billNumber                     varchar(255)                   not null,
   billConcept                    varchar(255)                   not null,
   billDate                       date,
   amountNoTax                    double                         not null,
   amountTaxToPay                 double                         not null,
   amountTaxToHold                double                         not null,
   amount                         double                         not null,
   paymentTypeInfo                text,
   comment                        text,
   primary key (idPaymentRequest)
)
type = InnoDB;

/*==============================================================*/
/* Index: PAYREQ_unique                                         */
/*==============================================================*/
create unique index PAYREQ_unique on paymentRequest
(
   idProject,
   idProvider,
   billNumber,
   billConcept
);

/*==============================================================*/
/* Table: paymentRequestDetails                                 */
/*==============================================================*/
create table paymentRequestDetails
(
   idPaymentRequestDetails        int                            not null AUTO_INCREMENT,
   idPaymentRequest               int                            not null,
   idProjectActivity              int,
   idProjectTask                  int,
   idProjectParcel                int,
   idProjectSubParcel             int,
   amount                         double                         not null,
   primary key (idPaymentRequestDetails)
)
type = InnoDB;

/*==============================================================*/
/* Index: PAYREQDET_unique                                      */
/*==============================================================*/
create unique index PAYREQDET_unique on paymentRequestDetails
(
   idPaymentRequest,
   idProjectActivity,
   idProjectTask,
   idProjectParcel,
   idProjectSubParcel
);

/*==============================================================*/
/* Table: paymentRequestState                                   */
/*==============================================================*/
create table paymentRequestState
(
   idPaymentRequestState          int                            not null AUTO_INCREMENT,
   name                           varchar(255)                   not null,
   primary key (idPaymentRequestState)
)
type = InnoDB;

insert into paymentRequestState values (0,"Creado");

/*==============================================================*/
/* Index: PRQST_unique                                          */
/*==============================================================*/
create unique index PRQST_unique on paymentRequestState
(
   name
);

/*==============================================================*/
/* Table: paymentRequestStateHistory                            */
/*==============================================================*/
create table paymentRequestStateHistory
(
   idPaymentRequestSatetHistory   int                            not null AUTO_INCREMENT,
   idPaymentRequest               int                            not null,
   idPaymentRequestState          int                            not null,
   idEmployee                     int,
   dateRegistered                 datetime                       not null,
   comment                        blob                           not null,
   primary key (idPaymentRequestSatetHistory)
);

/*==============================================================*/
/* Index: paymentRequestStateHistory_unique                     */
/*==============================================================*/
create unique index paymentRequestStateHistory_unique on paymentRequestStateHistory
(
   idPaymentRequest,
   idPaymentRequestState
);

/*==============================================================*/
/* Table: paymentType                                           */
/*==============================================================*/
create table paymentType
(
   idPaymentType                  int                            not null AUTO_INCREMENT,
   name                           varchar(255)                   not null,
   primary key (idPaymentType)
)
type = InnoDB;

insert into paymentType values (1,"Cheque");
insert into paymentType values (2,"Transferencia bancaria");
insert into paymentType values (3,"Efectivo");
/*==============================================================*/
/* Table: project                                               */
/*==============================================================*/
create table project
(
   idProject                      int                            not null AUTO_INCREMENT,
   idServerFile                   int,
   idCurrency                     int,
   name                           varchar(255)                   not null,
   primary key (idProject)
)
type = InnoDB;

/*==============================================================*/
/* Table: projectActivity                                       */
/*==============================================================*/
create table projectActivity
(
   idProjectActivity              int                            not null AUTO_INCREMENT,
   idParent                       int,
   idProject                      int                            not null,
   idCurrency                     int,
   idEmployee                     int,
   name                           varchar(255)                   not null,
   amountAuthorized               double                         not null,
   amountUsed                     double                         not null,
   dateStart                      date,
   dateEnd                        date,
   dateEndReal                    date,
   primary key (idProjectActivity)
)
type = InnoDB;

/*==============================================================*/
/* Index: PRJACT_unique                                         */
/*==============================================================*/
create unique index PRJACT_unique on projectActivity
(
   idProject,
   name
);

/*==============================================================*/
/* Table: projectActivityHelper                                 */
/*==============================================================*/
create table projectActivityHelper
(
   idProjectActivity              int                            not null AUTO_INCREMENT,
   name                           varchar(255)                   not null,
   primary key (idProjectActivity)
)
type = InnoDB;

#
# Dumping data for table 'projectActivityHelper'
#

INSERT INTO projectActivityHelper VALUES("1", "01. Terreno");
INSERT INTO projectActivityHelper VALUES("2", "02. Estructuración");
INSERT INTO projectActivityHelper VALUES("3", "03. Licencias / Legales");
INSERT INTO projectActivityHelper VALUES("4", "04. Comision Venta");
INSERT INTO projectActivityHelper VALUES("5", "05. Gerencia de Proyecto");
INSERT INTO projectActivityHelper VALUES("6", "06. Proyecto Ejecutivo");
INSERT INTO projectActivityHelper VALUES("7", "07. Construcción");
INSERT INTO projectActivityHelper VALUES("8", "08. Supervisión");
INSERT INTO projectActivityHelper VALUES("9", "09. Credito Puente");
INSERT INTO projectActivityHelper VALUES("10", "10. Estudios / SP Luz / Factibilidad");
INSERT INTO projectActivityHelper VALUES("11", "11. Otros");

/*==============================================================*/
/* Table: projectInfo                                           */
/*==============================================================*/
create table projectInfo
(
   idProject                      int                            not null,
   phrase                         varchar(255)                   not null,
   address                        text                           not null,
   siteURL                        varchar(255)                   not null,
   arquitect                      varchar(255)                   not null,
   descriptionUnits               text                           not null,
   descriptionGeneral             text                           not null,
   descriptionAccessory           text                           not null,
   descriptionAttributes          text                           not null,
   descriptionAdditional          text                           not null,
   dateStart                      date                           not null,
   dateEnd                        date                           not null
)
type = InnoDB;

/*==============================================================*/
/* Table: projectParcel                                         */
/*==============================================================*/
create table projectParcel
(
   idProjectParcel                int                            not null AUTO_INCREMENT,
   idParent                       int,
   idProjectTask                  int                            not null,
   idProjectActivity              int                            not null,
   idProject                      int                            not null,
   idCurrency                     int,
   idEmployee                     int,
   name                           varchar(255)                   not null,
   amountAuthorized               double                         not null,
   amountUsed                     double                         not null,
   dateStart                      date,
   dateEnd                        date,
   dateEndReal                    date,
   primary key (idProjectParcel)
)
type = InnoDB;

/*==============================================================*/
/* Index: PRJPRCL_unique                                        */
/*==============================================================*/
create unique index PRJPRCL_unique on projectParcel
(
   idProjectTask,
   name
);

/*==============================================================*/
/* Table: projectPhoto                                          */
/*==============================================================*/
create table projectPhoto
(
   idProjectPhoto                 int                            not null AUTO_INCREMENT,
   idProject                      int                            not null,
   idServerFile                   int                            not null,
   primary key (idProjectPhoto)
)
type = InnoDB;

/*==============================================================*/
/* Table: projectSubParcel                                      */
/*==============================================================*/
create table projectSubParcel
(
   idProjectSubParcel             int                            not null AUTO_INCREMENT,
   idParent                       int,
   idProjectParcel                int                            not null,
   idProjectTask                  int                            not null,
   idProjectActivity              int                            not null,
   idProject                      int                            not null,
   idCurrency                     int,
   idEmployee                     int,
   name                           varchar(255)                   not null,
   amountAuthorized               double                         not null,
   amountUsed                     double                         not null,
   dateStart                      date,
   dateEnd                        date,
   dateEndReal                    date,
   primary key (idProjectSubParcel)
)
type = InnoDB;

/*==============================================================*/
/* Index: PRJSUBPRCL_unique                                     */
/*==============================================================*/
create unique index PRJSUBPRCL_unique on projectSubParcel
(
   idProjectParcel,
   name
);

/*==============================================================*/
/* Table: projectTask                                           */
/*==============================================================*/
create table projectTask
(
   idProjectTask                  int                            not null AUTO_INCREMENT,
   idParent                       int,
   idProjectActivity              int                            not null,
   idProject                      int                            not null,
   idCurrency                     int,
   idEmployee                     int,
   name                           varchar(255)                   not null,
   amountAuthorized               double                         not null,
   amountUsed                     double                         not null,
   dateStart                      date,
   dateEnd                        date,
   dateEndReal                    date,
   primary key (idProjectTask)
)
type = InnoDB;

/*==============================================================*/
/* Index: PRJTSK_unique                                         */
/*==============================================================*/
create unique index PRJTSK_unique on projectTask
(
   idProjectActivity,
   name
);

/*==============================================================*/
/* Table: projectTaskHelper                                     */
/*==============================================================*/
create table projectTaskHelper
(
   idProjectTask                  int                            not null AUTO_INCREMENT,
   idProjectActivity              int                            not null,
   name                           varchar(255)                   not null,
   primary key (idProjectTask)
)
type = InnoDB;

#
# Dumping data for table 'projectTaskHelper'
#

INSERT INTO projectTaskHelper VALUES("1", "1", "01-A. Factibilidad / Normatividad");
INSERT INTO projectTaskHelper VALUES("2", "1", "01-B. Revisión fiscal");
INSERT INTO projectTaskHelper VALUES("3", "1", "01-C. Revisión financiera");
INSERT INTO projectTaskHelper VALUES("4", "1", "01-D. Revisión legal");
INSERT INTO projectTaskHelper VALUES("5", "1", "01-E. Compra");
INSERT INTO projectTaskHelper VALUES("6", "2", "02-A. Pago derechos hacienda");
INSERT INTO projectTaskHelper VALUES("7", "2", "02-B. Pago notario");
INSERT INTO projectTaskHelper VALUES("8", "2", "02-C. Pago escritura");
INSERT INTO projectTaskHelper VALUES("9", "2", "02-D. Pago comisión vendedor");
INSERT INTO projectTaskHelper VALUES("10", "3", "03-A. Pago derechos");
INSERT INTO projectTaskHelper VALUES("11", "3", "03-B. Gestoría");
INSERT INTO projectTaskHelper VALUES("12", "3", "03-C. Factibilidad");
INSERT INTO projectTaskHelper VALUES("13", "3", "03-D. Regimen Condominio");
INSERT INTO projectTaskHelper VALUES("14", "3", "03-E. Asesoria Fiscal / Legal");
INSERT INTO projectTaskHelper VALUES("15", "4", "04-A. Comisiones");
INSERT INTO projectTaskHelper VALUES("16", "4", "04-B. Gastos indirectos ventas");
INSERT INTO projectTaskHelper VALUES("17", "4", "04-C. Promoción / Publicidad");
INSERT INTO projectTaskHelper VALUES("18", "5", "05-A. Crédito / Cobranza");
INSERT INTO projectTaskHelper VALUES("19", "5", "05-B. Ventas");
INSERT INTO projectTaskHelper VALUES("20", "5", "05-C. Asignación indirectos");
INSERT INTO projectTaskHelper VALUES("21", "6", "06-A. Anteproyecto");
INSERT INTO projectTaskHelper VALUES("22", "6", "06-B. Proyecto arquitectónico");
INSERT INTO projectTaskHelper VALUES("23", "6", "06-C. Ingenierias");
INSERT INTO projectTaskHelper VALUES("24", "6", "06-D. Especificaciones y detalles");
INSERT INTO projectTaskHelper VALUES("25", "7", "07-A. Demolición");
INSERT INTO projectTaskHelper VALUES("26", "7", "07-B. Subcontratista");
INSERT INTO projectTaskHelper VALUES("27", "7", "07-C. Administración obra");
INSERT INTO projectTaskHelper VALUES("28", "8", "08-A. Catalogo conceptos");
INSERT INTO projectTaskHelper VALUES("29", "8", "08-B. Supervisión");
INSERT INTO projectTaskHelper VALUES("30", "10", "10-A. Estudio ambiental");
INSERT INTO projectTaskHelper VALUES("31", "10", "10-B. SP luz");
INSERT INTO projectTaskHelper VALUES("32", "10", "10-C. Otros");

/*==============================================================*/
/* Table: provider                                              */
/*==============================================================*/
create table provider
(
   idProvider                     int                            not null AUTO_INCREMENT,
   name                           varchar(255)                   not null,
   primary key (idProvider)
)
type = InnoDB;

/*==============================================================*/
/* Index: PROV_unique                                           */
/*==============================================================*/
create unique index PROV_unique on provider
(
   name
);

/*==============================================================*/
/* Table: providerData                                          */
/*==============================================================*/
create table providerData
(
   idProvider                     int                            not null,
   documentNumber                 varchar(255),
   address                        varchar(255),
   address1                       varchar(255),
   address2                       varchar(255),
   city                           varchar(255),
   state                          varchar(255),
   postalCode                     varchar(255),
   phone1                         varchar(255),
   phone2                         varchar(255),
   phone3                         varchar(255),
   email                          varchar(255)
)
type = InnoDB;

/*==============================================================*/
/* Index: PROVD_unique                                          */
/*==============================================================*/
create unique index PROVD_unique on providerData
(
   idProvider
);

/*==============================================================*/
/* Table: salesClient                                           */
/*==============================================================*/
create table salesClient
(
   idSalesClient                  int                            not null AUTO_INCREMENT,
   idEmployee                     int                            not null,
   dateRegistration               datetime                       not null,
   nameFirst                      varchar(255)                   not null,
   nameFirst1                     varchar(255)                   not null,
   nameLast                       varchar(255)                   not null,
   nameLast1                      varchar(255)                   not null,
   documentNumber                 varchar(255)                   not null,
   primary key (idSalesClient)
)
type = InnoDB;

/*==============================================================*/
/* Table: salesClientData                                       */
/*==============================================================*/
create table salesClientData
(
   idSalesClient                  int                            not null,
   idSalesContactMedia            int,
   idSalesContact                 int,
   address                        varchar(255)                   not null,
   address1                       varchar(255)                   not null,
   address2                       varchar(255)                   not null,
   city                           varchar(255)                   not null,
   state                          varchar(255)                   not null,
   postalCode                     varchar(255)                   not null,
   phone1                         varchar(255)                   not null,
   phone2                         varchar(255)                   not null,
   phone3                         varchar(255)                   not null,
   email                          varchar(255)                   not null
)
type = InnoDB;

/*==============================================================*/
/* Table: salesClientState                                      */
/*==============================================================*/
create table salesClientState
(
   idSalesClientState             int                            not null AUTO_INCREMENT,
   name                           varchar(64)                    not null,
   primary key (idSalesClientState)
)
type = InnoDB;

/*!40000 ALTER TABLE `salesClientState` DISABLE KEYS */;
LOCK TABLES `salesClientState` WRITE;
INSERT INTO salesClientState VALUES("10", "Pendiente");
INSERT INTO salesClientState VALUES("20", "Apartado");
INSERT INTO salesClientState VALUES("30", "Cliente");
INSERT INTO salesClientState VALUES("40", "Escriturado");
INSERT INTO salesClientState VALUES("999", "Rechazo");
INSERT INTO salesClientState VALUES("1000", "Prospecto vencido");
UNLOCK TABLES;
/*!40000 ALTER TABLE `salesClientState` ENABLE KEYS */;

/*==============================================================*/
/* Index: SLS_CS_name                                           */
/*==============================================================*/
create index SLS_CS_name on salesClientState
(
   name,
   idSalesClientState
);

/*==============================================================*/
/* Table: salesClientUnit                                       */
/*==============================================================*/
create table salesClientUnit
(
   idSalesClientUnit              int                            not null AUTO_INCREMENT,
   idSalesClient                  int                            not null,
   idSalesUnit                    int                            not null,
   idEmployee                     int                            not null,
   idSalesPaymentPlan             int,
   idSalesClientState             int                            not null,
   idSalesContact                 int,
   idSalesContactMedia            int,
   idProject                      int,
   dateRegistration               datetime                       not null,
   sellPrice                      double                         not null,
   primary key (idSalesClientUnit)
)
type = InnoDB;

/*==============================================================*/
/* Table: salesClientUnitReject                                 */
/*==============================================================*/
create table salesClientUnitReject
(
   idSalesClientUnitReject        int                            not null AUTO_INCREMENT,
   idSalesClient                  int                            not null,
   idSalesClientUnit              int                            not null,
   idSalesRejectOption            int                            not null,
   date_created                   datetime                       not null,
   description                    text                           not null,
   primary key (idSalesClientUnitReject)
)
type = InnoDB;

/*==============================================================*/
/* Table: salesContact                                          */
/*==============================================================*/
create table salesContact
(
   idSalesContact                 int                            not null AUTO_INCREMENT,
   idProject                      int,
   name                           varchar(255)                   not null,
   primary key (idSalesContact)
)
type = InnoDB;

/*==============================================================*/
/* Table: salesContactMedia                                     */
/*==============================================================*/
create table salesContactMedia
(
   idSalesContactMedia            int                            not null AUTO_INCREMENT,
   idProject                      int,
   name                           varchar(255)                   not null,
   primary key (idSalesContactMedia)
)
type = InnoDB;

/*==============================================================*/
/* Table: salesPaymentPlan                                      */
/*==============================================================*/
create table salesPaymentPlan
(
   idSalesPaymentPlan             int                            not null AUTO_INCREMENT,
   idSalesPaymentPlanType         int                            not null,
   idProject                      int                            not null,
   name                           varchar(255)                   not null,
   description                    text                           not null,
   primary key (idSalesPaymentPlan)
)
type = InnoDB;

/*==============================================================*/
/* Table: salesPaymentPlanType                                  */
/*==============================================================*/
create table salesPaymentPlanType
(
   idSalesPaymentPlanType         int                            not null AUTO_INCREMENT,
   name                           varchar(255)                   not null,
   primary key (idSalesPaymentPlanType)
)
type = InnoDB;

insert into salesPaymentPlanType values 
(1,"Contado"),
(2,"Financiamiento"),
(3,"Credito Hipotecario");

/*==============================================================*/
/* Table: salesRejectOption                                     */
/*==============================================================*/
create table salesRejectOption
(
   idSalesRejectOption            int                            not null AUTO_INCREMENT,
   name                           varchar(255)                   not null,
   primary key (idSalesRejectOption)
)
type = InnoDB;

/*!40000 ALTER TABLE `salesRejectOption` DISABLE KEYS */;
LOCK TABLES `salesRejectOption` WRITE;
INSERT INTO `salesRejectOption` VALUES 
(1,'Precio'),
(2,'Ingresos'),
(3,'Ubicacion'),
(4,'Credito rechazado'),
(5,'Preferencia estatica'),
(6,'Fecha de entrega'),
(7,'Dimensiones'),
(8,'Areas comunes'),
(9,'Acabados'),
(10,'Otros');
UNLOCK TABLES;
/*!40000 ALTER TABLE `salesRejectOption` ENABLE KEYS */;

/*==============================================================*/
/* Table: salesUnit                                             */
/*==============================================================*/
create table salesUnit
(
   idSalesUnit                    int                            not null AUTO_INCREMENT,
   idProject                      int                            not null,
   idSalesUnitType                int                            not null,
   idSalesUnitState               int                            not null,
   idCurrency                     int                            not null,
   number                         varchar(255)                   not null,
   measureUnit                    varchar(255)                   not null,
   quantity                       double                         not null,
   priceUnitary                   double                         not null,
   price                          double                         not null,
   primary key (idSalesUnit)
)
type = InnoDB;

/*==============================================================*/
/* Table: salesUnit1                                            */
/*==============================================================*/
create table salesUnit1
(
   idSalesUnit                    int                            not null,
   floor                          varchar(255),
   rooms                          varchar(255),
   bathRooms                      varchar(255),
   studio                         varchar(255),
   primary key (idSalesUnit)
)
type = InnoDB;

/*==============================================================*/
/* Table: salesUnitState                                        */
/*==============================================================*/
create table salesUnitState
(
   idSalesUnitState               int                            not null AUTO_INCREMENT,
   name                           varchar(255)                   not null,
   primary key (idSalesUnitState)
)
type = InnoDB;

/*!40000 ALTER TABLE `salesUnitState` DISABLE KEYS */;
LOCK TABLES `salesUnitState` WRITE;
INSERT INTO `salesUnitState` VALUES 
(1,'Disponible'),
(2,'Disponible con interesados'),
(3,'Bloqueado'),
(4,'Apartado'),
(5,'Vendido');
UNLOCK TABLES;
/*!40000 ALTER TABLE `salesUnitState` ENABLE KEYS */;

/*==============================================================*/
/* Table: salesUnitType                                         */
/*==============================================================*/
create table salesUnitType
(
   idSalesUnitType                int                            not null AUTO_INCREMENT,
   name                           varchar(255)                   not null,
   primary key (idSalesUnitType)
)
type = InnoDB;

/*!40000 ALTER TABLE `salesUnitType` DISABLE KEYS */;
LOCK TABLES `salesUnitType` WRITE;
INSERT INTO `salesUnitType` VALUES (1,'Unidad%20Estandar');
UNLOCK TABLES;
/*!40000 ALTER TABLE `salesUnitType` ENABLE KEYS */;
/*==============================================================*/
/* Table: serverFile                                            */
/*==============================================================*/
create table serverFile
(
   idServerFile                   int                            not null AUTO_INCREMENT,
   idServerFileType               int                            not null,
   idEmployee                     int,
   dateCreated                    datetime                       not null,
   displayName                    varchar(255)                   not null,
   clientFileName                 varchar(255)                   not null,
   contentType                    varchar(64)                    not null,
   fileSize                       int                            not null,
   serverFileName                 varchar(255)                   not null,
   primary key (idServerFile)
)
type = InnoDB;

/*==============================================================*/
/* Index: SERV_FL_unique                                        */
/*==============================================================*/
create unique index SERV_FL_unique on serverFile
(
   idServerFileType,
   displayName
);

/*==============================================================*/
/* Index: SERV_FL_idServerFileType                              */
/*==============================================================*/
create index SERV_FL_idServerFileType on serverFile
(
   idServerFileType
);

/*==============================================================*/
/* Index: SERV_FL_idEmployee                                    */
/*==============================================================*/
create index SERV_FL_idEmployee on serverFile
(
   idEmployee
);

/*==============================================================*/
/* Table: serverFileType                                        */
/*==============================================================*/
create table serverFileType
(
   idServerFileType               int                            not null AUTO_INCREMENT,
   name                           varchar(255)                   not null,
   primary key (idServerFileType)
)
type = InnoDB;

insert into serverFileType values (1,"Logo de la empresa");
insert into serverFileType values (2,"Logo del proyecto");
insert into serverFileType values (3,"Imagen de proyecto");
insert into serverFileType values (4,"Imagen de la factura");

/*==============================================================*/
/* Table: systemModule                                          */
/*==============================================================*/
create table systemModule
(
   idSystemModule                 int                            not null AUTO_INCREMENT,
   idParent                       int                            not null default 0,
   location                       varchar(255)                   not null,
   showInMenu                     char(1)                        not null default '666666',
   displayName                    varchar(255)                   not null,
   primary key (idSystemModule)
)
type = InnoDB;

INSERT INTO systemModule VALUES("100", "0", "sales", "Y", "Ventas");
INSERT INTO systemModule VALUES("101", "100", "sales/salesClient", "Y", "Prospectos/Clientes");
INSERT INTO systemModule VALUES("102", "100", "sales/salesUnit", "Y", "Unidades");
INSERT INTO systemModule VALUES("103", "100", "sales/salesPaymentPlan", "Y", "Planes de pago");
INSERT INTO systemModule VALUES("104", "100", "sales/salesContact", "Y", "Contactos");
INSERT INTO systemModule VALUES("105", "100", "sales/salesContactMedia", "Y", "Medios de contacto");
INSERT INTO systemModule VALUES("106", "100", "sales/salesClientState", "Y", "Estados de cliente");
INSERT INTO systemModule VALUES("107", "100", "sales/salesUnitState", "Y", "Estdos de unidad");
INSERT INTO systemModule VALUES("108", "100", "sales/salesRejectOption", "Y", "Opciones de rechazo");
INSERT INTO systemModule VALUES("109", "100", "sales/salesPaymentPlanType", "Y", "Planes de pago");
INSERT INTO systemModule VALUES("110", "100", "sales/salesUnitType", "Y", "Tipos de las unidades");
INSERT INTO systemModule VALUES("111", "100", "sales/salesUnitType_FD", "Y", "Unit type field definition");

INSERT INTO systemModule VALUES("200", "0", "humanResources", "Y", "Recursos humanos");
INSERT INTO systemModule VALUES("201", "200", "humanResources/employee", "Y", "Empleados");
INSERT INTO systemModule VALUES("203", "200", "humanResources/company", "Y", "Empresas");
INSERT INTO systemModule VALUES("204", "200", "humanResources/companyDepartment", "Y", "Areas");

INSERT INTO systemModule VALUES("300", "0", "administration", "Y", "Administracion");
INSERT INTO systemModule VALUES("301", "300", "administration/project", "Y", "Proyectos");
INSERT INTO systemModule VALUES("302", "300", "administration/projectActivity", "Y", "Actividades");
INSERT INTO systemModule VALUES("303", "300", "administration/projectTask", "Y", "Tareas");
INSERT INTO systemModule VALUES("304", "300", "administration/projectParcel", "Y", "Partida");
INSERT INTO systemModule VALUES("305", "300", "administration/projectSubParcel", "Y", "Sub-partida");
INSERT INTO systemModule VALUES("306", "300", "administration/paymentRequest", "Y", "Requisiciones de pago");
INSERT INTO systemModule VALUES("310", "300", "administration/provider", "Y", "Provedores");

INSERT INTO systemModule VALUES("1000", "0", "configuration", "Y", "Configuracion");
INSERT INTO systemModule VALUES("1010", "1000", "configuration/accessProfile", "Y", "Perfiles de acceso");
INSERT INTO systemModule VALUES("1020", "1000", "configuration/systemModule", "Y", "Modulos de sistema");
INSERT INTO systemModule VALUES("1030", "1000", "configuration/employeeType", "Y", "Tipos de empleados");
INSERT INTO systemModule VALUES("1031", "1000", "configuration/paymentType", "Y", "Tipos de pago");
INSERT INTO systemModule VALUES("1032", "1000", "configuration/paymentRequestState", "Y", "Estados de requisicion de pago");
INSERT INTO systemModule VALUES("1040", "1000", "configuration/currency", "Y", "Monedas");
INSERT INTO systemModule VALUES("1050", "1000", "configuration/currencyChangeRate", "Y", "Valores de cambio");

/*==============================================================*/
/* Index: SMOD_unique                                           */
/*==============================================================*/
create unique index SMOD_unique on systemModule
(
   idParent,
   location
);

alter table accessProfileRoles
   add constraint FK_accessProfile1 foreign key (idAccessProfile)
      references accessProfile (idAccessProfile)
      on delete cascade
      on update cascade;

alter table accessProfileRoles
   add constraint FK_systemModule1 foreign key (idSystemModule)
      references systemModule (idSystemModule)
      on delete cascade
      on update cascade;

alter table company
   add constraint FK_serverFile1 foreign key (idServerFile)
      references serverFile (idServerFile)
      on delete set null
      on update cascade;

alter table companyData
   add constraint FK_company3 foreign key (idCompany)
      references company (idCompany)
      on delete cascade
      on update cascade;

alter table companyDepartment
   add constraint FK_company1 foreign key (idCompany)
      references company (idCompany)
      on delete cascade
      on update cascade;

alter table currencyChangeRate
   add constraint FK_currency3 foreign key (idCurrencyFrom)
      references currency (idCurrency)
      on delete cascade
      on update cascade;

alter table currencyChangeRate
   add constraint FK_currency4 foreign key (idCurrencyTo)
      references currency (idCurrency)
      on delete cascade
      on update cascade;

alter table currencyChangeRate
   add constraint FK_employee8 foreign key (idEmployee)
      references employee (idEmployee)
      on delete set null
      on update cascade;

alter table employee
   add constraint FK_infEmployeeType foreign key (idEmployeeType)
      references employeeType (idEmployeeType)
      on delete restrict
      on update restrict;

alter table employeeAccessProfile
   add constraint FK_accessProfile2 foreign key (idAccessProfile)
      references accessProfile (idAccessProfile)
      on delete cascade
      on update cascade;

alter table employeeAccessProfile
   add constraint FK_employee3 foreign key (idEmployee)
      references employee (idEmployee)
      on delete cascade
      on update cascade;

alter table employeeAccessProfile
   add constraint FK_project7 foreign key (idProject)
      references project (idProject)
      on delete set null
      on update restrict;

alter table employeeCompany
   add constraint FK_company2 foreign key (idCompany)
      references company (idCompany)
      on delete cascade
      on update cascade;

alter table employeeCompany
   add constraint FK_companyDepartment1 foreign key (idCompanyDepartment)
      references companyDepartment (idCompanyDepartment)
      on delete cascade
      on update cascade;

alter table employeeCompany
   add constraint FK_employee5 foreign key (idEmployee)
      references employee (idEmployee)
      on delete cascade
      on update cascade;

alter table employeeData
   add constraint FK_employee1 foreign key (idEmployee)
      references employee (idEmployee)
      on delete cascade
      on update cascade;

alter table employeeUser
   add constraint FK_employee2 foreign key (idEmployee)
      references employee (idEmployee)
      on delete cascade
      on update cascade;

alter table paymentRequest
   add constraint FK_currency8 foreign key (idCurrency)
      references currency (idCurrency)
      on delete set null
      on update cascade;

alter table paymentRequest
   add constraint FK_employee13 foreign key (idEmployee)
      references employee (idEmployee)
      on delete set null
      on update cascade;

alter table paymentRequest
   add constraint FK_paymentRequestState1 foreign key (idPaymentRequestState)
      references paymentRequestState (idPaymentRequestState)
      on delete cascade
      on update cascade;

alter table paymentRequest
   add constraint FK_paymentType1 foreign key (idPaymentType)
      references paymentType (idPaymentType)
      on delete set null
      on update cascade;

alter table paymentRequest
   add constraint FK_project12 foreign key (idProject)
      references project (idProject)
      on delete cascade
      on update cascade;

alter table paymentRequest
   add constraint FK_provider2 foreign key (idProvider)
      references provider (idProvider)
      on delete restrict
      on update cascade;

alter table paymentRequest
   add constraint FK_serverFile4 foreign key (idServerFile)
      references serverFile (idServerFile)
      on delete set null
      on update cascade;

alter table paymentRequestDetails
   add constraint FK_paymentRequest1 foreign key (idPaymentRequest)
      references paymentRequest (idPaymentRequest)
      on delete cascade
      on update cascade;

alter table paymentRequestDetails
   add constraint FK_projectActivity4 foreign key (idProjectActivity)
      references projectActivity (idProjectActivity)
      on delete set null
      on update cascade;

alter table paymentRequestDetails
   add constraint FK_projectParcel2 foreign key (idProjectParcel)
      references projectParcel (idProjectParcel)
      on delete set null
      on update cascade;

alter table paymentRequestDetails
   add constraint FK_projectSubParcel1 foreign key (idProjectSubParcel)
      references projectSubParcel (idProjectSubParcel)
      on delete set null
      on update cascade;

alter table paymentRequestDetails
   add constraint FK_projectTask3 foreign key (idProjectTask)
      references projectTask (idProjectTask)
      on delete set null
      on update cascade;

alter table paymentRequestStateHistory
   add constraint FK_paymentRequest2 foreign key (idPaymentRequest)
      references paymentRequest (idPaymentRequest)
      on delete cascade
      on update cascade;

alter table paymentRequestStateHistory
   add constraint FK_paymentRequestState2 foreign key (idPaymentRequestState)
      references paymentRequestState (idPaymentRequestState)
      on delete cascade
      on update cascade;

alter table paymentRequestStateHistory
   add constraint Fk_employee14 foreign key (idEmployee)
      references employee (idEmployee)
      on delete set null
      on update cascade;

alter table project
   add constraint FK_currency1 foreign key (idCurrency)
      references currency (idCurrency)
      on delete set null
      on update cascade;

alter table project
   add constraint FK_serverFile2 foreign key (idServerFile)
      references serverFile (idServerFile)
      on delete set null
      on update cascade;

alter table projectActivity
   add constraint FK_currency5 foreign key (idCurrency)
      references currency (idCurrency)
      on delete set null
      on update cascade;

alter table projectActivity
   add constraint FK_employee9 foreign key (idEmployee)
      references employee (idEmployee)
      on delete set null
      on update cascade;

alter table projectActivity
   add constraint FK_project8 foreign key (idProject)
      references project (idProject)
      on delete cascade
      on update cascade;

alter table projectInfo
   add constraint FK_project2 foreign key (idProject)
      references project (idProject)
      on delete cascade
      on update cascade;

alter table projectParcel
   add constraint FK_currency7 foreign key (idCurrency)
      references currency (idCurrency)
      on delete set null
      on update cascade;

alter table projectParcel
   add constraint FK_employee11 foreign key (idEmployee)
      references employee (idEmployee)
      on delete set null
      on update cascade;

alter table projectParcel
   add constraint FK_project10 foreign key (idProject)
      references project (idProject)
      on delete cascade
      on update cascade;

alter table projectParcel
   add constraint FK_projectActivity2 foreign key (idProjectActivity)
      references projectActivity (idProjectActivity)
      on delete cascade
      on update cascade;

alter table projectParcel
   add constraint FK_projectTask1 foreign key (idProjectTask)
      references projectTask (idProjectTask)
      on delete cascade
      on update cascade;

alter table projectPhoto
   add constraint FK_project1 foreign key (idProject)
      references project (idProject)
      on delete cascade
      on update cascade;

alter table projectPhoto
   add constraint FK_serverFile3 foreign key (idServerFile)
      references serverFile (idServerFile)
      on delete cascade
      on update cascade;

alter table projectSubParcel
   add constraint FK_currency9 foreign key (idCurrency)
      references currency (idCurrency)
      on delete set null
      on update cascade;

alter table projectSubParcel
   add constraint FK_employee12 foreign key (idEmployee)
      references employee (idEmployee)
      on delete set null
      on update cascade;

alter table projectSubParcel
   add constraint FK_project11 foreign key (idProject)
      references project (idProject)
      on delete cascade
      on update cascade;

alter table projectSubParcel
   add constraint FK_projectActivity3 foreign key (idProjectActivity)
      references projectActivity (idProjectActivity)
      on delete cascade
      on update cascade;

alter table projectSubParcel
   add constraint FK_projectParcel1 foreign key (idProjectParcel)
      references projectParcel (idProjectParcel)
      on delete cascade
      on update cascade;

alter table projectSubParcel
   add constraint FK_projectTask2 foreign key (idProjectTask)
      references projectTask (idProjectTask)
      on delete cascade
      on update cascade;

alter table projectTask
   add constraint FK_currency6 foreign key (idCurrency)
      references currency (idCurrency)
      on delete set null
      on update cascade;

alter table projectTask
   add constraint FK_employee10 foreign key (idEmployee)
      references employee (idEmployee)
      on delete set null
      on update cascade;

alter table projectTask
   add constraint FK_project9 foreign key (idProject)
      references project (idProject)
      on delete cascade
      on update cascade;

alter table projectTask
   add constraint FK_projectActivity1 foreign key (idProjectActivity)
      references projectActivity (idProjectActivity)
      on delete cascade
      on update cascade;

alter table projectTaskHelper
   add constraint FK_projectActivityHelper1 foreign key (idProjectActivity)
      references projectActivityHelper (idProjectActivity)
      on delete cascade
      on update cascade;

alter table providerData
   add constraint FK_provider1 foreign key (idProvider)
      references provider (idProvider)
      on delete cascade
      on update cascade;

alter table salesClient
   add constraint FK_employee6 foreign key (idEmployee)
      references employee (idEmployee)
      on delete cascade
      on update cascade;

alter table salesClientData
   add constraint FK_salesClient1 foreign key (idSalesClient)
      references salesClient (idSalesClient)
      on delete cascade
      on update cascade;

alter table salesClientData
   add constraint FK_salesContact2 foreign key (idSalesContact)
      references salesContact (idSalesContact)
      on delete set null
      on update cascade;

alter table salesClientData
   add constraint FK_salesContactMedia2 foreign key (idSalesContactMedia)
      references salesContactMedia (idSalesContactMedia)
      on delete set null
      on update cascade;

alter table salesClientUnit
   add constraint FK_employee7 foreign key (idEmployee)
      references employee (idEmployee)
      on delete cascade
      on update cascade;

alter table salesClientUnit
   add constraint FK_project13 foreign key (idProject)
      references project (idProject)
      on delete set null
      on update cascade;

alter table salesClientUnit
   add constraint FK_salesClient2 foreign key (idSalesClient)
      references salesClient (idSalesClient)
      on delete cascade
      on update cascade;

alter table salesClientUnit
   add constraint FK_salesClientState1 foreign key (idSalesClientState)
      references salesClientState (idSalesClientState)
      on delete cascade
      on update cascade;

alter table salesClientUnit
   add constraint FK_salesContact1 foreign key (idSalesContact)
      references salesContact (idSalesContact)
      on delete set null
      on update cascade;

alter table salesClientUnit
   add constraint FK_salesContactMedia1 foreign key (idSalesContactMedia)
      references salesContactMedia (idSalesContactMedia)
      on delete set null
      on update cascade;

alter table salesClientUnit
   add constraint FK_salesPaymentPlan1 foreign key (idSalesPaymentPlan)
      references salesPaymentPlan (idSalesPaymentPlan)
      on delete set null
      on update cascade;

alter table salesClientUnit
   add constraint FK_salesUnit1 foreign key (idSalesUnit)
      references salesUnit (idSalesUnit)
      on delete cascade
      on update cascade;

alter table salesClientUnitReject
   add constraint FK_salesClientUnit1 foreign key (idSalesClientUnit)
      references salesClientUnit (idSalesClientUnit)
      on delete cascade
      on update cascade;

alter table salesClientUnitReject
   add constraint FK_salesClinet3 foreign key (idSalesClient)
      references salesClient (idSalesClient)
      on delete cascade
      on update cascade;

alter table salesClientUnitReject
   add constraint FK_salesRejectOption1 foreign key (idSalesRejectOption)
      references salesRejectOption (idSalesRejectOption)
      on delete cascade
      on update cascade;

alter table salesContact
   add constraint FK_project5 foreign key (idProject)
      references project (idProject)
      on delete set null
      on update cascade;

alter table salesContactMedia
   add constraint FK_project6 foreign key (idProject)
      references project (idProject)
      on delete set null
      on update cascade;

alter table salesPaymentPlan
   add constraint FK_project4 foreign key (idProject)
      references project (idProject)
      on delete cascade
      on update cascade;

alter table salesPaymentPlan
   add constraint FK_salesPaymentPlanType1 foreign key (idSalesPaymentPlanType)
      references salesPaymentPlanType (idSalesPaymentPlanType)
      on delete cascade
      on update cascade;

alter table salesUnit
   add constraint FK_currency2 foreign key (idCurrency)
      references currency (idCurrency)
      on delete cascade
      on update cascade;

alter table salesUnit
   add constraint FK_project3 foreign key (idProject)
      references project (idProject)
      on delete cascade
      on update cascade;

alter table salesUnit
   add constraint FK_salesUnitState1 foreign key (idSalesUnitState)
      references salesUnitState (idSalesUnitState)
      on delete cascade
      on update cascade;

alter table salesUnit
   add constraint FK_salesUnitType1 foreign key (idSalesUnitType)
      references salesUnitType (idSalesUnitType)
      on delete cascade
      on update cascade;

alter table salesUnit1
   add constraint FK_salesUnit2 foreign key (idSalesUnit)
      references salesUnit (idSalesUnit)
      on delete cascade
      on update cascade;

alter table serverFile
   add constraint FK_employee4 foreign key (idEmployee)
      references employee (idEmployee)
      on delete set null
      on update cascade;

alter table serverFile
   add constraint FK_serverFileType1 foreign key (idServerFileType)
      references serverFileType (idServerFileType)
      on delete restrict
      on update restrict;

