<?php
namespace App\Entity;
use App\Attributes\ClassNameConverter;
use DateTimeInterface;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[ORM\Entity(repositoryClass: 'App\Repository\CotisationRepository')]
#[Gedmo\Loggable]
#[ClassNameConverter(name: 'Cotisation')]
#[Vich\Uploadable]
class Cotisation extends EntityStatus implements TimestampableInterface
{
use TimestampableTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[Gedmo\Versioned]
#[ORM\Column(type: 'string', nullable: true)]
private ?string $anneeCotisation = null;
#[Gedmo\Versioned]
#[ORM\Column(type: 'string', nullable: true)]
private ?string $montantCotisation = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $commentaire = null;
#[Gedmo\Versioned]
#[ORM\Column(type: 'date', nullable: true)]
private ?DateTimeInterface $datePaiement = null;
#[Gedmo\Versioned]
#[ORM\ManyToOne(targetEntity: 'App\Entity\CotisationStatut', inversedBy: 'cotisations')]
private ?CotisationStatut $cotisationStatut = null;
#[Gedmo\Versioned]
#[ORM\ManyToOne(targetEntity: 'App\Entity\Entreprise', inversedBy: 'cotisations')]
private ?Entreprise $entreprise = null;
#[Gedmo\Versioned]
#[ORM\ManyToOne(targetEntity: 'App\Entity\TypeOffre', inversedBy: 'cotisations')]
private ?TypeOffre $typeOffre = null;
#[Gedmo\Versioned]
#[ORM\Column(nullable: true)]
private ?float $revenue = null;
#[ORM\ManyToOne]
private ?ParamCotisation $cotisationType = null;
#[ORM\Column(nullable: true)]
private ?int $year = null;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $revenueDate = null;
#[ORM\Column]
private ?bool $optionImportExport = false;
#[ORM\Column]
private ?bool $optionMapa = false;
#[ORM\Column(nullable: true)]
private ?float $priceHt = null;
#[ORM\Column(nullable: true)]
private ?float $priceVat = null;
#[ORM\Column(nullable: true)]
private ?float $priceTtc = null;
#[ORM\Column(nullable: true)]
private ?int $internalLicence = null;
#[ORM\Column(nullable: true)]
private ?int $communityLicence = null;
#[ORM\OneToOne(inversedBy: 'cotisation', cascade: ['persist', 'remove'])]
private ?Order $associetedOrder = null;
#[ORM\Column(nullable: true)]
private ?float $priceDepartmentPart = null;
#[ORM\Column(nullable: true)]
private ?float $priceNationalPart = null;
#[ORM\Column(nullable: true)]
private ?float $priceNationalPartCalculated = null;
#[ORM\Column(nullable: true)]
private ?float $priceOptionImportExport = null;
#[ORM\Column(nullable: true)]
private ?float $priceOptionMapa = null;
#[Vich\UploadableField(mapping: 'cotisations_ca', fileNameProperty: 'document', originalName: 'originalDocumentName')]
private ?File $documentFile = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $document = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $originalDocumentName = null;
#[Vich\UploadableField(mapping: 'cotisations_payment', fileNameProperty: 'proofOfPayment', originalName: 'originalProofOfPaymentName')]
private ?File $proofOfPaymentFile = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $proofOfPayment = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $originalProofOfPaymentName = null;
#[ORM\Column(nullable: true)]
private ?int $youngMemberYearNumber = null;
public function getId(): ?int
{
return $this->id;
}
public function getCommentaire(): ?string
{
return $this->commentaire;
}
public function setCommentaire(?string $commentaire): self
{
$this->commentaire = $commentaire;
return $this;
}
public function getAnneeCotisation(): ?string
{
return $this->anneeCotisation;
}
public function setAnneeCotisation(?string $anneeCotisation): self
{
$this->anneeCotisation = $anneeCotisation;
return $this;
}
public function getMontantCotisation(): ?string
{
return $this->montantCotisation;
}
public function setMontantCotisation(?string $montantCotisation): self
{
$this->montantCotisation = $montantCotisation;
return $this;
}
public function getDatePaiement(): ?DateTimeInterface
{
return $this->datePaiement;
}
public function setDatePaiement(?DateTimeInterface $datePaiement): self
{
$this->datePaiement = $datePaiement;
return $this;
}
public function getCotisationStatut(): ?CotisationStatut
{
return $this->cotisationStatut;
}
public function setCotisationStatut(?CotisationStatut $cotisationStatut): self
{
$this->cotisationStatut = $cotisationStatut;
return $this;
}
public function getEntreprise(): ?Entreprise
{
return $this->entreprise;
}
public function setEntreprise(?Entreprise $entreprise): self
{
$this->entreprise = $entreprise;
return $this;
}
public function getTypeOffre(): ?TypeOffre
{
return $this->typeOffre;
}
public function setTypeOffre(?TypeOffre $typeOffre): self
{
$this->typeOffre = $typeOffre;
return $this;
}
public function getRevenue(): ?float
{
return $this->revenue;
}
public function setRevenue(?float $revenue): self
{
$this->revenue = $revenue;
return $this;
}
public function getCotisationType(): ?ParamCotisation
{
return $this->cotisationType;
}
public function setCotisationType(?ParamCotisation $cotisationType): self
{
$this->cotisationType = $cotisationType;
return $this;
}
public function getYear(): ?int
{
return $this->year;
}
public function setYear(?int $year): self
{
$this->year = $year;
return $this;
}
public function getRevenueDate(): ?\DateTimeInterface
{
return $this->revenueDate;
}
public function setRevenueDate(?\DateTimeInterface $revenueDate): self
{
$this->revenueDate = $revenueDate;
return $this;
}
public function isOptionImportExport(): ?bool
{
return $this->optionImportExport;
}
public function setOptionImportExport(bool $optionImportExport): self
{
$this->optionImportExport = $optionImportExport;
return $this;
}
public function isOptionMapa(): ?bool
{
return $this->optionMapa;
}
public function setOptionMapa(bool $optionMapa): self
{
$this->optionMapa = $optionMapa;
return $this;
}
public function getPriceHt(): ?float
{
$assocOrder = $this->getAssocietedOrder();
if($assocOrder && !$this->isReduced() && $assocOrder->getTotalAmount()){
$total = 0;
foreach($assocOrder->getOrderLines() as $line){
if($line->getProduct()?->getTag() === 'mapa_part') continue;
$total += $line->getTotalPrice();
}
return $total;
}
return $this->priceHt;
}
public function setPriceHt(?float $priceHt): self
{
$this->priceHt = $priceHt;
return $this;
}
public function getPriceVat(): ?float
{
return $this->getPriceHt() / 100 * 20;
}
public function setPriceVat(?float $priceVat): self
{
$this->priceVat = $priceVat;
return $this;
}
public function getPriceTtc(): ?float
{
if ($this->optionMapa) {
return $this->getPriceHt() + $this->getPriceVat() + $this->getPriceOptionMapa();
}
return $this->getPriceHt() + $this->getPriceVat();
}
public function setPriceTtc(?float $priceTtc): self
{
$this->priceTtc = $priceTtc;
return $this;
}
public function getInternalLicence(): ?int
{
return $this->internalLicence;
}
public function setInternalLicence(?int $internalLicence): self
{
$this->internalLicence = $internalLicence;
return $this;
}
public function getCommunityLicence(): ?int
{
return $this->communityLicence;
}
public function setCommunityLicence(?int $communityLicence): self
{
$this->communityLicence = $communityLicence;
return $this;
}
public function getAssocietedOrder(): ?Order
{
return $this->associetedOrder;
}
public function setAssocietedOrder(?Order $associetedOrder): self
{
$this->associetedOrder = $associetedOrder;
return $this;
}
public function getPriceDepartmentPart(): ?float
{
return $this->priceDepartmentPart;
}
public function setPriceDepartmentPart(?float $priceDepartmentPart): self
{
$this->priceDepartmentPart = $priceDepartmentPart;
return $this;
}
public function getPriceNationalPart(): ?float
{
return $this->priceNationalPart;
}
public function setPriceNationalPart(?float $priceNationalPart): self
{
$this->priceNationalPart = $priceNationalPart;
return $this;
}
public function getPriceNationalPartCalculated(): ?float
{
return $this->priceNationalPartCalculated;
}
public function setPriceNationalPartCalculated(?float $priceNationalPartCalculated): self
{
$this->priceNationalPartCalculated = $priceNationalPartCalculated;
return $this;
}
public function getPriceOptionImportExport(): ?float
{
return $this->priceOptionImportExport;
}
public function setPriceOptionImportExport(?float $priceOptionImportExport): self
{
$this->priceOptionImportExport = $priceOptionImportExport;
return $this;
}
public function getPriceOptionMapa(): ?float
{
return $this->priceOptionMapa;
}
public function setPriceOptionMapa(?float $priceOptionMapa): self
{
$this->priceOptionMapa = $priceOptionMapa;
return $this;
}
public function getDocument(): ?string
{
return $this->document;
}
public function setDocument(?string $document): self
{
$this->document = $document;
return $this;
}
public function setDocumentFile(?File $documentFile = null): void
{
$this->documentFile = $documentFile;
if (null !== $documentFile) {
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getDocumentFile(): ?File
{
return $this->documentFile;
}
public function getOriginalDocumentName(): ?string
{
return $this->originalDocumentName;
}
public function setOriginalDocumentName(?string $originalDocumentName): self
{
$this->originalDocumentName = $originalDocumentName;
return $this;
}
public function setProofOfPaymentFile(?File $proofOfPaymentFile = null): void
{
$this->proofOfPaymentFile = $proofOfPaymentFile;
if (null !== $proofOfPaymentFile) {
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getProofOfPaymentFile(): ?File
{
return $this->proofOfPaymentFile;
}
public function getProofOfPayment(): ?string
{
return $this->proofOfPayment;
}
public function setProofOfPayment(?string $proofOfPayment): self
{
$this->proofOfPayment = $proofOfPayment;
return $this;
}
public function getOriginalProofOfPaymentName(): ?string
{
return $this->originalProofOfPaymentName;
}
public function setOriginalProofOfPaymentName(?string $originalProofOfPaymentName): self
{
$this->originalProofOfPaymentName = $originalProofOfPaymentName;
return $this;
}
public function getYoungMemberYearNumber(): ?int
{
return $this->youngMemberYearNumber;
}
public function setYoungMemberYearNumber(?int $youngMemberYearNumber): self
{
$this->youngMemberYearNumber = $youngMemberYearNumber;
return $this;
}
public function isReduced(): ?bool
{
return $this->getCotisationType()?->getTag() === 'integral' && $this->getPriceNationalPartCalculated() > $this->getPriceNationalPart();
}
}