src/Flexy/ShopBundle/Entity/Shipping/CashBox.php line 16

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Shipping;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Payment\Transaction;
  5. use App\Flexy\ShopBundle\Entity\Store\Store;
  6. use App\Flexy\ShopBundle\Repository\Shipping\CashBoxRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. #[ORM\Entity(repositoryClassCashBoxRepository::class)]
  12. #[ApiResource]
  13. class CashBox
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id null;
  19.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  20.     private ?\DateTimeInterface $createdAt null;
  21.    
  22.     #[ORM\ManyToOne(inversedBy'cashBoxes')]
  23.     private ?Store $store null;
  24.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  25.     private ?\DateTimeInterface $startAt null;
  26.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  27.     private ?\DateTimeInterface $endAt null;
  28.     #[ORM\OneToMany(mappedBy'cashBox'targetEntityCashOnDelivery::class)]
  29.     private Collection $cashOnDeliveries;
  30.     #[ORM\OneToMany(mappedBy'cashBox'targetEntityShipmentCollectMoney::class)]
  31.     private Collection $shipmentCollectMoney;
  32.     #[ORM\OneToMany(mappedBy'cashBox'targetEntityShipmentPaper::class)]
  33.     private Collection $shipmentPapers;
  34.     #[ORM\OneToMany(mappedBy'cashBox'targetEntityTransaction::class)]
  35.     private Collection $transactions;
  36.     #[ORM\Column(nullabletrue)]
  37.     private ?float $balanceLeft null;
  38.     #[ORM\Column(nullabletrue)]
  39.     private ?bool $isValid null;
  40.     public function __construct()
  41.     {
  42.        
  43.         $this->cashOnDeliveries = new ArrayCollection();
  44.         $this->shipmentCollectMoney = new ArrayCollection();
  45.         $this->shipmentPapers = new ArrayCollection();
  46.         $this->transactions = new ArrayCollection();
  47.         $this->balanceLeft 0;
  48.     }
  49.     public function __toString()
  50.     {
  51.         return $this->store." : ".$this->startAt->format("Y-m-d");
  52.     }
  53.     public function getId(): ?int
  54.     {
  55.         return $this->id;
  56.     }
  57.     public function getCreatedAt(): ?\DateTimeInterface
  58.     {
  59.         return $this->createdAt;
  60.     }
  61.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  62.     {
  63.         $this->createdAt $createdAt;
  64.         return $this;
  65.     }
  66.    
  67.     public function getStore(): ?Store
  68.     {
  69.         return $this->store;
  70.     }
  71.     public function setStore(?Store $store): self
  72.     {
  73.         $this->store $store;
  74.         return $this;
  75.     }
  76.     public function getStartAt(): ?\DateTimeInterface
  77.     {
  78.         return $this->startAt;
  79.     }
  80.     public function setStartAt(\DateTimeInterface $startAt): self
  81.     {
  82.         $this->startAt $startAt;
  83.         return $this;
  84.     }
  85.     public function getEndAt(): ?\DateTimeInterface
  86.     {
  87.         return $this->endAt;
  88.     }
  89.     public function setEndAt(\DateTimeInterface $endAt): self
  90.     {
  91.         $this->endAt $endAt;
  92.         return $this;
  93.     }
  94.     
  95.     public function getShipmentCollectMoneyCash(){
  96.         $amount 0;
  97.         foreach($this->getShipmentCollectMoney() as $singlePayment){
  98.             if($singlePayment->getPaymentMethod() == "cash" and $singlePayment->getCollectedAt() )  {
  99.                 $amount $amount $singlePayment->getAmount();
  100.             }
  101.                 
  102.             
  103.             
  104.         }
  105.         return $amount;
  106.     }
  107.     public function getShipmentCollectMoneyCheck(){
  108.         $amount 0;
  109.         foreach($this->getShipmentCollectMoney() as $singlePayment){
  110.             if($singlePayment->getPaymentMethod() == "check" and $singlePayment->getCollectedAt() )  {
  111.                 $amount $amount $singlePayment->getAmount();
  112.             }
  113.                 
  114.             
  115.             
  116.         }
  117.         return $amount;
  118.     }
  119.     public function getCODCash(){
  120.         $amountCOD 0;
  121.         foreach($this->getCashOnDeliveries() as $singleCOD){
  122.                 if($singleCOD->getPaymentMethod() == "cash" and $singleCOD->getCollectedAt() )  {
  123.                     $amountCOD $amountCOD $singleCOD->getAmount();
  124.                 }
  125.                 
  126.                 
  127.             
  128.         }
  129.         return $amountCOD;
  130.     }
  131.     public function getCODCheck(){
  132.         $amountCOD 0;
  133.         foreach($this->getCashOnDeliveries() as $singleCOD){
  134.                 if($singleCOD->getPaymentMethod() == "check" and $singleCOD->getCollectedAt() )  {
  135.                     $amountCOD $amountCOD $singleCOD->getAmount();
  136.                 }
  137.                 
  138.                 
  139.             
  140.         }
  141.         return $amountCOD;
  142.     }
  143.     public function getCODBill(){
  144.         $amountCOD 0;
  145.         foreach($this->getCashOnDeliveries() as $singleCOD){
  146.                 if($singleCOD->getPaymentMethod() == "bill" and $singleCOD->getCollectedAt() )  {
  147.                     $amountCOD $amountCOD $singleCOD->getAmount();
  148.                 }
  149.                 
  150.                 
  151.             
  152.         }
  153.         return $amountCOD;
  154.     }
  155.     public function getShipmentPapersInvoice(){
  156.         $shipmentPapers = [];
  157.         foreach($this->getShipmentPapers() as $singleShipmentPaper){
  158.                 if($singleShipmentPaper->getType() == "invoice" and $singleShipmentPaper->getCollectedAt() )  {
  159.                     $shipmentPapers[] = $singleShipmentPaper;
  160.                 }
  161.                 
  162.                 
  163.             
  164.         }
  165.         return $shipmentPapers;
  166.     }
  167.     public function getShipmentPapersDeliveryReceipt(){
  168.         $shipmentPapers = [];
  169.         foreach($this->getShipmentPapers() as $singleShipmentPaper){
  170.                 if($singleShipmentPaper->getType() == "delivery-receipt" and $singleShipmentPaper->getCollectedAt() )  {
  171.                     $shipmentPapers[] = $singleShipmentPaper;
  172.                 }
  173.                 
  174.                 
  175.             
  176.         }
  177.         return $shipmentPapers;
  178.     }
  179.     public function getValidatedTransactionsTransitAmount(){
  180.         $amount 0;
  181.         foreach($this->getTransactions() as $transaction){
  182.                 if($transaction->getPurpose() == "transit" and $transaction->getValidatedAt() )  {
  183.                     $amount $amount +  $transaction->getAmount();
  184.                 }
  185.                 
  186.                 
  187.             
  188.         }
  189.         return $amount;
  190.     }
  191.     public function getValidatedTransactionsCODAmount(){
  192.         $amount 0;
  193.         foreach($this->getTransactions() as $transaction){
  194.                 if($transaction->getPurpose() == "cod-cash" and $transaction->getValidatedAt() )  {
  195.                     $amount $amount +  $transaction->getAmount();
  196.                 }
  197.                 
  198.                 
  199.             
  200.         }
  201.         return $amount;
  202.     }
  203.     /**
  204.      * @return Collection<int, CashOnDelivery>
  205.      */
  206.     public function getCashOnDeliveries(): Collection
  207.     {
  208.         return $this->cashOnDeliveries;
  209.     }
  210.     public function addCashOnDelivery(CashOnDelivery $cashOnDelivery): self
  211.     {
  212.         if (!$this->cashOnDeliveries->contains($cashOnDelivery)) {
  213.             $this->cashOnDeliveries->add($cashOnDelivery);
  214.             $cashOnDelivery->setCashBox($this);
  215.         }
  216.         return $this;
  217.     }
  218.     public function removeCashOnDelivery(CashOnDelivery $cashOnDelivery): self
  219.     {
  220.         if ($this->cashOnDeliveries->removeElement($cashOnDelivery)) {
  221.             // set the owning side to null (unless already changed)
  222.             if ($cashOnDelivery->getCashBox() === $this) {
  223.                 $cashOnDelivery->setCashBox(null);
  224.             }
  225.         }
  226.         return $this;
  227.     }
  228.     /**
  229.      * @return Collection<int, ShipmentCollectMoney>
  230.      */
  231.     public function getShipmentCollectMoney(): Collection
  232.     {
  233.         return $this->shipmentCollectMoney;
  234.     }
  235.     public function addShipmentCollectMoney(ShipmentCollectMoney $shipmentCollectMoney): self
  236.     {
  237.         if (!$this->shipmentCollectMoney->contains($shipmentCollectMoney)) {
  238.             $this->shipmentCollectMoney->add($shipmentCollectMoney);
  239.             $shipmentCollectMoney->setCashBox($this);
  240.         }
  241.         return $this;
  242.     }
  243.     public function removeShipmentCollectMoney(ShipmentCollectMoney $shipmentCollectMoney): self
  244.     {
  245.         if ($this->shipmentCollectMoney->removeElement($shipmentCollectMoney)) {
  246.             // set the owning side to null (unless already changed)
  247.             if ($shipmentCollectMoney->getCashBox() === $this) {
  248.                 $shipmentCollectMoney->setCashBox(null);
  249.             }
  250.         }
  251.         return $this;
  252.     }
  253.     /**
  254.      * @return Collection<int, ShipmentPaper>
  255.      */
  256.     public function getShipmentPapers(): Collection
  257.     {
  258.         return $this->shipmentPapers;
  259.     }
  260.     public function addShipmentPaper(ShipmentPaper $shipmentPaper): self
  261.     {
  262.         if (!$this->shipmentPapers->contains($shipmentPaper)) {
  263.             $this->shipmentPapers->add($shipmentPaper);
  264.             $shipmentPaper->setCashBox($this);
  265.         }
  266.         return $this;
  267.     }
  268.     public function removeShipmentPaper(ShipmentPaper $shipmentPaper): self
  269.     {
  270.         if ($this->shipmentPapers->removeElement($shipmentPaper)) {
  271.             // set the owning side to null (unless already changed)
  272.             if ($shipmentPaper->getCashBox() === $this) {
  273.                 $shipmentPaper->setCashBox(null);
  274.             }
  275.         }
  276.         return $this;
  277.     }
  278.     /**
  279.      * @return Collection<int, Transaction>
  280.      */
  281.     public function getTransactions(): Collection
  282.     {
  283.         return $this->transactions;
  284.     }
  285.     public function addTransaction(Transaction $transaction): self
  286.     {
  287.         if (!$this->transactions->contains($transaction)) {
  288.             $this->transactions->add($transaction);
  289.             $transaction->setCashBox($this);
  290.         }
  291.         return $this;
  292.     }
  293.     public function removeTransaction(Transaction $transaction): self
  294.     {
  295.         if ($this->transactions->removeElement($transaction)) {
  296.             // set the owning side to null (unless already changed)
  297.             if ($transaction->getCashBox() === $this) {
  298.                 $transaction->setCashBox(null);
  299.             }
  300.         }
  301.         return $this;
  302.     }
  303.     public function getBalanceLeft(): ?float
  304.     {
  305.         return $this->balanceLeft;
  306.     }
  307.     public function setBalanceLeft(?float $balanceLeft): self
  308.     {
  309.         $this->balanceLeft $balanceLeft;
  310.         return $this;
  311.     }
  312.     public function isIsValid(): ?bool
  313.     {
  314.         return $this->isValid;
  315.     }
  316.     public function setIsValid(?bool $isValid): self
  317.     {
  318.         $this->isValid $isValid;
  319.         return $this;
  320.     }
  321. }