Files
logisticsAPI/app/Filament/Pages/Tiers.php
Marvin c84e0c680a Update Tiers functionality and enhance API documentation
- Changed the default value of the `$select` property in Tiers.php from `custid,custname` to `custid,name` to reflect valid column names.
- Updated the tiers.blade.php view to align the placeholder for the select field with the new default value.
- Enhanced the documentation for the `third_list` and `third_GetArtHistory` endpoints, detailing valid search columns, metadata, and response structures.
- Added new tests in TiersPageTest.php to verify the default select value, API parameter handling, and metadata storage.
- Overall, improved the user experience and API interaction for managing tiers.
2026-02-23 11:58:14 +01:00

107 lines
2.9 KiB
PHP

<?php
namespace App\Filament\Pages;
use App\Exceptions\LogisticsApiException;
use App\Services\LogisticsService;
use App\Support\ApiErrorTranslator;
use Filament\Pages\Page;
use Filament\Support\Icons\Heroicon;
class Tiers extends Page
{
protected static string|\BackedEnum|null $navigationIcon = Heroicon::OutlinedUsers;
protected static ?string $navigationLabel = 'Tiers';
protected static ?string $title = 'Tiers';
protected static ?int $navigationSort = 5;
protected string $view = 'filament.pages.tiers';
public string $mode = 'read';
public string $select = 'custid,name';
public string $search = '';
public int $results = 10;
public string $historyThirdId = '';
public array $data = [];
public array $historyData = [];
public ?array $metadata = null;
public ?string $errorMessage = null;
public bool $hasSearched = false;
public bool $hasHistory = false;
public function searchTiers(): void
{
$this->errorMessage = null;
if (blank($this->search)) {
$this->errorMessage = 'Le champ de recherche (search) est obligatoire.';
return;
}
$this->hasSearched = true;
try {
$service = app(LogisticsService::class);
$params = array_filter([
'select' => $this->select,
'results' => $this->results,
'search' => $this->search,
]);
$response = $service->thirdList($params);
$this->data = $response['data'] ?? [];
$this->metadata = $response['metadata'] ?? null;
$this->errorMessage = ApiErrorTranslator::translate($response['error'] ?? null);
} catch (LogisticsApiException $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->data = [];
} catch (\Throwable $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->data = [];
}
}
public function getArtHistory(): void
{
$this->errorMessage = null;
if (blank($this->historyThirdId)) {
$this->errorMessage = 'Le champ identifiant tiers (thirdid) est obligatoire.';
return;
}
$this->hasHistory = true;
try {
$service = app(LogisticsService::class);
$response = $service->thirdGetArtHistory($this->historyThirdId);
$this->historyData = $response['data'] ?? [];
$this->errorMessage = ApiErrorTranslator::translate($response['error'] ?? null);
} catch (LogisticsApiException $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->historyData = [];
} catch (\Throwable $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->historyData = [];
}
}
}