Skip to content

Commit

Permalink
Merge pull request #15 from GoteoFoundation/feat/transactions
Browse files Browse the repository at this point in the history
[FEAT] Transactions
  • Loading branch information
subiabre authored Jul 3, 2024
2 parents 84bdc33 + 32ca837 commit 5fa604a
Show file tree
Hide file tree
Showing 12 changed files with 881 additions and 803 deletions.
1,223 changes: 644 additions & 579 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Zenstruck\Foundry\ZenstruckFoundryBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
];
4 changes: 2 additions & 2 deletions config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ doctrine:
#server_version: '15'

profiling_collect_backtrace: '%kernel.debug%'
use_savepoints: true
orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
Expand Down Expand Up @@ -34,8 +35,7 @@ doctrine:
when@test:
doctrine:
dbal:
# "TEST_TOKEN" is typically set by ParaTest
dbname_suffix: '_test%env(default::TEST_TOKEN)%'
dbname_suffix: '_test'

when@prod:
doctrine:
Expand Down
3 changes: 3 additions & 0 deletions src/DependencyInjection/SystemVariablesLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\DBAL\Exception\ConnectionException;
use Doctrine\DBAL\Exception\TableNotFoundException;
use Symfony\Component\DependencyInjection\EnvVarLoaderInterface;
use Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException;

/**
* Loads SystemVar records as environment variables for the code to use.
Expand All @@ -27,6 +28,8 @@ public function loadEnvVars(): array
} catch (TableNotFoundException $e) {
// Ignore loader in environments where the table does not exist
return [];
} catch (ParameterCircularReferenceException $e) {
return [];
}

$processedVars = [];
Expand Down
119 changes: 83 additions & 36 deletions src/Entity/Accounting.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ class Accounting
#[ORM\Column(length: 3)]
private ?string $currency = null;

#[API\ApiProperty(writable: false)]
#[ORM\OneToMany(mappedBy: 'accounting', targetEntity: AccountingStatement::class)]
private Collection $statements;

#[API\ApiProperty(writable: false, readable: false)]
#[ORM\Column(length: 255)]
private ?string $ownerClass = null;
Expand All @@ -50,14 +46,21 @@ class Accounting
#[ORM\OneToOne(mappedBy: 'accounting', cascade: ['persist', 'remove'])]
private ?Tipjar $tipjar = null;

#[ORM\OneToMany(mappedBy: 'origin', targetEntity: AccountingTransaction::class)]
private Collection $transactionsIssued;

#[ORM\OneToMany(mappedBy: 'target', targetEntity: AccountingTransaction::class)]
private Collection $transactionsReceived;

public function __construct()
{
/*
* TODO: This property must be loaded from App's configuration,
* TO-DO: This property must be loaded from App's configuration,
* ideally a configuration that can be updated via a frontend, not env var only
*/
$this->currency = 'EUR';
$this->statements = new ArrayCollection();
$this->transactionsIssued = new ArrayCollection();
$this->transactionsReceived = new ArrayCollection();
}

public function getId(): ?int
Expand All @@ -77,36 +80,6 @@ public function setCurrency(string $currency): static
return $this;
}

/**
* @return Collection<int, AccountingStatement>
*/
public function getStatements(): Collection
{
return $this->statements;
}

public function addStatement(AccountingStatement $statement): static
{
if (!$this->statements->contains($statement)) {
$this->statements->add($statement);
$statement->setAccounting($this);
}

return $this;
}

public function removeStatement(AccountingStatement $statement): static
{
if ($this->statements->removeElement($statement)) {
// set the owning side to null (unless already changed)
if ($statement->getAccounting() === $this) {
$statement->setAccounting(null);
}
}

return $this;
}

public function getOwnerClass(): ?string
{
return $this->ownerClass;
Expand Down Expand Up @@ -191,4 +164,78 @@ public function setTipjar(Tipjar $tipjar): static

return $this;
}

public function getTransactions(): Collection
{
$transactions = [
...$this->getTransactionsIssued()->toArray(),
...$this->getTransactionsReceived()->toArray(),
];

\usort($transactions, function ($a, $b) {
return $a->getId() - $b->getId();
});

return new ArrayCollection($transactions);
}

/**
* @return Collection<int, AccountingTransaction>
*/
public function getTransactionsIssued(): Collection
{
return $this->transactionsIssued;
}

public function addTransactionsIssued(AccountingTransaction $transaction): static
{
if (!$this->transactionsIssued->contains($transaction)) {
$this->transactionsIssued->add($transaction);
$transaction->setOrigin($this);
}

return $this;
}

public function removeTransactionsIssued(AccountingTransaction $transaction): static
{
if ($this->transactionsIssued->removeElement($transaction)) {
// set the owning side to null (unless already changed)
if ($transaction->getOrigin() === $this) {
$transaction->setOrigin(null);
}
}

return $this;
}

/**
* @return Collection<int, AccountingTransaction>
*/
public function getTransactionsReceived(): Collection
{
return $this->transactionsReceived;
}

public function addTransactionsReceived(AccountingTransaction $transaction): static
{
if (!$this->transactionsReceived->contains($transaction)) {
$this->transactionsReceived->add($transaction);
$transaction->setTarget($this);
}

return $this;
}

public function removeTransactionsReceived(AccountingTransaction $transaction): static
{
if ($this->transactionsReceived->removeElement($transaction)) {
// set the owning side to null (unless already changed)
if ($transaction->getTarget() === $this) {
$transaction->setTarget(null);
}
}

return $this;
}
}
116 changes: 0 additions & 116 deletions src/Entity/AccountingStatement.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Entity/AccountingStatementDirection.php

This file was deleted.

8 changes: 6 additions & 2 deletions src/Entity/AccountingTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class AccountingTransaction
* The Accounting issuing the money of this Transaction.
*/
#[Assert\NotBlank()]
#[ORM\ManyToOne(inversedBy: 'transactionsIssued')]
#[ORM\ManyToOne(inversedBy: 'transactionsIssued', cascade: ['persist'])]
#[ORM\JoinColumn(nullable: false)]
private ?Accounting $origin = null;

/**
* The Accounting receiving the money of this Transaction.
*/
#[Assert\NotBlank()]
#[ORM\ManyToOne(inversedBy: 'transactionsReceived')]
#[ORM\ManyToOne(inversedBy: 'transactionsReceived', cascade: ['persist'])]
#[ORM\JoinColumn(nullable: false)]
private ?Accounting $target = null;

Expand Down Expand Up @@ -68,6 +68,8 @@ public function getOrigin(): ?Accounting

public function setOrigin(?Accounting $origin): static
{
$origin->addTransactionsIssued($this);

$this->origin = $origin;

return $this;
Expand All @@ -80,6 +82,8 @@ public function getTarget(): ?Accounting

public function setTarget(?Accounting $target): static
{
$target->addTransactionsReceived($this);

$this->target = $target;

return $this;
Expand Down
Loading

0 comments on commit 5fa604a

Please sign in to comment.