@@ -3,9 +3,11 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ConflictDeclaration;
|
||||
use App\Models\ConflictRelease;
|
||||
use App\Models\Requisition;
|
||||
use App\Models\Supplier;
|
||||
use App\Services\ConflictGuard;
|
||||
use App\Services\ConflictReleases;
|
||||
use App\Services\RequisitionWorkflow;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -70,12 +72,23 @@ class ConflictDeclarationController extends Controller
|
||||
$latest = $history->last();
|
||||
|
||||
Inertia::encryptHistory();
|
||||
$response = Inertia::render('conflicts/show', ['history' => $history, 'canCorrect' => $latest?->user_id === $this->staffIdentity($request)->id])->toResponse($request);
|
||||
$releases = app(ConflictReleases::class);
|
||||
$release = $releases->ready() ? ConflictRelease::query()->where('root_id', $rootId)->first() : null;
|
||||
$response = Inertia::render('conflicts/show', ['history' => $history, 'canCorrect' => $latest?->user_id === $this->staffIdentity($request)->id,
|
||||
'release' => $release, 'canAuthoriseRelease' => $release === null && $latest?->has_conflict === true && $releases->canAuthorise($this->staffIdentity($request)),
|
||||
])->toResponse($request);
|
||||
$response->headers->set('Cache-Control', 'private, no-store, max-age=0');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function authoriseRelease(Request $request, ConflictDeclaration $declaration, ConflictReleases $releases): RedirectResponse
|
||||
{
|
||||
$releases->authorise($this->staffIdentity($request), $declaration, $request->only(['operation_key', 'reason']));
|
||||
|
||||
return to_route('conflicts.show', $declaration);
|
||||
}
|
||||
|
||||
public function update(Request $request, ConflictDeclaration $declaration, ConflictGuard $guard, RequisitionWorkflow $workflow): RedirectResponse
|
||||
{
|
||||
abort_unless($declaration->user_id === $this->staffIdentity($request)->id, 403);
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Requisition;
|
||||
use App\Services\OperationalOrders;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class OperationalOrdersController extends Controller
|
||||
{
|
||||
public function index(Request $request, OperationalOrders $orders, ?Requisition $requisition = null): Response
|
||||
{
|
||||
$request->validate(['page' => 'nullable|integer|min:1|max:1000000']);
|
||||
Inertia::encryptHistory();
|
||||
$response = Inertia::render('requisitions/operational-orders', $orders->workspace($this->staffIdentity($request), $requisition))->toResponse($request);
|
||||
$response->headers->set('Cache-Control', 'private, no-store, max-age=0');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function configure(Request $request, OperationalOrders $orders): Response
|
||||
{
|
||||
$orders->configure($this->staffIdentity($request), $request->all());
|
||||
|
||||
return back()->with('success', 'Origem das novas ordens configurada.');
|
||||
}
|
||||
|
||||
public function store(Request $request, OperationalOrders $orders): Response
|
||||
{
|
||||
$orders->save($this->staffIdentity($request), $request->all());
|
||||
|
||||
return back()->with('success', 'Ordem registada e original preservado.');
|
||||
}
|
||||
|
||||
public function link(Request $request, Requisition $requisition, OperationalOrders $orders): Response
|
||||
{
|
||||
$orders->link($this->staffIdentity($request), $requisition, $request->all());
|
||||
|
||||
return back()->with('success', 'Ordem ligada à linha da requisição.');
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ use App\Services\OrganizationConfiguration;
|
||||
use App\Services\RequisitionApprovalLevels;
|
||||
use App\Services\RequisitionCategories;
|
||||
use App\Services\RequisitionExpiry;
|
||||
use App\Services\UrgentQuotationBasis;
|
||||
use App\Services\WorkContext;
|
||||
use App\Services\WorkflowTasks;
|
||||
use Brick\Math\BigDecimal;
|
||||
@@ -52,6 +53,7 @@ class OrganizationConfigurationController extends Controller
|
||||
'companyDetails' => Tenant::query()->findOrFail($actor->tenant_id)->company_details,
|
||||
'companyRules' => $this->companyRules((int) $actor->tenant_id),
|
||||
'comparisonPolicy' => app(ComparisonPolicy::class)->company(Tenant::query()->findOrFail($actor->tenant_id)),
|
||||
'urgentQuotationReady' => app(UrgentQuotationBasis::class)->ready(),
|
||||
'intelligencePolicy' => app(IntelligencePolicy::class)->company(Tenant::query()->findOrFail($actor->tenant_id)),
|
||||
'intelligenceReady' => Schema::hasColumn('tenants', 'intelligence_policy'),
|
||||
'aiPlan' => app(AiPreparationPlan::class)->company(Tenant::query()->findOrFail($actor->tenant_id)),
|
||||
@@ -98,6 +100,7 @@ class OrganizationConfigurationController extends Controller
|
||||
$rules += ['first_limit' => ['required', 'string', 'regex:/^\d{1,12}(\.\d{1,2})?$/D'], 'second_limit' => ['required', 'string', 'regex:/^\d{1,12}(\.\d{1,2})?$/D'], 'includes_tax' => 'required|boolean', 'reason' => 'required|string|min:10|max:4000'];
|
||||
} elseif ($command === 'comparison') {
|
||||
$rules += ['minimum_proposals' => 'required|integer|between:1,100', 'minimum_evaluators' => 'required|integer|between:1,100',
|
||||
'urgent_minimum_proposals' => 'sometimes|nullable|integer|between:1,100',
|
||||
'weights' => 'required|array:price,quality,delivery,history,payment', 'reason' => 'required|string|min:10|max:4000'];
|
||||
foreach (array_keys(ComparisonPolicy::DEFAULTS['weights']) as $criterion) {
|
||||
$rules['weights.'.$criterion] = 'required|integer|between:0,100';
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\PrivateAuditExport;
|
||||
use App\Services\PrivateAuditAccess;
|
||||
use App\Services\PrivateAuditExporter;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Inertia\Inertia;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class PrivateAuditController extends Controller
|
||||
{
|
||||
public function index(Request $request, PrivateAuditAccess $access): Response
|
||||
{
|
||||
$scope = $access->current($this->staffIdentity($request));
|
||||
$request->validate(['page' => 'nullable|integer|min:1|max:1000000']);
|
||||
$exports = PrivateAuditExport::query()->where('created_by', $scope['actor']->id)->where('work_context', $scope['context'])->latest('id')->paginate(20)
|
||||
->through(fn (PrivateAuditExport $export) => ['id' => $export->id, 'families' => $export->families,
|
||||
'created_at' => $export->created_at, 'size' => $export->size, 'sha256' => $export->sha256,
|
||||
'download_url' => '/auditoria/privada/'.$export->id.'/download']);
|
||||
Inertia::encryptHistory();
|
||||
$response = Inertia::render('audit/private', ['families' => collect($scope['granted'])->map(fn (string $key) => ['key' => $key, 'label' => PrivateAuditAccess::FAMILIES[$key]['label']])->values(), 'exports' => $exports])->toResponse($request);
|
||||
$response->headers->set('Cache-Control', 'private, no-store, max-age=0');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function store(Request $request, PrivateAuditExporter $service): Response
|
||||
{
|
||||
$service->generate($this->staffIdentity($request), $request->all());
|
||||
|
||||
return redirect('/auditoria/privada')->with('success', 'Pacote privado preparado e verificado.');
|
||||
}
|
||||
|
||||
public function download(Request $request, PrivateAuditExport $export, PrivateAuditExporter $service): Response
|
||||
{
|
||||
$actor = $this->staffIdentity($request);
|
||||
$service->verifiedPath($actor, $export);
|
||||
// Snapshot the verified bytes before any response: a later file change cannot alter the download.
|
||||
$copy = tmpfile();
|
||||
abort_unless(is_resource($copy), 503);
|
||||
try {
|
||||
$source = Storage::disk('local')->readStream($export->path);
|
||||
abort_unless(is_resource($source), 409);
|
||||
try {
|
||||
$size = stream_copy_to_stream($source, $copy);
|
||||
} finally {
|
||||
fclose($source);
|
||||
}
|
||||
rewind($copy);
|
||||
$hash = hash_init('sha256');
|
||||
hash_update_stream($hash, $copy);
|
||||
abort_unless($size === $export->size && hash_equals($export->sha256, hash_final($hash)), 409);
|
||||
$service->verifiedPath($actor, $export);
|
||||
rewind($copy);
|
||||
|
||||
return response()->streamDownload(function () use ($copy): void {
|
||||
try {
|
||||
fpassthru($copy);
|
||||
} finally {
|
||||
fclose($copy);
|
||||
}
|
||||
}, 'auditoria-'.$export->id.'.zip', ['Content-Type' => 'application/zip', 'Content-Length' => (string) $export->size,
|
||||
'Cache-Control' => 'private, no-store, max-age=0', 'X-Content-Type-Options' => 'nosniff']);
|
||||
} catch (\Throwable $error) {
|
||||
fclose($copy);
|
||||
throw $error;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ use App\Services\QuotationExchange;
|
||||
use App\Services\QuotationParticipation;
|
||||
use App\Services\QuotationPricing;
|
||||
use App\Services\RequisitionWorkflow;
|
||||
use App\Services\UrgentQuotationBasis;
|
||||
use Brick\Math\BigDecimal;
|
||||
use Brick\Math\RoundingMode;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
@@ -72,6 +73,7 @@ class QuotationController extends Controller
|
||||
'ready' => $result['ready'],
|
||||
'topIds' => $result['top_ids'],
|
||||
'comparisonPolicy' => $result['policy'],
|
||||
'urgentQuotationReady' => app(UrgentQuotationBasis::class)->ready(),
|
||||
'exchangeRates' => app(QuotationExchange::class)->rates($requisition),
|
||||
'exchangeAvailable' => app(QuotationExchange::class)->ready(),
|
||||
'canRecordExchange' => $actor->hasFunctions([PurchasingRole::Finance]) && ! app(OrganizationAccess::class)->maintenanceOnly($actor)
|
||||
|
||||
@@ -20,6 +20,7 @@ use App\Services\EquipmentWorkflow;
|
||||
use App\Services\ImportEstimates;
|
||||
use App\Services\ImportTariffCodes;
|
||||
use App\Services\InternalSupplyTrace;
|
||||
use App\Services\OperationalOrders;
|
||||
use App\Services\OrganizationAccess;
|
||||
use App\Services\RequisitionAuditTrail;
|
||||
use App\Services\RequisitionBudgetDistributions;
|
||||
@@ -135,6 +136,7 @@ class RequisitionController extends Controller
|
||||
'importTariffsReady' => app(ImportTariffCodes::class)->ready(),
|
||||
'importEstimatesReady' => app(ImportEstimates::class)->ready(),
|
||||
'capitalRegisterReady' => app(CapitalRegister::class)->ready(),
|
||||
'operationalOrdersReady' => app(OperationalOrders::class)->ready(),
|
||||
'accountsReady' => app(RequisitionLedgerAccounts::class)->ready(),
|
||||
'expiryReady' => app(RequisitionExpiry::class)->ready(),
|
||||
'canDecide' => $requisition->canDecide($this->actor($request)),
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Requisition;
|
||||
use App\Services\UrgentQuotationBasis;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class UrgentQuotationController extends Controller
|
||||
{
|
||||
public function show(Request $request, Requisition $requisition, UrgentQuotationBasis $service): Response
|
||||
{
|
||||
$request->validate(['page' => 'nullable|integer|min:1|max:1000000']);
|
||||
Inertia::encryptHistory();
|
||||
$response = Inertia::render('requisitions/urgent-stock', $service->workspace($this->staffIdentity($request), $requisition))->toResponse($request);
|
||||
$response->headers->set('Cache-Control', 'private, no-store, max-age=0');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function store(Request $request, Requisition $requisition, UrgentQuotationBasis $service): Response
|
||||
{
|
||||
$service->record($this->staffIdentity($request), $requisition, $request->all());
|
||||
|
||||
return back()->with('success', 'Stock mínimo documentado para esta linha e ciclo.');
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\OperationalOrders;
|
||||
use App\Services\OrganizationAccess;
|
||||
use App\Services\SupplierPayables;
|
||||
use App\Services\WorkContext;
|
||||
@@ -64,6 +65,8 @@ class HandleInertiaRequests extends Middleware
|
||||
],
|
||||
'payablesAvailable' => $actor !== null && app(SupplierPayables::class)->can($actor, 'view'),
|
||||
'orderCancellationAvailable' => $actor !== null && (bool) config('order_cancellation.enabled') && Schema::hasTable('order_cancellations'),
|
||||
'operationalOrdersAvailable' => $actor !== null && app(OperationalOrders::class)->ready(),
|
||||
'privateAuditAvailable' => $actor !== null && app(\App\Services\PrivateAuditAccess::class)->ready(),
|
||||
'sidebarOpen' => ! $request->hasCookie('sidebar_state') || $request->cookie('sidebar_state') === 'true',
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user