Files
HickLab3D_Dashboard/app/Models/ProjectCostSnapshot.php
T
hermes d4928789c4
Deploy HickLab3D Dashboard / Deploy to production (push) Failing after 23s
Add HL3D branding, Etsy Live/Draft paging and Projects lifecycle
Replace the old touchmark/PNG identity with the supplied lockup and
monogram, segmented role-aware navigation, Live/Draft listing filters
with generation-based cache invalidation, and admin Projects covering
immutable file revisions, listing live pointers, and exact-decimal
filament/packaging/shipping costing. Additive schema only; no Etsy
publication. Isolated clone tests: 301 tests, 1162 assertions.
2026-11-08 12:50:56 +00:00

79 lines
2.2 KiB
PHP

<?php
namespace App\Models;
use App\Services\ProjectCosting;
use Database\Factories\ProjectCostSnapshotFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class ProjectCostSnapshot extends Model
{
/** @use HasFactory<ProjectCostSnapshotFactory> */
use HasFactory;
public const BASIS_ESTIMATE = 'estimate';
public const BASIS_ACTUAL = 'actual';
protected $fillable = [
'project_id', 'revision_id', 'currency', 'basis', 'batch_units',
'filament_total', 'packaging_total', 'shipping_total', 'grand_total',
'source_reference', 'notes', 'recorded_by', 'recorded_at',
];
protected function casts(): array
{
return [
'filament_total' => 'decimal:4',
'packaging_total' => 'decimal:4',
'shipping_total' => 'decimal:4',
'grand_total' => 'decimal:4',
'recorded_at' => 'datetime',
];
}
public function project(): BelongsTo
{
return $this->belongsTo(Project::class);
}
public function revision(): BelongsTo
{
return $this->belongsTo(ProjectRevision::class, 'revision_id');
}
public function recorder(): BelongsTo
{
return $this->belongsTo(User::class, 'recorded_by');
}
public function lines(): HasMany
{
return $this->hasMany(ProjectCostLine::class, 'cost_snapshot_id');
}
/**
* A release requires every cost category to have been explicitly costed —
* even as an intentional zero — rather than merely recorded. A category left
* null ("not costed") is incomplete and must block a release going live.
*/
public function isComplete(): bool
{
return $this->filament_total !== null
&& $this->packaging_total !== null
&& $this->shipping_total !== null;
}
public function perUnitGrandTotal(): ?string
{
if ($this->grand_total === null) {
return null;
}
return ProjectCosting::perUnit((string) $this->grand_total, (int) $this->batch_units);
}
}