src/Flexy/ShopBundle/Entity/Shipping/CashBox.php line 16
<?phpnamespace App\Flexy\ShopBundle\Entity\Shipping;use ApiPlatform\Metadata\ApiResource;use App\Flexy\ShopBundle\Entity\Payment\Transaction;use App\Flexy\ShopBundle\Entity\Store\Store;use App\Flexy\ShopBundle\Repository\Shipping\CashBoxRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: CashBoxRepository::class)]#[ApiResource]class CashBox{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]private ?int $id = null;#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]private ?\DateTimeInterface $createdAt = null;#[ORM\ManyToOne(inversedBy: 'cashBoxes')]private ?Store $store = null;#[ORM\Column(type: Types::DATETIME_MUTABLE)]private ?\DateTimeInterface $startAt = null;#[ORM\Column(type: Types::DATETIME_MUTABLE)]private ?\DateTimeInterface $endAt = null;#[ORM\OneToMany(mappedBy: 'cashBox', targetEntity: CashOnDelivery::class)]private Collection $cashOnDeliveries;#[ORM\OneToMany(mappedBy: 'cashBox', targetEntity: ShipmentCollectMoney::class)]private Collection $shipmentCollectMoney;#[ORM\OneToMany(mappedBy: 'cashBox', targetEntity: ShipmentPaper::class)]private Collection $shipmentPapers;#[ORM\OneToMany(mappedBy: 'cashBox', targetEntity: Transaction::class)]private Collection $transactions;#[ORM\Column(nullable: true)]private ?float $balanceLeft = null;#[ORM\Column(nullable: true)]private ?bool $isValid = null;public function __construct(){$this->cashOnDeliveries = new ArrayCollection();$this->shipmentCollectMoney = new ArrayCollection();$this->shipmentPapers = new ArrayCollection();$this->transactions = new ArrayCollection();$this->balanceLeft = 0;}public function __toString(){return $this->store." : ".$this->startAt->format("Y-m-d");}public function getId(): ?int{return $this->id;}public function getCreatedAt(): ?\DateTimeInterface{return $this->createdAt;}public function setCreatedAt(?\DateTimeInterface $createdAt): self{$this->createdAt = $createdAt;return $this;}public function getStore(): ?Store{return $this->store;}public function setStore(?Store $store): self{$this->store = $store;return $this;}public function getStartAt(): ?\DateTimeInterface{return $this->startAt;}public function setStartAt(\DateTimeInterface $startAt): self{$this->startAt = $startAt;return $this;}public function getEndAt(): ?\DateTimeInterface{return $this->endAt;}public function setEndAt(\DateTimeInterface $endAt): self{$this->endAt = $endAt;return $this;}public function getShipmentCollectMoneyCash(){$amount = 0;foreach($this->getShipmentCollectMoney() as $singlePayment){if($singlePayment->getPaymentMethod() == "cash" and $singlePayment->getCollectedAt() ) {$amount = $amount + $singlePayment->getAmount();}}return $amount;}public function getShipmentCollectMoneyCheck(){$amount = 0;foreach($this->getShipmentCollectMoney() as $singlePayment){if($singlePayment->getPaymentMethod() == "check" and $singlePayment->getCollectedAt() ) {$amount = $amount + $singlePayment->getAmount();}}return $amount;}public function getCODCash(){$amountCOD = 0;foreach($this->getCashOnDeliveries() as $singleCOD){if($singleCOD->getPaymentMethod() == "cash" and $singleCOD->getCollectedAt() ) {$amountCOD = $amountCOD + $singleCOD->getAmount();}}return $amountCOD;}public function getCODCheck(){$amountCOD = 0;foreach($this->getCashOnDeliveries() as $singleCOD){if($singleCOD->getPaymentMethod() == "check" and $singleCOD->getCollectedAt() ) {$amountCOD = $amountCOD + $singleCOD->getAmount();}}return $amountCOD;}public function getCODBill(){$amountCOD = 0;foreach($this->getCashOnDeliveries() as $singleCOD){if($singleCOD->getPaymentMethod() == "bill" and $singleCOD->getCollectedAt() ) {$amountCOD = $amountCOD + $singleCOD->getAmount();}}return $amountCOD;}public function getShipmentPapersInvoice(){$shipmentPapers = [];foreach($this->getShipmentPapers() as $singleShipmentPaper){if($singleShipmentPaper->getType() == "invoice" and $singleShipmentPaper->getCollectedAt() ) {$shipmentPapers[] = $singleShipmentPaper;}}return $shipmentPapers;}public function getShipmentPapersDeliveryReceipt(){$shipmentPapers = [];foreach($this->getShipmentPapers() as $singleShipmentPaper){if($singleShipmentPaper->getType() == "delivery-receipt" and $singleShipmentPaper->getCollectedAt() ) {$shipmentPapers[] = $singleShipmentPaper;}}return $shipmentPapers;}public function getValidatedTransactionsTransitAmount(){$amount = 0;foreach($this->getTransactions() as $transaction){if($transaction->getPurpose() == "transit" and $transaction->getValidatedAt() ) {$amount = $amount + $transaction->getAmount();}}return $amount;}public function getValidatedTransactionsCODAmount(){$amount = 0;foreach($this->getTransactions() as $transaction){if($transaction->getPurpose() == "cod-cash" and $transaction->getValidatedAt() ) {$amount = $amount + $transaction->getAmount();}}return $amount;}/*** @return Collection<int, CashOnDelivery>*/public function getCashOnDeliveries(): Collection{return $this->cashOnDeliveries;}public function addCashOnDelivery(CashOnDelivery $cashOnDelivery): self{if (!$this->cashOnDeliveries->contains($cashOnDelivery)) {$this->cashOnDeliveries->add($cashOnDelivery);$cashOnDelivery->setCashBox($this);}return $this;}public function removeCashOnDelivery(CashOnDelivery $cashOnDelivery): self{if ($this->cashOnDeliveries->removeElement($cashOnDelivery)) {// set the owning side to null (unless already changed)if ($cashOnDelivery->getCashBox() === $this) {$cashOnDelivery->setCashBox(null);}}return $this;}/*** @return Collection<int, ShipmentCollectMoney>*/public function getShipmentCollectMoney(): Collection{return $this->shipmentCollectMoney;}public function addShipmentCollectMoney(ShipmentCollectMoney $shipmentCollectMoney): self{if (!$this->shipmentCollectMoney->contains($shipmentCollectMoney)) {$this->shipmentCollectMoney->add($shipmentCollectMoney);$shipmentCollectMoney->setCashBox($this);}return $this;}public function removeShipmentCollectMoney(ShipmentCollectMoney $shipmentCollectMoney): self{if ($this->shipmentCollectMoney->removeElement($shipmentCollectMoney)) {// set the owning side to null (unless already changed)if ($shipmentCollectMoney->getCashBox() === $this) {$shipmentCollectMoney->setCashBox(null);}}return $this;}/*** @return Collection<int, ShipmentPaper>*/public function getShipmentPapers(): Collection{return $this->shipmentPapers;}public function addShipmentPaper(ShipmentPaper $shipmentPaper): self{if (!$this->shipmentPapers->contains($shipmentPaper)) {$this->shipmentPapers->add($shipmentPaper);$shipmentPaper->setCashBox($this);}return $this;}public function removeShipmentPaper(ShipmentPaper $shipmentPaper): self{if ($this->shipmentPapers->removeElement($shipmentPaper)) {// set the owning side to null (unless already changed)if ($shipmentPaper->getCashBox() === $this) {$shipmentPaper->setCashBox(null);}}return $this;}/*** @return Collection<int, Transaction>*/public function getTransactions(): Collection{return $this->transactions;}public function addTransaction(Transaction $transaction): self{if (!$this->transactions->contains($transaction)) {$this->transactions->add($transaction);$transaction->setCashBox($this);}return $this;}public function removeTransaction(Transaction $transaction): self{if ($this->transactions->removeElement($transaction)) {// set the owning side to null (unless already changed)if ($transaction->getCashBox() === $this) {$transaction->setCashBox(null);}}return $this;}public function getBalanceLeft(): ?float{return $this->balanceLeft;}public function setBalanceLeft(?float $balanceLeft): self{$this->balanceLeft = $balanceLeft;return $this;}public function isIsValid(): ?bool{return $this->isValid;}public function setIsValid(?bool $isValid): self{$this->isValid = $isValid;return $this;}}