first commit
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled

This commit is contained in:
brusnitsyn
2026-04-06 00:06:00 +09:00
commit fb2e6c58e3
409 changed files with 42953 additions and 0 deletions

1
database/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.sqlite*

View 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,
]);
}
}

View 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(),
];
}
}

View 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(),
];
}
}

View 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),
];
}
}

View 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,
]);
}
}

View 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,
];
}
}

View 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),
];
}
}

View 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(),
]);
}
}

View 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),
]);
}
}

View 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(),
]);
}
}

View File

@@ -0,0 +1,49 @@
<?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('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->longText('payload');
$table->integer('last_activity')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
Schema::dropIfExists('password_reset_tokens');
Schema::dropIfExists('sessions');
}
};

View File

@@ -0,0 +1,35 @@
<?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('cache', function (Blueprint $table) {
$table->string('key')->primary();
$table->mediumText('value');
$table->integer('expiration')->index();
});
Schema::create('cache_locks', function (Blueprint $table) {
$table->string('key')->primary();
$table->string('owner');
$table->integer('expiration')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('cache');
Schema::dropIfExists('cache_locks');
}
};

View File

@@ -0,0 +1,57 @@
<?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('jobs', function (Blueprint $table) {
$table->id();
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
Schema::create('job_batches', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->integer('total_jobs');
$table->integer('pending_jobs');
$table->integer('failed_jobs');
$table->longText('failed_job_ids');
$table->mediumText('options')->nullable();
$table->integer('cancelled_at')->nullable();
$table->integer('created_at');
$table->integer('finished_at')->nullable();
});
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('jobs');
Schema::dropIfExists('job_batches');
Schema::dropIfExists('failed_jobs');
}
};

View File

@@ -0,0 +1,34 @@
<?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('users', function (Blueprint $table) {
$table->text('two_factor_secret')->after('password')->nullable();
$table->text('two_factor_recovery_codes')->after('two_factor_secret')->nullable();
$table->timestamp('two_factor_confirmed_at')->after('two_factor_recovery_codes')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn([
'two_factor_secret',
'two_factor_recovery_codes',
'two_factor_confirmed_at',
]);
});
}
};

View File

@@ -0,0 +1,55 @@
<?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('teams', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->boolean('is_personal')->default(false);
$table->timestamps();
$table->softDeletes();
});
Schema::create('team_members', function (Blueprint $table) {
$table->id();
$table->foreignId('team_id')->constrained()->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('role');
$table->timestamps();
$table->unique(['team_id', 'user_id']);
});
Schema::create('team_invitations', function (Blueprint $table) {
$table->id();
$table->string('code', 64)->unique();
$table->foreignId('team_id')->constrained()->cascadeOnDelete();
$table->string('email');
$table->string('role');
$table->foreignId('invited_by')->constrained('users')->cascadeOnDelete();
$table->timestamp('expires_at')->nullable();
$table->timestamp('accepted_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('team_invitations');
Schema::dropIfExists('team_members');
Schema::dropIfExists('teams');
}
};

View File

@@ -0,0 +1,32 @@
<?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('users', function (Blueprint $table) {
$table->foreignId('current_team_id')
->nullable()
->after('password')
->constrained('teams')
->nullOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropConstrainedForeignId('current_team_id');
});
}
};

View File

@@ -0,0 +1,28 @@
<?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('department_profiles', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('department_profiles');
}
};

View File

@@ -0,0 +1,30 @@
<?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('departments', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->boolean('is_active')->default(true);
$table->foreignIdFor(\App\Models\DepartmentProfile::class)->constrained();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('departments');
}
};

View File

@@ -0,0 +1,34 @@
<?php
use App\Models\Team;
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('report_periods', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(Team::class)->constrained()->cascadeOnDelete();
$table->unsignedSmallInteger('year');
$table->unsignedTinyInteger('month');
$table->string('status', 20)->default('draft');
$table->timestamps();
$table->unique(['team_id', 'year', 'month']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('report_periods');
}
};

View File

@@ -0,0 +1,33 @@
<?php
use App\Models\Department;
use App\Models\ReportPeriod;
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('medication_expense_rows', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(ReportPeriod::class)->constrained()->cascadeOnDelete();
$table->foreignIdFor(Department::class)->constrained()->cascadeOnDelete();
$table->timestamps();
$table->unique(['report_period_id', 'department_id']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('medication_expense_rows');
}
};

View File

@@ -0,0 +1,34 @@
<?php
use App\Models\MedicationExpenseRow;
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('medication_expense_values', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(MedicationExpenseRow::class)->constrained()->cascadeOnDelete();
$table->string('funding_source', 30);
$table->string('expense_category', 30);
$table->decimal('amount', 14, 2)->default(0);
$table->timestamps();
$table->unique(['medication_expense_row_id', 'funding_source', 'expense_category'], 'medication_expense_values_unique');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('medication_expense_values');
}
};

View File

@@ -0,0 +1,33 @@
<?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('service_catalogs', function (Blueprint $table) {
$table->id();
$table->string('code')->unique();
$table->string('name');
$table->string('unit', 50)->nullable();
$table->decimal('default_price', 14, 2)->default(0);
$table->unsignedInteger('sort_order')->default(0);
$table->boolean('is_active')->default(true);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('service_catalogs');
}
};

View File

@@ -0,0 +1,41 @@
<?php
use App\Models\Department;
use App\Models\ReportPeriod;
use App\Models\ServiceCatalog;
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('service_entries', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(ReportPeriod::class)->constrained()->cascadeOnDelete();
$table->foreignIdFor(ServiceCatalog::class)->constrained()->cascadeOnDelete();
$table->foreignIdFor(Department::class, 'provider_department_id')->constrained('departments')->cascadeOnDelete();
$table->foreignIdFor(Department::class, 'recipient_department_id')->constrained('departments')->cascadeOnDelete();
$table->decimal('quantity', 14, 2)->default(0);
$table->decimal('unit_price', 14, 2)->default(0);
$table->timestamps();
$table->unique(
['report_period_id', 'service_catalog_id', 'provider_department_id', 'recipient_department_id'],
'service_entries_unique'
);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('service_entries');
}
};

View File

@@ -0,0 +1,23 @@
<?php
namespace Database\Seeders;
use App\Models\User;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
// User::factory(10)->create();
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
]);
}
}