vendor/bluue/suppliers-orders-bundle/migrations/Version20221206231340.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace SuppliersOrdersBundleMigrations;
  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 Version20221206231340 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 suppliers_orders_bundle__receipt_note (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', supplier_order_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', context_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', validated_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)\', reference VARCHAR(128) DEFAULT NULL, options JSON NOT NULL, validated_at DATETIME DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_7D7418211605B9 (supplier_order_id), INDEX IDX_7D7418216B00C1CF (context_id), INDEX IDX_7D741821C69DE5E5 (validated_by_id), INDEX IDX_7D741821B03A8386 (created_by_id), INDEX IDX_7D741821896DBBDE (updated_by_id), INDEX IDX_7D741821C76F1F52 (deleted_by_id), INDEX reference (reference), INDEX validated_at (validated_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 suppliers_orders_bundle__receipt_note_line (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', receipt_note_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', supplier_order_line_id BINARY(16) NOT 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)\', quantity NUMERIC(20, 6) DEFAULT NULL, quantity_received NUMERIC(20, 6) DEFAULT NULL, options JSON NOT NULL, supplier_reference VARCHAR(255) DEFAULT NULL, wholesale_price NUMERIC(20, 6) DEFAULT NULL, price NUMERIC(20, 6) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_2C547A1E35A7ADAB (receipt_note_id), INDEX IDX_2C547A1EA9DC5CCE (supplier_order_line_id), INDEX IDX_2C547A1E727ACA70 (parent_id), INDEX IDX_2C547A1EB03A8386 (created_by_id), INDEX IDX_2C547A1E896DBBDE (updated_by_id), INDEX IDX_2C547A1EC76F1F52 (deleted_by_id), INDEX quantity (quantity), INDEX quantity_received (quantity_received), 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('CREATE TABLE suppliers_orders_bundle__supplier_order (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', context_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', supplier_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', currency_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)\', validated_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', currency_change_rate NUMERIC(20, 12) NOT NULL, reference VARCHAR(128) DEFAULT NULL, total_amount NUMERIC(20, 6) DEFAULT NULL, internal_reference VARCHAR(255) DEFAULT NULL, external_reference VARCHAR(255) DEFAULT NULL, internal_note LONGTEXT DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, validated_at DATETIME DEFAULT NULL, INDEX IDX_E63ACA816B00C1CF (context_id), INDEX IDX_E63ACA812ADD6D8C (supplier_id), INDEX IDX_E63ACA8138248176 (currency_id), INDEX IDX_E63ACA81B03A8386 (created_by_id), INDEX IDX_E63ACA81896DBBDE (updated_by_id), INDEX IDX_E63ACA81C76F1F52 (deleted_by_id), INDEX IDX_E63ACA81C69DE5E5 (validated_by_id), INDEX reference (reference), INDEX internal_reference (internal_reference), INDEX external_reference (external_reference), INDEX total_amount (total_amount), INDEX deleted_at (deleted_at), INDEX validated_at (validated_at), INDEX created_at (created_at), INDEX updated_at (updated_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  20.         $this->addSql('CREATE TABLE suppliers_orders_bundle__supplier_order_line (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', supplier_order_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', product_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', declination_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)\', supplier_reference VARCHAR(255) DEFAULT NULL, wholesale_price NUMERIC(20, 6) DEFAULT NULL, quantity NUMERIC(20, 6) DEFAULT NULL, quantity_receipted NUMERIC(20, 6) DEFAULT NULL, position INT NOT NULL, options JSON NOT NULL, total_amount NUMERIC(20, 6) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_389F67811605B9 (supplier_order_id), INDEX IDX_389F67814584665A (product_id), INDEX IDX_389F67819941A932 (declination_id), INDEX IDX_389F6781B03A8386 (created_by_id), INDEX IDX_389F6781896DBBDE (updated_by_id), INDEX IDX_389F6781C76F1F52 (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');
  21.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note ADD CONSTRAINT FK_7D7418211605B9 FOREIGN KEY (supplier_order_id) REFERENCES suppliers_orders_bundle__supplier_order (id)');
  22.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note ADD CONSTRAINT FK_7D7418216B00C1CF FOREIGN KEY (context_id) REFERENCES context (id)');
  23.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note ADD CONSTRAINT FK_7D741821C69DE5E5 FOREIGN KEY (validated_by_id) REFERENCES user (id)');
  24.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note ADD CONSTRAINT FK_7D741821B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  25.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note ADD CONSTRAINT FK_7D741821896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  26.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note ADD CONSTRAINT FK_7D741821C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  27.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line ADD CONSTRAINT FK_2C547A1E35A7ADAB FOREIGN KEY (receipt_note_id) REFERENCES suppliers_orders_bundle__receipt_note (id)');
  28.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line ADD CONSTRAINT FK_2C547A1EA9DC5CCE FOREIGN KEY (supplier_order_line_id) REFERENCES suppliers_orders_bundle__supplier_order_line (id)');
  29.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line ADD CONSTRAINT FK_2C547A1E727ACA70 FOREIGN KEY (parent_id) REFERENCES suppliers_orders_bundle__receipt_note_line (id)');
  30.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line ADD CONSTRAINT FK_2C547A1EB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  31.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line ADD CONSTRAINT FK_2C547A1E896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  32.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line ADD CONSTRAINT FK_2C547A1EC76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  33.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order ADD CONSTRAINT FK_E63ACA816B00C1CF FOREIGN KEY (context_id) REFERENCES context (id)');
  34.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order ADD CONSTRAINT FK_E63ACA812ADD6D8C FOREIGN KEY (supplier_id) REFERENCES suppliers_bundle__supplier (id)');
  35.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order ADD CONSTRAINT FK_E63ACA8138248176 FOREIGN KEY (currency_id) REFERENCES currency (id)');
  36.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order ADD CONSTRAINT FK_E63ACA81B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  37.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order ADD CONSTRAINT FK_E63ACA81896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  38.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order ADD CONSTRAINT FK_E63ACA81C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  39.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order ADD CONSTRAINT FK_E63ACA81C69DE5E5 FOREIGN KEY (validated_by_id) REFERENCES user (id)');
  40.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line ADD CONSTRAINT FK_389F67811605B9 FOREIGN KEY (supplier_order_id) REFERENCES suppliers_orders_bundle__supplier_order (id)');
  41.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line ADD CONSTRAINT FK_389F67814584665A FOREIGN KEY (product_id) REFERENCES products_bundle__product (id)');
  42.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line ADD CONSTRAINT FK_389F67819941A932 FOREIGN KEY (declination_id) REFERENCES products_bundle__declination (id)');
  43.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line ADD CONSTRAINT FK_389F6781B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  44.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line ADD CONSTRAINT FK_389F6781896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  45.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line ADD CONSTRAINT FK_389F6781C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  46.     }
  47.     public function down(Schema $schema): void
  48.     {
  49.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note DROP FOREIGN KEY FK_7D7418211605B9');
  50.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note DROP FOREIGN KEY FK_7D7418216B00C1CF');
  51.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note DROP FOREIGN KEY FK_7D741821C69DE5E5');
  52.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note DROP FOREIGN KEY FK_7D741821B03A8386');
  53.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note DROP FOREIGN KEY FK_7D741821896DBBDE');
  54.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note DROP FOREIGN KEY FK_7D741821C76F1F52');
  55.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line DROP FOREIGN KEY FK_2C547A1E35A7ADAB');
  56.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line DROP FOREIGN KEY FK_2C547A1EA9DC5CCE');
  57.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line DROP FOREIGN KEY FK_2C547A1E727ACA70');
  58.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line DROP FOREIGN KEY FK_2C547A1EB03A8386');
  59.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line DROP FOREIGN KEY FK_2C547A1E896DBBDE');
  60.         $this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line DROP FOREIGN KEY FK_2C547A1EC76F1F52');
  61.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order DROP FOREIGN KEY FK_E63ACA816B00C1CF');
  62.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order DROP FOREIGN KEY FK_E63ACA812ADD6D8C');
  63.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order DROP FOREIGN KEY FK_E63ACA8138248176');
  64.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order DROP FOREIGN KEY FK_E63ACA81B03A8386');
  65.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order DROP FOREIGN KEY FK_E63ACA81896DBBDE');
  66.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order DROP FOREIGN KEY FK_E63ACA81C76F1F52');
  67.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order DROP FOREIGN KEY FK_E63ACA81C69DE5E5');
  68.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line DROP FOREIGN KEY FK_389F67811605B9');
  69.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line DROP FOREIGN KEY FK_389F67814584665A');
  70.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line DROP FOREIGN KEY FK_389F67819941A932');
  71.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line DROP FOREIGN KEY FK_389F6781B03A8386');
  72.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line DROP FOREIGN KEY FK_389F6781896DBBDE');
  73.         $this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line DROP FOREIGN KEY FK_389F6781C76F1F52');
  74.         $this->addSql('DROP TABLE suppliers_orders_bundle__receipt_note');
  75.         $this->addSql('DROP TABLE suppliers_orders_bundle__receipt_note_line');
  76.         $this->addSql('DROP TABLE suppliers_orders_bundle__supplier_order');
  77.         $this->addSql('DROP TABLE suppliers_orders_bundle__supplier_order_line');
  78.     }
  79.     public function postUp(Schema $schema): void
  80.     {
  81.         parent::postUp($schema);
  82.         $now = (new \DateTime())->format('Y-m-d H:i:s');
  83.         $configurations = [
  84.             'suppliers_orders_bundle__shared_suppliers_orders' => true,
  85.             'suppliers_orders_bundle__price_calculation_with_packaging' => false,
  86.             'suppliers_orders_bundle__receipt_note_format' => 'BR/[[number]]',
  87.             'suppliers_orders_bundle__supplier_order_format' => 'CMD-FRN/[[number]]'
  88.         ];
  89.         foreach ($configurations as $configuration => $value) {
  90.             $this->connection->insert('configuration', [
  91.                 'id' => (new UuidV6())->toBinary(),
  92.                 'name' => $configuration,
  93.                 'context_id' => null,
  94.                 'value' => $this->objectSerialize->add((object) ['value' => $value]),
  95.                 'created_at' => $now,
  96.                 'updated_at' => $now
  97.             ]);
  98.         }
  99.         $fixturesPath dirname(__FILE__) . '/../src/Resources/views/Pdf/Fixtures/';
  100.         $pdfFiles = [
  101.             'layout',
  102.             'credit_note',
  103.             'supplier_order',
  104.             'receipt_note'
  105.         ];
  106.         foreach ($pdfFiles as $file) {
  107.             $fixtureFile $fixturesPath $file '.html.twig';
  108.             if (!file_exists($fixtureFile)) {
  109.                 continue;
  110.             }
  111.             $content file_get_contents($fixtureFile);
  112.             $this->connection->insert('configuration', [
  113.                 'id' => (new UuidV6())->toBinary(),
  114.                 'name' => 'suppliers_orders_bundle__' $file '_pdf',
  115.                 'context_id' => null,
  116.                 'value' => $this->objectSerialize->add((object) ['value' => $content]),
  117.                 'created_at' => $now,
  118.                 'updated_at' => $now
  119.             ]);
  120.         }
  121.     }
  122. }