Feature: allow to administrate budget resources and charges from the admin

This commit is contained in:
2023-01-23 20:40:01 +00:00
parent 99482edf0d
commit c4eb45edcc
57 changed files with 1546 additions and 49 deletions

View File

@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\Budget;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20221116163445 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('DROP SEQUENCE chill_budget.charge_type_id_seq CASCADE');
$this->addSql('DROP SEQUENCE chill_budget.resource_type_id_seq CASCADE');
$this->addSql('DROP TABLE chill_budget.charge_type');
$this->addSql('DROP TABLE chill_budget.resource_type');
}
public function getDescription(): string
{
return 'Create resource type and charge type';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE SEQUENCE chill_budget.charge_type_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE SEQUENCE chill_budget.resource_type_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE TABLE chill_budget.charge_type (id INT NOT NULL, isActive BOOLEAN DEFAULT TRUE NOT NULL, name JSONB DEFAULT \'{}\'::jsonb NOT NULL, ordering DOUBLE PRECISION DEFAULT \'0\' NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE chill_budget.resource_type (id INT NOT NULL, isActive BOOLEAN DEFAULT TRUE NOT NULL, name JSONB DEFAULT \'{}\'::jsonb NOT NULL, ordering DOUBLE PRECISION DEFAULT \'0\' NOT NULL, PRIMARY KEY(id))');
}
}

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\Budget;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20221130101659 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_budget.resource_type DROP kind');
$this->addSql('ALTER TABLE chill_budget.resource_type DROP tags');
$this->addSql('ALTER TABLE chill_budget.charge_type DROP kind');
$this->addSql('ALTER TABLE chill_budget.charge_type DROP tags');
}
public function getDescription(): string
{
return 'Add kind and tags property to charge and resource types';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_budget.charge_type ADD kind VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE chill_budget.charge_type ADD tags JSONB DEFAULT \'{}\'::jsonb NOT NULL');
$this->addSql('COMMENT ON COLUMN chill_budget.charge_type.tags IS \'(DC2Type:jsonb)\'');
$this->addSql('ALTER TABLE chill_budget.resource_type ADD kind VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE chill_budget.resource_type ADD tags JSONB DEFAULT \'{}\'::jsonb NOT NULL');
$this->addSql('COMMENT ON COLUMN chill_budget.resource_type.tags IS \'(DC2Type:jsonb)\'');
}
}

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\Budget;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20221202165608 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_budget.charge DROP CONSTRAINT FK_5C99D2C355284914');
$this->addSql('ALTER TABLE chill_budget.charge DROP charge_id');
$this->addSql('ALTER TABLE chill_budget.resource DROP CONSTRAINT FK_5E0A5E9789329D25');
$this->addSql('ALTER TABLE chill_budget.resource DROP resource_id');
}
public function getDescription(): string
{
return 'Integrate budget admin entity';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_budget.charge ADD charge_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_budget.charge ADD CONSTRAINT FK_5C99D2C355284914 FOREIGN KEY (charge_id) REFERENCES chill_budget.charge_type (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_5C99D2C355284914 ON chill_budget.charge (charge_id)');
$this->addSql('ALTER TABLE chill_budget.resource ADD resource_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_budget.resource ADD CONSTRAINT FK_5E0A5E9789329D25 FOREIGN KEY (resource_id) REFERENCES chill_budget.resource_type (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_5E0A5E9789329D25 ON chill_budget.resource (resource_id)');
}
}

View File

@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\Budget;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
final class Version20221207105407 extends AbstractMigration implements ContainerAwareInterface
{
public ContainerInterface $container;
public function down(Schema $schema): void
{
$this->addSql('DELETE FROM chill_budget.resource_type;');
$this->addSql('DELETE FROM chill_budget.charge_type;');
}
public function getDescription(): string
{
return 'Use new budget admin entities';
}
public function setContainer(?ContainerInterface $container = null)
{
$this->container = $container;
}
public function up(Schema $schema): void
{
$resources = $this->container->getParameter('chill_budget.resources');
$charges = $this->container->getParameter('chill_budget.charges');
foreach ($resources as $value) {
$lang = $value['labels'][0]['lang'];
$label = $value['labels'][0]['label'];
$kind = $value['key'];
$this->addSql(
'INSERT INTO chill_budget.resource_type (id, isActive, name, ordering, kind) VALUES (
nextval(\'chill_budget.resource_type_id_seq\'), true, jsonb_build_object(:lang::text, :label::text), 0, :kind::text)',
['lang' => $lang, 'label' => $label, 'kind' => $kind],
['lang' => Types::STRING, 'label' => Types::STRING, 'kind' => Types::STRING]
);
$this->addSql(
'UPDATE chill_budget.resource SET resource_id = resource_type.id
FROM chill_budget.resource_type WHERE resource.type = :kind AND resource_type.kind = resource.type;',
['kind' => $kind],
['kind' => Types::STRING]
);
}
foreach ($charges as $value) {
$lang = $value['labels'][0]['lang'];
$label = $value['labels'][0]['label'];
$kind = $value['key'];
$this->addSql(
'INSERT INTO chill_budget.charge_type VALUES (nextval(\'chill_budget.charge_type_id_seq\'), true,
jsonb_build_object(:lang::text, :label::text), 0, :kind::text);',
['lang' => $lang, 'label' => $label, 'kind' => $kind],
['lang' => Types::STRING, 'label' => Types::STRING, 'kind' => Types::STRING]
);
$this->addSql(
'UPDATE chill_budget.charge SET charge_id = charge_type.id
FROM chill_budget.charge_type WHERE charge.type = :kind AND charge_type.kind = charge.type;',
['kind' => $kind],
['kind' => Types::STRING]
);
}
}
}