diff --git a/DataTables/DocumentDataTable.php b/DataTables/DocumentDataTable.php index 20abfc8..42cf380 100644 --- a/DataTables/DocumentDataTable.php +++ b/DataTables/DocumentDataTable.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Builder as QueryBuilder; + use Illuminate\Support\Facades\Auth; use Modules\Cetaklabel\Entities\DocumentDetail; use Yajra\DataTables\EloquentDataTable; use Yajra\DataTables\Html\Builder as HtmlBuilder; @@ -23,9 +24,66 @@ $query = $query->with(['document']); return (new EloquentDataTable($query)) ->filter(function ($query) { + if (request()->has('search')) { $search = request()->get('search'); - $query->where('kode', 'like', "%" . $search['value'] . "%"); + if(Auth::user()->hasRole('otorisator')){ + $query->orWhereRelation('document','directorat_id', Auth::user()->directorat_id); + $query->whereIn('status', [0,4,6,9]); + } else if(Auth::user()->hasRole('operator')){ + $query->orWhereRelation('document','sub_directorat_id', Auth::user()->sub_directorat_id); + } + + $query->where(function($query) use ($search){ + $query->where('kode', 'like', "%" . $search['value'] . "%"); + $query->orWhereRelation('document','kode_dus', 'like', "%" . $search['value'] . "%"); + $query->orWhereRelation('document','kode_odner', 'like', "%" . $search['value'] . "%"); + + $query->orWhereRelation('document.directorat','kode', 'like', "%" . $search['value'] . "%"); + $query->orWhereRelation('document.directorat','name', 'like', "%" . $search['value'] . "%"); + + $query->orWhereRelation('document.sub_directorat','kode', 'like', "%" . $search['value'] . "%"); + $query->orWhereRelation('document.sub_directorat','name', 'like', "%" . $search['value'] . "%"); + + $query->orWhereRelation('document.job','kode', 'like', "%" . $search['value'] . "%"); + $query->orWhereRelation('document.job','name', 'like', "%" . $search['value'] . "%"); + + $query->orWhereRelation('document.sub_job','kode', 'like', "%" . $search['value'] . "%"); + $query->orWhereRelation('document.sub_job','name', 'like', "%" . $search['value'] . "%"); + + $query->orWhereRelation('document.sub_sub_job','kode', 'like', "%" . $search['value'] . "%"); + $query->orWhereRelation('document.sub_sub_job','name', 'like', "%" . $search['value'] . "%"); + + $query->orWhere('tanggal_dokumen', 'like', "%" . $search['value'] . "%"); + $query->orWhere('tanggal_upload', 'like', "%" . $search['value'] . "%"); + $query->orWhere('nama_nasabah', 'like', "%" . $search['value'] . "%"); + $query->orWhere('no_rekening', 'like', "%" . $search['value'] . "%"); + $query->orWhere('no_cif', 'like', "%" . $search['value'] . "%"); + $query->orWhere('group', 'like', "%" . $search['value'] . "%"); + $query->orWhere('nomor_dokumen', 'like', "%" . $search['value'] . "%"); + $query->orWhere('perihal', 'like', "%" . $search['value'] . "%"); + $query->orWhere('kode_cabang', 'like', "%" . $search['value'] . "%"); + $query->orWhere('jumlah_halaman', 'like', "%" . $search['value'] . "%"); + $query->orWhere('custom_field_1', 'like', "%" . $search['value'] . "%"); + $query->orWhere('custom_field_2', 'like', "%" . $search['value'] . "%"); + $query->orWhere('custom_field_3', 'like', "%" . $search['value'] . "%"); + $query->orWhere('custom_field_4', 'like', "%" . $search['value'] . "%"); + $query->orWhere('no_urut', 'like', "%" . $search['value'] . "%"); + $query->orWhere('kategori', 'like', "%" . $search['value'] . "%"); + $query->orWhere('keterangan', 'like', "%" . $search['value'] . "%"); + }); + } + + if(request()->has('tanggalawal')){ + if(request()->get('tanggalawal') != null){ + $query->where('tanggal_dokumen', '>=', Carbon::parse(request()->get('tanggalawal'))->format('Y-m-d')); + } + } + + if(request()->has('tanggalakhir')){ + if(request()->get('tanggalakhir') != null){ + $query->where('tanggal_dokumen', '<=', Carbon::parse(request()->get('tanggalakhir'))->format('Y-m-d')); + } } }) ->addColumn('kode_dus', function ($model) { @@ -57,11 +115,37 @@ ->addColumn('sub_sub_job', function ($model) { return $model->document->sub_sub_job->kode . ' - ' . $model->document->sub_sub_job->name; }) + ->addColumn('tanggal_approve', function ($model) { + if($model->approved_at){ + $dt = Carbon::create($model->approved_at); + return $dt->isoFormat('D MMMM Y H:mm:ss'); + } + + return "-"; + + }) + ->addColumn('approved_by', function ($model) { + return $model->approved->name ?? ""; + }) ->addColumn('status', function ($model) { if ($model->status == 1) { return 'Approved'; } else if ($model->status == 0) { - return 'Menunggu Approval'; + return 'Menunggu Approval'; + } else if ($model->status == 3) { + return 'Rejected'; + } else if ($model->status == 4) { + return 'Approved Request Download'; + } else if ($model->status == 5) { + return 'Approved Download Approved'; + } else if ($model->status == 6) { + return 'Approved Request Delete'; + } else if ($model->status == 7) { + return 'Approved Request Delete'; + } else if ($model->status == 8) { + return 'Deleted'; + } else if ($model->status == 9) { + return 'Approved Request Non-Aktif'; } }) ->addIndexColumn() @@ -115,6 +199,8 @@ Column::make('nomor_dokumen'), Column::make('tanggal_dokumen'), Column::make('jumlah_halaman'), + Column::make('tanggal_approve'), + Column::make('approved_by'), Column::make('directorat')->title('Direktorat')->className('none'), Column::make('sub_directorat')->title('Sub Direktorat')->className('none'), Column::make('job')->title('Jenis Pekerjaan')->className('none'), @@ -127,7 +213,6 @@ Column::computed('action') ->exportable(false) ->printable(false) - ->width(60) ->addClass('text-center'), ]; } diff --git a/Database/Migrations/2023_04_17_135930_create_document_details_table.php b/Database/Migrations/2023_04_17_135930_create_document_details_table.php index c56b6c6..ba950da 100644 --- a/Database/Migrations/2023_04_17_135930_create_document_details_table.php +++ b/Database/Migrations/2023_04_17_135930_create_document_details_table.php @@ -39,14 +39,16 @@ $table->string('keterangan')->nullable(); + $table->string('aktif')->default(0)->nullable(); $table->string('status')->default(0)->nullable(); $table->timestamps(); $table->softDeletes(); - + $table->timestamp('approved_at')->nullable(); $table->unsignedBigInteger('created_by')->nullable(); $table->unsignedBigInteger('updated_by')->nullable(); $table->unsignedBigInteger('deleted_by')->nullable(); + $table->unsignedBigInteger('approved_by')->nullable(); }); } diff --git a/Entities/Document.php b/Entities/Document.php index 43293e2..a2d60ba 100644 --- a/Entities/Document.php +++ b/Entities/Document.php @@ -46,11 +46,6 @@ return $this->belongsTo(SubSubJob::class); } - public function special_code() - { - return $this->belongsTo(SpecialCode::class); - } - public function document_details() { return $this->hasMany(DocumentDetail::class); diff --git a/Entities/DocumentDetail.php b/Entities/DocumentDetail.php index c7e1fb7..8a6f9ad 100644 --- a/Entities/DocumentDetail.php +++ b/Entities/DocumentDetail.php @@ -2,6 +2,8 @@ namespace Modules\Cetaklabel\Entities; + use Modules\Usermanager\Entities\User; + class DocumentDetail extends BaseModel { protected $fillable = [ @@ -27,7 +29,10 @@ 'no_urut', 'kategori', 'keterangan', - 'status' + 'status', + 'approved_by', + 'approved_at', + 'aktif' ]; public function document() @@ -39,4 +44,14 @@ { return $this->belongsTo(DocumentType::class); } + + public function special_code() + { + return $this->belongsTo(SpecialCode::class); + } + + public function approved(){ + return $this->belongsTo(User::class, 'approved_by'); + } + } diff --git a/Http/Controllers/DocumentController.php b/Http/Controllers/DocumentController.php index 57665ad..f31670f 100644 --- a/Http/Controllers/DocumentController.php +++ b/Http/Controllers/DocumentController.php @@ -9,6 +9,7 @@ use Haruncpi\LaravelIdGenerator\IdGenerator; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; + use Illuminate\Support\Facades\View; use Modules\Cetaklabel\DataTables\DocumentDataTable; use Modules\Cetaklabel\Entities\Directorat; use Modules\Cetaklabel\Entities\Document; @@ -22,6 +23,13 @@ use Modules\Cetaklabel\Http\Requests\Document\StoreDocumentRequest; use Modules\Cetaklabel\Http\Requests\Document\UpdateDocumentRequest; use Response; + // Reference the Dompdf namespace + use Dompdf\Dompdf; +// Reference the Options namespace + use Dompdf\Options; +// Reference the Font Metrics namespace + use Dompdf\FontMetrics; + class DocumentController extends Controller { @@ -169,49 +177,45 @@ */ public function edit($id) { - if (is_null($this->user) || !$this->user->can('document.update')) { + if (is_null($this->user) || !$this->user->hasRole('otorisator')){ abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } - $document = Document::find($id); - $directorat = Directorat::all(); - $sub_directorat = SubDirectorat::where('directorat_id', $document->directorat_id)->get(); - $job = Job::where('sub_directorat_id', $document->sub_directorat_id)->get(); - $sub_job = SubJob::where('job_id', $document->job_id)->get(); - $sub_sub_job = SubSubJob::where('sub_job_id', $document->sub_job_id)->get(); - $special_code = SpecialCode::all(); - $document_type = DocumentType::all(); + $document = DocumentDetail::with('document')->find($id); - return view('cetaklabel::app.document.edit', compact('document', 'directorat', 'sub_directorat', 'job', 'sub_job', 'sub_sub_job', 'special_code', 'document_type')); + 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')); } /** * Update the specified resource in storage. */ - public function update(UpdateDocumentRequest $request, Document $documents) + public function update(Request $request) { - if (is_null($this->user) || !$this->user->can('document.update')) { + if (is_null($this->user) || !$this->user->hasRole('otorisator')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } - // Validate the request... - $validated = $request->validated(); + try { + $data = [ + '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); - // Update the Document... - if ($validated) { - try { - $document = Document::find($request->id); - $update = $document->update($validated); - - - return redirect()->route('document.index')->with('success', 'Document updated successfully.'); - } catch (Exception $e) { - return redirect()->route('document.index')->with('error', 'Document updated failed.'); - } + echo json_encode(['status' => 'success', 'message' => 'Document updated successfully.']); + } catch (Exception $e) { + echo json_encode(['status' => 'error', 'message' => 'Document updated failed.']); } - - return false; } /** @@ -236,14 +240,48 @@ 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->update(['status' => '4']); + echo json_encode(['status' => 'success', 'message' => 'Document menunggu Approval untuk di Cetak.']); + return; + } - $filepath = public_path($document->file); - return Response::download($filepath); + if($document->status == 4){ + $document->update(['status' => '5']); + echo json_encode(['status' => 'success', 'message' => 'Approval Berhasil.']); + return; + } + + if($document->status == 5){ + $document->update(['status' => '1']); + $document->save(); + $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 label(Request $request) @@ -266,7 +304,16 @@ $last = Carbon::create($last); $last = $last->isoFormat('DD MMMM Y'); + activity() + ->performedOn($document) + ->location('id') + ->causedBy(Auth::user()) + ->withProperties($document) + ->log('Cetak Label Dus'); + return view('cetaklabel::app.document.label', compact('document_detail', 'start', 'last', 'document')); + + } public function odner(Request $request) @@ -289,6 +336,13 @@ $last = Carbon::create($last); $last = $last->isoFormat('DD MMMM Y'); + activity() + ->performedOn($document) + ->location('id') + ->causedBy(Auth::user()) + ->withProperties($document) + ->log('Cetak Label Odner'); + return view('cetaklabel::app.document.odner', compact('document_detail', 'start', 'last', 'document')); } } diff --git a/Http/Controllers/SettingsController.php b/Http/Controllers/SettingsController.php index 6abcec3..583a8fc 100644 --- a/Http/Controllers/SettingsController.php +++ b/Http/Controllers/SettingsController.php @@ -6,6 +6,9 @@ use Illuminate\Contracts\Support\Renderable; use Illuminate\Http\Request; use Illuminate\Routing\Controller; + use Illuminate\Support\Facades\Auth; + use Modules\Cetaklabel\Entities\Document; + use Modules\Cetaklabel\Entities\DocumentDetail; class SettingsController extends Controller { diff --git a/Http/Requests/Document/StoreDocumentRequest.php b/Http/Requests/Document/StoreDocumentRequest.php index bdfed6a..7bc00ef 100644 --- a/Http/Requests/Document/StoreDocumentRequest.php +++ b/Http/Requests/Document/StoreDocumentRequest.php @@ -106,7 +106,7 @@ if($sum_halaman_document < Setting::get('maximal_halaman_per_dus')){ if(($sum_halaman_document + $this->jumlah_halaman) >= Setting::get('maximal_halaman_per_dus')){ - $sequence_odner += $this->sequence; + $sequence_odner += 1; } else { $sequence_odner = $this->sequence; } @@ -115,10 +115,10 @@ $sum_halaman_document = $this->sumHalaman($prefix,$i,$sequence_dus); if($sum_halaman_document < Setting::get('maximal_halaman_per_odner')){ if(($sum_halaman_document + $this->jumlah_halaman) >= Setting::get('maximal_halaman_per_odner')){ - $sequence_odner += $i; + $sequence_odner = $i + 1; break; } else { - $sequence_odner = $i; + $sequence_odner = $this->sequence; break; } } diff --git a/Resources/views/app/document/_action.blade.php b/Resources/views/app/document/_action.blade.php index 5f1c1bb..e4132e1 100644 --- a/Resources/views/app/document/_action.blade.php +++ b/Resources/views/app/document/_action.blade.php @@ -2,30 +2,64 @@ $route = explode('.', Route::currentRouteName()); @endphp