<?php
declare(strict_types = 1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240905104814 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$this->addSql(
'ALTER VIEW report_total_or_installments_count AS
select a.academic_year, a.title, count(a.id) as total
from (SELECT DISTINCT s.id AS id,
CASE
WHEN i.title = \'U cjelosti\' THEN \'Uplata u cjelosti\'
ELSE \'Rate\'
END AS title,
e.academic_year
FROM students s
LEFT JOIN udg_fms.profiles p ON s.id = p.student_id
LEFT JOIN enrollment_events e ON e.profile_id = p.id
LEFT JOIN tuition_installments i ON e.id = i.enrollment_id
where e.academic_year is not null
and e.tuition_modality_template_id is not null) a
group by a.academic_year, a.title;
'
);
$this->addSql(
'ALTER VIEW report_total_or_installments_amount AS
select a.academic_year, a.title, sum(a.total) as total
from (SELECT DISTINCT e.academic_year,
CASE
WHEN t.title = \'U cjelosti\' THEN \'Uplata u cjelosti\'
ELSE \'Rate\'
END AS title,
sum(t.amount) as total
FROM students s
LEFT JOIN udg_fms.profiles p ON s.id = p.student_id
LEFT JOIN enrollment_events e ON e.profile_id = p.id
left join tuition_installments t on t.enrollment_id = e.id
WHERE e.academic_year is not null
and e.tuition_modality_template_id is not null
and t.payed_on is not null
GROUP BY e.academic_year, title) a
group by a.academic_year, a.title;'
);
}
public function down(Schema $schema): void
{
$this->addSql(
'ALTER VIEW report_total_or_installments_count AS
select a.academic_year, a.title, count(a.id) as total
from (SELECT DISTINCT s.id AS id,
CASE
WHEN ti.title = \'Uplata u cjelosti\' THEN ti.title
ELSE \'Rate\'
END AS title,
e.academic_year
FROM students s
LEFT JOIN udg_fms.profiles p ON s.id = p.student_id
LEFT JOIN enrollment_events e ON e.profile_id = p.id
LEFT JOIN tuition_modality_templates t ON e.tuition_modality_template_id = t.id
LEFT JOIN tuition_installments_templates ti ON t.id = ti.tuition_modality_template_id
where e.academic_year is not null and e.tuition_modality_template_id is not null
) a
group by a.academic_year, a.title;
'
);
$this->addSql(
'ALTER VIEW report_total_or_installments_amount AS
select a.academic_year, a.title, sum(t.amount) as total
from (SELECT DISTINCT e.id,
CASE
WHEN ti.title = \'Uplata u cjelosti\' THEN ti.title
ELSE \'Rate\'
END AS title,
e.academic_year
FROM students s
LEFT JOIN udg_fms.profiles p ON s.id = p.student_id
LEFT JOIN enrollment_events e ON e.profile_id = p.id
LEFT JOIN tuition_modality_templates t ON e.tuition_modality_template_id = t.id
LEFT JOIN tuition_installments_templates ti ON t.id = ti.tuition_modality_template_id
WHERE e.academic_year is not null and e.tuition_modality_template_id is not null
GROUP BY e.id, title) a
left join tuition_installments t on t.enrollment_id = a.id
where t.payed_on is not null
group by a.academic_year,a.title;'
);
}
}