src/Entity/TreasuryCashRegister.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TreasuryCashRegisterRepository;
  4. use DateTimeImmutable;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. /**
  10.  * @ORM\Entity(repositoryClass=TreasuryCashRegisterRepository::class)
  11.  * Cette entite represente le releves (caisse journaliere)
  12.  * @UniqueEntity(fields={"code"}, message="Cet élt existe déjà")
  13.  */
  14. class TreasuryCashRegister
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\ManyToOne(targetEntity=Establishment::class, inversedBy="treasuryCashRegisters")
  24.      * @ORM\JoinColumn(nullable=false)
  25.      */
  26.     private $establishment;
  27.     /**
  28.      * @ORM\ManyToOne(targetEntity=TreasuryCheckout::class, inversedBy="treasuryCashRegisters")
  29.      * @ORM\JoinColumn(nullable=false)
  30.      */
  31.     private $checkout;
  32.     /**
  33.      * @ORM\Column(type="string", length=60, unique=true)
  34.      */
  35.     private $code;
  36.     /**
  37.      * @ORM\Column(type="boolean")
  38.      */
  39.     private $is_closed;
  40.     /**
  41.      * @ORM\Column(type="date_immutable")
  42.     */
  43.     private $create_at;
  44.     /**
  45.      * @ORM\Column(type="datetime_immutable")
  46.     */
  47.     private $created_at;
  48.     /**
  49.      * @ORM\Column(type="datetime_immutable")
  50.      */
  51.     private $updated_at;
  52.     /**
  53.      * @ORM\Column(type="integer")
  54.      */
  55.     private $created_by;
  56.     /**
  57.      * @ORM\Column(type="integer")
  58.      */
  59.     private $updated_by;
  60.     /**
  61.      * @ORM\OneToMany(targetEntity=TreasuryCashMovement::class, mappedBy="cashRegister")
  62.      */
  63.     private $treasuryCashMovements;
  64.     /**
  65.      * @ORM\OneToMany(targetEntity=AccountingStudentRegistrationFeeShedulPayment::class, mappedBy="cashRegister")
  66.      */
  67.     private $accountingStudentRegistrationFeeShedulPayments;
  68.     /**
  69.      * @ORM\OneToMany(targetEntity=AccountingExpense::class, mappedBy="cashRegister")
  70.      */
  71.     private $accountingExpenses;
  72.     /**
  73.      * @ORM\OneToMany(targetEntity=AccountingStudentRegistrationPayment::class, mappedBy="cashRegister")
  74.      * @ORM\OrderBy({"id" = "DESC"})
  75.      */
  76.     private $accountingStudentRegistrationPayments;
  77.     /**
  78.      * @ORM\ManyToOne(targetEntity=SchoolYear::class, inversedBy="treasuryCashRegisters")
  79.      * @ORM\JoinColumn(nullable=false)
  80.      */
  81.     private $schoolYear;
  82.     /**
  83.      * @ORM\OneToMany(targetEntity=TreasuryPayment::class, mappedBy="cashRegister")
  84.      */
  85.     private $treasuryPayments;
  86.     /**
  87.      * @ORM\OneToMany(targetEntity=AccountingCreditLine::class, mappedBy="payment_cash_register")
  88.      */
  89.     private $accountingCreditLines;
  90.     /**
  91.      * @ORM\Column(type="boolean")
  92.      */
  93.     private $is_founder_valedated;
  94.     /**
  95.      * @ORM\Column(type="boolean")
  96.      */
  97.     private $is_founder_rejected;
  98.     public function __construct()
  99.     {
  100.         $this->treasuryCashMovements = new ArrayCollection();
  101.         $this->accountingStudentRegistrationFeeShedulPayments = new ArrayCollection();
  102.         $this->accountingExpenses = new ArrayCollection();
  103.         $this->accountingStudentRegistrationPayments = new ArrayCollection();
  104.         $this->create_at = new DateTimeImmutable();
  105.         $this->is_closed false;
  106.         $this->is_founder_valedated false;
  107.         $this->is_founder_rejected false;
  108.         $this->treasuryPayments = new ArrayCollection();
  109.         $this->accountingCreditLines = new ArrayCollection();
  110.     }
  111.     public function __toString()
  112.     {
  113.         return $this->code;
  114.     }
  115.     public function getId(): ?int
  116.     {
  117.         return $this->id;
  118.     }
  119.     public function getEstablishment(): ?Establishment
  120.     {
  121.         return $this->establishment;
  122.     }
  123.     public function setEstablishment(?Establishment $establishment): self
  124.     {
  125.         $this->establishment $establishment;
  126.         return $this;
  127.     }
  128.     public function getCheckout(): ?TreasuryCheckout
  129.     {
  130.         return $this->checkout;
  131.     }
  132.     public function setCheckout(?TreasuryCheckout $checkout): self
  133.     {
  134.         $this->checkout $checkout;
  135.         return $this;
  136.     }
  137.     /**
  138.      * @return Collection|TreasuryCashMovement[]
  139.      */
  140.     public function getTreasuryCashMovements(): Collection
  141.     {
  142.         return $this->treasuryCashMovements;
  143.     }
  144.     public function addTreasuryCashMovement(TreasuryCashMovement $treasuryCashMovement): self
  145.     {
  146.         if (!$this->treasuryCashMovements->contains($treasuryCashMovement)) {
  147.             $this->treasuryCashMovements[] = $treasuryCashMovement;
  148.             $treasuryCashMovement->setCashRegister($this);
  149.         }
  150.         return $this;
  151.     }
  152.     public function removeTreasuryCashMovement(TreasuryCashMovement $treasuryCashMovement): self
  153.     {
  154.         if ($this->treasuryCashMovements->removeElement($treasuryCashMovement)) {
  155.             // set the owning side to null (unless already changed)
  156.             if ($treasuryCashMovement->getCashRegister() === $this) {
  157.                 $treasuryCashMovement->setCashRegister(null);
  158.             }
  159.         }
  160.         return $this;
  161.     }
  162.     /**
  163.      * @return Collection|AccountingStudentRegistrationFeeShedulPayment[]
  164.      */
  165.     public function getAccountingStudentRegistrationFeeShedulPayments(): Collection
  166.     {
  167.         return $this->accountingStudentRegistrationFeeShedulPayments;
  168.     }
  169.     public function addAccountingStudentRegistrationFeeShedulPayment(AccountingStudentRegistrationFeeShedulPayment $accountingStudentRegistrationFeeShedulPayment): self
  170.     {
  171.         if (!$this->accountingStudentRegistrationFeeShedulPayments->contains($accountingStudentRegistrationFeeShedulPayment)) {
  172.             $this->accountingStudentRegistrationFeeShedulPayments[] = $accountingStudentRegistrationFeeShedulPayment;
  173.             $accountingStudentRegistrationFeeShedulPayment->setCashRegister($this);
  174.         }
  175.         return $this;
  176.     }
  177.     public function removeAccountingStudentRegistrationFeeShedulPayment(AccountingStudentRegistrationFeeShedulPayment $accountingStudentRegistrationFeeShedulPayment): self
  178.     {
  179.         if ($this->accountingStudentRegistrationFeeShedulPayments->removeElement($accountingStudentRegistrationFeeShedulPayment)) {
  180.             // set the owning side to null (unless already changed)
  181.             if ($accountingStudentRegistrationFeeShedulPayment->getCashRegister() === $this) {
  182.                 $accountingStudentRegistrationFeeShedulPayment->setCashRegister(null);
  183.             }
  184.         }
  185.         return $this;
  186.     }
  187.     public function getCode(): ?string
  188.     {
  189.         return $this->code;
  190.     }
  191.     public function setCode(string $code): self
  192.     {
  193.         $this->code $code;
  194.         return $this;
  195.     }
  196.     public function getCreatedAt(): ?\DateTimeImmutable
  197.     {
  198.         return $this->created_at;
  199.     }
  200.     public function setCreatedAt(\DateTimeImmutable $created_at): self
  201.     {
  202.         $this->created_at $created_at;
  203.         return $this;
  204.     }
  205.     public function getUpdatedAt(): ?\DateTimeImmutable
  206.     {
  207.         return $this->updated_at;
  208.     }
  209.     public function setUpdatedAt(\DateTimeImmutable $updated_at): self
  210.     {
  211.         $this->updated_at $updated_at;
  212.         return $this;
  213.     }
  214.     public function getCreatedBy(): ?int
  215.     {
  216.         return $this->created_by;
  217.     }
  218.     public function setCreatedBy(int $created_by): self
  219.     {
  220.         $this->created_by $created_by;
  221.         return $this;
  222.     }
  223.     public function getUpdatedBy(): ?int
  224.     {
  225.         return $this->updated_by;
  226.     }
  227.     public function setUpdatedBy(int $updated_by): self
  228.     {
  229.         $this->updated_by $updated_by;
  230.         return $this;
  231.     }
  232.     /**
  233.      * @return Collection|AccountingExpense[]
  234.      */
  235.     public function getAccountingExpenses(): Collection
  236.     {
  237.         return $this->accountingExpenses;
  238.     }
  239.     public function addAccountingExpense(AccountingExpense $accountingExpense): self
  240.     {
  241.         if (!$this->accountingExpenses->contains($accountingExpense)) {
  242.             $this->accountingExpenses[] = $accountingExpense;
  243.             $accountingExpense->setCashRegister($this);
  244.         }
  245.         return $this;
  246.     }
  247.     public function removeAccountingExpense(AccountingExpense $accountingExpense): self
  248.     {
  249.         if ($this->accountingExpenses->removeElement($accountingExpense)) {
  250.             // set the owning side to null (unless already changed)
  251.             if ($accountingExpense->getCashRegister() === $this) {
  252.                 $accountingExpense->setCashRegister(null);
  253.             }
  254.         }
  255.         return $this;
  256.     }
  257.     /**
  258.      * @return Collection|AccountingStudentRegistrationPayment[]
  259.      */
  260.     public function getAccountingStudentRegistrationPayments(): Collection
  261.     {
  262.         return $this->accountingStudentRegistrationPayments;
  263.     }
  264.     public function addAccountingStudentRegistrationPayment(AccountingStudentRegistrationPayment $accountingStudentRegistrationPayment): self
  265.     {
  266.         if (!$this->accountingStudentRegistrationPayments->contains($accountingStudentRegistrationPayment)) {
  267.             $this->accountingStudentRegistrationPayments[] = $accountingStudentRegistrationPayment;
  268.             $accountingStudentRegistrationPayment->setCashRegister($this);
  269.         }
  270.         return $this;
  271.     }
  272.     public function removeAccountingStudentRegistrationPayment(AccountingStudentRegistrationPayment $accountingStudentRegistrationPayment): self
  273.     {
  274.         if ($this->accountingStudentRegistrationPayments->removeElement($accountingStudentRegistrationPayment)) {
  275.             // set the owning side to null (unless already changed)
  276.             if ($accountingStudentRegistrationPayment->getCashRegister() === $this) {
  277.                 $accountingStudentRegistrationPayment->setCashRegister(null);
  278.             }
  279.         }
  280.         return $this;
  281.     }
  282.     public function getCreateAt(): ?\DateTimeImmutable
  283.     {
  284.         return $this->create_at;
  285.     }
  286.     public function setCreateAt(\DateTimeImmutable $create_at): self
  287.     {
  288.         $this->create_at $create_at;
  289.         return $this;
  290.     }
  291.     public function getCashedIn(){
  292.         $cashedIn 0;
  293.         foreach ($this->getAccountingStudentRegistrationPayments() as $key => $payment) {
  294.             $cashedIn $cashedIn $payment->getAmount();
  295.         }
  296.         return $cashedIn;
  297.     }
  298.     public function getSpent(){
  299.         $spent 0;
  300.         foreach ($this->getAccountingExpenses() as $key => $expense) {
  301.             if ($expense->getIsPaid()) {
  302.                 $spent $spent $expense->getAmount();
  303.             }
  304.         }
  305.         return $spent;
  306.     }
  307.     public function getPaid(){
  308.         $paid 0;
  309.         foreach ($this->getTreasuryPayments() as $key => $treasuryPayment) {
  310.             if ($this->getIsFounderValedated() &&  !$treasuryPayment->getIsFounderRejected()) {
  311.                 $paid $paid $treasuryPayment->getAmount();
  312.             }
  313.         }
  314.         return $paid;
  315.     }
  316.     public function getAllPaid(){
  317.         $paid 0;
  318.         foreach ($this->getTreasuryPayments() as $key => $treasuryPayment) {
  319.             //if ($this->getIsFounderValedated()) {
  320.                 $paid $paid $treasuryPayment->getAmount();
  321.             //}
  322.         }
  323.         return $paid;
  324.     }
  325.     public function getAprovedPayment(){
  326.         $paid 0;
  327.         foreach ($this->getTreasuryPayments() as $key => $treasuryPayment) {
  328.             if ($treasuryPayment->getIsFounderValedated()) {
  329.                 $paid $paid $treasuryPayment->getAmount();
  330.             }
  331.         }
  332.         return $paid;
  333.     }
  334.     public function getNotAprovedPayment(){
  335.         $paid 0;
  336.         foreach ($this->getTreasuryPayments() as $key => $treasuryPayment) {
  337.             if (!$treasuryPayment->getIsFounderValedated()) {
  338.                 $paid $paid $treasuryPayment->getAmount();
  339.             }
  340.         }
  341.         return $paid;
  342.     }
  343.     public function toForward(TreasuryCashRegisterRepository $treasuryCashRegisterRepository){
  344.         return ($this->getCashedIn() + $this->getPostponed($treasuryCashRegisterRepository)) - ($this->getSpent() + $this->getPaid());
  345.     }
  346.     public function getPostPoned(TreasuryCashRegisterRepository $treasuryCashRegisterRepository){
  347.         $amount 0;
  348.         $treasuryCashRegisters $treasuryCashRegisterRepository->createQueryBuilder('entity')
  349.         ->andWhere('entity.create_at < :endAt')
  350.         ->setParameter('endAt'$this->getCreateAt())
  351.         ->andWhere('entity.checkout = :checkout')
  352.         ->setParameter('checkout'$this->getCheckout())
  353.         ->orderBy('entity.id''ASC')
  354.         ->getQuery()
  355.         ->getResult();
  356.         $cashedIn 0;
  357.         $spent 0;
  358.         $paid 0;
  359.         foreach ($treasuryCashRegisters as $key => $treasuryCashRegister) {
  360.             $paid $paid $treasuryCashRegister->getPaid();
  361.             $spent $spent $treasuryCashRegister->getSpent();
  362.             $cashedIn $cashedIn $treasuryCashRegister->getCashedIn();
  363.         }
  364.         $amount $cashedIn - ($spent $paid);
  365.         return $amount;
  366.     }
  367.     public function getSchoolYear(): ?SchoolYear
  368.     {
  369.         return $this->schoolYear;
  370.     }
  371.     public function setSchoolYear(?SchoolYear $schoolYear): self
  372.     {
  373.         $this->schoolYear $schoolYear;
  374.         return $this;
  375.     }
  376.     public function getIsClosed(): ?bool
  377.     {
  378.         return $this->is_closed;
  379.     }
  380.     public function setIsClosed(bool $is_closed): self
  381.     {
  382.         $this->is_closed $is_closed;
  383.         return $this;
  384.     }
  385.     /**
  386.      * @return Collection|TreasuryPayment[]
  387.      */
  388.     public function getTreasuryPayments(): Collection
  389.     {
  390.         return $this->treasuryPayments;
  391.     }
  392.     public function addTreasuryPayment(TreasuryPayment $treasuryPayment): self
  393.     {
  394.         if (!$this->treasuryPayments->contains($treasuryPayment)) {
  395.             $this->treasuryPayments[] = $treasuryPayment;
  396.             $treasuryPayment->setCashRegister($this);
  397.         }
  398.         return $this;
  399.     }
  400.     public function removeTreasuryPayment(TreasuryPayment $treasuryPayment): self
  401.     {
  402.         if ($this->treasuryPayments->removeElement($treasuryPayment)) {
  403.             // set the owning side to null (unless already changed)
  404.             if ($treasuryPayment->getCashRegister() === $this) {
  405.                 $treasuryPayment->setCashRegister(null);
  406.             }
  407.         }
  408.         return $this;
  409.     }
  410.     /**
  411.      * @return Collection|AccountingCreditLine[]
  412.      */
  413.     public function getAccountingCreditLines(): Collection
  414.     {
  415.         return $this->accountingCreditLines;
  416.     }
  417.     public function addAccountingCreditLine(AccountingCreditLine $accountingCreditLine): self
  418.     {
  419.         if (!$this->accountingCreditLines->contains($accountingCreditLine)) {
  420.             $this->accountingCreditLines[] = $accountingCreditLine;
  421.             $accountingCreditLine->setPaymentCashRegister($this);
  422.         }
  423.         return $this;
  424.     }
  425.     public function removeAccountingCreditLine(AccountingCreditLine $accountingCreditLine): self
  426.     {
  427.         if ($this->accountingCreditLines->removeElement($accountingCreditLine)) {
  428.             // set the owning side to null (unless already changed)
  429.             if ($accountingCreditLine->getPaymentCashRegister() === $this) {
  430.                 $accountingCreditLine->setPaymentCashRegister(null);
  431.             }
  432.         }
  433.         return $this;
  434.     }
  435.     public function getIsFounderValedated(): ?bool
  436.     {
  437.         return $this->is_founder_valedated;
  438.     }
  439.     public function setIsFounderValedated(bool $is_founder_valedated): self
  440.     {
  441.         $this->is_founder_valedated $is_founder_valedated;
  442.         return $this;
  443.     }
  444.     public function getIsFounderRejected(): ?bool
  445.     {
  446.         return $this->is_founder_rejected;
  447.     }
  448.     public function setIsFounderRejected(bool $is_founder_rejected): self
  449.     {
  450.         $this->is_founder_rejected $is_founder_rejected;
  451.         return $this;
  452.     }
  453. }