fix tests

This commit is contained in:
root
2026-06-11 11:46:12 -04:00
parent c91fa2ce4d
commit 5ead80fdc7
1489 changed files with 11349 additions and 10305 deletions
+16 -14
View File
@@ -2,7 +2,6 @@
namespace App\Models;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PurchaseOrderItem extends BaseModel
@@ -18,16 +17,17 @@ class PurchaseOrderItem extends BaseModel
'received_qty',
'unit_cost',
];
public $timestamps = true;
protected $casts = [
'purchase_order_id' => 'integer',
'supply_id' => 'integer',
'quantity' => 'integer',
'received_qty' => 'integer',
'unit_cost' => 'decimal:2', // adjust scale to match DB (e.g., decimal:4)
'created_at' => 'datetime',
'updated_at' => 'datetime',
'supply_id' => 'integer',
'quantity' => 'integer',
'received_qty' => 'integer',
'unit_cost' => 'decimal:2', // adjust scale to match DB (e.g., decimal:4)
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
public function getFillable(): array
@@ -58,16 +58,18 @@ class PurchaseOrderItem extends BaseModel
// total ordered cost
public function getLineTotalAttribute(): float
{
$qty = (int) ($this->quantity ?? 0);
$qty = (int) ($this->quantity ?? 0);
$cost = (float) ($this->unit_cost ?? 0);
return $qty * $cost;
}
// total received cost
public function getReceivedLineTotalAttribute(): float
{
$qty = (int) ($this->received_qty ?? 0);
$qty = (int) ($this->received_qty ?? 0);
$cost = (float) ($this->unit_cost ?? 0);
return $qty * $cost;
}
@@ -82,11 +84,11 @@ class PurchaseOrderItem extends BaseModel
// keep strict by default to match legacy behavior
return [
'purchase_order_id' => [$updating ? 'sometimes' : 'required', 'integer', 'min:1', 'exists:purchase_orders,id'],
'supply_id' => [$updating ? 'sometimes' : 'required', 'integer', 'min:1', 'exists:supplies,id'],
'description' => ['nullable', 'string', 'max:1000'],
'quantity' => [$updating ? 'sometimes' : 'required', 'integer', 'min:1'],
'received_qty' => ['nullable', 'integer', 'min:0', 'lte:quantity'],
'unit_cost' => [$updating ? 'sometimes' : 'required', 'numeric', 'min:0'],
'supply_id' => [$updating ? 'sometimes' : 'required', 'integer', 'min:1', 'exists:supplies,id'],
'description' => ['nullable', 'string', 'max:1000'],
'quantity' => [$updating ? 'sometimes' : 'required', 'integer', 'min:1'],
'received_qty' => ['nullable', 'integer', 'min:0', 'lte:quantity'],
'unit_cost' => [$updating ? 'sometimes' : 'required', 'numeric', 'min:0'],
];
}
}