<?php
namespace App\Entity;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use App\Repository\AccountingStudentRegistrationPaymentRepository;
/**
* @ORM\Entity(repositoryClass=AccountingStudentRegistrationPaymentRepository::class)
*/
class AccountingStudentRegistrationPayment
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Establishment::class, inversedBy="accountingStudentRegistrationPayments")
* @ORM\JoinColumn(nullable=false)
*/
private $establishment;
/**
* @ORM\ManyToOne(targetEntity=RegistrationStudentRegistration::class, inversedBy="accountingStudentRegistrationPayments")
* @ORM\JoinColumn(nullable=false)
*/
private $studentRegistration;
/**
* @ORM\ManyToOne(targetEntity=TreasuryCashRegister::class, inversedBy="accountingStudentRegistrationPayments")
* @ORM\JoinColumn(nullable=false)
*/
private $cashRegister;
/**
* @ORM\Column(type="string", length=255)
*/
private $code;
/**
* @ORM\Column(type="string", length=60, nullable=true)
*/
private $method;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $memo;
/**
* @ORM\Column(type="float")
*/
private $amount;
/**
* @ORM\Column(type="date_immutable")
*/
private $create_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=AccountingStudentRegistrationFeeShedulPayment::class, mappedBy="studentRegistrationPayment")
*/
private $accountingStudentRegistrationFeeShedulPayments;
/**
* @ORM\ManyToOne(targetEntity=SchoolYear::class, inversedBy="accountingStudentRegistrationPayments")
* @ORM\JoinColumn(nullable=false)
*/
private $schoolYear;
public function __construct()
{
$this->accountingStudentRegistrationFeeShedulPayments = new ArrayCollection();
$this->create_at = new DateTimeImmutable();
}
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 getCashRegister(): ?TreasuryCashRegister
{
return $this->cashRegister;
}
public function setCashRegister(?TreasuryCashRegister $cashRegister): self
{
$this->cashRegister = $cashRegister;
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->setStudentRegistrationPayment($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->getStudentRegistrationPayment() === $this) {
$accountingStudentRegistrationFeeShedulPayment->setStudentRegistrationPayment(null);
}
}
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
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 getAmount(): ?float
{
return $this->amount;
}
public function setAmount(float $amount): self
{
$this->amount = $amount;
return $this;
}
public function getSchoolYear(): ?SchoolYear
{
return $this->schoolYear;
}
public function setSchoolYear(?SchoolYear $schoolYear): self
{
$this->schoolYear = $schoolYear;
return $this;
}
public function getCreateAt(): ?\DateTimeImmutable
{
return $this->create_at;
}
public function setCreateAt(\DateTimeImmutable $create_at): self
{
$this->create_at = $create_at;
return $this;
}
public function getMethod(): ?string
{
return $this->method;
}
public function setMethod(?string $method): self
{
$this->method = $method;
return $this;
}
public function getMemo(): ?string
{
return $this->memo;
}
public function setMemo(?string $memo): self
{
$this->memo = $memo;
return $this;
}
public function getShedulAmount(){
$amount = 0;
foreach ($this->getAccountingStudentRegistrationFeeShedulPayments() as $key => $payment) {
$amount = $amount + $payment->getAmount();
}
return $amount;
}
public function isLastOfThisStudent(){
return $this->getId() == $this->getStudentRegistration()->getLastPaymentId();
}
public function isCanBeShow(){
return $this->getShedulAmount() < $this->getAmount();
}
public function isCanBePrint(){
return $this->getShedulAmount() == $this->getAmount() && $this->isLastOfThisStudent();
}
public function isPrintable(){
return $this->getShedulAmount() == $this->getAmount();
}
public function isCanBeSaftlyRemove(){
return $this->getShedulAmount() == 0 || $this->isLastOfThisStudent();
}
public function getUsername(UserRepository $userRepository){
return $userRepository->findOneBy(['id' => $this->created_by], []) ? $userRepository->findOneBy(['id' => $this->created_by], [])->getUserIdentifier() : null;
}
public function isFee(AccountingStudentRegistrationFee $accountingStudentRegistrationFee){
foreach ($this->getAccountingStudentRegistrationFeeShedulPayments() as $key => $accountingStudentRegistrationFeeShedulPayment) {
if ($accountingStudentRegistrationFeeShedulPayment->getStudentRegistrationFee() == $accountingStudentRegistrationFee) {
return true;
}
}
return false;
}
public function getFeeproviders(){
$feeProviders = new ArrayCollection();
foreach ($this->getAccountingStudentRegistrationFeeShedulPayments() as $key => $accountingStudentRegistrationFeeShedulPayment) {
foreach ($accountingStudentRegistrationFeeShedulPayment->getStudentRegistrationFee()->getFee()->getSettingFeeProviderDistributions() as $key => $settingFeeProviderDistribution) {
if (!$feeProviders->contains($settingFeeProviderDistribution->getSettingFeeProvider())) {
$feeProviders->add($settingFeeProviderDistribution->getSettingFeeProvider());
}
}
}
return $feeProviders;
}
public function getFeeEts(){
$count = 0;
foreach ($this->getAccountingStudentRegistrationFeeShedulPayments() as $key => $accountingStudentRegistrationFeeShedulPayment) {
if (0 <= count($accountingStudentRegistrationFeeShedulPayment->getStudentRegistrationFee()->getFee()->getSettingFeeProviderDistributions())) {
$count += 1;
}
}
return $count;
}
}