src\Entity\UserSurvey.php line 17

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use DateTime;
  5. use DateTimeInterface;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Exception;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\UserSurveyRepository")
  12.  */
  13. class UserSurvey
  14. {
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="userSurveys")
  23.      * @ORM\JoinColumn(nullable=false)
  24.      */
  25.     private $user;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity="App\Entity\Survey", inversedBy="userSurveys")
  28.      * @ORM\JoinColumn(nullable=false)
  29.      */
  30.     private $survey;
  31.     /**
  32.      * @ORM\Column(type="smallint", nullable=true)
  33.      */
  34.     private $surveyMode;
  35.     /**
  36.      * @ORM\Column(type="datetime", nullable=false)
  37.      */
  38.     private $dateAdd;
  39.     /**
  40.      * @ORM\Column(type="datetime", nullable=false)
  41.      */
  42.     private $dateUpdate;
  43.     /**
  44.      * @ORM\Column(type="datetime", nullable=false)
  45.      */
  46.     private $statusDateUpdate;
  47.     /**
  48.      * @ORM\Column(type="datetime", nullable=true)
  49.      */
  50.     private $dateFinish;
  51.     /**
  52.      * @ORM\Column(type="datetime", nullable=true)
  53.      */
  54.     private $dateAFC;
  55.     /**
  56.      * @ORM\Column(type="datetime", nullable=true)
  57.      */
  58.     private $dateLimit;
  59.     /**
  60.      * @ORM\Column(type="boolean", nullable=true)
  61.      */
  62.     private $hasAFCRequested;
  63.     /**
  64.      * @ORM\OneToMany(targetEntity="App\Entity\UserSurveyQuestion", mappedBy="userSurvey", orphanRemoval=true, cascade={"all"})
  65.      */
  66.     private $userSurveyQuestions;
  67.     /**
  68.      * @ORM\OneToOne(targetEntity="App\Entity\Order", mappedBy="userSurvey", orphanRemoval=true, cascade={"all"})
  69.      */
  70.     private $order;
  71.     /**
  72.      * @ORM\ManyToOne(targetEntity="App\Entity\AdminStatus", inversedBy="userSurveys")
  73.      */
  74.     private $adminStatus;
  75.     /**
  76.      * @ORM\Column(type="string", length=30, nullable=true)
  77.      */
  78.     private $orderReference;
  79.     /**
  80.      * @ORM\Column(type="smallint", nullable=true)
  81.      */
  82.     private $step;
  83.     /**
  84.      * @ORM\Column(type="array", nullable=true)
  85.      */
  86.     private $coveredStep;
  87.     /**
  88.      * @ORM\Column(type="float", scale=2, nullable=true)
  89.      */
  90.     private $price;
  91.     /**
  92.      * @ORM\Column(type="string", length=50, nullable=true)
  93.      */
  94.     private $paymentStatus;
  95.     /**
  96.      * @ORM\Column(type="string", length=50, nullable=true)
  97.      */
  98.     private $resultCode;
  99.     /**
  100.      * @ORM\Column(type="text", nullable=true)
  101.      */
  102.     private $resultComment;
  103.     /**
  104.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  105.      */
  106.     private $resultIS;
  107.     /**
  108.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  109.      */
  110.     private $resultQR;
  111.     /**
  112.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  113.      */
  114.     private $resultRS;
  115.     /**
  116.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  117.      */
  118.     private $resultAFC;
  119.     /**
  120.      * @ORM\Column(type="text", nullable=true)
  121.      */
  122.     private $resultAFCComment;
  123.     /**
  124.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  125.      */
  126.     private $resultPresta;
  127.     /**
  128.      * @ORM\Column(type="text", nullable=true)
  129.      */
  130.     private $resultPrestaComment;
  131.     /**
  132.      * @ORM\ManyToOne(targetEntity="App\Entity\UserSurvey", inversedBy="children")
  133.      */
  134.     private $parent;
  135.     /**
  136.      * @ORM\Column(type="array", nullable=true)
  137.      */
  138.     private $missingFiles;
  139.     /**
  140.      * @ORM\OneToMany(targetEntity="App\Entity\UserSurvey", mappedBy="parent", orphanRemoval=true, cascade={"all"})
  141.      */
  142.     private $children;
  143.     /**
  144.      * @ORM\Column(type="boolean", nullable=true)
  145.      */
  146.     private $isClone;
  147.     /**
  148.      * @ORM\ManyToOne(targetEntity="App\Entity\UserFile", inversedBy="userSurveys", cascade={"persist"})
  149.      */
  150.     private $userFile;
  151.     /**
  152.      * @ORM\Column(type="boolean", nullable=true)
  153.      */
  154.     private $isEdited;
  155.     /**
  156.      * @ORM\Column(type="boolean", nullable=true)
  157.      */
  158.     private $isThirdParty;
  159.     /**
  160.      * @ORM\Column(type="boolean", nullable=true)
  161.      */
  162.     private $isArchived;
  163.     /**
  164.      * @ORM\ManyToOne(targetEntity="App\Entity\TaxRectificationRequest", inversedBy="userSurveys")
  165.      */
  166.     private $taxRectificationRequest;
  167.     /**
  168.      * @ORM\Column(type="boolean", nullable=true, options={"default":"1"})
  169.      */
  170.     private $displayDocNotif;
  171.     private $dateLimitArray;
  172.     /**
  173.      * @ORM\OneToMany(targetEntity=UserSurveyComment::class, mappedBy="userSurvey", orphanRemoval=true, cascade={"all"})
  174.      */
  175.     private $userSurveyComments;
  176.     /**
  177.      * @ORM\ManyToOne(targetEntity=UserSurveyStatus::class)
  178.      * @ORM\JoinColumn(nullable=false, columnDefinition="INT DEFAULT 1")
  179.      */
  180.     private $userSurveyStatus;
  181.     /**
  182.      * @ORM\ManyToOne(targetEntity=SurveyProduct::class, inversedBy="userSurveys")
  183.      */
  184.     private $surveyProduct;
  185.     /**
  186.      * @ORM\ManyToOne(targetEntity=SurveyStep::class, inversedBy="userSurveys")
  187.      */
  188.     private $SurveyStep;
  189.     /**
  190.      * @ORM\ManyToOne(targetEntity=SurveyMode::class, inversedBy="userSurveys")
  191.      */
  192.     private $surveyModeObject;
  193.     /**
  194.      * @ORM\OneToMany(targetEntity=UserSurveyBexioArticle::class, mappedBy="userSurvey", orphanRemoval=true)
  195.      */
  196.     private $userSurveyBexioArticles;
  197.     /**
  198.      * @ORM\ManyToOne(targetEntity=Survey::class)
  199.      */
  200.     private $resultSurvey;
  201.     /**
  202.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="createdUserSurveys")
  203.      */
  204.     private $creator;
  205.     /**
  206.      * @ORM\Column(type="date", nullable=true)
  207.      */
  208.     private ?DateTimeInterface $internalAlertDate;
  209.     /**
  210.      * @ORM\Column(type="boolean", nullable=true)
  211.      */
  212.     private $noAFCResult;
  213.     /**
  214.      * @ORM\Column(type="float", nullable=true)
  215.      */
  216.     private $cmuResultN;
  217.     /**
  218.      * @ORM\Column(type="float", nullable=true)
  219.      */
  220.     private $cmuResultN1;
  221.     /**
  222.      * @ORM\Column(type="float", nullable=true)
  223.      */
  224.     private $cmuResultN2;
  225.     /**
  226.      * @ORM\Column(type="float", nullable=true)
  227.      */
  228.     private $cmuResultN3;
  229.     /**
  230.      * @ORM\Column(type="string", length=255, nullable=true)
  231.      */
  232.     private $cmuResultType;
  233.     /**
  234.      * @ORM\OneToMany(targetEntity=Email::class, mappedBy="UserSurvey", orphanRemoval=true, cascade={"all"})
  235.      */
  236.     private $emails;
  237.     /**
  238.      * UserSurvey constructor.
  239.      */
  240.     public function __construct(User $user null)
  241.     {
  242.         $this->userSurveyQuestions = new ArrayCollection();
  243.         // $this->status = 'INIT';
  244.         $this->isArchived false;
  245.         $this->step null;
  246.         if ($user) {
  247.             $this->setUser($user);
  248.         }
  249.         $this->setDateAdd(new \DateTime());
  250.         $this->setDateUpdate(new \DateTime());
  251.         $this->setStatusDateUpdate(new \DateTime());
  252.         $this->coveredStep = [];
  253.         $this->children = new ArrayCollection();
  254.         $this->surveyMode 0;
  255.         $this->isEdited false;
  256.         $this->isThirdParty false;
  257.         $this->setDateLimit(null);
  258.         $this->userSurveyComments = new ArrayCollection();
  259.         $this->userSurveyBexioArticles = new ArrayCollection();
  260.         $this->emails = new ArrayCollection();
  261.     }
  262.     /**
  263.      * UserSurvey cloner.
  264.      */
  265.     public function __clone()
  266.     {
  267.         // $this->status = 'ONGOING';
  268.         $this->step 1;
  269.         $this->isArchived 0;
  270.         $this->setDateAdd(new \DateTime());
  271.         $this->setDateUpdate(new \DateTime());
  272.         $this->coveredStep = [];
  273.         $this->children = new ArrayCollection();
  274.         $this->setPaymentStatus(null);
  275.         $this->setResultCode(null);
  276.         $this->setResultComment(null);
  277.         $this->setResultIs(null);
  278.         $this->setResultQR(null);
  279.         $this->setResultRS(null);
  280.         $this->setResultSurvey(null);
  281.         $this->setOrderReference(null);
  282.         $this->setOrder(null);
  283.         $this->setParent(null);
  284.         $this->setDateAFC(null);
  285.         $this->setDateFinish(null);
  286.         $this->setMissingFiles([]);
  287.         $this->setResultAFC(null);
  288.         $this->setResultAFCComment(null);
  289.         $this->setResultPresta(null);
  290.         $this->setResultPrestaComment(null);
  291.         $this->setPrice(0);
  292.         $this->setDisplayDocNotif(true);
  293.         $this->setDateLimit(null);
  294.         $userSurveyQuestions $this->userSurveyQuestions;
  295.         $this->userSurveyQuestions = new ArrayCollection();
  296.         foreach ($userSurveyQuestions as $userSurveyQuestion) {
  297.             if ('FileType' == $userSurveyQuestion->getQuestion()->getType()->getType()) {
  298.                 $cloneUserSurveyQuestion = clone $userSurveyQuestion;
  299.                 $cloneUserSurveyQuestion->setDateUpdate(new DateTime());
  300.                 $cloneUserSurveyQuestion->setDateAdd(new DateTime());
  301.                 $cloneUserSurveyQuestion->setValidState(null);
  302.                 $cloneUserSurveyQuestion->setValidComment(null);
  303.                 $cloneUserSurveyQuestion->setValue($userSurveyQuestion->getValue());
  304.                 $this->addUserSurveyQuestion($cloneUserSurveyQuestion);
  305.                 $cloneUserSurveyQuestion->setUserSurvey($this);
  306.             }
  307.         }
  308.     }
  309.     /**
  310.      * @return UserSurvey
  311.      */
  312.     public function addUserSurveyQuestion(UserSurveyQuestion $userSurveyQuestion): self
  313.     {
  314.         if (!$this->userSurveyQuestions->contains($userSurveyQuestion)) {
  315.             $this->userSurveyQuestions[] = $userSurveyQuestion;
  316.             $userSurveyQuestion->setUserSurvey($this);
  317.         }
  318.         return $this;
  319.     }
  320.     public function getDateAdd(): ?DateTimeInterface
  321.     {
  322.         return $this->dateAdd;
  323.     }
  324.     /**
  325.      * @return UserSurvey
  326.      */
  327.     public function setDateAdd(DateTimeInterface $dateAdd): self
  328.     {
  329.         $this->dateAdd $dateAdd;
  330.         return $this;
  331.     }
  332.     public function getDateUpdate(): ?DateTimeInterface
  333.     {
  334.         return $this->dateUpdate;
  335.     }
  336.     /**
  337.      * @return UserSurvey
  338.      */
  339.     public function setDateUpdate(DateTimeInterface $dateUpdate): self
  340.     {
  341.         $this->dateUpdate $dateUpdate;
  342.         return $this;
  343.     }
  344.     public function getDateFinish(): ?DateTimeInterface
  345.     {
  346.         if ($this->isProcessing()) {
  347.             return null;
  348.         }
  349.         return $this->dateFinish;
  350.     }
  351.     /**
  352.      * @param DateTimeInterface
  353.      *
  354.      * @return UserSurvey
  355.      */
  356.     public function setDateFinish(?DateTimeInterface $dateFinish): self
  357.     {
  358.         $this->dateFinish $dateFinish;
  359.         return $this;
  360.     }
  361.     public function isProcessing(): ?bool
  362.     {
  363.         if (in_array($this->getStatus(), ['PROCESSING''PROCESSING_DONE''PROCESSING_PENDING''PROCESSING_FILES_PENDING''PROCESSING_FILES_RECEIVED''PROCESSING_FILES_MISSING''PROCESSING_MISSING_FILES_SENT'])) {
  364.             return true;
  365.         }
  366.         return false;
  367.     }
  368.     public function getStatus(): ?string
  369.     {
  370.         return $this->getUserSurveyStatus()->getCode();
  371.     }
  372.     public function getUserSurveyStatus(): ?UserSurveyStatus
  373.     {
  374.         return $this->userSurveyStatus;
  375.     }
  376.     public function setUserSurveyStatus(?UserSurveyStatus $userSurveyStatus): self
  377.     {
  378.         $this->userSurveyStatus $userSurveyStatus;
  379.         return $this;
  380.     }
  381.     /**
  382.      * @return Collection|UserSurveyQuestion[]
  383.      */
  384.     public function getUserSurveyQuestions(): Collection
  385.     {
  386.         return $this->userSurveyQuestions;
  387.     }
  388.     public function getStep(): ?int
  389.     {
  390.         return $this->step;
  391.     }
  392.     public function setStep(?int $step): self
  393.     {
  394.         $this->step $step;
  395.         return $this;
  396.     }
  397.     public function getCoveredStep(): ?array
  398.     {
  399.         return $this->coveredStep;
  400.     }
  401.     public function setCoveredStep(?array $coveredStep): self
  402.     {
  403.         $this->coveredStep $coveredStep;
  404.         return $this;
  405.     }
  406.     public function addCoveredStep(int $coveredStep): self
  407.     {
  408.         if (is_null($this->coveredStep)) {
  409.             $this->coveredStep = [];
  410.         }
  411.         if (!in_array($coveredStep$this->coveredStep)) {
  412.             $this->coveredStep[] = $coveredStep;
  413.         }
  414.         $this->coveredStep array_unique($this->coveredStep);
  415.         return $this;
  416.     }
  417.     public function calculatePriceNew($userSurveyService)
  418.     {
  419.         $selectedProducts = [];
  420.         // generating the products
  421.         $rates $this->getSurvey()->getRatesForSurveyMode($this->getSurveyModeObject());
  422.         foreach ($rates as $rate) {
  423.             $product $rate->getSurveyProduct();
  424.             $isValidForConditions $userSurveyService->isSurveyProductValidForUserSurvey($product$this->getUserFile());
  425.             if ($isValidForConditions) {
  426.                 $quantity $userSurveyService->getProductQuantity($product$this->getUserFile());
  427.                 if ($quantity 0) {
  428.                     $selectedProducts[] = ['rate' => $rate'quantity' => $quantity];
  429.                 }
  430.             }
  431.         }
  432.         if (empty($selectedProducts)) {
  433.             if (array_key_exists(0$rates)) {
  434.                 $selectedProducts[] = ['rate' => $rates[0], 'quantity' => 1];
  435.             } else {
  436.                 $this->setPrice(0);
  437.                 if (!is_null($this->order)) {
  438.                     $this->order->updateAmounts(0);
  439.                 }
  440.                 return [];
  441.             }
  442.         }
  443.         if ($this->getSurvey()->getCode() == "CMU") {
  444.             $rate $rates[0];
  445.             $op $this->getPrice();
  446.             if ($this->getOrder()) {
  447.                 $op $this->getOrder()->getAmountNoDiscount();
  448.             }
  449.             $rate->setPrice($op);
  450.             $selectedProducts = [['rate' => $rate'quantity' => 1]];
  451.         }
  452.         // calculating price
  453.         $price 0;
  454.         foreach ($selectedProducts as $i => $selectedProduct) {
  455.             $price += $selectedProduct['rate']->getPrice() * $selectedProduct['quantity'];
  456.         }
  457.         $this->setPrice($price);
  458.         if (!is_null($this->order)) {
  459.             $this->order->updateAmounts($price);
  460.         }
  461.         return $selectedProducts;
  462.     }
  463.     public function getSurvey(): ?Survey
  464.     {
  465.         return $this->survey;
  466.     }
  467.     /**
  468.      * @return UserSurvey
  469.      */
  470.     public function setSurvey(?Survey $survey): self
  471.     {
  472.         $this->survey $survey;
  473.         return $this;
  474.     }
  475.     public function getSurveyModeObject(): ?SurveyMode
  476.     {
  477.         return $this->surveyModeObject;
  478.     }
  479.     public function setSurveyModeObject(?SurveyMode $surveyModeObject): self
  480.     {
  481.         $this->surveyModeObject $surveyModeObject;
  482.         return $this;
  483.     }
  484.     public function getSurveyProduct(): ?SurveyProduct
  485.     {
  486.         return $this->surveyProduct;
  487.     }
  488.     public function setSurveyProduct(?SurveyProduct $surveyProduct): self
  489.     {
  490.         $this->surveyProduct $surveyProduct;
  491.         return $this;
  492.     }
  493.     public function getUserFile(): ?UserFile
  494.     {
  495.         return $this->userFile;
  496.     }
  497.     public function setUserFile(?UserFile $userFile): self
  498.     {
  499.         $this->userFile $userFile;
  500.         return $this;
  501.     }
  502.     public function getPrice(): ?float
  503.     {
  504.         return floatval($this->price);
  505.     }
  506.     public function setPrice(float $price): self
  507.     {
  508.         $this->price $price;
  509.         return $this;
  510.     }
  511.     public function hasMultipleIteration($questions)
  512.     {
  513.         $baseIteration 0;
  514.         foreach ($questions as $question) {
  515.             if ($question->getIteration() != $baseIteration) {
  516.                 return true;
  517.             }
  518.         }
  519.         return false;
  520.     }
  521.     public function getIterations($questions)
  522.     {
  523.         $iterations = [];
  524.         foreach ($questions as $question) {
  525.             if (!in_array($question->getIteration(), $iterations)) {
  526.                 $iterations[] = $question->getIteration();
  527.             }
  528.         }
  529.         return $iterations;
  530.     }
  531.     public function reinitQuestionsRegardingCurrentGroup($questionGroup)
  532.     {
  533.         foreach ($this->userSurveyQuestions as $answer) {
  534.             if ($answer->getQuestionGroup() == $questionGroup && != $answer->getValidState() && -!= $answer->getValidState()) {
  535.                 $this->removeUserSurveyQuestion($answer);
  536.             }
  537.         }
  538.     }
  539.     /**
  540.      * @return UserSurvey
  541.      */
  542.     public function removeUserSurveyQuestion(UserSurveyQuestion $userSurveyQuestion): self
  543.     {
  544.         if ($this->userSurveyQuestions->contains($userSurveyQuestion)) {
  545.             $this->userSurveyQuestions->removeElement($userSurveyQuestion);
  546.             // set the owning side to null (unless already changed)
  547.             if ($userSurveyQuestion->getUserSurvey() === $this) {
  548.                 $userSurveyQuestion->setUserSurvey(null);
  549.             }
  550.         }
  551.         return $this;
  552.     }
  553.     public function reinitQuestionsRegardingCurrentGroupAfterCloning($questionGroup)
  554.     {
  555.         foreach ($this->userSurveyQuestions as $answer) {
  556.             if ($answer->getQuestionGroup() == $questionGroup) {
  557.                 $this->removeUserSurveyQuestion($answer);
  558.             }
  559.         }
  560.     }
  561.     public function removeQuestionsRegardingGroupIteration($questionGroupId$iteration)
  562.     {
  563.         foreach ($this->userSurveyQuestions as $answer) {
  564.             if ($answer->getQuestionGroup()->getId() == $questionGroupId && $answer->getIteration() == $iteration) {
  565.                 $this->removeUserSurveyQuestion($answer);
  566.             }
  567.         }
  568.     }
  569.     public function getId(): ?int
  570.     {
  571.         return $this->id;
  572.     }
  573.     public function isCancellable(): ?bool
  574.     {
  575.         if (in_array($this->getStatus(), ['INIT''ONGOING'])) {
  576.             return true;
  577.         }
  578.         return false;
  579.     }
  580.     public function isDoneAndPaid(): ?bool
  581.     {
  582.         if (in_array($this->getStatus(), ['DONE''PROCESSING_FILES_COMPLETED''PROCESSING_FILES_POSTED''PROCESSING_FILES_POSTED_FR''PROCESSING_FILES_POSTED_CMU']) && $this->isPaid()) {
  583.             return true;
  584.         }
  585.         return false;
  586.     }
  587.     public function isPaid()
  588.     {
  589.         return 'captured' == $this->getPaymentStatus() || 'payedout' == $this->getPaymentStatus();
  590.     }
  591.     public function getPaymentStatus(): ?string
  592.     {
  593.         if (!is_null($this->order)) {
  594.             return $this->order->getPaymentStatus();
  595.         }
  596.         return $this->paymentStatus;
  597.     }
  598.     public function setPaymentStatus(?string $paymentStatus): self
  599.     {
  600.         $this->paymentStatus $paymentStatus;
  601.         if (!is_null($this->order)) {
  602.             $this->order->setPaymentStatus($paymentStatus);
  603.         }
  604.         return $this;
  605.     }
  606.     public function getSurveyStatusLabel(): string
  607.     {
  608.         return $this->getUserSurveyStatus()->getname();
  609.     }
  610.     public function getSurveyStatusColor(): string
  611.     {
  612.         return $this->getUserSurveyStatus()->getBadgeColor();
  613.     }
  614.     /**
  615.      * @return string
  616.      */
  617.     public function getSurveyStatuses()
  618.     {
  619.         // TO BE DONE DEPENDING ON EASYADMIN EXT. USAGE
  620.         $statusLabel = [
  621.             'Initialisé' => 'INIT',
  622.             'En cours' => 'ONGOING',
  623.             'Remplie' => 'PENDING',
  624.         ];
  625.         return $statusLabel;
  626.     }
  627.     public function getSurveyPaymentStatusLabel(): string
  628.     {
  629.         $statusLabel '';
  630.         switch ($this->paymentStatus) {
  631.             case 'pending':
  632.                 $statusLabel 'En attente';
  633.                 break;
  634.             case 'captured':
  635.             case 'payedout':
  636.                 $statusLabel 'Payé';
  637.                 break;
  638.             case 'canceled':
  639.                 $statusLabel 'Annulé';
  640.                 break;
  641.             default:
  642.                 $statusLabel 'En attente';
  643.         }
  644.         return $statusLabel;
  645.     }
  646.     public function getSurveyResultLabel(): string
  647.     {
  648.         $statusLabel '';
  649.         switch ($this->resultCode) {
  650.             case 'PA':
  651.                 $statusLabel 'Pas avantageux';
  652.                 break;
  653.             case 'QR':
  654.                 $statusLabel 'TOU (Quasi-résident)';
  655.                 break;
  656.             case 'RS':
  657.                 $statusLabel 'DRIS (Rectification Impôt Source)';
  658.                 break;
  659.             case 'VALID':
  660.                 $statusLabel 'Validé';
  661.                 break;
  662.             case 'INVALID':
  663.                 $statusLabel 'Invalidé';
  664.                 break;
  665.             case 'REJECTED':
  666.                 $statusLabel 'Rejeté';
  667.                 break;
  668.             case 'CANCELED':
  669.                 $statusLabel 'Annulé';
  670.                 break;
  671.             default:
  672.                 $statusLabel '-';
  673.         }
  674.         return $statusLabel;
  675.     }
  676.     public function getPostPaymentQuestions()
  677.     {
  678.         if (in_array($this->survey->getId(), [13])) {
  679.             return true;
  680.         }
  681.         return null;
  682.     }
  683.     public function getResultCode(): ?string
  684.     {
  685.         return $this->resultCode;
  686.     }
  687.     public function setResultCode(?string $resultCode): self
  688.     {
  689.         $this->resultCode $resultCode;
  690.         return $this;
  691.     }
  692.     public function getResultComment(): ?string
  693.     {
  694.         return $this->resultComment;
  695.     }
  696.     public function setResultComment(?string $resultComment): self
  697.     {
  698.         $this->resultComment $resultComment;
  699.         return $this;
  700.     }
  701.     public function hasGetaxFile($webDir): ?bool
  702.     {
  703.         $hasGetaxFile false;
  704.         if (file_exists($webDir '/uploads/files/getax/tax/' $this->getId() . '_' $this->getUser()->getLastname() . $this->getUser()->getName() . (date('Y') - 1) . '_' date('d_m_y') . '.tax')) {
  705.             $hasGetaxFile true;
  706.         }
  707.         return $hasGetaxFile;
  708.     }
  709.     public function getUser(): ?User
  710.     {
  711.         return $this->user;
  712.     }
  713.     /**
  714.      * @return UserSurvey
  715.      */
  716.     public function setUser(?User $user): self
  717.     {
  718.         $this->user $user;
  719.         return $this;
  720.     }
  721.     public function hasUploadedFiles(): ?bool
  722.     {
  723.         $files $this->getUploadedFiles();
  724.         if (count($files) > 0) {
  725.             return true;
  726.         }
  727.         return false;
  728.     }
  729.     public function getUploadedFiles(): ?array
  730.     {
  731.         $files = [];
  732.         if (!is_null($this->getUserFile())) {
  733.             foreach ($this->getUserFile()->getUserFileDocumentsSorted() as $userFileDocument) {
  734.                 $files[] = $userFileDocument->getFileName();
  735.             }
  736.         }
  737.         return $files;
  738.     }
  739.     public function isSimulation(): ?bool
  740.     {
  741.         if (== $this->survey->getId()) {
  742.             return true;
  743.         } else {
  744.             return false;
  745.         }
  746.     }
  747.     public function getMissingFiles(): ?array
  748.     {
  749.         return $this->missingFiles;
  750.     }
  751.     public function setMissingFiles(?array $missingFiles): self
  752.     {
  753.         $this->missingFiles $missingFiles;
  754.         return $this;
  755.     }
  756.     public function hasChildren(): bool
  757.     {
  758.         return count($this->children) > 0;
  759.     }
  760.     public function getDateAFC(): ?DateTimeInterface
  761.     {
  762.         return $this->dateAFC;
  763.     }
  764.     public function setDateAFC(?DateTimeInterface $dateAFC): self
  765.     {
  766.         $this->dateAFC $dateAFC;
  767.         return $this;
  768.     }
  769.     /**
  770.      * @return Collection|UserSurvey[]
  771.      */
  772.     public function getChildren(): Collection
  773.     {
  774.         return $this->children;
  775.     }
  776.     public function addChild(UserSurvey $child): self
  777.     {
  778.         if (!$this->children->contains($child)) {
  779.             $this->children[] = $child;
  780.             $child->setParent($this);
  781.         }
  782.         return $this;
  783.     }
  784.     public function removeChild(UserSurvey $child): self
  785.     {
  786.         if ($this->children->contains($child)) {
  787.             $this->children->removeElement($child);
  788.             // set the owning side to null (unless already changed)
  789.             if ($child->getParent() === $this) {
  790.                 $child->setParent(null);
  791.             }
  792.         }
  793.         return $this;
  794.     }
  795.     public function getParent()
  796.     {
  797.         return $this->parent;
  798.     }
  799.     public function setParent(?self $parent): self
  800.     {
  801.         $this->parent $parent;
  802.         return $this;
  803.     }
  804.     public function getResultAFC()
  805.     {
  806.         return $this->resultAFC;
  807.     }
  808.     public function setResultAFC(?string $resultAFC): self
  809.     {
  810.         $this->resultAFC $resultAFC;
  811.         return $this;
  812.     }
  813.     public function getOrder(): ?Order
  814.     {
  815.         return $this->order;
  816.     }
  817.     /**
  818.      * @return UserSurvey
  819.      */
  820.     public function setOrder(?Order $order): self
  821.     {
  822.         $this->order $order;
  823.         return $this;
  824.     }
  825.     public function getResultAFCComment(): ?string
  826.     {
  827.         return $this->resultAFCComment;
  828.     }
  829.     public function setResultAFCComment(?string $resultAFCComment): self
  830.     {
  831.         $this->resultAFCComment $resultAFCComment;
  832.         return $this;
  833.     }
  834.     public function getOrderReference(): ?string
  835.     {
  836.         return $this->orderReference;
  837.     }
  838.     public function setOrderReference(?string $orderReference): self
  839.     {
  840.         $this->orderReference $orderReference;
  841.         return $this;
  842.     }
  843.     public function getResultPresta()
  844.     {
  845.         return $this->resultPresta;
  846.     }
  847.     public function setResultPresta(?string $resultPresta): self
  848.     {
  849.         $this->resultPresta $resultPresta;
  850.         return $this;
  851.     }
  852.     public function getResultPrestaComment(): ?string
  853.     {
  854.         return $this->resultPrestaComment;
  855.     }
  856.     public function setResultPrestaComment(?string $resultPrestaComment): self
  857.     {
  858.         $this->resultPrestaComment $resultPrestaComment;
  859.         return $this;
  860.     }
  861.     public function getSurveyMode(): ?int
  862.     {
  863.         return $this->surveyMode;
  864.     }
  865.     public function setSurveyMode(?int $surveyMode): self
  866.     {
  867.         $this->surveyMode $surveyMode;
  868.         return $this;
  869.     }
  870.     public function hasPostSteps(): ?bool
  871.     {
  872.         $has false;
  873.         if (!= $this->survey->getId()) {
  874.             if (!is_null($this->getSurveyModeObject())) {
  875.                 if ('ONLINE' == $this->getSurveyModeCode() || 'E-DEMARCHES' == $this->getSurveyModeCode()) {
  876.                     $has true;
  877.                 }
  878.             } else {
  879.                 if (== $this->surveyModeObject->getMode()->getCode()) {
  880.                     $has true;
  881.                 }
  882.             }
  883.         }
  884.         return $has;
  885.     }
  886.     public function getSurveyModeCode(): ?string
  887.     {
  888.         if (!is_null($this->surveyModeObject)) {
  889.             return $this->surveyModeObject->getMode()->getCode();
  890.         }
  891.         return null;
  892.     }
  893.     public function getModeLabel()
  894.     {
  895.         if (is_null($this->getSurveyModeObject())) {
  896.             $text 'En ligne';
  897.             if (== $this->survey->getId() && == $this->surveyMode) {
  898.                 $text '100% papier';
  899.             } elseif (== $this->survey->getId() && == $this->surveyMode) {
  900.                 $text 'E-démarches';
  901.             } elseif (== $this->survey->getId() && == $this->surveyMode) {
  902.                 $text 'Rendez-vous';
  903.             } elseif (in_array($this->survey->getId(), [23]) && == $this->surveyMode) {
  904.                 $text 'Dépôt physique';
  905.             } elseif (in_array($this->survey->getId(), [23]) && == $this->surveyMode) {
  906.                 $text 'Envoi postal';
  907.             }
  908.             return $text;
  909.         }
  910.         return $this->getSurveyModeObject()->getMode()->__toString();
  911.     }
  912.     public function getShortModeObjectLabel()
  913.     {
  914.         $label $this->getModeLabel();
  915.         if ($this->getSurveyModeObject()) {
  916.             if ($this->getSurveyModeObject()->getId() == 14) {
  917.                 //Département 01 au 19 et non résident
  918.                 $label '01-19';
  919.             } elseif ($this->getSurveyModeObject()->getId() == 21) {
  920.                 //Départements n°55 à 974
  921.                 $label '55-974';
  922.             } elseif ($this->getSurveyModeObject()->getId() == 22) {
  923.                 //Déclaration formulaire papier
  924.                 $label 'Papier';
  925.             }
  926.         }
  927.         return $label;
  928.     }
  929.     /**
  930.      * @return string
  931.      */
  932.     public function __toString()
  933.     {
  934.         $userName = !$this->getUser() instanceof User 'undefined User' $this->getUser()->getName() . ' ' $this->getUser()->getLastname();
  935.         $surveyName = !$this->getSurvey() instanceof Survey 'undefined Survey' $this->getSurvey()->getName();
  936.         return "{$userName} {$surveyName}";
  937.     }
  938.     /**
  939.      * Used to return client answer based on question label.
  940.      *
  941.      * @param int $label
  942.      *
  943.      * @return string $answer
  944.      */
  945.     public function getAnswerByLabel($label)
  946.     {
  947.         $answer '';
  948.         foreach ($this->userSurveyQuestions as $userSurveyQuestion) {
  949.             if ($userSurveyQuestion->getQuestion()->getName() == $label) {
  950.                 $answer $userSurveyQuestion->getValue();
  951.                 return $answer;
  952.             }
  953.         }
  954.         return $answer;
  955.     }
  956.     public function getIsClone(): ?bool
  957.     {
  958.         return $this->isClone;
  959.     }
  960.     public function setIsClone(?bool $isClone): self
  961.     {
  962.         $this->isClone $isClone;
  963.         return $this;
  964.     }
  965.     public function getIsEdited(): ?bool
  966.     {
  967.         return $this->isEdited;
  968.     }
  969.     public function setIsEdited(?bool $isEdited): self
  970.     {
  971.         $this->isEdited $isEdited;
  972.         return $this;
  973.     }
  974.     public function getIsThirdParty(): ?bool
  975.     {
  976.         return $this->isThirdParty;
  977.     }
  978.     public function setIsThirdParty(?bool $isThirdParty): self
  979.     {
  980.         $this->isThirdParty $isThirdParty;
  981.         return $this;
  982.     }
  983.     public function getStatusDateUpdate(): ?DateTimeInterface
  984.     {
  985.         return $this->statusDateUpdate;
  986.     }
  987.     public function setStatusDateUpdate(DateTimeInterface $statusDateUpdate): self
  988.     {
  989.         $this->statusDateUpdate $statusDateUpdate;
  990.         return $this;
  991.     }
  992.     public function getDateLimit(): ?DateTimeInterface
  993.     {
  994.         return $this->dateLimit;
  995.     }
  996.     public function setDateLimit(?DateTimeInterface $dateLimit): self
  997.     {
  998.         $this->dateLimit $dateLimit;
  999.         return $this;
  1000.     }
  1001.     public function getHasAFCRequested(): ?bool
  1002.     {
  1003.         return $this->hasAFCRequested;
  1004.     }
  1005.     public function setHasAFCRequested(?bool $hasAFCRequested): self
  1006.     {
  1007.         $this->hasAFCRequested $hasAFCRequested;
  1008.         return $this;
  1009.     }
  1010.     public function getTaxRectificationRequest(): ?TaxRectificationRequest
  1011.     {
  1012.         return $this->taxRectificationRequest;
  1013.     }
  1014.     public function setTaxRectificationRequest(?TaxRectificationRequest $taxRectificationRequest): self
  1015.     {
  1016.         $this->taxRectificationRequest $taxRectificationRequest;
  1017.         return $this;
  1018.     }
  1019.     public function getDisplayDocNotif(): ?bool
  1020.     {
  1021.         return $this->displayDocNotif;
  1022.     }
  1023.     public function setDisplayDocNotif(?bool $displayDocNotif): self
  1024.     {
  1025.         $this->displayDocNotif $displayDocNotif;
  1026.         return $this;
  1027.     }
  1028.     public function getDateLimitArray(): ?array
  1029.     {
  1030.         return $this->dateLimitArray;
  1031.     }
  1032.     /**
  1033.      * @throws Exception
  1034.      */
  1035.     public function fillDateLimitArray($displayAdminDates false): self
  1036.     {
  1037.         $this->dateLimitArray = [
  1038.             'Sans code' => null,
  1039.             '31/03' => new DateTime(date('Y') . '-03-31'),
  1040.             '30/04' => new DateTime(date('Y') . '-04-30'),
  1041.             '31/05' => new DateTime(date('Y') . '-05-31'),
  1042.             '30/06' => new DateTime(date('Y') . '-06-30'),
  1043.             '31/07' => new DateTime(date('Y') . '-07-31'),
  1044.             '31/08' => new DateTime(date('Y') . '-08-31'),
  1045.         ];
  1046.         if (!$displayAdminDates) {
  1047.             $this->dateLimitArray array_merge($this->dateLimitArray, ['Après août' => 'SUPERIOR_AUGUST']);
  1048.             array_unshift($this->dateLimitArray'CODE_DECLA');
  1049.             $keys array_keys($this->dateLimitArray);
  1050.             $keys[array_search(0$keys)] = 'Code ' date('Y') . ' ajouté';
  1051.             $this->dateLimitArray array_combine($keys$this->dateLimitArray);
  1052.         } else {
  1053.             $this->dateLimitArray array_merge($this->dateLimitArray, [
  1054.                 '30/09' => new DateTime(date('Y') . '-09-30'),
  1055.                 '31/10' => new DateTime(date('Y') . '-10-31'),
  1056.                 '30/11' => new DateTime(date('Y') . '-11-30'),
  1057.                 '31/12' => new DateTime(date('Y') . '-12-31'),
  1058.             ]);
  1059.         }
  1060.         return $this;
  1061.     }
  1062.     public function getTotalCapturedInformationsPercentString()
  1063.     {
  1064.         return $this->getTotalCapturedInformationsPercent() . '%';
  1065.     }
  1066.     public function getTotalCapturedInformationsPercent()
  1067.     {
  1068.         $percent 0;
  1069.         if (!is_null($this->getUserFile())) {
  1070.             $percent $this->getUserFile()->getTotalCapturedInformationsPercent();
  1071.         }
  1072.         return $percent;
  1073.     }
  1074.     /**
  1075.      * @return Collection<int, UserSurveyComment>
  1076.      */
  1077.     public function getUserSurveyComments(): Collection
  1078.     {
  1079.         return $this->userSurveyComments;
  1080.     }
  1081.     public function addUserSurveyComment(UserSurveyComment $userSurveyComment): self
  1082.     {
  1083.         if (!$this->userSurveyComments->contains($userSurveyComment)) {
  1084.             $this->userSurveyComments[] = $userSurveyComment;
  1085.             $userSurveyComment->setUserSurvey($this);
  1086.         }
  1087.         return $this;
  1088.     }
  1089.     public function removeUserSurveyComment(UserSurveyComment $userSurveyComment): self
  1090.     {
  1091.         if ($this->userSurveyComments->removeElement($userSurveyComment)) {
  1092.             // set the owning side to null (unless already changed)
  1093.             if ($userSurveyComment->getUserSurvey() === $this) {
  1094.                 $userSurveyComment->setUserSurvey(null);
  1095.             }
  1096.         }
  1097.         return $this;
  1098.     }
  1099.     public function countNotArchivedComments()
  1100.     {
  1101.         return $this->getNotArchivedComments()->count();
  1102.     }
  1103.     /**
  1104.      * @return Collection<int, UserSurveyComment>
  1105.      */
  1106.     public function getNotArchivedComments(): Collection
  1107.     {
  1108.         $notArchivedComments = [];
  1109.         foreach ($this->userSurveyComments as $comment) {
  1110.             if (true !== $comment->getIsArchived() && is_null($comment->getReplyTo())) {
  1111.                 $notArchivedComments[] = $comment;
  1112.             }
  1113.         }
  1114.         return new ArrayCollection($notArchivedComments);
  1115.     }
  1116.     public function getIsArchived(): ?bool
  1117.     {
  1118.         return $this->isArchived;
  1119.     }
  1120.     public function setIsArchived(?bool $isArchived): self
  1121.     {
  1122.         $this->isArchived $isArchived;
  1123.         return $this;
  1124.     }
  1125.     public function countNotArchivedCommentsAndReplies()
  1126.     {
  1127.         return (string)$this->getNotArchivedCommentsAndReplies()->count();
  1128.     }
  1129.     /**
  1130.      * @return Collection<int, UserSurveyComment>
  1131.      */
  1132.     public function getNotArchivedCommentsAndReplies(): Collection
  1133.     {
  1134.         $notArchivedComments = [];
  1135.         foreach ($this->userSurveyComments as $comment) {
  1136.             if (true !== $comment->getIsArchived()) {
  1137.                 $notArchivedComments[] = $comment;
  1138.             }
  1139.         }
  1140.         return new ArrayCollection($notArchivedComments);
  1141.     }
  1142.     public function getSurveyStep(): ?SurveyStep
  1143.     {
  1144.         return $this->SurveyStep;
  1145.     }
  1146.     public function setSurveyStep(?SurveyStep $SurveyStep): self
  1147.     {
  1148.         $this->SurveyStep $SurveyStep;
  1149.         return $this;
  1150.     }
  1151.     /**
  1152.      * @return Collection<int, UserSurveyBexioArticle>
  1153.      */
  1154.     public function getUserSurveyBexioArticles(): Collection
  1155.     {
  1156.         return $this->userSurveyBexioArticles;
  1157.     }
  1158.     public function addUserSurveyBexioArticle(UserSurveyBexioArticle $userSurveyBexioArticle): self
  1159.     {
  1160.         if (!$this->userSurveyBexioArticles->contains($userSurveyBexioArticle)) {
  1161.             $this->userSurveyBexioArticles[] = $userSurveyBexioArticle;
  1162.             $userSurveyBexioArticle->setUserSurvey($this);
  1163.         }
  1164.         return $this;
  1165.     }
  1166.     public function removeUserSurveyBexioArticle(UserSurveyBexioArticle $userSurveyBexioArticle): self
  1167.     {
  1168.         if ($this->userSurveyBexioArticles->removeElement($userSurveyBexioArticle)) {
  1169.             // set the owning side to null (unless already changed)
  1170.             if ($userSurveyBexioArticle->getUserSurvey() === $this) {
  1171.                 $userSurveyBexioArticle->setUserSurvey(null);
  1172.             }
  1173.         }
  1174.         return $this;
  1175.     }
  1176.     public function getResultSurvey(): ?Survey
  1177.     {
  1178.         return $this->resultSurvey;
  1179.     }
  1180.     public function setResultSurvey(?Survey $resultSurvey): self
  1181.     {
  1182.         $this->resultSurvey $resultSurvey;
  1183.         return $this;
  1184.     }
  1185.     public function getCreator(): ?User
  1186.     {
  1187.         return $this->creator;
  1188.     }
  1189.     public function setCreator(?User $creator): self
  1190.     {
  1191.         $this->creator $creator;
  1192.         return $this;
  1193.     }
  1194.     public function conditionalSurveyName()
  1195.     {
  1196.         $baseName $this->getSurvey()->getName();
  1197.         if ('QUASI_RESID' == $this->getSurvey()->getCode()) {
  1198.             if ($this->getUserFile()) {
  1199.                 if ('Suisse' == $this->getUserFile()->getResidence()) {
  1200.                     $baseName 'Déclaration suisse';
  1201.                 }
  1202.             }
  1203.         }
  1204.         return $baseName;
  1205.     }
  1206.     public function getInternalAlertDate(): ?DateTimeInterface
  1207.     {
  1208.         return $this->internalAlertDate;
  1209.     }
  1210.     public function setInternalAlertDate(?DateTimeInterface $internalAlertDate): self
  1211.     {
  1212.         $this->internalAlertDate $internalAlertDate;
  1213.         return $this;
  1214.     }
  1215.     public function badgeColorInternalAlertDate(): string
  1216.     {
  1217.         $d strtotime('today midnight');
  1218.         if (!is_null($this->internalAlertDate)) {
  1219.             if ($d $this->internalAlertDate->getTimestamp()) {
  1220.                 return 'badge-danger';
  1221.             }
  1222.             return 'badge-warning';
  1223.         }
  1224.         return '';
  1225.     }
  1226.     public function bgColorInternalAlertDate(): string
  1227.     {
  1228.         $d strtotime('today midnight');
  1229.         if (!is_null($this->internalAlertDate)) {
  1230.             if ($d $this->internalAlertDate->getTimestamp()) {
  1231.                 return 'text-bg-danger bg-opacity-25';
  1232.             }
  1233.             return 'text-bg-warning bg-opacity-25';
  1234.         }
  1235.         return '';
  1236.     }
  1237.     public function badgeColorDateLimit(): string
  1238.     {
  1239.         if (!is_null($this->dateAFC)) {
  1240.             return 'badge-secondary';
  1241.         }
  1242.         $d strtotime('today midnight');
  1243.         if ($d $this->dateLimit->getTimestamp()) {
  1244.             return 'badge-danger';
  1245.         }
  1246.         return 'badge-info';
  1247.     }
  1248.     public function getSurveyPaymentStatusBadgeColor()
  1249.     {
  1250.         if ($this->isPaid()) {
  1251.             return 'badge-success';
  1252.         }
  1253.         return 'badge-warning';
  1254.     }
  1255.     public function isNoAFCResult(): ?bool
  1256.     {
  1257.         return $this->noAFCResult;
  1258.     }
  1259.     public function setNoAFCResult(?bool $noAFCResult): self
  1260.     {
  1261.         $this->noAFCResult $noAFCResult;
  1262.         return $this;
  1263.     }
  1264.     public function getSurveyAdminStatus($adminStatusList)
  1265.     {
  1266.         $list = [];
  1267.         foreach ($adminStatusList as $i => $adminStatus) {
  1268.             $list[$adminStatus->getId()] = ['label' => $adminStatus->getTitle(), 'color' => $adminStatus->getColor()];
  1269.             foreach ($this->getSurvey()->getSurveyAdminStatuses() as $surveyAdminStatus) {
  1270.                 if ($surveyAdminStatus->getAdminStatus() == $adminStatus &&
  1271.                     $surveyAdminStatus->getUserSurveyStatus() == $this->getUserSurveyStatus()) {
  1272.                     $list[$adminStatus->getId()]['label'] = $surveyAdminStatus->getLabel();
  1273.                 }
  1274.             }
  1275.         }
  1276.         return $list;
  1277.     }
  1278.     public function getAdminStatus(): ?AdminStatus
  1279.     {
  1280.         return $this->adminStatus;
  1281.     }
  1282.     public function setAdminStatus($adminStatus): self
  1283.     {
  1284.         $this->adminStatus $adminStatus;
  1285.         return $this;
  1286.     }
  1287.     public function getCommentByTypes(array $types): ArrayCollection
  1288.     {
  1289.         $comments = [];
  1290.         foreach ($this->getNotArchivedComments() as $comment) {
  1291.             if (in_array($comment->getType(), $types)) {
  1292.                 $comments[] = $comment;
  1293.             }
  1294.         }
  1295.         return new ArrayCollection($comments);
  1296.     }
  1297.     public function calculQR()
  1298.     {
  1299.         return floatval($this->getResultIS()) - floatval($this->getResultQR());
  1300.     }
  1301.     public function getResultIS()
  1302.     {
  1303.         return $this->resultIS;
  1304.     }
  1305.     public function setResultIS(?string $resultIS): self
  1306.     {
  1307.         $this->resultIS $resultIS;
  1308.         return $this;
  1309.     }
  1310.     public function getResultQR()
  1311.     {
  1312.         return $this->resultQR;
  1313.     }
  1314.     public function setResultQR(?string $resultQR): self
  1315.     {
  1316.         $this->resultQR $resultQR;
  1317.         return $this;
  1318.     }
  1319.     public function calculRS()
  1320.     {
  1321.         return floatval($this->getResultIS()) - floatval($this->getResultRS());
  1322.     }
  1323.     public function getResultRS()
  1324.     {
  1325.         return $this->resultRS;
  1326.     }
  1327.     public function setResultRS(?string $resultRS): self
  1328.     {
  1329.         $this->resultRS $resultRS;
  1330.         return $this;
  1331.     }
  1332.     public function allowUserEdit(): bool
  1333.     {
  1334.         if ('CMU' == $this->getSurvey()->getCode()) {
  1335.             if (in_array($this->getStatus(), [
  1336.                 'OFFER_PENDING',
  1337.                 'OFFER_ACCEPTED',
  1338.                 'OFFER_DENIED',
  1339.                 'PROCESSING_PENDING',
  1340.                 'PROCESSING_FILES_RECEIVED',
  1341.                 'PROCESSING_MISSING_FILES_SENT',
  1342.                 'DONE',
  1343.                 'CANCELED',
  1344.             ])) {
  1345.                 return false;
  1346.             }
  1347.             return true;
  1348.         }
  1349.         if ('DECLARATION_DE_REVENUS_CNTFS' == $this->getSurvey()->getCode()) {
  1350.             if (in_array($this->getStatus(), [
  1351.                 'PROCESSING_PENDING',
  1352.                 'PROCESSING_FILES_RECEIVED',
  1353.                 'PROCESSING_MISSING_FILES_SENT',
  1354.                 'PROCESSING_FILES_POSTED_CMU',
  1355.                 'DONE',
  1356.                 'CANCELED',
  1357.             ])) {
  1358.                 return false;
  1359.             }
  1360.             return true;
  1361.         }
  1362.         if ($this->isPaid()) {
  1363.             return false;
  1364.         }
  1365.         if (in_array($this->getStatus(), [
  1366.             'DONE_PAYMENT_PENDING',
  1367.             'PROCESSING_FILES_POSTED_FR',
  1368.             'PROCESSING_FILES_POSTED_CMU',
  1369.             'CANCELED',
  1370.             'DONE',
  1371.             'PROCESSING_FILES_POSTED',
  1372.             'PROCESSING_FILES_COMPLETED',
  1373.             'PROCESSING_FILES_MISSING',
  1374.             'PROCESSING_MISSING_FILES_SENT',
  1375.             'PROCESSING_FILES_RECEIVED',
  1376.             'PROCESSING_FILES_PENDING',
  1377.             'PROCESSING_DONE',
  1378.             'PROCESSING',
  1379.         ])) {
  1380.             return false;
  1381.         }
  1382.         return true;
  1383.     }
  1384.     public function allowUserDeleteFiles()
  1385.     {
  1386.         if (in_array($this->getStatus(), [
  1387.             'PROCESSING',
  1388.             'PROCESSING_DONE',
  1389.             'PROCESSING_FILES_COMPLETED',
  1390.             'PROCESSING_FILES_POSTED',
  1391.             'DONE',
  1392.             'CANCELED',
  1393.             'PROCESSING_FILES_POSTED_FR',
  1394.             'DONE_PAYMENT_PENDING',
  1395.         ])) {
  1396.             return false;
  1397.         }
  1398.         return true;
  1399.     }
  1400.     public function getBexioStatusLabel(): string
  1401.     {
  1402.         if (!$this->order) {
  1403.             return 'Non relié';
  1404.         }
  1405.         if (is_null($this->order->getBexioInvoiceId())) {
  1406.             return 'Non relié';
  1407.         }
  1408.         if (true === $this->order->isBexioIsPaid()) {
  1409.             return 'Payé';
  1410.         } else {
  1411.             return 'Relié';
  1412.         }
  1413.     }
  1414.     public function getBexioStatusBadgeColor()
  1415.     {
  1416.         if (!$this->order) {
  1417.             return 'badge-danger';
  1418.         }
  1419.         if (is_null($this->order->getBexioInvoiceId())) {
  1420.             return 'badge-danger';
  1421.         }
  1422.         if (true === $this->order->isBexioIsPaid()) {
  1423.             return 'badge-success';
  1424.         } else {
  1425.             return 'badge-warning';
  1426.         }
  1427.     }
  1428.     public function getDpt()
  1429.     {
  1430.         $userFile $this->getUserFile();
  1431.         if ($userFile) {
  1432.             $owner $userFile->getOwner();
  1433.             if ($owner && !is_null($owner->getZipcode())) {
  1434.                 return substr($owner->getZipcode(), 02);
  1435.             }
  1436.         }
  1437.         return '';
  1438.     }
  1439.     public function getCmuResultN(): ?float
  1440.     {
  1441.         return $this->cmuResultN;
  1442.     }
  1443.     public function setCmuResultN(?float $cmuResultN): self
  1444.     {
  1445.         $this->cmuResultN $cmuResultN;
  1446.         return $this;
  1447.     }
  1448.     public function getCmuResultN1(): ?float
  1449.     {
  1450.         return $this->cmuResultN1;
  1451.     }
  1452.     public function setCmuResultN1(?float $cmuResultN1): self
  1453.     {
  1454.         $this->cmuResultN1 $cmuResultN1;
  1455.         return $this;
  1456.     }
  1457.     public function getCmuResultN2(): ?float
  1458.     {
  1459.         return $this->cmuResultN2;
  1460.     }
  1461.     public function setCmuResultN2(?float $cmuResultN2): self
  1462.     {
  1463.         $this->cmuResultN2 $cmuResultN2;
  1464.         return $this;
  1465.     }
  1466.     public function getCmuResultN3(): ?float
  1467.     {
  1468.         return $this->cmuResultN3;
  1469.     }
  1470.     public function setCmuResultN3(?float $cmuResultN3): self
  1471.     {
  1472.         $this->cmuResultN3 $cmuResultN3;
  1473.         return $this;
  1474.     }
  1475.     public function calculCmu()
  1476.     {
  1477.         return ($this->cmuResultN ?? 0) + ($this->cmuResultN1 ?? 0) + ($this->cmuResultN2 ?? 0) + ($this->cmuResultN3 ?? 0);
  1478.     }
  1479.     public function getCmuResultType(): ?string
  1480.     {
  1481.         return $this->cmuResultType;
  1482.     }
  1483.     public function setCmuResultType(?string $cmuResultType): self
  1484.     {
  1485.         $this->cmuResultType $cmuResultType;
  1486.         return $this;
  1487.     }
  1488.     /**
  1489.      * @return Collection<int, Email>
  1490.      */
  1491.     public function getEmails(): Collection
  1492.     {
  1493.         return $this->emails;
  1494.     }
  1495.     public function addEmail(Email $email): self
  1496.     {
  1497.         if (!$this->emails->contains($email)) {
  1498.             $this->emails[] = $email;
  1499.             $email->setUserSurvey($this);
  1500.         }
  1501.         return $this;
  1502.     }
  1503.     public function removeEmail(Email $email): self
  1504.     {
  1505.         if ($this->emails->removeElement($email)) {
  1506.             // set the owning side to null (unless already changed)
  1507.             if ($email->getUserSurvey() === $this) {
  1508.                 $email->setUserSurvey(null);
  1509.             }
  1510.         }
  1511.         return $this;
  1512.     }
  1513.     public function hasCommentType(string $type): bool
  1514.     {
  1515.         foreach ($this->getUserSurveyComments() as $surveyComment) {
  1516.             if ($surveyComment->getType() == $type) {
  1517.                 return true;
  1518.             }
  1519.         }
  1520.         return false;
  1521.     }
  1522.     public function hasDocToUpload()
  1523.     {
  1524.         $userFile $this->getUserFile();
  1525.         $survey $this->getSurvey();
  1526.         if ('DECLA_IMP_FR' == $survey->getCode()) {
  1527.             if (!is_null($userFile->getOwner())) {
  1528.                 foreach ($userFile->getOwner()->getRevenues() as $revenue) {
  1529.                     if (!is_null($revenue->getAnswer('canton'))) {
  1530.                         if ('genève' != strtolower($revenue->getAnswer('canton')) && 'CH' == $revenue->getCountry()) {
  1531.                             return true;
  1532.                         }
  1533.                     }
  1534.                 }
  1535.             }
  1536.             if (!is_null($userFile->getPrincipalPartner())) {
  1537.                 foreach ($userFile->getPrincipalPartner()->getRevenues() as $revenue) {
  1538.                     if (!is_null($revenue->getAnswer('canton'))) {
  1539.                         if ('genève' != strtolower($revenue->getAnswer('canton')) && 'CH' == $revenue->getCountry()) {
  1540.                             return true;
  1541.                         }
  1542.                     }
  1543.                 }
  1544.             }
  1545.         }
  1546.         if ('RECT_STD' == $survey->getCode() || 'QUASI_RESID' == $survey->getCode()) {
  1547.             if ($this->getStatus() == "PROCESSING_FILES_MISSING") {
  1548.                 if ($userFile->hasAskedDocumentByCode('LETTRE_PROCA') or $userFile->hasAskedDocumentByCode('TABL_TRAV') or $userFile->hasAskedDocumentByCode('FRAIS_MEDIC')) {
  1549.                     return true;
  1550.                 }
  1551.             } else {
  1552.                 if (!$userFile->hasValidatedDocumentsByCode('LETTRE_PROCA') or $userFile->hasAskedDocumentByCode('TABL_TRAV') or $userFile->hasAskedDocumentByCode('FRAIS_MEDIC')) {
  1553.                     return true;
  1554.                 }
  1555.             }
  1556.         }
  1557.         return false;
  1558.     }
  1559.     public function hasResult()
  1560.     {
  1561.         return $this->resultAFC != null || $this->cmuResultType != null;
  1562.     }
  1563. }