src/Entity/AchatFournisseur.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AchatFournisseurRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassAchatFournisseurRepository::class)]
  9. class AchatFournisseur
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\ManyToOne(inversedBy'achats')]
  16.     #[ORM\JoinColumn(nullabletrue)]
  17.     private ?Fournisseur $fournisseur null;
  18.     #[ORM\Column(length255nullabletrue)]
  19.     private ?string $numeroFacture null;
  20.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  21.     private ?\DateTimeInterface $dateAchat null;
  22.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  23.     private ?\DateTimeInterface $dateEcheance null;
  24.     #[ORM\Column]
  25.     private ?float $montantHT null;
  26.     #[ORM\Column(nullabletrue)]
  27.     private ?float $montantTVA null;
  28.     #[ORM\Column]
  29.     private ?float $montantTotal null;
  30.     #[ORM\Column(nullabletrue)]
  31.     private ?float $montantPaye 0;
  32.     #[ORM\Column(length50)]
  33.     private ?string $statut 'EN_ATTENTE'// EN_ATTENTE, PARTIELLEMENT_PAYE, PAYE, ANNULE
  34.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  35.     private ?string $description null;
  36.     #[ORM\ManyToOne]
  37.     #[ORM\JoinColumn(nullabletrue)]
  38.     private ?Boutique $boutique null;
  39.     #[ORM\ManyToOne]
  40.     #[ORM\JoinColumn(nullabletrue)]
  41.     private ?User $utilisateur null;
  42.     #[ORM\OneToMany(mappedBy'achat'targetEntityLigneAchat::class, cascade: ['persist''remove'])]
  43.     private Collection $lignes;
  44.     #[ORM\OneToMany(mappedBy'achat'targetEntityPaiementFournisseur::class)]
  45.     private Collection $paiements;
  46.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  47.     private ?\DateTimeInterface $createdAt null;
  48.     #[ORM\OneToOne(inversedBy'achat'cascade: ['persist''remove'])]
  49.     private ?CommandeFournisseur $commande null;
  50.     #[ORM\OneToMany(mappedBy'achatFournisseur'targetEntityEntreeStock::class)]
  51.     private Collection $entreesStock;
  52.     public function __construct()
  53.     {
  54.         $this->lignes = new ArrayCollection();
  55.         $this->paiements = new ArrayCollection();
  56.         $this->entreesStock = new ArrayCollection();
  57.         $this->createdAt = new \DateTime();
  58.         $this->dateAchat = new \DateTime();
  59.     }
  60.     public function getId(): ?int
  61.     {
  62.         return $this->id;
  63.     }
  64.     public function getFournisseur(): ?Fournisseur
  65.     {
  66.         return $this->fournisseur;
  67.     }
  68.     public function setFournisseur(?Fournisseur $fournisseur): static
  69.     {
  70.         $this->fournisseur $fournisseur;
  71.         return $this;
  72.     }
  73.     public function getNumeroFacture(): ?string
  74.     {
  75.         return $this->numeroFacture;
  76.     }
  77.     public function setNumeroFacture(?string $numeroFacture): static
  78.     {
  79.         $this->numeroFacture $numeroFacture;
  80.         return $this;
  81.     }
  82.     public function getDateAchat(): ?\DateTimeInterface
  83.     {
  84.         return $this->dateAchat;
  85.     }
  86.     public function setDateAchat(\DateTimeInterface $dateAchat): static
  87.     {
  88.         $this->dateAchat $dateAchat;
  89.         return $this;
  90.     }
  91.     public function getDateEcheance(): ?\DateTimeInterface
  92.     {
  93.         return $this->dateEcheance;
  94.     }
  95.     public function setDateEcheance(?\DateTimeInterface $dateEcheance): static
  96.     {
  97.         $this->dateEcheance $dateEcheance;
  98.         return $this;
  99.     }
  100.     public function getMontantHT(): ?float
  101.     {
  102.         return $this->montantHT;
  103.     }
  104.     public function setMontantHT(float $montantHT): static
  105.     {
  106.         $this->montantHT $montantHT;
  107.         return $this;
  108.     }
  109.     public function getMontantTVA(): ?float
  110.     {
  111.         return $this->montantTVA;
  112.     }
  113.     public function setMontantTVA(?float $montantTVA): static
  114.     {
  115.         $this->montantTVA $montantTVA;
  116.         return $this;
  117.     }
  118.     public function getMontantTotal(): ?float
  119.     {
  120.         return $this->montantTotal;
  121.     }
  122.     public function setMontantTotal(float $montantTotal): static
  123.     {
  124.         $this->montantTotal $montantTotal;
  125.         return $this;
  126.     }
  127.     public function getMontantPaye(): ?float
  128.     {
  129.         return $this->montantPaye ?? 0;
  130.     }
  131.     public function setMontantPaye(?float $montantPaye): static
  132.     {
  133.         $this->montantPaye $montantPaye;
  134.         return $this;
  135.     }
  136.     public function getStatut(): ?string
  137.     {
  138.         return $this->statut;
  139.     }
  140.     public function setStatut(string $statut): static
  141.     {
  142.         $this->statut $statut;
  143.         return $this;
  144.     }
  145.     public function getDescription(): ?string
  146.     {
  147.         return $this->description;
  148.     }
  149.     public function setDescription(?string $description): static
  150.     {
  151.         $this->description $description;
  152.         return $this;
  153.     }
  154.     public function getBoutique(): ?Boutique
  155.     {
  156.         return $this->boutique;
  157.     }
  158.     public function setBoutique(?Boutique $boutique): static
  159.     {
  160.         $this->boutique $boutique;
  161.         return $this;
  162.     }
  163.     public function getUtilisateur(): ?User
  164.     {
  165.         return $this->utilisateur;
  166.     }
  167.     public function setUtilisateur(?User $utilisateur): static
  168.     {
  169.         $this->utilisateur $utilisateur;
  170.         return $this;
  171.     }
  172.     /**
  173.      * @return Collection<int, LigneAchat>
  174.      */
  175.     public function getLignes(): Collection
  176.     {
  177.         return $this->lignes;
  178.     }
  179.     public function addLigne(LigneAchat $ligne): static
  180.     {
  181.         if (!$this->lignes->contains($ligne)) {
  182.             $this->lignes->add($ligne);
  183.             $ligne->setAchat($this);
  184.         }
  185.         return $this;
  186.     }
  187.     public function removeLigne(LigneAchat $ligne): static
  188.     {
  189.         if ($this->lignes->removeElement($ligne)) {
  190.             if ($ligne->getAchat() === $this) {
  191.                 $ligne->setAchat(null);
  192.             }
  193.         }
  194.         return $this;
  195.     }
  196.     /**
  197.      * @return Collection<int, PaiementFournisseur>
  198.      */
  199.     public function getPaiements(): Collection
  200.     {
  201.         return $this->paiements;
  202.     }
  203.     public function addPaiement(PaiementFournisseur $paiement): static
  204.     {
  205.         if (!$this->paiements->contains($paiement)) {
  206.             $this->paiements->add($paiement);
  207.             $paiement->setAchat($this);
  208.         }
  209.         return $this;
  210.     }
  211.     public function removePaiement(PaiementFournisseur $paiement): static
  212.     {
  213.         if ($this->paiements->removeElement($paiement)) {
  214.             if ($paiement->getAchat() === $this) {
  215.                 $paiement->setAchat(null);
  216.             }
  217.         }
  218.         return $this;
  219.     }
  220.     public function getCreatedAt(): ?\DateTimeInterface
  221.     {
  222.         return $this->createdAt;
  223.     }
  224.     public function setCreatedAt(\DateTimeInterface $createdAt): static
  225.     {
  226.         $this->createdAt $createdAt;
  227.         return $this;
  228.     }
  229.     /**
  230.      * Calcule le montant restant à payer
  231.      */
  232.     public function getMontantRestant(): float
  233.     {
  234.         return $this->montantTotal $this->getMontantPaye();
  235.     }
  236.     /**
  237.      * Met à jour le statut selon les paiements
  238.      */
  239.     public function updateStatut(): void
  240.     {
  241.         $montantPaye $this->calculerMontantPaye();
  242.         $this->setMontantPaye($montantPaye);
  243.         if ($montantPaye <= 0) {
  244.             $this->setStatut('EN_ATTENTE');
  245.         } elseif ($montantPaye >= $this->montantTotal) {
  246.             $this->setStatut('PAYE');
  247.         } else {
  248.             $this->setStatut('PARTIELLEMENT_PAYE');
  249.         }
  250.     }
  251.     /**
  252.      * Calcule le montant payé via les paiements
  253.      */
  254.     public function calculerMontantPaye(): float
  255.     {
  256.         $total 0;
  257.         foreach ($this->paiements as $paiement) {
  258.             $total += $paiement->getMontant();
  259.         }
  260.         return $total;
  261.     }
  262.     public function getCommande(): ?CommandeFournisseur
  263.     {
  264.         return $this->commande;
  265.     }
  266.     public function setCommande(?CommandeFournisseur $commande): static
  267.     {
  268.         $this->commande $commande;
  269.         return $this;
  270.     }
  271.     /**
  272.      * @return Collection<int, EntreeStock>
  273.      */
  274.     public function getEntreesStock(): Collection
  275.     {
  276.         return $this->entreesStock;
  277.     }
  278.     public function addEntreeStock(EntreeStock $entreeStock): static
  279.     {
  280.         if (!$this->entreesStock->contains($entreeStock)) {
  281.             $this->entreesStock->add($entreeStock);
  282.             $entreeStock->setAchatFournisseur($this);
  283.         }
  284.         return $this;
  285.     }
  286.     public function removeEntreeStock(EntreeStock $entreeStock): static
  287.     {
  288.         if ($this->entreesStock->removeElement($entreeStock)) {
  289.             if ($entreeStock->getAchatFournisseur() === $this) {
  290.                 $entreeStock->setAchatFournisseur(null);
  291.             }
  292.         }
  293.         return $this;
  294.     }
  295.     public function __toString(): string
  296.     {
  297.         return sprintf(
  298.             'Achat #%d - %s - %s FCFA',
  299.             $this->id ?? 0,
  300.             $this->fournisseur $this->fournisseur->getNom() : 'Sans fournisseur',
  301.             number_format($this->montantTotal0','' ')
  302.         );
  303.     }
  304. }