chore: update document approval workflow and bug fixes
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ProjectReports\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProjectReportsController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('projectreports::index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('projectreports::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('projectreports::show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('projectreports::edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ProjectReports\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Inertia;
|
||||
use Modules\ApprovalWorkflow\Services\ApprovalService;
|
||||
use Modules\ProjectManagement\Enums\DelayReason;
|
||||
use Modules\ProjectManagement\Enums\ReportStatus;
|
||||
use Modules\ProjectManagement\Enums\WeatherCondition;
|
||||
use Modules\ProjectManagement\Models\HseRecord;
|
||||
use Modules\ProjectManagement\Models\Project;
|
||||
use Modules\ProjectManagement\Models\TaskDelay;
|
||||
use Modules\ProjectManagement\Models\WeeklyStatusReport;
|
||||
use Modules\ProjectManagement\Models\WorkforceMetric;
|
||||
|
||||
class StatusReportController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private ApprovalService $approvalService,
|
||||
) {}
|
||||
|
||||
public function index(Request $request, Project $project)
|
||||
{
|
||||
$reports = $project->statusReports()
|
||||
->with(['workforceMetric', 'hseRecord', 'submitter:id,name'])
|
||||
->when($request->status, fn ($q, $s) => $q->where('status', $s))
|
||||
->paginate(15)
|
||||
->withQueryString();
|
||||
|
||||
return Inertia::render('ProjectReports::Reports/Index', [
|
||||
'project' => $project->load('status'), // we need status for transitions if we want to show it
|
||||
'reports' => $reports,
|
||||
'filters' => $request->only(['status']),
|
||||
'statuses' => collect(ReportStatus::cases())->map(fn ($s) => [
|
||||
'value' => $s->value,
|
||||
'label' => $s->label(),
|
||||
]),
|
||||
'allowedTransitions' => collect($project->status->allowedTransitions())->map(fn ($s) => [
|
||||
'value' => $s->value,
|
||||
'label' => $s->label(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(Project $project)
|
||||
{
|
||||
$latestReport = $project->statusReports()->first();
|
||||
|
||||
$defaultStart = $latestReport
|
||||
? $latestReport->period_end->addDay()->format('Y-m-d')
|
||||
: ($project->start_date?->format('Y-m-d') ?? now()->format('Y-m-d'));
|
||||
|
||||
return Inertia::render('ProjectManagement::Reports/Create', [
|
||||
'project' => $project->only('id', 'name', 'code'),
|
||||
'defaultPeriodStart' => $defaultStart,
|
||||
'defaultPeriodEnd' => now()->format('Y-m-d'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request, Project $project)
|
||||
{
|
||||
$validated = $this->validateReport($request);
|
||||
|
||||
$report = DB::transaction(function () use ($validated, $project, $request) {
|
||||
$report = $project->statusReports()->create([
|
||||
'period_start' => $validated['period_start'],
|
||||
'period_end' => $validated['period_end'],
|
||||
'narrative_status' => $validated['narrative_status'] ?? null,
|
||||
'narrative_weather' => $validated['narrative_weather'] ?? null,
|
||||
'narrative_compliance' => $validated['narrative_compliance'] ?? null,
|
||||
'submitted_by' => $request->user()->id,
|
||||
]);
|
||||
|
||||
$periodManHours = (float) ($validated['period_man_hours'] ?? 0);
|
||||
$cumulative = WorkforceMetric::calculateCumulative(
|
||||
$project->id,
|
||||
$validated['period_start'],
|
||||
$periodManHours,
|
||||
);
|
||||
|
||||
$report->workforceMetric()->create([
|
||||
'active_workforce' => $validated['active_workforce'] ?? 0,
|
||||
'period_man_hours' => $periodManHours,
|
||||
'cumulative_man_hours' => $cumulative,
|
||||
'logistics_km' => $validated['logistics_km'] ?? 0,
|
||||
]);
|
||||
|
||||
$report->hseRecord()->create([
|
||||
'toolbox_meetings' => $validated['toolbox_meetings'] ?? 0,
|
||||
'safety_observations' => $validated['safety_observations'] ?? 0,
|
||||
'fatalities' => $validated['fatalities'] ?? 0,
|
||||
'major_injuries' => $validated['major_injuries'] ?? 0,
|
||||
'first_aid_cases' => $validated['first_aid_cases'] ?? 0,
|
||||
'medical_cases' => $validated['medical_cases'] ?? 0,
|
||||
'near_misses' => $validated['near_misses'] ?? 0,
|
||||
'environmental_damage' => $validated['environmental_damage'] ?? 0,
|
||||
'property_damage' => $validated['property_damage'] ?? 0,
|
||||
'fines' => $validated['fines'] ?? 0,
|
||||
]);
|
||||
|
||||
return $report;
|
||||
});
|
||||
|
||||
// Auto-populate weather from task delays if user left fields empty
|
||||
$this->autoPopulateWeather($report, $project);
|
||||
|
||||
return redirect()->route('projects.reports.show', [$project, $report])
|
||||
->with('success', 'Status report created.');
|
||||
}
|
||||
|
||||
public function show(Project $project, WeeklyStatusReport $report)
|
||||
{
|
||||
$report->load([
|
||||
'workforceMetric',
|
||||
'hseRecord',
|
||||
'submitter:id,name',
|
||||
'approver:id,name',
|
||||
'approvalChains.steps.approver:id,name',
|
||||
]);
|
||||
|
||||
return Inertia::render('ProjectManagement::Reports/Show', [
|
||||
'project' => $project->load(['customer:id,name', 'contractor:id,company_name']),
|
||||
'report' => $report,
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit(Project $project, WeeklyStatusReport $report)
|
||||
{
|
||||
if (!in_array($report->status, [ReportStatus::Draft, ReportStatus::Rejected])) {
|
||||
return back()->with('error', 'Only draft or rejected reports can be edited.');
|
||||
}
|
||||
|
||||
$report->load(['workforceMetric', 'hseRecord']);
|
||||
|
||||
return Inertia::render('ProjectManagement::Reports/Edit', [
|
||||
'project' => $project->only('id', 'name', 'code'),
|
||||
'report' => $report,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Project $project, WeeklyStatusReport $report)
|
||||
{
|
||||
if (!in_array($report->status, [ReportStatus::Draft, ReportStatus::Rejected])) {
|
||||
return back()->with('error', 'Only draft or rejected reports can be edited.');
|
||||
}
|
||||
|
||||
$validated = $this->validateReport($request);
|
||||
|
||||
DB::transaction(function () use ($validated, $project, $report) {
|
||||
$report->update([
|
||||
'period_start' => $validated['period_start'],
|
||||
'period_end' => $validated['period_end'],
|
||||
'narrative_status' => $validated['narrative_status'] ?? null,
|
||||
'narrative_weather' => $validated['narrative_weather'] ?? null,
|
||||
'narrative_compliance' => $validated['narrative_compliance'] ?? null,
|
||||
'status' => ReportStatus::Draft, // reset to draft on edit
|
||||
]);
|
||||
|
||||
$periodManHours = (float) ($validated['period_man_hours'] ?? 0);
|
||||
$cumulative = WorkforceMetric::calculateCumulative(
|
||||
$project->id,
|
||||
$validated['period_start'],
|
||||
$periodManHours,
|
||||
$report->id,
|
||||
);
|
||||
|
||||
$report->workforceMetric()->updateOrCreate(
|
||||
['weekly_status_report_id' => $report->id],
|
||||
[
|
||||
'active_workforce' => $validated['active_workforce'] ?? 0,
|
||||
'period_man_hours' => $periodManHours,
|
||||
'cumulative_man_hours' => $cumulative,
|
||||
'logistics_km' => $validated['logistics_km'] ?? 0,
|
||||
]
|
||||
);
|
||||
|
||||
$report->hseRecord()->updateOrCreate(
|
||||
['weekly_status_report_id' => $report->id],
|
||||
[
|
||||
'toolbox_meetings' => $validated['toolbox_meetings'] ?? 0,
|
||||
'safety_observations' => $validated['safety_observations'] ?? 0,
|
||||
'fatalities' => $validated['fatalities'] ?? 0,
|
||||
'major_injuries' => $validated['major_injuries'] ?? 0,
|
||||
'first_aid_cases' => $validated['first_aid_cases'] ?? 0,
|
||||
'medical_cases' => $validated['medical_cases'] ?? 0,
|
||||
'near_misses' => $validated['near_misses'] ?? 0,
|
||||
'environmental_damage' => $validated['environmental_damage'] ?? 0,
|
||||
'property_damage' => $validated['property_damage'] ?? 0,
|
||||
'fines' => $validated['fines'] ?? 0,
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
// Auto-populate weather from task delays if user left fields empty
|
||||
$this->autoPopulateWeather($report, $project);
|
||||
|
||||
return redirect()->route('projects.reports.show', [$project, $report])
|
||||
->with('success', 'Status report updated.');
|
||||
}
|
||||
|
||||
public function submitForApproval(Request $request, Project $project, WeeklyStatusReport $report)
|
||||
{
|
||||
if ($report->status !== ReportStatus::Draft) {
|
||||
return back()->with('error', 'Only draft reports can be submitted for approval.');
|
||||
}
|
||||
|
||||
$report->transitionTo(ReportStatus::Submitted);
|
||||
|
||||
// Get PM as the approver
|
||||
$pm = $project->personnel()->wherePivot('role', 'pm')->first();
|
||||
|
||||
if (!$pm) {
|
||||
return back()->with('error', 'No Project Manager assigned. Cannot submit for approval.');
|
||||
}
|
||||
|
||||
$this->approvalService->createChain(
|
||||
approvable: $report,
|
||||
approverIds: [$pm->id],
|
||||
type: 'weekly_status_report',
|
||||
initiatedBy: $request->user()->id,
|
||||
notes: "Weekly status report for {$report->period_label}",
|
||||
);
|
||||
|
||||
$report->transitionTo(ReportStatus::InReview);
|
||||
|
||||
return back()->with('success', 'Report submitted for approval.');
|
||||
}
|
||||
|
||||
public function destroy(Project $project, WeeklyStatusReport $report)
|
||||
{
|
||||
if ($report->status !== ReportStatus::Draft) {
|
||||
return back()->with('error', 'Only draft reports can be deleted.');
|
||||
}
|
||||
|
||||
$report->delete();
|
||||
|
||||
return redirect()->route('projects.reports.index', $project)
|
||||
->with('success', 'Report deleted.');
|
||||
}
|
||||
|
||||
private function validateReport(Request $request): array
|
||||
{
|
||||
return $request->validate([
|
||||
'period_start' => 'required|date',
|
||||
'period_end' => 'required|date|after_or_equal:period_start',
|
||||
// Narrative
|
||||
'narrative_status' => 'nullable|string|max:2000',
|
||||
'narrative_weather' => 'nullable|string|max:2000',
|
||||
'narrative_compliance' => 'nullable|string|max:2000',
|
||||
// Structured weather
|
||||
'weather_work_days_lost' => 'nullable|integer|min:0',
|
||||
'weather_conditions' => 'nullable|array',
|
||||
'weather_conditions.*' => 'string',
|
||||
// Workforce
|
||||
'active_workforce' => 'nullable|integer|min:0',
|
||||
'period_man_hours' => 'nullable|numeric|min:0',
|
||||
'logistics_km' => 'nullable|numeric|min:0',
|
||||
// HSE Proactive
|
||||
'toolbox_meetings' => 'nullable|integer|min:0',
|
||||
'safety_observations' => 'nullable|integer|min:0',
|
||||
// HSE Reactive
|
||||
'fatalities' => 'nullable|integer|min:0',
|
||||
'major_injuries' => 'nullable|integer|min:0',
|
||||
'first_aid_cases' => 'nullable|integer|min:0',
|
||||
'medical_cases' => 'nullable|integer|min:0',
|
||||
'near_misses' => 'nullable|integer|min:0',
|
||||
'environmental_damage' => 'nullable|integer|min:0',
|
||||
'property_damage' => 'nullable|integer|min:0',
|
||||
'fines' => 'nullable|numeric|min:0',
|
||||
]);
|
||||
}
|
||||
|
||||
private function autoPopulateWeather(WeeklyStatusReport $report, Project $project): void
|
||||
{
|
||||
$delays = TaskDelay::whereIn('task_id', $project->tasks()->pluck('id'))
|
||||
->where('reason_type', DelayReason::Weather)
|
||||
->whereBetween('delay_date', [$report->period_start, $report->period_end])
|
||||
->get();
|
||||
|
||||
if ($delays->isEmpty()) return;
|
||||
|
||||
$totalHours = (float) $delays->sum('lost_hours');
|
||||
$daysLost = (int) ceil($totalHours / 8);
|
||||
$conditions = $delays->pluck('weather_condition')
|
||||
->filter()
|
||||
->map(fn ($c) => $c instanceof WeatherCondition ? $c->value : $c)
|
||||
->unique()
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
$updates = [];
|
||||
|
||||
if ($report->weather_work_days_lost === 0 && $daysLost > 0) {
|
||||
$updates['weather_work_days_lost'] = $daysLost;
|
||||
}
|
||||
|
||||
if (empty($report->weather_conditions) && !empty($conditions)) {
|
||||
$updates['weather_conditions'] = $conditions;
|
||||
}
|
||||
|
||||
// Auto-generate narrative if empty
|
||||
if (empty($report->narrative_weather) && !empty($conditions)) {
|
||||
$labels = collect($conditions)->map(fn ($v) => WeatherCondition::tryFrom($v)?->label() ?? $v)->join(', ');
|
||||
$updates['narrative_weather'] = "Weather delays recorded: {$labels}. Total {$daysLost} work day(s) lost ({$totalHours} hours).";
|
||||
}
|
||||
|
||||
if (!empty($updates)) {
|
||||
$report->update($updates);
|
||||
}
|
||||
}
|
||||
}
|
||||
0
Modules/ProjectReports/app/Providers/.gitkeep
Normal file
0
Modules/ProjectReports/app/Providers/.gitkeep
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ProjectReports\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event handler mappings for the application.
|
||||
*
|
||||
* @var array<string, array<int, string>>
|
||||
*/
|
||||
protected $listen = [];
|
||||
|
||||
/**
|
||||
* Indicates if events should be discovered.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $shouldDiscoverEvents = true;
|
||||
|
||||
/**
|
||||
* Configure the proper event listeners for email verification.
|
||||
*/
|
||||
protected function configureEmailVerification(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ProjectReports\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Nwidart\Modules\Traits\PathNamespace;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
|
||||
class ProjectReportsServiceProvider extends ServiceProvider
|
||||
{
|
||||
use PathNamespace;
|
||||
|
||||
protected string $name = 'ProjectReports';
|
||||
|
||||
protected string $nameLower = 'projectreports';
|
||||
|
||||
/**
|
||||
* Boot the application events.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$this->registerCommands();
|
||||
$this->registerCommandSchedules();
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
$this->loadMigrationsFrom(module_path($this->name, 'database/migrations'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->register(EventServiceProvider::class);
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register commands in the format of Command::class
|
||||
*/
|
||||
protected function registerCommands(): void
|
||||
{
|
||||
// $this->commands([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register command Schedules.
|
||||
*/
|
||||
protected function registerCommandSchedules(): void
|
||||
{
|
||||
// $this->app->booted(function () {
|
||||
// $schedule = $this->app->make(Schedule::class);
|
||||
// $schedule->command('inspire')->hourly();
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
* Register translations.
|
||||
*/
|
||||
public function registerTranslations(): void
|
||||
{
|
||||
$langPath = resource_path('lang/modules/'.$this->nameLower);
|
||||
|
||||
if (is_dir($langPath)) {
|
||||
$this->loadTranslationsFrom($langPath, $this->nameLower);
|
||||
$this->loadJsonTranslationsFrom($langPath);
|
||||
} else {
|
||||
$this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->nameLower);
|
||||
$this->loadJsonTranslationsFrom(module_path($this->name, 'lang'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register config.
|
||||
*/
|
||||
protected function registerConfig(): void
|
||||
{
|
||||
$relativeConfigPath = config('modules.paths.generator.config.path');
|
||||
$configPath = module_path($this->name, $relativeConfigPath);
|
||||
|
||||
if (is_dir($configPath)) {
|
||||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
if ($file->isFile() && $file->getExtension() === 'php') {
|
||||
$relativePath = str_replace($configPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
|
||||
$configKey = $this->nameLower . '.' . str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
|
||||
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;
|
||||
|
||||
$this->publishes([$file->getPathname() => config_path($relativePath)], 'config');
|
||||
$this->mergeConfigFrom($file->getPathname(), $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register views.
|
||||
*/
|
||||
public function registerViews(): void
|
||||
{
|
||||
$viewPath = resource_path('views/modules/'.$this->nameLower);
|
||||
$sourcePath = module_path($this->name, 'resources/views');
|
||||
|
||||
$this->publishes([$sourcePath => $viewPath], ['views', $this->nameLower.'-module-views']);
|
||||
|
||||
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower);
|
||||
|
||||
$componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path')));
|
||||
Blade::componentNamespace($componentNamespace, $this->nameLower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*/
|
||||
public function provides(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
private function getPublishableViewPaths(): array
|
||||
{
|
||||
$paths = [];
|
||||
foreach (config('view.paths') as $path) {
|
||||
if (is_dir($path.'/modules/'.$this->nameLower)) {
|
||||
$paths[] = $path.'/modules/'.$this->nameLower;
|
||||
}
|
||||
}
|
||||
|
||||
return $paths;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ProjectReports\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $name = 'ProjectReports';
|
||||
|
||||
/**
|
||||
* Called before routes are registered.
|
||||
*
|
||||
* Register any model bindings or pattern based filters.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*/
|
||||
public function map(): void
|
||||
{
|
||||
$this->mapApiRoutes();
|
||||
$this->mapWebRoutes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "web" routes for the application.
|
||||
*
|
||||
* These routes all receive session state, CSRF protection, etc.
|
||||
*/
|
||||
protected function mapWebRoutes(): void
|
||||
{
|
||||
Route::middleware('web')->group(module_path($this->name, '/routes/web.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*/
|
||||
protected function mapApiRoutes(): void
|
||||
{
|
||||
Route::middleware('api')->prefix('api')->name('api.')->group(module_path($this->name, '/routes/api.php'));
|
||||
}
|
||||
}
|
||||
30
Modules/ProjectReports/composer.json
Normal file
30
Modules/ProjectReports/composer.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "nwidart/projectreports",
|
||||
"description": "",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Widart",
|
||||
"email": "n.widart@gmail.com"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [],
|
||||
"aliases": {
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\ProjectReports\\": "app/",
|
||||
"Modules\\ProjectReports\\Database\\Factories\\": "database/factories/",
|
||||
"Modules\\ProjectReports\\Database\\Seeders\\": "database/seeders/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Modules\\ProjectReports\\Tests\\": "tests/"
|
||||
}
|
||||
}
|
||||
}
|
||||
0
Modules/ProjectReports/config/.gitkeep
Normal file
0
Modules/ProjectReports/config/.gitkeep
Normal file
5
Modules/ProjectReports/config/config.php
Normal file
5
Modules/ProjectReports/config/config.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => 'ProjectReports',
|
||||
];
|
||||
0
Modules/ProjectReports/database/factories/.gitkeep
Normal file
0
Modules/ProjectReports/database/factories/.gitkeep
Normal file
0
Modules/ProjectReports/database/migrations/.gitkeep
Normal file
0
Modules/ProjectReports/database/migrations/.gitkeep
Normal file
0
Modules/ProjectReports/database/seeders/.gitkeep
Normal file
0
Modules/ProjectReports/database/seeders/.gitkeep
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ProjectReports\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ProjectReportsDatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
}
|
||||
}
|
||||
11
Modules/ProjectReports/module.json
Normal file
11
Modules/ProjectReports/module.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "ProjectReports",
|
||||
"alias": "projectreports",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"priority": 0,
|
||||
"providers": [
|
||||
"Modules\\ProjectReports\\Providers\\ProjectReportsServiceProvider"
|
||||
],
|
||||
"files": []
|
||||
}
|
||||
15
Modules/ProjectReports/package.json
Normal file
15
Modules/ProjectReports/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"axios": "^1.1.2",
|
||||
"laravel-vite-plugin": "^0.7.5",
|
||||
"sass": "^1.69.5",
|
||||
"postcss": "^8.3.7",
|
||||
"vite": "^4.0.0"
|
||||
}
|
||||
}
|
||||
0
Modules/ProjectReports/resources/assets/.gitkeep
Normal file
0
Modules/ProjectReports/resources/assets/.gitkeep
Normal file
0
Modules/ProjectReports/resources/assets/js/app.js
Normal file
0
Modules/ProjectReports/resources/assets/js/app.js
Normal file
97
Modules/ProjectReports/resources/js/Pages/Reports/Index.tsx
Normal file
97
Modules/ProjectReports/resources/js/Pages/Reports/Index.tsx
Normal file
@@ -0,0 +1,97 @@
|
||||
import ProjectLayout from '../../../../../ProjectManagement/resources/js/Layouts/ProjectLayout';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/Components/ui/card';
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/Components/ui/table';
|
||||
import { Button } from '@/Components/ui/button';
|
||||
import { Badge } from '@/Components/ui/badge';
|
||||
import { ClipboardList, Plus, Eye } from 'lucide-react';
|
||||
import { Link } from '@inertiajs/react';
|
||||
|
||||
export default function Reports({ project, reports }: any) {
|
||||
const statusLabel = (s: string) => s.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
|
||||
|
||||
const reportTotalIncidents = (hse?: any): number => {
|
||||
if (!hse) return 0;
|
||||
return hse.fatalities + hse.major_injuries + hse.first_aid_cases
|
||||
+ hse.medical_cases + hse.near_misses + hse.environmental_damage + hse.property_damage;
|
||||
};
|
||||
|
||||
return (
|
||||
<ProjectLayout project={project} currentTab="reports">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex items-center justify-between">
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<ClipboardList className="h-5 w-5 text-gray-500" /> Status Reports
|
||||
</CardTitle>
|
||||
<Link href={route('projects.reports.create', { project: project.ulid })}>
|
||||
<Button size="sm"><Plus className="mr-2 h-4 w-4" /> New Report</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Period</TableHead>
|
||||
<TableHead>Submitter</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead className="text-right">Man-hours</TableHead>
|
||||
<TableHead className="text-center">HSE Incidents</TableHead>
|
||||
<TableHead className="text-right">Actions</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{reports?.data?.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={6} className="text-center text-gray-500 py-8">
|
||||
No reports submitted yet.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
reports?.data?.map((report: any) => {
|
||||
const incidentCount = reportTotalIncidents(report.hse_record);
|
||||
return (
|
||||
<TableRow key={report.id}>
|
||||
<TableCell className="font-medium text-sm tabular-nums">
|
||||
{new Date(report.period_start).toLocaleDateString('en-PH', { month: 'short', day: 'numeric' })}
|
||||
{' - '}
|
||||
{new Date(report.period_end).toLocaleDateString('en-PH', { month: 'short', day: 'numeric', year: 'numeric' })}
|
||||
</TableCell>
|
||||
<TableCell className="text-sm">{report.submitter?.name}</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant={
|
||||
report.status === 'approved' ? 'default' :
|
||||
report.status === 'draft' ? 'secondary' :
|
||||
report.status === 'rejected' ? 'destructive' : 'outline'
|
||||
}>
|
||||
{statusLabel(report.status)}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell className="text-right text-sm tabular-nums">
|
||||
{report.workforce_metric?.period_man_hours || '-'}
|
||||
</TableCell>
|
||||
<TableCell className="text-center">
|
||||
{incidentCount > 0 ? (
|
||||
<Badge variant="destructive" className="bg-red-100 text-red-800 hover:bg-red-100 border-red-200">{incidentCount} issues</Badge>
|
||||
) : (
|
||||
<span className="text-gray-400 text-sm">—</span>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<Link href={route('projects.reports.show', [project.ulid, report.ulid])}>
|
||||
<Button variant="ghost" size="icon-sm" title="View Report">
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</ProjectLayout>
|
||||
);
|
||||
}
|
||||
0
Modules/ProjectReports/resources/views/.gitkeep
Normal file
0
Modules/ProjectReports/resources/views/.gitkeep
Normal file
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
|
||||
<title>ProjectReports Module - {{ config('app.name', 'Laravel') }}</title>
|
||||
|
||||
<meta name="description" content="{{ $description ?? '' }}">
|
||||
<meta name="keywords" content="{{ $keywords ?? '' }}">
|
||||
<meta name="author" content="{{ $author ?? '' }}">
|
||||
|
||||
<!-- Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.bunny.net">
|
||||
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
|
||||
|
||||
{{-- Vite CSS --}}
|
||||
{{-- {{ module_vite('build-projectreports', 'resources/assets/sass/app.scss', storage_path('vite.hot')) }} --}}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@yield('content')
|
||||
|
||||
{{-- Vite JS --}}
|
||||
{{-- {{ module_vite('build-projectreports', 'resources/assets/js/app.js', storage_path('vite.hot')) }} --}}
|
||||
</body>
|
||||
7
Modules/ProjectReports/resources/views/index.blade.php
Normal file
7
Modules/ProjectReports/resources/views/index.blade.php
Normal file
@@ -0,0 +1,7 @@
|
||||
@extends('projectreports::layouts.master')
|
||||
|
||||
@section('content')
|
||||
<h1>Hello World</h1>
|
||||
|
||||
<p>Module: {!! config('projectreports.name') !!}</p>
|
||||
@endsection
|
||||
0
Modules/ProjectReports/routes/.gitkeep
Normal file
0
Modules/ProjectReports/routes/.gitkeep
Normal file
19
Modules/ProjectReports/routes/api.php
Normal file
19
Modules/ProjectReports/routes/api.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\ProjectReports\Http\Controllers\ProjectReportsController;
|
||||
|
||||
/*
|
||||
*--------------------------------------------------------------------------
|
||||
* API Routes
|
||||
*--------------------------------------------------------------------------
|
||||
*
|
||||
* Here is where you can register API routes for your application. These
|
||||
* routes are loaded by the RouteServiceProvider within a group which
|
||||
* is assigned the "api" middleware group. Enjoy building your API!
|
||||
*
|
||||
*/
|
||||
|
||||
Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () {
|
||||
Route::apiResource('projectreports', ProjectReportsController::class)->names('projectreports');
|
||||
});
|
||||
10
Modules/ProjectReports/routes/web.php
Normal file
10
Modules/ProjectReports/routes/web.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\ProjectReports\Http\Controllers\StatusReportController;
|
||||
|
||||
Route::middleware(['web', 'auth', 'permission:projects.access'])->group(function () {
|
||||
Route::get('projects/{project}/reports', [StatusReportController::class, 'index'])->name('projects.reports.index');
|
||||
Route::resource('projects.reports', StatusReportController::class)->parameters(['reports' => 'report'])->except(['index']);
|
||||
Route::patch('projects/{project}/reports/{report}/submit', [StatusReportController::class, 'submitForApproval'])->name('projects.reports.submit');
|
||||
});
|
||||
0
Modules/ProjectReports/tests/Feature/.gitkeep
Normal file
0
Modules/ProjectReports/tests/Feature/.gitkeep
Normal file
0
Modules/ProjectReports/tests/Unit/.gitkeep
Normal file
0
Modules/ProjectReports/tests/Unit/.gitkeep
Normal file
57
Modules/ProjectReports/vite.config.js
Normal file
57
Modules/ProjectReports/vite.config.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import laravel from 'laravel-vite-plugin';
|
||||
import { readdirSync, statSync } from 'fs';
|
||||
import { join,relative,dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
outDir: '../../public/build-projectreports',
|
||||
emptyOutDir: true,
|
||||
manifest: true,
|
||||
},
|
||||
plugins: [
|
||||
laravel({
|
||||
publicDirectory: '../../public',
|
||||
buildDirectory: 'build-projectreports',
|
||||
input: [
|
||||
__dirname + '/resources/assets/sass/app.scss',
|
||||
__dirname + '/resources/assets/js/app.js'
|
||||
],
|
||||
refresh: true,
|
||||
}),
|
||||
],
|
||||
});
|
||||
// Scen all resources for assets file. Return array
|
||||
//function getFilePaths(dir) {
|
||||
// const filePaths = [];
|
||||
//
|
||||
// function walkDirectory(currentPath) {
|
||||
// const files = readdirSync(currentPath);
|
||||
// for (const file of files) {
|
||||
// const filePath = join(currentPath, file);
|
||||
// const stats = statSync(filePath);
|
||||
// if (stats.isFile() && !file.startsWith('.')) {
|
||||
// const relativePath = 'Modules/ProjectReports/'+relative(__dirname, filePath);
|
||||
// filePaths.push(relativePath);
|
||||
// } else if (stats.isDirectory()) {
|
||||
// walkDirectory(filePath);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// walkDirectory(dir);
|
||||
// return filePaths;
|
||||
//}
|
||||
|
||||
//const __filename = fileURLToPath(import.meta.url);
|
||||
//const __dirname = dirname(__filename);
|
||||
|
||||
//const assetsDir = join(__dirname, 'resources/assets');
|
||||
//export const paths = getFilePaths(assetsDir);
|
||||
|
||||
|
||||
//export const paths = [
|
||||
// 'Modules/ProjectReports/resources/assets/sass/app.scss',
|
||||
// 'Modules/ProjectReports/resources/assets/js/app.js',
|
||||
//];
|
||||
Reference in New Issue
Block a user