- Menambahkan kolom `remarks` pada tabel print_statement_logs untuk menyimpan catatan tambahan. - Mengubah validasi periode pada `PrintStatementRequest` untuk mencegah request duplikasi periode. - Memperbaiki tampilan di `statements.index` dan `statements.show` agar lebih responsif dan informatif. - Mengubah logika download statement untuk mendukung file range periode dalam format zip. - Menambahkan logika cek file statement berdasarkan ketersediaan file di storage SFTP. - Menghapus file legacy `create.blade.php` yang tidak lagi digunakan. - Menyesuaikan ikon menu dari `calendar` ke `printer` agar lebih relevan. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
185 lines
4.7 KiB
PHP
185 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace Modules\Webstatement\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Modules\Basicdata\Models\Branch;
|
|
use Modules\Usermanagement\Models\User;
|
|
|
|
class PrintStatementLog extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'branch_code',
|
|
'account_number',
|
|
'period_from',
|
|
'period_to',
|
|
'is_period_range',
|
|
'is_available',
|
|
'is_downloaded',
|
|
'ip_address',
|
|
'user_agent',
|
|
'downloaded_at',
|
|
'authorization_status',
|
|
'created_by',
|
|
'updated_by',
|
|
'deleted_by',
|
|
'authorized_by',
|
|
'authorized_at',
|
|
'remarks',
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_period_range' => 'boolean',
|
|
'is_available' => 'boolean',
|
|
'is_downloaded' => 'boolean',
|
|
'downloaded_at' => 'datetime',
|
|
'authorized_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* Get the formatted period display
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getPeriodDisplayAttribute()
|
|
{
|
|
if ($this->is_period_range) {
|
|
return $this->formatPeriod($this->period_from) . ' - ' . $this->formatPeriod($this->period_to);
|
|
}
|
|
|
|
return $this->formatPeriod($this->period_from);
|
|
}
|
|
|
|
/**
|
|
* Format period from YYYYMM to Month Year
|
|
*
|
|
* @param string $period
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function formatPeriod($period)
|
|
{
|
|
if (strlen($period) !== 6) {
|
|
return $period;
|
|
}
|
|
|
|
$year = substr($period, 0, 4);
|
|
$month = substr($period, 4, 2);
|
|
|
|
return date('F Y', mktime(0, 0, 0, (int) $month, 1, (int) $year));
|
|
}
|
|
|
|
/**
|
|
* Get the user who requested the statement
|
|
*/
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
/**
|
|
* Get the user who created the record
|
|
*/
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
/**
|
|
* Get the user who updated the record
|
|
*/
|
|
public function updater()
|
|
{
|
|
return $this->belongsTo(User::class, 'updated_by');
|
|
}
|
|
|
|
/**
|
|
* Get the user who authorized the record
|
|
*/
|
|
public function authorizer()
|
|
{
|
|
return $this->belongsTo(User::class, 'authorized_by');
|
|
}
|
|
|
|
/**
|
|
* Scope a query to only include pending authorization records
|
|
*/
|
|
public function scopePending($query)
|
|
{
|
|
return $query->where('authorization_status', 'pending');
|
|
}
|
|
|
|
/**
|
|
* Scope a query to only include approved records
|
|
*/
|
|
public function scopeApproved($query)
|
|
{
|
|
return $query->where('authorization_status', 'approved');
|
|
}
|
|
|
|
/**
|
|
* Scope a query to only include rejected records
|
|
*/
|
|
public function scopeRejected($query)
|
|
{
|
|
return $query->where('authorization_status', 'rejected');
|
|
}
|
|
|
|
/**
|
|
* Scope a query to only include downloaded records
|
|
*/
|
|
public function scopeDownloaded($query)
|
|
{
|
|
return $query->where('is_downloaded', true);
|
|
}
|
|
|
|
/**
|
|
* Scope a query to only include available records
|
|
*/
|
|
public function scopeAvailable($query)
|
|
{
|
|
return $query->where('is_available', true);
|
|
}
|
|
|
|
/**
|
|
* Check if the statement is for a single period
|
|
*/
|
|
public function isSinglePeriod()
|
|
{
|
|
return !$this->is_period_range;
|
|
}
|
|
|
|
/**
|
|
* Check if the statement is authorized
|
|
*/
|
|
public function isAuthorized()
|
|
{
|
|
return $this->authorization_status === 'approved';
|
|
}
|
|
|
|
/**
|
|
* Check if the statement is rejected
|
|
*/
|
|
public function isRejected()
|
|
{
|
|
return $this->authorization_status === 'rejected';
|
|
}
|
|
|
|
/**
|
|
* Check if the statement is pending authorization
|
|
*/
|
|
public function isPending()
|
|
{
|
|
return $this->authorization_status === 'pending';
|
|
}
|
|
|
|
public function branch(){
|
|
return $this->belongsTo(Branch::class, 'branch_code','code');
|
|
}
|
|
}
|