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.
This commit is contained in:
2026-02-20 15:51:58 +01:00
parent 8637dcc7cb
commit 7df94b64fa
22 changed files with 1777 additions and 376 deletions

View File

@@ -19,6 +19,8 @@ class Articles extends Page
protected string $view = 'filament.pages.articles';
public string $mode = 'read';
public string $search = '';
public string $select = 'artid,artname';

View File

@@ -0,0 +1,117 @@
<?php
namespace App\Filament\Pages;
use App\Exceptions\LogisticsApiException;
use App\Services\LogisticsService;
use Filament\Pages\Page;
use Filament\Support\Icons\Heroicon;
class Divers extends Page
{
protected static string|\BackedEnum|null $navigationIcon = Heroicon::OutlinedWrenchScrewdriver;
protected static ?string $navigationLabel = 'Divers';
protected static ?string $title = 'Divers';
protected static ?int $navigationSort = 6;
protected string $view = 'filament.pages.divers';
public string $mode = 'read';
// getserialnumber
public array $serialData = [];
// codes_list
public string $code = '';
public array $codesData = [];
// custom_geninv_updatestock
public string $stkArtId = '';
public string $stkId = '';
public string $stkQty = '';
public string $stkToCheck = '';
public string $stkToCheckDetail = '';
public string $stkMode = '';
public array $updateStockResult = [];
public ?string $errorMessage = null;
public function getSerialNumber(): void
{
try {
$service = app(LogisticsService::class);
$response = $service->getSerialNumber();
$this->serialData = is_array($response['data'] ?? null) ? $response['data'] : ['value' => $response['data'] ?? null];
$this->errorMessage = $response['error'] ?? null;
} catch (LogisticsApiException $e) {
$this->errorMessage = $e->getMessage();
$this->serialData = [];
} catch (\Throwable $e) {
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
$this->serialData = [];
}
}
public function searchCodes(): void
{
if (blank($this->code)) {
return;
}
try {
$service = app(LogisticsService::class);
$response = $service->codesList(['code' => $this->code]);
$this->codesData = $response['data'] ?? [];
$this->errorMessage = $response['error'] ?? null;
} catch (LogisticsApiException $e) {
$this->errorMessage = $e->getMessage();
$this->codesData = [];
} catch (\Throwable $e) {
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
$this->codesData = [];
}
}
public function updateStock(): void
{
if (blank($this->stkArtId) || blank($this->stkId) || blank($this->stkQty)) {
return;
}
try {
$service = app(LogisticsService::class);
$params = array_filter([
'ARTID' => $this->stkArtId,
'STKID' => $this->stkId,
'QTY' => $this->stkQty,
'TOCHECK' => $this->stkToCheck,
'TOCHECKDETAIL' => $this->stkToCheckDetail,
'MODE' => $this->stkMode,
]);
$response = $service->customGeninvUpdatestock($params);
$this->updateStockResult = $response['data'] ?? [];
$this->errorMessage = $response['error'] ?? null;
} catch (LogisticsApiException $e) {
$this->errorMessage = $e->getMessage();
$this->updateStockResult = [];
} catch (\Throwable $e) {
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
$this->updateStockResult = [];
}
}
}

View File

@@ -19,18 +19,100 @@ class Documents extends Page
protected string $view = 'filament.pages.documents';
public string $mode = 'read';
// document_list
public string $select = 'jnl,number,thirdid,date';
public string $thirdId = '';
// document_detail
public string $detailJnl = '';
public string $detailNumber = '';
// Document_GetStatusList
public string $statusJnl = '';
// Document_GetUnitPriceAndVat
public string $priceArtId = '';
public string $priceQty = '';
public string $priceJnl = '';
public string $priceThirdId = '';
public string $priceDate = '';
// Document_GetDueDate
public string $payDelay = '';
public string $dueDateInput = '';
// Document_GetAttachListThumbnail
public string $attachJnl = '';
public string $attachNumber = '';
// Document_GetPDF
public string $pdfJnl = '';
public string $pdfNumber = '';
public string $pdfLayout = '';
// document_add
public string $addThirdId = '';
public string $addDate = '';
public string $addArtIds = '';
public string $addQty = '';
public string $addSalePrice = '';
public string $addJnl = '';
public string $addDiscount = '';
public string $addVatId = '';
public string $addVatPc = '';
// document_mod
public string $modNumber = '';
public string $modJnl = '';
public string $modThirdId = '';
public string $modArtIds = '';
public string $modQty = '';
public string $modSalePrice = '';
// Data holders
public array $data = [];
public array $detailData = [];
public array $statusData = [];
public array $priceData = [];
public array $dueDateData = [];
public array $attachData = [];
public array $pdfData = [];
public array $addResult = [];
public array $modResult = [];
public ?array $metadata = null;
public ?string $errorMessage = null;
@@ -79,4 +161,204 @@ class Documents extends Page
$this->detailData = [];
}
}
public function getStatusList(): void
{
if (blank($this->statusJnl)) {
return;
}
try {
$service = app(LogisticsService::class);
$response = $service->documentGetStatusList($this->statusJnl);
$this->statusData = $response['data'] ?? [];
$this->errorMessage = $response['error'] ?? null;
} catch (LogisticsApiException $e) {
$this->errorMessage = $e->getMessage();
$this->statusData = [];
} catch (\Throwable $e) {
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
$this->statusData = [];
}
}
public function getUnitPriceAndVat(): void
{
if (blank($this->priceArtId) || blank($this->priceQty) || blank($this->priceJnl) || blank($this->priceThirdId) || blank($this->priceDate)) {
return;
}
try {
$service = app(LogisticsService::class);
$response = $service->documentGetUnitPriceAndVat([
'ARTID' => $this->priceArtId,
'QTY' => $this->priceQty,
'JNL' => $this->priceJnl,
'THIRDID' => $this->priceThirdId,
'DATE' => $this->priceDate,
]);
$this->priceData = $response['data'] ?? [];
$this->errorMessage = $response['error'] ?? null;
} catch (LogisticsApiException $e) {
$this->errorMessage = $e->getMessage();
$this->priceData = [];
} catch (\Throwable $e) {
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
$this->priceData = [];
}
}
public function getDueDate(): void
{
if (blank($this->payDelay) || blank($this->dueDateInput)) {
return;
}
try {
$service = app(LogisticsService::class);
$response = $service->documentGetDueDate($this->payDelay, $this->dueDateInput);
$this->dueDateData = $response['data'] ?? [];
$this->errorMessage = $response['error'] ?? null;
} catch (LogisticsApiException $e) {
$this->errorMessage = $e->getMessage();
$this->dueDateData = [];
} catch (\Throwable $e) {
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
$this->dueDateData = [];
}
}
public function getAttachListThumbnail(): void
{
if (blank($this->attachJnl) || blank($this->attachNumber)) {
return;
}
try {
$service = app(LogisticsService::class);
$response = $service->documentGetAttachListThumbnail($this->attachJnl, $this->attachNumber);
$this->attachData = $response['data'] ?? [];
$this->errorMessage = $response['error'] ?? null;
} catch (LogisticsApiException $e) {
$this->errorMessage = $e->getMessage();
$this->attachData = [];
} catch (\Throwable $e) {
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
$this->attachData = [];
}
}
public function getPdf(): void
{
if (blank($this->pdfJnl) || blank($this->pdfNumber) || blank($this->pdfLayout)) {
return;
}
try {
$service = app(LogisticsService::class);
$response = $service->documentGetPdf($this->pdfJnl, $this->pdfNumber, $this->pdfLayout);
$this->pdfData = $response['data'] ?? [];
$this->errorMessage = $response['error'] ?? null;
} catch (LogisticsApiException $e) {
$this->errorMessage = $e->getMessage();
$this->pdfData = [];
} catch (\Throwable $e) {
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
$this->pdfData = [];
}
}
public function addDocument(): void
{
if (blank($this->addThirdId) || blank($this->addDate) || blank($this->addArtIds) || blank($this->addQty) || blank($this->addSalePrice) || blank($this->addJnl)) {
return;
}
try {
$service = app(LogisticsService::class);
$params = [
'ThirdId' => $this->addThirdId,
'Date' => $this->addDate,
'Artid' => $this->splitCsv($this->addArtIds),
'Qty' => $this->splitCsv($this->addQty),
'Saleprice' => $this->splitCsv($this->addSalePrice),
'JNL' => $this->addJnl,
];
if (filled($this->addDiscount)) {
$params['Discount'] = $this->splitCsv($this->addDiscount);
}
if (filled($this->addVatId)) {
$params['Vatid'] = $this->splitCsv($this->addVatId);
}
if (filled($this->addVatPc)) {
$params['Vatpc'] = $this->splitCsv($this->addVatPc);
}
$response = $service->documentAdd($params);
$this->addResult = $response['data'] ?? [];
$this->errorMessage = $response['error'] ?? null;
} catch (LogisticsApiException $e) {
$this->errorMessage = $e->getMessage();
$this->addResult = [];
} catch (\Throwable $e) {
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
$this->addResult = [];
}
}
public function modDocument(): void
{
if (blank($this->modNumber) || blank($this->modJnl)) {
return;
}
try {
$service = app(LogisticsService::class);
$params = [
'number' => $this->modNumber,
'JNL' => $this->modJnl,
];
if (filled($this->modThirdId)) {
$params['Thirdid'] = $this->modThirdId;
}
if (filled($this->modArtIds)) {
$params['Artid'] = $this->splitCsv($this->modArtIds);
}
if (filled($this->modQty)) {
$params['Qty'] = $this->splitCsv($this->modQty);
}
if (filled($this->modSalePrice)) {
$params['Saleprice'] = $this->splitCsv($this->modSalePrice);
}
$response = $service->documentMod($params);
$this->modResult = $response['data'] ?? [];
$this->errorMessage = $response['error'] ?? null;
} catch (LogisticsApiException $e) {
$this->errorMessage = $e->getMessage();
$this->modResult = [];
} catch (\Throwable $e) {
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
$this->modResult = [];
}
}
/**
* @return array<int, string>
*/
private function splitCsv(string $value): array
{
return array_map('trim', explode(',', $value));
}
}

View File

@@ -19,6 +19,8 @@ class Journaux extends Page
protected string $view = 'filament.pages.journaux';
public string $mode = 'read';
public string $select = '';
public int $results = 10;

View File

@@ -19,6 +19,8 @@ class Tiers extends Page
protected string $view = 'filament.pages.tiers';
public string $mode = 'read';
public string $select = 'custid,custname';
public string $search = '';