src/Flexy/ShopBundle/Entity/Order/CashBoxOrder.php line 17
<?php
namespace App\Flexy\ShopBundle\Entity\Order;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\Flexy\ShopBundle\Entity\Order\CashBoxOrderRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use \App\Flexy\ShopBundle\Entity\Order\Order;
use \App\Flexy\ShopBundle\Entity\Store\Store;
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
#[ORM\Entity(repositoryClass: CashBoxOrderRepository::class)]
#[ApiResource]
class CashBoxOrder
{
use SoftDeleteableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\OneToMany(mappedBy: 'cashBoxOrder', targetEntity: Order::class,cascade:["persist"],orphanRemoval:true)]
private Collection $orders;
#[ORM\ManyToOne(inversedBy: 'cashBoxOrders')]
private ?Store $store = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $startAt = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $endAt = null;
public function __construct()
{
$this->orders = new ArrayCollection();
}
public function __toString()
{
return $this->startAt->format("Y-m-d")." - ".$this->endAt->format("Y-m-d");
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders->add($order);
$order->setCashBoxOrder($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getCashBoxOrder() === $this) {
$order->setCashBoxOrder(null);
}
}
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 getPaymentMethodsTotal(){
$listPayments = [];
foreach($this->getOrders() as $singleOrder){
if($singleOrder->getStatus() != "canceled" and $singleOrder->getStatus() != null and $singleOrder->getReference() != null){
foreach($singleOrder->getPayments() as $singlePayment){
if(array_key_exists($singlePayment->getPaymentMethod()->getName(),$listPayments)){
$oldValue = $listPayments[$singlePayment->getPaymentMethod()->getName()];
$listPayments[$singlePayment->getPaymentMethod()->getName()] = $oldValue + $singlePayment->getAmount() ;
}else{
$listPayments[$singlePayment->getPaymentMethod()->getName()] = $singlePayment->getAmount();
}
}
}
}
return $listPayments;
}
}