From 031e4957b4b828611bf1813b2e98c9a91146ddcb Mon Sep 17 00:00:00 2001 From: FlavioBarachino Date: Fri, 7 Jul 2023 13:36:33 +0200 Subject: [PATCH] Inizializzazione dei dropdown di categoria e tags --- app/Models/Categorie.php | 4 +- app/Models/Movimenti.php | 10 ++-- public/js/app/movimenti.js | 52 +++++++++++++------ .../views/conti/movimenti/list.blade.php | 2 +- 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/app/Models/Categorie.php b/app/Models/Categorie.php index a9e539b..8bb6dcd 100644 --- a/app/Models/Categorie.php +++ b/app/Models/Categorie.php @@ -22,12 +22,12 @@ class Categorie extends Model public static function listSpesa() { - return DB::table('categories')->where('cat_uscita','=',1)->get(); + return DB::table('categories')->where('cat_uscita','=',1)->orderBy('cat_name')->get(); } public static function listEntrata() { - return DB::table('categories')->where('cat_entrata','=',1)->get(); + return DB::table('categories')->where('cat_entrata','=',1)->orderBy('cat_name')->get(); } public static function inserisci($request){ diff --git a/app/Models/Movimenti.php b/app/Models/Movimenti.php index 61a7301..a58637f 100644 --- a/app/Models/Movimenti.php +++ b/app/Models/Movimenti.php @@ -10,6 +10,8 @@ use Rap2hpoutre\FastExcel\FastExcel; class Movimenti extends Model { use HasFactory; + protected $dates = ['mov_data']; + protected $casts = [ 'mov_data'=>'datetime']; public static function getList() { return DB::table('movimentis') @@ -179,7 +181,8 @@ class Movimenti extends Model if($line['DARE']<>'') { $dati=[ - 'mov_data'=>self::dateFormat(0,$line['VALUTA']), + 'mov_data'=>self::dateFormat(0,$line['VALUTA']), // date_format(date_create($movimento->mov_data),'d/m/Y' + // 'mov_data'=>date_format(date_create($line['VALUTA']),'Y-m-d'), 'mov_fk_categoria'=>1, 'mov_descrizione'=>$line['DESCRIZIONE OPERAZIONE'], 'mov_importo'=>'-'.trim(str_replace(',','.',(str_replace('.','',$line['DARE'])))), @@ -191,6 +194,7 @@ class Movimenti extends Model { $dati=[ 'mov_data'=>self::dateFormat(0,$line['VALUTA']), + //'mov_data'=>date_format(date_create($line['VALUTA']),'Y-m-d'), 'mov_fk_categoria'=>1, 'mov_descrizione'=>$line['DESCRIZIONE OPERAZIONE'], 'mov_importo'=>trim(str_replace(',','.',(str_replace('.','',$line['AVERE'])))), @@ -216,11 +220,11 @@ class Movimenti extends Model if($type) { - $string=$string->format('Y-m-d'); + // $string=$string->format('Y-m-d'); list($year,$month,$day) = explode('-',$string); return $day.'/'.$month.'/'.$year; } else { - $string=$string->format('d/m/Y'); + // $string=$string->format('d/m/Y'); list($day,$month,$year) =explode('/',$string); return $year.'-'.$month.'-'.$day; } diff --git a/public/js/app/movimenti.js b/public/js/app/movimenti.js index c2a67fa..feafdaa 100644 --- a/public/js/app/movimenti.js +++ b/public/js/app/movimenti.js @@ -24,24 +24,32 @@ var strDate = d.getFullYear() + '-' + $(document).on('click', '.open_modal_spesa', function() { console.log(strDate); $("#categoria").empty(); + $("#tags").empty(); $('#form').find('input[type="text"], textarea, input[type="number"],input[type="date"],option').val(""); $('#form').find('input[type="date"]').val(strDate); $('#myModal').modal('show'); $('.modal-title').text(' Nuovo movimento in uscita'); $('#form').attr('action', '/admin/movimenti/spesa'); - $.getJSON("/admin/service/catlistSpesa", {}, function(data) { - $.each(data, function(i, item) { + $.getJSON("/admin/service/catlistSpesa", {}, function(cats) { + $.each(cats, function(i, cat) { $("select[name='mov_fk_categoria']").append( - new Option(item.cat_name, item.id) + new Option(cat.cat_name, cat.id) ) } ); }); + $.getJSON("/admin/service/taglist", {}, function(tags) { + $.each(tags, function(i, tag) { + $("select[name='mov_fk_tags']").append( + new Option(tag.tag_name, tag.id) + ) + }); +}); }); - $(document).on('click', '.open_modal_entrata', function() { console.log(strDate); $("#categoria").empty(); + $("#tags").empty(); $('#form').find('input[type="text"], textarea, input[type="number"],option').val(""); $('#form').find('input[type="date"]').val(strDate); $('#myModal').modal('show'); @@ -55,12 +63,20 @@ $(document).on('click', '.open_modal_entrata', function() { } ); }); + $.getJSON("/admin/service/taglist", {}, function(data) { + $.each(data, function(i, item) { + $("select[name='mov_fk_tags']").append( + new Option(item.tag_name, item.id) + ) + }); +}); }); $(document).on('click', '.open_modal_modifica', function() { var url = "/admin/movimenti/modify"; var riga_id = $(this).val(); $("#categoria").empty(); + $("#tags").empty(); $.getJSON(url + '/' + riga_id, function(data) { // success data console.log(data[0]); @@ -80,23 +96,29 @@ $(document).on('click', '.open_modal_modifica', function() { // $('.panel-heading').text('Modifica movimento'); $('#form').attr('action', '/admin/movimenti/modify'); $('#form').append(''); + $.getJSON("/admin/service/taglist", {}, function(data) { + $.each(data, function(i, item) { + $("select[name='mov_fk_tags']").append( + new Option(item.tag_name, item.id) + ) + }); + }); + $.getJSON("/admin/service/catlist", {}, function(data) { + $.each(data, function(i, item) { + $("select[name='mov_fk_categoria']").append( + new Option(item.cat_name, item.id) + ) + } + ); + }); }); - -$.getJSON("/admin/service/catlist", {}, function(data) { - $.each(data, function(i, item) { - $("select[name='mov_fk_categoria']").append( - new Option(item.cat_name, item.id) - ) - } - ); -}); }); -$.getJSON("/admin/service/taglist", {}, function(data) { +/*$.getJSON("/admin/service/taglist", {}, function(data) { $.each(data, function(i, item) { $("select[name='mov_fk_tags']").append( new Option(item.tag_name, item.id) ) }); -}); +});*/ diff --git a/resources/views/conti/movimenti/list.blade.php b/resources/views/conti/movimenti/list.blade.php index 740dcdc..e4dc930 100644 --- a/resources/views/conti/movimenti/list.blade.php +++ b/resources/views/conti/movimenti/list.blade.php @@ -32,7 +32,7 @@ @foreach( $movimenti as $movimento ) - {{$movimento->mov_data}} + {{ $movimento->mov_data}} {{ $movimento->cat_name; }} {{ $movimento->mov_descrizione; }} € {{ $movimento->mov_importo; }}