- Added planned/actual/baseline dates to Phase and Feature models
- Created ProgressSnapshot model + migration for historical tracking
- Implemented CaptureDailyProgressSnapshot job (scheduled daily at 06:30)
- Added DeviationCalculator logic (SPI, planned progress, deviation days)
- ReportGenerator service with complete data aggregation
- ReportController with builder, preview, generate (HTML/Excel)
- ReportBuilder Livewire component with date range, entity selection, format
- ProjectReportExport with 10 sheets (Summary, Phases, Features, Inspections, Issues, Tasks, Deviations, Media, Progress Curve, Parameters)
- Blade partials for all sections (header, summary, phases, features, inspections, issues, tasks, media, deviations, progress curve)
- New routes: /projects/{project}/reports/*
- Added 'generate reports' permission
- All 101 tests passing
79 lines
1.8 KiB
PHP
79 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
|
|
class ProgressSnapshot extends Model
|
|
{
|
|
protected $fillable = [
|
|
'trackable_type',
|
|
'trackable_id',
|
|
'snapshot_date',
|
|
'progress',
|
|
'planned_start',
|
|
'planned_end',
|
|
'actual_start',
|
|
'actual_end',
|
|
'method',
|
|
'metadata',
|
|
];
|
|
|
|
protected $casts = [
|
|
'snapshot_date' => 'date',
|
|
'planned_start' => 'date',
|
|
'planned_end' => 'date',
|
|
'actual_start' => 'date',
|
|
'actual_end' => 'date',
|
|
'progress' => 'decimal:2',
|
|
'metadata' => 'array',
|
|
];
|
|
|
|
public function trackable(): MorphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
/**
|
|
* Scope for a specific date range
|
|
*/
|
|
public function scopeDateRange($query, $from, $to)
|
|
{
|
|
return $query->whereBetween('snapshot_date', [$from, $to]);
|
|
}
|
|
|
|
/**
|
|
* Scope for specific trackable
|
|
*/
|
|
public function scopeForTrackable($query, $model, $id = null)
|
|
{
|
|
$query->where('trackable_type', $model);
|
|
if ($id) {
|
|
$query->where('trackable_id', $id);
|
|
}
|
|
return $query;
|
|
}
|
|
|
|
/**
|
|
* Get latest snapshot for a trackable
|
|
*/
|
|
public static function latestFor($model, $id): ?self
|
|
{
|
|
return static::forTrackable($model, $id)
|
|
->latest('snapshot_date')
|
|
->first();
|
|
}
|
|
|
|
/**
|
|
* Get progress trend (last N snapshots)
|
|
*/
|
|
public static function trendFor($model, $id, int $limit = 10): array
|
|
{
|
|
return static::forTrackable($model, $id)
|
|
->orderBy('snapshot_date')
|
|
->take($limit)
|
|
->get(['snapshot_date', 'progress', 'method'])
|
|
->toArray();
|
|
}
|
|
} |