first commit
This commit is contained in:
37
database/factories/DepartmentFactory.php
Normal file
37
database/factories/DepartmentFactory.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\DepartmentProfile;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Department>
|
||||
*/
|
||||
class DepartmentFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->unique()->companySuffix(),
|
||||
'is_active' => true,
|
||||
'department_profile_id' => DepartmentProfile::factory(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the department is inactive.
|
||||
*/
|
||||
public function inactive(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'is_active' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
24
database/factories/DepartmentProfileFactory.php
Normal file
24
database/factories/DepartmentProfileFactory.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\DepartmentProfile;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<DepartmentProfile>
|
||||
*/
|
||||
class DepartmentProfileFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->unique()->jobTitle(),
|
||||
];
|
||||
}
|
||||
}
|
||||
29
database/factories/MedicationExpenseRowFactory.php
Normal file
29
database/factories/MedicationExpenseRowFactory.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\MedicationExpenseRow;
|
||||
use App\Models\ReportPeriod;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<MedicationExpenseRow>
|
||||
*/
|
||||
class MedicationExpenseRowFactory extends Factory
|
||||
{
|
||||
protected $model = MedicationExpenseRow::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'report_period_id' => ReportPeriod::factory(),
|
||||
'department_id' => Department::factory(),
|
||||
];
|
||||
}
|
||||
}
|
||||
32
database/factories/MedicationExpenseValueFactory.php
Normal file
32
database/factories/MedicationExpenseValueFactory.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\ExpenseCategory;
|
||||
use App\Enums\FundingSource;
|
||||
use App\Models\MedicationExpenseRow;
|
||||
use App\Models\MedicationExpenseValue;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<MedicationExpenseValue>
|
||||
*/
|
||||
class MedicationExpenseValueFactory extends Factory
|
||||
{
|
||||
protected $model = MedicationExpenseValue::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'medication_expense_row_id' => MedicationExpenseRow::factory(),
|
||||
'funding_source' => fake()->randomElement(FundingSource::cases()),
|
||||
'expense_category' => fake()->randomElement(ExpenseCategory::cases()),
|
||||
'amount' => fake()->randomFloat(2, 0, 100000),
|
||||
];
|
||||
}
|
||||
}
|
||||
41
database/factories/ReportPeriodFactory.php
Normal file
41
database/factories/ReportPeriodFactory.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\ReportPeriodStatus;
|
||||
use App\Models\ReportPeriod;
|
||||
use App\Models\Team;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<ReportPeriod>
|
||||
*/
|
||||
class ReportPeriodFactory extends Factory
|
||||
{
|
||||
protected $model = ReportPeriod::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'team_id' => Team::factory(),
|
||||
'year' => 2026,
|
||||
'month' => fake()->numberBetween(1, 12),
|
||||
'status' => ReportPeriodStatus::Draft,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the period is approved.
|
||||
*/
|
||||
public function approved(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => ReportPeriodStatus::Approved,
|
||||
]);
|
||||
}
|
||||
}
|
||||
33
database/factories/ServiceCatalogFactory.php
Normal file
33
database/factories/ServiceCatalogFactory.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\ServiceCatalog;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<ServiceCatalog>
|
||||
*/
|
||||
class ServiceCatalogFactory extends Factory
|
||||
{
|
||||
protected $model = ServiceCatalog::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$name = fake()->unique()->words(2, true);
|
||||
|
||||
return [
|
||||
'code' => str(fake()->unique()->slug(2))->replace('-', '_')->value(),
|
||||
'name' => mb_convert_case($name, MB_CASE_TITLE, 'UTF-8'),
|
||||
'unit' => fake()->randomElement(['усл.', 'иссл.', 'проц.']),
|
||||
'default_price' => fake()->randomFloat(2, 10, 10000),
|
||||
'sort_order' => fake()->numberBetween(1, 100),
|
||||
'is_active' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
34
database/factories/ServiceEntryFactory.php
Normal file
34
database/factories/ServiceEntryFactory.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\ReportPeriod;
|
||||
use App\Models\ServiceCatalog;
|
||||
use App\Models\ServiceEntry;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<ServiceEntry>
|
||||
*/
|
||||
class ServiceEntryFactory extends Factory
|
||||
{
|
||||
protected $model = ServiceEntry::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'report_period_id' => ReportPeriod::factory(),
|
||||
'service_catalog_id' => ServiceCatalog::factory(),
|
||||
'provider_department_id' => Department::factory(),
|
||||
'recipient_department_id' => Department::factory(),
|
||||
'quantity' => fake()->randomFloat(2, 0, 5000),
|
||||
'unit_price' => fake()->randomFloat(2, 10, 10000),
|
||||
];
|
||||
}
|
||||
}
|
||||
49
database/factories/TeamFactory.php
Normal file
49
database/factories/TeamFactory.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Team;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<Team>
|
||||
*/
|
||||
class TeamFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$name = fake()->unique()->company();
|
||||
|
||||
return [
|
||||
'name' => $name,
|
||||
'slug' => Str::slug($name),
|
||||
'is_personal' => false,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the team is a personal team.
|
||||
*/
|
||||
public function personal(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'is_personal' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the team has been deleted.
|
||||
*/
|
||||
public function trashed(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'deleted_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
62
database/factories/TeamInvitationFactory.php
Normal file
62
database/factories/TeamInvitationFactory.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\TeamRole;
|
||||
use App\Models\Team;
|
||||
use App\Models\TeamInvitation;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<TeamInvitation>
|
||||
*/
|
||||
class TeamInvitationFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'team_id' => Team::factory(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'role' => TeamRole::Member,
|
||||
'invited_by' => User::factory(),
|
||||
'expires_at' => null,
|
||||
'accepted_at' => null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the invitation has been accepted.
|
||||
*/
|
||||
public function accepted(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'accepted_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the invitation has expired.
|
||||
*/
|
||||
public function expired(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'expires_at' => now()->subDay(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the invitation expires in the given time.
|
||||
*/
|
||||
public function expiresIn(int $value, string $unit = 'days'): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'expires_at' => now()->add($unit, $value),
|
||||
]);
|
||||
}
|
||||
}
|
||||
80
database/factories/UserFactory.php
Normal file
80
database/factories/UserFactory.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\TeamRole;
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
'two_factor_secret' => null,
|
||||
'two_factor_recovery_codes' => null,
|
||||
'two_factor_confirmed_at' => null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the model factory.
|
||||
*/
|
||||
public function configure(): static
|
||||
{
|
||||
return $this->afterCreating(function ($user) {
|
||||
$team = Team::factory()->personal()->create([
|
||||
'name' => $user->name."'s Team",
|
||||
]);
|
||||
|
||||
$team->members()->attach($user, [
|
||||
'role' => TeamRole::Owner->value,
|
||||
]);
|
||||
|
||||
$user->switchTeam($team);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model has two-factor authentication configured.
|
||||
*/
|
||||
public function withTwoFactor(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'two_factor_secret' => encrypt('secret'),
|
||||
'two_factor_recovery_codes' => encrypt(json_encode(['recovery-code-1'])),
|
||||
'two_factor_confirmed_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user