clone & meine
This commit is contained in:
1 parent
d6e4789797
commit
23bed33cf3
23 files changed
+34880
-578
No files matched your search
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Klone;
|
||||
|
||||
use App\Models\ProjektAllgemeinflaechen;
|
||||
use App\Models\Projekte;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class KloneDokument
|
||||
{
|
||||
public static function clone($record)
|
||||
{
|
||||
$old_id = $record->id;
|
||||
|
||||
$insert_array = $record->toArray();
|
||||
unset($insert_array['id']);
|
||||
$insert_array['bezahlt_am'] = $record->bezahlt_am->format('Y-m-d H:i:s');
|
||||
$insert_array['created_at'] = Carbon::now();
|
||||
$insert_array['updated_at'] = Carbon::now();
|
||||
|
||||
$res = Projekte::insert($insert_array);
|
||||
$new_id = $res->id;
|
||||
|
||||
dd($new_id);
|
||||
|
||||
$res = ProjektAllgemeinflaechen::where('projekt_id', $old_id)->get()->toArray();
|
||||
foreach ($res as $row) {
|
||||
unset($row['id']);
|
||||
$row['projekt_id'] = $new_id;
|
||||
ProjektAllgemeinflaechen::insert($row);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,23 @@
|
||||
|
||||
namespace App\Filament\Resources\Projektes\Tables;
|
||||
|
||||
use App\Actions\Klone\KloneDokument;
|
||||
use App\Enums\ProjektStatus;
|
||||
use App\Models\Auftraggeber;
|
||||
use App\Models\Gutachter;
|
||||
use App\Models\Projekte;
|
||||
use App\Models\ProjektUser;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Enums\FiltersLayout;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ProjektesTable
|
||||
{
|
||||
@@ -22,8 +27,18 @@ class ProjektesTable
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id'),
|
||||
ToggleColumn::make('meine')
|
||||
->beforeStateUpdated(function ($record, $state) {
|
||||
if($state){
|
||||
ProjektUser::where('user_id', auth()->user()->id)->where('projekte_id', $record->id)->delete();
|
||||
return;
|
||||
}else{
|
||||
ProjektUser::create(['user_id' => auth()->user()->id, 'projekte_id' => $record->id]);
|
||||
return;
|
||||
}
|
||||
}),
|
||||
TextColumn::make('interner_name')
|
||||
->tooltip(fn ($record): HtmlString => new HtmlString($record->beschreibung))
|
||||
->tooltip(fn($record): HtmlString => new HtmlString($record->beschreibung))
|
||||
->label('Interner Name')
|
||||
->color('primary')
|
||||
->wrap()
|
||||
@@ -34,20 +49,30 @@ class ProjektesTable
|
||||
->label('Offizieller Name'),
|
||||
TextColumn::make('gutachter.company'),
|
||||
TextColumn::make('auftraggeber.company'),
|
||||
TextColumn::make('ort'),
|
||||
// TextColumn::make('ort'),
|
||||
TextColumn::make('erstellung')->sortable(),
|
||||
])
|
||||
->striped()
|
||||
->defaultSort('erstellung', direction: 'desc')
|
||||
->persistSortInSession()
|
||||
->persistFiltersInSession()
|
||||
->filters([
|
||||
Filter::make('meine')
|
||||
->schema([
|
||||
Toggle::make('meine')->label('Meine Projekte')
|
||||
])->query(function (Builder $query, array $data): Builder {
|
||||
return $query->when(
|
||||
$data['meine'],
|
||||
fn (Builder $query, $meine): Builder => $query->where('meine', $meine),
|
||||
);
|
||||
}),
|
||||
SelectFilter::make('status')
|
||||
->options(ProjektStatus::class),
|
||||
SelectFilter::make('gutachter_id')
|
||||
->label('Gutachter')
|
||||
->preload()
|
||||
->options(function () {
|
||||
$res = Projekte::where('konto_id', auth()->user()->konto_id)
|
||||
$res = Projekte::where('konto_id', Auth::user()->konto_id)
|
||||
->groupBy('gutachter_id')
|
||||
->pluck('gutachter_id')->toArray();
|
||||
|
||||
@@ -57,7 +82,7 @@ class ProjektesTable
|
||||
->label('Auftraggeber')
|
||||
->preload()
|
||||
->options(function () {
|
||||
$res = Projekte::where('konto_id', auth()->user()->konto_id)
|
||||
$res = Projekte::where('konto_id', Auth::user()->konto_id)
|
||||
->groupBy('auftraggeber_id')
|
||||
->pluck('auftraggeber_id')->toArray();
|
||||
|
||||
@@ -68,7 +93,7 @@ class ProjektesTable
|
||||
->recordActions([
|
||||
EditAction::make()->iconButton(),
|
||||
Action::make('dokument_klonen')
|
||||
->action(fn (Projekte $record) => KloneDokument::clone($record))
|
||||
->action(fn(Projekte $record) => $record->duplicate())
|
||||
->iconButton()
|
||||
->icon('phosphor-copy')
|
||||
->requiresConfirmation(),
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProjektUser extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'projekte_id',
|
||||
'user_id',
|
||||
];
|
||||
}
|
||||
+29
-1
@@ -7,12 +7,27 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Projekte extends Model
|
||||
{
|
||||
use \Bkwld\Cloner\Cloneable;
|
||||
|
||||
protected $cloneable_relations = [
|
||||
'projekt_objekte',
|
||||
'projekt_platzhalters',
|
||||
'projekt_allgemeinflaechens',
|
||||
'projekt_raeumealles',
|
||||
'projekt_methodes',
|
||||
'projekt_inhaltsverzeichnis',
|
||||
'projekt_merkmale',
|
||||
];
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'konto_id',
|
||||
'auftraggeber_id',
|
||||
'gutachter_id',
|
||||
'offizieller_name',
|
||||
'interner_name',
|
||||
'offizieller_name',
|
||||
'ort',
|
||||
'beschreibung',
|
||||
'erstellung',
|
||||
@@ -24,6 +39,9 @@ class Projekte extends Model
|
||||
'evaluation_gutachten',
|
||||
'pdf_nutzwerte_tabellen_umbruch',
|
||||
'bezahlt_am',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -40,6 +58,11 @@ class Projekte extends Model
|
||||
];
|
||||
}
|
||||
|
||||
public function meine()
|
||||
{
|
||||
return $this->belongsToMany(Projekte::class, 'projekt_users', 'projekte_id', 'user_id');
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::addGlobalScope(new KontoScope);
|
||||
@@ -50,6 +73,11 @@ class Projekte extends Model
|
||||
return $this->hasMany(ProjektObjekte::class);
|
||||
}
|
||||
|
||||
public function projekt_merkmale()
|
||||
{
|
||||
return $this->hasMany(ProjektMerkmale::class);
|
||||
}
|
||||
|
||||
public function auftraggeber()
|
||||
{
|
||||
return $this->belongsTo(Auftraggeber::class);
|
||||
|
||||
@@ -8,8 +8,8 @@ use Filament\Resources\Pages\Page;
|
||||
trait HasBackUrl
|
||||
{
|
||||
/**
|
||||
* überschreibt in EditRecords CancelAction da diese history based schritt für schit zurück ging.
|
||||
* mit diese änderung füht der Link direct zurück zur projekte liste.
|
||||
* überschreibt in EditRecords CancelAction da diese history based schritt für schritt zurück ginge.
|
||||
* mit diese änderung führt der Link direct zurück zur projekte liste.
|
||||
*/
|
||||
public ?string $backUrl = null;
|
||||
|
||||
|
||||
Reference in new issue
Block a user