Files
logisticsAPI/app/Filament/Pages/Tiers.php
Marvin 7df94b64fa Implement toggle for read/write mode across entity pages and enhance Documents and Divers functionality
- Added a toggle for switching between read and write modes on the Articles, Documents, Journaux, Tiers, and Divers pages, allowing users to access both data retrieval and data submission endpoints.
- Updated the Documents page to cover all 9 documented endpoints, including 7 for reading and 2 for writing, with appropriate error handling.
- Created a new Divers page to handle three endpoints: getserialnumber, codes_list, and custom_geninv_updatestock (the latter being non-functional).
- Introduced new methods in LogisticsService for handling PDF generation and stock updates, with corresponding updates in the API documentation.
- Improved form field components for better visual spacing in input fields.
2026-02-20 15:51:58 +01:00

86 lines
2.3 KiB
PHP

<?php
namespace App\Filament\Pages;
use App\Exceptions\LogisticsApiException;
use App\Services\LogisticsService;
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,custname';
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 function searchTiers(): void
{
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 = $response['error'] ?? null;
} catch (LogisticsApiException $e) {
$this->errorMessage = $e->getMessage();
$this->data = [];
} catch (\Throwable $e) {
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
$this->data = [];
}
}
public function getArtHistory(): void
{
if (blank($this->historyThirdId)) {
return;
}
try {
$service = app(LogisticsService::class);
$response = $service->thirdGetArtHistory($this->historyThirdId);
$this->historyData = $response['data'] ?? [];
$this->errorMessage = $response['error'] ?? null;
} catch (LogisticsApiException $e) {
$this->errorMessage = $e->getMessage();
$this->historyData = [];
} catch (\Throwable $e) {
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
$this->historyData = [];
}
}
}