<?php
declare(strict_types=1);
namespace SalesBundleMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Exception;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20221216102111 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE sales_bundle__delivery_note ADD invoice_address_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', ADD delivery_address_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', ADD currency_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', ADD currency_change_rate NUMERIC(20, 12) NOT NULL, ADD total_discount_untaxed NUMERIC(20, 6) DEFAULT NULL, ADD total_amount_no_discount_untaxed NUMERIC(20, 6) DEFAULT NULL, ADD total_amount_untaxed NUMERIC(20, 6) DEFAULT NULL, ADD total_tax_amount NUMERIC(20, 6) DEFAULT NULL, ADD total_amount NUMERIC(20, 6) DEFAULT NULL');
$this->addSql('ALTER TABLE sales_bundle__delivery_note ADD CONSTRAINT FK_9CC42D7C6BDFEB FOREIGN KEY (invoice_address_id) REFERENCES customers_bundle__customer (id)');
$this->addSql('ALTER TABLE sales_bundle__delivery_note ADD CONSTRAINT FK_9CC42D7EBF23851 FOREIGN KEY (delivery_address_id) REFERENCES customers_bundle__customer (id)');
$this->addSql('ALTER TABLE sales_bundle__delivery_note ADD CONSTRAINT FK_9CC42D738248176 FOREIGN KEY (currency_id) REFERENCES currency (id)');
$this->addSql('CREATE INDEX IDX_9CC42D7C6BDFEB ON sales_bundle__delivery_note (invoice_address_id)');
$this->addSql('CREATE INDEX IDX_9CC42D7EBF23851 ON sales_bundle__delivery_note (delivery_address_id)');
$this->addSql('CREATE INDEX IDX_9CC42D738248176 ON sales_bundle__delivery_note (currency_id)');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line ADD reference VARCHAR(128) DEFAULT NULL, ADD reference_brand VARCHAR(128) DEFAULT NULL, ADD name VARCHAR(255) DEFAULT NULL, ADD description LONGTEXT DEFAULT NULL, ADD unit_price NUMERIC(20, 6) DEFAULT NULL, ADD wholesale_price NUMERIC(20, 6) DEFAULT NULL, ADD margin_ratio NUMERIC(20, 6) DEFAULT NULL, ADD percentage_discount_untaxed NUMERIC(20, 6) DEFAULT NULL, ADD total_discount_untaxed NUMERIC(20, 6) DEFAULT NULL, ADD total_amount_no_discount_untaxed NUMERIC(20, 6) DEFAULT NULL, ADD total_amount_untaxed NUMERIC(20, 6) DEFAULT NULL, ADD total_tax_amount NUMERIC(20, 6) DEFAULT NULL, ADD total_amount NUMERIC(20, 6) DEFAULT NULL, ADD position INT NOT NULL');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line ADD line_type_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\'');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line ADD CONSTRAINT FK_CF8E237F70E80DF4 FOREIGN KEY (line_type_id) REFERENCES sales_bundle__line_type (id)');
$this->addSql('CREATE INDEX IDX_CF8E237F70E80DF4 ON sales_bundle__delivery_note_line (line_type_id)');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line ADD tax_rule_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\'');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line ADD CONSTRAINT FK_CF8E237F3506A35B FOREIGN KEY (tax_rule_id) REFERENCES tax_rule (id)');
$this->addSql('CREATE INDEX IDX_CF8E237F3506A35B ON sales_bundle__delivery_note_line (tax_rule_id)');
$this->addSql('ALTER TABLE sales_bundle__delivery_note ADD reduced_vat TINYINT(1) NOT NULL');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line ADD parent_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', ADD is_group TINYINT(1) NOT NULL');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line ADD CONSTRAINT FK_CF8E237F727ACA70 FOREIGN KEY (parent_id) REFERENCES sales_bundle__delivery_note_line (id)');
$this->addSql('CREATE INDEX IDX_CF8E237F727ACA70 ON sales_bundle__delivery_note_line (parent_id)');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line CHANGE order_line_id order_line_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\'');
$this->addSql('ALTER TABLE sales_bundle__delivery_note DROP INDEX UNIQ_9CC42D72989F1FD, ADD INDEX IDX_9CC42D72989F1FD (invoice_id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE sales_bundle__delivery_note DROP FOREIGN KEY FK_9CC42D7C6BDFEB');
$this->addSql('ALTER TABLE sales_bundle__delivery_note DROP FOREIGN KEY FK_9CC42D7EBF23851');
$this->addSql('ALTER TABLE sales_bundle__delivery_note DROP FOREIGN KEY FK_9CC42D738248176');
$this->addSql('DROP INDEX IDX_9CC42D7C6BDFEB ON sales_bundle__delivery_note');
$this->addSql('DROP INDEX IDX_9CC42D7EBF23851 ON sales_bundle__delivery_note');
$this->addSql('DROP INDEX IDX_9CC42D738248176 ON sales_bundle__delivery_note');
$this->addSql('ALTER TABLE sales_bundle__delivery_note DROP invoice_address_id, DROP delivery_address_id, DROP currency_id, DROP currency_change_rate, DROP total_discount_untaxed, DROP total_amount_no_discount_untaxed, DROP total_amount_untaxed, DROP total_tax_amount, DROP total_amount');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line DROP reference, DROP reference_brand, DROP name, DROP description, DROP unit_price, DROP wholesale_price, DROP margin_ratio, DROP percentage_discount_untaxed, DROP total_discount_untaxed, DROP total_amount_no_discount_untaxed, DROP total_amount_untaxed, DROP total_tax_amount, DROP total_amount, DROP position');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line DROP FOREIGN KEY FK_CF8E237F70E80DF4');
$this->addSql('DROP INDEX IDX_CF8E237F70E80DF4 ON sales_bundle__delivery_note_line');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line DROP line_type_id');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line DROP FOREIGN KEY FK_CF8E237F3506A35B');
$this->addSql('DROP INDEX IDX_CF8E237F3506A35B ON sales_bundle__delivery_note_line');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line DROP tax_rule_id');
$this->addSql('ALTER TABLE sales_bundle__delivery_note DROP reduced_vat');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line DROP FOREIGN KEY FK_CF8E237F727ACA70');
$this->addSql('DROP INDEX IDX_CF8E237F727ACA70 ON sales_bundle__delivery_note_line');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line DROP parent_id, DROP is_group');
$this->addSql('ALTER TABLE sales_bundle__delivery_note_line CHANGE order_line_id order_line_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\'');
$this->addSql('ALTER TABLE sales_bundle__delivery_note DROP INDEX IDX_9CC42D72989F1FD, ADD UNIQUE INDEX UNIQ_9CC42D72989F1FD (invoice_id)');
}
public function postUp(Schema $schema): void
{
parent::postUp($schema);
$queryLines = "UPDATE `sales_bundle__delivery_note_line` dnl, `sales_bundle__order_line` ol
SET dnl.line_type_id = ol.line_type_id,
dnl.tax_rule_id = ol.tax_rule_id,
dnl.reference = ol.reference,
dnl.reference_brand = ol.reference_brand,
dnl.name = ol.name,
dnl.description = ol.description,
dnl.unit_price = ol.unit_price,
dnl.wholesale_price = ol.wholesale_price,
dnl.margin_ratio = ol.margin_ratio,
dnl.percentage_discount_untaxed = ol.percentage_discount_untaxed,
dnl.total_discount_untaxed = (dnl.quantity * ol.total_discount_untaxed) / ol.quantity,
dnl.total_amount_no_discount_untaxed = (dnl.quantity * ol.total_amount_no_discount_untaxed) / ol.quantity,
dnl.total_amount_untaxed = (dnl.quantity * ol.total_amount_untaxed) / ol.quantity,
dnl.total_tax_amount = (dnl.quantity * ol.total_tax_amount) / ol.quantity,
dnl.total_amount = (dnl.quantity * ol.total_amount) / ol.quantity,
dnl.position = ol.position,
dnl.is_group = 0
WHERE dnl.order_line_id = ol.id AND dnl.deleted_at IS NULL
";
$query = "UPDATE `sales_bundle__delivery_note` dn, `sales_bundle__order` o
SET dn.invoice_address_id = o.invoice_address_id,
dn.delivery_address_id = o.delivery_address_id,
dn.currency_id = o.currency_id,
dn.currency_change_rate = o.currency_change_rate,
dn.reduced_vat = o.reduced_vat
WHERE dn.order_id = o.id AND dn.deleted_at IS NULL
";
try {
$connLines = $this->connection->prepare($queryLines);
$connLines->executeQuery();
$conn = $this->connection->prepare($query);
$conn->executeQuery();
} catch (Exception $e) {
}
}
}