<?php
namespace App\Entity;
use App\Repository\LigneCommandeRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: LigneCommandeRepository::class)]
class LigneCommande
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'lignes')]
#[ORM\JoinColumn(nullable: false)]
private ?CommandeFournisseur $commande = null;
#[ORM\ManyToOne]
private ?Produit $produit = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $designation = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
private ?string $quantite = '1.00';
#[ORM\Column(type: Types::DECIMAL, precision: 15, scale: 2)]
private ?string $prixUnitaire = '0.00';
#[ORM\Column(type: Types::DECIMAL, precision: 15, scale: 2)]
private ?string $montantLigne = '0.00';
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
private ?string $quantiteRecue = '0.00';
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $notes = null;
public function getId(): ?int
{
return $this->id;
}
public function getCommande(): ?CommandeFournisseur
{
return $this->commande;
}
public function setCommande(?CommandeFournisseur $commande): static
{
$this->commande = $commande;
return $this;
}
public function getProduit(): ?Produit
{
return $this->produit;
}
public function setProduit(?Produit $produit): static
{
$this->produit = $produit;
return $this;
}
public function getDesignation(): ?string
{
return $this->designation;
}
public function setDesignation(?string $designation): static
{
$this->designation = $designation;
return $this;
}
public function getQuantite(): ?string
{
return $this->quantite;
}
public function setQuantite(string $quantite): static
{
$this->quantite = $quantite;
return $this;
}
public function getPrixUnitaire(): ?string
{
return $this->prixUnitaire;
}
public function setPrixUnitaire(string $prixUnitaire): static
{
$this->prixUnitaire = $prixUnitaire;
return $this;
}
public function getMontantLigne(): ?string
{
return $this->montantLigne;
}
public function setMontantLigne(string $montantLigne): static
{
$this->montantLigne = $montantLigne;
return $this;
}
public function getQuantiteRecue(): ?string
{
return $this->quantiteRecue;
}
public function setQuantiteRecue(?string $quantiteRecue): static
{
$this->quantiteRecue = $quantiteRecue;
return $this;
}
public function getNotes(): ?string
{
return $this->notes;
}
public function setNotes(?string $notes): static
{
$this->notes = $notes;
return $this;
}
public function calculerMontant(): void
{
$montant = floatval($this->quantite) * floatval($this->prixUnitaire);
$this->montantLigne = number_format($montant, 2, '.', '');
}
public function getQuantiteRestante(): float
{
return floatval($this->quantite) - floatval($this->quantiteRecue ?? 0);
}
public function estTotalementRecue(): bool
{
return floatval($this->quantiteRecue ?? 0) >= floatval($this->quantite);
}
public function __toString(): string
{
return ($this->designation ?? $this->produit?->getNom() ?? 'Ligne') . ' - ' . $this->quantite;
}
}