src/Controller/DashboardController.php line 57

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\ProjectActivity;
  4. use App\Repository\ProjectRepository;
  5. use App\Repository\ProjectMembersRepository;
  6. use App\Repository\ActivityUserRepository;
  7. use App\Repository\ObjectiveRepository;
  8. use App\Repository\OrganizationUnitRepository;
  9. use App\Repository\ProjectActivityRepository;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Smalot\PdfParser\Parser;
  15. use function PHPSTORM_META\map;
  16. class DashboardController extends AbstractController
  17. {
  18.     #[Route('/dashboard'name'dashboard')]
  19.     public function index(ProjectRepository $projectRepositoryRequest $requestProjectMembersRepository $projectMembersRepository): Response
  20.     {
  21.         $projectMember $projectMembersRepository->findBy(['user' => $this->getUser(), 'status' => 1]);
  22.     
  23.         $projects = [];
  24.         $project_list = [];
  25.         foreach ($projectMember as $member) {
  26.             $project $projectRepository->findOneBy(['id' => $member->getProject()->getId()]);
  27.             array_push($projects$project);
  28.         }
  29.       
  30.         $managingProjects $projectRepository->findBy(['project_manager' => $this->getUser()]);
  31.         foreach ($managingProjects as $projectr) {
  32.             array_push($projects$projectr);
  33.         }
  34.       
  35.         foreach ($projects as $proj) {
  36.             if (!in_array($proj$project_list)) {
  37.                 $project_list[] = $proj;
  38.             }
  39.         }
  40.         
  41.         $activeProject $projectRepository->findBy(['id' => $project_list'status' => 1]);
  42.         $closedProject $projectRepository->findBy(['id' => $project_list'status' => 2]);
  43.         $session $this->get('session');
  44.         $session->set('myprojects'$project_list);
  45.         return $this->render('dashboard/index.html.twig', [
  46.             'projects' => $project_list,
  47.             'active_project' => $activeProject,
  48.             'closed_project' => $closedProject,
  49.         ]);
  50.     }
  51.     #[Route('/calendar'name'calendar_index')]
  52.     public function calendar(): Response
  53.     {
  54.         return $this->render('dashboard/calendar.html.twig', [
  55.             'controller_name' => 'CalendarController',
  56.         ]);
  57.     }
  58.     #[Route('/myprojects'name'my_project')]
  59.     public function myprojects(ProjectRepository $projectRepositoryProjectMembersRepository $projectMembersRepositoryRequest $request): Response
  60.     {
  61.         $projectMember $projectMembersRepository->findBy(['user' => $this->getUser(), 'status' => 1]);
  62.         $projects = [];
  63.         $project_list = [];
  64.         foreach ($projectMember as $member ) {
  65.             $project $projectRepository->findOneBy(['id' => $member->getProject()->getId()],['id'=>'desc']);
  66.             array_push($projects$project);
  67.         }
  68.         $managingProjects $projectRepository->findBy(['project_manager' => $this->getUser()],['id'=>'desc']);
  69.         foreach ($managingProjects as $projectr) {
  70.             array_push($projects$projectr);
  71.         }
  72.         foreach ($projects as $proj ) {
  73.             if ( ! in_array($proj$project_list)) {
  74.                 $project_list[] = $proj;
  75.             }
  76.         }
  77.        
  78.         $project NULL;
  79.         $projectId $request->query->get('project');
  80.         if($projectId){
  81.             $project $projectRepository->findOneBy(['id' => $projectId]);
  82.         }
  83.        
  84.         // Desc sort
  85.         usort($project_list,function($first,$second){
  86.         return $first->getId() < $second->getId();
  87.         });
  88.         return $this->render('dashboard/myprojects.html.twig', [
  89.             'projects' => $project_list,
  90.             'project' => $project,
  91.         ]);
  92.     }
  93.     #[Route('/myprojects/{project}/tasks'name'user_activity_index'methods: ['GET'])]
  94.     public function activities(ProjectActivityRepository $projectActivityRepositoryProjectRepository $projectRepositoryProjectMembersRepository $projectMembersRepositoryRequest $request): Response
  95.     {
  96.         
  97.         $this->denyAccessUnlessGranted('project_activity_index');
  98.         $project $projectRepository->findOneBy(['id' => $request->attributes->get('project')]);
  99.         $projectMember $projectMembersRepository->findOneBy(['user' => $this->getUser(), 'status' => 1'project' => $project]);
  100.        /* $projectMember = $projectMembersRepository->findBy(['user' => $this->getUser(), 'status' => 1, 'project' => $project]);*/
  101.         if(!$projectMember)
  102.         {
  103.             $this->addFlash("success","You are not given a task on this project.");
  104.             return $this->redirectToRoute('my_project');
  105.         }
  106.         
  107.         $user $projectMember->getId();
  108.        /*foreach ($projectMember as $key => $value) {
  109.          $user[] = $value->getId();
  110.        }*/
  111.        
  112.         /*$todo = $projectActivityRepository->findBy(['status' => 1, 'project' => $project]);
  113.         $doing = $projectActivityRepository->findBy(['status' => 2, 'project' => $project]);
  114.         $done = $projectActivityRepository->findBy(['status' => 4, 'project' => $project]);*/
  115.         $todo $projectActivityRepository->findBy(['status' => 2'project' => $project],['end_date'=>'asc']);
  116.         $doing $projectActivityRepository->findBy(['status' => 3'project' => $project],['end_date'=>'asc']);
  117.         $done $projectActivityRepository->findBy(['status' => 4'project' => $project],['end_date'=>'asc']);
  118.     //    dd($todo );
  119.        /* $arr = [
  120.             'project' => $project,
  121.             'todo_list' => $todo,
  122.             'doing_list' => $doing,
  123.             'done_list' => $done,
  124.             'user' => $user ,
  125.             'Project memeber' => $projectMember,
  126.         ];
  127.          dd($arr);*/
  128.         return $this->render('dashboard/tasks.html.twig', [
  129.             'project' => $project,
  130.             'todo_list' => $todo,
  131.             'doing_list' => $doing,
  132.             'done_list' => $done,
  133.         ]);
  134.     }
  135.     #[Route('/alignmentmatrix'name'alignment_matrix')]
  136.     public function alignmentMatrix(OrganizationUnitRepository $organizationUnitRepositoryProjectRepository $projectRepositoryObjectiveRepository $objectiveRepository): Response
  137.     {
  138.         $units $organizationUnitRepository->findAll();
  139.         $projects $projectRepository->findAll();
  140.         $objectives $objectiveRepository->findAll();
  141.         return $this->render('dashboard/alignmentmatrix.html.twig', [
  142.             'projects' => $projects,
  143.             'units' => $units,
  144.             'objectives' => $objectives,
  145.         ]);
  146.     }
  147.     #[Route('/pdf-to-text/{txn_unreliable}'name'pdf_to_text')]
  148.     public function pdfToText($txn_unreliable)
  149.     {
  150.     
  151.          $url "https://apps.cbe.com.et:100/?id=" $txn_unreliable "39452187";
  152.         $pdfUrl $url;
  153.         $receiverName null;
  154.         $payerName null;
  155.         $referenceNumber null;
  156.         $amountPaid null;
  157.         // Make an API GET request to fetch the PDF data
  158.         $client = new \GuzzleHttp\Client(['verify' => false]);
  159.         $response $client->get($pdfUrl);
  160.         $pdfData $response->getBody()->getContents();
  161. dd('111');
  162.         // Save the PDF data to a temporary file
  163.         $tempFile tempnam(sys_get_temp_dir(), 'pdf');
  164.         $tempFileWithExtension $tempFile '.pdf';
  165.         file_put_contents($tempFileWithExtension$pdfData);
  166.         // Create an instance of the Parser class
  167.         $parser = new Parser();
  168.         try {
  169.             // Parse the PDF file
  170.             $pdf $parser->parseFile($tempFileWithExtension);
  171.             // Extract text from the PDF
  172.             $text $pdf->getText();
  173.              dd($text);
  174.             // Extract receiver name
  175.             $receiverIndex strpos($text'Receiver');
  176.             if ($receiverIndex !== false) {
  177.                 $receiverTabPos strpos($text"\t"$receiverIndex);
  178.                 $receiverLineEndPos strpos($text"\n"$receiverTabPos);
  179.                 $receiverName trim(substr($text$receiverTabPos 1$receiverLineEndPos - ($receiverTabPos 1)));
  180.             }
  181.             //extract payer
  182.             $payer strpos($text'Payer');
  183.             if ($payer !== false) {
  184.                 $payerTabPos strpos($text"\t"$payer);
  185.                 $payerLineEndPos strpos($text"\n"$payerTabPos);
  186.                 $payerName trim(substr($text$payerTabPos 1$payerLineEndPos - ($payerTabPos 1)));
  187.             }
  188.             //extract reference number.
  189.             $reference strpos($text'Reference No.');
  190.             if ($reference !== false) {
  191.                 $referenceNumberTabPos strpos($text"\t"$reference);
  192.                 $referenceNumberLineEndPos strpos($text"\n"$referenceNumberTabPos);
  193.                 $referenceNumber trim(substr($text$referenceNumberTabPos 1$referenceNumberLineEndPos - ($referenceNumberTabPos 1)));
  194.             }
  195.             // Extract transferred amount
  196.             $amountIndex strpos($text'Transferred Amount');
  197.             if ($amountIndex !== false) {
  198.                 $amountTabPos strpos($text"\t"$amountIndex);
  199.                 $amountLineEndPos strpos($text"\n"$amountTabPos);
  200.                 $transferredAmount trim(substr($text$amountTabPos 1$amountLineEndPos - ($amountTabPos 1)));
  201.             }           // Delete the temporary file
  202.             unlink($tempFileWithExtension);
  203.             //   dd($receiverName, $transferredAmount);
  204.             return [
  205.                 'receiver_name' => $receiverName,
  206.                 'payer_name' => $payerName,
  207.                 'amount_paid' => $amountIndex,
  208.                 'reference_number' => $referenceNumber,
  209.             ];
  210.         } catch (\Exception $e) {
  211.             echo 'PDF file does not exist or could not be parsed.';
  212.         }
  213.     } 
  214.  
  215. }