Files
2026-07-05 18:14:23 +02:00

59 lines
1.7 KiB
PHP

<?php
namespace App\Filament\Imports;
use App\Models\ProjektAllgemeinflaechen;
use Filament\Notifications\Notification;
use Illuminate\Support\Facades\Auth;
class ImportAllgemeinDirect
{
public static function run(array $data, int $projekte_id)
{
$data = explode(PHP_EOL, $data['upload_data']);
$error = 0;
$new = 0;
foreach ($data as $row) {
$row = str_replace(';', '|', $row);
$cells = explode('|', $row);
if (\count($cells) != 4) {
$error = 1;
break;
}
$geschoss = trim($cells[1]);
$raumart = trim($cells[2]);
$flaeche = (float) str_replace(',', '.', trim($cells[3]));
if (is_numeric($flaeche) && $flaeche > 0) {
$allgemein = new ProjektAllgemeinflaechen;
$allgemein->projekte_id = $projekte_id;
$allgemein->geschoss = $geschoss;
$allgemein->raumart = $raumart;
$allgemein->flaeche = $flaeche;
$allgemein->save();
$new++;
}
}
if ($error) {
Notification::make()
->title('Fehlerbeim Import')
->body('Daten konnten nicht in vier Spalten aufgeteilt werden. Falscher Separator?')
->danger()
->send()
->sendToDatabase(Auth::user());
} else {
Notification::make()
->title('Allgemeinflächen wurden erfolgreich importiert')
->body('Es wurden '.$new.' Flächen hinzugefügt')
->success()
->send()
->sendToDatabase(Auth::user());
}
}
}