Merge branch 'develop' into feat/project-support-pumping
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
when@dev: &dev
|
||||
# See full configuration: https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#full-default-bundle-configuration
|
||||
zenstruck_foundry:
|
||||
persistence:
|
||||
flush_once: true
|
||||
|
||||
when@test: *dev
|
||||
|
||||
@@ -14,7 +14,7 @@ services:
|
||||
_instanceof:
|
||||
App\Gateway\GatewayInterface:
|
||||
tags: ['app.gateway.gateway']
|
||||
App\Library\Economy\Currency\ExchangeInterface:
|
||||
App\Money\Currency\ExchangeInterface:
|
||||
tags: ['app.lib.economy.currency.exchange']
|
||||
App\Matchfunding\Formula\FormulaInterface:
|
||||
tags: ['app.matchfunding.formula']
|
||||
@@ -94,7 +94,7 @@ services:
|
||||
$hosts:
|
||||
- 'peertube.plataformess.org'
|
||||
|
||||
App\Library\Economy\Currency\ExchangeLocator:
|
||||
App\Money\Currency\ExchangeLocator:
|
||||
arguments:
|
||||
- !tagged 'app.lib.economy.currency.exchange'
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
namespace App\ApiResource\Accounting;
|
||||
|
||||
use ApiPlatform\Metadata as API;
|
||||
use App\Entity\Accounting\Accounting;
|
||||
use App\Entity\Money;
|
||||
use App\ApiResource\ApiMoney;
|
||||
use App\State\Accounting\AccountingBalanceStateProvider;
|
||||
|
||||
/**
|
||||
@@ -35,5 +34,5 @@ class AccountingBalance
|
||||
* The money currently held by the Accounting.
|
||||
*/
|
||||
#[API\ApiProperty(security: 'is_granted("ACCOUNTING_VIEW", object.accounting)')]
|
||||
public Money $balance;
|
||||
public ApiMoney $balance;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\ApiResource\Accounting;
|
||||
|
||||
use ApiPlatform\Metadata as API;
|
||||
use ApiPlatform\Metadata\QueryParameter;
|
||||
use App\Entity\Money;
|
||||
use App\ApiResource\ApiMoney;
|
||||
use App\State\Accounting\AccountingBalancePointStateProvider;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
@@ -57,7 +57,7 @@ class AccountingBalancePoint
|
||||
/**
|
||||
* Resulting balance for items in this point.
|
||||
*/
|
||||
public Money $balance;
|
||||
public ApiMoney $balance;
|
||||
|
||||
/**
|
||||
* The number of items aggregated in this point.
|
||||
|
||||
@@ -5,8 +5,8 @@ namespace App\ApiResource\Accounting;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
|
||||
use ApiPlatform\Doctrine\Orm\State\Options;
|
||||
use ApiPlatform\Metadata as API;
|
||||
use App\ApiResource\ApiMoney;
|
||||
use App\Entity\Accounting\Transaction;
|
||||
use App\Entity\Money;
|
||||
use App\State\ApiResourceStateProvider;
|
||||
|
||||
/**
|
||||
@@ -33,7 +33,7 @@ class TransactionApiResource
|
||||
/**
|
||||
* The monetary value received at target and issued at origin.
|
||||
*/
|
||||
public Money $money;
|
||||
public ApiMoney $money;
|
||||
|
||||
/**
|
||||
* The Accounting from which the Transaction comes from.
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\ApiResource;
|
||||
|
||||
use App\Money\MoneyInterface;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class ApiMoney implements MoneyInterface
|
||||
{
|
||||
/**
|
||||
* An amount of currency.\
|
||||
* Expressed as the minor unit, e.g: cents, pennies, etc.
|
||||
*/
|
||||
#[Assert\NotBlank()]
|
||||
#[Assert\Positive()]
|
||||
public int $amount;
|
||||
|
||||
/**
|
||||
* 3-letter ISO 4217 currency code.
|
||||
*/
|
||||
#[Assert\NotBlank()]
|
||||
#[Assert\Currency()]
|
||||
public string $currency;
|
||||
|
||||
public function __construct(
|
||||
int $amount,
|
||||
string $currency,
|
||||
) {
|
||||
$this->amount = $amount;
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
public static function of(MoneyInterface $moneyInterface): self
|
||||
{
|
||||
return new self(
|
||||
$moneyInterface->getAmount(),
|
||||
$moneyInterface->getCurrency()
|
||||
);
|
||||
}
|
||||
|
||||
public function getAmount(): int
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
public function getCurrency(): string
|
||||
{
|
||||
return $this->currency;
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,9 @@ use ApiPlatform\Doctrine\Orm\Filter;
|
||||
use ApiPlatform\Doctrine\Orm\State\Options;
|
||||
use ApiPlatform\Metadata as API;
|
||||
use App\ApiResource\Accounting\AccountingApiResource;
|
||||
use App\ApiResource\ApiMoney;
|
||||
use App\Dto\Gateway\ChargeUpdationDto;
|
||||
use App\Entity\Gateway\Charge;
|
||||
use App\Entity\Money;
|
||||
use App\Filter\GatewayFilter;
|
||||
use App\Gateway\ChargeStatus;
|
||||
use App\Gateway\ChargeType;
|
||||
@@ -81,7 +81,7 @@ class ChargeApiResource
|
||||
#[Assert\NotBlank()]
|
||||
#[API\ApiFilter(Filter\RangeFilter::class, properties: ['money.amount'])]
|
||||
#[API\ApiFilter(Filter\SearchFilter::class, properties: ['money.currency' => 'exact'])]
|
||||
public Money $money;
|
||||
public ApiMoney $money;
|
||||
|
||||
/**
|
||||
* The status of the charge item with the Gateway.
|
||||
|
||||
@@ -6,7 +6,7 @@ use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
|
||||
use ApiPlatform\Doctrine\Orm\State\Options;
|
||||
use ApiPlatform\Metadata as API;
|
||||
use App\ApiResource\Money;
|
||||
use App\ApiResource\ApiMoney;
|
||||
use App\Entity\Matchfunding\MatchAgainst;
|
||||
use App\Entity\Matchfunding\MatchStrategy;
|
||||
use App\Mapping\Transformer\MatchFormulaMapTransformer;
|
||||
@@ -81,7 +81,7 @@ class MatchStrategyApiResource
|
||||
*/
|
||||
#[Assert\NotBlank()]
|
||||
#[Assert\Valid()]
|
||||
public Money $limit;
|
||||
public ApiMoney $limit;
|
||||
|
||||
/**
|
||||
* The `x` factor used to calculate the resulting match of funds with the MatchFormula.
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\ApiResource;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class Money
|
||||
{
|
||||
/**
|
||||
* An amount of currency.\
|
||||
* Expressed as the minor unit, e.g: cents, pennies, etc.
|
||||
*/
|
||||
#[Assert\NotBlank()]
|
||||
#[Assert\Positive()]
|
||||
public int $amount;
|
||||
|
||||
/**
|
||||
* 3-letter ISO 4217 currency code.
|
||||
*/
|
||||
#[Assert\NotBlank()]
|
||||
#[Assert\Currency()]
|
||||
public string $currency;
|
||||
}
|
||||
@@ -5,8 +5,8 @@ namespace App\ApiResource\Project;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
|
||||
use ApiPlatform\Doctrine\Orm\State\Options;
|
||||
use ApiPlatform\Metadata as API;
|
||||
use App\ApiResource\ApiMoney;
|
||||
use App\ApiResource\LocalizedApiResourceTrait;
|
||||
use App\ApiResource\Money;
|
||||
use App\Entity\Project\BudgetItem;
|
||||
use App\Entity\Project\BudgetItemType;
|
||||
use App\Entity\Project\ProjectDeadline;
|
||||
@@ -58,7 +58,7 @@ class BudgetItemApiResource
|
||||
*/
|
||||
#[Assert\NotBlank()]
|
||||
#[Assert\Valid()]
|
||||
public Money $money;
|
||||
public ApiMoney $money;
|
||||
|
||||
/**
|
||||
* Defines the budget category for this item within the project.
|
||||
|
||||
@@ -2,27 +2,27 @@
|
||||
|
||||
namespace App\ApiResource\Project;
|
||||
|
||||
use App\Entity\Money;
|
||||
use App\ApiResource\ApiMoney;
|
||||
|
||||
class BudgetSummary
|
||||
{
|
||||
/**
|
||||
* The total money by the included items.
|
||||
*/
|
||||
public Money $money;
|
||||
public ApiMoney $money;
|
||||
|
||||
/**
|
||||
* The total money of type 'task'.
|
||||
*/
|
||||
public Money $task;
|
||||
public ApiMoney $task;
|
||||
|
||||
/**
|
||||
* The total money of type 'material'.
|
||||
*/
|
||||
public Money $material;
|
||||
public ApiMoney $material;
|
||||
|
||||
/**
|
||||
* The total money of type 'infrastructure'.
|
||||
*/
|
||||
public Money $infra;
|
||||
public ApiMoney $infra;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
|
||||
use ApiPlatform\Doctrine\Orm\State\Options;
|
||||
use ApiPlatform\Metadata as API;
|
||||
use App\ApiResource\ApiMoney;
|
||||
use App\ApiResource\LocalizedApiResourceTrait;
|
||||
use App\Entity\Money;
|
||||
use App\Entity\Project\Reward;
|
||||
use App\State\ApiResourceStateProvider;
|
||||
use App\State\Project\RewardStateProcessor;
|
||||
@@ -56,7 +56,7 @@ class RewardApiResource
|
||||
*/
|
||||
#[Assert\NotBlank()]
|
||||
#[API\ApiFilter(OrderFilter::class, properties: ['money.amount'])]
|
||||
public Money $money;
|
||||
public ApiMoney $money;
|
||||
|
||||
/**
|
||||
* Rewards might be finite, i.e: has a limited amount of existing unitsTotal.
|
||||
|
||||
@@ -8,7 +8,7 @@ use ApiPlatform\Doctrine\Orm\State\Options;
|
||||
use ApiPlatform\Metadata as API;
|
||||
use App\ApiResource\Accounting\AccountingApiResource;
|
||||
use App\ApiResource\Accounting\TransactionApiResource;
|
||||
use App\Entity\Money;
|
||||
use App\ApiResource\ApiMoney;
|
||||
use App\Entity\Project\Support;
|
||||
use App\Mapping\Transformer\SupportMoneyMapTransformer;
|
||||
use App\State\ApiResourceStateProvider;
|
||||
@@ -66,7 +66,7 @@ class SupportApiResource
|
||||
* The total monetary value of the Transactions going to the Project.
|
||||
*/
|
||||
#[MapFrom(Support::class, transformer: SupportMoneyMapTransformer::class)]
|
||||
public Money $money;
|
||||
public ApiMoney $money;
|
||||
|
||||
/**
|
||||
* User's will to have their support to the Project be shown publicly.
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
namespace App\Benzina;
|
||||
|
||||
use App\Entity\Accounting\Transaction;
|
||||
use App\Entity\EmbeddableMoney;
|
||||
use App\Entity\Gateway\Charge;
|
||||
use App\Entity\Gateway\Checkout;
|
||||
use App\Entity\Gateway\Tracking;
|
||||
use App\Entity\Money;
|
||||
use App\Entity\Project\Project;
|
||||
use App\Entity\Project\Support;
|
||||
use App\Entity\Tipjar;
|
||||
@@ -270,7 +270,7 @@ class CheckoutsPump implements PumpInterface
|
||||
return ChargeType::Single;
|
||||
}
|
||||
|
||||
private function getChargeMoney(int $amount, string $currency): Money
|
||||
private function getChargeMoney(int $amount, string $currency): EmbeddableMoney
|
||||
{
|
||||
$amount = $amount * 100;
|
||||
|
||||
@@ -278,7 +278,7 @@ class CheckoutsPump implements PumpInterface
|
||||
$amount = self::MAX_INT;
|
||||
}
|
||||
|
||||
return new Money($amount, $currency);
|
||||
return new EmbeddableMoney($amount, $currency);
|
||||
}
|
||||
|
||||
private function getChargeStatus(array $record): ChargeStatus
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Benzina;
|
||||
|
||||
use App\Entity\Money;
|
||||
use App\Entity\EmbeddableMoney;
|
||||
use App\Entity\Project\BudgetItem;
|
||||
use App\Entity\Project\BudgetItemType;
|
||||
use App\Entity\Project\Project;
|
||||
@@ -64,7 +64,7 @@ class ProjectsBudgetPump implements PumpInterface
|
||||
$budgetItem->setType($this->getCostType($record));
|
||||
$budgetItem->setTitle($record['cost']);
|
||||
$budgetItem->setDescription($record['description'] ?? $record['cost']);
|
||||
$budgetItem->setMoney(new Money($record['amount'] * 100, 'EUR'));
|
||||
$budgetItem->setMoney(new EmbeddableMoney($record['amount'] * 100, 'EUR'));
|
||||
$budgetItem->setDeadline($this->getDeadline($record));
|
||||
|
||||
$localizations = $this->getCostLocalizations($budgetItem, $context);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Benzina;
|
||||
|
||||
use App\Entity\Money;
|
||||
use App\Entity\EmbeddableMoney;
|
||||
use App\Entity\Project\BudgetItemType;
|
||||
use App\Entity\Project\Project;
|
||||
use App\Entity\Project\Reward;
|
||||
@@ -73,7 +73,7 @@ class ProjectsRewardsPump implements PumpInterface
|
||||
$reward->setMigratedId($record['id']);
|
||||
$reward->setTitle($record['reward']);
|
||||
$reward->setDescription($record['description'] ?? $record['reward']);
|
||||
$reward->setMoney(new Money($record['amount'] * 100, 'EUR'));
|
||||
$reward->setMoney(new EmbeddableMoney($record['amount'] * 100, 'EUR'));
|
||||
$reward->setHasUnits($record['units'] > 0);
|
||||
$reward->setUnitsTotal($record['units'] ?? 0);
|
||||
$reward->setUnitsAvailable($record['units'] ?? 0);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Entity\Accounting;
|
||||
|
||||
use App\Entity\Money;
|
||||
use App\Entity\EmbeddableMoney as Money;
|
||||
use App\Entity\Trait\TimestampedCreationEntity;
|
||||
use App\Mapping\Provider\EntityMapProvider;
|
||||
use App\Repository\Accounting\TransactionRepository;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Money\MoneyInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
@@ -11,7 +12,7 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
* @see \Brick\Money
|
||||
*/
|
||||
#[ORM\Embeddable]
|
||||
class Money
|
||||
class EmbeddableMoney implements MoneyInterface
|
||||
{
|
||||
/**
|
||||
* An amount of currency.\
|
||||
@@ -33,4 +34,22 @@ class Money
|
||||
$this->amount = $amount;
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
public static function of(MoneyInterface $moneyInterface): self
|
||||
{
|
||||
return new self(
|
||||
$moneyInterface->getAmount(),
|
||||
$moneyInterface->getCurrency()
|
||||
);
|
||||
}
|
||||
|
||||
public function getAmount(): int
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
public function getCurrency(): string
|
||||
{
|
||||
return $this->currency;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace App\Entity\Gateway;
|
||||
|
||||
use App\Entity\Accounting\Accounting;
|
||||
use App\Entity\Accounting\Transaction;
|
||||
use App\Entity\Money;
|
||||
use App\Entity\EmbeddableMoney as Money;
|
||||
use App\Entity\Trait\TimestampedCreationEntity;
|
||||
use App\Entity\Trait\TimestampedUpdationEntity;
|
||||
use App\Gateway\ChargeStatus;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Entity\Matchfunding;
|
||||
|
||||
use App\Entity\Money;
|
||||
use App\Entity\EmbeddableMoney as Money;
|
||||
use App\Mapping\Provider\EntityMapProvider;
|
||||
use App\Matchfunding\Formula\MultiplicationFormula;
|
||||
use App\Repository\Matchfunding\MatchStrategyRepository;
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Entity\Project;
|
||||
|
||||
use App\Entity\EmbeddableMoney as Money;
|
||||
use App\Entity\Interface\LocalizedEntityInterface;
|
||||
use App\Entity\Money;
|
||||
use App\Entity\Trait\LocalizedEntityTrait;
|
||||
use App\Entity\Trait\MigratedEntity;
|
||||
use App\Mapping\Provider\EntityMapProvider;
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Entity\Project;
|
||||
|
||||
use App\Entity\EmbeddableMoney as Money;
|
||||
use App\Entity\Interface\LocalizedEntityInterface;
|
||||
use App\Entity\Money;
|
||||
use App\Entity\Trait\LocalizedEntityTrait;
|
||||
use App\Entity\Trait\MigratedEntity;
|
||||
use App\Mapping\Provider\EntityMapProvider;
|
||||
|
||||
@@ -13,10 +13,9 @@ use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[MapProvider(EntityMapProvider::class)]
|
||||
#[ORM\Table(name: 'project_support')]
|
||||
#[ORM\UniqueConstraint(fields: ['project', 'origin'])]
|
||||
#[ORM\Entity(repositoryClass: SupportRepository::class)]
|
||||
#[ORM\Table(name: 'project_support', uniqueConstraints: [
|
||||
new ORM\UniqueConstraint(fields: ['project', 'origin']),
|
||||
])]
|
||||
class Support
|
||||
{
|
||||
#[ORM\Id]
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
namespace App\Entity\Wallet;
|
||||
|
||||
use App\Repository\WalletFinancementRepository;
|
||||
use App\Entity\EmbeddableMoney;
|
||||
use App\Repository\Wallet\WalletFinancementRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
@@ -19,8 +20,8 @@ class WalletFinancement
|
||||
/**
|
||||
* The monetary value used in this Financement.
|
||||
*/
|
||||
#[ORM\Embedded(class: Money::class)]
|
||||
private ?Money $money = null;
|
||||
#[ORM\Embedded(class: EmbeddableMoney::class)]
|
||||
private ?EmbeddableMoney $money = null;
|
||||
|
||||
/**
|
||||
* An incoming Statement that originally saved the money in this Financement.
|
||||
@@ -41,12 +42,12 @@ class WalletFinancement
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getMoney(): ?Money
|
||||
public function getMoney(): ?EmbeddableMoney
|
||||
{
|
||||
return $this->money;
|
||||
}
|
||||
|
||||
public function setMoney(Money $money): static
|
||||
public function setMoney(EmbeddableMoney $money): static
|
||||
{
|
||||
$this->money = $money;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
namespace App\Entity\Wallet;
|
||||
|
||||
use App\Entity\Accounting\Transaction;
|
||||
use App\Entity\EmbeddableMoney;
|
||||
use App\Gateway\Wallet\StatementDirection;
|
||||
use App\Repository\WalletStatementRepository;
|
||||
use App\Repository\Wallet\WalletStatementRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@@ -40,8 +41,8 @@ class WalletStatement
|
||||
* For incoming Statements, the balance tells the available money.\
|
||||
* i.e: money not used yet by outgoing Statements.
|
||||
*/
|
||||
#[ORM\Embedded(class: Money::class)]
|
||||
private ?Money $balance = null;
|
||||
#[ORM\Embedded(class: EmbeddableMoney::class)]
|
||||
private ?EmbeddableMoney $balance = null;
|
||||
|
||||
/**
|
||||
* A collection of Financements for outgoing Statements that were made using money from this Statement.
|
||||
@@ -103,12 +104,12 @@ class WalletStatement
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBalance(): ?Money
|
||||
public function getBalance(): ?EmbeddableMoney
|
||||
{
|
||||
return $this->balance;
|
||||
}
|
||||
|
||||
public function setBalance(Money $balance): static
|
||||
public function setBalance(EmbeddableMoney $balance): static
|
||||
{
|
||||
$this->balance = $balance;
|
||||
|
||||
@@ -17,7 +17,7 @@ final class AuthorizationTokenSubscriber implements EventSubscriberInterface
|
||||
private AuthService $authService,
|
||||
) {}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
KernelEvents::VIEW => ['onView', EventPriorities::POST_WRITE],
|
||||
|
||||
@@ -5,12 +5,12 @@ namespace App\Gateway\Wallet;
|
||||
use App\Entity\Accounting\Transaction;
|
||||
use App\Entity\Gateway\Charge;
|
||||
use App\Entity\Gateway\Checkout;
|
||||
use App\Entity\Money;
|
||||
use App\Gateway\ChargeStatus;
|
||||
use App\Gateway\ChargeType;
|
||||
use App\Gateway\CheckoutStatus;
|
||||
use App\Gateway\GatewayInterface;
|
||||
use App\Library\Economy\MoneyService;
|
||||
use App\Money\Money;
|
||||
use App\Money\MoneyService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
@@ -4,11 +4,12 @@ namespace App\Gateway\Wallet;
|
||||
|
||||
use App\Entity\Accounting\Accounting;
|
||||
use App\Entity\Accounting\Transaction;
|
||||
use App\Entity\Money;
|
||||
use App\Entity\WalletFinancement;
|
||||
use App\Entity\WalletStatement;
|
||||
use App\Library\Economy\MoneyService;
|
||||
use App\Repository\WalletStatementRepository;
|
||||
use App\Entity\EmbeddableMoney;
|
||||
use App\Entity\Wallet\WalletFinancement;
|
||||
use App\Entity\Wallet\WalletStatement;
|
||||
use App\Money\Money;
|
||||
use App\Money\MoneyService;
|
||||
use App\Repository\Wallet\WalletStatementRepository;
|
||||
use Brick\Money as Brick;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
@@ -39,7 +40,10 @@ class WalletService
|
||||
$total = $total->plus($balance);
|
||||
}
|
||||
|
||||
return $this->money->toMoney($total);
|
||||
return new Money(
|
||||
$total->getMinorAmount()->toInt(),
|
||||
$total->getCurrency()->getCurrencyCode()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,7 +81,7 @@ class WalletService
|
||||
$origin = $transaction->getOrigin();
|
||||
|
||||
$spendGoal = $transaction->getMoney();
|
||||
$spentTotal = new Money(0, $spendGoal->currency);
|
||||
$spentTotal = new Money(0, $spendGoal->getCurrency());
|
||||
|
||||
$outgoing = new WalletStatement();
|
||||
$outgoing->setTransaction($transaction);
|
||||
@@ -85,7 +89,7 @@ class WalletService
|
||||
|
||||
$statements = $this->getStatements($origin);
|
||||
foreach ($statements as $statement) {
|
||||
if ($spendGoal->amount === 0) {
|
||||
if ($spendGoal->getAmount() === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -94,9 +98,9 @@ class WalletService
|
||||
}
|
||||
|
||||
$incoming = $statement;
|
||||
$balance = $incoming->getBalance();
|
||||
|
||||
if ($balance->amount === 0) {
|
||||
$balance = $incoming->getBalance();
|
||||
if ($balance->getAmount() === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -107,12 +111,14 @@ class WalletService
|
||||
}
|
||||
|
||||
$financement = new WalletFinancement();
|
||||
$financement->setMoney($balanceSpent);
|
||||
$financement->setMoney(EmbeddableMoney::of($balanceSpent));
|
||||
|
||||
$incoming->setBalance($this->money->substract($balanceSpent, $balance));
|
||||
$substracted = $this->money->substract($balanceSpent, $balance);
|
||||
$incoming->setBalance(EmbeddableMoney::of($substracted));
|
||||
$incoming->addFinancesTo($financement);
|
||||
|
||||
$outgoing->setBalance($this->money->add($balanceSpent, $spentTotal));
|
||||
$added = $this->money->add($balanceSpent, $spentTotal);
|
||||
$outgoing->setBalance(EmbeddableMoney::of($added));
|
||||
$outgoing->addFinancedBy($financement);
|
||||
|
||||
$this->entityManager->persist($incoming);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Mapping\Transformer;
|
||||
|
||||
use App\ApiResource\ApiMoney;
|
||||
use App\ApiResource\Project\Budget;
|
||||
use App\ApiResource\Project\BudgetSummary;
|
||||
use App\Entity\Project\BudgetItem;
|
||||
@@ -45,25 +46,25 @@ class BudgetMapTransformer implements PropertyTransformerInterface
|
||||
|
||||
$summary = new BudgetSummary();
|
||||
|
||||
$summary->money = $this->budgetService->calcBudget(
|
||||
$summary->money = ApiMoney::of($this->budgetService->calcBudget(
|
||||
$items,
|
||||
$currency
|
||||
)[$deadline];
|
||||
)[$deadline]);
|
||||
|
||||
$summary->task = $this->budgetService->calcBudget(
|
||||
$summary->task = ApiMoney::of($this->budgetService->calcBudget(
|
||||
$this->filterItemsByType($items, BudgetItemType::Task),
|
||||
$currency
|
||||
)[$deadline];
|
||||
)[$deadline]);
|
||||
|
||||
$summary->material = $this->budgetService->calcBudget(
|
||||
$summary->material = ApiMoney::of($this->budgetService->calcBudget(
|
||||
$this->filterItemsByType($items, BudgetItemType::Material),
|
||||
$currency
|
||||
)[$deadline];
|
||||
)[$deadline]);
|
||||
|
||||
$summary->infra = $this->budgetService->calcBudget(
|
||||
$summary->infra = ApiMoney::of($this->budgetService->calcBudget(
|
||||
$this->filterItemsByType($items, BudgetItemType::Infrastructure),
|
||||
$currency
|
||||
)[$deadline];
|
||||
)[$deadline]);
|
||||
|
||||
return $summary;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace App\Mapping\Transformer;
|
||||
|
||||
use App\Entity\Money;
|
||||
use App\ApiResource\ApiMoney;
|
||||
use App\Entity\Project\Support;
|
||||
use App\Library\Economy\MoneyService;
|
||||
use App\Money\Money;
|
||||
use App\Money\MoneyService;
|
||||
use AutoMapper\Transformer\PropertyTransformer\PropertyTransformerInterface;
|
||||
|
||||
class SupportMoneyMapTransformer implements PropertyTransformerInterface
|
||||
@@ -25,6 +26,6 @@ class SupportMoneyMapTransformer implements PropertyTransformerInterface
|
||||
$money = $this->moneyService->add($transaction->getMoney(), $money);
|
||||
}
|
||||
|
||||
return $money;
|
||||
return ApiMoney::of($money);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
namespace App\Matchfunding\Formula;
|
||||
|
||||
use App\Entity\Money;
|
||||
use App\Money\Money;
|
||||
use App\Money\MoneyInterface;
|
||||
|
||||
interface FormulaInterface
|
||||
{
|
||||
@@ -19,11 +20,11 @@ interface FormulaInterface
|
||||
/**
|
||||
* Process an input Money and obtain a delta Money, which is the Money to be given by the Matcher.
|
||||
*
|
||||
* @param float $factor A matching factor for the formula to use
|
||||
* @param Money $money The input Money that is to be matched
|
||||
* @param Money $limit An upper bound for the matching formula, the delta won't be higher than this
|
||||
* @param float $factor A matching factor for the formula to use
|
||||
* @param MoneyInterface $money The input Money that is to be matched
|
||||
* @param MoneyInterface $limit An upper bound for the matching formula, the delta won't be higher than this
|
||||
*
|
||||
* @return Money The output Money delta
|
||||
*/
|
||||
public function match(float $factor, Money $money, Money $limit): Money;
|
||||
public function match(float $factor, MoneyInterface $money, MoneyInterface $limit): Money;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
namespace App\Matchfunding\Formula;
|
||||
|
||||
use App\Entity\Money;
|
||||
use App\Library\Economy\MoneyService;
|
||||
use App\Money\Money;
|
||||
use App\Money\MoneyInterface;
|
||||
use App\Money\MoneyService;
|
||||
|
||||
class MultiplicationFormula implements FormulaInterface
|
||||
{
|
||||
@@ -17,12 +18,11 @@ class MultiplicationFormula implements FormulaInterface
|
||||
return 'min(factor * money, limit)';
|
||||
}
|
||||
|
||||
public function match(float $factor, Money $money, Money $limit): Money
|
||||
public function match(float $factor, MoneyInterface $money, MoneyInterface $limit): Money
|
||||
{
|
||||
$delta = \Brick\Money\Money::min(
|
||||
MoneyService::toBrick($limit),
|
||||
MoneyService::toBrick($money)
|
||||
->multipliedBy($factor)
|
||||
MoneyService::toBrick($money)->multipliedBy($factor)
|
||||
);
|
||||
|
||||
return MoneyService::toMoney($delta);
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
namespace App\Matchfunding\Formula;
|
||||
|
||||
use App\Entity\Money;
|
||||
use App\Library\Economy\MoneyService;
|
||||
use App\Money\Money;
|
||||
use App\Money\MoneyInterface;
|
||||
use App\Money\MoneyService;
|
||||
|
||||
class PercentageFormula implements FormulaInterface
|
||||
{
|
||||
@@ -17,13 +18,11 @@ class PercentageFormula implements FormulaInterface
|
||||
return 'min(factor * money / 100, limit)';
|
||||
}
|
||||
|
||||
public function match(float $factor, Money $money, Money $limit): Money
|
||||
public function match(float $factor, MoneyInterface $money, MoneyInterface $limit): Money
|
||||
{
|
||||
$delta = \Brick\Money\Money::min(
|
||||
MoneyService::toBrick($limit),
|
||||
MoneyService::toBrick($money)
|
||||
->multipliedBy($factor)
|
||||
->dividedBy(100)
|
||||
MoneyService::toBrick($money)->multipliedBy($factor)->dividedBy(100)
|
||||
);
|
||||
|
||||
return MoneyService::toMoney($delta);
|
||||
|
||||
+5
-4
@@ -1,9 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library\Economy\Currency;
|
||||
namespace App\Money\Currency;
|
||||
|
||||
use App\Entity\Money;
|
||||
use App\Library\Economy\MoneyService;
|
||||
use App\Money\Money;
|
||||
use App\Money\MoneyInterface;
|
||||
use App\Money\MoneyService;
|
||||
use Brick\Math\RoundingMode;
|
||||
use Brick\Money\CurrencyConverter;
|
||||
use Brick\Money\ExchangeRateProvider;
|
||||
@@ -71,7 +72,7 @@ class EuropeanCentralBankExchange implements ExchangeInterface
|
||||
return self::WEIGHT;
|
||||
}
|
||||
|
||||
public function convert(Money $money, string $toCurrency): Money
|
||||
public function convert(MoneyInterface $money, string $toCurrency): MoneyInterface
|
||||
{
|
||||
$converted = $this->converter->convert(
|
||||
MoneyService::toBrick($money),
|
||||
+6
-6
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library\Economy\Currency;
|
||||
namespace App\Money\Currency;
|
||||
|
||||
use App\Entity\Money;
|
||||
use App\Money\MoneyInterface;
|
||||
use Brick\Money\Exception\CurrencyConversionException;
|
||||
|
||||
interface ExchangeInterface
|
||||
@@ -18,14 +18,14 @@ interface ExchangeInterface
|
||||
public function getWeight(): int;
|
||||
|
||||
/**
|
||||
* @param Money $money The money to be converted
|
||||
* @param string $toCurrency The currency to convert to
|
||||
* @param MoneyInterface $money The money to be converted
|
||||
* @param string $toCurrency The currency to convert to
|
||||
*
|
||||
* @return Money The converted Money
|
||||
* @return MoneyInterface The converted MoneyInterface
|
||||
*
|
||||
* @throws CurrencyConversionException If the exchange rate is not available
|
||||
*/
|
||||
public function convert(Money $money, string $toCurrency): Money;
|
||||
public function convert(MoneyInterface $money, string $toCurrency): MoneyInterface;
|
||||
|
||||
/**
|
||||
* @param string $fromCurrency The currency to convert from
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library\Economy\Currency;
|
||||
namespace App\Money\Currency;
|
||||
|
||||
use Brick\Money\Exception\CurrencyConversionException;
|
||||
|
||||
@@ -24,7 +24,7 @@ class ExchangeLocator
|
||||
* @param ExchangeInterface $b
|
||||
*/
|
||||
usort($exchanges, function ($a, $b) {
|
||||
return $a->getWeight() < $b->getWeight();
|
||||
return $a->getWeight() <=> $b->getWeight();
|
||||
});
|
||||
|
||||
foreach ($exchanges as $exchange) {
|
||||
+5
-4
@@ -1,9 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library\Economy\Currency;
|
||||
namespace App\Money\Currency;
|
||||
|
||||
use App\Entity\Money;
|
||||
use App\Library\Economy\MoneyService;
|
||||
use App\Money\Money;
|
||||
use App\Money\MoneyInterface;
|
||||
use App\Money\MoneyService;
|
||||
use Brick\Math\RoundingMode;
|
||||
use Brick\Money\CurrencyConverter;
|
||||
use Brick\Money\ExchangeRateProvider;
|
||||
@@ -49,7 +50,7 @@ class FrankfurterExchange implements ExchangeInterface
|
||||
$this->converter = new CurrencyConverter($this->provider);
|
||||
}
|
||||
|
||||
public function convert(Money $money, string $toCurrency): Money
|
||||
public function convert(MoneyInterface $money, string $toCurrency): MoneyInterface
|
||||
{
|
||||
$converted = $this->converter->convert(
|
||||
MoneyService::toBrick($money),
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Money;
|
||||
|
||||
class Money implements MoneyInterface
|
||||
{
|
||||
public function __construct(
|
||||
private int $amount,
|
||||
private string $currency,
|
||||
) {}
|
||||
|
||||
public function getAmount(): int
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
public function getCurrency(): string
|
||||
{
|
||||
return $this->currency;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Money;
|
||||
|
||||
interface MoneyInterface
|
||||
{
|
||||
/**
|
||||
* @return int The monetary amount value. As expressed in the minor unit of the currency.
|
||||
*/
|
||||
public function getAmount(): int;
|
||||
|
||||
/**
|
||||
* @return string 3-letter ISO 4217 currency code
|
||||
*/
|
||||
public function getCurrency(): string;
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library\Economy;
|
||||
namespace App\Money;
|
||||
|
||||
use App\Entity\Money;
|
||||
use App\Library\Economy\Currency\ExchangeLocator;
|
||||
use Brick\Money as Brick;
|
||||
use App\Money\Currency\ExchangeLocator;
|
||||
use Brick\Money\Money as BrickMoney;
|
||||
|
||||
class MoneyService
|
||||
{
|
||||
@@ -12,7 +11,7 @@ class MoneyService
|
||||
private ExchangeLocator $exchangeLocator,
|
||||
) {}
|
||||
|
||||
public static function toMoney(Brick\Money $brick): Money
|
||||
public static function toMoney(BrickMoney $brick): Money
|
||||
{
|
||||
return new Money(
|
||||
$brick->getMinorAmount()->toInt(),
|
||||
@@ -20,17 +19,17 @@ class MoneyService
|
||||
);
|
||||
}
|
||||
|
||||
public static function toBrick(Money $money): Brick\Money
|
||||
public static function toBrick(MoneyInterface $money): BrickMoney
|
||||
{
|
||||
return Brick\Money::ofMinor($money->amount, $money->currency);
|
||||
return BrickMoney::ofMinor($money->getAmount(), $money->getCurrency());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds `a` to `b`.
|
||||
*/
|
||||
public function add(Money $a, Money $b): Money
|
||||
public function add(MoneyInterface $a, MoneyInterface $b): Money
|
||||
{
|
||||
$a = $this->convert($a, $b->currency);
|
||||
$a = $this->convert($a, $b->getCurrency());
|
||||
$ab = self::toBrick($b)->plus($a);
|
||||
|
||||
return self::toMoney($ab);
|
||||
@@ -39,9 +38,9 @@ class MoneyService
|
||||
/**
|
||||
* Substracts `a` from `b`.
|
||||
*/
|
||||
public function substract(Money $a, Money $b): Money
|
||||
public function substract(MoneyInterface $a, MoneyInterface $b): Money
|
||||
{
|
||||
$a = $this->convert($a, $b->currency);
|
||||
$a = $this->convert($a, $b->getCurrency());
|
||||
$ab = self::toBrick($b)->minus($a);
|
||||
|
||||
return self::toMoney($ab);
|
||||
@@ -52,9 +51,9 @@ class MoneyService
|
||||
*
|
||||
* @return bool `true` if `$money` is less than `$than`
|
||||
*/
|
||||
public function isLess(Money $money, Money $than): bool
|
||||
public function isLess(MoneyInterface $money, MoneyInterface $than): bool
|
||||
{
|
||||
$money = $this->convert($money, $than->currency);
|
||||
$money = $this->convert($money, $than->getCurrency());
|
||||
|
||||
return $money->isLessThan(self::toBrick($than));
|
||||
}
|
||||
@@ -64,16 +63,16 @@ class MoneyService
|
||||
*
|
||||
* @return bool `true` if `$money` is more than or same as `$than`
|
||||
*/
|
||||
public function isMoreOrSame(Money $money, Money $than): bool
|
||||
public function isMoreOrSame(MoneyInterface $money, MoneyInterface $than): bool
|
||||
{
|
||||
$money = $this->convert($money, $than->currency);
|
||||
$money = $this->convert($money, $than->getCurrency());
|
||||
|
||||
return $money->isGreaterThanOrEqualTo(self::toBrick($than));
|
||||
}
|
||||
|
||||
private function convert(Money $money, string $toCurrency): Brick\Money
|
||||
private function convert(MoneyInterface $money, string $toCurrency): BrickMoney
|
||||
{
|
||||
$fromCurrency = $money->currency;
|
||||
$fromCurrency = $money->getCurrency();
|
||||
if ($fromCurrency === $toCurrency) {
|
||||
return self::toBrick($money);
|
||||
}
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
namespace App\Repository\Wallet;
|
||||
|
||||
use App\Entity\WalletFinancement;
|
||||
use App\Entity\Wallet\WalletFinancement;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
namespace App\Repository\Wallet;
|
||||
|
||||
use App\Entity\Accounting\Accounting;
|
||||
use App\Entity\Accounting\Transaction;
|
||||
use App\Entity\WalletStatement;
|
||||
use App\Entity\Wallet\WalletStatement;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
@@ -3,12 +3,14 @@
|
||||
namespace App\Service;
|
||||
|
||||
use App\ApiResource\Accounting\AccountingBalancePoint;
|
||||
use App\ApiResource\ApiMoney;
|
||||
use App\Entity\Accounting\Accounting;
|
||||
use App\Entity\Accounting\Transaction;
|
||||
use App\Entity\Money;
|
||||
use App\Entity\User\User;
|
||||
use App\Gateway\Wallet\WalletService;
|
||||
use App\Library\Economy\MoneyService;
|
||||
use App\Money\Money;
|
||||
use App\Money\MoneyInterface;
|
||||
use App\Money\MoneyService;
|
||||
use App\Repository\Accounting\TransactionRepository;
|
||||
|
||||
class AccountingService
|
||||
@@ -64,13 +66,13 @@ class AccountingService
|
||||
private function createPoint(
|
||||
\DateTimeInterface $lowerBound,
|
||||
\DateTimeInterface $upperBound,
|
||||
Money $balance,
|
||||
MoneyInterface $balance,
|
||||
array $transactions,
|
||||
): AccountingBalancePoint {
|
||||
$point = new AccountingBalancePoint();
|
||||
$point->start = $lowerBound;
|
||||
$point->end = $upperBound;
|
||||
$point->balance = $balance;
|
||||
$point->balance = ApiMoney::of($balance);
|
||||
$point->length = count($transactions);
|
||||
|
||||
return $point;
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Service\Project;
|
||||
|
||||
use App\Entity\Money;
|
||||
use App\Entity\Project\BudgetItem;
|
||||
use App\Entity\Project\ProjectDeadline;
|
||||
use App\Library\Economy\MoneyService;
|
||||
use App\Money\Money;
|
||||
use App\Money\MoneyService;
|
||||
|
||||
class BudgetService
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace App\Validator;
|
||||
|
||||
use App\ApiResource\Project\RewardClaimApiResource;
|
||||
use App\Library\Economy\MoneyService;
|
||||
use App\Money\MoneyService;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace App\Tests\Gateway\Wallet;
|
||||
|
||||
use App\Entity\Accounting\Transaction;
|
||||
use App\Entity\Money;
|
||||
use App\Entity\EmbeddableMoney;
|
||||
use App\Entity\Tipjar;
|
||||
use App\Entity\User\User;
|
||||
use App\Gateway\Wallet\StatementDirection;
|
||||
@@ -62,19 +62,19 @@ class WalletServiceTest extends KernelTestCase
|
||||
|
||||
$balance = $this->walletService->getBalance($user);
|
||||
|
||||
$this->assertEquals(0, $balance->amount);
|
||||
$this->assertEquals($user->getCurrency(), $balance->currency);
|
||||
$this->assertEquals(0, $balance->getAmount());
|
||||
$this->assertEquals($user->getCurrency(), $balance->getCurrency());
|
||||
|
||||
$incoming = new Transaction();
|
||||
$incoming->setMoney(new Money(100, 'EUR'));
|
||||
$incoming->setMoney(new EmbeddableMoney(100, 'EUR'));
|
||||
$incoming->setOrigin($tipjar);
|
||||
$incoming->setTarget($user);
|
||||
|
||||
$income = $this->walletService->save($incoming);
|
||||
|
||||
$this->assertEquals(100, $income->getBalance()->amount);
|
||||
$this->assertEquals(100, $income->getBalance()->getAmount());
|
||||
$this->assertEquals(StatementDirection::Incoming->value, $income->getDirection()->value);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
$this->assertCount(0, $income->getFinancesTo());
|
||||
$this->assertCount(0, $income->getFinancedBy());
|
||||
|
||||
@@ -83,17 +83,17 @@ class WalletServiceTest extends KernelTestCase
|
||||
|
||||
$balance = $this->walletService->getBalance($user);
|
||||
|
||||
$this->assertEquals(100, $balance->amount);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals(100, $balance->getAmount());
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
|
||||
$statements = $this->walletService->getStatements($user);
|
||||
|
||||
$this->assertCount(1, $statements);
|
||||
|
||||
$statement = $statements[0];
|
||||
$this->assertEquals(100, $statement->getBalance()->amount);
|
||||
$this->assertEquals(100, $statement->getBalance()->getAmount());
|
||||
$this->assertEquals(StatementDirection::Incoming->value, $statement->getDirection()->value);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
$this->assertCount(0, $statement->getFinancesTo());
|
||||
$this->assertCount(0, $statement->getFinancedBy());
|
||||
}
|
||||
@@ -109,11 +109,11 @@ class WalletServiceTest extends KernelTestCase
|
||||
|
||||
$balance = $this->walletService->getBalance($user);
|
||||
|
||||
$this->assertEquals(0, $balance->amount);
|
||||
$this->assertEquals($user->getCurrency(), $balance->currency);
|
||||
$this->assertEquals(0, $balance->getAmount());
|
||||
$this->assertEquals($user->getCurrency(), $balance->getCurrency());
|
||||
|
||||
$incoming = new Transaction();
|
||||
$incoming->setMoney(new Money(100, 'EUR'));
|
||||
$incoming->setMoney(new EmbeddableMoney(100, 'EUR'));
|
||||
$incoming->setOrigin($tipjar);
|
||||
$incoming->setTarget($user);
|
||||
|
||||
@@ -122,17 +122,17 @@ class WalletServiceTest extends KernelTestCase
|
||||
|
||||
$balance = $this->walletService->getBalance($user);
|
||||
|
||||
$this->assertEquals(100, $balance->amount);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals(100, $balance->getAmount());
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
|
||||
$statements = $this->walletService->getStatements($user);
|
||||
|
||||
$this->assertCount(1, $statements);
|
||||
|
||||
$statement = $statements[0];
|
||||
$this->assertEquals(100, $statement->getBalance()->amount);
|
||||
$this->assertEquals(100, $statement->getBalance()->getAmount());
|
||||
$this->assertEquals(StatementDirection::Incoming->value, $statement->getDirection()->value);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
$this->assertCount(0, $statement->getFinancesTo());
|
||||
$this->assertCount(0, $statement->getFinancedBy());
|
||||
}
|
||||
@@ -143,7 +143,7 @@ class WalletServiceTest extends KernelTestCase
|
||||
$user = $this->getUser()->getAccounting();
|
||||
|
||||
$incoming = new Transaction();
|
||||
$incoming->setMoney(new Money(100, 'EUR'));
|
||||
$incoming->setMoney(new EmbeddableMoney(100, 'EUR'));
|
||||
$incoming->setOrigin($tipjar);
|
||||
$incoming->setTarget($user);
|
||||
|
||||
@@ -151,7 +151,7 @@ class WalletServiceTest extends KernelTestCase
|
||||
$this->entityManager->flush();
|
||||
|
||||
$outgoing = new Transaction();
|
||||
$outgoing->setMoney(new Money(20, 'EUR'));
|
||||
$outgoing->setMoney(new EmbeddableMoney(20, 'EUR'));
|
||||
$outgoing->setOrigin($user);
|
||||
$outgoing->setTarget($tipjar);
|
||||
|
||||
@@ -162,29 +162,29 @@ class WalletServiceTest extends KernelTestCase
|
||||
|
||||
$balance = $this->walletService->getBalance($user);
|
||||
|
||||
$this->assertEquals(80, $balance->amount);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals(80, $balance->getAmount());
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
|
||||
$statements = $this->walletService->getStatements($user);
|
||||
|
||||
$this->assertCount(2, $statements);
|
||||
|
||||
$statement = $statements[0];
|
||||
$this->assertEquals(80, $statement->getBalance()->amount);
|
||||
$this->assertEquals(80, $statement->getBalance()->getAmount());
|
||||
$this->assertEquals(StatementDirection::Incoming->value, $statement->getDirection()->value);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
$this->assertCount(1, $statement->getFinancesTo());
|
||||
$this->assertCount(0, $statement->getFinancedBy());
|
||||
|
||||
$statement = $statements[1];
|
||||
$this->assertEquals(20, $statement->getBalance()->amount);
|
||||
$this->assertEquals(20, $statement->getBalance()->getAmount());
|
||||
$this->assertEquals(StatementDirection::Outgoing->value, $statement->getDirection()->value);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
$this->assertCount(0, $statement->getFinancesTo());
|
||||
$this->assertCount(1, $statement->getFinancedBy());
|
||||
|
||||
$outgoing = new Transaction();
|
||||
$outgoing->setMoney(new Money(30, 'EUR'));
|
||||
$outgoing->setMoney(new EmbeddableMoney(30, 'EUR'));
|
||||
$outgoing->setOrigin($user);
|
||||
$outgoing->setTarget($tipjar);
|
||||
|
||||
@@ -195,43 +195,43 @@ class WalletServiceTest extends KernelTestCase
|
||||
|
||||
$balance = $this->walletService->getBalance($user);
|
||||
|
||||
$this->assertEquals(50, $balance->amount);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals(50, $balance->getAmount());
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
|
||||
$statements = $this->walletService->getStatements($user);
|
||||
|
||||
$this->assertCount(3, $statements);
|
||||
|
||||
$statement = $statements[0];
|
||||
$this->assertEquals(50, $statement->getBalance()->amount);
|
||||
$this->assertEquals(50, $statement->getBalance()->getAmount());
|
||||
$this->assertEquals(StatementDirection::Incoming->value, $statement->getDirection()->value);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
$this->assertCount(2, $statement->getFinancesTo());
|
||||
$this->assertCount(0, $statement->getFinancedBy());
|
||||
|
||||
$statement = $statements[1];
|
||||
$this->assertEquals(20, $statement->getBalance()->amount);
|
||||
$this->assertEquals(20, $statement->getBalance()->getAmount());
|
||||
$this->assertEquals(StatementDirection::Outgoing->value, $statement->getDirection()->value);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
$this->assertCount(0, $statement->getFinancesTo());
|
||||
$this->assertCount(1, $statement->getFinancedBy());
|
||||
|
||||
$financement = $statements[0]->getFinancesTo()[0];
|
||||
$this->assertEquals(20, $financement->getMoney()->amount);
|
||||
$this->assertEquals('EUR', $financement->getMoney()->currency);
|
||||
$this->assertEquals(20, $financement->getMoney()->getAmount());
|
||||
$this->assertEquals('EUR', $financement->getMoney()->getCurrency());
|
||||
$this->assertSame($financement, $statement->getFinancedBy()[0]);
|
||||
$this->assertEquals($financement->getId(), $statement->getFinancedBy()[0]->getId());
|
||||
|
||||
$statement = $statements[2];
|
||||
$this->assertEquals(30, $statement->getBalance()->amount);
|
||||
$this->assertEquals(30, $statement->getBalance()->getAmount());
|
||||
$this->assertEquals(StatementDirection::Outgoing->value, $statement->getDirection()->value);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
$this->assertCount(0, $statement->getFinancesTo());
|
||||
$this->assertCount(1, $statement->getFinancedBy());
|
||||
|
||||
$financement = $statements[0]->getFinancesTo()[1];
|
||||
$this->assertEquals(30, $financement->getMoney()->amount);
|
||||
$this->assertEquals('EUR', $financement->getMoney()->currency);
|
||||
$this->assertEquals(30, $financement->getMoney()->getAmount());
|
||||
$this->assertEquals('EUR', $financement->getMoney()->getCurrency());
|
||||
$this->assertSame($financement, $statement->getFinancedBy()[0]);
|
||||
$this->assertEquals($financement->getId(), $statement->getFinancedBy()[0]->getId());
|
||||
}
|
||||
@@ -242,7 +242,7 @@ class WalletServiceTest extends KernelTestCase
|
||||
$user = $this->getUser()->getAccounting();
|
||||
|
||||
$incoming = new Transaction();
|
||||
$incoming->setMoney(new Money(10, 'EUR'));
|
||||
$incoming->setMoney(new EmbeddableMoney(10, 'EUR'));
|
||||
$incoming->setOrigin($tipjar);
|
||||
$incoming->setTarget($user);
|
||||
|
||||
@@ -250,7 +250,7 @@ class WalletServiceTest extends KernelTestCase
|
||||
$this->entityManager->flush();
|
||||
|
||||
$incoming = new Transaction();
|
||||
$incoming->setMoney(new Money(11, 'EUR'));
|
||||
$incoming->setMoney(new EmbeddableMoney(11, 'EUR'));
|
||||
$incoming->setOrigin($tipjar);
|
||||
$incoming->setTarget($user);
|
||||
|
||||
@@ -258,7 +258,7 @@ class WalletServiceTest extends KernelTestCase
|
||||
$this->entityManager->flush();
|
||||
|
||||
$outgoing = new Transaction();
|
||||
$outgoing->setMoney(new Money(12, 'EUR'));
|
||||
$outgoing->setMoney(new EmbeddableMoney(12, 'EUR'));
|
||||
$outgoing->setOrigin($user);
|
||||
$outgoing->setTarget($tipjar);
|
||||
|
||||
@@ -268,7 +268,7 @@ class WalletServiceTest extends KernelTestCase
|
||||
$this->entityManager->flush();
|
||||
|
||||
$incoming = new Transaction();
|
||||
$incoming->setMoney(new Money(13, 'EUR'));
|
||||
$incoming->setMoney(new EmbeddableMoney(13, 'EUR'));
|
||||
$incoming->setOrigin($tipjar);
|
||||
$incoming->setTarget($user);
|
||||
|
||||
@@ -277,38 +277,38 @@ class WalletServiceTest extends KernelTestCase
|
||||
|
||||
$balance = $this->walletService->getBalance($user);
|
||||
|
||||
$this->assertEquals(22, $balance->amount);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals(22, $balance->getAmount());
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
|
||||
$statements = $this->walletService->getStatements($user);
|
||||
|
||||
$this->assertCount(4, $statements);
|
||||
|
||||
$statement = $statements[0];
|
||||
$this->assertEquals(0, $statement->getBalance()->amount);
|
||||
$this->assertEquals(0, $statement->getBalance()->getAmount());
|
||||
$this->assertEquals(StatementDirection::Incoming->value, $statement->getDirection()->value);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
$this->assertCount(1, $statement->getFinancesTo());
|
||||
$this->assertCount(0, $statement->getFinancedBy());
|
||||
|
||||
$statement = $statements[1];
|
||||
$this->assertEquals(9, $statement->getBalance()->amount);
|
||||
$this->assertEquals(9, $statement->getBalance()->getAmount());
|
||||
$this->assertEquals(StatementDirection::Incoming->value, $statement->getDirection()->value);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
$this->assertCount(1, $statement->getFinancesTo());
|
||||
$this->assertCount(0, $statement->getFinancedBy());
|
||||
|
||||
$statement = $statements[2];
|
||||
$this->assertEquals(12, $statement->getBalance()->amount);
|
||||
$this->assertEquals(12, $statement->getBalance()->getAmount());
|
||||
$this->assertEquals(StatementDirection::Outgoing->value, $statement->getDirection()->value);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
$this->assertCount(0, $statement->getFinancesTo());
|
||||
$this->assertCount(2, $statement->getFinancedBy());
|
||||
|
||||
$statement = $statements[3];
|
||||
$this->assertEquals(13, $statement->getBalance()->amount);
|
||||
$this->assertEquals(13, $statement->getBalance()->getAmount());
|
||||
$this->assertEquals(StatementDirection::Incoming->value, $statement->getDirection()->value);
|
||||
$this->assertEquals('EUR', $balance->currency);
|
||||
$this->assertEquals('EUR', $balance->getCurrency());
|
||||
$this->assertCount(0, $statement->getFinancesTo());
|
||||
$this->assertCount(0, $statement->getFinancedBy());
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Tests\Library\Economy\Currency;
|
||||
|
||||
use App\Library\Economy\Currency\EuropeanCentralBankExchange;
|
||||
use App\Money\Currency\EuropeanCentralBankExchange;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Tests\Library\Economy;
|
||||
|
||||
use App\Entity\Money;
|
||||
use App\Library\Economy\MoneyService;
|
||||
use App\Money\Money;
|
||||
use App\Money\MoneyService;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
@@ -64,17 +64,17 @@ class MoneyServiceTest extends KernelTestCase
|
||||
|
||||
$c = $this->moneyService->add($a, $b);
|
||||
|
||||
$this->assertEquals(100, $a->amount);
|
||||
$this->assertEquals(110, $b->amount);
|
||||
$this->assertEquals(210, $c->amount);
|
||||
$this->assertEquals(100, $a->getAmount());
|
||||
$this->assertEquals(110, $b->getAmount());
|
||||
$this->assertEquals(210, $c->getAmount());
|
||||
|
||||
$d = new Money(100, 'USD');
|
||||
$e = $this->moneyService->add($a, $d);
|
||||
|
||||
$this->assertEquals($d->amount, $a->amount);
|
||||
$this->assertEquals($d->currency, $e->currency);
|
||||
$this->assertEquals($d->getAmount(), $a->getAmount());
|
||||
$this->assertEquals($d->getCurrency(), $e->getCurrency());
|
||||
|
||||
$this->assertNotEquals($d->amount, $e->amount);
|
||||
$this->assertNotEquals($d->getAmount(), $e->getAmount());
|
||||
$this->assertTrue($this->moneyService->isMoreOrSame($e, $d));
|
||||
$this->assertTrue($this->moneyService->isMoreOrSame($e, $a));
|
||||
}
|
||||
@@ -86,16 +86,16 @@ class MoneyServiceTest extends KernelTestCase
|
||||
|
||||
$c = $this->moneyService->substract($a, $b);
|
||||
|
||||
$this->assertEquals(101, $a->amount);
|
||||
$this->assertEquals(210, $b->amount);
|
||||
$this->assertEquals(109, $c->amount);
|
||||
$this->assertEquals(101, $a->getAmount());
|
||||
$this->assertEquals(210, $b->getAmount());
|
||||
$this->assertEquals(109, $c->getAmount());
|
||||
|
||||
$d = new Money(500, 'USD');
|
||||
$e = $this->moneyService->substract($a, $d);
|
||||
|
||||
$this->assertEquals($d->currency, $e->currency);
|
||||
$this->assertEquals($d->getCurrency(), $e->getCurrency());
|
||||
|
||||
$this->assertNotEquals($d->amount, $e->amount);
|
||||
$this->assertNotEquals($d->getAmount(), $e->getAmount());
|
||||
$this->assertTrue($this->moneyService->isLess($e, $d));
|
||||
$this->assertTrue($this->moneyService->isMoreOrSame($e, $a));
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Tests\Service;
|
||||
|
||||
use App\ApiResource\Accounting\AccountingBalancePoint;
|
||||
use App\Entity\Accounting\Transaction;
|
||||
use App\Entity\Money;
|
||||
use App\Entity\EmbeddableMoney;
|
||||
use App\Entity\Tipjar;
|
||||
use App\Service\AccountingService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -46,7 +46,7 @@ class AccountingServiceTest extends KernelTestCase
|
||||
$target = $i % 2 ? $tipjars[\random_int(5, 9)] : $tipjars[\random_int(0, 5)];
|
||||
|
||||
$trx = new Transaction();
|
||||
$trx->setMoney(new Money(random_int(100, 999), 'EUR'));
|
||||
$trx->setMoney(new EmbeddableMoney(random_int(100, 999), 'EUR'));
|
||||
$trx->setOrigin($origin->getAccounting());
|
||||
$trx->setTarget($target->getAccounting());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user