feat: implement staff management and subscription system

- Added StaffController for managing clinic staff, including listing, creating, updating, and toggling staff status.
- Created ClinicStaff entity and repository for staff data handling.
- Developed SubscriptionController to manage subscription plans and periods, including trial subscriptions.
- Introduced SubscriptionPlan, SubscriptionPeriod, and ClinicSubscription entities for subscription management.
- Implemented SubscriptionService for handling subscription logic, including trial activation and subscription creation from payments.
- Added necessary repositories for subscription entities to facilitate data access and manipulation.
This commit is contained in:
hamed
2026-06-14 22:10:28 +03:30
parent dcd631f503
commit b0244f28f5
53 changed files with 4434 additions and 40 deletions
+35
View File
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260614181134 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE clinic_staff (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, entity_type VARCHAR(10) NOT NULL, entity_id INT NOT NULL, full_name VARCHAR(200) NOT NULL, phone VARCHAR(20) DEFAULT NULL, job_title VARCHAR(100) DEFAULT NULL, address LONGTEXT DEFAULT NULL, national_code VARCHAR(10) DEFAULT NULL, active TINYINT NOT NULL, created_at INT NOT NULL, updated_at INT NOT NULL, UNIQUE INDEX UNIQ_CBEA5AA1D17F50A6 (uuid), INDEX idx_staff_entity_active (entity_type, entity_id, active), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('ALTER TABLE doctor_addresses DROP FOREIGN KEY `FK_doctor_addr_clinic`');
$this->addSql('ALTER TABLE doctor_addresses CHANGE type type VARCHAR(10) NOT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE clinic_staff');
$this->addSql('ALTER TABLE doctor_addresses CHANGE type type VARCHAR(10) DEFAULT \'personal\' NOT NULL');
$this->addSql('ALTER TABLE doctor_addresses ADD CONSTRAINT `FK_doctor_addr_clinic` FOREIGN KEY (clinic_id) REFERENCES clinics (id) ON DELETE CASCADE');
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260614181629 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE clinic_subscriptions (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, entity_type VARCHAR(10) NOT NULL, entity_id INT NOT NULL, is_trial TINYINT NOT NULL, starts_at INT NOT NULL, expires_at INT DEFAULT NULL, created_at INT NOT NULL, plan_id INT NOT NULL, period_id INT NOT NULL, payment_id INT DEFAULT NULL, UNIQUE INDEX UNIQ_E4D1CC0FD17F50A6 (uuid), INDEX IDX_E4D1CC0FE899029B (plan_id), INDEX IDX_E4D1CC0FEC8B7ADE (period_id), INDEX IDX_E4D1CC0F4C3A3BB (payment_id), INDEX idx_subscription_entity_expires (entity_type, entity_id, expires_at), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE subscription_periods (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, label VARCHAR(50) NOT NULL, duration_months SMALLINT NOT NULL, price_rials INT NOT NULL, is_trial TINYINT NOT NULL, active TINYINT NOT NULL, sort_order SMALLINT NOT NULL, created_at INT NOT NULL, updated_at INT NOT NULL, plan_id INT NOT NULL, UNIQUE INDEX UNIQ_14027839D17F50A6 (uuid), INDEX IDX_14027839E899029B (plan_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE subscription_plans (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, name VARCHAR(30) NOT NULL, level SMALLINT NOT NULL, max_secretaries SMALLINT NOT NULL, features JSON NOT NULL, active TINYINT NOT NULL, created_at INT NOT NULL, updated_at INT NOT NULL, UNIQUE INDEX UNIQ_CF5F99A2D17F50A6 (uuid), UNIQUE INDEX UNIQ_CF5F99A25E237E06 (name), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('ALTER TABLE clinic_subscriptions ADD CONSTRAINT FK_E4D1CC0FE899029B FOREIGN KEY (plan_id) REFERENCES subscription_plans (id)');
$this->addSql('ALTER TABLE clinic_subscriptions ADD CONSTRAINT FK_E4D1CC0FEC8B7ADE FOREIGN KEY (period_id) REFERENCES subscription_periods (id)');
$this->addSql('ALTER TABLE clinic_subscriptions ADD CONSTRAINT FK_E4D1CC0F4C3A3BB FOREIGN KEY (payment_id) REFERENCES payments (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE subscription_periods ADD CONSTRAINT FK_14027839E899029B FOREIGN KEY (plan_id) REFERENCES subscription_plans (id)');
$this->addSql('ALTER TABLE payments ADD metadata JSON DEFAULT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE clinic_subscriptions DROP FOREIGN KEY FK_E4D1CC0FE899029B');
$this->addSql('ALTER TABLE clinic_subscriptions DROP FOREIGN KEY FK_E4D1CC0FEC8B7ADE');
$this->addSql('ALTER TABLE clinic_subscriptions DROP FOREIGN KEY FK_E4D1CC0F4C3A3BB');
$this->addSql('ALTER TABLE subscription_periods DROP FOREIGN KEY FK_14027839E899029B');
$this->addSql('DROP TABLE clinic_subscriptions');
$this->addSql('DROP TABLE subscription_periods');
$this->addSql('DROP TABLE subscription_plans');
$this->addSql('ALTER TABLE payments DROP metadata');
}
}
+84
View File
@@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\Uid\Uuid;
final class Version20260614181657 extends AbstractMigration
{
public function getDescription(): string
{
return 'Seed subscription plans and trial periods';
}
public function up(Schema $schema): void
{
$now = time();
// Plans
$freePlanUuid = Uuid::v4()->toRfc4122();
$basicPlanUuid = Uuid::v4()->toRfc4122();
$professionalPlanUuid = Uuid::v4()->toRfc4122();
$this->addSql("INSERT INTO subscription_plans (uuid, name, level, max_secretaries, features, active, created_at, updated_at) VALUES
('{$freePlanUuid}', 'free', 0, 1, '{\"patient_records\":false,\"services\":false,\"sms_panel\":false}', 1, {$now}, {$now}),
('{$basicPlanUuid}', 'basic', 1, 3, '{\"patient_records\":true,\"services\":true,\"sms_panel\":false}', 1, {$now}, {$now}),
('{$professionalPlanUuid}', 'professional', 2, 10,'{\"patient_records\":true,\"services\":true,\"sms_panel\":true}', 1, {$now}, {$now})
");
// Periods for basic plan: trial (7 days = 1/4 month), 1-month, 3-month, 12-month
$this->addSql("
INSERT INTO subscription_periods (uuid, plan_id, label, duration_months, price_rials, is_trial, active, sort_order, created_at, updated_at)
SELECT '" . Uuid::v4()->toRfc4122() . "', id, 'تریال ۷ روزه', 1, 0, 1, 1, 0, {$now}, {$now} FROM subscription_plans WHERE name = 'basic'
");
// Professional trial
$this->addSql("
INSERT INTO subscription_periods (uuid, plan_id, label, duration_months, price_rials, is_trial, active, sort_order, created_at, updated_at)
SELECT '" . Uuid::v4()->toRfc4122() . "', id, 'تریال ۷ روزه', 1, 0, 1, 1, 0, {$now}, {$now} FROM subscription_plans WHERE name = 'professional'
");
// Basic paid periods
$this->addSql("
INSERT INTO subscription_periods (uuid, plan_id, label, duration_months, price_rials, is_trial, active, sort_order, created_at, updated_at)
SELECT '" . Uuid::v4()->toRfc4122() . "', id, 'یک ماهه', 1, 290000, 0, 1, 1, {$now}, {$now} FROM subscription_plans WHERE name = 'basic'
");
$this->addSql("
INSERT INTO subscription_periods (uuid, plan_id, label, duration_months, price_rials, is_trial, active, sort_order, created_at, updated_at)
SELECT '" . Uuid::v4()->toRfc4122() . "', id, 'سه ماهه', 3, 790000, 0, 1, 2, {$now}, {$now} FROM subscription_plans WHERE name = 'basic'
");
$this->addSql("
INSERT INTO subscription_periods (uuid, plan_id, label, duration_months, price_rials, is_trial, active, sort_order, created_at, updated_at)
SELECT '" . Uuid::v4()->toRfc4122() . "', id, 'یک ساله', 12, 2900000, 0, 1, 3, {$now}, {$now} FROM subscription_plans WHERE name = 'basic'
");
// Professional paid periods
$this->addSql("
INSERT INTO subscription_periods (uuid, plan_id, label, duration_months, price_rials, is_trial, active, sort_order, created_at, updated_at)
SELECT '" . Uuid::v4()->toRfc4122() . "', id, 'یک ماهه', 1, 590000, 0, 1, 1, {$now}, {$now} FROM subscription_plans WHERE name = 'professional'
");
$this->addSql("
INSERT INTO subscription_periods (uuid, plan_id, label, duration_months, price_rials, is_trial, active, sort_order, created_at, updated_at)
SELECT '" . Uuid::v4()->toRfc4122() . "', id, 'سه ماهه', 3, 1590000, 0, 1, 2, {$now}, {$now} FROM subscription_plans WHERE name = 'professional'
");
$this->addSql("
INSERT INTO subscription_periods (uuid, plan_id, label, duration_months, price_rials, is_trial, active, sort_order, created_at, updated_at)
SELECT '" . Uuid::v4()->toRfc4122() . "', id, 'یک ساله', 12, 5900000, 0, 1, 3, {$now}, {$now} FROM subscription_plans WHERE name = 'professional'
");
// SiteConfig: trial_enabled
$this->addSql("INSERT IGNORE INTO site_config (config_key, config_value) VALUES ('trial_enabled', '1')");
$this->addSql("INSERT IGNORE INTO site_config (config_key, config_value) VALUES ('sms_price_rials', '500')");
}
public function down(Schema $schema): void
{
$this->addSql("DELETE FROM subscription_periods");
$this->addSql("DELETE FROM subscription_plans");
$this->addSql("DELETE FROM site_config WHERE config_key IN ('trial_enabled', 'sms_price_rials')");
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260614182549 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE service_items (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, name VARCHAR(200) NOT NULL, price_rials INT NOT NULL, active TINYINT NOT NULL, created_at INT NOT NULL, updated_at INT NOT NULL, section_id INT NOT NULL, staff_id INT DEFAULT NULL, UNIQUE INDEX UNIQ_486C04AAD17F50A6 (uuid), INDEX IDX_486C04AAD823E37A (section_id), INDEX IDX_486C04AAD4D57CD (staff_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE service_sections (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, entity_type VARCHAR(10) NOT NULL, entity_id INT NOT NULL, name VARCHAR(200) NOT NULL, active TINYINT NOT NULL, created_at INT NOT NULL, updated_at INT NOT NULL, UNIQUE INDEX UNIQ_D2E018A5D17F50A6 (uuid), INDEX idx_service_section_entity (entity_type, entity_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('ALTER TABLE service_items ADD CONSTRAINT FK_486C04AAD823E37A FOREIGN KEY (section_id) REFERENCES service_sections (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE service_items ADD CONSTRAINT FK_486C04AAD4D57CD FOREIGN KEY (staff_id) REFERENCES clinic_staff (id) ON DELETE SET NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE service_items DROP FOREIGN KEY FK_486C04AAD823E37A');
$this->addSql('ALTER TABLE service_items DROP FOREIGN KEY FK_486C04AAD4D57CD');
$this->addSql('DROP TABLE service_items');
$this->addSql('DROP TABLE service_sections');
}
}
+39
View File
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260614182950 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE sms_settings (id INT AUTO_INCREMENT NOT NULL, entity_type VARCHAR(10) NOT NULL, entity_id INT NOT NULL, reminder_enabled TINYINT NOT NULL, reminder_hours_before SMALLINT NOT NULL, post_visit_enabled TINYINT NOT NULL, post_visit_text LONGTEXT DEFAULT NULL, updated_at INT NOT NULL, UNIQUE INDEX uniq_sms_settings_entity (entity_type, entity_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE sms_wallet_transactions (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, type VARCHAR(10) NOT NULL, amount_rials INT NOT NULL, description VARCHAR(255) DEFAULT NULL, created_at INT NOT NULL, wallet_id INT NOT NULL, payment_id INT DEFAULT NULL, UNIQUE INDEX UNIQ_377BA1E0D17F50A6 (uuid), INDEX IDX_377BA1E0712520F3 (wallet_id), INDEX IDX_377BA1E04C3A3BB (payment_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE sms_wallets (id INT AUTO_INCREMENT NOT NULL, entity_type VARCHAR(10) NOT NULL, entity_id INT NOT NULL, balance_rials INT NOT NULL, created_at INT NOT NULL, updated_at INT NOT NULL, UNIQUE INDEX uniq_sms_wallet_entity (entity_type, entity_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('ALTER TABLE sms_wallet_transactions ADD CONSTRAINT FK_377BA1E0712520F3 FOREIGN KEY (wallet_id) REFERENCES sms_wallets (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE sms_wallet_transactions ADD CONSTRAINT FK_377BA1E04C3A3BB FOREIGN KEY (payment_id) REFERENCES payments (id) ON DELETE SET NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE sms_wallet_transactions DROP FOREIGN KEY FK_377BA1E0712520F3');
$this->addSql('ALTER TABLE sms_wallet_transactions DROP FOREIGN KEY FK_377BA1E04C3A3BB');
$this->addSql('DROP TABLE sms_settings');
$this->addSql('DROP TABLE sms_wallet_transactions');
$this->addSql('DROP TABLE sms_wallets');
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260614183527 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE patient_records (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, entity_type VARCHAR(10) NOT NULL, entity_id INT NOT NULL, created_by_type VARCHAR(15) NOT NULL, created_by_id INT NOT NULL, created_at INT NOT NULL, user_id INT NOT NULL, UNIQUE INDEX UNIQ_C1FE0DADD17F50A6 (uuid), INDEX IDX_C1FE0DADA76ED395 (user_id), UNIQUE INDEX uniq_patient_record (entity_type, entity_id, user_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE patient_sessions (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, insurance_base_id INT DEFAULT NULL, insurance_supplementary_id INT DEFAULT NULL, visit_price_rials INT NOT NULL, base_insurance_discount_percent NUMERIC(5, 2) NOT NULL, supplementary_discount_percent NUMERIC(5, 2) NOT NULL, services_total_rials INT NOT NULL, final_price_rials INT NOT NULL, payment_method VARCHAR(15) NOT NULL, notes LONGTEXT DEFAULT NULL, created_at INT NOT NULL, updated_at INT NOT NULL, record_id INT NOT NULL, appointment_id INT DEFAULT NULL, UNIQUE INDEX UNIQ_ADE5C5B6D17F50A6 (uuid), INDEX IDX_ADE5C5B64DFD750C (record_id), INDEX IDX_ADE5C5B6E5B533F9 (appointment_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE session_services (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, price_rials INT NOT NULL, created_at INT NOT NULL, session_id INT NOT NULL, service_item_id INT NOT NULL, staff_id INT DEFAULT NULL, UNIQUE INDEX UNIQ_F89E8101D17F50A6 (uuid), INDEX IDX_F89E8101613FECDF (session_id), INDEX IDX_F89E8101DDEB00C2 (service_item_id), INDEX IDX_F89E8101D4D57CD (staff_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('ALTER TABLE patient_records ADD CONSTRAINT FK_C1FE0DADA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE RESTRICT');
$this->addSql('ALTER TABLE patient_sessions ADD CONSTRAINT FK_ADE5C5B64DFD750C FOREIGN KEY (record_id) REFERENCES patient_records (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE patient_sessions ADD CONSTRAINT FK_ADE5C5B6E5B533F9 FOREIGN KEY (appointment_id) REFERENCES appointments (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE session_services ADD CONSTRAINT FK_F89E8101613FECDF FOREIGN KEY (session_id) REFERENCES patient_sessions (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE session_services ADD CONSTRAINT FK_F89E8101DDEB00C2 FOREIGN KEY (service_item_id) REFERENCES service_items (id) ON DELETE RESTRICT');
$this->addSql('ALTER TABLE session_services ADD CONSTRAINT FK_F89E8101D4D57CD FOREIGN KEY (staff_id) REFERENCES clinic_staff (id) ON DELETE SET NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE patient_records DROP FOREIGN KEY FK_C1FE0DADA76ED395');
$this->addSql('ALTER TABLE patient_sessions DROP FOREIGN KEY FK_ADE5C5B64DFD750C');
$this->addSql('ALTER TABLE patient_sessions DROP FOREIGN KEY FK_ADE5C5B6E5B533F9');
$this->addSql('ALTER TABLE session_services DROP FOREIGN KEY FK_F89E8101613FECDF');
$this->addSql('ALTER TABLE session_services DROP FOREIGN KEY FK_F89E8101DDEB00C2');
$this->addSql('ALTER TABLE session_services DROP FOREIGN KEY FK_F89E8101D4D57CD');
$this->addSql('DROP TABLE patient_records');
$this->addSql('DROP TABLE patient_sessions');
$this->addSql('DROP TABLE session_services');
}
}