From 9ecdaa0cddafa924a69c38a4c057b470f1217d66 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Fri, 13 Sep 2024 14:12:35 +0700 Subject: [PATCH] Update Module Debitur penambahan default cif 0x10 dan di buat mandatory update field npwp input harus minimal 15 dan maksimal 16 digit penambahan rules --- app/Http/Controllers/DebitureController.php | 1 + app/Http/Requests/DebitureRequest.php | 11 ++++---- app/Rules/UniqueCifExceptZero.php | 25 +++++++++++++++++++ .../debitur/components/debitur.blade.php | 3 ++- 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 app/Rules/UniqueCifExceptZero.php diff --git a/app/Http/Controllers/DebitureController.php b/app/Http/Controllers/DebitureController.php index e6762e3..b429265 100644 --- a/app/Http/Controllers/DebitureController.php +++ b/app/Http/Controllers/DebitureController.php @@ -71,6 +71,7 @@ public function update(DebitureRequest $request, $id) { + //print_r($request->all());exit; $validate = $request->validated(); if ($validate) { diff --git a/app/Http/Requests/DebitureRequest.php b/app/Http/Requests/DebitureRequest.php index ff87263..7f83fbb 100644 --- a/app/Http/Requests/DebitureRequest.php +++ b/app/Http/Requests/DebitureRequest.php @@ -3,6 +3,7 @@ namespace Modules\Lpj\Http\Requests; use Illuminate\Foundation\Http\FormRequest; + use Modules\Lpj\Rules\UniqueCifExceptZero; class DebitureRequest extends FormRequest { @@ -21,7 +22,7 @@ 'nomor_rekening' => 'nullable|string|max:50', 'name' => 'required', 'registered_at' => 'nullable|date', - 'npwp' => 'nullable|string|max:16', + 'npwp' => 'nullable|string|min:15|max:16', 'email' => 'nullable|email', 'phone' => 'nullable|string|max:15', 'address' => 'nullable|string', @@ -29,10 +30,10 @@ 'status' => 'nullable|boolean' ]; - if ($this->method() == 'PUT') { - $rules['cif'] = 'nullable|unique:debitures,cif,' . $this->id; - } else { - $rules['cif'] = 'nullable|unique:debitures,cif'; + if($this->method() == 'PUT'){ + $rules['cif'] = ['required', new UniqueCifExceptZero($this->id)]; + }else{ + $rules['cif'] = ['required', new UniqueCifExceptZero(null)]; } return $rules; diff --git a/app/Rules/UniqueCifExceptZero.php b/app/Rules/UniqueCifExceptZero.php new file mode 100644 index 0000000..e7236ce --- /dev/null +++ b/app/Rules/UniqueCifExceptZero.php @@ -0,0 +1,25 @@ +id = $id; + } + + public function validate($attribute, $value, $fail): void + { + if (Debiture::where($attribute, $value) + ->where('id', '!=', $this->id) + ->where($attribute, '!=', '000000') + ->exists()) { + $fail('The :attribute field must be uniquse.'.$this->id); + } + } +} diff --git a/resources/views/debitur/components/debitur.blade.php b/resources/views/debitur/components/debitur.blade.php index 8170af7..157ad1b 100644 --- a/resources/views/debitur/components/debitur.blade.php +++ b/resources/views/debitur/components/debitur.blade.php @@ -1,5 +1,6 @@
@if(isset($debitur->id)) + @method('PUT') @endif @csrf @@ -29,7 +30,7 @@ CIF
- + @error('cif') {{ $message }} @enderror