<?php
/**
* Reception.php
* Created by Stéphane Brun
* Date: 10/07/2018 at 08:28
*/
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\ReceptionRepository")
* @ORM\Table(name="reception",
* uniqueConstraints={
* @ORM\UniqueConstraint(name="facture_unique", columns={"company_id", "fournisseur_id", "factureFournisseur"})
* }
* )
*/
class Reception
{
const HISTORY_WATCH = array(
'type' => 'Type',
'date' => 'Date',
'indicatif' => 'Indicatif',
'dateLimite' => 'Date limite',
'descriptif' => 'Descriptif',
'completee' => 'Complétée',
);
const FERME = 1;
const DEPOT = 2;
const MISE_EN_PLACE = 3;
const OFFICE = 4;
const SOLDE = 4;
//Used in import void provider
const INDICATIF_DIFF_MONTH = 4;
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="date", type="datetime")
*/
protected $date;
/**
* @ORM\Column(name="date_limite", type="datetime", nullable=true)
*/
protected $dateLimite;
/**
* @ORM\Column(name="indicatif", type="datetime", nullable=true)
*/
protected $indicatif;
/**
* Many Features have One Product.
* @ORM\ManyToOne(targetEntity="Commande", inversedBy="receptions")
* @ORM\JoinColumn(name="commandesVisees", referencedColumnName="id")
*/
protected $commandeVisee;
/**
* @ORM\Column(name="completee", type="boolean")
*/
protected $completee = false;
/**
* @ORM\Column(name="original", type="string", length=100, nullable=true)
*/
protected $original;
/**
* @ORM\Column(name="descriptif", type="string", length=150, nullable=true)
*/
protected $descriptif;
/**
* @ORM\Column(name="factureFTP", type="boolean")
*/
protected $factureFTP = false;
/**
* @ORM\Column(name="signature", type="string", length=5, nullable=true)
*/
protected $signature;
/**
* has one Company
*
* @ORM\ManyToOne(targetEntity="App\Entity\Company")
* @ORM\JoinColumn(name="company_id", referencedColumnName="id", nullable=true)
*/
protected $company;
/**
* has one Fournisseurs
*
* @ORM\ManyToOne(targetEntity="App\Entity\Fournisseurs")
* @ORM\JoinColumn(name="fournisseur_id", referencedColumnName="id")
*/
protected $fournisseur;
/**
* @ORM\Column(name="factureFournisseur", type="string", length=50)
*/
protected $factureFournisseur;
/**
* has many ReceptionDetail
*
* @ORM\OneToMany(targetEntity="App\Entity\ReceptionDetail", mappedBy="reception", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"produit" = "ASC"})
*/
protected $details;
/**
* has one ReceptionType
*
* @ORM\ManyToOne(targetEntity="App\Entity\ReceptionType")
* @ORM\JoinColumn(name="type_id", referencedColumnName="id")
*/
protected $type;
/**
* has one SysUser
*
* @ORM\ManyToOne(targetEntity="App\Entity\SysUsers")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $user;
/**
* @ORM\Column(name="ftp_total_receive", type="integer", length=200, nullable=true)
*/
protected $ftpTotalReceive = 0;
/**
* @ORM\Column(name="ftp_total_net", type="float", length=200, nullable=true)
*/
protected $ftpTotalNetNoTaxeAndTransport = 0;
/**
* @ORM\Column(name="ftp_total_tps", type="float", length=200, nullable=true)
*/
protected $ftpTotalTps = 0;
/**
* @ORM\Column(name="ftp_total_tvq", type="float", length=200, nullable=true)
*/
protected $ftpTotalTvq = 0;
/**
* @ORM\Column(name="ftp_total_invoice", type="float", length=200, nullable=true)
*/
protected $ftpTotalInvoice = 0;
public function __construct()
{
$this->details = new ArrayCollection();
$this->date = new \DateTime();
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return mixed
*/
public function getDate()
{
return $this->date;
}
/**
* @param mixed $date
* @return Reception
*/
public function setDate($date)
{
if (is_string($date)) {
$this->date = new \DateTime($date);
} else {
$this->date = $date;
}
return $this;
}
/**
* @return mixed
*/
public function getDateLimite()
{
return $this->dateLimite;
}
/**
* @param mixed $dateLimite
* @return Reception
*/
public function setDateLimite($dateLimite)
{
$this->dateLimite = $dateLimite;
return $this;
}
/**
* @return mixed
*/
public function getIndicatif()
{
return $this->indicatif;
}
/**
* @param mixed $indicatif
* @return Reception
*/
public function setIndicatif($indicatif)
{
$this->indicatif = $indicatif;
return $this;
}
/**
* @return mixed
*/
public function getCommandeVisee()
{
return $this->commandeVisee;
}
/**
* @param mixed $commandeVisee
*/
public function setCommandeVisee($commandeVisee)
{
$this->commandeVisee = $commandeVisee;
}
/**
* @return mixed
*/
public function getCompletee()
{
return $this->completee;
}
/**
* @return mixed
*/
public function isCompletee()
{
return $this->completee;
}
/**
* @param mixed $completee
* @return Reception
*/
public function setCompletee($completee)
{
$this->completee = $completee;
return $this;
}
/**
* @return mixed
*/
public function getOriginal()
{
return $this->original;
}
/**
* @param mixed $original
* @return Reception
*/
public function setOriginal($original)
{
$this->original = $original;
return $this;
}
/**
* @return mixed
*/
public function getDescriptif()
{
return $this->descriptif;
}
/**
* @param mixed $descriptif
* @return Reception
*/
public function setDescriptif($descriptif)
{
$this->descriptif = $descriptif;
return $this;
}
/**
* @return mixed
*/
public function getFactureFTP()
{
return $this->factureFTP;
}
/**
* @return mixed
*/
public function isFactureFtp()
{
return $this->getFactureFTP();
}
/**
* @param mixed $factureFTP
* @return Reception
*/
public function setFactureFTP($factureFTP)
{
$this->factureFTP = $factureFTP;
return $this;
}
/**
* @return mixed
*/
public function getSignature()
{
return $this->signature;
}
/**
* @param mixed $signature
* @return Reception
*/
public function setSignature($signature)
{
$this->signature = $signature;
return $this;
}
/**
* @return Fournisseurs
*/
public function getFournisseur()
{
return $this->fournisseur;
}
/**
* @param Fournisseurs $fournisseur
* @return Reception
*/
public function setFournisseur(Fournisseurs $fournisseur)
{
$this->fournisseur = $fournisseur;
return $this;
}
/**
* @return mixed
*/
public function getFactureFournisseur()
{
return $this->factureFournisseur;
}
/**
* @param mixed $factureFournisseur
* @return Reception
*/
public function setFactureFournisseur($factureFournisseur)
{
$this->factureFournisseur = $factureFournisseur;
return $this;
}
/**
* @return ReceptionType
*/
public function getType()
{
return $this->type;
}
/**
* @param ReceptionType $type
* @return Reception
*/
public function setType(ReceptionType $type)
{
$this->type = $type;
return $this;
}
/**
* @return Company
*/
public function getCompany()
{
return $this->company;
}
/**
* @param Company $company
* @return Reception
*/
public function setCompany(Company $company)
{
$this->company = $company;
return $this;
}
/**
* @return mixed
*/
public function getDetails()
{
return $this->details;
}
/**
* @param mixed $details
* @return Reception
*/
public function setDetails($details)
{
$this->details = $details;
return $this;
}
/**
* @param ReceptionDetail $detail
* @return Reception
*/
public function addDetail(ReceptionDetail $detail)
{
if (!$this->details->contains($detail)) {
$this->details->add($detail);
$detail->setReception($this);
}
return $this;
}
/**
* @param ReceptionDetail $detail
* @return Reception
*/
public function removeDetail(ReceptionDetail $detail)
{
if ($this->details->contains($detail)) {
$this->details->removeElement($detail);
// $detail->setReception(null);
}
return $this;
}
/**
* @return SysUsers
*/
public function getUser()
{
return $this->user;
}
/**
* @param SysUsers $user
* @return Reception
*/
public function setUser(SysUsers $user)
{
$this->user = $user;
return $this;
}
/**
* @return mixed
*/
public function getFtpTotalReceive()
{
return $this->ftpTotalReceive;
}
/**
* @param mixed $ftpTotalReceive
*/
public function setFtpTotalReceive($ftpTotalReceive): void
{
$this->ftpTotalReceive = $ftpTotalReceive;
}
/**
* @return mixed
*/
public function getFtpTotalNetNoTaxeAndTransport()
{
return $this->ftpTotalNetNoTaxeAndTransport;
}
/**
* @param mixed $ftpTotalNetNoTaxeAndTransport
*/
public function setFtpTotalNetNoTaxeAndTransport($ftpTotalNetNoTaxeAndTransport): void
{
$this->ftpTotalNetNoTaxeAndTransport = $ftpTotalNetNoTaxeAndTransport;
}
/**
* @return mixed
*/
public function getFtpTotalTps()
{
return $this->ftpTotalTps;
}
/**
* @param mixed $ftpTotalTps
*/
public function setFtpTotalTps($ftpTotalTps): void
{
$this->ftpTotalTps = $ftpTotalTps;
}
/**
* @return mixed
*/
public function getFtpTotalTvq()
{
return $this->ftpTotalTvq;
}
/**
* @param mixed $ftpTotalTvq
*/
public function setFtpTotalTvq($ftpTotalTvq): void
{
$this->ftpTotalTvq = $ftpTotalTvq;
}
/**
* @return mixed
*/
public function getFtpTotalInvoice()
{
return $this->ftpTotalInvoice;
}
/**
* @param mixed $ftpTotalInvoice
*/
public function setFtpTotalInvoice($ftpTotalInvoice): void
{
$this->ftpTotalInvoice = $ftpTotalInvoice;
}
/***
* @param Reception $reception
* @return Reception
* @throws \Exception
*/
public static function calculDateLimit(Reception $reception) : Reception
{
if (empty($reception->getDate()) || empty($reception->getFournisseur())) {
return $reception;
}
$date = $reception->getDate();
$dateLimit = clone($date);
return $reception->setDateLimite(
$dateLimit->add(
new \DateInterval('P' . $reception->getFournisseur()->getDureeOffice() . 'D')
)
);
}
/***
* @param Reception $reception
* @return Reception
* @throws \Exception
*/
public function calculIndicatif(Reception $reception) : Reception
{
if (empty($reception->getDate())) {
return $reception;
}
$date = $reception->getDate();
$dateIndicatif = clone($date);
return $reception->setIndicatif(
$dateIndicatif->add(
new \DateInterval('P' . $this::INDICATIF_DIFF_MONTH . 'M')
)
);
}
}