<?php
declare(strict_types=1);
namespace App\Entity;
use DateTime;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Exception;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserSurveyRepository")
*/
class UserSurvey
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="userSurveys")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Survey", inversedBy="userSurveys")
* @ORM\JoinColumn(nullable=false)
*/
private $survey;
/**
* @ORM\Column(type="smallint", nullable=true)
*/
private $surveyMode;
/**
* @ORM\Column(type="datetime", nullable=false)
*/
private $dateAdd;
/**
* @ORM\Column(type="datetime", nullable=false)
*/
private $dateUpdate;
/**
* @ORM\Column(type="datetime", nullable=false)
*/
private $statusDateUpdate;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $dateFinish;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $dateAFC;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $dateLimit;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $hasAFCRequested;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserSurveyQuestion", mappedBy="userSurvey", orphanRemoval=true, cascade={"all"})
*/
private $userSurveyQuestions;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Order", mappedBy="userSurvey", orphanRemoval=true, cascade={"all"})
*/
private $order;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\AdminStatus", inversedBy="userSurveys")
*/
private $adminStatus;
/**
* @ORM\Column(type="string", length=30, nullable=true)
*/
private $orderReference;
/**
* @ORM\Column(type="smallint", nullable=true)
*/
private $step;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $coveredStep;
/**
* @ORM\Column(type="float", scale=2, nullable=true)
*/
private $price;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $paymentStatus;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $resultCode;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $resultComment;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $resultIS;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $resultQR;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $resultRS;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $resultAFC;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $resultAFCComment;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $resultPresta;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $resultPrestaComment;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\UserSurvey", inversedBy="children")
*/
private $parent;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $missingFiles;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserSurvey", mappedBy="parent", orphanRemoval=true, cascade={"all"})
*/
private $children;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isClone;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\UserFile", inversedBy="userSurveys", cascade={"persist"})
*/
private $userFile;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isEdited;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isThirdParty;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isArchived;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\TaxRectificationRequest", inversedBy="userSurveys")
*/
private $taxRectificationRequest;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default":"1"})
*/
private $displayDocNotif;
private $dateLimitArray;
/**
* @ORM\OneToMany(targetEntity=UserSurveyComment::class, mappedBy="userSurvey", orphanRemoval=true, cascade={"all"})
*/
private $userSurveyComments;
/**
* @ORM\ManyToOne(targetEntity=UserSurveyStatus::class)
* @ORM\JoinColumn(nullable=false, columnDefinition="INT DEFAULT 1")
*/
private $userSurveyStatus;
/**
* @ORM\ManyToOne(targetEntity=SurveyProduct::class, inversedBy="userSurveys")
*/
private $surveyProduct;
/**
* @ORM\ManyToOne(targetEntity=SurveyStep::class, inversedBy="userSurveys")
*/
private $SurveyStep;
/**
* @ORM\ManyToOne(targetEntity=SurveyMode::class, inversedBy="userSurveys")
*/
private $surveyModeObject;
/**
* @ORM\OneToMany(targetEntity=UserSurveyBexioArticle::class, mappedBy="userSurvey", orphanRemoval=true)
*/
private $userSurveyBexioArticles;
/**
* @ORM\ManyToOne(targetEntity=Survey::class)
*/
private $resultSurvey;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="createdUserSurveys")
*/
private $creator;
/**
* @ORM\Column(type="date", nullable=true)
*/
private ?DateTimeInterface $internalAlertDate;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $noAFCResult;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $cmuResultN;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $cmuResultN1;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $cmuResultN2;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $cmuResultN3;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $cmuResultType;
/**
* @ORM\OneToMany(targetEntity=Email::class, mappedBy="UserSurvey", orphanRemoval=true, cascade={"all"})
*/
private $emails;
/**
* UserSurvey constructor.
*/
public function __construct(User $user = null)
{
$this->userSurveyQuestions = new ArrayCollection();
// $this->status = 'INIT';
$this->isArchived = false;
$this->step = null;
if ($user) {
$this->setUser($user);
}
$this->setDateAdd(new \DateTime());
$this->setDateUpdate(new \DateTime());
$this->setStatusDateUpdate(new \DateTime());
$this->coveredStep = [];
$this->children = new ArrayCollection();
$this->surveyMode = 0;
$this->isEdited = false;
$this->isThirdParty = false;
$this->setDateLimit(null);
$this->userSurveyComments = new ArrayCollection();
$this->userSurveyBexioArticles = new ArrayCollection();
$this->emails = new ArrayCollection();
}
/**
* UserSurvey cloner.
*/
public function __clone()
{
// $this->status = 'ONGOING';
$this->step = 1;
$this->isArchived = 0;
$this->setDateAdd(new \DateTime());
$this->setDateUpdate(new \DateTime());
$this->coveredStep = [];
$this->children = new ArrayCollection();
$this->setPaymentStatus(null);
$this->setResultCode(null);
$this->setResultComment(null);
$this->setResultIs(null);
$this->setResultQR(null);
$this->setResultRS(null);
$this->setResultSurvey(null);
$this->setOrderReference(null);
$this->setOrder(null);
$this->setParent(null);
$this->setDateAFC(null);
$this->setDateFinish(null);
$this->setMissingFiles([]);
$this->setResultAFC(null);
$this->setResultAFCComment(null);
$this->setResultPresta(null);
$this->setResultPrestaComment(null);
$this->setPrice(0);
$this->setDisplayDocNotif(true);
$this->setDateLimit(null);
$userSurveyQuestions = $this->userSurveyQuestions;
$this->userSurveyQuestions = new ArrayCollection();
foreach ($userSurveyQuestions as $userSurveyQuestion) {
if ('FileType' == $userSurveyQuestion->getQuestion()->getType()->getType()) {
$cloneUserSurveyQuestion = clone $userSurveyQuestion;
$cloneUserSurveyQuestion->setDateUpdate(new DateTime());
$cloneUserSurveyQuestion->setDateAdd(new DateTime());
$cloneUserSurveyQuestion->setValidState(null);
$cloneUserSurveyQuestion->setValidComment(null);
$cloneUserSurveyQuestion->setValue($userSurveyQuestion->getValue());
$this->addUserSurveyQuestion($cloneUserSurveyQuestion);
$cloneUserSurveyQuestion->setUserSurvey($this);
}
}
}
/**
* @return UserSurvey
*/
public function addUserSurveyQuestion(UserSurveyQuestion $userSurveyQuestion): self
{
if (!$this->userSurveyQuestions->contains($userSurveyQuestion)) {
$this->userSurveyQuestions[] = $userSurveyQuestion;
$userSurveyQuestion->setUserSurvey($this);
}
return $this;
}
public function getDateAdd(): ?DateTimeInterface
{
return $this->dateAdd;
}
/**
* @return UserSurvey
*/
public function setDateAdd(DateTimeInterface $dateAdd): self
{
$this->dateAdd = $dateAdd;
return $this;
}
public function getDateUpdate(): ?DateTimeInterface
{
return $this->dateUpdate;
}
/**
* @return UserSurvey
*/
public function setDateUpdate(DateTimeInterface $dateUpdate): self
{
$this->dateUpdate = $dateUpdate;
return $this;
}
public function getDateFinish(): ?DateTimeInterface
{
if ($this->isProcessing()) {
return null;
}
return $this->dateFinish;
}
/**
* @param DateTimeInterface
*
* @return UserSurvey
*/
public function setDateFinish(?DateTimeInterface $dateFinish): self
{
$this->dateFinish = $dateFinish;
return $this;
}
public function isProcessing(): ?bool
{
if (in_array($this->getStatus(), ['PROCESSING', 'PROCESSING_DONE', 'PROCESSING_PENDING', 'PROCESSING_FILES_PENDING', 'PROCESSING_FILES_RECEIVED', 'PROCESSING_FILES_MISSING', 'PROCESSING_MISSING_FILES_SENT'])) {
return true;
}
return false;
}
public function getStatus(): ?string
{
return $this->getUserSurveyStatus()->getCode();
}
public function getUserSurveyStatus(): ?UserSurveyStatus
{
return $this->userSurveyStatus;
}
public function setUserSurveyStatus(?UserSurveyStatus $userSurveyStatus): self
{
$this->userSurveyStatus = $userSurveyStatus;
return $this;
}
/**
* @return Collection|UserSurveyQuestion[]
*/
public function getUserSurveyQuestions(): Collection
{
return $this->userSurveyQuestions;
}
public function getStep(): ?int
{
return $this->step;
}
public function setStep(?int $step): self
{
$this->step = $step;
return $this;
}
public function getCoveredStep(): ?array
{
return $this->coveredStep;
}
public function setCoveredStep(?array $coveredStep): self
{
$this->coveredStep = $coveredStep;
return $this;
}
public function addCoveredStep(int $coveredStep): self
{
if (is_null($this->coveredStep)) {
$this->coveredStep = [];
}
if (!in_array($coveredStep, $this->coveredStep)) {
$this->coveredStep[] = $coveredStep;
}
$this->coveredStep = array_unique($this->coveredStep);
return $this;
}
public function calculatePriceNew($userSurveyService)
{
$selectedProducts = [];
// generating the products
$rates = $this->getSurvey()->getRatesForSurveyMode($this->getSurveyModeObject());
foreach ($rates as $rate) {
$product = $rate->getSurveyProduct();
$isValidForConditions = $userSurveyService->isSurveyProductValidForUserSurvey($product, $this->getUserFile());
if ($isValidForConditions) {
$quantity = $userSurveyService->getProductQuantity($product, $this->getUserFile());
if ($quantity > 0) {
$selectedProducts[] = ['rate' => $rate, 'quantity' => $quantity];
}
}
}
if (empty($selectedProducts)) {
if (array_key_exists(0, $rates)) {
$selectedProducts[] = ['rate' => $rates[0], 'quantity' => 1];
} else {
$this->setPrice(0);
if (!is_null($this->order)) {
$this->order->updateAmounts(0);
}
return [];
}
}
if ($this->getSurvey()->getCode() == "CMU") {
$rate = $rates[0];
$op = $this->getPrice();
if ($this->getOrder()) {
$op = $this->getOrder()->getAmountNoDiscount();
}
$rate->setPrice($op);
$selectedProducts = [['rate' => $rate, 'quantity' => 1]];
}
// calculating price
$price = 0;
foreach ($selectedProducts as $i => $selectedProduct) {
$price += $selectedProduct['rate']->getPrice() * $selectedProduct['quantity'];
}
$this->setPrice($price);
if (!is_null($this->order)) {
$this->order->updateAmounts($price);
}
return $selectedProducts;
}
public function getSurvey(): ?Survey
{
return $this->survey;
}
/**
* @return UserSurvey
*/
public function setSurvey(?Survey $survey): self
{
$this->survey = $survey;
return $this;
}
public function getSurveyModeObject(): ?SurveyMode
{
return $this->surveyModeObject;
}
public function setSurveyModeObject(?SurveyMode $surveyModeObject): self
{
$this->surveyModeObject = $surveyModeObject;
return $this;
}
public function getSurveyProduct(): ?SurveyProduct
{
return $this->surveyProduct;
}
public function setSurveyProduct(?SurveyProduct $surveyProduct): self
{
$this->surveyProduct = $surveyProduct;
return $this;
}
public function getUserFile(): ?UserFile
{
return $this->userFile;
}
public function setUserFile(?UserFile $userFile): self
{
$this->userFile = $userFile;
return $this;
}
public function getPrice(): ?float
{
return floatval($this->price);
}
public function setPrice(float $price): self
{
$this->price = $price;
return $this;
}
public function hasMultipleIteration($questions)
{
$baseIteration = 0;
foreach ($questions as $question) {
if ($question->getIteration() != $baseIteration) {
return true;
}
}
return false;
}
public function getIterations($questions)
{
$iterations = [];
foreach ($questions as $question) {
if (!in_array($question->getIteration(), $iterations)) {
$iterations[] = $question->getIteration();
}
}
return $iterations;
}
public function reinitQuestionsRegardingCurrentGroup($questionGroup)
{
foreach ($this->userSurveyQuestions as $answer) {
if ($answer->getQuestionGroup() == $questionGroup && 1 != $answer->getValidState() && -1 != $answer->getValidState()) {
$this->removeUserSurveyQuestion($answer);
}
}
}
/**
* @return UserSurvey
*/
public function removeUserSurveyQuestion(UserSurveyQuestion $userSurveyQuestion): self
{
if ($this->userSurveyQuestions->contains($userSurveyQuestion)) {
$this->userSurveyQuestions->removeElement($userSurveyQuestion);
// set the owning side to null (unless already changed)
if ($userSurveyQuestion->getUserSurvey() === $this) {
$userSurveyQuestion->setUserSurvey(null);
}
}
return $this;
}
public function reinitQuestionsRegardingCurrentGroupAfterCloning($questionGroup)
{
foreach ($this->userSurveyQuestions as $answer) {
if ($answer->getQuestionGroup() == $questionGroup) {
$this->removeUserSurveyQuestion($answer);
}
}
}
public function removeQuestionsRegardingGroupIteration($questionGroupId, $iteration)
{
foreach ($this->userSurveyQuestions as $answer) {
if ($answer->getQuestionGroup()->getId() == $questionGroupId && $answer->getIteration() == $iteration) {
$this->removeUserSurveyQuestion($answer);
}
}
}
public function getId(): ?int
{
return $this->id;
}
public function isCancellable(): ?bool
{
if (in_array($this->getStatus(), ['INIT', 'ONGOING'])) {
return true;
}
return false;
}
public function isDoneAndPaid(): ?bool
{
if (in_array($this->getStatus(), ['DONE', 'PROCESSING_FILES_COMPLETED', 'PROCESSING_FILES_POSTED', 'PROCESSING_FILES_POSTED_FR', 'PROCESSING_FILES_POSTED_CMU']) && $this->isPaid()) {
return true;
}
return false;
}
public function isPaid()
{
return 'captured' == $this->getPaymentStatus() || 'payedout' == $this->getPaymentStatus();
}
public function getPaymentStatus(): ?string
{
if (!is_null($this->order)) {
return $this->order->getPaymentStatus();
}
return $this->paymentStatus;
}
public function setPaymentStatus(?string $paymentStatus): self
{
$this->paymentStatus = $paymentStatus;
if (!is_null($this->order)) {
$this->order->setPaymentStatus($paymentStatus);
}
return $this;
}
public function getSurveyStatusLabel(): string
{
return $this->getUserSurveyStatus()->getname();
}
public function getSurveyStatusColor(): string
{
return $this->getUserSurveyStatus()->getBadgeColor();
}
/**
* @return string
*/
public function getSurveyStatuses()
{
// TO BE DONE DEPENDING ON EASYADMIN EXT. USAGE
$statusLabel = [
'Initialisé' => 'INIT',
'En cours' => 'ONGOING',
'Remplie' => 'PENDING',
];
return $statusLabel;
}
public function getSurveyPaymentStatusLabel(): string
{
$statusLabel = '';
switch ($this->paymentStatus) {
case 'pending':
$statusLabel = 'En attente';
break;
case 'captured':
case 'payedout':
$statusLabel = 'Payé';
break;
case 'canceled':
$statusLabel = 'Annulé';
break;
default:
$statusLabel = 'En attente';
}
return $statusLabel;
}
public function getSurveyResultLabel(): string
{
$statusLabel = '';
switch ($this->resultCode) {
case 'PA':
$statusLabel = 'Pas avantageux';
break;
case 'QR':
$statusLabel = 'TOU (Quasi-résident)';
break;
case 'RS':
$statusLabel = 'DRIS (Rectification Impôt Source)';
break;
case 'VALID':
$statusLabel = 'Validé';
break;
case 'INVALID':
$statusLabel = 'Invalidé';
break;
case 'REJECTED':
$statusLabel = 'Rejeté';
break;
case 'CANCELED':
$statusLabel = 'Annulé';
break;
default:
$statusLabel = '-';
}
return $statusLabel;
}
public function getPostPaymentQuestions()
{
if (in_array($this->survey->getId(), [1, 3])) {
return true;
}
return null;
}
public function getResultCode(): ?string
{
return $this->resultCode;
}
public function setResultCode(?string $resultCode): self
{
$this->resultCode = $resultCode;
return $this;
}
public function getResultComment(): ?string
{
return $this->resultComment;
}
public function setResultComment(?string $resultComment): self
{
$this->resultComment = $resultComment;
return $this;
}
public function hasGetaxFile($webDir): ?bool
{
$hasGetaxFile = false;
if (file_exists($webDir . '/uploads/files/getax/tax/' . $this->getId() . '_' . $this->getUser()->getLastname() . $this->getUser()->getName() . (date('Y') - 1) . '_' . date('d_m_y') . '.tax')) {
$hasGetaxFile = true;
}
return $hasGetaxFile;
}
public function getUser(): ?User
{
return $this->user;
}
/**
* @return UserSurvey
*/
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function hasUploadedFiles(): ?bool
{
$files = $this->getUploadedFiles();
if (count($files) > 0) {
return true;
}
return false;
}
public function getUploadedFiles(): ?array
{
$files = [];
if (!is_null($this->getUserFile())) {
foreach ($this->getUserFile()->getUserFileDocumentsSorted() as $userFileDocument) {
$files[] = $userFileDocument->getFileName();
}
}
return $files;
}
public function isSimulation(): ?bool
{
if (1 == $this->survey->getId()) {
return true;
} else {
return false;
}
}
public function getMissingFiles(): ?array
{
return $this->missingFiles;
}
public function setMissingFiles(?array $missingFiles): self
{
$this->missingFiles = $missingFiles;
return $this;
}
public function hasChildren(): bool
{
return count($this->children) > 0;
}
public function getDateAFC(): ?DateTimeInterface
{
return $this->dateAFC;
}
public function setDateAFC(?DateTimeInterface $dateAFC): self
{
$this->dateAFC = $dateAFC;
return $this;
}
/**
* @return Collection|UserSurvey[]
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(UserSurvey $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChild(UserSurvey $child): self
{
if ($this->children->contains($child)) {
$this->children->removeElement($child);
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
public function getParent()
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
public function getResultAFC()
{
return $this->resultAFC;
}
public function setResultAFC(?string $resultAFC): self
{
$this->resultAFC = $resultAFC;
return $this;
}
public function getOrder(): ?Order
{
return $this->order;
}
/**
* @return UserSurvey
*/
public function setOrder(?Order $order): self
{
$this->order = $order;
return $this;
}
public function getResultAFCComment(): ?string
{
return $this->resultAFCComment;
}
public function setResultAFCComment(?string $resultAFCComment): self
{
$this->resultAFCComment = $resultAFCComment;
return $this;
}
public function getOrderReference(): ?string
{
return $this->orderReference;
}
public function setOrderReference(?string $orderReference): self
{
$this->orderReference = $orderReference;
return $this;
}
public function getResultPresta()
{
return $this->resultPresta;
}
public function setResultPresta(?string $resultPresta): self
{
$this->resultPresta = $resultPresta;
return $this;
}
public function getResultPrestaComment(): ?string
{
return $this->resultPrestaComment;
}
public function setResultPrestaComment(?string $resultPrestaComment): self
{
$this->resultPrestaComment = $resultPrestaComment;
return $this;
}
public function getSurveyMode(): ?int
{
return $this->surveyMode;
}
public function setSurveyMode(?int $surveyMode): self
{
$this->surveyMode = $surveyMode;
return $this;
}
public function hasPostSteps(): ?bool
{
$has = false;
if (1 != $this->survey->getId()) {
if (!is_null($this->getSurveyModeObject())) {
if ('ONLINE' == $this->getSurveyModeCode() || 'E-DEMARCHES' == $this->getSurveyModeCode()) {
$has = true;
}
} else {
if (0 == $this->surveyModeObject->getMode()->getCode()) {
$has = true;
}
}
}
return $has;
}
public function getSurveyModeCode(): ?string
{
if (!is_null($this->surveyModeObject)) {
return $this->surveyModeObject->getMode()->getCode();
}
return null;
}
public function getModeLabel()
{
if (is_null($this->getSurveyModeObject())) {
$text = 'En ligne';
if (1 == $this->survey->getId() && 1 == $this->surveyMode) {
$text = '100% papier';
} elseif (2 == $this->survey->getId() && 0 == $this->surveyMode) {
$text = 'E-démarches';
} elseif (1 == $this->survey->getId() && 2 == $this->surveyMode) {
$text = 'Rendez-vous';
} elseif (in_array($this->survey->getId(), [2, 3]) && 1 == $this->surveyMode) {
$text = 'Dépôt physique';
} elseif (in_array($this->survey->getId(), [2, 3]) && 2 == $this->surveyMode) {
$text = 'Envoi postal';
}
return $text;
}
return $this->getSurveyModeObject()->getMode()->__toString();
}
public function getShortModeObjectLabel()
{
$label = $this->getModeLabel();
if ($this->getSurveyModeObject()) {
if ($this->getSurveyModeObject()->getId() == 14) {
//Département 01 au 19 et non résident
$label = '01-19';
} elseif ($this->getSurveyModeObject()->getId() == 21) {
//Départements n°55 à 974
$label = '55-974';
} elseif ($this->getSurveyModeObject()->getId() == 22) {
//Déclaration formulaire papier
$label = 'Papier';
}
}
return $label;
}
/**
* @return string
*/
public function __toString()
{
$userName = !$this->getUser() instanceof User ? 'undefined User' : $this->getUser()->getName() . ' ' . $this->getUser()->getLastname();
$surveyName = !$this->getSurvey() instanceof Survey ? 'undefined Survey' : $this->getSurvey()->getName();
return "{$userName} {$surveyName}";
}
/**
* Used to return client answer based on question label.
*
* @param int $label
*
* @return string $answer
*/
public function getAnswerByLabel($label)
{
$answer = '';
foreach ($this->userSurveyQuestions as $userSurveyQuestion) {
if ($userSurveyQuestion->getQuestion()->getName() == $label) {
$answer = $userSurveyQuestion->getValue();
return $answer;
}
}
return $answer;
}
public function getIsClone(): ?bool
{
return $this->isClone;
}
public function setIsClone(?bool $isClone): self
{
$this->isClone = $isClone;
return $this;
}
public function getIsEdited(): ?bool
{
return $this->isEdited;
}
public function setIsEdited(?bool $isEdited): self
{
$this->isEdited = $isEdited;
return $this;
}
public function getIsThirdParty(): ?bool
{
return $this->isThirdParty;
}
public function setIsThirdParty(?bool $isThirdParty): self
{
$this->isThirdParty = $isThirdParty;
return $this;
}
public function getStatusDateUpdate(): ?DateTimeInterface
{
return $this->statusDateUpdate;
}
public function setStatusDateUpdate(DateTimeInterface $statusDateUpdate): self
{
$this->statusDateUpdate = $statusDateUpdate;
return $this;
}
public function getDateLimit(): ?DateTimeInterface
{
return $this->dateLimit;
}
public function setDateLimit(?DateTimeInterface $dateLimit): self
{
$this->dateLimit = $dateLimit;
return $this;
}
public function getHasAFCRequested(): ?bool
{
return $this->hasAFCRequested;
}
public function setHasAFCRequested(?bool $hasAFCRequested): self
{
$this->hasAFCRequested = $hasAFCRequested;
return $this;
}
public function getTaxRectificationRequest(): ?TaxRectificationRequest
{
return $this->taxRectificationRequest;
}
public function setTaxRectificationRequest(?TaxRectificationRequest $taxRectificationRequest): self
{
$this->taxRectificationRequest = $taxRectificationRequest;
return $this;
}
public function getDisplayDocNotif(): ?bool
{
return $this->displayDocNotif;
}
public function setDisplayDocNotif(?bool $displayDocNotif): self
{
$this->displayDocNotif = $displayDocNotif;
return $this;
}
public function getDateLimitArray(): ?array
{
return $this->dateLimitArray;
}
/**
* @throws Exception
*/
public function fillDateLimitArray($displayAdminDates = false): self
{
$this->dateLimitArray = [
'Sans code' => null,
'31/03' => new DateTime(date('Y') . '-03-31'),
'30/04' => new DateTime(date('Y') . '-04-30'),
'31/05' => new DateTime(date('Y') . '-05-31'),
'30/06' => new DateTime(date('Y') . '-06-30'),
'31/07' => new DateTime(date('Y') . '-07-31'),
'31/08' => new DateTime(date('Y') . '-08-31'),
];
if (!$displayAdminDates) {
$this->dateLimitArray = array_merge($this->dateLimitArray, ['Après août' => 'SUPERIOR_AUGUST']);
array_unshift($this->dateLimitArray, 'CODE_DECLA');
$keys = array_keys($this->dateLimitArray);
$keys[array_search(0, $keys)] = 'Code ' . date('Y') . ' ajouté';
$this->dateLimitArray = array_combine($keys, $this->dateLimitArray);
} else {
$this->dateLimitArray = array_merge($this->dateLimitArray, [
'30/09' => new DateTime(date('Y') . '-09-30'),
'31/10' => new DateTime(date('Y') . '-10-31'),
'30/11' => new DateTime(date('Y') . '-11-30'),
'31/12' => new DateTime(date('Y') . '-12-31'),
]);
}
return $this;
}
public function getTotalCapturedInformationsPercentString()
{
return $this->getTotalCapturedInformationsPercent() . '%';
}
public function getTotalCapturedInformationsPercent()
{
$percent = 0;
if (!is_null($this->getUserFile())) {
$percent = $this->getUserFile()->getTotalCapturedInformationsPercent();
}
return $percent;
}
/**
* @return Collection<int, UserSurveyComment>
*/
public function getUserSurveyComments(): Collection
{
return $this->userSurveyComments;
}
public function addUserSurveyComment(UserSurveyComment $userSurveyComment): self
{
if (!$this->userSurveyComments->contains($userSurveyComment)) {
$this->userSurveyComments[] = $userSurveyComment;
$userSurveyComment->setUserSurvey($this);
}
return $this;
}
public function removeUserSurveyComment(UserSurveyComment $userSurveyComment): self
{
if ($this->userSurveyComments->removeElement($userSurveyComment)) {
// set the owning side to null (unless already changed)
if ($userSurveyComment->getUserSurvey() === $this) {
$userSurveyComment->setUserSurvey(null);
}
}
return $this;
}
public function countNotArchivedComments()
{
return $this->getNotArchivedComments()->count();
}
/**
* @return Collection<int, UserSurveyComment>
*/
public function getNotArchivedComments(): Collection
{
$notArchivedComments = [];
foreach ($this->userSurveyComments as $comment) {
if (true !== $comment->getIsArchived() && is_null($comment->getReplyTo())) {
$notArchivedComments[] = $comment;
}
}
return new ArrayCollection($notArchivedComments);
}
public function getIsArchived(): ?bool
{
return $this->isArchived;
}
public function setIsArchived(?bool $isArchived): self
{
$this->isArchived = $isArchived;
return $this;
}
public function countNotArchivedCommentsAndReplies()
{
return (string)$this->getNotArchivedCommentsAndReplies()->count();
}
/**
* @return Collection<int, UserSurveyComment>
*/
public function getNotArchivedCommentsAndReplies(): Collection
{
$notArchivedComments = [];
foreach ($this->userSurveyComments as $comment) {
if (true !== $comment->getIsArchived()) {
$notArchivedComments[] = $comment;
}
}
return new ArrayCollection($notArchivedComments);
}
public function getSurveyStep(): ?SurveyStep
{
return $this->SurveyStep;
}
public function setSurveyStep(?SurveyStep $SurveyStep): self
{
$this->SurveyStep = $SurveyStep;
return $this;
}
/**
* @return Collection<int, UserSurveyBexioArticle>
*/
public function getUserSurveyBexioArticles(): Collection
{
return $this->userSurveyBexioArticles;
}
public function addUserSurveyBexioArticle(UserSurveyBexioArticle $userSurveyBexioArticle): self
{
if (!$this->userSurveyBexioArticles->contains($userSurveyBexioArticle)) {
$this->userSurveyBexioArticles[] = $userSurveyBexioArticle;
$userSurveyBexioArticle->setUserSurvey($this);
}
return $this;
}
public function removeUserSurveyBexioArticle(UserSurveyBexioArticle $userSurveyBexioArticle): self
{
if ($this->userSurveyBexioArticles->removeElement($userSurveyBexioArticle)) {
// set the owning side to null (unless already changed)
if ($userSurveyBexioArticle->getUserSurvey() === $this) {
$userSurveyBexioArticle->setUserSurvey(null);
}
}
return $this;
}
public function getResultSurvey(): ?Survey
{
return $this->resultSurvey;
}
public function setResultSurvey(?Survey $resultSurvey): self
{
$this->resultSurvey = $resultSurvey;
return $this;
}
public function getCreator(): ?User
{
return $this->creator;
}
public function setCreator(?User $creator): self
{
$this->creator = $creator;
return $this;
}
public function conditionalSurveyName()
{
$baseName = $this->getSurvey()->getName();
if ('QUASI_RESID' == $this->getSurvey()->getCode()) {
if ($this->getUserFile()) {
if ('Suisse' == $this->getUserFile()->getResidence()) {
$baseName = 'Déclaration suisse';
}
}
}
return $baseName;
}
public function getInternalAlertDate(): ?DateTimeInterface
{
return $this->internalAlertDate;
}
public function setInternalAlertDate(?DateTimeInterface $internalAlertDate): self
{
$this->internalAlertDate = $internalAlertDate;
return $this;
}
public function badgeColorInternalAlertDate(): string
{
$d = strtotime('today midnight');
if (!is_null($this->internalAlertDate)) {
if ($d > $this->internalAlertDate->getTimestamp()) {
return 'badge-danger';
}
return 'badge-warning';
}
return '';
}
public function bgColorInternalAlertDate(): string
{
$d = strtotime('today midnight');
if (!is_null($this->internalAlertDate)) {
if ($d > $this->internalAlertDate->getTimestamp()) {
return 'text-bg-danger bg-opacity-25';
}
return 'text-bg-warning bg-opacity-25';
}
return '';
}
public function badgeColorDateLimit(): string
{
if (!is_null($this->dateAFC)) {
return 'badge-secondary';
}
$d = strtotime('today midnight');
if ($d > $this->dateLimit->getTimestamp()) {
return 'badge-danger';
}
return 'badge-info';
}
public function getSurveyPaymentStatusBadgeColor()
{
if ($this->isPaid()) {
return 'badge-success';
}
return 'badge-warning';
}
public function isNoAFCResult(): ?bool
{
return $this->noAFCResult;
}
public function setNoAFCResult(?bool $noAFCResult): self
{
$this->noAFCResult = $noAFCResult;
return $this;
}
public function getSurveyAdminStatus($adminStatusList)
{
$list = [];
foreach ($adminStatusList as $i => $adminStatus) {
$list[$adminStatus->getId()] = ['label' => $adminStatus->getTitle(), 'color' => $adminStatus->getColor()];
foreach ($this->getSurvey()->getSurveyAdminStatuses() as $surveyAdminStatus) {
if ($surveyAdminStatus->getAdminStatus() == $adminStatus &&
$surveyAdminStatus->getUserSurveyStatus() == $this->getUserSurveyStatus()) {
$list[$adminStatus->getId()]['label'] = $surveyAdminStatus->getLabel();
}
}
}
return $list;
}
public function getAdminStatus(): ?AdminStatus
{
return $this->adminStatus;
}
public function setAdminStatus($adminStatus): self
{
$this->adminStatus = $adminStatus;
return $this;
}
public function getCommentByTypes(array $types): ArrayCollection
{
$comments = [];
foreach ($this->getNotArchivedComments() as $comment) {
if (in_array($comment->getType(), $types)) {
$comments[] = $comment;
}
}
return new ArrayCollection($comments);
}
public function calculQR()
{
return floatval($this->getResultIS()) - floatval($this->getResultQR());
}
public function getResultIS()
{
return $this->resultIS;
}
public function setResultIS(?string $resultIS): self
{
$this->resultIS = $resultIS;
return $this;
}
public function getResultQR()
{
return $this->resultQR;
}
public function setResultQR(?string $resultQR): self
{
$this->resultQR = $resultQR;
return $this;
}
public function calculRS()
{
return floatval($this->getResultIS()) - floatval($this->getResultRS());
}
public function getResultRS()
{
return $this->resultRS;
}
public function setResultRS(?string $resultRS): self
{
$this->resultRS = $resultRS;
return $this;
}
public function allowUserEdit(): bool
{
if ('CMU' == $this->getSurvey()->getCode()) {
if (in_array($this->getStatus(), [
'OFFER_PENDING',
'OFFER_ACCEPTED',
'OFFER_DENIED',
'PROCESSING_PENDING',
'PROCESSING_FILES_RECEIVED',
'PROCESSING_MISSING_FILES_SENT',
'DONE',
'CANCELED',
])) {
return false;
}
return true;
}
if ('DECLARATION_DE_REVENUS_CNTFS' == $this->getSurvey()->getCode()) {
if (in_array($this->getStatus(), [
'PROCESSING_PENDING',
'PROCESSING_FILES_RECEIVED',
'PROCESSING_MISSING_FILES_SENT',
'PROCESSING_FILES_POSTED_CMU',
'DONE',
'CANCELED',
])) {
return false;
}
return true;
}
if ($this->isPaid()) {
return false;
}
if (in_array($this->getStatus(), [
'DONE_PAYMENT_PENDING',
'PROCESSING_FILES_POSTED_FR',
'PROCESSING_FILES_POSTED_CMU',
'CANCELED',
'DONE',
'PROCESSING_FILES_POSTED',
'PROCESSING_FILES_COMPLETED',
'PROCESSING_FILES_MISSING',
'PROCESSING_MISSING_FILES_SENT',
'PROCESSING_FILES_RECEIVED',
'PROCESSING_FILES_PENDING',
'PROCESSING_DONE',
'PROCESSING',
])) {
return false;
}
return true;
}
public function allowUserDeleteFiles()
{
if (in_array($this->getStatus(), [
'PROCESSING',
'PROCESSING_DONE',
'PROCESSING_FILES_COMPLETED',
'PROCESSING_FILES_POSTED',
'DONE',
'CANCELED',
'PROCESSING_FILES_POSTED_FR',
'DONE_PAYMENT_PENDING',
])) {
return false;
}
return true;
}
public function getBexioStatusLabel(): string
{
if (!$this->order) {
return 'Non relié';
}
if (is_null($this->order->getBexioInvoiceId())) {
return 'Non relié';
}
if (true === $this->order->isBexioIsPaid()) {
return 'Payé';
} else {
return 'Relié';
}
}
public function getBexioStatusBadgeColor()
{
if (!$this->order) {
return 'badge-danger';
}
if (is_null($this->order->getBexioInvoiceId())) {
return 'badge-danger';
}
if (true === $this->order->isBexioIsPaid()) {
return 'badge-success';
} else {
return 'badge-warning';
}
}
public function getDpt()
{
$userFile = $this->getUserFile();
if ($userFile) {
$owner = $userFile->getOwner();
if ($owner && !is_null($owner->getZipcode())) {
return substr($owner->getZipcode(), 0, 2);
}
}
return '';
}
public function getCmuResultN(): ?float
{
return $this->cmuResultN;
}
public function setCmuResultN(?float $cmuResultN): self
{
$this->cmuResultN = $cmuResultN;
return $this;
}
public function getCmuResultN1(): ?float
{
return $this->cmuResultN1;
}
public function setCmuResultN1(?float $cmuResultN1): self
{
$this->cmuResultN1 = $cmuResultN1;
return $this;
}
public function getCmuResultN2(): ?float
{
return $this->cmuResultN2;
}
public function setCmuResultN2(?float $cmuResultN2): self
{
$this->cmuResultN2 = $cmuResultN2;
return $this;
}
public function getCmuResultN3(): ?float
{
return $this->cmuResultN3;
}
public function setCmuResultN3(?float $cmuResultN3): self
{
$this->cmuResultN3 = $cmuResultN3;
return $this;
}
public function calculCmu()
{
return ($this->cmuResultN ?? 0) + ($this->cmuResultN1 ?? 0) + ($this->cmuResultN2 ?? 0) + ($this->cmuResultN3 ?? 0);
}
public function getCmuResultType(): ?string
{
return $this->cmuResultType;
}
public function setCmuResultType(?string $cmuResultType): self
{
$this->cmuResultType = $cmuResultType;
return $this;
}
/**
* @return Collection<int, Email>
*/
public function getEmails(): Collection
{
return $this->emails;
}
public function addEmail(Email $email): self
{
if (!$this->emails->contains($email)) {
$this->emails[] = $email;
$email->setUserSurvey($this);
}
return $this;
}
public function removeEmail(Email $email): self
{
if ($this->emails->removeElement($email)) {
// set the owning side to null (unless already changed)
if ($email->getUserSurvey() === $this) {
$email->setUserSurvey(null);
}
}
return $this;
}
public function hasCommentType(string $type): bool
{
foreach ($this->getUserSurveyComments() as $surveyComment) {
if ($surveyComment->getType() == $type) {
return true;
}
}
return false;
}
public function hasDocToUpload()
{
$userFile = $this->getUserFile();
$survey = $this->getSurvey();
if ('DECLA_IMP_FR' == $survey->getCode()) {
if (!is_null($userFile->getOwner())) {
foreach ($userFile->getOwner()->getRevenues() as $revenue) {
if (!is_null($revenue->getAnswer('canton'))) {
if ('genève' != strtolower($revenue->getAnswer('canton')) && 'CH' == $revenue->getCountry()) {
return true;
}
}
}
}
if (!is_null($userFile->getPrincipalPartner())) {
foreach ($userFile->getPrincipalPartner()->getRevenues() as $revenue) {
if (!is_null($revenue->getAnswer('canton'))) {
if ('genève' != strtolower($revenue->getAnswer('canton')) && 'CH' == $revenue->getCountry()) {
return true;
}
}
}
}
}
if ('RECT_STD' == $survey->getCode() || 'QUASI_RESID' == $survey->getCode()) {
if ($this->getStatus() == "PROCESSING_FILES_MISSING") {
if ($userFile->hasAskedDocumentByCode('LETTRE_PROCA') or $userFile->hasAskedDocumentByCode('TABL_TRAV') or $userFile->hasAskedDocumentByCode('FRAIS_MEDIC')) {
return true;
}
} else {
if (!$userFile->hasValidatedDocumentsByCode('LETTRE_PROCA') or $userFile->hasAskedDocumentByCode('TABL_TRAV') or $userFile->hasAskedDocumentByCode('FRAIS_MEDIC')) {
return true;
}
}
}
return false;
}
public function hasResult()
{
return $this->resultAFC != null || $this->cmuResultType != null;
}
}