Bläddra i källkod

Merge branch 'features' of onunez/soma-frontend into development

Oscar José Nuñez Chávez 5 år sedan
förälder
incheckning
de4eda4c63

+ 8 - 1
src/app/components/dashboard/dashboard.component.html

@@ -42,29 +42,33 @@
                 </div>
               </div>
               <div class="col-sm-12 col-md-6">
-                <h4>Tarifa actual:</h4>
+                <h4>Tarifa actual (USD$/kWh):</h4>
                 <div *ngIf="rates.tarifa_actual.cargo_energia">
                   Cargo de energia:
                   <strong>
                     {{ rates.tarifa_actual.cargo_energia | number: "1.2-4" }}
+                    USD$/kWh
                   </strong>
                 </div>
                 <div *ngIf="rates.tarifa_actual.cargo_energia_b1">
                   Cargo de energia por bloque 1:
                   <strong>
                     {{ rates.tarifa_actual.cargo_energia_b1 | number: "1.2-4" }}
+                    USD$/kWh
                   </strong>
                 </div>
                 <div *ngIf="rates.tarifa_actual.cargo_energia_b2">
                   Cargo de energia por bloque 2:
                   <strong>
                     {{ rates.tarifa_actual.cargo_energia_b2 | number: "1.2-4" }}
+                    USD$/kWh
                   </strong>
                 </div>
                 <div *ngIf="rates.tarifa_actual.cargo_energia_b3">
                   Cargo de energia por bloque 3:
                   <strong>
                     {{ rates.tarifa_actual.cargo_energia_b3 | number: "1.2-4" }}
+                    USD$/kWh
                   </strong>
                 </div>
                 <div *ngIf="rates.tarifa_actual.cargo_energia_punta">
@@ -73,6 +77,7 @@
                     {{
                       rates.tarifa_actual.cargo_energia_punta | number: "1.2-4"
                     }}
+                    USD$/kWh
                   </strong>
                 </div>
                 <div *ngIf="rates.tarifa_actual.cargo_energia_resto">
@@ -81,6 +86,7 @@
                     {{
                       rates.tarifa_actual.cargo_energia_resto | number: "1.2-4"
                     }}
+                    USD$/kWh
                   </strong>
                 </div>
                 <div *ngIf="rates.tarifa_actual.cargo_energia_valle">
@@ -89,6 +95,7 @@
                     {{
                       rates.tarifa_actual.cargo_energia_valle | number: "1.2-4"
                     }}
+                    USD$/kWh
                   </strong>
                 </div>
                 <br />

+ 1 - 6
src/app/components/profile/profile.component.ts

@@ -46,10 +46,6 @@ export class ProfileComponent implements OnInit {
     });
     Swal.showLoading();
 
-    this.catalogsService.getCatalogs().subscribe((res) => {
-      console.log(res);
-    });
-
     this.catalogsService.getCatalogByName("distribuidoras").subscribe((res) => {
       this.distributor = res["data"]["catalogo"]["records"];
     });
@@ -62,7 +58,6 @@ export class ProfileComponent implements OnInit {
       .getUserById(this.authService.getUserId())
       .subscribe((ans) => {
         this.user = ans["data"]["user"];
-        console.log(this.user);
         Swal.close();
         this.editProfile = true;
         this.first_name = this.user.first_name;
@@ -98,7 +93,6 @@ export class ProfileComponent implements OnInit {
 
   editUser(form: any) {
     this.submitted = true;
-    console.log(this.userForm);
     // stop here if form is invalid
     if (this.userForm.invalid) {
       return;
@@ -135,6 +129,7 @@ export class ProfileComponent implements OnInit {
             confirmButtonText: "Se ha actualizado su perfil exitosamente",
           }).then((result) => {
             Swal.close();
+            window.location.reload();
           });
         }
       },

+ 43 - 17
src/app/components/rates/rates.component.html

@@ -21,29 +21,33 @@
                     {{ rates.distribuidora }}
                   </strong>
                 </h3>
-                <h4>Tarifa actual:</h4>
+                <h4>Tarifa actual (USD$/kWh):</h4>
                 <div *ngIf="rates.tarifa_actual.cargo_energia">
                   Cargo de energia:
                   <strong>
                     {{ rates.tarifa_actual.cargo_energia | number: "1.2-4" }}
+                    USD$/kWh
                   </strong>
                 </div>
                 <div *ngIf="rates.tarifa_actual.cargo_energia_b1">
                   Cargo de energia por bloque 1:
                   <strong>
                     {{ rates.tarifa_actual.cargo_energia_b1 | number: "1.2-4" }}
+                    USD$/kWh
                   </strong>
                 </div>
                 <div *ngIf="rates.tarifa_actual.cargo_energia_b2">
                   Cargo de energia por bloque 2:
                   <strong>
                     {{ rates.tarifa_actual.cargo_energia_b2 | number: "1.2-4" }}
+                    USD$/kWh
                   </strong>
                 </div>
                 <div *ngIf="rates.tarifa_actual.cargo_energia_b3">
                   Cargo de energia por bloque 3:
                   <strong>
                     {{ rates.tarifa_actual.cargo_energia_b3 | number: "1.2-4" }}
+                    USD$/kWh
                   </strong>
                 </div>
                 <div *ngIf="rates.tarifa_actual.cargo_energia_punta">
@@ -52,6 +56,7 @@
                     {{
                       rates.tarifa_actual.cargo_energia_punta | number: "1.2-4"
                     }}
+                    USD$/kWh
                   </strong>
                 </div>
                 <div *ngIf="rates.tarifa_actual.cargo_energia_resto">
@@ -60,6 +65,7 @@
                     {{
                       rates.tarifa_actual.cargo_energia_resto | number: "1.2-4"
                     }}
+                    USD$/kWh
                   </strong>
                 </div>
                 <div *ngIf="rates.tarifa_actual.cargo_energia_valle">
@@ -68,6 +74,7 @@
                     {{
                       rates.tarifa_actual.cargo_energia_valle | number: "1.2-4"
                     }}
+                    USD$/kWh
                   </strong>
                 </div>
                 <br />
@@ -84,7 +91,7 @@
                 </div>
                 <h4>Incremento con respecto a tarifa anterior (%)</h4>
 
-                <div *ngIf="rates.incremento_porcentaje.cargo_energia">
+                <div *ngIf="rates.incremento_porcentaje.cargo_energia != null">
                   Cargo de energia:
                   <strong>
                     {{
@@ -93,7 +100,10 @@
                     }}%
                   </strong>
                 </div>
-                <div *ngIf="rates.incremento_porcentaje.cargo_energia_b1">
+
+                <div
+                  *ngIf="rates.incremento_porcentaje.cargo_energia_b1 != null"
+                >
                   Cargo de energia por bloque 1:
                   <strong>
                     {{
@@ -102,7 +112,9 @@
                     }}%
                   </strong>
                 </div>
-                <div *ngIf="rates.incremento_porcentaje.cargo_energia_b2">
+                <div
+                  *ngIf="rates.incremento_porcentaje.cargo_energia_b2 != null"
+                >
                   Cargo de energia por bloque 2:
                   <strong>
                     {{
@@ -111,16 +123,22 @@
                     }}%
                   </strong>
                 </div>
-                <div *ngIf="rates.incremento_porcentaje.cargo_energia_b3">
+                <div
+                  *ngIf="rates.incremento_porcentaje.cargo_energia_b3 != null"
+                >
                   Cargo de energia por bloque 3:
                   <strong>
                     {{
                       rates.incremento_porcentaje.cargo_energia_b3
-                        | number: "1.2-4"
+                        | number: "0.2-4"
                     }}%
                   </strong>
                 </div>
-                <div *ngIf="rates.incremento_porcentaje.cargo_energia_punta">
+                <div
+                  *ngIf="
+                    rates.incremento_porcentaje.cargo_energia_punta != null
+                  "
+                >
                   Cargo de energia punta:
                   <strong>
                     {{
@@ -129,7 +147,11 @@
                     }}%
                   </strong>
                 </div>
-                <div *ngIf="rates.incremento_porcentaje.cargo_energia_resto">
+                <div
+                  *ngIf="
+                    rates.incremento_porcentaje.cargo_energia_resto != null
+                  "
+                >
                   Cargo de energia resto:
                   <strong>
                     {{
@@ -138,7 +160,11 @@
                     }}%
                   </strong>
                 </div>
-                <div *ngIf="rates.incremento_porcentaje.cargo_energia_valle">
+                <div
+                  *ngIf="
+                    rates.incremento_porcentaje.cargo_energia_valle != null
+                  "
+                >
                   Cargo de energia valle:
                   <strong>
                     {{
@@ -209,11 +235,11 @@
               name="sel3"
             >
               <option
-                *ngFor="let item of listAssets"
-                [selected]="item.id === assetID"
-                [value]="item.id"
+                *ngFor="let item of distribuidoras"
+                [selected]="item.codigo === distribuidoraSel"
+                [value]="item.codigo"
               >
-                {{ userLevel == 0 ? "PLANTA INVERLEC" : item.name }}</option
+                {{ item.nombre }}</option
               >
             </select>
           </div>
@@ -230,11 +256,11 @@
               name="sel3"
             >
               <option
-                *ngFor="let item of listAssets"
-                [selected]="item.id === assetID"
-                [value]="item.id"
+                *ngFor="let item of tarifas"
+                [selected]="item.codigo === tarifaSel"
+                [value]="item.codigo"
               >
-                {{ userLevel == 0 ? "PLANTA INVERLEC" : item.name }}</option
+                {{ item.nombre }}</option
               >
             </select>
           </div>

+ 76 - 58
src/app/components/rates/rates.component.ts

@@ -14,6 +14,7 @@ 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";
 
 @Component({
   selector: "app-rates",
@@ -109,6 +110,8 @@ export class RatesComponent implements OnInit {
   @ViewChild("baseChart", null) chart: BaseChartDirective;
   metersData: any[];
   metersValues: unknown[];
+  distribuidoras: any;
+  tarifas: any;
 
   constructor(
     private plantsService: PlantsService,
@@ -117,7 +120,8 @@ export class RatesComponent implements OnInit {
     private router: Router,
     private zone: NgZone,
     private authService: AuthService,
-    private ratesService: RatesService
+    private ratesService: RatesService,
+    private catalogService: CatalogsService
   ) {
     //DEMO
     this.userLevel = +this.authService.getUserLevel();
@@ -136,18 +140,21 @@ export class RatesComponent implements OnInit {
     }, 3000);
 
     this.ratesService.getDefaultRate().subscribe((res) => {
-      console.log("tarifa");
-      console.log(res);
       this.rates = res["data"];
     });
 
+    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.ratesService.getHistoricalRate().subscribe((res) => {
-      console.log("historico");
-      console.log(res);
       this.metersData = [];
       this.metersValues = Object.values(res["data"]["tarifas"]);
 
-      console.log(this.metersValues);
       let meterKeys2 = Object.keys(this.metersValues);
 
       let labels = [];
@@ -155,99 +162,108 @@ export class RatesComponent implements OnInit {
       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) {
-        console.log();
-        //let label = localStorage.getItem("email") == "inverlec@grupomerelec.com" ? `INVERLEC ${prop}` : this.metersValues[prop]["label"];
-
-        //label = this.metersValues["dateMin"] + "-" + this.metersValues["dateMax"] ;
-        /*
-        let measure_values = Object.values(
-          this.metersValues[prop]["data"]
-            .map((obj) => obj.total_energy_kWh)
-            .reverse()
-        );*/
-
         labels.push(
           `${this.metersValues[prop]["dateMin"]} - ${this.metersValues[prop]["dateMax"]}`
         );
-
         if (this.metersValues[prop]["cargo_energia"] != "") {
           cargo_energia.push(this.metersValues[prop]["cargo_energia"]);
         }
-
         if (this.metersValues[prop]["cargo_energia_b1"] != "") {
           cargo_energia_b1.push(this.metersValues[prop]["cargo_energia_b1"]);
         }
-
         if (this.metersValues[prop]["cargo_energia_b2"] != "") {
           cargo_energia_b2.push(this.metersValues[prop]["cargo_energia_b2"]);
         }
-
         if (this.metersValues[prop]["cargo_energia_b3"] != "") {
           cargo_energia_b3.push(this.metersValues[prop]["cargo_energia_b3"]);
         }
-
-        /*
-        
-        
-        this.metersData.push(
-          {
-            label: label,
-            backgroundColor: this.barChartColors[prop],
-            data: measure_values,
-            barPercentage: 0.7,
-            borderColor: this.borderChartColors[prop],
-          }
-        );*/
+        if (this.metersValues[prop]["cargo_energia_punta"] != "") {
+          cargo_energia_punta.push(
+            this.metersValues[prop]["cargo_energia_punta"]
+          );
+        }
+        if (this.metersValues[prop]["cargo_energia_resto"] != "") {
+          cargo_energia_resto.push(
+            this.metersValues[prop]["cargo_energia_resto"]
+          );
+        }
+        if (this.metersValues[prop]["cargo_energia_valle"] != "") {
+          cargo_energia_valle.push(
+            this.metersValues[prop]["cargo_energia_valle"]
+          );
+        }
       }
-      console.log(labels);
       this.barChartType = "line";
       this.barChartLabels = labels;
 
-      this.metersData.push(
-        {
+      if (cargo_energia.length > 0) {
+        this.metersData.push({
           label: "Cargo energia",
           backgroundColor: this.barChartColors[0],
           data: cargo_energia,
           barPercentage: 0.7,
           borderColor: this.borderChartColors[0],
-        },
-        {
+        });
+      }
+      if (cargo_energia_b1.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],
-        },
-        {
+        });
+      }
+      if (cargo_energia_b2.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],
-        },
-        {
+        });
+      }
+      if (cargo_energia_b3.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],
-        }
-      );
-      /*
-      
-      this.metersValues[0]["data"]
-                  .map((obj) =>
-                    formatDate(
-                      obj.dateMin.replace(/-/g, "/").replace("T", " "),
-                      "HH:mm ",
-                      "es-Es",
-                      "-0600"
-                    )
-                  )
-                  .reverse();
-      */
+        });
+      }
+      if (cargo_energia_punta.length > 0) {
+        this.metersData.push({
+          label: "Cargo energia punta",
+          backgroundColor: this.barChartColors[4],
+          data: cargo_energia_punta,
+          barPercentage: 0.7,
+          borderColor: this.borderChartColors[4],
+        });
+      }
+      if (cargo_energia_resto.length > 0) {
+        this.metersData.push({
+          label: "Cargo energia resto",
+          backgroundColor: this.barChartColors[5],
+          data: cargo_energia_resto,
+          barPercentage: 0.7,
+          borderColor: this.borderChartColors[5],
+        });
+      }
+      if (cargo_energia_valle.length > 0) {
+        this.metersData.push({
+          label: "Cargo energia valle",
+          backgroundColor: this.barChartColors[6],
+          data: cargo_energia_valle,
+          barPercentage: 0.7,
+          borderColor: this.borderChartColors[6],
+        });
+      }
 
       this.barChartOptions = {
         title: {
@@ -307,4 +323,6 @@ export class RatesComponent implements OnInit {
   }
 
   ngOnChanges(): void {}
+
+  onChangeObj() {}
 }