<?php
/**
* Transfert.php
* Created by Stéphane Brun
* Date: 2018-09-19 at 15:05
*/
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\TransfertRepository")
* @ORM\Table(name="transfert")
*/
class Transfert
{
const STATUS_NEW = 1;
const STATUS_SEEN = 2; // Pas utilisé
const STATUS_RECEIVED = 3;
const STATUS_SENT = 4;
const STATUS_CANCELED = 5;
const STATUS_ASKED = 6;
const STATUS_ASK_ACCEPTED = 7; // Pas utilisé
const STATUS_ASK_REFUSED = 8;
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="date", type="datetime")
*/
protected $date;
/**
* @ORM\Column(name="date_sent", type="datetime", nullable=true)
*/
protected $dateSent;
/**
* @ORM\Column(name="date_accepted", type="datetime", nullable=true)
*/
protected $dateAccepted;
/**
* @ORM\Column(name="date_cancelled", type="datetime", nullable=true)
*/
protected $dateCancelled;
/**
* @ORM\Column(name="date_asked", type="datetime", nullable=true)
*/
protected $dateAsked;
/**
* @ORM\Column(name="date_ask_refused", type="datetime", nullable=true)
*/
protected $dateAskRefused;
/**
* @ORM\Column(name="status", type="integer")
*/
protected $status;
/**
* @ORM\Column(name="commentaire", type="text", nullable=true)
*/
protected $commentaire;
/**
* has many TransfertDetail
*
* @ORM\OneToMany(targetEntity="TransfertDetail", mappedBy="transfert", cascade={"persist", "remove"}, orphanRemoval=true)
*/
protected $details;
/**
* has one From Company
*
* @ORM\ManyToOne(targetEntity="App\Entity\Company")
* @ORM\JoinColumn(name="from_company_id", referencedColumnName="id")
*/
protected $from;
/**
* has one From Company
*
* @ORM\ManyToOne(targetEntity="App\Entity\Company")
* @ORM\JoinColumn(name="to_company_id", referencedColumnName="id")
*/
protected $to;
/**
* has one SysUser
*
* @ORM\ManyToOne(targetEntity="App\Entity\SysUsers")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $user;
public function __construct()
{
$this->details = new ArrayCollection();
$this->date = new \DateTime();
$this->status = self::STATUS_NEW;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return mixed
*/
public function getDate()
{
return $this->date;
}
/**
* @param mixed $date
* @return Transfert
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* @return mixed
*/
public function getDetails()
{
return $this->details;
}
/**
* @param mixed $details
* @return Transfert
*/
public function setDetails(TransfertDetail $details)
{
$this->details = $details;
return $this;
}
/**
* @param TransfertDetail $detail
* @return Transfert
*/
public function addDetail(TransfertDetail $detail)
{
if (!$this->details->contains($detail)) {
$this->details->add($detail);
$detail->setTransfert($this);
}
return $this;
}
/**
* @param TransfertDetail $detail
* @return Transfert
*/
public function removeDetail(TransfertDetail $detail)
{
if ($this->details->contains($detail)) {
$this->details->removeElement($detail);
// $detail->setTransfert(null);
}
return $this;
}
/**
* @return mixed
*/
public function getDateSent()
{
return $this->dateSent;
}
/**
* @param mixed $dateSent
* @return Transfert
*/
public function setDateSent($dateSent)
{
$this->dateSent = $dateSent;
return $this;
}
/**
* @return mixed
*/
public function getDateAccepted()
{
return $this->dateAccepted;
}
/**
* @param mixed $dateAccepted
* @return Transfert
*/
public function setDateAccepted($dateAccepted)
{
$this->dateAccepted = $dateAccepted;
return $this;
}
/**
* @return mixed
*/
public function getStatus()
{
return $this->status;
}
/**
* @param mixed $status
* @return Transfert
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* @return mixed
*/
public function getFrom()
{
return $this->from;
}
/**
* @param Company $from
* @return Transfert
*/
public function setFrom(Company $from)
{
$this->from = $from;
return $this;
}
/**
* @return mixed
*/
public function getTo()
{
return $this->to;
}
/**
* @param Company $to
* @return Transfert
*/
public function setTo(Company $to)
{
$this->to = $to;
return $this;
}
/**
* @return mixed
*/
public function getCommentaire()
{
return $this->commentaire;
}
/**
* @param mixed $commentaire
* @return Transfert
*/
public function setCommentaire($commentaire)
{
$this->commentaire = $commentaire;
return $this;
}
/**
* @return mixed
*/
public function getDateCancelled()
{
return $this->dateCancelled;
}
/**
* @param mixed $dateCancelled
* @return Transfert
*/
public function setDateCancelled($dateCancelled)
{
$this->dateCancelled = $dateCancelled;
return $this;
}
/**
* @return mixed
*/
public function getDateAsked()
{
return $this->dateAsked;
}
/**
* @param mixed $dateAsked
* @return Transfert
*/
public function setDateAsked($dateAsked)
{
$this->dateAsked = $dateAsked;
return $this;
}
/**
* @return mixed
*/
public function getDateAskRefused()
{
return $this->dateAskRefused;
}
/**
* @param mixed $dateAskRefused
* @return Transfert
*/
public function setDateAskRefused($dateAskRefused)
{
$this->dateAskRefused = $dateAskRefused;
return $this;
}
/**
* @return mixed
*/
public function getUser()
{
return $this->user;
}
/**
* @param mixed $user
* @return Transfert
*/
public function setUser($user)
{
$this->user = $user;
return $this;
}
/**
* @return float
*/
public function getTotalValue() : float
{
$total = 0.0;
/** @var TransfertDetail $detail */
foreach ($this->getDetails() as $detail) {
$total += $detail->getProduit()->getCoutant() * $detail->getQuantite();
}
return $total;
}
}