|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace DoctrineMigrations; |
| 6 | + |
| 7 | +use Doctrine\DBAL\Schema\Schema; |
| 8 | +use Doctrine\Migrations\AbstractMigration; |
| 9 | + |
| 10 | +final class Version20260422130000 extends AbstractMigration |
| 11 | +{ |
| 12 | + public function getDescription(): string |
| 13 | + { |
| 14 | + return 'Add price_components for split-VAT packages, optional revenue_account overrides on prices, price_components, invoice_positions and invoice_appartments, plus accounting_settings labels for booking journal remarks.'; |
| 15 | + } |
| 16 | + |
| 17 | + public function up(Schema $schema): void |
| 18 | + { |
| 19 | + $this->addSql('CREATE TABLE price_components ( |
| 20 | + id INT AUTO_INCREMENT NOT NULL, |
| 21 | + price_id INT NOT NULL, |
| 22 | + revenue_account_id INT DEFAULT NULL, |
| 23 | + description VARCHAR(100) NOT NULL, |
| 24 | + vat NUMERIC(10, 2) NOT NULL, |
| 25 | + allocation_type VARCHAR(16) NOT NULL, |
| 26 | + allocation_value NUMERIC(10, 4) NOT NULL, |
| 27 | + is_remainder TINYINT(1) NOT NULL, |
| 28 | + sort_order SMALLINT NOT NULL, |
| 29 | + INDEX IDX_PRICE_COMPONENTS_PRICE (price_id), |
| 30 | + INDEX IDX_PRICE_COMPONENTS_REVENUE_ACCOUNT (revenue_account_id), |
| 31 | + PRIMARY KEY(id) |
| 32 | + ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); |
| 33 | + |
| 34 | + $this->addSql('ALTER TABLE price_components |
| 35 | + ADD CONSTRAINT FK_PRICE_COMPONENTS_PRICE FOREIGN KEY (price_id) REFERENCES prices (id) ON DELETE CASCADE'); |
| 36 | + $this->addSql('ALTER TABLE price_components |
| 37 | + ADD CONSTRAINT FK_PRICE_COMPONENTS_REVENUE_ACCOUNT FOREIGN KEY (revenue_account_id) REFERENCES accounting_accounts (id) ON DELETE SET NULL'); |
| 38 | + |
| 39 | + $this->addSql('ALTER TABLE prices ADD revenue_account_id INT DEFAULT NULL'); |
| 40 | + $this->addSql('ALTER TABLE prices |
| 41 | + ADD CONSTRAINT FK_PRICES_REVENUE_ACCOUNT FOREIGN KEY (revenue_account_id) REFERENCES accounting_accounts (id) ON DELETE SET NULL'); |
| 42 | + $this->addSql('CREATE INDEX IDX_PRICES_REVENUE_ACCOUNT ON prices (revenue_account_id)'); |
| 43 | + |
| 44 | + $this->addSql('ALTER TABLE invoice_positions ADD revenue_account_id INT DEFAULT NULL'); |
| 45 | + $this->addSql('ALTER TABLE invoice_positions |
| 46 | + ADD CONSTRAINT FK_INVOICE_POSITIONS_REVENUE_ACCOUNT FOREIGN KEY (revenue_account_id) REFERENCES accounting_accounts (id) ON DELETE SET NULL'); |
| 47 | + $this->addSql('CREATE INDEX IDX_INVOICE_POSITIONS_REVENUE_ACCOUNT ON invoice_positions (revenue_account_id)'); |
| 48 | + |
| 49 | + $this->addSql('ALTER TABLE invoice_appartments ADD revenue_account_id INT DEFAULT NULL'); |
| 50 | + $this->addSql('ALTER TABLE invoice_appartments |
| 51 | + ADD CONSTRAINT FK_INVOICE_APPARTMENTS_REVENUE_ACCOUNT FOREIGN KEY (revenue_account_id) REFERENCES accounting_accounts (id) ON DELETE SET NULL'); |
| 52 | + $this->addSql('CREATE INDEX IDX_INVOICE_APPARTMENTS_REVENUE_ACCOUNT ON invoice_appartments (revenue_account_id)'); |
| 53 | + |
| 54 | + $this->addSql('ALTER TABLE accounting_settings |
| 55 | + ADD main_position_label VARCHAR(60) DEFAULT NULL, |
| 56 | + ADD misc_position_label VARCHAR(60) DEFAULT NULL'); |
| 57 | + |
| 58 | + // Prevent deleting tax rates and accounting accounts from clearing references on booking journal entries. |
| 59 | + $this->addSql('ALTER TABLE booking_entries DROP FOREIGN KEY FK_be_debit'); |
| 60 | + $this->addSql('ALTER TABLE booking_entries DROP FOREIGN KEY FK_be_credit'); |
| 61 | + $this->addSql('ALTER TABLE booking_entries DROP FOREIGN KEY FK_be_taxrate'); |
| 62 | + |
| 63 | + $this->addSql('ALTER TABLE booking_entries |
| 64 | + ADD CONSTRAINT FK_be_debit FOREIGN KEY (debit_account_id) REFERENCES accounting_accounts (id)'); |
| 65 | + $this->addSql('ALTER TABLE booking_entries |
| 66 | + ADD CONSTRAINT FK_be_credit FOREIGN KEY (credit_account_id) REFERENCES accounting_accounts (id)'); |
| 67 | + $this->addSql('ALTER TABLE booking_entries |
| 68 | + ADD CONSTRAINT FK_be_taxrate FOREIGN KEY (tax_rate_id) REFERENCES tax_rates (id)'); |
| 69 | + |
| 70 | + } |
| 71 | + |
| 72 | + public function down(Schema $schema): void |
| 73 | + { |
| 74 | + $this->addSql('ALTER TABLE accounting_settings |
| 75 | + DROP main_position_label, |
| 76 | + DROP misc_position_label'); |
| 77 | + |
| 78 | + $this->addSql('ALTER TABLE invoice_appartments DROP FOREIGN KEY FK_INVOICE_APPARTMENTS_REVENUE_ACCOUNT'); |
| 79 | + $this->addSql('DROP INDEX IDX_INVOICE_APPARTMENTS_REVENUE_ACCOUNT ON invoice_appartments'); |
| 80 | + $this->addSql('ALTER TABLE invoice_appartments DROP revenue_account_id'); |
| 81 | + |
| 82 | + $this->addSql('ALTER TABLE invoice_positions DROP FOREIGN KEY FK_INVOICE_POSITIONS_REVENUE_ACCOUNT'); |
| 83 | + $this->addSql('DROP INDEX IDX_INVOICE_POSITIONS_REVENUE_ACCOUNT ON invoice_positions'); |
| 84 | + $this->addSql('ALTER TABLE invoice_positions DROP revenue_account_id'); |
| 85 | + |
| 86 | + $this->addSql('ALTER TABLE prices DROP FOREIGN KEY FK_PRICES_REVENUE_ACCOUNT'); |
| 87 | + $this->addSql('DROP INDEX IDX_PRICES_REVENUE_ACCOUNT ON prices'); |
| 88 | + $this->addSql('ALTER TABLE prices DROP revenue_account_id'); |
| 89 | + |
| 90 | + $this->addSql('ALTER TABLE price_components DROP FOREIGN KEY FK_PRICE_COMPONENTS_REVENUE_ACCOUNT'); |
| 91 | + $this->addSql('ALTER TABLE price_components DROP FOREIGN KEY FK_PRICE_COMPONENTS_PRICE'); |
| 92 | + $this->addSql('DROP TABLE price_components'); |
| 93 | + |
| 94 | + $this->addSql('ALTER TABLE booking_entries DROP FOREIGN KEY FK_be_debit'); |
| 95 | + $this->addSql('ALTER TABLE booking_entries DROP FOREIGN KEY FK_be_credit'); |
| 96 | + $this->addSql('ALTER TABLE booking_entries DROP FOREIGN KEY FK_be_taxrate'); |
| 97 | + |
| 98 | + $this->addSql('ALTER TABLE booking_entries |
| 99 | + ADD CONSTRAINT FK_be_debit FOREIGN KEY (debit_account_id) REFERENCES accounting_accounts (id) ON DELETE SET NULL'); |
| 100 | + $this->addSql('ALTER TABLE booking_entries |
| 101 | + ADD CONSTRAINT FK_be_credit FOREIGN KEY (credit_account_id) REFERENCES accounting_accounts (id) ON DELETE SET NULL'); |
| 102 | + $this->addSql('ALTER TABLE booking_entries |
| 103 | + ADD CONSTRAINT FK_be_taxrate FOREIGN KEY (tax_rate_id) REFERENCES tax_rates (id) ON DELETE SET NULL'); |
| 104 | + } |
| 105 | + |
| 106 | + public function isTransactional(): bool |
| 107 | + { |
| 108 | + return false; |
| 109 | + } |
| 110 | +} |
0 commit comments