import { Injectable } from "@angular/core"; import { HttpClient, HttpHeaders } from "@angular/common/http"; import { Observable } from "rxjs"; const BASE_URL = 'https://kapi.absys.ninja/hemat'; @Injectable({ providedIn: "root", }) export class CostManagementService { constructor(private http: HttpClient) {} getCostManagement(id, period, category): Observable { const endpoint = `/cost_management`; const params = new URLSearchParams({ page: "1", limit: "100", building_id: id, periode: period, }); if (category) { params.append("category_id", category); } const url = `${BASE_URL}${endpoint}?${params.toString()}`; const headers = new HttpHeaders({ "Content-Type": "application/json", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", }); return this.http.get(url, { headers }); } getCompWaterElectCost(id): Observable { const endpoint = `/cost_management/card/comp-water-elect-cost`; const url = `${BASE_URL}${endpoint}?building_id=${id}`; const headers = new HttpHeaders({ "Content-Type": "application/json", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", }); return this.http.get(url, { headers }); } getCompPrevMonthCost(id): Observable { const endpoint = `/cost_management/card/comp-prev-month-cost`; const url = `${BASE_URL}${endpoint}?building_id=${id}`; const headers = new HttpHeaders({ "Content-Type": "application/json", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", }); return this.http.get(url, { headers }); } getCompActEstCost(id): Observable { const endpoint = `/cost_management/card/comp-act-est-cost`; const url = `${BASE_URL}${endpoint}?building_id=${id}`; const headers = new HttpHeaders({ "Content-Type": "application/json", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", }); return this.http.get(url, { headers }); } getSyncCost(data: any): Observable { const endpoint = `/cost_management/cost/sync`; const url = `${BASE_URL}${endpoint}`; const headers = new HttpHeaders({ "Content-Type": "application/json", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", }); return this.http.post(url, data, { headers }); } getRealCostByBuildingId(id: any, period: any): Observable { const endpoint = `/real-cost/get/byBuildingId`; const url = `${BASE_URL}${endpoint}?building_id=${id}&periode=${period}`; const headers = new HttpHeaders({ "Content-Type": "application/json", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", }); return this.http.get(url, { headers }); } putRealCost(data: any, id: any): Observable { const endpoint = `/real-cost`; const url = `${BASE_URL}${endpoint}/${id}`; const headers = new HttpHeaders({ 'Content-Type': 'application/json', 'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' }); return this.http.put(url, data, { headers }); } getBUildingById(id: any): Observable { const endpoint = `/building`; const url = `${BASE_URL}${endpoint}/${id}`; const headers = new HttpHeaders({ 'Content-Type': 'application/json', 'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' }); return this.http.get(url, { headers }); } getCostDetail(category: any, room: any, period: any): Observable { const endpoint = `/cost-detail/get/Details`; const url = `${BASE_URL}${endpoint}?category_id=${category}&room_id=${room}&periode=${period}`; const headers = new HttpHeaders({ 'Content-Type': 'application/json', 'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' }); return this.http.get(url, { headers }); } }