• File: GeneralMonthClose.php
  • Full Path: /var/www/imaliapi/app/GeneralMonthClose.php
  • Date Modified: 10/11/2024 8:28 PM
  • File size: 2.25 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php

namespace App;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use DateTimeInterface;

setlocale(LC_TIME, 'pt');

class GeneralMonthClose extends Model
{
    use HasFactory;
    use LogsActivity;

    protected $fillable = [
        'transaction',
        'date_reference',

        'voucher_phone',
        'voucher_tv',
        'voucher_water',
        'voucher_credelec',
        'payment',
        'transfer',
        'total',

        'voucher_phone_comision',
        'voucher_tv_comision',
        'voucher_water_comision',
        'voucher_credelec_comision',
        'payment_comision',
        'transfer_comision',
        'total_comitions',

        'status',
    ];

    protected static $logAttributes = [
        'transaction',
        'date_reference',

        'voucher_phone',
        'voucher_tv',
        'voucher_water',
        'voucher_credelec',
        'payment',
        'transfer',
        'total',

        'voucher_phone_comision',
        'voucher_tv_comision',
        'voucher_water_comision',
        'voucher_credelec_comision',
        'payment_comision',
        'transfer_comision',
        'total_comitions',

        'status',
    ];
    protected $logAttribute = [
        'transaction',
        'date_reference',

        'voucher_phone',
        'voucher_tv',
        'voucher_water',
        'voucher_credelec',
        'payment',
        'transfer',
        'total',

        'voucher_phone_comision',
        'voucher_tv_comision',
        'voucher_water_comision',
        'voucher_credelec_comision',
        'payment_comision',
        'transfer_comision',
        'total_comitions',

        'status',
    ];

    public function getDescriptionForEvent(string $eventName): string
    {
        return "This model has been {$eventName}";
    }

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('d-m-Y H:i:s');
    }

    public function getDateReferenceAttribute($value)
    {
        return date("F Y", strtotime($value));
    }

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()->logOnly($this->logAttribute);
    }
}