src/Entity/Transfert.php line 16

Open in your IDE?
  1. <?php
  2. /**
  3.  * Transfert.php
  4.  * Created by Stéphane Brun
  5.  * Date: 2018-09-19 at 15:05
  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\TransfertRepository")
  12.  * @ORM\Table(name="transfert")
  13.  */
  14. class Transfert
  15. {
  16.     const STATUS_NEW 1;
  17.     const STATUS_SEEN 2;              // Pas utilisé
  18.     const STATUS_RECEIVED 3;
  19.     const STATUS_SENT 4;
  20.     const STATUS_CANCELED 5;
  21.     const STATUS_ASKED 6;
  22.     const STATUS_ASK_ACCEPTED 7;      // Pas utilisé
  23.     const STATUS_ASK_REFUSED 8;
  24.     /**
  25.      * @ORM\Column(type="integer")
  26.      * @ORM\Id
  27.      * @ORM\GeneratedValue(strategy="AUTO")
  28.      */
  29.     protected $id;
  30.     /**
  31.      * @ORM\Column(name="date", type="datetime")
  32.      */
  33.     protected $date;
  34.     /**
  35.      * @ORM\Column(name="date_sent", type="datetime", nullable=true)
  36.      */
  37.     protected $dateSent;
  38.     /**
  39.      * @ORM\Column(name="date_accepted", type="datetime", nullable=true)
  40.      */
  41.     protected $dateAccepted;
  42.     /**
  43.      * @ORM\Column(name="date_cancelled", type="datetime", nullable=true)
  44.      */
  45.     protected $dateCancelled;
  46.     /**
  47.      * @ORM\Column(name="date_asked", type="datetime", nullable=true)
  48.      */
  49.     protected $dateAsked;
  50.     /**
  51.      * @ORM\Column(name="date_ask_refused", type="datetime", nullable=true)
  52.      */
  53.     protected $dateAskRefused;
  54.     /**
  55.      * @ORM\Column(name="status", type="integer")
  56.      */
  57.     protected $status;
  58.     /**
  59.      * @ORM\Column(name="commentaire", type="text", nullable=true)
  60.      */
  61.     protected $commentaire;
  62.     /**
  63.      * has many TransfertDetail
  64.      *
  65.      * @ORM\OneToMany(targetEntity="TransfertDetail", mappedBy="transfert", cascade={"persist", "remove"}, orphanRemoval=true)
  66.      */
  67.     protected $details;
  68.     /**
  69.      * has one From Company
  70.      *
  71.      * @ORM\ManyToOne(targetEntity="App\Entity\Company")
  72.      * @ORM\JoinColumn(name="from_company_id", referencedColumnName="id")
  73.      */
  74.     protected $from;
  75.     /**
  76.      * has one From Company
  77.      *
  78.      * @ORM\ManyToOne(targetEntity="App\Entity\Company")
  79.      * @ORM\JoinColumn(name="to_company_id", referencedColumnName="id")
  80.      */
  81.     protected $to;
  82.     /**
  83.      * has one SysUser
  84.      *
  85.      * @ORM\ManyToOne(targetEntity="App\Entity\SysUsers")
  86.      * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  87.      */
  88.     protected $user;
  89.     public function __construct()
  90.     {
  91.         $this->details = new ArrayCollection();
  92.         $this->date = new \DateTime();
  93.         $this->status self::STATUS_NEW;
  94.     }
  95.     /**
  96.      * @return mixed
  97.      */
  98.     public function getId()
  99.     {
  100.         return $this->id;
  101.     }
  102.     /**
  103.      * @return mixed
  104.      */
  105.     public function getDate()
  106.     {
  107.         return $this->date;
  108.     }
  109.     /**
  110.      * @param mixed $date
  111.      * @return Transfert
  112.      */
  113.     public function setDate($date)
  114.     {
  115.         $this->date $date;
  116.         return $this;
  117.     }
  118.     /**
  119.      * @return mixed
  120.      */
  121.     public function getDetails()
  122.     {
  123.         return $this->details;
  124.     }
  125.     /**
  126.      * @param mixed $details
  127.      * @return Transfert
  128.      */
  129.     public function setDetails(TransfertDetail $details)
  130.     {
  131.         $this->details $details;
  132.         return $this;
  133.     }
  134.     /**
  135.      * @param TransfertDetail $detail
  136.      * @return Transfert
  137.      */
  138.     public function addDetail(TransfertDetail $detail)
  139.     {
  140.         if (!$this->details->contains($detail)) {
  141.             $this->details->add($detail);
  142.             $detail->setTransfert($this);
  143.         }
  144.         return $this;
  145.     }
  146.     /**
  147.      * @param TransfertDetail $detail
  148.      * @return Transfert
  149.      */
  150.     public function removeDetail(TransfertDetail $detail)
  151.     {
  152.         if ($this->details->contains($detail)) {
  153.             $this->details->removeElement($detail);
  154. //            $detail->setTransfert(null);
  155.         }
  156.         return $this;
  157.     }
  158.     /**
  159.      * @return mixed
  160.      */
  161.     public function getDateSent()
  162.     {
  163.         return $this->dateSent;
  164.     }
  165.     /**
  166.      * @param mixed $dateSent
  167.      * @return Transfert
  168.      */
  169.     public function setDateSent($dateSent)
  170.     {
  171.         $this->dateSent $dateSent;
  172.         return $this;
  173.     }
  174.     /**
  175.      * @return mixed
  176.      */
  177.     public function getDateAccepted()
  178.     {
  179.         return $this->dateAccepted;
  180.     }
  181.     /**
  182.      * @param mixed $dateAccepted
  183.      * @return Transfert
  184.      */
  185.     public function setDateAccepted($dateAccepted)
  186.     {
  187.         $this->dateAccepted $dateAccepted;
  188.         return $this;
  189.     }
  190.     /**
  191.      * @return mixed
  192.      */
  193.     public function getStatus()
  194.     {
  195.         return $this->status;
  196.     }
  197.     /**
  198.      * @param mixed $status
  199.      * @return Transfert
  200.      */
  201.     public function setStatus($status)
  202.     {
  203.         $this->status $status;
  204.         return $this;
  205.     }
  206.     /**
  207.      * @return mixed
  208.      */
  209.     public function getFrom()
  210.     {
  211.         return $this->from;
  212.     }
  213.     /**
  214.      * @param Company $from
  215.      * @return Transfert
  216.      */
  217.     public function setFrom(Company $from)
  218.     {
  219.         $this->from $from;
  220.         return $this;
  221.     }
  222.     /**
  223.      * @return mixed
  224.      */
  225.     public function getTo()
  226.     {
  227.         return $this->to;
  228.     }
  229.     /**
  230.      * @param Company $to
  231.      * @return Transfert
  232.      */
  233.     public function setTo(Company $to)
  234.     {
  235.         $this->to $to;
  236.         return $this;
  237.     }
  238.     /**
  239.      * @return mixed
  240.      */
  241.     public function getCommentaire()
  242.     {
  243.         return $this->commentaire;
  244.     }
  245.     /**
  246.      * @param mixed $commentaire
  247.      * @return Transfert
  248.      */
  249.     public function setCommentaire($commentaire)
  250.     {
  251.         $this->commentaire $commentaire;
  252.         return $this;
  253.     }
  254.     /**
  255.      * @return mixed
  256.      */
  257.     public function getDateCancelled()
  258.     {
  259.         return $this->dateCancelled;
  260.     }
  261.     /**
  262.      * @param mixed $dateCancelled
  263.      * @return Transfert
  264.      */
  265.     public function setDateCancelled($dateCancelled)
  266.     {
  267.         $this->dateCancelled $dateCancelled;
  268.         return $this;
  269.     }
  270.     /**
  271.      * @return mixed
  272.      */
  273.     public function getDateAsked()
  274.     {
  275.         return $this->dateAsked;
  276.     }
  277.     /**
  278.      * @param mixed $dateAsked
  279.      * @return Transfert
  280.      */
  281.     public function setDateAsked($dateAsked)
  282.     {
  283.         $this->dateAsked $dateAsked;
  284.         return $this;
  285.     }
  286.     /**
  287.      * @return mixed
  288.      */
  289.     public function getDateAskRefused()
  290.     {
  291.         return $this->dateAskRefused;
  292.     }
  293.     /**
  294.      * @param mixed $dateAskRefused
  295.      * @return Transfert
  296.      */
  297.     public function setDateAskRefused($dateAskRefused)
  298.     {
  299.         $this->dateAskRefused $dateAskRefused;
  300.         return $this;
  301.     }
  302.     /**
  303.      * @return mixed
  304.      */
  305.     public function getUser()
  306.     {
  307.         return $this->user;
  308.     }
  309.     /**
  310.      * @param mixed $user
  311.      * @return Transfert
  312.      */
  313.     public function setUser($user)
  314.     {
  315.         $this->user $user;
  316.         return $this;
  317.     }
  318.     /**
  319.      * @return float
  320.      */
  321.     public function getTotalValue() : float
  322.     {
  323.         $total 0.0;
  324.         /** @var TransfertDetail $detail */
  325.         foreach ($this->getDetails() as $detail) {
  326.             $total += $detail->getProduit()->getCoutant() * $detail->getQuantite();
  327.         }
  328.         return $total;
  329.     }
  330. }