DocumentItem.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App;
  3. use App\Traits\DateTimeTrait;
  4. use App\Traits\SoftDeleteTrait;
  5. use JsonSerializable;
  6. /**
  7. * @property int $id
  8. * @property int $document_id
  9. * @property string $description
  10. * @property string $serial_number
  11. * @property int $quantity
  12. * @property string $unit_price
  13. * @property string $insurance_value
  14. */
  15. class DocumentItem extends Model implements JsonSerializable {
  16. protected static $table = "document_item";
  17. protected static $idField = "id";
  18. protected static $fillableFields = [
  19. "document_id",
  20. "description", "serial_number",
  21. "quantity", "unit_price", "insurance_value",
  22. "dts_created", "dts_updated", "dts_deleted"
  23. ];
  24. use DateTimeTrait;
  25. use SoftDeleteTrait;
  26. // Object methods
  27. public function getAmount(): string {
  28. return bcmul($this->unit_price, $this->quantity, 2);
  29. }
  30. public function jsonSerialize(): array {
  31. return [
  32. "id" => (int) $this->id,
  33. "documentId" => (int) $this->document_id,
  34. "description" => $this->description,
  35. "serialNumber" => $this->serial_number,
  36. "quantity" => (int) $this->quantity,
  37. "unitPrice" => $this->unit_price,
  38. "insuranceValue" => $this->insurance_value,
  39. ];
  40. }
  41. }