src/Entity/Sales/CallOffOrder.php line 58
<?php
namespace App\Entity\Sales;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use App\Dto\Sales\CallOffOrderInput;
use App\Entity\Common as Common;
use App\Entity\Common\Company;
use App\Entity\File\Upload;
use App\Entity\Identity\User;
use App\Processor\Sales\CallOffOrderInputProcessor;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Table(name: 'contract_call_off_order')]
#[ORM\Index(columns: ['file_id'], name: 'contract_call_off_order_file_id_idx')]
#[ORM\Index(columns: ['client_id'], name: 'contract_call_off_order_client_id_idx')]
#[ORM\Index(columns: ['created_by'], name: 'contract_call_off_order_created_by_idx')]
#[ORM\Index(columns: ['updated_by'], name: 'contract_call_off_order_updated_by_idx')]
#[ORM\UniqueConstraint(name: 'contract_call_off_order_slug_key', columns: ['slug'])]
#[ORM\UniqueConstraint(name: 'contract_call_off_order_number_key', columns: ['client_id', 'number'])]
#[ORM\Entity]
#[UniqueEntity('number')]
#[GetCollection(
uriTemplate: '/sales/clients/{client}/call_off_orders',
uriVariables: [
'client' => new Link(toProperty: 'client', fromClass: Company::class),
],
)]
#[ApiResource(
uriTemplate: '/sales/clients/{client}/call_off_orders/{slug}',
operations: [
new Get(),
new Delete(),
new Patch(inputFormats: ['json' => ['application/merge-patch+json'], 'multipart' => ['multipart/form-data']]),
new Put(inputFormats: ['json' => ['application/json'], 'multipart' => ['multipart/form-data']]),
],
uriVariables: [
'client' => new Link(toProperty: 'client', fromClass: Company::class),
'slug' => new Link(fromClass: CallOffOrder::class),
],
input: CallOffOrderInput::class,
processor: CallOffOrderInputProcessor::class,
)]
class CallOffOrder
{
use Common\Blameable;
use Common\Trackable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'contract_call_off_order_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
#[ApiProperty(identifier: false)]
private ?int $id = null;
#[Gedmo\Slug(fields: ['number'])]
#[ORM\Column(type: Types::STRING)]
#[ApiProperty(identifier: true)]
private string $slug;
#[Assert\NotNull]
#[Assert\Length(min: 5)]
#[ORM\Column(type: Types::STRING)]
private ?string $number = null;
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: Company::class)]
#[ORM\JoinColumn(name: 'client_id', nullable: false)]
private ?Company $client = null;
/** @var Collection<int, Contract> */
#[ORM\ManyToMany(targetEntity: Contract::class, inversedBy: 'callOffOrders')]
#[ORM\JoinTable(name: 'contract_call_off_order_contract_map')]
#[ORM\JoinColumn(name: 'call_off_order_id')]
#[ORM\InverseJoinColumn(name: 'contract_id')]
private Collection $contracts;
#[ORM\ManyToOne(targetEntity: Upload::class, cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(name: 'file_id', referencedColumnName: 'id')]
private ?Upload $file = null;
#[Assert\NotNull]
#[ORM\Column(type: Types::DATE_MUTABLE, options: ['default' => 'CURRENT_DATE'])]
private ?DateTimeInterface $receivedOn = null;
#[Assert\GreaterThanOrEqual(propertyPath: 'receivedOn')]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?DateTimeInterface $exhaustedOn = null;
#[Assert\Type(type: Upload::class)]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private ?bool $expired = false;
#[Gedmo\Blameable(on: 'create')]
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'created_by', nullable: false)]
protected ?User $createdBy = null;
public function __construct()
{
$this->contracts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getNumber(): ?string
{
return $this->number;
}
public function setNumber(string $number): self
{
$this->number = $number;
return $this;
}
public function getClient(): ?Company
{
return $this->client;
}
public function setClient(?Company $contract): self
{
$this->client = $contract;
return $this;
}
/**
* @return Collection<int, Contract>
*/
public function getContracts(): Collection
{
return $this->contracts;
}
public function addContract(Contract $contract): self
{
if (!$this->contracts->contains($contract)) {
$this->contracts->add($contract);
}
return $this;
}
public function removeContract(Contract $contract): self
{
$this->contracts->removeElement($contract);
return $this;
}
public function getFile(): ?Upload
{
return $this->file;
}
public function setFile(?Upload $file): self
{
$this->file = $file;
return $this;
}
public function getReceivedOn(): ?DateTimeInterface
{
return $this->receivedOn;
}
public function setReceivedOn(DateTimeInterface $receivedOn): self
{
$this->receivedOn = $receivedOn;
return $this;
}
public function getExhaustedOn(): ?DateTimeInterface
{
return $this->exhaustedOn;
}
public function setExhaustedOn(?DateTimeInterface $exhaustedOn): self
{
$this->exhaustedOn = $exhaustedOn;
return $this;
}
public function isExpired(): ?bool
{
return $this->expired;
}
public function setExpired(bool $expired): self
{
$this->expired = $expired;
return $this;
}
}