migrations/Version20240826111236.php line 1

Open in your IDE?
  1. <?php
  2.     declare(strict_types 1);
  3.     namespace DoctrineMigrations;
  4.     use Doctrine\DBAL\Schema\Schema;
  5.     use Doctrine\Migrations\AbstractMigration;
  6.     /**
  7.      * Auto-generated Migration: Please modify to your needs!
  8.      */
  9.     final class Version20240826111236 extends AbstractMigration
  10.     {
  11.         public function getDescription(): string
  12.         {
  13.             return 'Views for dashboard page';
  14.         }
  15.         public function up(Schema $schema): void
  16.         {
  17.             $this->addSql(
  18.                 'CREATE VIEW report_total_or_installments_count AS
  19. select a.academic_year, a.title, count(a.id) as total
  20. from (SELECT DISTINCT s.id    AS id,
  21.                       CASE
  22.                           WHEN ti.title = \'Uplata u cjelosti\' THEN ti.title
  23.                           ELSE \'Rate\'
  24.                           END AS title,
  25.                       e.academic_year
  26.       FROM students s
  27.                LEFT JOIN udg_fms.profiles p ON s.id = p.student_id
  28.                LEFT JOIN enrollment_events e ON e.profile_id = p.id
  29.                LEFT JOIN tuition_modality_templates t ON e.tuition_modality_template_id = t.id
  30.                LEFT JOIN tuition_installments_templates ti ON t.id = ti.tuition_modality_template_id
  31.       where e.academic_year is not null  and e.tuition_modality_template_id is not null
  32.       ) a
  33. group by a.academic_year, a.title;
  34. '
  35.             );
  36.             $this->addSql(
  37.                 'CREATE VIEW report_total_or_installments_amount AS
  38. select a.academic_year, a.title, sum(t.amount) as total
  39. from (SELECT DISTINCT e.id,
  40.                       CASE
  41.                           WHEN ti.title = \'Uplata u cjelosti\' THEN ti.title
  42.                           ELSE \'Rate\'
  43.                           END AS title,
  44.                       e.academic_year
  45.       FROM students s
  46.                LEFT JOIN udg_fms.profiles p ON s.id = p.student_id
  47.                LEFT JOIN enrollment_events e ON e.profile_id = p.id
  48.                LEFT JOIN tuition_modality_templates t ON e.tuition_modality_template_id = t.id
  49.                LEFT JOIN tuition_installments_templates ti ON t.id = ti.tuition_modality_template_id
  50.       WHERE e.academic_year is not null  and e.tuition_modality_template_id is not null
  51.       GROUP BY e.id, title) a
  52.          left join tuition_installments t on t.enrollment_id = a.id
  53. where t.payed_on is not null
  54. group by a.academic_year,a.title;'
  55.             );
  56.             $this->addSql(
  57.                 'CREATE VIEW report_total_of_sponsored_students AS
  58. SELECT e.academic_year,
  59.        t.title,
  60.        count(s.id) as total
  61. FROM students s
  62.          LEFT JOIN udg_fms.profiles p ON s.id = p.student_id
  63.          LEFT JOIN enrollment_events e ON e.profile_id = p.id
  64.          LEFT JOIN tuition_modality_templates t ON e.tuition_modality_template_id = t.id
  65. WHERE t.covered = 1
  66.   and e.academic_year is not null
  67. group by e.academic_year, t.title;'
  68.             );
  69.             $this->addSql(
  70.                 'CREATE VIEW academic_years AS
  71. SELECT DISTINCT e.academic_year
  72. FROM enrollment_events e
  73. where e.academic_year is not null
  74. order by e.academic_year'
  75.             );
  76.         }
  77.         public function down(Schema $schema): void
  78.         {
  79.             $this->addSql('DROP VIEW report_total_or_installments_count');
  80.             $this->addSql('DROP VIEW report_total_or_installments_amount');
  81.             $this->addSql('DROP VIEW report_total_of_sponsored_students');
  82.             $this->addSql('DROP VIEW academic_years');
  83.         }
  84.     }