diff --git a/DataTables/DebiturDataTable.php b/DataTables/DebiturDataTable.php index c97e94f..1756592 100644 --- a/DataTables/DebiturDataTable.php +++ b/DataTables/DebiturDataTable.php @@ -2,6 +2,7 @@ namespace Modules\Writeoff\DataTables; + use Carbon\Carbon; use Illuminate\Database\Eloquent\Builder as QueryBuilder; use Modules\Writeoff\Entities\Branch; use Modules\Writeoff\Entities\Debitur; @@ -28,14 +29,15 @@ ->orWhere('name', 'like', "%" . $search['value'] . "%"); } })->addIndexColumn()->editColumn('registered_at', function ($row) { - return $row->registered_at->locale('id')->translatedFormat('d F Y H:i:s'); + $date = Carbon::create($row->registered_at); + return $date->locale('id')->translatedFormat('d F Y'); })->editColumn('cabang', function ($row) { return $row->branch_id ? Branch::find($row->branch_id)->name : '-'; })->editColumn('status', function ($row) { - $status = $row->status=='A' ? 'Aktif' : 'Tidak Aktif'; + $status = $row->status ? 'Aktif' : 'Tidak Aktif'; $oto = $row->authorized_at !== null ? 'Authorised' : 'Not Authorised'; return $status.' '.$oto; - })->rawColumns(['action'])->addColumn('action', function ($debitur) { + })->rawColumns(['action','status'])->addColumn('action', function ($debitur) { return view('writeoff::parameter.debitur._actions', compact('debitur')); })->setRowId('id'); } diff --git a/Database/Migrations/2023_11_06_101550_create_debitur_table.php b/Database/Migrations/2023_11_06_101550_create_debitur_table.php index 00f5fb0..cfe36a4 100644 --- a/Database/Migrations/2023_11_06_101550_create_debitur_table.php +++ b/Database/Migrations/2023_11_06_101550_create_debitur_table.php @@ -1,43 +1,44 @@ id(); - $table->foreignIdFor(Branch::class)->constrained()->onDelete('cascade'); - $table->string('kode',4)->unique(); - $table->string('name'); - $table->timestamp('registered_at')->nullable(); - $table->text('address')->nullable(); - $table->string('npwp',16)->nullable(); - $table->char('status', 1)->default('A'); - $table->timestamps(); - $table->timestamp('authorized_at')->nullable(); - $table->char('authorized_status', 1)->nullable(); - $table->softDeletes(); + return new class extends Migration { + /** + * Run the migrations. + */ + public function up() + : void + { + Schema::create('debitur', function (Blueprint $table) { + $table->id(); + $table->foreignIdFor(Branch::class)->constrained()->onDelete('cascade'); + $table->string('kode', 6)->unique(); + $table->string('name'); + $table->date('registered_at')->nullable(); + $table->text('address')->nullable(); + $table->string('npwp', 16)->nullable(); + $table->boolean('status')->default(true)->nullable(); + $table->timestamps(); + $table->timestamp('authorized_at')->nullable(); + $table->char('authorized_status', 1)->nullable(); + $table->softDeletes(); - $table->unsignedBigInteger('created_by')->nullable(); - $table->unsignedBigInteger('updated_by')->nullable(); - $table->unsignedBigInteger('deleted_by')->nullable(); - $table->unsignedBigInteger('authorized_by')->nullable(); - }); - } + $table->unsignedBigInteger('created_by')->nullable(); + $table->unsignedBigInteger('updated_by')->nullable(); + $table->unsignedBigInteger('deleted_by')->nullable(); + $table->unsignedBigInteger('authorized_by')->nullable(); + }); + } - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('debitur'); - } -}; + /** + * Reverse the migrations. + */ + public function down() + : void + { + Schema::dropIfExists('debitur'); + } + }; diff --git a/Entities/Branch.php b/Entities/Branch.php index 6a07d20..ad4e8b0 100644 --- a/Entities/Branch.php +++ b/Entities/Branch.php @@ -16,4 +16,8 @@ 'authorized_by', ]; + public function debiturs() + { + return $this->hasMany(Debitur::class); + } } diff --git a/Entities/Debitur.php b/Entities/Debitur.php index 4dff2ad..496ef9a 100644 --- a/Entities/Debitur.php +++ b/Entities/Debitur.php @@ -18,4 +18,14 @@ 'authorized_by', ]; + public function branch() + { + return $this->belongsTo(Branch::class); + } + + public function rekenings() + { + return $this->hasMany(Rekening::class); + } + } diff --git a/Http/Requests/Debitur/StoreDebiturRequest.php b/Http/Requests/Debitur/StoreDebiturRequest.php index 991dd3a..5796db8 100644 --- a/Http/Requests/Debitur/StoreDebiturRequest.php +++ b/Http/Requests/Debitur/StoreDebiturRequest.php @@ -28,10 +28,10 @@ : array { return [ - 'kode' => 'required|string|max:9|min:9|unique:debitur,kode', + 'kode' => 'required|string|max:6|min:6|unique:debitur,kode', 'name' => 'required|string|max:100', 'branch_id' => 'required|integer|exists:branches,id', - 'status' => 'required|string|max:1|min:1|in:A,I', + 'status' => 'required|boolean', 'address' => 'nullable|string|max:255', 'npwp' => 'nullable|string|max:16|min:16', 'registered_at' => 'nullable|date_format:Y-m-d' @@ -75,11 +75,4 @@ 'messages' => 'Debitur created failed.' ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); } - - protected function prepareForValidation() - { - $this->merge([ - 'status' => $this->status ? 'A' : 'I' - ]); - } } diff --git a/Http/Requests/Debitur/UpdateDebiturRequest.php b/Http/Requests/Debitur/UpdateDebiturRequest.php index b602c07..80bb428 100644 --- a/Http/Requests/Debitur/UpdateDebiturRequest.php +++ b/Http/Requests/Debitur/UpdateDebiturRequest.php @@ -33,10 +33,10 @@ $this->_id = json_decode(json_decode(file_get_contents('php://input'))->components[0]->snapshot)->data->id; return [ - 'kode' => 'required|string|max:9|min:9|unique:debitur,kode,' . $this->_id, + 'kode' => 'required|string|max:6|min:6|unique:debitur,kode,' . $this->_id, 'name' => 'required|string|max:100', 'branch_id' => 'required|integer|exists:branches,id', - 'status' => 'required|string|max:1|min:1|in:A,I|default:A', + 'status' => 'required|boolean', 'address' => 'nullable|string|max:255', 'npwp' => 'nullable|string|max:16|min:16', 'registered_at' => 'nullable|date_format:Y-m-d' @@ -72,11 +72,4 @@ 'messages' => 'Debitur updated failed.' ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); } - - protected function prepareForValidation() - { - $this->merge([ - 'status' => $this->status ? 'A' : 'I' - ]); - } } diff --git a/Livewire/Debitur/DebiturModal.php b/Livewire/Debitur/DebiturModal.php index 9dd28f2..f97b877 100644 --- a/Livewire/Debitur/DebiturModal.php +++ b/Livewire/Debitur/DebiturModal.php @@ -7,7 +7,7 @@ use Modules\Writeoff\Entities\Branch; use Modules\Writeoff\Entities\Debitur; use Modules\Writeoff\Http\Requests\Debitur\StoreDebiturRequest; - use Modules\Writeoff\Http\Requests\Debitur\UpdateDebiturRequest; + use Modules\Writeoff\Http\Requests\Debitur\UpdateRekeningRequest; class DebiturModal extends Component { @@ -48,7 +48,6 @@ 'address' => $this->address, 'npwp' => $this->npwp, 'registered_at' => $this->registered_at, - ]; @@ -80,7 +79,7 @@ $this->kode = $debitur->kode; $this->name = $debitur->name; $this->branch_id = $debitur->branch_id; - $this->status = $debitur->status; + $this->status = $debitur->status==1?true:false; $this->address = $debitur->address; $this->npwp = $debitur->npwp; $this->registered_at = $debitur->registered_at; @@ -103,13 +102,10 @@ protected function rules() { if ($this->edit_mode) { - $request = new UpdateDebiturRequest(); + $request = new UpdateRekeningRequest(); } else { $request = new StoreDebiturRequest(); } - - dd($request->rules()); - return $request->rules(); } } diff --git a/Resources/views/livewire/debitur/debitur-modal.blade.php b/Resources/views/livewire/debitur/debitur-modal.blade.php index 25efb93..de65e3d 100644 --- a/Resources/views/livewire/debitur/debitur-modal.blade.php +++ b/Resources/views/livewire/debitur/debitur-modal.blade.php @@ -99,12 +99,13 @@ {{ $message }} @enderror -
- + + @error('status') + {{ $message }} @enderror
diff --git a/Resources/views/parameter/debitur/index.blade.php b/Resources/views/parameter/debitur/index.blade.php index adee4c9..a2ce431 100644 --- a/Resources/views/parameter/debitur/index.blade.php +++ b/Resources/views/parameter/debitur/index.blade.php @@ -1,7 +1,7 @@ @section('title') - Cabang + Debitur @endsection @section('breadcrumbs')