<?php
namespace App\Entity;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity]
#[ORM\Table(
name: 'component_inventory_log_entry',
options: ['collate' => 'utf8_swedish_ci']
)]
class ComponentInventoryLogEntry implements EntityInterface
{
const TYPE_INCREASE = 0;
const TYPE_DECREASE = 1;
const TYPE_SET = 2;
const TYPE_UPDATE_UNIT_PRICE = 3;
#[ORM\Id]
#[ORM\Column(
type: 'integer'
)]
#[ORM\GeneratedValue(
strategy: 'AUTO'
)]
protected ?int $id = null;
/**
* Unit price in euro cents.
*/
#[ORM\Column(
type: 'decimal',
precision: 13,
scale: 3,
nullable: true
)]
#[Assert\PositiveOrZero]
protected ?string $batchUnitPrice = null;
#[ORM\Column(
type: 'datetime'
)]
#[Assert\NotNull]
protected DateTime $created;
#[ORM\Column(
type: 'string',
length: 200,
nullable: true
)]
protected ?string $excelFileName = null;
#[ORM\ManyToOne(
targetEntity: ComponentInventoryItem::class,
inversedBy: 'logEntries'
)]
#[ORM\JoinColumn(
name: 'item_id',
referencedColumnName: 'id',
onDelete: 'cascade'
)]
#[Assert\NotNull]
protected ComponentInventoryItem $item;
#[ORM\Column(
type: 'string',
length: 20,
nullable: true
)]
#[Assert\Length(
max: 20
)]
protected ?string $note = null;
#[ORM\Column(
type: 'integer',
nullable: true
)]
#[Assert\PositiveOrZero]
protected ?int $previousQuantity = null;
/**
* Unit price in euro cents.
*/
#[ORM\Column(
type: 'decimal',
precision: 13,
scale: 3,
nullable: true
)]
protected ?string $previousUnitPrice = null;
#[ORM\Column(
type: 'string',
length: 15,
nullable: true
)]
protected ?string $purchaseOrderNumber = null;
#[ORM\Column(
type: 'integer'
)]
#[Assert\NotNull]
protected int $type;
#[ORM\Column(
type: 'integer'
)]
#[Assert\NotNull]
#[Assert\PositiveOrZero]
protected int $updatedQuantity;
/**
* Unit price in euro cents.
*/
#[ORM\Column(
type: 'decimal',
precision: 13,
scale: 3
)]
#[Assert\NotNull]
#[Assert\Positive]
protected string $updatedUnitPrice;
/**
* @param ComponentInventoryItem $item
* @param int $type
* @param int $updatedQuantity
* @param float $updatedUnitPrice
* @param float|null $batchUnitPrice
* @param int|null $previousQuantity
* @param float|null $previousUnitPrice
* @param string|null $note
* @param string|null $purchaseOrderNumber
* @param string|null $excelFileName
*/
public function __construct(
ComponentInventoryItem $item,
int $type,
int $updatedQuantity,
float $updatedUnitPrice,
?float $batchUnitPrice,
?int $previousQuantity,
?float $previousUnitPrice,
?string $note = null,
?string $purchaseOrderNumber = null,
?string $excelFileName = null
) {
$this->item = $item;
$this->type = $type;
$this->updatedQuantity = $updatedQuantity;
$this->updatedUnitPrice = number_format($updatedUnitPrice, 3, '.', '');
$this->batchUnitPrice = null !== $batchUnitPrice ? number_format($batchUnitPrice, 3, '.', '') : null;
$this->previousQuantity = $previousQuantity;
$this->previousUnitPrice = null !== $previousUnitPrice ? number_format($previousUnitPrice, 3, '.', '') : null;
$this->note = $note;
$this->purchaseOrderNumber = $purchaseOrderNumber;
$this->excelFileName = $excelFileName;
$this->created = new DateTime();
}
/**
* @return float|null
*/
public function getBatchUnitPrice(): ?float
{
return null !== $this->batchUnitPrice ? (float) $this->batchUnitPrice : null;
}
/**
* @return DateTime
*/
public function getCreated(): DateTime
{
return $this->created;
}
/**
* @return string|null
*/
public function getExcelFileName(): ?string
{
return $this->excelFileName;
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return ComponentInventoryItem
*/
public function getItem(): ComponentInventoryItem
{
return $this->item;
}
/**
* @return string|null
*/
public function getNote(): ?string
{
return $this->note;
}
/**
* @return int|null
*/
public function getPreviousQuantity(): ?int
{
return $this->previousQuantity;
}
/**
* @return float|null
*/
public function getPreviousTotalValue(): ?float
{
if (null === $this->previousQuantity || null === $this->previousUnitPrice) {
return null;
}
return $this->previousQuantity * $this->getPreviousUnitPrice();
}
/**
* @return float|null
*/
public function getPreviousUnitPrice(): ?float
{
return null !== $this->previousUnitPrice ? (float) $this->previousUnitPrice : null;
}
/**
* @return string|null
*/
public function getPurchaseOrderNumber(): ?string
{
return $this->purchaseOrderNumber;
}
/**
* @return int
*/
public function getQuantityChange(): int
{
return $this->updatedQuantity - (null === $this->previousQuantity ? 0 : $this->previousQuantity);
}
/**
* @return int
*/
public function getType(): int
{
return $this->type;
}
/**
* @return int
*/
public function getUpdatedQuantity(): int
{
return $this->updatedQuantity;
}
/**
* @return float
*/
public function getUpdatedTotalValue(): float
{
return $this->updatedQuantity * $this->getUpdatedUnitPrice();
}
/**
* @return float
*/
public function getUpdatedUnitPrice(): float
{
return (float) $this->updatedUnitPrice;
}
}