DocumentItem.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. */
  14. class DocumentItem extends Model implements JsonSerializable {
  15. protected static $table = "document_item";
  16. protected static $idField = "id";
  17. protected static $fillableFields = [
  18. "document_id",
  19. "description", "serial_number",
  20. "quantity", "unit_price",
  21. "dts_created", "dts_updated", "dts_deleted"
  22. ];
  23. use DateTimeTrait;
  24. use SoftDeleteTrait;
  25. // Object methods
  26. public function getAmount(): string {
  27. return bcmul($this->unit_price, $this->quantity, 2);
  28. }
  29. public function jsonSerialize(): array {
  30. return [
  31. "id" => (int) $this->id,
  32. "documentId" => (int) $this->document_id,
  33. "description" => $this->description,
  34. "serialNumber" => $this->serial_number,
  35. "quantity" => (int) $this->quantity,
  36. "unitPrice" => $this->unit_price,
  37. ];
  38. }
  39. }