- Implemented TransactionIndex component for displaying transactions with pagination and filtering options. - Created TransactionCardRow component for rendering individual transaction details. - Added TransactionItemSubRow component for displaying detailed order items within a transaction. - Integrated delete confirmation dialog for transaction deletion. - Updated routes to include transaction management with appropriate permissions.
144 lines
3.5 KiB
PHP
144 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\OrderChannel;
|
|
use App\Enums\OrderStatus;
|
|
use App\Enums\PaymentType;
|
|
use App\Enums\PriceType;
|
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
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;
|
|
use Spatie\MediaLibrary\HasMedia;
|
|
use Spatie\MediaLibrary\InteractsWithMedia;
|
|
|
|
#[Guarded(['id'])]
|
|
class Order extends Model implements HasMedia
|
|
{
|
|
use HasFactory, InteractsWithMedia, 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',
|
|
'cogs' => '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 qris(Builder $query): void
|
|
{
|
|
$query->where('payment_type', PaymentType::QRIS);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function store(Builder $query): void
|
|
{
|
|
$query->where('channel', OrderChannel::STORE);
|
|
}
|
|
|
|
#[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 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);
|
|
}
|
|
}
|