<?php
namespace App\Controller\Api;
use App\Entity\User;
use App\Entity\SchoolYear;
use App\Service\SMSSender;
use Informagenie\OrangeSDK;
use App\Entity\TreasuryCashRegister;
use App\Repository\AccountingExpenseRepository;
use App\Repository\AccountingStudentRegistrationFeeRepository;
use App\Repository\AccountingStudentRegistrationPaymentRepository;
use App\Repository\SchoolYearRepository;
use App\Repository\EstablishmentRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Repository\EstablishmentGroupRepository;
use App\Repository\RegistrationStudentRegistrationRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class ApiController extends AbstractController
{
/**
* @Route("/api/_student_registrations", name="api_registration_student_registrations", methods={"GET","POST"})
*/
public function _student_registrations(RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository, AccountingStudentRegistrationFeeRepository $accountingStudentRegistrationFeeRepository, AccountingStudentRegistrationPaymentRepository $accountingStudentRegistrationPaymentRepository, AccountingExpenseRepository $accountingExpenseRepository): Response
{
/**@var User $user */
$user = $this->getUser();
$establishment = $user->getEstablishment();
$schoolYear = $user->getSchoolYear();
$accountingExpense = $accountingExpenseRepository->createQueryBuilder('entity')
->innerJoin('entity.establishment', 'establishment')
->addSelect('establishment')
->andWhere('establishment.establishmentGroup = :establishmentGroup')
->setParameter('establishmentGroup', $establishment->getEstablishmentGroup())
->andWhere('entity.create_date BETWEEN :startDate AND :endDate')
->setParameter('startDate', date('Y').'-01-01')
->setParameter('endDate', date('Y').'-12-31')
/* ->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear) */
->andWhere('entity.is_canceled = :is_canceled')
->setParameter('is_canceled', 0)
->andWhere('entity.is_paid = :is_paid')
->setParameter('is_paid', 1)
->select('SUM(entity.amount) as amount')
->getQuery()
->getSingleScalarResult();
$accountingStudentRegistrationFee = $accountingStudentRegistrationFeeRepository->createQueryBuilder('entity')
->innerJoin('entity.studentRegistration', 'studentRegistration')
->addSelect('studentRegistration')
->andWhere('studentRegistration.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('studentRegistration.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->andWhere('entity.is_cancel = :is_cancel')
->setParameter('is_cancel', 0)
->andWhere('entity.is_archived = :is_archived')
->setParameter('is_archived', 0)
->select('SUM(entity.amount) as amount')
->getQuery()
->getSingleScalarResult();
$accountingStudentRegistrationPayment = $accountingStudentRegistrationPaymentRepository->createQueryBuilder('entity')
->innerJoin('entity.studentRegistration', 'studentRegistration')
->addSelect('studentRegistration')
->andWhere('studentRegistration.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('studentRegistration.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->select('SUM(entity.amount) as amount')
->getQuery()
->getSingleScalarResult();
$registration_student_registrations = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
->innerJoin('entity.student', 'student')
->addSelect('student')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->getQuery()
->getResult();
$registration_student_registration_women = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
->innerJoin('entity.student', 'student')
->addSelect('student')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->andWhere('student.gender = :gender')
->setParameter('gender', 'FEMININ')
->getQuery()
->getResult();
$registration_student_registration_men = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
->innerJoin('entity.student', 'student')
->addSelect('student')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->andWhere('student.gender = :gender')
->setParameter('gender', 'MASCULIN')
->getQuery()
->getResult();
$registration_student_registration_affecteds = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
->innerJoin('entity.student', 'student')
->addSelect('student')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->andWhere('student.is_affected = :is_affected')
->setParameter('is_affected', 1)
->getQuery()
->getResult();
return $this->renderForm('api/render/student_registrations.html.twig', [
'registration_student_registrations' => count($registration_student_registrations),
'registration_student_registration_women' => count($registration_student_registration_women),
'registration_student_registration_men' => count($registration_student_registration_men),
'registration_student_registration_affecteds' => count($registration_student_registration_affecteds),
'accountingStudentRegistrationFee' => $accountingStudentRegistrationFee,
'accountingStudentRegistrationPayment' => $accountingStudentRegistrationPayment,
'accountingExpense' => $accountingExpense
]);
}
/**
* @Route("/api/_gender_echart", name="api_gender_echart", methods={"GET","POST"})
*/
public function _gender_echart(RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository): Response
{
/**@var User $user */
$user = $this->getUser();
$establishment = $user->getEstablishment();
$schoolYear = $user->getSchoolYear();
$registration_student_registrations = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
->innerJoin('entity.student', 'student')
->addSelect('student')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->getQuery()
->getResult();
$registration_student_registration_women = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
->innerJoin('entity.student', 'student')
->addSelect('student')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->andWhere('student.gender = :gender')
->setParameter('gender', 'FEMININ')
->getQuery()
->getResult();
$registration_student_registration_men = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
->innerJoin('entity.student', 'student')
->addSelect('student')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->andWhere('student.gender = :gender')
->setParameter('gender', 'MASCULIN')
->getQuery()
->getResult();
return $this->json([
'code' => 200,
'registration_student_registrations' => count($registration_student_registrations),
'women' => count($registration_student_registrations) > 0 ? floatval(number_format(((count($registration_student_registration_women) * 100) / count($registration_student_registrations)), 2, '.', '')) : 0,
'men' => count($registration_student_registrations) > 0 ? floatval(number_format(((count($registration_student_registration_men) * 100) / count($registration_student_registrations)), 2, '.', '')) : 0,
'count_women' => count($registration_student_registration_women),
'count_men' => count($registration_student_registration_men),
'message' => "Validation effectuée :)"
], 200);
}
/**
* @Route("/api/_status_echart", name="api_status_echart", methods={"GET","POST"})
*/
public function _status_echart(RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository): Response
{
/**@var User $user */
$user = $this->getUser();
$establishment = $user->getEstablishment();
$schoolYear = $user->getSchoolYear();
$registration_student_registrations = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
->innerJoin('entity.student', 'student')
->addSelect('student')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->getQuery()
->getResult();
$registration_student_registration_affecteds = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
->innerJoin('entity.student', 'student')
->addSelect('student')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->andWhere('student.is_affected = :is_affected')
->setParameter('is_affected', 1)
->getQuery()
->getResult();
$registration_student_registration_not_affecteds = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
->innerJoin('entity.student', 'student')
->addSelect('student')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->andWhere('student.is_affected = :is_affected')
->setParameter('is_affected', 0)
->getQuery()
->getResult();
return $this->json([
'code' => 200,
'registration_student_registrations' => count($registration_student_registrations),
'affecteds' => count($registration_student_registrations) > 0 ? floatval(number_format(((count($registration_student_registration_affecteds) * 100) / count($registration_student_registrations)), 2, '.', '')) : 0,
'count_affecteds' => count($registration_student_registration_affecteds),
'not_affecteds' => count($registration_student_registrations) > 0 ? floatval(number_format(((count($registration_student_registration_not_affecteds) * 100) / count($registration_student_registrations)), 2, '.', '')) : 0,
'count_not_affecteds' => count($registration_student_registration_not_affecteds),
'message' => "Validation effectuée :)"
], 200);
}
}