src/Flexy/ShopBundle/Entity/Order/CashBoxOrder.php line 17

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Order;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\Flexy\ShopBundle\Entity\Order\CashBoxOrderRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use \App\Flexy\ShopBundle\Entity\Order\Order;
  10. use \App\Flexy\ShopBundle\Entity\Store\Store;
  11. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
  12. #[ORM\Entity(repositoryClassCashBoxOrderRepository::class)]
  13. #[ApiResource]
  14. class CashBoxOrder
  15. {
  16.     use SoftDeleteableEntity;
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column]
  20.     private ?int $id null;
  21.     #[ORM\OneToMany(mappedBy'cashBoxOrder'targetEntityOrder::class,cascade:["persist"],orphanRemoval:true)]
  22.     private Collection $orders;
  23.     #[ORM\ManyToOne(inversedBy'cashBoxOrders')]
  24.     private ?Store $store null;
  25.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  26.     private ?\DateTimeInterface $startAt null;
  27.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  28.     private ?\DateTimeInterface $endAt null;
  29.     public function __construct()
  30.     {
  31.         $this->orders = new ArrayCollection();
  32.     }
  33.     public function __toString()
  34.     {
  35.         return $this->startAt->format("Y-m-d")." - ".$this->endAt->format("Y-m-d");
  36.     }
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     /**
  42.      * @return Collection<int, Order>
  43.      */
  44.     public function getOrders(): Collection
  45.     {
  46.         return $this->orders;
  47.     }
  48.     public function addOrder(Order $order): self
  49.     {
  50.         if (!$this->orders->contains($order)) {
  51.             $this->orders->add($order);
  52.             $order->setCashBoxOrder($this);
  53.         }
  54.         return $this;
  55.     }
  56.     public function removeOrder(Order $order): self
  57.     {
  58.         if ($this->orders->removeElement($order)) {
  59.             // set the owning side to null (unless already changed)
  60.             if ($order->getCashBoxOrder() === $this) {
  61.                 $order->setCashBoxOrder(null);
  62.             }
  63.         }
  64.         return $this;
  65.     }
  66.     public function getStore(): ?Store
  67.     {
  68.         return $this->store;
  69.     }
  70.     public function setStore(?Store $store): self
  71.     {
  72.         $this->store $store;
  73.         return $this;
  74.     }
  75.     public function getStartAt(): ?\DateTimeInterface
  76.     {
  77.         return $this->startAt;
  78.     }
  79.     public function setStartAt(?\DateTimeInterface $startAt): self
  80.     {
  81.         $this->startAt $startAt;
  82.         return $this;
  83.     }
  84.     public function getEndAt(): ?\DateTimeInterface
  85.     {
  86.         return $this->endAt;
  87.     }
  88.     public function setEndAt(?\DateTimeInterface $endAt): self
  89.     {
  90.         $this->endAt $endAt;
  91.         return $this;
  92.     }
  93.     public function getPaymentMethodsTotal(){
  94.         $listPayments = [];
  95.         
  96.         foreach($this->getOrders() as $singleOrder){
  97.             if($singleOrder->getStatus() != "canceled" and $singleOrder->getStatus() != null and $singleOrder->getReference() != null){
  98.                 foreach($singleOrder->getPayments() as $singlePayment){
  99.                     if(array_key_exists($singlePayment->getPaymentMethod()->getName(),$listPayments)){
  100.                         $oldValue $listPayments[$singlePayment->getPaymentMethod()->getName()];
  101.                         $listPayments[$singlePayment->getPaymentMethod()->getName()] = $oldValue $singlePayment->getAmount() ;
  102.                     }else{
  103.                         $listPayments[$singlePayment->getPaymentMethod()->getName()] = $singlePayment->getAmount();
  104.                     }
  105.                 }
  106.             }
  107.             
  108.         }
  109.         return $listPayments;
  110.     }
  111. }