# ---------------------------------------------------------------------- #
# Script generated with: DeZign for Databases V7.3.4                     #
# Target DBMS:           MySQL 5                                         #
# Project file:          abliaDbComuni3.dez                              #
# Project name:          DB COMUNI - ABLIA                               #
# Author:                Andrea Colzi                                    #
# Script type:           Alter database script                           #
# Created on:            2016-11-17 10:53                                #
# ---------------------------------------------------------------------- #



# ---------------------------------------------------------------------- #
# Drop table "CLIFOR_AGENTE"                                             #
# ---------------------------------------------------------------------- #

# Remove autoinc for PK drop #

ALTER TABLE `CLIFOR_AGENTE` MODIFY `id_cliforAgente` INTEGER NOT NULL;

# Drop constraints #

ALTER TABLE `CLIFOR_AGENTE` DROP PRIMARY KEY;

# Drop table #

DROP TABLE `CLIFOR_AGENTE`;

# ---------------------------------------------------------------------- #
# Modify table "CLIFOR"                                                  #
# ---------------------------------------------------------------------- #

ALTER TABLE `CLIFOR` ADD COLUMN `id_agente` INTEGER;

ALTER TABLE `CLIFOR` ADD COLUMN `id_respCommerciale` INTEGER;

ALTER TABLE `CLIFOR` ADD COLUMN `percAgente` DECIMAL(5,2);

ALTER TABLE `CLIFOR` ADD COLUMN `percRespCommerciale` DECIMAL(5,2);

# ---------------------------------------------------------------------- #
# Modify table "DOCUMENTO"                                               #
# ---------------------------------------------------------------------- #

ALTER TABLE `DOCUMENTO` ADD COLUMN `dataRestituzioneAcconto` DATE;

ALTER TABLE `DOCUMENTO` ADD COLUMN `id_agente` INTEGER;

ALTER TABLE `DOCUMENTO` ADD COLUMN `id_respCommerciale` INTEGER;


# ---------------------------------------------------------------------- #
# Modify table "LISTINO_TIPO"                                            #
# ---------------------------------------------------------------------- #

ALTER TABLE `LISTINO_TIPO` ADD COLUMN `percLT1` DECIMAL(5,2);

ALTER TABLE `LISTINO_TIPO` ADD COLUMN `percLT2` DECIMAL(5,2);

ALTER TABLE `LISTINO_TIPO` ADD COLUMN `percLT3` DECIMAL(5,2);

# ---------------------------------------------------------------------- #
# Modify table "LISTINO_ARTICOLO"                                        #
# ---------------------------------------------------------------------- #

ALTER TABLE `LISTINO_ARTICOLO` ADD COLUMN `percLA1` DECIMAL(5,2);

ALTER TABLE `LISTINO_ARTICOLO` ADD COLUMN `percLA2` DECIMAL(5,2);

ALTER TABLE `LISTINO_ARTICOLO` ADD COLUMN `percLA3` DECIMAL(5,2);


#ALTER TABLE `LISTINO` ADD COLUMN `percL1` DECIMAL(5,2);

#ALTER TABLE `LISTINO` ADD COLUMN `percL2` DECIMAL(5,2);

#ALTER TABLE `LISTINO` ADD COLUMN `percL3` DECIMAL(5,2);



# ---------------------------------------------------------------------- #
# Alter table "CLIFOR_TIPO_CLIFOR"                                       #
# ---------------------------------------------------------------------- #

ALTER TABLE `CLIFOR_TIPO_CLIFOR` ADD COLUMN `percProvvigione` DECIMAL(5,2);



# ---------------------------------------------------------------------- #
# Add table "ARTICOLO_PROGETTISTA"                                       #
# ---------------------------------------------------------------------- #

CREATE TABLE `ARTICOLO_PROGETTISTA` (
    `id_articoloProgettista` INTEGER NOT NULL AUTO_INCREMENT,
    `id_articolo` INTEGER,
    `id_clifor` INTEGER,
    `percProvvigione` DECIMAL(5,2),
    CONSTRAINT `PK_ARTICOLO_PROGETTISTA` PRIMARY KEY (`id_articoloProgettista`)
);

# ---------------------------------------------------------------------- #
# Add foreign key constraints                                            #
# ---------------------------------------------------------------------- #

ALTER TABLE `CLIFOR` ADD CONSTRAINT `CLIFOR_CLIFOR_agente` 
    FOREIGN KEY (`id_agente`) REFERENCES `CLIFOR` (`id_clifor`);

ALTER TABLE `CLIFOR` ADD CONSTRAINT `CLIFOR_CLIFOR_resp_comm` 
    FOREIGN KEY (`id_respCommerciale`) REFERENCES `CLIFOR` (`id_clifor`);