You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.8 KiB
PHTML

<?php
namespace App\Models;
1 year ago
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Support\Carbon;
class PaylaterHistory extends Model
{
const STATUS_VALID = 0;
const STATUS_WAIT_UPLOAD = 1;
const STATUS_WAIT_APPROVE = 2;
const STATUS_WAIT_PAYMENT = 3;
const STATUS_INVALID = 4;
const STATUS_REJECT = 5;
const STATUS_EXPIRED = 6;
const TYPE_PAYMENT = 0;
const TYPE_UPGRADE = 1;
const TYPE_REPAYMENT = 3;
const TYPE_UPDATE_TENOR = 4;
protected $fillable = [
'debit',
'credit',
'description',
'customer_id',
'type',
'is_valid',
1 year ago
'image_prove',
];
1 year ago
protected $appends = [
'format_human_created_at',
'format_created_at',
'amount',
];
public function update_customer_paylater()
{
$customer = Customer::find($this->customer_id);
$paylater = $customer->paylater;
$paylater->update([
'usage' => $paylater->usage + $this->debit - $this->credit,
// TODO: add day dateline
]);
1 year ago
}
public function formatHumanCreatedAt(): Attribute
{
return Attribute::make(get: function () {
1 year ago
return Carbon::parse($this->created_at)->translatedFormat('d F Y');
1 year ago
});
}
public function formatCreatedAt(): Attribute
{
return Attribute::make(get: function () {
1 year ago
return Carbon::parse($this->created_at)->translatedFormat('d F Y H:i:s');
1 year ago
});
}
public function amount(): Attribute
{
return Attribute::make(get: function () {
if ($this->credit == 0) {
1 year ago
return 'Rp'.number_format($this->debit, is_float($this->debit) ? 2 : 0, ',', '.');
1 year ago
}
1 year ago
return '-Rp'.number_format($this->credit, is_float($this->credit) ? 2 : 0, ',', '.');
1 year ago
});
}
}