Fix foreign keys 2.4

Nel file SQL per la versione 2.4 era assente l'engine MySQL per la creazione tabelle, il che non impediva l'aggiunta delle foreign keys di base.
This commit is contained in:
Thomas Zilio 2018-06-16 18:07:16 +02:00
parent 4e59efd06a
commit 1b88be1609
4 changed files with 50 additions and 39 deletions

View File

@ -3,18 +3,16 @@
include_once __DIR__.'/../../../core.php';
switch ($resource) {
case 'get_conti':
$idmastrino = get('idmastrino');
$conti = array();
$rs_conti = $dbo->fetchArray("SELECT *, (SELECT descrizione FROM co_pianodeiconti3 WHERE id=co_movimenti_modelli.idconto) AS descrizione_conto FROM co_movimenti_modelli WHERE idmastrino=".prepare($idmastrino)." GROUP BY id");
$conti = [];
$rs_conti = $dbo->fetchArray('SELECT *, (SELECT descrizione FROM co_pianodeiconti3 WHERE id=co_movimenti_modelli.idconto) AS descrizione_conto FROM co_movimenti_modelli WHERE idmastrino='.prepare($idmastrino).' GROUP BY id');
for($i=0;$i<sizeof($rs_conti);$i++){
$conti[$i] = $rs_conti[$i]['idconto'].";".$rs_conti[$i]['descrizione_conto'];
for ($i = 0; $i < sizeof($rs_conti); ++$i) {
$conti[$i] = $rs_conti[$i]['idconto'].';'.$rs_conti[$i]['descrizione_conto'];
}
echo implode(',', $conti);
break;
}
}

View File

@ -28,9 +28,8 @@ CREATE TABLE IF NOT EXISTS `zz_prints` (
`main` tinyint(1) NOT NULL,
`default` tinyint(1) NOT NULL,
`enabled` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_module`) REFERENCES `zz_modules`(`id`) ON DELETE CASCADE
);
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
-- Inserimento delle stampe di base
INSERT INTO `zz_prints` (`id_module`, `name`, `directory`, `options`, `previous`, `enabled`, `default`) VALUES
@ -99,7 +98,7 @@ CREATE TABLE IF NOT EXISTS `zz_smtp` (
`main` tinyint(1) NOT NULL,
`deleted` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
);
) ENGINE=InnoDB;
--
-- Struttura della tabella `zz_emails`
@ -119,10 +118,8 @@ CREATE TABLE IF NOT EXISTS `zz_emails` (
`read_notify` tinyint(1) NOT NULL,
`main` tinyint(1) NOT NULL,
`deleted` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
FOREIGN KEY (`id_module`) REFERENCES `zz_modules`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`id_smtp`) REFERENCES `zz_smtp`(`id`) ON DELETE CASCADE
);
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
--
-- Struttura della tabella `zz_emails`
@ -132,10 +129,8 @@ CREATE TABLE IF NOT EXISTS `zz_email_print` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_email` int(11) NOT NULL,
`id_print` int(11) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_email`) REFERENCES `zz_emails`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`id_print`) REFERENCES `zz_prints`(`id`) ON DELETE CASCADE
);
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
-- Aggiunta dei moduli dedicati alla gestione delle email
INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Account email', 'Account email', 'smtp', 'SELECT |select| FROM zz_smtp WHERE 1=1 AND deleted = 0 HAVING 2=2 ORDER BY `name`', 'fa fa-user-o', '2.3', '2.3', '10', NULL, 1, 1);
@ -185,7 +180,7 @@ CREATE TABLE IF NOT EXISTS `zz_segments` (
`note` text NOT NULL,
`predefined` BOOLEAN NOT NULL,
PRIMARY KEY (`id`)
);
) ENGINE=InnoDB;
-- Popolo con i segmenti di default
INSERT INTO `zz_segments` (`id`, `id_module`, `name`, `clause`, `position`, `pattern`,`note`, `predefined`) VALUES
@ -234,10 +229,8 @@ CREATE TABLE IF NOT EXISTS `zz_fields` (
`order` int(11) NOT NULL,
`on_add` boolean NOT NULL,
`top` boolean NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_module`) REFERENCES `zz_modules`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`id_plugin`) REFERENCES `zz_plugins`(`id`) ON DELETE CASCADE
);
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
--
-- Struttura della tabella `zz_fields`
@ -248,9 +241,8 @@ CREATE TABLE IF NOT EXISTS `zz_field_record` (
`id_field` int(11) NOT NULL,
`id_record` int(11) NOT NULL,
`value` text NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_field`) REFERENCES `zz_fields`(`id`) ON DELETE CASCADE
);
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
-- Aggiunta modulo di importazione
INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES
@ -319,7 +311,7 @@ CREATE TABLE IF NOT EXISTS `co_banche` (
`note` text NOT NULL,
`deleted` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
);
) ENGINE=InnoDB;
-- Innesto modulo per gestione banche
INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Banche', 'Banche', 'banche', 'SELECT |select| FROM `co_banche` WHERE 1=1 AND deleted = 0 GROUP BY `nome` HAVING 2=2', '', 'fa fa-university', '2.4', '2.4', '1', (SELECT `id` FROM `zz_modules` m WHERE `name` = 'Tabelle'), '1', '1');
@ -350,4 +342,4 @@ INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable
DELETE FROM `co_iva` WHERE `co_iva`.`descrizione` = 'Esente art. 10' AND `co_iva`.`id` NOT IN (SELECT `idiva` FROM co_righe_documenti UNION SELECT `idiva` FROM co_righe_preventivi UNION SELECT `idiva` FROM dt_righe_ddt UNION SELECT `idiva` FROM or_righe_ordini );
-- Allineamento query widget 'Contratti in scadenza'
UPDATE `zz_widgets` SET `query` = 'SELECT COUNT(id) AS dato, DATEDIFF( data_conclusione, NOW() ) AS giorni_rimanenti FROM co_contratti WHERE idstato IN(SELECT id FROM co_staticontratti WHERE fatturabile = 1) AND NOT EXISTS (SELECT id FROM co_righe_documenti WHERE co_righe_documenti.idcontratto = co_contratti.id) AND rinnovabile=1 AND NOW() > DATE_ADD( data_conclusione, INTERVAL - ABS(giorni_preavviso_rinnovo) DAY) AND YEAR(data_conclusione) > 1970 ORDER BY giorni_rimanenti ASC' WHERE `zz_widgets`.`name` = 'Contratti in scadenza';
UPDATE `zz_widgets` SET `query` = 'SELECT COUNT(id) AS dato, DATEDIFF( data_conclusione, NOW() ) AS giorni_rimanenti FROM co_contratti WHERE idstato IN(SELECT id FROM co_staticontratti WHERE fatturabile = 1) AND NOT EXISTS (SELECT id FROM co_righe_documenti WHERE co_righe_documenti.idcontratto = co_contratti.id) AND rinnovabile=1 AND NOW() > DATE_ADD( data_conclusione, INTERVAL - ABS(giorni_preavviso_rinnovo) DAY) AND YEAR(data_conclusione) > 1970 ORDER BY giorni_rimanenti ASC' WHERE `zz_widgets`.`name` = 'Contratti in scadenza';

View File

@ -39,7 +39,7 @@ CREATE TABLE IF NOT EXISTS `co_movimenti_modelli` (
`idmastrino` int(11) NOT NULL,
`descrizione` text NOT NULL,
`idconto` int(11) NOT NULL
);
) ENGINE=InnoDB;
ALTER TABLE `co_movimenti_modelli` ADD PRIMARY KEY (`id`);
@ -92,8 +92,9 @@ CREATE TABLE IF NOT EXISTS `co_righe_contratti_materiali` (
`sconto_unitario` decimal(12,4) NOT NULL,
`tipo_sconto` enum('UNT','PRC') NOT NULL DEFAULT 'UNT',
PRIMARY KEY (`id`),
KEY `id_riga_contratto` (`id_riga_contratto`)
);
FOREIGN KEY `id_riga_contratto` (`id_riga_contratto`)
) ENGINE=InnoDB;
-- Struttura della tabella `co_righe_contratti_articoli`
@ -116,9 +117,10 @@ CREATE TABLE IF NOT EXISTS `co_righe_contratti_articoli` (
`abilita_serial` tinyint(1) NOT NULL DEFAULT '0',
`idimpianto` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `id_riga_contratto` (`id_riga_contratto`),
KEY `idimpianto` (`idimpianto`)
);
FOREIGN KEY `id_riga_contratto` (`id_riga_contratto`),
FOREIGN KEY `idimpianto` (`idimpianto`)
) ENGINE=InnoDB;
-- Modifica query wiget per mostrare solo quelli che non sono stati rinnovati
@ -273,4 +275,23 @@ UPDATE `in_statiintervento` SET `can_delete` = '0' WHERE `in_statiintervento`.`i
UPDATE `zz_views` SET `summable` = '1' WHERE `zz_views`.`id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Scadenzario') AND name = 'Importo';
-- Collego il preventivo alla riga dell'ordine
ALTER TABLE `or_righe_ordini` ADD `idpreventivo` INT(11) NOT NULL AFTER `idarticolo`;
ALTER TABLE `or_righe_ordini` ADD `idpreventivo` INT(11) NOT NULL AFTER `idarticolo`;
-- Fix foreign keys (2.4)
ALTER TABLE `zz_emails`
ADD FOREIGN KEY (`id_module`) REFERENCES `zz_modules`(`id`) ON DELETE CASCADE,
ADD FOREIGN KEY (`id_smtp`) REFERENCES `zz_smtp`(`id`) ON DELETE CASCADE;
ALTER TABLE `zz_email_print`
ADD FOREIGN KEY (`id_email`) REFERENCES `zz_emails`(`id`) ON DELETE CASCADE,
ADD FOREIGN KEY (`id_print`) REFERENCES `zz_prints`(`id`) ON DELETE CASCADE;
ALTER TABLE `zz_fields`
ADD FOREIGN KEY (`id_module`) REFERENCES `zz_modules`(`id`) ON DELETE CASCADE,
ADD FOREIGN KEY (`id_plugin`) REFERENCES `zz_plugins`(`id`) ON DELETE CASCADE;
ALTER TABLE `zz_field_record`
ADD FOREIGN KEY (`id_field`) REFERENCES `zz_fields`(`id`) ON DELETE CASCADE;
ALTER TABLE `zz_prints`
ADD FOREIGN KEY (`id_module`) REFERENCES `zz_modules`(`id`) ON DELETE CASCADE;

View File

@ -5,4 +5,4 @@ CREATE TABLE `updates` (
`script` boolean NOT NULL,
`done` int(11),
PRIMARY KEY (`id`)
) ENGINE = InnoDB;
) ENGINE=InnoDB;