Files
2026-09-01 10:46:29 -03:00

73 lines
1.7 KiB
PHP
Executable File

<?php
namespace Modules\FluxoCaixaPro\Models;
use Illuminate\Database\Eloquent\Model;
/**
* Class CashFlowAnalysis
*
* Represents an AI-generated cash flow analysis in the Fluxo de Caixa Pró module.
*
* @package Modules\FluxoCaixaPro\Models
*/
class CashFlowAnalysis extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'cash_flow_analysis';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'idbus',
'iduser',
'analysis_date',
'summary_data',
'recommendations',
'projections'
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'idbus' => 'integer',
'iduser' => 'integer',
'analysis_date' => 'date',
'summary_data' => 'array',
'projections' => 'array'
];
/**
* 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'];
}
});
}
}