src/Entity/Retour.php line 17

Open in your IDE?
  1. <?php
  2. /**
  3.  * Retour.php
  4.  * Created by Stéphane Brun
  5.  * Date: 25/07/2018 at 10:11
  6.  */
  7. namespace App\Entity;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\RetourRepository")
  12.  * @ORM\Table(name="retour")
  13.  */
  14. class Retour
  15. {
  16.     public const STATUS_NEW 1;
  17.     public const STATUS_PREPARE 2;
  18.     public const STATUS_VALIDATED 3;
  19.     public const STATUS_FINISHED 4;
  20.     /**
  21.      * @ORM\Column(type="integer")
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue(strategy="AUTO")
  24.      */
  25.     protected $id;
  26.     /**
  27.      * @ORM\Column(name="status", type="integer")
  28.      */
  29.     protected $status self::STATUS_NEW;
  30.     /**
  31.      * has one Fournisseurs
  32.      *
  33.      * @ORM\ManyToOne(targetEntity="App\Entity\Fournisseurs")
  34.      * @ORM\JoinColumn(name="fournisseur_id", referencedColumnName="id", nullable=true)
  35.      */
  36.     protected $fournisseur;
  37.     /**
  38.      * @ORM\Column(name="factures_visees", type="text", nullable=true)
  39.      */
  40.     protected $facturesVisees;
  41.     /**
  42.      * @ORM\Column(name="raison", type="integer", nullable=true)
  43.      */
  44.     protected $raison;
  45.     /**
  46.      * @ORM\Column(name="date", type="datetime")
  47.      */
  48.     protected $date;
  49.     /**
  50.      * @ORM\Column(name="commentaire", type="text", nullable=true)
  51.      */
  52.     protected $commentaire;
  53.     /**
  54.      * @ORM\Column(name="completee", type="boolean")
  55.      */
  56.     protected $complete 0;
  57.     /**
  58.      * @ORM\Column(name="imprimee", type="boolean")
  59.      */
  60.     protected $imprimee 0;
  61.     /**
  62.      * @ORM\Column(name="automatique", type="boolean")
  63.      */
  64.     protected $automatique 0;
  65.     /**
  66.      * @ORM\Column(name="signature", type="string", length=50, nullable=true)
  67.      */
  68.     protected $signature;
  69.     /**
  70.      * @ORM\Column(name="bordereau_imprime", type="boolean")
  71.      */
  72.     protected $bordereauImprime 0;
  73.     /**
  74.      * @ORM\Column(name="depot", type="boolean")
  75.      */
  76.     protected $depot 0;
  77.     /**
  78.      * @ORM\Column(name="paye", type="boolean")
  79.      */
  80.     protected $paye 0;
  81.     /**
  82.      * @ORM\Column(name="date_paye", type="datetime", nullable=true)
  83.      */
  84.     protected $datePaye;
  85.     /**
  86.      * has one Company
  87.      *
  88.      * @ORM\ManyToOne(targetEntity="App\Entity\Company")
  89.      * @ORM\JoinColumn(name="company_id", referencedColumnName="id")
  90.      */
  91.     protected $company;
  92.     /**
  93.      * has one SysUser
  94.      *
  95.      * @ORM\ManyToOne(targetEntity="App\Entity\SysUsers")
  96.      * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  97.      */
  98.     protected $user;
  99.     /**
  100.      * has many RetourDetail
  101.      * , cascade={"persist", "remove"}
  102.      * @ORM\OneToMany(targetEntity="App\Entity\RetourDetail", mappedBy="retour")
  103.      */
  104.     protected $details;
  105.     public function __construct()
  106.     {
  107.         $this->details = new ArrayCollection();
  108.         $this->date = new \DateTime();
  109.     }
  110.     /**
  111.      * @return mixed
  112.      */
  113.     public function getId()
  114.     {
  115.         return $this->id;
  116.     }
  117.     /**
  118.      * @return mixed
  119.      */
  120.     public function getFournisseur()
  121.     {
  122.         return $this->fournisseur;
  123.     }
  124.     /**
  125.      * @param mixed $fournisseur
  126.      * @return Retour
  127.      */
  128.     public function setFournisseur($fournisseur)
  129.     {
  130.         $this->fournisseur $fournisseur;
  131.         return $this;
  132.     }
  133.     /**
  134.      * @return mixed
  135.      */
  136.     public function getFacturesVisees()
  137.     {
  138.         return $this->facturesVisees;
  139.     }
  140.     /**
  141.      * @param mixed $facturesVisees
  142.      * @return Retour
  143.      */
  144.     public function setFacturesVisees($facturesVisees)
  145.     {
  146.         $this->facturesVisees $facturesVisees;
  147.         return $this;
  148.     }
  149.     /**
  150.      * @return mixed
  151.      */
  152.     public function getRaison()
  153.     {
  154.         return $this->raison;
  155.     }
  156.     /**
  157.      * @param mixed $raison
  158.      * @return Retour
  159.      */
  160.     public function setRaison($raison)
  161.     {
  162.         $this->raison $raison;
  163.         return $this;
  164.     }
  165.     /**
  166.      * @return mixed
  167.      */
  168.     public function getDate()
  169.     {
  170.         return $this->date;
  171.     }
  172.     /**
  173.      * @param mixed $date
  174.      * @return Retour
  175.      */
  176.     public function setDate($date)
  177.     {
  178.         $this->date $date;
  179.         return $this;
  180.     }
  181.     /**
  182.      * @return mixed
  183.      */
  184.     public function getCommentaire()
  185.     {
  186.         return $this->commentaire;
  187.     }
  188.     /**
  189.      * @param mixed $commentaire
  190.      * @return Retour
  191.      */
  192.     public function setCommentaire($commentaire)
  193.     {
  194.         $this->commentaire $commentaire;
  195.         return $this;
  196.     }
  197.     /**
  198.      * @return mixed
  199.      */
  200.     public function getComplete()
  201.     {
  202.         return $this->complete;
  203.     }
  204.     /**
  205.      * @param mixed $complete
  206.      * @return Retour
  207.      */
  208.     public function setComplete($complete)
  209.     {
  210.         $this->complete $complete;
  211.         return $this;
  212.     }
  213.     /**
  214.      * @return mixed
  215.      */
  216.     public function getImprimee()
  217.     {
  218.         return $this->imprimee;
  219.     }
  220.     /**
  221.      * @param mixed $imprimee
  222.      * @return Retour
  223.      */
  224.     public function setImprimee($imprimee)
  225.     {
  226.         $this->imprimee $imprimee;
  227.         return $this;
  228.     }
  229.     /**
  230.      * @return mixed
  231.      */
  232.     public function getAutomatique()
  233.     {
  234.         return $this->automatique;
  235.     }
  236.     /**
  237.      * @param mixed $automatique
  238.      * @return Retour
  239.      */
  240.     public function setAutomatique($automatique)
  241.     {
  242.         $this->automatique $automatique;
  243.         return $this;
  244.     }
  245.     /**
  246.      * @return mixed
  247.      */
  248.     public function getSignature()
  249.     {
  250.         return $this->signature;
  251.     }
  252.     /**
  253.      * @param mixed $signature
  254.      * @return Retour
  255.      */
  256.     public function setSignature($signature)
  257.     {
  258.         $this->signature $signature;
  259.         return $this;
  260.     }
  261.     /**
  262.      * @return mixed
  263.      */
  264.     public function getBordereauImprime()
  265.     {
  266.         return $this->bordereauImprime;
  267.     }
  268.     /**
  269.      * @param mixed $bordereauImprime
  270.      * @return Retour
  271.      */
  272.     public function setBordereauImprime($bordereauImprime)
  273.     {
  274.         $this->bordereauImprime $bordereauImprime;
  275.         return $this;
  276.     }
  277.     /**
  278.      * @return mixed
  279.      */
  280.     public function getDepot()
  281.     {
  282.         return $this->depot;
  283.     }
  284.     /**
  285.      * @param mixed $depot
  286.      * @return Retour
  287.      */
  288.     public function setDepot($depot)
  289.     {
  290.         $this->depot $depot;
  291.         return $this;
  292.     }
  293.     /**
  294.      * @return mixed
  295.      */
  296.     public function getCompany()
  297.     {
  298.         return $this->company;
  299.     }
  300.     /**
  301.      * @param mixed $company
  302.      * @return Retour
  303.      */
  304.     public function setCompany($company)
  305.     {
  306.         $this->company $company;
  307.         return $this;
  308.     }
  309.     /**
  310.      * @return mixed
  311.      */
  312.     public function getUser()
  313.     {
  314.         return $this->user;
  315.     }
  316.     /**
  317.      * @param mixed $user
  318.      * @return Retour
  319.      */
  320.     public function setUser($user)
  321.     {
  322.         $this->user $user;
  323.         return $this;
  324.     }
  325.     /**
  326.      * @return mixed
  327.      */
  328.     public function getDetails()
  329.     {
  330.         return $this->details;
  331.     }
  332.     /**
  333.      * @param mixed $details
  334.      * @return Retour
  335.      */
  336.     public function setDetails($details)
  337.     {
  338.         $this->details $details;
  339.         return $this;
  340.     }
  341.     /**
  342.      * @param RetourDetail $detail
  343.      * @return $this
  344.      */
  345.     public function addDetail(RetourDetail $detail)
  346.     {
  347.         if (!$this->details->contains($detail)) {
  348.             $this->details->add($detail);
  349.             $detail->setRetour($this);
  350.         }
  351.         return $this;
  352.     }
  353.     /**
  354.      * @param RetourDetail $detail
  355.      * @return $this
  356.      */
  357.     public function removeDetail(RetourDetail $detail)
  358.     {
  359.         if ($this->details->contains($detail)) {
  360.             $this->details->removeElement($detail);
  361.             $detail->setRetour(null);
  362.         }
  363.         return $this;
  364.     }
  365.     /**
  366.      * @return mixed
  367.      */
  368.     public function getStatus()
  369.     {
  370.         return $this->status;
  371.     }
  372.     /**
  373.      * @param mixed $status
  374.      * @return Retour
  375.      */
  376.     public function setStatus($status)
  377.     {
  378.         $this->status $status;
  379.         return $this;
  380.     }
  381.     /**
  382.      * @return int
  383.      */
  384.     public function getPaye(): int
  385.     {
  386.         return $this->paye;
  387.     }
  388.     /**
  389.      * @param int $paye
  390.      * @return Retour
  391.      */
  392.     public function setPaye(int $paye): Retour
  393.     {
  394.         $this->paye $paye;
  395.         return $this;
  396.     }
  397.     /**
  398.      * @return mixed
  399.      */
  400.     public function getDatePaye()
  401.     {
  402.         return $this->datePaye;
  403.     }
  404.     /**
  405.      * @param mixed $datePaye
  406.      * @return Retour
  407.      */
  408.     public function setDatePaye($datePaye)
  409.     {
  410.         $this->datePaye $datePaye;
  411.         return $this;
  412.     }
  413.     public function isFinished()
  414.     {
  415.         return $this->getStatus() == self::STATUS_FINISHED;
  416.     }
  417.     public function getTotal($tps 0$tvq 0)
  418.     {
  419.         $total 0;
  420.         $ttps 0;
  421.         $ttvq 0;
  422.         /** @var RetourDetail $detail */
  423.         foreach ($this->getDetails() as $detail) {
  424.             $ht = ($detail->getPvu() - ($detail->getPvu() * $detail->getRemise() / 100));
  425.             $ht $ht $detail->getQteRetournee();
  426.             $total += $ht;
  427.             if ($detail->getProduit()) {
  428.                 if ($detail->getProduit()->getTps()) {
  429.                     $ttps += ($ht $tps);
  430.                 }
  431.                 if ($detail->getProduit()->getTvq()) {
  432.                     $ttvq += ($ht $tvq);
  433.                 }
  434.             }
  435.         }
  436.         return ["ht"=>$total"tps"=>round($ttps,2), "tvq"=>round($ttvq,2)];
  437.     }
  438. }