From f693de6d37c783cf1def02ae9e2bad2a19ccb0b7 Mon Sep 17 00:00:00 2001 From: Luca Date: Thu, 28 Mar 2019 18:40:19 +0100 Subject: [PATCH] Aggiunto modulo per gestire gli stati dei preventivi --- modules/stati_intervento/api/retrieve.php | 2 +- modules/stati_intervento/edit.php | 2 +- modules/stati_preventivo/actions.php | 53 +++++++++++++++++ modules/stati_preventivo/add.php | 38 +++++++++++++ modules/stati_preventivo/api/retrieve.php | 22 ++++++++ modules/stati_preventivo/edit.php | 69 +++++++++++++++++++++++ modules/stati_preventivo/init.php | 7 +++ modules/tipi_intervento/edit.php | 2 +- update/2_4_9.sql | 17 +++++- 9 files changed, 208 insertions(+), 4 deletions(-) create mode 100644 modules/stati_preventivo/actions.php create mode 100644 modules/stati_preventivo/add.php create mode 100644 modules/stati_preventivo/api/retrieve.php create mode 100644 modules/stati_preventivo/edit.php create mode 100644 modules/stati_preventivo/init.php diff --git a/modules/stati_intervento/api/retrieve.php b/modules/stati_intervento/api/retrieve.php index 5b233de38..7ff7c4db8 100644 --- a/modules/stati_intervento/api/retrieve.php +++ b/modules/stati_intervento/api/retrieve.php @@ -1,7 +1,7 @@
- {[ "type": "checkbox", "label": "", "name": "notifica", "value": "$notifica$" ]} + {[ "type": "checkbox", "label": "", "name": "notifica", "help": ".", "value": "$notifica$" ]}
diff --git a/modules/stati_preventivo/actions.php b/modules/stati_preventivo/actions.php new file mode 100644 index 000000000..99e691c26 --- /dev/null +++ b/modules/stati_preventivo/actions.php @@ -0,0 +1,53 @@ +update('co_statipreventivi', [ + 'descrizione' => (count($dbo->fetchArray('SELECT descrizione FROM co_statipreventivi WHERE descrizione = '.prepare(post('descrizione')))) > 0) ? $dbo->fetchOne('SELECT descrizione FROM co_statipreventivi WHERE id ='.$id_record)['descrizione'] : post('descrizione'), + 'icona' => post('icona'), + 'is_completato' => post('is_completato') ?: null, + 'is_fatturabile' => post('is_fatturabile') ?: null, + 'is_pianificabile' => post('is_pianificabile') ?: null, + ], ['id' => $id_record]); + + flash()->info(tr('Informazioni salvate correttamente.')); + + break; + + case 'add': + + $descrizione = post('descrizione'); + $icona = post('icona'); + $is_completato = post('is_completato') ?: null; + $is_fatturabile = post('is_fatturabile') ?: null; + $is_pianificabile = post('is_pianificabile') ?: null; + + //controlla descrizione che non sia duplicata + if (count($dbo->fetchArray('SELECT descrizione FROM co_statipreventivi WHERE descrizione='.prepare($descrizione))) > 0) { + flash()->error(tr('Stato di preventivo già esistente.')); + } else { + $query = 'INSERT INTO co_statipreventivi(descrizione, icona, is_completato, is_fatturabile, is_pianificabile) VALUES ('.prepare($descrizione).', '.prepare($icona).', '.prepare($is_completato).', '.prepare($is_fatturabile).', '.prepare($is_pianificabile).' )'; + $dbo->query($query); + $id_record = $dbo->lastInsertedID(); + flash()->info(tr('Nuovo stato preventivo aggiunto.')); + } + + break; + + case 'delete': + + //scelgo se settare come eliminato o cancellare direttamente la riga se non è stato utilizzato nei preventivi + if (count($dbo->fetchArray('SELECT id FROM co_preventivi WHERE idstato='.prepare($id_record))) > 0) { + $query = 'UPDATE co_statipreventivi SET deleted_at = NOW() WHERE id='.prepare($id_record); + } else { + $query = 'DELETE FROM co_statipreventivi WHERE id='.prepare($id_record); + } + + $dbo->query($query); + + flash()->info(tr('Stato preventivo eliminato.')); + + break; +} diff --git a/modules/stati_preventivo/add.php b/modules/stati_preventivo/add.php new file mode 100644 index 000000000..ef2f8c60c --- /dev/null +++ b/modules/stati_preventivo/add.php @@ -0,0 +1,38 @@ +
+ + + +
+
+ {[ "type": "text", "label": "", "name": "descrizione", "required": 1 ]} +
+
+ +
+
+ {[ "type": "checkbox", "label": "", "name": "is_completato", "value": "$is_completato$", "help": "", "placeholder": "", "extra": "" ]} +
+ +
+ {[ "type": "checkbox", "label": "", "name": "is_pianificabile", "value": "$is_pianificabile$", "help": "", "placeholder": "", "extra": "" ]} +
+ +
+ {[ "type": "checkbox", "label": "", "name": "is_fatturabile", "value": "$is_fatturabile$", "help": "", "placeholder": "", "extra": "" ]} +
+
+ {[ "type": "text", "label": "", "name": "icona", "required": 1, "class": "text-center", "value": "fa ", "extra": "" ]} +
+
+ + +
+
+ +
+
+
\ No newline at end of file diff --git a/modules/stati_preventivo/api/retrieve.php b/modules/stati_preventivo/api/retrieve.php new file mode 100644 index 000000000..af31f366f --- /dev/null +++ b/modules/stati_preventivo/api/retrieve.php @@ -0,0 +1,22 @@ + 'id', + ]; + + if (empty($where['deleted_at'])) { + $where['deleted_at'] = null; + } + + break; +} + +return [ + 'stati_preventivo', +]; diff --git a/modules/stati_preventivo/edit.php b/modules/stati_preventivo/edit.php new file mode 100644 index 000000000..cd5e98c50 --- /dev/null +++ b/modules/stati_preventivo/edit.php @@ -0,0 +1,69 @@ +fetchArray('SELECT id FROM co_preventivi WHERE idstato='.prepare($id_record))); + +if ($preventivi == 0) { + + $attr = ''; + +} else { + + $attr = 'readonly'; + echo '
'.tr('Alcune impostazioni non possono essere modificate per questo stato perché già utilizzato in alcuni preventivi.').'
'; + +} +?> +
+ + + + +
+ + +
+ {[ "type": "text", "label": "", "name": "descrizione", "required": 1, "value": "$descrizione$" ]} +
+ +
+ {[ "type": "checkbox", "label": "", "name": "is_completato", "value": "$is_completato$", "help": "", "placeholder": "", "extra": "" ]} +
+ +
+ {[ "type": "checkbox", "label": "", "name": "is_pianificabile", "value": "$is_pianificabile$", "help": "", "placeholder": "", "extra": "" ]} +
+ +
+ {[ "type": "checkbox", "label": "", "name": "is_fatturabile", "value": "$is_fatturabile$", "help": "", "placeholder": "", "extra": "" ]} +
+ +
+ +
+ +
+ {[ "type": "text", "label": "", "name": "icona", "required": 1, "class": "text-center", "value": "$icona$", "extra": "" ]} +
+ +
+ +
+ + + + '.tr('Ci sono _NUM_ preventivi collegati', [ + '_NUM_' => $preventivi, + ]).'. +
'; +} +?> + + + + \ No newline at end of file diff --git a/modules/stati_preventivo/init.php b/modules/stati_preventivo/init.php new file mode 100644 index 000000000..1d8336f51 --- /dev/null +++ b/modules/stati_preventivo/init.php @@ -0,0 +1,7 @@ +fetchOne('SELECT * FROM co_statipreventivi WHERE id='.prepare($id_record)); +} diff --git a/modules/tipi_intervento/edit.php b/modules/tipi_intervento/edit.php index 4c1fc9427..a4e802190 100644 --- a/modules/tipi_intervento/edit.php +++ b/modules/tipi_intervento/edit.php @@ -17,7 +17,7 @@ include_once __DIR__.'/../../core.php';
- {[ "type": "number", "label": "", "name": "tempo_standard", "help": "Esempi:
  • 60 minuti = 1 ora
  • 30 minuti = 0,5 ore
  • 15 minuti = 0,25 ore
'); ?>", "maxlength": 5, "min-value": "0", "max-value": "24", "class": "text-center", "value": "$tempo_standard$", "icon-after": "ore" ]} + {[ "type": "number", "label": "", "name": "tempo_standard", "help": "Esempi:
  • 60 minuti = 1 ora
  • 30 minuti = 0,5 ore
  • 15 minuti = 0,25 ore
Suggerisce il tempo solitamente impiegato per questa tipologia di attivita'); ?>.", "maxlength": 5, "min-value": "0", "max-value": "24", "class": "text-center", "value": "$tempo_standard$", "icon-after": "ore" ]}
diff --git a/update/2_4_9.sql b/update/2_4_9.sql index 7d55e5db9..b14610027 100644 --- a/update/2_4_9.sql +++ b/update/2_4_9.sql @@ -82,4 +82,19 @@ UPDATE `zz_modules` SET `options` = 'SELECT |select| FROM `dt_ddt` INNER JOIN `d UPDATE `zz_views` SET `query` = 'co_movimenti.idmastrino' WHERE `name` = 'id' AND `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Prima nota'); -- Stato FE (Attestazione di avvenuta trasmissione della fattura con impossibilità di recapito, estensione ricevuta .zip) -INSERT INTO `fe_stati_documento` (`codice`, `descrizione`, `icon`) VALUES ('AT', 'Attestazione trasmissione', 'fa fa-check text-warning'); \ No newline at end of file +INSERT INTO `fe_stati_documento` (`codice`, `descrizione`, `icon`) VALUES ('AT', 'Attestazione trasmissione', 'fa fa-check text-warning'); + +-- Aggiungo deleted_at per co_statipreventivi e co_staticontratti +ALTER TABLE `co_statipreventivi` ADD `deleted_at` DATETIME NULL AFTER `updated_at`; +ALTER TABLE `co_staticontratti` ADD `deleted_at` DATETIME NULL AFTER `updated_at`; + +-- Aggiunto modulo per gestire gli stati dei preventivi +INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Stati dei preventivi', 'Stati dei preventivi','stati_preventivo', 'SELECT |select| FROM `co_statipreventivi` WHERE 1=1 AND deleted_at IS NULL HAVING 2=2', '', 'fa fa-angle-right', '2.4.9', '2.4.9', '1', (SELECT `id` FROM `zz_modules` t WHERE t.`name` = 'Preventivi'), '1', '1'); + +INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`, `default`) VALUES +((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stati dei preventivi'), 'Fatturabile', 'IF(is_fatturabile, ''Sì'', ''No'')', 6, 1, 0, 0), +((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stati dei preventivi'), 'Completato', 'IF(is_completato, ''Sì'', ''No'')', 5, 1, 0, 0), +((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stati dei preventivi'), 'Pianificabile', 'IF(is_pianificabile, ''Sì'', ''No'')', 4, 1, 0, 0), +((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stati dei preventivi'), 'Icona', 'icona', 3, 1, 0, 0), +((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stati dei preventivi'), 'Descrizione', 'descrizione', 2, 1, 0, 0), +((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stati dei preventivi'), 'id', 'id', 1, 0, 0, 1); \ No newline at end of file