diff --git a/mail.php b/mail.php index 3672b0901..29ed1a8b5 100755 --- a/mail.php +++ b/mail.php @@ -31,6 +31,17 @@ $subject = $module->replacePlaceholders($id_record, $template['subject']); $emails = explode(';', $module->replacePlaceholders($id_record, '{email}')); $id_anagrafica = $module->replacePlaceholders($id_record, '{id_anagrafica}'); +// Aggiungo email referenti in base alla mansione impostata nel template +$mansioni = $dbo->select('em_mansioni_template', 'idmansione', ['id_template' => $template->id]); +foreach ($mansioni as $mansione) { + $referenti = $dbo->select('an_referenti', 'email', ['idmansione' => $mansione['idmansione']]); + foreach ($referenti as $referente) { + if (!in_array($referente['email'], $emails)) { + $emails[] = $referente['email']; + } + } +} + // Campi mancanti $campi_mancanti = []; diff --git a/modules/anagrafiche/add.php b/modules/anagrafiche/add.php index e47facb35..5a50a7658 100755 --- a/modules/anagrafiche/add.php +++ b/modules/anagrafiche/add.php @@ -110,7 +110,7 @@ echo '
- {[ "type": "text", "label": "'.tr('Email').'", "name": "email", "class": "email-mask", "placeholder":"casella@dominio.ext", "icon-before": "" ]} + {[ "type": "text", "label": "'.tr('Email').'", "name": "email", "class": "email-mask", "placeholder":"casella@dominio.ext", "icon-before": "", "validation": "email" ]}
diff --git a/modules/anagrafiche/ajax/complete.php b/modules/anagrafiche/ajax/complete.php index 7c8b56ed7..79d2f0cdf 100755 --- a/modules/anagrafiche/ajax/complete.php +++ b/modules/anagrafiche/ajax/complete.php @@ -111,17 +111,4 @@ switch ($resource) { echo json_encode($results); break; - - case 'get_mansioni': - $q = 'SELECT DISTINCT mansione FROM an_referenti'; - $rs = $dbo->fetchArray($q); - $n = sizeof($rs); - - for ($i = 0; $i < $n; ++$i) { - echo html_entity_decode($rs[$i]['mansione']); - if (($i + 1) < $n) { - echo '|'; - } - } - break; } diff --git a/modules/anagrafiche/ajax/search.php b/modules/anagrafiche/ajax/search.php index d15debf0b..dd9dfbd84 100755 --- a/modules/anagrafiche/ajax/search.php +++ b/modules/anagrafiche/ajax/search.php @@ -87,10 +87,10 @@ foreach ($rs as $r) { // Referenti anagrafiche $fields = [ - 'Nome' => 'nome', - 'Mansione' => 'mansione', - 'Telefono' => 'telefono', - 'Email' => 'email', + 'Nome' => 'an_referenti.nome', + 'Mansione' => 'an_mansioni.nome', + 'Telefono' => 'an_referenti.telefono', + 'Email' => 'an_referenti.email', ]; $query = 'SELECT *, idanagrafica as id'; @@ -99,7 +99,7 @@ foreach ($fields as $name => $value) { $query .= ', '.$value." AS '".str_replace("'", "\'", $name)."'"; } -$query .= ' FROM an_referenti WHERE idanagrafica IN('.implode(',', $idanagrafiche).') '; +$query .= ' FROM an_referenti LEFT JOIN an_mansioni ON an_referenti.idmansione=an_mansioni.id WHERE idanagrafica IN('.implode(',', $idanagrafiche).') '; foreach ($fields as $name => $value) { $query .= ' OR '.$value.' LIKE "%'.$term.'%"'; diff --git a/modules/anagrafiche/ajax/select.php b/modules/anagrafiche/ajax/select.php index 3a2071819..8cb89b09c 100755 --- a/modules/anagrafiche/ajax/select.php +++ b/modules/anagrafiche/ajax/select.php @@ -289,10 +289,10 @@ switch ($resource) { */ case 'referenti': if (isset($superselect['idanagrafica'])) { - $query = 'SELECT id, nome AS descrizione, an_referenti.mansione AS optgroup FROM an_referenti |where| ORDER BY optgroup, nome'; + $query = 'SELECT an_referenti.id, an_referenti.nome AS descrizione, an_mansioni.nome AS optgroup FROM an_referenti LEFT JOIN an_mansioni ON an_referenti.idmansione=an_mansioni.id |where| ORDER BY optgroup, an_referenti.nome'; foreach ($elements as $element) { - $filter[] = 'id='.prepare($element); + $filter[] = 'an_referenti.id='.prepare($element); } if (isset($superselect['idclientefinale'])) { @@ -302,7 +302,7 @@ switch ($resource) { } if (!empty($search)) { - $search_fields[] = 'nome LIKE '.prepare('%'.$search.'%'); + $search_fields[] = 'an_referenti.nome LIKE '.prepare('%'.$search.'%'); } } break; diff --git a/modules/anagrafiche/edit.php b/modules/anagrafiche/edit.php index 14ed37a4b..1399ad6da 100755 --- a/modules/anagrafiche/edit.php +++ b/modules/anagrafiche/edit.php @@ -209,7 +209,7 @@ if (sizeof($problemi_anagrafica) > 0) {
- {[ "type": "text", "label": "", "name": "email", "placeholder": "casella@dominio.ext", "value": "$email$", "icon-before": "", "validation": "email" ]} + {[ "type": "text", "label": "", "name": "email", "class": "email-mask", "placeholder": "casella@dominio.ext", "value": "$email$", "icon-before": "", "validation": "email" ]}
diff --git a/modules/emails/actions.php b/modules/emails/actions.php index cf4d434b2..809ce23cf 100755 --- a/modules/emails/actions.php +++ b/modules/emails/actions.php @@ -48,6 +48,7 @@ switch (post('op')) { ], ['id' => $id_record]); $dbo->sync('em_print_template', ['id_template' => $id_record], ['id_print' => (array) post('prints')]); + $dbo->sync('em_mansioni_template', ['id_template' => $id_record], ['idmansione' => (array) post('idmansioni')]); flash()->info(tr('Informazioni salvate correttamente!')); diff --git a/modules/emails/edit.php b/modules/emails/edit.php index c9dea6085..d9a6ef4cc 100755 --- a/modules/emails/edit.php +++ b/modules/emails/edit.php @@ -87,13 +87,22 @@ if (!$record['predefined']) { // Stampe $selected_prints = $dbo->fetchArray('SELECT id_print FROM em_print_template WHERE id_template = '.prepare($id_record)); -$selected = array_column($selected_prints, 'id_print'); +$selected_prints = array_column($selected_prints, 'id_print'); + +$selected_mansioni = $dbo->fetchArray('SELECT idmansione FROM em_mansioni_template WHERE id_template = '.prepare($id_record)); +$selected_mansioni = array_column($selected_mansioni, 'idmansione'); echo '
- {[ "type": "select", "multiple": "1", "label": "'.tr('Stampe').'", "name": "prints[]", "value": "'.implode(',', $selected).'", "values": "query=SELECT id, title AS text FROM zz_prints WHERE id_module = '.prepare($record['id_module']).' AND enabled=1" ]} + {[ "type": "select", "multiple": "1", "label": "'.tr('Stampe').'", "name": "prints[]", "value": "'.implode(',', $selected_prints).'", "values": "query=SELECT id, title AS text FROM zz_prints WHERE id_module = '.prepare($record['id_module']).' AND enabled=1" ]} +
+
+ +
+
+ {[ "type": "select", "multiple": "1", "label": "'.tr('Mansioni').'", "name": "idmansioni[]", "value": "'.implode(',', $selected_mansioni).'", "ajax-source": "mansioni" ]}
'; diff --git a/modules/mansioni/actions.php b/modules/mansioni/actions.php new file mode 100644 index 000000000..b86ef57f4 --- /dev/null +++ b/modules/mansioni/actions.php @@ -0,0 +1,69 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +switch (post('op')) { + case 'update': + $nome = post('nome'); + + if ($dbo->fetchNum('SELECT * FROM `an_mansioni` WHERE `nome`='.prepare($nome).' AND `id`!='.prepare($id_record)) == 0) { + $dbo->query('UPDATE `an_mansioni` SET `nome`='.prepare($nome).' WHERE `id`='.prepare($id_record)); + flash()->info(tr('Salvataggio completato.')); + } else { + flash()->error(tr("E' già presente una _TYPE_ con lo stesso nome", [ + '_TYPE_' => 'mansione', + ])); + } + + break; + + case 'add': + $nome = post('nome'); + + if ($dbo->fetchNum('SELECT * FROM `an_mansioni` WHERE `nome`='.prepare($nome)) == 0) { + $dbo->query('INSERT INTO `an_mansioni` (`nome`) VALUES ('.prepare($nome).')'); + + $id_record = $dbo->lastInsertedID(); + + flash()->info(tr('Aggiunta nuova _TYPE_', [ + '_TYPE_' => 'mansione', + ])); + } else { + flash()->error(tr("E' già presente una _TYPE_ con lo stesso nome", [ + '_TYPE_' => 'mansione', + ])); + } + + break; + + case 'delete': + $referenti = $dbo->fetchNum('SELECT id FROM an_referenti WHERE idmansione='.prepare($id_record)); + + if (isset($id_record) && empty($referenti)) { + $dbo->query('DELETE FROM `an_mansioni` WHERE `id`='.prepare($id_record)); + flash()->info(tr('_TYPE_ eliminata con successo.', [ + '_TYPE_' => 'Mansione', + ])); + } else { + flash()->error(tr('Sono presenti dei referenti collegati a questa mansione.')); + } + + break; +} diff --git a/modules/mansioni/add.php b/modules/mansioni/add.php new file mode 100644 index 000000000..94a5af101 --- /dev/null +++ b/modules/mansioni/add.php @@ -0,0 +1,38 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +?>
+ + + +
+
+ {[ "type": "text", "label": "", "name": "nome", "required": 1 ]} +
+
+ + +
+
+ +
+
+
diff --git a/modules/mansioni/ajax/select.php b/modules/mansioni/ajax/select.php new file mode 100644 index 000000000..8b41e2a01 --- /dev/null +++ b/modules/mansioni/ajax/select.php @@ -0,0 +1,35 @@ +. + */ + +include_once __DIR__.'/../../../core.php'; + +switch ($resource) { + case 'mansioni': + $query = 'SELECT id, nome AS descrizione FROM an_mansioni |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/mansioni/edit.php b/modules/mansioni/edit.php new file mode 100644 index 000000000..e4ed05752 --- /dev/null +++ b/modules/mansioni/edit.php @@ -0,0 +1,60 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +?> + +
+ + + + +
+
+

+
+ +
+
+
+ {[ "type": "text", "label": "", "name": "nome", "required": 1, "value": "$nome$" ]} +
+
+
+
+
+ +fetchNum('SELECT id FROM an_referenti WHERE idmansione='.prepare($id_record)); + +if (!empty($mansioni_collegate)) { + echo ' +
+ '.tr('Ci sono _NUM_ referenti collegati', [ + '_NUM_' => $mansioni_collegate, + ]).'. +
'; +} +?> + + + + diff --git a/modules/mansioni/init.php b/modules/mansioni/init.php new file mode 100644 index 000000000..a199b8707 --- /dev/null +++ b/modules/mansioni/init.php @@ -0,0 +1,24 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +if (isset($id_record)) { + $record = $dbo->fetchOne('SELECT * FROM `an_mansioni` WHERE id='.prepare($id_record)); +} diff --git a/plugins/referenti/actions.php b/plugins/referenti/actions.php index 665a362f5..d007d5da9 100755 --- a/plugins/referenti/actions.php +++ b/plugins/referenti/actions.php @@ -27,7 +27,7 @@ switch ($operazione) { $dbo->insert('an_referenti', [ 'idanagrafica' => $id_parent, 'nome' => post('nome'), - 'mansione' => post('mansione'), + 'idmansione' => post('idmansione'), 'telefono' => post('telefono'), 'email' => post('email'), 'idsede' => post('idsede'), @@ -51,7 +51,7 @@ switch ($operazione) { $dbo->update('an_referenti', [ 'idanagrafica' => $id_parent, 'nome' => post('nome'), - 'mansione' => post('mansione'), + 'idmansione' => post('idmansione'), 'telefono' => post('telefono'), 'email' => post('email'), 'idsede' => post('idsede'), diff --git a/plugins/referenti/add.php b/plugins/referenti/add.php index 15b7083f3..32286fc4b 100755 --- a/plugins/referenti/add.php +++ b/plugins/referenti/add.php @@ -34,7 +34,7 @@ echo '
- {[ "type": "text", "label": "'.tr('Mansione').'", "name": "mansione", "required": 1 ]} + {[ "type": "select", "label": "'.tr('Mansione').'", "name": "idmansione", "ajax-source": "mansioni", "required": 1 ]}
@@ -44,7 +44,7 @@ echo '
- {[ "type": "text", "label": "'.tr('Indirizzo email').'", "name": "email" ]} + {[ "type": "text", "label": "'.tr('Indirizzo email').'", "name": "email", "class": "email-mask", "validation": "email"]}
@@ -65,11 +65,3 @@ echo ' '; -?> - diff --git a/plugins/referenti/edit.php b/plugins/referenti/edit.php index ea04449a9..a4348aea1 100755 --- a/plugins/referenti/edit.php +++ b/plugins/referenti/edit.php @@ -33,7 +33,7 @@ echo '
- {[ "type": "text", "label": "'.tr('Mansione').'", "name": "mansione", "required": 1, "value" : "$mansione$" ]} + {[ "type": "select", "label": "'.tr('Mansione').'", "name": "idmansione", "ajax-source": "mansioni", "required": 1, "value" : "$idmansione$" ]}
@@ -43,7 +43,7 @@ echo '
- {[ "type": "text", "label": "'.tr('Indirizzo email').'", "name": "email", "value" : "$email$" ]} + {[ "type": "text", "label": "'.tr('Indirizzo email').'", "name": "email", "class": "email-mask", "value" : "$email$", "validation": "email" ]}
@@ -68,11 +68,3 @@ echo ' '; -?> - diff --git a/plugins/sedi/add.php b/plugins/sedi/add.php index 58ebb4d91..8e8f0bf58 100755 --- a/plugins/sedi/add.php +++ b/plugins/sedi/add.php @@ -82,7 +82,7 @@ echo '
- {[ "type": "text", "label": "'.tr('Indirizzo email').'", "name": "email" ]} + {[ "type": "text", "label": "'.tr('Indirizzo email').'", "name": "email", "class": "email-mask", "validation": "email" ]}
diff --git a/plugins/sedi/edit.php b/plugins/sedi/edit.php index 8b1e555f4..f9b18ac18 100755 --- a/plugins/sedi/edit.php +++ b/plugins/sedi/edit.php @@ -92,7 +92,7 @@ echo '
- {[ "type": "text", "label": "'.tr('Indirizzo email').'", "name": "email", "value": "$email$" ]} + {[ "type": "text", "label": "'.tr('Indirizzo email').'", "name": "email", "value": "$email$", "class": "email-mask", "validation": "email" ]}
diff --git a/src/API/App/v1/Referenti.php b/src/API/App/v1/Referenti.php index ab245c556..93b64f841 100644 --- a/src/API/App/v1/Referenti.php +++ b/src/API/App/v1/Referenti.php @@ -50,14 +50,15 @@ class Referenti extends AppResource implements RetrieveInterface public function retrieveRecord($id) { // Gestione della visualizzazione dei dettagli del record - $query = 'SELECT id, + $query = 'SELECT an_referenti.id, idanagrafica AS id_cliente, IF(idsede = 0, NULL, idsede) AS id_sede, - nome, - mansione, + an_referenti.nome, + an_mansioni.nome AS mansione, telefono, email - FROM an_referenti + FROM an_referenti + LEFT JOIN an_mansioni ON an_referenti.idmansione=an_mansioni.id WHERE an_referenti.id = '.prepare($id); $record = database()->fetchOne($query); diff --git a/update/2_4_28.sql b/update/2_4_28.sql index be3a80cc5..fc0615de1 100644 --- a/update/2_4_28.sql +++ b/update/2_4_28.sql @@ -30,4 +30,30 @@ UPDATE `zz_prints` SET `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` UPDATE `zz_prints` SET `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name`='Stampe contabili') WHERE `zz_prints`.`name` = 'Bilancio'; -- Aggiunta stampa libro giornale -INSERT INTO `zz_prints` (`id`, `id_module`, `is_record`, `name`, `title`, `filename`, `directory`, `previous`, `options`, `icon`, `version`, `compatibility`, `order`, `predefined`, `default`, `enabled`) VALUES (NULL, (SELECT `id` FROM `zz_modules` WHERE `name`='Stampe contabili'), '1', 'Libro giornale', 'Libro giornale', 'Libro giornale', 'libro_giornale', 'idconto', '', 'fa fa-print', '', '', '0', '0', '1', '1'); \ No newline at end of file +INSERT INTO `zz_prints` (`id`, `id_module`, `is_record`, `name`, `title`, `filename`, `directory`, `previous`, `options`, `icon`, `version`, `compatibility`, `order`, `predefined`, `default`, `enabled`) VALUES (NULL, (SELECT `id` FROM `zz_modules` WHERE `name`='Stampe contabili'), '1', 'Libro giornale', 'Libro giornale', 'Libro giornale', 'libro_giornale', 'idconto', '', 'fa fa-print', '', '', '0', '0', '1', '1'); + +'-- Aggiunta tabella mansioni +CREATE TABLE IF NOT EXISTS `an_mansioni` ( `id` INT NOT NULL AUTO_INCREMENT , `nome` VARCHAR(100) NOT NULL , `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , `updated_at` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , PRIMARY KEY (`id`)); + +INSERT INTO `an_mansioni`( + `nome` +)( + SELECT DISTINCT `mansione` FROM `an_referenti` +); +ALTER TABLE `an_referenti` ADD `idmansione` INT NOT NULL AFTER `idsede`; + +UPDATE `an_referenti`, `an_mansioni` SET `idmansione`=`an_mansioni`.`id` WHERE `an_mansioni`.`nome`=`an_referenti`.`mansione`; + +ALTER TABLE `an_referenti` DROP `mansione`; + +-- Aggiunto modulo mansioni referenti +INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES +(NULL, 'Mansioni referenti', 'Mansioni referenti', 'mansioni', 'SELECT |select| FROM an_mansioni ORDER BY `nome`', NULL, 'fa fa-angle-right', '1.0', '2.*', '100', '40', '1', '1'); + +INSERT INTO `zz_views` (`id`, `id_module`, `name`, `query`, `order`, `visible`, `format`, `default`) VALUES +(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Mansioni referenti'), 'id', 'an_mansioni.id', 1, 0, 0, 1), +(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Mansioni referenti'), 'Nome', 'an_mansioni.nome', 2, 1, 0, 1); + +UPDATE `zz_plugins` SET `options` = ' { \"main_query\": [ { \"type\": \"table\", \"fields\": \"Nominativo, Mansione, Telefono, Indirizzo email, Sede\", \"query\": \"SELECT an_referenti.id, an_referenti.nome AS Nominativo, an_mansioni.nome AS Mansione, an_referenti.telefono AS Telefono, an_referenti.email AS \'Indirizzo email\', IF(idsede = 0, \'Sede legale\', an_sedi.nomesede) AS Sede FROM an_referenti LEFT OUTER JOIN an_sedi ON idsede = an_sedi.id LEFT OUTER JOIN an_mansioni ON idmansione = an_mansioni.id WHERE 1=1 AND an_referenti.idanagrafica=|id_parent| HAVING 2=2 ORDER BY an_referenti.id DESC\"} ]}' WHERE `zz_plugins`.`name` = 'Referenti'; + +CREATE TABLE IF NOT EXISTS `em_mansioni_template` ( `id` INT NOT NULL AUTO_INCREMENT , `idmansione` INT NOT NULL , `id_template` INT NOT NULL , `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , `updated_at` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`)); \ No newline at end of file