96 lines
2.2 KiB
PHP
Executable File
96 lines
2.2 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\FluxoCaixaPro\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* Class Transaction
|
|
*
|
|
* Represents a financial transaction in the Fluxo de Caixa Pró module.
|
|
*
|
|
* @package Modules\FluxoCaixaPro\Models
|
|
*/
|
|
class Transaction extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'cash_flow_transactions';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'idbus',
|
|
'iduser',
|
|
'category_id',
|
|
'description',
|
|
'amount',
|
|
'transaction_date',
|
|
'due_date',
|
|
'payment_date',
|
|
'type',
|
|
'status',
|
|
'is_personal',
|
|
'notes',
|
|
'metadata'
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'idbus' => 'integer',
|
|
'iduser' => 'integer',
|
|
'amount' => 'decimal:2',
|
|
'transaction_date' => 'date',
|
|
'due_date' => 'date',
|
|
'payment_date' => 'date',
|
|
'is_personal' => 'boolean',
|
|
'metadata' => 'array',
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime'
|
|
];
|
|
|
|
/**
|
|
* The "booted" method of the model.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted()
|
|
{
|
|
static::addGlobalScope('company', function ($query) {
|
|
if (isset($_SESSION['user_idbus']) && $_SESSION['user_idbus'] !== null && (!isset($_SESSION['user_role']) || $_SESSION['user_role'] !== 'super_admin')) {
|
|
$query->where('idbus', $_SESSION['user_idbus']);
|
|
}
|
|
});
|
|
|
|
static::creating(function ($model) {
|
|
if (isset($_SESSION['user_idbus'])) {
|
|
$model->idbus = $_SESSION['user_idbus'];
|
|
}
|
|
if (isset($_SESSION['user_id'])) {
|
|
$model->iduser = $_SESSION['user_id'];
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get the category that owns the transaction.
|
|
*
|
|
* @return BelongsTo
|
|
*/
|
|
public function category(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Category::class, 'category_id');
|
|
}
|
|
}
|