From d438c3d94dfd274f56b77716ccbb4b9e43743a37 Mon Sep 17 00:00:00 2001 From: Luca Date: Thu, 14 Nov 2019 17:27:33 +0100 Subject: [PATCH] =?UTF-8?q?Permetto=20eliminazione=20tipo=20intervento=20s?= =?UTF-8?q?olo=20se=20questo=20non=20=C3=A8=20utilizzado=20da=20nessun'alt?= =?UTF-8?q?ra=20parte=20a=20gestionale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix eliminazione co_contratti_tipiintervento quando elimino un contratto --- modules/contratti/actions.php | 1 + modules/tipi_intervento/actions.php | 37 +++++++++++++++++++++++------ modules/tipi_intervento/edit.php | 23 ++++++++++++++---- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/modules/contratti/actions.php b/modules/contratti/actions.php index 76e775177..3c19633f0 100644 --- a/modules/contratti/actions.php +++ b/modules/contratti/actions.php @@ -263,6 +263,7 @@ switch (post('op')) { $contratto->delete(); $dbo->query('DELETE FROM co_promemoria WHERE idcontratto='.prepare($id_record)); + $dbo->query('DELETE FROM co_contratti_tipiintervento WHERE idcontratto='.prepare($id_record)); flash()->info(tr('Contratto eliminato!')); } catch (InvalidArgumentException $e) { diff --git a/modules/tipi_intervento/actions.php b/modules/tipi_intervento/actions.php index dceff6021..d0a16c3d5 100644 --- a/modules/tipi_intervento/actions.php +++ b/modules/tipi_intervento/actions.php @@ -49,15 +49,38 @@ switch (post('op')) { break; case 'delete': - $query = 'DELETE FROM in_tipiintervento WHERE idtipointervento='.prepare($id_record); - $dbo->query($query); + + // Permetto eliminazione tipo intervento solo se questo non è utilizzado da nessun'altra parte a gestionale + $elementi = $dbo->fetchArray('SELECT `in_interventi`.`idtipointervento` FROM `in_interventi` WHERE `in_interventi`.`idtipointervento` = '.prepare($id_record).' + UNION + SELECT `an_anagrafiche`.`idtipointervento_default` AS `idtipointervento` FROM `an_anagrafiche` WHERE `an_anagrafiche`.`idtipointervento_default` = '.prepare($id_record).' + UNION + SELECT `co_preventivi`.`idtipointervento` FROM `co_preventivi` WHERE `co_preventivi`.`idtipointervento` = '.prepare($id_record).' + UNION + SELECT `co_promemoria`.`idtipointervento` FROM `co_promemoria` WHERE `co_promemoria`.`idtipointervento` = '.prepare($id_record).' + UNION + SELECT `in_tariffe`.`idtipointervento` FROM `in_tariffe` WHERE `in_tariffe`.`idtipointervento` = '.prepare($id_record).' + UNION + SELECT `in_interventi_tecnici`.`idtipointervento` FROM `in_interventi_tecnici` WHERE `in_interventi_tecnici`.`idtipointervento` = '.prepare($id_record).' + UNION + SELECT `co_contratti_tipiintervento`.`idtipointervento` FROM `co_contratti_tipiintervento` WHERE `co_contratti_tipiintervento`.`idtipointervento` = '.prepare($id_record).' + ORDER BY `idtipointervento`'); - // Elimino anche le tariffe collegate ai vari tecnici - $query = 'DELETE FROM in_tariffe WHERE idtipointervento='.prepare($id_record); - $dbo->query($query); + + + if (empty($elementi)) { + + $query = 'DELETE FROM in_tipiintervento WHERE idtipointervento='.prepare($id_record); + $dbo->query($query); - flash()->info(tr('Tipo di intervento eliminato!')); - break; + // Elimino anche le tariffe collegate ai vari tecnici + $query = 'DELETE FROM in_tariffe WHERE idtipointervento='.prepare($id_record); + $dbo->query($query); + + flash()->info(tr('Tipo di intervento eliminato!')); + break; + + } case 'import': $values = [ diff --git a/modules/tipi_intervento/edit.php b/modules/tipi_intervento/edit.php index 6bd32a50f..276b1b485 100644 --- a/modules/tipi_intervento/edit.php +++ b/modules/tipi_intervento/edit.php @@ -69,15 +69,28 @@ include_once __DIR__.'/../../core.php'; fetchArray('SELECT `in_interventi`.`idtipointervento` FROM `in_interventi` WHERE `in_interventi`.`idtipointervento` = '.prepare($id_record).' +UNION +SELECT `an_anagrafiche`.`idtipointervento_default` AS `idtipointervento` FROM `an_anagrafiche` WHERE `an_anagrafiche`.`idtipointervento_default` = '.prepare($id_record).' +UNION +SELECT `co_preventivi`.`idtipointervento` FROM `co_preventivi` WHERE `co_preventivi`.`idtipointervento` = '.prepare($id_record).' +UNION +SELECT `co_promemoria`.`idtipointervento` FROM `co_promemoria` WHERE `co_promemoria`.`idtipointervento` = '.prepare($id_record).' +UNION +SELECT `in_tariffe`.`idtipointervento` FROM `in_tariffe` WHERE `in_tariffe`.`idtipointervento` = '.prepare($id_record).' +UNION +SELECT `in_interventi_tecnici`.`idtipointervento` FROM `in_interventi_tecnici` WHERE `in_interventi_tecnici`.`idtipointervento` = '.prepare($id_record).' +UNION +SELECT `co_contratti_tipiintervento`.`idtipointervento` FROM `co_contratti_tipiintervento` WHERE `co_contratti_tipiintervento`.`idtipointervento` = '.prepare($id_record).' +ORDER BY `idtipointervento`'); -$interventi = $dbo->fetchArray('SELECT COUNT(*) AS tot_interventi FROM in_interventi WHERE idtipointervento='.prepare($id_record)); -$tot_interventi = $interventi[0]['tot_interventi']; -if ($tot_interventi > 0) { +if (!empty($elementi)) { echo '
- '.tr('Ci sono _NUM_ interventi collegati', [ - '_NUM_' => $tot_interventi, + '.tr('Ci sono _NUM_ records collegati', [ + '_NUM_' => count($elementi), ]).'.
'; } else {