From 734fdd03257aaf870cd1fc3b9e47f391b5eb9885 Mon Sep 17 00:00:00 2001 From: Gunawan19621 Date: Mon, 20 Nov 2023 08:26:27 +0700 Subject: [PATCH 1/2] update disposal --- app/Http/Controllers/DisposalController.php | 72 +++++++---- app/Http/Controllers/HomeController.php | 42 ++++++- .../Disposal/ValidasiCreateDisposal.php | 43 +++++++ .../Disposal/ValidasiUpdateDisposal.php | 28 +++++ app/Models/Disposal.php | 46 +++++++ ...23_11_17_075418_create_disposals_table.php | 36 ++++++ .../views/dashboard/Disposal/create.blade.php | 58 +++++++-- .../views/dashboard/Disposal/edit.blade.php | 118 +++++++++++++++++- .../views/dashboard/Disposal/index.blade.php | 77 +++++++----- resources/views/dashboard/index.blade.php | 98 +++++++++++---- resources/views/layouts/sidebar.blade.php | 8 +- routes/web.php | 4 +- 12 files changed, 532 insertions(+), 98 deletions(-) create mode 100644 app/Http/Requests/Disposal/ValidasiCreateDisposal.php create mode 100644 app/Http/Requests/Disposal/ValidasiUpdateDisposal.php create mode 100644 app/Models/Disposal.php create mode 100644 database/migrations/2023_11_17_075418_create_disposals_table.php diff --git a/app/Http/Controllers/DisposalController.php b/app/Http/Controllers/DisposalController.php index b1850e4..7cb9662 100644 --- a/app/Http/Controllers/DisposalController.php +++ b/app/Http/Controllers/DisposalController.php @@ -3,14 +3,19 @@ namespace App\Http\Controllers; use App\Models\Peti; +use App\Models\Customer; use App\Models\m_warehouse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; +use App\Http\Requests\Disposal\ValidasiCreateDisposal; +use App\Models\Disposal; class DisposalController extends Controller { public function index() { $data = [ + 'disposal' => Disposal::all(), 'active' => 'menu-disposal', ]; return view('dashboard.Disposal.index', $data); @@ -25,6 +30,7 @@ class DisposalController extends Controller $data = [ 'peti' => Peti::get(), 'warehouse' => m_warehouse::get(), + 'customer' => Customer::get(), 'active' => 'menu-disposal', ]; return view('dashboard.Disposal.create', $data); @@ -33,52 +39,76 @@ class DisposalController extends Controller /** * Store a newly created resource in storage. */ - public function store($request) + public function store(ValidasiCreateDisposal $request) { - // + // dd($request->all()); + try { + // Mendapatkan informasi pengguna yang sedang login + $currentUser = Auth::user(); + + // Validasi data dari request + $validatedData = $request->validated(); + + // Menambahkan informasi pengguna ke dalam data yang akan disimpan + $validatedData['created_by'] = $currentUser->fullname; + $validatedData['updated_by'] = $currentUser->fullname; + + // Membuat entitas Transfer + Disposal::create($validatedData); + + return redirect()->route('dashboard.disposal.index')->with('success', 'Data Disposal Peti berhasil ditambahkan'); + } catch (\Throwable $th) { + return redirect()->back()->with('error', 'Data Disposal Peti gagal dimasukan ke disposal'); + } } /** * Display the specified resource. */ - public function show($id) - { - $data = [ - 'active' => 'menu-disposal', - ]; - return view('dashboard.Disposal.show', $data); - } + // public function show($id) + // { + // $data = [ + // 'active' => 'menu-disposal', + // ]; + // return view('dashboard.Disposal.show', $data); + // } /** * Show the form for editing the specified resource. */ public function edit($id) { + $jenis_disposal = ['Pemusnaan', 'Perbaikan']; $data = [ + 'disposal' => Disposal::findOrFail($id), + 'peti' => Peti::get(), + 'customer' => Customer::get(), + 'warehouse' => m_warehouse::get(), 'active' => 'menu-disposal', ]; - return view('dashboard.Disposal.edit', $data); + return view('dashboard.Disposal.edit', compact('jenis_disposal'), $data); } /** * Update the specified resource in storage. */ - public function update($request, $id) - { - // - } + // public function update($request, $id) + // { + // // + // } /** * Remove the specified resource from storage. */ public function destroy($id) { - // try { - // $typepeti = Peti::findOrFail($id); - // $typepeti->delete(); - // return redirect()->back()->with('success', 'Data peti berhasil dihapus'); - // } catch (\Throwable $th) { - // return redirect()->back()->with('error', 'Data peti gagal dihapus'); - // } + // dd("oke"); + try { + $disposal = Disposal::findOrFail($id); + $disposal->delete(); + return redirect()->back()->with('success', 'Data disposal peti berhasil dihapus'); + } catch (\Throwable $th) { + return redirect()->back()->with('error', 'Data disposal peti gagal dihapus'); + } } } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index f6a32ad..f612ab9 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -24,7 +24,6 @@ class HomeController extends Controller { $data = [ 'reminder' => \App\Models\asset_status::whereNull('enter_at')->count(), - 'jumlahAsset' => \App\Models\m_asset::count(), 'jumlahPeminjaman' => \App\Models\asset_status::count(), 'jumlahPengembalian' => \App\Models\asset_status::whereNotNull('enter_at')->count(), 'active' => 'menu-user', @@ -32,6 +31,8 @@ class HomeController extends Controller return view('pages.user.index', $data); } + + //data pertahun untuk bar chart public function generateChartData() { $years = []; @@ -86,4 +87,43 @@ class HomeController extends Controller return compact('years', 'exitData', 'enterData', 'monthNames'); } + + public function generateChartDataPie() + { + $years = []; + $enterData = []; + $monthNames = [ + 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', + 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember' + ]; + + // Ambil data tahun dari kolom date_pembuatan + $enterYears = \App\Models\Peti::selectRaw('YEAR(date_pembuatan) as year') + ->distinct() + ->orderBy('year', 'asc') + ->get() + ->pluck('year') + ->toArray(); + + // Gabungkan dan sortir tahun-tahun dari kolom date_pembuatan + $years = array_unique($enterYears); + sort($years); + + foreach ($years as $year) { + $yearEnterData = []; + + // Ambil data untuk setiap bulan dalam tahun tersebut + foreach ($monthNames as $monthName) { + $enterCount = \App\Models\Peti::whereYear('date_pembuatan', $year) + ->whereMonth('date_pembuatan', array_search($monthName, $monthNames) + 1) + ->count(); + + $yearEnterData[] = $enterCount; + } + + $enterData[] = $yearEnterData; + } + + return compact('years', 'enterData', 'monthNames'); + } } diff --git a/app/Http/Requests/Disposal/ValidasiCreateDisposal.php b/app/Http/Requests/Disposal/ValidasiCreateDisposal.php new file mode 100644 index 0000000..77429c6 --- /dev/null +++ b/app/Http/Requests/Disposal/ValidasiCreateDisposal.php @@ -0,0 +1,43 @@ +|string> + */ + public function rules(): array + { + return [ + 'peti_id' => 'nullable', + 'customer_id' => 'nullable', + 'warehouse_id' => 'nullable', + 'date_disposal' => 'nullable|date', + 'description' => 'nullable|string', + 'jenis_disposal' => 'nullable|string|max:50', + ]; + } + + public function messages(): array + { + return [ + 'date_disposal.date' => 'Format tanggal disposal tidak valid.', + 'description.string' => 'Deskripsi harus berupa teks.', + 'jenis_disposal.string' => 'Jenis disposal harus berupa teks.', + 'jenis_disposal.max' => 'Jenis disposal tidak boleh lebih dari :max karakter.', + ]; + } +} diff --git a/app/Http/Requests/Disposal/ValidasiUpdateDisposal.php b/app/Http/Requests/Disposal/ValidasiUpdateDisposal.php new file mode 100644 index 0000000..66e086d --- /dev/null +++ b/app/Http/Requests/Disposal/ValidasiUpdateDisposal.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + // + ]; + } +} diff --git a/app/Models/Disposal.php b/app/Models/Disposal.php new file mode 100644 index 0000000..bc463cd --- /dev/null +++ b/app/Models/Disposal.php @@ -0,0 +1,46 @@ +belongsTo(Peti::class, 'peti_id')->select( + 'id', + 'tipe_peti_id', + 'customer_id', + 'warehouse_id', + 'date_pembuatan', + 'kondisipeti_id', + 'fix_lot', + 'updated_by', + ); + } + public function customer() + { + return $this->belongsTo(Customer::class, 'customer_id')->select( + 'name', + 'code_customer', + ); + } +} diff --git a/database/migrations/2023_11_17_075418_create_disposals_table.php b/database/migrations/2023_11_17_075418_create_disposals_table.php new file mode 100644 index 0000000..f734f9b --- /dev/null +++ b/database/migrations/2023_11_17_075418_create_disposals_table.php @@ -0,0 +1,36 @@ +uuid('id')->primary(); + $table->foreignUuid('peti_id')->nullable()->constrained('petis')->onDelete('set null'); + $table->foreignUuid('customer_id')->nullable()->constrained('customers'); + $table->foreignUuid('warehouse_id')->nullable()->constrained('m_warehouses'); + $table->date('date_disposal')->nullable(); + $table->text('description')->nullable(); + $table->string('jenis_disposal', 50)->nullable(); + $table->timestamps(); + $table->softDeletes(); + $table->string('created_by', 200)->nullable(); + $table->string('updated_by', 200)->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('disposals'); + } +}; diff --git a/resources/views/dashboard/Disposal/create.blade.php b/resources/views/dashboard/Disposal/create.blade.php index 3b57099..5bd4587 100644 --- a/resources/views/dashboard/Disposal/create.blade.php +++ b/resources/views/dashboard/Disposal/create.blade.php @@ -10,8 +10,8 @@
-
+ @csrf
- + {{--
@@ -61,43 +61,54 @@ - {{-- @php - $no_peminjaman = 1; + +
No
--}} + + + + + + + + + + + + + + @php + $nodisposal = 1; @endphp - @forelse ($peminjaman as $data_peminjaman) - @if ($data_peminjaman->enter_warehouse == null) - - - - - - - - - - - @endif + @forelse ($disposal as $data_disposal) + + + + + + + + + @empty

Data Kosong

- @endforelse --}} + @endforelse
NoKode PetiNama CustomerTanggal DisposalAlasan DisposalJenis DisposalAction
{{ $no_peminjaman++ }}{{ $data_peminjaman->peti->fix_lot }}{{ $data_peminjaman->peti->customer->name }}{{ $data_peminjaman->peti->customer->code_customer }} - - {{ $data_peminjaman->peti->tipe_peti->type }}{{ \Carbon\Carbon::parse($data_peminjaman->exit_at)->format('d/m/Y') }}{{ $data_peminjaman->exit_pic }}{{ $data_peminjaman->warehouse->name }} - - - -
- @csrf - @method('DELETE') - -
-
{{ $nodisposal++ }}{{ $data_disposal->peti->fix_lot }}{{ $data_disposal->customer->name }}{{ \Carbon\Carbon::parse($data_disposal->date_disposal)->format('d/m/Y') }}{{ $data_disposal->description }}{{ $data_disposal->jenis_disposal }} + + + +
+ @csrf + @method('DELETE') + +
+
+
diff --git a/resources/views/dashboard/index.blade.php b/resources/views/dashboard/index.blade.php index a8970f9..564d641 100644 --- a/resources/views/dashboard/index.blade.php +++ b/resources/views/dashboard/index.blade.php @@ -87,7 +87,7 @@ -
+ {{--
Grafik Peminjaman VS Pengembalian
@@ -105,12 +105,35 @@ @endforeach - +
+
--}} +
+
+
+
Grafik Peminjaman VS Pengembalian
+
+ @php + $chartData = app('App\Http\Controllers\HomeController')->generateChartData(); + @endphp +
+ + + + +
+
+
@@ -118,11 +141,21 @@
Grafik Pengadaan Peti
- + @php + $chartDataPie = app('App\Http\Controllers\HomeController')->generateChartDataPie(); + @endphp +
-
- -
+ + + +
@@ -132,41 +165,51 @@ +