first commit

This commit is contained in:
Saufi
2026-06-24 20:32:14 +08:00
commit 10fb30ad69
201 changed files with 21356 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\ReportingCycleRequest;
use App\Models\ChecklistTemplate;
use App\Models\ReportingCycle;
use App\Services\ReportingCycleService;
class ReportingCycleController extends Controller
{
public function __construct(protected ReportingCycleService $service) {}
public function index()
{
$this->authorize('viewAny', ReportingCycle::class);
$cycles = ReportingCycle::withCount('submissions')
->orderByDesc('renewal_year')->paginate(15);
return view('reporting_cycles.index', compact('cycles'));
}
public function create()
{
$this->authorize('create', ReportingCycle::class);
$templates = ChecklistTemplate::orderByDesc('is_active')->get();
return view('reporting_cycles.create', [
'cycle' => new ReportingCycle(['licence_period_year' => 1, 'status' => 'aktif']),
'templates' => $templates,
]);
}
public function store(ReportingCycleRequest $request)
{
$attrs = $this->service->buildAttributes(
(int) $request->renewal_year,
$request->cut_off_date
);
$cycle = ReportingCycle::create(array_merge($request->validated(), $attrs));
return redirect()->route('reporting-cycles.index')
->with('success', "Kitaran pembaharuan {$cycle->renewal_year} (pelaporan {$cycle->reporting_year}) dicipta.");
}
public function edit(ReportingCycle $reportingCycle)
{
$this->authorize('update', $reportingCycle);
$templates = ChecklistTemplate::orderByDesc('is_active')->get();
return view('reporting_cycles.edit', ['cycle' => $reportingCycle, 'templates' => $templates]);
}
public function update(ReportingCycleRequest $request, ReportingCycle $reportingCycle)
{
$this->authorize('update', $reportingCycle);
// Kira semula tahun pelaporan & tempoh jika tahun pembaharuan berubah.
$attrs = $this->service->buildAttributes(
(int) $request->renewal_year,
$request->cut_off_date
);
// Kekalkan templat pilihan pengguna jika diberi.
$attrs['checklist_template_id'] = $request->checklist_template_id ?? $attrs['checklist_template_id'];
$reportingCycle->update(array_merge($request->validated(), $attrs));
return redirect()->route('reporting-cycles.index')
->with('success', 'Kitaran pelaporan dikemas kini.');
}
public function destroy(ReportingCycle $reportingCycle)
{
$this->authorize('delete', $reportingCycle);
if ($reportingCycle->submissions()->exists()) {
return back()->with('error', 'Kitaran tidak boleh dipadam kerana telah mempunyai serahan.');
}
$reportingCycle->delete();
return redirect()->route('reporting-cycles.index')->with('success', 'Kitaran dipadam.');
}
}