modify clockin & leave

This commit is contained in:
2026-03-04 23:45:26 +08:00
parent ce706694ef
commit 0516db1690
7 changed files with 163 additions and 77 deletions
+14 -2
View File
@@ -60,6 +60,18 @@ class _LeaveFormState extends State<LeaveForm> {
final start = DateTime(_startDate.year, _startDate.month, _startDate.day, _startTime.hour, _startTime.minute);
final end = DateTime(_endDate.year, _endDate.month, _endDate.day, _endTime.hour, _endTime.minute);
// 檢查結束時間是否大於開始時間
if (end.isBefore(start) || end.isAtSameMomentAs(start)) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('結束時間必須大於開始時間')));
return;
}
// 修正 2: 自動推算天數與小時 (簡易版:假設一天 8 小時工作制)
final duration = end.difference(start);
final double totalHours = duration.inMinutes / 60.0;
final double calcDays = (totalHours / 8).floorToDouble();
final double calcHours = totalHours % 8;
final newLeave = Leave(
billNo: '', // API 端生成
personId: widget.userId,
@@ -67,8 +79,8 @@ class _LeaveFormState extends State<LeaveForm> {
leaveType: _selectedType!.id, // 傳送 ID 給後端
startTime: start,
endTime: end,
days: 1.0, // 簡化處理,實際可依 start/end 計算
hours: 8.0,
days: calcDays, // 寫入計算後的天數
hours: calcHours, // 寫入計算後的小時
leaveNote: _note,
);