vendor/bluue/recurring-invoices-bundle/migrations/Version20221207104305.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace RecurringInvoicesBundleMigrations;
  4. use App\Services\ObjectSerialize;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\Migrations\AbstractMigration;
  7. use Symfony\Component\Uid\UuidV6;
  8. final class Version20221207104305 extends AbstractMigration
  9. {
  10.     private ObjectSerialize $objectSerialize;
  11.     public function setObjectSerialize(ObjectSerialize $objectSerialize)
  12.     {
  13.         $this->objectSerialize $objectSerialize;
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $this->addSql('CREATE TABLE recurring_invoices_bundle__recurring_invoice (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', context_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', customer_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', invoice_address_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', delivery_address_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', currency_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', payment_term_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', canceled_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', created_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', updated_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', deleted_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', currency_change_rate NUMERIC(20, 12) NOT NULL, reference VARCHAR(255) DEFAULT NULL, internal_name VARCHAR(255) DEFAULT NULL, external_name VARCHAR(255) DEFAULT NULL, reduced_vat TINYINT(1) NOT NULL, total_discount_untaxed NUMERIC(20, 6) DEFAULT NULL, total_amount_no_discount_untaxed NUMERIC(20, 6) DEFAULT NULL, total_amount_untaxed NUMERIC(20, 6) DEFAULT NULL, total_tax_amount NUMERIC(20, 6) DEFAULT NULL, total_amount NUMERIC(20, 6) DEFAULT NULL, last_invoice_generation DATE DEFAULT NULL, next_invoice_generation DATE DEFAULT NULL, daily_recurrence INT DEFAULT NULL, monthly_recurrence INT DEFAULT NULL, annual_recurrence INT DEFAULT NULL, max_invoices INT DEFAULT NULL, auto_validation TINYINT(1) NOT NULL, finished TINYINT(1) NOT NULL, options JSON NOT NULL, is_active TINYINT(1) DEFAULT 1 NOT NULL, canceled_at DATETIME DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_6B9712E6B00C1CF (context_id), INDEX IDX_6B9712E9395C3F3 (customer_id), INDEX IDX_6B9712EC6BDFEB (invoice_address_id), INDEX IDX_6B9712EEBF23851 (delivery_address_id), INDEX IDX_6B9712E38248176 (currency_id), INDEX IDX_6B9712E17653B16 (payment_term_id), INDEX IDX_6B9712E1418957 (canceled_by_id), INDEX IDX_6B9712EB03A8386 (created_by_id), INDEX IDX_6B9712E896DBBDE (updated_by_id), INDEX IDX_6B9712EC76F1F52 (deleted_by_id), INDEX internal_name (internal_name), INDEX total_amount_untaxed (total_amount_untaxed), INDEX total_amount (total_amount), INDEX is_active (is_active), INDEX canceled_at (canceled_at), INDEX deleted_at (deleted_at), INDEX created_at (created_at), INDEX updated_at (updated_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  18.         $this->addSql('CREATE TABLE recurring_invoices_bundle__recurring_invoice_line (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', recurring_invoice_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', line_type_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', tax_rule_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', parent_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', created_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', updated_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', deleted_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', is_group TINYINT(1) NOT NULL, reference VARCHAR(128) DEFAULT NULL, reference_brand VARCHAR(128) DEFAULT NULL, name VARCHAR(255) DEFAULT NULL, description LONGTEXT DEFAULT NULL, unit_price NUMERIC(20, 6) DEFAULT NULL, quantity NUMERIC(20, 6) DEFAULT NULL, wholesale_price NUMERIC(20, 6) DEFAULT NULL, margin_ratio NUMERIC(20, 6) DEFAULT NULL, percentage_discount_untaxed NUMERIC(20, 6) DEFAULT NULL, total_discount_untaxed NUMERIC(20, 6) DEFAULT NULL, total_amount_no_discount_untaxed NUMERIC(20, 6) DEFAULT NULL, total_amount_untaxed NUMERIC(20, 6) DEFAULT NULL, total_tax_amount NUMERIC(20, 6) DEFAULT NULL, total_amount NUMERIC(20, 6) DEFAULT NULL, position INT NOT NULL, options JSON NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_BD96F0689F85F85C (recurring_invoice_id), INDEX IDX_BD96F06870E80DF4 (line_type_id), INDEX IDX_BD96F0683506A35B (tax_rule_id), INDEX IDX_BD96F068727ACA70 (parent_id), INDEX IDX_BD96F068B03A8386 (created_by_id), INDEX IDX_BD96F068896DBBDE (updated_by_id), INDEX IDX_BD96F068C76F1F52 (deleted_by_id), INDEX deleted_at (deleted_at), INDEX created_at (created_at), INDEX updated_at (updated_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  19.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712E6B00C1CF FOREIGN KEY (context_id) REFERENCES context (id)');
  20.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712E9395C3F3 FOREIGN KEY (customer_id) REFERENCES customers_bundle__customer (id)');
  21.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712EC6BDFEB FOREIGN KEY (invoice_address_id) REFERENCES customers_bundle__customer (id)');
  22.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712EEBF23851 FOREIGN KEY (delivery_address_id) REFERENCES customers_bundle__customer (id)');
  23.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712E38248176 FOREIGN KEY (currency_id) REFERENCES currency (id)');
  24.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712E17653B16 FOREIGN KEY (payment_term_id) REFERENCES sales_bundle__payment_term (id)');
  25.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712E1418957 FOREIGN KEY (canceled_by_id) REFERENCES user (id)');
  26.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712EB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  27.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712E896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  28.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712EC76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  29.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line ADD CONSTRAINT FK_BD96F0689F85F85C FOREIGN KEY (recurring_invoice_id) REFERENCES recurring_invoices_bundle__recurring_invoice (id)');
  30.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line ADD CONSTRAINT FK_BD96F06870E80DF4 FOREIGN KEY (line_type_id) REFERENCES sales_bundle__line_type (id)');
  31.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line ADD CONSTRAINT FK_BD96F0683506A35B FOREIGN KEY (tax_rule_id) REFERENCES tax_rule (id)');
  32.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line ADD CONSTRAINT FK_BD96F068727ACA70 FOREIGN KEY (parent_id) REFERENCES recurring_invoices_bundle__recurring_invoice_line (id)');
  33.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line ADD CONSTRAINT FK_BD96F068B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  34.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line ADD CONSTRAINT FK_BD96F068896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  35.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line ADD CONSTRAINT FK_BD96F068C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  36.         $this->addSql('ALTER TABLE sales_bundle__invoice ADD recurring_invoice_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\'');
  37.         $this->addSql('ALTER TABLE sales_bundle__invoice ADD CONSTRAINT FK_BB8C2B4C9F85F85C FOREIGN KEY (recurring_invoice_id) REFERENCES recurring_invoices_bundle__recurring_invoice (id)');
  38.         $this->addSql('CREATE INDEX IDX_BB8C2B4C9F85F85C ON sales_bundle__invoice (recurring_invoice_id)');
  39.     }
  40.     public function down(Schema $schema): void
  41.     {
  42.         $this->addSql('ALTER TABLE sales_bundle__invoice DROP FOREIGN KEY FK_BB8C2B4C9F85F85C');
  43.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712E6B00C1CF');
  44.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712E9395C3F3');
  45.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712EC6BDFEB');
  46.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712EEBF23851');
  47.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712E38248176');
  48.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712E17653B16');
  49.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712E1418957');
  50.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712EB03A8386');
  51.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712E896DBBDE');
  52.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712EC76F1F52');
  53.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line DROP FOREIGN KEY FK_BD96F0689F85F85C');
  54.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line DROP FOREIGN KEY FK_BD96F06870E80DF4');
  55.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line DROP FOREIGN KEY FK_BD96F0683506A35B');
  56.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line DROP FOREIGN KEY FK_BD96F068727ACA70');
  57.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line DROP FOREIGN KEY FK_BD96F068B03A8386');
  58.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line DROP FOREIGN KEY FK_BD96F068896DBBDE');
  59.         $this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line DROP FOREIGN KEY FK_BD96F068C76F1F52');
  60.         $this->addSql('DROP TABLE recurring_invoices_bundle__recurring_invoice');
  61.         $this->addSql('DROP TABLE recurring_invoices_bundle__recurring_invoice_line');
  62.         $this->addSql('DROP INDEX IDX_BB8C2B4C9F85F85C ON sales_bundle__invoice');
  63.         $this->addSql('ALTER TABLE sales_bundle__invoice DROP recurring_invoice_id');
  64.     }
  65.     public function postUp(Schema $schema): void
  66.     {
  67.         parent::postUp($schema);
  68.         $now = (new \DateTime())->format('Y-m-d H:i:s');
  69.         $configurations = [
  70.             'recurring_invoices_bundle__reference_format' => 'FA-REC/[[number]]',
  71.             'recurring_invoices_bundle__automatic_invoice_validation_default' => true
  72.         ];
  73.         foreach ($configurations as $configuration => $value) {
  74.             $this->connection->insert('configuration', [
  75.                 'id' => (new UuidV6())->toBinary(),
  76.                 'name' => $configuration,
  77.                 'context_id' => null,
  78.                 'value' => $this->objectSerialize->add((object) ['value' => $value]),
  79.                 'created_at' => $now,
  80.                 'updated_at' => $now
  81.             ]);
  82.         }
  83.         $this->connection->insert('cron_job', [
  84.             'name' => 'recurring-invoices-check-generation',
  85.             'command' => 'bluue-bundle:recurring-invoices:check-generation',
  86.             'schedule' => '0 6 * * *',
  87.             'description' => '',
  88.             'enabled' => 1
  89.         ]);
  90.     }
  91. }