src/Entity/ComponentInventoryLogEntry.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. #[ORM\Entity]
  7. #[ORM\Table(
  8.     name'component_inventory_log_entry',
  9.     options: ['collate' => 'utf8_swedish_ci']
  10. )]
  11. class ComponentInventoryLogEntry implements EntityInterface
  12. {
  13.     const TYPE_INCREASE 0;
  14.     const TYPE_DECREASE 1;
  15.     const TYPE_SET 2;
  16.     const TYPE_UPDATE_UNIT_PRICE 3;
  17.     #[ORM\Id]
  18.     #[ORM\Column(
  19.         type'integer'
  20.     )]
  21.     #[ORM\GeneratedValue(
  22.         strategy'AUTO'
  23.     )]
  24.     protected ?int $id null;
  25.     /**
  26.      * Unit price in euro cents.
  27.      */
  28.     #[ORM\Column(
  29.         type'decimal',
  30.         precision13,
  31.         scale3,
  32.         nullabletrue
  33.     )]
  34.     #[Assert\PositiveOrZero]
  35.     protected ?string $batchUnitPrice null;
  36.     #[ORM\Column(
  37.         type'datetime'
  38.     )]
  39.     #[Assert\NotNull]
  40.     protected DateTime $created;
  41.     #[ORM\Column(
  42.         type'string',
  43.         length200,
  44.         nullabletrue
  45.     )]
  46.     protected ?string $excelFileName null;
  47.     #[ORM\ManyToOne(
  48.         targetEntityComponentInventoryItem::class,
  49.         inversedBy'logEntries'
  50.     )]
  51.     #[ORM\JoinColumn(
  52.         name'item_id',
  53.         referencedColumnName'id',
  54.         onDelete'cascade'
  55.     )]
  56.     #[Assert\NotNull]
  57.     protected ComponentInventoryItem $item;
  58.     #[ORM\Column(
  59.         type'string',
  60.         length20,
  61.         nullabletrue
  62.     )]
  63.     #[Assert\Length(
  64.         max20
  65.     )]
  66.     protected ?string $note null;
  67.     #[ORM\Column(
  68.         type'integer',
  69.         nullabletrue
  70.     )]
  71.     #[Assert\PositiveOrZero]
  72.     protected ?int $previousQuantity null;
  73.     /**
  74.      * Unit price in euro cents.
  75.      */
  76.     #[ORM\Column(
  77.         type'decimal',
  78.         precision13,
  79.         scale3,
  80.         nullabletrue
  81.     )]
  82.     protected ?string $previousUnitPrice null;
  83.     #[ORM\Column(
  84.         type'string',
  85.         length15,
  86.         nullabletrue
  87.     )]
  88.     protected ?string $purchaseOrderNumber null;
  89.     #[ORM\Column(
  90.         type'integer'
  91.     )]
  92.     #[Assert\NotNull]
  93.     protected int $type;
  94.     #[ORM\Column(
  95.         type'integer'
  96.     )]
  97.     #[Assert\NotNull]
  98.     #[Assert\PositiveOrZero]
  99.     protected int $updatedQuantity;
  100.     /**
  101.      * Unit price in euro cents.
  102.      */
  103.     #[ORM\Column(
  104.         type'decimal',
  105.         precision13,
  106.         scale3
  107.     )]
  108.     #[Assert\NotNull]
  109.     #[Assert\Positive]
  110.     protected string $updatedUnitPrice;
  111.     /**
  112.      * @param ComponentInventoryItem $item
  113.      * @param int $type
  114.      * @param int $updatedQuantity
  115.      * @param float $updatedUnitPrice
  116.      * @param float|null $batchUnitPrice
  117.      * @param int|null $previousQuantity
  118.      * @param float|null $previousUnitPrice
  119.      * @param string|null $note
  120.      * @param string|null $purchaseOrderNumber
  121.      * @param string|null $excelFileName
  122.      */
  123.     public function __construct(
  124.         ComponentInventoryItem $item,
  125.         int $type,
  126.         int $updatedQuantity,
  127.         float $updatedUnitPrice,
  128.         ?float $batchUnitPrice,
  129.         ?int $previousQuantity,
  130.         ?float $previousUnitPrice,
  131.         ?string $note null,
  132.         ?string $purchaseOrderNumber null,
  133.         ?string $excelFileName null
  134.     ) {
  135.         $this->item $item;
  136.         $this->type $type;
  137.         $this->updatedQuantity $updatedQuantity;
  138.         $this->updatedUnitPrice number_format($updatedUnitPrice3'.''');
  139.         $this->batchUnitPrice null !== $batchUnitPrice number_format($batchUnitPrice3'.''') : null;
  140.         $this->previousQuantity $previousQuantity;
  141.         $this->previousUnitPrice null !== $previousUnitPrice number_format($previousUnitPrice3'.''') : null;
  142.         $this->note $note;
  143.         $this->purchaseOrderNumber $purchaseOrderNumber;
  144.         $this->excelFileName $excelFileName;
  145.         $this->created = new DateTime();
  146.     }
  147.     /**
  148.      * @return float|null
  149.      */
  150.     public function getBatchUnitPrice(): ?float
  151.     {
  152.         return null !== $this->batchUnitPrice ? (float) $this->batchUnitPrice null;
  153.     }
  154.     /**
  155.      * @return DateTime
  156.      */
  157.     public function getCreated(): DateTime
  158.     {
  159.         return $this->created;
  160.     }
  161.     /**
  162.      * @return string|null
  163.      */
  164.     public function getExcelFileName(): ?string
  165.     {
  166.         return $this->excelFileName;
  167.     }
  168.     /**
  169.      * @return int|null
  170.      */
  171.     public function getId(): ?int
  172.     {
  173.         return $this->id;
  174.     }
  175.     /**
  176.      * @return ComponentInventoryItem
  177.      */
  178.     public function getItem(): ComponentInventoryItem
  179.     {
  180.         return $this->item;
  181.     }
  182.     /**
  183.      * @return string|null
  184.      */
  185.     public function getNote(): ?string
  186.     {
  187.         return $this->note;
  188.     }
  189.     /**
  190.      * @return int|null
  191.      */
  192.     public function getPreviousQuantity(): ?int
  193.     {
  194.         return $this->previousQuantity;
  195.     }
  196.     /**
  197.      * @return float|null
  198.      */
  199.     public function getPreviousTotalValue(): ?float
  200.     {
  201.         if (null === $this->previousQuantity || null === $this->previousUnitPrice) {
  202.             return null;
  203.         }
  204.         return $this->previousQuantity $this->getPreviousUnitPrice();
  205.     }
  206.     /**
  207.      * @return float|null
  208.      */
  209.     public function getPreviousUnitPrice(): ?float
  210.     {
  211.         return null !== $this->previousUnitPrice ? (float) $this->previousUnitPrice null;
  212.     }
  213.     /**
  214.      * @return string|null
  215.      */
  216.     public function getPurchaseOrderNumber(): ?string
  217.     {
  218.         return $this->purchaseOrderNumber;
  219.     }
  220.     /**
  221.      * @return int
  222.      */
  223.     public function getQuantityChange(): int
  224.     {
  225.         return $this->updatedQuantity - (null === $this->previousQuantity $this->previousQuantity);
  226.     }
  227.     /**
  228.      * @return int
  229.      */
  230.     public function getType(): int
  231.     {
  232.         return $this->type;
  233.     }
  234.     /**
  235.      * @return int
  236.      */
  237.     public function getUpdatedQuantity(): int
  238.     {
  239.         return $this->updatedQuantity;
  240.     }
  241.     /**
  242.      * @return float
  243.      */
  244.     public function getUpdatedTotalValue(): float
  245.     {
  246.         return $this->updatedQuantity $this->getUpdatedUnitPrice();
  247.     }
  248.     /**
  249.      * @return float
  250.      */
  251.     public function getUpdatedUnitPrice(): float
  252.     {
  253.         return (float) $this->updatedUnitPrice;
  254.     }
  255. }