270 lines
8.8 KiB
PHP
Executable File
270 lines
8.8 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* SysCMS - Content Management System
|
|
*
|
|
* Copyright (c) 2026 SysCMS Team
|
|
* All rights reserved.
|
|
*
|
|
* Author: SysCMS Team
|
|
* Project: SysCMS
|
|
*/
|
|
|
|
namespace Modules\Erp\Controllers;
|
|
|
|
use App\Controllers\BaseAdminController;
|
|
use Kernel\View;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use App\Models\Module;
|
|
|
|
/**
|
|
* ERPController - Controller for handling ERP central dashboard
|
|
*
|
|
* @package Modules\Erp\Controllers
|
|
*/
|
|
class ERPController extends BaseAdminController
|
|
{
|
|
/**
|
|
* ERPController constructor
|
|
*
|
|
* @param View $view
|
|
*/
|
|
public function __construct(View $view)
|
|
{
|
|
parent::__construct($view);
|
|
}
|
|
|
|
/**
|
|
* Display the User Manual.
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function manual(): Response
|
|
{
|
|
return $this->renderAdminView('@erp/admin/manual.twig', [
|
|
'title' => __('erp.user_manual') ?? 'Manual do Usuário'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Display the Implementation Guide.
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function implementationGuide(): Response
|
|
{
|
|
return $this->renderAdminView('@erp/admin/implementation_guide.twig', [
|
|
'title' => __('erp.admin.implementation_guide') ?? 'Guia de Implantação ERP'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* index - Display the ERP central dashboard
|
|
*
|
|
* @param Request $request
|
|
* @return Response
|
|
*/
|
|
public function index(Request $request): Response
|
|
{
|
|
$user = $this->getCurrentUser();
|
|
|
|
// Block Super Admin from accessing ERP
|
|
if ($user && $user->isSuperAdmin()) {
|
|
return $this->renderAdminView('errors/unauthorized.twig', [
|
|
'message' => 'Super Admin não tem permissão para acessar o módulo ERP.'
|
|
]);
|
|
}
|
|
|
|
// Allow access ONLY to Admin and Member
|
|
$hasAccess = $user && (
|
|
$user->isAdmin() ||
|
|
$user->isMember()
|
|
);
|
|
|
|
if (!$hasAccess) {
|
|
$this->addFlash('error', __('auth.unauthorized'));
|
|
return $this->redirect('/admin');
|
|
}
|
|
|
|
// Get all active modules
|
|
$activeModules = Module::query()
|
|
->where('modules_ative', true)
|
|
->get();
|
|
|
|
$modules = [];
|
|
|
|
// Define specific configurations for known modules (URL overrides, colors, icons if missing in DB)
|
|
$moduleConfigs = [
|
|
'company' => [
|
|
'url' => '/admin/companies',
|
|
'icon' => 'bi bi-building-gear',
|
|
'color' => '#0d6efd'
|
|
],
|
|
'erpclients' => [
|
|
'url' => '/admin/erp/clients',
|
|
'color' => '#0dcaf0'
|
|
],
|
|
'erpmemberpermissions' => [
|
|
'url' => '/admin/erp/permissions',
|
|
'icon' => 'bi bi-person-lock',
|
|
'color' => '#198754'
|
|
],
|
|
'erphrm' => [
|
|
'url' => '/admin/erp/hrm',
|
|
'color' => '#6f42c1'
|
|
],
|
|
'erpprojects' => [
|
|
'url' => '/admin/erp/projects',
|
|
'color' => '#6610f2'
|
|
],
|
|
'erpservtags' => [
|
|
'url' => '/admin/erp/servtags',
|
|
'icon' => 'bi bi-tags',
|
|
'color' => '#d63384'
|
|
],
|
|
'erpcarriers' => [
|
|
'url' => '/admin/erp/carriers',
|
|
'color' => '#0dcaf0'
|
|
],
|
|
'erpproducts' => [
|
|
'url' => '/admin/erp/products',
|
|
'color' => '#6610f2'
|
|
],
|
|
'erpsales' => [
|
|
'url' => '/admin/erp/sales',
|
|
'color' => '#198754'
|
|
],
|
|
'erpvehicles' => [
|
|
'url' => '/admin/erp/vehicles',
|
|
'color' => '#fd7e14'
|
|
],
|
|
'erpcrm' => [
|
|
'url' => '/admin/erp/crm',
|
|
'icon' => 'bi bi-people',
|
|
'color' => '#fd7e14'
|
|
],
|
|
'erpfinance' => [
|
|
'url' => '/admin/erp/finance',
|
|
'color' => '#198754'
|
|
],
|
|
'erpstock' => [
|
|
'url' => '/admin/erp/stock',
|
|
'color' => '#fd7e14'
|
|
],
|
|
'erprawmaterials' => [
|
|
'url' => '/admin/erp/rawmaterials',
|
|
'color' => '#6f42c1'
|
|
],
|
|
'erpvendors' => [
|
|
'url' => '/admin/erp/vendors',
|
|
'icon' => 'bi bi-shop',
|
|
'color' => '#0dcaf0'
|
|
],
|
|
'erporganization' => [
|
|
'url' => '/admin/erp/organization',
|
|
'color' => '#0d6efd'
|
|
],
|
|
'erpgercom' => [
|
|
'url' => '/admin/erp/gercom',
|
|
'color' => '#ffc107'
|
|
],
|
|
'erppoe' => [
|
|
'url' => '/admin/erp/poe',
|
|
'icon' => 'bi bi-clipboard-check',
|
|
'color' => '#6c757d'
|
|
],
|
|
'erpproduction' => [
|
|
'url' => '/admin/erp/production',
|
|
'icon' => 'bi bi-gear-wide-connected',
|
|
'color' => '#fd7e14'
|
|
],
|
|
];
|
|
|
|
foreach ($activeModules as $module) {
|
|
// Use module path (folder name) as the robust identifier/slug
|
|
// Fallback to name if path is empty (though path should exist)
|
|
$slug = !empty($module->modules_path) ? basename($module->modules_path) : strtolower(str_replace(' ', '', trim($module->modules_name)));
|
|
$slug = strtolower($slug); // Ensure lowercase
|
|
|
|
// Skip main ERP module
|
|
if ($slug === 'erp') continue;
|
|
|
|
// Filter only Company or ERP modules
|
|
if ($slug !== 'company' && !str_starts_with($slug, 'erp')) continue;
|
|
|
|
// Check permission
|
|
// Use slug for permission check (standard convention: slug.view)
|
|
$permission = $slug . '.view';
|
|
|
|
// If admin, bypass check. If not admin, check permission.
|
|
if (!$user->isAdmin() && !$user->hasPermission($permission)) {
|
|
// Fallback: check permission based on name if slug fails (legacy support)
|
|
$legacyName = strtolower(str_replace(' ', '', trim($module->modules_name)));
|
|
if ($legacyName !== $slug && !$user->hasPermission($legacyName . '.view')) {
|
|
continue;
|
|
}
|
|
// If neither permission exists, skip
|
|
if ($legacyName === $slug) continue;
|
|
}
|
|
|
|
// Determine URL
|
|
// Check config by slug
|
|
$config = $moduleConfigs[$slug] ?? null;
|
|
|
|
if ($config && isset($config['url'])) {
|
|
$url = url($config['url']);
|
|
} else {
|
|
// Auto-generate URL from slug
|
|
$suffix = str_replace('erp', '', $slug);
|
|
if ($slug === 'company') $suffix = 'companies';
|
|
|
|
$url = url('/admin/erp/' . $suffix);
|
|
}
|
|
|
|
// Determine Icon
|
|
$icon = $module->modules_icon;
|
|
if (empty($icon)) {
|
|
$icon = isset($config['icon']) ? $config['icon'] : 'bi bi-box';
|
|
}
|
|
|
|
// Determine Color
|
|
$color = isset($config['color']) ? $config['color'] : '#6c757d';
|
|
|
|
// Determine Name and Description (Try translation, fallback to DB)
|
|
$suffix = str_replace('erp', '', $slug);
|
|
if ($slug === 'company') $suffix = 'company';
|
|
|
|
$nameKey = "erp.modules.{$suffix}.name";
|
|
$descKey = "erp.modules.{$suffix}.description";
|
|
|
|
// Get platformName using PlatformService
|
|
$platformService = new \App\Services\PlatformService();
|
|
$platformName = $platformService->getPlatformName();
|
|
|
|
$displayName = __($nameKey, ['platformName' => $platformName]);
|
|
if ($displayName === $nameKey) {
|
|
$displayName = $module->modules_display_name ?: ucfirst($slug);
|
|
}
|
|
|
|
$description = __($descKey, ['platformName' => $platformName]);
|
|
if ($description === $descKey) {
|
|
$description = $module->modules_description ?: '';
|
|
}
|
|
|
|
$modules[] = [
|
|
'name' => $displayName,
|
|
'url' => $url,
|
|
'icon' => $icon,
|
|
'color' => $color,
|
|
'description' => $description
|
|
];
|
|
}
|
|
|
|
return $this->renderAdminView('@erp/admin/index.twig', [
|
|
'title' => __('erp.admin.title'),
|
|
'modules' => $modules
|
|
]);
|
|
}
|
|
}
|