vendor/bluue/accounting-bundle/migrations/Version20221207102423.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace AccountingBundleMigrations;
  4. use App\Services\ObjectSerialize;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\Migrations\AbstractMigration;
  7. use Symfony\Component\Uid\UuidV6;
  8. final class Version20221207102423 extends AbstractMigration
  9. {
  10.     private ObjectSerialize $objectSerialize;
  11.     public function setObjectSerialize(ObjectSerialize $objectSerialize)
  12.     {
  13.         $this->objectSerialize $objectSerialize;
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $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');
  18.         $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');
  19.         $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');
  20.         $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');
  21.         $this->addSql('ALTER TABLE accounting_bundle__account ADD CONSTRAINT FK_F422CBC7B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  22.         $this->addSql('ALTER TABLE accounting_bundle__account ADD CONSTRAINT FK_F422CBC7896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  23.         $this->addSql('ALTER TABLE accounting_bundle__account ADD CONSTRAINT FK_F422CBC7C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  24.         $this->addSql('ALTER TABLE accounting_bundle__account_translations ADD CONSTRAINT FK_1A196C21232D562B FOREIGN KEY (object_id) REFERENCES accounting_bundle__account (id) ON DELETE CASCADE');
  25.         $this->addSql('ALTER TABLE accounting_bundle__customer_account ADD CONSTRAINT FK_1AAE13969395C3F3 FOREIGN KEY (customer_id) REFERENCES customers_bundle__customer (id)');
  26.         $this->addSql('ALTER TABLE accounting_bundle__customer_account ADD CONSTRAINT FK_1AAE1396B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  27.         $this->addSql('ALTER TABLE accounting_bundle__customer_account ADD CONSTRAINT FK_1AAE1396896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  28.         $this->addSql('ALTER TABLE accounting_bundle__customer_account ADD CONSTRAINT FK_1AAE1396C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  29.         $this->addSql('ALTER TABLE accounting_bundle__product_account ADD CONSTRAINT FK_58256FDEB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  30.         $this->addSql('ALTER TABLE accounting_bundle__product_account ADD CONSTRAINT FK_58256FDE896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  31.         $this->addSql('ALTER TABLE accounting_bundle__product_account ADD CONSTRAINT FK_58256FDEC76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  32.     }
  33.     public function down(Schema $schema): void
  34.     {
  35.         $this->addSql('ALTER TABLE accounting_bundle__account DROP FOREIGN KEY FK_F422CBC7B03A8386');
  36.         $this->addSql('ALTER TABLE accounting_bundle__account DROP FOREIGN KEY FK_F422CBC7896DBBDE');
  37.         $this->addSql('ALTER TABLE accounting_bundle__account DROP FOREIGN KEY FK_F422CBC7C76F1F52');
  38.         $this->addSql('ALTER TABLE accounting_bundle__account_translations DROP FOREIGN KEY FK_1A196C21232D562B');
  39.         $this->addSql('ALTER TABLE accounting_bundle__customer_account DROP FOREIGN KEY FK_1AAE13969395C3F3');
  40.         $this->addSql('ALTER TABLE accounting_bundle__customer_account DROP FOREIGN KEY FK_1AAE1396B03A8386');
  41.         $this->addSql('ALTER TABLE accounting_bundle__customer_account DROP FOREIGN KEY FK_1AAE1396896DBBDE');
  42.         $this->addSql('ALTER TABLE accounting_bundle__customer_account DROP FOREIGN KEY FK_1AAE1396C76F1F52');
  43.         $this->addSql('ALTER TABLE accounting_bundle__product_account DROP FOREIGN KEY FK_58256FDEB03A8386');
  44.         $this->addSql('ALTER TABLE accounting_bundle__product_account DROP FOREIGN KEY FK_58256FDE896DBBDE');
  45.         $this->addSql('ALTER TABLE accounting_bundle__product_account DROP FOREIGN KEY FK_58256FDEC76F1F52');
  46.         $this->addSql('ALTER TABLE accounting_bundle__product_account DROP FOREIGN KEY FK_58256FDE4584665A');
  47.         $this->addSql('DROP TABLE accounting_bundle__account');
  48.         $this->addSql('DROP TABLE accounting_bundle__account_translations');
  49.         $this->addSql('DROP TABLE accounting_bundle__customer_account');
  50.         $this->addSql('DROP TABLE accounting_bundle__product_account');
  51.     }
  52.     public function postUp(Schema $schema): void
  53.     {
  54.         parent::postUp($schema);
  55.         $now = (new \DateTime())->format('Y-m-d H:i:s');
  56.         $configurations = [
  57.             'accounting_bundle__vat_collected_account' => '44570000',
  58.             'accounting_bundle__vat_deductible_account' => '44560000',
  59.             'accounting_bundle__journal_code_sales' => 'VTE',
  60.             'accounting_bundle__customers_account' => '41100000',
  61.             'accounting_bundle__sales_type_account_1' => '70700000',
  62.             'accounting_bundle__sales_type_account_2' => '70600000',
  63.             'accounting_bundle__sales_type_account_manufactured_pack' => '70100000',
  64.             'accounting_bundle__journal_code_banks' => 'BQE',
  65.             'accounting_bundle__banks_account' => '51210000',
  66.             'accounting_bundle__journal_code_purchases' => 'ACH',
  67.             'accounting_bundle__suppliers_account' => '40100000'
  68.         ];
  69.         foreach ($configurations as $configuration => $value) {
  70.             $this->connection->insert('configuration', [
  71.                 'id' => (new UuidV6())->toBinary(),
  72.                 'name' => $configuration,
  73.                 'context_id' => null,
  74.                 'value' => $this->objectSerialize->add((object) ['value' => $value]),
  75.                 'created_at' => $now,
  76.                 'updated_at' => $now
  77.             ]);
  78.         }
  79.         $accountsFile dirname(__FILE__) . '/../assets/fixtures/plan_comptable.csv';
  80.         if (($handle fopen($accountsFile'r')) !== false) {
  81.             while (($data fgetcsv($handlenull";")) !== false) {
  82.                 $accountId = (new UuidV6())->toBinary();
  83.                 $this->connection->insert('accounting_bundle__account', [
  84.                     'id' => $accountId,
  85.                     'name' => $data[1],
  86.                     'number' => $data[0],
  87.                     'created_at' => $now,
  88.                     'updated_at' => $now
  89.                 ]);
  90.             }
  91.             fclose($handle);
  92.         }
  93.     }
  94. }