perbaikan cost management service

This commit is contained in:
Fuzi_fauzia 2024-06-12 10:08:23 +07:00
parent 70d8993141
commit ef118ad33e
3 changed files with 66 additions and 53 deletions

View File

@ -168,8 +168,10 @@
type="button" type="button"
class="btn btn-outline-success ml-2" class="btn btn-outline-success ml-2"
(click)="doFilter()" (click)="doFilter()"
[disabled]="spinnerFilterActive"
> >
<i class="la la-search"></i> <i class="la la-search" *ngIf="!spinnerFilterActive"></i>
<i class="la la-spinner spinner" *ngIf="spinnerFilterActive"></i>
</button> </button>
</div> </div>
</div> </div>
@ -358,15 +360,9 @@
> >
<button <button
class="btn btn-sm btn-warning mr-1" class="btn btn-sm btn-warning mr-1"
(click)="editRow(row)" (click)="viewRow(row)"
> >
<i class="ficon feather ft-edit"></i> <i class="ficon feather ft-eye"></i>
</button>
<button
class="btn btn-sm btn-danger"
(click)="deleteRow(row)"
>
<i class="ficon feather ft-trash-2"></i>
</button> </button>
</ng-template> </ng-template>
</ngx-datatable-column> </ngx-datatable-column>

View File

@ -26,6 +26,7 @@ export class CostManagementComponent implements OnInit {
public focucedElement = ""; public focucedElement = "";
spinnerActive = false; spinnerActive = false;
spinnerActiveActual = false; spinnerActiveActual = false;
spinnerFilterActive = false;
donutChart2: any; donutChart2: any;
@ -67,32 +68,37 @@ export class CostManagementComponent implements OnInit {
const currentDate = new Date(); const currentDate = new Date();
this.dateSelected = currentDate.toISOString().slice(0, 7); this.dateSelected = currentDate.toISOString().slice(0, 7);
this.fetchData(this.storedData.buildingId, this.dateSelected, this.categorySelected); this.fetchData(
this.storedData.buildingId,
this.dateSelected,
this.categorySelected
);
this.dataListMaster(); this.dataListMaster();
this.dataListBuilding(); this.dataListBuilding();
this.dataCompWaterElectCost(this.storedData.buildingId); this.dataCompWaterElectCost(this.storedData.buildingId);
this.dataCompPrevMonthCost(this.storedData.buildingId); this.dataCompPrevMonthCost(this.storedData.buildingId);
this.dataCompActEstCost(this.storedData.buildingId); this.dataCompActEstCost(this.storedData.buildingId);
} }
fetchData(id, period, category) { fetchData(id, period, category) {
this.costService.getCostManagement(id, period, category).subscribe((response) => { this.costService
this.data = response.results.data; .getCostManagement(id, period, category)
this.filteredRows = this.data; .subscribe((response) => {
this.kwhTerm = response.results.kwh; this.data = response.results.data;
this.costTerm = response.results.cost; this.filteredRows = this.data;
this.kwhTerm = response.results.kwh;
this.costTerm = response.results.cost;
this.data_cost = this.filteredRows.map((item) => ({ this.data_cost = this.filteredRows.map((item) => ({
building: item.name, building: item.name,
categoryName: item.category_name, categoryName: item.category_name,
estimationCost: item.estimation_cost, estimationCost: item.estimation_cost,
totalUse: item.total_use, totalUse: item.total_use,
endDate: item.end_date, endDate: item.end_date,
statusId: item.status_id, statusId: item.status_id,
})); }));
}); });
} }
dataListMaster() { dataListMaster() {
@ -222,7 +228,11 @@ export class CostManagementComponent implements OnInit {
}); });
setTimeout(() => { setTimeout(() => {
this.spinnerActive = false; this.spinnerActive = false;
this.fetchData(this.buildingSelected, this.dateSelected, this.categorySelected ); this.fetchData(
this.buildingSelected,
this.dateSelected,
this.categorySelected
);
}, 3000); }, 3000);
} }
@ -236,7 +246,11 @@ export class CostManagementComponent implements OnInit {
}); });
setTimeout(() => { setTimeout(() => {
this.spinnerActiveActual = false; this.spinnerActiveActual = false;
this.fetchData(this.buildingSelected, this.dateSelected, this.categorySelected ); this.fetchData(
this.buildingSelected,
this.dateSelected,
this.categorySelected
);
}, 3000); }, 3000);
} }
@ -247,10 +261,18 @@ export class CostManagementComponent implements OnInit {
date: this.dateSelected, date: this.dateSelected,
searchTerm: this.searchTerm, searchTerm: this.searchTerm,
}; };
this.fetchData(this.buildingSelected, this.dateSelected, this.categorySelected ); this.spinnerFilterActive = true;
this.dataCompWaterElectCost(this.buildingSelected); setTimeout(() => {
this.dataCompPrevMonthCost(this.buildingSelected); this.spinnerFilterActive = false;
this.dataCompActEstCost(this.buildingSelected); this.fetchData(
this.buildingSelected,
this.dateSelected,
this.categorySelected
);
this.dataCompWaterElectCost(this.buildingSelected);
this.dataCompPrevMonthCost(this.buildingSelected);
this.dataCompActEstCost(this.buildingSelected);
}, 3000);
} }
addFieldValue() { addFieldValue() {
@ -301,19 +323,4 @@ export class CostManagementComponent implements OnInit {
console.log("View row:", row); console.log("View row:", row);
this.router.navigate(["/cost-management/view", row.name]); this.router.navigate(["/cost-management/view", row.name]);
} }
editRow(row) {
console.log("Edit row:", row);
this.router.navigate(["/cost-management/edit", row.name]);
}
deleteRow(row) {
console.log("Delete row:", row);
}
onTouchStart(event: Event) {
event.preventDefault(); // Add this if necessary
}
} }

View File

@ -2,6 +2,8 @@ import { Injectable } from "@angular/core";
import { HttpClient, HttpHeaders } from "@angular/common/http"; import { HttpClient, HttpHeaders } from "@angular/common/http";
import { Observable } from "rxjs"; import { Observable } from "rxjs";
const BASE_URL = 'https://kapi.absys.ninja/hemat';
@Injectable({ @Injectable({
providedIn: "root", providedIn: "root",
}) })
@ -9,7 +11,7 @@ export class CostManagementService {
constructor(private http: HttpClient) {} constructor(private http: HttpClient) {}
getCostManagement(id, period, category): Observable<any> { getCostManagement(id, period, category): Observable<any> {
const baseUrl = `https://kapi.absys.ninja/hemat/cost_management`; const endpoint = `/cost_management`;
const params = new URLSearchParams({ const params = new URLSearchParams({
page: "1", page: "1",
limit: "100", limit: "100",
@ -19,31 +21,37 @@ export class CostManagementService {
if (category) { if (category) {
params.append("category_id", category); params.append("category_id", category);
} }
const url = `${baseUrl}?${params.toString()}`; const url = `${BASE_URL}${endpoint}?${params.toString()}`;
const headers = new HttpHeaders({ const headers = new HttpHeaders({
"Content-Type": "application/json", "Content-Type": "application/json",
"x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT",
}); });
return this.http.get<any>(url, { headers }); return this.http.get<any>(url, { headers });
} }
getCompWaterElectCost(id): Observable<any> { getCompWaterElectCost(id): Observable<any> {
const url = `https://kapi.absys.ninja/hemat/cost_management/card/comp-water-elect-cost?building_id=${id}`; const endpoint = `/cost_management/card/comp-water-elect-cost`;
const url = `${BASE_URL}${endpoint}?building_id=${id}`;
const headers = new HttpHeaders({ const headers = new HttpHeaders({
"Content-Type": "application/json", "Content-Type": "application/json",
"x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT",
}); });
return this.http.get<any>(url, { headers }); return this.http.get<any>(url, { headers });
} }
getCompPrevMonthCost(id): Observable<any> { getCompPrevMonthCost(id): Observable<any> {
const url = `https://kapi.absys.ninja/hemat/cost_management/card/comp-prev-month-cost?building_id=${id}`; const endpoint = `/cost_management/card/comp-prev-month-cost`;
const url = `${BASE_URL}${endpoint}?building_id=${id}`;
const headers = new HttpHeaders({ const headers = new HttpHeaders({
"Content-Type": "application/json", "Content-Type": "application/json",
"x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT",
}); });
return this.http.get<any>(url, { headers }); return this.http.get<any>(url, { headers });
} }
getCompActEstCost(id): Observable<any> { getCompActEstCost(id): Observable<any> {
const url = `https://kapi.absys.ninja/hemat/cost_management/card/comp-act-est-cost?building_id=${id}`; const endpoint = `/cost_management/card/comp-act-est-cost`;
const url = `${BASE_URL}${endpoint}?building_id=${id}`;
const headers = new HttpHeaders({ const headers = new HttpHeaders({
"Content-Type": "application/json", "Content-Type": "application/json",
"x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT",
@ -52,7 +60,8 @@ export class CostManagementService {
} }
getSyncCost(data: any): Observable<any> { getSyncCost(data: any): Observable<any> {
const url = `https://kapi.absys.ninja/hemat/cost_management/cost/sync`; const endpoint = `/cost_management/cost/sync`;
const url = `${BASE_URL}${endpoint}`;
const headers = new HttpHeaders({ const headers = new HttpHeaders({
"Content-Type": "application/json", "Content-Type": "application/json",
"x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT",
@ -61,7 +70,8 @@ export class CostManagementService {
} }
getRealCostByBuildingId(id: any, period: any): Observable<any> { getRealCostByBuildingId(id: any, period: any): Observable<any> {
const url = `https://kapi.absys.ninja/hemat/real-cost/get/byBuildingId?building_id=${id}&periode=${period}`; const endpoint = `/real-cost/get/byBuildingId`;
const url = `${BASE_URL}${endpoint}?building_id=${id}&periode=${period}`;
const headers = new HttpHeaders({ const headers = new HttpHeaders({
"Content-Type": "application/json", "Content-Type": "application/json",
"x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT",