src/Flexy/ShopBundle/Entity/Accounting/Invoice.php line 32

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Accounting;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use App\Flexy\ShopBundle\Entity\Customer\Customer;
  8. use App\Flexy\ShopBundle\Entity\Customer\CustomerWalletPoint;
  9. use App\Flexy\ShopBundle\Entity\Order\Order;
  10. use App\Flexy\ShopBundle\Entity\Payment\PaymentMethod;
  11. use App\Repository\Flexy\ShopBundle\Entity\Accounting\InvoiceRepository;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\DBAL\Types\Types;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Gedmo\Mapping\Annotation as Gedmo;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. #[ORM\Entity(repositoryClassInvoiceRepository::class)]
  20. #[ApiResource(
  21.     normalizationContext: ['groups' => ['read','readPackEngagements']],
  22.     denormalizationContext: ['groups' => ['write']],
  23. )]
  24. #[ApiFilter(SearchFilter::class, properties: ['customer.id' => 'exact'])]
  25. class Invoice
  26. {
  27.     #[ORM\Id]
  28.     #[ORM\GeneratedValue]
  29.     #[ORM\Column]
  30.     #[Groups(["read","write"])]
  31.     private ?int $id null;
  32.     #[ORM\OneToMany(mappedBy'invoice'targetEntityOrder::class, cascade: ['persist'])]
  33.     private Collection $orders;
  34.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  35.     #[Groups(["read","write"])]
  36.     private ?string $description null;
  37.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  38.     #[Groups(["read","write"])]
  39.     private ?\DateTimeInterface $createdAt null;
  40.     #[ORM\ManyToOne(inversedBy'invoices'cascade: ['persist'])]
  41.     #[Assert\Valid]
  42.     #[Groups(["read","write"])]
  43.     private ?Customer $customer null;
  44.     #[ORM\Column(type'string'length255nullabletrue)]
  45.     #[Groups(["read","write"])]
  46.     private ?string $firstName null;
  47.     #[ORM\Column(type'string'length255nullabletrue)]
  48.     #[Groups(["read","write"])]
  49.     private ?string $lastName null;
  50.     #[ORM\Column(type'string'length255nullabletrue)]
  51.     #[Groups(["read","write"])]
  52.     private ?string $companyName null;
  53.     #[ORM\Column(type'string'length255nullabletrue)]
  54.     #[Groups(["read","write"])]
  55.     private ?string $address null;
  56.     #[ORM\Column(type'string'length255nullabletrue)]
  57.     #[Groups(["read","write"])]
  58.     private ?string $city null;
  59.     #[ORM\Column(type'string'length255nullabletrue)]
  60.     #[Groups(["read","write"])]
  61.     private ?string $country null;
  62.     #[ORM\Column(type'string'length255nullabletrue)]
  63.     #[Groups(["read","write"])]
  64.     private ?string $postcode null;
  65.     #[ORM\Column(type'string'length255nullabletrue)]
  66.     #[Groups(["read","write"])]
  67.     private ?string $email null;
  68.     #[ORM\Column(type'string'length255nullabletrue)]
  69.     #[Groups(["read","write"])]
  70.     private ?string $tel null;
  71.     #[ORM\Column(nullabletrue)]
  72.     #[Groups(["read","write"])]
  73.     private ?float $payedAmount null;
  74.     #[ORM\Column(type'float'nullabletrue)]
  75.     #[Groups(["read","write"])]
  76.     private $walletPaymentAmount 0;
  77.     #[ORM\Column(type'string'length255nullabletrue)]
  78.     private $tokenStripe;
  79.     #[ORM\ManyToOne(inversedBy'invoices')]
  80.     #[Groups(["read","write"])]
  81.     private ?PaymentMethod $paymentMethod null;
  82.     #[ORM\Column(length255nullabletrue)]
  83.     #[Groups(["read","write"])]
  84.     private ?string $status "draft";
  85.     #[ORM\OneToMany(mappedBy'invoice'targetEntityCustomerWalletPoint::class)]
  86.     #[Groups(["read","write"])]
  87.     private Collection $customerWalletPoints;
  88.     #[ORM\Column(length255nullabletrue)]
  89.     #[Groups(["read","write"])]
  90.     private ?string $source null;
  91.     public function __construct()
  92.     {
  93.         $this->orders = new ArrayCollection();
  94.         $this->customerWalletPoints = new ArrayCollection();
  95.         $this->createdAt = new \DateTime();
  96.     }
  97.     public function getId(): ?int
  98.     {
  99.         return $this->id;
  100.     }
  101.     
  102.     public function getInvoiceNumber($secondaryPrefix=null)
  103.     {
  104.         $prefix "FA-";
  105.         
  106.         $invoiceNumber $prefix.$this->createdAt->format("ym").str_pad((string) $this->id5"0"STR_PAD_LEFT);
  107.         if($secondaryPrefix){
  108.             $invoiceNumber $prefix.$this->createdAt->format("ym").str_pad((string) $this->id5"0"STR_PAD_LEFT)."-".$secondaryPrefix;
  109.         }
  110.         return $invoiceNumber;
  111.     }
  112.     /**
  113.      * @return Collection<int, Order>
  114.      */
  115.     public function getOrders(): Collection
  116.     {
  117.         return $this->orders;
  118.     }
  119.     public function addOrder(Order $order): self
  120.     {
  121.         if (!$this->orders->contains($order)) {
  122.             $this->orders->add($order);
  123.             $order->setInvoice($this);
  124.         }
  125.         return $this;
  126.     }
  127.     public function removeOrder(Order $order): self
  128.     {
  129.         if ($this->orders->removeElement($order)) {
  130.             // set the owning side to null (unless already changed)
  131.             if ($order->getInvoice() === $this) {
  132.                 $order->setInvoice(null);
  133.             }
  134.         }
  135.         return $this;
  136.     }
  137.     public function getDescription(): ?string
  138.     {
  139.         return $this->description;
  140.     }
  141.     public function setDescription(?string $description): self
  142.     {
  143.         $this->description $description;
  144.         return $this;
  145.     }
  146.     public function getCreatedAt(): ?\DateTimeInterface
  147.     {
  148.         return $this->createdAt;
  149.     }
  150.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  151.     {
  152.         $this->createdAt $createdAt;
  153.         return $this;
  154.     }
  155.     public function getCustomer(): ?Customer
  156.     {
  157.         return $this->customer;
  158.     }
  159.     public function setCustomer(?Customer $customer): self
  160.     {
  161.         $this->customer $customer;
  162.         return $this;
  163.     }
  164.     /**
  165.      * Get the value of firstName
  166.      */ 
  167.     public function getFirstName()
  168.     {
  169.         return $this->firstName;
  170.     }
  171.     /**
  172.      * Set the value of firstName
  173.      *
  174.      * @return  self
  175.      */ 
  176.     public function setFirstName($firstName)
  177.     {
  178.         $this->firstName $firstName;
  179.         return $this;
  180.     }
  181.     /**
  182.      * Get the value of lastName
  183.      */ 
  184.     public function getLastName()
  185.     {
  186.         return $this->lastName;
  187.     }
  188.     /**
  189.      * Set the value of lastName
  190.      *
  191.      * @return  self
  192.      */ 
  193.     public function setLastName($lastName)
  194.     {
  195.         $this->lastName $lastName;
  196.         return $this;
  197.     }
  198.     /**
  199.      * Get the value of companyName
  200.      */ 
  201.     public function getCompanyName()
  202.     {
  203.         return $this->companyName;
  204.     }
  205.     /**
  206.      * Set the value of companyName
  207.      *
  208.      * @return  self
  209.      */ 
  210.     public function setCompanyName($companyName)
  211.     {
  212.         $this->companyName $companyName;
  213.         return $this;
  214.     }
  215.     /**
  216.      * Get the value of tel
  217.      */ 
  218.     public function getTel()
  219.     {
  220.         return $this->tel;
  221.     }
  222.     /**
  223.      * Set the value of tel
  224.      *
  225.      * @return  self
  226.      */ 
  227.     public function setTel($tel)
  228.     {
  229.         $this->tel $tel;
  230.         return $this;
  231.     }
  232.     /**
  233.      * Get the value of email
  234.      */ 
  235.     public function getEmail()
  236.     {
  237.         return $this->email;
  238.     }
  239.     /**
  240.      * Set the value of email
  241.      *
  242.      * @return  self
  243.      */ 
  244.     public function setEmail($email)
  245.     {
  246.         $this->email $email;
  247.         return $this;
  248.     }
  249.     /**
  250.      * Get the value of postcode
  251.      */ 
  252.     public function getPostcode()
  253.     {
  254.         return $this->postcode;
  255.     }
  256.     /**
  257.      * Set the value of postcode
  258.      *
  259.      * @return  self
  260.      */ 
  261.     public function setPostcode($postcode)
  262.     {
  263.         $this->postcode $postcode;
  264.         return $this;
  265.     }
  266.     /**
  267.      * Get the value of country
  268.      */ 
  269.     public function getCountry()
  270.     {
  271.         return $this->country;
  272.     }
  273.     /**
  274.      * Set the value of country
  275.      *
  276.      * @return  self
  277.      */ 
  278.     public function setCountry($country)
  279.     {
  280.         $this->country $country;
  281.         return $this;
  282.     }
  283.     /**
  284.      * Get the value of city
  285.      */ 
  286.     public function getCity()
  287.     {
  288.         return $this->city;
  289.     }
  290.     /**
  291.      * Set the value of city
  292.      *
  293.      * @return  self
  294.      */ 
  295.     public function setCity($city)
  296.     {
  297.         $this->city $city;
  298.         return $this;
  299.     }
  300.     /**
  301.      * Get the value of address
  302.      */ 
  303.     public function getAddress()
  304.     {
  305.         return $this->address;
  306.     }
  307.     /**
  308.      * Set the value of address
  309.      *
  310.      * @return  self
  311.      */ 
  312.     public function setAddress($address)
  313.     {
  314.         $this->address $address;
  315.         return $this;
  316.     }
  317.     public function getTotalAmount(){
  318.         $totalAmount 0;
  319.         foreach($this->getOrders() as $singleOrder){
  320.             $totalAmount $totalAmount + (float)$singleOrder->getTotalAmount();
  321.         }
  322.         
  323.         return (float)$totalAmount;
  324.     }
  325.     public function getPayedAmount(): ?float
  326.     {
  327.         return $this->payedAmount;
  328.     }
  329.     public function setPayedAmount(?float $payedAmount): self
  330.     {
  331.         $this->payedAmount $payedAmount;
  332.         return $this;
  333.     }
  334.  /**
  335.     * Get the value of walletPaymentAmount
  336.     */ 
  337.    public function getWalletPaymentAmount()
  338.    {
  339.        return $this->walletPaymentAmount;
  340.    }
  341.    /**
  342.     * Set the value of walletPaymentAmount
  343.     *
  344.     * @return  self
  345.     */ 
  346.    public function setWalletPaymentAmount($walletPaymentAmount)
  347.    {
  348.        $this->walletPaymentAmount $walletPaymentAmount;
  349.        return $this;
  350.    }
  351.        /**
  352.      * Get the value of tokenStripe
  353.      */ 
  354.     public function getTokenStripe()
  355.     {
  356.         return $this->tokenStripe;
  357.     }
  358.     /**
  359.      * Set the value of tokenStripe
  360.      *
  361.      * @return  self
  362.      */ 
  363.     public function setTokenStripe($tokenStripe)
  364.     {
  365.         $this->tokenStripe $tokenStripe;
  366.         return $this;
  367.     }
  368.     public function getPaymentMethod(): ?PaymentMethod
  369.     {
  370.         return $this->paymentMethod;
  371.     }
  372.     public function setPaymentMethod(?PaymentMethod $paymentMethod): self
  373.     {
  374.         $this->paymentMethod $paymentMethod;
  375.         return $this;
  376.     }
  377.     public function getStatus(): ?string
  378.     {
  379.         return $this->status;
  380.     }
  381.     public function setStatus(?string $status): self
  382.     {
  383.         $this->status $status;
  384.         return $this;
  385.     }
  386.     /**
  387.      * @return Collection<int, CustomerWalletPoint>
  388.      */
  389.     public function getCustomerWalletPoints(): Collection
  390.     {
  391.         return $this->customerWalletPoints;
  392.     }
  393.     public function addCustomerWalletPoint(CustomerWalletPoint $customerWalletPoint): self
  394.     {
  395.         if (!$this->customerWalletPoints->contains($customerWalletPoint)) {
  396.             $this->customerWalletPoints->add($customerWalletPoint);
  397.             $customerWalletPoint->setInvoice($this);
  398.         }
  399.         return $this;
  400.     }
  401.     public function removeCustomerWalletPoint(CustomerWalletPoint $customerWalletPoint): self
  402.     {
  403.         if ($this->customerWalletPoints->removeElement($customerWalletPoint)) {
  404.             // set the owning side to null (unless already changed)
  405.             if ($customerWalletPoint->getInvoice() === $this) {
  406.                 $customerWalletPoint->setInvoice(null);
  407.             }
  408.         }
  409.         return $this;
  410.     }
  411.     public function getSource(): ?string
  412.     {
  413.         return $this->source;
  414.     }
  415.     public function setSource(?string $source): self
  416.     {
  417.         $this->source $source;
  418.         return $this;
  419.     }
  420. }