|
|
|
@ -3,7 +3,9 @@
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use App\Enums\OrderStatus;
|
|
|
|
|
use Database\Factories\OrderFactory;
|
|
|
|
|
use DateTimeInterface;
|
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
@ -12,6 +14,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
|
|
|
|
|
class Order extends Model
|
|
|
|
|
{
|
|
|
|
|
/** @use HasFactory<OrderFactory> */
|
|
|
|
|
use HasFactory, SoftDeletes;
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
@ -36,7 +39,7 @@ class Order extends Model
|
|
|
|
|
'active',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public static function boot()
|
|
|
|
|
public static function boot(): void
|
|
|
|
|
{
|
|
|
|
|
parent::boot();
|
|
|
|
|
|
|
|
|
@ -46,9 +49,9 @@ class Order extends Model
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function generateInternalPo($id): string
|
|
|
|
|
public function generateInternalPo(int $id): string
|
|
|
|
|
{
|
|
|
|
|
$po = str_pad($id, 4, '0', STR_PAD_LEFT);
|
|
|
|
|
$po = str_pad(strval($id), 4, '0', STR_PAD_LEFT);
|
|
|
|
|
$year = date('y');
|
|
|
|
|
|
|
|
|
|
return 'TN'.$year.'-'.$po;
|
|
|
|
@ -64,38 +67,63 @@ class Order extends Model
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopeActive($query)
|
|
|
|
|
/**
|
|
|
|
|
* @param Builder<Order> $query
|
|
|
|
|
* @return Builder<Order>
|
|
|
|
|
*/
|
|
|
|
|
public function scopeActive(Builder $query): Builder
|
|
|
|
|
{
|
|
|
|
|
return $query->where('status', 'approved')
|
|
|
|
|
->orWhere('status', 'production');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopeFinished($query)
|
|
|
|
|
/**
|
|
|
|
|
* @param Builder<Order> $query
|
|
|
|
|
* @return Builder<Order>
|
|
|
|
|
*/
|
|
|
|
|
public function scopeFinished(Builder $query): Builder
|
|
|
|
|
{
|
|
|
|
|
return $query->where('status', 'shipped')
|
|
|
|
|
->orWhere('status', 'completed');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopeInvoiced($query)
|
|
|
|
|
/**
|
|
|
|
|
* @param Builder<Order> $query
|
|
|
|
|
* @return Builder<Order>
|
|
|
|
|
*/
|
|
|
|
|
public function scopeInvoiced(Builder $query): Builder
|
|
|
|
|
{
|
|
|
|
|
return $query->where('status', 'invoiced');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopeRush($query)
|
|
|
|
|
/**
|
|
|
|
|
* @param Builder<Order> $query
|
|
|
|
|
* @return Builder<Order>
|
|
|
|
|
*/
|
|
|
|
|
public function scopeRush(Builder $query): Builder
|
|
|
|
|
{
|
|
|
|
|
return $query->where('rush', true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return BelongsTo<Customer, self>
|
|
|
|
|
*/
|
|
|
|
|
public function customer(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Customer::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return HasMany<OrderProduct>
|
|
|
|
|
*/
|
|
|
|
|
public function orderProducts(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(OrderProduct::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return HasMany<ProductService>
|
|
|
|
|
*/
|
|
|
|
|
public function productServices(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(ProductService::class);
|
|
|
|
|