<?php
namespace App\Entity;
use App\Repository\PointTransactionRepository;
use App\Traits\DateTrait;
use DateTime;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Expose;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=PointTransactionRepository::class)
*
* @Serializer\ExclusionPolicy("ALL")
*/
class PointTransaction
{
use DateTrait;
/** Solde des commandes */
private int $orderSolde = 0;
/** Solde des points de fidélités */
private int $fidelitySolde = 0;
/**
* Identifiant unique auto-incrémenté
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Expose
* @Serializer\Groups({"point_transaction:id"})
*/
private ?int $id = NULL;
/**
* Utilisateur lié à la transaction
*
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="pointTransactions")
* @ORM\JoinColumn(nullable=false)
*
* @Expose
* @Serializer\Groups({"point_transaction:user"})
*/
private ?User $user = NULL;
/**
* Commande liée à la transaction
*
* @ORM\ManyToOne(targetEntity=SaleOrder::class, inversedBy="pointTransactions")
*/
private ?SaleOrder $saleOrder = NULL;
/**
* Valeur de la transaction
*
* @ORM\Column(type="float")
*
* @Expose
* @Serializer\Groups({"point_transaction:value"})
*/
private ?float $value = NULL;
/**
* Label de la transaction
*
* @ORM\Column(type="string", length=255)
*
* @Assert\NotBlank
*
* @Expose
* @Serializer\Groups({"point_transaction:label"})
*/
private ?string $label = NULL;
/**
* Date d'expiration de la transaction
*
* @ORM\Column(type="datetime", nullable=true)
*/
private ?DateTime $expiredAt = NULL;
/**
* Transaction liée à la transaction
*
* @ORM\ManyToOne(
* targetEntity=PointTransaction::class,
* inversedBy="childrenPointTransactions",
* cascade={"persist", "remove"}
* )
*/
private ?PointTransaction $linkedPointTransaction = NULL;
/**
* Liste des transactions enfants liées à la transaction
*
* @ORM\OneToMany(targetEntity=PointTransaction::class, mappedBy="linkedPointTransaction", orphanRemoval=true)
*/
private ?Collection $childrenPointTransactions;
/**
* Type de transaction
*
* @ORM\ManyToOne(targetEntity=PointTransactionType::class, inversedBy="pointTransactions")
* @ORM\JoinColumn(nullable=false)
*/
private ?PointTransactionType $transactionType = NULL;
/**
* Déclaration d'achat liée à la transaction
*
* @ORM\ManyToOne(targetEntity=Purchase::class, inversedBy="pointTransactions")
*/
private ?Purchase $purchase = NULL;
/**
* Historique d'import lié à la transaction
*
* @ORM\ManyToOne(
* targetEntity=PointTransactionImportHistory::class,
* inversedBy="pointTransactions",
* cascade={"persist"}
* )
*/
private ?PointTransactionImportHistory $importHistory = NULL;
/**
* Date d'effet de la transaction
*
* @ORM\Column(type="datetime", nullable=true)
*/
private ?DateTimeInterface $effectiveAt = NULL;
/**
* Méthode d'import de la transaction
*
* @ORM\Column(type="string", length=32, nullable=true)
*/
private ?string $importMethod = NULL;
/**
* Commande de produit personnalisé liée à la transaction
*
* @ORM\ManyToOne(targetEntity=CustomProductOrder::class)
*/
private ?CustomProductOrder $customProductOrder = NULL;
/**
* Résultat d'activité lié à la transaction
*
* @ORM\OneToOne(
* targetEntity=UserBusinessResult::class,
* inversedBy="pointTransaction",
* cascade={"persist", "remove"}
* )
*/
private ?UserBusinessResult $businessResult = NULL;
/**
* Catégorie de la transaction
*
* @ORM\Column(type="string", length=64, nullable=true)
*/
private ?string $category = NULL;
public function __construct()
{
$this->childrenPointTransactions = new ArrayCollection();
}
public function __toString()
{
return $this->getValue() . ' - ' . $this->getLabel();
}
// MÉTHODES NÉCESSAIRES POUR LE CALCUL DE POINT : NE PAS EFFACER
public function setOrderSolde( $orderSolde ): PointTransaction
{
$this->orderSolde += $orderSolde;
return $this;
}
public function getOrderSolde(): int
{
return $this->orderSolde;
}
public function setFidelitySolde( $fidelitySolde ): PointTransaction
{
$this->fidelitySolde += $fidelitySolde;
return $this;
}
public function getFidelitySolde(): int
{
return $this->fidelitySolde;
}
// END METHODES
public function getId(): ?int
{
return $this->id;
}
public function getValue(): ?float
{
return $this->value;
}
public function setValue( float $value ): self
{
$this->value = $value;
return $this;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel( string $label ): self
{
$this->label = $label;
return $this;
}
public function getExpiredAt(): ?DateTimeInterface
{
return $this->expiredAt;
}
public function setExpiredAt( ?DateTimeInterface $expiredAt ): self
{
$this->expiredAt = $expiredAt;
return $this;
}
public function getEffectiveAt(): ?DateTimeInterface
{
return $this->effectiveAt;
}
public function setEffectiveAt( ?DateTimeInterface $effectiveAt ): self
{
$this->effectiveAt = $effectiveAt;
return $this;
}
public function getImportMethod(): ?string
{
return $this->importMethod;
}
public function setImportMethod( ?string $importMethod ): self
{
$this->importMethod = $importMethod;
return $this;
}
public function getCategory(): ?string
{
return $this->category;
}
public function setCategory( ?string $category ): self
{
$this->category = $category;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser( ?User $user ): self
{
$this->user = $user;
return $this;
}
public function getSaleOrder(): ?SaleOrder
{
return $this->saleOrder;
}
public function setSaleOrder( ?SaleOrder $saleOrder ): self
{
$this->saleOrder = $saleOrder;
return $this;
}
public function getLinkedPointTransaction(): ?self
{
return $this->linkedPointTransaction;
}
public function setLinkedPointTransaction( ?self $linkedPointTransaction ): self
{
$this->linkedPointTransaction = $linkedPointTransaction;
return $this;
}
/**
* @return Collection<int, PointTransaction>
*/
public function getChildrenPointTransactions(): Collection
{
return $this->childrenPointTransactions;
}
public function addChildrenPointTransaction( PointTransaction $childrenPointTransaction ): self
{
if ( !$this->childrenPointTransactions->contains( $childrenPointTransaction ) ) {
$this->childrenPointTransactions[] = $childrenPointTransaction;
$childrenPointTransaction->setLinkedPointTransaction( $this );
}
return $this;
}
public function removeChildrenPointTransaction( PointTransaction $childrenPointTransaction ): self
{
if ( $this->childrenPointTransactions->removeElement( $childrenPointTransaction ) ) {
// set the owning side to null (unless already changed)
if ( $childrenPointTransaction->getLinkedPointTransaction() === $this ) {
$childrenPointTransaction->setLinkedPointTransaction( NULL );
}
}
return $this;
}
public function getTransactionType(): ?PointTransactionType
{
return $this->transactionType;
}
public function setTransactionType( ?PointTransactionType $transactionType ): self
{
$this->transactionType = $transactionType;
return $this;
}
public function getPurchase(): ?Purchase
{
return $this->purchase;
}
public function setPurchase( ?Purchase $purchase ): self
{
$this->purchase = $purchase;
return $this;
}
public function getImportHistory(): ?PointTransactionImportHistory
{
return $this->importHistory;
}
public function setImportHistory( ?PointTransactionImportHistory $importHistory ): self
{
$this->importHistory = $importHistory;
return $this;
}
public function getCustomProductOrder(): ?CustomProductOrder
{
return $this->customProductOrder;
}
public function setCustomProductOrder( ?CustomProductOrder $customProductOrder ): self
{
$this->customProductOrder = $customProductOrder;
return $this;
}
public function getBusinessResult(): ?UserBusinessResult
{
return $this->businessResult;
}
public function setBusinessResult( ?UserBusinessResult $businessResult ): self
{
$this->businessResult = $businessResult;
return $this;
}
}