<?php
/**
* Retour.php
* Created by Stéphane Brun
* Date: 25/07/2018 at 10:11
*/
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\RetourRepository")
* @ORM\Table(name="retour")
*/
class Retour
{
public const STATUS_NEW = 1;
public const STATUS_PREPARE = 2;
public const STATUS_VALIDATED = 3;
public const STATUS_FINISHED = 4;
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="status", type="integer")
*/
protected $status = self::STATUS_NEW;
/**
* has one Fournisseurs
*
* @ORM\ManyToOne(targetEntity="App\Entity\Fournisseurs")
* @ORM\JoinColumn(name="fournisseur_id", referencedColumnName="id", nullable=true)
*/
protected $fournisseur;
/**
* @ORM\Column(name="factures_visees", type="text", nullable=true)
*/
protected $facturesVisees;
/**
* @ORM\Column(name="raison", type="integer", nullable=true)
*/
protected $raison;
/**
* @ORM\Column(name="date", type="datetime")
*/
protected $date;
/**
* @ORM\Column(name="commentaire", type="text", nullable=true)
*/
protected $commentaire;
/**
* @ORM\Column(name="completee", type="boolean")
*/
protected $complete = 0;
/**
* @ORM\Column(name="imprimee", type="boolean")
*/
protected $imprimee = 0;
/**
* @ORM\Column(name="automatique", type="boolean")
*/
protected $automatique = 0;
/**
* @ORM\Column(name="signature", type="string", length=50, nullable=true)
*/
protected $signature;
/**
* @ORM\Column(name="bordereau_imprime", type="boolean")
*/
protected $bordereauImprime = 0;
/**
* @ORM\Column(name="depot", type="boolean")
*/
protected $depot = 0;
/**
* @ORM\Column(name="paye", type="boolean")
*/
protected $paye = 0;
/**
* @ORM\Column(name="date_paye", type="datetime", nullable=true)
*/
protected $datePaye;
/**
* has one Company
*
* @ORM\ManyToOne(targetEntity="App\Entity\Company")
* @ORM\JoinColumn(name="company_id", referencedColumnName="id")
*/
protected $company;
/**
* has one SysUser
*
* @ORM\ManyToOne(targetEntity="App\Entity\SysUsers")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $user;
/**
* has many RetourDetail
* , cascade={"persist", "remove"}
* @ORM\OneToMany(targetEntity="App\Entity\RetourDetail", mappedBy="retour")
*/
protected $details;
public function __construct()
{
$this->details = new ArrayCollection();
$this->date = new \DateTime();
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return mixed
*/
public function getFournisseur()
{
return $this->fournisseur;
}
/**
* @param mixed $fournisseur
* @return Retour
*/
public function setFournisseur($fournisseur)
{
$this->fournisseur = $fournisseur;
return $this;
}
/**
* @return mixed
*/
public function getFacturesVisees()
{
return $this->facturesVisees;
}
/**
* @param mixed $facturesVisees
* @return Retour
*/
public function setFacturesVisees($facturesVisees)
{
$this->facturesVisees = $facturesVisees;
return $this;
}
/**
* @return mixed
*/
public function getRaison()
{
return $this->raison;
}
/**
* @param mixed $raison
* @return Retour
*/
public function setRaison($raison)
{
$this->raison = $raison;
return $this;
}
/**
* @return mixed
*/
public function getDate()
{
return $this->date;
}
/**
* @param mixed $date
* @return Retour
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* @return mixed
*/
public function getCommentaire()
{
return $this->commentaire;
}
/**
* @param mixed $commentaire
* @return Retour
*/
public function setCommentaire($commentaire)
{
$this->commentaire = $commentaire;
return $this;
}
/**
* @return mixed
*/
public function getComplete()
{
return $this->complete;
}
/**
* @param mixed $complete
* @return Retour
*/
public function setComplete($complete)
{
$this->complete = $complete;
return $this;
}
/**
* @return mixed
*/
public function getImprimee()
{
return $this->imprimee;
}
/**
* @param mixed $imprimee
* @return Retour
*/
public function setImprimee($imprimee)
{
$this->imprimee = $imprimee;
return $this;
}
/**
* @return mixed
*/
public function getAutomatique()
{
return $this->automatique;
}
/**
* @param mixed $automatique
* @return Retour
*/
public function setAutomatique($automatique)
{
$this->automatique = $automatique;
return $this;
}
/**
* @return mixed
*/
public function getSignature()
{
return $this->signature;
}
/**
* @param mixed $signature
* @return Retour
*/
public function setSignature($signature)
{
$this->signature = $signature;
return $this;
}
/**
* @return mixed
*/
public function getBordereauImprime()
{
return $this->bordereauImprime;
}
/**
* @param mixed $bordereauImprime
* @return Retour
*/
public function setBordereauImprime($bordereauImprime)
{
$this->bordereauImprime = $bordereauImprime;
return $this;
}
/**
* @return mixed
*/
public function getDepot()
{
return $this->depot;
}
/**
* @param mixed $depot
* @return Retour
*/
public function setDepot($depot)
{
$this->depot = $depot;
return $this;
}
/**
* @return mixed
*/
public function getCompany()
{
return $this->company;
}
/**
* @param mixed $company
* @return Retour
*/
public function setCompany($company)
{
$this->company = $company;
return $this;
}
/**
* @return mixed
*/
public function getUser()
{
return $this->user;
}
/**
* @param mixed $user
* @return Retour
*/
public function setUser($user)
{
$this->user = $user;
return $this;
}
/**
* @return mixed
*/
public function getDetails()
{
return $this->details;
}
/**
* @param mixed $details
* @return Retour
*/
public function setDetails($details)
{
$this->details = $details;
return $this;
}
/**
* @param RetourDetail $detail
* @return $this
*/
public function addDetail(RetourDetail $detail)
{
if (!$this->details->contains($detail)) {
$this->details->add($detail);
$detail->setRetour($this);
}
return $this;
}
/**
* @param RetourDetail $detail
* @return $this
*/
public function removeDetail(RetourDetail $detail)
{
if ($this->details->contains($detail)) {
$this->details->removeElement($detail);
$detail->setRetour(null);
}
return $this;
}
/**
* @return mixed
*/
public function getStatus()
{
return $this->status;
}
/**
* @param mixed $status
* @return Retour
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* @return int
*/
public function getPaye(): int
{
return $this->paye;
}
/**
* @param int $paye
* @return Retour
*/
public function setPaye(int $paye): Retour
{
$this->paye = $paye;
return $this;
}
/**
* @return mixed
*/
public function getDatePaye()
{
return $this->datePaye;
}
/**
* @param mixed $datePaye
* @return Retour
*/
public function setDatePaye($datePaye)
{
$this->datePaye = $datePaye;
return $this;
}
public function isFinished()
{
return $this->getStatus() == self::STATUS_FINISHED;
}
public function getTotal($tps = 0, $tvq = 0)
{
$total = 0;
$ttps = 0;
$ttvq = 0;
/** @var RetourDetail $detail */
foreach ($this->getDetails() as $detail) {
$ht = ($detail->getPvu() - ($detail->getPvu() * $detail->getRemise() / 100));
$ht = $ht * $detail->getQteRetournee();
$total += $ht;
if ($detail->getProduit()) {
if ($detail->getProduit()->getTps()) {
$ttps += ($ht * $tps);
}
if ($detail->getProduit()->getTvq()) {
$ttvq += ($ht * $tvq);
}
}
}
return ["ht"=>$total, "tps"=>round($ttps,2), "tvq"=>round($ttvq,2)];
}
}