src/Entity/PointTransaction.php line 21

Open in your IDE?
  1. <?php
  2.     namespace App\Entity;
  3.     use App\Repository\PointTransactionRepository;
  4.     use App\Traits\DateTrait;
  5.     use DateTime;
  6.     use DateTimeInterface;
  7.     use Doctrine\Common\Collections\ArrayCollection;
  8.     use Doctrine\Common\Collections\Collection;
  9.     use Doctrine\ORM\Mapping as ORM;
  10.     use JMS\Serializer\Annotation as Serializer;
  11.     use JMS\Serializer\Annotation\Expose;
  12.     use Symfony\Component\Validator\Constraints as Assert;
  13.     /**
  14.      * @ORM\Entity(repositoryClass=PointTransactionRepository::class)
  15.      *
  16.      * @Serializer\ExclusionPolicy("ALL")
  17.      */
  18.     class PointTransaction
  19.     {
  20.         use DateTrait;
  21.         /** Solde des commandes */
  22.         private int $orderSolde 0;
  23.         /** Solde des points de fidélités */
  24.         private int $fidelitySolde 0;
  25.         /**
  26.          * Identifiant unique auto-incrémenté
  27.          *
  28.          * @ORM\Id
  29.          * @ORM\GeneratedValue
  30.          * @ORM\Column(type="integer")
  31.          *
  32.          * @Expose
  33.          * @Serializer\Groups({"point_transaction:id"})
  34.          */
  35.         private ?int $id NULL;
  36.         /**
  37.          * Utilisateur lié à la transaction
  38.          *
  39.          * @ORM\ManyToOne(targetEntity=User::class, inversedBy="pointTransactions")
  40.          * @ORM\JoinColumn(nullable=false)
  41.          *
  42.          * @Expose
  43.          * @Serializer\Groups({"point_transaction:user"})
  44.          */
  45.         private ?User $user NULL;
  46.         /**
  47.          * Commande liée à la transaction
  48.          *
  49.          * @ORM\ManyToOne(targetEntity=SaleOrder::class, inversedBy="pointTransactions")
  50.          */
  51.         private ?SaleOrder $saleOrder NULL;
  52.         /**
  53.          * Valeur de la transaction
  54.          *
  55.          * @ORM\Column(type="float")
  56.          *
  57.          * @Expose
  58.          * @Serializer\Groups({"point_transaction:value"})
  59.          */
  60.         private ?float $value NULL;
  61.         /**
  62.          * Label de la transaction
  63.          *
  64.          * @ORM\Column(type="string", length=255)
  65.          *
  66.          * @Assert\NotBlank
  67.          *
  68.          * @Expose
  69.          * @Serializer\Groups({"point_transaction:label"})
  70.          */
  71.         private ?string $label NULL;
  72.         /**
  73.          * Date d'expiration de la transaction
  74.          *
  75.          * @ORM\Column(type="datetime", nullable=true)
  76.          */
  77.         private ?DateTime $expiredAt NULL;
  78.         /**
  79.          * Transaction liée à la transaction
  80.          *
  81.          * @ORM\ManyToOne(
  82.          *     targetEntity=PointTransaction::class,
  83.          *     inversedBy="childrenPointTransactions",
  84.          *     cascade={"persist", "remove"}
  85.          * )
  86.          */
  87.         private ?PointTransaction $linkedPointTransaction NULL;
  88.         /**
  89.          * Liste des transactions enfants liées à la transaction
  90.          *
  91.          * @ORM\OneToMany(targetEntity=PointTransaction::class, mappedBy="linkedPointTransaction", orphanRemoval=true)
  92.          */
  93.         private ?Collection $childrenPointTransactions;
  94.         /**
  95.          * Type de transaction
  96.          *
  97.          * @ORM\ManyToOne(targetEntity=PointTransactionType::class, inversedBy="pointTransactions")
  98.          * @ORM\JoinColumn(nullable=false)
  99.          */
  100.         private ?PointTransactionType $transactionType NULL;
  101.         /**
  102.          * Déclaration d'achat liée à la transaction
  103.          *
  104.          * @ORM\ManyToOne(targetEntity=Purchase::class, inversedBy="pointTransactions")
  105.          */
  106.         private ?Purchase $purchase NULL;
  107.         /**
  108.          * Historique d'import lié à la transaction
  109.          *
  110.          * @ORM\ManyToOne(
  111.          *     targetEntity=PointTransactionImportHistory::class,
  112.          *     inversedBy="pointTransactions",
  113.          *     cascade={"persist"}
  114.          * )
  115.          */
  116.         private ?PointTransactionImportHistory $importHistory NULL;
  117.         /**
  118.          * Date d'effet de la transaction
  119.          *
  120.          * @ORM\Column(type="datetime", nullable=true)
  121.          */
  122.         private ?DateTimeInterface $effectiveAt NULL;
  123.         /**
  124.          * Méthode d'import de la transaction
  125.          *
  126.          * @ORM\Column(type="string", length=32, nullable=true)
  127.          */
  128.         private ?string $importMethod NULL;
  129.         /**
  130.          * Commande de produit personnalisé liée à la transaction
  131.          *
  132.          * @ORM\ManyToOne(targetEntity=CustomProductOrder::class)
  133.          */
  134.         private ?CustomProductOrder $customProductOrder NULL;
  135.         /**
  136.          * Résultat d'activité lié à la transaction
  137.          *
  138.          * @ORM\OneToOne(
  139.          *     targetEntity=UserBusinessResult::class,
  140.          *     inversedBy="pointTransaction",
  141.          *     cascade={"persist", "remove"}
  142.          * )
  143.          */
  144.         private ?UserBusinessResult $businessResult NULL;
  145.         /**
  146.          * Catégorie de la transaction
  147.          *
  148.          * @ORM\Column(type="string", length=64, nullable=true)
  149.          */
  150.         private ?string $category NULL;
  151.         public function __construct()
  152.         {
  153.             $this->childrenPointTransactions = new ArrayCollection();
  154.         }
  155.         public function __toString()
  156.         {
  157.             return $this->getValue() . ' - ' $this->getLabel();
  158.         }
  159.         // MÉTHODES NÉCESSAIRES POUR LE CALCUL DE POINT : NE PAS EFFACER
  160.         public function setOrderSolde$orderSolde ): PointTransaction
  161.         {
  162.             $this->orderSolde += $orderSolde;
  163.             return $this;
  164.         }
  165.         public function getOrderSolde(): int
  166.         {
  167.             return $this->orderSolde;
  168.         }
  169.         public function setFidelitySolde$fidelitySolde ): PointTransaction
  170.         {
  171.             $this->fidelitySolde += $fidelitySolde;
  172.             return $this;
  173.         }
  174.         public function getFidelitySolde(): int
  175.         {
  176.             return $this->fidelitySolde;
  177.         }
  178.         // END METHODES
  179.         public function getId(): ?int
  180.         {
  181.             return $this->id;
  182.         }
  183.         public function getValue(): ?float
  184.         {
  185.             return $this->value;
  186.         }
  187.         public function setValuefloat $value ): self
  188.         {
  189.             $this->value $value;
  190.             return $this;
  191.         }
  192.         public function getLabel(): ?string
  193.         {
  194.             return $this->label;
  195.         }
  196.         public function setLabelstring $label ): self
  197.         {
  198.             $this->label $label;
  199.             return $this;
  200.         }
  201.         public function getExpiredAt(): ?DateTimeInterface
  202.         {
  203.             return $this->expiredAt;
  204.         }
  205.         public function setExpiredAt( ?DateTimeInterface $expiredAt ): self
  206.         {
  207.             $this->expiredAt $expiredAt;
  208.             return $this;
  209.         }
  210.         public function getEffectiveAt(): ?DateTimeInterface
  211.         {
  212.             return $this->effectiveAt;
  213.         }
  214.         public function setEffectiveAt( ?DateTimeInterface $effectiveAt ): self
  215.         {
  216.             $this->effectiveAt $effectiveAt;
  217.             return $this;
  218.         }
  219.         public function getImportMethod(): ?string
  220.         {
  221.             return $this->importMethod;
  222.         }
  223.         public function setImportMethod( ?string $importMethod ): self
  224.         {
  225.             $this->importMethod $importMethod;
  226.             return $this;
  227.         }
  228.         public function getCategory(): ?string
  229.         {
  230.             return $this->category;
  231.         }
  232.         public function setCategory( ?string $category ): self
  233.         {
  234.             $this->category $category;
  235.             return $this;
  236.         }
  237.         public function getUser(): ?User
  238.         {
  239.             return $this->user;
  240.         }
  241.         public function setUser( ?User $user ): self
  242.         {
  243.             $this->user $user;
  244.             return $this;
  245.         }
  246.         public function getSaleOrder(): ?SaleOrder
  247.         {
  248.             return $this->saleOrder;
  249.         }
  250.         public function setSaleOrder( ?SaleOrder $saleOrder ): self
  251.         {
  252.             $this->saleOrder $saleOrder;
  253.             return $this;
  254.         }
  255.         public function getLinkedPointTransaction(): ?self
  256.         {
  257.             return $this->linkedPointTransaction;
  258.         }
  259.         public function setLinkedPointTransaction( ?self $linkedPointTransaction ): self
  260.         {
  261.             $this->linkedPointTransaction $linkedPointTransaction;
  262.             return $this;
  263.         }
  264.         /**
  265.          * @return Collection<int, PointTransaction>
  266.          */
  267.         public function getChildrenPointTransactions(): Collection
  268.         {
  269.             return $this->childrenPointTransactions;
  270.         }
  271.         public function addChildrenPointTransactionPointTransaction $childrenPointTransaction ): self
  272.         {
  273.             if ( !$this->childrenPointTransactions->contains$childrenPointTransaction ) ) {
  274.                 $this->childrenPointTransactions[] = $childrenPointTransaction;
  275.                 $childrenPointTransaction->setLinkedPointTransaction$this );
  276.             }
  277.             return $this;
  278.         }
  279.         public function removeChildrenPointTransactionPointTransaction $childrenPointTransaction ): self
  280.         {
  281.             if ( $this->childrenPointTransactions->removeElement$childrenPointTransaction ) ) {
  282.                 // set the owning side to null (unless already changed)
  283.                 if ( $childrenPointTransaction->getLinkedPointTransaction() === $this ) {
  284.                     $childrenPointTransaction->setLinkedPointTransactionNULL );
  285.                 }
  286.             }
  287.             return $this;
  288.         }
  289.         public function getTransactionType(): ?PointTransactionType
  290.         {
  291.             return $this->transactionType;
  292.         }
  293.         public function setTransactionType( ?PointTransactionType $transactionType ): self
  294.         {
  295.             $this->transactionType $transactionType;
  296.             return $this;
  297.         }
  298.         public function getPurchase(): ?Purchase
  299.         {
  300.             return $this->purchase;
  301.         }
  302.         public function setPurchase( ?Purchase $purchase ): self
  303.         {
  304.             $this->purchase $purchase;
  305.             return $this;
  306.         }
  307.         public function getImportHistory(): ?PointTransactionImportHistory
  308.         {
  309.             return $this->importHistory;
  310.         }
  311.         public function setImportHistory( ?PointTransactionImportHistory $importHistory ): self
  312.         {
  313.             $this->importHistory $importHistory;
  314.             return $this;
  315.         }
  316.         public function getCustomProductOrder(): ?CustomProductOrder
  317.         {
  318.             return $this->customProductOrder;
  319.         }
  320.         public function setCustomProductOrder( ?CustomProductOrder $customProductOrder ): self
  321.         {
  322.             $this->customProductOrder $customProductOrder;
  323.             return $this;
  324.         }
  325.         public function getBusinessResult(): ?UserBusinessResult
  326.         {
  327.             return $this->businessResult;
  328.         }
  329.         public function setBusinessResult( ?UserBusinessResult $businessResult ): self
  330.         {
  331.             $this->businessResult $businessResult;
  332.             return $this;
  333.         }
  334.     }