diff --git a/app/Http/Controllers/MovimentiController.php b/app/Http/Controllers/MovimentiController.php index 28d2819..0dee858 100644 --- a/app/Http/Controllers/MovimentiController.php +++ b/app/Http/Controllers/MovimentiController.php @@ -335,6 +335,22 @@ class MovimentiController extends Controller } } + public function importGenericCsv(Request $request) + { + if ($request->hasFile('filename')) + { + $filename=$request->file('filename')->store(); + $csv_headers=Movimenti::retrieveHeaders($filename); + $db_fields=Movimenti::getDbFields(); + + return view('conti.importGeneric',['csv'=>$csv_headers,'db'=>$db_fields,'filename'=>$filename]); + } + + else { + return 'Nessun File trovato'; + } + } + public function importFile() { return view('conti.import'); @@ -345,6 +361,13 @@ class MovimentiController extends Controller return view('conti.importCR'); } + public function importFileGen() + { + return view('conti.importGen'); + } + + + /* public function test() { Movimenti::getYearsFromMovimenti(); diff --git a/app/Models/Movimenti.php b/app/Models/Movimenti.php index 2a43767..f95bc43 100644 --- a/app/Models/Movimenti.php +++ b/app/Models/Movimenti.php @@ -5,10 +5,12 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Storage; use Rap2hpoutre\FastExcel\FastExcel; use App\Models\Categorie; use App\Models\Conto; use App\Models\User; +//use Illuminate\Support\Facades\Schema; class Movimenti extends Model { @@ -45,7 +47,7 @@ JOIN categories as c ON a.mov_fk_categoria=c.id'; public function Tags() { - return $this->belongsTo(Tags::class); + return $this->belongsTo(tag::class); } public static function getList() { @@ -242,7 +244,7 @@ JOIN categories as c ON a.mov_fk_categoria=c.id'; public static function importEstrattoIng($filename) { - $inputPath='/var/www/html/gestionale_mt/public/storage/tenant'.tenant('id').'/'.$filename; + $inputPath='/var/www/html/gestionale2025/storage/app/public/'.$filename; // $outputPath='/var/www/html/gestionale_mt/public/tenant'.tenant('id').'/import/'.$filename.'.csv'; $outputPath = $inputPath.'.csv'; rename($inputPath,$outputPath); @@ -275,7 +277,7 @@ JOIN categories as c ON a.mov_fk_categoria=c.id'; public static function importEstrattoCR($filename) { - $inputPath='/var/www/html/gestionale_mt/public/storage/tenant'.tenant('id').'/'.$filename; + $inputPath='/var/www/html/gestionale2025/storage/app/public/'.$filename; // $outputPath='/var/www/html/gestionale_mt/public/'.tenant('id')."/app/".$filename; $outputPath = $inputPath.'.csv'; rename($inputPath,$outputPath); @@ -317,15 +319,27 @@ JOIN categories as c ON a.mov_fk_categoria=c.id'; } // Test filtri categoria - public function mapFieldByName($name) + public static function retrieveHeaders($filename) { - // definisce lo schema per rigenerare il file CSV secondo standard di importazione - $fields = Illuminate\Support\Facade\Schema::getColumnListing('movimentis')->mapFieldByName; - foreach ($fields as $field) - { - echo $column . "\n"; - } + $inputPath= Storage::path($filename); + $outputPath = $inputPath.'.csv'; + rename($inputPath,$outputPath); + $rows = (new FastExcel)->configureCsv(';')->import($outputPath); + $headers = array_keys($rows->first()); + return $headers; + } + + public static function getDbFields() + { + return [ + "Data movimento"=>"mov_data", + "Descrizione"=>"mov_descrizione", + "Importo"=>"mov_importo", + "Categoria"=>"mov_fk_categoria", + "Tag"=>"mov_fk_tags", + "Conto"=>"conto_id", + ]; } // Test applicazione regole diff --git a/config/adminlte.php b/config/adminlte.php index 27f2416..7c476a1 100644 --- a/config/adminlte.php +++ b/config/adminlte.php @@ -383,6 +383,11 @@ return [ 'text' => 'Importa Estratto conto Cassa Rurale', 'route' => 'importCR', ], + [ + 'text' => 'Importa Generic CSV', + 'route' => 'importGen', + ], + ], ], ], diff --git a/resources/views/conti/importGen.blade.php b/resources/views/conti/importGen.blade.php new file mode 100644 index 0000000..8c46167 --- /dev/null +++ b/resources/views/conti/importGen.blade.php @@ -0,0 +1,27 @@ +@extends('adminlte::page') + +@section('content_header') +