Commit e09330cc by Yvon

ccas : 6228 : create balanceCcas and update amount at each transaction if required

parent 8dd2a2a4
......@@ -31,6 +31,11 @@ class AccountPrestataire extends Account
*/
protected $operations;
/**
* @ORM\Column(type="decimal", scale=2, options={"default": 0.00})
*/
protected $balanceCcas = 0.00;
public function __construct()
{
$this->operations = new ArrayCollection();
......@@ -57,4 +62,21 @@ class AccountPrestataire extends Account
{
return $this->getPrestataire();
}
public function getBalanceCcas(): ?float
{
return $this->balanceCcas;
}
/**
* Can be negative amount.
*
* @param float $montant Used during a transaction to ncrement or decrement balance of CCAS transactions
*/
public function addAmountCcas(float $montant): self
{
$this->balanceCcas += $montant;
return $this;
}
}
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240506132104 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE account_prestataire ADD balance_ccas NUMERIC(10, 2) DEFAULT \'0\' NOT NULL');
$this->addSql('ALTER TABLE prestataire CHANGE iban iban LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:personal_data)\'');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE account_prestataire DROP balance_ccas');
$this->addSql('ALTER TABLE prestataire CHANGE iban iban LONGTEXT CHARACTER SET utf8 DEFAULT NULL COLLATE `utf8_general_ci` COMMENT \'(DC2Type:personal_data)\'');
}
}
......@@ -17,6 +17,7 @@ use App\Entity\OperationPrestataire;
use App\Entity\OperationSiege;
use App\Entity\Prestataire;
use App\Entity\Siege;
use App\Entity\Transaction;
use App\Enum\CurrencyEnum;
use App\Enum\MoyenEnum;
use App\Events\FluxEvent;
......@@ -134,6 +135,13 @@ class OperationUtils
);
// $account->addOperation($operation);
$account->addAmount($operation->getMontant());
if(
$flux instanceof Transaction //only process $flux with getIsCcas method
&& $flux->getIsCcas() //check if this flux should increment ccas balance
&& $account instanceof AccountPrestataire //only process the prestataire side of the flux
) {
$account->addAmountCcas($operation->getMontant());
}
$em->persist($operation);
$em->persist($account);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment