src/Entity/DetteFournisseur.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\DetteFournisseurRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. #[ORM\Entity(repositoryClassDetteFournisseurRepository::class)]
  7. class DetteFournisseur
  8. {
  9.     #[ORM\Id]
  10.     #[ORM\GeneratedValue]
  11.     #[ORM\Column]
  12.     private ?int $id null;
  13.     #[ORM\ManyToOne(inversedBy'dettes')]
  14.     #[ORM\JoinColumn(nullabletrue)]
  15.     private ?Fournisseur $fournisseur null;
  16.     #[ORM\ManyToOne]
  17.     #[ORM\JoinColumn(nullabletrue)]
  18.     private ?AchatFournisseur $achat null;
  19.     #[ORM\Column]
  20.     private ?float $montantInitial null;
  21.     #[ORM\Column]
  22.     private ?float $montantPaye 0;
  23.     #[ORM\Column]
  24.     private ?float $montantRestant null;
  25.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  26.     private ?\DateTimeInterface $dateCreation null;
  27.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  28.     private ?\DateTimeInterface $dateEcheance null;
  29.     #[ORM\Column]
  30.     private ?bool $estPayee false;
  31.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  32.     private ?\DateTimeInterface $datePaiementComplet null;
  33.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  34.     private ?string $notes null;
  35.     #[ORM\ManyToOne]
  36.     #[ORM\JoinColumn(nullabletrue)]
  37.     private ?Boutique $boutique null;
  38.     #[ORM\Column(length255nullabletrue)]
  39.     private ?string $reference null;
  40.     public function __construct()
  41.     {
  42.         $this->dateCreation = new \DateTime();
  43.     }
  44.     public function getId(): ?int
  45.     {
  46.         return $this->id;
  47.     }
  48.     public function getFournisseur(): ?Fournisseur
  49.     {
  50.         return $this->fournisseur;
  51.     }
  52.     public function setFournisseur(?Fournisseur $fournisseur): static
  53.     {
  54.         $this->fournisseur $fournisseur;
  55.         return $this;
  56.     }
  57.     public function getAchat(): ?AchatFournisseur
  58.     {
  59.         return $this->achat;
  60.     }
  61.     public function setAchat(?AchatFournisseur $achat): static
  62.     {
  63.         $this->achat $achat;
  64.         return $this;
  65.     }
  66.     public function getMontantInitial(): ?float
  67.     {
  68.         return $this->montantInitial;
  69.     }
  70.     public function setMontantInitial(float $montantInitial): static
  71.     {
  72.         $this->montantInitial $montantInitial;
  73.         $this->montantRestant $montantInitial;
  74.         return $this;
  75.     }
  76.     public function getMontantPaye(): ?float
  77.     {
  78.         return $this->montantPaye ?? 0;
  79.     }
  80.     public function setMontantPaye(float $montantPaye): static
  81.     {
  82.         $this->montantPaye $montantPaye;
  83.         return $this;
  84.     }
  85.     public function getMontantRestant(): ?float
  86.     {
  87.         return $this->montantRestant;
  88.     }
  89.     public function setMontantRestant(float $montantRestant): static
  90.     {
  91.         $this->montantRestant $montantRestant;
  92.         return $this;
  93.     }
  94.     public function getDateCreation(): ?\DateTimeInterface
  95.     {
  96.         return $this->dateCreation;
  97.     }
  98.     public function setDateCreation(\DateTimeInterface $dateCreation): static
  99.     {
  100.         $this->dateCreation $dateCreation;
  101.         return $this;
  102.     }
  103.     public function getDateEcheance(): ?\DateTimeInterface
  104.     {
  105.         return $this->dateEcheance;
  106.     }
  107.     public function setDateEcheance(?\DateTimeInterface $dateEcheance): static
  108.     {
  109.         $this->dateEcheance $dateEcheance;
  110.         return $this;
  111.     }
  112.     public function isEstPayee(): ?bool
  113.     {
  114.         return $this->estPayee;
  115.     }
  116.     public function setEstPayee(bool $estPayee): static
  117.     {
  118.         $this->estPayee $estPayee;
  119.         return $this;
  120.     }
  121.     public function getDatePaiementComplet(): ?\DateTimeInterface
  122.     {
  123.         return $this->datePaiementComplet;
  124.     }
  125.     public function setDatePaiementComplet(?\DateTimeInterface $datePaiementComplet): static
  126.     {
  127.         $this->datePaiementComplet $datePaiementComplet;
  128.         return $this;
  129.     }
  130.     public function getNotes(): ?string
  131.     {
  132.         return $this->notes;
  133.     }
  134.     public function setNotes(?string $notes): static
  135.     {
  136.         $this->notes $notes;
  137.         return $this;
  138.     }
  139.     public function getBoutique(): ?Boutique
  140.     {
  141.         return $this->boutique;
  142.     }
  143.     public function setBoutique(?Boutique $boutique): static
  144.     {
  145.         $this->boutique $boutique;
  146.         return $this;
  147.     }
  148.     public function getReference(): ?string
  149.     {
  150.         return $this->reference;
  151.     }
  152.     public function setReference(?string $reference): static
  153.     {
  154.         $this->reference $reference;
  155.         return $this;
  156.     }
  157.     /**
  158.      * Enregistre un paiement sur cette dette
  159.      */
  160.     public function enregistrerPaiement(float $montant): void
  161.     {
  162.         $this->montantPaye += $montant;
  163.         $this->montantRestant -= $montant;
  164.         if ($this->montantRestant <= 0.01) {
  165.             $this->montantRestant 0;
  166.             $this->estPayee true;
  167.             $this->datePaiementComplet = new \DateTime();
  168.         }
  169.     }
  170.     /**
  171.      * VĂ©rifie si la dette est en retard
  172.      */
  173.     public function estEnRetard(): bool
  174.     {
  175.         if ($this->estPayee || !$this->dateEcheance) {
  176.             return false;
  177.         }
  178.         return $this->dateEcheance < new \DateTime();
  179.     }
  180.     public function __toString(): string
  181.     {
  182.         return sprintf(
  183.             'Dette #%d - %s - Restant: %s FCFA',
  184.             $this->id ?? 0,
  185.             $this->fournisseur $this->fournisseur->getNom() : 'Sans fournisseur',
  186.             number_format($this->montantRestant0','' ')
  187.         );
  188.     }
  189. }