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 @@