mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-15 11:42:15 +01:00
Added billable rates; Added project members; Added visibility to projects
This commit is contained in:
@@ -10,6 +10,7 @@ use Laravel\Jetstream\Membership as JetstreamMembership;
|
||||
/**
|
||||
* @property string $id
|
||||
* @property string $role
|
||||
* @property int|null $billable_rate
|
||||
* @property string $organization_id
|
||||
* @property string $user_id
|
||||
* @property string $created_at
|
||||
|
||||
@@ -20,6 +20,8 @@ use Laravel\Jetstream\Team as JetstreamTeam;
|
||||
* @property string $id
|
||||
* @property string $name
|
||||
* @property bool $personal_team
|
||||
* @property string $currency
|
||||
* @property int|null $billable_rate
|
||||
* @property User $owner
|
||||
* @property Collection<User> $users
|
||||
* @property Collection<string, User> $realUsers
|
||||
@@ -40,6 +42,7 @@ class Organization extends JetstreamTeam
|
||||
protected $casts = [
|
||||
'name' => 'string',
|
||||
'personal_team' => 'boolean',
|
||||
'currency' => 'string',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -63,6 +66,15 @@ class Organization extends JetstreamTeam
|
||||
'deleted' => TeamDeleted::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The model's default values for attributes.
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $attributes = [
|
||||
'currency' => 'EUR',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get all the non-placeholder users of the organization including its owner.
|
||||
*
|
||||
@@ -88,7 +100,10 @@ class Organization extends JetstreamTeam
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Jetstream::userModel(), Jetstream::membershipModel())
|
||||
->withPivot('role')
|
||||
->withPivot([
|
||||
'role',
|
||||
'billable_rate',
|
||||
])
|
||||
->withTimestamps()
|
||||
->as('membership');
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
* @property string $color
|
||||
* @property string $organization_id
|
||||
* @property string $client_id
|
||||
* @property int|null $billable_rate
|
||||
* @property-read Organization $organization
|
||||
* @property-read Client|null $client
|
||||
* @property-read Collection<Task> $tasks
|
||||
@@ -55,6 +56,14 @@ class Project extends Model
|
||||
return $this->belongsTo(Client::class, 'client_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<ProjectMember>
|
||||
*/
|
||||
public function members(): HasMany
|
||||
{
|
||||
return $this->hasMany(ProjectMember::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<Task>
|
||||
*/
|
||||
|
||||
52
app/Models/ProjectMember.php
Normal file
52
app/Models/ProjectMember.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\ProjectMemberFactory;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property string $id
|
||||
* @property int|null $billable_rate
|
||||
* @property string $project_id
|
||||
* @property string $user_id
|
||||
* @property-read Project $project
|
||||
* @property-read User $user
|
||||
*
|
||||
* @method static ProjectMemberFactory factory()
|
||||
*/
|
||||
class ProjectMember extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasUuids;
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'billable_rate' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Project, ProjectMember>
|
||||
*/
|
||||
public function project(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Project::class, 'project_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, ProjectMember>
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Service\BillableRateService;
|
||||
use Carbon\CarbonInterval;
|
||||
use Database\Factories\TimeEntryFactory;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
@@ -11,12 +12,14 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Korridor\LaravelComputedAttributes\ComputedAttributes;
|
||||
|
||||
/**
|
||||
* @property string $id
|
||||
* @property string $description
|
||||
* @property Carbon $start
|
||||
* @property Carbon|null $end
|
||||
* @property int $billable_rate Billable rate per hour in cents
|
||||
* @property bool $billable
|
||||
* @property array $tags
|
||||
* @property string $user_id
|
||||
@@ -32,6 +35,7 @@ use Illuminate\Support\Carbon;
|
||||
*/
|
||||
class TimeEntry extends Model
|
||||
{
|
||||
use ComputedAttributes;
|
||||
use HasFactory;
|
||||
use HasUuids;
|
||||
|
||||
@@ -46,8 +50,24 @@ class TimeEntry extends Model
|
||||
'end' => 'datetime',
|
||||
'billable' => 'bool',
|
||||
'tags' => 'array',
|
||||
'billable_rate' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are computed. (f.e. for performance reasons)
|
||||
* These attributes can be regenerated at any time.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected array $computed = [
|
||||
'billable_rate',
|
||||
];
|
||||
|
||||
public function getBillableRateComputed(): ?int
|
||||
{
|
||||
return app(BillableRateService::class)->getBillableRateForTimeEntry($this);
|
||||
}
|
||||
|
||||
public function getDuration(): ?CarbonInterval
|
||||
{
|
||||
return $this->end === null ? null : $this->start->diffAsCarbonInterval($this->end);
|
||||
|
||||
@@ -115,6 +115,7 @@ class User extends Authenticatable
|
||||
return $this->belongsToMany(Organization::class, Membership::class)
|
||||
->withPivot([
|
||||
'role',
|
||||
'billable_rate',
|
||||
])
|
||||
->withTimestamps()
|
||||
->as('membership');
|
||||
|
||||
Reference in New Issue
Block a user