Implement CRUD functionality for Articles and Tiers with enhanced API documentation

- Introduced new endpoints for creating and modifying articles (`art_add`, `art_mod`) and tiers (`third_add`, `third_mod`), allowing users to manage these entities effectively.
- Updated the Articles and Tiers pages to include forms for adding and modifying records, complete with parameter tables for clear guidance on required inputs.
- Enhanced the API documentation to include detailed descriptions, examples, and metadata for the new endpoints, improving usability and understanding for developers.
- Created a new rule for writing conventions with French accents to ensure consistency across the project.
- Updated existing documentation to reflect structural changes and added a summary table for CRUD operations.
- Added tests to verify the functionality of the new features and ensure robust error handling.
This commit is contained in:
2026-02-23 15:55:09 +01:00
parent b95ee46b1c
commit 714bdc3dd7
15 changed files with 1479 additions and 145 deletions

View File

@@ -30,10 +30,28 @@ class Articles extends Page
public string $stockArticleId = '';
// art_add
public string $addArtId = '';
public string $addName = '';
public string $addSalePrice = '';
// art_mod
public string $modArtId = '';
public string $modName = '';
public string $modSalePrice = '';
public array $data = [];
public array $stockData = [];
public array $addResult = [];
public array $modResult = [];
public ?array $metadata = null;
public ?string $errorMessage = null;
@@ -42,6 +60,10 @@ class Articles extends Page
public bool $hasCheckedStock = false;
public bool $hasAdded = false;
public bool $hasModified = false;
/**
* @return array<int, array{name: string, type: string, required: string, description: string}>
*/
@@ -93,6 +115,104 @@ class Articles extends Page
}
}
/**
* @return array<int, array{name: string, type: string, required: string, description: string}>
*/
public function paramTableArtAdd(): array
{
return [
['name' => 'ARTID', 'type' => 'string', 'required' => 'Oui', 'description' => "Identifiant unique de l'article à créer. Doit être unique dans la table art."],
['name' => 'NAME1', 'type' => 'string', 'required' => 'Non', 'description' => "Nom / libellé de l'article."],
['name' => 'SALEPRICE', 'type' => 'string', 'required' => 'Non', 'description' => 'Prix de vente unitaire (format string, ex : "99.99").'],
];
}
/**
* @return array<int, array{name: string, type: string, required: string, description: string}>
*/
public function paramTableArtMod(): array
{
return [
['name' => 'ARTID', 'type' => 'string', 'required' => 'Oui', 'description' => "Identifiant de l'article à modifier. Doit exister dans la table art."],
['name' => 'NAME1', 'type' => 'string', 'required' => 'Non', 'description' => "Nouveau nom / libellé de l'article."],
['name' => 'SALEPRICE', 'type' => 'string', 'required' => 'Non', 'description' => 'Nouveau prix de vente unitaire (format string).'],
];
}
public function addArticle(): void
{
$this->errorMessage = null;
if (blank($this->addArtId)) {
$this->errorMessage = 'Le champ identifiant article (ARTID) est obligatoire.';
return;
}
$this->hasAdded = true;
try {
$service = app(LogisticsService::class);
$params = ['ARTID' => $this->addArtId];
if (filled($this->addName)) {
$params['NAME1'] = $this->addName;
}
if (filled($this->addSalePrice)) {
$params['SALEPRICE'] = $this->addSalePrice;
}
$response = $service->artAdd($params);
$this->addResult = $response['data'] ?? [];
$this->errorMessage = ApiErrorTranslator::translate($response['error'] ?? null);
} catch (LogisticsApiException $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->addResult = [];
} catch (\Throwable $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->addResult = [];
}
}
public function modArticle(): void
{
$this->errorMessage = null;
if (blank($this->modArtId)) {
$this->errorMessage = 'Le champ identifiant article (ARTID) est obligatoire.';
return;
}
$this->hasModified = true;
try {
$service = app(LogisticsService::class);
$params = ['ARTID' => $this->modArtId];
if (filled($this->modName)) {
$params['NAME1'] = $this->modName;
}
if (filled($this->modSalePrice)) {
$params['SALEPRICE'] = $this->modSalePrice;
}
$response = $service->artMod($params);
$this->modResult = $response['data'] ?? [];
$this->errorMessage = ApiErrorTranslator::translate($response['error'] ?? null);
} catch (LogisticsApiException $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->modResult = [];
} catch (\Throwable $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->modResult = [];
}
}
public function getStock(): void
{
$this->errorMessage = null;

View File

@@ -30,10 +30,30 @@ class Tiers extends Page
public string $historyThirdId = '';
// third_add
public string $addName = '';
public string $addVat = '';
public string $addEmail = '';
// third_mod
public string $modCustId = '';
public string $modName = '';
public string $modVat = '';
public string $modEmail = '';
public array $data = [];
public array $historyData = [];
public array $addResult = [];
public array $modResult = [];
public ?array $metadata = null;
public ?string $errorMessage = null;
@@ -42,6 +62,10 @@ class Tiers extends Page
public bool $hasHistory = false;
public bool $hasAdded = false;
public bool $hasModified = false;
/**
* @return array<int, array{name: string, type: string, required: string, description: string}>
*/
@@ -64,6 +88,104 @@ class Tiers extends Page
];
}
/**
* @return array<int, array{name: string, type: string, required: string, description: string}>
*/
public function paramTableThirdAdd(): array
{
return [
['name' => 'NAME', 'type' => 'string', 'required' => 'Non', 'description' => 'Nom du tiers (raison sociale ou nom complet).'],
['name' => 'VAT', 'type' => 'string', 'required' => 'Non', 'description' => 'Numéro de TVA (ex : BE0123456789).'],
['name' => 'EMAIL', 'type' => 'string', 'required' => 'Non', 'description' => 'Adresse e-mail du tiers.'],
];
}
/**
* @return array<int, array{name: string, type: string, required: string, description: string}>
*/
public function paramTableThirdMod(): array
{
return [
['name' => 'CUSTID', 'type' => 'string', 'required' => 'Oui', 'description' => 'Identifiant du tiers à modifier (champ custid de la table cust). Doit exister.'],
['name' => 'NAME', 'type' => 'string', 'required' => 'Non', 'description' => 'Nouveau nom du tiers.'],
['name' => 'VAT', 'type' => 'string', 'required' => 'Non', 'description' => 'Nouveau numéro de TVA.'],
['name' => 'EMAIL', 'type' => 'string', 'required' => 'Non', 'description' => 'Nouvelle adresse e-mail.'],
];
}
public function addTiers(): void
{
$this->errorMessage = null;
$this->hasAdded = true;
try {
$service = app(LogisticsService::class);
$params = [];
if (filled($this->addName)) {
$params['NAME'] = $this->addName;
}
if (filled($this->addVat)) {
$params['VAT'] = $this->addVat;
}
if (filled($this->addEmail)) {
$params['EMAIL'] = $this->addEmail;
}
$response = $service->thirdAdd($params);
$this->addResult = $response['data'] ?? [];
$this->errorMessage = ApiErrorTranslator::translate($response['error'] ?? null);
} catch (LogisticsApiException $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->addResult = [];
} catch (\Throwable $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->addResult = [];
}
}
public function modTiers(): void
{
$this->errorMessage = null;
if (blank($this->modCustId)) {
$this->errorMessage = 'Le champ identifiant tiers (CUSTID) est obligatoire.';
return;
}
$this->hasModified = true;
try {
$service = app(LogisticsService::class);
$params = ['CUSTID' => $this->modCustId];
if (filled($this->modName)) {
$params['NAME'] = $this->modName;
}
if (filled($this->modVat)) {
$params['VAT'] = $this->modVat;
}
if (filled($this->modEmail)) {
$params['EMAIL'] = $this->modEmail;
}
$response = $service->thirdMod($params);
$this->modResult = $response['data'] ?? [];
$this->errorMessage = ApiErrorTranslator::translate($response['error'] ?? null);
} catch (LogisticsApiException $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->modResult = [];
} catch (\Throwable $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->modResult = [];
}
}
public function searchTiers(): void
{
$this->errorMessage = null;