Attendence and leave

This commit is contained in:
kratikpal 2024-08-03 11:08:58 +05:30
parent 288d3caa9f
commit 79250d06c3
13 changed files with 484 additions and 149 deletions

View File

@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:label="cheminova"
android:label="Territory Manager"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity

3
devtools_options.yaml Normal file
View File

@ -0,0 +1,3 @@
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:

View File

@ -13,7 +13,7 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>cheminova</string>
<string>Territory Manager</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>

View File

@ -1,12 +1,9 @@
import 'package:cheminova/services/api_client.dart';
import 'package:cheminova/services/api_urls.dart';
import 'package:cheminova/services/secure__storage_service.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
class AttendanceProvider extends ChangeNotifier {
final _storageService = SecureStorageService();
final _apiClient = ApiClient();
bool _isLoading = false;
@ -34,6 +31,15 @@ class AttendanceProvider extends ChangeNotifier {
} else {
return (false, response.data['message'].toString());
}
} on DioException catch (e) {
setLoading(false);
if (e.response != null && e.response?.data != null) {
// Extracting the error message from the Dio response
return (false, e.response!.data['message'].toString());
} else {
// When no response or response data is available
return (false, 'Something went wrong');
}
} catch (e) {
setLoading(false);
return (false, 'Something want wrong');

View File

@ -0,0 +1,91 @@
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import '../services/api_client.dart';
import '../services/api_urls.dart';
class MarkLeaveProvider extends ChangeNotifier {
final _apiClient = ApiClient();
bool _isLoading = false;
bool get isLoading => _isLoading;
void setLoading(bool loading) {
_isLoading = loading;
notifyListeners();
}
final dateController = TextEditingController(
text: DateFormat('dd/MM/yyyy').format(DateTime.now()));
final timeController =
TextEditingController(text: DateFormat('hh:mm a').format(DateTime.now()));
final locationController = TextEditingController();
final notesController = TextEditingController();
String selectedLeaveType = 'Sick';
void onLeaveTypeSelected(String leaveType) {
selectedLeaveType = leaveType;
notifyListeners();
}
Widget buildLeaveTypeOption(String leaveType) {
bool isSelected = leaveType == selectedLeaveType;
return GestureDetector(
onTap: () => onLeaveTypeSelected(leaveType),
child: Container(
margin: const EdgeInsets.only(bottom: 10),
width: 120,
padding: const EdgeInsets.symmetric(vertical: 5.0),
decoration: BoxDecoration(
color: isSelected ? Colors.blue : Colors.white,
borderRadius: BorderRadius.circular(10.0),
),
child: Center(
child: Text(
leaveType,
style: TextStyle(
color: isSelected ? Colors.white : Colors.black,
fontSize: 16.0,
),
),
),
),
);
}
Future<(bool, String)> markLeave(String date, String time, String location,
String reason, String leaveType) async {
setLoading(true);
try {
Response response = await _apiClient.post(ApiUrls.markLeaveUrl, data: {
"date": date,
"time": time,
"reason": reason,
"leaveType": '$leaveType Leave',
"location": location
});
setLoading(false);
if (response.statusCode == 200) {
return (true, response.data['message'].toString());
} else {
return (false, response.data['message'].toString());
}
} on DioException catch (e) {
setLoading(false);
if (e.response != null && e.response?.data != null) {
// Extracting the error message from the Dio response
return (false, e.response!.data['message'].toString());
} else {
// When no response or response data is available
return (false, 'Something went wrong');
}
} catch (e) {
setLoading(false);
return (false, 'Something want wrong');
}
}
}

View File

@ -43,6 +43,7 @@ class UserProvider extends ChangeNotifier {
Future<void> clearUserProfile() async {
_user = null;
await SecureStorageService().delete(key: 'user');
notifyListeners();
}
}

View File

@ -0,0 +1,155 @@
import 'package:cheminova/widgets/common_app_bar.dart';
import 'package:cheminova/widgets/common_background.dart';
import 'package:cheminova/widgets/common_drawer.dart';
import 'package:cheminova/widgets/common_elevated_button.dart';
import 'package:flutter/material.dart';
class AssignTaskScreen extends StatefulWidget {
const AssignTaskScreen({super.key});
@override
State<AssignTaskScreen> createState() => _AssignTaskScreenState();
}
class _AssignTaskScreenState extends State<AssignTaskScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: true,
appBar: CommonAppBar(
backgroundColor: Colors.transparent,
elevation: 0,
actions: [
IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Image.asset('assets/Back_attendance.png'),
padding: const EdgeInsets.only(right: 20),
),
],
title: const Center(
child: Text(
'Assign Tasks',
style: TextStyle(color: Colors.black87, fontSize: 20),
),
),
),
drawer: const CommonDrawer(),
body: CommonBackground(
child: SafeArea(
child: Container(
padding: const EdgeInsets.all(20.0).copyWith(top: 15, bottom: 30),
margin: const EdgeInsets.symmetric(horizontal: 30.0)
.copyWith(bottom: 50),
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
color: const Color(0xffB4D1E5).withOpacity(0.5),
borderRadius: BorderRadius.circular(26.0),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Assign Tasks',
style: TextStyle(
fontSize: 24,
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: 'Anek',
),
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 200,
width: MediaQuery.of(context).size.width / 4.2,
child: _customCard(title: "Total Tasks", subtitle: "100"),
),
SizedBox(
height: 200,
width: MediaQuery.of(context).size.width / 4.2,
child:
_customCard(title: "Tasks Pending", subtitle: "100"),
),
SizedBox(
height: 200,
width: MediaQuery.of(context).size.width / 4.2,
child: _customCard(
title: "Reports Submitted", subtitle: "100"),
),
],
),
CommonElevatedButton(
backgroundColor: const Color(0xff004791),
borderRadius: 30,
width: double.infinity,
height: kToolbarHeight - 10,
text: 'ASSIGN TASKS',
onPressed: () {},
),
const SizedBox(height: 15),
CommonElevatedButton(
backgroundColor: const Color(0xff004791),
borderRadius: 30,
width: double.infinity,
height: kToolbarHeight - 10,
text: 'VIEW TASK STATUS',
onPressed: () {},
),
const SizedBox(height: 15),
CommonElevatedButton(
backgroundColor: const Color(0xff004791),
borderRadius: 30,
width: double.infinity,
height: kToolbarHeight - 10,
text: 'MANAGE SCs',
onPressed: () {},
),
],
),
),
),
),
);
}
Widget _customCard({required String title, required String subtitle}) {
return Container(
padding: const EdgeInsets.all(8.0).copyWith(top: 15, bottom: 30),
margin: const EdgeInsets.all(4).copyWith(bottom: 30),
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
color: const Color(0xffB4D1E5).withOpacity(0.6),
borderRadius: BorderRadius.circular(16.0),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
title,
style: const TextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: 'Anek',
),
),
const SizedBox(height: 10),
Text(
subtitle,
style: const TextStyle(
fontSize: 34,
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: 'Anek',
),
),
],
),
);
}
}

View File

@ -1,4 +1,5 @@
import 'package:cheminova/provider/user_provider.dart';
import 'package:cheminova/screens/assign_task_screen.dart';
import 'package:cheminova/screens/calendar_screen.dart';
import 'package:cheminova/screens/collect_kyc_screen.dart';
import 'package:cheminova/screens/mark_attendence_screen.dart';
@ -8,7 +9,6 @@ import 'package:cheminova/screens/summary_screen.dart';
import 'package:cheminova/screens/product_sales_data.dart';
import 'package:cheminova/screens/update_inventory_screen.dart';
import 'package:cheminova/screens/display_sales_screen.dart';
import 'package:cheminova/widgets/common_app_bar.dart';
import 'package:cheminova/widgets/common_drawer.dart';
import 'package:flutter/material.dart';
import 'package:cheminova/widgets/common_background.dart';
@ -43,7 +43,7 @@ class _HomePageState extends State<HomePage> {
// backgroundImage: AssetImage(
// 'assets/profile.png'), // Replace with actual user image
// ),
const SizedBox(width: 10),
// const SizedBox(width: 10),
Consumer<UserProvider>(
builder: (context, userProvider, child) {
return Column(
@ -107,7 +107,13 @@ class _HomePageState extends State<HomePage> {
const SizedBox(
height: 5,
),
_buildCustomCard('Assign Tasks', '', onTap: () {}),
_buildCustomCard('Assign Tasks', '', onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const AssignTaskScreen(),
));
}),
const SizedBox(
height: 5,
),

View File

@ -1,7 +1,6 @@
import 'package:cheminova/provider/login_provider.dart';
import 'package:cheminova/screens/forgot_password_screen.dart';
import 'package:cheminova/screens/home_screen.dart';
import 'package:cheminova/screens/verify_phone_screen.dart';
import 'package:cheminova/widgets/common_background.dart';
import 'package:cheminova/widgets/common_elevated_button.dart';
import 'package:cheminova/widgets/common_text_form_field.dart';

View File

@ -11,6 +11,7 @@ import 'package:geocoding/geocoding.dart';
import 'package:geolocator/geolocator.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
class MarkAttendanceScreen extends StatefulWidget {
const MarkAttendanceScreen({super.key});
@ -21,7 +22,7 @@ class MarkAttendanceScreen extends StatefulWidget {
class _MarkAttendanceScreenState extends State<MarkAttendanceScreen> {
late AttendanceProvider attendanceProvider;
final dateController = TextEditingController(
text: DateFormat('dd/MM/yyyy').format(DateTime.now()));
text: DateFormat('yyyy/MM/dd').format(DateTime.now()));
final timeController =
TextEditingController(text: DateFormat('hh:mm a').format(DateTime.now()));
@ -74,7 +75,8 @@ class _MarkAttendanceScreenState extends State<MarkAttendanceScreen> {
return ChangeNotifierProvider<AttendanceProvider>(
create: (_) => attendanceProvider,
builder: (context, child) => CommonBackground(
child: Scaffold(backgroundColor: Colors.transparent,
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: CommonAppBar(
actions: [
IconButton(
@ -90,7 +92,9 @@ class _MarkAttendanceScreenState extends State<MarkAttendanceScreen> {
fontSize: 28,
color: Colors.black,
fontWeight: FontWeight.w400,
fontFamily: 'Anek')), backgroundColor: Colors.transparent, elevation: 0,
fontFamily: 'Anek')),
backgroundColor: Colors.transparent,
elevation: 0,
),
drawer: const CommonDrawer(),
body: Stack(
@ -105,8 +109,8 @@ class _MarkAttendanceScreenState extends State<MarkAttendanceScreen> {
children: <Widget>[
const SizedBox(height: 16),
Container(
padding:
const EdgeInsets.all(20.0).copyWith(top: 30, bottom: 30),
padding: const EdgeInsets.all(20.0)
.copyWith(top: 30, bottom: 30),
margin: const EdgeInsets.symmetric(horizontal: 20.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
@ -149,7 +153,8 @@ class _MarkAttendanceScreenState extends State<MarkAttendanceScreen> {
AttendanceProvider value,
Widget? child) =>
CommonElevatedButton(
backgroundColor: const Color(0xff004791),
backgroundColor:
const Color(0xff004791),
borderRadius: 30,
width: double.infinity,
height: kToolbarHeight - 10,
@ -157,16 +162,22 @@ class _MarkAttendanceScreenState extends State<MarkAttendanceScreen> {
onPressed: () {
value
.markAttendance(
dateController.text.trim(),
timeController.text.trim(),
locationController.text.trim(),
notesController.text.trim())
dateController.text
.trim(),
timeController.text
.trim(),
locationController.text
.trim(),
notesController.text
.trim())
.then(
(result) {
var (status, message) = result;
var (status, message) =
result;
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(
content: Text(message)));
content:
Text(message)));
if (status) {
Navigator.pushReplacement(
context,
@ -210,17 +221,18 @@ class _MarkAttendanceScreenState extends State<MarkAttendanceScreen> {
left: 0,
right: 0,
bottom: 0,
child: Consumer<AttendanceProvider>(builder: (context, value, child) {
child: Consumer<AttendanceProvider>(
builder: (context, value, child) {
if (value.isLoading) {
return
Container(
return Container(
color: Colors.black12,
child: const Center(child: CircularProgressIndicator()));
}
else{
child:
const Center(child: CircularProgressIndicator()));
} else {
return const SizedBox();
}
}, ),
},
),
)
],
),

View File

@ -1,3 +1,4 @@
import 'package:cheminova/provider/mark_leave_provider.dart';
import 'package:cheminova/screens/Attendance_success.dart';
import 'package:cheminova/widgets/common_drawer.dart';
import 'package:flutter/material.dart';
@ -5,6 +6,7 @@ import 'package:cheminova/widgets/common_background.dart';
import 'package:geocoding/geocoding.dart';
import 'package:geolocator/geolocator.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import '../widgets/common_app_bar.dart';
import '../widgets/common_elevated_button.dart';
import '../widgets/common_text_form_field.dart';
@ -17,8 +19,10 @@ class OnLeaveScreen extends StatefulWidget {
}
class _OnLeaveScreenState extends State<OnLeaveScreen> {
late MarkLeaveProvider _markLeaveProvider;
final dateController = TextEditingController(
text: DateFormat('dd/MM/yyyy').format(DateTime.now()));
text: DateFormat('yyyy/MM/dd').format(DateTime.now()));
final timeController =
TextEditingController(text: DateFormat('hh:mm a').format(DateTime.now()));
@ -39,7 +43,8 @@ class _OnLeaveScreenState extends State<OnLeaveScreen> {
return GestureDetector(
onTap: () => onLeaveTypeSelected(leaveType),
child: Container(margin: EdgeInsets.only(bottom: 10),
child: Container(
margin: const EdgeInsets.only(bottom: 10),
width: 120,
padding: const EdgeInsets.symmetric(vertical: 5.0),
decoration: BoxDecoration(
@ -58,9 +63,11 @@ class _OnLeaveScreenState extends State<OnLeaveScreen> {
),
);
}
@override
void initState() {
super.initState();
_markLeaveProvider = MarkLeaveProvider();
_getCurrentLocation();
}
@ -99,16 +106,19 @@ class _OnLeaveScreenState extends State<OnLeaveScreen> {
@override
Widget build(BuildContext context) {
return CommonBackground(
child: Scaffold(backgroundColor: Colors.transparent,
return ChangeNotifierProvider<MarkLeaveProvider>(
create: (_) => _markLeaveProvider,
builder: (context, child) => CommonBackground(
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: CommonAppBar(
actions: [
IconButton(
onPressed: ()
{
onPressed: () {
Navigator.pop(context);
},
icon: Image.asset('assets/Back_attendance.png'), padding: const EdgeInsets.only(right: 20),
icon: Image.asset('assets/Back_attendance.png'),
padding: const EdgeInsets.only(right: 20),
),
],
title: const Text('On Leave',
@ -116,7 +126,9 @@ class _OnLeaveScreenState extends State<OnLeaveScreen> {
fontSize: 28,
color: Colors.black,
fontWeight: FontWeight.w400,
fontFamily: 'Anek')), backgroundColor: Colors.transparent, elevation: 0,
fontFamily: 'Anek')),
backgroundColor: Colors.transparent,
elevation: 0,
),
drawer: const CommonDrawer(),
body: Padding(
@ -129,8 +141,8 @@ class _OnLeaveScreenState extends State<OnLeaveScreen> {
children: <Widget>[
const SizedBox(height: 16),
Container(
padding:
const EdgeInsets.all(20.0).copyWith(top: 30, bottom: 30),
padding: const EdgeInsets.all(20.0)
.copyWith(top: 30, bottom: 30),
margin: const EdgeInsets.symmetric(horizontal: 30.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
@ -158,7 +170,8 @@ class _OnLeaveScreenState extends State<OnLeaveScreen> {
fontWeight: FontWeight.w400,
fontFamily: 'Anek')),
const SizedBox(height: 3),
Wrap(direction: Axis.horizontal,
Wrap(
direction: Axis.horizontal,
children: [
buildLeaveTypeOption('Sick'),
const SizedBox(width: 10),
@ -177,25 +190,56 @@ class _OnLeaveScreenState extends State<OnLeaveScreen> {
const SizedBox(height: 16),
Align(
alignment: Alignment.center,
child: CommonElevatedButton(
child: Consumer<MarkLeaveProvider>(
builder: (context, value, child) =>
CommonElevatedButton(
borderRadius: 30,
width: double.infinity,
height: kToolbarHeight - 10,
text: 'ON LEAVE',
backgroundColor: const Color(0xff00784C),
backgroundColor:
const Color(0xff00784C),
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => const AttendanceSuccess()));
})
),
],
),
),
],
),
),
),),
value
.markLeave(
dateController.text
.trim(),
timeController.text
.trim(),
locationController.text
.trim(),
notesController.text
.trim(),
selectedLeaveType)
.then(
(result) {
var (status, message) =
result;
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(
content:
Text(message)));
if (status) {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) =>
const AttendanceSuccess()));
}
},
);
// Navigator.push(context, MaterialPageRoute(builder:(context) => const AttendanceSuccess(),));
}),
)),
],
),
),
],
),
),
),
),
));
}
}

View File

@ -8,25 +8,42 @@ class ApiClient {
final SecureStorageService _storageService = SecureStorageService();
ApiClient({String? baseUrl})
: _dio = Dio(BaseOptions(
: _dio = Dio(
BaseOptions(
baseUrl: baseUrl ?? ApiUrls.baseUrl,
connectTimeout: const Duration(seconds: 120),
receiveTimeout: const Duration(seconds: 120))) {
_dio.interceptors
.add(LogInterceptor(responseBody: true, requestBody: true));
_dio.interceptors.add(PrettyDioLogger());
_dio.interceptors
.add(InterceptorsWrapper(onRequest: (options, handler) async {
receiveTimeout: const Duration(seconds: 120),
),
) {
_dio.interceptors.add(
InterceptorsWrapper(
onRequest: (options, handler) async {
String? token = await _storageService.read(key: 'access_token');
if (token != null) {
options.headers['Authorization'] = 'Bearer $token';
}
return handler.next(options);
}, onResponse: (response, handler) {
},
onResponse: (response, handler) {
return handler.next(response);
}, onError: (DioException e, handler) {
},
onError: (DioException e, handler) {
return handler.next(e);
}));
},
),
);
_dio.interceptors
.add(LogInterceptor(responseBody: true, requestBody: true));
_dio.interceptors.add(PrettyDioLogger(
requestHeader: true,
requestBody: true,
responseBody: true,
responseHeader: false,
error: true,
compact: true,
maxWidth: 90,
));
}
Future<Response> get(String path, {Map<String, dynamic>? queryParameters}) {

View File

@ -2,7 +2,8 @@ class ApiUrls {
static const String baseUrl = 'https://cheminova-api-2.onrender.com/api/';
static const String loginUrl = 'territorymanager/login';
static const String profileUrl = 'territorymanager/my-profile';
static const String markAttendanceUrl = 'v1/markattendance/salescoordinator';
static const String markAttendanceUrl = 'v1/markattendance/territorymanager';
static const String markLeaveUrl = 'v1/markleave/territorymanager';
static const String forgetPasswordUrl = 'territorymanager/forgot-password';
static const String changePasswordUrl = 'territorymanager/password/update';
}