<?php
declare(strict_types=1);
namespace AccountingBundleMigrations;
use App\Services\ObjectSerialize;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\Uid\UuidV6;
final class Version20221207102423 extends AbstractMigration
{
private ObjectSerialize $objectSerialize;
public function setObjectSerialize(ObjectSerialize $objectSerialize)
{
$this->objectSerialize = $objectSerialize;
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE accounting_bundle__account (id BINARY(16) NOT 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)\', name VARCHAR(128) NOT NULL, number VARCHAR(32) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_F422CBC796901F54 (number), INDEX IDX_F422CBC7B03A8386 (created_by_id), INDEX IDX_F422CBC7896DBBDE (updated_by_id), INDEX IDX_F422CBC7C76F1F52 (deleted_by_id), INDEX name (name), INDEX number (number), 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 accounting_bundle__account_translations (id INT AUTO_INCREMENT NOT NULL, object_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', locale VARCHAR(8) NOT NULL, field VARCHAR(32) NOT NULL, content LONGTEXT DEFAULT NULL, INDEX IDX_1A196C21232D562B (object_id), FULLTEXT INDEX content (content), UNIQUE INDEX lookup_unique_idx (locale, object_id, field), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE accounting_bundle__customer_account (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', customer_id BINARY(16) NOT 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)\', number VARCHAR(32) DEFAULT NULL, auxiliary_number VARCHAR(32) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_1AAE13969395C3F3 (customer_id), INDEX IDX_1AAE1396B03A8386 (created_by_id), INDEX IDX_1AAE1396896DBBDE (updated_by_id), INDEX IDX_1AAE1396C76F1F52 (deleted_by_id), INDEX number (number), INDEX auxiliary_number (auxiliary_number), 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 accounting_bundle__product_account (id BINARY(16) NOT 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)\', sales_number VARCHAR(32) DEFAULT NULL, purchases_number VARCHAR(32) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_58256FDEB03A8386 (created_by_id), INDEX IDX_58256FDE896DBBDE (updated_by_id), INDEX IDX_58256FDEC76F1F52 (deleted_by_id), INDEX sales_number (sales_number), INDEX purchases_number (purchases_number), 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 accounting_bundle__account ADD CONSTRAINT FK_F422CBC7B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE accounting_bundle__account ADD CONSTRAINT FK_F422CBC7896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE accounting_bundle__account ADD CONSTRAINT FK_F422CBC7C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE accounting_bundle__account_translations ADD CONSTRAINT FK_1A196C21232D562B FOREIGN KEY (object_id) REFERENCES accounting_bundle__account (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE accounting_bundle__customer_account ADD CONSTRAINT FK_1AAE13969395C3F3 FOREIGN KEY (customer_id) REFERENCES customers_bundle__customer (id)');
$this->addSql('ALTER TABLE accounting_bundle__customer_account ADD CONSTRAINT FK_1AAE1396B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE accounting_bundle__customer_account ADD CONSTRAINT FK_1AAE1396896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE accounting_bundle__customer_account ADD CONSTRAINT FK_1AAE1396C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE accounting_bundle__product_account ADD CONSTRAINT FK_58256FDEB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE accounting_bundle__product_account ADD CONSTRAINT FK_58256FDE896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE accounting_bundle__product_account ADD CONSTRAINT FK_58256FDEC76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE accounting_bundle__account DROP FOREIGN KEY FK_F422CBC7B03A8386');
$this->addSql('ALTER TABLE accounting_bundle__account DROP FOREIGN KEY FK_F422CBC7896DBBDE');
$this->addSql('ALTER TABLE accounting_bundle__account DROP FOREIGN KEY FK_F422CBC7C76F1F52');
$this->addSql('ALTER TABLE accounting_bundle__account_translations DROP FOREIGN KEY FK_1A196C21232D562B');
$this->addSql('ALTER TABLE accounting_bundle__customer_account DROP FOREIGN KEY FK_1AAE13969395C3F3');
$this->addSql('ALTER TABLE accounting_bundle__customer_account DROP FOREIGN KEY FK_1AAE1396B03A8386');
$this->addSql('ALTER TABLE accounting_bundle__customer_account DROP FOREIGN KEY FK_1AAE1396896DBBDE');
$this->addSql('ALTER TABLE accounting_bundle__customer_account DROP FOREIGN KEY FK_1AAE1396C76F1F52');
$this->addSql('ALTER TABLE accounting_bundle__product_account DROP FOREIGN KEY FK_58256FDEB03A8386');
$this->addSql('ALTER TABLE accounting_bundle__product_account DROP FOREIGN KEY FK_58256FDE896DBBDE');
$this->addSql('ALTER TABLE accounting_bundle__product_account DROP FOREIGN KEY FK_58256FDEC76F1F52');
$this->addSql('ALTER TABLE accounting_bundle__product_account DROP FOREIGN KEY FK_58256FDE4584665A');
$this->addSql('DROP TABLE accounting_bundle__account');
$this->addSql('DROP TABLE accounting_bundle__account_translations');
$this->addSql('DROP TABLE accounting_bundle__customer_account');
$this->addSql('DROP TABLE accounting_bundle__product_account');
}
public function postUp(Schema $schema): void
{
parent::postUp($schema);
$now = (new \DateTime())->format('Y-m-d H:i:s');
$configurations = [
'accounting_bundle__vat_collected_account' => '44570000',
'accounting_bundle__vat_deductible_account' => '44560000',
'accounting_bundle__journal_code_sales' => 'VTE',
'accounting_bundle__customers_account' => '41100000',
'accounting_bundle__sales_type_account_1' => '70700000',
'accounting_bundle__sales_type_account_2' => '70600000',
'accounting_bundle__sales_type_account_manufactured_pack' => '70100000',
'accounting_bundle__journal_code_banks' => 'BQE',
'accounting_bundle__banks_account' => '51210000',
'accounting_bundle__journal_code_purchases' => 'ACH',
'accounting_bundle__suppliers_account' => '40100000'
];
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
]);
}
$accountsFile = dirname(__FILE__) . '/../assets/fixtures/plan_comptable.csv';
if (($handle = fopen($accountsFile, 'r')) !== false) {
while (($data = fgetcsv($handle, null, ";")) !== false) {
$accountId = (new UuidV6())->toBinary();
$this->connection->insert('accounting_bundle__account', [
'id' => $accountId,
'name' => $data[1],
'number' => $data[0],
'created_at' => $now,
'updated_at' => $now
]);
}
fclose($handle);
}
}
}