<?php
namespace App\Entity;
use App\Repository\TblOperationVenteRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Traits\TimestampableTrait;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
/**
* @ORM\Entity(repositoryClass=TblOperationVenteRepository::class)
*/
class TblOperationVente
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="date" )
*/
private $date;
/**
* @ORM\Column(type="float" , nullable=true)
*/
private $totalPrix;
/**
* @ORM\Column(type="float" , nullable=true)
*/
private $totalCaisse;
/**
* @ORM\ManyToOne(targetEntity=RefTypeVente::class, inversedBy="tblOperationVentes")
*/
private $typeVente;
/**
* @ORM\OneToMany(targetEntity=TblDetailCharge::class, mappedBy="tblOperationVente" ,cascade={"persist"})
*/
private $detailCharge;
/**
* @ORM\OneToMany(targetEntity=TblDetailProduitVente::class, mappedBy="tblOperationVente",cascade={"persist"})
*/
private $detailProduitVente;
/**
* @ORM\OneToMany(targetEntity=TblDetailQuantiteParcelle::class, mappedBy="tblOperationVente" , cascade={"persist"},orphanRemoval=true)
*/
private $detailQuantiteParcelle;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="tblOperationVentes")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="vendeur", referencedColumnName="user_id")
* })
*/
private $vendeur;
/**
* @ORM\ManyToOne(targetEntity=RefVille::class, inversedBy="tblOperationVentes")
*/
private $destination;
/**
* @ORM\ManyToMany(targetEntity=RefMoyenTransport::class)
* @ORM\JoinTable(name="lnk_moyen_transport_tbl_operation_vente",
* joinColumns={
* @ORM\JoinColumn(name="tbl_operation_vente_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="ref_moyen_transport_id", referencedColumnName="id", nullable=false)
* }
* )
*/
private $moyenTransports;
/**
* @ORM\ManyToMany(targetEntity=TblFile::class,cascade={"persist"})
* @ORM\JoinTable(name="lnk_tbl_tblOperationVente_tbl_file",
* joinColumns={
* @ORM\JoinColumn(name="tbl_tblOperationVentes_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="tbl_file_id", referencedColumnName="id", nullable=false)
* }
* )
*/
private $files;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $matricule;
use WorkflowableVente;
use TimestampableTrait;
public function __construct()
{
$this->detailCharge = new ArrayCollection();
$this->detailProduitVente = new ArrayCollection();
$this->detailQuantiteParcelle = new ArrayCollection();
$this->moyenTransports = new ArrayCollection();
$this->files = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getTotalPrix(): ?float
{
return $this->totalPrix;
}
public function setTotalPrix(float $totalPrix): self
{
$this->totalPrix = $totalPrix;
return $this;
}
public function getTotalCaisse(): ?float
{
return $this->totalCaisse;
}
public function setTotalCaisse(float $totalCaisse): self
{
$this->totalCaisse = $totalCaisse;
return $this;
}
public function getTypeVente(): ?RefTypeVente
{
return $this->typeVente;
}
public function setTypeVente(?RefTypeVente $typeVente): self
{
$this->typeVente = $typeVente;
return $this;
}
public function toArrayDatatable($urlEdit,$urlShow)
{
return [
$this->getDate()->format('d/m/Y'),
$this->getVendeur()->__toString(),
$this->getProfitOperationVente()." DH",
$this->getTransportsToString(),
$this->getMatricule()?: "--",
$this->getTotalCaisse(),
$this->getetatAvancementForOperation().' %',
'<a class="btn btn-primary" title="Modifier" href=' . $urlEdit . '><i class="ti ti-edit"></i></a> <a class="btn btn-default" href=' . $urlShow . '><i class="ti ti-eye"></i></a>'
];
}
public function getTransportsToString()
{
$result = '';
foreach($this->getMoyenTransports() as $moyen) {
$result .= $moyen->getLibelle(). '<br>';
}
return $result;
}
public function getTotalQuantiteForParcelle()
{
$reste = 0;
foreach($this->detailQuantiteParcelle as $detailQuantite){
if( $detailQuantite->getDeletedAt() == null ){
$reste += $detailQuantite->getQuantite();
}
}
return $reste;
}
public function getTotalCaisseForParcelle()
{
$reste = 0;
foreach($this->detailQuantiteParcelle as $detailQuantite){
$reste += $detailQuantite->getCaisse();
}
return $reste;
}
public function getTotalCaisseForProduitVente()
{
$reste = 0;
foreach($this->detailProduitVente as $detailProduit){
$reste += $detailProduit->getCaisse();
}
return $reste;
}
public function getTotalQuantiteForVente()
{
$reste = 0;
foreach($this->detailProduitVente as $detailProduit){
if( $detailProduit->getDeletedAt() == null ){
$reste += $detailProduit->getQuantite();
}
}
return $reste;
}
public function getTotalPrixVenteEtQuantite()
{
$reste = 0;
foreach($this->detailProduitVente as $detailProduit){
if( $detailProduit->getDeletedAt() == null ){
$reste += $detailProduit->getPrixVente() * $detailProduit->getQuantite();
}
}
return $reste;
}
public function getProfitOperationVente()
{
return $this->getTotalPrixVenteEtQuantite()-$this->getTotalMontantForCharge();
}
public function getTotalMontantForCharge()
{
$reste = 0;
foreach($this->detailCharge as $detailCharges){
if( $detailCharges->getDeletedAt() == null ){
$reste += $detailCharges->getMontant();
}
}
return $reste;
}
public function getTotalQuantiteForCharge()
{
$reste = 0;
foreach($this->detailCharge as $detailCharges){
$reste += $detailCharges->getQuantite();
}
return $reste;
}
public function getetatAvancementForOperation()
{
$etatAvancement = 0;
if($this->getTotalQuantiteForParcelle()){
$etatAvancement = intval($this->getTotalQuantiteForVente() * 100 / $this->getTotalQuantiteForParcelle());
}
return $etatAvancement?:0;
}
/**
* @return Collection<int, TblDetailCharge>
*/
public function getDetailCharge(): Collection
{
return $this->detailCharge;
}
public function addDetailCharge(TblDetailCharge $detailCharge): self
{
if (!$this->detailCharge->contains($detailCharge)) {
$this->detailCharge[] = $detailCharge;
$detailCharge->setTblOperationVente($this);
}
return $this;
}
public function removeDetailCharge(TblDetailCharge $detailCharge): self
{
if ($this->detailCharge->removeElement($detailCharge)) {
// set the owning side to null (unless already changed)
if ($detailCharge->getTblOperationVente() === $this) {
$detailCharge->setTblOperationVente(null);
}
}
return $this;
}
/**
* @return Collection<int, TblDetailProduitVente>
*/
public function getDetailProduitVente(): Collection
{
return $this->detailProduitVente;
}
public function addDetailProduitVente(TblDetailProduitVente $detailProduitVente): self
{
if (!$this->detailProduitVente->contains($detailProduitVente)) {
$this->detailProduitVente[] = $detailProduitVente;
$detailProduitVente->setTblOperationVente($this);
}
return $this;
}
public function removeDetailProduitVente(TblDetailProduitVente $detailProduitVente): self
{
if ($this->detailProduitVente->removeElement($detailProduitVente)) {
// set the owning side to null (unless already changed)
if ($detailProduitVente->getTblOperationVente() === $this) {
$detailProduitVente->setTblOperationVente(null);
}
}
return $this;
}
/**
* @return Collection<int, TblDetailQuantiteParcelle>
*/
public function getDetailQuantiteParcelle(): Collection
{
return $this->detailQuantiteParcelle;
}
public function addDetailQuantiteParcelle(TblDetailQuantiteParcelle $detailQuantiteParcelle): self
{
if (!$this->detailQuantiteParcelle->contains($detailQuantiteParcelle)) {
$this->detailQuantiteParcelle[] = $detailQuantiteParcelle;
$detailQuantiteParcelle->setTblOperationVente($this);
}
return $this;
}
public function removeDetailQuantiteParcelle(TblDetailQuantiteParcelle $detailQuantiteParcelle): self
{
if ($this->detailQuantiteParcelle->removeElement($detailQuantiteParcelle)) {
// set the owning side to null (unless already changed)
if ($detailQuantiteParcelle->getTblOperationVente() === $this) {
$detailQuantiteParcelle->setTblOperationVente(null);
}
}
return $this;
}
public function getVendeur(): ?User
{
return $this->vendeur;
}
public function setVendeur(?User $vendeur): self
{
$this->vendeur = $vendeur;
return $this;
}
public function getDestination(): ?RefVille
{
return $this->destination;
}
public function setDestination(?RefVille $destination): self
{
$this->destination = $destination;
return $this;
}
/**
* @return Collection<int, RefMoyenTransport>
*/
public function getMoyenTransports(): Collection
{
return $this->moyenTransports;
}
public function addMoyenTransport(RefMoyenTransport $moyenTransport): self
{
if (!$this->moyenTransports->contains($moyenTransport)) {
$this->moyenTransports[] = $moyenTransport;
}
return $this;
}
public function removeMoyenTransport(RefMoyenTransport $moyenTransport): self
{
if ($this->moyenTransports->removeElement($moyenTransport)) {
}
return $this;
}
/**
* @return Collection<int, TblFile>
*/
public function getFiles(): Collection
{
return $this->files;
}
public function addFile(TblFile $file): self
{
if (!$this->files->contains($file)) {
$this->files[] = $file;
}
return $this;
}
public function removeFile(TblFile $file): self
{
$this->files->removeElement($file);
return $this;
}
public function getMatricule(): ?string
{
return $this->matricule;
}
public function setMatricule(?string $matricule): self
{
$this->matricule = $matricule;
return $this;
}
}