mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
229 lines
4.2 KiB
PHP
229 lines
4.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\AMLI\BudgetBundle\Entity;
|
|
|
|
use Chill\PersonBundle\Entity\Person;
|
|
use DateTime;
|
|
use DateTimeImmutable;
|
|
use DateTimeInterface;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
/**
|
|
* AbstractElement.
|
|
*
|
|
* @ORM\MappedSuperclass
|
|
*/
|
|
abstract class AbstractElement
|
|
{
|
|
/**
|
|
* @var decimal
|
|
*
|
|
* @ORM\Column(name="amount", type="decimal", precision=10, scale=2)
|
|
* @Assert\GreaterThan(
|
|
* value=0
|
|
* )
|
|
* @Assert\NotNull(
|
|
* message="The amount cannot be empty"
|
|
* )
|
|
*/
|
|
private $amount;
|
|
|
|
/**
|
|
* @var string|null
|
|
*
|
|
* @ORM\Column(name="comment", type="text", nullable=true)
|
|
*/
|
|
private $comment;
|
|
|
|
/**
|
|
* @var DateTimeImmutable|null
|
|
*
|
|
* @ORM\Column(name="endDate", type="datetime_immutable", nullable=true)
|
|
* @Assert\GreaterThan(
|
|
* propertyPath="startDate",
|
|
* message="The budget element's end date must be after the start date"
|
|
* )
|
|
*/
|
|
private $endDate;
|
|
|
|
/**
|
|
* @var Person
|
|
* @ORM\ManyToOne(
|
|
* targetEntity="\Chill\PersonBundle\Entity\Person"
|
|
* )
|
|
*/
|
|
private $person;
|
|
|
|
/**
|
|
* @var DateTimeImmutable
|
|
*
|
|
* @ORM\Column(name="startDate", type="datetime_immutable")
|
|
* @Assert\Date
|
|
*/
|
|
private $startDate;
|
|
|
|
/**
|
|
* @var string
|
|
*
|
|
* @ORM\Column(name="type", type="string", length=255)
|
|
*/
|
|
private $type;
|
|
|
|
/**
|
|
* Get amount.
|
|
*
|
|
* @return float
|
|
*/
|
|
public function getAmount()
|
|
{
|
|
return (float) $this->amount;
|
|
}
|
|
|
|
/**
|
|
* Get comment.
|
|
*
|
|
* @return string|null
|
|
*/
|
|
public function getComment()
|
|
{
|
|
return $this->comment;
|
|
}
|
|
|
|
/**
|
|
* Get endDate.
|
|
*
|
|
* @return DateTimeImmutable|null
|
|
*/
|
|
public function getEndDate()
|
|
{
|
|
return $this->endDate;
|
|
}
|
|
|
|
public function getPerson(): Person
|
|
{
|
|
return $this->person;
|
|
}
|
|
|
|
/**
|
|
* Get startDate.
|
|
*
|
|
* @return DateTimeImmutable
|
|
*/
|
|
public function getStartDate()
|
|
{
|
|
return $this->startDate;
|
|
}
|
|
|
|
/**
|
|
* Get type.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getType()
|
|
{
|
|
return $this->type;
|
|
}
|
|
|
|
abstract public function isCharge(): bool;
|
|
|
|
public function isEmpty()
|
|
{
|
|
return 0 == $this->amount;
|
|
}
|
|
|
|
abstract public function isResource(): bool;
|
|
|
|
/**
|
|
* Set amount.
|
|
*
|
|
* @param string $amount
|
|
*
|
|
* @return AbstractElement
|
|
*/
|
|
public function setAmount($amount)
|
|
{
|
|
$this->amount = $amount;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set comment.
|
|
*
|
|
* @param string|null $comment
|
|
*
|
|
* @return AbstractElement
|
|
*/
|
|
public function setComment($comment = null)
|
|
{
|
|
$this->comment = $comment;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set endDate.
|
|
*
|
|
* @return AbstractElement
|
|
*/
|
|
public function setEndDate(?DateTimeInterface $endDate = null)
|
|
{
|
|
if ($endDate instanceof DateTime) {
|
|
$this->endDate = DateTimeImmutable::createFromMutable($endDate);
|
|
} elseif (null === $endDate) {
|
|
$this->endDate = null;
|
|
} else {
|
|
$this->endDate = $endDate;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setPerson(Person $person)
|
|
{
|
|
$this->person = $person;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set startDate.
|
|
*
|
|
* @return AbstractElement
|
|
*/
|
|
public function setStartDate(DateTimeInterface $startDate)
|
|
{
|
|
if ($startDate instanceof DateTime) {
|
|
$this->startDate = DateTimeImmutable::createFromMutable($startDate);
|
|
} elseif (null === $startDate) {
|
|
$this->startDate = null;
|
|
} else {
|
|
$this->startDate = $startDate;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set type.
|
|
*
|
|
* @param string $type
|
|
*
|
|
* @return AbstractElement
|
|
*/
|
|
public function setType($type)
|
|
{
|
|
$this->type = $type;
|
|
|
|
return $this;
|
|
}
|
|
}
|