|
|
@@ -1,36 +1,39 @@
|
|
|
-import { ActivatedRoute, Router } from "@angular/router";
|
|
|
-import { Component, OnInit, NgZone, ViewChild } from "@angular/core";
|
|
|
-import { Chart, ChartOptions, ChartType, ChartDataSets } from "chart.js";
|
|
|
-import { Label, BaseChartDirective } from "ng2-charts";
|
|
|
-import { PlantsService } from "src/app/services/plants.service";
|
|
|
-import { OrganizationsService } from "src/app/services/organizations.service";
|
|
|
-
|
|
|
-import { MatPaginator } from "@angular/material/paginator";
|
|
|
-import { MatSort } from "@angular/material/sort";
|
|
|
-import { MatTableDataSource } from "@angular/material/table";
|
|
|
-import { AuthService } from "@app/services/auth2.service";
|
|
|
-import { formatDate, DatePipe } from "@angular/common";
|
|
|
-
|
|
|
-import * as moment from "moment";
|
|
|
-import Swal from "sweetalert2";
|
|
|
-import { RatesService } from "@app/services/rates.service";
|
|
|
-import { CatalogsService } from "@app/services/catalogs.service";
|
|
|
-import { Rate } from "@app/models/rate";
|
|
|
+import { ActivatedRoute, Router } from '@angular/router';
|
|
|
+import { Component, OnInit, NgZone, ViewChild } from '@angular/core';
|
|
|
+import { Chart, ChartOptions, ChartType, ChartDataSets } from 'chart.js';
|
|
|
+import { Label, BaseChartDirective } from 'ng2-charts';
|
|
|
+import { PlantsService } from 'src/app/services/plants.service';
|
|
|
+import { OrganizationsService } from 'src/app/services/organizations.service';
|
|
|
+
|
|
|
+import { MatPaginator } from '@angular/material/paginator';
|
|
|
+import { MatSort } from '@angular/material/sort';
|
|
|
+import { MatTableDataSource } from '@angular/material/table';
|
|
|
+import { AuthService } from '@app/services/auth2.service';
|
|
|
+import { formatDate, DatePipe } from '@angular/common';
|
|
|
+
|
|
|
+import * as moment from 'moment';
|
|
|
+import Swal from 'sweetalert2';
|
|
|
+import { RatesService } from '@app/services/rates.service';
|
|
|
+import { CatalogsService } from '@app/services/catalogs.service';
|
|
|
+import { Rate } from '@app/models/rate';
|
|
|
+import { stringify } from 'querystring';
|
|
|
+import { Tariff } from '@app/models/tariff';
|
|
|
+import { Cargo } from '@app/models/cargo';
|
|
|
|
|
|
@Component({
|
|
|
- selector: "app-rates",
|
|
|
- templateUrl: "./rates.component.html",
|
|
|
- styleUrls: ["./rates.component.scss"],
|
|
|
+ selector: 'app-rates',
|
|
|
+ templateUrl: './rates.component.html',
|
|
|
+ styleUrls: ['./rates.component.scss'],
|
|
|
})
|
|
|
export class RatesComponent implements OnInit {
|
|
|
- title = "Tarifas";
|
|
|
+ title = 'Tarifas';
|
|
|
|
|
|
listData: any;
|
|
|
rows = [];
|
|
|
|
|
|
listAssets: any;
|
|
|
dataSource = new MatTableDataSource(this.listAssets);
|
|
|
- displayedColumns: string[] = ["name", "country", "city", "id"];
|
|
|
+ displayedColumns: string[] = ['name', 'country', 'city', 'id'];
|
|
|
|
|
|
error: boolean;
|
|
|
listOrganizations: any;
|
|
|
@@ -43,8 +46,8 @@ export class RatesComponent implements OnInit {
|
|
|
meterKeys2: any;
|
|
|
assetKeys: any;
|
|
|
|
|
|
- sumarize: number = 0;
|
|
|
- totalInstalled: number = 0;
|
|
|
+ sumarize = 0;
|
|
|
+ totalInstalled = 0;
|
|
|
|
|
|
totalMetersInstalled: string;
|
|
|
|
|
|
@@ -55,8 +58,8 @@ export class RatesComponent implements OnInit {
|
|
|
totalAssetsInstalled: any;
|
|
|
|
|
|
rates: Rate = {
|
|
|
- distribuidora: "-",
|
|
|
- codigo_tarifa: "-",
|
|
|
+ distribuidora: '-',
|
|
|
+ codigo_tarifa: '-',
|
|
|
tarifa_actual: {
|
|
|
dateMin: null,
|
|
|
dateMax: null,
|
|
|
@@ -84,31 +87,31 @@ export class RatesComponent implements OnInit {
|
|
|
chart1: Chart;
|
|
|
chart1Type;
|
|
|
barChartColors: any = [
|
|
|
- "#5c90aa",
|
|
|
- "#a7c1d3",
|
|
|
- "#4e5151",
|
|
|
- "#916458",
|
|
|
- "#ee964b",
|
|
|
- "#a9d0ea",
|
|
|
- "#a7c957",
|
|
|
- "#f2e8cf",
|
|
|
+ '#075d9d',
|
|
|
+ '#ff9800',
|
|
|
+ '#D1495B',
|
|
|
+ '#916458',
|
|
|
+ '#ee964b',
|
|
|
+ '#a9d0ea',
|
|
|
+ '#a7c957',
|
|
|
+ '#f2e8cf',
|
|
|
];
|
|
|
borderChartColors: any = [
|
|
|
- "#336b87",
|
|
|
- "#90afc5",
|
|
|
- "#2a3132",
|
|
|
- "#763626",
|
|
|
- "#d38d51",
|
|
|
- "#a2cae4",
|
|
|
- "#91b43d",
|
|
|
- "#d3cbb7",
|
|
|
+ '#336b87',
|
|
|
+ '#90afc5',
|
|
|
+ '#2a3132',
|
|
|
+ '#763626',
|
|
|
+ '#d38d51',
|
|
|
+ '#a2cae4',
|
|
|
+ '#91b43d',
|
|
|
+ '#d3cbb7',
|
|
|
];
|
|
|
public barChartType: ChartType;
|
|
|
public barChartLegend: boolean;
|
|
|
public barChartLabels: Label[];
|
|
|
public barChartOptions: ChartOptions;
|
|
|
public barChartData: ChartDataSets[];
|
|
|
- @ViewChild("baseChart", null) chart: BaseChartDirective;
|
|
|
+ @ViewChild('baseChart', null) chart: BaseChartDirective;
|
|
|
metersData: any[];
|
|
|
metersValues: unknown[];
|
|
|
distribuidoras: any;
|
|
|
@@ -116,6 +119,10 @@ export class RatesComponent implements OnInit {
|
|
|
distribuidoraSel: any;
|
|
|
tarifaSel: any;
|
|
|
|
|
|
+ tarifa: Tariff;
|
|
|
+ vigencia: string;
|
|
|
+ tarifaActual: Cargo[];
|
|
|
+
|
|
|
constructor(
|
|
|
private plantsService: PlantsService,
|
|
|
private route: ActivatedRoute,
|
|
|
@@ -124,15 +131,16 @@ export class RatesComponent implements OnInit {
|
|
|
private zone: NgZone,
|
|
|
private authService: AuthService,
|
|
|
private ratesService: RatesService,
|
|
|
- private catalogService: CatalogsService
|
|
|
+ private catalogService: CatalogsService,
|
|
|
+ private datePipe: DatePipe
|
|
|
) {
|
|
|
//DEMO
|
|
|
this.userLevel = +this.authService.getUserLevel();
|
|
|
|
|
|
Swal.fire({
|
|
|
allowOutsideClick: false,
|
|
|
- type: "info",
|
|
|
- text: "Espere por favor...",
|
|
|
+ type: 'info',
|
|
|
+ text: 'Espere por favor...',
|
|
|
});
|
|
|
Swal.showLoading();
|
|
|
}
|
|
|
@@ -142,146 +150,136 @@ export class RatesComponent implements OnInit {
|
|
|
Swal.close();
|
|
|
}, 3000);
|
|
|
|
|
|
- this.ratesService.getDefaultRate().subscribe((res) => {
|
|
|
- this.rates = res["data"];
|
|
|
- });
|
|
|
+ this.getCurretTariff();
|
|
|
|
|
|
- this.catalogService.getCatalogByName("distribuidoras").subscribe((res) => {
|
|
|
- this.distribuidoras = res["data"]["catalogo"]["records"];
|
|
|
+ this.catalogService.getCatalogByName('distribuidoras').subscribe((res) => {
|
|
|
+ this.distribuidoras = res.data.catalogo.records;
|
|
|
});
|
|
|
|
|
|
- this.catalogService.getCatalogByName("tarifas").subscribe((res) => {
|
|
|
- this.tarifas = res["data"]["catalogo"]["records"];
|
|
|
+ this.catalogService.getCatalogByName('tarifas').subscribe((res) => {
|
|
|
+ this.tarifas = res.data.catalogo.records;
|
|
|
+
|
|
|
});
|
|
|
|
|
|
this.ratesService.getHistoricalRate().subscribe((res) => {
|
|
|
this.metersData = [];
|
|
|
- this.metersValues = Object.values(res["data"]["tarifas"]);
|
|
|
-
|
|
|
- let meterKeys2 = Object.keys(this.metersValues);
|
|
|
-
|
|
|
- let labels = [];
|
|
|
- let cargo_energia = [];
|
|
|
- let cargo_energia_b1 = [];
|
|
|
- let cargo_energia_b2 = [];
|
|
|
- let cargo_energia_b3 = [];
|
|
|
- let cargo_energia_punta = [];
|
|
|
- let cargo_energia_resto = [];
|
|
|
- let cargo_energia_valle = [];
|
|
|
-
|
|
|
- for (let prop in meterKeys2) {
|
|
|
- labels.push(
|
|
|
- `${this.metersValues[prop]["dateMin"]} - ${this.metersValues[prop]["dateMax"]}`
|
|
|
- );
|
|
|
- if (this.metersValues[prop]["cargo_energia"] != "") {
|
|
|
- cargo_energia.push(this.metersValues[prop]["cargo_energia"]);
|
|
|
+ this.metersValues = Object.values(res.data.tarifas);
|
|
|
+ const meterKeys2 = Object.keys(this.metersValues);
|
|
|
+
|
|
|
+ const labels = [];
|
|
|
+ const cargoEnergia = [];
|
|
|
+ const cargoEnergiaB1 = [];
|
|
|
+ const cargoEnergiaB2 = [];
|
|
|
+ const cargoEnergiaB3 = [];
|
|
|
+ const cargoEnergiaPunta = [];
|
|
|
+ const cargoEnergiaResto = [];
|
|
|
+ const cargoEnergiaValle = [];
|
|
|
+
|
|
|
+
|
|
|
+ res.data.tarifas.forEach(tarifa => {
|
|
|
+ labels.push(`${tarifa.dateMin}`);
|
|
|
+ if (tarifa.cargo_energia) {
|
|
|
+ cargoEnergia.push(tarifa.cargo_energia);
|
|
|
}
|
|
|
- if (this.metersValues[prop]["cargo_energia_b1"] != "") {
|
|
|
- cargo_energia_b1.push(this.metersValues[prop]["cargo_energia_b1"]);
|
|
|
+ if (tarifa.cargo_energia_b1) {
|
|
|
+ cargoEnergiaB1.push(tarifa.cargo_energia_b1);
|
|
|
}
|
|
|
- if (this.metersValues[prop]["cargo_energia_b2"] != "") {
|
|
|
- cargo_energia_b2.push(this.metersValues[prop]["cargo_energia_b2"]);
|
|
|
+ if (tarifa.cargo_energia_b2) {
|
|
|
+ cargoEnergiaB2.push(tarifa.cargo_energia_b2);
|
|
|
}
|
|
|
- if (this.metersValues[prop]["cargo_energia_b3"] != "") {
|
|
|
- cargo_energia_b3.push(this.metersValues[prop]["cargo_energia_b3"]);
|
|
|
+ if (tarifa.cargo_energia_b3) {
|
|
|
+ cargoEnergiaB3.push(tarifa.cargo_energia_b3);
|
|
|
}
|
|
|
- if (this.metersValues[prop]["cargo_energia_punta"] != "") {
|
|
|
- cargo_energia_punta.push(
|
|
|
- this.metersValues[prop]["cargo_energia_punta"]
|
|
|
- );
|
|
|
+ if (tarifa.cargo_energia_punta) {
|
|
|
+ cargoEnergiaPunta.push(tarifa.cargo_energia_punta);
|
|
|
}
|
|
|
- if (this.metersValues[prop]["cargo_energia_resto"] != "") {
|
|
|
- cargo_energia_resto.push(
|
|
|
- this.metersValues[prop]["cargo_energia_resto"]
|
|
|
- );
|
|
|
+ if (tarifa.cargo_energia_resto) {
|
|
|
+ cargoEnergiaResto.push(tarifa.cargo_energia_resto);
|
|
|
}
|
|
|
- if (this.metersValues[prop]["cargo_energia_valle"] != "") {
|
|
|
- cargo_energia_valle.push(
|
|
|
- this.metersValues[prop]["cargo_energia_valle"]
|
|
|
- );
|
|
|
+ if (tarifa.cargo_energia_valle) {
|
|
|
+ cargoEnergiaValle.push(tarifa.cargo_energia_valle);
|
|
|
}
|
|
|
- }
|
|
|
- this.barChartType = "line";
|
|
|
+ });
|
|
|
+
|
|
|
+ this.barChartType = 'bar';
|
|
|
+
|
|
|
+ // Process Chart labels
|
|
|
+ labels.forEach((date, index, arr) => {
|
|
|
+ arr[index] = this.datePipe.transform(new Date(date), 'dd/MMM/yy', '+0000');
|
|
|
+ });
|
|
|
+
|
|
|
this.barChartLabels = labels;
|
|
|
|
|
|
- if (cargo_energia.length > 0) {
|
|
|
+
|
|
|
+ if (cargoEnergia.length > 0) {
|
|
|
this.metersData.push({
|
|
|
- label: "Cargo energia",
|
|
|
- backgroundColor: this.barChartColors[0],
|
|
|
- data: cargo_energia,
|
|
|
- barPercentage: 0.7,
|
|
|
- borderColor: this.borderChartColors[0],
|
|
|
+ label: 'Cargo Energía',
|
|
|
+ data: cargoEnergia,
|
|
|
+
|
|
|
});
|
|
|
}
|
|
|
- if (cargo_energia_b1.length > 0) {
|
|
|
+ if (cargoEnergiaB1.length > 0) {
|
|
|
this.metersData.push({
|
|
|
- label: "Cargo energia bloque 1",
|
|
|
- backgroundColor: this.barChartColors[1],
|
|
|
- data: cargo_energia_b1,
|
|
|
- barPercentage: 0.7,
|
|
|
- borderColor: this.borderChartColors[1],
|
|
|
+ label: 'Cargo Energía Bloque 1',
|
|
|
+ data: cargoEnergiaB1,
|
|
|
+
|
|
|
});
|
|
|
}
|
|
|
- if (cargo_energia_b2.length > 0) {
|
|
|
+ if (cargoEnergiaB2.length > 0) {
|
|
|
this.metersData.push({
|
|
|
- label: "Cargo energia bloque 2",
|
|
|
- backgroundColor: this.barChartColors[2],
|
|
|
- data: cargo_energia_b2,
|
|
|
- barPercentage: 0.7,
|
|
|
- borderColor: this.borderChartColors[2],
|
|
|
+ label: 'Cargo Energía Bloque 2',
|
|
|
+ data: cargoEnergiaB2,
|
|
|
+
|
|
|
});
|
|
|
}
|
|
|
- if (cargo_energia_b3.length > 0) {
|
|
|
+ if (cargoEnergiaB3.length > 0) {
|
|
|
this.metersData.push({
|
|
|
- label: "Cargo energia bloque 3",
|
|
|
- backgroundColor: this.barChartColors[3],
|
|
|
- data: cargo_energia_b3,
|
|
|
- barPercentage: 0.7,
|
|
|
- borderColor: this.borderChartColors[3],
|
|
|
+ label: 'Cargo Energía Bloque 3',
|
|
|
+ data: cargoEnergiaB3,
|
|
|
+
|
|
|
});
|
|
|
}
|
|
|
- if (cargo_energia_punta.length > 0) {
|
|
|
+ if (cargoEnergiaPunta.length > 0) {
|
|
|
this.metersData.push({
|
|
|
- label: "Cargo energia punta",
|
|
|
- backgroundColor: this.barChartColors[4],
|
|
|
- data: cargo_energia_punta,
|
|
|
- barPercentage: 0.7,
|
|
|
- borderColor: this.borderChartColors[4],
|
|
|
+ label: 'Cargo Energía Punta',
|
|
|
+ data: cargoEnergiaPunta,
|
|
|
+
|
|
|
});
|
|
|
}
|
|
|
- if (cargo_energia_resto.length > 0) {
|
|
|
+ if (cargoEnergiaResto.length > 0) {
|
|
|
this.metersData.push({
|
|
|
- label: "Cargo energia resto",
|
|
|
- backgroundColor: this.barChartColors[5],
|
|
|
- data: cargo_energia_resto,
|
|
|
- barPercentage: 0.7,
|
|
|
- borderColor: this.borderChartColors[5],
|
|
|
+ label: 'Cargo Energía Resto',
|
|
|
+ data: cargoEnergiaResto,
|
|
|
+
|
|
|
});
|
|
|
}
|
|
|
- if (cargo_energia_valle.length > 0) {
|
|
|
+ if (cargoEnergiaValle.length > 0) {
|
|
|
this.metersData.push({
|
|
|
- label: "Cargo energia valle",
|
|
|
- backgroundColor: this.barChartColors[6],
|
|
|
- data: cargo_energia_valle,
|
|
|
- barPercentage: 0.7,
|
|
|
- borderColor: this.borderChartColors[6],
|
|
|
+ label: 'Cargo Energía Valle',
|
|
|
+ data: cargoEnergiaValle,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ // Set colors
|
|
|
+ this.metersData.forEach((dataset, i) => {
|
|
|
+ dataset.backgroundColor = this.barChartColors[i];
|
|
|
+ dataset.hoverBackgroundColor = this.barChartColors[i];
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
this.barChartOptions = {
|
|
|
title: {
|
|
|
- display: true,
|
|
|
+ display: false,
|
|
|
},
|
|
|
tooltips: {
|
|
|
- mode: "index",
|
|
|
+ mode: 'index',
|
|
|
callbacks: {
|
|
|
// Get the total of the energy produced in every point and show it in the hover tooltip
|
|
|
- label: function (tooltipItem, data) {
|
|
|
- var label = data.datasets[tooltipItem.datasetIndex].label || "";
|
|
|
- var value =
|
|
|
- data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
|
|
|
+ label: (tooltipItem, data) => {
|
|
|
+ const label = data.datasets[tooltipItem.datasetIndex].label || '';
|
|
|
+ const value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
|
|
|
|
|
|
- return label + " : " + value;
|
|
|
+ return `${label} : ${Number.parseFloat(value.toString()).toPrecision(6)}`;
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -296,10 +294,10 @@ export class RatesComponent implements OnInit {
|
|
|
yAxes: [
|
|
|
{
|
|
|
stacked: false,
|
|
|
- position: "left",
|
|
|
+ position: 'left',
|
|
|
scaleLabel: {
|
|
|
display: true,
|
|
|
- labelString: "Tarifa en $USD por kWh",
|
|
|
+ labelString: '$USD/kWh',
|
|
|
},
|
|
|
},
|
|
|
],
|
|
|
@@ -312,7 +310,7 @@ export class RatesComponent implements OnInit {
|
|
|
|
|
|
var responsiveOptions: any[] = [
|
|
|
[
|
|
|
- "screen and (max-width: 640px)",
|
|
|
+ 'screen and (max-width: 640px)',
|
|
|
{
|
|
|
seriesBarDistance: 5,
|
|
|
axisX: {
|
|
|
@@ -323,9 +321,10 @@ export class RatesComponent implements OnInit {
|
|
|
},
|
|
|
],
|
|
|
];
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- ngOnChanges(): void {}
|
|
|
+ ngOnChanges(): void { }
|
|
|
|
|
|
onChangeD(event: any) {
|
|
|
this.distribuidoraSel = event.target.value;
|
|
|
@@ -333,4 +332,22 @@ export class RatesComponent implements OnInit {
|
|
|
onChangeT(event: any) {
|
|
|
this.tarifaSel = event.target.value;
|
|
|
}
|
|
|
+
|
|
|
+ getCurretTariff(): void {
|
|
|
+ this.ratesService.getDefaultRate().subscribe(tarifa => {
|
|
|
+ this.tarifa = tarifa.data;
|
|
|
+ this.tarifaActual = this.tarifa.tarifa_actual.cargos.filter(cargo => cargo.value !== '');
|
|
|
+ this.vigencia = this.getTariffPeriod(this.tarifa);
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ getTariffPeriod(tarifa: Tariff) {
|
|
|
+ const inicio = this.datePipe.transform(new Date(tarifa.tarifa_actual.vigencia.inicio), 'dd/MMM/yy', '+0000')
|
|
|
+ const fin = this.datePipe.transform(new Date(tarifa.tarifa_actual.vigencia.fin), 'dd/MMM/yy', '+0000')
|
|
|
+ const period = `Vigencia: ${inicio} - ${fin}`;
|
|
|
+ return period;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|