src/Flexy/ShopBundle/Entity/Accounting/Invoice.php line 32
<?php
namespace App\Flexy\ShopBundle\Entity\Accounting;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Flexy\ShopBundle\Entity\Customer\Customer;
use App\Flexy\ShopBundle\Entity\Customer\CustomerWalletPoint;
use App\Flexy\ShopBundle\Entity\Order\Order;
use App\Flexy\ShopBundle\Entity\Payment\PaymentMethod;
use App\Repository\Flexy\ShopBundle\Entity\Accounting\InvoiceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: InvoiceRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['read','readPackEngagements']],
denormalizationContext: ['groups' => ['write']],
)]
#[ApiFilter(SearchFilter::class, properties: ['customer.id' => 'exact'])]
class Invoice
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(["read","write"])]
private ?int $id = null;
#[ORM\OneToMany(mappedBy: 'invoice', targetEntity: Order::class, cascade: ['persist'])]
private Collection $orders;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(["read","write"])]
private ?string $description = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
#[Groups(["read","write"])]
private ?\DateTimeInterface $createdAt = null;
#[ORM\ManyToOne(inversedBy: 'invoices', cascade: ['persist'])]
#[Assert\Valid]
#[Groups(["read","write"])]
private ?Customer $customer = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(["read","write"])]
private ?string $firstName = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(["read","write"])]
private ?string $lastName = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(["read","write"])]
private ?string $companyName = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(["read","write"])]
private ?string $address = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(["read","write"])]
private ?string $city = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(["read","write"])]
private ?string $country = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(["read","write"])]
private ?string $postcode = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(["read","write"])]
private ?string $email = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(["read","write"])]
private ?string $tel = null;
#[ORM\Column(nullable: true)]
#[Groups(["read","write"])]
private ?float $payedAmount = null;
#[ORM\Column(type: 'float', nullable: true)]
#[Groups(["read","write"])]
private $walletPaymentAmount = 0;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $tokenStripe;
#[ORM\ManyToOne(inversedBy: 'invoices')]
#[Groups(["read","write"])]
private ?PaymentMethod $paymentMethod = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(["read","write"])]
private ?string $status = "draft";
#[ORM\OneToMany(mappedBy: 'invoice', targetEntity: CustomerWalletPoint::class)]
#[Groups(["read","write"])]
private Collection $customerWalletPoints;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(["read","write"])]
private ?string $source = null;
public function __construct()
{
$this->orders = new ArrayCollection();
$this->customerWalletPoints = new ArrayCollection();
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getInvoiceNumber($secondaryPrefix=null)
{
$prefix = "FA-";
$invoiceNumber = $prefix.$this->createdAt->format("ym").str_pad((string) $this->id, 5, "0", STR_PAD_LEFT);
if($secondaryPrefix){
$invoiceNumber = $prefix.$this->createdAt->format("ym").str_pad((string) $this->id, 5, "0", STR_PAD_LEFT)."-".$secondaryPrefix;
}
return $invoiceNumber;
}
/**
* @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->setInvoice($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->getInvoice() === $this) {
$order->setInvoice(null);
}
}
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getCustomer(): ?Customer
{
return $this->customer;
}
public function setCustomer(?Customer $customer): self
{
$this->customer = $customer;
return $this;
}
/**
* Get the value of firstName
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* Set the value of firstName
*
* @return self
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
return $this;
}
/**
* Get the value of lastName
*/
public function getLastName()
{
return $this->lastName;
}
/**
* Set the value of lastName
*
* @return self
*/
public function setLastName($lastName)
{
$this->lastName = $lastName;
return $this;
}
/**
* Get the value of companyName
*/
public function getCompanyName()
{
return $this->companyName;
}
/**
* Set the value of companyName
*
* @return self
*/
public function setCompanyName($companyName)
{
$this->companyName = $companyName;
return $this;
}
/**
* Get the value of tel
*/
public function getTel()
{
return $this->tel;
}
/**
* Set the value of tel
*
* @return self
*/
public function setTel($tel)
{
$this->tel = $tel;
return $this;
}
/**
* Get the value of email
*/
public function getEmail()
{
return $this->email;
}
/**
* Set the value of email
*
* @return self
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get the value of postcode
*/
public function getPostcode()
{
return $this->postcode;
}
/**
* Set the value of postcode
*
* @return self
*/
public function setPostcode($postcode)
{
$this->postcode = $postcode;
return $this;
}
/**
* Get the value of country
*/
public function getCountry()
{
return $this->country;
}
/**
* Set the value of country
*
* @return self
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* Get the value of city
*/
public function getCity()
{
return $this->city;
}
/**
* Set the value of city
*
* @return self
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get the value of address
*/
public function getAddress()
{
return $this->address;
}
/**
* Set the value of address
*
* @return self
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
public function getTotalAmount(){
$totalAmount = 0;
foreach($this->getOrders() as $singleOrder){
$totalAmount = $totalAmount + (float)$singleOrder->getTotalAmount();
}
return (float)$totalAmount;
}
public function getPayedAmount(): ?float
{
return $this->payedAmount;
}
public function setPayedAmount(?float $payedAmount): self
{
$this->payedAmount = $payedAmount;
return $this;
}
/**
* Get the value of walletPaymentAmount
*/
public function getWalletPaymentAmount()
{
return $this->walletPaymentAmount;
}
/**
* Set the value of walletPaymentAmount
*
* @return self
*/
public function setWalletPaymentAmount($walletPaymentAmount)
{
$this->walletPaymentAmount = $walletPaymentAmount;
return $this;
}
/**
* Get the value of tokenStripe
*/
public function getTokenStripe()
{
return $this->tokenStripe;
}
/**
* Set the value of tokenStripe
*
* @return self
*/
public function setTokenStripe($tokenStripe)
{
$this->tokenStripe = $tokenStripe;
return $this;
}
public function getPaymentMethod(): ?PaymentMethod
{
return $this->paymentMethod;
}
public function setPaymentMethod(?PaymentMethod $paymentMethod): self
{
$this->paymentMethod = $paymentMethod;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(?string $status): self
{
$this->status = $status;
return $this;
}
/**
* @return Collection<int, CustomerWalletPoint>
*/
public function getCustomerWalletPoints(): Collection
{
return $this->customerWalletPoints;
}
public function addCustomerWalletPoint(CustomerWalletPoint $customerWalletPoint): self
{
if (!$this->customerWalletPoints->contains($customerWalletPoint)) {
$this->customerWalletPoints->add($customerWalletPoint);
$customerWalletPoint->setInvoice($this);
}
return $this;
}
public function removeCustomerWalletPoint(CustomerWalletPoint $customerWalletPoint): self
{
if ($this->customerWalletPoints->removeElement($customerWalletPoint)) {
// set the owning side to null (unless already changed)
if ($customerWalletPoint->getInvoice() === $this) {
$customerWalletPoint->setInvoice(null);
}
}
return $this;
}
public function getSource(): ?string
{
return $this->source;
}
public function setSource(?string $source): self
{
$this->source = $source;
return $this;
}
}