78 lines
1.7 KiB
PHP
78 lines
1.7 KiB
PHP
<?php namespace App\Models;
|
|
/**
|
|
* @copyright (c) 2025 Notsoweb Software (https://notsoweb.com) - All Rights Reserved
|
|
*/
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Descripción
|
|
*
|
|
* @author Moisés Cortés C. <moises.cortes@notsoweb.com>
|
|
*
|
|
* @version 1.0.0
|
|
*/
|
|
class InvoiceRequest extends Model
|
|
{
|
|
protected $fillable = [
|
|
'sale_id',
|
|
'client_id',
|
|
'status',
|
|
'requested_at',
|
|
'processed_at',
|
|
'processed_by',
|
|
'notes',
|
|
];
|
|
|
|
protected $casts = [
|
|
'requested_at' => 'datetime',
|
|
'processed_at' => 'datetime',
|
|
];
|
|
|
|
const STATUS_PENDING = 'pending';
|
|
const STATUS_PROCESSED = 'processed';
|
|
const STATUS_REJECTED = 'rejected';
|
|
|
|
public function sale()
|
|
{
|
|
return $this->belongsTo(Sale::class);
|
|
}
|
|
|
|
public function client()
|
|
{
|
|
return $this->belongsTo(Client::class);
|
|
}
|
|
|
|
public function processedBy()
|
|
{
|
|
return $this->belongsTo(User::class, 'processed_by');
|
|
}
|
|
|
|
/**
|
|
* Marcar como procesada
|
|
*/
|
|
public function markAsProcessed(int $userId, ?string $notes = null): bool
|
|
{
|
|
return $this->update([
|
|
'status' => self::STATUS_PROCESSED,
|
|
'processed_at' => now(),
|
|
'processed_by' => $userId,
|
|
'notes' => $notes ?? $this->notes,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Marcar como rechazada
|
|
*/
|
|
public function markAsRejected(int $userId, ?string $notes = null): bool
|
|
{
|
|
return $this->update([
|
|
'status' => self::STATUS_REJECTED,
|
|
'processed_at' => now(),
|
|
'processed_by' => $userId,
|
|
'notes' => $notes ?? $this->notes,
|
|
]);
|
|
}
|
|
}
|