Merge branch 'staging' into feature/senior-officer
This commit is contained in:
@@ -21,10 +21,17 @@
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\StatusPermohonan;
|
||||
use Modules\Lpj\Models\TujuanPenilaian;
|
||||
use Modules\Lpj\Services\PermohonanHistoryService;
|
||||
|
||||
class PermohonanController extends Controller
|
||||
{
|
||||
public $user;
|
||||
protected $historyService;
|
||||
|
||||
public function __construct(PermohonanHistoryService $historyService)
|
||||
{
|
||||
$this->historyService = $historyService;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
@@ -36,8 +43,30 @@
|
||||
$validate = $request->validated();
|
||||
if ($validate) {
|
||||
try {
|
||||
// Process file upload
|
||||
$filePath = null;
|
||||
if ($request->hasFile('attachment')) {
|
||||
$file = $request->file('attachment');
|
||||
$fileName = time() . '_' . $file->getClientOriginalName();
|
||||
$filePath = $file->storeAs('permohonan_attachments', $fileName, 'public');
|
||||
}
|
||||
|
||||
// Get keterangan if provided
|
||||
$keterangan = $request->input('keterangan') ?? null;
|
||||
|
||||
|
||||
// Save to database
|
||||
Permohonan::create($validate);
|
||||
$permohonan = Permohonan::create($validate);
|
||||
|
||||
// Create history
|
||||
$this->historyService->createHistory(
|
||||
$permohonan,
|
||||
$validate['status'],
|
||||
$keterangan,
|
||||
[], // beforeRequest is empty for new permohonan
|
||||
$permohonan->toArray(),
|
||||
$filePath
|
||||
);
|
||||
return redirect()
|
||||
->route('permohonan.index')->with('success', 'Permohonan created successfully');
|
||||
} catch (Exception $e) {
|
||||
@@ -107,16 +136,41 @@
|
||||
|
||||
public function update(PermohonanRequest $request, $id)
|
||||
{
|
||||
$validate = $request->validated();
|
||||
$permohonan = Permohonan::findOrFail($id);
|
||||
$beforeRequest = $permohonan->toArray();
|
||||
|
||||
$validate = $request->validated();
|
||||
if ($validate) {
|
||||
try {
|
||||
// Update in database
|
||||
$permohonan = Permohonan::find($id);
|
||||
|
||||
if ($permohonan->status == 'revisi') {
|
||||
$validate['status'] = 'order';
|
||||
}
|
||||
|
||||
$permohonan->update($validate);
|
||||
|
||||
$afterRequest = $permohonan->fresh()->toArray();
|
||||
// Process file upload
|
||||
$file = null;
|
||||
if ($request->hasFile('attachment')) {
|
||||
$file = $request->file('attachment');
|
||||
}
|
||||
|
||||
// Get keterangan if provided
|
||||
$keterangan = $request->input('keterangan') ?? null;
|
||||
|
||||
$status =$validate['status'] ?? $permohonan->status;
|
||||
|
||||
$this->historyService->createHistory(
|
||||
$permohonan,
|
||||
$status,
|
||||
$keterangan,
|
||||
$beforeRequest,
|
||||
$afterRequest,
|
||||
$file
|
||||
);
|
||||
|
||||
return redirect()
|
||||
->route('permohonan.index')->with('success', 'Permohonan updated successfully');
|
||||
} catch (Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user