<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Article d'une CommandeCaisse.
*
* Le prix et la TVA sont une copie de ceux du produit, rafraîchie tant que la
* commande est ouverte (CaisseService::synchroniserPrix) : la caisse encaisse
* toujours le prix à jour, et la ligne reste valable si le produit est supprimé.
*
* @ORM\Entity
* @ORM\Table(name="ligne_commande_caisse")
*/
class LigneCommandeCaisse
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=CommandeCaisse::class, inversedBy="lignes")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private $commande;
/**
* @ORM\ManyToOne(targetEntity=Produit::class)
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
private $produit;
/**
* @ORM\Column(type="string", length=255)
*/
private $libelle;
/**
* @ORM\Column(type="float")
*/
private $quantite = 1.0;
/**
* Prix unitaire HT avant remise.
*
* @ORM\Column(type="float")
*/
private $prixUnitaireHt = 0.0;
/**
* @ORM\Column(type="float")
*/
private $tauxTva = 0.0;
/**
* Remise saisie à la main sur la ligne (%). Null : remise promo du produit.
*
* @ORM\Column(type="float", nullable=true)
*/
private $remiseManuelle;
/**
* Remise promo du produit (%) au moment de l'ajout / du dernier rafraîchissement.
*
* @ORM\Column(type="float", options={"default": 0})
*/
private $remiseProduit = 0.0;
/**
* Précision pour la cuisine : "sans oignon", "bien cuit"...
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $note;
/**
* Quantité déjà transmise à la cuisine (bon de cuisine).
*
* @ORM\Column(type="float", options={"default": 0})
*/
private $quantiteEnvoyeeCuisine = 0.0;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
public function __construct()
{
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getCommande(): ?CommandeCaisse
{
return $this->commande;
}
public function setCommande(?CommandeCaisse $commande): self
{
$this->commande = $commande;
return $this;
}
public function getProduit(): ?Produit
{
return $this->produit;
}
public function setProduit(?Produit $produit): self
{
$this->produit = $produit;
return $this;
}
public function getLibelle(): string
{
return $this->libelle;
}
public function setLibelle(string $libelle): self
{
$this->libelle = mb_substr($libelle, 0, 255);
return $this;
}
public function getQuantite(): float
{
return $this->quantite;
}
public function setQuantite(float $quantite): self
{
$this->quantite = $quantite;
return $this;
}
public function getPrixUnitaireHt(): float
{
return $this->prixUnitaireHt;
}
public function setPrixUnitaireHt(float $prixUnitaireHt): self
{
$this->prixUnitaireHt = $prixUnitaireHt;
return $this;
}
public function getTauxTva(): float
{
return $this->tauxTva;
}
public function setTauxTva(float $tauxTva): self
{
$this->tauxTva = $tauxTva;
return $this;
}
public function getRemiseManuelle(): ?float
{
return $this->remiseManuelle;
}
public function setRemiseManuelle(?float $remiseManuelle): self
{
$this->remiseManuelle = $remiseManuelle === null ? null : max(0.0, min(100.0, $remiseManuelle));
return $this;
}
public function getRemiseProduit(): float
{
return $this->remiseProduit;
}
public function setRemiseProduit(float $remiseProduit): self
{
$this->remiseProduit = $remiseProduit;
return $this;
}
/**
* Remise effectivement appliquée (%) : la remise manuelle remplace la promo produit.
*/
public function getTauxRemise(): float
{
return $this->remiseManuelle !== null ? $this->remiseManuelle : $this->remiseProduit;
}
public function getNote(): ?string
{
return $this->note;
}
public function setNote(?string $note): self
{
$note = $note !== null ? trim($note) : null;
$this->note = $note !== '' && $note !== null ? mb_substr($note, 0, 255) : null;
return $this;
}
public function getQuantiteEnvoyeeCuisine(): float
{
return $this->quantiteEnvoyeeCuisine;
}
public function setQuantiteEnvoyeeCuisine(float $quantiteEnvoyeeCuisine): self
{
$this->quantiteEnvoyeeCuisine = $quantiteEnvoyeeCuisine;
return $this;
}
public function getQuantiteAEnvoyer(): float
{
return max(0.0, $this->quantite - $this->quantiteEnvoyeeCuisine);
}
public function isEnvoyeeCuisine(): bool
{
return $this->quantiteEnvoyeeCuisine > 0;
}
public function getCreatedAt(): \DateTimeInterface
{
return $this->createdAt;
}
}