Explorar o código

add the network sync step

Olivier Massot %!s(int64=3) %!d(string=hai) anos
pai
achega
53a9c51981

+ 1 - 0
src/Enum/Organization/OrganizationIdsEnum.php

@@ -12,5 +12,6 @@ class OrganizationIdsEnum extends Enum
 {
     private const CMF     = 12097;
     private const _2IOS   = 32366;
+    private const FFEC    = 91295;
     private const OPENTALENT_BASE   = 13;
 }

+ 29 - 1
src/Service/Dolibarr/DolibarrSync/DolibarrSyncService.php

@@ -4,6 +4,8 @@ namespace App\Service\Dolibarr\DolibarrSync;
 
 use App\Entity\Core\AddressPostal;
 use App\Entity\Organization\OrganizationAddressPostal;
+use App\Enum\Network\NetworkEnum;
+use App\Enum\Organization\OrganizationIdsEnum;
 use App\Repository\Organization\OrganizationRepository;
 use App\Service\Dolibarr\DolibarrApiService;
 use Exception;
@@ -104,12 +106,38 @@ class DolibarrSyncService
 
                 if ($params) {
                     $operations[] = new DolibarrSyncOperation(
-                        'Organization ' . $organization->getId() . ': update address',
+                        'Organization ' . $organization->getId() . ': update address ' .
+                        '(current: ' . $params['address'] . ' ' . $params['zip'] . ' ' . $params['town'] . ')',
                         'PUT',
                         'thirdparties/' . $dolibarrClient['id'],
                         $params
                     );
                 }
+
+                // Network
+                $network = $organization->getNetworkOrganizations()->first()->getNetwork();
+                $parentOrganizationId = null;
+
+                if ($network->getId() === NetworkEnum::CMF()) {
+                    $parentOrganizationId = OrganizationIdsEnum::CMF();
+                } else if ($network->getId() === NetworkEnum::FFEC()) {
+                    $parentOrganizationId = OrganizationIdsEnum::FFEC();
+                }
+
+                if ($parentOrganizationId !== null) {
+                    $parent = $this->dolibarrApiService->getSociety($parentOrganizationId);
+
+                    $operations[] = new DolibarrSyncOperation(
+                        'Organization ' . $organization->getId() . ': update network ' .
+                        '(current: ' . $parent['parent'] . ')',
+                        'PUT',
+                        'thirdparties/' . $dolibarrClient['id'],
+                        ['parent' => $parent['id']]
+                    );
+                }
+
+                
+
             }
         }