diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index cbb3849..95422cd 100644 --- a/app/Http/Controllers/CustomerController.php +++ b/app/Http/Controllers/CustomerController.php @@ -18,7 +18,7 @@ class CustomerController extends Controller public function index() { $data = [ - 'customer' => Customer::all(), + 'customer' => Customer::orderBy('created_at', 'desc')->get(), 'active' => 'menu-customer', ]; return view('dashboard.Master_Data.Customer.index', $data); diff --git a/app/Http/Controllers/DisposalController.php b/app/Http/Controllers/DisposalController.php index b1850e4..6915ba1 100644 --- a/app/Http/Controllers/DisposalController.php +++ b/app/Http/Controllers/DisposalController.php @@ -3,14 +3,21 @@ namespace App\Http\Controllers; use App\Models\Peti; +use App\Models\Customer; +use App\Models\Disposal; use App\Models\m_warehouse; use Illuminate\Http\Request; +use Symfony\Component\Uid\Uuid; +use Illuminate\Support\Facades\Auth; +use App\Http\Requests\Disposal\ValidasiCreateDisposal; +use App\Http\Requests\Disposal\ValidasiUpdateDisposal; class DisposalController extends Controller { public function index() { $data = [ + 'disposal' => Disposal::orderBy('created_at', 'desc')->get(), 'active' => 'menu-disposal', ]; return view('dashboard.Disposal.index', $data); @@ -25,6 +32,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,39 +41,100 @@ class DisposalController extends Controller /** * Store a newly created resource in storage. */ - public function store($request) + public function store(ValidasiCreateDisposal $request) { - // + // dd($request->all()); + // dd($request); + 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['mobile_id'] = Uuid::v4(); // Menambahkan ID Mobile + $validatedData['created_by'] = $currentUser->fullname; + $validatedData['updated_by'] = $currentUser->fullname; + + // Membuat entitas Disposal + $disposal = Disposal::create($validatedData); + + // Mengupdate warehouse_id pada model Peti + Peti::where('id', $disposal->peti_id) + ->update([ + 'status' => $disposal->status_disposal, + ]); + + 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(ValidasiUpdateDisposal $request, $id) { - // + // dd("oke"); + 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['updated_by'] = $currentUser->fullname; + + // Mencari transfer berdasarkan ID + $disposal = Disposal::find($id); + + if (!$disposal) { + return redirect()->route('dashboard.disposal.index')->with('error', 'Data Disposal Peti tidak ditemukan'); + } + + // Memperbarui data transfer + $disposal->update($validatedData); + + // Mengupdate warehouse_id pada model Peti + Peti::where('id', $disposal->peti_id) + ->update([ + 'status' => $disposal->status_disposal, + ]); + + return redirect()->route('dashboard.disposal.index')->with('success', 'Data Disposal Peti berhasil diperbaharui'); + } catch (\Throwable $th) { + return redirect()->back()->with('error', 'Data Disposal Peti gagal diperbaharui'); + } } /** @@ -73,12 +142,13 @@ class DisposalController extends Controller */ 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/Controllers/KondisiPetiController.php b/app/Http/Controllers/KondisiPetiController.php index bb2e4ff..76a341a 100644 --- a/app/Http/Controllers/KondisiPetiController.php +++ b/app/Http/Controllers/KondisiPetiController.php @@ -13,7 +13,7 @@ class KondisiPetiController extends Controller public function index() { $data = [ - 'kondisiPeti' => Kondisi_Peti::all(), + 'kondisiPeti' => Kondisi_Peti::orderBy('created_at', 'desc')->get(), 'active' => 'menu-kondisipeti' ]; return view('dashboard.Master_Data.Manajemen_Peti.Kondisi_Peti.index', $data); diff --git a/app/Http/Controllers/M_userController.php b/app/Http/Controllers/M_userController.php index 9d39ad3..01ce030 100644 --- a/app/Http/Controllers/M_userController.php +++ b/app/Http/Controllers/M_userController.php @@ -17,9 +17,9 @@ class M_userController extends Controller public function index() { $data = [ + 'user' => User::orderBy('created_at', 'desc')->get(), 'warehouse' => m_warehouse::get(), 'role' => m_role::get(), - 'user' => User::get(), 'active' => 'menu-user', ]; return view('dashboard.Master_Data.User.index', $data); diff --git a/app/Http/Controllers/PeminjamanController.php b/app/Http/Controllers/PeminjamanController.php index c5d4e46..64871ec 100644 --- a/app/Http/Controllers/PeminjamanController.php +++ b/app/Http/Controllers/PeminjamanController.php @@ -5,12 +5,10 @@ namespace App\Http\Controllers; use App\Http\Requests\ValidasiCreatePeminjaman; use App\Http\Requests\ValidasiUpdatePeminjaman; use App\Models\Peti; -use App\Models\m_asset; use App\Models\m_warehouse; use App\Models\asset_status; -use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; -use SimpleSoftwareIO\QrCode\Facades\QrCode; +use Symfony\Component\Uid\Uuid; class PeminjamanController extends Controller { @@ -22,7 +20,7 @@ class PeminjamanController extends Controller $data = [ // 'peminjaman' => asset_status::get(), - 'peminjaman' => asset_status::get(), + 'peminjaman' => asset_status::orderBy('created_at', 'desc')->get(), 'warehouse' => m_warehouse::get(), 'active' => 'menu-peminjaman', ]; @@ -39,7 +37,10 @@ class PeminjamanController extends Controller 'peti' => Peti::all(), 'peminjaman' => asset_status::get(), 'warehouse' => m_warehouse::get(), - 'peti_block' => Peti::whereNotIn('id', asset_status::pluck('peti_id')->toArray())->get(), + 'peti_block' => Peti::whereNotIn('id', asset_status::where('status', 0)->pluck('peti_id')->toArray()) + ->where('status', 'AKTIF') // Sesuaikan dengan nama kolom yang benar + ->get(), + 'existingPeti' => asset_status::pluck('peti_id')->toArray(), 'active' => 'menu-peminjaman', ]; @@ -56,8 +57,10 @@ class PeminjamanController extends Controller $validatedData = $request->except('_token'); $validatedData['exit_pic'] = $currentUser->fullname; // Menambahkan ID pengguna sebagai created_by + $validatedData['mobile_id'] = Uuid::v4(); // Menambahkan ID Mobile $validatedData['created_by'] = $currentUser->fullname; // Menambahkan ID pengguna sebagai created_by $validatedData['updated_by'] = $currentUser->fullname; // Menambahkan ID pengguna sebagai updated_by + // dd($validatedData); asset_status::create($validatedData); return redirect()->route('dashboard.peminjaman.index')->with('success', 'Data peminjaman berhasil ditambah.'); diff --git a/app/Http/Controllers/PengembalianController.php b/app/Http/Controllers/PengembalianController.php index 3b8f037..0838a58 100644 --- a/app/Http/Controllers/PengembalianController.php +++ b/app/Http/Controllers/PengembalianController.php @@ -14,7 +14,7 @@ class PengembalianController extends Controller public function index() { $data = [ - 'peminjaman' => asset_status::all(), + 'peminjaman' => asset_status::orderBy('created_at', 'desc')->get(), 'active' => 'menu-pengembalian', ]; return view('dashboard.Pengembalian.index', $data); @@ -76,7 +76,9 @@ class PengembalianController extends Controller $peminjaman->enter_at = $request->input('enter_at'); $peminjaman->enter_warehouse = $request->input('enter_warehouse'); $peminjaman->kondisi_peti = $request->input('kondisi_peti'); - + // Mengatur status menjadi 0 secara otomatis + $peminjaman->status = 0; + // dd($peminjaman); $peminjaman->save(); return redirect()->route('dashboard.pengembalian.index')->with('success', 'Data peminjaman berhasil diperbaharui'); diff --git a/app/Http/Controllers/PetiController.php b/app/Http/Controllers/PetiController.php index 47775ea..8b9aaba 100644 --- a/app/Http/Controllers/PetiController.php +++ b/app/Http/Controllers/PetiController.php @@ -24,8 +24,8 @@ class PetiController extends Controller public function index() { $data = [ + 'peti' => Peti::orderBy('created_at', 'desc')->get(), 'kondisiPeti' => Kondisi_Peti::all(), - 'peti' => Peti::all(), 'active' => 'menu-peti', ]; return view('dashboard.Master_Data.Manajemen_Peti.Peti.index', $data); diff --git a/app/Http/Controllers/PetternLotPetiController.php b/app/Http/Controllers/PetternLotPetiController.php index f273592..852dc76 100644 --- a/app/Http/Controllers/PetternLotPetiController.php +++ b/app/Http/Controllers/PetternLotPetiController.php @@ -12,6 +12,7 @@ class PetternLotPetiController extends Controller public function index() { $data = [ + // 'warehouses' => m_warehouse::orderBy('created_at', 'desc')->get(), 'peti' => Peti::get(), 'active' => 'menu-Pettern_Lot_Peti' ]; diff --git a/app/Http/Controllers/RoleController.php b/app/Http/Controllers/RoleController.php index 6532e4a..23362b4 100644 --- a/app/Http/Controllers/RoleController.php +++ b/app/Http/Controllers/RoleController.php @@ -16,7 +16,7 @@ class RoleController extends Controller public function index() { $data = [ - 'role' => m_role::all(), + 'role' => m_role::orderBy('created_at', 'desc')->get(), 'active' => 'menu-role', ]; return view('dashboard.Master_Data.Role.index', $data); diff --git a/app/Http/Controllers/TransferController.php b/app/Http/Controllers/TransferController.php index 6e4b6a3..4c20870 100644 --- a/app/Http/Controllers/TransferController.php +++ b/app/Http/Controllers/TransferController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Models\Peti; +use Symfony\Component\Uid\Uuid; use App\Models\Customer; use App\Models\Transfer; use App\Models\m_warehouse; @@ -16,7 +17,7 @@ class TransferController extends Controller public function index() { $data = [ - 'transfer' => Transfer::all(), + 'transfer' => Transfer::orderBy('created_at', 'desc')->get(), 'active' => 'menu-transfer', ]; return view('dashboard.Transfer.index', $data); @@ -50,12 +51,13 @@ class TransferController extends Controller $validatedData = $request->validated(); // Menambahkan informasi pengguna ke dalam data yang akan disimpan + $validatedData['mobile_id'] = Uuid::v4(); // Menambahkan ID Mobile $validatedData['created_by'] = $currentUser->fullname; $validatedData['updated_by'] = $currentUser->fullname; // Membuat entitas Transfer $transfer = Transfer::create($validatedData); - + // dd($transfer); // Mengupdate warehouse_id pada model Peti Peti::where('id', $transfer->peti_id) ->update([ diff --git a/app/Http/Controllers/TypePetiController.php b/app/Http/Controllers/TypePetiController.php index 9a2c492..c3045ad 100644 --- a/app/Http/Controllers/TypePetiController.php +++ b/app/Http/Controllers/TypePetiController.php @@ -16,7 +16,7 @@ class TypePetiController extends Controller public function index() { $data = [ - 'typepeti' => Type_peti::all(), + 'typepeti' => Type_peti::orderBy('created_at', 'desc')->get(), 'active' => 'menu-typepeti', ]; return view('dashboard.Master_Data.Manajemen_Peti.Type_peti.index', $data); diff --git a/app/Http/Controllers/WarehouseController.php b/app/Http/Controllers/WarehouseController.php index 580ebd3..0c2697d 100644 --- a/app/Http/Controllers/WarehouseController.php +++ b/app/Http/Controllers/WarehouseController.php @@ -16,7 +16,7 @@ class WarehouseController extends Controller public function index() { $data = [ - 'warehouses' => m_warehouse::all(), + 'warehouses' => m_warehouse::orderBy('created_at', 'desc')->get(), 'active' => 'menu-warehouse', ]; return view('dashboard.Master_Data.Warehouse.index', $data); diff --git a/app/Http/Requests/Disposal/ValidasiCreateDisposal.php b/app/Http/Requests/Disposal/ValidasiCreateDisposal.php new file mode 100644 index 0000000..5090760 --- /dev/null +++ b/app/Http/Requests/Disposal/ValidasiCreateDisposal.php @@ -0,0 +1,41 @@ +|string> + */ + public function rules(): array + { + return [ + 'peti_id' => 'required', + 'customer_id' => 'nullable', + 'warehouse_id' => 'nullable', + 'date_disposal' => 'nullable|date', + 'description' => 'nullable|string', + 'status_disposal' => 'nullable', + ]; + } + + public function messages(): array + { + return [ + 'date_disposal.date' => 'Format tanggal disposal tidak valid.', + 'description.string' => 'Deskripsi harus berupa teks.', + ]; + } +} diff --git a/app/Http/Requests/Disposal/ValidasiUpdateDisposal.php b/app/Http/Requests/Disposal/ValidasiUpdateDisposal.php new file mode 100644 index 0000000..e400920 --- /dev/null +++ b/app/Http/Requests/Disposal/ValidasiUpdateDisposal.php @@ -0,0 +1,41 @@ +|string> + */ + public function rules(): array + { + return [ + 'peti_id' => 'required', + 'customer_id' => 'nullable', + 'warehouse_id' => 'nullable', + 'date_disposal' => 'nullable|date', + 'description' => 'nullable|string', + 'status_disposal' => 'nullable', + ]; + } + + public function messages(): array + { + return [ + 'date_disposal.date' => 'Format tanggal disposal tidak valid.', + 'description.string' => 'Deskripsi harus berupa teks.', + ]; + } +} diff --git a/app/Http/Requests/ValidasiUpdatePengembalian.php b/app/Http/Requests/ValidasiUpdatePengembalian.php index aadc956..6183ba7 100644 --- a/app/Http/Requests/ValidasiUpdatePengembalian.php +++ b/app/Http/Requests/ValidasiUpdatePengembalian.php @@ -29,6 +29,7 @@ class ValidasiUpdatePengembalian extends FormRequest 'enter_at' => 'required|date', 'enter_warehouse' => 'required', 'kondisi_peti' => 'required|string', + 'status' => '', ]; } diff --git a/app/Models/Disposal.php b/app/Models/Disposal.php new file mode 100644 index 0000000..966bf75 --- /dev/null +++ b/app/Models/Disposal.php @@ -0,0 +1,47 @@ +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/app/Models/Transfer.php b/app/Models/Transfer.php index e063ca7..2372bd2 100644 --- a/app/Models/Transfer.php +++ b/app/Models/Transfer.php @@ -14,6 +14,7 @@ class Transfer extends Model protected $table = 'transfers'; protected $fillable = [ + 'mobile_id', 'peti_id', 'source_warehouse', 'destination_warehouse', diff --git a/app/Models/asset_status.php b/app/Models/asset_status.php index 8b8f121..e5e5a66 100644 --- a/app/Models/asset_status.php +++ b/app/Models/asset_status.php @@ -15,6 +15,7 @@ class asset_status extends Model protected $table = 'asset_statuses'; protected $fillable = [ + 'mobile_id', 'peti_id', 'exit_at', 'est_pengembalian', @@ -24,6 +25,7 @@ class asset_status extends Model 'enter_pic', 'enter_warehouse', 'kondisi_peti', + 'status', 'created_by', 'updated_by', ]; diff --git a/database/migrations/2023_11_06_085238_create_petis_table.php b/database/migrations/2023_11_06_085238_create_petis_table.php index e43e795..4532dc4 100644 --- a/database/migrations/2023_11_06_085238_create_petis_table.php +++ b/database/migrations/2023_11_06_085238_create_petis_table.php @@ -23,6 +23,7 @@ return new class extends Migration $table->date('date_pembuatan', 100)->nullable(); $table->foreignUuid('warehouse_id')->nullable()->constrained('m_warehouses')->onDelete('set null'); $table->foreignUuid('kondisipeti_id')->nullable()->constrained('kondisi_petis')->onDelete('set null'); + $table->string('status', 50)->default('AKTIF'); $table->timestamps(); $table->softDeletes(); $table->string('created_by', 200)->nullable(); diff --git a/database/migrations/2023_11_06_122033_create_asset_statuses_table.php b/database/migrations/2023_11_06_122033_create_asset_statuses_table.php index 72f42ad..cade79b 100644 --- a/database/migrations/2023_11_06_122033_create_asset_statuses_table.php +++ b/database/migrations/2023_11_06_122033_create_asset_statuses_table.php @@ -13,6 +13,7 @@ return new class extends Migration { Schema::create('asset_statuses', function (Blueprint $table) { $table->uuid('id')->primary(); + $table->uuid('mobile_id')->nullable(); $table->foreignUuid('peti_id')->nullable()->constrained('petis')->onDelete('set null'); $table->date('exit_at')->nullable(); $table->date('est_pengembalian')->nullable(); @@ -22,6 +23,8 @@ return new class extends Migration $table->string('enter_pic', 200)->nullable(); $table->foreignUuid('enter_warehouse')->nullable()->constrained('m_warehouses'); $table->string('kondisi_peti')->nullable(); + // $table->string('status')->default('DIPINJAM'); + $table->boolean('status')->default(1); $table->timestamps(); $table->softDeletes(); $table->string('created_by', 200)->nullable(); diff --git a/database/migrations/2023_11_08_132316_create_transfers_table.php b/database/migrations/2023_11_08_132316_create_transfers_table.php index 4cca93b..8409fbc 100644 --- a/database/migrations/2023_11_08_132316_create_transfers_table.php +++ b/database/migrations/2023_11_08_132316_create_transfers_table.php @@ -13,11 +13,12 @@ return new class extends Migration { Schema::create('transfers', function (Blueprint $table) { $table->uuid('id')->primary(); - $table->foreignUuid('peti_id')->nullable()->constrained('petis')->onDelete('set null'); - $table->foreignUuid('name_customer')->nullable()->constrained('customers'); - $table->foreignUuid('source_warehouse')->nullable()->constrained('m_warehouses'); - $table->foreignUuid('destination_warehouse')->nullable()->constrained('m_warehouses'); - $table->date('date')->nullable(); + $table->uuid('mobile_id')->nullable(); + $table->foreignUuid('peti_id')->constrained('petis'); + $table->foreignUuid('name_customer')->constrained('customers'); + $table->foreignUuid('source_warehouse')->constrained('m_warehouses'); + $table->foreignUuid('destination_warehouse')->constrained('m_warehouses'); + $table->date('date'); $table->timestamps(); $table->softDeletes(); $table->string('created_by', 200)->nullable(); 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..a1e684c --- /dev/null +++ b/database/migrations/2023_11_17_075418_create_disposals_table.php @@ -0,0 +1,37 @@ +uuid('id')->primary(); + $table->uuid('mobile_id')->nullable(); + $table->foreignUuid('peti_id')->constrained('petis'); + $table->foreignUuid('customer_id')->nullable()->constrained('customers'); + $table->foreignUuid('warehouse_id')->nullable()->constrained('m_warehouses'); + $table->date('date_disposal'); + $table->text('description')->nullable(); + $table->string('status_disposal', 50); + $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..f3c63a9 100644 --- a/resources/views/dashboard/Disposal/create.blade.php +++ b/resources/views/dashboard/Disposal/create.blade.php @@ -10,8 +10,8 @@