# ---------------------------------------------------------------------- #
# Alter table "DOCUMENTO"                                                #
# ---------------------------------------------------------------------- #

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

ALTER TABLE `DOCUMENTO` ADD COLUMN `valoreDichiarato` DECIMAL(18,4);

ALTER TABLE `DOCUMENTO` ADD COLUMN `costoEffettivoSped` DECIMAL(18,4);

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

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

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

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


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


ALTER TABLE `DOCUMENTO` CHANGE `kg` `kgLordo` DOUBLE;



CREATE TABLE `ARTICOLO_USATO` (
    `id_articoloUsato` INTEGER NOT NULL AUTO_INCREMENT,
    `id_articolo` INTEGER,
    `dataDocumento` DATE,
    `numeroDocumento` VARCHAR(40),
    `flgTipoDocumento` INTEGER,
    `importo` DECIMAL(18,4),
    `id_fornitore` INTEGER,
    `id_rigaDocumento` INTEGER,
    `id_cliente` INTEGER,
    `tmstStampa` VARCHAR(40),
    `descrizioneRigaDocumento` VARCHAR(254),
    CONSTRAINT `PK_ARTICOLO_USATO` PRIMARY KEY (`id_articoloUsato`)
);

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

ALTER TABLE `ARTICOLO_USATO` ADD CONSTRAINT `ARTICOLO_ARTICOLO_USATO` 
    FOREIGN KEY (`id_articolo`) REFERENCES `ARTICOLO` (`id_articolo`);

ALTER TABLE `ARTICOLO_USATO` ADD CONSTRAINT `CLIFOR_ARTICOLO_USATO_fornitore` 
    FOREIGN KEY (`id_fornitore`) REFERENCES `CLIFOR` (`id_clifor`);

ALTER TABLE `ARTICOLO_USATO` ADD CONSTRAINT `CLIFOR_ARTICOLO_USATO_cliente` 
    FOREIGN KEY (`id_cliente`) REFERENCES `CLIFOR` (`id_clifor`);

ALTER TABLE `ARTICOLO_USATO` ADD CONSTRAINT `RIGA_DOCUMENTO_ARTICOLO_USATO` 
    FOREIGN KEY (`id_rigaDocumento`) REFERENCES `RIGA_DOCUMENTO` (`id_rigaDocumento`);
	
	
	
# ---------------------------------------------------------------------- #
# Alter table "USERS"                                                    #
# ---------------------------------------------------------------------- #

ALTER TABLE `USERS` ADD COLUMN `codiceAlt` VARCHAR(40);

CREATE UNIQUE INDEX `IDX_USERS_3` ON `USERS` (`codiceAlt`);

ALTER TABLE `DESTINAZIONE_DIVERSA` DROP FOREIGN KEY `NAZIONE_DESTINAZIONE_DIVERSA`;

ALTER TABLE `CLIFOR` DROP FOREIGN KEY `NAZIONE_CLIFOR`;

# ---------------------------------------------------------------------- #
# Alter table "DOCUMENTO"                                                #
# ---------------------------------------------------------------------- #

ALTER TABLE `DOCUMENTO` MODIFY `notePagamento` VARCHAR(254);

# ---------------------------------------------------------------------- #
# Alter table "TIPO_DOCUMENTO"                                           #
# ---------------------------------------------------------------------- #

ALTER TABLE `TIPO_DOCUMENTO` ADD COLUMN `flgUsato` INTEGER;

ALTER TABLE `TIPO_DOCUMENTO` ADD COLUMN `flgMovMagazzino` INTEGER;

#################################################################################
#################################################################################
#################################################################################
#################################################################################
#################################################################################
#################################################################################
#################################################################################
#################################################################################
#################################################################################
#################################################################################


# ---------------------------------------------------------------------- #
# Alter table "ARTICOLO"                                                 #
# ---------------------------------------------------------------------- #

ALTER TABLE `ARTICOLO` ADD COLUMN `scaffale` VARCHAR(40);

# ---------------------------------------------------------------------- #
# Alter table "ARTICOLO_USATO"                                           #
# ---------------------------------------------------------------------- #

ALTER TABLE `ARTICOLO_USATO` ADD COLUMN `codiceAlt` INTEGER;

CREATE UNIQUE INDEX `IDX_ARTICOLO_USATO_1` ON `ARTICOLO_USATO` (`codiceAlt`);


# ---------------------------------------------------------------------- #
# Alter table "ARTICOLO"                                                 #
# ---------------------------------------------------------------------- #

ALTER TABLE `ARTICOLO` ADD COLUMN `flgContoVendita` INTEGER;

# ---------------------------------------------------------------------- #
# Alter table "ARTICOLO"                                                 #
# ---------------------------------------------------------------------- #


ALTER TABLE `ARTICOLO` ADD COLUMN `descrizioneSearch` varchar(254);


CREATE INDEX `IDX_ARTICOLO_8` ON `ARTICOLO` (`descrizioneSearch`);



# ---------------------------------------------------------------------- #

ALTER TABLE `ARTICOLO` ADD COLUMN `flgInEsaurimento` INTEGER;
# ---------------------------------------------------------------------- #
# Alter table "TABLE_DESC"                                               #
# ---------------------------------------------------------------------- #

ALTER TABLE `TABLE_DESC` ADD COLUMN `valoreDefaultCR` VARCHAR(40);



# ---------------------------------------------------------------------- #
# Alter table "ARTICOLO"                                                 #
# ---------------------------------------------------------------------- #

ALTER TABLE `ARTICOLO` ADD COLUMN `descrizioneSearchFT` VARCHAR(254);

CREATE FULLTEXT INDEX `IDX_ARTICOLO_9` ON `ARTICOLO` (`descrizioneSearchFT`);


# ---------------------------------------------------------------------- #
# Alter table "ARTICOLO"                                                 #
# ---------------------------------------------------------------------- #

ALTER TABLE `ARTICOLO` ADD COLUMN `idTipoSearch` VARCHAR(400);

CREATE INDEX `IDX_ARTICOLO_10` ON `ARTICOLO` (`idTipoSearch`);


# ---------------------------------------------------------------------- #
# Alter table "ARTICOLO"                                                 #
# ---------------------------------------------------------------------- #

ALTER TABLE `ARTICOLO` ADD COLUMN `tipoOrdineSearch` INTEGER;

ALTER TABLE `ARTICOLO` ADD COLUMN `tipoDescrizioneSearch` VARCHAR(60);


CREATE INDEX `IDX_ARTICOLO_11` ON `ARTICOLO` (`tipoOrdineSearch` ASC);

CREATE INDEX `IDX_ARTICOLO_12` ON `ARTICOLO` (`tipoDescrizioneSearch` ASC);




