refactor: update application ID and improve attendance upload functionality

- Changed application ID from "com.marco.aiotstage" to "com.marco.aiot".
- Made markTime and date parameters required in uploadAttendanceImage method.
- Added logic to handle date selection and ensure attendance logs are uploaded with the correct date.
- Enhanced UI components for better user experience in attendance and directory views.
This commit is contained in:
Vaibhav Surve 2025-08-18 15:32:17 +05:30
parent fa767ea201
commit 1e48c686b2
8 changed files with 177 additions and 135 deletions

View File

@ -34,7 +34,7 @@ android {
// Default configuration for your application
defaultConfig {
// Specify your unique Application ID. This identifies your app on Google Play.
applicationId = "com.marco.aiotstage"
applicationId = "com.marco.aiot"
// Set minimum and target SDK versions based on Flutter's configuration
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion

View File

@ -3,16 +3,12 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:label="Marco_Stage"
android:label="Marco"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity

View File

@ -108,7 +108,8 @@ class AttendanceController extends GetxController {
String comment = "Marked via mobile app",
required int action,
bool imageCapture = true,
String? markTime,
String? markTime, // still optional in controller
String? date, // new optional param
}) async {
try {
uploadingStates[employeeId]?.value = true;
@ -141,6 +142,29 @@ class AttendanceController extends GetxController {
? ApiService.generateImageName(employeeId, employees.length + 1)
: "";
// ---------------- DATE / TIME LOGIC ----------------
final now = DateTime.now();
// Default effectiveDate = now
DateTime effectiveDate = now;
if (action == 1) {
// Checkout
// Try to find today's open log for this employee
final log = attendanceLogs.firstWhereOrNull(
(log) => log.employeeId == employeeId && log.checkOut == null,
);
if (log?.checkIn != null) {
effectiveDate = log!.checkIn!; // use check-in date
}
}
final formattedMarkTime = markTime ?? DateFormat('hh:mm a').format(now);
final formattedDate =
date ?? DateFormat('yyyy-MM-dd').format(effectiveDate);
// ---------------- API CALL ----------------
final result = await ApiService.uploadAttendanceImage(
id,
employeeId,
@ -152,10 +176,12 @@ class AttendanceController extends GetxController {
comment: comment,
action: action,
imageCapture: imageCapture,
markTime: markTime,
markTime: formattedMarkTime,
date: formattedDate,
);
logSafe("Attendance uploaded for $employeeId, action: $action");
logSafe(
"Attendance uploaded for $employeeId, action: $action, date: $formattedDate");
return result;
} catch (e, stacktrace) {
logSafe("Error uploading attendance",

View File

@ -182,22 +182,16 @@ class DirectoryController extends GetxController {
final bucketMatch = selectedBuckets.isEmpty ||
contact.bucketIds.any((id) => selectedBuckets.contains(id));
// Name, org, email, phone, tags
final nameMatch = contact.name.toLowerCase().contains(query);
final orgMatch = contact.organization.toLowerCase().contains(query);
final emailMatch = contact.contactEmails
.any((e) => e.emailAddress.toLowerCase().contains(query));
final phoneMatch = contact.contactPhones
.any((p) => p.phoneNumber.toLowerCase().contains(query));
final tagMatch =
contact.tags.any((tag) => tag.name.toLowerCase().contains(query));
final categoryNameMatch =
contact.contactCategory?.name.toLowerCase().contains(query) ?? false;
final bucketNameMatch = contact.bucketIds.any((id) {
final bucketName = contactBuckets
.firstWhereOrNull((b) => b.id == id)
@ -218,6 +212,10 @@ class DirectoryController extends GetxController {
return categoryMatch && bucketMatch && searchMatch;
}).toList();
// 🔑 Ensure results are always alphabetically sorted
filteredContacts
.sort((a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()));
}
void toggleCategory(String categoryId) {

View File

@ -1085,7 +1085,7 @@ class ApiService {
? _parseResponse(res, label: 'Regularization Logs')
: null);
static Future<bool> uploadAttendanceImage(
static Future<bool> uploadAttendanceImage(
String id,
String employeeId,
XFile? imageFile,
@ -1096,17 +1096,17 @@ class ApiService {
String comment = "",
required int action,
bool imageCapture = true,
String? markTime,
}) async {
final now = DateTime.now();
required String markTime, // 👈 now required
required String date, // 👈 new required param
}) async {
final body = {
"id": id,
"employeeId": employeeId,
"projectId": projectId,
"markTime": markTime ?? DateFormat('hh:mm a').format(now),
"markTime": markTime, // 👈 directly from UI
"comment": comment,
"action": action,
"date": DateFormat('yyyy-MM-dd').format(now),
"date": date, // 👈 directly from UI
if (imageCapture) "latitude": '$latitude',
if (imageCapture) "longitude": '$longitude',
};
@ -1134,6 +1134,7 @@ class ApiService {
body,
customTimeout: extendedTimeout,
);
if (response == null) return false;
final json = jsonDecode(response.body);
@ -1141,7 +1142,8 @@ class ApiService {
logSafe("Failed to upload image: ${json['message'] ?? 'Unknown error'}");
return false;
}
}
static String generateImageName(String employeeId, int count) {
final now = DateTime.now();

View File

@ -49,6 +49,9 @@ class BaseBottomSheet extends StatelessWidget {
),
],
),
child: SafeArea(
// 👈 prevents overlap with nav bar
top: false,
child: Padding(
padding: const EdgeInsets.fromLTRB(20, 16, 20, 32),
child: Column(
@ -67,10 +70,7 @@ class BaseBottomSheet extends StatelessWidget {
MyText.titleLarge(title, fontWeight: 700),
MySpacing.height(12),
child,
MySpacing.height(12),
// 👇 Buttons (if enabled)
if (showButtons) ...[
Row(
children: [
@ -113,7 +113,6 @@ class BaseBottomSheet extends StatelessWidget {
),
],
),
// 👇 Optional Bottom Content
if (bottomContent != null) ...[
MySpacing.height(12),
bottomContent!,
@ -124,6 +123,7 @@ class BaseBottomSheet extends StatelessWidget {
),
),
),
),
);
}
}

View File

@ -94,10 +94,13 @@ class _AttendanceFilterBottomSheetState
),
InkWell(
borderRadius: BorderRadius.circular(10),
onTap: () => widget.controller.selectDateRangeForAttendance(
onTap: () async {
await widget.controller.selectDateRangeForAttendance(
context,
widget.controller,
),
);
setState(() {}); // rebuild UI after date range is updated
},
child: Ink(
decoration: BoxDecoration(
color: Colors.white,

View File

@ -173,6 +173,23 @@ class _DirectoryViewState extends State<DirectoryView> {
const EdgeInsets.symmetric(horizontal: 12),
prefixIcon: const Icon(Icons.search,
size: 20, color: Colors.grey),
suffixIcon: ValueListenableBuilder<TextEditingValue>(
valueListenable: searchController,
builder: (context, value, _) {
if (value.text.isEmpty) {
return const SizedBox.shrink();
}
return IconButton(
icon: const Icon(Icons.clear,
size: 20, color: Colors.grey),
onPressed: () {
searchController.clear();
controller.searchQuery.value = '';
controller.applyFilters();
},
);
},
),
hintText: 'Search contacts...',
filled: true,
fillColor: Colors.white,