93 lines
2.0 KiB
PHP
Executable File
93 lines
2.0 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* SysCMS - Content Management System
|
|
*
|
|
* Copyright (c) 2026 SysCMS Team
|
|
* All rights reserved.
|
|
*
|
|
* Author: SysCMS Team
|
|
* Project: SysCMS
|
|
*/
|
|
|
|
namespace Modules\FluxoCaixaPro\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
/**
|
|
* Category - Model for cash flow categories
|
|
*
|
|
* @package Modules\FluxoCaixaPro\Models
|
|
*/
|
|
class Category extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'cash_flow_categories';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'idbus',
|
|
'iduser',
|
|
'name',
|
|
'type',
|
|
'color',
|
|
'icon',
|
|
'is_active'
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'idbus' => 'integer',
|
|
'iduser' => 'integer',
|
|
'is_active' => 'boolean',
|
|
'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'];
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* transactions - Get transactions for this category
|
|
*
|
|
* @return HasMany
|
|
*/
|
|
public function transactions(): HasMany
|
|
{
|
|
return $this->hasMany(Transaction::class, 'category_id');
|
|
}
|
|
}
|