<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Product\ProductType;
use App\Entity\Product\Famille;
use App\Entity\Product\SousFamille;
use App\Repository\ProductRepository;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* Product
*
* @ORM\Table(name="product")
* @ORM\Entity(repositoryClass=ProductRepository::class)
*/
class Product implements \JsonSerializable
{
const TYPE_TVA_ENCAISSEMENT = 0;
const TYPE_TVA_DEBIT = 1;
const TYPE_COIFFURE = 'coiffure';
const TYPE_ESTHETHIQUE = 'esthetique';
const FACTURATION_SITE = 'site';
const FACTURATION_CLIENT = 'client';
const TYPE_TAUX_TVA_STANDARD = 0;
const TYPE_TAUX_TVA_REDUIT = 1;
/**
* @var int
* @Groups({"planning"})
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
* @Groups({"planning"})
* @ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="marque", type="string", length=1000, nullable=true)
*/
private $marque;
/**
* @var string
*
* @ORM\Column(name="gamme", type="string", length=1000, nullable=true)
*/
private $gamme;
/**
* @var string
*
* @ORM\Column(name="compte", type="string", length=1000, nullable=false)
*/
private $compte;
/**
* @var string
*
* @ORM\Column(name="facturation", type="string", length=1000, nullable=false)
*/
private $facturation = Product::FACTURATION_SITE;
/**
* @var string
*
* @ORM\Column(name="type_taux_tva", type="integer", nullable=true)
*/
private $typeTauxTva = Product::TYPE_TAUX_TVA_STANDARD;
/**
*
* @ORM\Column(name="ui", type="string", nullable=true)
*/
private $ui;
/**
* @var string
*
* @ORM\Column(name="mesure", type="string", nullable=true)
*/
private $mesure;
/**
* @var string
*
* @ORM\Column(name="type", type="string", nullable=true)
*/
private $type;
/**
* @var string
*
* @ORM\Column(name="fournisseur", type="string", nullable=true)
*/
private $fournisseur;
/**
* @var string
*
* @ORM\Column(name="remiseGenerale", type="float", nullable=true)
*/
private $remiseGenerale;
/**
* @var string
*
* @ORM\Column(name="tempsNormatif", type="float", nullable=true)
*/
private $tempsNormatif;
/**
* @var string
*
* @ORM\Column(name="forfaitIllimite", type="boolean", nullable=true)
*/
private $forfaitIllimite = false;
/**
* @var string|null
*
* @ORM\Column(name="reference", type="string", length=255, nullable=true)
*/
private $reference;
/**
* @var string|null
*
* @ORM\Column(name="price_sell_ht_a", type="string", length=255, nullable=true)
*/
private $priceHtA;
/**
* @var string|null
*
* @ORM\Column(name="price_ht_b", type="float", nullable=true)
*/
private $priceHtB;
/**
* @var string|null
*
* @ORM\Column(name="price_ht_c", type="float", nullable=true)
*/
private $priceHtC;
/**
* @var string|null
*
* @ORM\Column(name="price_ht_c_d", type="float", nullable=true)
*/
private $priceHtD;
/**
* Prix dachat en fait
* @var string|null
*
* @ORM\Column(name="price_ht", type="string", length=255, nullable=true)
*/
private $priceHt;
/**
* @var string|null
*
* @ORM\Column(name="marge", type="string", length=255, nullable=true)
*/
private $marge;
/**
* @var string|null
*
* @ORM\Column(name="tva", type="string", length=255, nullable=true)
*/
private $tva;
/**
* @var string|null
*
* @ORM\Column(name="type_tva", type="string", nullable=true)
*/
private $typeTva;
/**
* @var string|null
*
* @ORM\Column(name="stock_quantity", type="integer", nullable=true)
*/
private $stockQuantity;
/**
* @var string|null
*
* @ORM\Column(name="gestion_stock", type="boolean", nullable=true)
*/
private $gestionStock = false;
/**
* @var string|null
*
* @ORM\Column(name="order_multiple", type="float", nullable=true)
*/
private $orderMultiple;
/**
* @var string|null
*
* @ORM\Column(name="indisponible_vente", type="boolean", nullable=true)
*/
private $indisponibleVente = false;
/**
* @var string|null
*
* @ORM\Column(name="unitVente", type="float", nullable=true)
*/
private $unitVente;
/**
* @var Salon ArrayCollection
* @ORM\OneToMany(targetEntity=RDVProduct::class, mappedBy="product", cascade={"remove"})
*/
protected $rdvProducts;
/**
* @ORM\OneToMany(targetEntity=RecurrenceProduct::class, mappedBy="product")
*/
private $recurrenceProducts;
/**
* @var ProductType
*
* @ORM\ManyToOne(targetEntity=ProductType::class)
* @ORM\JoinColumn(name="product_type", referencedColumnName="id")
*/
private $productType;
/**
* @var ProductType
*
* @ORM\ManyToOne(targetEntity=Famille::class)
* @ORM\JoinColumn(name="famille", referencedColumnName="id")
*/
private $famille;
/**
* @var ProductType
*
* @ORM\ManyToOne(targetEntity=SousFamille::class)
* @ORM\JoinColumn(name="sous_famille", referencedColumnName="id")
*/
private $sousFamille;
/**
* @ORM\OneToMany(targetEntity=ProductService::class, mappedBy="product", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $productServices;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $mandatory = false;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $noReservation = false;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $commercialName;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $checked = false;
/**
* @var int|null
*
* @ORM\Column(name="ordering", type="integer", nullable=true)
*/
private $ordering;
/**
* Product constructor.
*/
public function __construct()
{
$this->rdvProducts = new ArrayCollection();
$this->productServices = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(?string $reference): self
{
$this->reference = $reference;
return $this;
}
public function getPriceHt(): ?string
{
return $this->priceHt;
}
public function setPriceHt(?string $priceHt): self
{
$this->priceHt = $priceHt;
return $this;
}
public function getMarge(): ?string
{
return $this->marge;
}
public function setMarge(?string $marge): self
{
$this->marge = $marge;
return $this;
}
public function getTva(): ?string
{
return $this->tva;
}
public function setTva(?string $tva): self
{
$this->tva = $tva;
return $this;
}
/**
* @return string
*/
public function getMesure(): ?string
{
return $this->mesure;
}
/**
* @param string $mesure
*/
public function setMesure(?string $mesure): void
{
$this->mesure = $mesure;
}
/**
* @return string|null
*/
public function getUnitVente(): ?string
{
return $this->unitVente;
}
/**
* @param string|null $unitVente
*/
public function setUnitVente(?string $unitVente): void
{
$this->unitVente = $unitVente;
}
/**
* @return string|null
*/
public function getTypeTva(): ?string
{
return $this->typeTva;
}
/**
* @param string|null $typeTva
*/
public function setTypeTva(?string $typeTva): void
{
$this->typeTva = $typeTva;
}
/**
* @return string|null
*/
public function getGestionStock(): ?string
{
return $this->gestionStock;
}
/**
* @param string|null $gestionStock
*/
public function setGestionStock(?string $gestionStock): void
{
$this->gestionStock = $gestionStock;
}
/**
* @return string|null
*/
public function getIndisponibleVente(): ?string
{
return $this->indisponibleVente;
}
/**
* @param string|null $indisponibleVente
*/
public function setIndisponibleVente(?string $indisponibleVente): void
{
$this->indisponibleVente = $indisponibleVente;
}
/**
* @return string
*/
public function getRemiseGenerale(): ?string
{
return $this->remiseGenerale;
}
/**
* @param string $remiseGenerale
*/
public function setRemiseGenerale(string $remiseGenerale): void
{
$this->remiseGenerale = $remiseGenerale;
}
/**
* @return string
*/
public function getTempsNormatif(): ?string
{
return $this->tempsNormatif;
}
/**
* @param string $tempsNormatif
*/
public function setTempsNormatif(?string $tempsNormatif): void
{
$this->tempsNormatif = $tempsNormatif;
}
/**
* @return string
*/
public function getFournisseur(): ?string
{
return $this->fournisseur;
}
/**
* @param string $fournisseur
*/
public function setFournisseur(?string $fournisseur): void
{
$this->fournisseur = $fournisseur;
}
/**
* @return ProductType
*/
public function getProductType(): ?ProductType
{
return $this->productType;
}
/**
* @param ProductType $productType
*/
public function setProductType(ProductType $productType): void
{
$this->productType = $productType;
}
/**
* @return mixed
*/
public function getUi()
{
return $this->ui;
}
/**
* @param mixed $ui
*/
public function setUi($ui): void
{
$this->ui = $ui;
}
public function getPriceSellTTC()
{
$calcul = $this->floatvalue($this->priceHt) * (1 + intval($this->getTva()) / 100);
return round($calcul, 2);
}
public function getPriceSellTTCA()
{
$calcul = round($this->floatvalue($this->priceHtA), 2) * (1 + intval($this->getTva()) / 100);
return round($calcul, 2);
}
function floatvalue($val)
{
$val = str_replace(",", ".", $val);
$val = preg_replace('/\.(?=.*\.)/', '', $val);
return floatval($val);
}
public function getPriceSellTTCByGrid($grid)
{
$price = 0;
switch ($grid) {
case 1:
$price = $this->getPriceHtA();
break;
case 2:
$price = $this->getPriceHtB();
break;
case 3:
$price = $this->getPriceHtC();
break;
case 4:
$price = $this->getPriceHtD();
break;
}
$calcul = $this->floatvalue($price) * (1 + intval($this->getTva()) / 100);
return round($calcul, 2);
}
/**
* @return Famille
*/
public function getFamille(): ?Famille
{
return $this->famille;
}
/**
* @param Famille $famille
*/
public function setFamille(Famille $famille): void
{
$this->famille = $famille;
}
/**
* @return SousFamille
*/
public function getSousFamille(): ?SousFamille
{
return $this->sousFamille;
}
/**
* @param SousFamille $sousFamille
*/
public function setSousFamille(SousFamille $sousFamille): void
{
$this->sousFamille = $sousFamille;
}
/**
* @return string
*/
public function getType(): ?string
{
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type): void
{
$this->type = $type;
}
/**
* @return Salon
*/
public function getRdvProducts()
{
return $this->rdvProducts;
}
/**
* @param RDVProduct $rdvProducts
*/
public function setRdvProducts(RDVProduct $rdvProducts): void
{
$this->rdvProducts = $rdvProducts;
}
/**
* @return string|null
*/
public function getOrderMultiple(): ?string
{
return $this->orderMultiple;
}
/**
* @param string|null $orderMultiple
*/
public function setOrderMultiple(?string $orderMultiple): void
{
$this->orderMultiple = $orderMultiple;
}
/**
* @return string|null
*/
public function getStockQuantity(): ?string
{
return $this->stockQuantity;
}
/**
* @param string|null $stockQuantity
*/
public function setStockQuantity(?string $stockQuantity): void
{
$this->stockQuantity = $stockQuantity;
}
/**
* @return string
*/
public function getMarque(): ?string
{
return $this->marque;
}
/**
* @param string $marque
*/
public function setMarque(?string $marque): void
{
$this->marque = $marque;
}
/**
* @return string
*/
public function getGamme(): ?string
{
return $this->gamme;
}
/**
* @param string $gamme
*/
public function setGamme(?string $gamme): void
{
$this->gamme = $gamme;
}
/**
* @return string
*/
public function getCompte(): ?string
{
return $this->compte;
}
/**
* @param string $compte
*/
public function setCompte(?string $compte): void
{
$this->compte = $compte;
}
/**
* @return string
*/
public function getFacturation(): ?string
{
return $this->facturation;
}
/**
* @param string $facturation
*/
public function setFacturation(string $facturation): void
{
$this->facturation = $facturation;
}
/**
* @return string|null
*/
public function getPriceHtB(): ?string
{
return $this->priceHtB;
}
/**
* @param string|null $priceHtB
*/
public function setPriceHtB(?string $priceHtB): void
{
$this->priceHtB = $priceHtB;
}
/**
* @return string|null
*/
public function getPriceHtC(): ?string
{
return $this->priceHtC;
}
/**
* @param string|null $priceHtC
*/
public function setPriceHtC(?string $priceHtC): void
{
$this->priceHtC = $priceHtC;
}
/**
* @return string|null
*/
public function getPriceHtD(): ?string
{
return $this->priceHtD;
}
/**
* @param string|null $priceHtD
*/
public function setPriceHtD(?string $priceHtD): void
{
$this->priceHtD = $priceHtD;
}
/**
* @return string|null
*/
public function getPriceHtA(): ?string
{
return $this->priceHtA;
}
/**
* @param string|null $priceHtA
*/
public function setPriceHtA(?string $priceHtA): void
{
$this->priceHtA = $priceHtA;
}
/**
* @return string
*/
public function getForfaitIllimite(): ?bool
{
return $this->forfaitIllimite;
}
/**
* @param string $forfaitIllimite
*/
public function setForfaitIllimite(bool $forfaitIllimite): void
{
$this->forfaitIllimite = $forfaitIllimite;
}
/**
* @return string
*/
public function getTypeTauxTva(): ?string
{
return $this->typeTauxTva;
}
/**
* @param string $typeTauxTva
*/
public function setTypeTauxTva(string $typeTauxTva): void
{
$this->typeTauxTva = $typeTauxTva;
}
/**
* @return Collection<int, ProductService>
*/
public function getProductServices(): Collection
{
return $this->productServices;
}
public function addProductService(ProductService $productService): self
{
if (!$this->productServices->contains($productService)) {
$this->productServices[] = $productService;
$productService->setProduct($this);
}
return $this;
}
public function removeProductService(ProductService $productService): self
{
if ($this->productServices->removeElement($productService)) {
// set the owning side to null (unless already changed)
if ($productService->getProduct() === $this) {
$productService->setProduct(null);
}
}
return $this;
}
public function isMandatory(): ?bool
{
return $this->mandatory;
}
public function setMandatory(bool $mandatory): self
{
$this->mandatory = $mandatory;
return $this;
}
public function displayName()
{
return $this->getPriceSellTTC() ? $this->getName() . ' ' . $this->getPriceSellTTC() . '€' : $this->getName();
}
public function isNoReservation(): ?bool
{
return $this->noReservation;
}
public function setNoReservation(?bool $noReservation): self
{
$this->noReservation = $noReservation;
return $this;
}
public function getCommercialName(): ?string
{
return $this->commercialName;
}
public function setCommercialName(?string $commercialName): self
{
$this->commercialName = $commercialName;
return $this;
}
public function isChecked(): ?bool
{
return $this->checked;
}
public function setChecked(?bool $checked): self
{
$this->checked = $checked;
return $this;
}
/**
* @return Collection<int, RecurrenceProduct>
*/
public function getRecurrenceProducts(): Collection
{
return $this->recurrenceProducts;
}
public function addRecurrenceProduct(RecurrenceProduct $recurrenceProduct): self
{
if (!$this->recurrenceProducts->contains($recurrenceProduct)) {
$this->recurrenceProducts[] = $recurrenceProduct;
$recurrenceProduct->setProduct($this);
}
return $this;
}
public function removeRecurrenceProduct(RecurrenceProduct $recurrenceProduct): self
{
if ($this->recurrenceProducts->removeElement($recurrenceProduct)) {
// Set the owning side to null (unless already changed)
if ($recurrenceProduct->getProduct() === $this) {
$recurrenceProduct->setProduct(null);
}
}
return $this;
}
/**
* @return int
*/
public function getOrdering(): ?int
{
return $this->ordering;
}
/**
* @param int $ordering
*/
public function setOrdering(?int $ordering): void
{
$this->ordering = $ordering;
}
public function jsonSerialize()
{
return [
'id' => $this->id,
'name' => $this->name,
];
}
}