/*==============================================================*/
/* DBMS name:      MySQL 4.11                                   */
/* Created on:     01/09/2005 8:23:32 PM                        */
/*==============================================================*/


alter table accessProfileRoles
   drop foreign key FK_accessProfile1;

alter table accessProfileRoles
   drop foreign key FK_systemModule1;

alter table currencyChangeRate
   drop foreign key FK_currency3;

alter table currencyChangeRate
   drop foreign key FK_currency4;

alter table currencyChangeRate
   drop foreign key FK_employee4;

alter table demo_salesUnit1
   drop foreign key FK_salesUnit_demo1;

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_project1;

alter table employeeData
   drop foreign key FK_employee1;

alter table employeeUser
   drop foreign key FK_employee2;

alter table ltc_salesUnit1
   drop foreign key FK_salesUnit_ltc1;

alter table project
   drop foreign key FK_currency2;

alter table project
   drop foreign key FK_salesPaymentPlan2;

alter table project
   drop foreign key FK_serverFile1;

alter table projectConfiguration
   drop foreign key FK_accessProfile3;

alter table projectConfiguration
   drop foreign key FK_project11;

alter table projectInfo
   drop foreign key FK_project4;

alter table projectPhoto
   drop foreign key FK_project3;

alter table projectPhoto
   drop foreign key FK_serverFile3;

alter table projectSalesPlan
   drop foreign key FK_currency6;

alter table projectSalesPlan
   drop foreign key FK_project10;

alter table salesClient
   drop foreign key FK_employee6;

alter table salesClientData
   drop foreign key FK_salesClient1;

alter table salesClientData
   drop foreign key FK_salesContact1;

alter table salesClientData
   drop foreign key FK_salesContactMedia1;

alter table salesClientUnit
   drop foreign key FK_currency5;

alter table salesClientUnit
   drop foreign key FK_employee7;

alter table salesClientUnit
   drop foreign key FK_project7;

alter table salesClientUnit
   drop foreign key FK_salesClient2;

alter table salesClientUnit
   drop foreign key FK_salesClientState1;

alter table salesClientUnit
   drop foreign key FK_salesContact2;

alter table salesClientUnit
   drop foreign key FK_salesContactMedia2;

alter table salesClientUnit
   drop foreign key FK_salesPaymentPlan1;

alter table salesClientUnit
   drop foreign key FK_salesUnit1;

alter table salesClientUnitPaymentSchema
   drop foreign key FK_salesClientUnit2;

alter table salesClientUnitReject
   drop foreign key FK_salesClient3;

alter table salesClientUnitReject
   drop foreign key FK_salesClientUnit1;

alter table salesClientUnitReject
   drop foreign key FK_salesRejectOption1;

alter table salesClientUnitStateHistory
   drop foreign key FK_employee10;

alter table salesClientUnitStateHistory
   drop foreign key FK_salesClientState2;

alter table salesClientUnitStateHistory
   drop foreign key FK_salesClientUnit4;

alter table salesContact
   drop foreign key FK_project5;

alter table salesContactMedia
   drop foreign key FK_project6;

alter table salesPayment
   drop foreign key FK_employee9;

alter table salesPayment
   drop foreign key FK_salesClientUnit3;

alter table salesPayment
   drop foreign key FK_salesPaymentType;

alter table salesPaymentPlan
   drop foreign key FK_project8;

alter table salesUnit
   drop foreign key FK_currency1;

alter table salesUnit
   drop foreign key FK_project2;

alter table salesUnit
   drop foreign key FK_projectPhoto1;

alter table salesUnit
   drop foreign key FK_salesUnitState1;

alter table salesUnit
   drop foreign key FK_salesUnitType1;

alter table sellerClientProject
   drop foreign key FK_employee8;

alter table sellerClientProject
   drop foreign key FK_project9;

alter table sellerClientProject
   drop foreign key FK_salesClient4;

alter table serverFile
   drop foreign key FK_employee5;

alter table serverFile
   drop foreign key FK_serverFileType1;

alter table ultra_salesUnit1
   drop foreign key FK_salesUnit_T1;

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 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 ED_idEmployee on employeeData;

drop index EMPT_unique on employeeType;

drop index EU_idEmployee on employeeUser;

drop index EU_unique on employeeUser;

drop index projectInfo_unique on projectInfo;

drop index projectSalesPlan_unique on projectSalesPlan;

drop index salesClientData_unique on salesClientData;

drop index SLS_CS_name on salesClientState;

drop index salesClientUnitPaymentSchema_unique on salesClientUnitPaymentSchema;

drop index salesClientUnitStateHistory_unique on salesClientUnitStateHistory;

drop index salesPayment_unique on salesPayment;

drop index sellerClientProject_unique on sellerClientProject;

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 currency;

drop table if exists currencyChangeRate;

drop table if exists demo_salesUnit1;

drop table if exists employee;

drop table if exists employeeAccessProfile;

drop table if exists employeeData;

drop table if exists employeeType;

drop table if exists employeeUser;

drop table if exists ltc_salesUnit1;

drop table if exists project;

drop table if exists projectConfiguration;

drop table if exists projectInfo;

drop table if exists projectPhoto;

drop table if exists projectSalesPlan;

drop table if exists salesClient;

drop table if exists salesClientData;

drop table if exists salesClientState;

drop table if exists salesClientUnit;

drop table if exists salesClientUnitPaymentSchema;

drop table if exists salesClientUnitReject;

drop table if exists salesClientUnitStateHistory;

drop table if exists salesContact;

drop table if exists salesContactMedia;

drop table if exists salesPayment;

drop table if exists salesPaymentPlan;

drop table if exists salesPaymentType;

drop table if exists salesRejectOption;

drop table if exists salesUnit;

drop table if exists salesUnitState;

drop table if exists salesUnitType;

drop table if exists sellerClientProject;

drop table if exists serverFile;

drop table if exists serverFileType;

drop table if exists systemModule;

drop table if exists ultra_salesUnit1;

/*==============================================================*/
/* Table: accessProfile                                         */
/*==============================================================*/
create table accessProfile
(
   idAccessProfile                int                            not null AUTO_INCREMENT,
   name                           varchar(255)                   not null,
   primary key (idAccessProfile)
)
type = InnoDB;

/*==============================================================*/
/* 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;

/*==============================================================*/
/* 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: currency                                              */
/*==============================================================*/
create table currency
(
   idCurrency                     int                            not null AUTO_INCREMENT,
   name                           varchar(64)                    not null,
   primary key (idCurrency)
)
type = InnoDB;

/*==============================================================*/
/* 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: demo_salesUnit1                                       */
/*==============================================================*/
create table demo_salesUnit1
(
   idSalesUnit                    int                            not null,
   banos                          varchar(255)                   not null,
   recamaras                      varchar(255)                   not null,
   m2interiores                   double                         not null,
   m2terraza                      double                         not null,
   primary key (idSalesUnit)
)
type = InnoDB;

/*==============================================================*/
/* Table: employee                                              */
/*==============================================================*/
create table employee
(
   idEmployee                     int                            not null AUTO_INCREMENT,
   idEmployeeType                 int                            not null,
   idSupervisor                   int,
   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,
   dateBirthday                   date,
   primary key (idEmployee)
)
type = InnoDB;

/*==============================================================*/
/* Index: EMP_unique                                            */
/*==============================================================*/
create unique index EMP_unique on employee
(
   nameFirst,
   nameFirst1,
   nameLast,
   nameLast1
);

/*==============================================================*/
/* 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;

/*==============================================================*/
/* Index: EAP_unique                                            */
/*==============================================================*/
create unique index EAP_unique on employeeAccessProfile
(
   idEmployee,
   idProject
);

/*==============================================================*/
/* Index: EAP_idEmployee                                        */
/*==============================================================*/
create index EAP_idEmployee on employeeAccessProfile
(
   idEmployee
);

/*==============================================================*/
/* Index: EAP_idAccessProfile                                   */
/*==============================================================*/
create index EAP_idAccessProfile on employeeAccessProfile
(
   idAccessProfile
);

/*==============================================================*/
/* 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;

/*==============================================================*/
/* 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;

/*==============================================================*/
/* Index: EU_unique                                             */
/*==============================================================*/
create unique index EU_unique on employeeUser
(
   username
);

/*==============================================================*/
/* Index: EU_idEmployee                                         */
/*==============================================================*/
create unique index EU_idEmployee on employeeUser
(
   idEmployee
);

/*==============================================================*/
/* Table: ltc_salesUnit1                                        */
/*==============================================================*/
create table ltc_salesUnit1
(
   idSalesUnit                    int                            not null,
   departamento                   varchar(255)                   not null,
   vista                          varchar(255)                   not null,
   recamaras                      varchar(255)                   not null,
   m2interiores                   double                         not null,
   m2terraza                      double                         not null,
   primary key (idSalesUnit)
)
type = InnoDB;

/*==============================================================*/
/* Table: project                                               */
/*==============================================================*/
create table project
(
   idProject                      int                            not null AUTO_INCREMENT,
   idServerFile                   int,
   idCurrency                     int,
   idSalesPaymentPlan             int,
   name                           varchar(255)                   not null,
   primary key (idProject)
)
type = InnoDB;

/*==============================================================*/
/* Table: projectConfiguration                                  */
/*==============================================================*/
create table projectConfiguration
(
   idProject                      int                            not null,
   idBookingMailAccessProfile     int
);

/*==============================================================*/
/* Table: projectInfo                                           */
/*==============================================================*/
create table projectInfo
(
   idProject                      int                            not null,
   phrase                         varchar(255)                   not null,
   address                        blob                           not null,
   siteURL                        varchar(255)                   not null,
   arquitect                      varchar(255)                   not null,
   descriptionUnits               blob                           not null,
   descriptionGeneral             blob                           not null,
   descriptionAccessory           blob                           not null,
   descriptionAttributes          blob                           not null,
   descriptionAdditional          blob                           not null,
   dateStart                      date                           not null,
   dateEnd                        date                           not null
)
type = InnoDB;

/*==============================================================*/
/* Index: projectInfo_unique                                    */
/*==============================================================*/
create unique index projectInfo_unique on projectInfo
(
   idProject
);

/*==============================================================*/
/* 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: projectSalesPlan                                      */
/*==============================================================*/
create table projectSalesPlan
(
   idProjectSalesPlan             int                            not null AUTO_INCREMENT,
   idProject                      int                            not null,
   idCurrency                     int                            not null,
   datePeriod                     date                           not null,
   numberOfUnits                  integer                        not null,
   amount                         double                         not null,
   primary key (idProjectSalesPlan)
)
type = InnoDB;

/*==============================================================*/
/* Index: projectSalesPlan_unique                               */
/*==============================================================*/
create unique index projectSalesPlan_unique on projectSalesPlan
(
   idProject,
   datePeriod
);

/*==============================================================*/
/* Table: salesClient                                           */
/*==============================================================*/
create table salesClient
(
   idSalesClient                  int                            not null AUTO_INCREMENT,
   idEmployee                     int,
   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;

/*==============================================================*/
/* Index: salesClientData_unique                                */
/*==============================================================*/
create unique index salesClientData_unique on salesClientData
(
   idSalesClient
);

/*==============================================================*/
/* Table: salesClientState                                      */
/*==============================================================*/
create table salesClientState
(
   idSalesClientState             int                            not null AUTO_INCREMENT,
   name                           varchar(64)                    not null,
   primary key (idSalesClientState)
)
type = InnoDB;

/*==============================================================*/
/* 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,
   idSalesPaymentPlan             int,
   idSalesClientState             int                            not null,
   idSalesContact                 int,
   idSalesContactMedia            int,
   idProject                      int                            not null,
   idCurrency                     int,
   dateRegistration               datetime                       not null,
   sellPrice                      double                         not null,
   price                          double                         not null,
   primary key (idSalesClientUnit)
)
type = InnoDB;

/*==============================================================*/
/* Table: salesClientUnitPaymentSchema                          */
/*==============================================================*/
create table salesClientUnitPaymentSchema
(
   idSalesClientUnit              int                            not null,
   booking                        double                         not null,
   dateBooking                    date,
   hook                           double                         not null,
   dateHook                       date,
   monthly                        double                         not null,
   monthes                        int                            not null,
   dateMonthlyPaymentStart        date,
   lastMonthlyPaymentDay          int                            not null,
   final1                         double                         not null,
   final2                         double                         not null,
   dateFinal1                     date,
   dateFinal2                     date,
   penalty                        double                         not null,
   extra1                         double,
   extra2                         double,
   extra3                         double,
   extra4                         double,
   dateExtra1                     date,
   dateExtra2                     date,
   dateExtra3                     date,
   dateExtra4                     date
);

/*==============================================================*/
/* Index: salesClientUnitPaymentSchema_unique                   */
/*==============================================================*/
create unique index salesClientUnitPaymentSchema_unique on salesClientUnitPaymentSchema
(
   idSalesClientUnit
);

/*==============================================================*/
/* 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                    blob                           not null,
   primary key (idSalesClientUnitReject)
)
type = InnoDB;

/*==============================================================*/
/* Table: salesClientUnitStateHistory                           */
/*==============================================================*/
create table salesClientUnitStateHistory
(
   idSalesClientUnit              int                            not null,
   idSalesClientState             int                            not null,
   idEmployee                     int                            not null,
   dateRegistration               datetime                       not null
)
type = InnoDB;

/*==============================================================*/
/* Index: salesClientUnitStateHistory_unique                    */
/*==============================================================*/
create unique index salesClientUnitStateHistory_unique on salesClientUnitStateHistory
(
   idSalesClientUnit,
   idSalesClientState,
   idEmployee,
   dateRegistration
);

/*==============================================================*/
/* 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: salesPayment                                          */
/*==============================================================*/
create table salesPayment
(
   idSalesPayment                 int                            not null AUTO_INCREMENT,
   dateRegistration               datetime,
   idSalesPaymentType             int                            not null,
   idSalesClientUnit              int                            not null,
   idEmployee                     int,
   datePaymentExpected            date                           not null,
   datePayment                    date,
   amountExpected                 double                         not null,
   amount                         double                         not null,
   primary key (idSalesPayment)
);

/*==============================================================*/
/* Index: salesPayment_unique                                   */
/*==============================================================*/
create unique index salesPayment_unique on salesPayment
(
   idSalesPaymentType,
   idSalesClientUnit,
   datePaymentExpected,
   datePayment
);

/*==============================================================*/
/* Table: salesPaymentPlan                                      */
/*==============================================================*/
create table salesPaymentPlan
(
   idSalesPaymentPlan             int                            not null AUTO_INCREMENT,
   idProject                      int,
   name                           varchar(255)                   not null,
   increment                      double                         not null,
   booking                        double                         not null,
   hook                           double                         not null,
   monthly                        double                         not null,
   dateMonthlyEnd                 date,
   final1                         double                         not null,
   final2                         double                         not null,
   dateFinal1                     date,
   dateFinal2                     date,
   description                    blob                           not null,
   primary key (idSalesPaymentPlan)
)
type = InnoDB;

/*==============================================================*/
/* Table: salesPaymentType                                      */
/*==============================================================*/
create table salesPaymentType
(
   idSalesPaymentType             int                            not null AUTO_INCREMENT,
   name                           varchar(64)                    not null,
   primary key (idSalesPaymentType)
)
type = InnoDB;

/*==============================================================*/
/* Table: salesRejectOption                                     */
/*==============================================================*/
create table salesRejectOption
(
   idSalesRejectOption            int                            not null AUTO_INCREMENT,
   name                           varchar(255)                   not null,
   primary key (idSalesRejectOption)
)
type = InnoDB;

/*==============================================================*/
/* 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,
   idProjectPhoto                 int,
   floor                          varchar(64)                    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: salesUnitState                                        */
/*==============================================================*/
create table salesUnitState
(
   idSalesUnitState               int                            not null AUTO_INCREMENT,
   name                           varchar(255)                   not null,
   primary key (idSalesUnitState)
)
type = InnoDB;

/*==============================================================*/
/* Table: salesUnitType                                         */
/*==============================================================*/
create table salesUnitType
(
   idSalesUnitType                int                            not null AUTO_INCREMENT,
   name                           varchar(255)                   not null,
   primary key (idSalesUnitType)
)
type = InnoDB;

/*==============================================================*/
/* Table: sellerClientProject                                   */
/*==============================================================*/
create table sellerClientProject
(
   idEmployee                     int,
   idSalesClient                  int                            not null,
   idProject                      int,
   dateRegistration               datetime                       not null
)
type = InnoDB;

/*==============================================================*/
/* Index: sellerClientProject_unique                            */
/*==============================================================*/
create unique index sellerClientProject_unique on sellerClientProject
(
   idSalesClient,
   idProject
);

/*==============================================================*/
/* 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;

/*==============================================================*/
/* 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;

/*==============================================================*/
/* Index: SMOD_unique                                           */
/*==============================================================*/
create unique index SMOD_unique on systemModule
(
   idParent,
   location
);

/*==============================================================*/
/* Table: ultra_salesUnit1                                      */
/*==============================================================*/
create table ultra_salesUnit1
(
   idSalesUnit                    int                            not null,
   position                       varchar(255)                   not null,
   primary key (idSalesUnit)
)
type = InnoDB;

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 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_employee4 foreign key (idEmployee)
      references employee (idEmployee)
      on delete set null
      on update cascade;

alter table demo_salesUnit1
   add constraint FK_salesUnit_demo1 foreign key (idSalesUnit)
      references salesUnit (idSalesUnit)
      on delete cascade
      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_project1 foreign key (idProject)
      references project (idProject)
      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 ltc_salesUnit1
   add constraint FK_salesUnit_ltc1 foreign key (idSalesUnit)
      references salesUnit (idSalesUnit)
      on delete cascade
      on update cascade;

alter table project
   add constraint FK_currency2 foreign key (idCurrency)
      references currency (idCurrency)
      on delete set null
      on update cascade;

alter table project
   add constraint FK_salesPaymentPlan2 foreign key (idSalesPaymentPlan)
      references salesPaymentPlan (idSalesPaymentPlan)
      on delete set null
      on update cascade;

alter table project
   add constraint FK_serverFile1 foreign key (idServerFile)
      references serverFile (idServerFile)
      on delete set null
      on update cascade;

alter table projectConfiguration
   add constraint FK_accessProfile3 foreign key (idBookingMailAccessProfile)
      references accessProfile (idAccessProfile)
      on delete set null
      on update cascade;

alter table projectConfiguration
   add constraint FK_project11 foreign key (idProject)
      references project (idProject)
      on delete cascade
      on update cascade;

alter table projectInfo
   add constraint FK_project4 foreign key (idProject)
      references project (idProject)
      on delete cascade
      on update cascade;

alter table projectPhoto
   add constraint FK_project3 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 projectSalesPlan
   add constraint FK_currency6 foreign key (idCurrency)
      references currency (idCurrency)
      on delete cascade
      on update cascade;

alter table projectSalesPlan
   add constraint FK_project10 foreign key (idProject)
      references project (idProject)
      on delete cascade
      on update cascade;

alter table salesClient
   add constraint FK_employee6 foreign key (idEmployee)
      references employee (idEmployee)
      on delete set null
      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_salesContact1 foreign key (idSalesContact)
      references salesContact (idSalesContact)
      on delete set null
      on update cascade;

alter table salesClientData
   add constraint FK_salesContactMedia1 foreign key (idSalesContactMedia)
      references salesContactMedia (idSalesContactMedia)
      on delete set null
      on update cascade;

alter table salesClientUnit
   add constraint FK_currency5 foreign key (idCurrency)
      references currency (idCurrency)
      on delete set null
      on update cascade;

alter table salesClientUnit
   add constraint FK_employee7 foreign key (idEmployee)
      references employee (idEmployee)
      on delete set null
      on update cascade;

alter table salesClientUnit
   add constraint FK_project7 foreign key (idProject)
      references project (idProject)
      on delete cascade
      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_salesContact2 foreign key (idSalesContact)
      references salesContact (idSalesContact)
      on delete set null
      on update cascade;

alter table salesClientUnit
   add constraint FK_salesContactMedia2 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 salesClientUnitPaymentSchema
   add constraint FK_salesClientUnit2 foreign key (idSalesClientUnit)
      references salesClientUnit (idSalesClientUnit)
      on delete cascade
      on update cascade;

alter table salesClientUnitReject
   add constraint FK_salesClient3 foreign key (idSalesClient)
      references salesClient (idSalesClient)
      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_salesRejectOption1 foreign key (idSalesRejectOption)
      references salesRejectOption (idSalesRejectOption)
      on delete cascade
      on update cascade;

alter table salesClientUnitStateHistory
   add constraint FK_employee10 foreign key (idEmployee)
      references employee (idEmployee)
      on delete cascade
      on update cascade;

alter table salesClientUnitStateHistory
   add constraint FK_salesClientState2 foreign key (idSalesClientState)
      references salesClientState (idSalesClientState)
      on delete cascade
      on update cascade;

alter table salesClientUnitStateHistory
   add constraint FK_salesClientUnit4 foreign key (idSalesClientUnit)
      references salesClientUnit (idSalesClientUnit)
      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 salesPayment
   add constraint FK_employee9 foreign key (idEmployee)
      references employee (idEmployee)
      on delete set null
      on update cascade;

alter table salesPayment
   add constraint FK_salesClientUnit3 foreign key (idSalesClientUnit)
      references salesClientUnit (idSalesClientUnit)
      on delete cascade
      on update cascade;

alter table salesPayment
   add constraint FK_salesPaymentType foreign key (idSalesPaymentType)
      references salesPaymentType (idSalesPaymentType)
      on delete cascade
      on update cascade;

alter table salesPaymentPlan
   add constraint FK_project8 foreign key (idProject)
      references project (idProject)
      on delete set null
      on update cascade;

alter table salesUnit
   add constraint FK_currency1 foreign key (idCurrency)
      references currency (idCurrency)
      on delete cascade
      on update cascade;

alter table salesUnit
   add constraint FK_project2 foreign key (idProject)
      references project (idProject)
      on delete cascade
      on update cascade;

alter table salesUnit
   add constraint FK_projectPhoto1 foreign key (idProjectPhoto)
      references projectPhoto (idProjectPhoto)
      on delete set null
      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 sellerClientProject
   add constraint FK_employee8 foreign key (idEmployee)
      references employee (idEmployee)
      on delete set null
      on update cascade;

alter table sellerClientProject
   add constraint FK_project9 foreign key (idProject)
      references project (idProject)
      on delete set null
      on update cascade;

alter table sellerClientProject
   add constraint FK_salesClient4 foreign key (idSalesClient)
      references salesClient (idSalesClient)
      on delete cascade
      on update cascade;

alter table serverFile
   add constraint FK_employee5 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;

alter table ultra_salesUnit1
   add constraint FK_salesUnit_T1 foreign key (idSalesUnit)
      references salesUnit (idSalesUnit)
      on delete cascade
      on update cascade;

