Cost units can be edited

This commit is contained in:
2026-02-08 20:06:38 +01:00
parent 6fc65e195c
commit bccfc11687
53 changed files with 2021 additions and 29 deletions

40
app/Models/CostUnit.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
namespace App\Models;
use App\Scopes\InstancedModel;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
/**
* @property string $name
* @property string $type
* @property string $billing_deadline
* @property string $distance_allowance
* @property boolean $mail_on_new
* @property boolean $allow_new
* @property boolean $archived
* @property Tenant $tenant
*/
class CostUnit extends InstancedModel
{
protected $fillable = [
'name',
'tenant',
'type',
'billing_deadline',
'distance_allowance',
'mail_on_new',
'allow_new',
'archived',
];
public function tresurers() : BelongsToMany{
return $this->belongsToMany(User::class, 'cost_unit_treasurers', 'cost_unit_id', 'user_id')
->withTimestamps();
}
public function resetTreasurers() {
$this->tresurers()->detach();
$this->save();
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
@@ -95,7 +96,7 @@ class User extends Authenticatable
public function getFullname() : string {
return sprintf('%1$1s %2$s %3$s',
$this->firstname,
$this->nickname !== '' ? '(' . $this->nickname . ')' : '',
$this->nickname !== null ? '(' . $this->nickname . ')' : '',
$this->lastname
);
}
@@ -103,4 +104,14 @@ class User extends Authenticatable
public function getNicename() : string {
return $this->nickname ?? $this->firstname;
}
public function localGroup() : Tenant {
return $this->belongsTo(Tenant::class, 'local_group', 'slug')->first();
}
public function costUnits()
{
return $this->belongsToMany(CostUnit::class, 'cost_unit_treasurers', 'user_id', 'cost_unit_id')
->withTimestamps();
}
}