diff --git a/modules/banche/actions.php b/modules/banche/actions.php
index f7ca9367d1..e0ef47c91d 100755
--- a/modules/banche/actions.php
+++ b/modules/banche/actions.php
@@ -63,7 +63,8 @@
$banca->codice_sia = post('codice_sia');
$banca->commissioni_riba_insolute = post('commissioni_riba_insolute');
- $banca->predefined = post('predefined');
+ $banca->enabled = post('enabled');
+ $banca->predefined = $banca->enabled ? post('predefined') : 0;
$banca->save();
diff --git a/modules/banche/ajax/select.php b/modules/banche/ajax/select.php
index 6b280c275e..5c81fb86e2 100644
--- a/modules/banche/ajax/select.php
+++ b/modules/banche/ajax/select.php
@@ -34,6 +34,7 @@
if (empty($filter)) {
$where[] = 'deleted_at IS NULL';
+ $where[] = 'enabled = 1';
}
$where[] = 'id_anagrafica='.prepare($superselect['id_anagrafica']);
diff --git a/modules/banche/edit.php b/modules/banche/edit.php
index 64808fe893..445fb5f4de 100644
--- a/modules/banche/edit.php
+++ b/modules/banche/edit.php
@@ -43,7 +43,11 @@
{[ "type": "checkbox", "label": "", "name": "predefined", "value": "$predefined$", "disabled": "" ]}
-
+
+ {[ "type": "checkbox", "label": "", "name": "enabled", "value": "$enabled$" ]}
+
+
+
{[ "type": "text", "label": "", "name": "nome", "required": "1", "value": "$nome$" ]}
@@ -412,4 +416,4 @@ function createSepaBadge(value, label) {
e.preventDefault();
checkIban();
});
-
+
\ No newline at end of file
diff --git a/modules/banche/src/Banca.php b/modules/banche/src/Banca.php
index 24423c467d..3d47e65ad1 100644
--- a/modules/banche/src/Banca.php
+++ b/modules/banche/src/Banca.php
@@ -51,6 +51,7 @@ public static function build(?Anagrafica $anagrafica = null, $nome = null, $iban
$model->nome = $nome;
$model->iban = $iban;
$model->bic = $bic;
+ $model->enabled = 1;
// Salvataggio delle informazioni
$model->save();
@@ -84,11 +85,20 @@ public function save(array $options = [])
protected function fixPredefined()
{
+ $enabled = $this->enabled ?? true;
$predefined = $this->predefined ?? false;
- // Selezione automatica per primo record
+ // Una banca disabilitata non può essere predefinita.
+ if (empty($enabled)) {
+ $this->attributes['predefined'] = 0;
+
+ return;
+ }
+
+ // Selezione automatica per primo record attivo.
$count = self::where('id_anagrafica', $this->id_anagrafica)
->where('id', '!=', $this->id)
+ ->where('enabled', 1)
->count();
if (empty($predefined) && empty($count)) {
$predefined = true;
diff --git a/update/2_12.sql b/update/2_12.sql
index 201536992c..0c7fd3b619 100644
--- a/update/2_12.sql
+++ b/update/2_12.sql
@@ -102,3 +102,6 @@ INSERT INTO `zz_settings` (`nome`, `valore`, `tipo`, `editable`, `sezione`, `ord
INSERT INTO `zz_settings_lang` (`id_lang`, `id_record`, `title`, `help`) VALUES
(1, (SELECT `id` FROM `zz_settings` WHERE `nome` = 'Tipologia anagrafica predefinita'), 'Tipologia anagrafica predefinita', 'Tipologia (Azienda, Ente pubblico o Privato) preselezionata automaticamente nella finestra di aggiunta di una nuova anagrafica. Se non impostata, nessuna tipologia viene preselezionata.'),
(2, (SELECT `id` FROM `zz_settings` WHERE `nome` = 'Tipologia anagrafica predefinita'), 'Default entity classification', 'Classification (Company, Public entity or Private) automatically preselected in the new entity creation window. If not set, no classification is preselected.');
+
+-- Gestione stato attivo delle banche
+ALTER TABLE `co_banche` ADD `enabled` TINYINT(1) NOT NULL DEFAULT 1 AFTER `predefined`;