update new version
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
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();
|
||||
@@ -8,7 +9,7 @@ class LeaveApiService {
|
||||
// 獲取個人請假紀錄
|
||||
Future<List<Leave>> fetchLeaves(String personId) async {
|
||||
// 排序:按單據日期降冪
|
||||
String queryFilter = "1^100^billdate^*^personid^=^$personId";
|
||||
String queryFilter = "1^100^billdate^*^^^personid^$personId";
|
||||
|
||||
return await _apiService.fetchList<Leave>(
|
||||
tableName: "hrs_leave",
|
||||
@@ -19,11 +20,14 @@ class LeaveApiService {
|
||||
}
|
||||
|
||||
// 提交請假單 (新增)
|
||||
Future<bool> createLeave(Leave leave) async {
|
||||
//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": leave.personId,
|
||||
"personid": currentUid,
|
||||
"agentid": leave.agentId,
|
||||
"leavetype": leave.leaveType,
|
||||
"starttime": DateFormat('yyyy-MM-dd HH:mm:ss').format(leave.startTime!),
|
||||
@@ -32,13 +36,17 @@ class LeaveApiService {
|
||||
"hours": leave.hours,
|
||||
"leave_note": leave.leaveNote,
|
||||
"flow_status": "1", // 提交即進入審核中
|
||||
"create_user": leave.personId,
|
||||
"create_user": currentUid,
|
||||
"create_date": DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now()),
|
||||
};
|
||||
|
||||
// 呼叫底層 saveData 實作
|
||||
// return await _apiService.saveData("hrs_leave", data);
|
||||
print("提交假單: $data");
|
||||
return true;
|
||||
return await _apiService.fetchList<Leave>(
|
||||
tableName: "hrs_leave",
|
||||
pk: "ClockInId",
|
||||
queryFilter: "", // 通常新增不需要 filter,依後端 API 協議而定
|
||||
action: "C", // 傳入您指定的動作碼 'C' (Create)
|
||||
data: data, // 將打卡欄位資料透過額外參數傳入
|
||||
fromJson: (json) => Leave.fromJson(json), // 這裡填入模型的解析工廠
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user