From 0a3551c1e66ecfd543ad7c654284063e8c5f3c44 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?ROBERTO=20J=C3=9ANIOR?= <roberto.junior@seduc.go.gov.br>
Date: Thu, 31 Oct 2019 15:48:55 -0300
Subject: [PATCH] =?UTF-8?q?Voltando=20as=20altera=C3=A7=C3=B5es=20do=20com?=
 =?UTF-8?q?mit=2088047377.=20Para=20atender=20a=20issue=20613?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../services/collaboration-scheme.service.ts  | 123 +++++++-----------
 1 file changed, 48 insertions(+), 75 deletions(-)

diff --git a/src/app/simulator/access-and-offer/collaboration-scheme/services/collaboration-scheme.service.ts b/src/app/simulator/access-and-offer/collaboration-scheme/services/collaboration-scheme.service.ts
index d60180a6..6e8c50a5 100644
--- a/src/app/simulator/access-and-offer/collaboration-scheme/services/collaboration-scheme.service.ts
+++ b/src/app/simulator/access-and-offer/collaboration-scheme/services/collaboration-scheme.service.ts
@@ -1,6 +1,6 @@
 import { Injectable } from '@angular/core';
 import { Observable } from 'rxjs';
-import { map, switchMap } from 'rxjs/operators';
+import { map } from 'rxjs/operators';
 import * as _ from 'lodash';
 
 import { Functionality } from '../../../../shared/entities/functionality/functionality';
@@ -8,10 +8,12 @@ import { HttpService } from '../../../../shared/services/http/http.service';
 import { UtilitiesService } from '../../../../shared/services/utilities/utilities.service';
 import { CollaborationScheme } from '../entities/collaboration-scheme';
 import { CollaborationSchemesByStage } from '../entities/collaboration-schemes-by-stage';
+import { SelectLocation } from '../../../select-location/entities/select-location';
 import { SessionService } from '../../../../shared/services/session/session.service';
 import { AdmDependency } from '../../../../shared/entities/enums/adm-dependency.enum';
 import { EnrollmentProjection } from '../../enrollment-projection/entities/enrollment-projection';
 import { EnrollmentProjectionByLocation } from '../../enrollment-projection/entities/enrollment-projection-by-location';
+import { ViewEnrollmentByStageSeries } from '../../view-enrollment-by-stage-series/entities/view-enrollment-by-stage-series';
 import { CurrentYearService } from '../../../shared/services/current-year/current-year.service';
 import { NavigableComponentService } from '../../../shared/entities/base/navigable-component-service';
 import { SourceInformationEnum } from './../../../../shared/entities/enums/source-information.enum';
@@ -33,69 +35,65 @@ export class CollaborationSchemeService implements NavigableComponentService {
     collaborationScheme.totalCurrentPublicEnrollment = 0;
     collaborationScheme.totalProposalPublicEnrollment = 0;
 
-    return this.getEnrollmentT4().pipe(
-      switchMap(enrollmentT4 => {
-        return this.utilitiesService.getStages().pipe(
-          map(stages => {
-            collaborationSchemesByStage = stages.map(stage => new CollaborationSchemesByStage({
-              id: stage.id,
-              stageDescription: stage.description,
-              numberCurrentPublicEnrollment: 0,
-              numberProposalPublicEnrollment: 0,
-              federalPercentage: 0,
-              statePercentage: 0,
-              municipalPercentage: 0
-            }));
+    return this.utilitiesService.getStages().pipe(
+      map(stages => {
+        collaborationSchemesByStage = stages.map(stage => new CollaborationSchemesByStage({
+          id: stage.id,
+          stageDescription: stage.description,
+          numberCurrentPublicEnrollment: 0,
+          numberProposalPublicEnrollment: 0,
+          federalPercentage: 0,
+          statePercentage: 0,
+          municipalPercentage: 0
+        }));
 
-            const resultForEnrollmentProjection: EnrollmentProjection = this.sessionService.getItem<EnrollmentProjection>(Functionality.enrollmentProjection.key);
-            const enrollmentOfferYear: number = this.currentYearService.getEnrollmentCurrentYear();
+        const enrollmentOfferYear: number = this.currentYearService.getEnrollmentCurrentYear();
 
-            collaborationScheme.yearCurrentPublicEnrollment = enrollmentOfferYear;
-            collaborationScheme.yearProposalPublicEnrollment = enrollmentOfferYear + 1;
+        collaborationScheme.yearCurrentPublicEnrollment = enrollmentOfferYear;
+        collaborationScheme.yearProposalPublicEnrollment = enrollmentOfferYear + 1;
 
-            for (const stage of stages) {
+        const resultForEnrollmentProjection: EnrollmentProjection = this.sessionService.getItem<EnrollmentProjection>(Functionality.enrollmentProjection.key);
+        const resultForViewEnrollmentProjection: ViewEnrollmentByStageSeries =
+          this.sessionService.getItem<ViewEnrollmentByStageSeries>(Functionality.viewEnrollmentByStageAndSeries.key);
+        const resultForSelectLocation: SelectLocation = this.sessionService.getItem<SelectLocation>(Functionality.selectLocation.key);
 
-              const collaboration: CollaborationSchemesByStage = _.find(collaborationSchemesByStage, c => c.id === stage.id);
-              const stagesAdmDependencyLocationEnrollments = _.filter(enrollmentT4, s => s.education_level_short_id === stage.id);
+        for (const stage of stages) {
 
-              const enrollmentsByAdmDependencyFederal = _.find(stagesAdmDependencyLocationEnrollments, t => t.adm_dependency_id === AdmDependency.Federal);
-              const enrollmentsByAdmDependencyState = _.find(stagesAdmDependencyLocationEnrollments, t => t.adm_dependency_id === AdmDependency.State);
-              const enrollmentsByAdmDependencyMunicipal = _.find(stagesAdmDependencyLocationEnrollments, t => t.adm_dependency_id === AdmDependency.Municipal);
+          const collaboration: CollaborationSchemesByStage = _.find(collaborationSchemesByStage, c => c.id === stage.id);
 
-              const totalEnrollmentsByAdmDependencyFederal = enrollmentsByAdmDependencyFederal ? enrollmentsByAdmDependencyFederal.total : 0;
-              const totalEnrollmentsByAdmDependencyState = enrollmentsByAdmDependencyState ? enrollmentsByAdmDependencyState.total : 0;
-              const totalEnrollmentsByAdmDependencyMunicipal = enrollmentsByAdmDependencyMunicipal ? enrollmentsByAdmDependencyMunicipal.total : 0;
+          const stagesAdmDependencyLocationEnrollments = _.find(resultForViewEnrollmentProjection.stagesAdmDependencyLocationEnrollments, s => s.id === stage.id);
 
-              const totalCurrentPublicEnrollment =
-                (totalEnrollmentsByAdmDependencyFederal + totalEnrollmentsByAdmDependencyState + totalEnrollmentsByAdmDependencyMunicipal);
+          const totalEnrollmentsByAdmDependencyFederal = _.find(stagesAdmDependencyLocationEnrollments.totalEnrollmentsByAdmDependency, t => t.id === AdmDependency.Federal);
+          const totalEnrollmentsByAdmDependencyState = _.find(stagesAdmDependencyLocationEnrollments.totalEnrollmentsByAdmDependency, t => t.id === AdmDependency.State);
+          const totalEnrollmentsByAdmDependencyMunicipal = _.find(stagesAdmDependencyLocationEnrollments.totalEnrollmentsByAdmDependency, t => t.id === AdmDependency.Municipal);
+          const totalCurrentPublicEnrollment = (totalEnrollmentsByAdmDependencyFederal.quantity + totalEnrollmentsByAdmDependencyState.quantity + totalEnrollmentsByAdmDependencyMunicipal.quantity);
 
-              if (collaboration) {
-                const enrollmentProjectionByLocation: EnrollmentProjectionByLocation = _.head(resultForEnrollmentProjection.enrollmentsProjectionsByLocations);
+          if (collaboration) {
+            const enrollmentProjectionByLocation: EnrollmentProjectionByLocation = _.head(resultForEnrollmentProjection.enrollmentsProjectionsByLocations);
 
-                const stageEnrollment = _.find(enrollmentProjectionByLocation.stagesEnrollments, r => r.id === stage.id);
+            const stageEnrollment = _.find(enrollmentProjectionByLocation.stagesEnrollments, r => r.id === stage.id);
 
-                if (stageEnrollment) {
-                  collaboration.numberCurrentPublicEnrollment = totalCurrentPublicEnrollment;
+            if (stageEnrollment) {
+              collaboration.numberCurrentPublicEnrollment = stageEnrollment.totalCurrentOffers;
 
-                  const stagesEnrollmentsProposal = _.find(enrollmentProjectionByLocation.stagesEnrollments, r => r.id === stage.id);
-                  collaboration.numberProposalPublicEnrollment =
-                    _.find(stagesEnrollmentsProposal.totalEnrollments, s => s.year === collaborationScheme.yearProposalPublicEnrollment).quantity;
+              const stagesEnrollmentsProposal = _.find(enrollmentProjectionByLocation.stagesEnrollments, r => r.id === stage.id);
+              collaboration.numberProposalPublicEnrollment =
+                _.find(stagesEnrollmentsProposal.totalEnrollments, s => s.year === collaborationScheme.yearProposalPublicEnrollment).quantity;
 
-                  collaboration.federalPercentage = ((totalEnrollmentsByAdmDependencyFederal / totalCurrentPublicEnrollment) * 100);
-                  collaboration.statePercentage = ((totalEnrollmentsByAdmDependencyState / totalCurrentPublicEnrollment) * 100);
-                  collaboration.municipalPercentage = ((totalEnrollmentsByAdmDependencyMunicipal / totalCurrentPublicEnrollment) * 100);
-                }
+              collaboration.federalPercentage = ((totalEnrollmentsByAdmDependencyFederal.quantity / totalCurrentPublicEnrollment) * 100);
+              collaboration.statePercentage = ((totalEnrollmentsByAdmDependencyState.quantity / totalCurrentPublicEnrollment) * 100);
+              collaboration.municipalPercentage = ((totalEnrollmentsByAdmDependencyMunicipal.quantity / totalCurrentPublicEnrollment) * 100);
+            }
 
-              }
+          }
 
-              collaborationScheme.collaborationSchemeByStage.push(collaboration);
-              collaborationScheme.totalCurrentPublicEnrollment = collaborationScheme.collaborationSchemeByStage.reduce((prevVal, elem) => prevVal + elem.numberCurrentPublicEnrollment, 0);
-              collaborationScheme.totalProposalPublicEnrollment = collaborationScheme.collaborationSchemeByStage.reduce((prevVal, elem) => prevVal + elem.numberProposalPublicEnrollment, 0);
-            }
-            collaborationScheme.sourceInformations = this.getSourceInformations();
-            return collaborationScheme;
+          collaborationScheme.collaborationSchemeByStage.push(collaboration);
+          collaborationScheme.totalCurrentPublicEnrollment = collaborationScheme.collaborationSchemeByStage.reduce((prevVal, elem) => prevVal + elem.numberCurrentPublicEnrollment, 0);
+          collaborationScheme.totalProposalPublicEnrollment = collaborationScheme.collaborationSchemeByStage.reduce((prevVal, elem) => prevVal + elem.numberProposalPublicEnrollment, 0);
+        }
+        collaborationScheme.sourceInformations = this.getSourceInformations();
+        return collaborationScheme;
 
-          }));
       }));
   }
 
@@ -113,29 +111,4 @@ export class CollaborationSchemeService implements NavigableComponentService {
     }));
     return footNotes;
   }
-
-  getEnrollmentT4(): Observable<any> {
-
-    let filtersLocation: Array<string> = new Array<string>();
-    const enrollmentCurrentYear: number = this.currentYearService.getEnrollmentCurrentYear();
-
-    filtersLocation = this.utilitiesService.getSelectLocationFilter();
-
-    let filters: Array<string> = new Array<string>(
-      `min_year:"${enrollmentCurrentYear}"`,
-      `max_year:"${enrollmentCurrentYear}"`,
-      `adm_dependency:["1","2","3"]`
-    );
-
-    filters = filters.concat(filtersLocation);
-
-    const options: any = this.httpService.getRequestOptionsWithSearchParams(new Map<string, string>([['filter', filters.join(',')]]));
-
-    return this.httpService.getApiEndpoint().pipe(
-      switchMap(apiEndpoint => {
-        return this.httpService.get<Array<any>>(`${apiEndpoint}/enrollment?dims=education_level_short,adm_dependency`, options).pipe(
-          map(diagnosticT4 => diagnosticT4));
-      }));
-  }
-
-}
+}
\ No newline at end of file
-- 
GitLab