Просмотр исходного кода

Merge branch 'feature/boutique' into develop

Vincent 9 месяцев назад
Родитель
Сommit
d989c1cbbe

+ 62 - 0
src/ApiResources/Profile/OrganizationProfile.php

@@ -9,6 +9,7 @@ use ApiPlatform\Metadata\ApiResource;
 use ApiPlatform\Metadata\Get;
 use App\ApiResources\ApiResourcesInterface;
 use App\Enum\Organization\LegalEnum;
+use App\Enum\Organization\PrincipalTypeEnum;
 use App\Enum\Organization\SettingsProductEnum;
 use Symfony\Component\Serializer\Annotation\Groups;
 use Symfony\Component\Validator\Constraints as Assert;
@@ -65,6 +66,19 @@ class OrganizationProfile implements ApiResourcesInterface
     #[Groups('access_profile_read')]
     private ?int $parametersId = null;
 
+    #[Groups('access_profile_read')]
+    #[Assert\Type(type: PrincipalTypeEnum::class)]
+    private ?PrincipalTypeEnum $principalType = null;
+
+    #[Groups('access_profile_read')]
+    private ?bool $trialActive = false;
+
+    #[Groups('access_profile_read')]
+    private ?int $trialCountDown = null;
+
+    #[Groups('access_profile_read')]
+    private ?SettingsProductEnum $productBeforeTrial = null;
+
     public function getId(): ?int
     {
         return $this->id;
@@ -224,4 +238,52 @@ class OrganizationProfile implements ApiResourcesInterface
 
         return $this;
     }
+
+    public function getPrincipalType(): ?PrincipalTypeEnum
+    {
+        return $this->principalType;
+    }
+
+    public function setPrincipalType(?PrincipalTypeEnum $principalType): self
+    {
+        $this->principalType = $principalType;
+
+        return $this;
+    }
+
+    public function isTrialActive(): bool
+    {
+        return $this->trialActive;
+    }
+
+    public function setTrialActive(?bool $trialActive): self
+    {
+        $this->trialActive = $trialActive ?? false;
+
+        return $this;
+    }
+
+    public function getTrialCountDown(): ?int
+    {
+        return $this->trialCountDown;
+    }
+
+    public function setTrialCountDown(?int $trialCountDown): self
+    {
+        $this->trialCountDown = $trialCountDown;
+
+        return $this;
+    }
+
+    public function getProductBeforeTrial(): ?SettingsProductEnum
+    {
+        return $this->productBeforeTrial;
+    }
+
+    public function setProductBeforeTrial(?SettingsProductEnum $productBeforeTrial): self
+    {
+        $this->productBeforeTrial = $productBeforeTrial;
+
+        return $this;
+    }
 }

+ 45 - 0
src/Entity/Organization/Settings.php

@@ -44,6 +44,15 @@ class Settings
     #[ORM\Column(length: 255, options: ['default' => 'FRANCE'])]
     private string $country;
 
+    #[ORM\Column(nullable: true)]
+    private ?bool $trialActive = false;
+
+    #[ORM\Column(type: 'date', nullable: true)]
+    private ?\DateTimeInterface $lastTrialStartDate = null;
+
+    #[ORM\Column(length: 50, nullable: true, enumType: SettingsProductEnum::class)]
+    private ?SettingsProductEnum $productBeforeTrial;
+
     public function getId(): ?int
     {
         return $this->id;
@@ -125,6 +134,42 @@ class Settings
         return $this;
     }
 
+    public function isTrialActive(): ?bool
+    {
+        return $this->trialActive;
+    }
+
+    public function setTrialActive(?bool $trialActive): self
+    {
+        $this->trialActive = $trialActive;
+
+        return $this;
+    }
+
+    public function getlLastTrialStartDate(): ?\DateTimeInterface
+    {
+        return $this->lastTrialStartDate;
+    }
+
+    public function setLastTrialStartDate(?\DateTimeInterface $lastTrialStartDate): self
+    {
+        $this->lastTrialStartDate = $lastTrialStartDate;
+
+        return $this;
+    }
+
+    public function getProductBeforeTrial(): ?SettingsProductEnum
+    {
+        return $this->productBeforeTrial;
+    }
+
+    public function setProductBeforeTrial(?SettingsProductEnum $productBeforeTrial): self
+    {
+        $this->productBeforeTrial = $productBeforeTrial;
+
+        return $this;
+    }
+
     public function getCreateDate(): ?\DateTimeInterface
     {
         return $this->createDate;

+ 1 - 0
src/Service/ApiResourceBuilder/Dolibarr/DolibarrAccountBuilder.php

@@ -15,6 +15,7 @@ class DolibarrAccountBuilder
     public const PRODUCT_MAPPING = [
         'Opentalent Artist' => 'PRODUCT_ARTIST',   // OT Artist
         'Opentalent Artist Premium' => 'PRODUCT_ARTIST_PREMIUM',   // OT Artist Premium
+        'Opentalent Artist Premium (Essai)' => 'PRODUCT_ARTIST_PREMIUM_TRIAL',   // OT Artist Premium (trial)
         'Opentalent School' => 'PRODUCT_SCHOOL',   // OT School Standard
         'Opentalent School Premium' => 'PRODUCT_SCHOOL_PREMIUM',   // OT School Premium
         'Opentalent Manager' => 'PRODUCT_MANAGER',   // OT Manager

+ 5 - 0
src/Service/Organization/OrganizationProfileCreator.php

@@ -22,6 +22,7 @@ class OrganizationProfileCreator
         private Module $module,
         private Tree $tree,
         private OrganizationUtils $organizationUtils,
+        private Trial $trialService
     ) {
     }
 
@@ -37,6 +38,10 @@ class OrganizationProfileCreator
         $organizationProfile->setProduct($organization->getSettings()->getProduct());
         $organizationProfile->setParametersId($organization->getParameters()->getId());
         $organizationProfile->setLegalStatus($organization->getLegalStatus());
+        $organizationProfile->setPrincipalType($organization->getPrincipalType());
+        $organizationProfile->setTrialActive($organization->getSettings()->isTrialActive());
+        $organizationProfile->setTrialCountDown($this->trialService->getTrialCountdown($organization->getSettings()->getlLastTrialStartDate()));
+        $organizationProfile->setProductBeforeTrial($organization->getSettings()->getProductBeforeTrial());
         $organizationProfile->setHasChildren($organization->getNetworkOrganizationChildren()->count() > 1);
         $organizationProfile->setShowAdherentList(
             $organization->getParameters()->getShowAdherentList()

+ 37 - 0
src/Service/Organization/Trial.php

@@ -0,0 +1,37 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Service\Organization;
+
+use App\Service\Utils\DatesUtils;
+
+/**
+ * Class OrganizationProfileCreator : Service contenant les manipulations associés à la ressource OrganizationProfile.
+ */
+class Trial
+{
+    public function __construct(
+        private DatesUtils $datesUtils
+    )
+    {
+    }
+
+    /**
+     * Retourne le décompte sur 30 jours du dernier lancement d'essai
+     * @param $trialStartDate
+     * @return int
+     */
+    public function getTrialCountdown(?\DateTimeInterface $trialStartDate){
+        if(empty($trialStartDate)){
+            return 0;
+        }
+
+        $daysSince = $this->datesUtils::daysSince($trialStartDate);
+        if($daysSince > 30){
+            return 0;
+        }
+
+        return 30 - $daysSince;
+    }
+}