diff --git a/lib/Screens/plans/create_plans.dart b/lib/Screens/plans/create_plans.dart index 82c324c..7c7ee2b 100644 --- a/lib/Screens/plans/create_plans.dart +++ b/lib/Screens/plans/create_plans.dart @@ -1047,7 +1047,7 @@ class CreateNewPlansState extends State { data: { "plan_id": planId, "user_id": widget.approverId, - "delegater_id": widget.delegaterId, + "delegation_user_id": widget.delegaterId, }, methodName: 'Plan Approval', ); @@ -1060,7 +1060,7 @@ class CreateNewPlansState extends State { data: { "plan_id": planId, "user_id": widget.approverId, - "delegater_id": widget.delegaterId, + "delegation_user_id": widget.delegaterId, "reason": remarks, }, methodName: 'Plan Rejection', diff --git a/lib/Screens/userManagement/create_user/office_details.dart b/lib/Screens/userManagement/create_user/office_details.dart index 2ca78e3..4b176d7 100644 --- a/lib/Screens/userManagement/create_user/office_details.dart +++ b/lib/Screens/userManagement/create_user/office_details.dart @@ -217,7 +217,7 @@ class _OfficeDetailsState extends State { Future fetchDepartment() async { try { - List department = await apiService.fetchCostCenter(); + List department = await apiService.fetchDepartmentCostCenter(); setState(() { apiCostData = department; }); diff --git a/lib/services/apiService.dart b/lib/services/apiService.dart index d391549..5d60c78 100644 --- a/lib/services/apiService.dart +++ b/lib/services/apiService.dart @@ -162,6 +162,60 @@ class ApiService { } } + Future fetchDepartmentCostCenter() async { + final String apiUrldata = '$apiUrl/api/getDepartmentList'; + + final token = await getToken(); + + final userId = await getUserId(); + + // print("SUSRTRT- $userId"); + // + if (token == null) { + throw Exception('Token not found. Please log in.'); + } + + final response = await http.get( + Uri.parse(apiUrldata), + headers: { + 'Authorization': 'Bearer $token', + 'Content-Type': 'application/json', + }, + ); + + if (response.statusCode == 200) { + try { + final data = json.decode(response.body); + print(data); + + if (!data.containsKey('data') || data['data'] is! List) { + throw Exception( + "Invalid response format: 'data' field is missing or not a List"); + } + + List plansJson = data['data']; // 'data' is a Map, not a List + // setState(() { + // apiCostData = plansJson; // Store API response in state + // if(apiCostData!.isNotEmpty){ + // selectedCostCenterId =apiCostData?.first['department_id']; + // } + + // if (apiCostData != null && apiCostData!.isNotEmpty) { + // selectedCostCenterId ??= apiCostData!.first['department_id']?.toString(); + // } + // }); + + print('plansJSON'); + + return plansJson; + } catch (e) { + throw Exception('Error parsing response: $e'); + } + } else { + throw Exception('Failed to load plans'); + } + } + Future> fetchMasterDropdown() async { final String apiUrldata = '$apiUrl/api/getDropdownMaster';