- Add RestockIndex component for displaying and managing restocks. - Create RestockCardRow component for rendering individual restock items. - Implement RestockItemSubRow component for displaying detailed item information. - Define routes for restock management in web.php. - Create RestockTest to cover various scenarios for restock creation, updating, and deletion. - Ensure proper handling of permissions for restock actions. - Add validation for restock data and ensure correct relationships are maintained.
56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\ProductStockQuality;
|
|
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\SoftDeletes;
|
|
|
|
#[Guarded(['id'])]
|
|
class OrderItem extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'stock_quality' => ProductStockQuality::class,
|
|
'quantity' => 'integer',
|
|
'unit_price' => 'integer',
|
|
'subtotal' => 'integer',
|
|
];
|
|
}
|
|
|
|
#[Scope]
|
|
protected function reject(Builder $query): void
|
|
{
|
|
$query->where('stock_quality', ProductStockQuality::REJECT);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function good(Builder $query): void
|
|
{
|
|
$query->where('stock_quality', ProductStockQuality::GOOD);
|
|
}
|
|
|
|
public function order(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Order::class);
|
|
}
|
|
|
|
public function productVariant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ProductVariant::class);
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
}
|