From 6aba52df8da3f6f06301710cd004f84ab3e12859 Mon Sep 17 00:00:00 2001 From: MatteoPistorello Date: Wed, 9 Feb 2022 14:32:03 +0100 Subject: [PATCH] Fix codice aliquota iva e validazione --- modules/iva/add.php | 6 +++++- modules/iva/edit.php | 2 +- modules/iva/validation.php | 42 ++++++++++++++++++++++++++++++++++++++ update/2_4_31.sql | 5 ++++- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 modules/iva/validation.php diff --git a/modules/iva/add.php b/modules/iva/add.php index ebc4f5d58..6834ee8e1 100755 --- a/modules/iva/add.php +++ b/modules/iva/add.php @@ -19,6 +19,10 @@ include_once __DIR__.'/../../core.php'; +use Modules\Iva\Aliquota; + +$codice = Aliquota::max('id')+1; + ?>
@@ -29,7 +33,7 @@ include_once __DIR__.'/../../core.php';
- {[ "type": "number", "label": "", "name": "codice", "required": 1, "decimals":0, "min-value":"0", "max-value":"999", "maxlength": 3 ]} + {[ "type": "number", "label": "", "name": "codice", "required": 1, "decimals":0, "min-value":"0", "max-value":"999", "maxlength": 3, "value": "", "validation": "codice" ]}
diff --git a/modules/iva/edit.php b/modules/iva/edit.php index 61a231fb6..60ef5451d 100755 --- a/modules/iva/edit.php +++ b/modules/iva/edit.php @@ -79,7 +79,7 @@ if ($res) {
- {[ "type": "number", "label": "", "name": "codice", "value": "$codice$", "required": 1, "decimals":0, "min-value":"0", "max-value":"999", "maxlength": 3, "extra": "" ]} + {[ "type": "number", "label": "", "name": "codice", "value": "$codice$", "required": 1, "decimals":0, "min-value":"0", "max-value":"999", "maxlength": 3, "extra": "", "validation": "codice" ]}
diff --git a/modules/iva/validation.php b/modules/iva/validation.php new file mode 100644 index 000000000..f5b35d860 --- /dev/null +++ b/modules/iva/validation.php @@ -0,0 +1,42 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +use Modules\Iva\Aliquota; + +$name = filter('name'); +$value = filter('value'); + +switch ($name) { + case 'codice': + $disponibile = Aliquota::where([ + ['codice', $value], + ['id', '<>', $id_record], + ])->count() == 0; + + $message = $disponibile ? tr('Il codice è disponbile') : tr('Il codice è già utilizzato in un altra aliquota'); + + $response = [ + 'result' => $disponibile, + 'message' => $message, + ]; + + break; +} diff --git a/update/2_4_31.sql b/update/2_4_31.sql index b3b45c79b..17184ed6a 100644 --- a/update/2_4_31.sql +++ b/update/2_4_31.sql @@ -1,2 +1,5 @@ -- Aggiunta dicitura fissa nei segmenti fiscali -ALTER TABLE `zz_segments` ADD `dicitura_fissa` TEXT NOT NULL AFTER `note`; \ No newline at end of file +ALTER TABLE `zz_segments` ADD `dicitura_fissa` TEXT NOT NULL AFTER `note`; + +-- Fix codice iva +UPDATE `co_iva` SET `codice`=`id` WHERE `codice` IS NULL; \ No newline at end of file