Revert "fix(user): menambahkan kolom referral_code dan menyesuaikan logika yang ada"
This reverts commit 7fa46c0e9b.
This commit is contained in:
parent
f33275994b
commit
4f41461310
@ -65,10 +65,8 @@ public function columns(): array
|
|||||||
))
|
))
|
||||||
->html(),
|
->html(),
|
||||||
|
|
||||||
Column::make('Kode Referral', 'referral_code')
|
Column::make('Kode Referral', 'referralCode.code')
|
||||||
->format(fn ($value) => Blade::render(
|
->format(fn ($value) => Blade::render('<flux:badge color="zinc">'.$value.'</flux:badge>'))
|
||||||
'<flux:badge color="zinc">'.$value.'</flux:badge>'
|
|
||||||
))
|
|
||||||
->html(),
|
->html(),
|
||||||
|
|
||||||
Column::make('Gaji Pokok', 'employee.base_salary')
|
Column::make('Gaji Pokok', 'employee.base_salary')
|
||||||
@ -139,7 +137,7 @@ public function columns(): array
|
|||||||
|
|
||||||
public function builder(): Builder
|
public function builder(): Builder
|
||||||
{
|
{
|
||||||
return User::select('users.id', 'email', 'username', 'users.status', 'employee.code', 'employee.full_name', 'employee.phone_number', 'employee.base_salary', 'employee.address', 'employee.hire_date', 'employee.resign_date', 'employee.birthdate', 'employee.gender')->with('employee');
|
return User::select('users.id', 'email', 'username', 'users.status', 'employee.code', 'employee.full_name', 'employee.phone_number', 'employee.base_salary', 'employee.address', 'employee.hire_date', 'employee.resign_date', 'employee.birthdate', 'employee.gender')->with(['employee', 'referralCode']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function filters(): array
|
public function filters(): array
|
||||||
|
|||||||
33
app/Models/ReferralCode.php
Normal file
33
app/Models/ReferralCode.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
class ReferralCode extends Model
|
||||||
|
{
|
||||||
|
use HasFactory, SoftDeletes;
|
||||||
|
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'uses_count' => 'int',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function user(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function referralUsage(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(ReferralUsage::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
24
app/Models/ReferralUsage.php
Normal file
24
app/Models/ReferralUsage.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
class ReferralUsage extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
|
||||||
|
public function user(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function referralCode(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ReferralCode::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -41,4 +41,14 @@ public function membership(): HasOne
|
|||||||
{
|
{
|
||||||
return $this->hasOne(Membership::class);
|
return $this->hasOne(Membership::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function referralCode(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(ReferralCode::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function referralUsage(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(ReferralUsage::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
use App\Enums\UserStatus;
|
use App\Enums\UserStatus;
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
@ -11,13 +10,10 @@ class UserFactory extends Factory
|
|||||||
{
|
{
|
||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
$username = $this->faker->unique()->regexify('[A-Za-z0-9]{8}');
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'email' => $this->faker->unique()->safeEmail(),
|
'email' => $this->faker->unique()->safeEmail(),
|
||||||
'username' => $username,
|
'username' => fake()->unique()->regexify('[A-Za-z0-9]{8}'),
|
||||||
'password' => Hash::make(config('myconfig.password_default')),
|
'password' => Hash::make(config('myconfig.password_default')),
|
||||||
'referral_code' => generateReferralCode($username, User::max('id') + 1),
|
|
||||||
'status' => $this->faker->randomElement(UserStatus::cases()),
|
'status' => $this->faker->randomElement(UserStatus::cases()),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,6 @@ public function up(): void
|
|||||||
$table->string('email', 100)->unique();
|
$table->string('email', 100)->unique();
|
||||||
$table->string('username', 20)->unique();
|
$table->string('username', 20)->unique();
|
||||||
$table->string('password', 97);
|
$table->string('password', 97);
|
||||||
$table->string('referral_code', 20)->unique();
|
|
||||||
$table->enum('status', [UserStatus::values()])->default(UserStatus::ACTIVE)->comment(UserStatus::comment());
|
$table->enum('status', [UserStatus::values()])->default(UserStatus::ACTIVE)->comment(UserStatus::comment());
|
||||||
$table->timestamp('last_login_at')->nullable();
|
$table->timestamp('last_login_at')->nullable();
|
||||||
$table->timestamp('last_password_change_at')->nullable();
|
$table->timestamp('last_password_change_at')->nullable();
|
||||||
|
|||||||
@ -0,0 +1,31 @@
|
|||||||
|
<?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::create('referral_codes', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->string('code', 20)->unique();
|
||||||
|
$table->unsignedInteger('uses_count')->default(0);
|
||||||
|
$table->timestamps();
|
||||||
|
$table->softDeletes();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('referral_codes');
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
<?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::create('referral_usages', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->foreignId('referral_code_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('referral_usages');
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -5,6 +5,7 @@
|
|||||||
use App\Enums\EmploymentStatus;
|
use App\Enums\EmploymentStatus;
|
||||||
use App\Enums\Gender;
|
use App\Enums\Gender;
|
||||||
use App\Models\Employee;
|
use App\Models\Employee;
|
||||||
|
use App\Models\ReferralCode;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
@ -17,7 +18,6 @@ public function run(): void
|
|||||||
'email' => 'project.pangestuyoga@gmail.com',
|
'email' => 'project.pangestuyoga@gmail.com',
|
||||||
'username' => 'pangestu',
|
'username' => 'pangestu',
|
||||||
'password' => Hash::make(config('myconfig.password_default')),
|
'password' => Hash::make(config('myconfig.password_default')),
|
||||||
'referral_code' => generateReferralCode('pangestu', 1),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Employee::create([
|
Employee::create([
|
||||||
@ -31,5 +31,10 @@ public function run(): void
|
|||||||
'hire_date' => now(),
|
'hire_date' => now(),
|
||||||
'status' => EmploymentStatus::PERMANENT,
|
'status' => EmploymentStatus::PERMANENT,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
ReferralCode::create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'code' => generateReferralCode('pangestu', 1),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,6 @@
|
|||||||
->set('form.full_name', $data['full_name'])
|
->set('form.full_name', $data['full_name'])
|
||||||
->set('form.username', $data['username'])
|
->set('form.username', $data['username'])
|
||||||
->set('form.email', $data['email'])
|
->set('form.email', $data['email'])
|
||||||
->set('form.referral_code', $data['referral_code'])
|
|
||||||
->set('form.phone_number', $data['phone_number'])
|
->set('form.phone_number', $data['phone_number'])
|
||||||
->set('form.base_salary', $data['base_salary'])
|
->set('form.base_salary', $data['base_salary'])
|
||||||
->set('form.birthdate', $data['birthdate'])
|
->set('form.birthdate', $data['birthdate'])
|
||||||
|
|||||||
@ -33,7 +33,6 @@
|
|||||||
->set('form.full_name', $data['full_name'])
|
->set('form.full_name', $data['full_name'])
|
||||||
->set('form.username', $data['username'])
|
->set('form.username', $data['username'])
|
||||||
->set('form.email', $data['email'])
|
->set('form.email', $data['email'])
|
||||||
->set('form.referral_code', $data['referral_code'])
|
|
||||||
->set('form.phone_number', $data['phone_number'])
|
->set('form.phone_number', $data['phone_number'])
|
||||||
->set('form.base_salary', $data['base_salary'])
|
->set('form.base_salary', $data['base_salary'])
|
||||||
->set('form.birthdate', $data['birthdate'])
|
->set('form.birthdate', $data['birthdate'])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user