<?php
namespace AdminBundle\Entity;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Account
*/
#[ORM\Table(name: 'account')]
#[ORM\Entity(repositoryClass: \AdminBundle\Repository\AccountRepository::class)]
#[ORM\HasLifecycleCallbacks]
class Account extends BaseEntity
{
const ACCOUNT_FILE_FOLDER = 'upload/account/';
const ACCOUNT_BADGES_FILE_FOLDER = 'upload/account/badges/';
const EMPLOYER_TYPE_HOSPITAL = 0;
const EMPLOYER_TYPE_SUPERMARKET = 1;
const EMPLOYER_TYPE_FIRE_DEPARTMENT = 2;
const EMPLOYER_TYPES = [
self::EMPLOYER_TYPE_HOSPITAL => 'Hospital',
self::EMPLOYER_TYPE_SUPERMARKET => 'Supermarket',
self::EMPLOYER_TYPE_FIRE_DEPARTMENT => 'Fire department',
];
const BADGE_PROOF_PICTURE_SETTER = 'setBadgeProofPicture';
/**
* @var int
*/
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
/**
* @var string
*/
#[ORM\Column(name: 'title', type: 'string', length: 255)]
private $title;
/**
* @var DateTime
*/
#[ORM\Column(name: 'birth_date', type: 'date', nullable: true)]
private $birthDate;
/**
* @var string
*/
#[ORM\Column(name: 'name', type: 'string', length: 255)]
private $name;
/**
* @var string
*/
#[ORM\Column(name: 'phone', type: 'string', length: 20)]
private $phone;
/**
* @var string
*/
#[ORM\Column(name: 'email', type: 'string', length: 255, nullable: true)]
private $email;
/**
* @var string
*/
#[ORM\Column(name: 'department', type: 'string', length: 255, nullable: true)]
private $department;
/**
* @var string
*/
#[ORM\Column(name: 'job_title', type: 'string', length: 255, nullable: true)]
private $jobTitle;
/**
* @var string
*/
#[ORM\Column(name: 'ba_address1', type: 'string', length: 255, nullable: true)]
private $baAddress1;
/**
* @var string
*/
#[ORM\Column(name: 'ba_address2', type: 'string', length: 255, nullable: true)]
private $baAddress2;
/**
* @var string
*/
#[ORM\Column(name: 'ba_door_number', type: 'string', length: 255, nullable: true)]
private $baDoorNumber;
/**
* @var string
*/
#[ORM\Column(name: 'ba_store_apt', type: 'string', length: 255, nullable: true)]
private $baStoreApt;
/**
* @var string
*/
#[ORM\Column(name: 'ba_city', type: 'string', length: 255, nullable: true)]
private $baCity;
/**
* @var string
*/
#[ORM\Column(name: 'ba_postcode', type: 'string', length: 255, nullable: true)]
private $baPostcode;
/**
* @var string
*/
#[ORM\Column(name: 'ba_country', type: 'string', length: 255, nullable: true)]
private $baCountry;
/**
* @var string
*/
#[ORM\Column(name: 'picture', type: 'string', length: 255, nullable: true)]
private $picture;
/**
* @var UploadedFile
*/
#[Assert\File(mimeTypes: ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'])]
private $pictureFile;
/**
* @var string
*/
#[ORM\Column(name: 'notes', type: 'text', nullable: true)]
private $notes;
/**
* @var float
*/
#[ORM\Column(name: 'credit', type: 'float', nullable: true)]
private $credit;
/**
* @var DateTime
*/
#[ORM\Column(name: 'creation_date', type: 'datetime')]
private $creationDate;
/**
* @var DateTime
*/
#[ORM\Column(name: 'updated', type: 'datetime')]
protected $updated;
/**
* @var GroupAccounts
*/
#[ORM\JoinColumn(name: 'group_account_id', referencedColumnName: 'id', onDelete: 'SET NULL')]
#[ORM\ManyToOne(targetEntity: \GroupAccounts::class, inversedBy: 'accounts')]
private $group;
/**
* @var Company
*/
#[ORM\JoinColumn(name: 'company_id', referencedColumnName: 'id', onDelete: 'SET NULL')]
#[ORM\ManyToOne(targetEntity: \Company::class, inversedBy: 'accounts')]
private $company;
/**
* @var User
*/
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'SET NULL')]
#[ORM\OneToOne(targetEntity: \User::class, inversedBy: 'account', cascade: ['all'])]
protected $user;
/**
* @var ClientInvoices
*/
#[ORM\OneToMany(targetEntity: \AdminBundle\Entity\ClientInvoices::class, mappedBy: 'client', cascade: ['persist', 'remove'], orphanRemoval: true)]
protected $clientInvoices;
/**
* @var string
*/
#[ORM\Column(name: 'employer_name', type: 'string', length: 255, nullable: true)]
protected $employerName;
/**
* @var string
*/
#[ORM\Column(name: 'employer_phone', type: 'string', length: 255, nullable: true)]
protected $employerPhone;
/**
* @var string
*/
#[ORM\Column(name: 'employer_type', type: 'integer', length: 255, nullable: true)]
protected $employerType;
/**
* @var string
*/
#[ORM\Column(name: 'workplace_postcode', type: 'string', length: 255, nullable: true)]
protected $workplacePostcode;
/**
* @var string
*/
#[ORM\Column(name: 'badge_proof_picture', type: 'string', length: 255, nullable: true)]
private $badgeProofPicture;
/**
* @var UploadedFile
*/
#[Assert\File(mimeTypes: ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'])]
private $badgeProofPictureFile;
/**
* @var string
*/
#[ORM\Column(name: 'worker_voucher_usage', type: 'integer', length: 255, nullable: true)]
protected $workerVoucherUsage;
/**
* @var DateTime
*/
#[ORM\Column(name: 'last_used_worker_voucher', type: 'datetime', nullable: true)]
protected $lastUsedWorkerVoucher;
public function __construct()
{
$this->creationDate = new DateTime();
$this->updated = new DateTime();
$this->clientInvoices = new ArrayCollection();
$this->credit = 0;
$this->workerVoucherUsage = 0;
}
/**
* @return GroupAccounts
*/
public function getGroup()
{
return $this->group;
}
/**
* @param GroupAccounts $group
* @return Account
*/
public function setGroup($group)
{
$this->group = $group;
return $this;
}
/**
* @return Company
*/
public function getCompany()
{
return $this->company;
}
/**
* @param Company $company
* @return Account
*/
public function setCompany($company)
{
$this->company = $company;
return $this;
}
/**
* @return UploadedFile|null
*/
public function getPictureFile()
{
return $this->pictureFile;
}
/**
* @param UploadedFile $pictureFile
* @return $this
*/
public function setPictureFile($pictureFile)
{
$this->pictureFile = $pictureFile;
$this->setUpdated(new DateTime());
return $this;
}
/**
* @return DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* @param DateTime $updated
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
*
* @return Account
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set birthDate
*
* @param DateTime $birthDate
*
* @return Account
*/
public function setBirthDate($birthDate)
{
$this->birthDate = $birthDate;
return $this;
}
/**
* Get birthDate
*
* @return DateTime
*/
public function getBirthDate()
{
return $this->birthDate;
}
/**
* Set name
*
* @param string $name
*
* @return Account
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set phone
*
* @param string $phone
*
* @return Account
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set email
*
* @param string $email
*
* @return Account
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set department
*
* @param string $department
*
* @return Account
*/
public function setDepartment($department)
{
$this->department = $department;
return $this;
}
/**
* Get department
*
* @return string
*/
public function getDepartment()
{
return $this->department;
}
/**
* Set jobTitle
*
* @param string $jobTitle
*
* @return Account
*/
public function setJobTitle($jobTitle)
{
$this->jobTitle = $jobTitle;
return $this;
}
/**
* Get jobTitle
*
* @return string
*/
public function getJobTitle()
{
return $this->jobTitle;
}
/**
* Set baAddress1
*
* @param string $baAddress1
*
* @return Account
*/
public function setBaAddress1($baAddress1)
{
$this->baAddress1 = $baAddress1;
return $this;
}
/**
* Get baAddress1
*
* @return string
*/
public function getBaAddress1()
{
return $this->baAddress1;
}
/**
* Set baAddress2
*
* @param string $baAddress2
*
* @return Account
*/
public function setBaAddress2($baAddress2)
{
$this->baAddress2 = $baAddress2;
return $this;
}
/**
* Get baAddress2
*
* @return string
*/
public function getBaAddress2()
{
return $this->baAddress2;
}
/**
* Set baDoorNumber
*
* @param string $baDoorNumber
*
* @return Account
*/
public function setBaDoorNumber($baDoorNumber)
{
$this->baDoorNumber = $baDoorNumber;
return $this;
}
/**
* Get baDoorNumber
*
* @return string
*/
public function getBaDoorNumber()
{
return $this->baDoorNumber;
}
/**
* Set baStoreApt
*
* @param string $baStoreApt
*
* @return Account
*/
public function setBaStoreApt($baStoreApt)
{
$this->baStoreApt = $baStoreApt;
return $this;
}
/**
* Get baStoreApt
*
* @return string
*/
public function getBaStoreApt()
{
return $this->baStoreApt;
}
/**
* Set baCity
*
* @param string $baCity
*
* @return Account
*/
public function setBaCity($baCity)
{
$this->baCity = $baCity;
return $this;
}
/**
* Get baCity
*
* @return string
*/
public function getBaCity()
{
return $this->baCity;
}
/**
* Set baPostcode
*
* @param string $baPostcode
*
* @return Account
*/
public function setBaPostcode($baPostcode)
{
$this->baPostcode = $baPostcode;
return $this;
}
/**
* Get baPostcode
*
* @return string
*/
public function getBaPostcode()
{
return $this->baPostcode;
}
/**
* Set baCountry
*
* @param string $baCountry
*
* @return Account
*/
public function setBaCountry($baCountry)
{
$this->baCountry = $baCountry;
return $this;
}
/**
* Get baCountry
*
* @return string
*/
public function getBaCountry()
{
return $this->baCountry;
}
/**
* Set picture
*
* @param string $picture
*
* @return Account
*/
public function setPicture($picture)
{
$this->picture = $picture;
return $this;
}
/**
* Get picture
*
* @return string
*/
public function getPicture()
{
return $this->picture;
}
/**
* Set notes
*
* @param string $notes
*
* @return Account
*/
public function setNotes($notes)
{
$this->notes = $notes;
return $this;
}
/**
* Get notes
*
* @return string
*/
public function getNotes()
{
return $this->notes;
}
/**
* Set credit
*
* @param float $credit
*
* @return Account
*/
public function setCredit($credit)
{
$this->credit = $credit;
return $this;
}
/**
* Get credit
*
* @return float
*/
public function getCredit()
{
return empty($this->credit) ? 0 : $this->credit;
}
/**
* Set creationDate
*
* @param DateTime $creationDate
*
* @return Account
*/
public function setCreationDate($creationDate)
{
$this->creationDate = $creationDate;
return $this;
}
/**
* Get creationDate
*
* @return DateTime
*/
public function getCreationDate()
{
return $this->creationDate;
}
/**
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* @param User $user
* @return Account
*/
public function setUser($user)
{
$this->user = $user;
return $this;
}
protected function getUploadFilePath()
{
return self::ACCOUNT_FILE_FOLDER . $this->getId() . '/';
}
public function getPicturePath()
{
if (!$this->picture) {
return;
}
return $this->getUploadFilePath() . $this->picture;
}
public function uploadPicture()
{
if (null === $this->getPictureFile()) {
return;
}
$this->removePictureFile();
$filename = sha1(uniqid(mt_rand(), true));
$this->picture = $filename . '.' . $this->getPictureFile()->guessExtension();
$this->getPictureFile()->move(
$this->getUploadFilePath(),
$this->picture
);
$this->setPictureFile(null);
}
#[ORM\PreUpdate]
#[ORM\PrePersist]
public function lifecycleFileUpload()
{
$this->uploadPicture();
}
#[ORM\PostRemove]
public function removeUpload()
{
$this->removePictureFile();
}
public function removePictureFile()
{
if ($pictureFile = $this->getPicturePath()) {
@unlink($pictureFile);
}
}
public function __toString()
{
return '[' . $this->getId() . ']' . $this->getName() . '(' . $this->getPhone() . ')';
}
public function getClientInvoices()
{
return $this->clientInvoices;
}
public function addClientInvoices(ClientInvoices $clientInvoices)
{
$this->clientInvoices->add($clientInvoices);
}
/**
* @param string $employerName
*
* @return Account
*/
public function setEmployerName($employerName)
{
$this->employerName = $employerName;
return $this;
}
/**
* @return string
*/
public function getEmployerName()
{
return $this->employerName;
}
/**
* @param string $employerPhone
*
* @return Account
*/
public function setEmployerPhone($employerPhone)
{
$this->employerPhone = $employerPhone;
return $this;
}
/**
* @return string
*/
public function getEmployerPhone()
{
return $this->employerPhone;
}
/**
* @param int $employerType
*
* @return Account
*/
public function setEmployerType($employerType)
{
$this->employerType = $employerType;
return $this;
}
/**
* @return int
*/
public function getEmployerType()
{
return $this->employerType;
}
/**
* @param string $workplacePostcode
*
* @return Account
*/
public function setWorkplacePostcode($workplacePostcode)
{
$this->workplacePostcode = $workplacePostcode;
return $this;
}
/**
* @return string
*/
public function getWorkplacePostcode()
{
return $this->workplacePostcode;
}
/**
* @return UploadedFile|null
*/
public function getBadgeProofPictureFile()
{
return $this->badgeProofPictureFile;
}
/**
* @param UploadedFile $badgeProofPictureFile
*
* @return Account
*/
public function setBadgeProofPictureFile($badgeProofPictureFile)
{
$this->badgeProofPictureFile = $badgeProofPictureFile;
$this->setUpdated(new DateTime());
return $this;
}
/**
* @param string $badgeProofPicture
*
* @return Account
*/
public function setBadgeProofPicture($badgeProofPicture)
{
$this->badgeProofPicture = $badgeProofPicture;
return $this;
}
/**
* @return string
*/
public function getBadgeProofPicture()
{
return $this->badgeProofPicture;
}
public function getBadgeUploadFilePath()
{
return self::ACCOUNT_BADGES_FILE_FOLDER . $this->getId() . '/';
}
public function getBadgePicturePath()
{
if (!$this->badgeProofPicture) {
return;
}
return $this->getBadgeUploadFilePath() . $this->badgeProofPicture;
}
public function uploadBadgePicture()
{
if (!$this->getBadgeProofPictureFile()) {
return;
}
$this->removeBadgePictureFile();
$filename = sha1(uniqid(mt_rand(), true));
$this->badgeProofPicture = $filename . '.' . $this->getBadgeProofPictureFile()->guessExtension();
$this->getBadgeProofPictureFile()->move(
$this->getBadgeUploadFilePath(),
$this->badgeProofPicture
);
$this->setBadgeProofPictureFile(null);
}
#[ORM\PreUpdate]
#[ORM\PrePersist]
public function lifecycleBadgeFileUpload()
{
$this->uploadBadgePicture();
}
#[ORM\PostRemove]
public function removeBadgePictureFile()
{
$this->removeBadgePicture();
}
public function removeBadgePicture()
{
if ($pictureFile = $this->getBadgeUploadFilePath()) {
@unlink($pictureFile);
}
}
/**
* @param int $workerVoucherUsage
*
* @return Account
*/
public function setWorkerVoucherUsage($workerVoucherUsage)
{
$this->workerVoucherUsage = $workerVoucherUsage;
return $this;
}
/**
* @return int
*/
public function getWorkerVoucherUsage()
{
return $this->workerVoucherUsage;
}
/**
* Set lastUsedWorkerVoucher
*
* @param DateTime $lastUsedWorkerVoucher
*
* @return Account
*/
public function setLastUsedWorkerVoucher($lastUsedWorkerVoucher)
{
$this->lastUsedWorkerVoucher = $lastUsedWorkerVoucher;
return $this;
}
/**
* Get lastUsedWorkerVoucher
*
* @return DateTime
*/
public function getLastUsedWorkerVoucher()
{
return $this->lastUsedWorkerVoucher;
}
public static function getEmployerTypes()
{
$types = [];
foreach (self::EMPLOYER_TYPES as $key => $type) {
$types[] = ['id' => $key, 'name' => $type];
}
return $types;
}
/**
* Get activityHistory
*
* @return Array
*/
public static function getActivityHistory()
{
return [];
}
}