diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index 9c5c956..b950531 100644 --- a/app/Http/Controllers/CustomerController.php +++ b/app/Http/Controllers/CustomerController.php @@ -38,11 +38,12 @@ class CustomerController extends Controller */ public function store(ValidasiCreateCustomer $request) { + // dd($request); try { $currentUser = Auth::user(); $validatedData = $request->except('_token'); - $validatedData['created_by'] = $currentUser->id; // Menggunakan nama pengguna sebagai created_by - $validatedData['updated_by'] = $currentUser->id; // Menggunakan nama pengguna sebagai updated_by + $validatedData['created_by'] = $currentUser->fullname; // Menggunakan nama pengguna sebagai created_by + $validatedData['updated_by'] = $currentUser->fullname; // Menggunakan nama pengguna sebagai updated_by Customer::create($validatedData); return redirect()->route('dashboard.customer.index')->with('success', 'Data customer berhasil ditambahkan'); } catch (\Throwable $th) { diff --git a/app/Http/Controllers/PeminjamanController.php b/app/Http/Controllers/PeminjamanController.php index 1b3fd08..9d72f07 100644 --- a/app/Http/Controllers/PeminjamanController.php +++ b/app/Http/Controllers/PeminjamanController.php @@ -2,6 +2,8 @@ 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; @@ -38,6 +40,7 @@ class PeminjamanController extends Controller 'asset' => m_asset::all(), 'peminjaman' => asset_status::get(), 'warehouse' => m_warehouse::get(), + 'existingPeti' => asset_status::pluck('peti_id')->toArray(), 'active' => 'menu-peminjaman', ]; return view('dashboard.Peminjaman.create', $data); @@ -46,17 +49,8 @@ class PeminjamanController extends Controller /** * Store a newly created resource in storage. */ - public function store(Request $request) + public function store(ValidasiCreatePeminjaman $request) { - // dd('oke'); - // dd($request->all()); - $request->validate([ - 'peti_id' => 'required', - 'exit_at' => 'required', - 'est_pengembalian' => 'required', - 'exit_warehouse' => 'required', - ]); - // dd($request); try { $currentUser = Auth::user(); @@ -97,16 +91,8 @@ class PeminjamanController extends Controller /** * Update the specified resource in storage. */ - public function update(Request $request, $id) + public function update(ValidasiUpdatePeminjaman $request, $id) { - // dd('oke'); - // dd($request->all()); - $request->validate([ - 'peti_id' => 'required', - 'exit_at' => 'required', - 'est_pengembalian' => 'required', - 'exit_warehouse' => 'required', - ]); // dd($request); try { $peminjaman = asset_status::findOrFail($id); diff --git a/app/Http/Controllers/PengembalianController.php b/app/Http/Controllers/PengembalianController.php index c74b682..3b8f037 100644 --- a/app/Http/Controllers/PengembalianController.php +++ b/app/Http/Controllers/PengembalianController.php @@ -2,8 +2,8 @@ namespace App\Http\Controllers; +use App\Http\Requests\ValidasiUpdatePengembalian; use App\Models\Peti; -use App\Models\m_asset; use App\Models\m_warehouse; use App\Models\asset_status; use Illuminate\Http\Request; @@ -60,24 +60,14 @@ class PengembalianController extends Controller /** * Update the specified resource in storage. */ - public function update(Request $request, $id) + public function update(ValidasiUpdatePengembalian $request, $id) { - $request->validate([ - 'peti_id' => 'required', - 'exit_at' => 'required', - 'est_pengembalian' => 'required', - 'exit_warehouse' => 'required', - 'enter_at' => 'required', - 'enter_warehouse' => 'required', - 'kondisi_peti' => 'required', - ]); - try { $peminjaman = asset_status::findOrFail($id); // Update atribut-atribut yang diperlukan - $peminjaman->enter_pic = Auth::user()->id; - $peminjaman->updated_by = Auth::user()->id; + $peminjaman->enter_pic = Auth::user()->fullname; + $peminjaman->updated_by = Auth::user()->fullname; $peminjaman->peti_id = $request->input('peti_id'); $peminjaman->exit_at = $request->input('exit_at'); @@ -87,7 +77,6 @@ class PengembalianController extends Controller $peminjaman->enter_warehouse = $request->input('enter_warehouse'); $peminjaman->kondisi_peti = $request->input('kondisi_peti'); - // dd($peminjaman); $peminjaman->save(); return redirect()->route('dashboard.pengembalian.index')->with('success', 'Data peminjaman berhasil diperbaharui'); @@ -97,34 +86,6 @@ class PengembalianController extends Controller } } - // public function update(Request $request, $id) - // { - // // dd($request->all()); - // $request->validate([ - // 'peti_id' => 'required', - // 'exit_at' => 'required', - // 'est_pengembalian' => 'required', - // 'exit_warehouse' => 'required', - // 'enter_at' => 'required', - // 'enter_warehouse' => 'required', - // 'kondisi_peti' => 'required', - // ]); - // // dd($request); - - // try { - // $peminjaman = asset_status::findOrFail($id); - // $peminjaman['enter_pic'] = Auth::user()->id; // Menambahkan ID pengguna sebagai updated_by - // $peminjaman['updated_by'] = Auth::user()->id; // Menambahkan ID pengguna sebagai updated_by - // dd($peminjaman); - // $peminjaman->update($request->all()); - - // return redirect()->route('dashboard.pengembalian.index')->with('success', 'Data peminjaman berhasil diperbaharui'); - // } catch (\Throwable $th) { - // // Tampilkan pesan kesalahan untuk debugging - // return redirect()->back()->with('error', 'Data peminjaman gagal diperbaharui: ' . $th->getMessage()); - // } - // } - /** * Remove the specified resource from storage. */ diff --git a/app/Http/Requests/ValidasiCreateCustomer.php b/app/Http/Requests/ValidasiCreateCustomer.php index 821610f..5087062 100644 --- a/app/Http/Requests/ValidasiCreateCustomer.php +++ b/app/Http/Requests/ValidasiCreateCustomer.php @@ -25,7 +25,7 @@ class ValidasiCreateCustomer extends FormRequest 'name' => 'required|string|max:50', 'code_customer' => 'required|string|max:15|unique:customers,code_customer', 'lot_no' => 'required|string|max:50', - 'no_tlp' => 'required|numeric', + 'no_tlp' => 'required', 'address' => 'required|string', ]; } @@ -43,7 +43,7 @@ class ValidasiCreateCustomer extends FormRequest 'lot_no.required' => 'Kolom lot_no wajib diisi.', 'lot_no.string' => 'Kolom lot_no harus berupa teks.', 'no_tlp.required' => 'Kolom no_tlp wajib diisi.', - 'no_tlp.numeric' => 'Kolom no_tlp harus berisi angka.', + // 'no_tlp.numeric' => 'Kolom no_tlp harus berisi angka.', 'no_tlp.max' => 'Kolom no_tlp tidak boleh lebih dari :max karakter.', 'address.required' => 'Kolom address wajib diisi.', 'address.string' => 'Kolom address harus berupa teks.', diff --git a/app/Http/Requests/ValidasiCreatePeminjaman.php b/app/Http/Requests/ValidasiCreatePeminjaman.php new file mode 100644 index 0000000..a62d980 --- /dev/null +++ b/app/Http/Requests/ValidasiCreatePeminjaman.php @@ -0,0 +1,45 @@ +|string> + */ + public function rules(): array + { + return [ + 'peti_id' => 'required|integer', // Pastikan peti_id ada dalam tabel petis + 'exit_at' => 'required|date', + 'est_pengembalian' => 'required|date', // Estimasi pengembalian harus setelah exit_at + 'exit_warehouse' => 'required|integer', + ]; + } + + public function messages() + { + return [ + 'peti_id.required' => 'Bidang Detail Peti wajib diisi.', + 'peti_id.integer' => 'Detail Peti harus berupa angka.', + 'exit_at.required' => 'Bidang Tanggal Peminjaman wajib diisi.', + 'exit_at.date' => 'Bidang Tanggal Peminjaman harus berupa tanggal.', + 'est_pengembalian.required' => 'Bidang Estimasi Tanggal Pengembalian wajib diisi.', + 'est_pengembalian.date' => 'Bidang Estimasi Tanggal Pengembalian harus berupa tanggal.', + 'exit_warehouse.required' => 'Bidang Asal Gudang wajib diisi.', + 'exit_warehouse.integer' => 'Asal Gudang harus berupa angka.', + ]; + } +} diff --git a/app/Http/Requests/ValidasiUpdatePeminjaman.php b/app/Http/Requests/ValidasiUpdatePeminjaman.php new file mode 100644 index 0000000..fe72ace --- /dev/null +++ b/app/Http/Requests/ValidasiUpdatePeminjaman.php @@ -0,0 +1,45 @@ +|string> + */ + public function rules(): array + { + return [ + 'peti_id' => 'required|integer', // Pastikan peti_id ada dalam tabel petis + 'exit_at' => 'required|date', + 'est_pengembalian' => 'required|date', // Estimasi pengembalian harus setelah exit_at + 'exit_warehouse' => 'required|integer', + ]; + } + + public function messages() + { + return [ + 'peti_id.required' => 'Bidang Detail Peti wajib diisi.', + 'peti_id.integer' => 'Detail Peti harus berupa angka.', + 'exit_at.required' => 'Bidang Tanggal Peminjaman wajib diisi.', + 'exit_at.date' => 'Bidang Tanggal Peminjaman harus berupa tanggal.', + 'est_pengembalian.required' => 'Bidang Estimasi Tanggal Pengembalian wajib diisi.', + 'est_pengembalian.date' => 'Bidang Estimasi Tanggal Pengembalian harus berupa tanggal.', + 'exit_warehouse.required' => 'Bidang Asal Gudang wajib diisi.', + 'exit_warehouse.integer' => 'Asal Gudang harus berupa angka.', + ]; + } +} diff --git a/app/Http/Requests/ValidasiUpdatePengembalian.php b/app/Http/Requests/ValidasiUpdatePengembalian.php new file mode 100644 index 0000000..fe8f9c9 --- /dev/null +++ b/app/Http/Requests/ValidasiUpdatePengembalian.php @@ -0,0 +1,54 @@ +|string> + */ + public function rules(): array + { + return [ + 'peti_id' => 'required|integer', + 'exit_at' => 'required|date', + 'est_pengembalian' => 'required|date', + 'exit_warehouse' => 'required|integer', + 'enter_at' => 'required|date', + 'enter_warehouse' => 'required|integer', + 'kondisi_peti' => 'required|string', + ]; + } + + public function messages() + { + return [ + 'peti_id.required' => 'Kolom peti_id wajib diisi.', + 'peti_id.integer' => 'Kolom peti_id harus berupa angka bulat.', + 'exit_at.required' => 'Kolom exit_at wajib diisi.', + 'exit_at.date' => 'Kolom exit_at harus berupa tanggal.', + 'est_pengembalian.required' => 'Kolom est_pengembalian wajib diisi.', + 'est_pengembalian.date' => 'Kolom est_pengembalian harus berupa tanggal.', + 'exit_warehouse.required' => 'Kolom exit_warehouse wajib diisi.', + 'exit_warehouse.integer' => 'Kolom exit_warehouse harus berupa angka bulat.', + 'enter_at.required' => 'Kolom enter_at wajib diisi.', + 'enter_at.date' => 'Kolom enter_at harus berupa tanggal.', + 'enter_warehouse.required' => 'Kolom enter_warehouse wajib diisi.', + 'enter_warehouse.integer' => 'Kolom enter_warehouse harus berupa angka bulat.', + 'kondisi_peti.required' => 'Kolom kondisi_peti wajib diisi.', + 'kondisi_peti.string' => 'Kolom kondisi_peti harus berupa teks.', + ]; + } +} diff --git a/app/Models/asset_status.php b/app/Models/asset_status.php index 708092c..898b651 100644 --- a/app/Models/asset_status.php +++ b/app/Models/asset_status.php @@ -14,15 +14,15 @@ class asset_status extends Model protected $table = 'asset_statuses'; protected $fillable = [ - 'peti_id', //sudah - 'exit_at', //sudah - 'est_pengembalian', //sudah - 'exit_pic', // di controler - 'exit_warehouse', //sudah - 'enter_at', // //sudah - 'enter_pic', // //sudah - 'enter_warehouse', // //sudah - 'kondisi_peti', // //sudah + 'peti_id', + 'exit_at', + 'est_pengembalian', + 'exit_pic', + 'exit_warehouse', + 'enter_at', + 'enter_pic', + 'enter_warehouse', + 'kondisi_peti', 'created_by', 'updated_by', ]; diff --git a/resources/views/dashboard/Master_Data/Customer/create.blade.php b/resources/views/dashboard/Master_Data/Customer/create.blade.php index 3be5f4a..292ceba 100644 --- a/resources/views/dashboard/Master_Data/Customer/create.blade.php +++ b/resources/views/dashboard/Master_Data/Customer/create.blade.php @@ -14,23 +14,27 @@
@csrf
- + + placeholder="Masukan nama customer" pattern="[^0-9]+" + oninput="this.value=this.value.replace(/[0-9]/g,'');" required> - + - + - - + + - +