###### atelier ######
### 102
ALTER TABLE `DOCUMENTO` MODIFY `eMailDocumento` VARCHAR(254);
### 103
# ---------------------------------------------------------------------- #
# Add table "MAIL_NEWSLETTER"                                            #
# ---------------------------------------------------------------------- #

CREATE TABLE `MAIL_NEWSLETTER` (
    `id_mailNewsletter` INTEGER NOT NULL AUTO_INCREMENT,
    `indirizzo` VARCHAR(255),
    CONSTRAINT `PK_MAIL_NEWSLETTER` PRIMARY KEY (`id_mailNewsletter`)
);

# ---------------------------------------------------------------------- #
# Modify table "MAIL_NEWSLETTER"                                         #
# ---------------------------------------------------------------------- #

ALTER TABLE `MAIL_NEWSLETTER` ADD COLUMN `id_templateMsg` INTEGER;

ALTER TABLE `MAIL_NEWSLETTER` ADD COLUMN `dataTemplate` DATE;

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

#ALTER TABLE `MAIL_NEWSLETTER` ADD CONSTRAINT `TEMPLATE_MSG_MAIL_NEWSLETTER` 
#    FOREIGN KEY (`id_templateMsg`) REFERENCES `TEMPLATE_MSG` (`id_templateMsg`);
### 104


# ---------------------------------------------------------------------- #
# Modify table "ARTICOLO"                                                #
# ---------------------------------------------------------------------- #

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

# ---------------------------------------------------------------------- #
# Modify table "ARTICOLO_VARIANTE"                                       #
# ---------------------------------------------------------------------- #

ALTER TABLE `ARTICOLO_VARIANTE` ADD COLUMN `flgDispo` INTEGER;

# ---------------------------------------------------------------------- #
# Modify table "ARTICOLO_TAGLIA"                                         #
# ---------------------------------------------------------------------- #

ALTER TABLE `ARTICOLO_TAGLIA` ADD COLUMN `flgDispo` INTEGER;

### 105

# ---------------------------------------------------------------------- #
# Modify table "MOVIMENTO"                                               #
# ---------------------------------------------------------------------- #

ALTER TABLE `MOVIMENTO` ADD COLUMN `id_causaleMagazzino` INTEGER;

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

ALTER TABLE `MOVIMENTO` ADD CONSTRAINT `CAUSALE_MAGAZZINO_MOVIMENTO` 
    FOREIGN KEY (`id_causaleMagazzino`) REFERENCES `CAUSALE_MAGAZZINO` (`id_causaleMagazzino`);

### 106

ALTER TABLE `RIGA_DOCUMENTO` ADD COLUMN `qtaSlipStampate` INTEGER;

update RIGA_DOCUMENTO set qtaSlipStampate = quantita where flgStampaSlip=1;

# ---------------------------------------------------------------------- #
# Modify table "ARTICOLO"                                                #
# ---------------------------------------------------------------------- #

ALTER TABLE `ARTICOLO` ADD COLUMN `abbuonoPrezzoPubblico` DECIMAL(18,4);

# ---------------------------------------------------------------------- #
# Modify table "RIGA_DOCUMENTO"                                          #
# ---------------------------------------------------------------------- #

ALTER TABLE `RIGA_DOCUMENTO` DROP COLUMN `flgStampaSlip`;



ALTER TABLE `MOVIMENTO` ADD COLUMN `dataMovimento` DATE;



### 107

ALTER TABLE `MAIL_NEWSLETTER` ADD COLUMN `eMail` VARCHAR(255);

UPDATE MAIL_NEWSLETTER set eMail=indirizzo;

ALTER TABLE `MAIL_NEWSLETTER` DROP COLUMN `indirizzo`;

CREATE UNIQUE INDEX `IDX_MAIL_NEWSLETTER_1` ON `MAIL_NEWSLETTER` (`eMail`);
DROP INDEX `IDX_CODA_MESSAGGI_1` ON `CODA_MESSAGGI`;

DROP INDEX `IDX_CODA_MESSAGGI_2` ON `CODA_MESSAGGI`;

DROP INDEX `IDX_CODA_MESSAGGI_3` ON `CODA_MESSAGGI`;
### 108
# ---------------------------------------------------------------------- #
# Modify table "DOCUMENTO"                                               #
# ---------------------------------------------------------------------- #

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

ALTER TABLE `DOCUMENTO` ADD COLUMN `ipDownload` VARCHAR(254);

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

### 109


# ---------------------------------------------------------------------- #
# Drop foreign key constraints                                           #
# ---------------------------------------------------------------------- #

ALTER TABLE `USERS` DROP FOREIGN KEY `USER_PROFILE_USERS`;

ALTER TABLE `USERS` DROP FOREIGN KEY `POSTAZIONE_USERS`;

ALTER TABLE `USERS` DROP FOREIGN KEY `CLIFOR_USERS`;

ALTER TABLE `USER_ACCESS` DROP FOREIGN KEY `ACCESS_USER_ACCESS`;

ALTER TABLE `USER_ACCESS` DROP FOREIGN KEY `USERS_USER_ACCESS`;

ALTER TABLE `USER_ACCESS` DROP FOREIGN KEY `DITTA_USER_ACCESS`;

ALTER TABLE `LOG` DROP FOREIGN KEY `USERS_LOG`;

ALTER TABLE `LOG` DROP FOREIGN KEY `BLACKLIST_LOG`;

ALTER TABLE `LOG` DROP FOREIGN KEY `DITTA_LOG`;

ALTER TABLE `ACCESS_GROUP` DROP FOREIGN KEY `DITTA_ACCESS_GROUP`;

ALTER TABLE `NEWS` DROP FOREIGN KEY `TIPO_NEWS_NEWS`;

ALTER TABLE `BLACKLIST` DROP FOREIGN KEY `DITTA_BLACKLIST`;

ALTER TABLE `POSTAZIONE` DROP FOREIGN KEY `REG_CASSA_POSTAZIONE`;

ALTER TABLE `POSTAZIONE` DROP FOREIGN KEY `TIPO_POSTAZIONE_POSTAZIONE`;

ALTER TABLE `POSTAZIONE` DROP FOREIGN KEY `DITTA_POSTAZIONE`;

ALTER TABLE `WHITELIST` DROP FOREIGN KEY `DITTA_WHITELIST`;

ALTER TABLE `TIPO_POSTAZIONE` DROP FOREIGN KEY `DITTA_TIPO_POSTAZIONE`;

ALTER TABLE `USER_DITTA` DROP FOREIGN KEY `DITTA_USER_DITTA`;

ALTER TABLE `USER_DITTA` DROP FOREIGN KEY `USERS_USER_DITTA`;

ALTER TABLE `USER_DITTA` DROP FOREIGN KEY `USER_PROFILE_USER_DITTA`;

ALTER TABLE `ACCESS_DITTA` DROP FOREIGN KEY `ACCESS_ACCESS_DITTA`;

ALTER TABLE `ACCESS_DITTA` DROP FOREIGN KEY `DITTA_ACCESS_DITTA`;

ALTER TABLE `PARM_DITTA` DROP FOREIGN KEY `PARM_PARM_DITTA`;

ALTER TABLE `PARM_DITTA` DROP FOREIGN KEY `DITTA_PARM_DITTA`;

ALTER TABLE `USER_ACCESS_GROUP` DROP FOREIGN KEY `ACCESS_GROUP_USER_ACCESS_GROUP`;

ALTER TABLE `USER_ACCESS_GROUP` DROP FOREIGN KEY `USERS_USER_ACCESS_GROUP`;

ALTER TABLE `ACCESS_GROUP_ACCESS` DROP FOREIGN KEY `ACCESS_ACCESS_GROUP_ACCESS`;

ALTER TABLE `ACCESS_GROUP_ACCESS` DROP FOREIGN KEY `ACCESS_GROUP_ACCESS_GROUP_ACCESS`;

ALTER TABLE `CLIFOR_USERS` DROP FOREIGN KEY `USERS_CLIFOR_USERS`;

ALTER TABLE `ALLEGATO_NEWS` DROP FOREIGN KEY `NEWS_ALLEGATO_NEWS`;

ALTER TABLE `SPESA` DROP FOREIGN KEY `USERS_SPESA`;

ALTER TABLE `USER_WHITELIST` DROP FOREIGN KEY `WHITELIST_USER_WHITELIST`;

ALTER TABLE `USER_WHITELIST` DROP FOREIGN KEY `USERS_USER_WHITELIST`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `USERS_DOCUMENTO_interv`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `USERS_DOCUMENTO_chiusura`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `USERS_DOCUMENTO`;

# ---------------------------------------------------------------------- #
# Drop table "ACCESS_DITTA"                                              #
# ---------------------------------------------------------------------- #

# Remove autoinc for PK drop #

ALTER TABLE `ACCESS_DITTA` MODIFY `id_accessDitta` INTEGER NOT NULL;

# Drop constraints #

ALTER TABLE `ACCESS_DITTA` DROP PRIMARY KEY;

# Drop table #

DROP TABLE `ACCESS_DITTA`;

# ---------------------------------------------------------------------- #
# Drop table "PARM_DITTA"                                                #
# ---------------------------------------------------------------------- #

# Remove autoinc for PK drop #

ALTER TABLE `PARM_DITTA` MODIFY `id_parmDitta` INTEGER NOT NULL;

# Drop constraints #

ALTER TABLE `PARM_DITTA` DROP PRIMARY KEY;

# Drop table #

DROP TABLE `PARM_DITTA`;

# ---------------------------------------------------------------------- #
# Modify table "USERS"                                                   #
# ---------------------------------------------------------------------- #

ALTER TABLE `USERS` ADD COLUMN `flgNews` INTEGER;

# ---------------------------------------------------------------------- #
# Modify table "ACCESS"                                                  #
# ---------------------------------------------------------------------- #

ALTER TABLE `ACCESS` DROP COLUMN `flgCondivisa`;

ALTER TABLE `ACCESS` ADD COLUMN `versione` VARCHAR(20);

# ---------------------------------------------------------------------- #
# Modify table "USER_ACCESS"                                             #
# ---------------------------------------------------------------------- #

DROP INDEX `IDX_USER_ACCESS_1` ON `USER_ACCESS`;

ALTER TABLE `USER_ACCESS` DROP COLUMN `id_ditta`;

CREATE UNIQUE INDEX `IDX_USER_ACCESS_1` ON `USER_ACCESS` (`id_users`,`id_access`);

# ---------------------------------------------------------------------- #
# Modify table "LOG"                                                     #
# ---------------------------------------------------------------------- #

ALTER TABLE `LOG` DROP COLUMN `id_ditta`;

# ---------------------------------------------------------------------- #
# Modify table "ACCESS_GROUP"                                            #
# ---------------------------------------------------------------------- #

ALTER TABLE `ACCESS_GROUP` DROP COLUMN `id_ditta`;

# ---------------------------------------------------------------------- #
# Modify table "NEWS"                                                    #
# ---------------------------------------------------------------------- #

ALTER TABLE `NEWS` ADD COLUMN `dataInvio` DATE;

# ---------------------------------------------------------------------- #
# Modify table "BLACKLIST"                                               #
# ---------------------------------------------------------------------- #

ALTER TABLE `BLACKLIST` DROP COLUMN `id_ditta`;

# ---------------------------------------------------------------------- #
# Modify table "POSTAZIONE"                                              #
# ---------------------------------------------------------------------- #

ALTER TABLE `POSTAZIONE` DROP COLUMN `id_ditta`;

# ---------------------------------------------------------------------- #
# Modify table "WHITELIST"                                               #
# ---------------------------------------------------------------------- #

ALTER TABLE `WHITELIST` DROP COLUMN `id_ditta`;

# ---------------------------------------------------------------------- #
# Modify table "TIPO_POSTAZIONE"                                         #
# ---------------------------------------------------------------------- #

ALTER TABLE `TIPO_POSTAZIONE` DROP COLUMN `id_ditta`;

# ---------------------------------------------------------------------- #
# Modify table "DITTA"                                                   #
# ---------------------------------------------------------------------- #

ALTER TABLE `DITTA` DROP COLUMN `nome`;

ALTER TABLE `DITTA` DROP COLUMN `indirizzo`;

ALTER TABLE `DITTA` DROP COLUMN `numeroCivico`;

ALTER TABLE `DITTA` DROP COLUMN `descrizioneComune`;

ALTER TABLE `DITTA` DROP COLUMN `provinciaComune`;

ALTER TABLE `DITTA` DROP COLUMN `capComune`;

ALTER TABLE `DITTA` DROP COLUMN `capZona`;

ALTER TABLE `DITTA` DROP COLUMN `descrizioneNazione`;

ALTER TABLE `DITTA` DROP COLUMN `codFisc`;

ALTER TABLE `DITTA` DROP COLUMN `pIva`;

ALTER TABLE `DITTA` DROP COLUMN `eMail`;

ALTER TABLE `DITTA` DROP COLUMN `eMailAmm`;

ALTER TABLE `DITTA` DROP COLUMN `cellulare`;

ALTER TABLE `DITTA` DROP COLUMN `telefono`;

ALTER TABLE `DITTA` DROP COLUMN `telefonoAmm`;

ALTER TABLE `DITTA` DROP COLUMN `fax`;

ALTER TABLE `DITTA` DROP COLUMN `nota`;

ALTER TABLE `DITTA` DROP COLUMN `imgTmst`;

ALTER TABLE `DITTA` DROP COLUMN `lastUpdTmst`;

ALTER TABLE `DITTA` DROP COLUMN `lastUpdId_user`;

ALTER TABLE `DITTA` ADD COLUMN `database` VARCHAR(40);

ALTER TABLE `DITTA` ADD COLUMN `user` VARCHAR(40);

ALTER TABLE `DITTA` ADD COLUMN `pwd` VARCHAR(40);

ALTER TABLE `DITTA` ADD COLUMN `initalCons` INTEGER;

ALTER TABLE `DITTA` ADD COLUMN `maxCons` INTEGER;

ALTER TABLE `DITTA` ADD COLUMN `timeout` INTEGER;

ALTER TABLE `DITTA` CHANGE `cognome` `descrizione` VARCHAR(254);

# ---------------------------------------------------------------------- #
# Modify table "USER_DITTA"                                              #
# ---------------------------------------------------------------------- #

DROP INDEX `IDX_USER_DITTA_1` ON `USER_DITTA`;

ALTER TABLE `USER_DITTA` DROP COLUMN `id_userProfile`;

ALTER TABLE `USER_DITTA` MODIFY `id_ditta` INTEGER;

ALTER TABLE `USER_DITTA` MODIFY `id_users` INTEGER;



# ---------------------------------------------------------------------- #
# Add table "USER_CLIFOR"                                                #
# ---------------------------------------------------------------------- #

CREATE TABLE `USER_CLIFOR` (
    `id_userClifor` INTEGER NOT NULL AUTO_INCREMENT,
    `id_users` INTEGER,
    `id_clifor` INTEGER,
    CONSTRAINT `PK_USER_CLIFOR` PRIMARY KEY (`id_userClifor`)
);

# ---------------------------------------------------------------------- #
# Add table "NEWS_USERS"                                                 #
# ---------------------------------------------------------------------- #

CREATE TABLE `NEWS_USERS` (
    `id_newsUsers` INTEGER NOT NULL AUTO_INCREMENT,
    `id_news` INTEGER,
    `id_users` INTEGER,
    `tmstInvio` TIMESTAMP,
    CONSTRAINT `PK_NEWS_USERS` PRIMARY KEY (`id_newsUsers`)
);

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

ALTER TABLE `USERS` ADD CONSTRAINT `USER_PROFILE_USERS` 
    FOREIGN KEY (`id_userProfile`) REFERENCES `USER_PROFILE` (`id_userProfile`);

ALTER TABLE `USERS` ADD CONSTRAINT `POSTAZIONE_USERS` 
    FOREIGN KEY (`id_postazione`) REFERENCES `POSTAZIONE` (`id_postazione`);

ALTER TABLE `USERS` ADD CONSTRAINT `CLIFOR_USERS` 
    FOREIGN KEY (`id_clifor`) REFERENCES `CLIFOR` (`id_clifor`);

ALTER TABLE `USER_ACCESS` ADD CONSTRAINT `ACCESS_USER_ACCESS` 
    FOREIGN KEY (`id_access`) REFERENCES `ACCESS` (`id_access`);

ALTER TABLE `USER_ACCESS` ADD CONSTRAINT `USERS_USER_ACCESS` 
    FOREIGN KEY (`id_users`) REFERENCES `USERS` (`id_users`);

ALTER TABLE `LOG` ADD CONSTRAINT `USERS_LOG` 
    FOREIGN KEY (`id_users`) REFERENCES `USERS` (`id_users`);

ALTER TABLE `LOG` ADD CONSTRAINT `BLACKLIST_LOG` 
    FOREIGN KEY (`id_blacklist`) REFERENCES `BLACKLIST` (`id_blacklist`);

ALTER TABLE `NEWS` ADD CONSTRAINT `TIPO_NEWS_NEWS` 
    FOREIGN KEY (`id_tipoNews`) REFERENCES `TIPO_NEWS` (`id_tipoNews`);

ALTER TABLE `POSTAZIONE` ADD CONSTRAINT `REG_CASSA_POSTAZIONE` 
    FOREIGN KEY (`id_regCassa`) REFERENCES `REG_CASSA` (`id_regCassa`);

ALTER TABLE `POSTAZIONE` ADD CONSTRAINT `TIPO_POSTAZIONE_POSTAZIONE` 
    FOREIGN KEY (`id_tipoPostazione`) REFERENCES `TIPO_POSTAZIONE` (`id_tipoPostazione`);

ALTER TABLE `USER_DITTA` ADD CONSTRAINT `DITTA_USER_DITTA` 
    FOREIGN KEY (`id_ditta`) REFERENCES `DITTA` (`id_ditta`);

ALTER TABLE `USER_DITTA` ADD CONSTRAINT `USERS_USER_DITTA` 
    FOREIGN KEY (`id_users`) REFERENCES `USERS` (`id_users`);

#*#ALTER TABLE `USER_CLIFOR` ADD CONSTRAINT `USERS_USER_CLIFOR` 
#    FOREIGN KEY (`id_users`) REFERENCES `USERS` (`id_users`);

#*#ALTER TABLE `USER_CLIFOR` ADD CONSTRAINT `CLIFOR_USER_CLIFOR` 
#    FOREIGN KEY (`id_clifor`) REFERENCES `CLIFOR` (`id_clifor`);

#*#ALTER TABLE `NEWS_USERS` ADD CONSTRAINT `NEWS_NEWS_USERS` 
#    FOREIGN KEY (`id_news`) REFERENCES `NEWS` (`id_news`);

#*#ALTER TABLE `NEWS_USERS` ADD CONSTRAINT `USERS_NEWS_USERS` 
#    FOREIGN KEY (`id_users`) REFERENCES `USERS` (`id_users`);

ALTER TABLE `USER_ACCESS_GROUP` ADD CONSTRAINT `ACCESS_GROUP_USER_ACCESS_GROUP` 
    FOREIGN KEY (`id_accessGroup`) REFERENCES `ACCESS_GROUP` (`id_accessGroup`);

ALTER TABLE `USER_ACCESS_GROUP` ADD CONSTRAINT `USERS_USER_ACCESS_GROUP` 
    FOREIGN KEY (`id_users`) REFERENCES `USERS` (`id_users`);

ALTER TABLE `ACCESS_GROUP_ACCESS` ADD CONSTRAINT `ACCESS_ACCESS_GROUP_ACCESS` 
    FOREIGN KEY (`id_access`) REFERENCES `ACCESS` (`id_access`);

ALTER TABLE `ACCESS_GROUP_ACCESS` ADD CONSTRAINT `ACCESS_GROUP_ACCESS_GROUP_ACCESS` 
    FOREIGN KEY (`id_accessGroup`) REFERENCES `ACCESS_GROUP` (`id_accessGroup`);

ALTER TABLE `CLIFOR_USERS` ADD CONSTRAINT `USERS_CLIFOR_USERS` 
    FOREIGN KEY (`id_users`) REFERENCES `USERS` (`id_users`);

ALTER TABLE `ALLEGATO_NEWS` ADD CONSTRAINT `NEWS_ALLEGATO_NEWS` 
    FOREIGN KEY (`id_news`) REFERENCES `NEWS` (`id_news`);

ALTER TABLE `SPESA` ADD CONSTRAINT `USERS_SPESA` 
    FOREIGN KEY (`id_users`) REFERENCES `USERS` (`id_users`);

ALTER TABLE `USER_WHITELIST` ADD CONSTRAINT `WHITELIST_USER_WHITELIST` 
    FOREIGN KEY (`id_whitelist`) REFERENCES `WHITELIST` (`id_whitelist`);

ALTER TABLE `USER_WHITELIST` ADD CONSTRAINT `USERS_USER_WHITELIST` 
    FOREIGN KEY (`id_users`) REFERENCES `USERS` (`id_users`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `USERS_DOCUMENTO_interv` 
    FOREIGN KEY (`id_usersIntervento`) REFERENCES `USERS` (`id_users`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `USERS_DOCUMENTO_chiusura` 
    FOREIGN KEY (`id_usersChiusura`) REFERENCES `USERS` (`id_users`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `USERS_DOCUMENTO` 
    FOREIGN KEY (`id_users`) REFERENCES `USERS` (`id_users`);

update USERS set flgNews=1;
### 110

ALTER TABLE `ARTICOLO_VARIANTE` ADD COLUMN `flgInAggiornamento` INTEGER;


### 111
ALTER TABLE `ARTICOLO` ADD COLUMN `quantitaMagazzinoMovimentoHtml` VARCHAR(254);


### 112


# ---------------------------------------------------------------------- #
# Modify table "USERS"                                                   #
# ---------------------------------------------------------------------- #

ALTER TABLE `USERS` ADD COLUMN `imgProfilo` VARCHAR(30);

# ---------------------------------------------------------------------- #
# Modify table "RIGA_DOCUMENTO"                                          #
# ---------------------------------------------------------------------- #

ALTER TABLE `RIGA_DOCUMENTO` ADD COLUMN `statoPrenotazione` INTEGER;

UPDATE RIGA_DOCUMENTO set statoPrenotazione =-1;


### 113

ALTER TABLE `DOCUMENTO` ADD COLUMN `tmstStampato` VARCHAR(60);

ALTER TABLE `TIPO_PAGAMENTO` ADD COLUMN `flgIncassoPagamento` INTEGER;

CREATE TABLE `INCASSO_PAGAMENTO` (
    `id_incassoPagamento` INTEGER NOT NULL AUTO_INCREMENT,
    `dataIP` DATE,
    `importoIP` DECIMAL(18,4),
    `notaIP` TEXT,
    `id_documento` INTEGER,
    `id_movimento` INTEGER,
    CONSTRAINT `PK_INCASSO_PAGAMENTO` PRIMARY KEY (`id_incassoPagamento`)
);

#*#ALTER TABLE `INCASSO_PAGAMENTO` ADD CONSTRAINT `DOCUMENTO_INCASSO_PAGAMENTO` 
#    FOREIGN KEY (`id_documento`) REFERENCES `DOCUMENTO` (`id_documento`);

#*#ALTER TABLE `INCASSO_PAGAMENTO` ADD CONSTRAINT `MOVIMENTO_INCASSO_PAGAMENTO` 
#    FOREIGN KEY (`id_movimento`) REFERENCES `MOVIMENTO` (`id_movimento`);

### 114

# ---------------------------------------------------------------------- #
# Modify table "USERS"                                                   #
# ---------------------------------------------------------------------- #

ALTER TABLE `USERS` ADD COLUMN `cittaNascita` VARCHAR(30);

ALTER TABLE `USERS` ADD COLUMN `provinciaNascita` VARCHAR(4);

# ---------------------------------------------------------------------- #
# Modify table "TIPO_DOCUMENTO"                                          #
# ---------------------------------------------------------------------- #

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

# ---------------------------------------------------------------------- #
# Modify table "DITTA"                                                   #
# ---------------------------------------------------------------------- #

ALTER TABLE `DITTA` ADD COLUMN `reuseCons` INTEGER;

ALTER TABLE `DITTA` ADD COLUMN `maxConnectionHits` INTEGER;

ALTER TABLE `DITTA` ADD COLUMN `connectionLifeTime` INTEGER;

ALTER TABLE `DITTA` ADD COLUMN `dbDriver` INTEGER;

### 115

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

ALTER TABLE `CLIFOR` MODIFY `capZona` VARCHAR(10);


### 116
# ---------------------------------------------------------------------- #
# Add table "BANCA"                                                      #
# ---------------------------------------------------------------------- #

CREATE TABLE `BANCA` (
    `id_banca` INTEGER NOT NULL AUTO_INCREMENT,
     `id_abiCab` INTEGER ,
    `id_comune` INTEGER,
    `descrizione` VARCHAR(60),
    `iban` CHAR(27),
    `indirizzo` VARCHAR(60),
    `telefono` VARCHAR(30),
    `email` VARCHAR(30),
    `bic` VARCHAR(30),
    `capZona` VARCHAR(10),
    CONSTRAINT `PK_BANCA` PRIMARY KEY (`id_banca`)
);

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

ALTER TABLE `BANCA` ADD CONSTRAINT `COMUNE_BANCA` 
    FOREIGN KEY (`id_comune`) REFERENCES `COMUNE` (`id_comune`);

### 117

ALTER TABLE `DOCUMENTO` ADD COLUMN `oraDownload` TIME;

### 118
# ---------------------------------------------------------------------- #
# Add table "DOCUMENTO_PAGAMENTO"                                        #
# ---------------------------------------------------------------------- #

CREATE TABLE `DOCUMENTO_PAGAMENTO` (
    `id_documentoPagamento` INTEGER NOT NULL AUTO_INCREMENT,
    `id_documento` INTEGER,
    `data` DATE,
    `importo` DECIMAL(18,4),
    `nota` VARCHAR(254),
    CONSTRAINT `PK_DOCUMENTO_PAGAMENTO` PRIMARY KEY (`id_documentoPagamento`)
);


#*#ALTER TABLE `DOCUMENTO_PAGAMENTO` ADD CONSTRAINT `DOCUMENTO_DOCUMENTO_PAGAMENTO` 
#    FOREIGN KEY (`id_documento`) REFERENCES `DOCUMENTO` (`id_documento`);
	
# ---------------------------------------------------------------------- #
# Drop foreign key constraints                                           #
# ---------------------------------------------------------------------- #

##ALTER TABLE `DOCUMENTO_PAGAMENTO` DROP FOREIGN KEY `DOCUMENTO_DOCUMENTO_PAGAMENTO`;

# ---------------------------------------------------------------------- #
# Modify table "DOCUMENTO_PAGAMENTO"                                     #
# ---------------------------------------------------------------------- #

ALTER TABLE `DOCUMENTO_PAGAMENTO` ADD COLUMN `id_tipoPagamento` INTEGER;

ALTER TABLE `DOCUMENTO_PAGAMENTO` ADD COLUMN `tipoMovimento` INTEGER;

ALTER TABLE `DOCUMENTO_PAGAMENTO` MODIFY `id_tipoPagamento` INTEGER AFTER `id_documento`;

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

#*#ALTER TABLE `DOCUMENTO_PAGAMENTO` ADD CONSTRAINT `DOCUMENTO_DOCUMENTO_PAGAMENTO` 
##    FOREIGN KEY (`id_documento`) REFERENCES `DOCUMENTO` (`id_documento`);

#*#ALTER TABLE `DOCUMENTO_PAGAMENTO` ADD CONSTRAINT `TIPO_PAGAMENTO_DOCUMENTO_PAGAMENTO` 
##    FOREIGN KEY (`id_tipoPagamento`) REFERENCES `TIPO_PAGAMENTO` (`id_tipoPagamento`);


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

ALTER TABLE `DOCUMENTO` ADD COLUMN `bic` VARCHAR(30);


### 120

# ---------------------------------------------------------------------- #
# Modify table "ARTICOLO_VARIANTE"                                       #
# ---------------------------------------------------------------------- #

ALTER TABLE `ARTICOLO_VARIANTE` ADD COLUMN `quantitaMagazzinoMovimentoHtml` VARCHAR(254);

### 121

ALTER TABLE `ARTICOLO` ADD COLUMN `quantitaW` DOUBLE;

ALTER TABLE `ARTICOLO` ADD COLUMN `quantitaImpegnata` DOUBLE;

ALTER TABLE `ARTICOLO` ADD COLUMN `quantitaInArrivo` DOUBLE;

ALTER TABLE `ARTICOLO` ADD COLUMN `quantitaCalcolate` BOOL;
### 122


# ---------------------------------------------------------------------- #
# Modify table "TIPO_DOCUMENTO"                                          #
# ---------------------------------------------------------------------- #

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

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

ALTER TABLE `TIPO_DOCUMENTO` ADD COLUMN `coloreBordoEsterno` CHAR(7);

ALTER TABLE `TIPO_DOCUMENTO` ADD COLUMN `coloreBordoInterno` CHAR(7);

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

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

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

### 123

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

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

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `BANCA_DOCUMENTO_ANTICIPO` 
    FOREIGN KEY (`id_bancaAnticipo`) REFERENCES `BANCA` (`id_banca`);


### 124
# ---------------------------------------------------------------------- #
# Modify table "NEWS"                                                    #
# ---------------------------------------------------------------------- #

ALTER TABLE `NEWS` ADD COLUMN `dataFine` DATE;



### 125
# ---------------------------------------------------------------------- #
# Modify table "DOCUMENTO"                                               #
# ---------------------------------------------------------------------- #
#non sono sicuro di averlo messo!! da verificare
ALTER TABLE `DOCUMENTO` ADD COLUMN `flgHasDocumentiPrelevabili` INTEGER;

### 126


ALTER TABLE `DOCUMENTO_PAGAMENTO` ADD COLUMN `flgTipoIncasso` INTEGER;

### 127


ALTER TABLE `TIPO_DOCUMENTO` ADD COLUMN `riferimento` VARCHAR(40);

### 128

# ---------------------------------------------------------------------- #
# Modify table "USERS"                                                   #
# ---------------------------------------------------------------------- #

ALTER TABLE `USERS` ADD COLUMN `flgSuper` INTEGER;

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

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


ALTER TABLE `WHITELIST` ADD COLUMN `flgAttivo` INTEGER;


# ---------------------------------------------------------------------- #
# Modify table "USERS"                                                   #
# ---------------------------------------------------------------------- #

ALTER TABLE `USERS` ADD COLUMN `elencoIpAbilitati` VARCHAR(254);


##default allegato clifor
ALTER TABLE ALLEGATO_CLIFOR ADD COLUMN  flgDefault integer;
### 129
# Modify table "USERS"                                                   #
# ---------------------------------------------------------------------- #

ALTER TABLE `USERS` ADD COLUMN `pwdSuper` VARCHAR(30);

ALTER TABLE `USERS` DROP COLUMN `flgSuper`;

### 130
# ---------------------------------------------------------------------- #
# 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:            2015-09-25 15:34                                #
# ---------------------------------------------------------------------- #


# ---------------------------------------------------------------------- #
# Drop foreign key constraints                                           #
# ---------------------------------------------------------------------- #

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `TIPO_DOCUMENTO_DOCUMENTO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `VETTORE_DOCUMENTO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `TIPO_PAGAMENTO_DOCUMENTO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `CLIFOR_DOCUMENTO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `ASPETTO_DOCUMENTO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `ESERCIZIO_DOCUMENTO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `DOCUMENTO_DOCUMENTO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `COMUNE_DOCUMENTO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `CAUSALE_TRASPORTO_DOCUMENTO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `DESTINAZIONE_DIVERSA_DOCUMENTO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `USERS_DOCUMENTO_interv`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `USERS_DOCUMENTO_chiusura`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `USERS_DOCUMENTO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `PORTO_DOCUMENTO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `CONTATORE_DOCUMENTO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `CLIFOR_DOCUMENTO_LISTINO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `IVA_DOCUMENTO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `MAG_FISICO_DOCUMENTO_PARTENZA_PARTENZA`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `MAG_FISICO_DOCUMENTO_ARRIVO_ARRIVO`;

ALTER TABLE `DOCUMENTO` DROP FOREIGN KEY `BANCA_DOCUMENTO_ANTICIPO`;

ALTER TABLE `RIGA_DOCUMENTO` DROP FOREIGN KEY `DOCUMENTO_RIGA_DOCUMENTO`;

ALTER TABLE `DOC_FIGLIO_PADRE` DROP FOREIGN KEY `DOCUMENTO_DOC_FIGLIO_PADRE_PADRE`;

ALTER TABLE `DOC_FIGLIO_PADRE` DROP FOREIGN KEY `DOCUMENTO_DOC_FIGLIO_PADRE_figlio`;

ALTER TABLE `ALLEGATO_DOCUMENTO` DROP FOREIGN KEY `DOCUMENTO_ALLEGATO_DOCUMENTO`;

ALTER TABLE `RIGA_DOCUMENTO` DROP FOREIGN KEY `DOCUMENTOpadre_RIGA_DOCUMENTO`;

ALTER TABLE `DOCUMENTO_AGENTE` DROP FOREIGN KEY `DOCUMENTO_DOCUMENTO_AGENTE`;

#*#ALTER TABLE `INCASSO_PAGAMENTO` DROP FOREIGN KEY `DOCUMENTO_INCASSO_PAGAMENTO`;

#*#ALTER TABLE `DOCUMENTO_PAGAMENTO` DROP FOREIGN KEY `DOCUMENTO_DOCUMENTO_PAGAMENTO`;

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

DROP INDEX `IDX_DOCUMENTO_1` ON `DOCUMENTO`;

ALTER TABLE `DOCUMENTO` MODIFY `id_contatore` INTEGER NOT NULL;

CREATE UNIQUE INDEX `IDX_DOCUMENTO_1` ON `DOCUMENTO` (`progDocumento` ASC,`id_contatore` ASC,`id_esercizio` ASC,`flgStato` ASC,`progDocumentoAgg` ASC);

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

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `TIPO_DOCUMENTO_DOCUMENTO` 
    FOREIGN KEY (`id_tipoDocumento`) REFERENCES `TIPO_DOCUMENTO` (`id_tipoDocumento`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `VETTORE_DOCUMENTO` 
    FOREIGN KEY (`id_vettore`) REFERENCES `VETTORE` (`id_vettore`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `TIPO_PAGAMENTO_DOCUMENTO` 
    FOREIGN KEY (`id_tipoPagamento`) REFERENCES `TIPO_PAGAMENTO` (`id_tipoPagamento`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `CLIFOR_DOCUMENTO` 
    FOREIGN KEY (`id_clifor`) REFERENCES `CLIFOR` (`id_clifor`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `ASPETTO_DOCUMENTO` 
    FOREIGN KEY (`id_aspetto`) REFERENCES `ASPETTO` (`id_aspetto`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `ESERCIZIO_DOCUMENTO` 
    FOREIGN KEY (`id_esercizio`) REFERENCES `ESERCIZIO` (`id_esercizio`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `DOCUMENTO_DOCUMENTO` 
    FOREIGN KEY (`id_documentoFiglio`) REFERENCES `DOCUMENTO` (`id_documento`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `COMUNE_DOCUMENTO` 
    FOREIGN KEY (`id_comuneSped`) REFERENCES `COMUNE` (`id_comune`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `CAUSALE_TRASPORTO_DOCUMENTO` 
    FOREIGN KEY (`id_causaleTrasporto`) REFERENCES `CAUSALE_TRASPORTO` (`id_causaleTrasporto`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `DESTINAZIONE_DIVERSA_DOCUMENTO` 
    FOREIGN KEY (`id_destinazioneDiversa`) REFERENCES `DESTINAZIONE_DIVERSA` (`id_destinazioneDiversa`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `USERS_DOCUMENTO_interv` 
    FOREIGN KEY (`id_usersIntervento`) REFERENCES `USERS` (`id_users`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `USERS_DOCUMENTO_chiusura` 
    FOREIGN KEY (`id_usersChiusura`) REFERENCES `USERS` (`id_users`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `USERS_DOCUMENTO` 
    FOREIGN KEY (`id_users`) REFERENCES `USERS` (`id_users`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `PORTO_DOCUMENTO` 
    FOREIGN KEY (`id_porto`) REFERENCES `PORTO` (`id_porto`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `CONTATORE_DOCUMENTO` 
    FOREIGN KEY (`id_contatore`) REFERENCES `CONTATORE` (`id_contatore`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `CLIFOR_DOCUMENTO_LISTINO` 
    FOREIGN KEY (`id_cliforListino`) REFERENCES `CLIFOR` (`id_clifor`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `IVA_DOCUMENTO` 
    FOREIGN KEY (`id_ivaDoc`) REFERENCES `IVA` (`id_iva`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `MAG_FISICO_DOCUMENTO_PARTENZA_PARTENZA` 
    FOREIGN KEY (`id_magFisicoPartenza`) REFERENCES `MAG_FISICO` (`id_magFisico`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `MAG_FISICO_DOCUMENTO_ARRIVO_ARRIVO` 
    FOREIGN KEY (`id_magFisicoArrivo`) REFERENCES `MAG_FISICO` (`id_magFisico`);

ALTER TABLE `DOCUMENTO` ADD CONSTRAINT `BANCA_DOCUMENTO_ANTICIPO` 
    FOREIGN KEY (`id_bancaAnticipo`) REFERENCES `BANCA` (`id_banca`);

ALTER TABLE `RIGA_DOCUMENTO` ADD CONSTRAINT `DOCUMENTO_RIGA_DOCUMENTO` 
    FOREIGN KEY (`id_documento`) REFERENCES `DOCUMENTO` (`id_documento`);

ALTER TABLE `DOC_FIGLIO_PADRE` ADD CONSTRAINT `DOCUMENTO_DOC_FIGLIO_PADRE_PADRE` 
    FOREIGN KEY (`id_documentoPadre`) REFERENCES `DOCUMENTO` (`id_documento`);

ALTER TABLE `DOC_FIGLIO_PADRE` ADD CONSTRAINT `DOCUMENTO_DOC_FIGLIO_PADRE_figlio` 
    FOREIGN KEY (`id_documentoFiglio`) REFERENCES `DOCUMENTO` (`id_documento`);

ALTER TABLE `ALLEGATO_DOCUMENTO` ADD CONSTRAINT `DOCUMENTO_ALLEGATO_DOCUMENTO` 
    FOREIGN KEY (`id_documento`) REFERENCES `DOCUMENTO` (`id_documento`);

ALTER TABLE `RIGA_DOCUMENTO` ADD CONSTRAINT `DOCUMENTOpadre_RIGA_DOCUMENTO` 
    FOREIGN KEY (`id_documentoPadre`) REFERENCES `DOCUMENTO` (`id_documento`);

ALTER TABLE `DOCUMENTO_AGENTE` ADD CONSTRAINT `DOCUMENTO_DOCUMENTO_AGENTE` 
    FOREIGN KEY (`id_documento`) REFERENCES `DOCUMENTO` (`id_documento`);

#*#ALTER TABLE `INCASSO_PAGAMENTO` ADD CONSTRAINT `DOCUMENTO_INCASSO_PAGAMENTO` 
##   FOREIGN KEY (`id_documento`) REFERENCES `DOCUMENTO` (`id_documento`);

#*#ALTER TABLE `DOCUMENTO_PAGAMENTO` ADD CONSTRAINT `DOCUMENTO_DOCUMENTO_PAGAMENTO` 
##    FOREIGN KEY (`id_documento`) REFERENCES `DOCUMENTO` (`id_documento`);


### 131

# ---------------------------------------------------------------------- #
# Modify table "ARTICOLO"                                                #
# ---------------------------------------------------------------------- #

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

# ---------------------------------------------------------------------- #
# Modify table "BANCA"                                                   #
# ---------------------------------------------------------------------- #

ALTER TABLE `BANCA` MODIFY `email` VARCHAR(60);

### 132
##log su db diverso
### 133
# ---------------------------------------------------------------------- #
# Modify table "LOG"                                                     #
# ---------------------------------------------------------------------- #

#ALTER TABLE `LOG` MODIFY `descrizione` TEXT;

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

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

# ---------------------------------------------------------------------- #
# Modify table "TIPO_DOCUMENTO"                                          #
# ---------------------------------------------------------------------- #

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

# ---------------------------------------------------------------------- #
# Modify table "IVA"                                                     #
# ---------------------------------------------------------------------- #

ALTER TABLE `IVA` ADD COLUMN `id_pianoConti` INTEGER;

# ---------------------------------------------------------------------- #
# Modify table "BANCA"                                                   #
# ---------------------------------------------------------------------- #

ALTER TABLE `BANCA` ADD COLUMN `id_pianoConti` INTEGER;

# ---------------------------------------------------------------------- #
# Add table "PIANO_CONTI"                                                #
# ---------------------------------------------------------------------- #

CREATE TABLE `PIANO_CONTI` (
    `id_pianoConti` INTEGER NOT NULL AUTO_INCREMENT,
    `conto` VARCHAR(40),
    `descrizione` VARCHAR(254),
    `flgTipo` INTEGER,
    `flgCFBI` INTEGER,
    `flgMovimentabile` INTEGER,
    CONSTRAINT `PK_PIANO_CONTI` PRIMARY KEY (`id_pianoConti`)
);

# ---------------------------------------------------------------------- #
# Add table "MOV_CONTABILE"                                              #
# ---------------------------------------------------------------------- #

CREATE TABLE `MOV_CONTABILE` (
    `id_movContabile` INTEGER NOT NULL AUTO_INCREMENT,
    `id_causaleContabile` INTEGER,
    `dataMovContabile` DATE,
    `descrizione` VARCHAR(254),
    `flgStato` INTEGER,
    CONSTRAINT `PK_MOV_CONTABILE` PRIMARY KEY (`id_movContabile`)
);

# ---------------------------------------------------------------------- #
# Add table "RIGA_MOV_CONTABILE"                                         #
# ---------------------------------------------------------------------- #

CREATE TABLE `RIGA_MOV_CONTABILE` (
    `id_rigaMovContabile` INTEGER NOT NULL AUTO_INCREMENT,
    `id_movContabile` INTEGER,
    `importo` DECIMAL(18,4),
    `flgDA` INTEGER,
    `id_pianoConti` INTEGER,
    `id_clifor` INTEGER,
    `id_banca` INTEGER,
    `id_documento` INTEGER,
    `id_iva` INTEGER,
    CONSTRAINT `PK_RIGA_MOV_CONTABILE` PRIMARY KEY (`id_rigaMovContabile`)
);

# ---------------------------------------------------------------------- #
# Add table "CAUSALE_CONTABILE"                                          #
# ---------------------------------------------------------------------- #

CREATE TABLE `CAUSALE_CONTABILE` (
    `id_causaleContabile` INTEGER NOT NULL AUTO_INCREMENT,
    `descrizione` VARCHAR(40),
    CONSTRAINT `PK_CAUSALE_CONTABILE` PRIMARY KEY (`id_causaleContabile`)
);

# ---------------------------------------------------------------------- #
# Add table "RIGA_CAUSALE_CONTABILE"                                     #
# ---------------------------------------------------------------------- #

CREATE TABLE `RIGA_CAUSALE_CONTABILE` (
    `id_rigaCausaleContabile` INTEGER NOT NULL AUTO_INCREMENT,
    `id_causaleContabile` INTEGER,
    `id_pianoConti` INTEGER,
    `flgDA` INTEGER,
    CONSTRAINT `PK_RIGA_CAUSALE_CONTABILE` PRIMARY KEY (`id_rigaCausaleContabile`)
);

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

ALTER TABLE `CLIFOR` ADD CONSTRAINT `PIANO_CONTI_CLIFOR` 
    FOREIGN KEY (`id_pianoConti`) REFERENCES `PIANO_CONTI` (`id_pianoConti`);

ALTER TABLE `TIPO_DOCUMENTO` ADD CONSTRAINT `CAUSALE_CONTABILE_TIPO_DOCUMENTO` 
    FOREIGN KEY (`id_causaleContabile`) REFERENCES `CAUSALE_CONTABILE` (`id_causaleContabile`);

ALTER TABLE `IVA` ADD CONSTRAINT `PIANO_CONTI_IVA` 
    FOREIGN KEY (`id_pianoConti`) REFERENCES `PIANO_CONTI` (`id_pianoConti`);

ALTER TABLE `BANCA` ADD CONSTRAINT `PIANO_CONTI_BANCA` 
    FOREIGN KEY (`id_pianoConti`) REFERENCES `PIANO_CONTI` (`id_pianoConti`);

ALTER TABLE `MOV_CONTABILE` ADD CONSTRAINT `CAUSALE_CONTABILE_MOV_CONTABILE` 
    FOREIGN KEY (`id_causaleContabile`) REFERENCES `CAUSALE_CONTABILE` (`id_causaleContabile`);

ALTER TABLE `RIGA_MOV_CONTABILE` ADD CONSTRAINT `MOV_CONTABILE_RIGA_MOV_CONTABILE` 
    FOREIGN KEY (`id_movContabile`) REFERENCES `MOV_CONTABILE` (`id_movContabile`);

ALTER TABLE `RIGA_MOV_CONTABILE` ADD CONSTRAINT `PIANO_CONTI_RIGA_MOV_CONTABILE` 
    FOREIGN KEY (`id_pianoConti`) REFERENCES `PIANO_CONTI` (`id_pianoConti`);

#*#ALTER TABLE `RIGA_MOV_CONTABILE` ADD CONSTRAINT `CLIFOR_RIGA_MOV_CONTABILE` 
#*#    FOREIGN KEY (`id_clifor`) REFERENCES `CLIFOR` (`id_clifor`);

ALTER TABLE `RIGA_MOV_CONTABILE` ADD CONSTRAINT `BANCA_RIGA_MOV_CONTABILE` 
    FOREIGN KEY (`id_banca`) REFERENCES `BANCA` (`id_banca`);

#*#ALTER TABLE `RIGA_MOV_CONTABILE` ADD CONSTRAINT `DOCUMENTO_RIGA_MOV_CONTABILE` 
#*#    FOREIGN KEY (`id_documento`) REFERENCES `DOCUMENTO` (`id_documento`);

#*#ALTER TABLE `RIGA_MOV_CONTABILE` ADD CONSTRAINT `IVA_RIGA_MOV_CONTABILE` 
#*#    FOREIGN KEY (`id_iva`) REFERENCES `IVA` (`id_iva`);

ALTER TABLE `RIGA_CAUSALE_CONTABILE` ADD CONSTRAINT `PIANO_CONTI_RIGA_CAUSALE_CONTABILE` 
    FOREIGN KEY (`id_pianoConti`) REFERENCES `PIANO_CONTI` (`id_pianoConti`);

ALTER TABLE `RIGA_CAUSALE_CONTABILE` ADD CONSTRAINT `CAUSALE_CONTABILE_RIGA_CAUSALE_CONTABILE` 
    FOREIGN KEY (`id_causaleContabile`) REFERENCES `CAUSALE_CONTABILE` (`id_causaleContabile`);

### 134

# ---------------------------------------------------------------------- #
# 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-01-14 12:19                                #
# ---------------------------------------------------------------------- #


# ---------------------------------------------------------------------- #
# Drop foreign key constraints                                           #
# ---------------------------------------------------------------------- #


# ---------------------------------------------------------------------- #
# Modify table "PIANO_CONTI"                                             #
# ---------------------------------------------------------------------- #

ALTER TABLE `PIANO_CONTI` ADD COLUMN `contoCompleto` VARCHAR(40);

ALTER TABLE `PIANO_CONTI` ADD COLUMN `mastro` VARCHAR(40);

ALTER TABLE `PIANO_CONTI` ADD COLUMN `sottoconto` VARCHAR(40);

ALTER TABLE `PIANO_CONTI` MODIFY `contoCompleto` VARCHAR(40) AFTER `id_pianoConti`;

ALTER TABLE `PIANO_CONTI` MODIFY `descrizione` VARCHAR(254) AFTER `contoCompleto`;

ALTER TABLE `PIANO_CONTI` MODIFY `flgTipo` INTEGER AFTER `descrizione`;

ALTER TABLE `PIANO_CONTI` MODIFY `flgCFBI` INTEGER AFTER `flgTipo`;

ALTER TABLE `PIANO_CONTI` MODIFY `flgMovimentabile` INTEGER AFTER `flgCFBI`;

ALTER TABLE `PIANO_CONTI` MODIFY `mastro` VARCHAR(40) AFTER `flgMovimentabile`;

ALTER TABLE `PIANO_CONTI` MODIFY `conto` VARCHAR(40) AFTER `mastro`;

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

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

ALTER TABLE `DOCUMENTO` ADD COLUMN `clienteNome` VARCHAR(254);

ALTER TABLE `DOCUMENTO` ADD COLUMN `clienteCognome` VARCHAR(254);

ALTER TABLE `DOCUMENTO` ADD COLUMN `clienteIndirizzo` VARCHAR(254);

ALTER TABLE `DOCUMENTO` ADD COLUMN `clienteCf` VARCHAR(254);

ALTER TABLE `DOCUMENTO` ADD COLUMN `clientePiva` VARCHAR(254);


### 136

# ---------------------------------------------------------------------- #
# Modify table "USERS"                                                   #
# ---------------------------------------------------------------------- #

ALTER TABLE `USERS` ADD COLUMN `imgTmst` CHAR(40);

### 137


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

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

ALTER TABLE `DOCUMENTO` ADD COLUMN `notaSblocco` VARCHAR(1000);

# ---------------------------------------------------------------------- #
# Modify table "COMUNE"                                                  #
# ---------------------------------------------------------------------- #

ALTER TABLE `COMUNE` ADD COLUMN `id_zona` INTEGER;

# ---------------------------------------------------------------------- #
# Add table "ZONA"                                                       #
# ---------------------------------------------------------------------- #

CREATE TABLE `ZONA` (
    `id_zona` INTEGER NOT NULL AUTO_INCREMENT,
    `descrizione` VARCHAR(30),
    CONSTRAINT `PK_ZONA` PRIMARY KEY (`id_zona`)
);
ALTER TABLE `COMUNE` ADD CONSTRAINT `ZONA_COMUNE` 
    FOREIGN KEY (`id_zona`) REFERENCES `ZONA` (`id_zona`);


###nazione

ALTER TABLE `NAZIONE` ADD COLUMN `descrizioneInLingua` VARCHAR(60);

ALTER TABLE `NAZIONE` CHANGE `id_lingua` `lang` CHAR(3);




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


ALTER TABLE `CLIFOR` ADD COLUMN `speseIncasso` DECIMAL(18,4);


 ALTER TABLE `BANCA` DROP FOREIGN KEY `COMUNE_BANCA`;
ALTER TABLE `BANCA` DROP COLUMN `id_comune`;




# ---------------------------------------------------------------------- #
# Add table "ABI_CAB"                                                    #
# ---------------------------------------------------------------------- #

CREATE TABLE `ABI_CAB` (
    `id_abiCab` INTEGER NOT NULL AUTO_INCREMENT,
    `descrizione` VARCHAR(60),
    `agenzia` VARCHAR(40),
    `indirizzo` VARCHAR(60),
    `capZona` VARCHAR(10),
    `abi` VARCHAR(6),
    `cab` VARCHAR(6),
    `bic` VARCHAR(30),
    `codiceAlt` VARCHAR(40),
    CONSTRAINT `PK_ABI_CAB` PRIMARY KEY (`id_abiCab`)
);


ALTER TABLE `BANCA` ADD CONSTRAINT `ABI_CAB_BANCA` 
    FOREIGN KEY (`id_abiCab`) REFERENCES `ABI_CAB` (`id_abiCab`);

##139



### 140
# ---------------------------------------------------------------------- #
# Add table "DOCUMENTO_SCADENZA"                                         #
# ---------------------------------------------------------------------- #

CREATE TABLE `DOCUMENTO_SCADENZA` (
    `id_documentoScadenza` INTEGER NOT NULL AUTO_INCREMENT,
    `id_documento` INTEGER,
    `id_distintaRiba` INTEGER,
    `dataScadenza` DATE,
    `importoScadenza` DECIMAL(18,4),
    `flgScadenzaSelezionata` INTEGER,
    CONSTRAINT `PK_DOCUMENTO_SCADENZA` PRIMARY KEY (`id_documentoScadenza`)
);

# ---------------------------------------------------------------------- #
# Add table "DISTINTA_RIBA"                                              #
# ---------------------------------------------------------------------- #

CREATE TABLE `DISTINTA_RIBA` (
    `id_distintaRiba` INTEGER NOT NULL AUTO_INCREMENT,
    `id_banca` INTEGER,
    `dataPresentazione` DATE,
    `flgStatoDistinta` INTEGER,
    `flgAccorpaScadenze` INTEGER,
    `flgContabilizzata` VARCHAR(40),
    CONSTRAINT `PK_DISTINTA_RIBA` PRIMARY KEY (`id_distintaRiba`)
);

# ---------------------------------------------------------------------- #
# Add table "MESE_ESCLUSO"                                               #
# ---------------------------------------------------------------------- #

CREATE TABLE `MESE_ESCLUSO` (
    `id_meseEscluso` INTEGER NOT NULL AUTO_INCREMENT,
    `id_tipoPagamento` INTEGER,
    `meseEscluso` INTEGER,
    `giornoEscluso` INTEGER,
    CONSTRAINT `PK_MESE_ESCLUSO` PRIMARY KEY (`id_meseEscluso`)
);

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

#*#ALTER TABLE `DOCUMENTO_SCADENZA` ADD CONSTRAINT `DOCUMENTO_DOCUMENTO_SCADENZA` 
#*#    FOREIGN KEY (`id_documento`) REFERENCES `DOCUMENTO` (`id_documento`);

ALTER TABLE `DOCUMENTO_SCADENZA` ADD CONSTRAINT `DISTINTA_RIBA_DOCUMENTO_SCADENZA` 
    FOREIGN KEY (`id_distintaRiba`) REFERENCES `DISTINTA_RIBA` (`id_distintaRiba`);

ALTER TABLE `DISTINTA_RIBA` ADD CONSTRAINT `BANCA_DISTINTA_RIBA` 
    FOREIGN KEY (`id_banca`) REFERENCES `BANCA` (`id_banca`);

#*#ALTER TABLE `MESE_ESCLUSO` ADD CONSTRAINT `TIPO_PAGAMENTO_MESE_ESCLUSO` 
#*#    FOREIGN KEY (`id_tipoPagamento`) REFERENCES `TIPO_PAGAMENTO` (`id_tipoPagamento`);
###

# ---------------------------------------------------------------------- #
# Modify table "DISTINTA_RIBA"                                           #
# ---------------------------------------------------------------------- #

ALTER TABLE `DISTINTA_RIBA` MODIFY `flgContabilizzata` INTEGER;

##141??
ALTER TABLE `CLIFOR` ADD COLUMN `bic` VARCHAR(20);
# ---------------------------------------------------------------------- #
# Modify table "DISTINTA_RIBA"                                           #
# ---------------------------------------------------------------------- #

ALTER TABLE `DISTINTA_RIBA` MODIFY `flgContabilizzata` INTEGER;



## 142

DROP INDEX `IDX_DOCUMENTO_16` ON `DOCUMENTO`;

ALTER TABLE `DOCUMENTO` MODIFY `id_documentoXpay` VARCHAR(40);

CREATE UNIQUE INDEX `IDX_DOCUMENTO_16` ON `DOCUMENTO` (`id_documentoXpay`);

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


#*#ALTER TABLE `LISTINO_ARTICOLO` ADD COLUMN   `percLA` DECIMAL(5,2);

  
ALTER TABLE `LISTINO_ARTICOLO` ADD COLUMN `abbuonoPrezzoPubblicoLA` DECIMAL(18,4);

ALTER TABLE `LISTINO_ARTICOLO` ADD COLUMN `dataCambiamentoPrezzoLA` DATE;

ALTER TABLE `LISTINO_ARTICOLO` CHANGE `prezzoOfferta` `prezzoOffertaLA` DECIMAL(18,4);

ALTER TABLE `LISTINO_ARTICOLO` CHANGE `dataScadenzaOfferta` `dataScadenzaOffertaLA` DATE;


## 144

# ---------------------------------------------------------------------- #
# Alter table "ARTICOLO_VARIANTE"                                        #
# ---------------------------------------------------------------------- #

ALTER TABLE `ARTICOLO_VARIANTE` ADD COLUMN `flgListinoArticolo` INTEGER;

### \145


ALTER TABLE `POSTAZIONE` ADD COLUMN `hostname` VARCHAR(60);

### 146

# ---------------------------------------------------------------------- #
# Alter table "TIPO_BANNER"                                              #
# ---------------------------------------------------------------------- #

ALTER TABLE `TIPO_BANNER` MODIFY `larghezza` VARCHAR(10);

ALTER TABLE `TIPO_BANNER` MODIFY `altezza` VARCHAR(10);



###152
# ---------------------------------------------------------------------- #
# 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-12-12 09:43                                #
# ---------------------------------------------------------------------- #


# ---------------------------------------------------------------------- #
# Drop foreign key constraints                                           #
# ---------------------------------------------------------------------- #
# ---------------------------------------------------------------------- #
# Modify table "ACCESS"                                                  #
# ---------------------------------------------------------------------- #

ALTER TABLE `ACCESS` ADD COLUMN `flgDeleteCascade` INTEGER;

# ---------------------------------------------------------------------- #
# Modify table "LOG"                                                     #
# ---------------------------------------------------------------------- #



#153

# ---------------------------------------------------------------------- #
# Alter table "CODA_MESSAGGI"                                            #
# ---------------------------------------------------------------------- #

ALTER TABLE `CODA_MESSAGGI` CHANGE `messaggio` `testoMessaggio` TEXT;

# ---------------------------------------------------------------------- #
# Alter table "TEMPLATE_MSG"                                             #
# ---------------------------------------------------------------------- #

ALTER TABLE `TEMPLATE_MSG` CHANGE `messaggio` `testoMessaggio` TEXT;
