<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231228120024 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// Some values may be incorrectly inserted if the prices of certain products or the rates of certain taxes have been changed after the creation of the orders.
$this->addSql('DELETE FROM `doctrine_migration_versions` WHERE `version` LIKE "%Version20231220155042"');
$this->addSql('UPDATE order_item oi
JOIN product p ON oi.product_id = p.id
JOIN `order` o ON oi.checking_id = o.id
JOIN shop_mode sm ON o.shop_mode_id = sm.id
JOIN product_shop_mode psm ON p.id = psm.product_id AND psm.shop_mode_id = sm.id
JOIN tax t ON psm.tax_id = t.id
SET oi.taxes_total = ROUND(
(oi.total - (oi.total / (1 + t.rate))) * oi.quantity, 2
)');
$this->addSql('UPDATE `order` o
SET o.taxes_total = (
SELECT SUM(oi.taxes_total)
FROM order_item oi
WHERE oi.checking_id = o.id
)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}