src/Entity/CommandeFournisseur.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CommandeFournisseurRepository;
  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(repositoryClassCommandeFournisseurRepository::class)]
  9. class CommandeFournisseur
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length50uniquetrue)]
  16.     private ?string $numeroCommande null;
  17.     #[ORM\ManyToOne(inversedBy'commandes')]
  18.     #[ORM\JoinColumn(nullablefalse)]
  19.     private ?Fournisseur $fournisseur null;
  20.     #[ORM\Column(typeTypes::DATE_MUTABLE)]
  21.     private ?\DateTimeInterface $dateCommande null;
  22.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  23.     private ?\DateTimeInterface $dateLivraisonPrevue null;
  24.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  25.     private ?\DateTimeInterface $dateLivraisonReelle null;
  26.     #[ORM\Column(length50)]
  27.     private ?string $statut 'brouillon'
  28.     // brouillon, validee, envoyee, en_cours, partiellement_recue, recue, annulee
  29.     #[ORM\Column(typeTypes::DECIMALprecision15scale2)]
  30.     private ?string $montantHT '0.00';
  31.     #[ORM\Column(typeTypes::DECIMALprecision15scale2nullabletrue)]
  32.     private ?string $montantTVA null;
  33.     #[ORM\Column(typeTypes::DECIMALprecision15scale2)]
  34.     private ?string $montantTotal '0.00';
  35.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  36.     private ?string $notes null;
  37.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  38.     private ?string $conditionsLivraison null;
  39.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  40.     private ?string $conditionsPaiement null;
  41.     #[ORM\ManyToOne]
  42.     #[ORM\JoinColumn(nullablefalse)]
  43.     private ?User $createdBy null;
  44.     #[ORM\ManyToOne]
  45.     private ?User $validatedBy null;
  46.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  47.     private ?\DateTimeInterface $dateValidation null;
  48.     #[ORM\ManyToOne]
  49.     private ?Boutique $boutique null;
  50.     #[ORM\OneToMany(mappedBy'commande'targetEntityLigneCommande::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  51.     private Collection $lignes;
  52.     #[ORM\OneToOne(mappedBy'commande'cascade: ['persist''remove'])]
  53.     private ?AchatFournisseur $achat null;
  54.     #[ORM\Column]
  55.     private ?\DateTimeImmutable $createdAt null;
  56.     #[ORM\Column(nullabletrue)]
  57.     private ?\DateTimeImmutable $updatedAt null;
  58.     public function __construct()
  59.     {
  60.         $this->lignes = new ArrayCollection();
  61.         $this->createdAt = new \DateTimeImmutable();
  62.         $this->dateCommande = new \DateTime();
  63.     }
  64.     // Getters et Setters...
  65.     public function getId(): ?int
  66.     {
  67.         return $this->id;
  68.     }
  69.     public function getNumeroCommande(): ?string
  70.     {
  71.         return $this->numeroCommande;
  72.     }
  73.     public function setNumeroCommande(string $numeroCommande): static
  74.     {
  75.         $this->numeroCommande $numeroCommande;
  76.         return $this;
  77.     }
  78.     public function getFournisseur(): ?Fournisseur
  79.     {
  80.         return $this->fournisseur;
  81.     }
  82.     public function setFournisseur(?Fournisseur $fournisseur): static
  83.     {
  84.         $this->fournisseur $fournisseur;
  85.         return $this;
  86.     }
  87.     public function getDateCommande(): ?\DateTimeInterface
  88.     {
  89.         return $this->dateCommande;
  90.     }
  91.     public function setDateCommande(\DateTimeInterface $dateCommande): static
  92.     {
  93.         $this->dateCommande $dateCommande;
  94.         return $this;
  95.     }
  96.     public function getDateLivraisonPrevue(): ?\DateTimeInterface
  97.     {
  98.         return $this->dateLivraisonPrevue;
  99.     }
  100.     public function setDateLivraisonPrevue(?\DateTimeInterface $dateLivraisonPrevue): static
  101.     {
  102.         $this->dateLivraisonPrevue $dateLivraisonPrevue;
  103.         return $this;
  104.     }
  105.     public function getDateLivraisonReelle(): ?\DateTimeInterface
  106.     {
  107.         return $this->dateLivraisonReelle;
  108.     }
  109.     public function setDateLivraisonReelle(?\DateTimeInterface $dateLivraisonReelle): static
  110.     {
  111.         $this->dateLivraisonReelle $dateLivraisonReelle;
  112.         return $this;
  113.     }
  114.     public function getStatut(): ?string
  115.     {
  116.         return $this->statut;
  117.     }
  118.     public function setStatut(string $statut): static
  119.     {
  120.         $this->statut $statut;
  121.         return $this;
  122.     }
  123.     public function getMontantHT(): ?string
  124.     {
  125.         return $this->montantHT;
  126.     }
  127.     public function setMontantHT(string $montantHT): static
  128.     {
  129.         $this->montantHT $montantHT;
  130.         return $this;
  131.     }
  132.     public function getMontantTVA(): ?string
  133.     {
  134.         return $this->montantTVA;
  135.     }
  136.     public function setMontantTVA(?string $montantTVA): static
  137.     {
  138.         $this->montantTVA $montantTVA;
  139.         return $this;
  140.     }
  141.     public function getMontantTotal(): ?string
  142.     {
  143.         return $this->montantTotal;
  144.     }
  145.     public function setMontantTotal(string $montantTotal): static
  146.     {
  147.         $this->montantTotal $montantTotal;
  148.         return $this;
  149.     }
  150.     public function getNotes(): ?string
  151.     {
  152.         return $this->notes;
  153.     }
  154.     public function setNotes(?string $notes): static
  155.     {
  156.         $this->notes $notes;
  157.         return $this;
  158.     }
  159.     public function getConditionsLivraison(): ?string
  160.     {
  161.         return $this->conditionsLivraison;
  162.     }
  163.     public function setConditionsLivraison(?string $conditionsLivraison): static
  164.     {
  165.         $this->conditionsLivraison $conditionsLivraison;
  166.         return $this;
  167.     }
  168.     public function getConditionsPaiement(): ?string
  169.     {
  170.         return $this->conditionsPaiement;
  171.     }
  172.     public function setConditionsPaiement(?string $conditionsPaiement): static
  173.     {
  174.         $this->conditionsPaiement $conditionsPaiement;
  175.         return $this;
  176.     }
  177.     public function getCreatedBy(): ?User
  178.     {
  179.         return $this->createdBy;
  180.     }
  181.     public function setCreatedBy(?User $createdBy): static
  182.     {
  183.         $this->createdBy $createdBy;
  184.         return $this;
  185.     }
  186.     public function getValidatedBy(): ?User
  187.     {
  188.         return $this->validatedBy;
  189.     }
  190.     public function setValidatedBy(?User $validatedBy): static
  191.     {
  192.         $this->validatedBy $validatedBy;
  193.         return $this;
  194.     }
  195.     public function getDateValidation(): ?\DateTimeInterface
  196.     {
  197.         return $this->dateValidation;
  198.     }
  199.     public function setDateValidation(?\DateTimeInterface $dateValidation): static
  200.     {
  201.         $this->dateValidation $dateValidation;
  202.         return $this;
  203.     }
  204.     public function getBoutique(): ?Boutique
  205.     {
  206.         return $this->boutique;
  207.     }
  208.     public function setBoutique(?Boutique $boutique): static
  209.     {
  210.         $this->boutique $boutique;
  211.         return $this;
  212.     }
  213.     /**
  214.      * @return Collection<int, LigneCommande>
  215.      */
  216.     public function getLignes(): Collection
  217.     {
  218.         return $this->lignes;
  219.     }
  220.     public function addLigne(LigneCommande $ligne): static
  221.     {
  222.         if (!$this->lignes->contains($ligne)) {
  223.             $this->lignes->add($ligne);
  224.             $ligne->setCommande($this);
  225.         }
  226.         return $this;
  227.     }
  228.     public function removeLigne(LigneCommande $ligne): static
  229.     {
  230.         if ($this->lignes->removeElement($ligne)) {
  231.             if ($ligne->getCommande() === $this) {
  232.                 $ligne->setCommande(null);
  233.             }
  234.         }
  235.         return $this;
  236.     }
  237.     public function getAchat(): ?AchatFournisseur
  238.     {
  239.         return $this->achat;
  240.     }
  241.     public function setAchat(?AchatFournisseur $achat): static
  242.     {
  243.         // set the owning side of the relation if necessary
  244.         if ($achat !== null && $achat->getCommande() !== $this) {
  245.             $achat->setCommande($this);
  246.         }
  247.         $this->achat $achat;
  248.         return $this;
  249.     }
  250.     public function getCreatedAt(): ?\DateTimeImmutable
  251.     {
  252.         return $this->createdAt;
  253.     }
  254.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  255.     {
  256.         $this->createdAt $createdAt;
  257.         return $this;
  258.     }
  259.     public function getUpdatedAt(): ?\DateTimeImmutable
  260.     {
  261.         return $this->updatedAt;
  262.     }
  263.     public function setUpdatedAt(?\DateTimeImmutable $updatedAt): static
  264.     {
  265.         $this->updatedAt $updatedAt;
  266.         return $this;
  267.     }
  268.     public function calculerMontants(): void
  269.     {
  270.         $totalHT 0;
  271.         
  272.         foreach ($this->lignes as $ligne) {
  273.             $totalHT += floatval($ligne->getQuantite()) * floatval($ligne->getPrixUnitaire());
  274.         }
  275.         $this->montantHT number_format($totalHT2'.''');
  276.         
  277.         // TVA 18%
  278.         $montantTVA $totalHT 0.18;
  279.         $this->montantTVA number_format($montantTVA2'.''');
  280.         
  281.         $this->montantTotal number_format($totalHT $montantTVA2'.''');
  282.     }
  283.     public function genererNumeroCommande(): string
  284.     {
  285.         $date $this->dateCommande ?? new \DateTime();
  286.         return 'CMD-' $date->format('Ymd') . '-' str_pad($this->id ?? 05'0'STR_PAD_LEFT);
  287.     }
  288.     public function peutEtreValidee(): bool
  289.     {
  290.         return $this->statut === 'brouillon' && $this->lignes->count() > 0;
  291.     }
  292.     public function peutEtreTransformeeEnAchat(): bool
  293.     {
  294.         return in_array($this->statut, ['recue''partiellement_recue']) && $this->achat === null;
  295.     }
  296.     public function __toString(): string
  297.     {
  298.         return $this->numeroCommande ?? 'Nouvelle commande';
  299.     }
  300. }