src/Entity/Campaign.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Service\MissionService;
  4. use App\Enum\Role;
  5. use App\Enum\ProductType;
  6. use App\Repository\CampaignRepository;
  7. use App\Service\CampaignService;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\DBAL\Types\Types;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Uid\Uuid;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. #[ORM\Entity(repositoryClassCampaignRepository::class)]
  16. #[ORM\Table(name'campaigns')]
  17. class Campaign
  18. {
  19.     #[ORM\Id]
  20.     #[ORM\Column(type'string'length22uniquetrue)]
  21.     #[Groups(['campaign''mission_list''mission_read','message_read'])]
  22.     
  23.     private string $id;
  24.     #[ORM\Column(type'string')]
  25.     #[Assert\NotBlank(message'Merci de remplir ce champs')]
  26.     #[Groups(['campaign''mission_list''mission_read'])]
  27.     private ?string $name '';
  28.     #[ORM\Column(type'string')]
  29.     #[Groups(['campaign','mission_list','mission_read'])]
  30.     private string $state 'provisional';
  31.     #[ORM\Column(type'datetime'nullabletrue)]
  32.     private ?\DateTimeInterface $dateClosed null;
  33.     
  34.     #[ORM\Column(type'boolean'nullabletrue)]
  35.     private $isNew;
  36.     #[ORM\Column(type'boolean'nullabletrue)]
  37.     private $disabled;
  38.       #[ORM\Column(type'boolean'nullabletrue)]
  39.     private $confidentiality;
  40.     #[ORM\Column(type'datetime_immutable')]
  41.     #[Groups(['campaign'])]
  42.     private \DateTimeImmutable $createdAt;
  43.     #[ORM\ManyToOne(targetEntityCompany::class, inversedBy'campaigns',  cascade: ["persist"])]
  44.     #[Groups(['campaign''mission_read','mission_list'])]
  45.     private ?Company $company null;
  46.     #[ORM\OneToMany(mappedBy'campaign'targetEntityMission::class, cascade: ['persist'], orphanRemovaltrue)]
  47.     #[Groups(['campaign'])]
  48.     private Collection $missions;
  49.     #[ORM\ManyToOne(targetEntityUser::class, inversedBy'campaigns')]
  50.     private ?User $orderedBy null;
  51.     #[ORM\Column(type'boolean'nullabletrue)]
  52.     private ?bool $invoiced false;
  53.      #[ORM\Column(type'boolean'nullabletrue)]
  54.     private ?bool $activeFrequency false;
  55.     #[ORM\OneToMany(mappedBy'campaign'targetEntityInvoice::class, cascade: ['persist'])]
  56.     private ?Collection $invoices;
  57.     #[ORM\OneToOne(targetEntityRecurringService::class,cascade: ['persist'])]
  58.     private $frequency;
  59.     #[ORM\OneToMany(mappedBy'campaign'targetEntityMessage::class)]
  60.     #[Groups(['mission_read'])]
  61.     private ?Collection $messages;
  62.     #[ORM\Column(type'string'length255nullabletrue)]
  63.     private ?string $totalCostCampaign null;
  64.     #[ORM\Column(type'text'nullabletrue)]
  65.     private ?string $cancelReason null;
  66.     #[ORM\Column(type'text'nullabletrue)]
  67.     private ?string $brief null;
  68.     #[ORM\Column(type'boolean'nullabletrue)]
  69.     private $isPaidOnCredit;
  70.     #[ORM\Column(type'string'length255nullabletrue)]
  71.     private $paymentMethod;
  72.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  73.     private $activatedAt;
  74.     #[ORM\Column(type'string'length255nullabletrue)]
  75.     private $clientStatus;
  76.     #[ORM\Column(type'boolean'nullabletrue)]
  77.     private $isToBeinvoiced;
  78.     #[ORM\Column(type'float'nullabletrue)]
  79.     private $discountForCompany;
  80.     #[ORM\Column(type'boolean'nullabletrue)]
  81.     private $reSendToClient;
  82.      #[ORM\OneToMany(mappedBy'campaign'targetEntityFileMission::class, cascade: ["persist""remove"], orphanRemovaltrue)]
  83.     private ?Collection $fileMissions;
  84.     /**
  85.      * This property is not persited because there are a problème in the commande
  86.      * 
  87.      * @var string
  88.      */
  89.     private ?string $errorCommand null;
  90.     #[ORM\Column(type'string'length255nullabletrue)]
  91.     private $numberInitialOfMissions;
  92.     #[ORM\Column(type'string'length255nullabletrue)]
  93.     private $lastState;
  94.     #[ORM\ManyToOne(targetEntityCreditHistory::class, inversedBy'campaigns')]
  95.     private $creditHistory;
  96.     #[ORM\Column(type'text'nullabletrue)]
  97.     private $deleteReason;
  98.     #[ORM\Column(type'boolean')]
  99.     private $isOrdoredByAdmin;
  100.     #[ORM\Column(type'array'nullabletrue)]
  101.     private $defautObserver = [];
  102.     #[ORM\Column(type'array'nullabletrue)]
  103.     private $defaultValidator = [];
  104.     #[ORM\Column(type'array'nullabletrue)]
  105.     private $defaultValidatorExternal = [];
  106.     #[ORM\Column(type'array'nullabletrue)]
  107.     private $defautObserverExternal = [];
  108.     #[ORM\Column(nullabletrue)]
  109.     private ?\DateTimeImmutable $statusModifyAt null;
  110.     #[ORM\Column(nullabletrue)]
  111.     private ?bool $isRecurrent null;
  112.     #[ORM\Column(length255,nullabletrue)]
  113.     private ?string $recurringState null;
  114.     #[ORM\OneToMany(mappedBy'campaign'targetEntityCampaignPendingToSend::class)]
  115.     private $campaignPendingToSends;
  116.     #[ORM\Column(type'integer'nullabletrue)]
  117.     private $lastStepWp;
  118.     #[ORM\Column(type'integer'nullabletrue)]
  119.     private $frontWpId;
  120.     #[ORM\Column(type'string'length255nullabletrue)]
  121.     private $wpSlug;
  122.     #[ORM\Column(type'array'nullabletrue)]
  123.     #[Groups(['campaign''mission_list''mission_read'])]
  124.     private $stateHistory = [];
  125.     #[ORM\Column(type'integer'nullabletrue)]
  126.     private $typeInitiation;
  127.     #[ORM\Column(type'boolean'nullabletrue)]
  128.     private $emailSentInsuffBudget;
  129.     #[ORM\Column(type'array'nullabletrue)]
  130.     private $user_writing = [];
  131.     #[ORM\Column(type'string'length255nullabletrue)]
  132.     private $cloningSourceId;
  133.     #[ORM\Column(nullabletrue)]
  134.     private ?int $isActivated 0;
  135.     #[Groups(['mission_read'])]
  136.     private $isAlreadyStart=false;
  137.     #[ORM\Column(nullabletrue)]
  138.     private ?bool $newForLivrable null;
  139.     public function __construct()
  140.     {
  141.         $this->id Uuid::v4()->toBase58();
  142.         $this->createdAt = new \DateTimeImmutable();
  143.         $this->activatedAt = new \DateTimeImmutable();
  144.         $this->statusModifyAt = new \DateTimeImmutable();
  145.         $this->missions = new ArrayCollection();
  146.         $this->invoices = new ArrayCollection();
  147.         $this->messages = new ArrayCollection();
  148.         $this->isToBeinvoiced false;
  149.         $this->reSendToClientfalse;
  150.         $this->clientStatus="";
  151.         $this->isOrdoredByAdmin false;
  152.         $this->activeFrequency false;
  153.         $this->recurringState null;
  154.         $this->fileMissions = new ArrayCollection();
  155.         $this->confidentiality false;
  156.         $this->campaignPendingToSends = new ArrayCollection();
  157.         $this->stateHistory = [];
  158.         $this->emailSentInsuffBudget false;
  159.         $this->wpSlug "";
  160.         $this->newForLivrable false
  161.     }
  162.     public function __clone()
  163.     {
  164.         $this->cloningSourceId =  $this->getId(); 
  165.         $this->id Uuid::v4()->toBase58();
  166.         $this->missions = new ArrayCollection();
  167.         $this->messages = new ArrayCollection();
  168.         $this->createdAt = new \DateTimeImmutable();
  169.         $this->activatedAt = new \DateTimeImmutable();;
  170.         $this->invoices = clone $this->invoices;
  171.         $this->frequency null;
  172.         
  173.        
  174.     
  175.     }
  176.     public function getId(): ?string
  177.     {
  178.         return $this->id;
  179.     }
  180.     public function generateNewId():self{
  181.         $this->id Uuid::v4()->toBase58() ;
  182.         return $this;
  183.     }
  184.     /**
  185.      * @return string
  186.      */
  187.     public function getName(): string
  188.     {
  189.         return $this->name;
  190.     }
  191.     /**
  192.      * @param string $name
  193.      * @return Campaign
  194.      */
  195.     public function setName(?string $name): Campaign
  196.     {
  197.         $this->name $name;
  198.         return $this;
  199.     }
  200.     /**
  201.      * @return \DateTimeImmutable|null
  202.      */
  203.     public function getCreatedAt(): ?\DateTimeInterface
  204.     {
  205.         return $this->createdAt;
  206.     }
  207.     /**
  208.      * @param \DateTimeImmutable|null $createdAt
  209.      * @return Campaign
  210.      */
  211.     public function setCreatedAt(?\DateTimeImmutable $createdAt): Campaign
  212.     {
  213.         $this->createdAt $createdAt;
  214.         return $this;
  215.     }
  216.     public function getCompany(): ?Company
  217.     {
  218.         return $this->company;
  219.     }
  220.     public function setCompany(?Company $company): self
  221.     {
  222.         $this->company $company;
  223.         return $this;
  224.     }
  225.     /**
  226.      * @return Collection|Mission[]
  227.      */
  228.     public function getMissions(): Collection
  229.     {
  230.         return $this->missions;
  231.     }
  232.     public function addMission(Mission $mission): self
  233.     {
  234.         if (!$this->missions->contains($mission)) {
  235.             $this->missions[] = $mission;
  236.             $mission->setCampaign($this);
  237.         }
  238.         return $this;
  239.     }
  240.     public function removeMission(Mission $mission): self
  241.     {
  242.         if ($this->missions->removeElement($mission)) {
  243.             // set the owning side to null (unless already changed)
  244.             if ($mission->getCampaign() === $this) {
  245.                 $mission->setCampaign(null);
  246.             }
  247.         }
  248.         return $this;
  249.     }
  250.     /**
  251.      * @return string
  252.      */
  253.     public function getState(): string
  254.     {
  255.         return $this->state;
  256.     }
  257.     /**
  258.      * @param string $state
  259.      * @return Campaign
  260.      */
  261.     public function setState(string $state): Campaign
  262.     {   
  263.         $this->statusModifyAt = new \DateTimeImmutable();
  264.         $notActivated $this->getCreatedAt() ==  $this->getActivatedAt() ? true false;
  265.         $isCampaignNotActivated is_null($this->getIsActivated()) || $this->getIsActivated() == true false
  266.         if ($this->getState() !== "in_progress" &&  ($state == "in_progress" || $state == "archived") && $notActivated && $isCampaignNotActivated){
  267.             $this->setActivatedAt(new \DateTimeImmutable());
  268.             $this->setIsActivated(1);
  269.         }
  270.         $this->setLastState($this->state);
  271.         $stateHistory $this->getStateHistory()!=null ?  $this->getStateHistory() : [];
  272.         $this->setStateHistory([...$stateHistory, [
  273.             [
  274.                 'date'=> date('d/M/Y h:i:s'), 
  275.                 'state'=>$this->state
  276.             ]
  277.         ]]);
  278.         $this->state $state;
  279.         //modify date closed
  280.         if ($state == "closed") {
  281.             $this->dateClosed = new \DateTimeImmutable();
  282.         }
  283.         //end modification
  284.         return $this;
  285.     }
  286.     
  287.     public function getOrderedBy(): ?User
  288.     {
  289.         return $this->orderedBy;
  290.     }
  291.     public function setOrderedBy(?User $orderedBy): self
  292.     {
  293.         $this->orderedBy $orderedBy;
  294.         return $this;
  295.     }
  296.     public function getProgress(): int
  297.     {
  298.         $progress 0;
  299.         foreach ($this->getMissionsWithoutEspaceDeDiscussion() as $mission) {
  300.             if (!empty($mission->getWorkflow())) {
  301.                 if ($mission->getState() == "finalized") {
  302.                     $progress +=100;
  303.                 }else{
  304.                     $progress += $mission->getWorkflow()->getProgress();
  305.                 }
  306.             }
  307.         }
  308.         $count 0;
  309.         foreach ($this->getMissionsWithoutEspaceDeDiscussion() as $mission) {
  310.             if ($mission->getProduct()->getName() != "Espace de discussion") {
  311.                 $count++;
  312.             }
  313.         }
  314.         if ($progress 0) {
  315.             return $progress $count;
  316.         }
  317.         // $progress  = $progress > 100 ? 100 :  $progress; 
  318.         return round($progress);
  319.     }
  320.     public function getTotalCost(): float
  321.     {
  322.         $cost 0;
  323.      
  324.         foreach ($this->getMissions() as $mission) {
  325.             if($mission->getState() != "cancelled"){
  326.                 $cost += $mission->getPrice() * $mission->getQuantity();
  327.                 
  328.             }
  329.         }
  330.         return $cost;
  331.     }
  332.     public function getInvoiced(): ?bool
  333.     {
  334.         return $this->invoiced;
  335.     }
  336.     public function setInvoiced(?bool $invoiced): self
  337.     {
  338.         $this->invoiced $invoiced;
  339.         return $this;
  340.     }
  341.     /**
  342.      * @return Collection|Invoice[]
  343.      */
  344.     public function getInvoices(): Collection
  345.     {
  346.         return $this->invoices;
  347.     }
  348.     public function addInvoice(Invoice $invoice): self
  349.     {
  350.         if (!$this->invoices->contains($invoice)) {
  351.             $this->invoices[] = $invoice;
  352.             $invoice->setCampaign($this);
  353.         }
  354.         return $this;
  355.     }
  356.     public function removeInvoice(Invoice $invoice): self
  357.     {
  358.         if ($this->invoices->removeElement($invoice)) {
  359.             // set the owning side to null (unless already changed)
  360.             if ($invoice->getCampaign() === $this) {
  361.                 $invoice->setCampaign(null);
  362.             }
  363.         }
  364.         return $this;
  365.     }
  366.     /**
  367.      * @return Collection|Message[]
  368.      */
  369.     public function getMessages(): Collection
  370.     {
  371.         return $this->messages;
  372.     }
  373.     public function addMessage(Message $message): self
  374.     {
  375.         if (!$this->messages->contains($message)) {
  376.             $this->messages[] = $message;
  377.             $message->setCampaign($this);
  378.         }
  379.         return $this;
  380.     }
  381.     public function subcontractorActivatedForfait($idUser){
  382.         foreach ($this->getMissions() as $mission) {
  383.             foreach ($mission->getParticipants() as $key => $participant) {
  384.                 if ($idUser == $participant->getUser()->getId() and $participant->isActivated()) {
  385.                     return true;
  386.                 }
  387.             }
  388.         }
  389.         return false;
  390.     }
  391.     public function allProductIsForfait(){
  392.      
  393.         foreach ($this->getMissions() as $mission) {
  394.             if ($mission->getProduct()->getType() != ProductType::AU_FORFAIT) {
  395.                 return false;
  396.             }
  397.         }
  398.         return true;
  399.     }
  400.     public function removeMessage(Message $message): self
  401.     {
  402.         if ($this->messages->removeElement($message)) {
  403.             // set the owning side to null (unless already changed)
  404.             if ($message->getCampaign() === $this) {
  405.                 $message->setCampaign(null);
  406.             }
  407.         }
  408.         return $this;
  409.     }
  410.     public function getTotalCostCampaign(): ?string
  411.     {
  412.         return $this->totalCostCampaign;
  413.     }
  414.     public function setTotalCostCampaign(?string $totalCostCampaign): self
  415.     {
  416.         $this->totalCostCampaign $totalCostCampaign;
  417.         return $this;
  418.     }
  419.     /**
  420.      * @return string|null
  421.      */
  422.     public function getCancelReason(): ?string
  423.     {
  424.         return $this->cancelReason;
  425.     }
  426.     /**
  427.      * @param string|null $cancelReason
  428.      */
  429.     public function setCancelReason(?string $cancelReason): void
  430.     {
  431.         $this->cancelReason $cancelReason;
  432.     }
  433.     /**
  434.      * @return string|null
  435.      */
  436.     public function getBrief(): ?string
  437.     {
  438.         return $this->addTargetBlankToBriefLink($this->brief);
  439.     }
  440.     /**
  441.      * @param string|null $brief
  442.      */
  443.     public function setBrief(?string $brief):void
  444.     {
  445.         $this->brief $this->addTargetBlankToBriefLink($brief);
  446.     }
  447.     /**
  448.      * @param string|null $brief
  449.      * @return string|null $brief
  450.      */
  451.     private function addTargetBlankToBriefLink(?string $brief): ?string {
  452.         $regex '/<a\s+(?:[^>]*?\s+)?href="([^"]*)"(?:[^>]*?\s+)?(target="_blank")?>([^<]*)<\/a>/i';
  453.         if(!is_null($brief)){
  454.             preg_match_all($regex,$brief,$matches,PREG_SET_ORDER);
  455.             foreach ($matches as $match){
  456.                 // $match[1] est l'URL du lien
  457.                 // $match[2] est l'attribut target si prĂ©sent
  458.                 // $match[3] est le contenu du lien
  459.                 if (!empty($match[1]) && empty($match[2])) {
  460.                     // Ajoutez l'attribut target="_blank" si l'URL n'est pas vide et que l'attribut target n'est pas prĂ©sent
  461.                     $brief str_replace($match[0], '<a href="'.$match[1].'" target="_blank">'.$match[3].'</a>'$brief);
  462.                 }
  463.             }
  464.         }
  465.        
  466.         return $brief;
  467.     }
  468.     public function canActivate(bool $isAdmin falsebool $isSubContractor false): bool
  469.     {
  470.         if ($this->getMissions()->count() === 0) {
  471.             return false;
  472.         }
  473.         if (!$isSubContractor && !$isAdmin) {
  474.             return false;
  475.         }
  476.         $subcontractors = [];
  477.         foreach ($this->getMissions() as $mission) {
  478.             if (!$mission->canActivate()) {
  479.                 return false;
  480.             }
  481.             foreach ($mission->getParticipants() as $participant) {
  482.                 if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR && !in_array($participant->getUser()->getId(), $subcontractors)) {
  483.                     $subcontractors[] = $participant->getUser()->getId();
  484.                 }
  485.             }
  486.         }
  487.         if (!$isAdmin && count($subcontractors) > 1) {
  488.             return false;
  489.         }
  490.         return true;
  491.     }
  492.     public function canShowPriceInClient(){
  493.         $show true;
  494.         foreach ($this->getMissions() as $mission) {
  495.             //product forfaitaire pas pris en compte
  496.             if ($mission->getProduct()->getType()->value == 1) {
  497.                 continue;
  498.             }
  499.             //end
  500.             //first test is determine all  mission already have a complete subcontrator
  501.             $jobNotExists array_diff($this->getJobInMission($mission), $this->getJobSubcontractorInMission($mission));
  502.              if (!empty($jobNotExists)) {
  503.                  return false;
  504.              }
  505.              if($mission->getProduct()->getType()->value  == ){
  506.                 continue;
  507.              }
  508.              //second test is determine all  subcontrator is evaluated
  509.              foreach ($mission->getParticipants() as $participant) {
  510.                 if($mission->getPriceSale()!=null){
  511.                     continue;
  512.                 }
  513.                 if ($participant->getRole()->value =="ROLE_SUBCONTRACTOR" ) {
  514.                     if (is_null($participant->getEstimatedIncome()))
  515.                          {
  516.                         return false;
  517.                     }
  518.                 }
  519.             }
  520.         }
  521.        
  522.         return $show;
  523.     }
  524.     /**
  525.      * get all job in mission
  526.      * @param  Mission $mission 
  527.      * @return Array
  528.      */
  529.     public function getJobInMission(Mission $mission)
  530.     {
  531.         $listJobInMission = [];
  532.         foreach ($mission->getProduct()->getJobs() as $job) {
  533.             $listJobInMission[] = $job->getName();
  534.         }
  535.         return $listJobInMission;
  536.     }
  537.      /**
  538.      * get all job participant in mission
  539.      * @param  Mission $mission 
  540.      * @return Array
  541.      */
  542.     public function getJobSubcontractorInMission(Mission $mission)
  543.     {
  544.         $listAllJobSub = [];
  545.         foreach ($mission->getParticipants() as $participant) {
  546.             if (!is_null($participant) && !is_null($participant->getJob()))
  547.                 $listAllJobSub[] = $participant->getJob()->getName();
  548.         }
  549.         return $listAllJobSub;
  550.     }
  551.     /**
  552.      * Get content of campaign and returned this content
  553.      * 
  554.      * 1 : if content of campaign is a product forfaitaire only
  555.      * 
  556.      * 2 : if content of campaign is a product to evaluate only
  557.      * 
  558.      * 3 : if content of campaign is a product mixed only
  559.      * 
  560.      * @return int 
  561.      */
  562.     public function getTypeOfProduct():int
  563.     {
  564.         $nombreProductForfaitaire ;
  565.         $nombreProductAEvaluer ;
  566.         $nombreOfMissions sizeof($this->getMissions());
  567.         foreach ($this->getMissions() as $key => $mission) {
  568.                 if($mission->getProduct()->getType()->value == || $mission->getProduct()->getType()->value == ){
  569.                     $nombreProductForfaitaire++;
  570.                 }
  571.                 else{
  572.                     $nombreProductAEvaluer ++;
  573.                 }
  574.         }
  575.         if($nombreProductForfaitaire==$nombreOfMissions){
  576.             return 1;
  577.         }
  578.         elseif($nombreProductAEvaluer==$nombreOfMissions){
  579.             return 2;
  580.         }
  581.         else {
  582.             return 3;
  583.         }
  584.     }
  585.    
  586.     /**
  587.      * This method show if one subcontrator is in an all mission
  588.      * 
  589.      * @return bool true if one subcontractor for all mission in campaign, and false for contrary
  590.      */
  591.     public function isOneSubcontractorForAllMission():bool
  592.     {
  593.         $userIdnull;
  594.         foreach ($this->getMissions() as $mission) {
  595.             foreach ($mission->getParticipants() as $participant) {
  596.                 if($participant->getRole()->value =="ROLE_SUBCONTRACTOR" && !in_array('ROLE_BOT',$participant->getUser()->getRoles())){
  597.                     if($userId == null){
  598.                         $userId $participant->getUser()->getId();
  599.                     }
  600.                     else{
  601.                         if($userId !==  $participant->getUser()->getId()){
  602.                             return false;
  603.                         }
  604.                     }
  605.                 }
  606.             }
  607.         }
  608.         return true;
  609.     }
  610.     public function haveBot(){
  611.         foreach ($this->getMissions() as $mission) {
  612.             foreach ($mission->getParticipants() as $participant) {
  613.                 if (in_array('ROLE_BOT',$participant->getUser()->getRoles())) {
  614.                     return true;
  615.                 }
  616.             }
  617.         }
  618.         return false;
  619.     }
  620.     /**
  621.      * Get all  mission no subcontractor
  622.      * 
  623.      * @return array
  624.      */
  625.     public function getMissionNoSubContractor(): array
  626.     {   
  627.         $missionNoSubContractor = [];
  628.         foreach ($this->getMissions() as $mission) {
  629.             if(!$this->missionHaveSubcontractor($mission)){
  630.                 $missionNoSubContractor=[...$missionNoSubContractor$mission];
  631.             }
  632.         }
  633.         return $missionNoSubContractor;
  634.     }
  635.     public function canResendMail()
  636.     {
  637.         foreach ($this->getMissions() as $mission) {
  638.             if ($mission->getWorkflow() !== null)
  639.                 foreach ($mission->getWorkflow()->getSteps() as  $step) {
  640.                     if ($step->isActive()) {
  641.                         return true;
  642.                     }
  643.                 }
  644.         }
  645.         return false;
  646.     }
  647.     /**
  648.      * For know if a campain is payed by credit
  649.      * 
  650.      * @return bool|null
  651.      */
  652.     public function getIsPaidOnCredit(): ?bool
  653.     {
  654.         return $this->isPaidOnCredit;
  655.     }
  656.     /**
  657.      * @param bool|null $isPaidOnCredit
  658.      * 
  659.      * @return self
  660.      */
  661.     public function setIsPaidOnCredit(?bool $isPaidOnCredit): self
  662.     {
  663.         $this->isPaidOnCredit $isPaidOnCredit;
  664.         return $this;
  665.     }
  666.     public function getPaymentMethod(): ?string
  667.     {
  668.         return $this->paymentMethod;
  669.     }
  670.     public function setPaymentMethod(?string $paymentMethod): self
  671.     {
  672.         $this->paymentMethod $paymentMethod;
  673.         return $this;
  674.     }
  675.     public function canActivateEveryMission()
  676.     {
  677.         $verifisAllMissionisDefined true;
  678.         foreach ($this->getMissions() as $mission) {
  679.             if ( $mission->getStateProvider() != "cancelled" ) {
  680.                 if ($mission->canActivate() === false) {
  681.                     return false;
  682.                 }
  683.                 if (!$this->missionHaveSubcontractor($mission)) {
  684.                     return false;
  685.                 }
  686.                 if (is_null($mission->getWorkflow())) {
  687.                     return false;
  688.                 }
  689.             }
  690.         }
  691.         return $verifisAllMissionisDefined;
  692.     }
  693.     public function missionHaveSubcontractor($mission)
  694.     {
  695.         //1 = temps passĂ© izy de tsy ilaina.
  696.         $haveSubcontractor false;
  697.         foreach ($mission->getParticipants() as $participant) {
  698.             if (($participant->getRole() === Role::ROLE_SUBCONTRACTOR and $participant->getUser()->getBillingMethod() == and !in_array('ROLE_BOT'$participant->getUser()->getRoles()))
  699.                 or
  700.                 ($participant->getRole() === Role::ROLE_SUBCONTRACTOR and $participant->getUser()->getBillingMethod() == and !in_array('ROLE_BOT'$participant->getUser()->getRoles()))
  701.             ) {
  702.                 $haveSubcontractor true;
  703.             }
  704.         }
  705.         return $haveSubcontractor;
  706.     }
  707.     public function getActivatedAt(): ?\DateTimeImmutable
  708.     {
  709.         return $this->activatedAt;
  710.     }
  711.     public function setActivatedAt(?\DateTimeImmutable $activatedAt): self
  712.     {
  713.         $this->activatedAt $activatedAt;
  714.         return $this;
  715.     }
  716.     public function getClientStatus(): ?string
  717.     {
  718.         return $this->clientStatus;
  719.     }
  720.     public function setClientStatus(?string $clientStatus): self
  721.     {
  722.         $this->clientStatus $clientStatus;
  723.         return $this;
  724.     }
  725.     public function isToBeinvoiced(): ?bool
  726.     {
  727.         return $this->isToBeinvoiced;
  728.     }
  729.     public function setIsToBeinvoiced(?bool $isToBeinvoiced): self
  730.     {
  731.         $this->isToBeinvoiced $isToBeinvoiced;
  732.         return $this;
  733.     }
  734.     public function getDiscountForCompany(): ?float
  735.     {
  736.         return $this->discountForCompany;
  737.     }
  738.     public function setDiscountForCompany(?float $discountForCompany): self
  739.     {
  740.         $this->discountForCompany $discountForCompany;
  741.         return $this;
  742.     }
  743.     public function getReSendToClient(): ?bool
  744.     {
  745.         return $this->reSendToClient;
  746.     }
  747.     public function setReSendToClient(?bool $reSendToClient): self
  748.     {
  749.         $this->reSendToClient $reSendToClient;
  750.         return $this;
  751.     }
  752.     /**
  753.      * To get a error if a commande have an error 
  754.      * 
  755.      * @return string
  756.      */
  757.     public function getErrorCommand():?string{
  758.         return $this->errorCommand;
  759.     }
  760.    
  761.     /**
  762.      * set a error command manually because this is not persisted
  763.      * 
  764.      * @param string $errorCommand
  765.      * 
  766.      * @return void
  767.      */
  768.     public function setErrorCommand(?string $errorCommand):void 
  769.     {
  770.         $this->errorCommand$errorCommand;
  771.     }
  772.     public function getNumberInitialOfMissions(): ?string
  773.     {
  774.         return $this->numberInitialOfMissions;
  775.     }
  776.     public function setNumberInitialOfMissions(?string $numberInitialOfMissions): self
  777.     {
  778.         $this->numberInitialOfMissions $numberInitialOfMissions;
  779.         return $this;
  780.     }
  781.     public function getLastState(): ?string
  782.     {
  783.         return $this->lastState;
  784.     }
  785.     public function setLastState(?string $lastState): self
  786.     {
  787.         $this->lastState $lastState;
  788.         return $this;
  789.     }
  790.     public function getDiscountValueForCredit(): float
  791.     {
  792.         return 220*(1-$this->getDiscountForCompany()/100);
  793.     }
  794.     public function getCreditHistory(): ?CreditHistory
  795.     {
  796.         return $this->creditHistory;
  797.     }
  798.     public function setCreditHistory(?CreditHistory $creditHistory): self
  799.     {
  800.         $this->creditHistory $creditHistory;
  801.         return $this;
  802.     }
  803.     public function canClosedCampaing(){
  804.         $missions $this->missions;
  805.         //connaitre les delais des participant s'il ont deja ajoutĂ© leur delais
  806.         foreach ($missions as $mission) {
  807.             //si tout les participants ont remplies leurs delais
  808.             foreach ($mission->getParticipants() as $participant) {
  809.                 if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR){
  810.                     if ( 
  811.                         (is_null($participant->getInitialTime()) || 
  812.                         is_null($participant->getEstimatedIncome())
  813.                         )
  814.                         ||
  815.                         ($participant->getInitialTime() == || $participant->getEstimatedIncome() == )
  816.                     ) {
  817.                         return false;
  818.                     }
  819.                 }
  820.             }
  821.             // $jobNotExists = array_diff($this->missionService->getJobInMission($mission), $this->missionService->getJobSubcontractorInMission($mission));
  822.         }
  823.         return true;
  824.     }
  825.     public function getDeleteReason(): ?string
  826.     {
  827.         return $this->deleteReason;
  828.     }
  829.     public function setDeleteReason(?string $deleteReason): self
  830.     {
  831.         $this->deleteReason $deleteReason;
  832.         
  833.         return $this;
  834.     }
  835.     public function isOrdoredByAdmin(): ?bool
  836.     {
  837.         return $this->isOrdoredByAdmin;
  838.     }
  839.     public function setIsOrdoredByAdmin(bool $isOrdoredByAdmin): self
  840.     {
  841.         $this->isOrdoredByAdmin $isOrdoredByAdmin;
  842.         return $this;
  843.     }
  844.     public function getDefautObserver(): ?array
  845.     {
  846.         return $this->defautObserver;
  847.     }
  848.     public function setDefautObserver(array $defautObserver): self
  849.     {
  850.         $this->defautObserver $defautObserver;
  851.         return $this;
  852.     }
  853.     public function getDefaultValidator(): ?array
  854.     {
  855.         return $this->defaultValidator;
  856.     }
  857.     public function setDefaultValidator(?array $defaultValidator): self
  858.     {
  859.         $this->defaultValidator $defaultValidator;
  860.         return $this;
  861.     }
  862.     public function getStatusModifyAt(): ?\DateTimeImmutable
  863.     {
  864.         return $this->statusModifyAt;
  865.     }
  866.     public function setStatusModifyAt(?\DateTimeImmutable $statusModifyAt): static
  867.     {
  868.         $this->statusModifyAt $statusModifyAt;
  869.         return $this;
  870.     }
  871.     public function getIsToBeinvoiced(): ?bool
  872.     {
  873.         return $this->isToBeinvoiced;
  874.     }
  875.     public function getIsOrdoredByAdmin(): ?bool
  876.     {
  877.         return $this->isOrdoredByAdmin;
  878.     }
  879.     public function getFrequency(): ?RecurringService
  880.     {
  881.         return $this->frequency;
  882.     }
  883.     public function setFrequency(?RecurringService $frequency): self
  884.     {
  885.         $this->frequency $frequency;
  886.         return $this;
  887.     }
  888.     public function getActiveFrequency(): ?bool
  889.     {
  890.         return $this->activeFrequency;
  891.     }
  892.     public function setActiveFrequency(?bool $activeFrequency): self
  893.     {
  894.         $this->activeFrequency $activeFrequency;
  895.         return $this;
  896.     }
  897.     public function isRecurrent(): ?bool
  898.     {
  899.         return $this->isRecurrent;
  900.     }
  901.     public function setIsRecurrent(?bool $isRecurrent): static
  902.     {
  903.         $this->isRecurrent $isRecurrent;
  904.         return $this;
  905.     }
  906.     public function  __toString(){
  907.         return $this->getName();
  908.     }
  909.     public function getRecurringState(): ?string
  910.     {
  911.         return $this->recurringState;
  912.     }
  913.     public function setRecurringState(?string $recurringState): static
  914.     {
  915.         $this->recurringState $recurringState;
  916.         return $this;
  917.     }
  918.     public function getIsRecurrent(): ?bool
  919.     {
  920.         return $this->isRecurrent;
  921.     }
  922.     /**
  923.      * @return Collection|FileMission[]
  924.      */
  925.     public function getFileMissions(): Collection
  926.     {
  927.         return $this->fileMissions;
  928.     }
  929.     public function addFileMission(FileMission $fileMission): self
  930.     {
  931.         if (!$this->fileMissions->contains($fileMission)) {
  932.             $this->fileMissions[] = $fileMission;
  933.             $fileMission->setCampaign($this);
  934.         }
  935.         return $this;
  936.     }
  937.     public function removeFileMission(FileMission $fileMission): self
  938.     {
  939.         if ($this->fileMissions->removeElement($fileMission)) {
  940.             // set the owning side to null (unless already changed)
  941.             if ($fileMission->getCampaign() === $this) {
  942.                 $fileMission->setCampaign(null);
  943.             }
  944.         }
  945.         return $this;
  946.     }
  947.     public function getIsNew(): ?bool
  948.     {
  949.         return $this->isNew;
  950.     }
  951.     public function setIsNew(?bool $isNew): self
  952.     {
  953.         $this->isNew $isNew;
  954.         return $this;
  955.     }
  956.     public function getConfidentiality(): ?bool
  957.     {
  958.         return $this->confidentiality;
  959.     }
  960.     public function setConfidentiality(?bool $confidentiality): self
  961.     {
  962.         $this->confidentiality $confidentiality;
  963.         return $this;
  964.     }
  965.     public function getDisabled(): ?bool
  966.     {
  967.         return $this->disabled;
  968.     }
  969.     public function setDisabled(?bool $disabled): self
  970.     {
  971.         $this->disabled $disabled;
  972.         return $this;
  973.     }
  974.     /**
  975.      * @return Collection|CampaignPendingToSend[]
  976.      */
  977.     public function getCampaignPendingToSends(): Collection
  978.     {
  979.         return $this->campaignPendingToSends;
  980.     }
  981.     public function addCampaignPendingToSend(CampaignPendingToSend $campaignPendingToSend): self
  982.     {
  983.         if (!$this->campaignPendingToSends->contains($campaignPendingToSend)) {
  984.             $this->campaignPendingToSends[] = $campaignPendingToSend;
  985.             $campaignPendingToSend->setCampaign($this);
  986.         }
  987.         return $this;
  988.     }
  989.     public function removeCampaignPendingToSend(CampaignPendingToSend $campaignPendingToSend): self
  990.     {
  991.         if ($this->campaignPendingToSends->removeElement($campaignPendingToSend)) {
  992.             // set the owning side to null (unless already changed)
  993.             if ($campaignPendingToSend->getCampaign() === $this) {
  994.                 $campaignPendingToSend->setCampaign(null);
  995.             }
  996.         }
  997.         return $this;
  998.     }
  999.     public function getDefaultValidatorExternal(): ?array
  1000.     {
  1001.         return $this->defaultValidatorExternal;
  1002.     }
  1003.     public function setDefaultValidatorExternal(?array $defaultValidatorExternal): self
  1004.     {
  1005.         $this->defaultValidatorExternal $defaultValidatorExternal;
  1006.         return $this;
  1007.     }
  1008.     public function getDefautObserverExternal(): ?array
  1009.     {
  1010.         return $this->defautObserverExternal;
  1011.     }
  1012.     public function setDefautObserverExternal(?array $defautObserverExternal): self
  1013.     {
  1014.         $this->defautObserverExternal $defautObserverExternal;
  1015.         return $this;
  1016.     }
  1017.     public function getLastStepWp(): ?int
  1018.     {
  1019.         return $this->lastStepWp;
  1020.     }
  1021.     public function setLastStepWp(?int $lastStepWp): self
  1022.     {
  1023.         $this->lastStepWp $lastStepWp;
  1024.         return $this;
  1025.     }
  1026.     public function getFrontWpId(): ?int
  1027.     {
  1028.         return $this->frontWpId;
  1029.     }
  1030.     public function setFrontWpId(?int $frontWpId): self
  1031.     {
  1032.         $this->frontWpId $frontWpId;
  1033.         return $this;
  1034.     }
  1035.     public function getWpSlug(): ?string
  1036.     {
  1037.         return $this->wpSlug;
  1038.     }
  1039.     public function setWpSlug(?string $wpSlug): self
  1040.     {
  1041.         $this->wpSlug $wpSlug;
  1042.         return $this;
  1043.     }
  1044.     public function getStateHistory(): ?array
  1045.     {
  1046.         return $this->stateHistory;
  1047.     }
  1048.     public function setStateHistory(?array $stateHistory): self
  1049.     {
  1050.         $this->stateHistory $stateHistory;
  1051.         return $this;
  1052.     }
  1053.     public function getTypeInitiation(): ?int
  1054.     {
  1055.         return $this->typeInitiation;
  1056.     }
  1057.     public function setTypeInitiation(?int $typeInitiation): self
  1058.     {
  1059.         $this->typeInitiation $typeInitiation;
  1060.         return $this;
  1061.     }
  1062.     public function getEmailSentInsuffBudget(): ?bool
  1063.     {
  1064.         return $this->emailSentInsuffBudget;
  1065.     }
  1066.     public function setEmailSentInsuffBudget(?bool $emailSentInsuffBudget): self
  1067.     {
  1068.         $this->emailSentInsuffBudget $emailSentInsuffBudget;
  1069.         return $this;
  1070.     }
  1071.     public function getAllUserExternal(){
  1072.         $allUserExternal = [];
  1073.         foreach ($this->getMissions() as $mission) {
  1074.             foreach ($mission->getParticipants() as $participant) {
  1075.                 if (in_array($participant->getRole()->value, ['ROLE_OBSERVER_EXTERNAL','ROLE_VALIDATOR_EXTERNAL']) and $participant->getUser()->getDeleted() == 0) {
  1076.                        $allUserExternal = [...$allUserExternal,$participant->getUser()];
  1077.                     }
  1078.                
  1079.             }
  1080.         }
  1081.         return $allUserExternal;
  1082.     }
  1083.     public function getAllUserInCampaing(){
  1084.         $allUser = [];
  1085.         foreach ($this->getMissions() as $mission) {
  1086.             foreach ($mission->getParticipants() as $participant) {
  1087.                 $allUser = [...$allUser,$participant->getUser()->getId()];
  1088.             }
  1089.         }
  1090.         return $allUser;
  1091.     }
  1092.      public function getAllUserInCampaingWithoutValidatorAndSubcontractor(){
  1093.         $allUser = [];
  1094.         $noRepeatIds = [];
  1095.         foreach ($this->getMissions() as $mission) {
  1096.             foreach ($mission->getParticipants() as $participant) {
  1097.                 if (!in_array($participant->getUser()->getId(), $noRepeatIds) and $participant->getRole() !== Role::ROLE_VALIDATOR and $participant->getRole() !== Role::ROLE_OBSERVER) {
  1098.                     $allUser = [...$allUser,$participant];
  1099.                     $noRepeatIds[] = $participant->getUser()->getId();
  1100.                 }
  1101.             }
  1102.         }
  1103.         return $allUser;
  1104.     }
  1105.     public function getUserWriting(): ?array
  1106.     {
  1107.         return $this->user_writing;
  1108.     }
  1109.     public function setUserWriting(?array $user_writing): self
  1110.     {
  1111.         $this->user_writing $user_writing;
  1112.         return $this;
  1113.     }
  1114.     public function getMissionsWithoutEspaceDeDiscussion(){
  1115.         $missions $this->getMissions(); 
  1116.         $tempMissions = [];
  1117.         foreach ($missions as $mission) {
  1118.             if($mission->getProduct()->getName() != "Espace de discussion"){
  1119.                 $tempMissions = [...$tempMissions$mission];
  1120.             }
  1121.         }
  1122.         return  new ArrayCollection($tempMissions); 
  1123.         
  1124.     }
  1125.     public function getMissionsWithoutTempPasse(){
  1126.         $missions $this->getMissions(); 
  1127.         $missonWithoutTempPasse = [];
  1128.         foreach ($missions as $mission) {
  1129.             if ($mission->getProduct()->getType() != ProductType::AU_TEMPS_PASSE) {
  1130.                 $tempMissions = [...$missonWithoutTempPasse$mission];
  1131.             }
  1132.         }
  1133.         return  new ArrayCollection($missonWithoutTempPasse); 
  1134.         
  1135.     }
  1136.     public function isAlreadyStart(){
  1137.         if($this->state == 'in_progress'){
  1138.             return true;
  1139.         }
  1140.         elseif($this->getStateHistory() != null ){
  1141.             foreach ($this->getStateHistory() as  $history) {
  1142.                   if($history[0] == 'in_progress'){
  1143.                     return true
  1144.                   }
  1145.             }
  1146.         }
  1147.         return false
  1148.     }
  1149.     // For api only, not persisted
  1150.     public function getIsAlreadyStart(){
  1151.         return $this->isAlreadyStart();
  1152.     }
  1153.     public function setIsAlreadyStart($isAlreadyStart){
  1154.         $this->isAlreadyStart $isAlreadyStart;
  1155.         return $this;
  1156.     }
  1157.     //
  1158.     public function getCloningSourceId(): ?string
  1159.     {
  1160.         return $this->cloningSourceId;
  1161.     }
  1162.     public function setCloningSourceId(?string $cloningSourceId): self
  1163.     {
  1164.         $this->cloningSourceId $cloningSourceId;
  1165.     
  1166.     }
  1167.     public function getIsActivated(): ?int
  1168.     {
  1169.         return $this->isActivated;
  1170.     }
  1171.     public function setIsActivated(?int $isActivated): static
  1172.     {
  1173.         $this->isActivated $isActivated;
  1174.         return $this;
  1175.     }
  1176.     public function getContactProject(){
  1177.         $contactProject = [];
  1178.         foreach ($this->getMissions() as $key => $mission) {
  1179.             foreach ($mission->getParticipants() as $participant) {
  1180.                 if ($participant->getRole() === Role::PROJECT_CONTACT) {
  1181.                     $contactProject[] = $participant->getUser();
  1182.                 }
  1183.             }
  1184.             if ($key 1) {
  1185.                 break;
  1186.             }
  1187.         }
  1188.         return $contactProject;
  1189.     }
  1190.     public function getDateClosed(): ?\DateTimeInterface
  1191.     {
  1192.         return $this->dateClosed;
  1193.     }
  1194.     public function setDateClosed(?\DateTimeInterface $dateClosed): static
  1195.     {
  1196.         $this->dateClosed $dateClosed;
  1197.         return $this;
  1198.     }
  1199.     public function isIsNew(): ?bool
  1200.     {
  1201.         return $this->isNew;
  1202.     }
  1203.     public function isDisabled(): ?bool
  1204.     {
  1205.         return $this->disabled;
  1206.     }
  1207.     public function isConfidentiality(): ?bool
  1208.     {
  1209.         return $this->confidentiality;
  1210.     }
  1211.     public function isInvoiced(): ?bool
  1212.     {
  1213.         return $this->invoiced;
  1214.     }
  1215.     public function isActiveFrequency(): ?bool
  1216.     {
  1217.         return $this->activeFrequency;
  1218.     }
  1219.     public function isIsPaidOnCredit(): ?bool
  1220.     {
  1221.         return $this->isPaidOnCredit;
  1222.     }
  1223.     public function isIsToBeinvoiced(): ?bool
  1224.     {
  1225.         return $this->isToBeinvoiced;
  1226.     }
  1227.     public function isReSendToClient(): ?bool
  1228.     {
  1229.         return $this->reSendToClient;
  1230.     }
  1231.     public function isIsOrdoredByAdmin(): ?bool
  1232.     {
  1233.         return $this->isOrdoredByAdmin;
  1234.     }
  1235.     public function isIsRecurrent(): ?bool
  1236.     {
  1237.         return $this->isRecurrent;
  1238.     }
  1239.     public function isEmailSentInsuffBudget(): ?bool
  1240.     {
  1241.         return $this->emailSentInsuffBudget;
  1242.     }
  1243.     public function isNewForLivrable(): ?bool
  1244.     {
  1245.         return $this->newForLivrable;
  1246.     }
  1247.     public function setNewForLivrable(?bool $newForLivrable): static
  1248.     {
  1249.         $this->newForLivrable $newForLivrable;
  1250.         return $this;
  1251.     }
  1252. }