<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**ah i
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210129183341 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('CREATE TABLE invoice_tax_detail (id INT AUTO_INCREMENT NOT NULL, invoice_id INT DEFAULT NULL, tax NUMERIC(10, 2) NOT NULL, taxable_amount NUMERIC(10, 2) NOT NULL, tax_amount NUMERIC(10, 2) NOT NULL, type VARCHAR(100) NOT NULL, INDEX IDX_9B0065A62989F1FD (invoice_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE invoice_tax_detail ADD CONSTRAINT FK_9B0065A62989F1FD FOREIGN KEY (invoice_id) REFERENCES invoice (id)');
$this->addSql('INSERT INTO invoice_tax_detail(invoice_id,type,tax,taxable_amount,tax_amount)
SELECT invoice_item.invoice_id,invoice_item.type,invoice_item.tax,SUM(invoice_item.unit_price * invoice_item.quantity),SUM(invoice_item.unit_price * invoice_item.quantity * (invoice_item.tax / 100)) FROM invoice_item
WHERE invoice_item.type <> "discount"
GROUP BY invoice_item.invoice_id, invoice_item.tax, invoice_item.type
ORDER BY invoice_item.invoice_id ASC'
);
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('DROP TABLE invoice_tax_detail');
}
}