<?php
namespace App\Entity;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use App\Repository\AccountingStudentRegistrationFeeRepository;
/**
* @ORM\Entity(repositoryClass=AccountingStudentRegistrationFeeRepository::class)
* Frais d'inscription
*/
class AccountingStudentRegistrationFee
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Establishment::class, inversedBy="accountingStudentRegistrationFees")
* @ORM\JoinColumn(nullable=false)
*/
private $establishment;
/**
* @ORM\ManyToOne(targetEntity=RegistrationStudentRegistration::class, inversedBy="accountingStudentRegistrationFees")
* @ORM\JoinColumn(nullable=false)
*/
private $studentRegistration;
/**
* @ORM\ManyToOne(targetEntity=SettingFee::class, inversedBy="accountingStudentRegistrationFees")
* @ORM\JoinColumn(nullable=false)
*/
private $fee;
/**
* @ORM\Column(type="string", length=60)
*/
private $code;
/**
* @ORM\Column(type="string", length=128)
*/
private $label;
/**
* @ORM\Column(type="float")
*/
private $amount;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $last_amount_paid;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $last_payment_id;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private $last_payment_at;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $created_at;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $updated_at;
/**
* @ORM\Column(type="integer")
*/
private $created_by;
/**
* @ORM\Column(type="integer")
*/
private $updated_by;
/**
* @ORM\OneToMany(targetEntity=AccountingStudentRegistrationFeeShedul::class, mappedBy="studentRegistrationFee")
* @ORM\OrderBy({"date_due" = "ASC"})
*/
private $accountingStudentRegistrationFeeSheduls;
/**
* @ORM\OneToMany(targetEntity=AccountingStudentRegistrationFeeShedulPayment::class, mappedBy="studentRegistrationFee")
*/
private $accountingStudentRegistrationFeeShedulPayments;
/**
* @ORM\OneToMany(targetEntity=RegistrationStudentDowngradeLine::class, mappedBy="accountingStudentRegistrationFee")
*/
private $registrationStudentDowngradeLines;
/**
* @ORM\OneToMany(targetEntity=RegistrationStudentAbandonmentLine::class, mappedBy="accountingStudentRegistrationFee")
*/
private $registrationStudentAbandonmentLines;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $amount_cancel;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $amount_reported;
/**
* @ORM\Column(type="boolean")
*/
private $is_reported;
/**
* @ORM\Column(type="boolean")
*/
private $is_cancel;
/**
* @ORM\OneToMany(targetEntity=AccountingCredit::class, mappedBy="feeToDelete")
*/
private $accountingCredits;
/**
* @ORM\Column(type="boolean")
*/
private $is_archived;
/**
* @ORM\Column(type="string", length=60, nullable=true)
*/
private $duration;
/**
* @ORM\Column(type="date_immutable", nullable=true)
*/
private $start_at;
/**
* @ORM\Column(type="date_immutable", nullable=true)
*/
private $end_at;
/**
* @ORM\OneToMany(targetEntity=StockKitOut::class, mappedBy="accountingStudentRegistrationFee")
*/
private $stockKitOuts;
public function __construct()
{
$this->accountingStudentRegistrationFeeSheduls = new ArrayCollection();
$this->accountingStudentRegistrationFeeShedulPayments = new ArrayCollection();
$this->registrationStudentDowngradeLines = new ArrayCollection();
$this->registrationStudentAbandonmentLines = new ArrayCollection();
$this->amount_cancel = 0;
$this->is_cancel = false;
$this->is_archived = false;
$this->is_reported = false;
$this->accountingCredits = new ArrayCollection();
$this->stockKitOuts = new ArrayCollection();
}
public function __toString()
{
return $this->label;
}
public function getId(): ?int
{
return $this->id;
}
public function getEstablishment(): ?Establishment
{
return $this->establishment;
}
public function setEstablishment(?Establishment $establishment): self
{
$this->establishment = $establishment;
return $this;
}
public function getStudentRegistration(): ?RegistrationStudentRegistration
{
return $this->studentRegistration;
}
public function setStudentRegistration(?RegistrationStudentRegistration $studentRegistration): self
{
$this->studentRegistration = $studentRegistration;
return $this;
}
public function getFee(): ?SettingFee
{
return $this->fee;
}
public function setFee(?SettingFee $fee): self
{
$this->fee = $fee;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getAmount(): ?float
{
/* if ($this->amount <= 0) {
return $this->getAmountRest() + $this->getAmountPaid();
} */
return $this->amount;
}
public function setAmount(float $amount): self
{
$this->amount = $amount;
return $this;
}
/**
* @return Collection|AccountingStudentRegistrationFeeShedul[]
*/
public function getAccountingStudentRegistrationFeeSheduls(): Collection
{
return $this->accountingStudentRegistrationFeeSheduls;
}
public function addAccountingStudentRegistrationFeeShedul(AccountingStudentRegistrationFeeShedul $accountingStudentRegistrationFeeShedul): self
{
if (!$this->accountingStudentRegistrationFeeSheduls->contains($accountingStudentRegistrationFeeShedul)) {
$this->accountingStudentRegistrationFeeSheduls[] = $accountingStudentRegistrationFeeShedul;
$accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($this);
}
return $this;
}
public function removeAccountingStudentRegistrationFeeShedul(AccountingStudentRegistrationFeeShedul $accountingStudentRegistrationFeeShedul): self
{
if ($this->accountingStudentRegistrationFeeSheduls->removeElement($accountingStudentRegistrationFeeShedul)) {
// set the owning side to null (unless already changed)
if ($accountingStudentRegistrationFeeShedul->getStudentRegistrationFee() === $this) {
$accountingStudentRegistrationFeeShedul->setStudentRegistrationFee(null);
}
}
return $this;
}
/**
* @return Collection|AccountingStudentRegistrationFeeShedulPayment[]
*/
public function getAccountingStudentRegistrationFeeShedulPayments(): Collection
{
return $this->accountingStudentRegistrationFeeShedulPayments;
}
public function addAccountingStudentRegistrationFeeShedulPayment(AccountingStudentRegistrationFeeShedulPayment $accountingStudentRegistrationFeeShedulPayment): self
{
if (!$this->accountingStudentRegistrationFeeShedulPayments->contains($accountingStudentRegistrationFeeShedulPayment)) {
$this->accountingStudentRegistrationFeeShedulPayments[] = $accountingStudentRegistrationFeeShedulPayment;
$accountingStudentRegistrationFeeShedulPayment->setStudentRegistrationFee($this);
}
return $this;
}
public function removeAccountingStudentRegistrationFeeShedulPayment(AccountingStudentRegistrationFeeShedulPayment $accountingStudentRegistrationFeeShedulPayment): self
{
if ($this->accountingStudentRegistrationFeeShedulPayments->removeElement($accountingStudentRegistrationFeeShedulPayment)) {
// set the owning side to null (unless already changed)
if ($accountingStudentRegistrationFeeShedulPayment->getStudentRegistrationFee() === $this) {
$accountingStudentRegistrationFeeShedulPayment->setStudentRegistrationFee(null);
}
}
return $this;
}
public function getAmountPaid(): ?float
{
$amount_paid = 0;
foreach ($this->getAccountingStudentRegistrationFeeShedulPayments() as $key => $value) {
if (!$value->getStudentRegistrationFee()->getIsArchived()) {
$amount_paid = $amount_paid + $value->getAmount();
}
}
return $amount_paid;
}
public function getAmountRest(): ?float
{
$amountRest = 0;
foreach ($this->getAccountingStudentRegistrationFeeSheduls() as $key => $accountingStudentRegistrationFeeShedul) {
//if (!$this->getIsArchived()) {
$amountRest = $amountRest + $accountingStudentRegistrationFeeShedul->getAmountRest();
//}
}
return $amountRest;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updated_at;
}
public function setUpdatedAt(\DateTimeImmutable $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
public function getCreatedBy(): ?int
{
return $this->created_by;
}
public function setCreatedBy(int $created_by): self
{
$this->created_by = $created_by;
return $this;
}
public function getUpdatedBy(): ?int
{
return $this->updated_by;
}
public function setUpdatedBy(int $updated_by): self
{
$this->updated_by = $updated_by;
return $this;
}
public function getDueDate(){
$due_date = null;
foreach ($this->getAccountingStudentRegistrationFeeSheduls() as $key => $shedul) {
if ($shedul->getAmountRest() > 0) {
$due_date = $shedul->getDateDue();
break;
}
}
return $due_date;
}
public function getDueAmount(){
$amount = 0;
foreach ($this->getAccountingStudentRegistrationFeeSheduls() as $key => $shedul) {
if ($shedul->getAmountRest() > 0) {
$amount = $amount + $shedul->getAmountRest();
break;
}
}
return $amount;
}
public function getLastAmountPaid(): ?float
{
return $this->last_amount_paid;
}
public function setLastAmountPaid(?float $last_amount_paid): self
{
$this->last_amount_paid = $last_amount_paid;
return $this;
}
public function getLastPaymentId(): ?int
{
return $this->last_payment_id;
}
public function setLastPaymentId(?int $last_payment_id): self
{
$this->last_payment_id = $last_payment_id;
return $this;
}
public function getLastPaymentAt(): ?\DateTimeImmutable
{
return $this->last_payment_at;
}
public function setLastPaymentAt(\DateTimeImmutable $last_payment_at): self
{
$this->last_payment_at = $last_payment_at;
return $this;
}
/**
* @return Collection|RegistrationStudentDowngradeLine[]
*/
public function getRegistrationStudentDowngradeLines(): Collection
{
return $this->registrationStudentDowngradeLines;
}
public function addRegistrationStudentDowngradeLine(RegistrationStudentDowngradeLine $registrationStudentDowngradeLine): self
{
if (!$this->registrationStudentDowngradeLines->contains($registrationStudentDowngradeLine)) {
$this->registrationStudentDowngradeLines[] = $registrationStudentDowngradeLine;
$registrationStudentDowngradeLine->setAccountingStudentRegistrationFee($this);
}
return $this;
}
public function removeRegistrationStudentDowngradeLine(RegistrationStudentDowngradeLine $registrationStudentDowngradeLine): self
{
if ($this->registrationStudentDowngradeLines->removeElement($registrationStudentDowngradeLine)) {
// set the owning side to null (unless already changed)
if ($registrationStudentDowngradeLine->getAccountingStudentRegistrationFee() === $this) {
$registrationStudentDowngradeLine->setAccountingStudentRegistrationFee(null);
}
}
return $this;
}
/**
* @return Collection|RegistrationStudentAbandonmentLine[]
*/
public function getRegistrationStudentAbandonmentLines(): Collection
{
return $this->registrationStudentAbandonmentLines;
}
public function addRegistrationStudentAbandonmentLine(RegistrationStudentAbandonmentLine $registrationStudentAbandonmentLine): self
{
if (!$this->registrationStudentAbandonmentLines->contains($registrationStudentAbandonmentLine)) {
$this->registrationStudentAbandonmentLines[] = $registrationStudentAbandonmentLine;
$registrationStudentAbandonmentLine->setAccountingStudentRegistrationFee($this);
}
return $this;
}
public function removeRegistrationStudentAbandonmentLine(RegistrationStudentAbandonmentLine $registrationStudentAbandonmentLine): self
{
if ($this->registrationStudentAbandonmentLines->removeElement($registrationStudentAbandonmentLine)) {
// set the owning side to null (unless already changed)
if ($registrationStudentAbandonmentLine->getAccountingStudentRegistrationFee() === $this) {
$registrationStudentAbandonmentLine->setAccountingStudentRegistrationFee(null);
}
}
return $this;
}
public function getAmountCancel(): ?float
{
$amountCancel = 0;
foreach ($this->getAccountingStudentRegistrationFeeSheduls() as $key => $accountingStudentRegistrationFeeShedul) {
$amountCancel = $amountCancel + $accountingStudentRegistrationFeeShedul->getAmountCancel();
}
return $amountCancel;
}
public function setAmountCancel(?float $amount_cancel): self
{
$this->amount_cancel = $amount_cancel;
return $this;
}
public function getIsCancel(): ?bool
{
return $this->is_cancel;
}
public function setIsCancel(bool $is_cancel): self
{
$this->is_cancel = $is_cancel;
return $this;
}
public function getSheduledAmount(){
$amount = 0;
foreach ($this->getAccountingStudentRegistrationFeeSheduls() as $key => $shedul) {
$amount = $amount + $shedul->getAmount();
}
return $amount;
}
/**
* @return Collection|AccountingCredit[]
*/
public function getAccountingCredits(): Collection
{
return $this->accountingCredits;
}
public function addAccountingCredit(AccountingCredit $accountingCredit): self
{
if (!$this->accountingCredits->contains($accountingCredit)) {
$this->accountingCredits[] = $accountingCredit;
$accountingCredit->setFeeToDelete($this);
}
return $this;
}
public function removeAccountingCredit(AccountingCredit $accountingCredit): self
{
if ($this->accountingCredits->removeElement($accountingCredit)) {
// set the owning side to null (unless already changed)
if ($accountingCredit->getFeeToDelete() === $this) {
$accountingCredit->setFeeToDelete(null);
}
}
return $this;
}
public function getIsArchived(): ?bool
{
return $this->is_archived;
}
public function setIsArchived(bool $is_archived): self
{
$this->is_archived = $is_archived;
return $this;
}
public function getDuration(): ?string
{
return $this->duration;
}
public function setDuration(?string $duration): self
{
$this->duration = $duration;
return $this;
}
public function getStartAt(): ?\DateTimeImmutable
{
return $this->start_at;
}
public function setStartAt(?\DateTimeImmutable $start_at): self
{
$this->start_at = $start_at;
return $this;
}
public function getEndAt(): ?\DateTimeImmutable
{
return $this->end_at;
}
public function setEndAt(?\DateTimeImmutable $end_at): self
{
$this->end_at = $end_at;
return $this;
}
public function getAmountDueAt(DateTimeImmutable $dueDate, $amountMax = 0){
$amountDue = 0;
foreach ($this->getAccountingStudentRegistrationFeeSheduls() as $key => $accountingStudentRegistrationFeeShedul) {
if ($accountingStudentRegistrationFeeShedul->getDateDue() <= $dueDate && $accountingStudentRegistrationFeeShedul->getAmountRest() > 0) {
$amountDue = $amountDue + $accountingStudentRegistrationFeeShedul->getAmountRest();
}
}
return $amountDue;
}
public function getAmountReported(): ?float
{
return $this->amount_reported;
}
public function setAmountReported(?float $amount_reported): self
{
$this->amount_reported = $amount_reported;
return $this;
}
public function getIsReported(): ?bool
{
return $this->is_reported;
}
public function setIsReported(bool $is_reported): self
{
$this->is_reported = $is_reported;
return $this;
}
/**
* @return Collection|StockKitOut[]
*/
public function getStockKitOuts(): Collection
{
return $this->stockKitOuts;
}
public function addStockKitOut(StockKitOut $stockKitOut): self
{
if (!$this->stockKitOuts->contains($stockKitOut)) {
$this->stockKitOuts[] = $stockKitOut;
$stockKitOut->setAccountingStudentRegistrationFee($this);
}
return $this;
}
public function removeStockKitOut(StockKitOut $stockKitOut): self
{
if ($this->stockKitOuts->removeElement($stockKitOut)) {
// set the owning side to null (unless already changed)
if ($stockKitOut->getAccountingStudentRegistrationFee() === $this) {
$stockKitOut->setAccountingStudentRegistrationFee(null);
}
}
return $this;
}
}