Skip to content

Commit d7d795b

Browse files
authored
Fix/ Sagres duplicate cpf student count (#722)
* Corrige a contagem duplicada de CPFs ao transferir estudantes entre turmas e escolas * Feat: added new version for changelog and config * Fix: data de nascimento nula
1 parent 606b316 commit d7d795b

File tree

3 files changed

+49
-25
lines changed

3 files changed

+49
-25
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [Versão 3.78.139]
2+
- Realizadas correções no módulo Sagres para evitar a contagem de CPFs de estudantes, evitando duplicações.
3+
14
## [Versão 3.78.138]
25
- Efetuadas correções no SQL responsável pela contagem das faltas dos alunos
36

app/modules/sagres/models/SagresConsultModel.php

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@
3434
*/
3535
class SagresConsultModel
3636
{
37-
private $dbCommand;
38-
39-
40-
41-
42-
public function __construct()
43-
{
44-
$this->dbCommand = Yii::app()->db->createCommand();
45-
}
4637

4738
public function cleanInconsistences()
4839
{
@@ -349,7 +340,7 @@ classroom c
349340
':referenceYear' => $referenceYear
350341
];
351342

352-
$turmas = $this->dbCommand->setText($query)
343+
$turmas = Yii::app()->db->createCommand()->setText($query)
353344
->bindValues($params)
354345
->queryAll();
355346

@@ -999,7 +990,7 @@ public function getMenuList($schoolId, $year, $month)
999990
$inconsistencyModel->insert();
1000991
}
1001992

1002-
if (!$this->validateDate($menuType->getData(), 'Y-m-d', 2)) {
993+
if (!$this->validateDate($menuType->getData(), 2)) {
1003994
$inconsistencyModel = new ValidationSagresModel();
1004995
$inconsistencyModel->enrollment = 'CARDÁPIO';
1005996
$inconsistencyModel->school = $schoolRes['name'];
@@ -1189,6 +1180,7 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
11891180
left join schedule s on cf.schedule_fk = s.id
11901181
WHERE
11911182
se.classroom_fk = :classId AND
1183+
se.status = 1 AND
11921184
c.school_year = :referenceYear
11931185
GROUP BY se.id;
11941186
";
@@ -1203,7 +1195,8 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
12031195

12041196
foreach ($enrollments as $enrollment) {
12051197

1206-
if (DateTime::createFromFormat("d/m/Y", $enrollment['birthdate']) === false) {
1198+
$convertedBirthdate = $this->convertBirthdate($enrollment['birthdate']);
1199+
if ($convertedBirthdate === false) {
12071200
$inconsistencyModel = new ValidationSagresModel();
12081201
$inconsistencyModel->enrollment = '<strong>ESTUDANTE<strong>';
12091202
$inconsistencyModel->school = $school->name;
@@ -1227,7 +1220,7 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
12271220
$studentType = new AlunoTType();
12281221
$studentType
12291222
->setNome($enrollment['name'])
1230-
->setDataNascimento(DateTime::createFromFormat("d/m/Y", $enrollment['birthdate']))
1223+
->setDataNascimento($convertedBirthdate)
12311224
->setCpfAluno(!empty($cpf) ? $cpf : null)
12321225
->setPcd($enrollment['deficiency'])
12331226
->setSexo($enrollment['gender']);
@@ -1270,7 +1263,7 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
12701263
$inconsistencyModel->insert();
12711264
}
12721265

1273-
if (!$this->validateDate($studentType->getDataNascimento(), 'Y-m-d', 1)) {
1266+
if (!$this->validateDate($studentType->getDataNascimento(), 1)) {
12741267
$inconsistencyModel = new ValidationSagresModel();
12751268
$inconsistencyModel->enrollment = '<strong>ESTUDANTE<strong>';
12761269
$inconsistencyModel->school = $school->name;
@@ -1377,7 +1370,7 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
13771370
$inconsistencyModel->insert();
13781371
}
13791372

1380-
if (!$this->validateDate($enrollmentType->getDataMatricula(), 'Y-m-d', 2)) {
1373+
if (!$this->validateDate($enrollmentType->getDataMatricula(), 2)) {
13811374
$inconsistencyModel = new ValidationSagresModel();
13821375
$inconsistencyModel->enrollment = 'MATRÍCULA';
13831376
$inconsistencyModel->school = $school->name;
@@ -1413,9 +1406,10 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
14131406
}
14141407
} else {
14151408
$studentType = new AlunoTType();
1409+
$convertedBirthdate = $this->convertBirthdate($enrollment['birthdate']);
14161410
$studentType
14171411
->setNome($enrollment['name'])
1418-
->setDataNascimento(DateTime::createFromFormat("d/m/Y", $enrollment['birthdate']))
1412+
->setDataNascimento($convertedBirthdate)
14191413
->setCpfAluno(!empty($cpf) ? $cpf : null)
14201414
->setPcd($enrollment['deficiency'])
14211415
->setSexo($enrollment['gender']);
@@ -1458,7 +1452,7 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
14581452
$inconsistencyModel->insert();
14591453
}
14601454

1461-
if (!$this->validateDate($studentType->getDataNascimento(), 'Y-m-d', 1)) {
1455+
if (!$this->validateDate($studentType->getDataNascimento(), 1)) {
14621456
$inconsistencyModel = new ValidationSagresModel();
14631457
$inconsistencyModel->enrollment = '<strong>ESTUDANTE<strong>';
14641458
$inconsistencyModel->school = $school->name;
@@ -1564,7 +1558,7 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
15641558
$inconsistencyModel->insert();
15651559
}
15661560

1567-
if (!$this->validateDate($enrollmentType->getDataMatricula(), 'Y-m-d', 2)) {
1561+
if (!$this->validateDate($enrollmentType->getDataMatricula(), 2)) {
15681562
$inconsistencyModel = new ValidationSagresModel();
15691563
$inconsistencyModel->enrollment = 'MATRÍCULA';
15701564
$inconsistencyModel->school = $school->name;
@@ -1603,7 +1597,22 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
16031597
return $enrollmentList;
16041598
}
16051599

1606-
public function getStudentSituation($situation)
1600+
public function convertBirthdate($birthdate) {
1601+
1602+
$date = DateTime::createFromFormat('Y-m-d', $birthdate);
1603+
if ($date && $date->format('Y-m-d') === $birthdate) {
1604+
return $date->format('d/m/Y');
1605+
}
1606+
1607+
$date = DateTime::createFromFormat('d/m/Y', $birthdate);
1608+
if ($date && $date->format('d/m/Y') === $birthdate) {
1609+
return $birthdate;
1610+
}
1611+
1612+
return false;
1613+
}
1614+
1615+
public function getStudentSituation($situation): bool
16071616
{
16081617
$situations = [
16091618
0 => false, // Não frequentou
@@ -1725,17 +1734,28 @@ public function convertTurn($turn)
17251734
}
17261735
}
17271736

1728-
public function validateDate($date, $format, $type)
1737+
public function validateDate($date, int $type): bool
17291738
{
1730-
$type = (int) $type;
1739+
$format = 'Y-m-d';
1740+
if($date === null)
1741+
return false;
1742+
17311743
if ($date instanceof Datetime) {
17321744
$dat = $date->format('Y-m-d');
17331745
} else {
1734-
$dt = new DateTime($date);
1746+
1747+
$dt = DateTime::createFromFormat($format, $date);
1748+
if ($dt === false) {
1749+
return false;
1750+
}
1751+
17351752
$dat = $dt->format('Y-m-d');
17361753
}
17371754

17381755
$d = DateTime::createFromFormat($format, $dat);
1756+
if ($d === false) {
1757+
return false;
1758+
}
17391759
$year = intval($d->format('Y'));
17401760
$currentYear = intval(date('Y'));
17411761

@@ -1756,11 +1776,12 @@ public function validateDate($date, $format, $type)
17561776
return $d && $d->format($format) == $dat;
17571777
}
17581778

1759-
public function validaCPF($cpf)
1779+
1780+
public function validaCPF(String $cpf): bool
17601781
{
17611782
$cpf = preg_replace('/[^0-9]/is', '', $cpf);
17621783

1763-
if (strlen($cpf) != 11) {
1784+
if (!$this->cpfLength($cpf)) {
17641785
return false;
17651786
}
17661787

config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
$debug = getenv("YII_DEBUG");
55
defined('YII_DEBUG') or define('YII_DEBUG', $debug);
66

7-
define("TAG_VERSION", '3.78.138');
7+
define("TAG_VERSION", '3.78.139');
88

99
define("YII_VERSION", Yii::getVersion());
1010
define("BOARD_MSG", '<div class="alert alert-success">Novas atualizações no TAG. Confira clicando <a class="changelog-link" href="?r=admin/changelog">aqui</a>.</div>');

0 commit comments

Comments
 (0)