src/Entity/FacturesDetail.php line 18

Open in your IDE?
  1. <?php
  2. /**
  3.  * FacturesDetail.php
  4.  * Created by Stéphane Brun
  5.  * Date: 19/04/2018 at 16:43
  6.  */
  7. namespace App\Entity;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\MaxDepth;
  10. /**
  11.  * @ORM\Entity()
  12.  * @ORM\Table(name="tfacturesdetail")
  13.  * @ORM\Entity(repositoryClass="App\Repository\FacturesDetailRepository")
  14.  */
  15. class FacturesDetail
  16. {
  17.     const HISTORY_WATCH = array(
  18.         'quantiteeLivree' => 'Quantité livrée',
  19.         'quantiteeCommandee' => 'Quantité commandée',
  20.         'rabaisM' => 'Rabais en $',
  21.         'rabaisP' => 'Rabais en %',
  22.         'bonCommande' => 'Commande spéciale',
  23.     );
  24.     /**
  25.      * @ORM\Column(name="DSeq", type="integer")
  26.      * @ORM\Id
  27.      * @ORM\GeneratedValue(strategy="AUTO")
  28.      */
  29.     protected $id;
  30.     /**
  31.      * @ORM\Column(name="DDesc", type="string", length=150, nullable=true)
  32.      */
  33.     protected $description;
  34.     /**
  35.      * @ORM\Column(name="DQteComm", type="integer", nullable=true)
  36.      */
  37.     protected $quantiteeCommandee;
  38.     /**
  39.      * @ORM\Column(name="DQteLivree", type="integer", nullable=true)
  40.      */
  41.     protected $quantiteeLivree;
  42.     /**
  43.      * @ORM\Column(name="DCodeReponse", type="integer", nullable=true)
  44.      */
  45.     protected $codeReponse;
  46.     /**
  47.      * @ORM\Column(name="DPVU", type="float", nullable=true)
  48.      */
  49.     protected $pvu;
  50.     /**
  51.      * @ORM\Column(name="DEsco", type="float", nullable=true)
  52.      */
  53.     protected $esco;
  54.     /**
  55.      * @ORM\Column(name="DEscM", type="float", nullable=true)
  56.      */
  57.     protected $escm;
  58.     /**
  59.      * @ORM\Column(name="DRabaisP", type="integer", nullable=true)
  60.      */
  61.     protected $rabaisP 0;
  62.     /**
  63.      * @ORM\Column(name="DRabaisM", type="float", nullable=true)
  64.      */
  65.     protected $rabaisM 0;
  66.     /**
  67.      * Many features have one product. This is the owning side.
  68.      * @ORM\ManyToOne(targetEntity="CommandeSpecialeDetail", inversedBy="facturesDetail")
  69.      * @ORM\JoinColumn(name="DRecuAcompte", referencedColumnName="id")
  70.      */
  71.     protected $recuAcompte;
  72.     /**
  73.      * @ORM\Column(name="DPrixFixe", type="boolean", nullable=true)
  74.      */
  75.     protected $prixFixe;
  76.     /**
  77.      * @ORM\Column(name="DCertificat", type="integer", nullable=true)
  78.      */
  79.     protected $certificat;
  80.     /**
  81.      * @ORM\Column(name="DCertificatInit", type="string", length=4, nullable=true)
  82.      */
  83.     protected $certificatInit;
  84.     /**
  85.      * @ORM\Column(name="DCommentaire", type="string", length=300, nullable=true)
  86.      */
  87.     protected $commentaire;
  88.     /**
  89.      * @ORM\Column(name="bon_commande", type="string", length=100, nullable=true)
  90.      */
  91.     protected $bonCommande;
  92.     /**
  93.      * Many FacturesDetail has one Factures
  94.      *
  95.      * @ORM\ManyToOne(targetEntity="App\Entity\Factures", inversedBy="details")
  96.      * @ORM\JoinColumn(name="DFacture", referencedColumnName="EFacture", nullable=false)
  97.      */
  98.     protected $facture;
  99.     /**
  100.      * Many FacturesDetails has one Titres
  101.      *
  102.      * @TODO: ne devrait pas être nullable
  103.      * @ORM\ManyToOne(targetEntity="App\Entity\Titre", cascade={"persist"})
  104.      * @ORM\JoinColumn(name="DProduit", referencedColumnName="TISBN", nullable=true)
  105.      */
  106.     protected $produit;
  107.     /**
  108.      * has one Company
  109.      *
  110.      * @ORM\ManyToOne(targetEntity="App\Entity\Company")
  111.      * @ORM\JoinColumn(name="company_id", referencedColumnName="id", nullable=true)
  112.      * @MaxDepth(1)
  113.      */
  114.     protected $company;
  115.     /**
  116.      * @ORM\Column(name="tpsOverridden", type="boolean", nullable=true)
  117.      */
  118.     private ?bool $tpsOverridden null;
  119.     /**
  120.      * @ORM\Column(name="tvqOverridden", type="boolean", nullable=true)
  121.      */
  122.     private ?bool $tvqOverridden null;
  123.     /**
  124.      * @return mixed
  125.      */
  126.     public function getCompany()
  127.     {
  128.         return $this->company;
  129.     }
  130.     /**
  131.      * @param Company $company
  132.      */
  133.     public function setCompany(Company $company)
  134.     {
  135.         $this->company $company;
  136.     }
  137.     /**
  138.      * @return mixed
  139.      */
  140.     public function getId()
  141.     {
  142.         return $this->id;
  143.     }
  144.     /**
  145.      * @return mixed
  146.      */
  147.     public function getProduit()
  148.     {
  149.         return $this->produit;
  150.     }
  151.     /**
  152.      * @param Titre $produit
  153.      */
  154.     public function setProduit(Titre $produit null)
  155.     {
  156.         $this->produit $produit;
  157.     }
  158.     /**
  159.      * @return mixed
  160.      */
  161.     public function getDescription()
  162.     {
  163.         return $this->description;
  164.     }
  165.     /**
  166.      * @param mixed $description
  167.      */
  168.     public function setDescription($description)
  169.     {
  170.         $this->description $description;
  171.     }
  172.     /**
  173.      * @return mixed
  174.      */
  175.     public function getQuantiteeCommandee()
  176.     {
  177.         return $this->quantiteeCommandee;
  178.     }
  179.     /**
  180.      * @param mixed $quantiteeCommandee
  181.      */
  182.     public function setQuantiteeCommandee($quantiteeCommandee)
  183.     {
  184.         $this->quantiteeCommandee $quantiteeCommandee;
  185.     }
  186.     /**
  187.      * @return mixed
  188.      */
  189.     public function getQuantiteeLivree()
  190.     {
  191.         return $this->quantiteeLivree;
  192.     }
  193.     /**
  194.      * @param mixed $quantiteeLivree
  195.      */
  196.     public function setQuantiteeLivree($quantiteeLivree)
  197.     {
  198.         $this->quantiteeLivree $quantiteeLivree;
  199.     }
  200.     /**
  201.      * @return mixed
  202.      */
  203.     public function getCodeReponse()
  204.     {
  205.         return $this->codeReponse;
  206.     }
  207.     /**
  208.      * @param mixed $codeReponse
  209.      */
  210.     public function setCodeReponse($codeReponse)
  211.     {
  212.         $this->codeReponse $codeReponse;
  213.     }
  214.     /**
  215.      * @return mixed
  216.      */
  217.     public function getPvu()
  218.     {
  219.         return $this->pvu;
  220.     }
  221.     /**
  222.      * @param mixed $pvu
  223.      */
  224.     public function setPvu($pvu)
  225.     {
  226.         $this->pvu $pvu;
  227.     }
  228.     /**
  229.      * @return mixed
  230.      */
  231.     public function getEsco()
  232.     {
  233.         return $this->esco;
  234.     }
  235.     /**
  236.      * @param mixed $esco
  237.      */
  238.     public function setEsco($esco)
  239.     {
  240.         $this->esco $esco;
  241.     }
  242.     /**
  243.      * @return mixed
  244.      */
  245.     public function getEscm()
  246.     {
  247.         return $this->escm;
  248.     }
  249.     /**
  250.      * @param mixed $escm
  251.      */
  252.     public function setEscm($escm)
  253.     {
  254.         $this->escm $escm;
  255.     }
  256.     /**
  257.      * @return mixed
  258.      */
  259.     public function getRabaisP()
  260.     {
  261.         return $this->rabaisP;
  262.     }
  263.     /**
  264.      * @param mixed $rabaisP
  265.      */
  266.     public function setRabaisP($rabaisP)
  267.     {
  268.         $this->rabaisP $rabaisP;
  269.     }
  270.     /**
  271.      * @return mixed
  272.      */
  273.     public function getRabaisM()
  274.     {
  275.         return $this->rabaisM;
  276.     }
  277.     /**
  278.      * @param mixed $rabaisM
  279.      */
  280.     public function setRabaisM($rabaisM)
  281.     {
  282.         $this->rabaisM $rabaisM;
  283.     }
  284.     /**
  285.      * @return mixed
  286.      */
  287.     public function getRecuAcompte()
  288.     {
  289.         return $this->recuAcompte;
  290.     }
  291.     /**
  292.      * @param mixed $recuAcompte
  293.      */
  294.     public function setRecuAcompte($recuAcompte)
  295.     {
  296.         $this->recuAcompte $recuAcompte;
  297.     }
  298.     /**
  299.      * @return mixed
  300.      */
  301.     public function getPrixFixe()
  302.     {
  303.         return $this->prixFixe;
  304.     }
  305.     /**
  306.      * @param mixed $prixFixe
  307.      */
  308.     public function setPrixFixe($prixFixe)
  309.     {
  310.         $this->prixFixe $prixFixe;
  311.     }
  312.     /**
  313.      * @return mixed
  314.      */
  315.     public function getCertificat()
  316.     {
  317.         return $this->certificat;
  318.     }
  319.     /**
  320.      * @param mixed $certificat
  321.      */
  322.     public function setCertificat($certificat)
  323.     {
  324.         $this->certificat $certificat;
  325.     }
  326.     /**
  327.      * @return mixed
  328.      */
  329.     public function getCertificatInit()
  330.     {
  331.         return $this->certificatInit;
  332.     }
  333.     /**
  334.      * @param mixed $certificatInit
  335.      */
  336.     public function setCertificatInit($certificatInit)
  337.     {
  338.         $this->certificatInit $certificatInit;
  339.     }
  340.     /**
  341.      * @return mixed
  342.      */
  343.     public function getCommentaire()
  344.     {
  345.         return $this->commentaire;
  346.     }
  347.     /**
  348.      * @param mixed $commentaire
  349.      */
  350.     public function setCommentaire($commentaire)
  351.     {
  352.         $this->commentaire $commentaire;
  353.     }
  354.     /**
  355.      * @return mixed
  356.      */
  357.     public function getFacture()
  358.     {
  359.         return $this->facture;
  360.     }
  361.     /**
  362.      * @param Factures $facture
  363.      */
  364.     public function setFacture(Factures $facture)
  365.     {
  366.         $this->facture $facture;
  367.     }
  368.     /**
  369.      * @return mixed
  370.      */
  371.     public function getBonCommande()
  372.     {
  373.         return $this->bonCommande;
  374.     }
  375.     /**
  376.      * @param mixed $bonCommande
  377.      * @return FacturesDetail
  378.      */
  379.     public function setBonCommande($bonCommande)
  380.     {
  381.         $this->bonCommande $bonCommande;
  382.         return $this;
  383.     }
  384.     public function getBrut($usedQteDelivred false)
  385.     {
  386.         $qte $this->getQuantiteeCommandee();
  387.         if ($usedQteDelivred) {
  388.             $qte $this->getQuantiteeLivree();
  389.         }
  390.         return $this->getPvu() * $qte;
  391.     }
  392.     public function getNet($usedQteDelivred false)
  393.     {
  394.         $pourcent =  $this->getBrut($usedQteDelivred) * ($this->getRabaisP() / 100);
  395.         //((qty * pvu) - pourcent - rabaisd)
  396.         return round($this->getBrut($usedQteDelivred) - $pourcent $this->getRabaisM(), 2PHP_ROUND_HALF_DOWN);
  397.     }
  398.     /**
  399.      * @return float
  400.      */
  401.     public function getRabaisTotal()
  402.     {
  403.         return (float)$this->getRabaisM() + ($this->getBrut() * ($this->getRabaisP() / 100));
  404.     }
  405.     /**
  406.      * @return float
  407.      */
  408.     public function getRabaisTotalPourcent()
  409.     {
  410.         $avantRabais $this->getBrut();
  411.         $apresRabais $this->getBrut() - $this->getRabaisM();
  412.         
  413.         /**
  414.          * Prevent divisible by zero error
  415.          */
  416.         if($avantRabais == 0) {
  417.             return 0;
  418.         }
  419.         return (float)$this->rabaisP + ($avantRabais $apresRabais) * (100 $avantRabais);
  420.     }
  421.     public function setTpsOverridden(?bool $value): self
  422.     {
  423.         $this->tpsOverridden $value;
  424.         return $this;
  425.     }
  426.     public function getTpsOverridden(): ?bool
  427.     {
  428.         return $this->tpsOverridden;
  429.     }
  430.     public function setTvqOverridden(?bool $value): self
  431.     {
  432.         $this->tvqOverridden $value;
  433.         return $this;
  434.     }
  435.     public function getTvqOverridden(): ?bool
  436.     {
  437.         return $this->tvqOverridden;
  438.     }
  439.     /**
  440.      * Get the TPS from the Category first if linked to a product
  441.      * Else we take the TPS from the product itself
  442.      *
  443.      * @return bool
  444.      */
  445.     public function getTps(): bool
  446.     {
  447.         if ($this->tpsOverridden !== null) {
  448.             return $this->tpsOverridden;
  449.         }
  450.         if ($this->produit->getCategory() !== null) {
  451.             return $this->produit->getCategory()->getHasTps();
  452.         }
  453.         return (bool) $this->produit->getTps();
  454.     }
  455.     /**
  456.      * Get the TVQ from the Category first if linked to a product
  457.      * Else we take the TVQ from the product itself
  458.      *
  459.      * @return bool
  460.      */
  461.     public function getTvq(): bool
  462.     {
  463.         if ($this->tvqOverridden !== null) {
  464.             return $this->tvqOverridden;
  465.         }
  466.         if ($this->produit->getCategory() !== null) {
  467.             return $this->produit->getCategory()->getHasTvq();
  468.         }
  469.         return (bool) $this->produit->getTvq();
  470.     }
  471. }