-interface

-service

-เพิ่มเทคนิค การส่ง ผ่านข้อมูล
This commit is contained in:
2025-11-13 14:53:37 +07:00
parent 37ca45701b
commit b3fa94f904
4 changed files with 92 additions and 50 deletions

View File

@@ -1,7 +1,10 @@
import { DashboardStateService } from './../../services/state/dashboard-state.service';
import { Component, OnInit, ViewChild } from '@angular/core';
import { ChartConfiguration, ChartOptions } from 'chart.js';
import { BaseChartDirective } from 'ng2-charts';
import { GeneralService } from '../../services/generalservice';
import { IDropAct } from '../../interfaces/dashboard.interface';
@Component({
selector: 'app-main-dashboard-content',
@@ -11,44 +14,17 @@ import { GeneralService } from '../../services/generalservice';
})
export class MainDashboardContentComponent implements OnInit {
@ViewChild(BaseChartDirective) chart?: BaseChartDirective;
myDropAct!: IDropAct;
public lineChartData: ChartConfiguration<'line'>['data'] = {
labels: [],
datasets: [
{
data: [],
label: 'Revenue',
fill: true,
tension: 0.5,
borderColor: 'rgba(75,192,192,1)',
backgroundColor: 'rgba(75,192,192,0.2)'
}
]
};
public lineChartOptions: ChartOptions<'line'> = {
responsive: true,
scales: {
y: {
beginAtZero: true
}
},
plugins: {
legend: {
display: true,
},
title: {
display: true,
text: 'Revenue Summary - Last 6 Months'
}
}
};
constructor(private generalService: GeneralService) {}
constructor(
private generalService: GeneralService,
private dashboardStateService: DashboardStateService
) {}
ngOnInit(): void {
let token = localStorage.getItem('access_token')
this.OnSearchAct(token, true);
this.OnSetupDashboard(token, true);
}
OnSearchAct(value: any, setupFirst: boolean): void {
@@ -60,7 +36,31 @@ export class MainDashboardContentComponent implements OnInit {
next: (result: any) => {
if (result.code === '200') {
this.generalService.trowApi(result);
console.log(`✅ OTP ส่งไปที่ ${value.email}`);
this.myDropAct = result.data
}
},
error: (error: any) => {
},
complete: () => {
}
});
}
OnSetupDashboard(value: any, setupFirst: boolean): void {
const uri = '/api/web/accountingSetup';
let request = {
token: value
}
this.generalService.postRequest(uri, request).subscribe({
next: (result: any) => {
if (result.code === '200') {
this.generalService.trowApi(result);
this.myDropAct = result.data
this.dashboardStateService.setStateResult(this.myDropAct)
}
},
error: (error: any) => {
@@ -94,24 +94,24 @@ export class MainDashboardContentComponent implements OnInit {
// });
// }
processChartData(data: any[]): void {
const labels = data.map(item => item.month);
const revenues = data.map(item => item.revenue);
// processChartData(data: any[]): void {
// const labels = data.map(item => item.month);
// const revenues = data.map(item => item.revenue);
this.lineChartData.labels = labels;
this.lineChartData.datasets[0].data = revenues;
// this.lineChartData.labels = labels;
// this.lineChartData.datasets[0].data = revenues;
this.chart?.update();
}
// this.chart?.update();
// }
setupPlaceholderData(): void {
// This function is called if the API fails, to show a sample graph.
const labels = ['January', 'February', 'March', 'April', 'May', 'June'];
const revenues = [1200, 1900, 3000, 5000, 2300, 3200]; // Sample data
// setupPlaceholderData(): void {
// // This function is called if the API fails, to show a sample graph.
// const labels = ['January', 'February', 'March', 'April', 'May', 'June'];
// const revenues = [1200, 1900, 3000, 5000, 2300, 3200]; // Sample data
this.lineChartData.labels = labels;
this.lineChartData.datasets[0].data = revenues;
// this.lineChartData.labels = labels;
// this.lineChartData.datasets[0].data = revenues;
this.chart?.update();
}
// this.chart?.update();
// }
}