<?php
namespace App\Entity;
use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
use AppBundle\Entity\Article;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="user_address")
* @ORM\HasLifecycleCallbacks
*/
class Address implements BlameableInterface, TimestampableInterface, SoftDeletableInterface {
use BlameableTrait;
use TimestampableTrait;
use SoftDeletableTrait;
//powiązane z kontem użytkownika
const ADDRESS_TYPE_DELIVERY = 'delivery';
const ADDRESS_TYPE_INVOICE = 'invoice';
//powiązane już z konkretnym adresem z zamówienia
const ADDRESS_TYPE_ORDER = 'delivery_order';
const ADDRESS_TYPE_ORDER_INVOICE = 'invoice_order';
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="address")
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Order", inversedBy="address")
*/
private $order;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\RoJudet")
*/
private $roJudet;
/**
* @var string
*
* @ORM\Column(name="street", type="string", length=255, nullable=true)
* @Assert\NotBlank(message = "Wpisz nazwę ulicy")
*/
protected $street;
/**
* @var string
*
* @ORM\Column(name="firstname", type="string", length=255, nullable=true)
*/
private $firstname;
/**
* @var string
*
* @ORM\Column(name="surname", type="string", length=255, nullable=true)
*/
private $surname;
/**
* @var string
*
* @ORM\Column(name="street_housenum", type="string", length=255, nullable=true)
*/
protected $streetHousenum;
/**
* @var string
*
* @ORM\Column(name="street_flatnum", type="string", length=255, nullable=true)
*/
protected $streetFlatnum;
/**
* @var string
*
* @ORM\Column(name="citycode", type="string", length=255, nullable=true)
*/
protected $citycode;
/**
* @var string
*
* @ORM\Column(name="city", type="string", length=255, nullable=true)
* @Assert\NotBlank(message = "Wpisz nazwę miejscowości")
*/
protected $city;
/**
* @var string
*
* @ORM\Column(name="mail", type="string", length=255, nullable=true)
*/
protected $mail;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=255, nullable=true)
*/
protected $email;
/**
* @var string
*
* @ORM\Column(name="telephone", type="string", length=255, nullable=true)
*/
private $telephone;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Country")
* @ORM\JoinColumn(name="country_id", referencedColumnName="id")
*/
protected $country;
/**
* Domyślny
* @Doctrine\ORM\Mapping\Column(type="boolean", nullable=true, options={"default"=0})
*/
protected $isDefault;
/**
* @var string
*
* @ORM\Column(name="company_name", type="string", length=255, nullable=true)
*/
private $companyName;
/**
* @var string
*
* @ORM\Column(name="vat_id", type="string", length=255, nullable=true)
*/
private $vatId;
/**
* @var string
*
* @ORM\Column(name="regon", type="string", length=255, nullable=true)
*/
private $regon;
/**
* @var string
*
* @ORM\Column(name="bank_account", type="string", length=255, nullable=true)
*/
private $bankAccount;
/**
* @var string
*
* @ORM\Column(name="iban", type="string", length=255, nullable=true)
*/
private $iban;
/**
* @var string
*
* @ORM\Column(name="address_type", type="string", length=255, nullable=true)
*/
private $addressType;
public function getCustomerId() {
if ($this->getVatId()) {
return $this->getVatId();
}
return 'brak';
}
public function jpkAddress() {
$beginning = '';
$address = $beginning.''.$this->street . ' ' . $this->streetHousenum . '<br/>'.
( $this->streetFlatnum ? '/' . $this->streetFlatnum : '' )
. ' ' . $this->citycode . ' ' . $this->city
;
return $address;
}
public function getCustomerName() {
if ($this->getCompanyName()) {
return $this->getCompanyName();
}
return $this->getFirstname().' '.$this->getSurname();
}
public function __construct()
{
$this->addressType = self::ADDRESS_TYPE_DELIVERY;
}
public function __toString()
{
$adres = $this->firstname.' '.$this->surname.'<br/>'.$this->street . ' ' . $this->streetHousenum . '<br/>'.
( $this->streetFlatnum ? '/' . $this->streetFlatnum : '' )
. '' . $this->citycode . ' ' . $this->city;
if ($this->getRoJudet()) {
$adres .= '<br/>Județ: '.$this->getRoJudet()->getName();
}
return $adres;
}
public function getInvoiceAddress($locale = 'pl') {
if ($this->companyName) {
$beginning = $this->companyName;
} else {
$beginning = $this->firstname.' '.$this->surname;
}
$address = $beginning.'<br/>'.$this->street . ' ' . $this->streetHousenum . '<br/>'.
( $this->streetFlatnum ? '/' . $this->streetFlatnum : '' )
. '' . $this->citycode . ' ' . $this->city
;
if ($this->getRoJudet()) {
$address .= '<br/>Județ: '.$this->getRoJudet()->getName();
}
if ($locale == 'pl') {
if ($this->vatId) {
$address .= '<br/>NIP: '.$this->vatId;
}
} elseif ($locale == 'ro') {
if ($this->vatId) {
$address .= '<br/>CIF: '.$this->vatId;
}
if ($this->regon) {
$address .= '<br/>Nr.ord.Reg.Com: '.$this->regon;
}
if ($this->bankAccount) {
$address .= '<br/>Bancă: '.$this->bankAccount;
}
if ($this->iban) {
$address .= '<br/>Cont IBAN: '.$this->iban;
}
} elseif ($locale == 'cz') {
if ($this->vatId) {
$address .= '<br/>DIČ: '.$this->vatId;
}
if ($this->regon) {
$address .= '<br/>IČO: '.$this->regon;
}
}
return $address;
}
/**
* Set street
*
* @param string $street
*
* @return Address
*/
public function setStreet($street)
{
$this->street = $street;
return $this;
}
/**
* Get street
*
* @return string
*/
public function getStreet()
{
return $this->street;
}
/**
* Set citycode
*
* @param string $citycode
*
* @return Address
*/
public function setCitycode($citycode)
{
$this->citycode = $citycode;
return $this;
}
/**
* Get citycode
*
* @return string
*/
public function getCitycode()
{
return $this->citycode;
}
/**
* Set city
*
* @param string $city
*
* @return Address
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get city
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set mail
*
* @param string $mail
*
* @return Address
*/
public function setMail($mail)
{
$this->mail = $mail;
return $this;
}
/**
* Get mail
*
* @return string
*/
public function getMail()
{
return $this->mail;
}
/**
* Set telephone
*
* @param string $telephone
*
* @return Address
*/
public function setTelephone($telephone)
{
$this->telephone = $telephone;
return $this;
}
/**
* Get telephone
*
* @return string
*/
public function getTelephone()
{
return $this->telephone;
}
/**
* Set country
*
* @param string $country
*
* @return Address
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* @return string
*/
public function getCountry()
{
return $this->country;
}
/**
* Set user
*
* @param \App\Entity\User $user
*
* @return Address
*/
public function setUser(\App\Entity\User $user = null)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return \App\Entity\User
*/
public function getUser()
{
return $this->user;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set streetHousenum
*
* @param string $streetHousenum
*
* @return Address
*/
public function setStreetHousenum($streetHousenum)
{
$this->streetHousenum = $streetHousenum;
return $this;
}
/**
* Get streetHousenum
*
* @return string
*/
public function getStreetHousenum()
{
return $this->streetHousenum;
}
/**
* Set streetFlatnum
*
* @param string $streetFlatnum
*
* @return Address
*/
public function setStreetFlatnum($streetFlatnum)
{
$this->streetFlatnum = $streetFlatnum;
return $this;
}
/**
* Get streetFlatnum
*
* @return string
*/
public function getStreetFlatnum()
{
return $this->streetFlatnum;
}
/**
* Set email
*
* @param string $email
*
* @return Address
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set isDefault
*
* @param boolean $isDefault
*
* @return Address
*/
public function setIsDefault($isDefault)
{
$this->isDefault = $isDefault;
return $this;
}
/**
* Get isDefault
*
* @return boolean
*/
public function getIsDefault()
{
return $this->isDefault;
}
/**
* Set companyName
*
* @param string $companyName
*
* @return Address
*/
public function setCompanyName($companyName)
{
$this->companyName = $companyName;
return $this;
}
/**
* Get companyName
*
* @return string
*/
public function getCompanyName()
{
return $this->companyName;
}
/**
* Set vatId
*
* @param string $vatId
*
* @return Address
*/
public function setVatId($vatId)
{
$this->vatId = $vatId;
return $this;
}
/**
* Get vatId
*
* @return string
*/
public function getVatId()
{
return $this->vatId;
}
/**
* Set addressType
*
* @param string $addressType
*
* @return Address
*/
public function setAddressType($addressType)
{
$this->addressType = $addressType;
return $this;
}
/**
* Get addressType
*
* @return string
*/
public function getAddressType()
{
return $this->addressType;
}
/**
* Set firstname
*
* @param string $firstname
*
* @return Address
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
return $this;
}
/**
* Get firstname
*
* @return string
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* Set surname
*
* @param string $surname
*
* @return Address
*/
public function setSurname($surname)
{
$this->surname = $surname;
return $this;
}
/**
* Get surname
*
* @return string
*/
public function getSurname()
{
return $this->surname;
}
/**
* @return string
*/
public function getRegon()
{
return $this->regon;
}
/**
* @param string $regon
*/
public function setRegon($regon)
{
$this->regon = $regon;
}
/**
* @return string
*/
public function getBankAccount()
{
return $this->bankAccount;
}
/**
* @param string $bankAccount
*/
public function setBankAccount($bankAccount)
{
$this->bankAccount = $bankAccount;
}
/**
* @return string
*/
public function getIban()
{
return $this->iban;
}
/**
* @param string $iban
*/
public function setIban($iban)
{
$this->iban = $iban;
}
/**
* Set roJudet
*
* @param \App\Entity\RoJudet $roJudet
*
* @return Address
*/
public function setRoJudet(\App\Entity\RoJudet $roJudet = null)
{
$this->roJudet = $roJudet;
return $this;
}
/**
* Get roJudet
*
* @return \App\Entity\RoJudet
*/
public function getRoJudet()
{
return $this->roJudet;
}
public function getOrder(): ?Order
{
return $this->order;
}
public function setOrder(?Order $order): self
{
$this->order = $order;
return $this;
}
}