middleware(function ($request, $next) { $this->user = Auth::guard('web')->user(); return $next($request); }); addVendor('chained-select'); } /** * Display a listing of the resource. */ public function index(DocumentDataTable $dataTable) { if (is_null($this->user) || !$this->user->can('document.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } return $dataTable->render('cetaklabel::app.document.index'); } /** * Store a newly created resource in storage. */ public function store(StoreDocumentRequest $request) { if (is_null($this->user) || !$this->user->can('document.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } // Validate the request... $validated = $request->validated();$validated = $request->validated(); $detailValidate = Validator::validate($request->all(), [ 'file' => [ File::types(['pdf', 'zip', 'jpg', 'jpeg', 'png', 'bmp', 'tiff']) ->max(5 * 1024) ] ]); // Store the Document... if ($validated && $detailValidate) { try { $document = Document::where(['kode_odner' => $validated['kode_odner'], 'sequence_odner' => $validated['sequence_odner'] ])->first(); if ($document) { $document->update($validated); } else { $document = Document::create($validated); } $created = Document::find($document->id); if ($request->hasFile('file')) { $file = $request->file('file'); $path = 'uploads/' . substr($created->kode, 0, 10) . '/' . $created->sequence_odner . '/' . substr($created->kode, -5, 3); $filename = substr($created->kode, -2, 2) . '_' . $file->getClientOriginalName(); if ($file->move(public_path($path), $filename)) { $request['file'] = $path . '/' . $filename; } } $special_code = SpecialCode::find($request->special_code_id); $kode = IdGenerator::generate([ 'table' => 'document_details', 'field' => 'kode', 'length' => 13, 'prefix' => $created->kode ]); $detail = [ 'kode' => $kode . $special_code->kode, 'no_urut' => substr($kode, -3, 3), 'document_id' => $created->id, 'document_type_id' => $request->document_type_id, 'special_code_id' => $request->special_code_id, 'tanggal_upload' => date('Y-m-d H:i:s'), 'tanggal_dokumen' => $request->tanggal_dokumen, 'nomor_dokumen' => $request->nomor_dokumen, 'perihal' => $request->perihal, 'kode_cabang' => $request->kode_cabang, 'jumlah_halaman' => $request->jumlah_halaman, 'custom_field_1' => $request->custom_field_1, 'custom_field_2' => $request->custom_field_2, 'custom_field_3' => $request->custom_field_3, 'custom_field_4' => $request->custom_field_4, 'file' => $path . '/' . $filename, 'nama_nasabah' => $request->nama_nasabah, 'no_rekening' => $request->no_rekening, 'no_cif' => $request->no_cif, 'group' => $request->group, 'kategori' => $request->kategori, 'status' => '0', 'keterangan' => '' ]; DocumentDetail::create($detail); return redirect()->route('document.index')->with('success', 'Document created successfully.'); } catch (Exception $e) { return redirect()->route('document.index')->with('error', 'Document created failed, ' . $e->getMessage()); } } return false; } /** * Update the specified resource in storage. */ public function update(Request $request) { if (is_null($this->user) || !$this->user->hasRole('dd')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } try { $data = [ 'approval_flag' => $request->flag ?? null, 'status' => $request->keterangan == "" ? '1' : '3', 'keterangan' => $request->keterangan ?? null, 'approved_at' => date('Y-m-d H:i:s'), 'approved_by' => $this->user->id ]; $documents = DocumentDetail::find($request->id); $documents->update($data); echo json_encode(['status' => 'success', 'message' => 'Document updated successfully.']); } catch (Exception $e) { echo json_encode(['status' => 'error', 'message' => 'Document updated failed.']); } } /** * Show the form for creating a new resource. */ public function create() { if (is_null($this->user) || !$this->user->can('document.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } $directorat = []; if($this->user->hasRole('ad')){ $directorat = Directorat::all(); } $subdirectorats = SubDirectorat::where('directorat_id',$this->user->directorat_id)->get(); $jobs = Job::where('sub_directorat_id',$this->user->sub_directorat_id)->get(); $special_code = SpecialCode::all(); $document_type = DocumentType::all(); $setting = Setting::all(); return view('cetaklabel::app.document.create', compact('directorat', 'special_code', 'document_type', 'setting','subdirectorats','jobs')); } /** * Display the specified resource. */ public function show(Document $documents) { if (is_null($this->user) || !$this->user->can('document.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } abort(404, 'Page not found !'); } /** * Show the form for editing the specified resource. */ public function edit($id) { if (is_null($this->user) || !$this->user->hasRole('dd')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } $document = DocumentDetail::with('document')->find($id); if ($document->status != '0') { abort(403, 'Sorry !! This Document has been authorized !'); } $document = DocumentDetail::with('document')->find($id); return view('cetaklabel::app.document.edit', compact('document')); } /** * Remove the specified resource from storage. */ public function destroy(Request $request) { if (is_null($this->user) || !$this->user->can('document.delete')) { abort(403, 'Sorry !! You are Unauthorized to delete any master data !'); } // Delete Detail Document First... $document_details = DocumentDetail::find($request->document); if ($document_details->status == 1) { $document_details->update(['status' => '6', 'keterangan' => $request->keterangan]); echo json_encode(['status' => 'success', 'message' => 'Document menunggu Approval untuk di Hapus.']); return; } if ($document_details->status == 6) { $document_details->update(['status' => '7']); echo json_encode(['status' => 'success', 'message' => 'Document menunggu Approval Tingkat 2 untuk di Hapus.']); return; } if ($document_details->status == 7) { $document_details->update(['status' => '8']); $document_details->delete(); echo json_encode(['status' => 'success', 'message' => 'Document deleted successfully.']); } } public function download(Request $request) { if (is_null($this->user) || !$this->user->can('document.read')) { abort(403, 'Sorry !! You are Unauthorized to download any master data !'); } $document = DocumentDetail::find($request->id); if ($document->status == 1 && $document->approval_flag == 1) { $document->update(['status' => '4']); $document->save(); echo json_encode(['status' => 'success', 'message' => 'Document menunggu Approval untuk di Cetak.']); return; } if ($document->status == 4 && $document->approval_flag == 1) { $document->update(['status' => '5']); $document->save(); echo json_encode(['status' => 'success', 'message' => 'Approval Berhasil.']); return; } if ($document->status == 5 && $document->approval_flag !== 1) { $document->update(['status' => '1']); $document->save(); $filepath = public_path($document->file); return Response::download($filepath); } /*if($document->status == 1 && $document->approval_flag !== 1){ $filepath = public_path($document->file); return Response::download($filepath); }*/ } public function aktif(Request $request) { $document = DocumentDetail::find($request->id); if ($document->aktif == 1 && $document->status != 9) { $document->update(['status' => '9', 'keterangan' => $request->keterangan]); echo json_encode(['status' => 'success', 'message' => 'Document menunggu Approval untuk di Nonaktifkan.']); return; } if ($document->aktif == 1 && $document->status == 9) { $document->update(['aktif' => '0', 'status' => '1']); echo json_encode(['status' => 'success', 'message' => 'Document Berhasil di Nonaktifkan.']); return; } } public function odner(Request $request) { if (is_null($this->user) || !$this->user->can('document.read')) { abort(403, 'Sorry !! You are Unauthorized to download any master data !'); } $document_detail = DocumentDetail::with(['document'])->find($request->id); $document = Document::with(['document_details'])->where(['kode_odner' => $document_detail->document->kode_odner, 'sequence_odner' => $document_detail->document->sequence_odner ])->first(); $start = DocumentDetail::where('document_id', $document_detail->document_id)->orderBy('tanggal_dokumen', 'asc')->first()->tanggal_dokumen; $last = DocumentDetail::where('document_id', $document_detail->document_id)->orderBy('tanggal_dokumen', 'desc')->first()->tanggal_dokumen; $start = Carbon::create($start); $start = $start->isoFormat('DD MMMM Y'); $last = Carbon::create($last); $last = $last->isoFormat('DD MMMM Y'); activity() ->performedOn($document) ->causedBy(Auth::user()) ->withProperties($document) ->log('Cetak Label Odner'); return view('cetaklabel::app.document.odner', compact('document_detail', 'start', 'last', 'document')); } }