-accouting Wep
All checks were successful
Build Docker Image / Build Docker Image (push) Successful in 8m54s
All checks were successful
Build Docker Image / Build Docker Image (push) Successful in 8m54s
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
|
||||
import { GeneralService } from '../../services/generalservice';
|
||||
import { IDropAct, IStateDrop, IStateResultResponse, IActData, IActSumData } from '../../interfaces/dashboard.interface'
|
||||
import { IDropAct, IStateDrop, IStateResultResponse, IActData, IActSumData, QuickRatio} from '../../interfaces/dashboard.interface'
|
||||
import { DashboardStateService } from '../../services/state/dashboard-state.service';
|
||||
|
||||
@Component({
|
||||
@@ -11,20 +11,21 @@ import { DashboardStateService } from '../../services/state/dashboard-state.serv
|
||||
styleUrl: './main-dashboard.component.css'
|
||||
})
|
||||
export class MainDashboardComponent implements OnInit {
|
||||
|
||||
@Output() saveEventSubmit = new EventEmitter<any>();
|
||||
mode: string = 'i';
|
||||
isModalOpen: boolean = false;
|
||||
isSubmitting: boolean = false;
|
||||
arrearsForm!: FormGroup;
|
||||
saveFrm!: FormGroup;
|
||||
myActData: IActData[] = [];
|
||||
quickRatios: QuickRatio[] = [];
|
||||
// myDropAct: IStateDrop[] = [];
|
||||
myDropAct: IStateDrop = { income: [], expense: [] };
|
||||
myActSumData: IActSumData = {
|
||||
summary: {
|
||||
totalIncome: '',
|
||||
totalExpense: '',
|
||||
netProfit: '',
|
||||
netProfit: 0,
|
||||
profitRate: '',
|
||||
adjustedProfitRate: '',
|
||||
period: ''
|
||||
@@ -34,10 +35,11 @@ export class MainDashboardComponent implements OnInit {
|
||||
expense: []
|
||||
}
|
||||
};
|
||||
|
||||
ActSumDataGradient: any
|
||||
|
||||
|
||||
readonly ownerName = 'Nuttakit';
|
||||
ownerName = localStorage.getItem('username') || 'ชนกนันต์';
|
||||
|
||||
constructor(
|
||||
private dashboardStateService: DashboardStateService
|
||||
@@ -83,12 +85,19 @@ export class MainDashboardComponent implements OnInit {
|
||||
// { label: 'มิ.ย.', value: 77 }
|
||||
// ];
|
||||
|
||||
readonly quickRatios = [
|
||||
{ label: 'กระแสเงินสด', value: '+฿312K', status: 'positive' },
|
||||
{ label: 'วงเงินคงเหลือ', value: '฿890K', status: 'neutral' },
|
||||
{ label: 'ค่าใช้จ่ายเดือนนี้', value: '฿412K', status: 'warning' }
|
||||
];
|
||||
// readonly quickRatios = [
|
||||
// { label: 'กระแสเงินสด', value: '+฿312K', status: 'positive' },
|
||||
// { label: 'วงเงินคงเหลือ', value: '฿890K', status: 'neutral' },
|
||||
// { label: 'ค่าใช้จ่ายเดือนนี้', value: '฿412K', status: 'warning' }
|
||||
// ];
|
||||
// ฟังก์ชันนี้ควรเรียกหลังจากได้รับข้อมูล myActSumData แล้ว (เช่นใน subscribe หรือ ngOnChanges)
|
||||
|
||||
|
||||
|
||||
// เพิ่มใน Class Component
|
||||
isNumber(val: any): boolean {
|
||||
return typeof val === 'number';
|
||||
}
|
||||
readonly periodSummaries = [
|
||||
{
|
||||
label: 'รายปี',
|
||||
@@ -217,8 +226,10 @@ export class MainDashboardComponent implements OnInit {
|
||||
if (data) {
|
||||
this.myActSumData = data;
|
||||
this.ActSumDataGradient = this.buildExpenseGradient()
|
||||
this.updateQuickRatios();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
setupFormControl(){
|
||||
this.arrearsForm = new FormGroup({
|
||||
@@ -230,15 +241,66 @@ export class MainDashboardComponent implements OnInit {
|
||||
});
|
||||
|
||||
this.saveFrm = new FormGroup({
|
||||
actacpdtm: new FormControl('',[Validators.required, Validators.maxLength(12)]),
|
||||
actacpdtm: new FormControl('',[Validators.required]),
|
||||
actqty: new FormControl('',[Validators.required]),
|
||||
actcat: new FormControl('',[Validators.required, Validators.maxLength(1)]),
|
||||
actcmt: new FormControl('',[Validators.maxLength(200)])
|
||||
});
|
||||
}
|
||||
|
||||
onSaveSubmit(){
|
||||
updateQuickRatios() {
|
||||
const summary = this.myActSumData.summary;
|
||||
|
||||
// แปลงค่า netProfit เป็นตัวเลขเพื่อเช็คเงื่อนไข (รองรับทั้ง string และ number)
|
||||
const netProfitVal = parseFloat(String(summary.netProfit));
|
||||
const profitRateVal = parseFloat(summary.profitRate.replace('%', '')); // ลบ % ออกก่อนเช็ค
|
||||
|
||||
this.quickRatios = [
|
||||
{
|
||||
label: 'รายรับรวม',
|
||||
value: summary.totalIncome,
|
||||
colorClass: 'text-green-600' // รายรับสีเขียวเสมอ (หรือจะใช้สีดำ text-gray-700 ก็ได้)
|
||||
},
|
||||
{
|
||||
label: 'รายจ่ายรวม',
|
||||
value: summary.totalExpense,
|
||||
colorClass: 'text-red-500' // รายจ่ายสีแดงอ่อน หรือสีปกติ
|
||||
},
|
||||
{
|
||||
label: 'คงเหลือสุทธิ', // หรือ กำไรสุทธิ
|
||||
value: netProfitVal, // ส่งเป็นตัวเลขไปให้ Pipe format
|
||||
// ถ้า >= 0 สีน้ำเงิน, ถ้าติดลบ สีแดง
|
||||
colorClass: netProfitVal >= 0 ? 'text-blue-600' : 'text-red-600 font-bold'
|
||||
},
|
||||
{
|
||||
label: 'อัตรากำไร',
|
||||
value: summary.profitRate,
|
||||
// เช็ค % ถ้าติดลบให้แดง
|
||||
colorClass: profitRateVal >= 0 ? 'text-blue-600' : 'text-red-600'
|
||||
},
|
||||
{
|
||||
label: 'ระยะเวลา',
|
||||
value: summary.period,
|
||||
colorClass: 'text-gray-500'
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
onSaveSubmit(){
|
||||
const rawDate = this.saveFrm.get('actacpdtm')?.value; // ค่าดิบ: "2025-11-21T14:23"
|
||||
let arysave = {
|
||||
actacpdtm: rawDate ? rawDate.replace(/[-T:]/g, '') : '',
|
||||
actqty: this.saveFrm.get('actqty')?.value,
|
||||
actcat: this.saveFrm.get('actcat')?.value,
|
||||
actcmt: this.saveFrm.get('actcmt')?.value,
|
||||
acttyp: this.mode
|
||||
}
|
||||
this.SaveEventSubmit(arysave);
|
||||
}
|
||||
|
||||
|
||||
SaveEventSubmit(event: any){
|
||||
this.saveEventSubmit.emit(event);
|
||||
}
|
||||
|
||||
onArrearsSubmit(){
|
||||
|
||||
Reference in New Issue
Block a user