2025-12-29 First Commit
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class ClockInRecord {
|
||||
final int? clockInId;
|
||||
final int? userId;
|
||||
final DateTime? dateTime;
|
||||
final double? latitude;
|
||||
final double? longitude;
|
||||
final String? type; // 上班/下班/加班...
|
||||
final String? storeId;
|
||||
|
||||
ClockInRecord({
|
||||
this.clockInId,
|
||||
this.userId,
|
||||
this.dateTime,
|
||||
this.latitude,
|
||||
this.longitude,
|
||||
this.type,
|
||||
this.storeId,
|
||||
});
|
||||
|
||||
factory ClockInRecord.fromJson(Map<String, dynamic> json) {
|
||||
return ClockInRecord(
|
||||
clockInId: json['ClockInId'] as int?,
|
||||
userId: json['ClockInUserId'] as int?,
|
||||
dateTime: json['ClockInDateTime'] != null ? DateTime.tryParse(json['ClockInDateTime']) : null,
|
||||
latitude: double.tryParse(json['ClockInLatitude']?.toString() ?? '0'),
|
||||
longitude: double.tryParse(json['ClockInLongitude']?.toString() ?? '0'),
|
||||
type: json['ClockInType'] as String?,
|
||||
storeId: json['ClockInStoreId'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
// Helper: 格式化顯示時間
|
||||
String get formattedTime => dateTime != null ? DateFormat('HH:mm:ss').format(dateTime!) : '--:--';
|
||||
String get formattedDate => dateTime != null ? DateFormat('yyyy-MM-dd').format(dateTime!) : 'N/A';
|
||||
|
||||
// Helper: 根據打卡類型回傳顏色
|
||||
Color get typeColor {
|
||||
if (type == '上班') return Colors.blue;
|
||||
if (type == '下班') return Colors.orange;
|
||||
return Colors.grey;
|
||||
}
|
||||
}
|
||||
|
||||
class ClockInStore {
|
||||
final String storeId;
|
||||
final String storeName;
|
||||
final String? storeAddress;
|
||||
final double latitude;
|
||||
final double longitude;
|
||||
final int distance; // 允許打卡公尺數
|
||||
|
||||
ClockInStore({
|
||||
required this.storeId,
|
||||
required this.storeName,
|
||||
this.storeAddress,
|
||||
required this.latitude,
|
||||
required this.longitude,
|
||||
required this.distance,
|
||||
});
|
||||
|
||||
factory ClockInStore.fromJson(Map<String, dynamic> json) {
|
||||
return ClockInStore(
|
||||
storeId: json['StoreId'] as String,
|
||||
storeName: json['StoreName'] as String? ?? '',
|
||||
storeAddress: json['StoreAddress'] as String?,
|
||||
// 強制將 decimal/String 轉為 double
|
||||
latitude: double.tryParse(json['StoreLatitude'].toString()) ?? 0.0,
|
||||
longitude: double.tryParse(json['StoreLongitude'].toString()) ?? 0.0,
|
||||
distance: int.tryParse(json['Distance'].toString()) ?? 100,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user