52 lines
1.9 KiB
Dart
52 lines
1.9 KiB
Dart
import './leave_model.dart';
|
|
import '../services/generic_api_service.dart';
|
|
import 'package:intl/intl.dart';
|
|
import '../auth_manager.dart'; // 確保引入 AuthManager
|
|
|
|
class LeaveApiService {
|
|
final GenericApiService _apiService = GenericApiService();
|
|
|
|
// 獲取個人請假紀錄
|
|
Future<List<Leave>> fetchLeaves(String personId) async {
|
|
// 排序:按單據日期降冪
|
|
String queryFilter = "1^100^billdate^*^^^personid^$personId";
|
|
|
|
return await _apiService.fetchList<Leave>(
|
|
tableName: "hrs_leave",
|
|
pk: "billno",
|
|
queryFilter: queryFilter,
|
|
fromJson: (json) => Leave.fromJson(json),
|
|
);
|
|
}
|
|
|
|
// 提交請假單 (新增)
|
|
//Future<bool> createLeave(Leave leave) async {
|
|
Future<List<Leave>> createLeave(Leave leave) async {
|
|
final String currentUid = AuthManager().currentUserId ?? leave.personId;
|
|
|
|
final Map<String, dynamic> data = {
|
|
"billdate": DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now()),
|
|
"billno": "LV${DateTime.now().millisecondsSinceEpoch}", // 範例編號
|
|
"personid": currentUid,
|
|
"agentid": leave.agentId,
|
|
"leavetype": leave.leaveType,
|
|
"starttime": DateFormat('yyyy-MM-dd HH:mm:ss').format(leave.startTime!),
|
|
"endtime": DateFormat('yyyy-MM-dd HH:mm:ss').format(leave.endTime!),
|
|
"days": leave.days,
|
|
"hours": leave.hours,
|
|
"leave_note": leave.leaveNote,
|
|
"flow_status": "1", // 提交即進入審核中
|
|
"create_user": currentUid,
|
|
"create_date": DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now()),
|
|
};
|
|
|
|
return await _apiService.fetchList<Leave>(
|
|
tableName: "hrs_leave",
|
|
pk: "ClockInId",
|
|
queryFilter: "", // 通常新增不需要 filter,依後端 API 協議而定
|
|
action: "C", // 傳入您指定的動作碼 'C' (Create)
|
|
data: data, // 將打卡欄位資料透過額外參數傳入
|
|
fromJson: (json) => Leave.fromJson(json), // 這裡填入模型的解析工廠
|
|
);
|
|
}
|
|
} |