63 lines
1.8 KiB
PHP
63 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Imports;
|
|
|
|
use App\Models\ProjektAllgemeinflaechen;
|
|
use Filament\Notifications\Notification;
|
|
|
|
class ImportAllgemeinDirect
|
|
{
|
|
public static function run($data, $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();
|
|
} else {
|
|
Notification::make()
|
|
->title('Allgemeinflächen wurden erfolgreich importiert')
|
|
->body($new.' wurden Flächen hinzugefügt')
|
|
->success()
|
|
->send();
|
|
|
|
$recipient = auth()->user();
|
|
Notification::make()
|
|
->title('Allgemeinflächen wurden erfolgreich importiert')
|
|
->body($new.' wurden Flächen hinzugefügt')
|
|
->success()
|
|
->sendToDatabase($recipient);
|
|
}
|
|
}
|
|
}
|