1 Commits

Author SHA1 Message Date
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
4 changed files with 84 additions and 1 deletions

View File

@@ -8,6 +8,7 @@
protected $fillable = [
'code',
'name',
'is_dalam_kota',
'address',
'mnemonic',
'customer_company',

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],
];
DB::table('currencies')->truncate();
// DB::table('currencies')->truncate();
DB::table('currencies')->delete();
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";
}
}