commit compras1 2911
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-29 05:28:30 +02:00
parent 1ddabbbdcc
commit 448948a487
137 changed files with 9481 additions and 1926 deletions
@@ -13,6 +13,8 @@ use App\Models\Supplier;
use App\Models\User;
use App\Models\Warehouse;
use App\Services\AgreementOrderLimits;
use App\Services\CapitalRegister;
use App\Services\OperationalOrders;
use App\Services\OrganizationAccess;
use App\Services\SavedProcurementSearches;
use App\Services\SupplyPlanning;
@@ -56,8 +58,12 @@ class ProcurementSearchController extends Controller
$warehouseRequestSearchAvailable = config('procurement_search.warehouse_requests_metadata_enabled') === true
&& $warehouseSelectors !== null && Schema::hasTable('warehouse_requests')
&& $actor->hasFunctions(['admin', 'warehouse_request_read', 'warehouse_request_prepare', 'warehouse_request_review', 'warehouse_request_deliver']);
$capitalQuery = app(CapitalRegister::class)->searchQuery($actor);
$operationalQuery = app(OperationalOrders::class)->searchQuery($actor);
$request->validate(['capital_page' => 'nullable|integer|min:1|max:1000000']);
$request->validate(['operational_orders_page' => 'nullable|integer|min:1|max:1000000']);
$request->validate(['equipment_page' => 'nullable|integer|min:1|max:1000000', 'stock_page' => 'nullable|integer|min:1|max:1000000', 'warehouses_page' => 'nullable|integer|min:1|max:1000000', 'receipts_page' => 'nullable|integer|min:1|max:1000000']);
$groups = DB::transaction(function () use ($actor, $term, $planning, $supplySearchAvailable, $supplySelectors, $warehouseRequestSearchAvailable, $warehouseSelectors) {
$groups = DB::transaction(function () use ($actor, $term, $planning, $supplySearchAvailable, $supplySelectors, $warehouseRequestSearchAvailable, $warehouseSelectors, $capitalQuery, $operationalQuery) {
if (DB::getDriverName() === 'pgsql' && DB::transactionLevel() === 1) {
DB::statement('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY');
}
@@ -148,6 +154,40 @@ class ProcurementSearchController extends Controller
$groups[] = ['key' => 'warehouse_requests', 'title' => 'Requisições internas de armazém', 'records' => $records];
}
if ($capitalQuery !== null) {
$capitalQuery->where(function ($query) use ($pattern) {
foreach (['code', 'name', 'reference'] as $field) {
// Fixed register fields only; literal search text remains bound.
$expression = DB::getDriverName() === 'pgsql'
? 'LOWER("data"->>\''.$field.'\') LIKE ? ESCAPE \'!\''
: "LOWER(json_extract(data, '$.".$field."')) LIKE ? ESCAPE '!'";
$query->orWhereRaw($expression, [$pattern]);
}
});
$records = $capitalQuery->latest('id')->paginate(15, ['id', 'record_key', 'version', 'state',
'data->code as code', 'data->name as name', 'data->type as register_type'], 'capital_page')->withQueryString()
->through(fn ($row) => ['id' => $row->id,
'title' => ($row->getAttribute('register_type') === 'asset' ? 'Imobilizado' : 'Projecto').' '.$row->getAttribute('code').' — '.$row->getAttribute('name').' · v'.$row->version,
'detail' => $row->state, 'href' => '/projectos-imobilizado?history='.rawurlencode($row->record_key)]);
$groups[] = ['key' => 'capital', 'title' => 'Projectos e imobilizado', 'records' => $records];
}
if ($operationalQuery !== null) {
$operationalQuery->where(function ($query) use ($pattern) {
foreach (['reference', 'utilisation_location', 'description'] as $field) {
$expression = DB::getDriverName() === 'pgsql'
? 'LOWER("data"->>\''.$field.'\') LIKE ? ESCAPE \'!\''
: "LOWER(json_extract(data, '$.".$field."')) LIKE ? ESCAPE '!'";
$query->orWhereRaw($expression, [$pattern]);
}
});
$records = $operationalQuery->latest('id')->paginate(15, ['id', 'version', 'state', 'data->reference as reference', 'data->type as order_type'], 'operational_orders_page')->withQueryString()
->through(fn ($row) => ['id' => $row->id,
'title' => ($row->getAttribute('order_type') === 'production' ? 'Produção' : 'Manutenção').' '.$row->getAttribute('reference').' · v'.$row->version,
'detail' => $row->state, 'href' => '/ordens-operacionais?order_id='.$row->id.'#op-order-'.$row->id]);
$groups[] = ['key' => 'operational_orders', 'title' => 'Ordens de produção e manutenção', 'records' => $records];
}
return $groups;
});
Inertia::encryptHistory();
@@ -156,6 +196,8 @@ class ProcurementSearchController extends Controller
'invoiceSearchAvailable' => config('procurement_search.finance_metadata_enabled') === true && $actor->hasFunctions([PurchasingRole::Admin, PurchasingRole::Finance]),
'supplySearchAvailable' => $supplySearchAvailable,
'warehouseRequestSearchAvailable' => $warehouseRequestSearchAvailable,
'capitalSearchAvailable' => $capitalQuery !== null,
'operationalOrderSearchAvailable' => $operationalQuery !== null,
])->toResponse($request);
$response->headers->set('Cache-Control', 'private, no-store, max-age=0');