2025-10-13 21:52:34 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models\Orders;
|
|
|
|
|
|
2025-12-24 08:54:52 +09:00
|
|
|
use App\Models\BadDebts\BadDebt;
|
2026-01-29 15:33:54 +09:00
|
|
|
use App\Traits\Auditable;
|
2025-10-13 21:52:34 +09:00
|
|
|
use App\Traits\BelongsToTenant;
|
|
|
|
|
use App\Traits\ModelTrait;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2025-12-24 08:54:52 +09:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2025-10-13 21:52:34 +09:00
|
|
|
|
|
|
|
|
class Client extends Model
|
|
|
|
|
{
|
2026-01-29 15:33:54 +09:00
|
|
|
use Auditable, BelongsToTenant, ModelTrait;
|
2025-10-13 21:52:34 +09:00
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'tenant_id',
|
|
|
|
|
'client_group_id',
|
|
|
|
|
'client_code',
|
|
|
|
|
'name',
|
|
|
|
|
'contact_person',
|
|
|
|
|
'phone',
|
2025-12-04 21:13:58 +09:00
|
|
|
'mobile',
|
|
|
|
|
'fax',
|
2025-10-13 21:52:34 +09:00
|
|
|
'email',
|
|
|
|
|
'address',
|
2025-12-04 21:13:58 +09:00
|
|
|
'account_id',
|
|
|
|
|
'account_password',
|
|
|
|
|
'purchase_payment_day',
|
|
|
|
|
'sales_payment_day',
|
2025-12-04 15:40:24 +09:00
|
|
|
'business_no',
|
|
|
|
|
'business_type',
|
|
|
|
|
'business_item',
|
2025-12-04 21:13:58 +09:00
|
|
|
'tax_agreement',
|
|
|
|
|
'tax_amount',
|
|
|
|
|
'tax_start_date',
|
|
|
|
|
'tax_end_date',
|
|
|
|
|
'memo',
|
2025-12-27 18:47:46 +09:00
|
|
|
'outstanding_balance',
|
|
|
|
|
'credit_limit',
|
2025-10-13 21:52:34 +09:00
|
|
|
'is_active',
|
2026-01-02 14:47:51 +09:00
|
|
|
'is_overdue',
|
2025-12-04 21:13:58 +09:00
|
|
|
'client_type',
|
|
|
|
|
'manager_name',
|
|
|
|
|
'manager_tel',
|
|
|
|
|
'system_manager',
|
2025-10-13 21:52:34 +09:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'is_active' => 'boolean',
|
2026-01-02 14:47:51 +09:00
|
|
|
'is_overdue' => 'boolean',
|
2025-12-04 21:13:58 +09:00
|
|
|
'tax_agreement' => 'boolean',
|
|
|
|
|
'tax_amount' => 'decimal:2',
|
2025-12-27 18:47:46 +09:00
|
|
|
'outstanding_balance' => 'decimal:2',
|
|
|
|
|
'credit_limit' => 'decimal:2',
|
2025-12-04 21:13:58 +09:00
|
|
|
'tax_start_date' => 'date',
|
|
|
|
|
'tax_end_date' => 'date',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $hidden = [
|
|
|
|
|
'account_password',
|
2025-10-13 21:52:34 +09:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// ClientGroup 관계
|
|
|
|
|
public function clientGroup()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(ClientGroup::class, 'client_group_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Orders 관계
|
|
|
|
|
public function orders()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Order::class, 'client_id');
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-24 08:54:52 +09:00
|
|
|
// 악성채권 관계
|
|
|
|
|
public function badDebts(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(BadDebt::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 활성 악성채권 관계 (추심중, 법적조치)
|
|
|
|
|
public function activeBadDebts(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(BadDebt::class)
|
|
|
|
|
->whereIn('status', [BadDebt::STATUS_COLLECTING, BadDebt::STATUS_LEGAL_ACTION])
|
|
|
|
|
->where('is_active', true);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-13 21:52:34 +09:00
|
|
|
// 스코프
|
|
|
|
|
public function scopeActive($query)
|
|
|
|
|
{
|
2025-12-08 20:25:38 +09:00
|
|
|
return $query->where('is_active', true);
|
2025-10-13 21:52:34 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopeCode($query, string $code)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('client_code', $code);
|
|
|
|
|
}
|
|
|
|
|
}
|