fix tests
This commit is contained in:
@@ -3,10 +3,9 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\BaseModel;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class PurchaseOrder extends BaseModel
|
||||
{
|
||||
@@ -25,18 +24,19 @@ class PurchaseOrder extends BaseModel
|
||||
'total',
|
||||
'notes',
|
||||
];
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
protected $casts = [
|
||||
'supplier_id' => 'integer',
|
||||
'order_date' => 'date', // or 'datetime' if your DB stores time too
|
||||
'expected_date' => 'date',
|
||||
'subtotal' => 'decimal:2',
|
||||
'tax' => 'decimal:2',
|
||||
'total' => 'decimal:2',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
'supplier_id' => 'integer',
|
||||
'order_date' => 'date', // or 'datetime' if your DB stores time too
|
||||
'expected_date' => 'date',
|
||||
'subtotal' => 'decimal:2',
|
||||
'tax' => 'decimal:2',
|
||||
'total' => 'decimal:2',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function getFillable(): array
|
||||
@@ -49,9 +49,12 @@ class PurchaseOrder extends BaseModel
|
||||
* ============================================================
|
||||
*/
|
||||
|
||||
public const STATUS_DRAFT = 'draft';
|
||||
public const STATUS_ORDERED = 'ordered';
|
||||
public const STATUS_DRAFT = 'draft';
|
||||
|
||||
public const STATUS_ORDERED = 'ordered';
|
||||
|
||||
public const STATUS_RECEIVED = 'received';
|
||||
|
||||
public const STATUS_CANCELED = 'canceled';
|
||||
|
||||
public static function allowedStatuses(): array
|
||||
@@ -116,8 +119,8 @@ class PurchaseOrder extends BaseModel
|
||||
$total = $subtotal + $tax;
|
||||
|
||||
$this->subtotal = $subtotal;
|
||||
$this->tax = $tax;
|
||||
$this->total = $total;
|
||||
$this->tax = $tax;
|
||||
$this->total = $total;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -125,18 +128,21 @@ class PurchaseOrder extends BaseModel
|
||||
public function markOrdered(): self
|
||||
{
|
||||
$this->status = self::STATUS_ORDERED;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function markReceived(): self
|
||||
{
|
||||
$this->status = self::STATUS_RECEIVED;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function markCanceled(): self
|
||||
{
|
||||
$this->status = self::STATUS_CANCELED;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -149,16 +155,16 @@ class PurchaseOrder extends BaseModel
|
||||
{
|
||||
// Mirrors legacy: unique purchase_orders.po_number except current id.
|
||||
return [
|
||||
'po_number' => ['required', 'string', 'max:60', 'unique:purchase_orders,po_number,' . ($id ?? 'NULL') . ',id'],
|
||||
'po_number' => ['required', 'string', 'max:60', 'unique:purchase_orders,po_number,'.($id ?? 'NULL').',id'],
|
||||
'supplier_id' => ['required', 'integer', 'min:1', 'exists:suppliers,id'],
|
||||
'status' => ['nullable', 'string', 'in:' . implode(',', self::allowedStatuses())],
|
||||
'status' => ['nullable', 'string', 'in:'.implode(',', self::allowedStatuses())],
|
||||
|
||||
'order_date' => ['nullable', 'date'],
|
||||
'expected_date' => ['nullable', 'date', 'after_or_equal:order_date'],
|
||||
'subtotal' => ['nullable', 'numeric', 'min:0'],
|
||||
'tax' => ['nullable', 'numeric', 'min:0'],
|
||||
'total' => ['nullable', 'numeric', 'min:0'],
|
||||
'notes' => ['nullable', 'string', 'max:5000'],
|
||||
'order_date' => ['nullable', 'date'],
|
||||
'expected_date' => ['nullable', 'date', 'after_or_equal:order_date'],
|
||||
'subtotal' => ['nullable', 'numeric', 'min:0'],
|
||||
'tax' => ['nullable', 'numeric', 'min:0'],
|
||||
'total' => ['nullable', 'numeric', 'min:0'],
|
||||
'notes' => ['nullable', 'string', 'max:5000'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user