diff --git a/modules/anagrafiche/ajax/select.php b/modules/anagrafiche/ajax/select.php index d47e68905..6187c6f20 100644 --- a/modules/anagrafiche/ajax/select.php +++ b/modules/anagrafiche/ajax/select.php @@ -295,6 +295,22 @@ switch ($resource) { break; + + case 'relazioni': + + $query = 'SELECT id, descrizione, colore AS _bgcolor_ FROM an_relazioni ORDER BY descrizione'; + + foreach ($elements as $element) { + $filter[] = 'id='.prepare($element); + } + + if (!empty($search)) { + $search_fields[] = 'descrizione LIKE '.prepare('%'.$search.'%'); + } + + break; + + case 'dichiarazioni_intento': $query = "SELECT id, CONCAT_WS(' - ', numero_protocollo, numero_progressivo) as descrizione FROM co_dichiarazioni_intento |where| ORDER BY data"; diff --git a/modules/anagrafiche/edit.php b/modules/anagrafiche/edit.php index a70cf5b7b..87edec15b 100644 --- a/modules/anagrafiche/edit.php +++ b/modules/anagrafiche/edit.php @@ -296,7 +296,7 @@ echo '
- {[ "type": "select", "label": "'.tr('Relazione con il cliente').'", "name": "idrelazione", "values": "query=SELECT id, descrizione, colore AS _bgcolor_ FROM an_relazioni ORDER BY descrizione", "value": "$idrelazione$" ]} + {[ "type": "select", "label": "'.tr('Relazione con il cliente').'", "name": "idrelazione", "ajax-source": "relazioni", "value": "$idrelazione$", "icon-after": "add|'.Modules::get('Relazioni')['id'].'" ]}
diff --git a/modules/relazioni_anagrafiche/actions.php b/modules/relazioni_anagrafiche/actions.php new file mode 100644 index 000000000..4631f4983 --- /dev/null +++ b/modules/relazioni_anagrafiche/actions.php @@ -0,0 +1,67 @@ +fetchNum('SELECT * FROM `an_relazioni` WHERE `descrizione`='.prepare($descrizione).' AND `id`!='.prepare($id_record)) == 0) { + $dbo->query('UPDATE `an_relazioni` SET `descrizione`='.prepare($descrizione).', `colore`='.prepare($colore).' WHERE `id`='.prepare($id_record)); + flash()->info(tr('Salvataggio completato.')); + } else { + flash()->error(tr("E' già presente una relazione _NAME_.", [ + '_TYPE_' => $descrizione, + ])); + } + } else { + flash()->error(tr('Ci sono stati alcuni errori durante il salvataggio.')); + } + + break; + + case 'add': + $descrizione = filter('descrizione'); + $colore = filter('colore'); + + if (isset($descrizione)) { + if ($dbo->fetchNum('SELECT * FROM `an_relazioni` WHERE `descrizione`='.prepare($descrizione)) == 0) { + $dbo->query('INSERT INTO `an_relazioni` (`descrizione`, `colore` ) VALUES ('.prepare($descrizione).', '.prepare($colore).' )'); + + $id_record = $dbo->lastInsertedID(); + + if (isAjaxRequest()) { + echo json_encode(['id' => $id_record, 'text' => $descrizione]); + } + + flash()->info(tr('Aggiunta nuova relazione _NAME_', [ + '_NAME_' => $descrizione, + ])); + } else { + flash()->error(tr("E' già presente una relazione di _NAME_.", [ + '_NAME_' => $descrizione, + ])); + } + } else { + flash()->error(tr('Ci sono stati alcuni errori durante il salvataggio.')); + } + + break; + + case 'delete': + + $righe = $dbo->fetchNum('SELECT idanagrafica FROM an_anagrafiche WHERE idrelazione='.prepare($id_record)); + + if (isset($id_record) && empty($righe)) { + $dbo->query('DELETE FROM `an_relazioni` WHERE `id`='.prepare($id_record)); + flash()->info(tr('Relazione _NAME_ eliminata con successo!', [ + '_NAME_' => $descrizione, + ])); + } else { + flash()->error(tr('Sono presenti '.count($righe).' anagrafiche collegate a questa relazione.')); + } + + break; +} diff --git a/modules/relazioni_anagrafiche/add.php b/modules/relazioni_anagrafiche/add.php new file mode 100644 index 000000000..8257b369d --- /dev/null +++ b/modules/relazioni_anagrafiche/add.php @@ -0,0 +1,34 @@ +
+ + + +
+
+ {[ "type": "text", "label": "", "name": "descrizione", "required": 1 ]} +
+ +
+ {[ "type": "text", "label": "", "name": "colore", "required": 1, "class": "colorpicker text-center", "value": "", "extra": "maxlength='7'", "icon-after": "
" ]} +
+
+ + +
+
+ +
+
+
+ + \ No newline at end of file diff --git a/modules/relazioni_anagrafiche/edit.php b/modules/relazioni_anagrafiche/edit.php new file mode 100644 index 000000000..df4021e59 --- /dev/null +++ b/modules/relazioni_anagrafiche/edit.php @@ -0,0 +1,60 @@ +
+ + + + +
+
+

+
+ +
+
+
+ {[ "type": "text", "label": "", "name": "descrizione", "required": 1, "value": "$descrizione$" ]} +
+ +
+ {[ "type": "text", "label": "", "name": "colore", "required": 1, "class": "colorpicker text-center", "value": "$colore$", "extra": "maxlength='7'", "icon-after": "
" ]} +
+ +
+
+
+ +
+ +fetchNum('SELECT idanagrafica FROM an_anagrafiche WHERE idrelazione='.prepare($id_record)); + +if (!empty($righe)) { + echo ' +
+ '.tr('Ci sono _NUM_ anagrafiche collegate', [ + '_NUM_' => count($righe), + ]).'. +
'; +}else{ +?> + + + + + + + + + \ No newline at end of file diff --git a/modules/relazioni_anagrafiche/init.php b/modules/relazioni_anagrafiche/init.php new file mode 100644 index 000000000..820c0a54e --- /dev/null +++ b/modules/relazioni_anagrafiche/init.php @@ -0,0 +1,7 @@ +fetchOne('SELECT * FROM `an_relazioni` WHERE id='.prepare($id_record)); +} diff --git a/update/2_4_13.sql b/update/2_4_13.sql index bba41be9d..d5e81cd5a 100644 --- a/update/2_4_13.sql +++ b/update/2_4_13.sql @@ -124,3 +124,14 @@ INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`, ((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stato email'), 'Modulo', '(SELECT zz_modules.title FROM zz_modules WHERE zz_modules.id = em_templates.id_module)', 3, 1, 0, 1, 1, 0), ((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stato email'), 'Destinatari', '(SELECT GROUP_CONCAT(address SEPARATOR "
") FROM em_email_receiver WHERE em_email_receiver.id_email = em_emails.id)', 1, 1, 0, 1, 1, 0); +-- Modulo Relazioni +INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Relazioni', 'Relazioni', 'relazioni_anagrafiche', 'SELECT |select| +FROM `an_relazioni` +WHERE 1=1 +HAVING 2=2 +ORDER BY `an_relazioni`.`created_at` DESC', '', 'fa fa-angle-right ', '2.4.13', '2.*', '1', (SELECT `id` FROM `zz_modules` t WHERE t.`name` = 'Anagrafiche'), '1', '1'); + +INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`, `default`, `visible`, `format`) VALUES +((SELECT `id` FROM `zz_modules` WHERE `name` = 'Relazioni'), 'id', 'an_relazioni.id', 1, 0, 0, 1, 0, 0), +((SELECT `id` FROM `zz_modules` WHERE `name` = 'Relazioni'), 'Descrizione', 'an_relazioni.descrizione', 2, 1, 0, 1, 1, 0), +((SELECT `id` FROM `zz_modules` WHERE `name` = 'Relazioni'), 'Colore', 'an_relazioni.colore', 3, 1, 0, 1, 1, 0); \ No newline at end of file