src/Entity/Delete/Proforma.php line 48
<?php
namespace App\Entity\Delete;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\Doctrine\Type\Expediting\TransportMode;
use App\Doctrine\Type\Finance\PayableStatus;
use App\Dto\Delete\PayableLines;
use App\Dto\Delete\ProformaCreationInput;
use App\Entity\Common as Common;
use App\Entity\Expediting\ShippingPlan;
use App\Entity\Sales\WorkOrder;
use App\Processor\Delete\ProformaCreationProcessor;
use App\Validator\IsValidEnum\IsValidEnum;
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\Component\Validator\Constraints as Assert;
#[ORM\Table(name: 'invoicing_proforma')]
#[ORM\Entity]
#[ApiResource(
operations: [
new Get(),
new GetCollection(),
new Post(input: ProformaCreationInput::class, processor: ProformaCreationProcessor::class),
new Patch(inputFormats: ['json' => ['application/merge-patch+json']]),
new Delete(),
],
routePrefix: '/invoicing',
)]
#[ApiFilter(SearchFilter::class, properties: [
'slug' => 'ipartial',
'reference' => 'ipartial',
'orderNumber' => 'ipartial',
'workOrders' => 'ipartial',
])]
class Proforma extends Invoiceable
{
use Common\Blameable;
use Common\Trackable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'invoicing_proforma_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
#[ApiProperty(identifier: false)]
private int $id;
#[ORM\ManyToOne(targetEntity: WorkOrder::class)]
#[ORM\JoinColumn(name: 'work_order_id')]
private ?WorkOrder $workOrder = null;
#[ORM\ManyToOne(targetEntity: ShippingPlan::class)]
#[ORM\JoinColumn(name: 'shipping_plan_id')]
private ?ShippingPlan $shippingPlan = null;
#[ORM\ManyToOne(targetEntity: Batch::class)]
#[ORM\JoinColumn(name: 'batch_id')]
private ?Batch $batch = null;
#[Gedmo\Slug(fields: ['number', 'reference'])]
#[ORM\Column(type: Types::STRING)]
#[ApiProperty(identifier: true)]
private string $slug;
#[Assert\NotBlank]
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING)]
private ?string $number = null;
#[Assert\NotBlank]
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING)]
private ?string $destinationCountryCode = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING)]
private ?string $workOrders = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING)]
protected ?string $tariffZone = null;
#[Assert\NotNull]
#[IsValidEnum(enum: TransportMode::class)]
#[ORM\Column(type: Types::STRING, enumType: TransportMode::class)]
private ?TransportMode $transportMode = TransportMode::SEA;
#[Assert\Type(type: PayableLines::class)]
#[ORM\Column(type: 'json_document', options: ['jsonb' => true])]
private ?PayableLines $lines = null;
#[Assert\NotNull]
#[IsValidEnum(enum: PayableStatus::class)]
#[ORM\Column(type: Types::STRING, enumType: PayableStatus::class)]
private ?PayableStatus $status = PayableStatus::DRAFTED;
/** @var Collection<int, Box> */
#[ORM\ManyToMany(targetEntity: Box::class)]
#[ORM\JoinTable(name: 'invoicing_proforma_box_map')]
#[ORM\JoinColumn(name: 'proforma_id')]
#[ORM\InverseJoinColumn(name: 'box_id')]
#[ORM\OrderBy(['id' => 'ASC'])]
#[ApiProperty(readableLink: true)]
private Collection $boxes;
public function __construct()
{
$this->boxes = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getWorkOrder(): ?WorkOrder
{
return $this->workOrder;
}
public function setWorkOrder(?WorkOrder $workOrder): self
{
$this->workOrder = $workOrder;
return $this;
}
public function getShippingPlan(): ?ShippingPlan
{
return $this->shippingPlan;
}
public function setShippingPlan(?ShippingPlan $shippingPlan): self
{
$this->shippingPlan = $shippingPlan;
return $this;
}
public function getBatch(): ?Batch
{
return $this->batch;
}
public function setBatch(?Batch $batch): self
{
$this->batch = $batch;
return $this;
}
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 getWorkOrders(): string
{
return $this->workOrders;
}
public function setWorkOrders(string $workOrders): self
{
$this->workOrders = $workOrders;
return $this;
}
public function getWorkOrderReferences(): array
{
$references = [];
foreach ($this->boxes as $box) {
$boxReferenceParts = explode('-', $box->getReference());
$references []= "{$boxReferenceParts[0]}-{$boxReferenceParts[1]}";
}
$references = array_unique($references);
sort($references);
return $references;
}
public function getDestinationCountryCode(): ?string
{
return $this->destinationCountryCode;
}
public function setDestinationCountryCode(string $destinationCountryCode): self
{
$this->destinationCountryCode = $destinationCountryCode;
return $this;
}
public function getTransportMode(): ?TransportMode
{
return $this->transportMode;
}
public function setTransportMode(?TransportMode $transportMode): self
{
$this->transportMode = $transportMode;
return $this;
}
public function getLines(): ?PayableLines
{
return $this->lines;
}
public function setLines(?PayableLines $lines): self
{
$this->lines = $lines;
return $this;
}
public function getAmount(): int|float|null
{
if (null === $this->lines) {
return null;
}
$amount = 0;
foreach ($this->lines->lines as $line) {
$amount += $line->rate * $line->quantity;
}
return $amount;
}
public function getStatus(): ?PayableStatus
{
return $this->status;
}
public function setStatus(?PayableStatus $status): self
{
$this->status = $status;
return $this;
}
public function getChargeableWeight(): ?float
{
if (empty($this->chargeableWeight) && $this->transportMode === TransportMode::SEA) {
return max($this->weight, $this->volume * 1000);
}
if (empty($this->chargeableWeight) && $this->transportMode === TransportMode::AIR) {
return max($this->weight, $this->volume * 167);
}
return $this->chargeableWeight;
}
/**
* @return Collection<int, Box>
*/
public function getBoxes(): Collection
{
return $this->boxes;
}
public function addBox(Box $box): self
{
if (!$this->boxes->contains($box)) {
$this->boxes->add($box);
}
return $this;
}
public function removeBox(Box $box): self
{
$this->boxes->removeElement($box);
return $this;
}
}