<?php
namespace App\AtechNet\CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\JoinTable;
use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\ORM\Mapping\OrderBy;
use Doctrine\ORM\Mapping\PrePersist;
use Doctrine\ORM\Mapping\PreUpdate;
use Doctrine\ORM\Mapping\Table as Table;
/**
* Document
*
* @Table(name="documents")
* @Entity(repositoryClass="App\AtechNet\CoreBundle\Repository\DocumentRepository")
* @HasLifecycleCallbacks
*/
class Document extends AbstractSignedEntity
{
public const int STATUS_NEW = 1;
public const int STATUS_PAID = 2;
public const int STATUS_POST_DUE_DATE = 3;
public const int STATUS_CANCELLED = 4;
public const int STATUS_ACCEPTED = 5;
public const int STATUS_DECLINED = 6;
public const int STATUS_OVERPAID = 7;
public const int STATUS_PARTIAL = 8;
public const int STATUS_NEEDS_ATTENTION = 9;
public const int LOCKED_AFTER_DAY_OF_MONTH = 5;
public const int LOCKED_AFTER_DAYS = 1;
public const array DOCUMENT_TYPE_TO_LOCK = [
DocumentGroup::TYPE_INVOICE_OUT,
DocumentGroup::TYPE_INVOICE_CREDIT_NOTE,
];
public const int HU_COMPANY_ADDED_PROFIT_PERCENT = 70;
public const string ERP_TYPE_KISGEP = 'kisgép';
public const string ERP_TYPE_NAGYGEP = 'nagygép';
public const string ERP_TYPE_KEPERNYO = 'képernyő, monitor';
public const string ERP_TYPE_ELEM = 'elem, akkumulátor';
public const string ERP_TYPE_ELECTROMOS = 'elektromos, elektronikus berendezések';
public const string ERP_TYPE_KIS_BERENDEZESEK = 'kisméretű számítástechnikai és távközlési berendezések';
public const string KSH_TYPE_SMARTPHONE_TABLET = 'Mobil / smartphone-tablet';
public const string KSH_TYPE_MONITOR = 'Monitor';
public const string KSH_TYPE_NOTEBOOK = 'Notebook';
public const string KSH_TYPE_PC = 'PC';
/**
* @return string[]
*/
public static function getCurrencyConvertCodes(): array
{
return [
'€' => 'EUR',
'Ft' => 'HUF',
'Kč' => 'CZK',
];
}
/**
* @return string[]
*/
public static function getCurrencyCodeChoices(): array
{
return [
'EUR' => 'EUR',
'USD' => 'USD',
'CZK' => 'CZK',
'HUF' => 'HUF',
'GBP' => 'GBP',
'PLN' => 'PLN',
'SEK' => 'SEK',
];
}
/**
* @return array
*/
public static function getStatusChoices(): array
{
return [
self::STATUS_NEW => 'Not paid',
self::STATUS_PAID => 'Paid',
self::STATUS_POST_DUE_DATE => 'Post due date',
self::STATUS_CANCELLED => 'Cancelled',
self::STATUS_ACCEPTED => 'Accepted',
self::STATUS_DECLINED => 'Declined',
self::STATUS_OVERPAID => 'Overpaid',
self::STATUS_PARTIAL => 'Partial',
self::STATUS_NEEDS_ATTENTION => 'Needs attention',
];
}
/**
* @param int $type
* @return array
*/
public static function getStatusChoicesForType($type): array
{
$keys = [];
switch ($type) {
case DocumentGroup::TYPE_INVOICE_PRE:
$keys = [
self::STATUS_NEW,
self::STATUS_POST_DUE_DATE,
self::STATUS_PAID,
self::STATUS_CANCELLED,
self::STATUS_NEEDS_ATTENTION,
];
break;
case DocumentGroup::TYPE_INVOICE_IN:
case DocumentGroup::TYPE_INVOICE_OUT:
case DocumentGroup::TYPE_INVOICE_CREDIT_NOTE:
case DocumentGroup::TYPE_BILL_OF_DELIVERY:
$keys = [
self::STATUS_NEW,
self::STATUS_POST_DUE_DATE,
self::STATUS_OVERPAID,
self::STATUS_PARTIAL,
self::STATUS_PAID,
self::STATUS_NEEDS_ATTENTION,
];
break;
case DocumentGroup::TYPE_PRICE_OFFER:
$keys = [
self::STATUS_NEW,
self::STATUS_ACCEPTED,
self::STATUS_DECLINED,
self::STATUS_NEEDS_ATTENTION,
];
break;
}
$result = [];
foreach ($keys as $k) {
$result[$k] = self::getStatusChoices()[$k];
}
return $result;
}
/**
* @param int $status
* @return string
*/
public static function getLabelClassForStatus(): array
{
return [
self::STATUS_NEW => "primary",
self::STATUS_PAID => "success",
self::STATUS_POST_DUE_DATE => "info",
self::STATUS_ACCEPTED => "info",
self::STATUS_PARTIAL => "info",
self::STATUS_CANCELLED => "danger",
self::STATUS_NEEDS_ATTENTION => "warning",
self::STATUS_DECLINED => "warning",
self::STATUS_OVERPAID => "warning",
];
}
/**
* @var DocumentGroup
*
* @ManyToOne(targetEntity="DocumentGroup", inversedBy="documents")
* @JoinColumn(name="group_id", referencedColumnName="id", nullable=false)
*/
private $group;
/**
* @var ?Order
*
* @ManyToOne(targetEntity="Order", inversedBy="documents")
* @JoinColumn(name="order_id", referencedColumnName="id", nullable=true)
*/
private $order;
/**
* @var ?Document
*
* @OneToOne(targetEntity="Document")
* @JoinColumn(name="related_document_id", referencedColumnName="id", nullable=true)
*/
private $relatedDocument;
/**
* @var ArrayCollection
*
* @ManyToMany(targetEntity="Document", inversedBy="relatedDocuments")
* @JoinTable(
* name="documents_related",
* joinColumns={
* @JoinColumn(name="document_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @JoinColumn(name="related_id", referencedColumnName="id")
* })
*/
private $initialDocuments;
/**
* @var ArrayCollection
*
* @ManyToMany(targetEntity="Document", mappedBy="initialDocuments")
* @OrderBy({"created" = "DESC"})
*/
private $relatedDocuments;
/**
* @var StockMovement
*
* @ManyToOne(targetEntity="StockMovement", inversedBy="documents")
* @JoinColumn(name="stock_movement_id", referencedColumnName="id", nullable=true)
*/
private $stockMovement;
/**
* @var Customer
*
* @ManyToOne(targetEntity="Customer", inversedBy="documents")
* @JoinColumn(name="customer_id", referencedColumnName="id", nullable=false)
*/
private $customer;
/**
* GROUP_PREFIX + GROUP_NEXT_ID (GROUP_ID_LENGTH)
* example: 02000001
* Number of zeros after prefix(02) depends on GROUP_ID_LENTH
*
* @var string
*
* @Column(name="code", type="string", length=32)
*/
private $code;
/**
* @var \DateTime
*
* @Column(name="created_date", type="datetime", nullable=false)
*/
private $createdDate;
/**
* @var string
*
* @Column(name="due_in_days", type="integer")
*/
private $dueInDays;
/**
* @var \DateTime
*
* @Column(name="due_date", type="datetime", nullable=false)
*/
private $dueDate;
/**
* @var \DateTime
*
* @Column(name="chargeability_date", type="datetime", nullable=false)
*/
private $chargeabilityDate;
/**
* @var integer
*
* @Column(name="payment_type_id", type="integer")
*/
private $paymentType;
/**
* @var integer
*
* @Column(name="shipping_type_id", type="integer")
*/
private $shippingType;
/**
* @var int
*
* @Column(name="variable_symbol", type="string", length=32)
*/
private $variableSymbol;
/**
* @var string
*
* @Column(name="external_number", type="string", length=40, nullable=true)
*/
private $externalNumber;
/**
* @var int
*
* @Column(name="constant_symbol", type="integer")
*/
private $constantSymbol;
/**
* @var string
*
* @Column(name="business_name", type="string", length=128, nullable=true)
*/
private $businessName;
/**
* @var string
*
* @Column(name="degree", type="string", length=32, nullable=true)
*/
private $degree;
/**
* @var string
*
* @Column(name="first_name", type="string", length=64)
*/
private $firstName;
/**
* @var string
*
* @Column(name="last_name", type="string", length=64)
*/
private $lastName;
/**
* @var string
*
* @Column(name="street", type="string", length=128)
*/
private $street;
/**
* @var string
*
* @Column(name="city", type="string", length=128)
*/
private $city;
/**
* @var string
*
* @Column(name="zip", type="string", length=16)
*/
private $zip;
/**
* @var string
*
* @Column(name="country", type="string", length=2)
*/
private $country;
/**
* @var string
*
* @Column(name="email", type="string", length=255, nullable=true)
*/
private $email;
/**
* @var string
*
* @Column(name="email_sent", type="string", length=255, nullable=true)
*/
private $emailSent;
/**
* @var string
*
* @Column(name="phone", type="string", length=32, nullable=true)
*/
private $phone;
/**
* @var string
*
* @Column(name="business_id", type="string", length=24, nullable=true)
*/
private $businessId;
/**
* @var string
*
* @Column(name="tax_id", type="string", length=24, nullable=true)
*/
private $taxId;
/**
* @var string
*
* @Column(name="vat_id", type="string", length=24, nullable=true)
*/
private $vatId;
/**
* @var float
*
* @Column(name="vat", type="decimal", precision=10, scale=2)
*/
private $vat;
/**
* @var bool
*
* @Column(name="ship_address_same", type="boolean")
*/
private $shipAddressSame = true;
/**
* @var string
*
* @Column(name="ship_business_name", type="string", length=128, nullable=true)
*/
private $shipBusinessName;
/**
* @var string
*
* @Column(name="ship_degree", type="string", length=32, nullable=true, nullable=true)
*/
private $shipDegree;
/**
* @var string
*
* @Column(name="ship_first_name", type="string", length=64, nullable=true)
*/
private $shipFirstName;
/**
* @var string
*
* @Column(name="ship_last_name", type="string", length=64, nullable=true)
*/
private $shipLastName;
/**
* @var string
*
* @Column(name="ship_street", type="string", length=128, nullable=true)
*/
private $shipStreet;
/**
* @var string
*
* @Column(name="ship_city", type="string", length=128, nullable=true)
*/
private $shipCity;
/**
* @var string
*
* @Column(name="ship_zip", type="string", length=16, nullable=true)
*/
private $shipZip;
/**
* @var string
*
* @Column(name="ship_country", type="string", length=2, nullable=true)
*/
private $shipCountry;
/**
* @var string
*
* @Column(name="ship_phone", type="string", length=32, nullable=true)
*/
private $shipPhone;
/**
* @var string
*
* @Column(name="attachment", type="string", length=512)
*/
private $attachment;
/**
* @var float
*
* @Column(name="total_price", type="decimal", precision=10, scale=2)
*/
private $totalPrice = 0;
/**
* @var float
*
* @Column(name="total_vat_price", type="decimal", precision=10, scale=2)
*/
private $totalVatPrice = 0;
/**
* @var float
*
* @Column(name="paid_price", type="decimal", precision=10, scale=2)
*/
private $paidPrice = 0;
/**
* @var float
*
* @Column(name="paid_vat_price", type="decimal", precision=10, scale=2)
*/
private $paidVatPrice = 0;
/**
* @var float
*
* @Column(name="exchange_rate", type="decimal", precision=10, scale=3)
*/
private $exchangeRate = 0;
/**
* @var string
*
* @Column(name="currency", type="string", length=3, nullable=true)
*/
private $currency;
/**
* @var User
*
* @ManyToOne(targetEntity="User")
* @JoinColumn(name="signed_by", referencedColumnName="id", nullable=false)
*/
private $signedBy;
/**
* @var bool
*
* @Column(name="signed_anonymously", type="boolean")
*/
private $signedAnonymously = false;
/**
* @var int
*
* @Column(name="status", type="integer")
*/
private $status;
/**
* @var string
*
* @Column(name="note", type="text", nullable=true)
*/
private $note;
/**
* @var int
*
* @Column(name="warranty", type="integer", nullable=true)
*/
private $warranty;
/**
* @var bool
*
* @Column(name="qty_in_weight", type="boolean")
*/
private $qtyInWeight = false;
/**
* @var \DateTime
*
* @Column(name="sent_date", type="datetime", nullable=true)
*/
private $sentDate;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="DocumentItem", mappedBy="document", orphanRemoval=true)
* @OrderBy({"created" = "DESC"})
**/
private $items;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="DocumentPayment", mappedBy="document", orphanRemoval=true)
* @OrderBy({"created" = "DESC"})
**/
private $payments;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="PaymentData", mappedBy="document", orphanRemoval=true)
* @OrderBy({"created" = "DESC"})
**/
private $paymentDatas;
/**
* @var bool
*
* @Column(name="payment_approved", type="boolean")
*/
private $paymentApproved = false;
/**
* @var User
*
* @ManyToOne(targetEntity="User")
* @JoinColumn(name="payment_approved_by", referencedColumnName="id", nullable=true)
*/
private $paymentApprovedBy;
/**
* @var \DateTime
*
* @Column(name="payment_approved_date", type="datetime", nullable=true)
*/
private $paymentApprovedDate;
/**
* @var string
*
* @Column(name="pohoda_number", type="text", nullable=true)
*/
private $pohodaNumber;
/**
* @var string|null
*
* @Column(name="account_number", type="text", nullable=true)
*/
private $accountNumber;
/**
* @var string
*
* @Column(name="shipment_number", type="text", nullable=true)
*/
private $shipmentNumber;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="DocumentComment", mappedBy="document", orphanRemoval=true)
* @OrderBy({"created" = "DESC"})
**/
private $comments;
/**
* @var Shipment|null
*
* @ManyToOne(targetEntity="Shipment", inversedBy="documents")
* @JoinColumn(name="shipment_id", referencedColumnName="id")
*/
private ?Shipment $shipment;
public function __construct()
{
parent::__construct();
$this->items = new ArrayCollection();
$this->initialDocuments = new ArrayCollection();
$this->relatedDocuments = new ArrayCollection();
}
/**
* @return DocumentGroup
*/
public function getGroup()
{
return $this->group;
}
/**
* @param DocumentGroup $group
*/
public function setGroup($group)
{
$this->group = $group;
}
/**
* @return Order|null
*/
public function getOrder(): ?Order
{
return $this->order;
}
/**
* @param Order|null $order
*
* @return void
*/
public function setOrder(?Order $order): void
{
$this->order = $order;
}
/**
* @return Document|null
*/
public function getRelatedDocument(): ?Document
{
return $this->relatedDocument;
}
/**
* @param Document|null $relatedDocument
*
* @return Document
*/
public function setRelatedDocument(?Document $relatedDocument)
{
$this->relatedDocument = $relatedDocument;
return $this;
}
/**
* Get all initial documents
*
* @return ArrayCollection
*/
public function getInitialDocuments(): Collection
{
return $this->initialDocuments;
}
/**
* Add an initial document
*
* @param Document $document
*/
public function addInitialDocument(Document $document): void
{
if (!$this->initialDocuments->contains($document)) {
$this->initialDocuments->add($document);
}
}
/**
* Remove an initial document
*
* @param Document $document
*/
public function removeInitialDocument(Document $document): void
{
if ($this->initialDocuments->contains($document)) {
$this->initialDocuments->removeElement($document);
}
}
/**
* Clear initial documents
*/
public function clearInitialDocuments(): void
{
$this->initialDocuments->clear();
}
/**
* Get all related documents
*
* @return ArrayCollection
*/
public function getRelatedDocuments(): Collection
{
return $this->relatedDocuments;
}
/**
* @return StockMovement
*/
public function getStockMovement()
{
return $this->stockMovement;
}
/**
* @param ?StockMovement $stockMovement
*/
public function setStockMovement(?StockMovement $stockMovement)
{
$this->stockMovement = $stockMovement;
}
/**
* @return Customer
*/
public function getCustomer()
{
return $this->customer;
}
/**
* @param Customer $customer
*/
public function setCustomer($customer)
{
$this->customer = $customer;
}
/**
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* @param string $code
*/
public function setCode($code)
{
$this->code = $code;
}
/**
* @return \DateTime
*/
public function getCreatedDate()
{
return $this->createdDate;
}
/**
* @param \DateTime $createdDate
*/
public function setCreatedDate($createdDate)
{
$this->createdDate = $createdDate;
}
/**
* @return int
*/
public function getDueInDays()
{
return $this->dueInDays;
}
/**
* @param int $dueInDays
*/
public function setDueInDays($dueInDays)
{
$this->dueInDays = $dueInDays;
}
/**
* @return \DateTime
*/
public function getDueDate()
{
return $this->dueDate;
}
/**
* @param \DateTime $dueDate
*/
public function setDueDate($dueDate)
{
$this->dueDate = $dueDate;
}
/**
* @return \DateTime
*/
public function getChargeabilityDate()
{
return $this->chargeabilityDate;
}
/**
* @param \DateTime $chargeabilityDate
*/
public function setChargeabilityDate($chargeabilityDate)
{
$this->chargeabilityDate = $chargeabilityDate;
}
/**
* @return DomainPaymentType
*/
public function getPaymentType()
{
return $this->paymentType;
}
/**
* @param DomainPaymentType $paymentType
*/
public function setPaymentType($paymentType)
{
$this->paymentType = $paymentType;
}
/**
* @return DomainShippingType
*/
public function getShippingType()
{
return $this->shippingType;
}
/**
* @param DomainShippingType $shippingType
*/
public function setShippingType($shippingType)
{
$this->shippingType = $shippingType;
}
/**
* @return int
*/
public function getVariableSymbol()
{
return $this->variableSymbol;
}
/**
* @param int $variableSymbol
*/
public function setVariableSymbol($variableSymbol)
{
$this->variableSymbol = $variableSymbol;
}
/**
* @return int
*/
public function getExternalNumber()
{
return $this->externalNumber;
}
/**
* @param int $externalNumber
*/
public function setExternalNumber($externalNumber)
{
$this->externalNumber = $externalNumber;
return $this;
}
/**
* @return int
*/
public function getConstantSymbol()
{
return $this->constantSymbol;
}
/**
* @param int $constantSymbol
*/
public function setConstantSymbol($constantSymbol)
{
$this->constantSymbol = $constantSymbol;
}
/**
* @return string
*/
public function getBusinessName()
{
return $this->businessName;
}
/**
* @param string $businessName
*/
public function setBusinessName($businessName)
{
$this->businessName = $businessName;
}
/**
* @return string
*/
public function getDegree()
{
return $this->degree;
}
/**
* @param string $degree
*/
public function setDegree($degree)
{
$this->degree = $degree;
}
/**
* @return string
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* @param string $firstName
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
}
/**
* @return string
*/
public function getLastName()
{
return $this->lastName;
}
/**
* @param string $lastName
*/
public function setLastName($lastName)
{
$this->lastName = $lastName;
}
/**
* @param bool $flipNames
* @return string
*/
public function getFullName($flipNames = false)
{
if ($flipNames) {
return !is_null($this->degree) ? $this->degree . ' ' : '' . $this->lastName . ' ' . $this->firstName;
}
return !is_null($this->degree) ? $this->degree . ' ' : '' . $this->firstName . ' ' . $this->lastName;
}
/**
* @return string
*/
public function getStreet()
{
return $this->street;
}
/**
* @param string $street
*/
public function setStreet($street)
{
$this->street = $street;
}
/**
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* @param string $city
*/
public function setCity($city)
{
$this->city = $city;
}
/**
* @return string
*/
public function getZip()
{
return $this->zip;
}
/**
* @param string $zip
*/
public function setZip($zip)
{
$this->zip = $zip;
}
/**
* @return string
*/
public function getCountry()
{
return $this->country;
}
/**
* @param string $country
*/
public function setCountry($country)
{
$this->country = $country;
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @param string $email
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* @return string|null
*/
public function getEmailSent(): ?string
{
return $this->emailSent;
}
/**
* @param string $emailSent
* @return void
*/
public function setEmailSent(string $emailSent): void
{
$this->emailSent = $emailSent;
}
/**
* @return void
*/
public function removeEmailSent(): void
{
$this->emailSent = null;
}
/**
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* @param string $phone
*/
public function setPhone($phone)
{
$this->phone = $phone;
}
/**
* @return string
*/
public function getBusinessId()
{
return $this->businessId;
}
/**
* @param string $businessId
*/
public function setBusinessId($businessId)
{
$this->businessId = $businessId;
}
/**
* @return string
*/
public function getTaxId()
{
return $this->taxId;
}
/**
* @param string $taxId
*/
public function setTaxId($taxId)
{
$this->taxId = $taxId;
}
/**
* @return string
*/
public function getVatId()
{
return $this->vatId;
}
/**
* @param string $vatId
*/
public function setVatId($vatId)
{
$this->vatId = $vatId;
}
/**
* @return float
*/
public function getVat(): float
{
return $this->vat;
}
/**
* @param $vat
* @return void
*/
public function setVat($vat): void
{
$this->vat = $vat;
}
/**
* @param null|float $totalPrice
* @return float|int|null
*/
public function getVatValueFromTotalPrice($totalPrice = null)
{
if ($this->getVat() > 0) {
$totalPrice = is_null($totalPrice) ? $this->getTotalPrice() : $totalPrice;
return $totalPrice * ($this->getVat() / 100);
}
return 0;
}
/**
* @param null|float $totalVatPrice
* @return float|int|null
*/
public function getVatValueFromTotalVatPrice($totalVatPrice = null)
{
if ($this->getVat() > 0) {
$totalVatPrice = is_null($totalVatPrice) ? $this->getTotalVatPrice() : $totalVatPrice;
return $totalVatPrice - $totalVatPrice / ((100 + $this->getVat()) / 100);
}
return 0;
}
/**
* @return boolean
*/
public function isShipAddressSame()
{
return $this->shipAddressSame;
}
/**
* @param boolean $shipAddressSame
*/
public function setShipAddressSame($shipAddressSame)
{
$this->shipAddressSame = $shipAddressSame;
}
/**
* @return string
*/
public function getShipBusinessName()
{
return $this->shipBusinessName;
}
/**
* @param string $shipBusinessName
*/
public function setShipBusinessName($shipBusinessName)
{
$this->shipBusinessName = $shipBusinessName;
}
/**
* @return string
*/
public function getShipDegree()
{
return $this->shipDegree;
}
/**
* @param string $shipDegree
*/
public function setShipDegree($shipDegree)
{
$this->shipDegree = $shipDegree;
}
/**
* @return string
*/
public function getShipFirstName()
{
return $this->shipFirstName;
}
/**
* @param string $shipFirstName
*/
public function setShipFirstName($shipFirstName)
{
$this->shipFirstName = $shipFirstName;
}
/**
* @return string
*/
public function getShipLastName()
{
return $this->shipLastName;
}
/**
* @param string $shipLastName
*/
public function setShipLastName($shipLastName)
{
$this->shipLastName = $shipLastName;
}
/**
* @return string
*/
public function getShipStreet()
{
return $this->shipStreet;
}
/**
* @param string $shipStreet
*/
public function setShipStreet($shipStreet)
{
$this->shipStreet = $shipStreet;
}
/**
* @return string
*/
public function getShipCity()
{
return $this->shipCity;
}
/**
* @param string $shipCity
*/
public function setShipCity($shipCity)
{
$this->shipCity = $shipCity;
}
/**
* @return string
*/
public function getShipZip()
{
return $this->shipZip;
}
/**
* @param string $shipZip
*/
public function setShipZip($shipZip)
{
$this->shipZip = $shipZip;
}
/**
* @return string
*/
public function getShipCountry()
{
return $this->shipCountry;
}
/**
* @param string $shipCountry
*/
public function setShipCountry($shipCountry)
{
$this->shipCountry = $shipCountry;
}
/**
* @return string
*/
public function getShipPhone()
{
return $this->shipPhone;
}
/**
* @param string $shipPhone
*/
public function setShipPhone($shipPhone)
{
$this->shipPhone = $shipPhone;
}
/**
* @return string
*/
public function getAttachment()
{
return $this->attachment;
}
/**
* @param string $attachment
*/
public function setAttachment($attachment)
{
$this->attachment = $attachment;
}
/**
* @return float
*/
public function getTotalPrice()
{
return $this->totalPrice;
}
/**
* @param float $totalPrice
*/
public function setTotalPrice($totalPrice)
{
$this->totalPrice = str_replace(',', '.', $totalPrice);
}
/**
* @return float
*/
public function getTotalVatPrice()
{
return $this->totalVatPrice;
}
/**
* @param float $totalVatPrice
*/
public function setTotalVatPrice($totalVatPrice)
{
$this->totalVatPrice = str_replace(',', '.', $totalVatPrice);
}
/**
* @return float
*/
public function getPaidPrice()
{
return $this->paidPrice;
}
/**
* @param float $paidPrice
*/
public function setPaidPrice($paidPrice)
{
$this->paidPrice = $paidPrice;
}
/**
* @return float
*/
public function getPaidVatPrice()
{
return $this->paidVatPrice;
}
/**
* @param float $paidVatPrice
*/
public function setPaidVatPrice($paidVatPrice)
{
$this->paidVatPrice = $paidVatPrice;
}
/**
* @param string $paidPrice
*/
public function setPaidPrices($paidPrice)
{
$this->setPaidPrice($paidPrice);
$this->setPaidVatPrice($this->getCompany()->createVatPrice($this->getPaidPrice(), $this->getVat()));
}
/**
* @return float
*/
public function getExchangeRate()
{
return $this->exchangeRate;
}
/**
* @param float $exchangeRate
*
* @return Document
*/
public function setExchangeRate($exchangeRate)
{
$this->exchangeRate = $exchangeRate;
return $this;
}
/**
* @return string
*/
public function getCurrency()
{
return $this->currency;
}
/**
* @param string $currency
*
* @return Document
*/
public function setCurrency($currency)
{
$this->currency = $currency;
return $this;
}
/**
* @return User
*/
public function getSignedBy()
{
return $this->signedBy;
}
/**
* @param User $signedBy
*/
public function setSignedBy($signedBy)
{
$this->signedBy = $signedBy;
}
/**
* @return bool
*/
public function getSignedAnonymously()
{
return $this->signedAnonymously;
}
/**
* @param bool $signedAnonymously
*/
public function setSignedAnonymously(bool $signedAnonymously)
{
$this->signedAnonymously = $signedAnonymously;
}
/**
* @return string
*/
public function getNote()
{
return $this->note;
}
/**
* @param string $note
* @return Document
*/
public function setNote($note)
{
$this->note = $note;
return $this;
}
/**
* @return int
*/
public function getWarranty()
{
return $this->warranty;
}
/**
* @param int $warranty
*/
public function setWarranty($warranty)
{
return $this->warranty = $warranty;
}
/**
* @return boolean
*/
public function isQtyInWeight()
{
return $this->qtyInWeight;
}
/**
* @param boolean $qtyInWeight
*/
public function setQtyInWeight($qtyInWeight)
{
$this->qtyInWeight = $qtyInWeight;
}
public function getItems()
{
return $this->items;
}
/**
* @param DocumentItem $item
*/
public function addItem($item)
{
if (!$this->items->contains($item)) {
$this->items->add($item);
}
}
/**
* @param DocumentItem $item
*/
public function removeMovementItem($item)
{
$this->items->removeElement($item);
}
/**
* @return void
*/
public function clearItems(): void
{
$this->items = new ArrayCollection();
}
/**
* @return ArrayCollection
*/
public function getPayments()
{
return $this->payments;
}
/**
* @return Company
*/
public function getCompany()
{
return $this->getGroup()->getCompany();
}
/**
* Set dueDate by numbers left for paying document
*
* @PrePersist
* @PreUpdate
*/
public function setDueDateByDueInDays()
{
$date = new \DateTime($this->createdDate->format('Y-m-d'));
$this->dueDate = $date->add(new \DateInterval('P' . $this->dueInDays . 'D'));
}
/**
* @PreUpdate
* @param PreUpdateEventArgs $eventArgs
*/
public function updateStatus(PreUpdateEventArgs $eventArgs)
{
if (!$eventArgs->getObject() instanceof Document) {
return;
}
if (
$eventArgs->hasChangedField('totalVatPrice')
&& $eventArgs->getOldValue('totalVatPrice') != $eventArgs->getNewValue('totalVatPrice')
&& $this->getStatus() != self::STATUS_PAID
) {
if ($this->dueDate < new \DateTime()) {
$this->setStatus(self::STATUS_POST_DUE_DATE);
} else {
$this->setStatus(self::STATUS_NEW);
}
}
if ($eventArgs->hasChangedField('dueInDays') && $this->getStatus() != self::STATUS_PAID) {
if ($this->dueDate < new \DateTime()) {
$this->setStatus(self::STATUS_POST_DUE_DATE);
} else {
$this->setStatus(self::STATUS_NEW);
}
}
}
/**
* @return int
*/
public function getStatus()
{
return $this->status;
}
/**
* @param int $status
*/
public function setStatus($status)
{
$this->status = $status;
}
/**
* @return int
*/
public function getAllItemQuantity()
{
$allQuantity = 0;
foreach ($this->getItems() as $item) {
$allQuantity += $item->getQuantity();
}
return $allQuantity;
}
/**
* @return mixed
*/
public function getStatusTitle()
{
return self::getStatusChoices()[$this->getStatus()];
}
/**
* @return bool
* @throws \Exception
*/
public function isLocked(): bool
{
$groupType = $this->getGroup()->getType();
if ($groupType == DocumentGroup::TYPE_INVOICE_IN && $this->isPaymentApproved()) {
return true;
}
/**
* temporary disabled
*/
// if (!is_null($this->sentDate)){
// return true;
// }
$lockBeforeDate = (new \DateTime())
->setTime(0, 0)
->sub(new \DateInterval('P' . self::LOCKED_AFTER_DAYS . 'D'))
;
return in_array($groupType, self::DOCUMENT_TYPE_TO_LOCK) && $this->getCreatedDate() < $lockBeforeDate;
}
/**
* @return ArrayCollection
*/
public function getProducts(): ArrayCollection
{
$products = new ArrayCollection();
foreach ($this->getItems() as $item) {
$product = $item->getProduct();
if (!is_null($product) && !$products->contains($product)) {
$products->add($product);
}
}
return $products;
}
public function calculateAndSetTotalPrices()
{
$totalVatPrice = 0;
foreach ($this->getItems() as $item) {
if ($item->getParent() != null) {
continue;
}
$totalVatPrice += $item->getVatItemFullPrice();
}
$totalVatPrice = round($totalVatPrice, 2);
$totalPrice = $totalVatPrice / Domain::getVatMultiplier($this->getVat());
$totalPrice = round($totalPrice, 2);
$this->setTotalVatPrice($totalVatPrice);
$this->setTotalPrice($totalPrice);
}
/**
* @return ArrayCollection
*/
public function getStockItems()
{
$stockItems = new ArrayCollection();
if (!is_null($this->getStockMovement())) {
foreach ($this->getStockMovement()->getMovementItems() as $movementItem) {
foreach ($movementItem->getStockItems() as $stockItem) {
if (!$stockItems->contains($stockItem)) {
$stockItems->add($stockItem);
}
}
}
}
return $stockItems;
}
/**
* @return \DateTime
*/
public function getSentDate()
{
return $this->sentDate;
}
/**
* @param \DateTime $sentDate
*/
public function setSentDate($sentDate)
{
$this->sentDate = $sentDate;
}
/**
* @return void
*/
public function removeSentDate()
{
$this->sentDate = null;
}
/**
* @return ArrayCollection
*/
public function getPaymentDatas()
{
return $this->paymentDatas;
}
/**
* @return bool
*/
public function isPaymentApproved(): bool
{
return $this->paymentApproved;
}
/**
* @param bool $paymentApproved
*/
public function setPaymentApproved(bool $paymentApproved): void
{
$this->paymentApproved = $paymentApproved;
}
/**
* @return User|null
*/
public function getPaymentApprovedBy(): ?User
{
return $this->paymentApprovedBy;
}
/**
* @param User|null $paymentApprovedBy
*/
public function setPaymentApprovedBy(?User $paymentApprovedBy): void
{
$this->paymentApprovedBy = $paymentApprovedBy;
}
/**
* @return \DateTime|null
*/
public function getPaymentApprovedDate(): ?\DateTime
{
return $this->paymentApprovedDate;
}
/**
* @param \DateTime|null $paymentApprovedDate
*/
public function setPaymentApprovedDate(?\DateTime $paymentApprovedDate): void
{
$this->paymentApprovedDate = $paymentApprovedDate;
}
/**
* @return string|null
*/
public function getPohodaNumber(): ?string
{
return $this->pohodaNumber;
}
/**
* @param string|null $pohodaNumber
*/
public function setPohodaNumber(string $pohodaNumber)
{
$this->pohodaNumber = $pohodaNumber;
}
/**
* @return string|null
*/
public function getShipmentNumber(): ?string
{
return $this->shipmentNumber;
}
/**
* @param string|null $shipmentNumber
*/
public function setShipmentNumber(string $shipmentNumber)
{
$this->shipmentNumber = $shipmentNumber;
}
/**
* @return ArrayCollection
*/
public function getComments()
{
return $this->comments;
}
/**
* @param ArrayCollection $comments
*/
public function setComments($comments)
{
$this->comments = $comments;
}
/**
* @return OrderSetting|null
*/
public function getEuPersonalTaxId(): ?OrderSetting
{
return $this->order && $this->group->getType() == DocumentGroup::TYPE_INVOICE_OUT ? $this->order->getEuPersonalTaxIdSetting() : null;
}
/**
* @return string|null
*/
public function getAccountNumber(): ?string
{
return $this->accountNumber;
}
/**
* @param string|null $accountNumber
* @return void
*/
public function setAccountNumber(?string $accountNumber): void
{
$this->accountNumber = $accountNumber;
}
/**
* @return Shipment|null
*/
public function getShipment(): ?Shipment
{
return $this->shipment;
}
/**
* @param Shipment|null $shipment
* @return void
*/
public function setShipment(?Shipment $shipment): void
{
$this->shipment = $shipment;
}
}