<?php
 
 
namespace App\Controller;
 
 
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
 
 
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 
use Symfony\Component\Routing\Annotation\Route;
 
 
use Symfony\Component\HttpFoundation\Request;
 
use Symfony\Component\HttpFoundation\JsonResponse;
 
use Symfony\Component\HttpFoundation\Response;
 
use Symfony\Component\HttpFoundation\RedirectResponse;
 
use Symfony\Component\HttpFoundation\Cookie;
 
use Symfony\Component\HttpKernel\Exception\HttpException;
 
use Psr\Log\LoggerInterface;
 
 
 
use App\Entity\BannedDomainEntity;
 
use App\Entity\BannedUserEntity;
 
use App\Entity\BonusEntity;
 
use App\Entity\GeneratedWalletEntity;
 
use App\Entity\MessageEntity;
 
use App\Entity\NotificationEntity;
 
use App\Entity\RecycledWalletEntity;
 
use App\Entity\ReferralEntity;
 
use App\Entity\SettingEntity;
 
use App\Entity\SupportTicketEntity;
 
use App\Entity\SupportTicketResponseEntity;
 
use App\Entity\UserAdjustedTokenEntity;
 
use App\Entity\UserBonusTokenEntity;
 
use App\Entity\UserEntity;
 
use App\Entity\UserOrderTokenEntity;
 
use App\Entity\UserStakeTokenEntity;
 
use App\Entity\UserMemeCoinEntity;
 
use Doctrine\ORM\EntityManagerInterface;
 
 
 
use App\Service\AuthService;
 
use App\Service\MailService;
 
use App\Service\BlockIoService;
 
 
class DashboardController extends AbstractController
 
{
 
 
    private LoggerInterface $logger;
 
 
    public function __construct(LoggerInterface $logger)
 
    {
 
        $this->logger = $logger;
 
    }
 
 
     #[Route("/dd", name:"dashboard_index")]
 
    public function indexAction(AuthService $authService, BlockIoService $blockIoService)
 
    {
 
 
 
        $em = $this->getDoctrine()->getManager();
 
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $em = $this->getDoctrine()->getManager();
 
        $user = $authService->getUser();
 
        $session = $this->get('session');
 
 
        if(!$user->isVerifiedProfile()){
 
            $session->getFlashBag()->add('error_messages', 'Please complete your profile before continuing.');
 
            return $this->redirect($this->generateUrl('dashboard_profile'),302);
 
        }
 
    
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
        
 
        $stagePurchase = $em->getRepository(UserOrderTokenEntity::class)->stagePurchase();
 
        $totalOrder  = $stagePurchase['stagePurchase'];
 
        $referralTotalEarnings = $em->getRepository(UserEntity::class)->refEarnings($user);
 
        $totalUser = $em->getRepository(UserEntity::class)->userCount();
 
        $referralsss = $em->getRepository(UserEntity::class)->referralBonusByReferrentUser($user);
 
 
       
 
        return $this->render('Dashboard/index.html.twig',array(
 
            'page_header' => ' Welcome To Your AiETF Wallet Dashboard',
 
            'user' => $user,
 
            'totalUser' => $totalUser, 
 
            'tokenDollarValue' => $tokenDollarValue,
 
            'pb' => $pb,
 
            'refTotalEarnings' => $referralTotalEarnings,
 
            'page_title' => 'Dashboard',
 
            'allReferrals' => count($referralsss),
 
             'title' => 'Dashboard AiETF Token',   
 
             'totalOrder' => $totalOrder ,
 
            'javascripts' => [
 
                'dashboard/index.js',
 
                'plugins/dragula/dragula.min.js',
 
                'plugins/jkanban/jkanban.js',
 
                'plugins/chartjs.min.js',
 
                'plugins/threejs.js',
 
                'plugins/orbit-controls.js'
 
            ],  
 
            'min_order' => $this->getParameter('app.min_order'),
 
            'max_order' => $this->getParameter('app.max_order'),
 
        ));
 
    }
 
 
 
   #[Route("/tokens", name:"dashboard_purchase")]
 
    public function purchaseAction(Request $request, AuthService $authService, BlockIoService $blockIoService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
        $stagePurchase = $em->getRepository(UserOrderTokenEntity::class)->stagePurchase();
 
        $totalOrder  = $stagePurchase['stagePurchase'];
 
        $totalBonus = $em->getRepository(UserBonusTokenEntity::class)->totalBonus();
 
 
        $btcPrc = $blockIoService->getNetworkPrice('btc');
 
        $ethPrc = $blockIoService->getNetworkPrice('eth'); 
 
        $bnbPrc = $blockIoService->getNetworkPrice('bnb');
 
        $xrpPrc = $blockIoService->getNetworkPrice('xrp');
 
        $adaPrc = $blockIoService->getNetworkPrice('ada');
 
        $solPrc = $blockIoService->getNetworkPrice('sol');
 
        $ltcPrc = $blockIoService->getNetworkPrice('ltc');
 
        $dogePrc = $blockIoService->getNetworkPrice('doge');
 
        $usdtPrc = $blockIoService->getNetworkPrice('usdt');
 
        $daiPrc = $blockIoService->getNetworkPrice('dai');
 
        $shibPrc = $blockIoService->getNetworkPrice('shib');
 
        $pepePrc = $blockIoService->getNetworkPrice('pepe');
 
        $dotPrc = $blockIoService->getNetworkPrice('dot');
 
        $trxPrc = $blockIoService->getNetworkPrice('trx');
 
        $stagePurchase = $em->getRepository(UserOrderTokenEntity::class)->stagePurchase();
 
        $totalOrder  = $stagePurchase['stagePurchase'];           
 
 
        // $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        // $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
        // $tokenAmt = $params['checkout']['token_quantity'] ? $params['checkout']['token_quantity'] : 0;
 
        // $paymentType = $params['checkout']['payment_type'] ? $params['checkout']['payment_type'] : '';
 
 
        return $this->render('Dashboard/purchase.html.twig',array(
 
            'page_header' => 'Purchase AiETF Tokens',
 
             'userNotifications' => $userNotifications,
 
             'userMessages' => $userMessages,
 
            'purchaseBonus' => $pb,
 
            'totalOrder'=> $totalOrder ? $totalOrder : 0,
 
            'tokenDollarValue' => $tokenDollarValue,
 
            'btcPrc' => $btcPrc,
 
            'ethPrc' => $ethPrc,
 
            'bnbPrc' => $bnbPrc,
 
            'xrpPrc' => $xrpPrc,
 
            'adaPrc' => $adaPrc,
 
            'solPrc' => $solPrc,
 
            'user' =>  $user,
 
            'ltcPrc' => $ltcPrc,
 
            'dogePrc' => $dogePrc,
 
            'usdtPrc' => $usdtPrc,
 
            'daiPrc' => $daiPrc,
 
            'dotPrc' => $dotPrc,
 
            'shibPrc' => $shibPrc,
 
            'pepePrc' => $pepePrc,
 
            'trxPrc' => $trxPrc,
 
            'title' => 'Purchase AiETF Token',  
 
            'min_order' => $this->getParameter('app.min_order'),
 
            'max_order' => $this->getParameter('app.max_order'),
 
            'javascripts' => [
 
                'dashboard/purchase_token.js'
 
            ]
 
 
        ));
 
    }
 
    
 
    #[Route("/purchase_token_inquiry/{id}", name:"dashboard_purchase_token_inquiry")]
 
    public function purchaseTokenInquiryAction(Request $request, AuthService $authService, $id, MailService $mailService)
 
    {
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $session = $this->get('session');
 
        $orderToken = $em->getRepository(UserOrderTokenEntity::class)->find(base64_decode($id));
 
 
 
 
        if(!$orderToken){
 
 
            $session->getFlashBag()->add('error_messages', 'Ooops something wen`t wrong please try again later.');
 
        } else {
 
 
            $currentDateTime = new \DateTime();
 
            $interval = $currentDateTime->diff($orderToken->getUpdatedAt());
 
            $diffInSeconds = ($interval->h * 3600) + ($interval->i * 60) + $interval->s;
 
 
            if($orderToken->getInquirySentCtr() == 0) { 
 
                
 
                $orderToken->setInquirySentCtr($orderToken->getInquirySentCtr() + 1);
 
                $em->flush();
 
 
               $msg = $this->renderView('Email/purchase_inquiry.html.twig' , ['orderToken' => $orderToken]);
 
               $mailService->sendMail('New Purchase Inquiry', $msg, '[email protected]');
 
                $session->getFlashBag()->set('success_messages', 'Your inquiry successfully sent to us. we will back to you as soon as possible.');
 
                return $this->redirectToRoute('dashboard_index' , array(), 302);
 
 
            }  else {
 
                
 
                    $remainingSeconds = 7200 - $diffInSeconds;
 
    
 
                    $hours = floor($remainingSeconds / 3600); // Get the number of hours
 
                    $minutes = floor(($remainingSeconds % 3600) / 60); // Get the remaining minutes
 
                   // $session->getFlashBag()->set('error_messages', 'Please wait ' . ($hours > 0 ? $hours . "hours and " : "") . ($minutes > 0 ? $minutes . " minutes"  : "")  . ' to send a missing payment inquiry.' );
 
                   $session->getFlashBag()->set('error_messages', 'Inquiry already sent we will come back to you as soon as possible.' ); 
 
                   return $this->redirectToRoute('dashboard_index' , array(), 302);
 
 
            }
 
       
 
 
        }
 
 
 
        return $this->render('Dashboard/stake.html.twig',array(
 
            'user' =>  $user
 
        ));
 
    }
 
    
 
#[Route("/stake", name:"dashboard_stake")]
 
    public function stakeAction(Request $request, AuthService $authService)
 
    {
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
       
 
    
 
          if($request->getMethod() == 'POST'){
 
 
            $errors = [];
 
            $data = $request->request->get('stake');
 
            $errors = $this->validateStake($data, $user);
 
 
            if(count($errors)){
 
 
                foreach($errors as $error) {
 
                    $this->get('session')->getFlashBag()->add('error_messages', $error);
 
                }
 
 
            } else {
 
 
                return $this->redirect($this->generateUrl('dashboard_stake_review', ['amount' => $data['amount'], 'type' => $data['type']]), 302);
 
            }
 
        } 
 
 
        return $this->render('Dashboard/stake.html.twig',array(
 
            'user' =>  $user
 
        ));
 
    }
 
 
    private function validateStake($formData, $user){
 
 
        $errors = [];
 
        $amount = str_replace(',', '', $formData['amount']);  
 
        switch ($formData['type']) {
 
            case 1:
 
                
 
                if(floatval( $amount) < 10000000){
 
                    $errors[] = 'Minimum amount is 10,000,000';
 
                }
 
 
                break;
 
            case 2 :
 
                
 
                if(floatval( $amount) < 50000000){
 
                    $errors[] = 'Minimum amount is 50,000,000';
 
                }
 
                break;
 
            case 3:
 
            
 
                if(floatval( $amount) < 100000000){
 
                    $errors[] = 'Minimum amount is 100,000,000';
 
                }
 
                
 
                break;
 
        }
 
 
        if(floatval($amount) > $user->totalBalance()){
 
            $errors[] = 'Insufficient balance to stake.';
 
        }
 
 
        return $errors;
 
    }
 
      
 
      
 
#[Route("/stakereview", name:"dashboard_stake_review")]
 
    public function stakereviewAction(Request $request, AuthService $authService)
 
    {
 
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
        $data = $request->query->all();
 
        $data['amount'] = str_replace(',', '', $data['amount']);
 
 
        if($request->getMethod() == 'POST'){
 
 
            $errors = [];
 
            $data = $request->request->get('stake');
 
           $errors = $this->validateStake($data, $user);
 
 
            if(count($errors)){
 
 
                foreach($errors as $error) {
 
                    $this->get('session')->getFlashBag()->add('error_messages', $error);
 
                }
 
 
            } else {
 
 
                    $amount = str_replace(',', '', $data['amount']);
 
                    $userStakeToken  = new UserStakeTokenEntity();
 
                    $userStakeToken->setTokenAmount($amount);
 
                    $userStakeToken->setType($data['type']);
 
                    $userStakeToken->setInterest((($data['type'] ==  '1' ? 7.45 : ($data['type'] ==  '2' ? 13 : 23.75) ) / 100) * floatval($amount));
 
                    $userStakeToken->setInterestPercent(($data['type'] ==  '1' ? 7.45 : ($data['type'] ==  '2' ? 13 : 23.75)));
 
                    $userStakeToken->setUser($user);
 
                    $userStakeToken->setStartDate(new \DateTime(date('Y/m/d')));
 
                    $userStakeToken->setEndDate(new \DateTime(date('Y/m/d', strtotime("+" .($data['type'] ==  '1' ? '6' : '12'). "month"))));
 
                    $userStakeToken->setTokenDollarValue($this->getParameter('app.token_dollar_value'));
 
                    $em->persist($userStakeToken);
 
                    $em->flush();
 
 
                    $this->get('session')->getFlashBag()->add('success_messages', 'Your token is successfully staking.');
 
                    return $this->redirect($this->generateUrl('dashboard_stake'), 302);
 
 
              }
 
        } 
 
 
 
        return $this->render('Dashboard/stakereview.html.twig',array(
 
            'purchaseBonus' => $pb,
 
            'tokenDollarValue' => $tokenDollarValue,
 
            'data'=> $data,
 
            'user' =>  $user,
 
            
 
        ));
 
    }
 
    
 
    
 
#[Route("/staking", name:"dashboard_staking")]
 
    public function stakingAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
   $amount = $em->getRepository(UserStakeTokenEntity::class)->findAll();
 
       $stakelist = $em->getRepository(UserStakeTokenEntity::class)->findBy(['user' => $user]);
 
 
 
        return $this->render('Dashboard/staking.html.twig',array(
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'purchaseBonus' => $pb,
 
            'tokenDollarValue' => $tokenDollarValue,
 
            'user' =>  $user,
 
            'page_title' => 'My GLN Stakes',
 
            'amount' => $amount,
 
'stakelist' => $stakelist,
 
        ));
 
    }
 
    
 
    
 
#[Route("/staking2", name:"dashboard_staking2")]
 
    public function staking2Action(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
      $amount = $em->getRepository(UserStakeTokenEntity::class)->findAll();
 
       $stakelist = $em->getRepository(UserStakeTokenEntity::class)->findBy(['user' => $user]);
 
 
 
        return $this->render('Dashboard/staking2.html.twig',array(
 
            'userNotifications' => $userNotifications,
 
            'userMessages' => $userMessages,
 
            'purchaseBonus' => $pb,
 
            'tokenDollarValue' => $tokenDollarValue,
 
            'user' =>  $user,
 
            'page_title' => 'My GLN Stakes',
 
            'amount' => $amount,
 
            'stakelist' => $stakelist,
 
        ));
 
    }
 
 
     #[Route("/tokens/review", name:"dashboard_purchase_review")]
 
    public function purchase_reviewAction(Request $request, AuthService $authService, BlockIoService $blockIoService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
                 
 
        if($request->getMethod() != 'POST'){
 
 
            $this->get('session')->getFlashBag()->add('error_messages', 'Unauthorized Access Please contact a system administrator.');
 
            return $this->redirect( $this->generateUrl('dashboard_purchase'), 302);
 
        } 
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
        $params = $request->request->all();
 
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
        $tokenAmt = $params['checkout']['token_quantity'] ? $params['checkout']['token_quantity'] : 0;
 
        $paymentType = $params['checkout']['payment_type'] && $params['checkout']['payment_type'] != ''  ? $params['checkout']['payment_type'] : 'btc';
 
        $bonusToken = $params['checkout']['bonus'] ?  $this->stringToInt($params['checkout']['bonus']) : '';
 
        $stagePurchase = $em->getRepository(UserOrderTokenEntity::class)->stagePurchase();
 
        $totalOrder  = $stagePurchase['stagePurchase']; 
 
        $tokenAmtInt = $this->stringToInt($tokenAmt);
 
$usdtValue = $this->stringToInt($tokenAmt) * $tokenDollarValue;
 
 
        $minOrder = $this->getParameter('app.min_order');
 
        $maxOrder = $this->getParameter('app.max_order');
 
 
        if(floatval($this->stringToInt($tokenAmt)) < floatval($minOrder) || floatval($this->stringToInt($tokenAmt)) > floatval($maxOrder)){
 
           
 
            $this->get('session')->getFlashBag()->add('error_messages', 'Minimum order should ' . number_format($minOrder, 2, '.' , ',') . ' and Maximum order shoul be ' . number_format($maxOrder, 2, '.' , ',') );
 
            return $this->redirect( $this->generateUrl('dashboard_purchase'), 302);
 
        }
 
 
        
 
     return $this->render('Dashboard/purchase_review.html.twig', array(
 
    'page_header' => 'Purchase AiETF Tokens',
 
    'userNotifications' => $userNotifications,
 
    'userMessages' => $userMessages,
 
    'totalOrder'=> $totalOrder ? $totalOrder : 0,
 
    'purchaseBonus' => $pb,
 
    'tokenDollarValue' => $usdtValue,
 
    'user' =>  $user,
 
    'tokenAmt' => $tokenAmt,
 
    'paymentType' => $paymentType,
 
    'bonusToken' => $bonusToken,
 
    'usdtValue' => $usdtValue,
 
    'title' => 'Purchase Review AiETF Token',
 
));
 
    }
 
 
     #[Route("/tokens/checkout", name:"dashboard_purchase_checkout")]
 
    public function purchase_checkoutAction(Request $request, AuthService $authService, BlockIoService $blockIoService)
 
    {
 
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $params = $request->query->all();
 
 
        $minOrder = $this->getParameter('app.min_order');
 
        $maxOrder = $this->getParameter('app.max_order');
 
 
        if(isset($params['paymentType']) && isset($params['tokenAmt']) ){
 
          
 
            $user = $authService->getUser();
 
            $em = $this->getDoctrine()->getManager();
 
            $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
            $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
        
 
            $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
            $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
            $promoB = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB10000'));
 
            $tokenAmt =  $this->stringToInt($params['tokenAmt']);
 
            $paymentType = $params['paymentType'];
 
            $label = time() . '-' . $this->generateRandomString();
 
       
 
            if(floatval($tokenAmt) < floatval($minOrder) || floatval($tokenAmt) > floatval($maxOrder)){
 
           
 
                $this->get('session')->getFlashBag()->add('error_messages', 'Ooops something went wrong please try again later.');
 
                return $this->redirect( $this->generateUrl('dashboard_purchase'), 302);
 
            }
 
 
           
 
    
 
    
 
            $recycledWallet = $em->getRepository(RecycledWalletEntity::class)->findOneBy(array('network' => $paymentType, 'status' => 'Available'));
 
 
            if(!$recycledWallet){
 
                $recycledWallet = $this->sdasdsa($em, $paymentType, $blockIoService);
 
            }
 
            // $recycledWallet = $blockIoService->wallet($paymentType);
 
            
 
            $cryptoPrc = $blockIoService->getNetworkPrice($paymentType);
 
            $duelInDollar = $this->stringToInt($tokenAmt) * $this->stringToInt($tokenDollarValue);
 
 
            $dueToCrt = $this->stringToInt($duelInDollar) /  $this->stringToInt($cryptoPrc);
 
 
            $newOrderToken = new UserOrderTokenEntity();
 
            $newOrderToken->setTokenValue($tokenDollarValue);
 
            $newOrderToken->setTokenAmount($tokenAmt);
 
            $newOrderToken->setLabel($recycledWallet->getWalletAddress());
 
            $newOrderToken->setAddress($recycledWallet->getWalletAddress());
 
            $newOrderToken->setAmount($dueToCrt);
 
            $newOrderToken->setNetwork($paymentType);
 
            $newOrderToken->setUser($user);
 
            $em->persist($newOrderToken);
 
            $em->flush();
 
            
 
            
 
            $recycledWallet->setStatus('Used');
 
            $em->flush();
 
            
 
 
           
 
            return $this->redirect($this->generateUrl('dashboard_purchase_details' , array('transactionId' => $newOrderToken->getIdEncoded())), 302);
 
 
        } else {
 
 
            $this->get('session')->getFlashBag()->add('error_messages', 'Oppsss something went wrong please try again.');
 
            return $this->redirect( $this->generateUrl('dashboard_purchase'), 302);
 
        }
 
    }
 
 
    private function stringToInt($n){
 
        return str_replace(",", "", $n); 
 
    }
 
 
      #[Route("/tokens/details/{transactionId}", name:"dashboard_purchase_details")]
 
    public function purchase_detailsAction(Request $request, AuthService $authService, BlockIoService $blockIoService, $transactionId)
 
    {
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin() (isset($params['paymentType']) && isset($params['tokenAmt']) );
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
        $orderToken = $em->getRepository(UserOrderTokenEntity::class)->find(base64_decode($transactionId));
 
        
 
        
 
         $params = $request->request->all();
 
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
        $tokenAmt = $orderToken->getAmount();
 
        $paymentType = $orderToken->getNetwork();
 
   
 
        $cryptoPrc =300000;
 
        $amtDue = $tokenAmt * $tokenDollarValue;
 
        $prcToCrt = $amtDue / $cryptoPrc;
 
        $stagePurchase = $em->getRepository(UserOrderTokenEntity::class)->stagePurchase();
 
        $totalOrder  = $stagePurchase['stagePurchase'];           
 
        
 
       
 
       
 
        return $this->render('Dashboard/purchase_details.html.twig',array(
 
            'userNotifications' => $userNotifications,
 
            'userMessages' => $userMessages,
 
            'orderToken' => $orderToken,
 
            'bonusToken' => $orderToken->getAmount() >= 10000 ? ($orderToken->getAmount() / 2.5) : 0,
 
            'user' =>  $user,
 
            'totalOrder'=> $totalOrder ? $totalOrder : 0,
 
            'paymentType' => $orderToken->getNetwork(),
 
            'purchaseBonus' => $pb,
 
            'tokenDollarValue' => $tokenDollarValue,
 
            'tokenAmt' => $tokenAmt,
 
            'paymentType' => $paymentType,
 
            'prcToCrt' => $prcToCrt,
 
            'title' => 'Purchase Checkout AiETF Token',   
 
            'page_header' => 'Purchase AiETF Tokens'
 
 
        ));
 
    }
 
 
 
   #[Route("/profile_avatar", name:"dashboard_profile_avatar")]
 
    public function profileAvatarAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        if($request->getMethod() == 'POST'){
 
 
            $user->setAvatar($request->get('avatar'));
 
            $em->flush();
 
        }
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
 
 
        return $this->render('Dashboard/profile_avatar.html.twig',array(
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'purchaseBonus' => $pb,
 
            'tokenDollarValue' => $tokenDollarValue,
 
            'user' =>  $user,
 
        ));
 
    }
 
 
    #[Route("/getting_started", name:"dashboard_getting_started")]
 
    public function gettingStartedAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
 
 
        return $this->render('Dashboard/getting_started.html.twig',array(
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'purchaseBonus' => $pb,
 
            'tokenDollarValue' => $tokenDollarValue,
 
            'user' =>  $user,
 
        ));
 
    }
 
 
 
    #[Route("/purchase_meme/{id}", name:"dashboard_purchase_meme")]
 
    public function purchaseMemeAction(Request $request, AuthService $authService, $id)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
    
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        $memeCoin = $em->getRepository(UserMemeCoinEntity::class)->find($id);
 
        if(!$memeCoin){
 
            $this->get('session')->getFlashBag()->add('error_messages', 'Invalid MemeCoin.');
 
            return $this->redirect($this->generateUrl('dashboard_meme_gallery'), 302);
 
        }
 
 
        return $this->render('Dashboard/purchase_meme.html.twig',array(
 
        'userNotifications' => $userNotifications,
 
        'userMessages' => $userMessages,
 
            'user' =>  $user,
 
        ));
 
    }
 
 
    #[Route("/meme_gallery", name:"dashboard_meme_gallery")]
 
    public function galleryMemeAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
        $memeCoins = $em->getRepository(UserMemeCoinEntity::class)->findAll();
 
 
        return $this->render('Dashboard/meme_gallery.html.twig',array(
 
            'userNotifications' => $userNotifications,
 
            'userMessages' => $userMessages,
 
            'user' =>  $user,
 
            'memeCoins' => $memeCoins
 
        ));
 
    }
 
    
 
    
 
 
    #[Route("/total_assets", name:"dashboard_total_assets")]
 
    public function totalAssetsAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
        $memeCoins = $em->getRepository(UserMemeCoinEntity::class)->findAll();
 
 
        return $this->render('Dashboard/totalassets.html.twig',array(
 
            'userNotifications' => $userNotifications,
 
            'userMessages' => $userMessages,
 
            'user' =>  $user,
 
            'memeCoins' => $memeCoins
 
        ));
 
    }
 
    
 
    
 
 
    #[Route("/meme_creator", name:"dashboard_meme_creator")]
 
    public function memeCreatorAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
 
        if($request->getMethod() == 'POST'){
 
 
            $formData = $request->request->all();
 
 
 
            if(isset($formData['form'])){
 
 
                $strToInt = preg_replace('/[^0-9.]/', '', $formData['form']['creation_cost']);
 
                $floatVal = (float)$strToInt;
 
                $errors = '';
 
                
 
                    $memeCoinExist = $em->getRepository(UserMemeCoinEntity::class)
 
                            ->findOneBy(['name' => $formData['form']['name']]) 
 
                            ?? $em->getRepository(UserMemeCoinEntity::class)
 
                                ->findOneBy(['symbol' => $formData['form']['symbol']]);
 
 
                if($memeCoinExist){
 
                    $errors = 'MemeCoin name or symbols are already exist.';
 
                }
 
 
                if($user->totalBalance() < $floatVal){
 
                    $errors = 'Insufficient balance.';
 
                }
 
 
                if(!empty($errors) || $errors != ''){
 
                     $this->get('session')->getFlashBag()->add('error_messages', $errors);
 
                    return $this->redirect($this->generateUrl('dashboard_meme_creator'), 302);
 
                }
 
 
                $userMemeCoin = new UserMemeCoinEntity();
 
                $userMemeCoin->setUser($user);
 
                $userMemeCoin->setName($formData['form']['name']);
 
                $userMemeCoin->setSymbol($formData['form']['symbol']);
 
                $userMemeCoin->setBasePrice($formData['form']['base_price']);
 
                $userMemeCoin->setTotalSupply($formData['form']['total_supply']);
 
                $userMemeCoin->setBurnAmount($floatVal * 0.75);
 
                $userMemeCoin->setRecycleAmount($floatVal * 0.25);
 
                $em->persist($userMemeCoin);
 
                $em->flush();
 
 
                $this->get('session')->getFlashBag()->add('success_messages', 'MemeCoin successfully created');
 
                return $this->redirect($this->generateUrl('dashboard_meme_creator'), 302);
 
              
 
            }
 
        }
 
 
 
        return $this->render('Dashboard/meme_creator.html.twig',array(
 
            'userNotifications' => $userNotifications,
 
            'userMessages' => $userMessages,
 
            'user' =>  $user,
 
        ));
 
    }
 
 
 
 
    #[Route("/meme_purchase", name:"dashboard_meme_purchase")]
 
    public function memePurchaseAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
 
        if($request->getMethod() == 'POST'){
 
 
            $formData = $request->request->all();
 
 
 
            if(isset($formData['form'])){
 
 
                $strToInt = preg_replace('/[^0-9.]/', '', $formData['form']['creation_cost']);
 
                $floatVal = (float)$strToInt;
 
 
                if($user->totalBalance() < $floatVal){
 
                    $this->get('session')->getFlashBag()->add('error_messages', 'You dont have enough balance.');
 
                    return $this->redirect($this->generateUrl('dashboard_meme_creator'), 302);
 
                }
 
 
                $userMemeCoin = new UserMemeCoinEntity();
 
                $userMemeCoin->setUser($user);
 
                $userMemeCoin->setName($formData['form']['name']);
 
                $userMemeCoin->setSymbol($formData['form']['symbol']);
 
                $userMemeCoin->setBasePrice($formData['form']['base_price']);
 
                $userMemeCoin->setTotalSupply($formData['form']['total_supply']);
 
                $userMemeCoin->setBurnAmount($floatVal * 0.75);
 
                $userMemeCoin->setRecycleAmount($floatVal * 0.25);
 
                $em->persist($userMemeCoin);
 
                $em->flush();
 
 
                $this->get('session')->getFlashBag()->add('success_messages', 'MemeCoin successfully created');
 
                return $this->redirect($this->generateUrl('dashboard_meme_creator'), 302);
 
              
 
            }
 
        }
 
 
 
        return $this->render('Dashboard/meme_purchase.html.twig',array(
 
            'userNotifications' => $userNotifications,
 
            'userMessages' => $userMessages,
 
            'user' =>  $user,
 
        ));
 
    }
 
 
 
 
 
    #[Route("/tracker", name:"dashboard_tracker")]
 
    public function trackerAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
 
 
        return $this->render('Dashboard/tracker.html.twig',array(
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'purchaseBonus' => $pb,
 
            'tokenDollarValue' => $tokenDollarValue,
 
            'user' =>  $user,
 
               'title' => 'ETF Portfolio Tracker',  
 
        ));
 
    }
 
 
#[Route("/burn", name:"dashboard_burn")]
 
public function burnAction(Request $request, AuthService $authService)
 
{
 
    if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
    $user = $authService->getUser();
 
    $em = $this->getDoctrine()->getManager();
 
 
    $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
    $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
    $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
    $pb = $em->getRepository(BonusEntity::class)->findOneBy(['code' => 'PB']);
 
 
    // ðŸ”¹ Total burned (all users)
 
    $totalBurned = (int) $em->createQueryBuilder()
 
        ->select('COALESCE(SUM(ua.amount), 0)')
 
        ->from(\App\Entity\UserAdjustedTokenEntity::class, 'ua')
 
        ->where('ua.reason = :reason')
 
        ->setParameter('reason', 'burn')
 
        ->getQuery()
 
        ->getSingleScalarResult();
 
    // ðŸ”¹ User's burned
 
    $userBurned = (int) $em->createQueryBuilder()
 
        ->select('COALESCE(SUM(ua.amount), 0)')
 
        ->from(\App\Entity\UserAdjustedTokenEntity::class, 'ua')
 
        ->where('ua.reason = :reason AND ua.user = :user')
 
        ->setParameter('reason', 'burn')
 
        ->setParameter('user', $user)
 
        ->getQuery()
 
        ->getSingleScalarResult();
 
 
    // ðŸ”¹ Remaining supply
 
 
        $totalBurned = (int) $em->createQueryBuilder()
 
        ->select('COALESCE(SUM(ua.amount), 0)')
 
        ->from(\App\Entity\UserAdjustedTokenEntity::class, 'ua')
 
        ->where('ua.reason = :reason')
 
        ->setParameter('reason', 'burn')
 
        ->getQuery()
 
        ->getSingleScalarResult();
 
 
        $recentUserBurneds = $em->createQueryBuilder()
 
            ->select('ua.amount, u.email')
 
            ->from(\App\Entity\UserAdjustedTokenEntity::class, 'ua')
 
            ->leftJoin('ua.user', 'u') 
 
            ->where('ua.reason = :reason')
 
            ->setParameter('reason', 'burn')
 
            ->orderBy('ua.id', 'DESC') 
 
            ->setMaxResults(10)
 
            ->getQuery()
 
            ->getResult();
 
 
 
    $initialSupply = 200000000000; // adjust this constant
 
    $remainingSupply = $initialSupply - $totalBurned;
 
 
    return $this->render('Dashboard/burn.html.twig', [
 
        'userNotifications' => $userNotifications,
 
        'userMessages' => $userMessages,
 
        'purchaseBonus' => $pb,
 
        'tokenDollarValue' => $tokenDollarValue,
 
        'user' => $user,
 
        'min_order' => 100,
 
        'title' => 'XRPV Burn Protocol',
 
        'totalBurned' => $totalBurned,
 
        'remainingSupply' => $remainingSupply,
 
        'userBurned' => $userBurned,
 
        'recentBurneds' => $recentUserBurneds
 
    ]);
 
}
 
 
 
 
#[Route("/burnconfirm", name:"dashboard_burnconfirm")]
 
public function burnconfirmAction(Request $request, AuthService $authService)
 
{
 
    if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
    $user = $authService->getUser();
 
    $em = $this->getDoctrine()->getManager();
 
    $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
    $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
    $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
    $pb = $em->getRepository(BonusEntity::class)->findOneBy(['code' => 'PB']);
 
 
    if ($request->isMethod('GET')) {
 
        $burnAmount = (int) $request->query->get('burn_amount', 0);
 
 
        return $this->render('Dashboard/burnconfirm.html.twig', [
 
            'userNotifications' => $userNotifications,
 
            'userMessages' => $userMessages,
 
            'purchaseBonus' => $pb,
 
            'tokenDollarValue' => $tokenDollarValue,
 
            'user' => $user,
 
            'burnAmount' => $burnAmount,
 
            'title' => 'XRPV Burn Confirm',
 
        ]);
 
    }
 
 
    if ($request->isMethod('POST')) {
 
        $burnAmount = (int) $request->request->get('burn_amount', 0);
 
        $currentBalance = $user->totalBalance();
 
 
        if ($burnAmount > 0 && $burnAmount <= $currentBalance) {
 
            $burn = new UserAdjustedTokenEntity();
 
            $burn->setUser($user);
 
            $burn->setAmount($burnAmount);  
 
            $burn->setReason('Burn');        
 
            $burn->setCreatedAt(new \DateTime());
 
 
            $em->persist($burn);
 
            $em->flush();
 
 
            $this->addFlash('burn_success', '🔥 You successfully burned '.number_format($burnAmount).' XRPV!');
 
            return $this->redirectToRoute('dashboard_index');
 
        }
 
 
        $this->addFlash('burn_error', 'Invalid burn amount.');
 
        return $this->redirectToRoute('dashboard_burn');
 
    }
 
}
 
 
 
       #[Route("/referral_media", name: "dashboard_project_media")]
 
    public function projectMediaAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
 
 
        return $this->render('Dashboard/project_media.html.twig',array(
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'purchaseBonus' => $pb,
 
            'tokenDollarValue' => $tokenDollarValue,
 
            'user' =>  $user,
 
            'title' => 'Referral Media AiETF Token',   
 
            'page_header' => 'AiEFT Referral Media'
 
 
        ));
 
    }
 
 
    #[Route("/project_statistics", name:"dashboard_project_statistics")]
 
    public function projectStatisticsAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
 
 
        return $this->render('Dashboard/project_statistics.html.twig',array(
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'purchaseBonus' => $pb,
 
            'tokenDollarValue' => $tokenDollarValue,
 
            'user' =>  $user,
 
        ));
 
    }
 
 
    #[Route("/walletholdings", name:"dashboard_walletholdings")]
 
    public function walletholdingsAction(Request $request, AuthService $authService, BlockIoService $blockIoService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        $sevenDaysOrder = $em->getRepository(UserEntity::class)->userLast7DaysOrderStatistics($user);
 
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
        $cryptoPrice = [
 
            'btc' => $blockIoService->getNetworkDetails('btc'),
 
            'eth' =>  $blockIoService->getNetworkDetails('eth'),
 
            'bnb' =>  $blockIoService->getNetworkDetails('bnb')
 
 
        ];
 
 
 
        return $this->render('Dashboard/walletholdings.html.twig',array(
 
            'page_title' => 'Account Activity',
 
            'userNotifications' => $userNotifications,
 
            'userMessages' => $userMessages,
 
            'purchaseBonus' => $pb,
 
            'tokenDollarValue' => $tokenDollarValue,
 
            'user' =>  $user,
 
            'cryptoPrice' => $cryptoPrice,
 
            'sevenDaysOrder' => $sevenDaysOrder
 
 
        ));
 
    }       
 
    
 
    
 
    #[Route("/stages", name:"dashboard_stages")]
 
    public function stagesAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
 
                 $stagePurchase = $em->getRepository(UserOrderTokenEntity::class)->stagePurchase();
 
       $totalOrder  = $stagePurchase['stagePurchase'];
 
           $totalBonus = $em->getRepository(UserBonusTokenEntity::class)->totalBonus();
 
 
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
 
 
        return $this->render('Dashboard/stages.html.twig',array(
 
            'page_title' => 'Project Stages',
 
            'userNotifications' => $userNotifications,
 
            'userMessages' => $userMessages,
 
            'purchaseBonus' => $pb,
 
            'tokenDollarValue' => $tokenDollarValue,
 
            
 
            'totalOrder'=> $totalOrder ? $totalOrder : 0,
 
            'tokenDisctributedall' => 10000000000 - $totalOrder - ($totalBonus['amt'] ? $totalBonus['amt'] : 0),
 
 
            'user' =>  $user,
 
 
        ));
 
    }       
 
    
 
    
 
   #[Route("/account_activity", name:"dashboard_account_activity")]
 
    public function accountActivityAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
 
        $orders = $em->getRepository(UserOrderTokenEntity::class)->findBy([
 
            'user' => $user->getId()
 
        ]);
 
 
        $bonuses = $em->getRepository(UserBonusTokenEntity::class)->findBy([
 
            'user' => $user->getId()
 
        ]);
 
 
        return $this->render('Dashboard/account_activity.html.twig',array(
 
            'title' => 'Transactions AiETF Token',   
 
            'orders' => $orders,
 
            'user' => $user,
 
            'bonuses' => $bonuses,
 
            'page_header' => 'Transactions & Bonuses'
 
 
        ));
 
    }    
 
 
   #[Route("/callisto_network", name:"dashboard_callisto_network")]
 
    public function callisto_networkAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        //$tokenBtcValue = $this->getParameter('token_btc_value');
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        if($request->getMethod() == 'POST'){
 
 
            $address = $request->get('address');
 
            
 
            $user->setCloAddress($address);
 
            $em->flush();
 
            $this->get('session')->getFlashBag()->add('success_messages', 'Callisto Network Address successfully updated.');
 
            return $this->redirect($this->generateUrl('dashboard_profile'),302);
 
 
        }
 
        return $this->render('Dashboard/callisto_network.html.twig',array(
 
            'page_title' => 'Buy Tokens',
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'user' => $user
 
        ));
 
    }
 
 
   #[Route("/order_preview", name:"dashboard_order_preview")]
 
    public function order_previewAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $em = $this->getDoctrine()->getManager();
 
        $tokenAmt = 0;
 
        $totalDue = 0;
 
 
        if($request->getMethod() == 'POST'){
 
 
            $order = $request->request->get('order');
 
            $errors = array();
 
 
            $pendingOrderCtr = $em->getRepository(UserOrderTokenEntity::class)->pendingOrderCtr($authService->getUser());
 
            // if(floatval($order['amount']) > 500){
 
 
            //     $errors[] = 'Maximum amount is 500,000.';
 
            // }
 
           if(floatval($pendingOrderCtr[0]['orderCtr']) > 5){
 
 
                $errors[] = 'Please complete your pending order to make a new order.';
 
           }
 
 
            if(floatval($order['amount']) < 100){
 
 
                $errors[] = 'Minimum amount is 25.';
 
            } 
 
 
            if(count($errors)){
 
 
               foreach($errors as $error) {
 
                 
 
                    $this->get('session')->getFlashBag()->add('error_messages', $error);
 
                }
 
 
                return $this->redirect($this->generateUrl('dashboard_buy_token'),302);
 
            
 
 
            } else {
 
 
                    $tokenAmt = str_replace(',', '', $order['amount']);
 
                    $totalDue = str_replace(',', '',$order['due_amount']);
 
                    $session = $this->container->get('session');
 
 
                    $btcToDollar = $session->get('btr');
 
 
                    $tokenBtcValue= number_format($this->container->getParameter('token_usd_value') / $btcToDollar , 8, '.', '');
 
                    $amountDue = $tokenAmt * $tokenBtcValue;
 
 
                    if(intval($totalDue) != intval(number_format($amountDue,8,'.',''))){
 
                       
 
                        throw new \Exception();
 
                    }
 
            }
 
        }
 
 
        $user = $authService->getUser();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        return $this->render('Dashboard/order_preview.html.twig',array(
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'price' => $tokenBtcValue,
 
            'totalAmt' => $tokenAmt,
 
            'totalDue' => $totalDue,
 
            'page_title' => 'Order Preview',
 
 
        ));
 
    }
 
 
   #[Route("/checkout_order_action", name:"dashboard_checkout_order_action")]
 
    public function checkout_order_actionAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
 
        if($request->getMethod() == 'POST'){
 
 
            $order = $request->request->get('order');
 
            $tokenAmt = $order['amt'];
 
            $session = $this->container->get('session');
 
 
            $tokenBtcValue= number_format($this->container->getParameter('token_usd_value') / $session->get('btr'), 8, '.', '');
 
            $amountDue = $tokenAmt * $tokenBtcValue;
 
 
            $blockIoService = $this->get('fullMoon.blockIoService');
 
 
            $em = $this->getDoctrine()->getManager();
 
 
 
            $label = time() . '-' . $this->generateRandomString();
 
            $newAddress = $blockIoService->getNewAddress($label);
 
            $walletAddress = $newAddress->data->address;  
 
 
            $newOrderToken = new UserOrderTokenEntity();
 
            $newOrderToken->setTokenValue($tokenBtcValue);
 
            $newOrderToken->setTokenAmount($tokenAmt);
 
            $newOrderToken->setLabel($label);
 
            $newOrderToken->setAddress($walletAddress);
 
            $newOrderToken->setAmount($amountDue);
 
            $newOrderToken->setNetwork('BTC');
 
            $newOrderToken->setUser($authService->getUser());
 
            $em->persist($newOrderToken);
 
            $em->flush();
 
 
            $notification = new NotificationEntity();
 
            $notification->setType('Token Order Placed');
 
            $notification->setMessage('Your Token Order  ' .$tokenAmt . 'Has Been Received');
 
            $notification->setUser($authService->getUser());
 
            $em->persist($notification);
 
            $em->flush();
 
 
            return $this->redirect($this->generateUrl('dashboard_order_details' ,array('id' => $newOrderToken->getIdEncoded())),302);
 
 
        } else {
 
 
            throw new \Exception();
 
        }
 
    }
 
 
   #[Route("/order_details/{id}", name:"dashboard_order_details")]
 
    public function order_detailsAction(Request $request, $id, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $em = $this->getDoctrine()->getManager();
 
 
        $user = $authService->getUser();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        return $this->render('Dashboard/order_details.html.twig',array(
 
      'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
                 'page_title' => 'Order Details',
 
           'order' => $em->getRepository(UserOrderTokenEntity::class)->find(base64_decode($id)) 
 
        ));
 
    }
 
 
   #[Route("/settings", name:"dashboard_profile")]
 
    public function profileAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
        $receiveMsgs  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
        if($request->getMethod() == 'POST'){
 
 
            $pr = $request->get('user');
 
            $errors = array();
 
 
            if(!count($errors)){
 
 
                if(isset($pr['passowrd']) && !empty($pr['password'])){
 
                    $user->setPassword($authService->better_crypt(md5($registrationForm['password']), 15));
 
                }
 
 
                // if(isset($pr['2fa'])){
 
 
                //     if(!$user->getHasEnabledTwoFa()){
 
 
                //            $enabledTwoFa = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'FETFAB'));
 
                //            $bonus = new UserBonusTokenEntity();
 
                //            $bonus->setUser($user);
 
                //            $bonus->setBonus($enabledTwoFa);
 
                //            $bonus->setAmount($enabledTwoFa->getBonusToken());
 
                //            $em->persist($bonus);
 
 
                //            $user->setHasEnabledTwoFa(true);
 
                //            $em->flush();
 
 
                //            $notification = new NotificationEntity();
 
                //            $notification->setType('Enaled 2Fa Rewards');
 
                //            $notification->setMessage('You just have received ' . $enabledTwoFa->getBonusToken() . ' Token for enabled your 2Fa.');
 
                //            $notification->setUser($user);
 
                //            $em->persist($notification);
 
                //            $em->flush();
 
                       
 
                //     }
 
 
                //     $user->setTwoFa(true);
 
                // } else {
 
                //     $user->setTwoFa(false);
 
                // }
 
                $user->setTwoFa(isset($pr['2fa']) ? true : false);
 
                $user->setIsNewsletterSubscriber(isset($pr['isNewsLetterSubscriber']) ? true : false);
 
                $user->setFirstName($pr['first_name']);
 
                $user->setLastName($pr['last_name']);
 
                $user->setAddress1($pr['address1']);
 
                $user->setCity($pr['city']);
 
                $user->setZipCode($pr['zip_code']);
 
                $user->setCountry($pr['country']);
 
 
                $em->flush();
 
                $this->get('session')->getFlashBag()->add('success_messages', 'Profile successfully updated.');
 
 
 
            } else {
 
 
                foreach($errors as $error) {
 
                 
 
                    $this->get('session')->getFlashBag()->add('error_messages', $error);
 
                }
 
            }
 
        }
 
 
        return $this->render('Dashboard/profile.html.twig',array(
 
 
            'user' => $user,
 
            'page_title' => 'Profile',
 
            'messages' => $receiveMsgs,
 
            'title' => 'Profile AiETF Token',   
 
            'page_header' => 'AiEFT Profile Settings'
 
        ));
 
    }
 
 
       #[Route("/security", name:"dashboard_security")]
 
    public function securityAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        if($request->getMethod() == 'POST'){
 
 
            $pr = $request->get('user');
 
            $errors = array();
 
 
            if($user->getPassword() !==  crypt(md5($pr['current_password']), $user->getPassword())){
 
 
                $errors[] = 'Current Password Is Incorrect.'; 
 
            } else {
 
 
                if(isset($pr['password']) && !empty($pr['password'])){
 
 
                    if(!$em->getRepository(UserEntity::class)->validatePassword($pr['password'])){
 
                      
 
                        $errors[] = 'Password should be at least 8 characters in length and should include at least one upper case letter, one number, and one special character.';
 
                    } else {
 
    
 
                        if($pr['password'] != $pr['confirm_password']){
 
                            $errors[] = 'Password is not match';
 
                        }
 
                    }
 
                }
 
            }
 
            
 
 
            if(!count($errors)){
 
 
                if(isset($pr['passowrd']) && !empty($pr['password'])){
 
                    $user->setPassword($authService->better_crypt(md5($registrationForm['password']), 15));
 
                }
 
 
                if(isset($pr['2fa'])){
 
 
                    if(!$user->getHasEnabledTwoFa()){
 
 
                           $enabledTwoFa = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'FETFAB'));
 
                           $bonus = new UserBonusTokenEntity();
 
                           $bonus->setUser($user);
 
                           $bonus->setBonus($enabledTwoFa);
 
                           $bonus->setAmount($enabledTwoFa->getBonusToken());
 
                           $em->persist($bonus);
 
 
                           $user->setHasEnabledTwoFa(true);
 
                           $em->flush();
 
 
                           $notification = new NotificationEntity();
 
                           $notification->setType('Enaled 2Fa Rewards');
 
                           $notification->setMessage('You just have received ' . $enabledTwoFa->getBonusToken() . ' Token for enabled your 2Fa.');
 
                           $notification->setUser($user);
 
                           $em->persist($notification);
 
                           $em->flush();
 
                       
 
                    }
 
 
                    $user->setTwoFa(true);
 
                } else {
 
                    $user->setTwoFa(false);
 
                }
 
 
                $em->flush();
 
                $this->get('session')->getFlashBag()->add('success_messages', 'Security successfully updated.');
 
 
 
            } else {
 
 
                foreach($errors as $error) {
 
                 
 
                    $this->get('session')->getFlashBag()->add('error_messages', $error);
 
                }
 
            }
 
        }
 
 
        return $this->render('Dashboard/security.html.twig',array(
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'user' => $user,
 
            'page_title' => 'Security'
 
        ));
 
    }
 
 
   #[Route("/transaction", name:"dashboard_transaction")]
 
    public function transactionAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
       $user = $authService->getUser();
 
       $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
    
 
    
 
        return $this->render('Dashboard/transaction.html.twig',array(
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'page_title' => 'Transaction',
 
            'user' =>  $user
 
        ));
 
    }
 
    
 
     #[Route("/global", name:"dashboard_global")]
 
    public function globalAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
            $em = $this->getDoctrine()->getManager();
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
        $stagePurchase = $em->getRepository(UserOrderTokenEntity::class)->stagePurchase();
 
 
        $em = $this->getDoctrine()->getManager();
 
        $user = $authService->getUser();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $pb = $em->getRepository(BonusEntity::class)->findOneBy(array('code' => 'PB'));
 
 
        $totalUser = $em->getRepository(UserEntity::class)->userCount();
 
       $totalOrder  = $stagePurchase['stagePurchase'];
 
         $referralTotalEarnings = $em->getRepository(UserEntity::class)->refEarnings($user);
 
        $userReferral1 = $em->getRepository(UserEntity::class)->levelReferral($user, 1);
 
       $totalBonus = $em->getRepository(UserBonusTokenEntity::class)->totalBonus();
 
       $totaluserslist = $em->getRepository(UserEntity::class)->findAll();
 
       $totalreferrallist = $em->getRepository(UserEntity::class)->findAll();
 
       
 
       
 
       
 
       $totalusertokens = $em->getRepository(UserOrderTokenEntity::class)->findAll();
 
 
 
  
 
        return $this->render('Dashboard/global.html.twig',array(
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'user' => $user,
 
            'tokenDollarValue' => $tokenDollarValue,
 
            'pb' => $pb,
 
            'totalUser' => $totalUser,
 
            'totalOrder'=> $totalOrder ? $totalOrder : 0,
 
            'tokenRaised' => $totalOrder ? $totalOrder * $tokenDollarValue : 0,
 
            'refTotalEarnings' => $referralTotalEarnings,
 
            'level1Referrals' => $userReferral1,
 
            'page_title' => 'Global Rankings',
 
            'totaluserslist' => $totaluserslist,
 
            'totalreferrallist' => $totalreferrallist,
 
            'totalusertokens' => $totalusertokens,
 
            'tokenDisctributed' => $totalOrder + ($totalBonus['amt'] ? $totalBonus['amt'] : 0)
 
 
    
 
        ));
 
    }
 
    
 
  
 
  
 
   #[Route("/my_reward", name:"dashboard_my_reward")]
 
    public function my_rewardAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
               $user = $authService->getUser();
 
               $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        return $this->render('Dashboard/my_reward.html.twig',array(
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'page_title' => 'My Rewards'
 
        ));
 
    }
 
 
 
       #[Route("/web5d", name:"web5_dollar")]
 
    public function dashboard_web5dollarAction(Request $request, AuthService $authService, BlockIoService $blockIoService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
     $btcPrice = $blockIoService->getNetworkPrice('btc');
 
       $ethPrice = $blockIoService->getNetworkPrice('eth');
 
    
 
               $user = $authService->getUser();
 
               $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        return $this->render('Dashboard/web5d.html.twig',array(
 
            
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'user' => $user,
 
            'tokenDollarValue' => $tokenDollarValue,
 
            'pb' => $pb,
 
            'btcPrice' => $btcPrice,
 
            'ethPrice' => $ethPrice,
 
            'totalUser' => $totalUser,
 
            'totalOrder'=> $totalOrder ? $totalOrder : 0,
 
            'tokenRaised' => $totalOrder ? $totalOrder * $tokenDollarValue : 0,
 
        
 
            
 
            
 
            
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'page_title' => 'Web5Dollar',
 
            'user' => $user
 
        ));
 
    }
 
 
 
       #[Route("/card_payment", name:"dashboard_card_payment")]
 
    public function dashboard_card_paymentAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
               $user = $authService->getUser();
 
               $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        return $this->render('Dashboard/card_payment.html.twig',array(
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'page_title' => 'My Rewards',
 
            'user' => $user
 
        ));
 
    }
 
 
 
   #[Route("/my_referrals", name:"dashboard_my_referrals")]
 
 
    public function my_referralsAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
 
        $rb  = $em->getRepository(BonusEntity::class)->findOneBy(array( 'code' => 'PR'));
 
        $rp  = $em->getRepository(BonusEntity::class)->findOneBy(array( 'code' => 'Purchase - PRSU'));
 
 
        $referralTotalEarnings = $em->getRepository(UserEntity::class)->refEarnings($user);
 
        $referrals = $em->getRepository(UserEntity::class)->referralBonusByReferrentUser($user);
 
        $tokenDollarValue = $this->getParameter('app.token_dollar_value');
 
        $top5Referrals = $em->getRepository(ReferralEntity::class)->top5Referral();
 
 
        return $this->render('Dashboard/my_referrals.html.twig',array(
 
            'page_header' => 'Referral Center',
 
            'title' => 'My Referrals AiETF Token',   
 
            'user' =>  $user,
 
            'rb' => $rb,
 
            'rp' => $rp,            
 
            'referrals' => $referrals,
 
            'tokenDollarValue' =>  $tokenDollarValue,
 
            'top5Referrals' => $top5Referrals
 
            
 
 
        ));
 
    }
 
 
   #[Route("/referral_center", name:"dashboard_referral_center")]
 
    public function referral_centerAction(Request $request, AuthService $authService)
 
    {
 
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $em = $this->getDoctrine()->getManager();
 
        $user = $authService->getUser();
 
 
        $refCtr = $em->getRepository(UserEntity::class)->levelOneRefCtr($user);
 
        $secRefCtr = $em->getRepository(UserEntity::class)->levelTwoRefCtr($user);
 
        $thiRefCtr = $em->getRepository(UserEntity::class)->levelThirdRefCtr($user);
 
        $refEarnings = $em->getRepository(UserEntity::class)->refEarnings($user);
 
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        return $this->render('Dashboard/referral_center.html.twig',array(
 
            'page_title' => 'Referral Center',
 
            'userNotifications' => $userNotifications,
 
            'userMessages' => $userMessages,
 
            'user' => $user,
 
            'refCtr' => $refCtr,
 
            'secRefCtr' => $secRefCtr,
 
            'thiRefCtr' => $thiRefCtr,
 
            'refEarnings' => $refEarnings
 
        ));
 
    }
 
 
       #[Route("/message", name:"dashboard_message")]
 
    public function messageAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
        $receiveMsgs  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        return $this->render('Dashboard/message.html.twig',array(
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'page_title' => 'Messages',
 
            'user' =>  $user,
 
            'messages' => $receiveMsgs
 
        ));
 
    }
 
 
      #[Route("/message/view/{message_id}", name:"dashboard_message_view")]
 
    public function message_viewAction(Request $request, AuthService $authService, $message_id)
 
    {
 
 
        
 
       
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $message = $em->getRepository(MessageEntity::class)->find($message_id);
 
 
        if(!$message){
 
            return $this->redirect($this->generateUrl('dashboard_message'), 302);
 
        } 
 
 
        $message->setStatus('Read');
 
        $em->flush();
 
 
        return $this->render('Dashboard/message_view.html.twig',array(
 
            'userNotifications' => $userNotifications,
 
            'page_title' => 'Message View',
 
            'user' =>  $user,
 
            'msg' => $message
 
        ));
 
    }
 
 
    #[Route("/message/form/{receiver_id}", name:"dashboard_message_form")]
 
    public function message_formAction(Request $request, AuthService $authService, $receiver_id)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
        $receiver = $em->getRepository(UserEntity::class)->find($receiver_id);
 
 
        if(!$receiver){
 
            return $this->redirect($this->generateUrl('dashboard_message'), 302);
 
        } 
 
 
        $msg = null;
 
        if($request->getMethod() === 'POST'){
 
            
 
            $msg = $request->get('message');
 
 
            $newMsg = new MessageEntity();
 
            $newMsg->setUser($user);
 
            $newMsg->setReceiver($receiver);
 
            $newMsg->setMessage($msg['message']);
 
            $em->persist($newMsg);
 
            $em->flush();
 
            
 
 
            $newNotif = new NotificationEntity();
 
            $newNotif->setType(1);
 
            $newNotif->setMessage('You have new Message From ' . $user->getFullName());
 
            $newNotif->setUser($receiver);
 
            $em->persist($newNotif);
 
            $em->flush();
 
 
            $this->get('session')->getFlashBag()->add('success_messages', 'Your message has been successfully sent to the user.');
 
            return $this->redirect($this->generateUrl('dashboard_message'), 302);
 
 
        }
 
 
        return $this->render('Dashboard/message_form.html.twig',array(
 
            'userNotifications' => $userNotifications,
 
            'userMessages' => $userMessages,
 
            'page_title' => 'Sent Message To: '.  $receiver->getFullName(),
 
            'user' =>  $user,
 
            'receiver_id' => $receiver_id
 
        ));
 
    }
 
 
   #[Route("/support_center", name:"dashboard_support_center")]
 
    public function support_centerAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $em = $this->getDoctrine()->getManager();
 
        $user = $authService->getUser();
 
 
        $supportTicketCtr = $em->getRepository(SupportTicketEntity::class)->supportTicketCtr($user);
 
        $supportTicketUnreadResCtr = $em->getRepository(SupportTicketEntity::class)->supportTicketWithNewReplyCtr($user);
 
 
        if($request->getMethod() === 'POST'){
 
 
            $params = $request->get('field');
 
 
            $errors = array();
 
            if(empty($params['msg'])){
 
                $errors[] = 'Please Put Your Message.';
 
            }
 
 
            if(empty($params['title'])){
 
                $errors[] = 'Please Put A Title To Your Question.';
 
            }
 
 
            if(!count($errors)){
 
 
                $support = new SupportTicketEntity();
 
                $support->setUser($user);
 
                $support->setTitle($params['title']);
 
                $support->setMessage($params['msg']);
 
                $em->persist($support);
 
                $em->flush();
 
 
                $this->get('session')->getFlashBag()->add('success_messages', 'Thank You For Connecting With Us We Will Be Back To You As Soon As Possible.');
 
 
            } else {
 
 
                foreach($errors as $error) {
 
                    $this->get('session')->getFlashBag()->add('error_messages', $error);
 
                }
 
            }
 
        }
 
 
               $user = $authService->getUser();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        return $this->render('Dashboard/support_center.html.twig',array(
 
            'page_title' => 'Support Center',
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'user' => $user,
 
            'supportTicketCtr' => $supportTicketCtr,
 
            'supportTicketUnreadResCtr' => $supportTicketUnreadResCtr
 
        ));
 
    }
 
 
       #[Route("/support_ticket/details/{id}", name:"dashboard_support_ticket_details")]
 
    public function support_ticket_detailsAction(Request $request, $id, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $em = $this->getDoctrine()->getManager();
 
        $user = $authService->getUser();
 
 
        $supportTicketCtr = $em->getRepository(SupportTicketEntity::class)->supportTicketCtr($user);
 
        $supportTicketUnreadResCtr = $em->getRepository(SupportTicketEntity::class)->supportTicketWithNewReplyCtr($user);
 
 
        $supportTicket = $em->getRepository(SupportTicketEntity::class)->find(base64_decode($id));
 
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
        return $this->render('Dashboard/support_ticket_details.html.twig',array(
 
            'page_title' => 'Support Center',
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'user' => $user,
 
            'supportTicket' => $supportTicket,
 
            'supportTicketCtr' => $supportTicketCtr,
 
            'supportTicketUnreadResCtr' => $supportTicketUnreadResCtr
 
        ));
 
    }
 
 
   #[Route("/promotional_materials", name:"dashboard_promotional_materials")]
 
    public function support_promotional_materialsAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $em = $this->getDoctrine()->getManager();
 
        $user = $authService->getUser();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        return $this->render('Dashboard/promotional_materials.html.twig',array(
 
            'page_title' => 'Promotional Materials',
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'user' => $user
 
        ));
 
    }
 
 
   #[Route("/how_to", name:"dashboard_how_to")]
 
    public function how_toAction(Request $request)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $em = $this->getDoctrine()->getManager();
 
        $user = $authService->getUser();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        return $this->render('Dashboard/how_to.html.twig',array(
 
            'page_title' => 'How To Articles',
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'user' => $user
 
        ));
 
    }
 
    
 
   #[Route("/support_ticket/response/form/{supportTicketId}", name:"dashboard_support_ticket_response_form")]
 
    public function support_ticket_response_formAction(Request $request, $supportTicketId, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $em = $this->getDoctrine()->getManager();
 
        $user = $authService->getUser();
 
 
        $supportTicket = $em->getRepository(SupportTicketEntity::class)->find($supportTicketId);
 
 
        if($request->getMethod() === 'POST'){
 
 
            $params = $request->get('field');
 
 
            $errors = array();
 
            if(empty($params['msg'])){
 
                $errors[] = 'Please Put Your Message.';
 
            }
 
 
            if(!count($errors)){
 
 
                $response = new SupportTicketResponseEntity();
 
                $response->setSupportTicket($supportTicket);
 
                $response->setMessage($params['msg']);
 
                $response->setUser($user);
 
                $em->persist($response);
 
                $em->flush();
 
 
                $this->get('session')->getFlashBag()->add('success_messages', 'Thank You For Connecting With Us We Will Be Back To You As Soon As Possible.');
 
                return  $this->redirect($this->generateUrl('dashboard_support_ticket_details', array('id' => base64_encode($supportTicketId))),302);
 
 
            } else {
 
 
                foreach($errors as $error) {
 
                    $this->get('session')->getFlashBag()->add('error_messages', $error);
 
                }
 
            }
 
        }
 
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
 
        return $this->render('Dashboard/support_ticket_response_form.html.twig',array(
 
            'page_title' => 'Support Center',
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'user' => $user,
 
            'supportTicket' => $supportTicket
 
        ));
 
    }
 
 
    #[Route("/notification", name:"dashboard_notification")]
 
    public function notificationAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $user = $authService->getUser();
 
        $em = $this->getDoctrine()->getManager();
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
        
 
        return $this->render('Dashboard/notification.html.twig',array(
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'page_title' => 'My Notification'
 
        ));
 
    }
 
 
          #[Route("/notification/details/{id}", name:"dashboard_notification_details")]
 
    public function notification_detailsAction(Request $request, $id, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $em = $this->getDoctrine()->getManager();
 
        $user = $authService->getUser();
 
 
        $notification = $em->getRepository(NotificationEntity::class)->find(base64_decode($id));
 
        $notification->setStatus('Read');
 
        $em->flush();
 
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
        return $this->render('Dashboard/notification_details.html.twig',array(
 
            'page_title' => 'Support Center',
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'user' => $user,
 
            'notification' => $notification
 
        ));
 
    }
 
 
   #[Route("/kyc_application", name:"dashboard_kyc_application")]
 
    public function kyc_applicationAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $em = $this->getDoctrine()->getManager();
 
        $user = $authService->getUser();
 
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
        return $this->render('Dashboard/kyc_application.html.twig',array(
 
            'page_title' => 'Kyc Application',
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'user' => $user
 
        ));
 
    }
 
 
    
 
   #[Route("/live_chat", name:"dashboard_livechat")]
 
    public function livechatAction(Request $request, AuthService $authService)
 
    {
 
        return $this->render('Dashboard/livechat.html.twig' ,array(
 
            'page_title' => 'Kyc Application',
 
            'userNotifications' => $userNotifications,
 
          'userMessages' => $userMessages,
 
                 'user' => $user
 
        ));
 
    }
 
 
   #[Route("/kyc_application_form", name:"dashboard_kyc_application_form")]
 
    public function kyc_application_formAction(Request $request, AuthService $authService)
 
    {
 
 
        
 
        if(!$authService->isLoggedIn()) return $authService->redirectToLogin();
 
 
        $em = $this->getDoctrine()->getManager();
 
        $user = $authService->getUser();
 
 
        if($request->getMethod() == 'POST'){
 
 
            $rp = $request->request->all();
 
 
            $user->setKycStatus('For-Confirmation');
 
            $user->setFirstName($rp['kyc']['firstname']);
 
            $user->setLastName($rp['kyc']['lastname']);
 
            $user->setEmail($rp['kyc']['email']);
 
            $user->setPhoneNo($rp['kyc']['no']);
 
            $user->setBirthDate($rp['kyc']['birthdate']);
 
            $user->setNationality($rp['kyc']['nationality']);
 
            $user->setAddress1($rp['kyc']['address1']);
 
            $user->setAddress2($rp['kyc']['address2']);
 
            $user->setCity($rp['kyc']['city']);
 
            $user->setZipCode($rp['kyc']['zip_code']);
 
 
            
 
            // if(isset($_FILES['kyc']) && !empty($_FILES['kyc']['tmp_name']['passport'])) {
 
 
            //     $basename : $user->getId() . '-' . time() . '.' . pathinfo($_FILES['kyc']['name']['passport'], PATHINFO_EXTENSION);
 
            //     $uploadFile = $user->getUploadRootDir() . '/' . $baseName;
 
 
            //     if(move_uploaded_file($_FILES['kyc']['tmp_name']['passport'], $uploadFile)) {
 
            //         $user->setIdFile($_FILES['kyc']['name']['passport']);
 
            //         $user->setIdFileParse($baseName);
 
            //         $user->setIdType('Passport');
 
            //     }
 
            // }   
 
 
            // if(isset($_FILES['kyc']) && !empty($_FILES['kyc']['tmp_name']['national_id'])) {
 
 
            //     $basename : $user->getId() . '-' . time() . '.' . pathinfo($_FILES['kyc']['name']['national_id'], PATHINFO_EXTENSION);
 
            //     $uploadFile = $user->getUploadRootDir() . '/' . $baseName;
 
 
            //     if(move_uploaded_file($_FILES['kyc']['tmp_name']['national_id'], $uploadFile)) {
 
            //         $user->setIdFile($_FILES['kyc']['name']['national_id']);
 
            //         $user->setIdFileParse($baseName);
 
            //         $user->setIdType('National Id');
 
            //     }
 
            // }
 
            
 
            // if(isset($_FILES['kyc']) && !empty($_FILES['kyc']['tmp_name']['driver_license'])) {
 
 
            //     $basename : $user->getId() . '-' . time() . '.' . pathinfo($_FILES['kyc']['name']['driver_license'], PATHINFO_EXTENSION);
 
            //     $uploadFile = $user ->getUploadRootDir() . '/' . $baseName;
 
 
            //     if(move_uploaded_file($_FILES['kyc']['tmp_name']['driver_license'], $uploadFile)) {
 
            //         $user->setIdFile($_FILES['kyc']['name']['driver_license']);
 
            //         $user->setIdFileParse($baseName);
 
            //         $user->setIdType('Driver License');
 
            //     }
 
            // }
 
 
            $em->flush();
 
 
            return $this->redirect($this->generateUrl('dashboard_kyc_application'),302);
 
        }
 
 
        $userNotifications  = $em->getRepository(NotificationEntity::class)->newNotifications($user);
 
        $userMessages  = $em->getRepository(MessageEntity::class)->receiveMessages($user);
 
        return $this->render('Dashboard/kyc_application_form.html.twig',array(
 
            'page_title' => 'Kyc Application Form',
 
       'userNotifications' => $userNotifications,
 
     'userMessages' => $userMessages,
 
            'user' => $user
 
        ));
 
    }
 
 
 
    private function generateRandomString($length = 6) {
 
       
 
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
 
        $charactersLength = strlen($characters);
 
        $randomString = '';
 
        $em = $this->getDoctrine()->getManager();
 
        for ($i = 0; $i < $length; $i++) {
 
            $randomString .= $characters[rand(0, $charactersLength - 1)];
 
        }
 
 
        $orderTokenAddressExists = $em->getRepository(UserOrderTokenEntity::class)->findOneBy(array('label' => $randomString));
 
        if($orderTokenAddressExists){
 
            $this->generateRandomString();
 
        }
 
 
        return $randomString;
 
    }
 
 
    
 
    private function compareByTimeStamp($time1, $time2)
 
    {
 
        if (strtotime($time1) < strtotime($time2))
 
            return 1;
 
        else if (strtotime($time1) > strtotime($time2)) 
 
            return -1;
 
        else
 
            return 0;
 
    }
 
 
    private function sdasdsa($em, $network, $blockIoService){
 
        
 
        $wallets = $em->getRepository(RecycledWalletEntity::class)->findBy(['network' => $network]);
 
 
        foreach($wallets as  $wallet){
 
 
            $wallet->setStatus('Available');
 
            $em->flush();
 
            
 
 
        }
 
 
        return $em->getRepository(RecycledWalletEntity::class)->findOneBy(array('status' => 'Available', 'network' => $network));
 
 
    }
 
}