src/Entity/Mission.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\ProductType;
  4. use App\Enum\Role;
  5. use App\Repository\MissionRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Symfony\Component\Uid\Uuid;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. #[ORM\Entity(repositoryClassMissionRepository::class)]
  13. #[ORM\Table(name'missions')]
  14. class Mission
  15. {
  16.     #[ORM\Id]
  17.     #[ORM\Column(type'string'length22uniquetrue)]
  18.     #[Groups(['campaign''mission_list''mission_read'])]
  19.     private string $id;
  20.     #[ORM\Column(type'integer'nullabletrue)]
  21.     #[Groups(['mission_list''mission_read'])]
  22.     private ?int $reference null;
  23.     #[ORM\Column(type'integer'nullabletrue)]
  24.     private ?int $positionOrder null;
  25.     #[ORM\Column(type'string'length255nullabletrue)]
  26.     #[Groups(['mission_list'])]
  27.     private ?string $stateClient;
  28.     #[ORM\Column(type'string'length255nullabletrue)]
  29.     #[Groups(['mission_list'])]
  30.     private ?string $stateProvider;
  31.     #[ORM\Column(type'datetime'nullabletrue)]
  32.     #[Groups(['mission_read'])]
  33.     private ?\DateTimeInterface $createdAt null;
  34.     #[ORM\Column(type'date'nullabletrue)]
  35.     #[Groups(['mission_read'])]
  36.     private ?\DateTimeInterface $desiredDelivery null;
  37.     #[ORM\ManyToOne(targetEntityCampaign::class, inversedBy'missions')]
  38.     #[Groups(['mission_list''mission_read'])]
  39.     private Campaign $campaign;
  40.     #[ORM\OneToMany(mappedBy'mission'targetEntityInfoMission::class, cascade: ["persist""remove"], orphanRemovaltrue)]
  41.     private ?Collection $infoMissions;
  42.     #[ORM\OneToMany(mappedBy'mission'targetEntityFileMission::class, cascade: ["persist""remove"], orphanRemovaltrue)]
  43.     private ?Collection $fileMissions;
  44.     #[ORM\ManyToOne(targetEntityUser::class, inversedBy'missions')]
  45.     private ?User $contact;
  46.     #[ORM\OneToMany(mappedBy'mission'targetEntityHistorique::class, cascade: ["persist""remove"], orphanRemovaltrue)]
  47.     #[ORM\OrderBy(['createdAt' => 'DESC'])]
  48.     private ?Collection $historiques;
  49.     #[ORM\Column(type'text'nullabletrue)]
  50.     private ?string $initialBriefing '';
  51.     #[ORM\ManyToOne(targetEntityProduct::class)]
  52.     #[ORM\JoinColumn(nullablefalse)]
  53.     #[Groups(['mission_list''mission_read'])]
  54.     private Product $product;
  55.     #[ORM\OneToMany(mappedBy'mission'targetEntityMissionParticipant::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  56.     #[Groups(['campaign','mission_list''mission_read'])]
  57.     private ?Collection $participants;
  58.     #[ORM\OneToOne(inversedBy'mission'targetEntityWorkflow::class, cascade: ['persist''remove'])]
  59.     #[Groups(['mission_read'])]
  60.     private ?Workflow $workflow null;
  61.     #[ORM\Column(type'string'length255nullabletrue)]
  62.     #[Groups(['mission_read'])]
  63.     private ?string $guideStep;
  64.     #[ORM\Column(type'integer')]
  65.     private int $quantity;
  66.     #[ORM\Column(type'decimal'precision10scale2nullabletrue)]
  67.     #[Groups(['mission_list''mission_read'])]
  68.     private ?float $price null;
  69.     #[ORM\Column(type'decimal'precision10scale2nullabletrue)]
  70.     #[Groups(['mission_list''mission_read'])]
  71.     private ?float $priceWithMargeMyFlow null;
  72.     #[ORM\Column(type'decimal'precision10scale2nullabletrue)]
  73.     #[Groups(['mission_list''mission_read'])]
  74.     private ?float $margeMyFlow null;
  75.     #[ORM\Column(type'decimal'precision10scale2nullabletrue)]
  76.     private ?float $priceSale null;
  77.     #[ORM\Column(type'string')]
  78.     #[Groups(['mission_list''mission_read'])]
  79.     private string $state 'provisional';
  80.     #[ORM\Column(type'text'nullabletrue)]
  81.     private ?string $cancelReason null;
  82.     #[ORM\Column(type'text'nullabletrue)]
  83.     private ?string $libelleCustom null;
  84.     #[ORM\Column(type'string'nullabletrue)]
  85.     #[Groups(['mission_list''mission_read'])]
  86.     private ?string $initialTime null;
  87.     #[ORM\Column(type'string'nullabletrue)]
  88.     private ?string $realTime null;
  89.     #[ORM\Column(type'date'length255nullabletrue)]
  90.     private ?\DateTimeInterface $preActivatedAt null;
  91.     #[ORM\Column(type'string'nullabletrue)]
  92.     private ?string $adminTime null;
  93.     #[ORM\Column(type'string'nullabletrue)]
  94.     private ?string $adminIncome null;
  95.     #[ORM\Column(type'integer'nullabletrue)]
  96.     private $discountForCompany;
  97.     #[ORM\Column(type'integer'nullabletrue)]
  98.     private $originalPrice;
  99.     #[ORM\Column(type'string'length255nullabletrue)]
  100.     private $oldCommand;
  101.     #[ORM\OneToMany(mappedBy'mission'targetEntityMessage::class)]
  102.     private $messages;
  103.     #[ORM\Column(type'string'length255nullabletrue)]
  104.     private $lastState;
  105.     #[ORM\Column(type'boolean'nullabletrue)]
  106.     private $canInvoiced;
  107.   
  108.     #[ORM\OneToMany(mappedBy'mission'targetEntityBalanceTransactions::class)]
  109.     private $balanceTransactions;
  110.     #[ORM\Column(type'boolean'nullabletrue)]
  111.     private $evaluate;
  112.     #[ORM\Column(type'boolean'nullabletrue)]
  113.     private $canSendEmailDaily;
  114.     #[ORM\Column(type'boolean'nullabletrue)]
  115.     private $canSendEmailMonthly;
  116.     #[ORM\Column(type'boolean'nullabletrue)]
  117.     private $canSendEmailWeekly;
  118.     /**
  119.      * only use for api message
  120.      */
  121.     #[Groups(['mission_list','mission_read'])]
  122.     private int $messageUnreadApi 0;
  123.     #[Groups(['mission_list','mission_read'])]
  124.     private bool $confidential false;
  125.     #[Groups(['mission_list','mission_read'])]
  126.     private bool $alreadyAcceptConfidentialityContract false;
  127.     #[Groups(['mission_list','mission_read'])]
  128.     private array $responsable = [];
  129.     #[Groups(['mission_list','mission_read'])]
  130.     private $remainDays;
  131.     #[Groups(['mission_list','mission_read'])]
  132.     private $campaignAmount;
  133.     #[Groups(['mission_list','mission_read'])]
  134.     private ?bool  $canActivate false;
  135.     #[Groups(['mission_list','mission_read'])]
  136.     private ?bool $canValidate false;
  137.     #[Groups(['mission_list','mission_read'])]
  138.     private  $planningAdditionalInformation;
  139.     #[Groups(['mission_list','mission_read'])]
  140.     private $campaignStateApi ;
  141.     #[Groups(['mission_list','mission_read'])]
  142.     private $priceApi;
  143.     #[Groups(['mission_list','mission_read'])]
  144.     private $timeApi;
  145.     #[Groups(['mission_list','mission_read'])]
  146.     private  $campaignStateHtml;
  147.     #[Groups(['mission_list','mission_read'])]
  148.     private  $tempId;
  149.     /************************ */
  150.     public function __construct()
  151.     {
  152.         $this->id Uuid::v4()->toBase58();
  153.         $this->createdAt = new \DateTime();
  154.         $this->infoMissions = new ArrayCollection();
  155.         $this->fileMissions = new ArrayCollection();
  156.         $this->historiques = new ArrayCollection();
  157.         $this->participants = new ArrayCollection();
  158.         $this->desiredDelivery = new \DateTime();
  159.         $this->messages = new ArrayCollection();
  160.         $this->canInvoiced false;
  161.         $this->balanceTransactions = new ArrayCollection();
  162.     }
  163.     public function getId(): ?string
  164.     {
  165.         return $this->id;
  166.     }
  167.     public function getTempId(): ?string
  168.     {
  169.         return $this->tempId;
  170.     }
  171.     public function setTempId(string $tempId)
  172.     {
  173.         $this->tempId $tempId ;
  174.     }
  175.   
  176.     public function __clone()
  177.     { 
  178.         $this->id Uuid::v4()->toBase58();
  179.         $participants = new ArrayCollection();
  180.         if($this->workflow !=null){
  181.             $this->workflow = clone  $this->workflow;
  182.         }
  183.         $fileMissions = new ArrayCollection();
  184.         $historiques =  new ArrayCollection();
  185.         
  186.         foreach ($this->historiques as $historique) {
  187.                 $cloneHistorique = clone $historique;
  188.                 $historiques->add($cloneHistorique);
  189.                 $cloneHistorique->setMission($this);
  190.         }
  191.         $this->historiques = new ArrayCollection($historiques->toArray());
  192.         
  193.         // foreach ($this->fileMissions as $fileMission) {
  194.         //     $cloneFileMission = clone $fileMission;
  195.         //     $cloneFileMission->setMission($this);
  196.         //     $fileMissions->add($cloneFileMission);
  197.         // }
  198.         
  199.         foreach ($this->participants as $participant) {
  200.             $clonedParticipant = clone $participant;
  201.             $clonedParticipant->setMission($this);
  202.             $participants->add($clonedParticipant);
  203.         }
  204.         $this->participants $participants ;
  205.         $this->fileMissions =  $fileMissions;
  206.         $this->balanceTransactions = new ArrayCollection();
  207.         $this->messages = new ArrayCollection();
  208.     }
  209.     public function getReference(): ?string
  210.     {
  211.         if (empty($this->reference)) {
  212.             return null;
  213.         }
  214.         return str_pad($this->reference50STR_PAD_LEFT);
  215.     }
  216.     public function setReference(?int $reference): self
  217.     {
  218.         $this->reference $reference;
  219.         return $this;
  220.     }
  221.     public function getStateClient(): ?string
  222.     {
  223.         return $this->stateClient;
  224.     }
  225.     public function setStateClient(?string $stateClient): self
  226.     {
  227.         $this->stateClient $stateClient;
  228.         return $this;
  229.     }
  230.     public function getStateProvider(): ?string
  231.     {
  232.         return $this->stateProvider;
  233.     }
  234.     public function setStateProvider(?string $stateProvider): self
  235.     {
  236.         $this->stateProvider $stateProvider;
  237.         return $this;
  238.     }
  239.     /**
  240.      * @return \DateTimeInterface|null
  241.      */
  242.     public function getCreatedAt(): ?\DateTimeInterface
  243.     {
  244.         return $this->createdAt;
  245.     }
  246.     /**
  247.      * @param \DateTimeInterface|null $createdAt
  248.      * @return Mission
  249.      */
  250.     public function setCreatedAt(?\DateTimeInterface $createdAt): Mission
  251.     {
  252.         $this->createdAt $createdAt;
  253.         return $this;
  254.     }
  255.     public function getDesiredDelivery(): ?\DateTimeInterface
  256.     {
  257.         return $this->desiredDelivery;
  258.     }
  259.     public function setDesiredDelivery(?\DateTimeInterface $desiredDelivery): self
  260.     {
  261.         $this->desiredDelivery $desiredDelivery;
  262.         return $this;
  263.     }
  264.     public function getCampaign(): ?Campaign
  265.     {
  266.         return $this->campaign;
  267.     }
  268.     public function setCampaign(?Campaign $campaign): self
  269.     {
  270.         $this->campaign $campaign;
  271.         return $this;
  272.     }
  273.     /**
  274.      * @return Collection|InfoMission[]
  275.      */
  276.     public function getInfoMissions(): Collection
  277.     {
  278.         return $this->infoMissions;
  279.     }
  280.     public function addInfoMission(InfoMission $infoMission): self
  281.     {
  282.         if (!$this->infoMissions->contains($infoMission)) {
  283.             $this->infoMissions[] = $infoMission;
  284.             $infoMission->setMission($this);
  285.         }
  286.         return $this;
  287.     }
  288.     public function removeInfoMission(InfoMission $infoMission): self
  289.     {
  290.         if ($this->infoMissions->removeElement($infoMission)) {
  291.             // set the owning side to null (unless already changed)
  292.             if ($infoMission->getMission() === $this) {
  293.                 $infoMission->setMission(null);
  294.             }
  295.         }
  296.         return $this;
  297.     }
  298.     /**
  299.      * @return Collection|FileMission[]
  300.      */
  301.     public function getFileMissions(): Collection
  302.     {
  303.         return $this->fileMissions;
  304.     }
  305.     public function addFileMission(FileMission $fileMission): self
  306.     {
  307.         if (!$this->fileMissions->contains($fileMission)) {
  308.             $this->fileMissions[] = $fileMission;
  309.             $fileMission->setMission($this);
  310.         }
  311.         return $this;
  312.     }
  313.     public function removeFileMission(FileMission $fileMission): self
  314.     {
  315.         if ($this->fileMissions->removeElement($fileMission)) {
  316.             // set the owning side to null (unless already changed)
  317.             if ($fileMission->getMission() === $this) {
  318.                 $fileMission->setMission(null);
  319.             }
  320.         }
  321.         return $this;
  322.     }
  323.     public function getContact(): ?User
  324.     {
  325.         return $this->contact;
  326.     }
  327.     public function setContact(?User $contact): self
  328.     {
  329.         $this->contact $contact;
  330.         return $this;
  331.     }
  332.     /**
  333.      * @return Collection|Historique[]
  334.      */
  335.     public function getHistoriques(): Collection
  336.     {
  337.         return $this->historiques;
  338.     }
  339.     public function addHistorique(Historique $historique): self
  340.     {
  341.         if (!$this->historiques->contains($historique)) {
  342.             $this->historiques[] = $historique;
  343.             $historique->setMission($this);
  344.         }
  345.         return $this;
  346.     }
  347.     public function removeHistorique(Historique $historique): self
  348.     {
  349.         if ($this->historiques->removeElement($historique)) {
  350.             // set the owning side to null (unless already changed)
  351.             if ($historique->getMission() === $this) {
  352.                 $historique->setMission(null);
  353.             }
  354.         }
  355.         return $this;
  356.     }
  357.     public function getInitialBriefing(): ?string
  358.     {
  359.         return $this->initialBriefing;
  360.     }
  361.     public function setInitialBriefing(?string $initialBriefingbool $isAddMission=true): self
  362.     {   
  363.         
  364.         if($isAddMission){
  365.             // $pattern="/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)/";
  366.             // $this->initialBriefing = preg_replace_callback($pattern, function ($matches) {
  367.             //     $url = $matches[0];
  368.             //     return "<a href='$url' target='_blank'> . {$url} . '</a>";
  369.             // }, $initialBriefing );
  370.         }
  371.         else{
  372.             // $initialBriefing = preg_replace('/<a\s+(?:[^>]*?\s+)?href="([^"]*)"/i', '<a href="$1" target="_blank"', $initialBriefing);
  373.             // $this->initialBriefing = $initialBriefing;
  374.         }
  375.         $this->initialBriefing $initialBriefing;
  376.         return $this;
  377.     }
  378.     public function getProduct(): ?Product
  379.     {
  380.         return $this->product;
  381.     }
  382.     public function setProduct(?Product $product): self
  383.     {
  384.         $this->product $product;
  385.         return $this;
  386.     }
  387.     /**
  388.      * @return Collection|MissionParticipant[]
  389.      */
  390.     public function getParticipants(): Collection
  391.     {
  392.         $participants $this->participants;
  393.         return $participants;
  394.     }
  395.     /**
  396.      * @return Collection|MissionParticipant[]
  397.      */
  398.     public function getParticipantsWithoutDoublon(): Collection
  399.     {
  400.        
  401.         $participants $this->participants;
  402.         $n count($participants);
  403.         for ($i 0$i $n 1$i++) {
  404.             for ($j 0$j $n $i 1$j++) {
  405.                 $participant1 $participants[$j];
  406.                 $participant2 $participants[$j 1];
  407.                 
  408.                 $income1 $participant1->getEstimatedIncome();
  409.                 $income2 $participant2->getEstimatedIncome();
  410.                 if ((is_null($income1) && !is_null($income2)) ||
  411.                     (!is_null($income1) && !is_null($income2) && $income1 $income2)) {
  412.                     $participants[$j] = $participant2;
  413.                     $participants[$j 1] = $participant1;
  414.                 }
  415.             }
  416.         }
  417.         return $participants;
  418.     }
  419.     public function addParticipant(MissionParticipant $participant): self
  420.     {
  421.         if (!$this->participants->contains($participant)) {
  422.             $this->participants[] = $participant;
  423.             $participant->setMission($this);
  424.         }
  425.         return $this;
  426.     }
  427.     public function removeParticipant(MissionParticipant $participant): self
  428.     {
  429.         if ($this->participants->removeElement($participant)) {
  430.             // set the owning side to null (unless already changed)
  431.             if ($participant->getMission() === $this) {
  432.                 $participant->setMission(null);
  433.             }
  434.         }
  435.         return $this;
  436.     }
  437.     public function getWorkflow(): ?Workflow
  438.     {
  439.         return $this->workflow;
  440.     }
  441.     public function setWorkflow(?Workflow $workflow): self
  442.     {
  443.         if ($workflow != null) {
  444.             foreach ($workflow->getSteps() as $step) {
  445.                 $step->setActive(false);
  446.             }
  447.         }
  448.         $this->workflow $workflow;
  449.         return $this;
  450.     }
  451.     public function getGuideStep(): ?string
  452.     {
  453.         return $this->guideStep;
  454.     }
  455.     public function setGuideStep(?string $guideStep): self
  456.     {
  457.         $this->guideStep $guideStep;
  458.         return $this;
  459.     }
  460.     public function getQuantity(): ?int
  461.     {
  462.         return $this->quantity;
  463.     }
  464.     public function setQuantity(int $quantity): self
  465.     {
  466.         $this->quantity $quantity;
  467.         return $this;
  468.     }
  469.     public function getPrice(): ?float
  470.     {
  471.         return $this->price;
  472.     }
  473.     public function setPrice(?float $price): self
  474.     {
  475.         $this->price $price;
  476.         return $this;
  477.     }
  478.     public function getState(): string
  479.     {
  480.         return $this->state;
  481.     }
  482.     public function setState(string $state): self
  483.     {   
  484.         $this->canSendEmailDaily true;
  485.         $this->canSendEmailWeekly true;
  486.         $this->canSendEmailMonthlytrue;
  487.         $this->lastState $this->state;
  488.         $this->state $state;
  489.         return $this;
  490.     }
  491.     /**
  492.      * @return string|null
  493.      */
  494.     public function getCancelReason(): ?string
  495.     {
  496.         return $this->cancelReason;
  497.     }
  498.     /**
  499.      * @param string|null $cancelReason
  500.      */
  501.     public function setCancelReason(?string $cancelReason): void
  502.     {
  503.         $this->cancelReason $cancelReason;
  504.     }
  505.     /**
  506.      * @return string|null
  507.      */
  508.     public function getLibelleCustom(): ?string
  509.     {
  510.         return $this->libelleCustom;
  511.     }
  512.     /**
  513.      * @param string|null $libelleCustom
  514.      */
  515.     public function setLibelleCustom(?string $libelleCustom): void
  516.     {
  517.         $this->libelleCustom $libelleCustom;
  518.     }
  519.     /**
  520.      * @return string|null
  521.      */
  522.     public function getInitialTime(): ?string
  523.     {
  524.         return $this->initialTime;
  525.     }
  526.     /**
  527.      * @param string|null $initialTime
  528.      */
  529.     public function setInitialTime(?string $initialTime): void
  530.     {
  531.         $this->initialTime $initialTime;
  532.     }
  533.     /**
  534.      * @return string|null
  535.      */
  536.     public function getRealTime(): ?string
  537.     {
  538.         return $this->realTime;
  539.     }
  540.     /**
  541.      * @param string|null $realTime
  542.      */
  543.     public function setRealTime(?string $realTime): void
  544.     {
  545.         $this->realTime $realTime;
  546.     }
  547.     /**
  548.      * @return \DateTimeInterface|null
  549.      */
  550.     public function getPreActivatedAt(): ?\DateTimeInterface
  551.     {
  552.         return $this->preActivatedAt;
  553.     }
  554.     /**
  555.      * @param \DateTimeInterface|null $preActivatedAt
  556.      */
  557.     public function setPreActivatedAt(?\DateTimeInterface $preActivatedAt): void
  558.     {
  559.         $this->preActivatedAt $preActivatedAt;
  560.     }
  561.     public function subcontractorNotActivatedMission(){
  562.         $result = [];
  563.         if ($this->getProduct()->getType() === ProductType::AU_FORFAIT or $this->getProduct()->getType() === ProductType::AU_TEMPS_PASSE) {
  564.             foreach ($this->getParticipants() as $participant) {
  565.                 if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR){
  566.                     if (!$participant->isActivated()) {
  567.                         $result [] = [$participant->getUser()];
  568.                     }
  569.                 }
  570.             }
  571.         }
  572.         return $result;
  573.     }
  574.     public function oneOfSubcontractorIsEvaluated(){
  575.         $evaluated false;
  576.         foreach ($this->getParticipants() as $participant) {
  577.             if (!is_null($participant->getEstimatedIncomeAdmin()) and $participant->getEstimatedIncomeAdmin() != 0) {
  578.                 $evaluated true;
  579.             }
  580.         }
  581.         return $evaluated;
  582.     }
  583.      public function allOfSubcontractorIsEvaluated(){
  584.         $nombreSubcontractorEvaluated =;
  585.         $nombreSubcontractor =;
  586.         foreach ($this->getParticipants() as $participant) {
  587.            if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR){
  588.                 $nombreSubcontractor++;
  589.                 if (!is_null($participant->getEstimatedIncomeAdmin()) and $participant->getEstimatedIncomeAdmin() != 0) {
  590.                     $nombreSubcontractorEvaluated++;
  591.                 }
  592.             }
  593.         }
  594.         return $nombreSubcontractorEvaluated == $nombreSubcontractor true false;
  595.     }
  596.     
  597.     public function determineMissionIsActivated(){
  598.         $activated true;
  599.         foreach ($this->getParticipants() as $participant) {
  600.             if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR)
  601.                 {
  602.                 if (!$participant->isActivated()) {
  603.                     $activated false;
  604.                 }
  605.             }
  606.         }
  607.         return $activated;
  608.     }
  609.     public function canActivate(): bool
  610.     {
  611.         
  612.         $count 0;
  613.         $activated 0;
  614.         foreach ($this->getParticipants() as $participant) {
  615.             if (
  616.                 $participant->getRole() === Role::ROLE_SUBCONTRACTOR and 
  617.                 !in_array('ROLE_BOT',$participant->getUser()->getRoles())
  618.         ) {
  619.                 $count++;
  620.                 if ($participant->isActivated()) {
  621.                     $activated++;
  622.                 }
  623.             }
  624.         }
  625.        
  626.         if ($count === || $count === $activated) {
  627.             return false;
  628.         }
  629.         if ($this->getProduct()->getType() === ProductType::A_EVALUER) {
  630.             foreach ($this->getParticipants() as $participant) {
  631.                 if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR && empty($participant->getInitialTime())) {
  632.                     return false;
  633.                 }
  634.             }
  635.         }else{
  636.             // foreach ($this->getCampaign()->getMissions() as $mission){
  637.             //     if ($mission->getProduct()->getStatut() === ProductType::A_EVALUER){
  638.             //         if ($mission->getStateProvider() == 'A évaluer'){
  639.             //             return false;
  640.             //         }
  641.             //     }
  642.             // }
  643.         }
  644.         if (null !== $this->getWorkflow()) {
  645.             foreach ($this->getWorkflow()->getSteps() as $step) {
  646.                 if ($step->isActive()) {
  647.                     return false;
  648.                 }
  649.             }
  650.         }
  651.         
  652.         return true;
  653.     }
  654.     /**
  655.      * @return string|null
  656.      */
  657.     public function getAdminTime(): ?string
  658.     {
  659.         return $this->adminTime;
  660.     }
  661.     /**
  662.      * @param string|null $adminTime
  663.      */
  664.     public function setAdminTime(?string $adminTime): void
  665.     {
  666.         $this->adminTime $adminTime;
  667.     }
  668.     /**
  669.      * @return string|null
  670.      */
  671.     public function getAdminIncome(): ?string
  672.     {
  673.         return $this->adminIncome;
  674.     }
  675.     /**
  676.      * @param string|null $adminIncome
  677.      */
  678.     public function setAdminIncome(?string $adminIncome): void
  679.     {
  680.         $this->adminIncome $adminIncome;
  681.     }
  682.     public function getDiscountForCompany(): ?int
  683.     {
  684.         return $this->discountForCompany;
  685.     }
  686.     public function setDiscountForCompany(?int $discountForCompany): self
  687.     {
  688.         $this->discountForCompany $discountForCompany;
  689.         return $this;
  690.     }
  691.     public function getOriginalPrice(): ?int
  692.     {
  693.         return $this->originalPrice;
  694.     }
  695.     public function setOriginalPrice(?int $originalPrice): self
  696.     {
  697.         $this->originalPrice $originalPrice;
  698.         return $this;
  699.     }
  700.     public function getTotalIncomeAdmin(){
  701.         $total 0;
  702.         foreach ($this->getParticipants() as  $participant) {
  703.             if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR) {
  704.                 if( is_null($participant->getEstimatedIncomeAdmin()) ){
  705.                     $total += $participant->getIncomeAdmin();
  706.                 }else{
  707.                     $total += $participant->getEstimatedIncomeAdmin();
  708.                 }
  709.             }
  710.         }
  711.         return $total;
  712.     }
  713.     public function getTotalInitialTimeAdmin(){
  714.         $total 0;
  715.         foreach ($this->getParticipants() as  $participant) {
  716.             if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR) {
  717.                 if( is_null($participant->getInitialTimeAdmin()) ){
  718.                     $total += $participant->getTimeAdmin();
  719.                 }else{
  720.                     $total+= $participant->getInitialTimeAdmin();
  721.                 }
  722.             }
  723.         }
  724.         return $total;
  725.     }
  726.     public function nbParticipant(){
  727.         $nb 0;
  728.         foreach ($this->getParticipants() as $participant) {
  729.             if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR) {
  730.                 $nb++;
  731.             }
  732.         }
  733.         return $nb;
  734.     }
  735.     public function onlySubcontractorInMission(){
  736.         if (($this->nbParticipant()) == 1) {
  737.             foreach ($this->getParticipants() as $participant) {
  738.                 if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR) {
  739.                     return $participant;
  740.                 }
  741.             }
  742.         }
  743.         return null;
  744.     }
  745.     public function getTvaForOnlyOneParticipant(){
  746.         foreach ($this->getParticipants() as $participant) {
  747.             if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR) {
  748.                 if (!is_null($participant->getUser()->getUserData())) {
  749.                     return $participant->getUser()->getUserData()->getTva();
  750.                 }
  751.             }
  752.         }
  753.         return 0;
  754.     }
  755.     /**
  756.      * get $quatity,$price, $idProduct, $timestamp  of shape "quatity-price-idProduct-timestamp"
  757.      * 
  758.      * timestamp is the timestamp or datedesired delivery
  759.      * 
  760.      * @return string|null
  761.      */
  762.     public function getOldCommand(): ?string
  763.     {
  764.         return $this->oldCommand;
  765.     }
  766.     /**
  767.      * @param string|null $oldCommand
  768.      * 
  769.      * @return self
  770.      */
  771.     public function setOldCommand(?string $oldCommand): self
  772.     {
  773.         $this->oldCommand $oldCommand;
  774.         return $this;
  775.     }
  776.     /**
  777.      * Get All participant by Type subcontractror and observer and validator 
  778.      * 
  779.      * @return array
  780.      */
  781.     public function getParticipantsByType():array
  782.     {
  783.         $participantListByType= [
  784.                 'subcontractor' => [],
  785.                 'observer' => [],
  786.                 'validateur'=> []
  787.             
  788.         ];
  789.         $idSubcontractorList = [];
  790.         foreach ($this->getParticipants() as $participant) {
  791.             if( !in_array("ROLE_BOT",$participant->getUser()->getRoles())){
  792.                 if($participant->getRole()== Role::ROLE_SUBCONTRACTOR){
  793.                     if (!in_array($participant->getUser()->getId(),$idSubcontractorList)) {
  794.                         $participantListByType['subcontractor']=[...$participantListByType['subcontractor'],$participant];
  795.                     }
  796.                     $idSubcontractorList[] = $participant->getUser()->getId();
  797.                   }
  798.                   if($participant->getRole()== Role::ROLE_OBSERVER){
  799.                       $participantListByType['observer']=[...$participantListByType['observer'],$participant];
  800.                   }
  801.                   if($participant->getRole()== Role::ROLE_VALIDATOR){
  802.                       $participantListByType['validateur']=[...$participantListByType['validateur'],$participant];
  803.                   }
  804.             }
  805.         }
  806.         return $participantListByType;
  807.     }
  808.     /**
  809.      * @return Collection|Message[]
  810.      */
  811.     public function getMessages(): Collection
  812.     {
  813.         return $this->messages;
  814.     }
  815.     public function addMessage(Message $message): self
  816.     {
  817.         if (!$this->messages->contains($message)) {
  818.             $this->messages[] = $message;
  819.             $message->setMission($this);
  820.         }
  821.         return $this;
  822.     }
  823.     public function removeMessage(Message $message): self
  824.     {
  825.         if ($this->messages->removeElement($message)) {
  826.             // set the owning side to null (unless already changed)
  827.             if ($message->getMission() === $this) {
  828.                 $message->setMission(null);
  829.             }
  830.         }
  831.         return $this;
  832.     }
  833.     public function getLastState(): ?string
  834.     {
  835.         return $this->lastState;
  836.     }
  837.     public function setLastState(?string $lastState): self
  838.     {
  839.         $this->lastState $lastState;
  840.         return $this;
  841.     }
  842.     public function lastStepIsActive(){
  843.         if (!is_null($this->workflow) && sizeof($this->workflow->getSteps()) > 0) {
  844.             return $this->workflow->getSteps()->last()->isActive();
  845.         }
  846.         return false;
  847.     }
  848.     /**
  849.      * return list of participant who doesnt have time and price in product type 3 (temp passé)
  850.      * @return Array
  851.      */
  852.     public function subcontractorIsReady(){
  853.         $participants $this->getParticipants();
  854.         $listParticipantOk = [];
  855.         $dataParticpantNotOK = [];
  856.         if ($this->getProduct()->getType() === ProductType::AU_TEMPS_PASSE) {
  857.             //All participant is ready
  858.             foreach ($participants as $participant) {
  859.                 if ( !is_null($participant->getEstimatedIncome()) and $participant->getEstimatedIncome() != and  $participant->getRole() === Role::ROLE_SUBCONTRACTOR
  860.                     ) {
  861.                     $listParticipantOk [] = $participant->getUser()->getId();
  862.                 }
  863.             }   
  864.             foreach ($participants as $participant) {
  865.                 
  866.                 if ((is_null($participant->getEstimatedIncome()) or is_null($participant->getInitialTime()) or $participant->getEstimatedIncome() == or ($participant->getInitialTime()) == 0) and  $participant->getRole() === Role::ROLE_SUBCONTRACTOR
  867.                     and !in_array($participant->getUser()->getId(),$listParticipantOk)
  868.                     ) {
  869.                                 $dataParticpantNotOK[] = [
  870.                                     'id' => $participant->getId(),
  871.                                     'firstname' => $participant->getUser()->getFirstname(),
  872.                                     'lastname' => $participant->getUser()->getLastname(),
  873.                                     'email' => $participant->getUser()->getEmail(),
  874.                                     'picture' => $participant->getUser()->getPictureName(),
  875.                                     'user' => $participant->getUser()
  876.                                 ];
  877.                 }
  878.             }
  879.         }
  880.         return ($dataParticpantNotOK);
  881.     }
  882.     public function getCanInvoiced(): ?bool
  883.     {
  884.         return $this->canInvoiced;
  885.     }
  886.     public function setCanInvoiced(?bool $canInvoiced): self
  887.     {
  888.         $this->canInvoiced $canInvoiced;
  889.         return $this;
  890.     }
  891.     /**
  892.      * @return Collection|BalanceTransactions[]
  893.      */
  894.     public function getBalanceTransactions(): Collection
  895.     {
  896.         return $this->balanceTransactions;
  897.     }
  898.     public function addBalanceTransaction(BalanceTransactions $balanceTransaction): self
  899.     {
  900.         if (!$this->balanceTransactions->contains($balanceTransaction)) {
  901.             $this->balanceTransactions[] = $balanceTransaction;
  902.             $balanceTransaction->setMission($this);
  903.         }
  904.         return $this;
  905.     }
  906.     public function removeBalanceTransaction(BalanceTransactions $balanceTransaction): self
  907.     {
  908.         if ($this->balanceTransactions->removeElement($balanceTransaction)) {
  909.             // set the owning side to null (unless already changed)
  910.             if ($balanceTransaction->getMission() === $this) {
  911.                 $balanceTransaction->setMission(null);
  912.             }
  913.         }
  914.         return $this;
  915.     }
  916.     public function isEvaluate(): ?bool
  917.     {
  918.         return $this->evaluate;
  919.     }
  920.     public function setEvaluate(?bool $evaluate): self
  921.     {
  922.         $this->evaluate $evaluate;
  923.         return $this;
  924.     }
  925.     public function getCanSendEmailDaily(): ?bool
  926.     {
  927.         return $this->canSendEmailDaily;
  928.     }
  929.     public function setCanSendEmailDaily(?bool $canSendEmailDaily): self
  930.     {
  931.         $this->canSendEmailDaily $canSendEmailDaily;
  932.         return $this;
  933.     }
  934.     public function getCanSendEmailMonthly(): ?bool
  935.     {
  936.         return $this->canSendEmailMonthly;
  937.     }
  938.     public function setCanSendEmailMonthly(?bool $canSendEmailMonthly): self
  939.     {
  940.         $this->canSendEmailMonthly $canSendEmailMonthly;
  941.         return $this;
  942.     }
  943.     public function getCanSendEmailWeekly(): ?bool
  944.     {
  945.         return $this->canSendEmailWeekly;
  946.     }
  947.     public function setCanSendEmailWeekly(?bool $canSendEmailWeekly): self
  948.     {
  949.         $this->canSendEmailWeekly $canSendEmailWeekly;
  950.         return $this;
  951.     }
  952.   
  953.  // for Api only
  954.     public function getCampaignStateHtml():string|null{
  955.                 
  956.         return $this->campaignStateHtml;
  957.     }
  958.     public function setCampaignStateHtml(?string $campaignStateHtml):self{
  959.         $this->campaignStateHtml $campaignStateHtml;
  960.         return $this;
  961.     }
  962.     public function getCampaignStateApi():array|null{
  963.                 
  964.         return $this->campaignStateApi;
  965.     }
  966.     public function setCampaignStateApi(?array $campaignStateApi):self{
  967.         $this->campaignStateApi $campaignStateApi;
  968.         return $this;
  969.     }
  970.     public function getMessageUnreadApi():int{
  971.             
  972.         return $this->messageUnreadApi;
  973.     }
  974.     public function setMessageUnreadApi(?int $messageUnreadApi):self{
  975.         $this->messageUnreadApi $messageUnreadApi;
  976.         return $this;
  977.     }
  978.     public function getCanActivate(){
  979.         return $this->canActivate;
  980.     }
  981.     public function setCanActivateApi(?bool $canActivate):self{
  982.         $this->canActivate $canActivate;
  983.         return $this;
  984.     }
  985.   
  986.     public function getCampaignAmount(){
  987.         return $this->campaignAmount;
  988.     }
  989.     public function setCampaignAmountApi($campaignAmount){
  990.         $this->campaignAmount $campaignAmount;
  991.     }
  992.     public function getCanValidate(){
  993.         return $this->canValidate;
  994.     }
  995.     public function setCanValidateApi(?bool $canValidate):self{
  996.         $this->canValidate $canValidate;
  997.         return $this;
  998.     }
  999.     public function getRemainDays(): ?float
  1000.     {
  1001.         return $this->remainDays;
  1002.     }
  1003.     public function setRemainDays(float $remainDays): self
  1004.     {
  1005.         $this->remainDays $remainDays;
  1006.         return $this;
  1007.     }
  1008.     public function getResponsable(): ?array
  1009.     {
  1010.         return $this->responsable;
  1011.     }
  1012.     public function setResponsable(array $responsable): self
  1013.     {
  1014.         $this->responsable $responsable;
  1015.         return $this;
  1016.     }
  1017.     public function getPlanningAdditionalInformation(){
  1018.         return $this->planningAdditionalInformation;
  1019.     }
  1020.     public function setPlanningAdditionalInformation($planningAdditionalInformation){
  1021.        $this->planningAdditionalInformation $planningAdditionalInformation;
  1022.        return $this;
  1023.        
  1024.     }
  1025.  ///////////////////
  1026.     public function getEvaluate(): ?bool
  1027.     {
  1028.         return $this->evaluate;
  1029.     }
  1030.     public function getPositionOrder(): ?int
  1031.     {
  1032.         return $this->positionOrder;
  1033.     }
  1034.     public function setPositionOrder(?int $positionOrder): self
  1035.     {
  1036.         $this->positionOrder $positionOrder;
  1037.         return $this;
  1038.     }
  1039.     public function getPriceSale(): ?string
  1040.     {
  1041.         return $this->priceSale;
  1042.     }
  1043.     public function setPriceSale(?string $priceSale): self
  1044.     {
  1045.         $this->priceSale $priceSale;
  1046.         return $this;
  1047.     }
  1048.     public function canStart(){
  1049.         $canStart = ['state'=>true,'ListOfMissions'=>''];
  1050.         $matriceStatus = ['in_progress'];
  1051.         $campaign $this->getCampaign();
  1052.         foreach ($campaign->getMissions() as $mission) {
  1053.             if ($mission->getPositionOrder() < $this->getPositionOrder() and in_array($mission->getState(),$matriceStatus) and !is_null($mission->getPositionOrder())) {
  1054.                $canStart['state'] =  false;
  1055.                $canStart['ListOfMissions'] .=  $mission->getProduct()->getName()." et ";
  1056.             }
  1057.         }
  1058.         if (strrpos($canStart['ListOfMissions'], "et") !== false) {
  1059.             // Extraire la partie de la chaîne avant la dernière occurrence de "et"
  1060.             $canStart['ListOfMissions'] = substr($canStart['ListOfMissions'], 0strrpos($canStart['ListOfMissions'], "et"));
  1061.         }
  1062.         return $canStart;
  1063.     }
  1064.     public function getPriceApi(): ?float
  1065.     {
  1066.         return $this->priceApi;
  1067.     }
  1068.     public function setPriceApi(?float $priceApi): self
  1069.     {
  1070.         $this->priceApi $priceApi;
  1071.         return $this;
  1072.     }
  1073.     public function getTimeApi(): ?float
  1074.     {
  1075.         return $this->timeApi;
  1076.     }
  1077.     public function setTimeApi(?float $timeApi): self
  1078.     {
  1079.         $this->timeApi $timeApi;
  1080.         return $this;
  1081.     }
  1082.     public function getPriceWithMargeMyFlow(): ?string
  1083.     {
  1084.         return $this->priceWithMargeMyFlow;
  1085.     }
  1086.     public function setPriceWithMargeMyFlow(?string $priceWithMargeMyFlow): self
  1087.     {
  1088.         $this->priceWithMargeMyFlow $priceWithMargeMyFlow;
  1089.         return $this;
  1090.     }
  1091.     public function getMargeMyFlow(): ?string
  1092.     {
  1093.         return $this->margeMyFlow;
  1094.     }
  1095.     public function setMargeMyFlow(?string $margeMyFlow): self
  1096.     {
  1097.         $this->margeMyFlow $margeMyFlow;
  1098.         return $this;
  1099.     }
  1100.    
  1101.     public function getConfidential(): ?bool
  1102.     {
  1103.         return $this->confidential;
  1104.     }
  1105.     public function setConfidential($confidential): self
  1106.     {
  1107.         $this->confidential $confidential;
  1108.         return $this;
  1109.     }
  1110.     public function getAlreadyAcceptConfidentialityContract(): ?bool
  1111.     {
  1112.         return $this->alreadyAcceptConfidentialityContract;
  1113.     }
  1114.     public function setAlreadyAcceptConfidentialityContract($alreadyAcceptConfidentialityContract): self
  1115.     {
  1116.         $this->alreadyAcceptConfidentialityContract $alreadyAcceptConfidentialityContract;
  1117.         return $this;
  1118.     }
  1119. }