194 lines
6.8 KiB
PHP
194 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace Modules\SupplyChain\Http\Controllers;
|
|
|
|
use App\Http\MenuIcons;
|
|
use App\Utils\ModuleUtil;
|
|
use Illuminate\Routing\Controller;
|
|
use Menu;
|
|
use Modules\SupplyChain\Services\SupplyChainIntegrationService;
|
|
|
|
class DataController extends Controller
|
|
{
|
|
public function superadmin_package()
|
|
{
|
|
return [
|
|
[
|
|
'name' => 'supplychain_module',
|
|
'label' => __('supplychain::lang.module_name'),
|
|
'default' => false,
|
|
],
|
|
];
|
|
}
|
|
|
|
public function user_permissions()
|
|
{
|
|
return [
|
|
['value' => 'supplychain.access', 'label' => __('supplychain::lang.access'), 'default' => false],
|
|
['value' => 'supplychain.view', 'label' => __('supplychain::lang.view_dashboard'), 'default' => false],
|
|
['value' => 'supplychain.scorecard.view', 'label' => __('supplychain::lang.scorecard_view'), 'default' => false],
|
|
['value' => 'supplychain.scorecard.create', 'label' => __('supplychain::lang.scorecard_create'), 'default' => false],
|
|
['value' => 'supplychain.forecast.view', 'label' => __('supplychain::lang.forecast_view'), 'default' => false],
|
|
['value' => 'supplychain.forecast.create', 'label' => __('supplychain::lang.forecast_create'), 'default' => false],
|
|
['value' => 'supplychain.rfq.view', 'label' => __('supplychain::lang.rfq_view'), 'default' => false],
|
|
['value' => 'supplychain.rfq.create', 'label' => __('supplychain::lang.rfq_create'), 'default' => false],
|
|
['value' => 'supplychain.rfq.update', 'label' => __('supplychain::lang.rfq_update'), 'default' => false],
|
|
];
|
|
}
|
|
|
|
public function get_contact_view_tabs()
|
|
{
|
|
$module_util = new ModuleUtil();
|
|
$business_id = request()->session()->get('user.business_id');
|
|
|
|
if (! \Module::has('SupplyChain') || ! \Module::isEnabled('SupplyChain')) {
|
|
return [];
|
|
}
|
|
|
|
if (! $module_util->isModuleInstalled('SupplyChain')
|
|
|| ! $module_util->hasThePermissionInSubscription($business_id, 'supplychain_module')) {
|
|
return [];
|
|
}
|
|
|
|
if (! auth()->user()->can('supplychain.scorecard.view')) {
|
|
return [];
|
|
}
|
|
|
|
return [
|
|
[
|
|
'tab_menu_path' => 'supplychain::contact.partial.tab_menu',
|
|
'tab_content_path' => 'supplychain::contact.partial.tab_content',
|
|
'tab_data' => [],
|
|
'module_js_path' => 'supplychain::contact.partial.tab_js',
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* IE MRP hook — import shortages into demand forecasts.
|
|
*
|
|
* @param mixed $run
|
|
*/
|
|
public function after_mrp_run($run)
|
|
{
|
|
if (! class_exists(SupplyChainIntegrationService::class)) {
|
|
return null;
|
|
}
|
|
|
|
return app(SupplyChainIntegrationService::class)->afterMrpRun($run);
|
|
}
|
|
|
|
/**
|
|
* IE MRP hook — provide forecast demand by variation.
|
|
*
|
|
* @param array<string, mixed> $data
|
|
*/
|
|
public function get_mrp_demand_inputs($data)
|
|
{
|
|
if (! class_exists(SupplyChainIntegrationService::class)) {
|
|
return [];
|
|
}
|
|
|
|
$businessId = (int) ($data['business_id'] ?? 0);
|
|
|
|
return app(SupplyChainIntegrationService::class)->getMrpDemandInputs($businessId);
|
|
}
|
|
|
|
/**
|
|
* IE MRP hook — enrich shortage analysis with demand forecasts.
|
|
*
|
|
* @param array<string, mixed> $data
|
|
*/
|
|
public function enrich_mrp_analysis($data)
|
|
{
|
|
if (! class_exists(SupplyChainIntegrationService::class)) {
|
|
return $data['analysis'] ?? [];
|
|
}
|
|
|
|
$businessId = (int) ($data['business_id'] ?? 0);
|
|
$analysis = $data['analysis'] ?? [];
|
|
|
|
if ($businessId <= 0 || empty($analysis)) {
|
|
return $analysis;
|
|
}
|
|
|
|
return app(SupplyChainIntegrationService::class)->enrichMrpAnalysis($businessId, $analysis);
|
|
}
|
|
|
|
public function modifyAdminMenu()
|
|
{
|
|
if (! \Module::has('SupplyChain') || ! \Module::isEnabled('SupplyChain')) {
|
|
return;
|
|
}
|
|
|
|
$business_id = session()->get('user.business_id');
|
|
$module_util = new ModuleUtil();
|
|
$is_enabled = (bool) $module_util->isModuleInstalled('SupplyChain');
|
|
|
|
if (! $is_enabled) {
|
|
return;
|
|
}
|
|
|
|
$user = auth()->user();
|
|
if (! $user->can('supplychain.access') && ! $user->can('supplychain.view')) {
|
|
return;
|
|
}
|
|
|
|
$hasSubscription = true;
|
|
if ($module_util->isSuperadminInstalled()) {
|
|
$hasSubscription = (bool) $module_util->hasThePermissionInSubscription($business_id, 'supplychain_module');
|
|
}
|
|
|
|
if (! $hasSubscription) {
|
|
return;
|
|
}
|
|
|
|
Menu::modify('admin-sidebar-menu', function ($menu) {
|
|
$menu->dropdown(
|
|
__('supplychain::lang.module_name'),
|
|
function ($sub) {
|
|
$user = auth()->user();
|
|
|
|
if ($user->can('supplychain.view') || $user->can('supplychain.access')) {
|
|
$sub->url(
|
|
action([DashboardController::class, 'index']),
|
|
__('supplychain::lang.dashboard'),
|
|
['active' => request()->segment(1) == 'supplychain' && request()->segment(2) == 'dashboard']
|
|
);
|
|
}
|
|
|
|
if ($user->can('supplychain.scorecard.view')) {
|
|
$sub->url(
|
|
action([SupplierScorecardController::class, 'index']),
|
|
__('supplychain::lang.supplier_scorecards'),
|
|
['active' => request()->segment(2) == 'supplier-scorecards']
|
|
);
|
|
}
|
|
|
|
if ($user->can('supplychain.forecast.view')) {
|
|
$sub->url(
|
|
action([DemandForecastController::class, 'index']),
|
|
__('supplychain::lang.demand_forecasts'),
|
|
['active' => request()->segment(2) == 'demand-forecasts']
|
|
);
|
|
}
|
|
|
|
if ($user->can('supplychain.rfq.view')) {
|
|
$sub->url(
|
|
action([RfqController::class, 'index']),
|
|
__('supplychain::lang.rfq'),
|
|
['active' => request()->segment(2) == 'rfq']
|
|
);
|
|
}
|
|
},
|
|
[
|
|
'icon' => MenuIcons::svg('truck'),
|
|
'active' => request()->segment(1) == 'supplychain',
|
|
'data-module' => 'SupplyChain',
|
|
'data-menu-group' => 'operations',
|
|
]
|
|
)->order(86);
|
|
});
|
|
}
|
|
}
|