68 lines
2.7 KiB
PHP
68 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\ShorakaFinancingService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Throwable;
|
|
|
|
class ShorakaController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$records = app(ShorakaFinancingService::class)->listForBranch(Auth::user()->cawangan);
|
|
$cawangan_info = ['details_caw' => Auth::user()->cawangan, 'kodcaw' => Auth::user()->cawangan];
|
|
return view('shoraka.index', compact('records', 'cawangan_info'));
|
|
}
|
|
|
|
public function operasiIndex(Request $request)
|
|
{
|
|
abort_unless(in_array(Auth::user()->roles, ['operasi', 'pc', 'ppc'], true), 403);
|
|
$isOperasi = Auth::user()->roles === 'operasi';
|
|
$filters = $request->validate([
|
|
'kodcaw' => 'nullable|string|max:30',
|
|
'norujukan' => 'nullable|string|max:100',
|
|
'status' => 'nullable|in:PENDING,Active,Completed,Cancelled,UNKNOWN,FAILED',
|
|
'date_from' => 'nullable|date_format:Y-m-d',
|
|
'date_to' => 'nullable|date_format:Y-m-d' . ($request->filled('date_from') ? '|after_or_equal:date_from' : ''),
|
|
]);
|
|
[$records, $branches] = app(ShorakaFinancingService::class)->search(
|
|
$filters,
|
|
$isOperasi ? null : Auth::user()->cawangan
|
|
);
|
|
$cawangan_info = ['details_caw' => Auth::user()->cawangan, 'kodcaw' => Auth::user()->cawangan];
|
|
return view('shoraka.operasi', compact('records', 'branches', 'filters', 'isOperasi', 'cawangan_info'));
|
|
}
|
|
|
|
public function pcIndex(Request $request)
|
|
{
|
|
abort_unless(in_array(Auth::user()->roles, ['pc', 'ppc'], true), 403);
|
|
return $this->operasiIndex($request);
|
|
}
|
|
|
|
public function show(string $norujukan, ShorakaFinancingService $service)
|
|
{
|
|
$data = null;
|
|
$error = null;
|
|
try {
|
|
$data = $service->snapshot($norujukan);
|
|
} catch (Throwable $exception) {
|
|
$error = 'Maklumat Shoraka tidak dapat diambil. Bayaran dan SAG masih ditahan.';
|
|
}
|
|
$cawangan_info = ['details_caw' => Auth::user()->cawangan, 'kodcaw' => Auth::user()->cawangan];
|
|
return view('shoraka.show', compact('norujukan', 'data', 'error', 'cawangan_info'));
|
|
}
|
|
|
|
public function certificate(string $norujukan, ShorakaFinancingService $service)
|
|
{
|
|
$response = $service->api()->get($service->url($norujukan, '/certificate'))->throw();
|
|
abort_unless(substr($response->body(), 0, 5) === '%PDF-', 502);
|
|
return response($response->body(), 200, [
|
|
'Content-Type' => 'application/pdf',
|
|
'Content-Disposition' => 'attachment; filename="sijil-shoraka.pdf"',
|
|
'Cache-Control' => 'private, no-store',
|
|
]);
|
|
}
|
|
}
|