<?php
/**
* FacturesDetail.php
* Created by Stéphane Brun
* Date: 19/04/2018 at 16:43
*/
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\MaxDepth;
/**
* @ORM\Entity()
* @ORM\Table(name="tfacturesdetail")
* @ORM\Entity(repositoryClass="App\Repository\FacturesDetailRepository")
*/
class FacturesDetail
{
const HISTORY_WATCH = array(
'quantiteeLivree' => 'Quantité livrée',
'quantiteeCommandee' => 'Quantité commandée',
'rabaisM' => 'Rabais en $',
'rabaisP' => 'Rabais en %',
'bonCommande' => 'Commande spéciale',
);
/**
* @ORM\Column(name="DSeq", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="DDesc", type="string", length=150, nullable=true)
*/
protected $description;
/**
* @ORM\Column(name="DQteComm", type="integer", nullable=true)
*/
protected $quantiteeCommandee;
/**
* @ORM\Column(name="DQteLivree", type="integer", nullable=true)
*/
protected $quantiteeLivree;
/**
* @ORM\Column(name="DCodeReponse", type="integer", nullable=true)
*/
protected $codeReponse;
/**
* @ORM\Column(name="DPVU", type="float", nullable=true)
*/
protected $pvu;
/**
* @ORM\Column(name="DEsco", type="float", nullable=true)
*/
protected $esco;
/**
* @ORM\Column(name="DEscM", type="float", nullable=true)
*/
protected $escm;
/**
* @ORM\Column(name="DRabaisP", type="integer", nullable=true)
*/
protected $rabaisP = 0;
/**
* @ORM\Column(name="DRabaisM", type="float", nullable=true)
*/
protected $rabaisM = 0;
/**
* Many features have one product. This is the owning side.
* @ORM\ManyToOne(targetEntity="CommandeSpecialeDetail", inversedBy="facturesDetail")
* @ORM\JoinColumn(name="DRecuAcompte", referencedColumnName="id")
*/
protected $recuAcompte;
/**
* @ORM\Column(name="DPrixFixe", type="boolean", nullable=true)
*/
protected $prixFixe;
/**
* @ORM\Column(name="DCertificat", type="integer", nullable=true)
*/
protected $certificat;
/**
* @ORM\Column(name="DCertificatInit", type="string", length=4, nullable=true)
*/
protected $certificatInit;
/**
* @ORM\Column(name="DCommentaire", type="string", length=300, nullable=true)
*/
protected $commentaire;
/**
* @ORM\Column(name="bon_commande", type="string", length=100, nullable=true)
*/
protected $bonCommande;
/**
* Many FacturesDetail has one Factures
*
* @ORM\ManyToOne(targetEntity="App\Entity\Factures", inversedBy="details")
* @ORM\JoinColumn(name="DFacture", referencedColumnName="EFacture", nullable=false)
*/
protected $facture;
/**
* Many FacturesDetails has one Titres
*
* @TODO: ne devrait pas être nullable
* @ORM\ManyToOne(targetEntity="App\Entity\Titre", cascade={"persist"})
* @ORM\JoinColumn(name="DProduit", referencedColumnName="TISBN", nullable=true)
*/
protected $produit;
/**
* has one Company
*
* @ORM\ManyToOne(targetEntity="App\Entity\Company")
* @ORM\JoinColumn(name="company_id", referencedColumnName="id", nullable=true)
* @MaxDepth(1)
*/
protected $company;
/**
* @ORM\Column(name="tpsOverridden", type="boolean", nullable=true)
*/
private ?bool $tpsOverridden = null;
/**
* @ORM\Column(name="tvqOverridden", type="boolean", nullable=true)
*/
private ?bool $tvqOverridden = null;
/**
* @return mixed
*/
public function getCompany()
{
return $this->company;
}
/**
* @param Company $company
*/
public function setCompany(Company $company)
{
$this->company = $company;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return mixed
*/
public function getProduit()
{
return $this->produit;
}
/**
* @param Titre $produit
*/
public function setProduit(Titre $produit = null)
{
$this->produit = $produit;
}
/**
* @return mixed
*/
public function getDescription()
{
return $this->description;
}
/**
* @param mixed $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* @return mixed
*/
public function getQuantiteeCommandee()
{
return $this->quantiteeCommandee;
}
/**
* @param mixed $quantiteeCommandee
*/
public function setQuantiteeCommandee($quantiteeCommandee)
{
$this->quantiteeCommandee = $quantiteeCommandee;
}
/**
* @return mixed
*/
public function getQuantiteeLivree()
{
return $this->quantiteeLivree;
}
/**
* @param mixed $quantiteeLivree
*/
public function setQuantiteeLivree($quantiteeLivree)
{
$this->quantiteeLivree = $quantiteeLivree;
}
/**
* @return mixed
*/
public function getCodeReponse()
{
return $this->codeReponse;
}
/**
* @param mixed $codeReponse
*/
public function setCodeReponse($codeReponse)
{
$this->codeReponse = $codeReponse;
}
/**
* @return mixed
*/
public function getPvu()
{
return $this->pvu;
}
/**
* @param mixed $pvu
*/
public function setPvu($pvu)
{
$this->pvu = $pvu;
}
/**
* @return mixed
*/
public function getEsco()
{
return $this->esco;
}
/**
* @param mixed $esco
*/
public function setEsco($esco)
{
$this->esco = $esco;
}
/**
* @return mixed
*/
public function getEscm()
{
return $this->escm;
}
/**
* @param mixed $escm
*/
public function setEscm($escm)
{
$this->escm = $escm;
}
/**
* @return mixed
*/
public function getRabaisP()
{
return $this->rabaisP;
}
/**
* @param mixed $rabaisP
*/
public function setRabaisP($rabaisP)
{
$this->rabaisP = $rabaisP;
}
/**
* @return mixed
*/
public function getRabaisM()
{
return $this->rabaisM;
}
/**
* @param mixed $rabaisM
*/
public function setRabaisM($rabaisM)
{
$this->rabaisM = $rabaisM;
}
/**
* @return mixed
*/
public function getRecuAcompte()
{
return $this->recuAcompte;
}
/**
* @param mixed $recuAcompte
*/
public function setRecuAcompte($recuAcompte)
{
$this->recuAcompte = $recuAcompte;
}
/**
* @return mixed
*/
public function getPrixFixe()
{
return $this->prixFixe;
}
/**
* @param mixed $prixFixe
*/
public function setPrixFixe($prixFixe)
{
$this->prixFixe = $prixFixe;
}
/**
* @return mixed
*/
public function getCertificat()
{
return $this->certificat;
}
/**
* @param mixed $certificat
*/
public function setCertificat($certificat)
{
$this->certificat = $certificat;
}
/**
* @return mixed
*/
public function getCertificatInit()
{
return $this->certificatInit;
}
/**
* @param mixed $certificatInit
*/
public function setCertificatInit($certificatInit)
{
$this->certificatInit = $certificatInit;
}
/**
* @return mixed
*/
public function getCommentaire()
{
return $this->commentaire;
}
/**
* @param mixed $commentaire
*/
public function setCommentaire($commentaire)
{
$this->commentaire = $commentaire;
}
/**
* @return mixed
*/
public function getFacture()
{
return $this->facture;
}
/**
* @param Factures $facture
*/
public function setFacture(Factures $facture)
{
$this->facture = $facture;
}
/**
* @return mixed
*/
public function getBonCommande()
{
return $this->bonCommande;
}
/**
* @param mixed $bonCommande
* @return FacturesDetail
*/
public function setBonCommande($bonCommande)
{
$this->bonCommande = $bonCommande;
return $this;
}
public function getBrut($usedQteDelivred = false)
{
$qte = $this->getQuantiteeCommandee();
if ($usedQteDelivred) {
$qte = $this->getQuantiteeLivree();
}
return $this->getPvu() * $qte;
}
public function getNet($usedQteDelivred = false)
{
$pourcent = $this->getBrut($usedQteDelivred) * ($this->getRabaisP() / 100);
//((qty * pvu) - pourcent - rabaisd)
return round($this->getBrut($usedQteDelivred) - $pourcent - $this->getRabaisM(), 2, PHP_ROUND_HALF_DOWN);
}
/**
* @return float
*/
public function getRabaisTotal()
{
return (float)$this->getRabaisM() + ($this->getBrut() * ($this->getRabaisP() / 100));
}
/**
* @return float
*/
public function getRabaisTotalPourcent()
{
$avantRabais = $this->getBrut();
$apresRabais = $this->getBrut() - $this->getRabaisM();
/**
* Prevent divisible by zero error
*/
if($avantRabais == 0) {
return 0;
}
return (float)$this->rabaisP + ($avantRabais - $apresRabais) * (100 / $avantRabais);
}
public function setTpsOverridden(?bool $value): self
{
$this->tpsOverridden = $value;
return $this;
}
public function getTpsOverridden(): ?bool
{
return $this->tpsOverridden;
}
public function setTvqOverridden(?bool $value): self
{
$this->tvqOverridden = $value;
return $this;
}
public function getTvqOverridden(): ?bool
{
return $this->tvqOverridden;
}
/**
* Get the TPS from the Category first if linked to a product
* Else we take the TPS from the product itself
*
* @return bool
*/
public function getTps(): bool
{
if ($this->tpsOverridden !== null) {
return $this->tpsOverridden;
}
if ($this->produit->getCategory() !== null) {
return $this->produit->getCategory()->getHasTps();
}
return (bool) $this->produit->getTps();
}
/**
* Get the TVQ from the Category first if linked to a product
* Else we take the TVQ from the product itself
*
* @return bool
*/
public function getTvq(): bool
{
if ($this->tvqOverridden !== null) {
return $this->tvqOverridden;
}
if ($this->produit->getCategory() !== null) {
return $this->produit->getCategory()->getHasTvq();
}
return (bool) $this->produit->getTvq();
}
}