<?php
namespace App\Controller;
use App\Entity\ProjectActivity;
use App\Repository\ProjectRepository;
use App\Repository\ProjectMembersRepository;
use App\Repository\ActivityUserRepository;
use App\Repository\ObjectiveRepository;
use App\Repository\OrganizationUnitRepository;
use App\Repository\ProjectActivityRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Smalot\PdfParser\Parser;
use function PHPSTORM_META\map;
class DashboardController extends AbstractController
{
#[Route('/dashboard', name: 'dashboard')]
public function index(ProjectRepository $projectRepository, Request $request, ProjectMembersRepository $projectMembersRepository): Response
{
$projectMember = $projectMembersRepository->findBy(['user' => $this->getUser(), 'status' => 1]);
$projects = [];
$project_list = [];
foreach ($projectMember as $member) {
$project = $projectRepository->findOneBy(['id' => $member->getProject()->getId()]);
array_push($projects, $project);
}
$managingProjects = $projectRepository->findBy(['project_manager' => $this->getUser()]);
foreach ($managingProjects as $projectr) {
array_push($projects, $projectr);
}
foreach ($projects as $proj) {
if (!in_array($proj, $project_list)) {
$project_list[] = $proj;
}
}
$activeProject = $projectRepository->findBy(['id' => $project_list, 'status' => 1]);
$closedProject = $projectRepository->findBy(['id' => $project_list, 'status' => 2]);
$session = $this->get('session');
$session->set('myprojects', $project_list);
return $this->render('dashboard/index.html.twig', [
'projects' => $project_list,
'active_project' => $activeProject,
'closed_project' => $closedProject,
]);
}
#[Route('/calendar', name: 'calendar_index')]
public function calendar(): Response
{
return $this->render('dashboard/calendar.html.twig', [
'controller_name' => 'CalendarController',
]);
}
#[Route('/myprojects', name: 'my_project')]
public function myprojects(ProjectRepository $projectRepository, ProjectMembersRepository $projectMembersRepository, Request $request): Response
{
$projectMember = $projectMembersRepository->findBy(['user' => $this->getUser(), 'status' => 1]);
$projects = [];
$project_list = [];
foreach ($projectMember as $member ) {
$project = $projectRepository->findOneBy(['id' => $member->getProject()->getId()],['id'=>'desc']);
array_push($projects, $project);
}
$managingProjects = $projectRepository->findBy(['project_manager' => $this->getUser()],['id'=>'desc']);
foreach ($managingProjects as $projectr) {
array_push($projects, $projectr);
}
foreach ($projects as $proj ) {
if ( ! in_array($proj, $project_list)) {
$project_list[] = $proj;
}
}
$project = NULL;
$projectId = $request->query->get('project');
if($projectId){
$project = $projectRepository->findOneBy(['id' => $projectId]);
}
// Desc sort
usort($project_list,function($first,$second){
return $first->getId() < $second->getId();
});
return $this->render('dashboard/myprojects.html.twig', [
'projects' => $project_list,
'project' => $project,
]);
}
#[Route('/myprojects/{project}/tasks', name: 'user_activity_index', methods: ['GET'])]
public function activities(ProjectActivityRepository $projectActivityRepository, ProjectRepository $projectRepository, ProjectMembersRepository $projectMembersRepository, Request $request): Response
{
$this->denyAccessUnlessGranted('project_activity_index');
$project = $projectRepository->findOneBy(['id' => $request->attributes->get('project')]);
$projectMember = $projectMembersRepository->findOneBy(['user' => $this->getUser(), 'status' => 1, 'project' => $project]);
/* $projectMember = $projectMembersRepository->findBy(['user' => $this->getUser(), 'status' => 1, 'project' => $project]);*/
if(!$projectMember)
{
$this->addFlash("success","You are not given a task on this project.");
return $this->redirectToRoute('my_project');
}
$user = $projectMember->getId();
/*foreach ($projectMember as $key => $value) {
$user[] = $value->getId();
}*/
/*$todo = $projectActivityRepository->findBy(['status' => 1, 'project' => $project]);
$doing = $projectActivityRepository->findBy(['status' => 2, 'project' => $project]);
$done = $projectActivityRepository->findBy(['status' => 4, 'project' => $project]);*/
$todo = $projectActivityRepository->findBy(['status' => 2, 'project' => $project],['end_date'=>'asc']);
$doing = $projectActivityRepository->findBy(['status' => 3, 'project' => $project],['end_date'=>'asc']);
$done = $projectActivityRepository->findBy(['status' => 4, 'project' => $project],['end_date'=>'asc']);
// dd($todo );
/* $arr = [
'project' => $project,
'todo_list' => $todo,
'doing_list' => $doing,
'done_list' => $done,
'user' => $user ,
'Project memeber' => $projectMember,
];
dd($arr);*/
return $this->render('dashboard/tasks.html.twig', [
'project' => $project,
'todo_list' => $todo,
'doing_list' => $doing,
'done_list' => $done,
]);
}
#[Route('/alignmentmatrix', name: 'alignment_matrix')]
public function alignmentMatrix(OrganizationUnitRepository $organizationUnitRepository, ProjectRepository $projectRepository, ObjectiveRepository $objectiveRepository): Response
{
$units = $organizationUnitRepository->findAll();
$projects = $projectRepository->findAll();
$objectives = $objectiveRepository->findAll();
return $this->render('dashboard/alignmentmatrix.html.twig', [
'projects' => $projects,
'units' => $units,
'objectives' => $objectives,
]);
}
#[Route('/pdf-to-text/{txn_unreliable}', name: 'pdf_to_text')]
public function pdfToText($txn_unreliable)
{
$url = "https://apps.cbe.com.et:100/?id=" . $txn_unreliable . "39452187";
$pdfUrl = $url;
$receiverName = null;
$payerName = null;
$referenceNumber = null;
$amountPaid = null;
// Make an API GET request to fetch the PDF data
$client = new \GuzzleHttp\Client(['verify' => false]);
$response = $client->get($pdfUrl);
$pdfData = $response->getBody()->getContents();
dd('111');
// Save the PDF data to a temporary file
$tempFile = tempnam(sys_get_temp_dir(), 'pdf');
$tempFileWithExtension = $tempFile . '.pdf';
file_put_contents($tempFileWithExtension, $pdfData);
// Create an instance of the Parser class
$parser = new Parser();
try {
// Parse the PDF file
$pdf = $parser->parseFile($tempFileWithExtension);
// Extract text from the PDF
$text = $pdf->getText();
dd($text);
// Extract receiver name
$receiverIndex = strpos($text, 'Receiver');
if ($receiverIndex !== false) {
$receiverTabPos = strpos($text, "\t", $receiverIndex);
$receiverLineEndPos = strpos($text, "\n", $receiverTabPos);
$receiverName = trim(substr($text, $receiverTabPos + 1, $receiverLineEndPos - ($receiverTabPos + 1)));
}
//extract payer
$payer = strpos($text, 'Payer');
if ($payer !== false) {
$payerTabPos = strpos($text, "\t", $payer);
$payerLineEndPos = strpos($text, "\n", $payerTabPos);
$payerName = trim(substr($text, $payerTabPos + 1, $payerLineEndPos - ($payerTabPos + 1)));
}
//extract reference number.
$reference = strpos($text, 'Reference No.');
if ($reference !== false) {
$referenceNumberTabPos = strpos($text, "\t", $reference);
$referenceNumberLineEndPos = strpos($text, "\n", $referenceNumberTabPos);
$referenceNumber = trim(substr($text, $referenceNumberTabPos + 1, $referenceNumberLineEndPos - ($referenceNumberTabPos + 1)));
}
// Extract transferred amount
$amountIndex = strpos($text, 'Transferred Amount');
if ($amountIndex !== false) {
$amountTabPos = strpos($text, "\t", $amountIndex);
$amountLineEndPos = strpos($text, "\n", $amountTabPos);
$transferredAmount = trim(substr($text, $amountTabPos + 1, $amountLineEndPos - ($amountTabPos + 1)));
} // Delete the temporary file
unlink($tempFileWithExtension);
// dd($receiverName, $transferredAmount);
return [
'receiver_name' => $receiverName,
'payer_name' => $payerName,
'amount_paid' => $amountIndex,
'reference_number' => $referenceNumber,
];
} catch (\Exception $e) {
echo 'PDF file does not exist or could not be parsed.';
}
}
}