dbmsv4/app/Entities/PaymentEntity.php
2026-03-11 12:43:39 +09:00

90 lines
2.4 KiB
PHP

<?php
namespace App\Entities;
use App\Models\PaymentModel;
use DateTime;
class PaymentEntity extends CommonEntity
{
const PK = PaymentModel::PK;
const TITLE = PaymentModel::TITLE;
public function __construct(array|null $data = null)
{
parent::__construct($data);
$this->nullableFields = [
...$this->nullableFields,
'clientinfo_uid',
'serviceinfo_uid',
'serverpartinfo_uid',
'pay',
'content',
];
}
public function getUserUid(): ?int
{
return $this->user_uid === null ? null : (int) $this->user_uid;
}
public function getClientInfoUid(): ?int
{
return $this->clientinfo_uid === null ? null : (int) $this->clientinfo_uid;
}
public function getServiceInfoUid(): ?int
{
return $this->serviceinfo_uid === null ? null : (int) $this->serviceinfo_uid;
}
public function getServerPartInfoUid(): ?int
{
return $this->serverpartinfo_uid === null ? null : (int) $this->serverpartinfo_uid;
}
//기본기능
public function getCustomTitle(): string
{
return sprintf("%s %s [%s]", $this->getTitle(), $this->getAmount(), $this->getBillingAt());
}
public function getBilling(): string
{
return $this->billing;
}
public function getAmount(): int
{
return (int) ($this->amount ?? 0);
}
public function getBillingAt(): string
{
return $this->billing_at;
}
public function getBillingMonth(): int
{
return (int) ($this->billing_month ?? 0);
}
public function getPay(): ?string
{
return $this->pay;
}
public function getContent(): ?string
{
return $this->content;
}
public function getCountDueAt(): string
{
$result = "";
if ($this->getStatus() === STATUS['UNPAID']) {
$now = new DateTime(); // 오늘 날짜
$due = new DateTime($this->getBillingAt());
if ($due < $now) {
$interval = $due->diff($now);
$result = "{$interval->days}일지남";
} else if ($due > $now) {
$interval = $now->diff($due);
$day = $interval->days + 1;
$result = "{$day}일전";
} else {
$result = "당일";
}
}
return $result;
}
}