2023-05-15 10:03:46 +00:00
|
|
|
<?php
|
|
|
|
|
2023-05-20 14:09:49 +00:00
|
|
|
namespace Modules\Cetaklabel\Http\Controllers;
|
2023-05-15 10:03:46 +00:00
|
|
|
|
2023-05-25 08:07:59 +00:00
|
|
|
use anlutro\LaravelSettings\Facades\Setting;
|
2023-05-15 10:03:46 +00:00
|
|
|
use App\Http\Controllers\Controller;
|
2023-05-25 01:53:06 +00:00
|
|
|
use Carbon\Carbon;
|
2023-05-15 10:03:46 +00:00
|
|
|
use Exception;
|
2023-05-25 01:53:06 +00:00
|
|
|
use Haruncpi\LaravelIdGenerator\IdGenerator;
|
2023-05-15 10:03:46 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
2023-05-26 02:31:37 +00:00
|
|
|
use Illuminate\Support\Facades\View;
|
2023-05-20 14:09:49 +00:00
|
|
|
use Modules\Cetaklabel\DataTables\DocumentDataTable;
|
|
|
|
use Modules\Cetaklabel\Entities\Directorat;
|
|
|
|
use Modules\Cetaklabel\Entities\Document;
|
|
|
|
use Modules\Cetaklabel\Entities\DocumentDetail;
|
|
|
|
use Modules\Cetaklabel\Entities\DocumentType;
|
|
|
|
use Modules\Cetaklabel\Entities\Job;
|
|
|
|
use Modules\Cetaklabel\Entities\SpecialCode;
|
|
|
|
use Modules\Cetaklabel\Entities\SubDirectorat;
|
|
|
|
use Modules\Cetaklabel\Entities\SubJob;
|
|
|
|
use Modules\Cetaklabel\Entities\SubSubJob;
|
|
|
|
use Modules\Cetaklabel\Http\Requests\Document\StoreDocumentRequest;
|
|
|
|
use Modules\Cetaklabel\Http\Requests\Document\UpdateDocumentRequest;
|
2023-05-25 01:53:06 +00:00
|
|
|
use Response;
|
2023-05-26 02:31:37 +00:00
|
|
|
// Reference the Dompdf namespace
|
|
|
|
use Dompdf\Dompdf;
|
|
|
|
// Reference the Options namespace
|
|
|
|
use Dompdf\Options;
|
|
|
|
// Reference the Font Metrics namespace
|
|
|
|
use Dompdf\FontMetrics;
|
|
|
|
|
2023-05-15 10:03:46 +00:00
|
|
|
|
|
|
|
class DocumentController extends Controller
|
|
|
|
{
|
|
|
|
public $user;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware(function ($request, $next) {
|
|
|
|
$this->user = Auth::guard('web')->user();
|
|
|
|
return $next($request);
|
|
|
|
});
|
|
|
|
|
2023-05-23 02:31:03 +00:00
|
|
|
addVendor('chained-select');
|
|
|
|
|
2023-05-15 10:03:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*/
|
|
|
|
public function index(DocumentDataTable $dataTable)
|
|
|
|
{
|
2023-05-23 02:31:03 +00:00
|
|
|
if (is_null($this->user) || !$this->user->can('document.read')) {
|
2023-05-15 10:03:46 +00:00
|
|
|
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)
|
|
|
|
{
|
2023-05-23 02:31:03 +00:00
|
|
|
if (is_null($this->user) || !$this->user->can('document.create')) {
|
2023-05-15 10:03:46 +00:00
|
|
|
abort(403, 'Sorry !! You are Unauthorized to create any master data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate the request...
|
|
|
|
$validated = $request->validated();
|
|
|
|
|
|
|
|
// Store the Document...
|
|
|
|
if ($validated) {
|
2023-05-23 02:31:03 +00:00
|
|
|
|
2023-05-15 10:03:46 +00:00
|
|
|
try {
|
2023-05-25 08:07:59 +00:00
|
|
|
$document = Document::where(['kode_odner' => $validated['kode_odner'],
|
|
|
|
'sequence_odner' => $validated['sequence_odner']
|
|
|
|
])->first();
|
2023-05-25 04:55:53 +00:00
|
|
|
|
2023-05-25 08:07:59 +00:00
|
|
|
if ($document) {
|
2023-05-25 04:55:53 +00:00
|
|
|
$document->update($validated);
|
|
|
|
} else {
|
|
|
|
$document = Document::create($validated);
|
|
|
|
}
|
2023-05-23 11:18:33 +00:00
|
|
|
|
2023-05-25 04:55:53 +00:00
|
|
|
$created = Document::find($document->id);
|
|
|
|
|
2023-05-25 08:07:59 +00:00
|
|
|
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();
|
2023-05-23 11:18:33 +00:00
|
|
|
|
2023-05-25 08:07:59 +00:00
|
|
|
if ($file->move(public_path($path), $filename)) {
|
|
|
|
$request['file'] = $path . '/' . $filename;
|
2023-05-23 11:18:33 +00:00
|
|
|
}
|
2023-05-15 10:03:46 +00:00
|
|
|
}
|
|
|
|
|
2023-05-25 08:07:59 +00:00
|
|
|
$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);
|
|
|
|
|
|
|
|
|
2023-05-15 10:03:46 +00:00
|
|
|
return redirect()->route('document.index')->with('success', 'Document created successfully.');
|
|
|
|
} catch (Exception $e) {
|
2023-05-25 01:53:06 +00:00
|
|
|
|
|
|
|
return redirect()->route('document.index')->with('error', 'Document created failed, ' . $e->getMessage());
|
2023-05-15 10:03:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2023-05-23 02:31:03 +00:00
|
|
|
if (is_null($this->user) || !$this->user->can('document.create')) {
|
2023-05-15 10:03:46 +00:00
|
|
|
abort(403, 'Sorry !! You are Unauthorized to create any master data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
$directorat = Directorat::all();
|
|
|
|
$special_code = SpecialCode::all();
|
|
|
|
$document_type = DocumentType::all();
|
2023-05-25 08:07:59 +00:00
|
|
|
$setting = Setting::all();
|
|
|
|
return view('cetaklabel::app.document.create', compact('directorat', 'special_code', 'document_type','setting'));
|
2023-05-15 10:03:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*/
|
|
|
|
public function show(Document $documents)
|
|
|
|
{
|
2023-05-23 02:31:03 +00:00
|
|
|
if (is_null($this->user) || !$this->user->can('document.read')) {
|
2023-05-15 10:03:46 +00:00
|
|
|
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)
|
|
|
|
{
|
2023-05-26 02:31:37 +00:00
|
|
|
if (is_null($this->user) || !$this->user->hasRole('otorisator')){
|
2023-05-15 10:03:46 +00:00
|
|
|
abort(403, 'Sorry !! You are Unauthorized to update any master data !');
|
|
|
|
}
|
|
|
|
|
2023-05-26 02:31:37 +00:00
|
|
|
$document = DocumentDetail::with('document')->find($id);
|
|
|
|
|
|
|
|
if ($document->status != '0') {
|
|
|
|
abort(403, 'Sorry !! This Document has been authorized !');
|
|
|
|
}
|
2023-05-15 10:03:46 +00:00
|
|
|
|
2023-05-26 02:31:37 +00:00
|
|
|
$document = DocumentDetail::with('document')->find($id);
|
|
|
|
|
|
|
|
return view('cetaklabel::app.document.edit', compact('document'));
|
2023-05-15 10:03:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*/
|
2023-05-26 02:31:37 +00:00
|
|
|
public function update(Request $request)
|
2023-05-15 10:03:46 +00:00
|
|
|
{
|
2023-05-26 02:31:37 +00:00
|
|
|
if (is_null($this->user) || !$this->user->hasRole('otorisator')) {
|
2023-05-15 10:03:46 +00:00
|
|
|
abort(403, 'Sorry !! You are Unauthorized to update any master data !');
|
|
|
|
}
|
|
|
|
|
2023-05-26 02:31:37 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Document updated successfully.']);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Document updated failed.']);
|
2023-05-15 10:03:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*/
|
|
|
|
public function destroy(Request $request)
|
|
|
|
{
|
2023-05-23 02:31:03 +00:00
|
|
|
if (is_null($this->user) || !$this->user->can('document.delete')) {
|
2023-05-15 10:03:46 +00:00
|
|
|
abort(403, 'Sorry !! You are Unauthorized to delete any master data !');
|
|
|
|
}
|
|
|
|
|
2023-05-25 01:53:06 +00:00
|
|
|
// Delete Detail Document First...
|
|
|
|
$document_details = DocumentDetail::where('document_id', $request->document)->get();
|
|
|
|
if ($document_details->count() > 0) {
|
|
|
|
foreach ($document_details as $document_detail) {
|
|
|
|
$document_detail->delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-15 10:03:46 +00:00
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Document deleted successfully.']);
|
|
|
|
}
|
2023-05-25 01:53:06 +00:00
|
|
|
|
|
|
|
public function download(Request $request)
|
|
|
|
{
|
2023-05-26 02:31:37 +00:00
|
|
|
|
2023-05-25 01:53:06 +00:00
|
|
|
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);
|
2023-05-26 02:31:37 +00:00
|
|
|
if($document->status == 1){
|
|
|
|
$document->update(['status' => '4']);
|
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Document menunggu Approval untuk di Cetak.']);
|
|
|
|
return;
|
|
|
|
}
|
2023-05-25 01:53:06 +00:00
|
|
|
|
2023-05-26 02:31:37 +00:00
|
|
|
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;
|
|
|
|
}
|
2023-05-25 01:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function label(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);
|
2023-05-25 08:07:59 +00:00
|
|
|
$document = Document::with(['document_details'])->where(['kode_dus' => $document_detail->document->kode_dus,
|
|
|
|
'sequence_dus' => $document_detail->document->sequence_dus
|
|
|
|
])->first();
|
2023-05-25 01:53:06 +00:00
|
|
|
|
2023-05-25 08:07:59 +00:00
|
|
|
$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;
|
2023-05-25 01:53:06 +00:00
|
|
|
|
|
|
|
$start = Carbon::create($start);
|
|
|
|
$start = $start->isoFormat('DD MMMM Y');
|
|
|
|
|
|
|
|
$last = Carbon::create($last);
|
|
|
|
$last = $last->isoFormat('DD MMMM Y');
|
|
|
|
|
2023-05-26 02:31:37 +00:00
|
|
|
activity()
|
|
|
|
->performedOn($document)
|
|
|
|
->location('id')
|
|
|
|
->causedBy(Auth::user())
|
|
|
|
->withProperties($document)
|
|
|
|
->log('Cetak Label Dus');
|
|
|
|
|
2023-05-25 01:53:06 +00:00
|
|
|
return view('cetaklabel::app.document.label', compact('document_detail', 'start', 'last', 'document'));
|
2023-05-26 02:31:37 +00:00
|
|
|
|
|
|
|
|
2023-05-25 01:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2023-05-25 08:07:59 +00:00
|
|
|
$document = Document::with(['document_details'])->where(['kode_odner' => $document_detail->document->kode_odner,
|
|
|
|
'sequence_odner' => $document_detail->document->sequence_odner
|
|
|
|
])->first();
|
2023-05-25 01:53:06 +00:00
|
|
|
|
2023-05-25 08:07:59 +00:00
|
|
|
$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;
|
2023-05-25 01:53:06 +00:00
|
|
|
|
|
|
|
$start = Carbon::create($start);
|
|
|
|
$start = $start->isoFormat('DD MMMM Y');
|
|
|
|
|
|
|
|
$last = Carbon::create($last);
|
|
|
|
$last = $last->isoFormat('DD MMMM Y');
|
|
|
|
|
2023-05-26 02:31:37 +00:00
|
|
|
activity()
|
|
|
|
->performedOn($document)
|
|
|
|
->location('id')
|
|
|
|
->causedBy(Auth::user())
|
|
|
|
->withProperties($document)
|
|
|
|
->log('Cetak Label Odner');
|
|
|
|
|
2023-05-25 01:53:06 +00:00
|
|
|
return view('cetaklabel::app.document.odner', compact('document_detail', 'start', 'last', 'document'));
|
|
|
|
}
|
2023-05-15 10:03:46 +00:00
|
|
|
}
|