<?php
declare(strict_types=1);
namespace SuppliersOrdersBundleMigrations;
use App\Services\ObjectSerialize;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\Uid\UuidV6;
final class Version20221206231340 extends AbstractMigration
{
private ObjectSerialize $objectSerialize;
public function setObjectSerialize(ObjectSerialize $objectSerialize)
{
$this->objectSerialize = $objectSerialize;
}
public function up(Schema $schema): void
{
$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');
$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');
$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');
$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');
$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)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note ADD CONSTRAINT FK_7D7418216B00C1CF FOREIGN KEY (context_id) REFERENCES context (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note ADD CONSTRAINT FK_7D741821C69DE5E5 FOREIGN KEY (validated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note ADD CONSTRAINT FK_7D741821B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note ADD CONSTRAINT FK_7D741821896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note ADD CONSTRAINT FK_7D741821C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$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)');
$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)');
$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)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line ADD CONSTRAINT FK_2C547A1EB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line ADD CONSTRAINT FK_2C547A1E896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line ADD CONSTRAINT FK_2C547A1EC76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order ADD CONSTRAINT FK_E63ACA816B00C1CF FOREIGN KEY (context_id) REFERENCES context (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order ADD CONSTRAINT FK_E63ACA812ADD6D8C FOREIGN KEY (supplier_id) REFERENCES suppliers_bundle__supplier (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order ADD CONSTRAINT FK_E63ACA8138248176 FOREIGN KEY (currency_id) REFERENCES currency (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order ADD CONSTRAINT FK_E63ACA81B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order ADD CONSTRAINT FK_E63ACA81896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order ADD CONSTRAINT FK_E63ACA81C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order ADD CONSTRAINT FK_E63ACA81C69DE5E5 FOREIGN KEY (validated_by_id) REFERENCES user (id)');
$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)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line ADD CONSTRAINT FK_389F67814584665A FOREIGN KEY (product_id) REFERENCES products_bundle__product (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line ADD CONSTRAINT FK_389F67819941A932 FOREIGN KEY (declination_id) REFERENCES products_bundle__declination (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line ADD CONSTRAINT FK_389F6781B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line ADD CONSTRAINT FK_389F6781896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line ADD CONSTRAINT FK_389F6781C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note DROP FOREIGN KEY FK_7D7418211605B9');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note DROP FOREIGN KEY FK_7D7418216B00C1CF');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note DROP FOREIGN KEY FK_7D741821C69DE5E5');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note DROP FOREIGN KEY FK_7D741821B03A8386');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note DROP FOREIGN KEY FK_7D741821896DBBDE');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note DROP FOREIGN KEY FK_7D741821C76F1F52');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line DROP FOREIGN KEY FK_2C547A1E35A7ADAB');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line DROP FOREIGN KEY FK_2C547A1EA9DC5CCE');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line DROP FOREIGN KEY FK_2C547A1E727ACA70');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line DROP FOREIGN KEY FK_2C547A1EB03A8386');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line DROP FOREIGN KEY FK_2C547A1E896DBBDE');
$this->addSql('ALTER TABLE suppliers_orders_bundle__receipt_note_line DROP FOREIGN KEY FK_2C547A1EC76F1F52');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order DROP FOREIGN KEY FK_E63ACA816B00C1CF');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order DROP FOREIGN KEY FK_E63ACA812ADD6D8C');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order DROP FOREIGN KEY FK_E63ACA8138248176');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order DROP FOREIGN KEY FK_E63ACA81B03A8386');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order DROP FOREIGN KEY FK_E63ACA81896DBBDE');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order DROP FOREIGN KEY FK_E63ACA81C76F1F52');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order DROP FOREIGN KEY FK_E63ACA81C69DE5E5');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line DROP FOREIGN KEY FK_389F67811605B9');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line DROP FOREIGN KEY FK_389F67814584665A');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line DROP FOREIGN KEY FK_389F67819941A932');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line DROP FOREIGN KEY FK_389F6781B03A8386');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line DROP FOREIGN KEY FK_389F6781896DBBDE');
$this->addSql('ALTER TABLE suppliers_orders_bundle__supplier_order_line DROP FOREIGN KEY FK_389F6781C76F1F52');
$this->addSql('DROP TABLE suppliers_orders_bundle__receipt_note');
$this->addSql('DROP TABLE suppliers_orders_bundle__receipt_note_line');
$this->addSql('DROP TABLE suppliers_orders_bundle__supplier_order');
$this->addSql('DROP TABLE suppliers_orders_bundle__supplier_order_line');
}
public function postUp(Schema $schema): void
{
parent::postUp($schema);
$now = (new \DateTime())->format('Y-m-d H:i:s');
$configurations = [
'suppliers_orders_bundle__shared_suppliers_orders' => true,
'suppliers_orders_bundle__price_calculation_with_packaging' => false,
'suppliers_orders_bundle__receipt_note_format' => 'BR/[[number]]',
'suppliers_orders_bundle__supplier_order_format' => 'CMD-FRN/[[number]]'
];
foreach ($configurations as $configuration => $value) {
$this->connection->insert('configuration', [
'id' => (new UuidV6())->toBinary(),
'name' => $configuration,
'context_id' => null,
'value' => $this->objectSerialize->add((object) ['value' => $value]),
'created_at' => $now,
'updated_at' => $now
]);
}
$fixturesPath = dirname(__FILE__) . '/../src/Resources/views/Pdf/Fixtures/';
$pdfFiles = [
'layout',
'credit_note',
'supplier_order',
'receipt_note'
];
foreach ($pdfFiles as $file) {
$fixtureFile = $fixturesPath . $file . '.html.twig';
if (!file_exists($fixtureFile)) {
continue;
}
$content = file_get_contents($fixtureFile);
$this->connection->insert('configuration', [
'id' => (new UuidV6())->toBinary(),
'name' => 'suppliers_orders_bundle__' . $file . '_pdf',
'context_id' => null,
'value' => $this->objectSerialize->add((object) ['value' => $content]),
'created_at' => $now,
'updated_at' => $now
]);
}
}
}