From 07636b7e7a97a7aaf83f8fc6c4df959919dba370 Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 25 Mar 2022 19:26:50 +0100 Subject: [PATCH] Introduzione modulo fasce orarie e modulo eventi --- lib/util.php | 2 +- modules/eventi/actions.php | 92 ++++++++++++++ modules/eventi/add.php | 43 +++++++ modules/eventi/ajax/select.php | 35 ++++++ modules/eventi/edit.php | 74 +++++++++++ modules/eventi/init.php | 24 ++++ modules/fasce_orarie/actions.php | 103 +++++++++++++++ modules/fasce_orarie/add.php | 38 ++++++ modules/fasce_orarie/ajax/select.php | 35 ++++++ modules/fasce_orarie/edit.php | 182 +++++++++++++++++++++++++++ modules/fasce_orarie/init.php | 24 ++++ src/Util/Query.php | 4 +- update/2_4_33.php | 25 ++++ update/2_4_33.sql | 70 +++++++++++ update/tables.php | 3 + 15 files changed, 751 insertions(+), 3 deletions(-) create mode 100644 modules/eventi/actions.php create mode 100644 modules/eventi/add.php create mode 100644 modules/eventi/ajax/select.php create mode 100644 modules/eventi/edit.php create mode 100644 modules/eventi/init.php create mode 100644 modules/fasce_orarie/actions.php create mode 100644 modules/fasce_orarie/add.php create mode 100644 modules/fasce_orarie/ajax/select.php create mode 100644 modules/fasce_orarie/edit.php create mode 100644 modules/fasce_orarie/init.php create mode 100644 update/2_4_33.php create mode 100644 update/2_4_33.sql diff --git a/lib/util.php b/lib/util.php index cde7af85a..0ed471c86 100755 --- a/lib/util.php +++ b/lib/util.php @@ -185,7 +185,7 @@ if (!function_exists('replace')) { */ function replace($string, $array) { - return str_replace(array_keys($array), array_values($array), $string); + return str_replace(array_keys($array), array_values($array), (string) $string); } } diff --git a/modules/eventi/actions.php b/modules/eventi/actions.php new file mode 100644 index 000000000..60712b5df --- /dev/null +++ b/modules/eventi/actions.php @@ -0,0 +1,92 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +switch (post('op')) { + case 'update': + $nome = post('nome'); + $data = post('data'); + $id_nazione = post('id_nazione'); + $id_regione = post('id_regione'); + $is_recurring = post('is_recurring'); + $is_bank_holiday = post('is_recurring'); + + if ($dbo->fetchNum('SELECT * FROM `zz_events` WHERE `nome`='.prepare($nome).' AND `id`!='.prepare($id_record)) == 0) { + + $dbo->update('zz_events', [ + 'nome' => $nome, + 'data' => $data, + 'id_nazione' =>$id_nazione, + 'id_regione' => $id_regione, + 'is_recurring' => $is_recurring, + 'is_bank_holiday' => $is_bank_holiday, + ], [ + 'id' => $id_record, + ]); + + + flash()->info(tr('Salvataggio completato.')); + } else { + flash()->error(tr("E' già presente un _TYPE_ con lo stesso nome", [ + '_TYPE_' => 'evento', + ])); + } + + break; + + case 'add': + $nome = post('nome'); + $id_nazione = post('id_nazione'); + if ($dbo->fetchNum('SELECT * FROM `zz_events` WHERE `id_nazione` = '.prepare($id_nazione).' AND `nome`='.prepare($nome)) == 0) { + + $dbo->insert('zz_events', [ + 'nome' => $nome, + 'id_nazione' => $id_nazione, + ]); + + $id_record = $dbo->lastInsertedID(); + + if (isAjaxRequest()) { + echo json_encode(['id' => $id_record, 'text' => $nome]); + } + + flash()->info(tr('Aggiunto nuovo _TYPE_', [ + '_TYPE_' => 'evento', + ])); + } else { + flash()->error(tr("E' già presente un _TYPE_ con lo stesso nome e nazione", [ + '_TYPE_' => 'evento', + ])); + } + + break; + + case 'delete': + + $dbo->delete('zz_events', [ + 'id' => $id_record, + ]); + + flash()->info(tr('_TYPE_ eliminato con successo.', [ + '_TYPE_' => 'Evento', + ])); + + break; +} diff --git a/modules/eventi/add.php b/modules/eventi/add.php new file mode 100644 index 000000000..e937fa9f0 --- /dev/null +++ b/modules/eventi/add.php @@ -0,0 +1,43 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +?>
+ + + +
+
+ {[ "type": "text", "label": "", "name": "nome", "required": 1 ]} +
+ +
+ {[ "type": "select", "label": "", "name": "id_nazione", "required": 1, "ajax-source": "nazioni" ]} +
+ +
+ + +
+
+ +
+
+
diff --git a/modules/eventi/ajax/select.php b/modules/eventi/ajax/select.php new file mode 100644 index 000000000..d1d9dab8c --- /dev/null +++ b/modules/eventi/ajax/select.php @@ -0,0 +1,35 @@ +. + */ + +include_once __DIR__.'/../../../core.php'; + +switch ($resource) { + case 'fasce_orarie': + $query = 'SELECT id, nome AS descrizione FROM zz_events |where| ORDER BY nome ASC'; + + foreach ($elements as $element) { + $filter[] = 'id='.prepare($element); + } + + if (!empty($search)) { + $search_fields[] = 'nome LIKE '.prepare('%'.$search.'%'); + } + + break; +} diff --git a/modules/eventi/edit.php b/modules/eventi/edit.php new file mode 100644 index 000000000..7371db15a --- /dev/null +++ b/modules/eventi/edit.php @@ -0,0 +1,74 @@ +. + */ + +use Carbon\Carbon; +include_once __DIR__.'/../../core.php'; + +//$block_edit = $record['is_predefined']; + +?> + +
+ + + + +
+
+

+
+ +
+
+
+ {[ "type": "text", "label": "", "name": "nome", "required": 1, "value": "$nome$" ]} +
+ +
+ {[ "type": "date", "label": "", "name": "data", "required": 1, "value": "$data$" ]} +
+
+ +
+
+ {[ "type": "select", "label": "", "name": "id_nazione", "required": 1, "value": "$id_nazione$", "ajax-source": "nazioni" ]} +
+ +
+ {[ "type": "select", "label": "", "name": "id_regione", "value": "$id_regione$", "ajax-source": "regioni" ]} +
+
+ +
+
+ {[ "type": "checkbox", "label": "", "name": "is_recurring", "value": "$is_recurring$" ]} +
+ +
+ {[ "type": "checkbox", "label": "", "name": "is_bank_holiday", "value": "$is_bank_holiday$" ]} +
+
+ +
+
+
+ + + + diff --git a/modules/eventi/init.php b/modules/eventi/init.php new file mode 100644 index 000000000..2b56bc5e3 --- /dev/null +++ b/modules/eventi/init.php @@ -0,0 +1,24 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +if (isset($id_record)) { + $record = $dbo->fetchOne('SELECT * FROM `zz_events` WHERE id='.prepare($id_record)); +} diff --git a/modules/fasce_orarie/actions.php b/modules/fasce_orarie/actions.php new file mode 100644 index 000000000..4ba9f1090 --- /dev/null +++ b/modules/fasce_orarie/actions.php @@ -0,0 +1,103 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +switch (post('op')) { + case 'update': + $nome = post('nome'); + $giorni = (array) post('giorni'); + $ora_inizio = post('ora_inizio'); + $ora_fine = post('ora_fine'); + $include_bank_holidays = post('include_bank_holidays'); + + if ($dbo->fetchNum('SELECT * FROM `in_fasceorarie` WHERE `nome`='.prepare($nome).' AND `id`!='.prepare($id_record)) == 0) { + + $dbo->update('in_fasceorarie', [ + 'nome' => $nome, + 'giorni' => $giorni ? implode(',' , $giorni) : null, + 'ora_inizio' =>$ora_inizio, + 'ora_fine' => $ora_fine, + 'include_bank_holidays' => $include_bank_holidays, + ], [ + 'id' => $id_record, + ]); + + + flash()->info(tr('Salvataggio completato.')); + } else { + flash()->error(tr("E' già presente una _TYPE_ con lo stesso nome", [ + '_TYPE_' => 'fascia oraria', + ])); + } + + break; + + case 'add': + $nome = post('nome'); + + if ($dbo->fetchNum('SELECT * FROM `in_fasceorarie` WHERE `nome`='.prepare($nome)) == 0) { + + $dbo->insert('in_fasceorarie', [ + 'nome' => $nome, + ]); + + $id_record = $dbo->lastInsertedID(); + + if (isAjaxRequest()) { + echo json_encode(['id' => $id_record, 'text' => $nome]); + } + + flash()->info(tr('Aggiunta nuova _TYPE_', [ + '_TYPE_' => 'fascia oraria', + ])); + } else { + flash()->error(tr("E' già presente una _TYPE_ con lo stesso nome", [ + '_TYPE_' => 'fascia oraria', + ])); + } + + break; + + case 'delete': + $tipi_interventi = $dbo->fetchNum('SELECT idtipointervento FROM in_fasceorarie_tipiintervento WHERE idfasciaoraria='.prepare($id_record)); + + if (isset($id_record) && empty($tipi_interventi)) { + + $dbo->delete('in_fasceorarie', [ + 'id' => $id_record, + 'can_delete' => 1, + ]); + + flash()->info(tr('_TYPE_ eliminata con successo.', [ + '_TYPE_' => 'Fascia oraria', + ])); + + } else { + + flash()->error(tr('Sono presenti dei tipi interventi collegate a questa fascia oraria.')); + + # soft delete + /*$dbo->update('in_fasceorarie', [ + 'deleted_at' => date('Y-m-d H:i:s'), + ], ['id' => $id_record, 'can_delete' => 1]);*/ + } + + break; +} diff --git a/modules/fasce_orarie/add.php b/modules/fasce_orarie/add.php new file mode 100644 index 000000000..afb7a3023 --- /dev/null +++ b/modules/fasce_orarie/add.php @@ -0,0 +1,38 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +?>
+ + + +
+
+ {[ "type": "text", "label": "", "name": "nome", "required": 1 ]} +
+
+ + +
+
+ +
+
+
diff --git a/modules/fasce_orarie/ajax/select.php b/modules/fasce_orarie/ajax/select.php new file mode 100644 index 000000000..26261053e --- /dev/null +++ b/modules/fasce_orarie/ajax/select.php @@ -0,0 +1,35 @@ +. + */ + +include_once __DIR__.'/../../../core.php'; + +switch ($resource) { + case 'fasce_orarie': + $query = 'SELECT id, nome AS descrizione FROM in_fasceorarie |where| ORDER BY nome ASC'; + + foreach ($elements as $element) { + $filter[] = 'id='.prepare($element); + } + + if (!empty($search)) { + $search_fields[] = 'nome LIKE '.prepare('%'.$search.'%'); + } + + break; +} diff --git a/modules/fasce_orarie/edit.php b/modules/fasce_orarie/edit.php new file mode 100644 index 000000000..1123a91dc --- /dev/null +++ b/modules/fasce_orarie/edit.php @@ -0,0 +1,182 @@ +. + */ + + +include_once __DIR__.'/../../core.php'; + +//$block_edit = $record['is_predefined']; + +?> + +
+ + + + +
+
+

+
+ +
+
+
+ {[ "type": "text", "label": "", "name": "nome", "required": 1, "value": "$nome$" ]} +
+ +
+ {[ "type": "select", "multiple":"1", "label": "", "name": "giorni[]", "required": 0, "value": "$giorni$", "values": "list=\"1\":\"\", \"2\":\"\", \"3\":\"\", \"4\":\"\", \"5\":\"\", \"6\":\"\", \"7\":\"\"" ]} +
+
+ +
+
+ {[ "type": "time", "label": "", "name": "ora_inizio", "required": 1, "value": "$ora_inizio$" ]} +
+ +
+ {[ "type": "time", "label": "", "name": "ora_fine", "required": 1, "value": "$ora_fine$" ]} +
+ +
+ {[ "type": "checkbox", "label": "", "name": "include_bank_holidays", "required": 0, "value": "$include_bank_holidays$" ]} +
+ + + +
+
+
+ + +
+
+

+
+ +
+
+ + fetchArray('SELECT * FROM `co_pagamenti` WHERE descrizione='.prepare($record['descrizione']).' ORDER BY `num_giorni` ASC'); + $numero_data = 1; + foreach ($results as $result) { + + } + + ?> + +
+
+ + + +
+
+
+ +
+ + + +
+
+

'.tr('Nuova data').'

+
+
+ + +
+
+ {[ "type": "text", "label": "'.tr('Nome').'", "name": "nome[-id-]"]} +
+ +
+ {[ "type": "date", "label": "'.tr('Data').'", "name": "data[-id-]" ]} +
+ +
+ {[ "type": "checkbox", "label": "'.tr('Data ricorrente').'", "name": "data_ricorrente[-id-]", "value": "" ]} +
+
+ +
+
+'; + +?> + + +fetchArray('SELECT in_tipiintervento.codice, in_tipiintervento.descrizione, in_tipiintervento.idtipointervento FROM in_tipiintervento LEFT JOIN in_fasceorarie_tipiintervento ON in_tipiintervento.idtipointervento=in_fasceorarie_tipiintervento.idtipointervento WHERE in_fasceorarie_tipiintervento.idfasciaoraria='.prepare($id_record)); + +if (!empty($elementi)) { + echo ' +
+
+

'.tr('Tipi interventi collegati: _NUM_', [ + '_NUM_' => count($elementi), + ]).'

+
+ +
+
+
+
    '; + + foreach ($elementi as $elemento) { + $descrizione = tr('_REF_ (_TIPO_INTERVENTO_)', [ + '_REF_' => $elemento['descrizione'], + '_TIPO_INTERVENTO_' => $elemento['codice'], + ]); + + $modulo = 'Tipi di intervento'; + $id = $elemento['idtipointervento']; + + echo ' +
  • '.Modules::link($modulo, $id, $descrizione).'
  • '; + + } + + echo ' +
+
+
'; +} + +?> + + + + diff --git a/modules/fasce_orarie/init.php b/modules/fasce_orarie/init.php new file mode 100644 index 000000000..05d90bc3b --- /dev/null +++ b/modules/fasce_orarie/init.php @@ -0,0 +1,24 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +if (isset($id_record)) { + $record = $dbo->fetchOne('SELECT * FROM `in_fasceorarie` WHERE id='.prepare($id_record)); +} diff --git a/src/Util/Query.php b/src/Util/Query.php index 2aed990ca..ac954036a 100755 --- a/src/Util/Query.php +++ b/src/Util/Query.php @@ -79,7 +79,7 @@ class Query $user = Auth::user(); // Sostituzione periodi temporali - preg_match('|date_period\((.+?)\)|', $query, $matches); + preg_match('|date_period\((.+?)\)|', (string) $query, $matches); $date_query = $date_filter = null; if (!empty($matches)) { $dates = explode(',', $matches[1]); @@ -102,7 +102,7 @@ class Query } // Sostituzione periodi temporali - preg_match('|segment\((.+?)\)|', $query, $matches); + preg_match('|segment\((.+?)\)|', (string) $query, $matches); $segment_name = !empty($matches[1]) ? $matches[1] : 'id_segment'; $segment_filter = !empty($matches[0]) ? $matches[0] : 'segment'; diff --git a/update/2_4_33.php b/update/2_4_33.php new file mode 100644 index 000000000..884e9112c --- /dev/null +++ b/update/2_4_33.php @@ -0,0 +1,25 @@ +fetchArray('SELECT * FROM in_fasceorarie'); +$tipi_intervento = $database->fetchArray('SELECT * FROM in_tipiintervento'); + +foreach ($fascie_orarie as $fascia_oraria) { + + foreach ($tipi_intervento as $tipo_intervento) { + + $database->insert('in_fasceorarie_tipiintervento', [ + 'idfasciaoraria' => $fascia_oraria['id'], + 'idtipointervento' => $tipo_intervento['idtipointervento'], + 'costo_orario' => $tipo_intervento['costo_orario'], + 'costo_km' => $tipo_intervento['costo_km'], + 'costo_diritto_chiamata' => $tipo_intervento['costo_diritto_chiamata'], + 'costo_orario_tecnico' => $tipo_intervento['costo_orario_tecnico'], + 'costo_km_tecnico' => $tipo_intervento['costo_km_tecnico'], + 'costo_diritto_chiamata_tecnico' => $tipo_intervento['costo_km_tecnico'], + ]); + + } + +} + +?> \ No newline at end of file diff --git a/update/2_4_33.sql b/update/2_4_33.sql new file mode 100644 index 000000000..3043b741d --- /dev/null +++ b/update/2_4_33.sql @@ -0,0 +1,70 @@ +-- Nuovo modulo "Fasce orarie" +CREATE TABLE IF NOT EXISTS `in_fasceorarie` ( + `id` int NOT NULL AUTO_INCREMENT, + `nome` varchar(255) NOT NULL, + `giorni` varchar(255) DEFAULT NULL, + `ora_inizio` time DEFAULT NULL, + `ora_fine` time DEFAULT NULL, + `can_delete` BOOLEAN NOT NULL DEFAULT TRUE, + `include_bank_holidays` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) +) ENGINE=InnoDB; + +INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`, `use_notes`, `use_checklists`) VALUES (NULL, 'Fasce orarie', 'Fasce orarie', 'fasce_orarie', 'SELECT |select| FROM `in_fasceorarie` WHERE 1=1 HAVING 2=2', '', 'fa fa-angle-right', '2.4.32', '2.4.32', '1', (SELECT id FROM zz_modules t WHERE t.name = 'Interventi'), '1', '1', '0', '0'); + +INSERT INTO `zz_views` (`id`, `id_module`, `name`, `query`, `order`, `visible`, `format`, `default`) VALUES +(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Fasce orarie'), 'id', 'in_fasceorarie.id', 1, 1, 0, 1), +(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Fasce orarie'), 'Nome', 'in_fasceorarie.nome', 2, 1, 0, 1), +(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Fasce orarie'), 'Festività', 'IF(in_fasceorarie.include_bank_holidays, ''Sì'', ''No'')', 3, 1, 0, 1); + + + +-- Fascia oraria "Ordinaria" +INSERT INTO `in_fasceorarie` (`id`, `nome`, `giorni`, `ora_inizio`, `ora_fine`, `can_delete`) VALUES (NULL, 'Ordinario', '1,2,3,4,5,6,7', '00:00', '23:59', '0'); + +-- Relazione fasca oraria / tipo intervento +CREATE TABLE IF NOT EXISTS `in_fasceorarie_tipiintervento` ( + `idfasciaoraria` int NOT NULL, + `idtipointervento` int NOT NULL, + `costo_orario` decimal(12,6) NOT NULL, + `costo_km` decimal(12,6) NOT NULL, + `costo_diritto_chiamata` decimal(12,6) NOT NULL, + `costo_orario_tecnico` decimal(12,6) NOT NULL, + `costo_km_tecnico` decimal(12,6) NOT NULL, + `costo_diritto_chiamata_tecnico` decimal(12,6) NOT NULL, + PRIMARY KEY (`idfasciaoraria`,`idtipointervento`), + FOREIGN KEY (`idfasciaoraria`) REFERENCES `in_fasceorarie` (`id`), + FOREIGN KEY (`idtipointervento`) REFERENCES `in_tipiintervento` (`idtipointervento`), + KEY `idtipointervento` (`idtipointervento`) +) ENGINE=InnoDB; + + +-- Nuovo modulo "Eventi" +CREATE TABLE IF NOT EXISTS `zz_events` ( + `id` int NOT NULL AUTO_INCREMENT, + `nome` varchar(255) NOT NULL, + `data` date NOT NULL, + `id_nazione` int NOT NULL, + `id_regione` int DEFAULT NULL, + `is_recurring` tinyint(1) NOT NULL DEFAULT '0', + `is_bank_holiday` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + FOREIGN KEY (`id_nazione`) REFERENCES `an_nazioni` (`id`) +) ENGINE=InnoDB; + + +INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`, `use_notes`, `use_checklists`) VALUES (NULL, 'Eventi', 'Eventi', 'eventi', 'SELECT |select| FROM `zz_events` INNER JOIN `an_nazioni` ON `an_nazioni`.id = `zz_events`.id_nazione WHERE 1=1 HAVING 2=2', '', 'fa fa-angle-right', '2.4.32', '2.4.32', '1', (SELECT id FROM zz_modules t WHERE t.name = 'Tabelle'), '1', '1', '0', '0'); + +INSERT INTO `zz_views` (`id`, `id_module`, `name`, `query`, `order`, `visible`, `format`, `default`) VALUES +(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Eventi'), 'id', 'zz_events.id', 1, 0, 0, 1), +(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Eventi'), 'Nome', 'zz_events.nome', 2, 1, 0, 1), +(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Eventi'), 'Nazione', 'an_nazioni.nome', 3, 1, 0, 1) +(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Eventi'), 'Data', 'zz_events.data', 4, 1, 1, 1),; + +-- Natale +INSERT INTO `zz_events` (`id`, `nome`, `data`, `id_nazione`, `id_regione`, `is_recurring`, `is_bank_holiday`) VALUES (NULL, 'Natale', '2022-12-25', (SELECT id FROM an_nazioni WHERE nome = 'Italia'), NULL, '1', '1'); + +-- Fix ordine colonne Conto dare e Conto avere in Prima nota +UPDATE `zz_views` SET `order` = '8' WHERE `zz_views`.`name` = 'Conto dare'; +UPDATE `zz_views` SET `order` = '9' WHERE `zz_views`.`name` = 'Conto avere'; +UPDATE `zz_views` SET `order` = '20' WHERE `zz_views`.`name` = '_print_'; diff --git a/update/tables.php b/update/tables.php index a3d0ee182..2fc3a048e 100755 --- a/update/tables.php +++ b/update/tables.php @@ -82,6 +82,8 @@ return [ 'in_tariffe', 'in_tipiintervento', 'in_vociservizio', + 'in_fasceorarie', + 'in_fasceorarie_tipiintervento', 'mg_articoli', 'mg_fornitore_articolo', 'mg_categorie', @@ -118,6 +120,7 @@ return [ 'zz_checklist_items', 'zz_documenti', 'zz_documenti_categorie', + 'zz_events', 'zz_field_record', 'zz_fields', 'zz_files',