- Added `rejections` table to track rejection reasons and related entities. - Created `attendances` table for employee attendance records with geolocation data. - Introduced `payroll_periods`, `payrolls`, and `payroll_adjustments` tables for payroll management. - Established `leave_requests` table to manage employee leave applications. - Implemented `purchases` and `purchase_items` tables for tracking supplier purchases. - Created `media` table for file storage and management. - Added `activity_log` table for tracking system activities. - Established `orders` and `order_items` tables for managing customer orders. - Created `cuttings`, `cutting_materials`, and `cutting_results` tables for production management. - Introduced `system_configurations` table for application settings. - Added `push_subscriptions` table for managing user push notifications. - Created `homepage_configurations` table for homepage settings. - Established `product_prices` table for managing product pricing. - Added `owner_verification_requests` table for tracking ownership verification processes. - Created `notifications` table for user notifications. - Established `employee_advance_payments` table for managing advance payments to employees. - Created `retail_stock_histories` table for tracking stock changes. - Established `stok_opnames` and `stok_opname_items` tables for stock opname management. - Created `cutting_material_combinations` table for managing material combinations. - Added `restocks` and `restock_items` tables for managing stock replenishments. - Established `stock_mutations` table for tracking stock changes across various operations.
159 lines
3.7 KiB
PHP
159 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use App\Enums\OrderChannel;
|
|
use App\Enums\OrderStatus;
|
|
use App\Enums\PaymentType;
|
|
use App\Enums\PriceType;
|
|
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;
|
|
|
|
#[Hidden(['id'])]
|
|
class Order extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'channel' => OrderChannel::class,
|
|
'price_type' => PriceType::class,
|
|
'status' => OrderStatus::class,
|
|
'payment_type' => PaymentType::class,
|
|
'is_affiliate' => 'boolean',
|
|
'subtotal' => 'integer',
|
|
'discount' => 'integer',
|
|
'nego_price' => 'integer',
|
|
'total_amount' => 'integer',
|
|
];
|
|
}
|
|
|
|
#[Scope]
|
|
protected function cancelled(Builder $query): void
|
|
{
|
|
$query->where('status', OrderStatus::CANCELLED);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function cash(Builder $query): void
|
|
{
|
|
$query->where('payment_type', PaymentType::CASH);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function completed(Builder $query): void
|
|
{
|
|
$query->where('status', OrderStatus::COMPLETED);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function credit(Builder $query): void
|
|
{
|
|
$query->where('payment_type', PaymentType::CREDIT);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function debit(Builder $query): void
|
|
{
|
|
$query->where('payment_type', PaymentType::DEBIT);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function offline(Builder $query): void
|
|
{
|
|
$query->where('channel', OrderChannel::OFFLINE);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function online(Builder $query): void
|
|
{
|
|
$query->where('channel', OrderChannel::ONLINE);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function pending(Builder $query): void
|
|
{
|
|
$query->where('status', OrderStatus::PENDING);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function processing(Builder $query): void
|
|
{
|
|
$query->where('status', OrderStatus::PROCESSING);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function refunded(Builder $query): void
|
|
{
|
|
$query->where('status', OrderStatus::REFUNDED);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function retail(Builder $query): void
|
|
{
|
|
$query->where('price_type', PriceType::RETAIL);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function shopee(Builder $query): void
|
|
{
|
|
$query->where('channel', OrderChannel::SHOPEE);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function tiktok(Builder $query): void
|
|
{
|
|
$query->where('channel', OrderChannel::TIKTOK);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function transfer(Builder $query): void
|
|
{
|
|
$query->where('payment_type', PaymentType::TRANSFER);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function whatsapp(Builder $query): void
|
|
{
|
|
$query->where('channel', OrderChannel::WHATSAPP);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function wholesale(Builder $query): void
|
|
{
|
|
$query->where('price_type', PriceType::WHOLESALE);
|
|
}
|
|
|
|
public function cashTransaction(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CashTransaction::class);
|
|
}
|
|
|
|
public function createdBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by_id');
|
|
}
|
|
|
|
public function customer(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Customer::class);
|
|
}
|
|
|
|
public function marketing(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'marketing_id');
|
|
}
|
|
|
|
public function orderItems(): HasMany
|
|
{
|
|
return $this->hasMany(OrderItem::class);
|
|
}
|
|
}
|