3 Commits

Author SHA1 Message Date
Sholahuddin Al Ayubi
b8cf5e550f refactor(branch): clean up formatting and structure in Branch model 2025-12-11 17:22:45 +07:00
Sholahuddin Al Ayubi
0526a1bb05 feat(branch): add 'is_dalam_kota' field to Branch form and validation rules 2025-12-11 15:30:20 +07:00
Sholahuddin Al Ayubi
fec8dc083c feat(Basicdata): Update 'is_dalam_kota' column and add new branches
- Update 'is_dalam_kota' to true for existing branches based on suffix code
- Set 'is_dalam_kota' to false for branches not in the list
- Add new branches (ID0012005 - KORPORASI, ID0010172 - AMBON TUAL MALUKU)
- Seeder is idempotent and can be rerun safely

run this command:
php artisan module:seed Basicdata --class="UpdateBranchesIsDalamKotaSeeder"

php artisan module:seed --class="Modules\\Basicdata\\Database\\Seeders\\UpdateBranchesIsDalamKotaSeeder"
2025-12-08 17:19:12 +07:00
6 changed files with 242 additions and 113 deletions

View File

@@ -28,6 +28,7 @@
'authorized_at' => 'nullable|datetime', 'authorized_at' => 'nullable|datetime',
'authorized_status' => 'nullable|string|max:1', 'authorized_status' => 'nullable|string|max:1',
'authorized_by' => 'nullable|exists:users,id', 'authorized_by' => 'nullable|exists:users,id',
'is_dalam_kota' => 'nullable|in:0,1',
]; ];
if ($this->method() == 'PUT') { if ($this->method() == 'PUT') {

View File

@@ -1,42 +1,49 @@
<?php <?php
namespace Modules\Basicdata\Models; namespace Modules\Basicdata\Models;
class Branch extends Base class Branch extends Base
{
protected $table = 'branches';
protected $fillable = [
'code',
'name',
'is_dalam_kota',
'address',
'mnemonic',
'customer_company',
'customer_mnemonic',
'company_group',
'curr_no',
'co_code',
'l_vendor_atm',
'l_vendor_cpc',
'status',
'authorized_at',
'authorized_status',
'authorized_by',
'parent_id'
];
/**
* Get the parent branch of this branch
*/
public function parent()
{ {
protected $table = 'branches'; return $this->belongsTo(Branch::class, 'parent_id');
protected $fillable = [
'code',
'name',
'address',
'mnemonic',
'customer_company',
'customer_mnemonic',
'company_group',
'curr_no',
'co_code',
'l_vendor_atm',
'l_vendor_cpc',
'status',
'authorized_at',
'authorized_status',
'authorized_by',
'parent_id'
];
/**
* Get the parent branch of this branch
*/
public function parent()
{
return $this->belongsTo(Branch::class, 'parent_id');
}
/**
* Get the child branches of this branch
*/
public function children()
{
return $this->hasMany(Branch::class, 'parent_id');
}
} }
/**
* Get the child branches of this branch
*/
public function children()
{
return $this->hasMany(Branch::class, 'parent_id');
}
public function users()
{
return $this->belongsToMany(Modules\Usermanagement\Models\User::class, 'user_branches', 'branch_id', 'user_id');
}
}

View File

@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('branches', function (Blueprint $table) {
$table->boolean('is_dalam_kota')->default(true)->after('name');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('branches', function (Blueprint $table) {
$table->dropColumn('is_dalam_kota');
});
}
};

View File

@@ -59,7 +59,8 @@
['code' => 'PKR', 'name' => 'Pakistani Rupee', 'symbol' => '₨', 'decimal_places' => 2, 'status' => true, 'created_at' => $now, 'updated_at' => $now], ['code' => 'PKR', 'name' => 'Pakistani Rupee', 'symbol' => '₨', 'decimal_places' => 2, 'status' => true, 'created_at' => $now, 'updated_at' => $now],
]; ];
DB::table('currencies')->truncate(); // DB::table('currencies')->truncate();
DB::table('currencies')->delete();
DB::table('currencies')->insert($currencies); DB::table('currencies')->insert($currencies);
} }
} }

View File

@@ -0,0 +1,54 @@
<?php
namespace Modules\Basicdata\Database\Seeders;
use Illuminate\Database\Seeder;
use Modules\Basicdata\Models\Branch;
class UpdateBranchesIsDalamKotaSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$codes = [
'0005','0012','0250','0016','0018','0279','0092','0022','0251',
'0029','0270','0096','0109','0098','2005','0008','0028','0015',
'0006','0090','0009','0023','0020','0099','0003','0010','0002',
'0273','0011','0105',
];
Branch::query()->update(['is_dalam_kota' => false]);
foreach ($codes as $code) {
Branch::where('code', 'like', '%' . $code)
->update(['is_dalam_kota' => true]);
}
$newBranches = [
[
'code' => 'ID0012005',
'name' => 'KORPORASI',
'is_dalam_kota' => true,
],
[
'code' => 'ID0010172',
'name' => 'AMBON TUAL MALUKU',
'is_dalam_kota' => false,
],
];
foreach ($newBranches as $branch) {
Branch::firstOrCreate(
['code' => $branch['code']],
[
'name' => $branch['name'],
'is_dalam_kota' => $branch['is_dalam_kota'],
]
);
}
echo "Seeder update kolom is_dalam_kota + insert data baru selesai!\n";
}
}

View File

@@ -6,83 +6,122 @@
@section('content') @section('content')
<div class="w-full grid gap-5 lg:gap-7.5 mx-auto"> <div class="w-full grid gap-5 lg:gap-7.5 mx-auto">
@if(isset($branch->id)) @if (isset($branch->id))
<form action="{{ route('basicdata.branch.update', $branch->id) }}" method="POST"> <form action="{{ route('basicdata.branch.update', $branch->id) }}" method="POST">
<input type="hidden" name="id" value="{{ $branch->id }}"> <input type="hidden" name="id" value="{{ $branch->id }}">
@method('PUT') @method('PUT')
@else @else
<form method="POST" action="{{ route('basicdata.branch.store') }}"> <form method="POST" action="{{ route('basicdata.branch.store') }}">
@endif @endif
@csrf @csrf
<div class="card pb-2.5"> <div class="card pb-2.5">
<div class="card-header" id="basic_settings"> <div class="card-header" id="basic_settings">
<h3 class="card-title"> <h3 class="card-title">
{{ isset($branch->id) ? 'Edit' : 'Tambah' }} Branch {{ isset($branch->id) ? 'Edit' : 'Tambah' }} Branch
</h3> </h3>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<a href="{{ route('basicdata.branch.index') }}" class="btn btn-xs btn-info"><i class="ki-filled ki-exit-left"></i> Back</a> <a href="{{ route('basicdata.branch.index') }}" class="btn btn-xs btn-info"><i
</div> class="ki-filled ki-exit-left"></i> Back</a>
</div> </div>
<div class="card-body grid gap-5"> </div>
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5"> <div class="card-body grid gap-5">
<label class="form-label max-w-56"> <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
Code <label class="form-label max-w-56">
</label> Code
<div class="flex flex-wrap items-baseline w-full"> </label>
<input class="input @error('code') border-danger bg-danger-light @enderror" type="text" name="code" value="{{ $branch->code ?? '' }}"> <div class="flex flex-wrap items-baseline w-full">
@error('code') <input class="input @error('code') border-danger bg-danger-light @enderror" type="text"
<em class="alert text-danger text-sm">{{ $message }}</em> name="code" value="{{ $branch->code ?? '' }}">
@enderror @error('code')
</div> <em class="alert text-danger text-sm">{{ $message }}</em>
</div> @enderror
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5"> </div>
<label class="form-label max-w-56"> </div>
Name <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
</label> <label class="form-label max-w-56">
<div class="flex flex-wrap items-baseline w-full"> Name
<input class="input @error('name') border-danger bg-danger-light @enderror" type="text" name="name" value="{{ $branch->name ?? '' }}"> </label>
@error('name') <div class="flex flex-wrap items-baseline w-full">
<em class="alert text-danger text-sm">{{ $message }}</em> <input class="input @error('name') border-danger bg-danger-light @enderror" type="text"
@enderror name="name" value="{{ $branch->name ?? '' }}">
</div> @error('name')
</div> <em class="alert text-danger text-sm">{{ $message }}</em>
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5"> @enderror
<label class="form-label max-w-56"> </div>
Parent Branch </div>
</label>
<div class="flex flex-wrap items-baseline w-full"> <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<select class="input @error('parent_id') border-danger bg-danger-light @enderror" name="parent_id"> <label class="form-label max-w-56">
<option value="">-- Select Parent Branch --</option> Branch Type
@foreach($branches as $parentBranch) </label>
@if(!isset($branch->id) || $parentBranch->id != $branch->id) <div class="flex flex-wrap items-baseline w-full">
<option value="{{ $parentBranch->id }}" {{ (isset($branch->parent_id) && $branch->parent_id == $parentBranch->id) ? 'selected' : '' }}>
{{ $parentBranch->code }} - {{ $parentBranch->name }} @php
</option> $selectedDalamKota = old(
@endif 'is_dalam_kota',
@endforeach isset($branch->is_dalam_kota) ? $branch->is_dalam_kota : '',
</select> );
@error('parent_id') @endphp
<em class="alert text-danger text-sm">{{ $message }}</em>
@enderror <select class="input @error('is_dalam_kota') border-danger bg-danger-light @enderror"
</div> name="is_dalam_kota" id="is_dalam_kota">
</div>
<div class="flex justify-end"> <!-- DEFAULT PILIHAN SAAT CREATE -->
@if(isset($branch->id)) <option value="">-- Select Branch Location --</option>
@can('basic-data.update')
<button type="submit" class="btn btn-primary"> <option value="1" {{ $selectedDalamKota == 1 ? 'selected' : '' }}>
Save Dalam Kota
</button> </option>
@endcan
@else <option value="0" {{ $selectedDalamKota == 0 ? 'selected' : '' }}>
@can('basic-data.create') Luar Kota
<button type="submit" class="btn btn-primary"> </option>
Save
</button> </select>
@endcan
@endif @error('is_dalam_kota')
</div> <em class="alert text-danger text-sm">{{ $message }}</em>
</div> @enderror
</div> </div>
</form> </div>
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label class="form-label max-w-56">
Parent Branch
</label>
<div class="flex flex-wrap items-baseline w-full">
<select class="input @error('parent_id') border-danger bg-danger-light @enderror" name="parent_id">
<option value="">-- Select Parent Branch --</option>
@foreach ($branches as $parentBranch)
@if (!isset($branch->id) || $parentBranch->id != $branch->id)
<option value="{{ $parentBranch->id }}"
{{ isset($branch->parent_id) && $branch->parent_id == $parentBranch->id ? 'selected' : '' }}>
{{ $parentBranch->code }} - {{ $parentBranch->name }}
</option>
@endif
@endforeach
</select>
@error('parent_id')
<em class="alert text-danger text-sm">{{ $message }}</em>
@enderror
</div>
</div>
<div class="flex justify-end">
@if (isset($branch->id))
@can('basic-data.update')
<button type="submit" class="btn btn-primary">
Save
</button>
@endcan
@else
@can('basic-data.create')
<button type="submit" class="btn btn-primary">
Save
</button>
@endcan
@endif
</div>
</div>
</div>
</form>
</div> </div>
@endsection @endsection