<?php
namespace App\AtechNet\CoreBundle\Entity;
use App\AtechNet\CoreBundle\Helper\Billingo;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OrderBy;
use Doctrine\ORM\Mapping\Table as Table;
/**
* CustomerBillingoData
*
* @Table(name="customers__billingo_data")
* @Entity()
*/
class CustomerBillingoData extends AbstractSignedEntity
{
/**
* @var Order
*
* @ManyToOne(targetEntity="Order", inversedBy="billingoDocuments")
* @JoinColumn(name="order_id", referencedColumnName="id")
*/
private $order;
/**
* @var Customer
*
* @ManyToOne(targetEntity="Customer", inversedBy="billingoDocuments")
* @JoinColumn(name="customer_id", referencedColumnName="id")
*/
private $customer;
/**
* @var StockMovement
*
* @ManyToOne(targetEntity="StockMovement", inversedBy="billingoDocuments")
* @JoinColumn(name="stock_movement_id", referencedColumnName="id")
*/
private $stockMovement;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="PaymentData", mappedBy="billingoDocument", orphanRemoval=true)
* @OrderBy({"created" = "DESC"})
**/
private $paymentDatas;
/**
* @var int
*
* @Column(name="type", type="integer")
*/
private $type;
/**
* @var string
*
* @Column(name="invoice_id", type="string")
*/
private $invoiceId;
/**
* @var string
*
* @Column(name="invoice_v3_id", type="string", nullable=true)
*/
private $invoiceV3Id;
/**
* @var string
*
* @Column(name="invoice_code", type="string")
*/
private $invoiceCode;
/**
* @var string
*
* @Column(name="prefix", type="string", nullable=true)
*/
private $prefix;
/**
* @var string
*
* @Column(name="invoice_code_with_prefix", type="string", nullable=true)
*/
private $invoiceCodeWithPrefix;
/**
* @var \DateTime
*
* @Column(name="fullfilment_date", type="datetime")
*/
private $fullfilment_date;
/**
* @var \DateTime
*
* @Column(name="due_date", type="datetime")
*/
private $due_date;
/**
* @var string
*
* @Column(name="comment", type="text", nullable=true)
*/
private $comment;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="BillingoComment", mappedBy="document", orphanRemoval=true)
* @OrderBy({"created" = "DESC"})
**/
private $comments;
/**
* @var float
*
* @Column(name="total_price", type="decimal", precision=18, scale=4)
*/
private $totalPrice;
/**
* @var float
*
* @Column(name="total_vat_price", type="decimal", precision=18, scale=4)
*/
private $totalVatPrice;
/**
* @var string
*
* @Column(name="currency", type="string", length=6)
*/
private $currency;
/**
* @var string
*
* @Column(name="client_uid", type="string", length=32)
*/
private $clientUid;
/**
* @var string
*
* @Column(name="block_uid", type="string", length=32)
*/
private $blockUid;
/**
* @var string
*
* @Column(name="uid", type="string", length=32)
*/
private $uid;
/**
* @var bool
*
* @Column(name="paid", type="boolean")
*/
private $paid;
/**
* @var string
*
* @Column(name="total_paid", type="decimal", precision=18, scale=4)
*/
private $totalPaid;
/**
* @var float
*
* @Column(name="vat", type="decimal", precision=10, scale=2)
*/
private $vat;
/**
* @var int
*
* @Column(name="payment_method", type="integer")
*/
private $paymentMethod;
/**
* @var bool
*
* @Column(name="canceled", type="boolean")
*/
private $canceled;
/**
* @var string
*
* @Column(name="canceled_invoice_id", type="string", length=32, nullable=true)
*/
private $canceledInvoiceId;
/**
* @var string
*
* @Column(name="canceled_invoice_v3_id", type="string", length=32, nullable=true)
*/
private $canceledInvoiceV3Id;
/**
* @var string
*
* @Column(name="canceled_invoice_code", type="string", length=32, nullable=true)
*/
private $canceledInvoiceCode;
/**
* @var string
*
* @Column(name="public_v3_invoice_link", type="string", length=256, nullable=true)
*/
private $publicV3InvoiceLink;
/**
* @var string
*
* @Column(name="public_v3_cancel_invoice_link", type="string", length=256, nullable=true)
*/
private $publicV3CancelInvoiceLink;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="BillingoPayment", mappedBy="billingoData", orphanRemoval=true)
* @OrderBy({"created" = "DESC"})
**/
private $payments;
/**
* @return Order
*/
public function getOrder()
{
return $this->order;
}
/**
* @param Order $order
*/
public function setOrder($order)
{
$this->order = $order;
}
/**
* @return Customer
*/
public function getCustomer()
{
return $this->customer;
}
/**
* @param Customer $customer
*/
public function setCustomer($customer)
{
$this->customer = $customer;
}
/**
* @return int
*/
public function getType()
{
return $this->type;
}
/**
* @param int $type
*/
public function setType($type)
{
$this->type = $type;
}
/**
* @return string
*/
public function getInvoiceId()
{
return $this->invoiceId;
}
/**
* @param string $invoiceId
*/
public function setInvoiceId($invoiceId)
{
$this->invoiceId = $invoiceId;
}
/**
* @return string
*/
public function getInvoiceCode()
{
return $this->invoiceCode;
}
/**
* @param string $invoiceCode
*/
public function setInvoiceCode($invoiceCode)
{
$this->invoiceCode = $invoiceCode;
}
/**
* @return \DateTime
*/
public function getFullfilmentDate()
{
return $this->fullfilment_date;
}
/**
* @param \DateTime $fullfilment_date
*/
public function setFullfilmentDate($fullfilment_date)
{
$this->fullfilment_date = $fullfilment_date;
}
/**
* @return \DateTime
*/
public function getDueDate()
{
return $this->due_date;
}
/**
* @param \DateTime $due_date
*/
public function setDueDate($due_date)
{
$this->due_date = $due_date;
}
/**
* @return string
*/
public function getComment()
{
return $this->comment;
}
/**
* @param string $comment
*/
public function setComment($comment)
{
$this->comment = $comment;
}
/**
* @return ArrayCollection
*/
public function getComments()
{
return $this->comments;
}
/**
* @return BillingoComment|null
*/
public function getLatestComment(): ?BillingoComment
{
return $this->getComments()->count() > 0 ? $this->getComments()->first() : null;
}
/**
* @return float
*/
public function getTotalPrice()
{
return $this->totalPrice;
}
/**
* @param float $totalPrice
*/
public function setTotalPrice($totalPrice)
{
$this->totalPrice = $totalPrice;
}
/**
* @return float
*/
public function getTotalVatPrice()
{
return $this->totalVatPrice;
}
/**
* @param float $totalVatPrice
*/
public function setTotalVatPrice($totalVatPrice)
{
$this->totalVatPrice = $totalVatPrice;
}
/**
* @return string
*/
public function getCurrency()
{
return $this->currency;
}
/**
* @param string $currency
*/
public function setCurrency($currency)
{
$this->currency = $currency;
}
/**
* @return string
*/
public function getClientUid()
{
return $this->clientUid;
}
/**
* @param string $clientUid
*/
public function setClientUid($clientUid)
{
$this->clientUid = $clientUid;
}
/**
* @return string
*/
public function getBlockUid()
{
return $this->blockUid;
}
/**
* @param string $blockUid
*/
public function setBlockUid($blockUid)
{
$this->blockUid = $blockUid;
}
/**
* @return string
*/
public function getUid()
{
return $this->uid;
}
/**
* @param string $uid
*/
public function setUid($uid)
{
$this->uid = $uid;
}
/**
* @return boolean
*/
public function isPaid()
{
return $this->paid;
}
/**
* @param boolean $paid
*/
public function setPaid($paid)
{
$this->paid = $paid;
}
/**
* @return string
*/
public function getTotalPaid()
{
return $this->totalPaid;
}
/**
* @param string $totalPaid
*/
public function setTotalPaid($totalPaid)
{
$this->totalPaid = $totalPaid;
}
/**
* @return float
*/
public function getVat()
{
return $this->vat;
}
/**
* @param float $vat
*/
public function setVat($vat)
{
$this->vat = $vat;
}
/**
* @return int
*/
public function getPaymentMethod()
{
return $this->paymentMethod;
}
/**
* @param int $paymentMethod
*/
public function setPaymentMethod($paymentMethod)
{
$this->paymentMethod = $paymentMethod;
}
/**
* @return float
*/
public function getPriceToPay()
{
return $this->getVat() == 0 ? $this->getTotalPrice() : $this->getTotalVatPrice();
}
/**
* @return boolean
*/
public function isCanceled()
{
return $this->canceled;
}
/**
* @param boolean $canceled
*/
public function setCanceled($canceled)
{
$this->canceled = $canceled;
}
/**
* @return bool
*/
public function isLocked()
{
return $this->getFullfilmentDate()->format('Ym') < date('Ym') && date('d') > Document::LOCKED_AFTER_DAY_OF_MONTH;
}
/**
* @return StockMovement
*/
public function getStockMovement()
{
return $this->stockMovement;
}
/**
* @param StockMovement $stockMovement
*/
public function setStockMovement($stockMovement)
{
$this->stockMovement = $stockMovement;
}
/**
* @return bool
*/
public function isReStockAvailable(): bool
{
foreach ($this->getOrder()->getStockMovements() as $stockMovement) {
if ($stockMovement->getType() == StockMovement::TYPE_IN) {
return false;
}
}
if (!is_null($this->getStockMovement()) && $this->getStockMovement()->getType() == StockMovement::TYPE_OUT) {
return true;
}
return false;
}
/**
* @return string
*/
public function getCanceledInvoiceId()
{
return $this->canceledInvoiceId;
}
/**
* @param string $canceledInvoiceId
*/
public function setCanceledInvoiceId($canceledInvoiceId)
{
return $this->canceledInvoiceId = $canceledInvoiceId;
}
/**
* @return string
*/
public function getCanceledInvoiceCode()
{
return $this->canceledInvoiceCode;
}
/**
* @param string $canceledInvoiceCode
*/
public function setCanceledInvoiceCode($canceledInvoiceCode)
{
return $this->canceledInvoiceCode = $canceledInvoiceCode;
}
/**
* @return ArrayCollection
*/
public function getPayments()
{
return $this->payments;
}
/**
* @param ArrayCollection $payments
*/
public function setPayments($payments)
{
$this->payments = $payments;
}
/**
* @return ArrayCollection
*/
public function getPaymentDatas()
{
return $this->paymentDatas;
}
/**
* @return string|void
*/
public function getStatusTitle()
{
if ($this->getTotalVatPrice() > $this->getTotalPaid()) {
return 'Not paid';
} elseif ($this->getTotalVatPrice() == $this->getTotalPaid()) {
return 'Paid';
} elseif ($this->getTotalVatPrice() < $this->getTotalPaid()) {
return 'Overpaid';
}
}
/**
* @return string|null
*/
public function getPrefix(): ?string
{
return $this->prefix;
}
/**
* @param string|null $prefix
*/
public function setPrefix(?string $prefix): void
{
$this->prefix = $prefix;
}
/**
* @return string|null
*/
public function getInvoiceCodeWithPrefix(): ?string
{
return $this->invoiceCodeWithPrefix;
}
/**
* @param string|null $invoiceCodeWithPrefix
*/
public function setInvoiceCodeWithPrefix(?string $invoiceCodeWithPrefix): void
{
$this->invoiceCodeWithPrefix = $invoiceCodeWithPrefix;
}
/**
* @return string|null
*/
public function getInvoiceV3Id(): ?string
{
return $this->invoiceV3Id;
}
/**
* @param string|null $invoiceV3Id
*/
public function setInvoiceV3Id(?string $invoiceV3Id): void
{
$this->invoiceV3Id = $invoiceV3Id;
}
/**
* @return string|null
*/
public function getCanceledInvoiceV3Id(): ?string
{
return $this->canceledInvoiceV3Id;
}
/**
* @param string|null $canceledInvoiceV3Id
*/
public function setCanceledInvoiceV3Id(?string $canceledInvoiceV3Id): void
{
$this->canceledInvoiceV3Id = $canceledInvoiceV3Id;
}
/**
* @return string|null
*/
public function getPublicV3InvoiceLink(): ?string
{
return Billingo::PUBLIC_URL_PREFIX . $this->publicV3InvoiceLink;
}
/**
* @param string|null $publicV3InvoiceLink
*/
public function setPublicV3InvoiceLink(?string $publicV3InvoiceLink): void
{
$this->publicV3InvoiceLink = $publicV3InvoiceLink;
}
/**
* @return string|null
*/
public function getPublicV3CancelInvoiceLink(): ?string
{
return Billingo::PUBLIC_URL_PREFIX . $this->publicV3CancelInvoiceLink;
}
/**
* @param string|null $publicV3CancelInvoiceLink
*/
public function setPublicV3CancelInvoiceLink(?string $publicV3CancelInvoiceLink): void
{
$this->publicV3CancelInvoiceLink = $publicV3CancelInvoiceLink;
}
}