From c58adc2e9e5c23e95182152b53bd081521801aac Mon Sep 17 00:00:00 2001 From: Luca Date: Wed, 8 May 2019 15:29:52 +0200 Subject: [PATCH] Aggiunto bulk per eliminazione aliq. iva non utilizzate --- modules/fatture/bulk.php | 2 +- modules/iva/bulk.php | 44 ++++++++++++++++++++++++++++++++++++++++ modules/iva/edit.php | 41 +++++++++++++++++++++---------------- 3 files changed, 69 insertions(+), 18 deletions(-) create mode 100644 modules/iva/bulk.php diff --git a/modules/fatture/bulk.php b/modules/fatture/bulk.php index de9a7dc3e..cc0f08a46 100644 --- a/modules/fatture/bulk.php +++ b/modules/fatture/bulk.php @@ -53,7 +53,7 @@ switch (post('op')) { case 'delete-bulk': if (App::debug()) { foreach ($id_records as $id) { - $dbo->query('DELETE FROM co_documenti WHERE id = '.prepare($id).Modules::getAdditionalsQuery($id_module)); + $dbo->query('DELETE FROM co_documenti WHERE id = '.prepare($id).Modules::getAdditionalsQuery($id_module)); $dbo->query('DELETE FROM co_righe_documenti WHERE iddocumento='.prepare($id).Modules::getAdditionalsQuery($id_module)); $dbo->query('DELETE FROM co_scadenziario WHERE iddocumento='.prepare($id).Modules::getAdditionalsQuery($id_module)); $dbo->query('DELETE FROM mg_movimenti WHERE iddocumento='.prepare($id).Modules::getAdditionalsQuery($id_module)); diff --git a/modules/iva/bulk.php b/modules/iva/bulk.php new file mode 100644 index 000000000..f0f8dd3a7 --- /dev/null +++ b/modules/iva/bulk.php @@ -0,0 +1,44 @@ +fetchNum('SELECT id FROM `co_iva` WHERE deleted_at IS NOT NULL'); + foreach ($id_records as $id) { + + $res = $dbo->fetchNum('SELECT `co_righe_documenti`.`id` FROM `co_righe_documenti` WHERE `co_righe_documenti`.`idiva`='.prepare($id). + ' UNION SELECT `co_righe_preventivi`.`id` FROM `co_righe_preventivi` WHERE `co_righe_preventivi`.`idiva` = '.prepare($id). + ' UNION SELECT `co_righe_contratti`.`id` FROM `co_righe_contratti` WHERE `co_righe_contratti`.`idiva` = '.prepare($id). + ' UNION SELECT `dt_righe_ddt`.`id` FROM `dt_righe_ddt` WHERE `dt_righe_ddt`.`idiva` = '.prepare($id). + ' UNION SELECT `or_righe_ordini`.`id` FROM `or_righe_ordini` WHERE `or_righe_ordini`.`idiva` = '.prepare($id). + ' UNION SELECT `mg_articoli`.`id` FROM `mg_articoli` WHERE `mg_articoli`.`idiva_vendita` = '.prepare($id). + ' UNION SELECT `an_anagrafiche`.`idanagrafica` AS `id` FROM `an_anagrafiche` WHERE `an_anagrafiche`.`idiva_vendite` = '.prepare($id).' OR `an_anagrafiche`.`idiva_acquisti` = '.prepare($id) ); + + + if (empty($res)) { + $dbo->query('UPDATE `co_iva` SET deleted_at = NOW() WHERE id = '.prepare($id).Modules::getAdditionalsQuery($id_module)); + } + + } + $count_iva = $dbo->fetchNum('SELECT id FROM `co_iva` WHERE deleted_at IS NOT NULL') - $count_iva; + + if ($count_iva>0){ + $msg = tr('_NUM_ tipologi_A_ iva eliminat_A_.', [ + '_NUM_' => $count_iva, + '_A_' => ($count_iva==1) ? 'a' : 'e']); + + flash()->info($msg); + } + else{ + flash()->warning(tr('Nessuna tipologia iva eliminata!')); + } + break; +} + +$bulk = [ + 'delete-bulk' => tr('Elimina selezionati'), +]; + +return $bulk; \ No newline at end of file diff --git a/modules/iva/edit.php b/modules/iva/edit.php index bfa5fe03d..5180fb34e 100644 --- a/modules/iva/edit.php +++ b/modules/iva/edit.php @@ -2,13 +2,6 @@ include_once __DIR__.'/../../core.php'; -if (!$record['default']) { - $attr = ''; -} else { - $attr = 'readonly'; - echo '
'.tr('Alcune impostazioni non possono essere modificate.').'
'; -} - $esigibilita = [ [ 'id' => 'I', @@ -79,16 +72,6 @@ $esigibilita = [ - - - - - + + +fetchNum('SELECT `co_righe_documenti`.`id` FROM `co_righe_documenti` WHERE `co_righe_documenti`.`idiva`='.prepare($id_record). +' UNION SELECT `co_righe_preventivi`.`id` FROM `co_righe_preventivi` WHERE `co_righe_preventivi`.`idiva` = '.prepare($id_record). +' UNION SELECT `co_righe_contratti`.`id` FROM `co_righe_contratti` WHERE `co_righe_contratti`.`idiva` = '.prepare($id_record). +' UNION SELECT `dt_righe_ddt`.`id` FROM `dt_righe_ddt` WHERE `dt_righe_ddt`.`idiva` = '.prepare($id_record). +' UNION SELECT `or_righe_ordini`.`id` FROM `or_righe_ordini` WHERE `or_righe_ordini`.`idiva` = '.prepare($id_record). +' UNION SELECT `mg_articoli`.`id` FROM `mg_articoli` WHERE `mg_articoli`.`idiva_vendita` = '.prepare($id_record). +' UNION SELECT `an_anagrafiche`.`idanagrafica` AS `id` FROM `an_anagrafiche` WHERE `an_anagrafiche`.`idiva_vendite` = '.prepare($id_record).' OR `an_anagrafiche`.`idiva_acquisti` = '.prepare($id_record) ); + + +if ($res) { + echo ' +
+

'.tr('Ci sono '.count($res).' documenti collegati a questa aliquota IVA. Non รจ possibile eliminarla.').'

+
'; +} else { + echo ' + + '.tr('Elimina').' + '; +} \ No newline at end of file