|
|
@@ -1,84 +0,0 @@
|
|
|
-<?php
|
|
|
-declare(strict_types=1);
|
|
|
-
|
|
|
-namespace App\Service\Dolibarr;
|
|
|
-
|
|
|
-use App\Service\ApiRequestService;
|
|
|
-use JetBrains\PhpStorm\Pure;
|
|
|
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
-use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
-
|
|
|
-/**
|
|
|
- * Service d'appel à l'API dolibarr
|
|
|
- *
|
|
|
- * @see https://prod-erp.2iopenservice.com/api/index.php/explorer/
|
|
|
- */
|
|
|
-class DolibarrService extends ApiRequestService
|
|
|
-{
|
|
|
- #[Pure]
|
|
|
- function __construct(HttpClientInterface $dolibarr_client)
|
|
|
- {
|
|
|
- parent::__construct($dolibarr_client);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get a dolibarr society by its opentalent organization id
|
|
|
- *
|
|
|
- * @param int $organizationId
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getSociety(int $organizationId): array {
|
|
|
- // impossible to retrieve a society by its extrafield 2iopen_organization_id (thanks dolibarr), so
|
|
|
- // we need to store the organization id in two fields: 2iopen_organization_id and ref_int :(
|
|
|
- return $this->getJsonContent("thirdparties" , ["limit" => "1", "sqlfilters" => "ref_int=" . $organizationId])[0];
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get the first active contract for the given dolibarr society
|
|
|
- *
|
|
|
- * @param int $socId
|
|
|
- * @return array|null
|
|
|
- */
|
|
|
- public function getActiveContract(int $socId): ?array {
|
|
|
- try {
|
|
|
- return $this->getJsonContent(
|
|
|
- "contracts",
|
|
|
- ["limit" => "1", "sqlfilters" => "statut=1", "thirdparty_ids=" . $socId => null]
|
|
|
- )[0];
|
|
|
- } catch (NotFoundHttpException) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get a society bills by their society id
|
|
|
- *
|
|
|
- * @param int $socId
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getBills(int $socId): array {
|
|
|
- try {
|
|
|
- return $this->getJsonContent(
|
|
|
- "invoices",
|
|
|
- ["sortfield" => "datef", "sortorder" => "DESC", "limit" => 5, "sqlfilters" => "fk_soc=" . $socId]);
|
|
|
- } catch (NotFoundHttpException) {
|
|
|
- return [];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * @param $organization
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function createSociety($organization): void
|
|
|
- {
|
|
|
- $body = sprintf(
|
|
|
- '{"name":"%s","client":"2","code_client":"-1","ref_int":"%s","import_key":"crm"}',
|
|
|
- $organization->getName(),
|
|
|
- $organization->getId()
|
|
|
- );
|
|
|
-
|
|
|
- $this->request('POST', "api/index.php/thirdparties", [], ['body' => $body]);
|
|
|
- }
|
|
|
-}
|