Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/enrollment statistical report #456

Merged
merged 9 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/config/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
),
);

if(YII_DEBUG){
if(!YII_DEBUG){
array_push($log_config['routes'], array(
'class'=>'CWebLogRoute',
)
Expand Down
73 changes: 72 additions & 1 deletion app/controllers/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function accessRules()
return array(
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions' => array('index', 'BFReport', 'numberStudentsPerClassroomReport',
'InstructorsPerClassroomReport', 'StudentsFileReport',
'EnrollmentStatisticsByYearReport','InstructorsPerClassroomReport', 'StudentsFileReport',
'getStudentsFileInformation', 'ResultBoardReport',
'StatisticalDataReport', 'StudentsDeclarationReport',
'EnrollmentPerClassroomReport', 'AtaSchoolPerformance',
Expand Down Expand Up @@ -401,6 +401,77 @@ public function actionNumberStudentsPerClassroomReport()
$this->render('NumberStudentsPerClassroomReport', $query);
}

public function actionEnrollmentStatisticsByYearReport()
{
// Construíndo condicionais e definindo ordenação para a consulta
$criteria = new CDbCriteria;
$criteria->order = 'name ASC';
$criteria->condition = "school_year = :year";
$criteria->params = array("year" => Yii::app()->user->year);
//Consulta todas as classes abertas no ano atual
$classrooms = Classroom::model()->findAll($criteria);
$stages = [];
$schools = [];
foreach ($classrooms as $classroom) {
//Coloca em um array o nome de todas as escolas que já não estão no mesmo (através da lista de classes)
if (!in_array($schools, $classroom->schoolInepFk->name)) {
array_push($schools, $classroom->schoolInepFk->name);
}
//Coloca em um array todos o stage number e nome dos estágios que já não estão no mesmo (através da lista de classes)
if (array_search($classroom->edcensoStageVsModalityFk->name, array_column($stages, 'name')) === false) {
array_push($stages, ["stageNumber" => $classroom->edcensoStageVsModalityFk->stage, "name" => $classroom->edcensoStageVsModalityFk->name, "alias" => $classroom->edcensoStageVsModalityFk->alias]);
}
}
//Cria a primeira linha da tabela com o grupo de estágios
$stageNumberGroups = [];
foreach($stages as $stage) {
if ($stageNumberGroups[$stage["stageNumber"]] == null){
//Adiciona indexado pelo stageNumber do array $stage a quantidade de celulas do estágio e o nome
$stageNumberGroups[$stage["stageNumber"]]["colspan"] = 0;
$stageNumberGroups[$stage["stageNumber"]]["colname"] = $this->translateStageNumbers($stage["stageNumber"]);
}
//Pra cada estagio, concatena mais uma celula ao grupo de estagios
$stageNumberGroups[$stage["stageNumber"]]["colspan"]++;
}

//Inicializa as celulas de contagem de matriculas com valor 0
$schoolStages = [];
foreach ($schools as $school) {
foreach ($stages as $stage) {
$schoolStages[$school][$stage["stageNumber"]][$stage["name"]] = 0;
}
}

//Para cada classe incrementa o contador de matriculas em cada celular dos estágios
foreach ($classrooms as $classroom) {
$schoolStages[$classroom->schoolInepFk->name][$classroom->edcensoStageVsModalityFk->stage][$classroom->edcensoStageVsModalityFk->name] += count($classroom->studentEnrollments);
}

$this->render('EnrollmentStatisticsByYearReport', array(
'schoolStages' => $schoolStages,
'stageNumberGroups' => $stageNumberGroups,
'stages' => $stages
));
}

private function translateStageNumbers ($stageNumber) {
switch($stageNumber) {
case "1" :
return "Ensino Infantil";
case "2":
return "Ensino Fundamental Menor";
case "3":
case "7":
return "Ensino Fundamental Maior";
case "4":
return "Ensino Médio";
case "6":
return "EJA";
default:
return "Resto";
}
}

public function actionClocReport()
{
$repository = new ReportsRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE
ADD `alias` varchar(20) COLLATE 'utf8_unicode_ci' NULL AFTER `name`;


UPDATE `edcenso_stage_vs_modality`
set alias = SUBSTRING(trim(SUBSTRING_INDEX(SUBSTRING_INDEX(name , '-', -1), '-', -1)), 1, 20)
8 changes: 6 additions & 2 deletions app/models/EdcensoStageVsModality.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* The followings are the available columns in table 'edcenso_stage_vs_modality':
* @property integer $id
* @property string $name
* @property string $alias
* @property integer $stage
*
* The followings are the available model relations:
Expand Down Expand Up @@ -108,10 +109,12 @@ public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return [
['name, stage', 'required'], ['stage', 'numerical', 'integerOnly' => TRUE],
['name, stage', 'required'],
['stage', 'numerical', 'integerOnly' => TRUE],
['name', 'length', 'max' => 100], // The following rule is used by search().
['alias', 'length', 'max'=>20],
// Please remove those attributes that should not be searched.
['id, name, stage', 'safe', 'on' => 'search'],
['id, name, alias, stage', 'safe', 'on' => 'search'],
];
}

Expand Down Expand Up @@ -151,6 +154,7 @@ public function search() {

$criteria->compare('id', $this->id);
$criteria->compare('name', $this->name, TRUE);
$criteria->compare('alias',$this->alias, TRUE);
$criteria->compare('stage', $this->stage);

return new CActiveDataProvider($this, [
Expand Down
39 changes: 39 additions & 0 deletions js/reports/EnrollmentStatisticsByYearReport/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
$(document).ready(function() {

var totalEnrollmentPerSchool;
var columnIndex;

$('#enrollment-table tbody tr').each(function() {
totalEnrollmentPerSchool = 0;
columnIndex = 0;
$(this).find(".stage-enrollment").each(function(i, value) {
totalEnrollmentPerSchool += Number($(value).html());
$(value).addClass('col-'+columnIndex);
columnIndex++;
});
$(this).find(".school-total, .unity-total").html(totalEnrollmentPerSchool);
});

$('#enrollment-table tfoot .col-total .stage-total').each(function(i) {
var colTotal = 0;
$('.col-'+i).each(function() {
colTotal += Number($(this).html());
});
$(this).html(colTotal);
});

$('#enrollment-table tfoot .group-stage-total .group-total').each(function(i) {
var groupTotal = 0;
$('.stage-'+i).each(function() {
groupTotal += Number($(this).html());
});
$(this).html(groupTotal);
});

var redeTotal = 0;
$('.unity-total').each(function() {
redeTotal += Number($(this).html());
});
$('.rede-total').html(redeTotal);

});
121 changes: 121 additions & 0 deletions themes/default/views/reports/EnrollmentStatisticsByYearReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php
/**
* @var ReportsController $this ReportsController
* @var EdcensoStageVsModality[] $stages List Of stages
*
*/
Yii::app()->clientScript->registerCoreScript('jquery');
$baseUrl = Yii::app()->baseUrl;
$cs = Yii::app()->getClientScript();
$cs->registerScriptFile($baseUrl . '/js/reports/EnrollmentStatisticsByYearReport/functions.js', CClientScript::POS_END);
$this->setPageTitle('TAG - ' . Yii::t('default', 'Reports'));
?>

<style>
th, td {
text-align: center !important;
vertical-align: middle !important;
}
/* Landscape orientation */
@page{
size: landscape;
}
/* Hidden the print button */
@media print {
#print {
display: none;
}
}
</style>

<div class="pageA4H">
<?php $this->renderPartial('HeadWithoutSchool'); ?>
<h3 id="report-title"><?php echo Yii::t('default', 'Matrículas Atuais'); ?></h3>
<div class="row-fluid hidden-print">
<div class="span12">
<div class="buttons">
<a id="print" onclick="imprimirPagina()" class='btn btn-icon glyphicons print hidden-print' style="padding: 10px;">
<img alt="impressora" src="<?php echo Yii::app()->theme->baseUrl; ?>/img/Impressora.svg" class="print hidden-print" />
<?php echo Yii::t('default', 'Print') ?>
<i></i>
</a>
</div>
</div>
</div>
<div>
<table id="enrollment-table" class="table table-bordered table-striped" aria-labelledby="report-title">

<thead>
<tr>
<th scope="col" colspan="2">ANO LETIVO DE <?= Yii::app()->user->year ?></th>
<?php foreach($stageNumberGroups as $stageNumberGroupName => $stageNumberGroup): ?>
<th scope="col" colspan="<?=$stageNumberGroup["colspan"]?>"><?=$stageNumberGroup["colname"]?></th>
<?php endforeach; ?>
<th scope="col"></th>
</tr>
<tr>
<th scope="col">Unidade Escolar</th>
<th scope="col">Total de Estudantes</th>
<?php foreach($schoolStages as $schoolNameIndex => $schoolNameValue): ?>
<?php foreach($schoolNameValue as $stageNumberIndex => $stageNumberValue): ?>
<?php foreach($stageNumberValue as $stageName => $enrollmentsCount): ?>
<?php $key = array_search($stageName, array_column($stages, 'name')) ?>
<th scope="col"><?= $stages[$key]["alias"] ?></th>
<?php endforeach; ?>
<?php endforeach; ?>
<?php break; endforeach; ?>
<th scope="col">Total por Unidade</th>
</tr>
<tr>

</tr>
</thead>
<tbody>
<?php foreach($schoolStages as $schoolNameIndex => $schoolNameValue): ?>
<tr>
<td><?= $schoolNameIndex ?></td>
<td class="school-total">0</td>
<?php $stageGroupIndex = 0; ?>
<?php foreach($schoolNameValue as $stageNumberIndex => $stageNumberValue): ?>
<?php foreach($stageNumberValue as $stageName => $enrollmentsCount): ?>
<td class="stage-enrollment stage-<?= $stageGroupIndex ?>"><?= ($enrollmentsCount == 0 ? "" : $enrollmentsCount) ?></td>
<?php endforeach; ?>
<?php $stageGroupIndex++; ?>
<?php endforeach; ?>
<td class="unity-total">0</td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr class="col-total">
<td colspan="2">Total de Alunos na Rede</td>
<?php foreach($schoolStages as $schoolNameIndex => $schoolNameValue): ?>
<?php foreach($schoolNameValue as $stageNumberIndex => $stageNumberValue): ?>
<?php foreach($stageNumberValue as $stageName => $enrollmentsCount): ?>
<td class="stage-total">0</td>
<?php endforeach; ?>
<?php endforeach; ?>
<?php break; endforeach; ?>
<td class="rede-total">0</td>
</tr>

<tr class="group-stage-total">
<td colspan="2"></td>
<?php foreach($stageNumberGroups as $stageNumberGroupName => $stageNumberGroup): ?>
<td class="group-total" colspan="<?=$stageNumberGroup["colspan"]?>">0</td>
<?php endforeach; ?>
<td></td>
</tr>
</tfoot>
</table>
</div>
<div id="rodape"><?php $this->renderPartial('footer'); ?></div>
</div>
<script>
function imprimirPagina() {
// printButton = document.getElementsByClassName('span12');
// printButton.style.visibility = 'hidden';
window.print();
// printButton.style.visibility = 'visible';
}
</script>
36 changes: 36 additions & 0 deletions themes/default/views/reports/HeadWithoutSchool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/* @var $this ReportsController
@var $school SchoolIdentification
*/

if(!isset($school)){
$school = SchoolIdentification::model()->findByPk(Yii::app()->user->school);
}

?>
<style>
#info li {text-align:center;}
#addinfo li{text-align: center}
</style>
<h3 class="heading visible-print"><?php echo @$title ?></h3>
<div id="header-report">
<?php
if(isset($school->logo_file_name)){
echo '<img id="logo" src="data:'.$school->logo_file_type.';base64,'.base64_encode($school->logo_file_content).'">';
};
?>
<ul id="info">
<?php if(isset($school->act_of_acknowledgement)&&(!empty($school->act_of_acknowledgement))){?>
<li><?php echo $school->name ?></li>
<?php }else{?>
<li>PREFEITURA MUNICIPAL DE <?php echo $school->edcensoCityFk->name ?></li>
<?php }?>
</ul>
<ul id="addinfo">
<li><?php echo $school->address.', '.(!empty($school->address_number) ? $school->address_number.', ':'' ).$school->address_neighborhood; ?>, <?php echo $school->edcensoCityFk->name . " - " . $school->edcensoUfFk->acronym ?> </li>
<li><?php echo $school->act_of_acknowledgement ?></li>
<!--<?php echo 'Email: '.(!empty($school->email) ? $school->email.' - ': (!empty($school->manager_email) ? $school->manager_email.' - ':'' ) ).'Tel: '.(!empty($school->phone_number) ? $school->phone_number:'' )?>-->
</ul>
<span class="clear"></span>

</div>
12 changes: 12 additions & 0 deletions themes/default/views/reports/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@
</button>
</a>

<a href="<?php echo Yii::app()->createUrl('reports/EnrollmentStatisticsByYearReport') ?>" target="_blank" rel="noopener">
<button type="button" class="report-box-container">
<div class="pull-left" style="margin-right: 20px;">
<span class="t-icon-line_graph t-reports_icons"></span>
</div>
<div class="pull-left">
<span class="title">Matrículas do ano</span><br>
<span class="subtitle">Dados estatísticos de matrículas deste ano</span>
</div>
</button>
</a>

<a href="<?php echo Yii::app()->createUrl('reports/incompatiblestudentagebyclassroomreport') ?>" target="_blank" rel="noopener">
<button type="button" class="report-box-container">
<div class="pull-left" style="margin-right: 20px;">
Expand Down