<?php
namespace App\Controller\Client;
use DateTime;
use App\Util\ParameterUtil;
use App\Service\AuthService;
use App\Service\EquipeService;
use App\Service\WalletService;
use App\Service\ContratService;
use App\Service\PackBuyService;
use App\Service\RevenueService;
use App\Service\CarriereService;
use App\Service\LicenciasService;
use App\Repository\UsersRepository;
use App\Repository\WalletRepository;
use App\Repository\AnnoncesRepository;
use Doctrine\ORM\EntityManagerInterface;
use App\Service\CommissionHandlerService;
use App\Repository\RevenueReportsRepository;
use App\Repository\UserInformationRepository;
use Symfony\Component\HttpFoundation\Request;
use ContainerEeeIkK5\getPackBuyServiceService;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class HomeController extends AbstractController
{
private $walletRepository;
private $carriereService;
private $packBuyService;
private $revenueReportsRepository;
private $equipeService;
private $licenceService;
private $revenueService;
public function __construct(
WalletRepository $walletRepository,
CarriereService $carriereService,
PackBuyService $packBuyService,
RevenueReportsRepository $revenueReportsRepository,
EquipeService $equipeService,
LicenciasService $licenceService,
RevenueService $revenueService,
private EntityManagerInterface $entityManager,
private PackBuyService $packService,
private UsersRepository $usersRepository,
private CommissionHandlerService $commissionHandlerService,
private ContratService $contratService,
private UserInformationRepository $userInformationRepository,
){
$this->walletRepository = $walletRepository;
$this->carriereService = $carriereService;
$this->packBuyService = $packBuyService;
$this->revenueReportsRepository = $revenueReportsRepository;
$this->equipeService = $equipeService;
$this->licenceService=$licenceService;
$this->revenueService = $revenueService;
}
#[Route('/', name: 'app_home_index')]
public function index(): Response
{
$user = $this->getUser();
if(in_array("ROLE_PLAYER", $user->getRoles())){
return $this->redirectToRoute('app_player_index');
}
return $this->redirectToRoute('app_client_dahsboard');
}
#[Route('/dashboard', name: 'app_client_dahsboard')]
public function dashboard(AnnoncesRepository $annoncesRepository,AuthService $authService): Response
{
if(in_array("ROLE_PLAYER", $this->getUser()->getRoles())){
return $this->redirectToRoute('app_player_index');
}
$now = new DateTime();
$annonce = $annoncesRepository->getActiveAnnoncesByBackOfficeLevel($this->getUser()->getCurrentBackOfficeLevel(),$now);
$plafond = $this->licenceService->getUserPlafond($this->getUser());
$wallet = $this->walletRepository->findOneBy(['userId' =>$this->getUser()->getId()]);
$carriere = $this->carriereService->getUserDenormalizedQualification($this->getUser());
$nextQualification = ParameterUtil::getQualificationByRank($carriere->getUserRank() +1 );
$packActifInformation = $this->packBuyService->getPackActifInformation($this->getUser());
$weekIncome = $this->revenueService->getTotalRevenueByUserWeekAndYear($this->getUser());
$directMembersInformation = $this->equipeService->getDirectMemberInformation($this->getUser());
$userRevenue = $this->revenueReportsRepository->getTotalRevenueByUser($this->getUser());
$directChildrenHighestPack = $this->packService->getHighestPackOfDirectChildrenBySide($this->getUser());
$directMembers = $this->usersRepository->countDirectChildren($this->getUser());
$directMembersSample = $this->usersRepository->getDirectMembersSample($this->getUser());
$downMembersSampleOfEachSide = $authService->getDownMembersOfEachSideSample($this->getUser());
$parrainageCommission= $this->commissionHandlerService->getCurrentParrainageCommission($this->getUser());
$directMembersActifs = $this->userInformationRepository->countActifDirectChildren($this->getUser());
if($userRevenue['rv_gauche'] == 0 || $userRevenue['rv_droite'] == 0 ){
$weekIncome['rv_gauche'] = $userRevenue['rv_gauche'];
$weekIncome['rv_droite'] = $userRevenue['rv_droite'];
}
$contratState = $this->contratService->checkPendingContrat($this->getUser());
$dayLeftForFastStart = $this->carriereService->getDayLeftForFastStart($this->getUser());
return $this->render('dashboard/client_dashboard.html.twig',[
'wallet' => $wallet,
'annonces'=> $annonce,
'carriere' => $carriere,
'nextQualification' => $nextQualification,
'packActifInformation' => $packActifInformation,
'weekIncome' => $weekIncome,
'directMembersInformation' => $directMembersInformation,
'plafond' => $plafond,
'userRevenue' => $userRevenue,
'directChildrenHighestPack' => $directChildrenHighestPack,
'directMembers' => $directMembers,
'directMembersSample' => $directMembersSample,
'downMembersSampleOfEachSide' => $downMembersSampleOfEachSide,
'parrainageCommission'=> $parrainageCommission,
'contratState' => $contratState ,
'directMembersActifs' => $directMembersActifs,
'dayLeftForFastStart' => $dayLeftForFastStart
]);
}
#[Route('/informations', name: 'app_important_infos')]
public function informations(): Response
{
return $this->render('infos/infos.html.twig',[
]);
}
#[Route('/data-protection-infos', name: 'app_data_protection_infos')]
public function dataProtectionInfos(Request $request): Response
{
if ($request->isMethod('POST')) {
$dataProtectionChecked = $request->get('dataProtectionChecked');
if($dataProtectionChecked){
$user = (object)$this->getUser();
$user->setDataProtectionChecked(true);
$this->entityManager->persist($user);
$this->entityManager->flush();
if($this->isGranted('KYC_INFO_SUBMITTED')){
return $this->redirectToRoute('app_client_dahsboard');
}
return $this->redirectToRoute('app_kyc');
}
}
return $this->render('infos/data-protection-infos.html.twig',[
]);
}
}