initial commit
This commit is contained in:
67
app/Models/Client.php
Normal file
67
app/Models/Client.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ClientStatus;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Client extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'email', 'phone', 'company',
|
||||
'ig_handle', 'tiktok_handle', 'youtube_handle',
|
||||
'address_line1', 'address_line2', 'city', 'state', 'postal_code', 'country',
|
||||
'status', 'notes', 'avatar',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'status' => ClientStatus::class,
|
||||
];
|
||||
|
||||
public function events(): HasMany
|
||||
{
|
||||
return $this->hasMany(Event::class);
|
||||
}
|
||||
|
||||
public function invoices(): HasMany
|
||||
{
|
||||
return $this->hasMany(Invoice::class);
|
||||
}
|
||||
|
||||
public function contentBriefs(): HasMany
|
||||
{
|
||||
return $this->hasMany(ContentBrief::class);
|
||||
}
|
||||
|
||||
public function mediaFiles(): HasMany
|
||||
{
|
||||
return $this->hasMany(MediaFile::class);
|
||||
}
|
||||
|
||||
public function getFullAddressAttribute(): string
|
||||
{
|
||||
return collect([
|
||||
$this->address_line1,
|
||||
$this->address_line2,
|
||||
$this->city,
|
||||
$this->state,
|
||||
$this->postal_code,
|
||||
$this->country,
|
||||
])->filter()->implode(', ');
|
||||
}
|
||||
|
||||
public function getInitialsAttribute(): string
|
||||
{
|
||||
$words = explode(' ', $this->name);
|
||||
return strtoupper(
|
||||
collect($words)->take(2)->map(fn ($w) => $w[0] ?? '')->implode('')
|
||||
);
|
||||
}
|
||||
}
|
||||
43
app/Models/ContentBrief.php
Normal file
43
app/Models/ContentBrief.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ContentStatus;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class ContentBrief extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'client_id', 'title', 'platform', 'content_type', 'status',
|
||||
'hook', 'body', 'cta', 'script', 'caption', 'hashtags',
|
||||
'target_date', 'posted_date', 'posted_url', 'sort_order', 'notes',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'status' => ContentStatus::class,
|
||||
'target_date' => 'date',
|
||||
'posted_date' => 'date',
|
||||
];
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Client::class);
|
||||
}
|
||||
|
||||
public function getPlatformIconAttribute(): string
|
||||
{
|
||||
return match($this->platform) {
|
||||
'instagram' => '📸',
|
||||
'tiktok' => '🎵',
|
||||
'youtube' => '▶️',
|
||||
default => '📱',
|
||||
};
|
||||
}
|
||||
}
|
||||
48
app/Models/Event.php
Normal file
48
app/Models/Event.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\EventStatus;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Event extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'client_id', 'title', 'description', 'event_type',
|
||||
'start_time', 'end_time', 'location', 'is_priority',
|
||||
'is_all_day', 'status', 'color', 'notes',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'start_time' => 'datetime',
|
||||
'end_time' => 'datetime',
|
||||
'is_priority' => 'boolean',
|
||||
'is_all_day' => 'boolean',
|
||||
'status' => EventStatus::class,
|
||||
];
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Client::class);
|
||||
}
|
||||
|
||||
public function scopeUpcoming($query, int $hours = 24)
|
||||
{
|
||||
return $query->where('start_time', '>=', now())
|
||||
->where('start_time', '<=', now()->addHours($hours))
|
||||
->where('status', '!=', EventStatus::Completed->value)
|
||||
->where('status', '!=', EventStatus::Cancelled->value);
|
||||
}
|
||||
|
||||
public function scopeToday($query)
|
||||
{
|
||||
return $query->whereDate('start_time', today());
|
||||
}
|
||||
}
|
||||
65
app/Models/Invoice.php
Normal file
65
app/Models/Invoice.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\InvoiceStatus;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Invoice extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'client_id', 'invoice_number', 'title', 'description',
|
||||
'subtotal', 'tax_rate', 'tax_amount', 'total', 'currency',
|
||||
'status', 'issue_date', 'due_date', 'paid_date', 'notes',
|
||||
'bank_name', 'bank_account', 'bank_holder',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'status' => InvoiceStatus::class,
|
||||
'issue_date' => 'date',
|
||||
'due_date' => 'date',
|
||||
'paid_date' => 'date',
|
||||
'subtotal' => 'decimal:2',
|
||||
'tax_rate' => 'decimal:2',
|
||||
'tax_amount' => 'decimal:2',
|
||||
'total' => 'decimal:2',
|
||||
];
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Client::class);
|
||||
}
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(InvoiceItem::class);
|
||||
}
|
||||
|
||||
public function recalculate(): void
|
||||
{
|
||||
$this->subtotal = $this->items->sum('total');
|
||||
$this->tax_amount = round($this->subtotal * ($this->tax_rate / 100), 2);
|
||||
$this->total = $this->subtotal + $this->tax_amount;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function getFormattedTotalAttribute(): string
|
||||
{
|
||||
return 'Rp ' . number_format((float) $this->total, 0, ',', '.');
|
||||
}
|
||||
|
||||
public static function generateNumber(): string
|
||||
{
|
||||
$prefix = 'INV-' . now()->format('Ym');
|
||||
$last = static::where('invoice_number', 'like', $prefix . '%')->count();
|
||||
return $prefix . '-' . str_pad((string) ($last + 1), 3, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
23
app/Models/InvoiceItem.php
Normal file
23
app/Models/InvoiceItem.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class InvoiceItem extends Model
|
||||
{
|
||||
protected $fillable = ['invoice_id', 'description', 'quantity', 'unit_price', 'total'];
|
||||
|
||||
protected $casts = [
|
||||
'unit_price' => 'decimal:2',
|
||||
'total' => 'decimal:2',
|
||||
];
|
||||
|
||||
public function invoice(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Invoice::class);
|
||||
}
|
||||
}
|
||||
51
app/Models/MediaFile.php
Normal file
51
app/Models/MediaFile.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class MediaFile extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'client_id', 'name', 'original_name', 'path', 'disk', 'mime_type', 'size', 'folder', 'description',
|
||||
];
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Client::class);
|
||||
}
|
||||
|
||||
public function getUrlAttribute(): string
|
||||
{
|
||||
return route('files.serve', $this->id);
|
||||
}
|
||||
|
||||
public function getHumanSizeAttribute(): string
|
||||
{
|
||||
$bytes = $this->size;
|
||||
if ($bytes >= 1073741824) return round($bytes / 1073741824, 2) . ' GB';
|
||||
if ($bytes >= 1048576) return round($bytes / 1048576, 2) . ' MB';
|
||||
if ($bytes >= 1024) return round($bytes / 1024, 2) . ' KB';
|
||||
return $bytes . ' B';
|
||||
}
|
||||
|
||||
public function getIsImageAttribute(): bool
|
||||
{
|
||||
return str_starts_with($this->mime_type, 'image/');
|
||||
}
|
||||
|
||||
public function getIconAttribute(): string
|
||||
{
|
||||
if ($this->is_image) return '🖼️';
|
||||
if (str_starts_with($this->mime_type, 'video/')) return '🎬';
|
||||
if (str_contains($this->mime_type, 'pdf')) return '📄';
|
||||
return '📁';
|
||||
}
|
||||
}
|
||||
36
app/Models/RateCard.php
Normal file
36
app/Models/RateCard.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RateCard extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'service_name', 'description', 'platform', 'content_type',
|
||||
'price', 'currency', 'price_unit', 'is_negotiable', 'is_active', 'sort_order',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'price' => 'decimal:2',
|
||||
'is_negotiable' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
public function getFormattedPriceAttribute(): string
|
||||
{
|
||||
return 'Rp ' . number_format((float) $this->price, 0, ',', '.');
|
||||
}
|
||||
|
||||
public function getPlatformIconAttribute(): string
|
||||
{
|
||||
return match($this->platform) {
|
||||
'instagram' => '📸',
|
||||
'tiktok' => '🎵',
|
||||
'youtube' => '▶️',
|
||||
default => '⭐',
|
||||
};
|
||||
}
|
||||
}
|
||||
40
app/Models/SocialStat.php
Normal file
40
app/Models/SocialStat.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SocialStat extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'platform', 'handle', 'followers', 'following', 'posts_count',
|
||||
'engagement_rate', 'avg_views', 'avg_likes', 'avg_comments',
|
||||
'recorded_date', 'raw_data',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'recorded_date' => 'date',
|
||||
'raw_data' => 'array',
|
||||
'engagement_rate' => 'decimal:2',
|
||||
];
|
||||
|
||||
public function getFormattedFollowersAttribute(): string
|
||||
{
|
||||
$n = $this->followers;
|
||||
if ($n >= 1_000_000) return round($n / 1_000_000, 1) . 'M';
|
||||
if ($n >= 1_000) return round($n / 1_000, 1) . 'K';
|
||||
return (string) $n;
|
||||
}
|
||||
|
||||
public function getPlatformIconAttribute(): string
|
||||
{
|
||||
return match($this->platform) {
|
||||
'instagram' => '📸',
|
||||
'tiktok' => '🎵',
|
||||
'youtube' => '▶️',
|
||||
default => '📱',
|
||||
};
|
||||
}
|
||||
}
|
||||
32
app/Models/User.php
Normal file
32
app/Models/User.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
#[Fillable(['name', 'email', 'password'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user