From 750e56f0e951b4b911e4538f99a4e9e3f49233e7 Mon Sep 17 00:00:00 2001 From: Flavio Barachino Date: Fri, 5 Sep 2025 12:10:17 +0200 Subject: [PATCH] =?UTF-8?q?Aggiunto=20la=20possibilit=C3=A0=20nelle=20rego?= =?UTF-8?q?le=20di=20importazione=20di=20poter=20aggiungere=20una=20nuova?= =?UTF-8?q?=20categoria?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Movimenti.php | 34 +++++++++++-------- public/js/app/import_rules.js | 31 +++++++++++++++++ resources/views/import_rules/create.blade.php | 7 ++++ 3 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 public/js/app/import_rules.js diff --git a/app/Models/Movimenti.php b/app/Models/Movimenti.php index 855e325..354b5d4 100644 --- a/app/Models/Movimenti.php +++ b/app/Models/Movimenti.php @@ -95,6 +95,9 @@ public function ContoA() 'mov_fk_tags'=>$request->mov_fk_tags, 'mov_inserito_da'=>$request->userid, 'conto_id'=>$request->conto_id, + + // 'conto_id_da'=>$request->conto_id_da, + // 'conto_id_a'=>$request->conto_id_a, ]); } @@ -217,21 +220,24 @@ public function ContoA() public static function listByCategory($cat) { - $expression=DB::raw(' SELECT a.id, - a.mov_data, - a.mov_importo_dare, - a.mov_importo_avere, - a.mov_descrizione, - c.cat_name, - t.tag_name, - (SELECT Count(entity_id) as quanti FROM gen_docs WHERE entity=0 AND entity_id = a.id) as quanti - FROM movimentis as a - JOIN tags as t ON a.mov_fk_tags=t.id - JOIN categories as c ON a.mov_fk_categoria=c.id - WHERE a.mov_fk_categoria = '.$cat ); + // $expression=DB::raw(' SELECT a.id, + // a.mov_data, + // a.mov_importo_dare, + // a.mov_importo_avere, + // a.mov_descrizione, + // c.cat_name, + // t.tag_name, + // (SELECT Count(entity_id) as quanti FROM gen_docs WHERE entity=0 AND entity_id = a.id) as quanti + // FROM movimentis as a + // JOIN tags as t ON a.mov_fk_tags=t.id + // JOIN categories as c ON a.mov_fk_categoria=c.id + // WHERE a.mov_fk_categoria = '.$cat ); - $query = $expression->getValue(DB::connection()->getQueryGrammar()); - return DB::select($query); + // $query = $expression->getValue(DB::connection()->getQueryGrammar()); + // return DB::select($query); + return self::with(['Tags', 'Categorie']) + ->where('mov_fk_categoria', $cat) + ->get(); } diff --git a/public/js/app/import_rules.js b/public/js/app/import_rules.js new file mode 100644 index 0000000..429d0a9 --- /dev/null +++ b/public/js/app/import_rules.js @@ -0,0 +1,31 @@ +$(document).ready(function() { + $('#category_id').change(function() { + if ($(this).val() === 'nuovo') { + $('#nuovo_valore').show(); + $('#nuovo_aggiungi').show(); + } else { + $('#nuovo_valore').hide(); + $('#nuovo_aggiungi').hide(); + } + }); + + $('#nuovo_aggiungi').click(function() { + var selectedValue = $('#category_id').val(); + var nuovoValore = $('#nuovo_valore').val().trim(); + + if (selectedValue === 'nuovo' && nuovoValore !== '') { + $.post('/api/categorie', { cat_name: nuovoValore,cat_entrata: 1,cat_uscita: 1, _token: $('meta[name="csrf-token"]').attr('content') }, function(data) { + if (data.success) { + // Aggiungi la nuova categoria alla select e selezionala + $('#category_id').append(new Option(nuovoValore, data.id, true, true)).trigger('change'); + $('#nuovo_valore').val('').hide(); + $('#nuovo_aggiungi').hide(); + } else { + alert('Errore durante l\'aggiunta della categoria: ' + data.message); + } + }, 'json'); + } else { + alert('Per favore, inserisci un nome valido per la nuova categoria.'); + } + }); +}); diff --git a/resources/views/import_rules/create.blade.php b/resources/views/import_rules/create.blade.php index 1564530..c295522 100644 --- a/resources/views/import_rules/create.blade.php +++ b/resources/views/import_rules/create.blade.php @@ -26,7 +26,10 @@ @foreach($categorie as $category) @endforeach + + +
@@ -44,3 +47,7 @@
@endsection + +@section('js') + +@endsection')