Compare commits
1 Commits
main
...
Feature_Pu
Author | SHA1 | Date | |
---|---|---|---|
0f072ed09e |
@ -5,82 +5,50 @@ plugins {
|
||||
id "dev.flutter.flutter-gradle-plugin"
|
||||
id("com.google.gms.google-services")
|
||||
}
|
||||
|
||||
// Load keystore properties from key.properties file
|
||||
def keystoreProperties = new Properties()
|
||||
def keystorePropertiesFile = rootProject.file('key.properties')
|
||||
if (keystorePropertiesFile.exists()) {
|
||||
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
|
||||
dependencies {
|
||||
// Import the Firebase BoM
|
||||
implementation(platform("com.google.firebase:firebase-bom:33.15.0"))
|
||||
// TODO: Add the dependencies for Firebase products you want to use
|
||||
// When using the BoM, don't specify versions in Firebase dependencies
|
||||
implementation("com.google.firebase:firebase-analytics")
|
||||
// Add the dependencies for any other desired Firebase products
|
||||
// https://firebase.google.com/docs/android/setup#available-libraries
|
||||
}
|
||||
|
||||
android {
|
||||
// Define the namespace for your Android application
|
||||
namespace = "com.marco.aiot"
|
||||
// Set the compile SDK version based on Flutter's configuration
|
||||
namespace = "com.example.marco"
|
||||
compileSdk = flutter.compileSdkVersion
|
||||
// Set the NDK version based on Flutter's configuration
|
||||
ndkVersion = flutter.ndkVersion
|
||||
|
||||
// Configure Java compatibility options
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
// ✅ Enable core library desugaring for Java 8+ APIs
|
||||
coreLibraryDesugaringEnabled true
|
||||
}
|
||||
|
||||
// Configure Kotlin options for JVM target
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
// Default configuration for your application
|
||||
defaultConfig {
|
||||
// Specify your unique Application ID. This identifies your app on Google Play.
|
||||
applicationId = "com.marco.aiot"
|
||||
// Set minimum and target SDK versions based on Flutter's configuration
|
||||
minSdk = 23
|
||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||
applicationId = "com.marcoaiot.marcopms"
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://flutter.dev/to/review-gradle-config.
|
||||
minSdk = flutter.minSdkVersion
|
||||
targetSdk = flutter.targetSdkVersion
|
||||
// Set version code and name based on Flutter's configuration (from pubspec.yaml)
|
||||
versionCode = flutter.versionCode
|
||||
versionName = flutter.versionName
|
||||
}
|
||||
|
||||
// Define signing configurations for different build types
|
||||
signingConfigs {
|
||||
release {
|
||||
// Reference the key alias from key.properties
|
||||
keyAlias keystoreProperties['keyAlias']
|
||||
// Reference the key password from key.properties
|
||||
keyPassword keystoreProperties['keyPassword']
|
||||
// Reference the keystore file path from key.properties
|
||||
storeFile file(keystoreProperties['storeFile'])
|
||||
// Reference the keystore password from key.properties
|
||||
storePassword keystoreProperties['storePassword']
|
||||
}
|
||||
}
|
||||
|
||||
// Define different build types (e.g., debug, release)
|
||||
buildTypes {
|
||||
release {
|
||||
// Apply the 'release' signing configuration defined above to the release build
|
||||
signingConfig signingConfigs.release
|
||||
// Enable code minification to reduce app size
|
||||
minifyEnabled true
|
||||
// Enable resource shrinking to remove unused resources
|
||||
shrinkResources true
|
||||
// Other release specific configurations can be added here, e.g., ProGuard rules
|
||||
// TODO: Add your own signing config for the release build.
|
||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||
signingConfig = signingConfigs.debug
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Configure Flutter specific settings, pointing to the root of your Flutter project
|
||||
flutter {
|
||||
source = "../.."
|
||||
}
|
||||
|
||||
// ✅ Add required dependencies for desugaring
|
||||
dependencies {
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.4'
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,21 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "626581282477",
|
||||
"project_id": "mtest-a0635",
|
||||
"storage_bucket": "mtest-a0635.firebasestorage.app"
|
||||
"project_number": "1092827913328",
|
||||
"project_id": "marcopms-mobileapp",
|
||||
"storage_bucket": "marcopms-mobileapp.firebasestorage.app"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:626581282477:android:8d3cf5009ff92ef67ff024",
|
||||
"mobilesdk_app_id": "1:1092827913328:android:2c70d4f75f334a572ae8b5",
|
||||
"android_client_info": {
|
||||
"package_name": "com.marco.aiot"
|
||||
"package_name": "com.marcoaiot.marcopms"
|
||||
}
|
||||
},
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyCBkDQRpbSdR0bo6pO4Bm0ZIdXkdaE3z-A"
|
||||
"current_key": "AIzaSyAugYA2UsQewE-Yd6LBU90hWb2W6NkiMpU"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
|
@ -6,6 +6,5 @@
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
|
||||
</manifest>
|
||||
|
@ -1,14 +1,16 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<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.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||
|
||||
|
||||
|
||||
|
||||
<application
|
||||
android:label="Marco"
|
||||
android:label="Marco_Stage"
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
<activity
|
||||
@ -28,6 +30,10 @@
|
||||
android:name="io.flutter.embedding.android.NormalTheme"
|
||||
android:resource="@style/NormalTheme"
|
||||
/>
|
||||
<meta-data
|
||||
android:name="com.google.firebase.messaging.default_notification_channel_id"
|
||||
android:value="high_importance_channel"/>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
@ -38,9 +44,6 @@
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
<meta-data
|
||||
android:name="com.google.firebase.messaging.default_notification_channel_id"
|
||||
android:value="high_importance_channel"/>
|
||||
</application>
|
||||
<!-- Required to query activities that can process text, see:
|
||||
https://developer.android.com/training/package-visibility and
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.marco.aiot
|
||||
package com.example.marco
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=false
|
||||
android.enableJetifier=true
|
||||
|
@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
|
||||
|
@ -18,9 +18,10 @@ pluginManagement {
|
||||
|
||||
plugins {
|
||||
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
|
||||
id "com.android.application" version "8.6.0" apply false
|
||||
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
|
||||
id "com.android.application" version "8.2.1" apply false
|
||||
id "org.jetbrains.kotlin.android" version "2.1.0" apply false
|
||||
id("com.google.gms.google-services") version "4.4.2" apply false
|
||||
|
||||
}
|
||||
|
||||
include ":app"
|
||||
|
95737
assets/data/australia.json
Normal file
192
assets/data/chat.json
Normal file
@ -0,0 +1,192 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"first_name": "James Carter",
|
||||
"email": "james.carter@example.com",
|
||||
"messages": [
|
||||
{
|
||||
"message": "How is your day going?",
|
||||
"send_at": "2024-11-15T10:05:10Z",
|
||||
"from_me": false
|
||||
},
|
||||
{
|
||||
"message": "Reminder about the project meeting tomorrow",
|
||||
"send_at": "2023-06-20T14:23:11Z",
|
||||
"from_me": true
|
||||
},
|
||||
{
|
||||
"message": "Can we meet today for a quick chat?",
|
||||
"send_at": "2023-04-19T17:30:08Z",
|
||||
"from_me": false
|
||||
},
|
||||
{
|
||||
"message": "Yes, all is good. See you tomorrow at 2 PM for the meeting",
|
||||
"send_at": "2023-03-22T11:09:45Z",
|
||||
"from_me": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"first_name": "Sophia Lee",
|
||||
"email": "sophia.lee@example.com",
|
||||
"messages": [
|
||||
{
|
||||
"message": "Are we meeting today for the weekly catch-up?",
|
||||
"send_at": "2023-09-10T08:45:36Z",
|
||||
"from_me": false
|
||||
},
|
||||
{
|
||||
"message": "Please review these updated documents",
|
||||
"send_at": "2023-11-17T11:22:33Z",
|
||||
"from_me": true
|
||||
},
|
||||
{
|
||||
"message": "Good morning, How are you? When is our next meeting?",
|
||||
"send_at": "2023-05-13T09:25:18Z",
|
||||
"from_me": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"first_name": "Ethan Scott",
|
||||
"email": "ethan.scott@example.com",
|
||||
"messages": [
|
||||
{
|
||||
"message": "Are you available for a quick call? Need to discuss something",
|
||||
"send_at": "2023-12-05T07:40:21Z",
|
||||
"from_me": false
|
||||
},
|
||||
{
|
||||
"message": "Let's meet today, shall we?",
|
||||
"send_at": "2023-03-17T14:00:12Z",
|
||||
"from_me": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"first_name": "Olivia Brown",
|
||||
"email": "olivia.brown@example.com",
|
||||
"messages": [
|
||||
{
|
||||
"message": "Let's meet today for a team discussion",
|
||||
"send_at": "2023-05-30T11:55:10Z",
|
||||
"from_me": false
|
||||
},
|
||||
{
|
||||
"message": "Hope you're having a great day. Let's catch up soon",
|
||||
"send_at": "2023-07-12T12:36:44Z",
|
||||
"from_me": true
|
||||
},
|
||||
{
|
||||
"message": "I need to go buy some groceries this afternoon, I'll be a bit late.",
|
||||
"send_at": "2024-01-10T13:20:45Z",
|
||||
"from_me": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"first_name": "Charlotte Miller",
|
||||
"email": "charlotte.miller@example.com",
|
||||
"messages": [
|
||||
{
|
||||
"message": "Are you available for a quick chat?",
|
||||
"send_at": "2023-11-11T16:50:09Z",
|
||||
"from_me": false
|
||||
},
|
||||
{
|
||||
"message": "I just sent you the updated contract documents for review.",
|
||||
"send_at": "2023-10-04T18:22:56Z",
|
||||
"from_me": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"first_name": "Jackson Harris",
|
||||
"email": "jackson.harris@example.com",
|
||||
"messages": [
|
||||
{
|
||||
"message": "How's everything going? Any updates on the project?",
|
||||
"send_at": "2023-08-25T11:10:30Z",
|
||||
"from_me": false
|
||||
},
|
||||
{
|
||||
"message": "Sending over the latest draft for your review",
|
||||
"send_at": "2023-12-02T10:14:50Z",
|
||||
"from_me": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"first_name": "Aiden Cooper",
|
||||
"email": "aiden.cooper@example.com",
|
||||
"messages": [
|
||||
{
|
||||
"message": "Do you have time today for a discussion?",
|
||||
"send_at": "2023-10-05T09:18:22Z",
|
||||
"from_me": false
|
||||
},
|
||||
{
|
||||
"message": "The new update is ready for deployment, please check it.",
|
||||
"send_at": "2024-01-25T11:29:13Z",
|
||||
"from_me": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"first_name": "Lily King",
|
||||
"email": "lily.king@example.com",
|
||||
"messages": [
|
||||
{
|
||||
"message": "Would you be able to meet today for a catch-up?",
|
||||
"send_at": "2023-06-18T13:12:09Z",
|
||||
"from_me": false
|
||||
},
|
||||
{
|
||||
"message": "I have finished reviewing the files, please take a look.",
|
||||
"send_at": "2023-12-18T16:47:02Z",
|
||||
"from_me": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"first_name": "Max Taylor",
|
||||
"email": "max.taylor@example.com",
|
||||
"messages": [
|
||||
{
|
||||
"message": "Please check the attached file and confirm if everything is okay.",
|
||||
"send_at": "2023-09-29T14:10:33Z",
|
||||
"from_me": false
|
||||
},
|
||||
{
|
||||
"message": "Sending over the revised schedule for the next phase.",
|
||||
"send_at": "2024-01-02T17:12:11Z",
|
||||
"from_me": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"first_name": "Avery Clark",
|
||||
"email": "avery.clark@example.com",
|
||||
"messages": [
|
||||
{
|
||||
"message": "Are we ready for the meeting today?",
|
||||
"send_at": "2023-08-22T12:43:50Z",
|
||||
"from_me": false
|
||||
},
|
||||
{
|
||||
"message": "I updated the timeline. Let me know if you have any questions.",
|
||||
"send_at": "2023-12-15T10:55:29Z",
|
||||
"from_me": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
82
assets/data/coin_growth.json
Normal file
@ -0,0 +1,82 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"asset": "Alaska Air Group, Inc.",
|
||||
"date": "2024-06-17T12:59:41Z",
|
||||
"ip_address": "113.9.18.110",
|
||||
"status": "Unpaid",
|
||||
"amount": 7061
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"asset": "T2 Biosystems, Inc.",
|
||||
"date": "2024-09-09T00:20:08Z",
|
||||
"ip_address": "45.51.68.143",
|
||||
"status": "Unpaid",
|
||||
"amount": 5677
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"asset": "North American Energy Partners, Inc.",
|
||||
"date": "2024-07-17T10:46:42Z",
|
||||
"ip_address": "221.131.122.193",
|
||||
"status": "Unpaid",
|
||||
"amount": 5420
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"asset": "Finjan Holdings, Inc.",
|
||||
"date": "2024-01-20T20:10:26Z",
|
||||
"ip_address": "50.242.43.22",
|
||||
"status": "Success",
|
||||
"amount": 6433
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"asset": "Omega Healthcare Investors, Inc.",
|
||||
"date": "2024-11-14T23:08:09Z",
|
||||
"ip_address": "109.125.5.131",
|
||||
"status": "Success",
|
||||
"amount": 6317
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"asset": "MediciNova, Inc.",
|
||||
"date": "2024-01-12T18:20:33Z",
|
||||
"ip_address": "54.103.156.190",
|
||||
"status": "Unpaid",
|
||||
"amount": 7952
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"asset": "PowerShares LadderRite 0-5 Year Corporate Bond Portfolio",
|
||||
"date": "2024-04-26T00:44:42Z",
|
||||
"ip_address": "169.190.183.205",
|
||||
"status": "Success",
|
||||
"amount": 6294
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"asset": "VelocityShares Daily 2x VIX Medium-Term ETN",
|
||||
"date": "2024-02-01T12:47:59Z",
|
||||
"ip_address": "144.189.211.137",
|
||||
"status": "Success",
|
||||
"amount": 4419
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"asset": "Liberty TripAdvisor Holdings, Inc.",
|
||||
"date": "2023-12-29T14:49:59Z",
|
||||
"ip_address": "166.41.221.149",
|
||||
"status": "Unpaid",
|
||||
"amount": 4195
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"asset": "Scorpio Tankers Inc.",
|
||||
"date": "2023-12-02T11:36:44Z",
|
||||
"ip_address": "27.151.0.226",
|
||||
"status": "Success",
|
||||
"amount": 8395
|
||||
}
|
||||
]
|
202
assets/data/customer.json
Normal file
@ -0,0 +1,202 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"first_name": "Sabina",
|
||||
"last_name": "Brothwood",
|
||||
"project_name": "Wunsch, DuBuque and Green",
|
||||
"phone_number": "541-568-8047",
|
||||
"balance": "31907",
|
||||
"order_count": 7,
|
||||
"last_order": "2022-10-07T03:43:16Z"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"first_name": "Felic",
|
||||
"last_name": "Parlor",
|
||||
"project_name": "Dare LLC",
|
||||
"phone_number": "866-349-3385",
|
||||
"balance": "02260",
|
||||
"order_count": 26,
|
||||
"last_order": "2023-07-12T07:52:19Z"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"first_name": "Marnie",
|
||||
"last_name": "Kofax",
|
||||
"project_name": "Von LLC",
|
||||
"phone_number": "821-779-3766",
|
||||
"balance": "663",
|
||||
"order_count": 21,
|
||||
"last_order": "2022-10-14T21:19:33Z"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"first_name": "Tine",
|
||||
"last_name": "Meron",
|
||||
"project_name": "Stracke Inc",
|
||||
"phone_number": "901-149-2915",
|
||||
"balance": "84",
|
||||
"order_count": 8,
|
||||
"last_order": "2023-04-06T12:36:09Z"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"first_name": "Shanon",
|
||||
"last_name": "Ivashchenko",
|
||||
"project_name": "Satterfield, Schultz and Jones",
|
||||
"phone_number": "452-728-1072",
|
||||
"balance": "0878",
|
||||
"order_count": 34,
|
||||
"last_order": "2023-04-03T15:07:21Z"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"first_name": "Guthrey",
|
||||
"last_name": "Crossland",
|
||||
"project_name": "Medhurst and Sons",
|
||||
"phone_number": "212-991-7314",
|
||||
"balance": "0291",
|
||||
"order_count": 7,
|
||||
"last_order": "2022-12-03T04:24:53Z"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"first_name": "Florie",
|
||||
"last_name": "Chestnutt",
|
||||
"project_name": "Beer-Kunze",
|
||||
"phone_number": "935-525-9749",
|
||||
"balance": "07984",
|
||||
"order_count": 69,
|
||||
"last_order": "2023-01-14T10:42:28Z"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"first_name": "Wittie",
|
||||
"last_name": "Damsell",
|
||||
"project_name": "Daniel, Legros and Roberts",
|
||||
"phone_number": "632-787-4799",
|
||||
"balance": "22844",
|
||||
"order_count": 41,
|
||||
"last_order": "2023-01-18T09:38:50Z"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"first_name": "Aimee",
|
||||
"last_name": "Dibdall",
|
||||
"project_name": "Schuster LLC",
|
||||
"phone_number": "404-339-9261",
|
||||
"balance": "460",
|
||||
"order_count": 41,
|
||||
"last_order": "2023-04-15T03:08:51Z"
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"first_name": "Inna",
|
||||
"last_name": "Juggins",
|
||||
"project_name": "Johnson Group",
|
||||
"phone_number": "769-573-9516",
|
||||
"balance": "77",
|
||||
"order_count": 18,
|
||||
"last_order": "2022-09-13T05:14:51Z"
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"first_name": "Cathyleen",
|
||||
"last_name": "Went",
|
||||
"project_name": "DuBuque LLC",
|
||||
"phone_number": "558-736-4450",
|
||||
"balance": "24",
|
||||
"order_count": 98,
|
||||
"last_order": "2023-07-05T05:26:12Z"
|
||||
},
|
||||
{
|
||||
"id": 12,
|
||||
"first_name": "Kora",
|
||||
"last_name": "Dowderswell",
|
||||
"project_name": "Harber, Daugherty and West",
|
||||
"phone_number": "721-147-2917",
|
||||
"balance": "32",
|
||||
"order_count": 5,
|
||||
"last_order": "2022-10-22T07:47:42Z"
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"first_name": "Loni",
|
||||
"last_name": "Armin",
|
||||
"project_name": "Fadel-Kerluke",
|
||||
"phone_number": "251-582-9867",
|
||||
"balance": "2122",
|
||||
"order_count": 4,
|
||||
"last_order": "2023-01-26T19:56:37Z"
|
||||
},
|
||||
{
|
||||
"id": 14,
|
||||
"first_name": "Kalle",
|
||||
"last_name": "Spybey",
|
||||
"project_name": "Kshlerin, Torp and Koelpin",
|
||||
"phone_number": "245-661-6328",
|
||||
"balance": "61034",
|
||||
"order_count": 70,
|
||||
"last_order": "2022-12-29T15:38:20Z"
|
||||
},
|
||||
{
|
||||
"id": 15,
|
||||
"first_name": "Verena",
|
||||
"last_name": "Skerme",
|
||||
"project_name": "Dach, Abshire and Crooks",
|
||||
"phone_number": "227-694-0272",
|
||||
"balance": "68921",
|
||||
"order_count": 3,
|
||||
"last_order": "2022-11-29T23:02:11Z"
|
||||
},
|
||||
{
|
||||
"id": 16,
|
||||
"first_name": "Lisle",
|
||||
"last_name": "McGowan",
|
||||
"project_name": "White, Murphy and Sawayn",
|
||||
"phone_number": "196-817-6277",
|
||||
"balance": "7250",
|
||||
"order_count": 34,
|
||||
"last_order": "2023-06-14T11:10:56Z"
|
||||
},
|
||||
{
|
||||
"id": 17,
|
||||
"first_name": "Bryce",
|
||||
"last_name": "Pires",
|
||||
"project_name": "Crooks Group",
|
||||
"phone_number": "424-217-0372",
|
||||
"balance": "549",
|
||||
"order_count": 50,
|
||||
"last_order": "2023-01-08T17:58:09Z"
|
||||
},
|
||||
{
|
||||
"id": 18,
|
||||
"first_name": "Ibrahim",
|
||||
"last_name": "Battram",
|
||||
"project_name": "Schmidt, Feil and Schaden",
|
||||
"phone_number": "836-473-5900",
|
||||
"balance": "3",
|
||||
"order_count": 86,
|
||||
"last_order": "2023-08-05T01:46:22Z"
|
||||
},
|
||||
{
|
||||
"id": 19,
|
||||
"first_name": "Josepha",
|
||||
"last_name": "Grishkov",
|
||||
"project_name": "Welch-Wisozk",
|
||||
"phone_number": "928-393-5306",
|
||||
"balance": "528",
|
||||
"order_count": 38,
|
||||
"last_order": "2023-08-18T19:01:25Z"
|
||||
},
|
||||
{
|
||||
"id": 20,
|
||||
"first_name": "Ellis",
|
||||
"last_name": "Barfoot",
|
||||
"project_name": "Davis, Ondricka and Schaefer",
|
||||
"phone_number": "169-236-9311",
|
||||
"balance": "169",
|
||||
"order_count": 11,
|
||||
"last_order": "2023-02-21T16:29:59Z"
|
||||
}
|
||||
]
|
72
assets/data/drag_n_drop_data.json
Normal file
@ -0,0 +1,72 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"image": "assets/dummy/dummy_1.jpg",
|
||||
"name": "Meir O'Leahy",
|
||||
"user_name": "moleahy0",
|
||||
"contact_number": "817-666-8080"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"image": "assets/dummy/dummy_2.jpg",
|
||||
"name": "Ernie Ayling",
|
||||
"user_name": "eayling1",
|
||||
"contact_number": "890-910-3243"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"image": "assets/dummy/dummy_3.jpg",
|
||||
"name": "Mead Ezzle",
|
||||
"user_name": "mezzle2",
|
||||
"contact_number": "293-162-4468"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"image": "assets/dummy/dummy_4.jpg",
|
||||
"name": "Esta Norewood",
|
||||
"user_name": "enorewood3",
|
||||
"contact_number": "532-164-0604"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"image": "assets/dummy/dummy_5.jpg",
|
||||
"name": "Bartram Cottell",
|
||||
"user_name": "bcottell4",
|
||||
"contact_number": "940-143-2842"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"image": "assets/dummy/dummy_1.jpg",
|
||||
"name": "Nicola Reolfo",
|
||||
"user_name": "nreolfo5",
|
||||
"contact_number": "356-558-8324"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"image": "assets/dummy/dummy_2.jpg",
|
||||
"name": "Normy Gilhoolie",
|
||||
"user_name": "ngilhoolie6",
|
||||
"contact_number": "256-770-5288"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"image": "assets/dummy/dummy_3.jpg",
|
||||
"name": "Octavia Margerrison",
|
||||
"user_name": "omargerrison7",
|
||||
"contact_number": "744-595-1968"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"image": "assets/dummy/dummy_4.jpg",
|
||||
"name": "Stella Barriball",
|
||||
"user_name": "sbarriball8",
|
||||
"contact_number": "906-522-1874"
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"image": "assets/dummy/dummy_5.jpg",
|
||||
"name": "Panchito Chase",
|
||||
"user_name": "pchase9",
|
||||
"contact_number": "929-922-7735"
|
||||
}
|
||||
]
|
54614
assets/data/europe_map.json
Normal file
102
assets/data/job_recent_application.json
Normal file
@ -0,0 +1,102 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"candidate": "Patrica",
|
||||
"category": "Manufacture",
|
||||
"designation": "Sr.UI Developer",
|
||||
"mail": "pbeedie0@ustream.tv",
|
||||
"location": "Pojan",
|
||||
"date": "2024-08-09T06:03:25Z",
|
||||
"type": "Freelancer"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"candidate": "Angelique",
|
||||
"category": "Marketing",
|
||||
"designation": "Team Lead",
|
||||
"mail": "asamwayes1@fotki.com",
|
||||
"location": "Jiangluo",
|
||||
"date": "2023-11-17T10:23:18Z",
|
||||
"type": "Hybride"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"candidate": "Garnet",
|
||||
"category": "Marketing",
|
||||
"designation": "Team Lead",
|
||||
"mail": "gjarrelt2@dailymail.co.uk",
|
||||
"location": "Wissembourg",
|
||||
"date": "2024-03-18T15:31:21Z",
|
||||
"type": "Freelancer"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"candidate": "Guglielmo",
|
||||
"category": "Manufacture",
|
||||
"designation": "Sales Executive",
|
||||
"mail": "gcarlone3@ted.com",
|
||||
"location": "Aoqiao",
|
||||
"date": "2024-04-08T22:04:13Z",
|
||||
"type": "Part Time"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"candidate": "Reggie",
|
||||
"category": "Manufacture",
|
||||
"designation": "Team Lead",
|
||||
"mail": "rmacieiczyk4@booking.com",
|
||||
"location": "Insrom",
|
||||
"date": "2024-01-09T06:29:40Z",
|
||||
"type": "Freelancer"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"candidate": "Florri",
|
||||
"category": "Manufacture",
|
||||
"designation": "Sales Executive",
|
||||
"mail": "fharesign5@yellowbook.com",
|
||||
"location": "Itambacuri",
|
||||
"date": "2024-09-05T11:09:36Z",
|
||||
"type": "Part Time"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"candidate": "Annabella",
|
||||
"category": "Manufacture",
|
||||
"designation": "Team Lead",
|
||||
"mail": "aossipenko6@ucoz.com",
|
||||
"location": "Watthana Nakhon",
|
||||
"date": "2024-07-27T16:17:23Z",
|
||||
"type": "Full Time"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"candidate": "Arlene",
|
||||
"category": "Manufacture",
|
||||
"designation": "Team Lead",
|
||||
"mail": "agook7@google.com.hk",
|
||||
"location": "Hayama",
|
||||
"date": "2024-09-14T13:32:31Z",
|
||||
"type": "Freelancer"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"candidate": "Shurlocke",
|
||||
"category": "Manufacture",
|
||||
"designation": "Sales Executive",
|
||||
"mail": "sgallehawk8@squidoo.com",
|
||||
"location": "Bel Air Rivière Sèche",
|
||||
"date": "2024-06-18T00:23:24Z",
|
||||
"type": "Freelancer"
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"candidate": "Ricoriki",
|
||||
"category": "Service",
|
||||
"designation": "Sales Executive",
|
||||
"mail": "rgillio9@mapy.cz",
|
||||
"location": "Tawangsari",
|
||||
"date": "2024-06-14T19:59:41Z",
|
||||
"type": "Freelancer"
|
||||
}
|
||||
]
|
112
assets/data/leads_report_data.json
Normal file
@ -0,0 +1,112 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"first_name": "Bordy",
|
||||
"email": "bjeffreys0@macromedia.com",
|
||||
"phone_number": "217-779-9808",
|
||||
"company_name": "Voonyx",
|
||||
"status": "Won Lead",
|
||||
"location": "Presidencia Roque Sáenz Peña",
|
||||
"date": "2024-06-20T06:26:12Z",
|
||||
"amount": 52397
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"first_name": "Collin",
|
||||
"email": "cgething1@paginegialle.it",
|
||||
"phone_number": "124-897-0512",
|
||||
"company_name": "Rhyzio",
|
||||
"status": "New Lead",
|
||||
"location": "Nombre de Jesús",
|
||||
"date": "2023-11-20T12:12:32Z",
|
||||
"amount": 58203
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"first_name": "Bear",
|
||||
"email": "bfowlds2@booking.com",
|
||||
"phone_number": "391-249-1041",
|
||||
"company_name": "Blogtag",
|
||||
"status": "Lost Lead",
|
||||
"location": "Shani",
|
||||
"date": "2024-11-09T07:57:49Z",
|
||||
"amount": 18717
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"first_name": "Robers",
|
||||
"email": "raujouanet3@google.cn",
|
||||
"phone_number": "128-604-5632",
|
||||
"company_name": "Quire",
|
||||
"status": "Lost Lead",
|
||||
"location": "Benghazi",
|
||||
"date": "2023-12-09T17:33:39Z",
|
||||
"amount": 11267
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"first_name": "Shirlene",
|
||||
"email": "sjoiris4@theglobeandmail.com",
|
||||
"phone_number": "471-884-5686",
|
||||
"company_name": "Voonder",
|
||||
"status": "New Lead",
|
||||
"location": "Krasnaye",
|
||||
"date": "2024-01-15T03:06:07Z",
|
||||
"amount": 66877
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"first_name": "Erik",
|
||||
"email": "ebudden5@zdnet.com",
|
||||
"phone_number": "957-550-9950",
|
||||
"company_name": "Digitube",
|
||||
"status": "Won Lead",
|
||||
"location": "Taouloukoult",
|
||||
"date": "2024-01-21T03:05:01Z",
|
||||
"amount": 55766
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"first_name": "Sabina",
|
||||
"email": "sdenman6@ning.com",
|
||||
"phone_number": "612-207-4109",
|
||||
"company_name": "Kwinu",
|
||||
"status": "Lost Lead",
|
||||
"location": "Minneapolis",
|
||||
"date": "2024-05-19T15:59:28Z",
|
||||
"amount": 24691
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"first_name": "Andi",
|
||||
"email": "aschruyer7@imdb.com",
|
||||
"phone_number": "410-936-5855",
|
||||
"company_name": "Photojam",
|
||||
"status": "Won Lead",
|
||||
"location": "Masina",
|
||||
"date": "2024-09-30T18:31:07Z",
|
||||
"amount": 7228
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"first_name": "Kathy",
|
||||
"email": "kstandall8@woothemes.com",
|
||||
"phone_number": "840-267-7381",
|
||||
"company_name": "Quinu",
|
||||
"status": "Won Lead",
|
||||
"location": "Shashi",
|
||||
"date": "2024-04-21T18:00:25Z",
|
||||
"amount": 85726
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"first_name": "Lenka",
|
||||
"email": "llennon9@hexun.com",
|
||||
"phone_number": "962-993-3146",
|
||||
"company_name": "Skaboo",
|
||||
"status": "Won Lead",
|
||||
"location": "Shireet",
|
||||
"date": "2024-06-19T12:27:05Z",
|
||||
"amount": 10069
|
||||
}
|
||||
]
|
197
assets/data/product_data.json
Normal file
@ -0,0 +1,197 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Mints - Striped Red",
|
||||
"description": "Laceration of ulnar artery at wrs/hnd lv of unsp arm",
|
||||
"price": 54,
|
||||
"stock": 72,
|
||||
"category": "Scallops 60/80 Iqf",
|
||||
"order_counts": 10,
|
||||
"created_at": "2022-07-20T09:52:34Z",
|
||||
"rating": 2.49,
|
||||
"rating_count": 42,
|
||||
"sku": "RCII"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Pasta - Ravioli",
|
||||
"description": "Oth disp fx of upper end l humer, subs for fx w delay heal",
|
||||
"price": 35,
|
||||
"stock": 64,
|
||||
"category": "Chocolate - Mi - Amere Semi",
|
||||
"order_counts": 45,
|
||||
"created_at": "2023-03-25T22:32:10Z",
|
||||
"rating": 4.66,
|
||||
"rating_count": 82,
|
||||
"sku": "RDS.A"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "Soup - Campbells Chili",
|
||||
"description": "Nondisp fx of anterior wall of left acetab, init for opn fx",
|
||||
"price": 27,
|
||||
"stock": 21,
|
||||
"category": "Tomatoes - Cherry, Yellow",
|
||||
"order_counts": 53,
|
||||
"created_at": "2022-05-18T15:56:06Z",
|
||||
"rating": 3.05,
|
||||
"rating_count": 66,
|
||||
"sku": "STNG"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"name": "Fennel - Seeds",
|
||||
"description": "Displ spiral fx shaft of ulna, r arm, 7thD",
|
||||
"price": 124,
|
||||
"stock": 56,
|
||||
"category": "Squid - U - 10 Thailand",
|
||||
"order_counts": 13,
|
||||
"created_at": "2022-04-21T11:32:39Z",
|
||||
"rating": 0.59,
|
||||
"rating_count": 55,
|
||||
"sku": "FEUZ"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"name": "Salt - Celery",
|
||||
"description": "Interstitial myositis, lower leg",
|
||||
"price": 25,
|
||||
"stock": 78,
|
||||
"category": "Gatorade - Lemon Lime",
|
||||
"order_counts": 30,
|
||||
"created_at": "2023-01-01T01:15:44Z",
|
||||
"rating": 1.42,
|
||||
"rating_count": 10,
|
||||
"sku": "VER"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"name": "Flour - Chickpea",
|
||||
"description": "Oth fx upr end unsp rad, 7thJ",
|
||||
"price": 131,
|
||||
"stock": 50,
|
||||
"category": "Sweet Pea Sprouts",
|
||||
"order_counts": 11,
|
||||
"created_at": "2023-04-09T04:41:43Z",
|
||||
"rating": 4.05,
|
||||
"rating_count": 24,
|
||||
"sku": "HDS"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"name": "Chips - Miss Vickies",
|
||||
"description": "Contusion of right hip, initial encounter",
|
||||
"price": 52,
|
||||
"stock": 63,
|
||||
"category": "Extract - Almond",
|
||||
"order_counts": 62,
|
||||
"created_at": "2022-06-24T05:25:56Z",
|
||||
"rating": 3.35,
|
||||
"rating_count": 6,
|
||||
"sku": "MACQW"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"name": "Ice Cream - Super Sandwich",
|
||||
"description": "Acute post-traumatic headache",
|
||||
"price": 87,
|
||||
"stock": 44,
|
||||
"category": "Bread - Wheat Baguette",
|
||||
"order_counts": 63,
|
||||
"created_at": "2022-07-06T05:37:09Z",
|
||||
"rating": 0.96,
|
||||
"rating_count": 38,
|
||||
"sku": "AA"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"name": "Alize Gold Passion",
|
||||
"description": "War op involving explosion of marine weapons, civilian",
|
||||
"price": 113,
|
||||
"stock": 72,
|
||||
"category": "Lid - Translucent, 3.5 And 6 Oz",
|
||||
"order_counts": 23,
|
||||
"created_at": "2022-07-09T18:19:37Z",
|
||||
"rating": 3.25,
|
||||
"rating_count": 64,
|
||||
"sku": "EVOK"
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"name": "Mushrooms - Honey",
|
||||
"description": "Sltr-haris Type IV physl fx low end l femr, 7thP",
|
||||
"price": 98,
|
||||
"stock": 64,
|
||||
"category": "Lemon Balm - Fresh",
|
||||
"order_counts": 5,
|
||||
"created_at": "2022-08-05T22:14:06Z",
|
||||
"rating": 3.51,
|
||||
"rating_count": 0,
|
||||
"sku": "TDG"
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"name": "Bread Base - Goodhearth",
|
||||
"description": "Unspecified injury of axillary artery",
|
||||
"price": 81,
|
||||
"stock": 56,
|
||||
"category": "Beef - Bones, Marrow",
|
||||
"order_counts": 76,
|
||||
"created_at": "2023-04-22T03:11:41Z",
|
||||
"rating": 4.07,
|
||||
"rating_count": 22,
|
||||
"sku": "GPAC"
|
||||
},
|
||||
{
|
||||
"id": 12,
|
||||
"name": "Veal - Heart",
|
||||
"description": "Laceration without foreign body of left buttock, subs encntr",
|
||||
"price": 93,
|
||||
"stock": 13,
|
||||
"category": "Peach - Fresh",
|
||||
"order_counts": 12,
|
||||
"created_at": "2023-02-18T16:15:16Z",
|
||||
"rating": 2.08,
|
||||
"rating_count": 87,
|
||||
"sku": "PAH"
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"name": "Tomatoes - Grape",
|
||||
"description": "Nondisplaced bicondylar fracture of left tibia",
|
||||
"price": 132,
|
||||
"stock": 13,
|
||||
"category": "Veal - Striploin",
|
||||
"order_counts": 24,
|
||||
"created_at": "2022-06-08T20:49:59Z",
|
||||
"rating": 3.32,
|
||||
"rating_count": 82,
|
||||
"sku": "ENZL"
|
||||
},
|
||||
{
|
||||
"id": 14,
|
||||
"name": "Tomato Paste",
|
||||
"description": "Abrasion of unspecified part of neck, initial encounter",
|
||||
"price": 48,
|
||||
"stock": 24,
|
||||
"category": "Juice - Tomato, 48 Oz",
|
||||
"order_counts": 4,
|
||||
"created_at": "2022-12-03T04:03:52Z",
|
||||
"rating": 4.11,
|
||||
"rating_count": 66,
|
||||
"sku": "LTEA"
|
||||
},
|
||||
{
|
||||
"id": 15,
|
||||
"name": "Cheese - Roquefort Pappillon",
|
||||
"description": "Wedge comprsn fx first thor vertebra, init for opn fx",
|
||||
"price": 15,
|
||||
"stock": 68,
|
||||
"category": "Veal - Insides, Grains",
|
||||
"order_counts": 72,
|
||||
"created_at": "2022-09-22T06:22:33Z",
|
||||
"rating": 1.54,
|
||||
"rating_count": 40,
|
||||
"sku": "AIF"
|
||||
}
|
||||
]
|
102
assets/data/product_order.json
Normal file
@ -0,0 +1,102 @@
|
||||
[
|
||||
{
|
||||
"order_id": "TWT76911",
|
||||
"customer_name": "Robinson",
|
||||
"location": "Lyubokhna",
|
||||
"order_date": "2023-09-17T00:35:06Z",
|
||||
"quantity": 6,
|
||||
"payments": "COD",
|
||||
"price": 336,
|
||||
"status": "New"
|
||||
},
|
||||
{
|
||||
"order_id": "TWT23890",
|
||||
"customer_name": "Claudina",
|
||||
"location": "Maracha",
|
||||
"order_date": "2023-09-11T15:01:04Z",
|
||||
"quantity": 8,
|
||||
"payments": "American Express",
|
||||
"price": 428,
|
||||
"status": "Shopping"
|
||||
},
|
||||
{
|
||||
"order_id": "TWT84616",
|
||||
"customer_name": "Dewain",
|
||||
"location": "Fuji",
|
||||
"order_date": "2023-12-26T02:42:54Z",
|
||||
"quantity": 6,
|
||||
"payments": "Credit Card",
|
||||
"price": 410,
|
||||
"status": "Shopping"
|
||||
},
|
||||
{
|
||||
"order_id": "TWT66711",
|
||||
"customer_name": "Margette",
|
||||
"location": "Chicago",
|
||||
"order_date": "2024-01-09T18:24:04Z",
|
||||
"quantity": 10,
|
||||
"payments": "Paypal",
|
||||
"price": 268,
|
||||
"status": "Pending"
|
||||
},
|
||||
{
|
||||
"order_id": "TWT50711",
|
||||
"customer_name": "Brittany",
|
||||
"location": "Hakha",
|
||||
"order_date": "2023-09-28T14:17:02Z",
|
||||
"quantity": 2,
|
||||
"payments": "Visa Card",
|
||||
"price": 229,
|
||||
"status": "New"
|
||||
},
|
||||
{
|
||||
"order_id": "TWT37588",
|
||||
"customer_name": "Venus",
|
||||
"location": "Sioguí Arriba",
|
||||
"order_date": "2023-10-16T18:22:32Z",
|
||||
"quantity": 5,
|
||||
"payments": "Visa Card",
|
||||
"price": 211,
|
||||
"status": "Delivered"
|
||||
},
|
||||
{
|
||||
"order_id": "TWT36092",
|
||||
"customer_name": "Norry",
|
||||
"location": "Hongqi",
|
||||
"order_date": "2024-01-28T16:50:34Z",
|
||||
"quantity": 7,
|
||||
"payments": "American Express",
|
||||
"price": 111,
|
||||
"status": "Shopping"
|
||||
},
|
||||
{
|
||||
"order_id": "TWT99659",
|
||||
"customer_name": "Rabbi",
|
||||
"location": "Macari",
|
||||
"order_date": "2023-03-27T17:42:51Z",
|
||||
"quantity": 9,
|
||||
"payments": "COD",
|
||||
"price": 268,
|
||||
"status": "Pending"
|
||||
},
|
||||
{
|
||||
"order_id": "TWT21952",
|
||||
"customer_name": "Hesther",
|
||||
"location": "København",
|
||||
"order_date": "2024-02-08T00:16:01Z",
|
||||
"quantity": 9,
|
||||
"payments": "Credit Card",
|
||||
"price": 392,
|
||||
"status": "Delivered"
|
||||
},
|
||||
{
|
||||
"order_id": "TWT66885",
|
||||
"customer_name": "Sioux",
|
||||
"location": "Taohua",
|
||||
"order_date": "2023-10-23T16:25:29Z",
|
||||
"quantity": 1,
|
||||
"payments": "Paypal",
|
||||
"price": 337,
|
||||
"status": "New"
|
||||
}
|
||||
]
|
82
assets/data/project_summary.json
Normal file
@ -0,0 +1,82 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"title": "Marketing Manager",
|
||||
"assign_to": "Hercules",
|
||||
"date": "2024-03-10T00:14:27Z",
|
||||
"priority": "High",
|
||||
"status": "Pending"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "Community Outreach Specialist",
|
||||
"assign_to": "Fayre",
|
||||
"date": "2024-10-07T06:24:18Z",
|
||||
"priority": "High",
|
||||
"status": "Pending"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"title": "Senior Quality Engineer",
|
||||
"assign_to": "Nancy",
|
||||
"date": "2024-01-11T18:22:29Z",
|
||||
"priority": "Medium",
|
||||
"status": "In Progress"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "VP Sales",
|
||||
"assign_to": "Jemimah",
|
||||
"date": "2024-06-17T17:57:40Z",
|
||||
"priority": "Low",
|
||||
"status": "Finished"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"title": "Sales Associate",
|
||||
"assign_to": "Raquel",
|
||||
"date": "2024-05-06T11:11:43Z",
|
||||
"priority": "Medium",
|
||||
"status": "Finished"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"title": "Dental Hygienist",
|
||||
"assign_to": "Vasili",
|
||||
"date": "2024-05-31T21:16:27Z",
|
||||
"priority": "High",
|
||||
"status": "Finished"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"title": "Occupational Therapist",
|
||||
"assign_to": "Lulu",
|
||||
"date": "2024-03-28T21:07:00Z",
|
||||
"priority": "Medium",
|
||||
"status": "Pending"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"title": "Analyst Programmer",
|
||||
"assign_to": "Egor",
|
||||
"date": "2023-12-11T08:16:01Z",
|
||||
"priority": "High",
|
||||
"status": "Finished"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"title": "Research Assistant III",
|
||||
"assign_to": "Max",
|
||||
"date": "2024-02-15T21:59:34Z",
|
||||
"priority": "High",
|
||||
"status": "Pending"
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"title": "Developer II",
|
||||
"assign_to": "Kaela",
|
||||
"date": "2024-06-24T07:29:47Z",
|
||||
"priority": "High",
|
||||
"status": "Cancelled"
|
||||
}
|
||||
]
|
47
assets/data/recent_order.json
Normal file
@ -0,0 +1,47 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"product_name": "Theobald",
|
||||
"quantity": 2,
|
||||
"customer": "Theobald Southcott",
|
||||
"status": "Shipped",
|
||||
"price": 361,
|
||||
"order_date": "2023-12-11T23:48:54Z"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"product_name": "Carla",
|
||||
"quantity": 3,
|
||||
"customer": "Carla Grgic",
|
||||
"status": "Pending",
|
||||
"price": 329,
|
||||
"order_date": "2024-05-25T09:37:51Z"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"product_name": "Liana",
|
||||
"quantity": 3,
|
||||
"customer": "Liana Swannell",
|
||||
"status": "Delivery",
|
||||
"price": 120,
|
||||
"order_date": "2024-04-06T19:02:14Z"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"product_name": "Radcliffe",
|
||||
"quantity": 4,
|
||||
"customer": "Radcliffe Venard",
|
||||
"status": "Shipped",
|
||||
"price": 750,
|
||||
"order_date": "2024-10-27T10:44:12Z"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"product_name": "Delmer",
|
||||
"quantity": 3,
|
||||
"customer": "Delmer Vamplew",
|
||||
"status": "Delivery",
|
||||
"price": 469,
|
||||
"order_date": "2024-10-16T15:55:22Z"
|
||||
}
|
||||
]
|
91
assets/data/task_list.json
Normal file
@ -0,0 +1,91 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"title": "Finish report",
|
||||
"description": "Complete the quarterly report for the team meeting.",
|
||||
"due_date": "2024-07-14T00:37:09Z",
|
||||
"priority": "High",
|
||||
"status": "Pending"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "Team meeting",
|
||||
"description": "Attend the weekly project meeting and provide updates.",
|
||||
"due_date": "2024-04-18T01:25:27Z",
|
||||
"priority": "Medium",
|
||||
"status": "Completed"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"title": "Buy groceries",
|
||||
"description": "Purchase ingredients for dinner and weekly supplies.",
|
||||
"due_date": "2024-02-17T16:32:03Z",
|
||||
"priority": "Low",
|
||||
"status": "Pending"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "Update website",
|
||||
"description": "Update the homepage with new content and images.",
|
||||
"due_date": "2024-07-16T15:49:59Z",
|
||||
"priority": "Medium",
|
||||
"status": "Pending"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"title": "Send emails",
|
||||
"description": "Send out follow-up emails to clients from last week's meeting.",
|
||||
"due_date": "2024-09-24T11:08:14Z",
|
||||
"priority": "High",
|
||||
"status": "Completed"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"title": "Organize workspace",
|
||||
"description": "Declutter desk and organize office supplies.",
|
||||
"due_date": "2024-10-06T11:49:14Z",
|
||||
"priority": "Low",
|
||||
"status": "Pending"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"title": "Prepare presentation",
|
||||
"description": "Create slides for next week's client pitch.",
|
||||
"due_date": "2024-05-20T04:38:51Z",
|
||||
"priority": "High",
|
||||
"status": "In Progress"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"title": "Write blog post",
|
||||
"description": "Write a blog post about industry trends for the company website.",
|
||||
"due_date": "2024-01-13T07:46:34Z",
|
||||
"priority": "Medium",
|
||||
"status": "Pending"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"title": "Schedule doctor's appointment",
|
||||
"description": "Call and book a check-up appointment with the doctor.",
|
||||
"due_date": "2024-09-22T10:54:21Z",
|
||||
"priority": "Low",
|
||||
"status": "Pending"
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"title": "Review budget",
|
||||
"description": "Review and adjust monthly budget for expenses.",
|
||||
"due_date": "2024-08-20T03:57:48Z",
|
||||
"priority": "Medium",
|
||||
"status": "Pending"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
62
assets/data/time_line.json
Normal file
@ -0,0 +1,62 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"first_name": "Roobbie",
|
||||
"last_name": "Ivashintsov",
|
||||
"email": "rivashintsov0@symantec.com"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"first_name": "Cissy",
|
||||
"last_name": "Salmons",
|
||||
"email": "csalmons1@unicef.org"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"first_name": "Jillene",
|
||||
"last_name": "Besnardeau",
|
||||
"email": "jbesnardeau2@china.com.cn"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"first_name": "Catriona",
|
||||
"last_name": "Wrennall",
|
||||
"email": "cwrennall3@godaddy.com"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"first_name": "Risa",
|
||||
"last_name": "Rumens",
|
||||
"email": "rrumens4@un.org"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"first_name": "Gianina",
|
||||
"last_name": "Pavlenkov",
|
||||
"email": "gpavlenkov5@ted.com"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"first_name": "Tripp",
|
||||
"last_name": "Blowick",
|
||||
"email": "tblowick6@reuters.com"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"first_name": "Ephrem",
|
||||
"last_name": "Pfertner",
|
||||
"email": "epfertner7@godaddy.com"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"first_name": "Jacinda",
|
||||
"last_name": "Tomkies",
|
||||
"email": "jtomkies8@si.edu"
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"first_name": "Traver",
|
||||
"last_name": "Poile",
|
||||
"email": "tpoile9@phoca.cz"
|
||||
}
|
||||
]
|
56
assets/data/visitors_by_channels_data.json
Normal file
@ -0,0 +1,56 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"session_duration": "2023-08-18T14:47:41Z",
|
||||
"channel": "Organic Search",
|
||||
"session": 547,
|
||||
"bounce_rate": 27.2,
|
||||
"target_reached": 843,
|
||||
"page_per_session": 4.4
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"session_duration": "2023-04-20T20:13:24Z",
|
||||
"channel": "Direct",
|
||||
"session": 855,
|
||||
"bounce_rate": 25.8,
|
||||
"target_reached": 998,
|
||||
"page_per_session": 6.6
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"session_duration": "2023-09-05T02:15:03Z",
|
||||
"channel": "Referral",
|
||||
"session": 337,
|
||||
"bounce_rate": 12.4,
|
||||
"target_reached": 509,
|
||||
"page_per_session": 8.0
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"session_duration": "2023-06-23T13:50:55Z",
|
||||
"channel": "Social",
|
||||
"session": 279,
|
||||
"bounce_rate": 40.4,
|
||||
"target_reached": 860,
|
||||
"page_per_session": 7.3
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"session_duration": "2023-09-14T09:01:34Z",
|
||||
"channel": "Email",
|
||||
"session": 118,
|
||||
"bounce_rate": 46.2,
|
||||
"target_reached": 168,
|
||||
"page_per_session": 3.0
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"session_duration": "2023-07-14T01:46:51Z",
|
||||
"channel": "Paid Search",
|
||||
"session": 205,
|
||||
"bounce_rate": 32.8,
|
||||
"target_reached": 583,
|
||||
"page_per_session": 2.5
|
||||
}
|
||||
]
|
42679
assets/data/world_map.json
Normal file
BIN
assets/dummy/dummy_1.jpg
Normal file
After Width: | Height: | Size: 117 KiB |
BIN
assets/dummy/dummy_2.jpg
Normal file
After Width: | Height: | Size: 146 KiB |
BIN
assets/dummy/dummy_3.jpg
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
assets/dummy/dummy_4.jpg
Normal file
After Width: | Height: | Size: 179 KiB |
BIN
assets/dummy/dummy_5.jpg
Normal file
After Width: | Height: | Size: 152 KiB |
BIN
assets/dummy/ecommerce/product_1.jpg
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
assets/dummy/ecommerce/product_10.jpg
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
assets/dummy/ecommerce/product_2.jpg
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
assets/dummy/ecommerce/product_3.jpg
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
assets/dummy/ecommerce/product_4.jpg
Normal file
After Width: | Height: | Size: 9.3 KiB |
BIN
assets/dummy/ecommerce/product_5.jpg
Normal file
After Width: | Height: | Size: 35 KiB |
BIN
assets/dummy/ecommerce/product_6.jpg
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
assets/dummy/ecommerce/product_7.jpg
Normal file
After Width: | Height: | Size: 45 KiB |
BIN
assets/dummy/ecommerce/product_8.jpg
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
assets/dummy/ecommerce/product_9.jpg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
assets/dummy/single_product/single_product_1.png
Normal file
After Width: | Height: | Size: 277 KiB |
BIN
assets/dummy/single_product/single_product_2.png
Normal file
After Width: | Height: | Size: 341 KiB |
BIN
assets/dummy/single_product/single_product_3.png
Normal file
After Width: | Height: | Size: 396 KiB |
BIN
assets/dummy/single_product/single_product_4.png
Normal file
After Width: | Height: | Size: 316 KiB |
BIN
assets/dummy/single_product/single_product_5.png
Normal file
After Width: | Height: | Size: 375 KiB |
BIN
assets/dummy/single_product/single_product_6.png
Normal file
After Width: | Height: | Size: 380 KiB |
@ -1,13 +0,0 @@
|
||||
{
|
||||
"type": "service_account",
|
||||
"project_id": "mtest-a0635",
|
||||
"private_key_id": "39a69f7d2a64234784e0d0ce6c113052296d6dc1",
|
||||
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCimbxktO7PeQ4h\n81Ye2ZBcZjltDhqqD0o9XyLmNdHszzM056bwpJkvgoyyTJAIvR2fcBF3YQFyuC+1\nddLHtchP48FjflZ+zZzLp7oaA/Zh28OZLbCsu+Nm8vO3WJVoIaJYgi+jEz21G128\ncOIbgkKIpLMz1wQhPPOwDTuSdQ+WajWJb04/aNrmTRH1hMreyhHiIFmalcavUgc1\nY5FvgrGs7EaKjYBevoFN3dwmEXjfyHjfBSxnt1yytl9tbtINqdrYLYAMm1l3+KqO\nCGxicQE5kjI1osI2wRjsk105RHnpxPg2GZnI4vTIOkEY5czhRSOs94g2d628H6fq\nVzf9UqwtAgMBAAECggEARluLf3AjHbdd/CbVDwhJRRIeqye9NfTjxOaTrVWAfp2x\npKTQQbSXbE1rIAOtF3rthH3zsNpSzBcS3cwb5rqr8JW2qpySRNAnlp//ER7Bz9pO\nKsvwdO3gGj3qY117WNGk8/NxNXkv7FvpFY8q54hXzdSmjjnt2YwMThOLwXXRxt2B\nFxN3FpBWqw12epqS162nW2nIRJ34Jloil4J5x61Sc79MCFyCxyhMlrBkY+Ni/xb1\nigBXBjczxNiJqqDie0mc16WB1HMEcBP9Yjtb46Hhfs3NDDWNqDkoM8QmEMSg8EHy\nyjcSlf0Wj8I9Kf+0PZo+2FB2DbuhfA8IVR9U/c00KQKBgQDd/OULx6QpmUev1Gl/\nrwwN67ZUMJ72cRuwvLFsMTIzZ+oItO0AR1uMkRZ1crOMc490XNUvSCGP6piZQAn1\nro8qNAh+0Q/UvKHM1khOj/4DxEGZRnNOhe6QLZM9QNygENuEYfdYDD9wcQI9Xs+B\nMIOBsuuqUVHlsbvYkeYNS8M8swKBgQC7g3i1dYRC/bkNMthVS4GTlFRuLscyIjTi\nhruhdaSE+fBZ5RO3XDzz6oDHYcdo/z5ySqI7EIsckNRbwFsMCOjSP3xJapadPYwU\nIhZBU7lgNlPnHJ/BIUwA5JZqRqGTNWrFINUHZFp2RK/x2bYdfoqY8bq08eWs9gmR\nc7U7i+6jnwKBgGaO3isxExD89fewBQWuk70it1vyEp785rQimT3JBM5nJeLb49sL\nHKq2pU+hrH4pLY+vC/cKNidNVS8IPRG6kf4HiB0+7Td15rLCFSnmsI6A72Wm/MK8\ncdk+lRXpj4SMBT8GG8Yb8ns6WrSLxwaCqV8UkHhhlZqvIIAP998Qr6StAoGAQTwr\n8nU/3k6G4qCdwo7SNZWVCgAcLMTZwTU+cZ2L7vdFNwELKu9cBT/ALZ1G0rB5+Skd\n546J1xZLyt/QzQ8McJjFlIUQgQO4iAiT1YZbJ62+4tiCe54p4uWjrrWD4MLkslAJ\nzNiM4DhlPa6QPRKZBTyTx/+f99xg18l5c43rJ+ECgYBkXMfjdn8SOaG6ggJrf1xx\nas49vwAscx4AJaOdVu3D8lCwoNCuAJhBHcFqsJ0wEHWpsqKAdXxqX/Nt2x8t7zL0\nPoRCvfsq5P7GdRrNhrHxLwjDqh+OS+Ow6t0esPQ5RPBgtjvthAlb7bV2nIfkpmdl\nFbjML8vkXk9iPJsbAfO2jw==\n-----END PRIVATE KEY-----\n",
|
||||
"client_email": "firebase-adminsdk-fbsvc@mtest-a0635.iam.gserviceaccount.com",
|
||||
"client_id": "111097905744982732087",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://oauth2.googleapis.com/token",
|
||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-fbsvc%40mtest-a0635.iam.gserviceaccount.com",
|
||||
"universe_domain": "googleapis.com"
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ===============================
|
||||
# Flutter APK Build Script (AAB Disabled)
|
||||
# ===============================
|
||||
|
||||
# Exit immediately if a command exits with a non-zero status
|
||||
set -e
|
||||
|
||||
# Colors for pretty output
|
||||
GREEN='\033[0;32m'
|
||||
CYAN='\033[0;36m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# App info
|
||||
APP_NAME="Marco"
|
||||
BUILD_DIR="build/app/outputs"
|
||||
|
||||
echo -e "${CYAN}🚀 Starting Flutter build script for $APP_NAME...${NC}"
|
||||
|
||||
# Step 1: Clean previous builds
|
||||
echo -e "${YELLOW}🧹 Cleaning previous builds...${NC}"
|
||||
flutter clean
|
||||
|
||||
# Step 2: Get dependencies
|
||||
echo -e "${YELLOW}📦 Fetching dependencies...${NC}"
|
||||
flutter pub get
|
||||
|
||||
# ==============================
|
||||
# Step 3: Build AAB (Commented)
|
||||
# ==============================
|
||||
# echo -e "${CYAN}🏗 Building AAB file...${NC}"
|
||||
# flutter build appbundle --release
|
||||
|
||||
# Step 4: Build APK
|
||||
echo -e "${CYAN}🏗 Building APK file...${NC}"
|
||||
flutter build apk --release
|
||||
|
||||
# Step 5: Show output paths
|
||||
# AAB_PATH="$BUILD_DIR/bundle/release/app-release.aab"
|
||||
APK_PATH="$BUILD_DIR/apk/release/app-release.apk"
|
||||
|
||||
echo -e "${GREEN}✅ Build completed successfully!${NC}"
|
||||
# echo -e "${YELLOW}📍 AAB file: ${CYAN}$AAB_PATH${NC}"
|
||||
echo -e "${YELLOW}📍 APK file: ${CYAN}$APK_PATH${NC}"
|
||||
|
||||
# Optional: open the folder (Mac/Linux)
|
||||
if command -v xdg-open &> /dev/null
|
||||
then
|
||||
xdg-open "$BUILD_DIR"
|
||||
elif command -v open &> /dev/null
|
||||
then
|
||||
open "$BUILD_DIR"
|
||||
fi
|
@ -368,7 +368,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.marco.aiot;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.marco;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
SWIFT_VERSION = 5.0;
|
||||
@ -384,7 +384,7 @@
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.marco.aiot.RunnerTests;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.marco.RunnerTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
@ -401,7 +401,7 @@
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.marco.aiot.RunnerTests;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.marco.RunnerTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 5.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
||||
@ -416,7 +416,7 @@
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.marco.aiot.RunnerTests;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.marco.RunnerTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 5.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
||||
@ -547,7 +547,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.marco.aiot;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.marco;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
@ -569,7 +569,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.marco.aiot;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.marco;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
SWIFT_VERSION = 5.0;
|
||||
|
@ -1,426 +0,0 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/widgets/my_image_compressor.dart';
|
||||
|
||||
import 'package:marco/model/attendance/attendance_model.dart';
|
||||
import 'package:marco/model/project_model.dart';
|
||||
import 'package:marco/model/employees/employee_model.dart';
|
||||
import 'package:marco/model/attendance/attendance_log_model.dart';
|
||||
import 'package:marco/model/regularization_log_model.dart';
|
||||
import 'package:marco/model/attendance/attendance_log_view_model.dart';
|
||||
import 'package:marco/model/attendance/organization_per_project_list_model.dart';
|
||||
import 'package:marco/controller/project_controller.dart';
|
||||
|
||||
class AttendanceController extends GetxController {
|
||||
// Data models
|
||||
List<AttendanceModel> attendances = [];
|
||||
List<ProjectModel> projects = [];
|
||||
List<EmployeeModel> employees = [];
|
||||
List<AttendanceLogModel> attendanceLogs = [];
|
||||
List<RegularizationLogModel> regularizationLogs = [];
|
||||
List<AttendanceLogViewModel> attendenceLogsView = [];
|
||||
// ------------------ Organizations ------------------
|
||||
List<Organization> organizations = [];
|
||||
Organization? selectedOrganization;
|
||||
final isLoadingOrganizations = false.obs;
|
||||
|
||||
// States
|
||||
String selectedTab = 'todaysAttendance';
|
||||
DateTime? startDateAttendance;
|
||||
DateTime? endDateAttendance;
|
||||
|
||||
final isLoading = true.obs;
|
||||
final isLoadingProjects = true.obs;
|
||||
final isLoadingEmployees = true.obs;
|
||||
final isLoadingAttendanceLogs = true.obs;
|
||||
final isLoadingRegularizationLogs = true.obs;
|
||||
final isLoadingLogView = true.obs;
|
||||
final uploadingStates = <String, RxBool>{}.obs;
|
||||
var showPendingOnly = false.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
_initializeDefaults();
|
||||
|
||||
// 🔹 Fetch organizations for the selected project
|
||||
final projectId = Get.find<ProjectController>().selectedProject?.id;
|
||||
if (projectId != null) {
|
||||
fetchOrganizations(projectId);
|
||||
}
|
||||
}
|
||||
|
||||
void _initializeDefaults() {
|
||||
_setDefaultDateRange();
|
||||
}
|
||||
|
||||
void _setDefaultDateRange() {
|
||||
final today = DateTime.now();
|
||||
startDateAttendance = today.subtract(const Duration(days: 7));
|
||||
endDateAttendance = today.subtract(const Duration(days: 1));
|
||||
logSafe(
|
||||
"Default date range set: $startDateAttendance to $endDateAttendance");
|
||||
}
|
||||
|
||||
// ------------------ Project & Employee ------------------
|
||||
/// Called when a notification says attendance has been updated
|
||||
Future<void> refreshDataFromNotification({String? projectId}) async {
|
||||
projectId ??= Get.find<ProjectController>().selectedProject?.id;
|
||||
if (projectId == null) {
|
||||
logSafe("No project selected for attendance refresh from notification",
|
||||
level: LogLevel.warning);
|
||||
return;
|
||||
}
|
||||
await fetchProjectData(projectId);
|
||||
logSafe(
|
||||
"Attendance data refreshed from notification for project $projectId");
|
||||
}
|
||||
|
||||
// 🔍 Search query
|
||||
final searchQuery = ''.obs;
|
||||
|
||||
// Computed filtered employees
|
||||
List<EmployeeModel> get filteredEmployees {
|
||||
if (searchQuery.value.isEmpty) return employees;
|
||||
return employees
|
||||
.where((e) =>
|
||||
e.name.toLowerCase().contains(searchQuery.value.toLowerCase()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
// Computed filtered logs
|
||||
List<AttendanceLogModel> get filteredLogs {
|
||||
if (searchQuery.value.isEmpty) return attendanceLogs;
|
||||
return attendanceLogs
|
||||
.where((log) =>
|
||||
(log.name).toLowerCase().contains(searchQuery.value.toLowerCase()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
// Computed filtered regularization logs
|
||||
List<RegularizationLogModel> get filteredRegularizationLogs {
|
||||
if (searchQuery.value.isEmpty) return regularizationLogs;
|
||||
return regularizationLogs
|
||||
.where((log) =>
|
||||
log.name.toLowerCase().contains(searchQuery.value.toLowerCase()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<void> fetchTodaysAttendance(String? projectId) async {
|
||||
if (projectId == null) return;
|
||||
|
||||
isLoadingEmployees.value = true;
|
||||
|
||||
final response = await ApiService.getTodaysAttendance(
|
||||
projectId,
|
||||
organizationId: selectedOrganization?.id,
|
||||
);
|
||||
if (response != null) {
|
||||
employees = response.map((e) => EmployeeModel.fromJson(e)).toList();
|
||||
for (var emp in employees) {
|
||||
uploadingStates[emp.id] = false.obs;
|
||||
}
|
||||
logSafe("Employees fetched: ${employees.length} for project $projectId");
|
||||
} else {
|
||||
logSafe("Failed to fetch employees for project $projectId",
|
||||
level: LogLevel.error);
|
||||
}
|
||||
isLoadingEmployees.value = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> fetchOrganizations(String projectId) async {
|
||||
isLoadingOrganizations.value = true;
|
||||
final response = await ApiService.getAssignedOrganizations(projectId);
|
||||
if (response != null) {
|
||||
organizations = response.data;
|
||||
logSafe("Organizations fetched: ${organizations.length}");
|
||||
} else {
|
||||
logSafe("Failed to fetch organizations for project $projectId",
|
||||
level: LogLevel.error);
|
||||
}
|
||||
isLoadingOrganizations.value = false;
|
||||
update();
|
||||
}
|
||||
|
||||
// ------------------ Attendance Capture ------------------
|
||||
|
||||
Future<bool> captureAndUploadAttendance(
|
||||
String id,
|
||||
String employeeId,
|
||||
String projectId, {
|
||||
String comment = "Marked via mobile app",
|
||||
required int action,
|
||||
bool imageCapture = true,
|
||||
String? markTime, // still optional in controller
|
||||
String? date, // new optional param
|
||||
}) async {
|
||||
try {
|
||||
uploadingStates[employeeId]?.value = true;
|
||||
|
||||
XFile? image;
|
||||
if (imageCapture) {
|
||||
image = await ImagePicker()
|
||||
.pickImage(source: ImageSource.camera, imageQuality: 80);
|
||||
if (image == null) {
|
||||
logSafe("Image capture cancelled.", level: LogLevel.warning);
|
||||
return false;
|
||||
}
|
||||
|
||||
final compressedBytes =
|
||||
await compressImageToUnder100KB(File(image.path));
|
||||
if (compressedBytes == null) {
|
||||
logSafe("Image compression failed.", level: LogLevel.error);
|
||||
return false;
|
||||
}
|
||||
|
||||
final compressedFile = await saveCompressedImageToFile(compressedBytes);
|
||||
image = XFile(compressedFile.path);
|
||||
}
|
||||
|
||||
if (!await _handleLocationPermission()) return false;
|
||||
final position = await Geolocator.getCurrentPosition(
|
||||
desiredAccuracy: LocationAccuracy.high);
|
||||
|
||||
final imageName = imageCapture
|
||||
? 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,
|
||||
image,
|
||||
position.latitude,
|
||||
position.longitude,
|
||||
imageName: imageName,
|
||||
projectId: projectId,
|
||||
comment: comment,
|
||||
action: action,
|
||||
imageCapture: imageCapture,
|
||||
markTime: formattedMarkTime,
|
||||
date: formattedDate,
|
||||
);
|
||||
|
||||
logSafe(
|
||||
"Attendance uploaded for $employeeId, action: $action, date: $formattedDate");
|
||||
return result;
|
||||
} catch (e, stacktrace) {
|
||||
logSafe("Error uploading attendance",
|
||||
level: LogLevel.error, error: e, stackTrace: stacktrace);
|
||||
return false;
|
||||
} finally {
|
||||
uploadingStates[employeeId]?.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _handleLocationPermission() async {
|
||||
LocationPermission permission = await Geolocator.checkPermission();
|
||||
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
logSafe('Location permissions are denied', level: LogLevel.warning);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (permission == LocationPermission.deniedForever) {
|
||||
logSafe('Location permissions are permanently denied',
|
||||
level: LogLevel.error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------ Attendance Logs ------------------
|
||||
|
||||
Future<void> fetchAttendanceLogs(String? projectId,
|
||||
{DateTime? dateFrom, DateTime? dateTo}) async {
|
||||
if (projectId == null) return;
|
||||
|
||||
isLoadingAttendanceLogs.value = true;
|
||||
|
||||
final response = await ApiService.getAttendanceLogs(
|
||||
projectId,
|
||||
dateFrom: dateFrom,
|
||||
dateTo: dateTo,
|
||||
organizationId: selectedOrganization?.id,
|
||||
);
|
||||
if (response != null) {
|
||||
attendanceLogs =
|
||||
response.map((e) => AttendanceLogModel.fromJson(e)).toList();
|
||||
logSafe("Attendance logs fetched: ${attendanceLogs.length}");
|
||||
} else {
|
||||
logSafe("Failed to fetch attendance logs for project $projectId",
|
||||
level: LogLevel.error);
|
||||
}
|
||||
|
||||
isLoadingAttendanceLogs.value = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Map<String, List<AttendanceLogModel>> groupLogsByCheckInDate() {
|
||||
final groupedLogs = <String, List<AttendanceLogModel>>{};
|
||||
|
||||
for (var logItem in attendanceLogs) {
|
||||
final checkInDate = logItem.checkIn != null
|
||||
? DateFormat('dd MMM yyyy').format(logItem.checkIn!)
|
||||
: 'Unknown';
|
||||
groupedLogs.putIfAbsent(checkInDate, () => []).add(logItem);
|
||||
}
|
||||
|
||||
final sortedEntries = groupedLogs.entries.toList()
|
||||
..sort((a, b) {
|
||||
if (a.key == 'Unknown') return 1;
|
||||
if (b.key == 'Unknown') return -1;
|
||||
final dateA = DateFormat('dd MMM yyyy').parse(a.key);
|
||||
final dateB = DateFormat('dd MMM yyyy').parse(b.key);
|
||||
return dateB.compareTo(dateA);
|
||||
});
|
||||
|
||||
return Map<String, List<AttendanceLogModel>>.fromEntries(sortedEntries);
|
||||
}
|
||||
|
||||
// ------------------ Regularization Logs ------------------
|
||||
|
||||
Future<void> fetchRegularizationLogs(String? projectId) async {
|
||||
if (projectId == null) return;
|
||||
|
||||
isLoadingRegularizationLogs.value = true;
|
||||
|
||||
final response = await ApiService.getRegularizationLogs(
|
||||
projectId,
|
||||
organizationId: selectedOrganization?.id,
|
||||
);
|
||||
if (response != null) {
|
||||
regularizationLogs =
|
||||
response.map((e) => RegularizationLogModel.fromJson(e)).toList();
|
||||
logSafe("Regularization logs fetched: ${regularizationLogs.length}");
|
||||
} else {
|
||||
logSafe("Failed to fetch regularization logs for project $projectId",
|
||||
level: LogLevel.error);
|
||||
}
|
||||
|
||||
isLoadingRegularizationLogs.value = false;
|
||||
update();
|
||||
}
|
||||
|
||||
// ------------------ Attendance Log View ------------------
|
||||
|
||||
Future<void> fetchLogsView(String? id) async {
|
||||
if (id == null) return;
|
||||
|
||||
isLoadingLogView.value = true;
|
||||
|
||||
final response = await ApiService.getAttendanceLogView(id);
|
||||
if (response != null) {
|
||||
attendenceLogsView =
|
||||
response.map((e) => AttendanceLogViewModel.fromJson(e)).toList();
|
||||
attendenceLogsView.sort((a, b) => (b.activityTime ?? DateTime(2000))
|
||||
.compareTo(a.activityTime ?? DateTime(2000)));
|
||||
logSafe("Attendance log view fetched for ID: $id");
|
||||
} else {
|
||||
logSafe("Failed to fetch attendance log view for ID $id",
|
||||
level: LogLevel.error);
|
||||
}
|
||||
|
||||
isLoadingLogView.value = false;
|
||||
update();
|
||||
}
|
||||
|
||||
// ------------------ Combined Load ------------------
|
||||
|
||||
Future<void> loadAttendanceData(String projectId) async {
|
||||
isLoading.value = true;
|
||||
await fetchProjectData(projectId);
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
||||
Future<void> fetchProjectData(String? projectId) async {
|
||||
if (projectId == null) return;
|
||||
|
||||
await fetchOrganizations(projectId);
|
||||
|
||||
// Call APIs depending on the selected tab only
|
||||
switch (selectedTab) {
|
||||
case 'todaysAttendance':
|
||||
await fetchTodaysAttendance(projectId);
|
||||
break;
|
||||
case 'attendanceLogs':
|
||||
await fetchAttendanceLogs(
|
||||
projectId,
|
||||
dateFrom: startDateAttendance,
|
||||
dateTo: endDateAttendance,
|
||||
);
|
||||
break;
|
||||
case 'regularizationRequests':
|
||||
await fetchRegularizationLogs(projectId);
|
||||
break;
|
||||
}
|
||||
|
||||
logSafe(
|
||||
"Project data fetched for project ID: $projectId, tab: $selectedTab");
|
||||
update();
|
||||
}
|
||||
|
||||
// ------------------ UI Interaction ------------------
|
||||
|
||||
Future<void> selectDateRangeForAttendance(
|
||||
BuildContext context, AttendanceController controller) async {
|
||||
final today = DateTime.now();
|
||||
|
||||
final picked = await showDateRangePicker(
|
||||
context: context,
|
||||
firstDate: DateTime(2022),
|
||||
lastDate: today.subtract(const Duration(days: 1)),
|
||||
initialDateRange: DateTimeRange(
|
||||
start: startDateAttendance ?? today.subtract(const Duration(days: 7)),
|
||||
end: endDateAttendance ?? today.subtract(const Duration(days: 1)),
|
||||
),
|
||||
);
|
||||
|
||||
if (picked != null) {
|
||||
startDateAttendance = picked.start;
|
||||
endDateAttendance = picked.end;
|
||||
logSafe(
|
||||
"Date range selected: $startDateAttendance to $endDateAttendance");
|
||||
|
||||
await controller.fetchAttendanceLogs(
|
||||
Get.find<ProjectController>().selectedProject?.id,
|
||||
dateFrom: picked.start,
|
||||
dateTo: picked.end,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -5,16 +5,12 @@ import 'package:marco/helpers/services/auth_service.dart';
|
||||
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
||||
import 'package:marco/helpers/widgets/my_validators.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/storage/local_storage.dart';
|
||||
|
||||
class ForgotPasswordController extends MyController {
|
||||
final MyFormValidator basicValidator = MyFormValidator();
|
||||
final RxBool isLoading = false.obs;
|
||||
MyFormValidator basicValidator = MyFormValidator();
|
||||
bool showPassword = false;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
basicValidator.addField(
|
||||
'email',
|
||||
required: true,
|
||||
@ -22,49 +18,49 @@ class ForgotPasswordController extends MyController {
|
||||
validators: [MyEmailValidator()],
|
||||
controller: TextEditingController(text: "demo@example.com"),
|
||||
);
|
||||
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
Future<void> onLogin() async {
|
||||
if (basicValidator.validateForm()) {
|
||||
update();
|
||||
var errors = await AuthService.loginUser(basicValidator.getData());
|
||||
if (errors != null) {
|
||||
basicValidator.validateForm();
|
||||
basicValidator.clearErrors();
|
||||
}
|
||||
Get.toNamed('/auth/reset_password');
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
/// New: Forgot password function
|
||||
Future<void> onForgotPassword() async {
|
||||
if (!basicValidator.validateForm()) return;
|
||||
|
||||
isLoading.value = true;
|
||||
final data = basicValidator.getData();
|
||||
final email = data['email']?.toString() ?? '';
|
||||
|
||||
try {
|
||||
logSafe("Forgot password requested for: $email", );
|
||||
|
||||
if (basicValidator.validateForm()) {
|
||||
update();
|
||||
final data = basicValidator.getData();
|
||||
final email = data['email']?.toString() ?? '';
|
||||
final result = await AuthService.forgotPassword(email);
|
||||
|
||||
if (result == null) {
|
||||
if (result != null) {
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "Password reset link has been sent.",
|
||||
message: "Your password reset link was sent.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
await LocalStorage.logout();
|
||||
} else {
|
||||
final errorMessage = result['error'] ?? "Failed to send reset link. Please try again.";
|
||||
showAppSnackbar(
|
||||
title: "Failed",
|
||||
message: errorMessage,
|
||||
type: SnackbarType.error,
|
||||
title: "Success",
|
||||
message: "Your password reset link was sent.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
logSafe("Failed to send reset password email for $email: $errorMessage", level: LogLevel.warning, );
|
||||
}
|
||||
} catch (e, stacktrace) {
|
||||
logSafe("Error during forgot password", level: LogLevel.error, error: e, stackTrace: stacktrace);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Something went wrong. Please try again later.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void gotoLogIn() {
|
||||
Get.offAllNamed('/auth/login-option');
|
||||
Get.toNamed('/auth/login-option');
|
||||
}
|
||||
}
|
||||
|
@ -6,15 +6,12 @@ import 'package:marco/helpers/widgets/my_form_validator.dart';
|
||||
import 'package:marco/helpers/widgets/my_validators.dart';
|
||||
import 'package:marco/helpers/services/storage/local_storage.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
|
||||
class LoginController extends MyController {
|
||||
final MyFormValidator basicValidator = MyFormValidator();
|
||||
|
||||
final RxBool isLoading = false.obs;
|
||||
final RxBool showPassword = false.obs;
|
||||
final RxBool isChecked = false.obs;
|
||||
final RxBool showSplash = false.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@ -41,46 +38,53 @@ class LoginController extends MyController {
|
||||
);
|
||||
}
|
||||
|
||||
void onChangeCheckBox(bool? value) => isChecked.value = value ?? false;
|
||||
void onChangeCheckBox(bool? value) {
|
||||
isChecked.value = value ?? false;
|
||||
}
|
||||
|
||||
void onChangeShowPassword() => showPassword.toggle();
|
||||
void onChangeShowPassword() {
|
||||
showPassword.toggle();
|
||||
}
|
||||
|
||||
Future<void> onLogin() async {
|
||||
if (!basicValidator.validateForm()) return;
|
||||
|
||||
showSplash.value = true;
|
||||
isLoading.value = true;
|
||||
|
||||
try {
|
||||
final loginData = basicValidator.getData();
|
||||
logSafe("Attempting login for user: ${loginData['username']}");
|
||||
final errors = await AuthService.loginUser(basicValidator.getData());
|
||||
|
||||
final errors = await AuthService.loginUser(loginData);
|
||||
|
||||
if (errors != null) {
|
||||
showAppSnackbar(
|
||||
title: "Login Failed",
|
||||
message: "Username or password is incorrect",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
basicValidator.addErrors(errors);
|
||||
basicValidator.validateForm();
|
||||
basicValidator.clearErrors();
|
||||
} else {
|
||||
await _handleRememberMe();
|
||||
enableRemoteLogging();
|
||||
logSafe("Login successful for user: ${loginData['username']}");
|
||||
Get.offNamed('/select-tenant');
|
||||
}
|
||||
} catch (e, stacktrace) {
|
||||
if (errors != null) {
|
||||
showAppSnackbar(
|
||||
title: "Login Error",
|
||||
message: "An unexpected error occurred",
|
||||
title: "Login Failed",
|
||||
message: "Username or password is incorrect",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
logSafe("Exception during login",
|
||||
level: LogLevel.error, error: e, stackTrace: stacktrace);
|
||||
} finally {
|
||||
showSplash.value = false;
|
||||
|
||||
basicValidator.addErrors(errors);
|
||||
basicValidator.validateForm();
|
||||
basicValidator.clearErrors();
|
||||
} else {
|
||||
await _handleRememberMe();
|
||||
final bool isMpinEnabled = LocalStorage.getIsMpin();
|
||||
print('MPIN Enabled? $isMpinEnabled');
|
||||
|
||||
if (isMpinEnabled) {
|
||||
Get.toNamed('/home');
|
||||
} else {
|
||||
Get.toNamed('/home');
|
||||
}
|
||||
}
|
||||
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
||||
void handlePostLoginNavigation() {
|
||||
final bool isMpinEnabled = LocalStorage.getIsMpin();
|
||||
|
||||
if (isMpinEnabled) {
|
||||
Get.offAllNamed('/home');
|
||||
} else {
|
||||
Get.offAllNamed('/home');
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,7 +99,6 @@ class LoginController extends MyController {
|
||||
await LocalStorage.removeToken('username');
|
||||
await LocalStorage.removeToken('password');
|
||||
await LocalStorage.setBool('remember_me', false);
|
||||
basicValidator.clearErrors();
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,7 +115,12 @@ class LoginController extends MyController {
|
||||
}
|
||||
}
|
||||
|
||||
void goToForgotPassword() => Get.toNamed('/auth/forgot_password');
|
||||
void goToForgotPassword() {
|
||||
Get.toNamed('/auth/forgot_password');
|
||||
}
|
||||
|
||||
void gotoRegister() => Get.offAndToNamed('/auth/register_account');
|
||||
void gotoRegister() {
|
||||
Get.offAndToNamed('/auth/register_account');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,82 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:marco/helpers/services/auth_service.dart';
|
||||
import 'package:marco/helpers/services/storage/local_storage.dart';
|
||||
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/firebase/firebase_messaging_service.dart';
|
||||
import 'package:marco/controller/permission_controller.dart';
|
||||
import 'package:marco/controller/project_controller.dart';
|
||||
import 'package:marco/view/dashboard/dashboard_screen.dart';
|
||||
|
||||
class MPINController extends GetxController {
|
||||
final Logger logger = Logger();
|
||||
|
||||
final MyFormValidator basicValidator = MyFormValidator();
|
||||
final isNewUser = false.obs;
|
||||
final isChangeMpin = false.obs;
|
||||
final RxBool isLoading = false.obs;
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
// Updated to 4-digit MPIN
|
||||
final digitControllers = List.generate(4, (_) => TextEditingController());
|
||||
final focusNodes = List.generate(4, (_) => FocusNode());
|
||||
|
||||
final retypeControllers = List.generate(4, (_) => TextEditingController());
|
||||
final retypeFocusNodes = List.generate(4, (_) => FocusNode());
|
||||
final digitControllers = List.generate(6, (_) => TextEditingController());
|
||||
final focusNodes = List.generate(6, (_) => FocusNode());
|
||||
|
||||
final retypeControllers = List.generate(6, (_) => TextEditingController());
|
||||
final retypeFocusNodes = List.generate(6, (_) => FocusNode());
|
||||
final RxInt failedAttempts = 0.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
final bool hasMpin = LocalStorage.getIsMpin();
|
||||
isNewUser.value = !hasMpin;
|
||||
logSafe("onInit called. isNewUser: ${isNewUser.value}");
|
||||
logger.i("[MPINController] onInit called. isNewUser: ${isNewUser.value}");
|
||||
}
|
||||
|
||||
/// Enable Change MPIN mode
|
||||
void setChangeMpinMode() {
|
||||
isChangeMpin.value = true;
|
||||
isNewUser.value = false;
|
||||
clearFields();
|
||||
clearRetypeFields();
|
||||
logSafe("setChangeMpinMode activated");
|
||||
}
|
||||
|
||||
/// Handle digit entry and focus movement
|
||||
void onDigitChanged(String value, int index, {bool isRetype = false}) {
|
||||
logSafe(
|
||||
"onDigitChanged -> index: $index, value: $value, isRetype: $isRetype");
|
||||
logger.i(
|
||||
"[MPINController] onDigitChanged -> index: $index, value: $value, isRetype: $isRetype");
|
||||
final nodes = isRetype ? retypeFocusNodes : focusNodes;
|
||||
if (value.isNotEmpty && index < 3) {
|
||||
if (value.isNotEmpty && index < 5) {
|
||||
nodes[index + 1].requestFocus();
|
||||
} else if (value.isEmpty && index > 0) {
|
||||
nodes[index - 1].requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/// Submit MPIN for verification or generation
|
||||
Future<void> onSubmitMPIN() async {
|
||||
logSafe("onSubmitMPIN triggered");
|
||||
logger.i("[MPINController] onSubmitMPIN triggered");
|
||||
|
||||
if (!formKey.currentState!.validate()) {
|
||||
logSafe("Form validation failed", level: LogLevel.warning);
|
||||
logger.w("[MPINController] Form validation failed");
|
||||
return;
|
||||
}
|
||||
|
||||
final enteredMPIN = digitControllers.map((c) => c.text).join();
|
||||
logSafe("Entered MPIN: $enteredMPIN");
|
||||
logger.i("[MPINController] Entered MPIN: $enteredMPIN");
|
||||
|
||||
if (enteredMPIN.length < 4) {
|
||||
_showError("Please enter all 4 digits.");
|
||||
if (enteredMPIN.length < 6) {
|
||||
_showError("Please enter all 6 digits.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNewUser.value || isChangeMpin.value) {
|
||||
if (isNewUser.value) {
|
||||
final retypeMPIN = retypeControllers.map((c) => c.text).join();
|
||||
logSafe("Retyped MPIN: $retypeMPIN");
|
||||
logger.i("[MPINController] Retyped MPIN: $retypeMPIN");
|
||||
|
||||
if (retypeMPIN.length < 4) {
|
||||
_showError("Please enter all 4 digits in Retype MPIN.");
|
||||
if (retypeMPIN.length < 6) {
|
||||
_showError("Please enter all 6 digits in Retype MPIN.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -87,50 +72,44 @@ class MPINController extends GetxController {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.i("[MPINController] MPINs matched. Proceeding to generate MPIN.");
|
||||
final bool success = await generateMPIN(mpin: enteredMPIN);
|
||||
|
||||
if (success) {
|
||||
logSafe("MPIN generation/change successful.");
|
||||
logger.i("[MPINController] MPIN generation successful.");
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: isChangeMpin.value
|
||||
? "MPIN changed successfully."
|
||||
: "MPIN generated successfully. Please login again.",
|
||||
message: "MPIN generated successfully. Please login again.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
await LocalStorage.logout();
|
||||
} else {
|
||||
logSafe("MPIN generation/change failed.", level: LogLevel.warning);
|
||||
logger.w("[MPINController] MPIN generation failed.");
|
||||
clearFields();
|
||||
clearRetypeFields();
|
||||
}
|
||||
} else {
|
||||
logSafe("Existing user. Proceeding to verify MPIN.");
|
||||
logger.i("[MPINController] Existing user. Proceeding to verify MPIN.");
|
||||
await verifyMPIN();
|
||||
}
|
||||
}
|
||||
|
||||
/// Forgot MPIN
|
||||
Future<void> onForgotMPIN() async {
|
||||
logSafe("onForgotMPIN called");
|
||||
logger.i("[MPINController] onForgotMPIN called");
|
||||
isNewUser.value = true;
|
||||
isChangeMpin.value = false;
|
||||
clearFields();
|
||||
clearRetypeFields();
|
||||
}
|
||||
|
||||
/// Switch to login/enter MPIN screen
|
||||
void switchToEnterMPIN() {
|
||||
logSafe("switchToEnterMPIN called");
|
||||
logger.i("[MPINController] switchToEnterMPIN called");
|
||||
isNewUser.value = false;
|
||||
isChangeMpin.value = false;
|
||||
clearFields();
|
||||
clearRetypeFields();
|
||||
}
|
||||
|
||||
/// Show error snackbar
|
||||
void _showError(String message) {
|
||||
logSafe("ERROR: $message", level: LogLevel.error);
|
||||
logger.e("[MPINController] ERROR: $message");
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: message,
|
||||
@ -138,42 +117,38 @@ class MPINController extends GetxController {
|
||||
);
|
||||
}
|
||||
|
||||
/// Navigate to dashboard
|
||||
/// Navigate to tenant selection after MPIN verification
|
||||
void _navigateToTenantSelection({String? message}) {
|
||||
void _navigateToDashboard({String? message}) {
|
||||
if (message != null) {
|
||||
logSafe("Navigating to Tenant Selection with message: $message");
|
||||
logger
|
||||
.i("[MPINController] Navigating to Dashboard with message: $message");
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: message,
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
}
|
||||
Get.offAllNamed('/select-tenant');
|
||||
Get.offAll(() => const DashboardScreen());
|
||||
}
|
||||
|
||||
/// Clear the primary MPIN fields
|
||||
void clearFields() {
|
||||
logSafe("clearFields called");
|
||||
logger.i("[MPINController] clearFields called");
|
||||
for (final c in digitControllers) {
|
||||
c.clear();
|
||||
}
|
||||
focusNodes.first.requestFocus();
|
||||
}
|
||||
|
||||
/// Clear the retype MPIN fields
|
||||
void clearRetypeFields() {
|
||||
logSafe("clearRetypeFields called");
|
||||
logger.i("[MPINController] clearRetypeFields called");
|
||||
for (final c in retypeControllers) {
|
||||
c.clear();
|
||||
}
|
||||
retypeFocusNodes.first.requestFocus();
|
||||
}
|
||||
|
||||
/// Cleanup
|
||||
@override
|
||||
void onClose() {
|
||||
logSafe("onClose called");
|
||||
logger.i("[MPINController] onClose called");
|
||||
for (final controller in digitControllers) {
|
||||
controller.dispose();
|
||||
}
|
||||
@ -189,11 +164,12 @@ class MPINController extends GetxController {
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
/// Generate MPIN for new user/change MPIN
|
||||
Future<bool> generateMPIN({required String mpin}) async {
|
||||
Future<bool> generateMPIN({
|
||||
required String mpin,
|
||||
}) async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
logSafe("generateMPIN started");
|
||||
logger.i("[MPINController] generateMPIN started for MPIN: $mpin");
|
||||
|
||||
final employeeInfo = LocalStorage.getEmployeeInfo();
|
||||
final String? employeeId = employeeInfo?.id;
|
||||
@ -204,7 +180,8 @@ class MPINController extends GetxController {
|
||||
return false;
|
||||
}
|
||||
|
||||
logSafe("Calling AuthService.generateMpin for employeeId: $employeeId");
|
||||
logger.i(
|
||||
"[MPINController] Calling AuthService.generateMpin for employeeId: $employeeId");
|
||||
|
||||
final response = await AuthService.generateMpin(
|
||||
employeeId: employeeId,
|
||||
@ -214,12 +191,22 @@ class MPINController extends GetxController {
|
||||
isLoading.value = false;
|
||||
|
||||
if (response == null) {
|
||||
logger.i("[MPINController] MPIN generated successfully");
|
||||
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "MPIN generated successfully. Please login again.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
|
||||
await LocalStorage.logout();
|
||||
|
||||
return true;
|
||||
} else {
|
||||
logSafe("MPIN generation returned error: $response",
|
||||
level: LogLevel.warning);
|
||||
logger.w(
|
||||
"[MPINController] MPIN generation returned error response: $response");
|
||||
showAppSnackbar(
|
||||
title: "MPIN Operation Failed",
|
||||
title: "MPIN Generation Failed",
|
||||
message: "Please check your inputs.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
@ -230,23 +217,25 @@ class MPINController extends GetxController {
|
||||
}
|
||||
} catch (e) {
|
||||
isLoading.value = false;
|
||||
logSafe("Exception in generateMPIN", level: LogLevel.error, error: e);
|
||||
_showError("Failed to process MPIN.");
|
||||
_showError("Failed to generate MPIN: $e");
|
||||
logger.e("[MPINController] Exception in generateMPIN: $e");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Verify MPIN for existing user
|
||||
Future<void> verifyMPIN() async {
|
||||
logSafe("verifyMPIN triggered");
|
||||
logger.i("[MPINController] verifyMPIN triggered");
|
||||
|
||||
final enteredMPIN = digitControllers.map((c) => c.text).join();
|
||||
if (enteredMPIN.length < 4) {
|
||||
_showError("Please enter all 4 digits.");
|
||||
logger.i("[MPINController] Entered MPIN: $enteredMPIN");
|
||||
|
||||
if (enteredMPIN.length < 6) {
|
||||
_showError("Please enter all 6 digits.");
|
||||
return;
|
||||
}
|
||||
|
||||
final mpinToken = await LocalStorage.getMpinToken();
|
||||
|
||||
if (mpinToken == null || mpinToken.isEmpty) {
|
||||
_showError("Missing MPIN token. Please log in again.");
|
||||
return;
|
||||
@ -255,43 +244,28 @@ class MPINController extends GetxController {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
|
||||
final fcmToken = await FirebaseNotificationService().getFcmToken();
|
||||
|
||||
final response = await AuthService.verifyMpin(
|
||||
mpin: enteredMPIN,
|
||||
mpinToken: mpinToken,
|
||||
fcmToken: fcmToken ?? '',
|
||||
);
|
||||
|
||||
isLoading.value = false;
|
||||
|
||||
if (response == null) {
|
||||
logSafe("MPIN verified successfully");
|
||||
await LocalStorage.setBool('mpin_verified', true);
|
||||
logger.i("[MPINController] MPIN verified successfully.");
|
||||
|
||||
// 🔹 Ensure controllers are injected and loaded
|
||||
final token = await LocalStorage.getJwtToken();
|
||||
if (token != null && token.isNotEmpty) {
|
||||
if (!Get.isRegistered<PermissionController>()) {
|
||||
Get.put(PermissionController());
|
||||
await Get.find<PermissionController>().loadData(token);
|
||||
}
|
||||
if (!Get.isRegistered<ProjectController>()) {
|
||||
Get.put(ProjectController(), permanent: true);
|
||||
await Get.find<ProjectController>().fetchProjects();
|
||||
}
|
||||
}
|
||||
// Set mpin_verified to true in local storage here:
|
||||
await LocalStorage.setBool('mpin_verified', true);
|
||||
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "MPIN Verified Successfully",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
_navigateToTenantSelection();
|
||||
_navigateToDashboard();
|
||||
} else {
|
||||
final errorMessage = response["error"] ?? "Invalid MPIN";
|
||||
logSafe("MPIN verification failed: $errorMessage",
|
||||
level: LogLevel.warning);
|
||||
logger.w("[MPINController] MPIN verification failed: $errorMessage");
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: errorMessage,
|
||||
@ -302,12 +276,16 @@ class MPINController extends GetxController {
|
||||
}
|
||||
} catch (e) {
|
||||
isLoading.value = false;
|
||||
logSafe("Exception in verifyMPIN", level: LogLevel.error, error: e);
|
||||
_showError("Something went wrong. Please try again.");
|
||||
final error = "Failed to verify MPIN: $e";
|
||||
logger.e("[MPINController] Exception in verifyMPIN: $error");
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Something went wrong. Please try again.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Increment failed attempts and warn
|
||||
void onInvalidMPIN() {
|
||||
failedAttempts.value++;
|
||||
if (failedAttempts.value >= 3) {
|
||||
|
@ -4,8 +4,6 @@ import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/helpers/services/auth_service.dart';
|
||||
import 'package:marco/helpers/services/storage/local_storage.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
|
||||
class OTPController extends GetxController {
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
@ -25,8 +23,6 @@ class OTPController extends GetxController {
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
timer.value = 0;
|
||||
_loadSavedEmail();
|
||||
logSafe("[OTPController] Initialized");
|
||||
}
|
||||
|
||||
@override
|
||||
@ -39,22 +35,15 @@ class OTPController extends GetxController {
|
||||
for (final node in focusNodes) {
|
||||
node.dispose();
|
||||
}
|
||||
logSafe("[OTPController] Disposed");
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
Future<bool> _sendOTP(String email) async {
|
||||
logSafe("[OTPController] Sending OTP");
|
||||
final result = await AuthService.generateOtp(email);
|
||||
if (result == null) {
|
||||
logSafe("[OTPController] OTP sent successfully");
|
||||
debugPrint('OTP sent to $email');
|
||||
return true;
|
||||
} else {
|
||||
logSafe(
|
||||
"[OTPController] OTP send failed",
|
||||
level: LogLevel.warning,
|
||||
error: result['error'],
|
||||
);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: result['error'] ?? "Failed to send OTP",
|
||||
@ -66,10 +55,8 @@ class OTPController extends GetxController {
|
||||
|
||||
Future<void> sendOTP() async {
|
||||
final userEmail = emailController.text.trim();
|
||||
logSafe("[OTPController] sendOTP called");
|
||||
|
||||
if (!_validateEmail(userEmail)) {
|
||||
logSafe("[OTPController] Invalid email format", level: LogLevel.warning);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Please enter a valid email address",
|
||||
@ -85,7 +72,6 @@ class OTPController extends GetxController {
|
||||
if (success) {
|
||||
email.value = userEmail;
|
||||
isOTPSent.value = true;
|
||||
await _saveEmailIfRemembered(userEmail);
|
||||
_startTimer();
|
||||
_clearOTPFields();
|
||||
}
|
||||
@ -95,9 +81,8 @@ class OTPController extends GetxController {
|
||||
|
||||
Future<void> onResendOTP() async {
|
||||
if (isResending.value) return;
|
||||
logSafe("[OTPController] Resending OTP");
|
||||
|
||||
isResending.value = true;
|
||||
|
||||
_clearOTPFields();
|
||||
|
||||
final success = await _sendOTP(email.value);
|
||||
@ -109,8 +94,6 @@ class OTPController extends GetxController {
|
||||
}
|
||||
|
||||
void onOTPChanged(String value, int index) {
|
||||
logSafe("[OTPController] OTP field changed: index=$index",
|
||||
level: LogLevel.debug);
|
||||
if (value.isNotEmpty) {
|
||||
if (index < otpControllers.length - 1) {
|
||||
focusNodes[index + 1].requestFocus();
|
||||
@ -126,31 +109,36 @@ class OTPController extends GetxController {
|
||||
|
||||
Future<void> verifyOTP() async {
|
||||
final enteredOTP = otpControllers.map((c) => c.text).join();
|
||||
|
||||
final result = await AuthService.verifyOtp(
|
||||
email: email.value,
|
||||
otp: enteredOTP,
|
||||
);
|
||||
|
||||
if (result == null) {
|
||||
// ✅ Handle remember-me like in LoginController
|
||||
final remember = LocalStorage.getBool('remember_me') ?? false;
|
||||
if (remember) await LocalStorage.setToken('otp_email', email.value);
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "OTP verified successfully",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
final bool isMpinEnabled = LocalStorage.getIsMpin();
|
||||
print('MPIN Enabled? $isMpinEnabled');
|
||||
|
||||
// ✅ Enable remote logging
|
||||
enableRemoteLogging();
|
||||
|
||||
Get.offAllNamed('/select-tenant');
|
||||
if (isMpinEnabled) {
|
||||
Get.offAllNamed('/home');
|
||||
} else {
|
||||
Get.offAllNamed('/home');
|
||||
}
|
||||
} else {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: result['error']!,
|
||||
message: result['error'] ?? "Failed to verify OTP",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _clearOTPFields() {
|
||||
logSafe("[OTPController] Clearing OTP input fields", level: LogLevel.debug);
|
||||
for (final controller in otpControllers) {
|
||||
controller.clear();
|
||||
}
|
||||
@ -158,7 +146,6 @@ class OTPController extends GetxController {
|
||||
}
|
||||
|
||||
void _startTimer() {
|
||||
logSafe("[OTPController] Starting resend timer");
|
||||
timer.value = 60;
|
||||
_countdownTimer?.cancel();
|
||||
_countdownTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
@ -171,8 +158,6 @@ class OTPController extends GetxController {
|
||||
}
|
||||
|
||||
void resetForChangeEmail() {
|
||||
logSafe("[OTPController] Resetting OTP form for change email");
|
||||
|
||||
isOTPSent.value = false;
|
||||
email.value = '';
|
||||
emailController.clear();
|
||||
@ -185,33 +170,10 @@ class OTPController extends GetxController {
|
||||
for (final node in focusNodes) {
|
||||
node.unfocus();
|
||||
}
|
||||
|
||||
// Optionally remove saved email
|
||||
LocalStorage.removeToken('otp_email');
|
||||
}
|
||||
|
||||
bool _validateEmail(String email) {
|
||||
final regex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,}$');
|
||||
return regex.hasMatch(email);
|
||||
}
|
||||
|
||||
/// Save email to local storage if "remember me" is set
|
||||
Future<void> _saveEmailIfRemembered(String email) async {
|
||||
final remember = LocalStorage.getBool('remember_me') ?? false;
|
||||
if (remember) {
|
||||
await LocalStorage.setToken('otp_email', email);
|
||||
}
|
||||
}
|
||||
|
||||
/// Load email from local storage if "remember me" is true
|
||||
Future<void> _loadSavedEmail() async {
|
||||
final remember = LocalStorage.getBool('remember_me') ?? false;
|
||||
if (remember) {
|
||||
final savedEmail = LocalStorage.getToken('otp_email') ?? '';
|
||||
emailController.text = savedEmail;
|
||||
email.value = savedEmail;
|
||||
logSafe(
|
||||
"[OTPController] Loaded saved email from local storage: $savedEmail");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,17 +3,16 @@ import 'package:get/get.dart';
|
||||
import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
||||
import 'package:marco/helpers/widgets/my_validators.dart';
|
||||
import 'package:marco/helpers/services/auth_service.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
|
||||
import 'package:marco/helpers/services/auth_service.dart';
|
||||
|
||||
class RegisterAccountController extends MyController {
|
||||
MyFormValidator basicValidator = MyFormValidator();
|
||||
|
||||
bool showPassword = false;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
logSafe("[RegisterAccountController] onInit called");
|
||||
|
||||
basicValidator.addField(
|
||||
'email',
|
||||
required: true,
|
||||
@ -39,40 +38,29 @@ class RegisterAccountController extends MyController {
|
||||
validators: [MyLengthValidator(min: 6, max: 10)],
|
||||
controller: TextEditingController(),
|
||||
);
|
||||
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
Future<void> onLogin() async {
|
||||
if (basicValidator.validateForm()) {
|
||||
update();
|
||||
final data = basicValidator.getData();
|
||||
logSafe("[RegisterAccountController] Submitting registration data");
|
||||
|
||||
final errors = await AuthService.loginUser(data);
|
||||
var errors = await AuthService.loginUser(basicValidator.getData());
|
||||
if (errors != null) {
|
||||
logSafe("[RegisterAccountController] Login errors: $errors", level: LogLevel.warning);
|
||||
basicValidator.addErrors(errors);
|
||||
basicValidator.validateForm();
|
||||
basicValidator.clearErrors();
|
||||
}
|
||||
|
||||
logSafe("[RegisterAccountController] Redirecting to /starter");
|
||||
Get.toNamed('/starter');
|
||||
update();
|
||||
} else {
|
||||
logSafe("[RegisterAccountController] Validation failed", level: LogLevel.warning);
|
||||
}
|
||||
}
|
||||
|
||||
void onChangeShowPassword() {
|
||||
showPassword = !showPassword;
|
||||
logSafe("[RegisterAccountController] showPassword toggled: $showPassword");
|
||||
update();
|
||||
}
|
||||
|
||||
void gotoLogin() {
|
||||
logSafe("[RegisterAccountController] Navigating to /auth/login-option");
|
||||
Get.toNamed('/auth/login-option');
|
||||
}
|
||||
}
|
||||
|
@ -4,68 +4,56 @@ import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/helpers/services/auth_service.dart';
|
||||
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
||||
import 'package:marco/helpers/widgets/my_validators.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
|
||||
class ResetPasswordController extends MyController {
|
||||
MyFormValidator basicValidator = MyFormValidator();
|
||||
bool showPassword = false;
|
||||
|
||||
bool confirmPassword = false;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
logSafe("[ResetPasswordController] onInit called");
|
||||
|
||||
basicValidator.addField(
|
||||
'password',
|
||||
required: true,
|
||||
validators: [MyLengthValidator(min: 6, max: 10)],
|
||||
validators: [
|
||||
MyLengthValidator(min: 6, max: 10),
|
||||
],
|
||||
controller: TextEditingController(),
|
||||
);
|
||||
|
||||
basicValidator.addField(
|
||||
'confirm_password',
|
||||
required: true,
|
||||
label: "Confirm password",
|
||||
validators: [MyLengthValidator(min: 6, max: 10)],
|
||||
validators: [
|
||||
MyLengthValidator(min: 6, max: 10),
|
||||
],
|
||||
controller: TextEditingController(),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> onResetPassword() async {
|
||||
logSafe("[ResetPasswordController] onResetPassword triggered");
|
||||
|
||||
if (basicValidator.validateForm()) {
|
||||
final data = basicValidator.getData();
|
||||
logSafe("[ResetPasswordController] Reset password form data");
|
||||
|
||||
update();
|
||||
|
||||
final errors = await AuthService.loginUser(data); // Consider renaming this to resetPassword() for clarity
|
||||
var errors = await AuthService.loginUser(basicValidator.getData());
|
||||
if (errors != null) {
|
||||
logSafe("[ResetPasswordController] Received errors: $errors", level: LogLevel.warning);
|
||||
basicValidator.addErrors(errors);
|
||||
basicValidator.validateForm();
|
||||
basicValidator.clearErrors();
|
||||
}
|
||||
|
||||
logSafe("[ResetPasswordController] Navigating to /dashboard");
|
||||
Get.toNamed('/dashboard');
|
||||
Get.toNamed('/home');
|
||||
update();
|
||||
} else {
|
||||
logSafe("[ResetPasswordController] Form validation failed", level: LogLevel.warning);
|
||||
}
|
||||
}
|
||||
|
||||
void onChangeShowPassword() {
|
||||
showPassword = !showPassword;
|
||||
logSafe("[ResetPasswordController] showPassword toggled: $showPassword");
|
||||
update();
|
||||
}
|
||||
|
||||
void onConfirmPassword() {
|
||||
confirmPassword = !confirmPassword;
|
||||
logSafe("[ResetPasswordController] confirmPassword toggled: $confirmPassword");
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
290
lib/controller/dashboard/add_employee_controller.dart
Normal file
@ -0,0 +1,290 @@
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
enum Gender {
|
||||
male,
|
||||
female,
|
||||
other;
|
||||
|
||||
const Gender();
|
||||
}
|
||||
|
||||
final Logger logger = Logger();
|
||||
|
||||
class AddEmployeeController extends MyController {
|
||||
List<PlatformFile> files = [];
|
||||
final MyFormValidator basicValidator = MyFormValidator();
|
||||
Gender? selectedGender;
|
||||
List<Map<String, dynamic>> roles = [];
|
||||
String? selectedRoleId;
|
||||
final List<Map<String, String>> countries = [
|
||||
{"code": "+91", "name": "India"},
|
||||
{"code": "+1", "name": "USA"},
|
||||
{"code": "+971", "name": "UAE"},
|
||||
{"code": "+44", "name": "UK"},
|
||||
{"code": "+81", "name": "Japan"},
|
||||
{"code": "+61", "name": "Australia"},
|
||||
{"code": "+49", "name": "Germany"},
|
||||
{"code": "+33", "name": "France"},
|
||||
{"code": "+86", "name": "China"},
|
||||
];
|
||||
|
||||
final Map<String, int> minDigitsPerCountry = {
|
||||
"+91": 10,
|
||||
"+1": 10,
|
||||
"+971": 9,
|
||||
"+44": 10,
|
||||
"+81": 10,
|
||||
"+61": 9,
|
||||
"+49": 10,
|
||||
"+33": 9,
|
||||
"+86": 11,
|
||||
};
|
||||
|
||||
final Map<String, int> maxDigitsPerCountry = {
|
||||
"+91": 10,
|
||||
"+1": 10,
|
||||
"+971": 9,
|
||||
"+44": 11,
|
||||
"+81": 10,
|
||||
"+61": 9,
|
||||
"+49": 11,
|
||||
"+33": 9,
|
||||
"+86": 11,
|
||||
};
|
||||
String selectedCountryCode = "+91";
|
||||
|
||||
bool showOnline = true;
|
||||
final List<String> categories = [];
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
logger.i("Initializing AddEmployeeController...");
|
||||
_initializeFields();
|
||||
fetchRoles();
|
||||
}
|
||||
|
||||
void _initializeFields() {
|
||||
basicValidator.addField(
|
||||
'first_name',
|
||||
label: "First Name",
|
||||
required: true,
|
||||
controller: TextEditingController(),
|
||||
);
|
||||
basicValidator.addField(
|
||||
'phone_number',
|
||||
label: "Phone Number",
|
||||
required: true,
|
||||
controller: TextEditingController(),
|
||||
);
|
||||
basicValidator.addField(
|
||||
'last_name',
|
||||
label: "Last Name",
|
||||
required: true,
|
||||
controller: TextEditingController(),
|
||||
);
|
||||
logger.i("Fields initialized for first_name, phone_number, last_name.");
|
||||
}
|
||||
|
||||
void onGenderSelected(Gender? gender) {
|
||||
selectedGender = gender;
|
||||
logger.i("Gender selected: ${gender?.name}");
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> fetchRoles() async {
|
||||
logger.i("Fetching roles...");
|
||||
try {
|
||||
final result = await ApiService.getRoles();
|
||||
if (result != null) {
|
||||
roles = List<Map<String, dynamic>>.from(result);
|
||||
logger.i("Roles fetched successfully.");
|
||||
update();
|
||||
} else {
|
||||
logger.e("Failed to fetch roles: null result");
|
||||
}
|
||||
} catch (e, st) {
|
||||
logger.e("Error fetching roles: $e", error: e, stackTrace: st);
|
||||
}
|
||||
}
|
||||
|
||||
void onRoleSelected(String? roleId) {
|
||||
selectedRoleId = roleId;
|
||||
logger.i("Role selected: $roleId");
|
||||
update();
|
||||
}
|
||||
|
||||
Future<bool> createEmployees() async {
|
||||
logger.i("Starting employee creation...");
|
||||
if (selectedGender == null || selectedRoleId == null) {
|
||||
logger.w("Missing gender or role.");
|
||||
showAppSnackbar(
|
||||
title: "Missing Fields",
|
||||
message: "Please select both Gender and Role.",
|
||||
type: SnackbarType.warning,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
final firstName = basicValidator.getController("first_name")?.text.trim();
|
||||
final lastName = basicValidator.getController("last_name")?.text.trim();
|
||||
final phoneNumber =
|
||||
basicValidator.getController("phone_number")?.text.trim();
|
||||
|
||||
logger.i(
|
||||
"Creating employee with Name: $firstName $lastName, Phone: $phoneNumber, Gender: ${selectedGender!.name}");
|
||||
|
||||
try {
|
||||
final response = await ApiService.createEmployee(
|
||||
firstName: firstName!,
|
||||
lastName: lastName!,
|
||||
phoneNumber: phoneNumber!,
|
||||
gender: selectedGender!.name,
|
||||
jobRoleId: selectedRoleId!,
|
||||
);
|
||||
|
||||
if (response == true) {
|
||||
logger.i("Employee created successfully.");
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "Employee created successfully!",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
logger.e("Failed to create employee (response false).");
|
||||
}
|
||||
} catch (e, st) {
|
||||
logger.e("Error creating employee: $e", error: e, stackTrace: st);
|
||||
}
|
||||
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to create employee.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<bool> _checkAndRequestContactsPermission() async {
|
||||
final status = await Permission.contacts.request();
|
||||
|
||||
if (status.isGranted) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (status.isPermanentlyDenied) {
|
||||
await openAppSettings();
|
||||
}
|
||||
|
||||
showAppSnackbar(
|
||||
title: "Permission Required",
|
||||
message:
|
||||
"Please allow Contacts permission from settings to pick a contact.",
|
||||
type: SnackbarType.warning,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> pickContact(BuildContext context) async {
|
||||
final permissionGranted = await _checkAndRequestContactsPermission();
|
||||
|
||||
if (!permissionGranted) return;
|
||||
|
||||
try {
|
||||
final picked = await FlutterContacts.openExternalPick();
|
||||
|
||||
if (picked == null) return; // User canceled contact picking
|
||||
|
||||
final contact =
|
||||
await FlutterContacts.getContact(picked.id, withProperties: true);
|
||||
|
||||
if (contact == null) {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to load contact details.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (contact.phones.isEmpty) {
|
||||
showAppSnackbar(
|
||||
title: "No Phone Number",
|
||||
message: "Selected contact has no phone number.",
|
||||
type: SnackbarType.warning,
|
||||
);
|
||||
return;
|
||||
}
|
||||
final indiaPhones = contact.phones.where((p) {
|
||||
final normalized = p.number.replaceAll(RegExp(r'[^0-9+]'), '');
|
||||
return normalized.startsWith('+91') ||
|
||||
RegExp(r'^\d{10}$').hasMatch(normalized);
|
||||
}).toList();
|
||||
|
||||
if (indiaPhones.isEmpty) {
|
||||
showAppSnackbar(
|
||||
title: "No Indian Number",
|
||||
message: "Selected contact has no Indian (+91) phone number.",
|
||||
type: SnackbarType.warning,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
String? selectedPhone;
|
||||
|
||||
if (indiaPhones.length == 1) {
|
||||
selectedPhone = indiaPhones.first.number;
|
||||
} else {
|
||||
selectedPhone = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text("Choose an Indian number"),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: indiaPhones
|
||||
.map((p) => ListTile(
|
||||
title: Text(p.number),
|
||||
onTap: () => Navigator.of(ctx).pop(p.number),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (selectedPhone == null) return;
|
||||
}
|
||||
final normalizedPhone = selectedPhone.replaceAll(RegExp(r'[^0-9]'), '');
|
||||
|
||||
// Remove country code prefix if present, keep only 10 digits
|
||||
String phoneWithoutCountryCode;
|
||||
|
||||
if (normalizedPhone.length > 10) {
|
||||
phoneWithoutCountryCode =
|
||||
normalizedPhone.substring(normalizedPhone.length - 10);
|
||||
} else {
|
||||
phoneWithoutCountryCode = normalizedPhone;
|
||||
}
|
||||
|
||||
basicValidator.getController('phone_number')?.text =
|
||||
phoneWithoutCountryCode;
|
||||
|
||||
update();
|
||||
} catch (e, st) {
|
||||
logger.e("Error fetching contacts: $e", error: e, stackTrace: st);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to fetch contacts.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
52
lib/controller/dashboard/analytics_controller.dart
Normal file
@ -0,0 +1,52 @@
|
||||
import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/model/chart_model.dart';
|
||||
import 'package:marco/model/visitor_by_channels_model.dart';
|
||||
import 'package:syncfusion_flutter_charts/charts.dart';
|
||||
|
||||
class AnalyticsController extends MyController {
|
||||
String selectActivity = "Year";
|
||||
List<VisitorByChannelsModel> visitorByChannel = [];
|
||||
final TooltipBehavior columnChartToolTip = TooltipBehavior(enable: true, format: 'point.x : point.y', tooltipPosition: TooltipPosition.pointer);
|
||||
final TooltipBehavior audienceOverview = TooltipBehavior(enable: true, format: 'point.x : point.y', tooltipPosition: TooltipPosition.pointer);
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
VisitorByChannelsModel.dummyList.then((value) {
|
||||
visitorByChannel = value;
|
||||
update();
|
||||
});
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
void onSelectedActivity(String time) {
|
||||
selectActivity = time;
|
||||
update();
|
||||
}
|
||||
|
||||
void removeData(index) {
|
||||
visitorByChannel.removeAt(index);
|
||||
update();
|
||||
}
|
||||
|
||||
final List<ChartSampleData> columnChart = <ChartSampleData>[
|
||||
ChartSampleData(x: 2010, y: 32, yValue: 50),
|
||||
ChartSampleData(x: 2011, y: 44, yValue: 40),
|
||||
ChartSampleData(x: 2012, y: 40, yValue: 60),
|
||||
ChartSampleData(x: 2013, y: 50, yValue: 38),
|
||||
ChartSampleData(x: 2014, y: 10, yValue: 28),
|
||||
ChartSampleData(x: 2015, y: 20, yValue: 16),
|
||||
ChartSampleData(x: 2016, y: 30, yValue: 50),
|
||||
];
|
||||
|
||||
final List<ChartSampleData> audienceOverviewChart = [
|
||||
ChartSampleData(x: 2018, y: 50, yValue: 38),
|
||||
ChartSampleData(x: 2019, y: 10, yValue: 28),
|
||||
ChartSampleData(x: 2020, y: 32, yValue: 50),
|
||||
ChartSampleData(x: 2020, y: 44, yValue: 40),
|
||||
ChartSampleData(x: 2020, y: 40, yValue: 60),
|
||||
ChartSampleData(x: 2020, y: 50, yValue: 38),
|
||||
ChartSampleData(x: 2021, y: 10, yValue: 28),
|
||||
ChartSampleData(x: 2022, y: 20, yValue: 16),
|
||||
ChartSampleData(x: 2023, y: 30, yValue: 50)
|
||||
];
|
||||
}
|
394
lib/controller/dashboard/attendance_screen_controller.dart
Normal file
@ -0,0 +1,394 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/widgets/my_image_compressor.dart';
|
||||
import 'package:marco/model/attendance_model.dart';
|
||||
import 'package:marco/model/project_model.dart';
|
||||
import 'package:marco/model/employee_model.dart';
|
||||
import 'package:marco/model/attendance_log_model.dart';
|
||||
import 'package:marco/model/regularization_log_model.dart';
|
||||
import 'package:marco/model/attendance_log_view_model.dart';
|
||||
|
||||
final Logger log = Logger();
|
||||
|
||||
class AttendanceController extends GetxController {
|
||||
// Data lists
|
||||
List<AttendanceModel> attendances = [];
|
||||
List<ProjectModel> projects = [];
|
||||
List<EmployeeModel> employees = [];
|
||||
List<AttendanceLogModel> attendanceLogs = [];
|
||||
List<RegularizationLogModel> regularizationLogs = [];
|
||||
List<AttendanceLogViewModel> attendenceLogsView = [];
|
||||
|
||||
// Selected values
|
||||
String? selectedProjectId;
|
||||
String selectedTab = 'Employee List';
|
||||
|
||||
// Date range for attendance filtering
|
||||
DateTime? startDateAttendance;
|
||||
DateTime? endDateAttendance;
|
||||
|
||||
// Loading states
|
||||
RxBool isLoading = true.obs;
|
||||
RxBool isLoadingProjects = true.obs;
|
||||
RxBool isLoadingEmployees = true.obs;
|
||||
RxBool isLoadingAttendanceLogs = true.obs;
|
||||
RxBool isLoadingRegularizationLogs = true.obs;
|
||||
RxBool isLoadingLogView = true.obs;
|
||||
|
||||
// Uploading state per employee (keyed by employeeId)
|
||||
RxMap<String, RxBool> uploadingStates = <String, RxBool>{}.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
_initializeDefaults();
|
||||
}
|
||||
|
||||
void _initializeDefaults() {
|
||||
_setDefaultDateRange();
|
||||
fetchProjects();
|
||||
}
|
||||
|
||||
void _setDefaultDateRange() {
|
||||
final today = DateTime.now();
|
||||
startDateAttendance = today.subtract(const Duration(days: 7));
|
||||
endDateAttendance = today.subtract(const Duration(days: 1));
|
||||
log.i("Default date range set: $startDateAttendance to $endDateAttendance");
|
||||
}
|
||||
|
||||
/// Checks and requests location permission, returns true if granted.
|
||||
Future<bool> _handleLocationPermission() async {
|
||||
LocationPermission permission = await Geolocator.checkPermission();
|
||||
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
log.w('Location permissions are denied');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (permission == LocationPermission.deniedForever) {
|
||||
log.e('Location permissions are permanently denied');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Fetches projects and initializes selected project.
|
||||
Future<void> fetchProjects() async {
|
||||
isLoadingProjects.value = true;
|
||||
isLoading.value = true;
|
||||
|
||||
final response = await ApiService.getProjects();
|
||||
|
||||
if (response != null && response.isNotEmpty) {
|
||||
projects = response.map((json) => ProjectModel.fromJson(json)).toList();
|
||||
selectedProjectId = projects.first.id.toString();
|
||||
log.i("Projects fetched: ${projects.length}");
|
||||
|
||||
await fetchProjectData(selectedProjectId);
|
||||
} else {
|
||||
log.w("No projects found or API call failed.");
|
||||
}
|
||||
|
||||
isLoadingProjects.value = false;
|
||||
isLoading.value = false;
|
||||
|
||||
update(['attendance_dashboard_controller']);
|
||||
}
|
||||
|
||||
/// Fetches employees, attendance logs and regularization logs for a project.
|
||||
Future<void> fetchProjectData(String? projectId) async {
|
||||
if (projectId == null) return;
|
||||
|
||||
isLoading.value = true;
|
||||
|
||||
await Future.wait([
|
||||
fetchEmployeesByProject(projectId),
|
||||
fetchAttendanceLogs(projectId,
|
||||
dateFrom: startDateAttendance, dateTo: endDateAttendance),
|
||||
fetchRegularizationLogs(projectId),
|
||||
]);
|
||||
|
||||
isLoading.value = false;
|
||||
|
||||
log.i("Project data fetched for project ID: $projectId");
|
||||
}
|
||||
|
||||
/// Fetches employees for the given project.
|
||||
Future<void> fetchEmployeesByProject(String? projectId) async {
|
||||
if (projectId == null) return;
|
||||
|
||||
isLoadingEmployees.value = true;
|
||||
|
||||
final response = await ApiService.getEmployeesByProject(projectId);
|
||||
|
||||
if (response != null) {
|
||||
employees = response.map((json) => EmployeeModel.fromJson(json)).toList();
|
||||
|
||||
// Initialize uploading states for employees
|
||||
for (var emp in employees) {
|
||||
uploadingStates[emp.id] = false.obs;
|
||||
}
|
||||
|
||||
log.i("Employees fetched: ${employees.length} for project $projectId");
|
||||
update();
|
||||
} else {
|
||||
log.e("Failed to fetch employees for project $projectId");
|
||||
}
|
||||
|
||||
isLoadingEmployees.value = false;
|
||||
}
|
||||
|
||||
/// Captures image, gets location, and uploads attendance data.
|
||||
/// Returns true on success.
|
||||
Future<bool> captureAndUploadAttendance(
|
||||
String id,
|
||||
String employeeId,
|
||||
String projectId, {
|
||||
String comment = "Marked via mobile app",
|
||||
required int action,
|
||||
bool imageCapture = true,
|
||||
String? markTime,
|
||||
}) async {
|
||||
try {
|
||||
uploadingStates[employeeId]?.value = true;
|
||||
|
||||
XFile? image;
|
||||
if (imageCapture) {
|
||||
image = await ImagePicker().pickImage(
|
||||
source: ImageSource.camera,
|
||||
imageQuality: 80,
|
||||
);
|
||||
if (image == null) {
|
||||
log.w("Image capture cancelled.");
|
||||
uploadingStates[employeeId]?.value = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
final compressedBytes = await compressImageToUnder100KB(File(image.path));
|
||||
if (compressedBytes == null) {
|
||||
log.e("Image compression failed.");
|
||||
uploadingStates[employeeId]?.value = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
final compressedFile = await saveCompressedImageToFile(compressedBytes);
|
||||
image = XFile(compressedFile.path);
|
||||
}
|
||||
|
||||
final hasLocationPermission = await _handleLocationPermission();
|
||||
if (!hasLocationPermission) {
|
||||
uploadingStates[employeeId]?.value = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
final position = await Geolocator.getCurrentPosition(
|
||||
desiredAccuracy: LocationAccuracy.high,
|
||||
);
|
||||
|
||||
final imageName = imageCapture
|
||||
? ApiService.generateImageName(employeeId, employees.length + 1)
|
||||
: "";
|
||||
|
||||
final result = await ApiService.uploadAttendanceImage(
|
||||
id,
|
||||
employeeId,
|
||||
image,
|
||||
position.latitude,
|
||||
position.longitude,
|
||||
imageName: imageName,
|
||||
projectId: projectId,
|
||||
comment: comment,
|
||||
action: action,
|
||||
imageCapture: imageCapture,
|
||||
markTime: markTime,
|
||||
);
|
||||
|
||||
log.i("Attendance uploaded for $employeeId, action: $action");
|
||||
return result;
|
||||
} catch (e, stacktrace) {
|
||||
log.e("Error uploading attendance", error: e, stackTrace: stacktrace);
|
||||
return false;
|
||||
} finally {
|
||||
uploadingStates[employeeId]?.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens a date range picker for attendance filtering and fetches logs on selection.
|
||||
Future<void> selectDateRangeForAttendance(
|
||||
BuildContext context,
|
||||
AttendanceController controller,
|
||||
) async {
|
||||
final today = DateTime.now();
|
||||
final todayDateOnly = DateTime(today.year, today.month, today.day);
|
||||
|
||||
final picked = await showDateRangePicker(
|
||||
context: context,
|
||||
firstDate: DateTime(2022),
|
||||
lastDate: todayDateOnly.subtract(const Duration(days: 1)),
|
||||
initialDateRange: DateTimeRange(
|
||||
start: startDateAttendance ?? today.subtract(const Duration(days: 7)),
|
||||
end: endDateAttendance ?? todayDateOnly.subtract(const Duration(days: 1)),
|
||||
),
|
||||
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
width: 400,
|
||||
height: 500,
|
||||
child: Theme(
|
||||
data: Theme.of(context).copyWith(
|
||||
colorScheme: ColorScheme.light(
|
||||
primary: const Color.fromARGB(255, 95, 132, 255),
|
||||
onPrimary: Colors.white,
|
||||
onSurface: Colors.teal.shade800,
|
||||
),
|
||||
textButtonTheme: TextButtonThemeData(
|
||||
style: TextButton.styleFrom(foregroundColor: Colors.teal),
|
||||
),
|
||||
dialogTheme: const DialogTheme(backgroundColor: Colors.white),
|
||||
),
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (picked != null) {
|
||||
startDateAttendance = picked.start;
|
||||
endDateAttendance = picked.end;
|
||||
|
||||
log.i("Date range selected: $startDateAttendance to $endDateAttendance");
|
||||
|
||||
await controller.fetchAttendanceLogs(
|
||||
controller.selectedProjectId,
|
||||
dateFrom: picked.start,
|
||||
dateTo: picked.end,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetches attendance logs filtered by project and date range.
|
||||
Future<void> fetchAttendanceLogs(
|
||||
String? projectId, {
|
||||
DateTime? dateFrom,
|
||||
DateTime? dateTo,
|
||||
}) async {
|
||||
if (projectId == null) return;
|
||||
|
||||
isLoadingAttendanceLogs.value = true;
|
||||
isLoading.value = true;
|
||||
|
||||
final response = await ApiService.getAttendanceLogs(
|
||||
projectId,
|
||||
dateFrom: dateFrom,
|
||||
dateTo: dateTo,
|
||||
);
|
||||
|
||||
if (response != null) {
|
||||
attendanceLogs =
|
||||
response.map((json) => AttendanceLogModel.fromJson(json)).toList();
|
||||
log.i("Attendance logs fetched: ${attendanceLogs.length}");
|
||||
update();
|
||||
} else {
|
||||
log.e("Failed to fetch attendance logs for project $projectId");
|
||||
}
|
||||
|
||||
isLoadingAttendanceLogs.value = false;
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
||||
/// Groups attendance logs by check-in date formatted as 'dd MMM yyyy'.
|
||||
Map<String, List<AttendanceLogModel>> groupLogsByCheckInDate() {
|
||||
final groupedLogs = <String, List<AttendanceLogModel>>{};
|
||||
|
||||
for (var logItem in attendanceLogs) {
|
||||
final checkInDate = logItem.checkIn != null
|
||||
? DateFormat('dd MMM yyyy').format(logItem.checkIn!)
|
||||
: 'Unknown';
|
||||
|
||||
groupedLogs.putIfAbsent(checkInDate, () => []);
|
||||
groupedLogs[checkInDate]!.add(logItem);
|
||||
}
|
||||
|
||||
final sortedEntries = groupedLogs.entries.toList()
|
||||
..sort((a, b) {
|
||||
if (a.key == 'Unknown') return 1;
|
||||
if (b.key == 'Unknown') return -1;
|
||||
final dateA = DateFormat('dd MMM yyyy').parse(a.key);
|
||||
final dateB = DateFormat('dd MMM yyyy').parse(b.key);
|
||||
return dateB.compareTo(dateA);
|
||||
});
|
||||
|
||||
final sortedMap = Map<String, List<AttendanceLogModel>>.fromEntries(sortedEntries);
|
||||
|
||||
log.i("Logs grouped and sorted by check-in date.");
|
||||
return sortedMap;
|
||||
}
|
||||
|
||||
/// Fetches regularization logs for a project.
|
||||
Future<void> fetchRegularizationLogs(
|
||||
String? projectId, {
|
||||
DateTime? dateFrom,
|
||||
DateTime? dateTo,
|
||||
}) async {
|
||||
if (projectId == null) return;
|
||||
|
||||
isLoadingRegularizationLogs.value = true;
|
||||
isLoading.value = true;
|
||||
|
||||
final response = await ApiService.getRegularizationLogs(projectId);
|
||||
|
||||
if (response != null) {
|
||||
regularizationLogs =
|
||||
response.map((json) => RegularizationLogModel.fromJson(json)).toList();
|
||||
log.i("Regularization logs fetched: ${regularizationLogs.length}");
|
||||
update();
|
||||
} else {
|
||||
log.e("Failed to fetch regularization logs for project $projectId");
|
||||
}
|
||||
|
||||
isLoadingRegularizationLogs.value = false;
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
||||
/// Fetches detailed attendance log view for a specific ID.
|
||||
Future<void> fetchLogsView(String? id) async {
|
||||
if (id == null) return;
|
||||
|
||||
isLoadingLogView.value = true;
|
||||
isLoading.value = true;
|
||||
|
||||
final response = await ApiService.getAttendanceLogView(id);
|
||||
|
||||
if (response != null) {
|
||||
attendenceLogsView =
|
||||
response.map((json) => AttendanceLogViewModel.fromJson(json)).toList();
|
||||
|
||||
attendenceLogsView.sort((a, b) {
|
||||
if (a.activityTime == null || b.activityTime == null) return 0;
|
||||
return b.activityTime!.compareTo(a.activityTime!);
|
||||
});
|
||||
|
||||
log.i("Attendance log view fetched for ID: $id");
|
||||
update();
|
||||
} else {
|
||||
log.e("Failed to fetch attendance log view for ID $id");
|
||||
}
|
||||
|
||||
isLoadingLogView.value = false;
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
35
lib/controller/dashboard/crm_controller.dart
Normal file
@ -0,0 +1,35 @@
|
||||
import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/model/chart_model.dart';
|
||||
import 'package:marco/model/lead_report_model.dart';
|
||||
import 'package:syncfusion_flutter_charts/charts.dart';
|
||||
|
||||
class CrmController extends MyController {
|
||||
List<ChartSampleData>? chartData;
|
||||
List<LeadReportModel> leadReport = [];
|
||||
TooltipBehavior? tooltipBehavior;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
tooltipBehavior = TooltipBehavior(enable: true);
|
||||
chartData = <ChartSampleData>[
|
||||
ChartSampleData(x: 'Jan', y: 10, secondSeriesYValue: 5),
|
||||
ChartSampleData(x: 'Feb', y: 12, secondSeriesYValue: 8),
|
||||
ChartSampleData(x: 'Mar', y: 14, secondSeriesYValue: 9),
|
||||
ChartSampleData(x: 'Apr', y: 11, secondSeriesYValue: 7),
|
||||
ChartSampleData(x: 'May', y: 15, secondSeriesYValue: 10),
|
||||
ChartSampleData(x: 'Jun', y: 9, secondSeriesYValue: 6),
|
||||
ChartSampleData(x: 'Jul', y: 13, secondSeriesYValue: 7),
|
||||
ChartSampleData(x: 'Aug', y: 12, secondSeriesYValue: 8),
|
||||
ChartSampleData(x: 'Sep', y: 14, secondSeriesYValue: 10),
|
||||
ChartSampleData(x: 'Oct', y: 15, secondSeriesYValue: 12),
|
||||
ChartSampleData(x: 'Nov', y: 13, secondSeriesYValue: 9),
|
||||
ChartSampleData(x: 'Dec', y: 11, secondSeriesYValue: 6),
|
||||
];
|
||||
|
||||
LeadReportModel.dummyList.then((value) {
|
||||
leadReport = value.sublist(0, 5);
|
||||
update();
|
||||
});
|
||||
super.onInit();
|
||||
}
|
||||
}
|
43
lib/controller/dashboard/crypto_controller.dart
Normal file
@ -0,0 +1,43 @@
|
||||
import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/model/chart_model.dart';
|
||||
import 'package:marco/model/coin_growth_model.dart';
|
||||
import 'package:syncfusion_flutter_charts/charts.dart';
|
||||
|
||||
class CryptoController extends MyController {
|
||||
List<ChartSampleData>? chartData;
|
||||
DateTimeIntervalType intervalType = DateTimeIntervalType.months;
|
||||
List<CoinGrowthModel> coinGrowth = [];
|
||||
|
||||
bool enableSolidCandle = false;
|
||||
|
||||
TrackballBehavior? trackballBehavior;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
CoinGrowthModel.dummyList.then((value) {
|
||||
coinGrowth = value.sublist(0, 5);
|
||||
update();
|
||||
});
|
||||
chartData = <ChartSampleData>[
|
||||
ChartSampleData(x: 'Jan', y: 50, secondSeriesYValue: 40, thirdSeriesYValue: 45),
|
||||
ChartSampleData(x: 'Feb', y: 47, secondSeriesYValue: 39, thirdSeriesYValue: 48),
|
||||
ChartSampleData(x: 'Mar', y: 55, secondSeriesYValue: 42, thirdSeriesYValue: 50),
|
||||
ChartSampleData(x: 'Apr', y: 60, secondSeriesYValue: 45, thirdSeriesYValue: 53),
|
||||
ChartSampleData(x: 'May', y: 70, secondSeriesYValue: 50, thirdSeriesYValue: 58),
|
||||
ChartSampleData(x: 'Jun', y: 75, secondSeriesYValue: 55, thirdSeriesYValue: 62),
|
||||
ChartSampleData(x: 'Jul', y: 80, secondSeriesYValue: 58, thirdSeriesYValue: 65),
|
||||
ChartSampleData(x: 'Aug', y: 78, secondSeriesYValue: 60, thirdSeriesYValue: 66),
|
||||
ChartSampleData(x: 'Sep', y: 72, secondSeriesYValue: 55, thirdSeriesYValue: 64),
|
||||
ChartSampleData(x: 'Oct', y: 65, secondSeriesYValue: 50, thirdSeriesYValue: 57),
|
||||
ChartSampleData(x: 'Nov', y: 58, secondSeriesYValue: 45, thirdSeriesYValue: 53),
|
||||
ChartSampleData(x: 'Dec', y: 50, secondSeriesYValue: 40, thirdSeriesYValue: 48)
|
||||
];
|
||||
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
void onSelectIntervalType(DateTimeIntervalType interval) {
|
||||
intervalType = interval;
|
||||
update();
|
||||
}
|
||||
}
|
127
lib/controller/dashboard/daily_task_controller.dart
Normal file
@ -0,0 +1,127 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/model/project_model.dart';
|
||||
import 'package:marco/model/daily_task_model.dart';
|
||||
|
||||
final Logger log = Logger();
|
||||
|
||||
class DailyTaskController extends GetxController {
|
||||
List<ProjectModel> projects = [];
|
||||
String? selectedProjectId;
|
||||
|
||||
DateTime? startDateTask;
|
||||
DateTime? endDateTask;
|
||||
|
||||
List<TaskModel> dailyTasks = [];
|
||||
final RxSet<String> expandedDates = <String>{}.obs;
|
||||
|
||||
void toggleDate(String dateKey) {
|
||||
if (expandedDates.contains(dateKey)) {
|
||||
expandedDates.remove(dateKey);
|
||||
} else {
|
||||
expandedDates.add(dateKey);
|
||||
}
|
||||
}
|
||||
|
||||
RxBool isLoading = false.obs;
|
||||
Map<String, List<TaskModel>> groupedDailyTasks = {};
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
_initializeDefaults();
|
||||
}
|
||||
|
||||
void _initializeDefaults() {
|
||||
_setDefaultDateRange();
|
||||
fetchProjects();
|
||||
}
|
||||
|
||||
void _setDefaultDateRange() {
|
||||
final today = DateTime.now();
|
||||
startDateTask = today.subtract(const Duration(days: 7));
|
||||
endDateTask = today;
|
||||
log.i("Default date range set: $startDateTask to $endDateTask");
|
||||
}
|
||||
|
||||
Future<void> fetchProjects() async {
|
||||
isLoading.value = true;
|
||||
|
||||
final response = await ApiService.getProjects();
|
||||
isLoading.value = false;
|
||||
|
||||
if (response?.isEmpty ?? true) {
|
||||
log.w("No project data found or API call failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
projects = response!.map((json) => ProjectModel.fromJson(json)).toList();
|
||||
selectedProjectId = projects.first.id.toString();
|
||||
log.i("Projects fetched: ${projects.length} projects loaded.");
|
||||
update();
|
||||
await fetchTaskData(selectedProjectId);
|
||||
}
|
||||
|
||||
Future<void> fetchTaskData(String? projectId) async {
|
||||
if (projectId == null) return;
|
||||
|
||||
isLoading.value = true;
|
||||
final response = await ApiService.getDailyTasks(
|
||||
projectId,
|
||||
dateFrom: startDateTask,
|
||||
dateTo: endDateTask,
|
||||
);
|
||||
isLoading.value = false;
|
||||
|
||||
if (response != null) {
|
||||
groupedDailyTasks.clear();
|
||||
|
||||
for (var taskJson in response) {
|
||||
TaskModel task = TaskModel.fromJson(taskJson);
|
||||
String assignmentDateKey =
|
||||
task.assignmentDate.toIso8601String().split('T')[0];
|
||||
|
||||
if (groupedDailyTasks.containsKey(assignmentDateKey)) {
|
||||
groupedDailyTasks[assignmentDateKey]?.add(task);
|
||||
} else {
|
||||
groupedDailyTasks[assignmentDateKey] = [task];
|
||||
}
|
||||
}
|
||||
|
||||
// Flatten the grouped tasks into the existing dailyTasks list
|
||||
dailyTasks = groupedDailyTasks.values.expand((list) => list).toList();
|
||||
|
||||
log.i("Daily tasks fetched and grouped: ${dailyTasks.length}");
|
||||
|
||||
update();
|
||||
} else {
|
||||
log.e("Failed to fetch daily tasks for project $projectId");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> selectDateRangeForTaskData(
|
||||
BuildContext context,
|
||||
DailyTaskController controller,
|
||||
) async {
|
||||
final picked = await showDateRangePicker(
|
||||
context: context,
|
||||
firstDate: DateTime(2022),
|
||||
lastDate: DateTime.now(),
|
||||
initialDateRange: DateTimeRange(
|
||||
start:
|
||||
startDateTask ?? DateTime.now().subtract(const Duration(days: 7)),
|
||||
end: endDateTask ?? DateTime.now(),
|
||||
),
|
||||
);
|
||||
|
||||
if (picked == null) return;
|
||||
|
||||
startDateTask = picked.start;
|
||||
endDateTask = picked.end;
|
||||
|
||||
log.i("Date range selected: $startDateTask to $endDateTask");
|
||||
|
||||
await controller.fetchTaskData(controller.selectedProjectId);
|
||||
}
|
||||
}
|
@ -1,263 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/controller/project_controller.dart';
|
||||
import 'package:marco/model/dashboard/project_progress_model.dart';
|
||||
|
||||
class DashboardController extends GetxController {
|
||||
// =========================
|
||||
// Attendance overview
|
||||
// =========================
|
||||
final RxList<Map<String, dynamic>> roleWiseData =
|
||||
<Map<String, dynamic>>[].obs;
|
||||
final RxString attendanceSelectedRange = '15D'.obs;
|
||||
final RxBool attendanceIsChartView = true.obs;
|
||||
final RxBool isAttendanceLoading = false.obs;
|
||||
|
||||
// =========================
|
||||
// Project progress overview
|
||||
// =========================
|
||||
final RxList<ChartTaskData> projectChartData = <ChartTaskData>[].obs;
|
||||
final RxString projectSelectedRange = '15D'.obs;
|
||||
final RxBool projectIsChartView = true.obs;
|
||||
final RxBool isProjectLoading = false.obs;
|
||||
|
||||
// =========================
|
||||
// Projects overview
|
||||
// =========================
|
||||
final RxInt totalProjects = 0.obs;
|
||||
final RxInt ongoingProjects = 0.obs;
|
||||
final RxBool isProjectsLoading = false.obs;
|
||||
|
||||
// =========================
|
||||
// Tasks overview
|
||||
// =========================
|
||||
final RxInt totalTasks = 0.obs;
|
||||
final RxInt completedTasks = 0.obs;
|
||||
final RxBool isTasksLoading = false.obs;
|
||||
|
||||
// =========================
|
||||
// Teams overview
|
||||
// =========================
|
||||
final RxInt totalEmployees = 0.obs;
|
||||
final RxInt inToday = 0.obs;
|
||||
final RxBool isTeamsLoading = false.obs;
|
||||
|
||||
// Common ranges
|
||||
final List<String> ranges = ['7D', '15D', '30D'];
|
||||
|
||||
// Inside your DashboardController
|
||||
final ProjectController projectController =
|
||||
Get.put(ProjectController(), permanent: true);
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
logSafe(
|
||||
'DashboardController initialized with project ID: ${projectController.selectedProjectId.value}',
|
||||
level: LogLevel.info,
|
||||
);
|
||||
|
||||
fetchAllDashboardData();
|
||||
|
||||
// React to project change
|
||||
ever<String>(projectController.selectedProjectId, (id) {
|
||||
fetchAllDashboardData();
|
||||
});
|
||||
|
||||
// React to range changes
|
||||
ever(attendanceSelectedRange, (_) => fetchRoleWiseAttendance());
|
||||
ever(projectSelectedRange, (_) => fetchProjectProgress());
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Helper Methods
|
||||
// =========================
|
||||
int _getDaysFromRange(String range) {
|
||||
switch (range) {
|
||||
case '7D':
|
||||
return 7;
|
||||
case '15D':
|
||||
return 15;
|
||||
case '30D':
|
||||
return 30;
|
||||
case '3M':
|
||||
return 90;
|
||||
case '6M':
|
||||
return 180;
|
||||
default:
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
|
||||
int getAttendanceDays() => _getDaysFromRange(attendanceSelectedRange.value);
|
||||
int getProjectDays() => _getDaysFromRange(projectSelectedRange.value);
|
||||
|
||||
void updateAttendanceRange(String range) {
|
||||
attendanceSelectedRange.value = range;
|
||||
logSafe('Attendance range updated to $range', level: LogLevel.debug);
|
||||
}
|
||||
|
||||
void updateProjectRange(String range) {
|
||||
projectSelectedRange.value = range;
|
||||
logSafe('Project range updated to $range', level: LogLevel.debug);
|
||||
}
|
||||
|
||||
void toggleAttendanceChartView(bool isChart) {
|
||||
attendanceIsChartView.value = isChart;
|
||||
logSafe('Attendance chart view toggled to: $isChart',
|
||||
level: LogLevel.debug);
|
||||
}
|
||||
|
||||
void toggleProjectChartView(bool isChart) {
|
||||
projectIsChartView.value = isChart;
|
||||
logSafe('Project chart view toggled to: $isChart', level: LogLevel.debug);
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Manual Refresh Methods
|
||||
// =========================
|
||||
Future<void> refreshDashboard() async {
|
||||
logSafe('Manual dashboard refresh triggered.', level: LogLevel.debug);
|
||||
await fetchAllDashboardData();
|
||||
}
|
||||
|
||||
Future<void> refreshAttendance() async => fetchRoleWiseAttendance();
|
||||
Future<void> refreshTasks() async {
|
||||
final projectId = projectController.selectedProjectId.value;
|
||||
if (projectId.isNotEmpty) await fetchDashboardTasks(projectId: projectId);
|
||||
}
|
||||
|
||||
Future<void> refreshProjects() async => fetchProjectProgress();
|
||||
|
||||
// =========================
|
||||
// Fetch All Dashboard Data
|
||||
// =========================
|
||||
Future<void> fetchAllDashboardData() async {
|
||||
final String projectId = projectController.selectedProjectId.value;
|
||||
|
||||
if (projectId.isEmpty) {
|
||||
logSafe('No project selected. Skipping dashboard API calls.',
|
||||
level: LogLevel.warning);
|
||||
return;
|
||||
}
|
||||
|
||||
await Future.wait([
|
||||
fetchRoleWiseAttendance(),
|
||||
fetchProjectProgress(),
|
||||
fetchDashboardTasks(projectId: projectId),
|
||||
fetchDashboardTeams(projectId: projectId),
|
||||
]);
|
||||
}
|
||||
|
||||
// =========================
|
||||
// API Calls
|
||||
// =========================
|
||||
Future<void> fetchRoleWiseAttendance() async {
|
||||
final String projectId = projectController.selectedProjectId.value;
|
||||
if (projectId.isEmpty) return;
|
||||
|
||||
try {
|
||||
isAttendanceLoading.value = true;
|
||||
final List<dynamic>? response =
|
||||
await ApiService.getDashboardAttendanceOverview(
|
||||
projectId, getAttendanceDays());
|
||||
|
||||
if (response != null) {
|
||||
roleWiseData.value =
|
||||
response.map((e) => Map<String, dynamic>.from(e)).toList();
|
||||
logSafe('Attendance overview fetched successfully.',
|
||||
level: LogLevel.info);
|
||||
} else {
|
||||
roleWiseData.clear();
|
||||
logSafe('Failed to fetch attendance overview: response is null.',
|
||||
level: LogLevel.error);
|
||||
}
|
||||
} catch (e, st) {
|
||||
roleWiseData.clear();
|
||||
logSafe('Error fetching attendance overview',
|
||||
level: LogLevel.error, error: e, stackTrace: st);
|
||||
} finally {
|
||||
isAttendanceLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchProjectProgress() async {
|
||||
final String projectId = projectController.selectedProjectId.value;
|
||||
if (projectId.isEmpty) return;
|
||||
|
||||
try {
|
||||
isProjectLoading.value = true;
|
||||
final response = await ApiService.getProjectProgress(
|
||||
projectId: projectId, days: getProjectDays());
|
||||
|
||||
if (response != null && response.success) {
|
||||
projectChartData.value =
|
||||
response.data.map((d) => ChartTaskData.fromProjectData(d)).toList();
|
||||
logSafe('Project progress data mapped for chart', level: LogLevel.info);
|
||||
} else {
|
||||
projectChartData.clear();
|
||||
logSafe('Failed to fetch project progress', level: LogLevel.error);
|
||||
}
|
||||
} catch (e, st) {
|
||||
projectChartData.clear();
|
||||
logSafe('Error fetching project progress',
|
||||
level: LogLevel.error, error: e, stackTrace: st);
|
||||
} finally {
|
||||
isProjectLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchDashboardTasks({required String projectId}) async {
|
||||
if (projectId.isEmpty) return;
|
||||
|
||||
try {
|
||||
isTasksLoading.value = true;
|
||||
final response = await ApiService.getDashboardTasks(projectId: projectId);
|
||||
|
||||
if (response != null && response.success) {
|
||||
totalTasks.value = response.data?.totalTasks ?? 0;
|
||||
completedTasks.value = response.data?.completedTasks ?? 0;
|
||||
logSafe('Dashboard tasks fetched', level: LogLevel.info);
|
||||
} else {
|
||||
totalTasks.value = 0;
|
||||
completedTasks.value = 0;
|
||||
logSafe('Failed to fetch tasks', level: LogLevel.error);
|
||||
}
|
||||
} catch (e, st) {
|
||||
totalTasks.value = 0;
|
||||
completedTasks.value = 0;
|
||||
logSafe('Error fetching tasks',
|
||||
level: LogLevel.error, error: e, stackTrace: st);
|
||||
} finally {
|
||||
isTasksLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchDashboardTeams({required String projectId}) async {
|
||||
if (projectId.isEmpty) return;
|
||||
|
||||
try {
|
||||
isTeamsLoading.value = true;
|
||||
final response = await ApiService.getDashboardTeams(projectId: projectId);
|
||||
|
||||
if (response != null && response.success) {
|
||||
totalEmployees.value = response.data?.totalEmployees ?? 0;
|
||||
inToday.value = response.data?.inToday ?? 0;
|
||||
logSafe('Dashboard teams fetched', level: LogLevel.info);
|
||||
} else {
|
||||
totalEmployees.value = 0;
|
||||
inToday.value = 0;
|
||||
logSafe('Failed to fetch teams', level: LogLevel.error);
|
||||
}
|
||||
} catch (e, st) {
|
||||
totalEmployees.value = 0;
|
||||
inToday.value = 0;
|
||||
logSafe('Error fetching teams',
|
||||
level: LogLevel.error, error: e, stackTrace: st);
|
||||
} finally {
|
||||
isTeamsLoading.value = false;
|
||||
}
|
||||
}
|
||||
}
|
69
lib/controller/dashboard/ecommerce_controller.dart
Normal file
@ -0,0 +1,69 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/model/chart_model.dart';
|
||||
import 'package:marco/model/product_order_modal.dart';
|
||||
import 'package:syncfusion_flutter_charts/charts.dart';
|
||||
|
||||
class EcommerceController extends MyController {
|
||||
List<ChartSampleData>? salesAnalyticsData;
|
||||
List<ProductOrderModal> order = [];
|
||||
String selectedTimeByLocation = "Year";
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
ProductOrderModal.dummyList.then((value) {
|
||||
order = value.sublist(0, 5);
|
||||
update();
|
||||
});
|
||||
salesAnalyticsData = <ChartSampleData>[
|
||||
ChartSampleData(x: 'Jan', y: 43, secondSeriesYValue: 37, thirdSeriesYValue: 41),
|
||||
ChartSampleData(x: 'Feb', y: 45, secondSeriesYValue: 37, thirdSeriesYValue: 45),
|
||||
ChartSampleData(x: 'Mar', y: 50, secondSeriesYValue: 39, thirdSeriesYValue: 48),
|
||||
ChartSampleData(x: 'Apr', y: 55, secondSeriesYValue: 43, thirdSeriesYValue: 52),
|
||||
ChartSampleData(x: 'May', y: 63, secondSeriesYValue: 48, thirdSeriesYValue: 57),
|
||||
ChartSampleData(x: 'Jun', y: 68, secondSeriesYValue: 54, thirdSeriesYValue: 61),
|
||||
ChartSampleData(x: 'Jul', y: 72, secondSeriesYValue: 57, thirdSeriesYValue: 66),
|
||||
ChartSampleData(x: 'Aug', y: 70, secondSeriesYValue: 57, thirdSeriesYValue: 66),
|
||||
ChartSampleData(x: 'Sep', y: 66, secondSeriesYValue: 54, thirdSeriesYValue: 63),
|
||||
ChartSampleData(x: 'Oct', y: 57, secondSeriesYValue: 48, thirdSeriesYValue: 55),
|
||||
ChartSampleData(x: 'Nov', y: 50, secondSeriesYValue: 43, thirdSeriesYValue: 50),
|
||||
ChartSampleData(x: 'Dec', y: 45, secondSeriesYValue: 37, thirdSeriesYValue: 45)
|
||||
];
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
final List<ChartSampleData> chartData = [
|
||||
ChartSampleData(x: 'Jan', y: 10, yValue: 1000),
|
||||
ChartSampleData(x: 'Fab', y: 20, yValue: 2000),
|
||||
ChartSampleData(x: 'Mar', y: 15, yValue: 1500),
|
||||
ChartSampleData(x: 'Jun', y: 5, yValue: 500),
|
||||
ChartSampleData(x: 'Jul', y: 30, yValue: 3000),
|
||||
ChartSampleData(x: 'Aug', y: 20, yValue: 2000),
|
||||
ChartSampleData(x: 'Sep', y: 40, yValue: 4000),
|
||||
ChartSampleData(x: 'Oct', y: 60, yValue: 6000),
|
||||
ChartSampleData(x: 'Nov', y: 55, yValue: 5500),
|
||||
ChartSampleData(x: 'Dec', y: 38, yValue: 3000),
|
||||
];
|
||||
final TooltipBehavior chart = TooltipBehavior(
|
||||
enable: true,
|
||||
format: 'point.x : point.yValue1 : point.yValue2',
|
||||
);
|
||||
|
||||
final List<ChartSampleData> circleChart = [
|
||||
ChartSampleData(x: 'David', y: 25, pointColor: const Color.fromRGBO(9, 0, 136, 1)),
|
||||
ChartSampleData(x: 'Steve', y: 38, pointColor: const Color.fromRGBO(147, 0, 119, 1)),
|
||||
ChartSampleData(x: 'Jack', y: 34, pointColor: const Color.fromRGBO(228, 0, 124, 1)),
|
||||
ChartSampleData(x: 'Others', y: 52, pointColor: const Color.fromRGBO(255, 189, 57, 1))
|
||||
];
|
||||
|
||||
void onSelectedTimeByLocation(String time) {
|
||||
selectedTimeByLocation = time;
|
||||
update();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
salesAnalyticsData!.clear();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
@ -1,152 +1,86 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/model/attendance/attendance_model.dart';
|
||||
import 'package:marco/model/attendance_model.dart';
|
||||
import 'package:marco/model/project_model.dart';
|
||||
import 'package:marco/model/employees/employee_model.dart';
|
||||
import 'package:marco/model/employee_model.dart';
|
||||
import 'package:marco/model/employees/employee_details_model.dart';
|
||||
import 'package:marco/controller/project_controller.dart';
|
||||
|
||||
final Logger log = Logger();
|
||||
|
||||
class EmployeesScreenController extends GetxController {
|
||||
List<AttendanceModel> attendances = [];
|
||||
List<ProjectModel> projects = [];
|
||||
String? selectedProjectId;
|
||||
List<EmployeeModel> employees = [];
|
||||
List<EmployeeDetailsModel> employeeDetails = [];
|
||||
RxBool isAllEmployeeSelected = false.obs;
|
||||
RxList<EmployeeModel> employees = <EmployeeModel>[].obs;
|
||||
|
||||
RxBool isLoading = false.obs;
|
||||
RxMap<String, RxBool> uploadingStates = <String, RxBool>{}.obs;
|
||||
Rxn<EmployeeDetailsModel> selectedEmployeeDetails =
|
||||
Rxn<EmployeeDetailsModel>();
|
||||
RxBool isLoadingEmployeeDetails = false.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
isLoading.value = true;
|
||||
fetchAllProjects().then((_) {
|
||||
final projectId = Get.find<ProjectController>().selectedProject?.id;
|
||||
if (projectId != null) {
|
||||
selectedProjectId = projectId;
|
||||
fetchEmployeesByProject(projectId);
|
||||
} else if (isAllEmployeeSelected.value) {
|
||||
fetchAllEmployees();
|
||||
} else {
|
||||
clearEmployees();
|
||||
}
|
||||
});
|
||||
fetchAllProjects();
|
||||
fetchAllEmployees();
|
||||
}
|
||||
|
||||
Future<void> fetchAllProjects() async {
|
||||
isLoading.value = true;
|
||||
|
||||
await _handleApiCall(
|
||||
ApiService.getProjects,
|
||||
onSuccess: (data) {
|
||||
projects = data.map((json) => ProjectModel.fromJson(json)).toList();
|
||||
logSafe(
|
||||
"Projects fetched: ${projects.length} projects loaded.",
|
||||
level: LogLevel.info,
|
||||
);
|
||||
},
|
||||
onEmpty: () {
|
||||
logSafe("No project data found or API call failed.",
|
||||
level: LogLevel.warning);
|
||||
log.i("Projects fetched: ${projects.length} projects loaded.");
|
||||
},
|
||||
onEmpty: () => log.w("No project data found or API call failed."),
|
||||
);
|
||||
|
||||
isLoading.value = false;
|
||||
update();
|
||||
}
|
||||
|
||||
void clearEmployees() {
|
||||
employees.clear();
|
||||
logSafe("Employees cleared", level: LogLevel.info);
|
||||
update(['employee_screen_controller']);
|
||||
}
|
||||
|
||||
Future<void> fetchAllEmployees({String? organizationId}) async {
|
||||
Future<void> fetchAllEmployees() async {
|
||||
isLoading.value = true;
|
||||
update(['employee_screen_controller']);
|
||||
|
||||
await _handleApiCall(
|
||||
() => ApiService.getAllEmployees(
|
||||
organizationId: organizationId), // pass orgId to API
|
||||
ApiService.getAllEmployees,
|
||||
onSuccess: (data) {
|
||||
employees.assignAll(data.map((json) => EmployeeModel.fromJson(json)));
|
||||
logSafe(
|
||||
"All Employees fetched: ${employees.length} employees loaded.",
|
||||
level: LogLevel.info,
|
||||
);
|
||||
},
|
||||
onEmpty: () {
|
||||
employees.clear();
|
||||
logSafe(
|
||||
"No Employee data found or API call failed",
|
||||
level: LogLevel.warning,
|
||||
);
|
||||
employees = data.map((json) => EmployeeModel.fromJson(json)).toList();
|
||||
log.i("All Employees fetched: ${employees.length} employees loaded.");
|
||||
},
|
||||
onEmpty: () => log.w("No Employee data found or API call failed."),
|
||||
);
|
||||
|
||||
isLoading.value = false;
|
||||
update(['employee_screen_controller']);
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> fetchEmployeesByProject(String projectId,
|
||||
{String? organizationId}) async {
|
||||
if (projectId.isEmpty) return;
|
||||
Future<void> fetchEmployeesByProject(String? projectId) async {
|
||||
if (projectId == null || projectId.isEmpty) {
|
||||
log.e("Project ID is required but was null or empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading.value = true;
|
||||
|
||||
await _handleApiCall(
|
||||
() => ApiService.getAllEmployeesByProject(projectId,
|
||||
organizationId: organizationId),
|
||||
() => ApiService.getAllEmployeesByProject(projectId),
|
||||
onSuccess: (data) {
|
||||
employees.assignAll(data.map((json) => EmployeeModel.fromJson(json)));
|
||||
employees = data.map((json) => EmployeeModel.fromJson(json)).toList();
|
||||
for (var emp in employees) {
|
||||
uploadingStates[emp.id] = false.obs;
|
||||
}
|
||||
},
|
||||
onEmpty: () => employees.clear(),
|
||||
);
|
||||
|
||||
isLoading.value = false;
|
||||
update(['employee_screen_controller']);
|
||||
}
|
||||
|
||||
Future<void> fetchEmployeeDetails(String? employeeId) async {
|
||||
if (employeeId == null || employeeId.isEmpty) return;
|
||||
|
||||
isLoadingEmployeeDetails.value = true;
|
||||
|
||||
await _handleSingleApiCall(
|
||||
() => ApiService.getEmployeeDetails(employeeId),
|
||||
onSuccess: (data) {
|
||||
selectedEmployeeDetails.value = EmployeeDetailsModel.fromJson(data);
|
||||
logSafe(
|
||||
"Employee details loaded for $employeeId",
|
||||
level: LogLevel.info,
|
||||
);
|
||||
log.i("Employees fetched: ${employees.length} for project $projectId");
|
||||
update();
|
||||
},
|
||||
onEmpty: () {
|
||||
selectedEmployeeDetails.value = null;
|
||||
logSafe(
|
||||
"No employee details found for $employeeId",
|
||||
level: LogLevel.warning,
|
||||
);
|
||||
},
|
||||
onError: (e) {
|
||||
selectedEmployeeDetails.value = null;
|
||||
logSafe(
|
||||
"Error fetching employee details for $employeeId",
|
||||
level: LogLevel.error,
|
||||
error: e,
|
||||
);
|
||||
log.w("No employees found for project $projectId.");
|
||||
employees = [];
|
||||
update();
|
||||
},
|
||||
onError: (e) =>
|
||||
log.e("Error fetching employees for project $projectId: $e"),
|
||||
);
|
||||
|
||||
isLoadingEmployeeDetails.value = false;
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
||||
Future<void> _handleApiCall(
|
||||
@ -166,11 +100,32 @@ class EmployeesScreenController extends GetxController {
|
||||
if (onError != null) {
|
||||
onError(e);
|
||||
} else {
|
||||
logSafe("API call error", level: LogLevel.error, error: e);
|
||||
log.e("API call error: $e");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchEmployeeDetails(String? employeeId) async {
|
||||
if (employeeId == null || employeeId.isEmpty) return;
|
||||
|
||||
isLoadingEmployeeDetails.value = true;
|
||||
|
||||
await _handleSingleApiCall(
|
||||
() => ApiService.getEmployeeDetails(employeeId),
|
||||
onSuccess: (data) {
|
||||
selectedEmployeeDetails.value = EmployeeDetailsModel.fromJson(data);
|
||||
},
|
||||
onEmpty: () {
|
||||
selectedEmployeeDetails.value = null;
|
||||
},
|
||||
onError: (e) {
|
||||
selectedEmployeeDetails.value = null;
|
||||
},
|
||||
);
|
||||
|
||||
isLoadingEmployeeDetails.value = false;
|
||||
}
|
||||
|
||||
Future<void> _handleSingleApiCall(
|
||||
Future<Map<String, dynamic>?> Function() apiCall, {
|
||||
required Function(Map<String, dynamic>) onSuccess,
|
||||
@ -188,7 +143,7 @@ class EmployeesScreenController extends GetxController {
|
||||
if (onError != null) {
|
||||
onError(e);
|
||||
} else {
|
||||
logSafe("API call error", level: LogLevel.error, error: e);
|
||||
log.e("API call error: $e");
|
||||
}
|
||||
}
|
||||
}
|
42
lib/controller/dashboard/job_controller.dart
Normal file
@ -0,0 +1,42 @@
|
||||
import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/helpers/widgets/my_text_utils.dart';
|
||||
import 'package:marco/model/chart_model.dart';
|
||||
import 'package:marco/model/job_recent_application_model.dart';
|
||||
import 'package:syncfusion_flutter_charts/charts.dart';
|
||||
|
||||
class JobController extends MyController {
|
||||
int isSelectedListingPerformanceTime = 0;
|
||||
List<ChartSampleData>? chartData;
|
||||
TooltipBehavior? columnToolTip;
|
||||
List<JobRecentApplicationModel> recentApplication = [];
|
||||
List<String> dummyTexts = List.generate(12, (index) => MyTextUtils.getDummyText(60));
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
chartData = <ChartSampleData>[
|
||||
ChartSampleData(x: 'Jan', y: 4, secondSeriesYValue: 8),
|
||||
ChartSampleData(x: 'Feb', y: 9, secondSeriesYValue: 7),
|
||||
ChartSampleData(x: 'Mar', y: 6, secondSeriesYValue: 5),
|
||||
ChartSampleData(x: 'Apr', y: 8, secondSeriesYValue: 3),
|
||||
ChartSampleData(x: 'May', y: 7, secondSeriesYValue: 9),
|
||||
ChartSampleData(x: 'Jun', y: 10, secondSeriesYValue: 6),
|
||||
ChartSampleData(x: 'Jul', y: 5, secondSeriesYValue: 4),
|
||||
ChartSampleData(x: 'Aug', y: 3, secondSeriesYValue: 2),
|
||||
ChartSampleData(x: 'Sep', y: 6, secondSeriesYValue: 10),
|
||||
ChartSampleData(x: 'Oct', y: 4, secondSeriesYValue: 8),
|
||||
ChartSampleData(x: 'Nov', y: 9, secondSeriesYValue: 6),
|
||||
ChartSampleData(x: 'Dec', y: 7, secondSeriesYValue: 5),
|
||||
];
|
||||
columnToolTip = TooltipBehavior(enable: true);
|
||||
JobRecentApplicationModel.dummyList.then((value) {
|
||||
recentApplication = value.sublist(0, 5);
|
||||
update();
|
||||
});
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
void onSelectListingPerformanceTimeToggle(index) {
|
||||
isSelectedListingPerformanceTime = index;
|
||||
update();
|
||||
}
|
||||
}
|
46
lib/controller/dashboard/project_controller.dart
Normal file
@ -0,0 +1,46 @@
|
||||
import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/model/chart_model.dart';
|
||||
import 'package:marco/model/project_summary_model.dart';
|
||||
import 'package:marco/model/task_list_model.dart';
|
||||
import 'package:syncfusion_flutter_charts/charts.dart';
|
||||
|
||||
class ProjectController extends MyController {
|
||||
TooltipBehavior? tooltipBehavior;
|
||||
List<TaskListModel> task = [];
|
||||
List<ProjectSummaryModel> projectSummary = [];
|
||||
List<ChartSampleData>? chartData;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
TaskListModel.dummyList.then((value) {
|
||||
task = value;
|
||||
update();
|
||||
});
|
||||
ProjectSummaryModel.dummyList.then((value) {
|
||||
projectSummary = value.sublist(0, 5);
|
||||
update();
|
||||
});
|
||||
chartData = <ChartSampleData>[
|
||||
ChartSampleData(x: 'Jan', y: 10, secondSeriesYValue: 8, thirdSeriesYValue: 12),
|
||||
ChartSampleData(x: 'Feb', y: 5, secondSeriesYValue: 6, thirdSeriesYValue: 7),
|
||||
ChartSampleData(x: 'Mar', y: 11, secondSeriesYValue: 9, thirdSeriesYValue: 6),
|
||||
ChartSampleData(x: 'Apr', y: 14, secondSeriesYValue: 10, thirdSeriesYValue: 13),
|
||||
ChartSampleData(x: 'May', y: 9, secondSeriesYValue: 7, thirdSeriesYValue: 5),
|
||||
ChartSampleData(x: 'Jun', y: 8, secondSeriesYValue: 12, thirdSeriesYValue: 11),
|
||||
ChartSampleData(x: 'Jul', y: 12, secondSeriesYValue: 11, thirdSeriesYValue: 9),
|
||||
ChartSampleData(x: 'Aug', y: 7, secondSeriesYValue: 13, thirdSeriesYValue: 10),
|
||||
ChartSampleData(x: 'Sep', y: 6, secondSeriesYValue: 5, thirdSeriesYValue: 8),
|
||||
ChartSampleData(x: 'Oct', y: 4, secondSeriesYValue: 14, thirdSeriesYValue: 15),
|
||||
ChartSampleData(x: 'Nov', y: 13, secondSeriesYValue: 4, thirdSeriesYValue: 11),
|
||||
ChartSampleData(x: 'Dec', y: 15, secondSeriesYValue: 3, thirdSeriesYValue: 4)
|
||||
];
|
||||
|
||||
tooltipBehavior = TooltipBehavior(enable: true, format: 'point.x : point.ym');
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
void onSelectTask(TaskListModel task) {
|
||||
task.isSelectTask = !task.isSelectTask;
|
||||
update();
|
||||
}
|
||||
}
|
56
lib/controller/dashboard/sales_controller.dart
Normal file
@ -0,0 +1,56 @@
|
||||
import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/model/chart_model.dart';
|
||||
import 'package:marco/model/recent_order_model.dart';
|
||||
import 'package:syncfusion_flutter_charts/charts.dart';
|
||||
|
||||
class SalesController extends MyController {
|
||||
List<ChartData>? statisticsData;
|
||||
List<RecentOrderModel> recentOrder = [];
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
RecentOrderModel.dummyList.then((value) {
|
||||
recentOrder = value;
|
||||
update();
|
||||
});
|
||||
|
||||
statisticsData = <ChartData>[
|
||||
ChartData(2005, 15, 25),
|
||||
ChartData(2006, 40, 55),
|
||||
ChartData(2007, 50, 70),
|
||||
ChartData(2008, 55, 80),
|
||||
ChartData(2009, 65, 85),
|
||||
ChartData(2010, 70, 95),
|
||||
ChartData(2011, 90, 110)
|
||||
];
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
final List<ChartSampleData> visitorChartData = [
|
||||
ChartSampleData(x: 'Jan', y: 12, yValue: 1200),
|
||||
ChartSampleData(x: 'Feb', y: 18, yValue: 1800),
|
||||
ChartSampleData(x: 'Mar', y: 22, yValue: 2200),
|
||||
ChartSampleData(x: 'Apr', y: 10, yValue: 1000),
|
||||
ChartSampleData(x: 'May', y: 25, yValue: 2500),
|
||||
ChartSampleData(x: 'Jun', y: 35, yValue: 3500),
|
||||
ChartSampleData(x: 'Jul', y: 28, yValue: 2800),
|
||||
ChartSampleData(x: 'Aug', y: 45, yValue: 4500),
|
||||
ChartSampleData(x: 'Sep', y: 50, yValue: 5000),
|
||||
ChartSampleData(x: 'Oct', y: 60, yValue: 6000),
|
||||
ChartSampleData(x: 'Nov', y: 42, yValue: 4200),
|
||||
ChartSampleData(x: 'Dec', y: 55, yValue: 5500),
|
||||
];
|
||||
|
||||
final TooltipBehavior visitorChart = TooltipBehavior(
|
||||
enable: true,
|
||||
format: 'point.x : point.yValue1 : point.yValue2',
|
||||
);
|
||||
}
|
||||
|
||||
class ChartData {
|
||||
ChartData(this.x, this.y, this.y2);
|
||||
|
||||
final double x;
|
||||
final double y;
|
||||
final double y2;
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/controller/directory/directory_controller.dart';
|
||||
import 'package:marco/controller/directory/notes_controller.dart';
|
||||
|
||||
class AddCommentController extends GetxController {
|
||||
final String contactId;
|
||||
|
||||
AddCommentController({required this.contactId});
|
||||
|
||||
final RxString note = ''.obs;
|
||||
final RxBool isSubmitting = false.obs;
|
||||
|
||||
Future<void> submitComment() async {
|
||||
if (note.value.trim().isEmpty) {
|
||||
showAppSnackbar(
|
||||
title: "Missing Comment",
|
||||
message: "Please enter a comment before submitting.",
|
||||
type: SnackbarType.warning,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
isSubmitting.value = true;
|
||||
|
||||
try {
|
||||
logSafe("Submitting comment for contactId: $contactId");
|
||||
|
||||
final success = await ApiService.addContactComment(
|
||||
note.value.trim(),
|
||||
contactId,
|
||||
);
|
||||
|
||||
if (success) {
|
||||
logSafe("Comment added successfully.");
|
||||
|
||||
// Refresh UI
|
||||
final directoryController = Get.find<DirectoryController>();
|
||||
await directoryController.fetchCommentsForContact(contactId);
|
||||
|
||||
final notesController = Get.find<NotesController>();
|
||||
await notesController.fetchNotes(
|
||||
pageSize: 1000, pageNumber: 1); // ✅ Fixed here
|
||||
|
||||
Get.back(result: true);
|
||||
|
||||
showAppSnackbar(
|
||||
title: "Comment Added",
|
||||
message: "Your comment has been successfully added.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
logSafe("Error while submitting comment: $e", level: LogLevel.error);
|
||||
showAppSnackbar(
|
||||
title: "Unexpected Error",
|
||||
message: "Something went wrong while adding your comment.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
} finally {
|
||||
isSubmitting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
void updateNote(String value) {
|
||||
note.value = value;
|
||||
logSafe("Note updated: ${value.trim()}");
|
||||
}
|
||||
}
|
@ -1,316 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
|
||||
class AddContactController extends GetxController {
|
||||
final RxList<String> categories = <String>[].obs;
|
||||
final RxList<String> buckets = <String>[].obs;
|
||||
final RxList<String> globalProjects = <String>[].obs;
|
||||
final RxList<String> tags = <String>[].obs;
|
||||
|
||||
final RxString selectedCategory = ''.obs;
|
||||
final RxList<String> selectedBuckets = <String>[].obs;
|
||||
final RxString selectedProject = ''.obs;
|
||||
|
||||
final RxList<String> enteredTags = <String>[].obs;
|
||||
final RxList<String> filteredSuggestions = <String>[].obs;
|
||||
final RxList<String> organizationNames = <String>[].obs;
|
||||
final RxList<String> filteredOrgSuggestions = <String>[].obs;
|
||||
|
||||
final RxMap<String, String> categoriesMap = <String, String>{}.obs;
|
||||
final RxMap<String, String> bucketsMap = <String, String>{}.obs;
|
||||
final RxMap<String, String> projectsMap = <String, String>{}.obs;
|
||||
final RxMap<String, String> tagsMap = <String, String>{}.obs;
|
||||
final RxBool isInitialized = false.obs;
|
||||
final RxList<String> selectedProjects = <String>[].obs;
|
||||
final RxBool isSubmitting = false.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
logSafe("AddContactController initialized", level: LogLevel.debug);
|
||||
fetchInitialData();
|
||||
}
|
||||
|
||||
Future<void> fetchInitialData() async {
|
||||
logSafe("Fetching initial dropdown data", level: LogLevel.debug);
|
||||
await Future.wait([
|
||||
fetchBuckets(),
|
||||
fetchGlobalProjects(),
|
||||
fetchTags(),
|
||||
fetchCategories(),
|
||||
fetchOrganizationNames(),
|
||||
]);
|
||||
|
||||
// ✅ Mark initialization as done
|
||||
isInitialized.value = true;
|
||||
}
|
||||
|
||||
void resetForm() {
|
||||
selectedCategory.value = '';
|
||||
selectedProject.value = '';
|
||||
selectedBuckets.clear();
|
||||
enteredTags.clear();
|
||||
filteredSuggestions.clear();
|
||||
filteredOrgSuggestions.clear();
|
||||
selectedProjects.clear();
|
||||
}
|
||||
|
||||
Future<void> fetchBuckets() async {
|
||||
try {
|
||||
final response = await ApiService.getContactBucketList();
|
||||
if (response != null && response['data'] is List) {
|
||||
final names = <String>[];
|
||||
for (var item in response['data']) {
|
||||
if (item['name'] != null && item['id'] != null) {
|
||||
bucketsMap[item['name']] = item['id'].toString();
|
||||
names.add(item['name']);
|
||||
}
|
||||
}
|
||||
buckets.assignAll(names);
|
||||
logSafe("Fetched \${names.length} buckets");
|
||||
}
|
||||
} catch (e) {
|
||||
logSafe("Failed to fetch buckets: \$e", level: LogLevel.error);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchOrganizationNames() async {
|
||||
try {
|
||||
final orgs = await ApiService.getOrganizationList();
|
||||
organizationNames.assignAll(orgs);
|
||||
logSafe("Fetched \${orgs.length} organization names");
|
||||
} catch (e) {
|
||||
logSafe("Failed to load organization names: \$e", level: LogLevel.error);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> submitContact({
|
||||
String? id,
|
||||
required String name,
|
||||
required String organization,
|
||||
required List<Map<String, String>> emails,
|
||||
required List<Map<String, String>> phones,
|
||||
required String address,
|
||||
required String description,
|
||||
String? designation,
|
||||
}) async {
|
||||
if (isSubmitting.value) return;
|
||||
isSubmitting.value = true;
|
||||
|
||||
final categoryId = categoriesMap[selectedCategory.value];
|
||||
final bucketIds = selectedBuckets
|
||||
.map((name) => bucketsMap[name])
|
||||
.whereType<String>()
|
||||
.toList();
|
||||
|
||||
if (bucketIds.isEmpty) {
|
||||
showAppSnackbar(
|
||||
title: "Missing Buckets",
|
||||
message: "Please select at least one bucket.",
|
||||
type: SnackbarType.warning,
|
||||
);
|
||||
isSubmitting.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
final projectIds = selectedProjects
|
||||
.map((name) => projectsMap[name])
|
||||
.whereType<String>()
|
||||
.toList();
|
||||
|
||||
if (name.trim().isEmpty) {
|
||||
showAppSnackbar(
|
||||
title: "Missing Name",
|
||||
message: "Please enter the contact name.",
|
||||
type: SnackbarType.warning,
|
||||
);
|
||||
isSubmitting.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (organization.trim().isEmpty) {
|
||||
showAppSnackbar(
|
||||
title: "Missing Organization",
|
||||
message: "Please enter the organization name.",
|
||||
type: SnackbarType.warning,
|
||||
);
|
||||
isSubmitting.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedBuckets.isEmpty) {
|
||||
showAppSnackbar(
|
||||
title: "Missing Bucket",
|
||||
message: "Please select at least one bucket.",
|
||||
type: SnackbarType.warning,
|
||||
);
|
||||
isSubmitting.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final tagObjects = enteredTags.map((tagName) {
|
||||
final tagId = tagsMap[tagName];
|
||||
return tagId != null
|
||||
? {"id": tagId, "name": tagName}
|
||||
: {"name": tagName};
|
||||
}).toList();
|
||||
|
||||
final body = {
|
||||
if (id != null) "id": id,
|
||||
"name": name.trim(),
|
||||
"organization": organization.trim(),
|
||||
if (selectedCategory.value.isNotEmpty && categoryId != null)
|
||||
"contactCategoryId": categoryId,
|
||||
if (projectIds.isNotEmpty) "projectIds": projectIds,
|
||||
"bucketIds": bucketIds,
|
||||
if (enteredTags.isNotEmpty) "tags": tagObjects,
|
||||
if (emails.isNotEmpty) "contactEmails": emails,
|
||||
if (phones.isNotEmpty) "contactPhones": phones,
|
||||
if (address.trim().isNotEmpty) "address": address.trim(),
|
||||
if (description.trim().isNotEmpty) "description": description.trim(),
|
||||
if (designation != null && designation.trim().isNotEmpty)
|
||||
"designation": designation.trim(),
|
||||
};
|
||||
|
||||
logSafe("${id != null ? 'Updating' : 'Creating'} contact");
|
||||
|
||||
final response = id != null
|
||||
? await ApiService.updateContact(id, body)
|
||||
: await ApiService.createContact(body);
|
||||
|
||||
if (response == true) {
|
||||
Get.back(result: true);
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: id != null
|
||||
? "Contact updated successfully"
|
||||
: "Contact created successfully",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
} else {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to ${id != null ? 'update' : 'create'} contact",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
logSafe("Submit contact error: $e", level: LogLevel.error);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Something went wrong",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
} finally {
|
||||
isSubmitting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
void filterOrganizationSuggestions(String query) {
|
||||
if (query.trim().isEmpty) {
|
||||
filteredOrgSuggestions.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
final lower = query.toLowerCase();
|
||||
filteredOrgSuggestions.assignAll(
|
||||
organizationNames
|
||||
.where((name) => name.toLowerCase().contains(lower))
|
||||
.toList(),
|
||||
);
|
||||
logSafe("Filtered organization suggestions for: \$query",
|
||||
level: LogLevel.debug);
|
||||
}
|
||||
|
||||
Future<void> fetchGlobalProjects() async {
|
||||
try {
|
||||
final response = await ApiService.getGlobalProjects();
|
||||
if (response != null) {
|
||||
final names = <String>[];
|
||||
for (var item in response) {
|
||||
final name = item['name']?.toString().trim();
|
||||
final id = item['id']?.toString().trim();
|
||||
if (name != null && id != null && name.isNotEmpty) {
|
||||
projectsMap[name] = id;
|
||||
names.add(name);
|
||||
}
|
||||
}
|
||||
globalProjects.assignAll(names);
|
||||
logSafe("Fetched \${names.length} global projects");
|
||||
}
|
||||
} catch (e) {
|
||||
logSafe("Failed to fetch global projects: \$e", level: LogLevel.error);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchTags() async {
|
||||
try {
|
||||
final response = await ApiService.getContactTagList();
|
||||
if (response != null && response['data'] is List) {
|
||||
tags.assignAll(List<String>.from(
|
||||
response['data'].map((e) => e['name'] ?? '').where((e) => e != ''),
|
||||
));
|
||||
logSafe("Fetched \${tags.length} tags");
|
||||
}
|
||||
} catch (e) {
|
||||
logSafe("Failed to fetch tags: \$e", level: LogLevel.error);
|
||||
}
|
||||
}
|
||||
|
||||
void filterSuggestions(String query) {
|
||||
if (query.trim().isEmpty) {
|
||||
filteredSuggestions.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
final lower = query.toLowerCase();
|
||||
filteredSuggestions.assignAll(
|
||||
tags
|
||||
.where((tag) =>
|
||||
tag.toLowerCase().contains(lower) && !enteredTags.contains(tag))
|
||||
.toList(),
|
||||
);
|
||||
logSafe("Filtered tag suggestions for: \$query", level: LogLevel.debug);
|
||||
}
|
||||
|
||||
void clearSuggestions() {
|
||||
filteredSuggestions.clear();
|
||||
logSafe("Cleared tag suggestions", level: LogLevel.debug);
|
||||
}
|
||||
|
||||
Future<void> fetchCategories() async {
|
||||
try {
|
||||
final response = await ApiService.getContactCategoryList();
|
||||
if (response != null && response['data'] is List) {
|
||||
final names = <String>[];
|
||||
for (var item in response['data']) {
|
||||
final name = item['name']?.toString().trim();
|
||||
final id = item['id']?.toString().trim();
|
||||
if (name != null && id != null && name.isNotEmpty) {
|
||||
categoriesMap[name] = id;
|
||||
names.add(name);
|
||||
}
|
||||
}
|
||||
categories.assignAll(names);
|
||||
logSafe("Fetched \${names.length} contact categories");
|
||||
}
|
||||
} catch (e) {
|
||||
logSafe("Failed to fetch categories: \$e", level: LogLevel.error);
|
||||
}
|
||||
}
|
||||
|
||||
void addEnteredTag(String tag) {
|
||||
if (tag.trim().isNotEmpty && !enteredTags.contains(tag.trim())) {
|
||||
enteredTags.add(tag.trim());
|
||||
logSafe("Added tag: \$tag", level: LogLevel.debug);
|
||||
}
|
||||
}
|
||||
|
||||
void removeEnteredTag(String tag) {
|
||||
enteredTags.remove(tag);
|
||||
logSafe("Removed tag: \$tag", level: LogLevel.debug);
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
|
||||
class BucketController extends GetxController {
|
||||
RxBool isCreating = false.obs;
|
||||
final RxString name = ''.obs;
|
||||
final RxString description = ''.obs;
|
||||
|
||||
Future<void> createBucket() async {
|
||||
if (name.value.trim().isEmpty) {
|
||||
showAppSnackbar(
|
||||
title: "Missing Name",
|
||||
message: "Bucket name is required.",
|
||||
type: SnackbarType.warning,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
isCreating.value = true;
|
||||
|
||||
try {
|
||||
logSafe("Creating bucket: ${name.value}");
|
||||
|
||||
final success = await ApiService.createBucket(
|
||||
name: name.value.trim(),
|
||||
description: description.value.trim(),
|
||||
);
|
||||
|
||||
if (success) {
|
||||
logSafe("Bucket created successfully");
|
||||
|
||||
Get.back(result: true); // Close bottom sheet/dialog
|
||||
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "Bucket has been created successfully.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
} else {
|
||||
logSafe("Bucket creation failed", level: LogLevel.error);
|
||||
showAppSnackbar(
|
||||
title: "Creation Failed",
|
||||
message: "Unable to create bucket. Please try again later.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
logSafe("Error during bucket creation: $e", level: LogLevel.error);
|
||||
showAppSnackbar(
|
||||
title: "Unexpected Error",
|
||||
message: "Something went wrong. Please try again.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
} finally {
|
||||
isCreating.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
void updateName(String value) {
|
||||
name.value = value;
|
||||
logSafe("Bucket name updated: ${value.trim()}");
|
||||
}
|
||||
|
||||
void updateDescription(String value) {
|
||||
description.value = value;
|
||||
logSafe("Bucket description updated: ${value.trim()}");
|
||||
}
|
||||
}
|
@ -1,390 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/model/directory/contact_model.dart';
|
||||
import 'package:marco/model/directory/contact_bucket_list_model.dart';
|
||||
import 'package:marco/model/directory/directory_comment_model.dart';
|
||||
|
||||
class DirectoryController extends GetxController {
|
||||
// -------------------- CONTACTS --------------------
|
||||
RxList<ContactModel> allContacts = <ContactModel>[].obs;
|
||||
RxList<ContactModel> filteredContacts = <ContactModel>[].obs;
|
||||
RxList<ContactCategory> contactCategories = <ContactCategory>[].obs;
|
||||
RxList<String> selectedCategories = <String>[].obs;
|
||||
RxList<String> selectedBuckets = <String>[].obs;
|
||||
RxBool isActive = true.obs;
|
||||
RxBool isLoading = false.obs;
|
||||
RxList<ContactBucket> contactBuckets = <ContactBucket>[].obs;
|
||||
RxString searchQuery = ''.obs;
|
||||
|
||||
// -------------------- COMMENTS --------------------
|
||||
final Map<String, RxList<DirectoryComment>> activeCommentsMap = {};
|
||||
final Map<String, RxList<DirectoryComment>> inactiveCommentsMap = {};
|
||||
final editingCommentId = Rxn<String>();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchContacts();
|
||||
fetchBuckets();
|
||||
}
|
||||
|
||||
// -------------------- COMMENTS HANDLING --------------------
|
||||
|
||||
RxList<DirectoryComment> getCommentsForContact(String contactId,
|
||||
{bool active = true}) {
|
||||
return active
|
||||
? activeCommentsMap[contactId] ?? <DirectoryComment>[].obs
|
||||
: inactiveCommentsMap[contactId] ?? <DirectoryComment>[].obs;
|
||||
}
|
||||
|
||||
Future<void> fetchCommentsForContact(String contactId,
|
||||
{bool active = true}) async {
|
||||
try {
|
||||
final data =
|
||||
await ApiService.getDirectoryComments(contactId, active: active);
|
||||
var comments =
|
||||
data?.map((e) => DirectoryComment.fromJson(e)).toList() ?? [];
|
||||
|
||||
// ✅ Deduplicate by ID before storing
|
||||
final Map<String, DirectoryComment> uniqueMap = {
|
||||
for (var c in comments) c.id: c,
|
||||
};
|
||||
comments = uniqueMap.values.toList()
|
||||
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||
|
||||
if (active) {
|
||||
activeCommentsMap[contactId] = <DirectoryComment>[].obs
|
||||
..assignAll(comments);
|
||||
} else {
|
||||
inactiveCommentsMap[contactId] = <DirectoryComment>[].obs
|
||||
..assignAll(comments);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
logSafe("Error fetching ${active ? 'active' : 'inactive'} comments: $e",
|
||||
level: LogLevel.error);
|
||||
logSafe(stack.toString(), level: LogLevel.debug);
|
||||
|
||||
if (active) {
|
||||
activeCommentsMap[contactId] = <DirectoryComment>[].obs;
|
||||
} else {
|
||||
inactiveCommentsMap[contactId] = <DirectoryComment>[].obs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<DirectoryComment> combinedComments(String contactId) {
|
||||
final activeList = getCommentsForContact(contactId, active: true);
|
||||
final inactiveList = getCommentsForContact(contactId, active: false);
|
||||
|
||||
// ✅ Deduplicate by ID (active wins)
|
||||
final Map<String, DirectoryComment> byId = {};
|
||||
for (final c in inactiveList) {
|
||||
byId[c.id] = c;
|
||||
}
|
||||
for (final c in activeList) {
|
||||
byId[c.id] = c;
|
||||
}
|
||||
|
||||
final combined = byId.values.toList()
|
||||
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||
return combined;
|
||||
}
|
||||
|
||||
Future<void> updateComment(DirectoryComment comment) async {
|
||||
try {
|
||||
final existing = getCommentsForContact(comment.contactId)
|
||||
.firstWhereOrNull((c) => c.id == comment.id);
|
||||
|
||||
if (existing != null && existing.note.trim() == comment.note.trim()) {
|
||||
showAppSnackbar(
|
||||
title: "No Changes",
|
||||
message: "No changes were made to the comment.",
|
||||
type: SnackbarType.info,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final success = await ApiService.updateContactComment(
|
||||
comment.id, comment.note, comment.contactId);
|
||||
|
||||
if (success) {
|
||||
await fetchCommentsForContact(comment.contactId, active: true);
|
||||
await fetchCommentsForContact(comment.contactId, active: false);
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "Comment updated successfully.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
} else {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to update comment.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
logSafe("Update comment failed: $e", level: LogLevel.error);
|
||||
logSafe(stack.toString(), level: LogLevel.debug);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to update comment.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteComment(String commentId, String contactId) async {
|
||||
try {
|
||||
final success = await ApiService.restoreContactComment(commentId, false);
|
||||
|
||||
if (success) {
|
||||
if (editingCommentId.value == commentId) editingCommentId.value = null;
|
||||
await fetchCommentsForContact(contactId, active: true);
|
||||
await fetchCommentsForContact(contactId, active: false);
|
||||
showAppSnackbar(
|
||||
title: "Deleted",
|
||||
message: "Comment deleted successfully.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
} else {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to delete comment.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
logSafe("Delete comment failed: $e", level: LogLevel.error);
|
||||
logSafe(stack.toString(), level: LogLevel.debug);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Something went wrong while deleting comment.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> restoreComment(String commentId, String contactId) async {
|
||||
try {
|
||||
final success = await ApiService.restoreContactComment(commentId, true);
|
||||
|
||||
if (success) {
|
||||
await fetchCommentsForContact(contactId, active: true);
|
||||
await fetchCommentsForContact(contactId, active: false);
|
||||
showAppSnackbar(
|
||||
title: "Restored",
|
||||
message: "Comment restored successfully.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
} else {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to restore comment.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
logSafe("Restore comment failed: $e", level: LogLevel.error);
|
||||
logSafe(stack.toString(), level: LogLevel.debug);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Something went wrong while restoring comment.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------- CONTACTS HANDLING --------------------
|
||||
|
||||
Future<void> fetchBuckets() async {
|
||||
try {
|
||||
final response = await ApiService.getContactBucketList();
|
||||
if (response != null && response['data'] is List) {
|
||||
final buckets = (response['data'] as List)
|
||||
.map((e) => ContactBucket.fromJson(e))
|
||||
.toList();
|
||||
contactBuckets.assignAll(buckets);
|
||||
} else {
|
||||
contactBuckets.clear();
|
||||
}
|
||||
} catch (e) {
|
||||
logSafe("Bucket fetch error: $e", level: LogLevel.error);
|
||||
}
|
||||
}
|
||||
// -------------------- CONTACT DELETION / RESTORE --------------------
|
||||
|
||||
Future<void> deleteContact(String contactId) async {
|
||||
try {
|
||||
final success = await ApiService.deleteDirectoryContact(contactId);
|
||||
if (success) {
|
||||
// Refresh contacts after deletion
|
||||
await fetchContacts(active: true);
|
||||
await fetchContacts(active: false);
|
||||
showAppSnackbar(
|
||||
title: "Deleted",
|
||||
message: "Contact deleted successfully.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
} else {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to delete contact.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
logSafe("Delete contact failed: $e", level: LogLevel.error);
|
||||
logSafe(stack.toString(), level: LogLevel.debug);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Something went wrong while deleting contact.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> restoreContact(String contactId) async {
|
||||
try {
|
||||
final success = await ApiService.restoreDirectoryContact(contactId);
|
||||
if (success) {
|
||||
// Refresh contacts after restore
|
||||
await fetchContacts(active: true);
|
||||
await fetchContacts(active: false);
|
||||
showAppSnackbar(
|
||||
title: "Restored",
|
||||
message: "Contact restored successfully.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
} else {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to restore contact.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
logSafe("Restore contact failed: $e", level: LogLevel.error);
|
||||
logSafe(stack.toString(), level: LogLevel.debug);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Something went wrong while restoring contact.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchContacts({bool active = true}) async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
final response = await ApiService.getDirectoryData(isActive: active);
|
||||
|
||||
if (response != null) {
|
||||
final contacts = response.map((e) => ContactModel.fromJson(e)).toList();
|
||||
allContacts.assignAll(contacts);
|
||||
extractCategoriesFromContacts();
|
||||
applyFilters();
|
||||
} else {
|
||||
allContacts.clear();
|
||||
filteredContacts.clear();
|
||||
}
|
||||
} catch (e) {
|
||||
logSafe("Directory fetch error: $e", level: LogLevel.error);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
void extractCategoriesFromContacts() {
|
||||
final uniqueCategories = <String, ContactCategory>{};
|
||||
for (final contact in allContacts) {
|
||||
final category = contact.contactCategory;
|
||||
if (category != null) {
|
||||
uniqueCategories.putIfAbsent(category.id, () => category);
|
||||
}
|
||||
}
|
||||
contactCategories.value = uniqueCategories.values.toList();
|
||||
}
|
||||
|
||||
void applyFilters() {
|
||||
final query = searchQuery.value.toLowerCase();
|
||||
|
||||
filteredContacts.value = allContacts.where((contact) {
|
||||
final categoryMatch = selectedCategories.isEmpty ||
|
||||
(contact.contactCategory != null &&
|
||||
selectedCategories.contains(contact.contactCategory!.id));
|
||||
|
||||
final bucketMatch = selectedBuckets.isEmpty ||
|
||||
contact.bucketIds.any((id) => selectedBuckets.contains(id));
|
||||
|
||||
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)
|
||||
?.name
|
||||
.toLowerCase() ??
|
||||
'';
|
||||
return bucketName.contains(query);
|
||||
});
|
||||
|
||||
final searchMatch = query.isEmpty ||
|
||||
nameMatch ||
|
||||
orgMatch ||
|
||||
emailMatch ||
|
||||
phoneMatch ||
|
||||
tagMatch ||
|
||||
categoryNameMatch ||
|
||||
bucketNameMatch;
|
||||
|
||||
return categoryMatch && bucketMatch && searchMatch;
|
||||
}).toList();
|
||||
|
||||
filteredContacts
|
||||
.sort((a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()));
|
||||
}
|
||||
|
||||
void toggleCategory(String categoryId) {
|
||||
if (selectedCategories.contains(categoryId)) {
|
||||
selectedCategories.remove(categoryId);
|
||||
} else {
|
||||
selectedCategories.add(categoryId);
|
||||
}
|
||||
}
|
||||
|
||||
void toggleBucket(String bucketId) {
|
||||
if (selectedBuckets.contains(bucketId)) {
|
||||
selectedBuckets.remove(bucketId);
|
||||
} else {
|
||||
selectedBuckets.add(bucketId);
|
||||
}
|
||||
}
|
||||
|
||||
void updateSearchQuery(String value) {
|
||||
searchQuery.value = value;
|
||||
applyFilters();
|
||||
}
|
||||
|
||||
String getBucketNames(ContactModel contact, List<ContactBucket> allBuckets) {
|
||||
return contact.bucketIds
|
||||
.map((id) => allBuckets.firstWhereOrNull((b) => b.id == id)?.name ?? '')
|
||||
.where((name) => name.isNotEmpty)
|
||||
.join(', ');
|
||||
}
|
||||
|
||||
bool hasActiveFilters() {
|
||||
return selectedCategories.isNotEmpty ||
|
||||
selectedBuckets.isNotEmpty ||
|
||||
searchQuery.value.trim().isNotEmpty;
|
||||
}
|
||||
}
|
@ -1,152 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/model/employees/employee_model.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/controller/directory/directory_controller.dart';
|
||||
|
||||
class ManageBucketController extends GetxController {
|
||||
RxList<EmployeeModel> allEmployees = <EmployeeModel>[].obs;
|
||||
RxBool isLoading = false.obs;
|
||||
|
||||
final DirectoryController directoryController = Get.find();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchAllEmployees();
|
||||
}
|
||||
|
||||
Future<bool> updateBucket({
|
||||
required String id,
|
||||
required String name,
|
||||
required String description,
|
||||
required List<String> employeeIds,
|
||||
required List<String> originalEmployeeIds,
|
||||
}) async {
|
||||
isLoading(true);
|
||||
update();
|
||||
|
||||
try {
|
||||
final updated = await ApiService.updateBucket(
|
||||
id: id,
|
||||
name: name,
|
||||
description: description,
|
||||
);
|
||||
|
||||
if (!updated) {
|
||||
showAppSnackbar(
|
||||
title: "Update Failed",
|
||||
message: "Unable to update bucket details.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
isLoading(false);
|
||||
update();
|
||||
return false;
|
||||
}
|
||||
|
||||
final allInvolvedIds = {...originalEmployeeIds, ...employeeIds}.toList();
|
||||
|
||||
final assignPayload = allInvolvedIds.map((empId) {
|
||||
return {
|
||||
"employeeId": empId,
|
||||
"isActive": employeeIds.contains(empId),
|
||||
};
|
||||
}).toList();
|
||||
|
||||
final assigned = await ApiService.assignEmployeesToBucket(
|
||||
bucketId: id,
|
||||
employees: assignPayload,
|
||||
);
|
||||
|
||||
if (!assigned) {
|
||||
showAppSnackbar(
|
||||
title: "Assignment Failed",
|
||||
message: "Employees couldn't be updated.",
|
||||
type: SnackbarType.warning,
|
||||
);
|
||||
} else {
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "Bucket updated successfully.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (e, stack) {
|
||||
logSafe("Error in updateBucket: $e", level: LogLevel.error);
|
||||
logSafe("Stack: $stack", level: LogLevel.debug);
|
||||
showAppSnackbar(
|
||||
title: "Unexpected Error",
|
||||
message: "Please try again later.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return false;
|
||||
} finally {
|
||||
isLoading(false);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchAllEmployees() async {
|
||||
isLoading.value = true;
|
||||
|
||||
try {
|
||||
final response = await ApiService.getAllEmployees();
|
||||
if (response != null && response.isNotEmpty) {
|
||||
allEmployees.assignAll(
|
||||
response.map((json) => EmployeeModel.fromJson(json)));
|
||||
logSafe(
|
||||
"All Employees fetched for Manage Bucket: ${allEmployees.length}",
|
||||
level: LogLevel.info,
|
||||
);
|
||||
} else {
|
||||
allEmployees.clear();
|
||||
logSafe("No employees found for Manage Bucket.",
|
||||
level: LogLevel.warning);
|
||||
}
|
||||
} catch (e) {
|
||||
allEmployees.clear();
|
||||
logSafe("Error fetching employees in Manage Bucket",
|
||||
level: LogLevel.error, error: e);
|
||||
}
|
||||
|
||||
isLoading.value = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> deleteBucket(String bucketId) async {
|
||||
isLoading.value = true;
|
||||
update();
|
||||
|
||||
try {
|
||||
final deleted = await ApiService.deleteBucket(bucketId);
|
||||
if (deleted) {
|
||||
directoryController.contactBuckets.removeWhere((b) => b.id == bucketId);
|
||||
showAppSnackbar(
|
||||
title: "Deleted",
|
||||
message: "Bucket deleted successfully.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
} else {
|
||||
showAppSnackbar(
|
||||
title: "Delete Failed",
|
||||
message: "Unable to delete bucket.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
logSafe("Error deleting bucket: $e", level: LogLevel.error);
|
||||
logSafe("Stack: $stack", level: LogLevel.debug);
|
||||
showAppSnackbar(
|
||||
title: "Unexpected Error",
|
||||
message: "Failed to delete bucket.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,169 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/model/directory/note_list_response_model.dart';
|
||||
|
||||
class NotesController extends GetxController {
|
||||
RxList<NoteModel> notesList = <NoteModel>[].obs;
|
||||
RxBool isLoading = false.obs;
|
||||
RxnString editingNoteId = RxnString();
|
||||
RxString searchQuery = ''.obs;
|
||||
|
||||
List<NoteModel> get filteredNotesList {
|
||||
if (searchQuery.isEmpty) return notesList;
|
||||
|
||||
final query = searchQuery.value.toLowerCase();
|
||||
return notesList.where((note) {
|
||||
return note.note.toLowerCase().contains(query) ||
|
||||
note.contactName.toLowerCase().contains(query) ||
|
||||
note.organizationName.toLowerCase().contains(query) ||
|
||||
note.createdBy.firstName.toLowerCase().contains(query);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchNotes();
|
||||
}
|
||||
|
||||
Future<void> fetchNotes({int pageSize = 1000, int pageNumber = 1}) async {
|
||||
isLoading.value = true;
|
||||
logSafe(
|
||||
"📤 Fetching directory notes with pageSize=$pageSize & pageNumber=$pageNumber");
|
||||
|
||||
try {
|
||||
final response = await ApiService.getDirectoryNotes(
|
||||
pageSize: pageSize, pageNumber: pageNumber);
|
||||
logSafe("💡 Directory Notes Response: $response");
|
||||
|
||||
if (response == null) {
|
||||
logSafe("⚠️ Response is null while fetching directory notes");
|
||||
notesList.clear();
|
||||
} else {
|
||||
logSafe("💡 Directory Notes Response: $response");
|
||||
notesList.value = NotePaginationData.fromJson(response).data;
|
||||
}
|
||||
} catch (e, st) {
|
||||
logSafe("💥 Error occurred while fetching directory notes",
|
||||
error: e, stackTrace: st);
|
||||
notesList.clear();
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateNote(NoteModel updatedNote) async {
|
||||
try {
|
||||
logSafe(
|
||||
"Attempting to update note. id: ${updatedNote.id}, contactId: ${updatedNote.contactId}");
|
||||
|
||||
final oldNote = notesList.firstWhereOrNull((n) => n.id == updatedNote.id);
|
||||
|
||||
if (oldNote != null && oldNote.note.trim() == updatedNote.note.trim()) {
|
||||
logSafe("No changes detected in note. id: ${updatedNote.id}");
|
||||
showAppSnackbar(
|
||||
title: "No Changes",
|
||||
message: "No changes were made to the note.",
|
||||
type: SnackbarType.info,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final success = await ApiService.updateContactComment(
|
||||
updatedNote.id,
|
||||
updatedNote.note,
|
||||
updatedNote.contactId,
|
||||
);
|
||||
|
||||
if (success) {
|
||||
logSafe("Note updated successfully. id: ${updatedNote.id}");
|
||||
final index = notesList.indexWhere((n) => n.id == updatedNote.id);
|
||||
if (index != -1) {
|
||||
notesList[index] = updatedNote;
|
||||
notesList.refresh();
|
||||
}
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "Note updated successfully.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
} else {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to update note.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
logSafe("Update note failed: ${e.toString()}");
|
||||
logSafe("StackTrace: ${stackTrace.toString()}");
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to update note.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> restoreOrDeleteNote(NoteModel note,
|
||||
{bool restore = true}) async {
|
||||
final action = restore ? "restore" : "delete";
|
||||
|
||||
try {
|
||||
logSafe("Attempting to $action note id: ${note.id}");
|
||||
|
||||
final success = await ApiService.restoreContactComment(
|
||||
note.id,
|
||||
restore, // true = restore, false = delete
|
||||
);
|
||||
|
||||
if (success) {
|
||||
final index = notesList.indexWhere((n) => n.id == note.id);
|
||||
if (index != -1) {
|
||||
notesList[index] = note.copyWith(isActive: restore);
|
||||
notesList.refresh();
|
||||
}
|
||||
showAppSnackbar(
|
||||
title: restore ? "Restored" : "Deleted",
|
||||
message: restore
|
||||
? "Note has been restored successfully."
|
||||
: "Note has been deleted successfully.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
} else {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message:
|
||||
restore ? "Failed to restore note." : "Failed to delete note.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
} catch (e, st) {
|
||||
logSafe("$action note failed: $e", error: e, stackTrace: st);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Something went wrong while trying to $action the note.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void addNote(NoteModel note) {
|
||||
notesList.insert(0, note);
|
||||
logSafe("Note added to list");
|
||||
}
|
||||
|
||||
void deleteNote(int index) {
|
||||
if (index >= 0 && index < notesList.length) {
|
||||
notesList.removeAt(index);
|
||||
logSafe("Note removed from list at index $index");
|
||||
}
|
||||
}
|
||||
|
||||
void clearAllNotes() {
|
||||
notesList.clear();
|
||||
logSafe("All notes cleared from list");
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/model/document/document_details_model.dart';
|
||||
import 'package:marco/model/document/document_version_model.dart';
|
||||
|
||||
class DocumentDetailsController extends GetxController {
|
||||
/// Observables
|
||||
var isLoading = false.obs;
|
||||
var documentDetails = Rxn<DocumentDetailsResponse>();
|
||||
|
||||
var versions = <DocumentVersionItem>[].obs;
|
||||
var isVersionsLoading = false.obs;
|
||||
|
||||
// Loading states for buttons
|
||||
var isVerifyLoading = false.obs;
|
||||
var isRejectLoading = false.obs;
|
||||
|
||||
/// Fetch document details by id
|
||||
Future<void> fetchDocumentDetails(String documentId) async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
final response = await ApiService.getDocumentDetailsApi(documentId);
|
||||
documentDetails.value = response;
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch document versions by parentAttachmentId
|
||||
Future<void> fetchDocumentVersions(String parentAttachmentId) async {
|
||||
try {
|
||||
isVersionsLoading.value = true;
|
||||
final response = await ApiService.getDocumentVersionsApi(
|
||||
parentAttachmentId: parentAttachmentId,
|
||||
);
|
||||
if (response != null) {
|
||||
versions.assignAll(response.data.data);
|
||||
} else {
|
||||
versions.clear();
|
||||
}
|
||||
} finally {
|
||||
isVersionsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Verify document
|
||||
Future<bool> verifyDocument(String documentId) async {
|
||||
try {
|
||||
isVerifyLoading.value = true;
|
||||
final result =
|
||||
await ApiService.verifyDocumentApi(id: documentId, isVerify: true);
|
||||
if (result) await fetchDocumentDetails(documentId);
|
||||
return result;
|
||||
} finally {
|
||||
isVerifyLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Reject document
|
||||
Future<bool> rejectDocument(String documentId) async {
|
||||
try {
|
||||
isRejectLoading.value = true;
|
||||
final result =
|
||||
await ApiService.verifyDocumentApi(id: documentId, isVerify: false);
|
||||
if (result) await fetchDocumentDetails(documentId);
|
||||
return result;
|
||||
} finally {
|
||||
isRejectLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch Pre-Signed URL for a given version
|
||||
Future<String?> fetchPresignedUrl(String versionId) async {
|
||||
return await ApiService.getPresignedUrlApi(versionId);
|
||||
}
|
||||
|
||||
/// Clear data when leaving the screen
|
||||
void clearDetails() {
|
||||
documentDetails.value = null;
|
||||
versions.clear();
|
||||
}
|
||||
}
|
@ -1,239 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/model/document/master_document_type_model.dart';
|
||||
import 'package:marco/model/document/master_document_tags.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
|
||||
class DocumentUploadController extends GetxController {
|
||||
// Observables
|
||||
var isLoading = false.obs;
|
||||
var isUploading = false.obs;
|
||||
|
||||
var categories = <DocumentType>[].obs;
|
||||
var tags = <TagItem>[].obs;
|
||||
|
||||
DocumentType? selectedCategory;
|
||||
|
||||
/// --- FILE HANDLING ---
|
||||
String? selectedFileName;
|
||||
String? selectedFileBase64;
|
||||
String? selectedFileContentType;
|
||||
int? selectedFileSize;
|
||||
|
||||
/// --- TAG HANDLING ---
|
||||
final tagCtrl = TextEditingController();
|
||||
final enteredTags = <String>[].obs;
|
||||
final filteredSuggestions = <String>[].obs;
|
||||
var documentTypes = <DocumentType>[].obs;
|
||||
DocumentType? selectedType;
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchCategories();
|
||||
fetchTags();
|
||||
}
|
||||
|
||||
/// Fetch available document categories
|
||||
Future<void> fetchCategories() async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
final response = await ApiService.getMasterDocumentTypesApi();
|
||||
if (response != null && response.data.isNotEmpty) {
|
||||
categories.assignAll(response.data);
|
||||
logSafe("Fetched categories: ${categories.length}");
|
||||
} else {
|
||||
logSafe("No categories fetched", level: LogLevel.warning);
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchDocumentTypes(String categoryId) async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
final response =
|
||||
await ApiService.getDocumentTypesByCategoryApi(categoryId);
|
||||
if (response != null && response.data.isNotEmpty) {
|
||||
documentTypes.assignAll(response.data);
|
||||
selectedType = null; // reset previous type
|
||||
} else {
|
||||
documentTypes.clear();
|
||||
selectedType = null;
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> fetchPresignedUrl(String versionId) async {
|
||||
return await ApiService.getPresignedUrlApi(versionId);
|
||||
}
|
||||
|
||||
/// Fetch available document tags
|
||||
Future<void> fetchTags() async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
final response = await ApiService.getMasterDocumentTagsApi();
|
||||
if (response != null) {
|
||||
tags.assignAll(response.data);
|
||||
logSafe("Fetched tags: ${tags.length}");
|
||||
} else {
|
||||
logSafe("No tags fetched", level: LogLevel.warning);
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// --- TAG LOGIC ---
|
||||
void filterSuggestions(String query) {
|
||||
if (query.isEmpty) {
|
||||
filteredSuggestions.clear();
|
||||
return;
|
||||
}
|
||||
filteredSuggestions.assignAll(
|
||||
tags.map((t) => t.name).where(
|
||||
(tag) => tag.toLowerCase().contains(query.toLowerCase()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void addEnteredTag(String tag) {
|
||||
if (tag.trim().isEmpty) return;
|
||||
if (!enteredTags.contains(tag.trim())) {
|
||||
enteredTags.add(tag.trim());
|
||||
}
|
||||
}
|
||||
|
||||
void removeEnteredTag(String tag) {
|
||||
enteredTags.remove(tag);
|
||||
}
|
||||
|
||||
void clearSuggestions() {
|
||||
filteredSuggestions.clear();
|
||||
}
|
||||
|
||||
/// Upload document
|
||||
Future<bool> uploadDocument({
|
||||
required String documentId,
|
||||
required String name,
|
||||
required String entityId,
|
||||
required String documentTypeId,
|
||||
required String fileName,
|
||||
required String base64Data,
|
||||
required String contentType,
|
||||
required int fileSize,
|
||||
String? description,
|
||||
}) async {
|
||||
try {
|
||||
isUploading.value = true;
|
||||
|
||||
final payloadTags =
|
||||
enteredTags.map((t) => {"name": t, "isActive": true}).toList();
|
||||
|
||||
final payload = {
|
||||
"documentId": documentId,
|
||||
"name": name,
|
||||
"description": description,
|
||||
"entityId": entityId,
|
||||
"documentTypeId": documentTypeId,
|
||||
"fileName": fileName,
|
||||
"base64Data":
|
||||
base64Data.isNotEmpty ? "<base64-string-truncated>" : null,
|
||||
"contentType": contentType,
|
||||
"fileSize": fileSize,
|
||||
"tags": payloadTags,
|
||||
};
|
||||
|
||||
// Log the payload (hide long base64 string for readability)
|
||||
logSafe("Upload payload: $payload");
|
||||
|
||||
final success = await ApiService.uploadDocumentApi(
|
||||
documentId: documentId,
|
||||
name: name,
|
||||
description: description,
|
||||
entityId: entityId,
|
||||
documentTypeId: documentTypeId,
|
||||
fileName: fileName,
|
||||
base64Data: base64Data,
|
||||
contentType: contentType,
|
||||
fileSize: fileSize,
|
||||
tags: payloadTags,
|
||||
);
|
||||
|
||||
if (success) {
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "Document uploaded successfully",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
} else {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Could not upload document",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
|
||||
return success;
|
||||
} catch (e, stack) {
|
||||
logSafe("Upload error: $e", level: LogLevel.error);
|
||||
logSafe("Stacktrace: $stack", level: LogLevel.debug);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "An unexpected error occurred",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return false;
|
||||
} finally {
|
||||
isUploading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> editDocument(Map<String, dynamic> payload) async {
|
||||
try {
|
||||
isUploading.value = true;
|
||||
|
||||
final attachment = payload["attachment"];
|
||||
|
||||
final success = await ApiService.editDocumentApi(
|
||||
id: payload["id"],
|
||||
name: payload["name"],
|
||||
documentId: payload["documentId"],
|
||||
description: payload["description"],
|
||||
tags: (payload["tags"] as List).cast<Map<String, dynamic>>(),
|
||||
attachment: attachment,
|
||||
);
|
||||
|
||||
if (success) {
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "Document updated successfully",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
} else {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to update document",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
|
||||
return success;
|
||||
} catch (e, stack) {
|
||||
logSafe("Edit error: $e", level: LogLevel.error);
|
||||
logSafe("Stacktrace: $stack", level: LogLevel.debug);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "An unexpected error occurred",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return false;
|
||||
} finally {
|
||||
isUploading.value = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,181 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/model/document/document_filter_model.dart';
|
||||
import 'package:marco/model/document/documents_list_model.dart';
|
||||
|
||||
class DocumentController extends GetxController {
|
||||
// ------------------ Observables ---------------------
|
||||
var isLoading = false.obs;
|
||||
var documents = <DocumentItem>[].obs;
|
||||
var filters = Rxn<DocumentFiltersData>();
|
||||
|
||||
// ✅ Selected filters (multi-select support)
|
||||
var selectedUploadedBy = <String>[].obs;
|
||||
var selectedCategory = <String>[].obs;
|
||||
var selectedType = <String>[].obs;
|
||||
var selectedTag = <String>[].obs;
|
||||
|
||||
// Pagination state
|
||||
var pageNumber = 1.obs;
|
||||
final int pageSize = 20;
|
||||
var hasMore = true.obs;
|
||||
|
||||
// Error message
|
||||
var errorMessage = "".obs;
|
||||
|
||||
// NEW: show inactive toggle
|
||||
var showInactive = false.obs;
|
||||
|
||||
// NEW: search
|
||||
var searchQuery = ''.obs;
|
||||
var searchController = TextEditingController();
|
||||
// New filter fields
|
||||
var isUploadedAt = true.obs;
|
||||
var isVerified = RxnBool();
|
||||
var startDate = Rxn<String>();
|
||||
var endDate = Rxn<String>();
|
||||
|
||||
// ------------------ API Calls -----------------------
|
||||
|
||||
/// Fetch Document Filters for an Entity
|
||||
Future<void> fetchFilters(String entityTypeId) async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
final response = await ApiService.getDocumentFilters(entityTypeId);
|
||||
|
||||
if (response != null && response.success) {
|
||||
filters.value = response.data;
|
||||
} else {
|
||||
errorMessage.value = response?.message ?? "Failed to fetch filters";
|
||||
}
|
||||
} catch (e) {
|
||||
errorMessage.value = "Error fetching filters: $e";
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Toggle document active/inactive state
|
||||
Future<bool> toggleDocumentActive(
|
||||
String id, {
|
||||
required bool isActive,
|
||||
required String entityTypeId,
|
||||
required String entityId,
|
||||
}) async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
final success =
|
||||
await ApiService.deleteDocumentApi(id: id, isActive: isActive);
|
||||
|
||||
if (success) {
|
||||
// 🔥 Always fetch fresh list after toggle
|
||||
await fetchDocuments(
|
||||
entityTypeId: entityTypeId,
|
||||
entityId: entityId,
|
||||
reset: true,
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
errorMessage.value = "Failed to update document state";
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
errorMessage.value = "Error updating document: $e";
|
||||
return false;
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Permanently delete a document (or deactivate depending on API)
|
||||
Future<bool> deleteDocument(String id, {bool isActive = false}) async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
final success =
|
||||
await ApiService.deleteDocumentApi(id: id, isActive: isActive);
|
||||
|
||||
if (success) {
|
||||
// remove from local list immediately for better UX
|
||||
documents.removeWhere((doc) => doc.id == id);
|
||||
return true;
|
||||
} else {
|
||||
errorMessage.value = "Failed to delete document";
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
errorMessage.value = "Error deleting document: $e";
|
||||
return false;
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch Documents for an entity
|
||||
Future<void> fetchDocuments({
|
||||
required String entityTypeId,
|
||||
required String entityId,
|
||||
String? filter,
|
||||
String? searchString,
|
||||
bool reset = false,
|
||||
}) async {
|
||||
try {
|
||||
if (reset) {
|
||||
pageNumber.value = 1;
|
||||
documents.clear();
|
||||
hasMore.value = true;
|
||||
}
|
||||
|
||||
if (!hasMore.value) return;
|
||||
|
||||
isLoading.value = true;
|
||||
|
||||
final response = await ApiService.getDocumentListApi(
|
||||
entityTypeId: entityTypeId,
|
||||
entityId: entityId,
|
||||
filter: filter ?? "",
|
||||
searchString: searchString ?? searchQuery.value,
|
||||
pageNumber: pageNumber.value,
|
||||
pageSize: pageSize,
|
||||
isActive: !showInactive.value,
|
||||
);
|
||||
|
||||
if (response != null && response.success) {
|
||||
if (response.data.data.isNotEmpty) {
|
||||
documents.addAll(response.data.data);
|
||||
pageNumber.value++;
|
||||
} else {
|
||||
hasMore.value = false;
|
||||
}
|
||||
} else {
|
||||
errorMessage.value = response?.message ?? "Failed to fetch documents";
|
||||
}
|
||||
} catch (e) {
|
||||
errorMessage.value = "Error fetching documents: $e";
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------ Helpers -----------------------
|
||||
|
||||
/// Clear selected filters
|
||||
void clearFilters() {
|
||||
selectedUploadedBy.clear();
|
||||
selectedCategory.clear();
|
||||
selectedType.clear();
|
||||
selectedTag.clear();
|
||||
isUploadedAt.value = true;
|
||||
isVerified.value = null;
|
||||
startDate.value = null;
|
||||
endDate.value = null;
|
||||
}
|
||||
|
||||
/// Check if any filters are active (for red dot indicator)
|
||||
bool hasActiveFilters() {
|
||||
return selectedUploadedBy.isNotEmpty ||
|
||||
selectedCategory.isNotEmpty ||
|
||||
selectedType.isNotEmpty ||
|
||||
selectedTag.isNotEmpty;
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/model/dynamicMenu/dynamic_menu_model.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
|
||||
class DynamicMenuController extends GetxController {
|
||||
// UI reactive states
|
||||
final RxBool isLoading = false.obs;
|
||||
final RxBool hasError = false.obs;
|
||||
final RxString errorMessage = ''.obs;
|
||||
final RxList<MenuItem> menuItems = <MenuItem>[].obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
// Fetch menus directly from API at startup
|
||||
fetchMenu();
|
||||
}
|
||||
|
||||
/// Fetch dynamic menu from API (no local cache)
|
||||
Future<void> fetchMenu() async {
|
||||
isLoading.value = true;
|
||||
hasError.value = false;
|
||||
errorMessage.value = '';
|
||||
|
||||
try {
|
||||
final responseData = await ApiService.getMenuApi();
|
||||
if (responseData != null) {
|
||||
final menuResponse = MenuResponse.fromJson(responseData);
|
||||
menuItems.assignAll(menuResponse.data);
|
||||
|
||||
logSafe("✅ Menu loaded from API with ${menuItems.length} items");
|
||||
} else {
|
||||
_handleApiFailure("Menu API returned null response");
|
||||
}
|
||||
} catch (e) {
|
||||
_handleApiFailure("Menu fetch exception: $e");
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
void _handleApiFailure(String logMessage) {
|
||||
logSafe(logMessage, level: LogLevel.error);
|
||||
|
||||
// No cache available, show error state
|
||||
hasError.value = true;
|
||||
errorMessage.value = "❌ Unable to load menus. Please try again later.";
|
||||
menuItems.clear();
|
||||
}
|
||||
|
||||
bool isMenuAllowed(String menuName) {
|
||||
final menu = menuItems.firstWhereOrNull((m) => m.name == menuName);
|
||||
return menu?.available ?? false;
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
super.onClose();
|
||||
}
|
||||
}
|
@ -1,310 +0,0 @@
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
enum Gender {
|
||||
male,
|
||||
female,
|
||||
other;
|
||||
|
||||
const Gender();
|
||||
}
|
||||
|
||||
class AddEmployeeController extends MyController {
|
||||
Map<String, dynamic>? editingEmployeeData;
|
||||
|
||||
// State
|
||||
final MyFormValidator basicValidator = MyFormValidator();
|
||||
final List<PlatformFile> files = [];
|
||||
final List<String> categories = [];
|
||||
|
||||
Gender? selectedGender;
|
||||
List<Map<String, dynamic>> roles = [];
|
||||
String? selectedRoleId;
|
||||
String selectedCountryCode = '+91';
|
||||
bool showOnline = true;
|
||||
DateTime? joiningDate;
|
||||
String? selectedOrganizationId;
|
||||
RxString selectedOrganizationName = RxString('');
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
logSafe('Initializing AddEmployeeController...');
|
||||
_initializeFields();
|
||||
fetchRoles();
|
||||
|
||||
if (editingEmployeeData != null) {
|
||||
prefillFields();
|
||||
}
|
||||
}
|
||||
|
||||
void _initializeFields() {
|
||||
basicValidator.addField(
|
||||
'first_name',
|
||||
label: 'First Name',
|
||||
required: true,
|
||||
controller: TextEditingController(),
|
||||
);
|
||||
basicValidator.addField(
|
||||
'phone_number',
|
||||
label: 'Phone Number',
|
||||
required: true,
|
||||
controller: TextEditingController(),
|
||||
);
|
||||
basicValidator.addField(
|
||||
'last_name',
|
||||
label: 'Last Name',
|
||||
required: true,
|
||||
controller: TextEditingController(),
|
||||
);
|
||||
// Email is optional in controller; UI enforces when application access is checked
|
||||
basicValidator.addField(
|
||||
'email',
|
||||
label: 'Email',
|
||||
required: false,
|
||||
controller: TextEditingController(),
|
||||
);
|
||||
|
||||
logSafe('Fields initialized for first_name, phone_number, last_name, email.');
|
||||
}
|
||||
|
||||
// Prefill fields in edit mode
|
||||
void prefillFields() {
|
||||
logSafe('Prefilling data for editing...');
|
||||
basicValidator.getController('first_name')?.text =
|
||||
editingEmployeeData?['first_name'] ?? '';
|
||||
basicValidator.getController('last_name')?.text =
|
||||
editingEmployeeData?['last_name'] ?? '';
|
||||
basicValidator.getController('phone_number')?.text =
|
||||
editingEmployeeData?['phone_number'] ?? '';
|
||||
|
||||
selectedGender = editingEmployeeData?['gender'] != null
|
||||
? Gender.values.firstWhereOrNull((g) => g.name == editingEmployeeData!['gender'])
|
||||
: null;
|
||||
|
||||
basicValidator.getController('email')?.text =
|
||||
editingEmployeeData?['email'] ?? '';
|
||||
|
||||
selectedRoleId = editingEmployeeData?['job_role_id'];
|
||||
|
||||
if (editingEmployeeData?['joining_date'] != null) {
|
||||
joiningDate = DateTime.tryParse(editingEmployeeData!['joining_date']);
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void setJoiningDate(DateTime date) {
|
||||
joiningDate = date;
|
||||
logSafe('Joining date selected: $date');
|
||||
update();
|
||||
}
|
||||
|
||||
void onGenderSelected(Gender? gender) {
|
||||
selectedGender = gender;
|
||||
logSafe('Gender selected: ${gender?.name}');
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> fetchRoles() async {
|
||||
logSafe('Fetching roles...');
|
||||
try {
|
||||
final result = await ApiService.getRoles();
|
||||
if (result != null) {
|
||||
roles = List<Map<String, dynamic>>.from(result);
|
||||
logSafe('Roles fetched successfully.');
|
||||
update();
|
||||
} else {
|
||||
logSafe('Failed to fetch roles: null result', level: LogLevel.error);
|
||||
}
|
||||
} catch (e, st) {
|
||||
logSafe('Error fetching roles', level: LogLevel.error, error: e, stackTrace: st);
|
||||
}
|
||||
}
|
||||
|
||||
void onRoleSelected(String? roleId) {
|
||||
selectedRoleId = roleId;
|
||||
logSafe('Role selected: $roleId');
|
||||
update();
|
||||
}
|
||||
|
||||
// Create or update employee
|
||||
Future<Map<String, dynamic>?> createOrUpdateEmployee({
|
||||
String? email,
|
||||
bool hasApplicationAccess = false,
|
||||
}) async {
|
||||
logSafe(editingEmployeeData != null
|
||||
? 'Starting employee update...'
|
||||
: 'Starting employee creation...');
|
||||
|
||||
if (selectedGender == null || selectedRoleId == null) {
|
||||
showAppSnackbar(
|
||||
title: 'Missing Fields',
|
||||
message: 'Please select both Gender and Role.',
|
||||
type: SnackbarType.warning,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
final firstName = basicValidator.getController('first_name')?.text.trim();
|
||||
final lastName = basicValidator.getController('last_name')?.text.trim();
|
||||
final phoneNumber = basicValidator.getController('phone_number')?.text.trim();
|
||||
|
||||
try {
|
||||
// sanitize orgId before sending
|
||||
final String? orgId = (selectedOrganizationId != null &&
|
||||
selectedOrganizationId!.trim().isNotEmpty)
|
||||
? selectedOrganizationId
|
||||
: null;
|
||||
|
||||
final response = await ApiService.createEmployee(
|
||||
id: editingEmployeeData?['id'],
|
||||
firstName: firstName!,
|
||||
lastName: lastName!,
|
||||
phoneNumber: phoneNumber!,
|
||||
gender: selectedGender!.name,
|
||||
jobRoleId: selectedRoleId!,
|
||||
joiningDate: joiningDate?.toIso8601String() ?? '',
|
||||
organizationId: orgId,
|
||||
email: email,
|
||||
hasApplicationAccess: hasApplicationAccess,
|
||||
);
|
||||
|
||||
logSafe('Response: $response');
|
||||
|
||||
if (response != null && response['success'] == true) {
|
||||
showAppSnackbar(
|
||||
title: 'Success',
|
||||
message: editingEmployeeData != null
|
||||
? 'Employee updated successfully!'
|
||||
: 'Employee created successfully!',
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
return response;
|
||||
} else {
|
||||
logSafe('Failed operation', level: LogLevel.error);
|
||||
}
|
||||
} catch (e, st) {
|
||||
logSafe('Error creating/updating employee',
|
||||
level: LogLevel.error, error: e, stackTrace: st);
|
||||
}
|
||||
|
||||
showAppSnackbar(
|
||||
title: 'Error',
|
||||
message: 'Failed to save employee.',
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<bool> _checkAndRequestContactsPermission() async {
|
||||
final status = await Permission.contacts.request();
|
||||
|
||||
if (status.isGranted) return true;
|
||||
|
||||
if (status.isPermanentlyDenied) {
|
||||
await openAppSettings();
|
||||
}
|
||||
|
||||
showAppSnackbar(
|
||||
title: 'Permission Required',
|
||||
message: 'Please allow Contacts permission from settings to pick a contact.',
|
||||
type: SnackbarType.warning,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> pickContact(BuildContext context) async {
|
||||
final permissionGranted = await _checkAndRequestContactsPermission();
|
||||
if (!permissionGranted) return;
|
||||
|
||||
try {
|
||||
final picked = await FlutterContacts.openExternalPick();
|
||||
if (picked == null) return;
|
||||
|
||||
final contact =
|
||||
await FlutterContacts.getContact(picked.id, withProperties: true);
|
||||
if (contact == null) {
|
||||
showAppSnackbar(
|
||||
title: 'Error',
|
||||
message: 'Failed to load contact details.',
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (contact.phones.isEmpty) {
|
||||
showAppSnackbar(
|
||||
title: 'No Phone Number',
|
||||
message: 'Selected contact has no phone number.',
|
||||
type: SnackbarType.warning,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final indiaPhones = contact.phones.where((p) {
|
||||
final normalized = p.number.replaceAll(RegExp(r'[^0-9+]'), '');
|
||||
return normalized.startsWith('+91') ||
|
||||
RegExp(r'^\d{10}$').hasMatch(normalized);
|
||||
}).toList();
|
||||
|
||||
if (indiaPhones.isEmpty) {
|
||||
showAppSnackbar(
|
||||
title: 'No Indian Number',
|
||||
message: 'Selected contact has no Indian (+91) phone number.',
|
||||
type: SnackbarType.warning,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
String? selectedPhone;
|
||||
if (indiaPhones.length == 1) {
|
||||
selectedPhone = indiaPhones.first.number;
|
||||
} else {
|
||||
selectedPhone = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('Choose an Indian number'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: indiaPhones
|
||||
.map(
|
||||
(p) => ListTile(
|
||||
title: Text(p.number),
|
||||
onTap: () => Navigator.of(ctx).pop(p.number),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (selectedPhone == null) return;
|
||||
}
|
||||
|
||||
final normalizedPhone = selectedPhone.replaceAll(RegExp(r'[^0-9]'), '');
|
||||
final phoneWithoutCountryCode = normalizedPhone.length > 10
|
||||
? normalizedPhone.substring(normalizedPhone.length - 10)
|
||||
: normalizedPhone;
|
||||
|
||||
basicValidator.getController('phone_number')?.text =
|
||||
phoneWithoutCountryCode;
|
||||
update();
|
||||
} catch (e, st) {
|
||||
logSafe('Error fetching contacts',
|
||||
level: LogLevel.error, error: e, stackTrace: st);
|
||||
showAppSnackbar(
|
||||
title: 'Error',
|
||||
message: 'Failed to fetch contacts.',
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/model/global_project_model.dart';
|
||||
import 'package:marco/model/employees/assigned_projects_model.dart';
|
||||
import 'package:marco/controller/project_controller.dart';
|
||||
|
||||
class AssignProjectController extends GetxController {
|
||||
final String employeeId;
|
||||
final String jobRoleId;
|
||||
|
||||
AssignProjectController({
|
||||
required this.employeeId,
|
||||
required this.jobRoleId,
|
||||
});
|
||||
|
||||
final ProjectController projectController = Get.put(ProjectController());
|
||||
|
||||
RxBool isLoading = false.obs;
|
||||
RxBool isAssigning = false.obs;
|
||||
|
||||
RxList<String> assignedProjectIds = <String>[].obs;
|
||||
RxList<String> selectedProjects = <String>[].obs;
|
||||
RxList<GlobalProjectModel> allProjects = <GlobalProjectModel>[].obs;
|
||||
RxList<GlobalProjectModel> filteredProjects = <GlobalProjectModel>[].obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
fetchAllProjectsAndAssignments();
|
||||
});
|
||||
}
|
||||
|
||||
/// Fetch all projects and assigned projects
|
||||
Future<void> fetchAllProjectsAndAssignments() async {
|
||||
isLoading.value = true;
|
||||
try {
|
||||
await projectController.fetchProjects();
|
||||
allProjects.assignAll(projectController.projects);
|
||||
filteredProjects.assignAll(allProjects); // initially show all
|
||||
|
||||
final responseList = await ApiService.getAssignedProjects(employeeId);
|
||||
if (responseList != null) {
|
||||
final assignedProjects =
|
||||
responseList.map((e) => AssignedProject.fromJson(e)).toList();
|
||||
|
||||
assignedProjectIds.assignAll(
|
||||
assignedProjects.map((p) => p.id).toList(),
|
||||
);
|
||||
selectedProjects.assignAll(assignedProjectIds);
|
||||
}
|
||||
|
||||
logSafe("All Projects: ${allProjects.map((e) => e.id)}");
|
||||
logSafe("Assigned Project IDs: $assignedProjectIds");
|
||||
} catch (e, stack) {
|
||||
logSafe("Error fetching projects or assignments: $e",
|
||||
level: LogLevel.error);
|
||||
logSafe("StackTrace: $stack", level: LogLevel.debug);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Assign selected projects
|
||||
Future<bool> assignProjectsToEmployee() async {
|
||||
if (selectedProjects.isEmpty) {
|
||||
logSafe("No projects selected for assignment.", level: LogLevel.warning);
|
||||
return false;
|
||||
}
|
||||
|
||||
final List<Map<String, dynamic>> projectPayload =
|
||||
selectedProjects.map((id) {
|
||||
return {"projectId": id, "jobRoleId": jobRoleId, "status": true};
|
||||
}).toList();
|
||||
|
||||
isAssigning.value = true;
|
||||
try {
|
||||
final success = await ApiService.assignProjects(
|
||||
employeeId: employeeId,
|
||||
projects: projectPayload,
|
||||
);
|
||||
|
||||
if (success) {
|
||||
logSafe("Projects assigned successfully.");
|
||||
assignedProjectIds.assignAll(selectedProjects);
|
||||
return true;
|
||||
} else {
|
||||
logSafe("Failed to assign projects.", level: LogLevel.error);
|
||||
return false;
|
||||
}
|
||||
} catch (e, stack) {
|
||||
logSafe("Error assigning projects: $e", level: LogLevel.error);
|
||||
logSafe("StackTrace: $stack", level: LogLevel.debug);
|
||||
return false;
|
||||
} finally {
|
||||
isAssigning.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Toggle project selection
|
||||
void toggleProjectSelection(String projectId, bool isSelected) {
|
||||
if (isSelected) {
|
||||
if (!selectedProjects.contains(projectId)) {
|
||||
selectedProjects.add(projectId);
|
||||
}
|
||||
} else {
|
||||
selectedProjects.remove(projectId);
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if project is selected
|
||||
bool isProjectSelected(String projectId) {
|
||||
return selectedProjects.contains(projectId);
|
||||
}
|
||||
|
||||
/// Select all / deselect all
|
||||
void toggleSelectAll() {
|
||||
if (areAllSelected()) {
|
||||
selectedProjects.clear();
|
||||
} else {
|
||||
selectedProjects.assignAll(allProjects.map((p) => p.id.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
/// Are all selected?
|
||||
bool areAllSelected() {
|
||||
return selectedProjects.length == allProjects.length &&
|
||||
allProjects.isNotEmpty;
|
||||
}
|
||||
|
||||
/// Filter projects by search text
|
||||
void filterProjects(String query) {
|
||||
if (query.isEmpty) {
|
||||
filteredProjects.assignAll(allProjects);
|
||||
} else {
|
||||
filteredProjects.assignAll(
|
||||
allProjects
|
||||
.where((p) => p.name.toLowerCase().contains(query.toLowerCase()))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,497 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:geocoding/geocoding.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:mime/mime.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
import 'package:marco/controller/expense/expense_screen_controller.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/model/employees/employee_model.dart';
|
||||
import 'package:marco/model/expense/expense_type_model.dart';
|
||||
import 'package:marco/model/expense/payment_types_model.dart';
|
||||
|
||||
class AddExpenseController extends GetxController {
|
||||
// --- Text Controllers ---
|
||||
final controllers = <TextEditingController>[
|
||||
TextEditingController(), // amount
|
||||
TextEditingController(), // description
|
||||
TextEditingController(), // supplier
|
||||
TextEditingController(), // transactionId
|
||||
TextEditingController(), // gst
|
||||
TextEditingController(), // location
|
||||
TextEditingController(), // transactionDate
|
||||
TextEditingController(), // noOfPersons
|
||||
TextEditingController(), // employeeSearch
|
||||
];
|
||||
|
||||
TextEditingController get amountController => controllers[0];
|
||||
TextEditingController get descriptionController => controllers[1];
|
||||
TextEditingController get supplierController => controllers[2];
|
||||
TextEditingController get transactionIdController => controllers[3];
|
||||
TextEditingController get gstController => controllers[4];
|
||||
TextEditingController get locationController => controllers[5];
|
||||
TextEditingController get transactionDateController => controllers[6];
|
||||
TextEditingController get noOfPersonsController => controllers[7];
|
||||
TextEditingController get employeeSearchController => controllers[8];
|
||||
|
||||
// --- Reactive State ---
|
||||
final isLoading = false.obs;
|
||||
final isSubmitting = false.obs;
|
||||
final isFetchingLocation = false.obs;
|
||||
final isEditMode = false.obs;
|
||||
final isSearchingEmployees = false.obs;
|
||||
|
||||
// --- Dropdown Selections & Data ---
|
||||
final selectedPaymentMode = Rxn<PaymentModeModel>();
|
||||
final selectedExpenseType = Rxn<ExpenseTypeModel>();
|
||||
final selectedPaidBy = Rxn<EmployeeModel>();
|
||||
final selectedProject = ''.obs;
|
||||
final selectedTransactionDate = Rxn<DateTime>();
|
||||
|
||||
final attachments = <File>[].obs;
|
||||
final existingAttachments = <Map<String, dynamic>>[].obs;
|
||||
final globalProjects = <String>[].obs;
|
||||
final projectsMap = <String, String>{}.obs;
|
||||
|
||||
final expenseTypes = <ExpenseTypeModel>[].obs;
|
||||
final paymentModes = <PaymentModeModel>[].obs;
|
||||
final allEmployees = <EmployeeModel>[].obs;
|
||||
final employeeSearchResults = <EmployeeModel>[].obs;
|
||||
|
||||
String? editingExpenseId;
|
||||
|
||||
final expenseController = Get.find<ExpenseController>();
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
loadMasterData();
|
||||
employeeSearchController.addListener(
|
||||
() => searchEmployees(employeeSearchController.text),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
for (var c in controllers) {
|
||||
c.dispose();
|
||||
}
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
// --- Employee Search ---
|
||||
Future<void> searchEmployees(String query) async {
|
||||
if (query.trim().isEmpty) return employeeSearchResults.clear();
|
||||
isSearchingEmployees.value = true;
|
||||
try {
|
||||
final data = await ApiService.searchEmployeesBasic(
|
||||
searchString: query.trim(),
|
||||
);
|
||||
|
||||
if (data is List) {
|
||||
employeeSearchResults.assignAll(
|
||||
data
|
||||
.map((e) => EmployeeModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
} else {
|
||||
employeeSearchResults.clear();
|
||||
}
|
||||
} catch (e) {
|
||||
logSafe("Error searching employees: $e", level: LogLevel.error);
|
||||
employeeSearchResults.clear();
|
||||
} finally {
|
||||
isSearchingEmployees.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Form Population (Edit) ---
|
||||
Future<void> populateFieldsForEdit(Map<String, dynamic> data) async {
|
||||
isEditMode.value = true;
|
||||
editingExpenseId = '${data['id']}';
|
||||
|
||||
selectedProject.value = data['projectName'] ?? '';
|
||||
amountController.text = '${data['amount'] ?? ''}';
|
||||
supplierController.text = data['supplerName'] ?? '';
|
||||
descriptionController.text = data['description'] ?? '';
|
||||
transactionIdController.text = data['transactionId'] ?? '';
|
||||
locationController.text = data['location'] ?? '';
|
||||
noOfPersonsController.text = '${data['noOfPersons'] ?? 0}';
|
||||
|
||||
_setTransactionDate(data['transactionDate']);
|
||||
_setDropdowns(data);
|
||||
await _setPaidBy(data);
|
||||
_setAttachments(data['attachments']);
|
||||
|
||||
_logPrefilledData();
|
||||
}
|
||||
|
||||
void _setTransactionDate(dynamic dateStr) {
|
||||
if (dateStr == null) {
|
||||
selectedTransactionDate.value = null;
|
||||
transactionDateController.clear();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final parsed = DateTime.parse(dateStr);
|
||||
selectedTransactionDate.value = parsed;
|
||||
transactionDateController.text = DateFormat('dd-MM-yyyy').format(parsed);
|
||||
} catch (_) {
|
||||
selectedTransactionDate.value = null;
|
||||
transactionDateController.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void _setDropdowns(Map<String, dynamic> data) {
|
||||
selectedExpenseType.value =
|
||||
expenseTypes.firstWhereOrNull((e) => e.id == data['expensesTypeId']);
|
||||
selectedPaymentMode.value =
|
||||
paymentModes.firstWhereOrNull((e) => e.id == data['paymentModeId']);
|
||||
}
|
||||
|
||||
Future<void> _setPaidBy(Map<String, dynamic> data) async {
|
||||
final paidById = '${data['paidById']}';
|
||||
selectedPaidBy.value =
|
||||
allEmployees.firstWhereOrNull((e) => e.id.trim() == paidById.trim());
|
||||
|
||||
if (selectedPaidBy.value == null && data['paidByFirstName'] != null) {
|
||||
await searchEmployees(
|
||||
'${data['paidByFirstName']} ${data['paidByLastName']}',
|
||||
);
|
||||
selectedPaidBy.value = employeeSearchResults
|
||||
.firstWhereOrNull((e) => e.id.trim() == paidById.trim());
|
||||
}
|
||||
}
|
||||
|
||||
void _setAttachments(dynamic attachmentsData) {
|
||||
existingAttachments.clear();
|
||||
if (attachmentsData is List) {
|
||||
existingAttachments.addAll(
|
||||
List<Map<String, dynamic>>.from(attachmentsData).map(
|
||||
(e) => {...e, 'isActive': true},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _logPrefilledData() {
|
||||
final info = [
|
||||
'ID: $editingExpenseId',
|
||||
'Project: ${selectedProject.value}',
|
||||
'Amount: ${amountController.text}',
|
||||
'Supplier: ${supplierController.text}',
|
||||
'Description: ${descriptionController.text}',
|
||||
'Transaction ID: ${transactionIdController.text}',
|
||||
'Location: ${locationController.text}',
|
||||
'Transaction Date: ${transactionDateController.text}',
|
||||
'No. of Persons: ${noOfPersonsController.text}',
|
||||
'Expense Type: ${selectedExpenseType.value?.name}',
|
||||
'Payment Mode: ${selectedPaymentMode.value?.name}',
|
||||
'Paid By: ${selectedPaidBy.value?.name}',
|
||||
'Attachments: ${attachments.length}',
|
||||
'Existing Attachments: ${existingAttachments.length}',
|
||||
];
|
||||
for (var line in info) {
|
||||
logSafe(line, level: LogLevel.info);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Pickers ---
|
||||
Future<void> pickTransactionDate(BuildContext context) async {
|
||||
final pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: selectedTransactionDate.value ?? DateTime.now(),
|
||||
firstDate: DateTime(DateTime.now().year - 5),
|
||||
lastDate: DateTime.now(),
|
||||
);
|
||||
|
||||
if (pickedDate != null) {
|
||||
final now = DateTime.now();
|
||||
final finalDateTime = DateTime(
|
||||
pickedDate.year,
|
||||
pickedDate.month,
|
||||
pickedDate.day,
|
||||
now.hour,
|
||||
now.minute,
|
||||
now.second,
|
||||
);
|
||||
selectedTransactionDate.value = finalDateTime;
|
||||
transactionDateController.text =
|
||||
DateFormat('dd MMM yyyy').format(finalDateTime);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> pickAttachments() async {
|
||||
try {
|
||||
final result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.custom,
|
||||
allowedExtensions: ['jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx'],
|
||||
allowMultiple: true,
|
||||
);
|
||||
if (result != null) {
|
||||
attachments.addAll(
|
||||
result.paths.whereType<String>().map(File.new),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
_errorSnackbar("Attachment error: $e");
|
||||
}
|
||||
}
|
||||
|
||||
void removeAttachment(File file) => attachments.remove(file);
|
||||
|
||||
Future<void> pickFromCamera() async {
|
||||
try {
|
||||
final pickedFile = await _picker.pickImage(source: ImageSource.camera);
|
||||
if (pickedFile != null) attachments.add(File(pickedFile.path));
|
||||
} catch (e) {
|
||||
_errorSnackbar("Camera error: $e");
|
||||
}
|
||||
}
|
||||
|
||||
// --- Location ---
|
||||
Future<void> fetchCurrentLocation() async {
|
||||
isFetchingLocation.value = true;
|
||||
try {
|
||||
if (!await _ensureLocationPermission()) return;
|
||||
|
||||
final position = await Geolocator.getCurrentPosition();
|
||||
final placemarks =
|
||||
await placemarkFromCoordinates(position.latitude, position.longitude);
|
||||
|
||||
locationController.text = placemarks.isNotEmpty
|
||||
? [
|
||||
placemarks.first.name,
|
||||
placemarks.first.street,
|
||||
placemarks.first.locality,
|
||||
placemarks.first.administrativeArea,
|
||||
placemarks.first.country,
|
||||
].where((e) => e?.isNotEmpty == true).join(", ")
|
||||
: "${position.latitude}, ${position.longitude}";
|
||||
} catch (e) {
|
||||
_errorSnackbar("Location error: $e");
|
||||
} finally {
|
||||
isFetchingLocation.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _ensureLocationPermission() async {
|
||||
var permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied ||
|
||||
permission == LocationPermission.deniedForever) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
if (permission == LocationPermission.denied ||
|
||||
permission == LocationPermission.deniedForever) {
|
||||
_errorSnackbar("Location permission denied.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!await Geolocator.isLocationServiceEnabled()) {
|
||||
_errorSnackbar("Location service disabled.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// --- Data Fetching ---
|
||||
Future<void> loadMasterData() async =>
|
||||
Future.wait([fetchMasterData(), fetchGlobalProjects()]);
|
||||
|
||||
Future<void> fetchMasterData() async {
|
||||
try {
|
||||
final types = await ApiService.getMasterExpenseTypes();
|
||||
if (types is List) {
|
||||
expenseTypes.value = types
|
||||
.map((e) => ExpenseTypeModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
final modes = await ApiService.getMasterPaymentModes();
|
||||
if (modes is List) {
|
||||
paymentModes.value = modes
|
||||
.map((e) => PaymentModeModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
} catch (_) {
|
||||
_errorSnackbar("Failed to fetch master data");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchGlobalProjects() async {
|
||||
try {
|
||||
final response = await ApiService.getGlobalProjects();
|
||||
if (response != null) {
|
||||
final names = <String>[];
|
||||
for (var item in response) {
|
||||
final name = item['name']?.toString().trim();
|
||||
final id = item['id']?.toString().trim();
|
||||
if (name != null && id != null) {
|
||||
projectsMap[name] = id;
|
||||
names.add(name);
|
||||
}
|
||||
}
|
||||
globalProjects.assignAll(names);
|
||||
}
|
||||
} catch (e) {
|
||||
logSafe("Error fetching projects: $e", level: LogLevel.error);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Submission ---
|
||||
Future<void> submitOrUpdateExpense() async {
|
||||
if (isSubmitting.value) return;
|
||||
isSubmitting.value = true;
|
||||
try {
|
||||
final validationMsg = validateForm();
|
||||
if (validationMsg.isNotEmpty) {
|
||||
_errorSnackbar(validationMsg, "Missing Fields");
|
||||
return;
|
||||
}
|
||||
|
||||
final payload = await _buildExpensePayload();
|
||||
final success = await _submitToApi(payload);
|
||||
|
||||
if (success) {
|
||||
await expenseController.fetchExpenses();
|
||||
Get.back();
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message:
|
||||
"Expense ${isEditMode.value ? 'updated' : 'created'} successfully!",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
} else {
|
||||
_errorSnackbar("Operation failed. Try again.");
|
||||
}
|
||||
} catch (e) {
|
||||
_errorSnackbar("Unexpected error: $e");
|
||||
} finally {
|
||||
isSubmitting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _submitToApi(Map<String, dynamic> payload) async {
|
||||
if (isEditMode.value && editingExpenseId != null) {
|
||||
return ApiService.editExpenseApi(
|
||||
expenseId: editingExpenseId!,
|
||||
payload: payload,
|
||||
);
|
||||
}
|
||||
return ApiService.createExpenseApi(
|
||||
projectId: payload['projectId'],
|
||||
expensesTypeId: payload['expensesTypeId'],
|
||||
paymentModeId: payload['paymentModeId'],
|
||||
paidById: payload['paidById'],
|
||||
transactionDate: DateTime.parse(payload['transactionDate']),
|
||||
transactionId: payload['transactionId'],
|
||||
description: payload['description'],
|
||||
location: payload['location'],
|
||||
supplerName: payload['supplerName'],
|
||||
amount: payload['amount'],
|
||||
noOfPersons: payload['noOfPersons'],
|
||||
billAttachments: payload['billAttachments'],
|
||||
);
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> _buildExpensePayload() async {
|
||||
final now = DateTime.now();
|
||||
|
||||
final existingPayload = isEditMode.value
|
||||
? existingAttachments
|
||||
.map((e) => {
|
||||
"documentId": e['documentId'],
|
||||
"fileName": e['fileName'],
|
||||
"contentType": e['contentType'],
|
||||
"fileSize": 0,
|
||||
"description": "",
|
||||
"url": e['url'],
|
||||
"isActive": e['isActive'] ?? true,
|
||||
"base64Data": "",
|
||||
})
|
||||
.toList()
|
||||
: <Map<String, dynamic>>[];
|
||||
|
||||
final newPayload = await Future.wait(
|
||||
attachments.map((file) async {
|
||||
final bytes = await file.readAsBytes();
|
||||
return {
|
||||
"fileName": file.path.split('/').last,
|
||||
"base64Data": base64Encode(bytes),
|
||||
"contentType":
|
||||
lookupMimeType(file.path) ?? 'application/octet-stream',
|
||||
"fileSize": await file.length(),
|
||||
"description": "",
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
final type = selectedExpenseType.value!;
|
||||
|
||||
return {
|
||||
if (isEditMode.value && editingExpenseId != null) "id": editingExpenseId,
|
||||
"projectId": projectsMap[selectedProject.value]!,
|
||||
"expensesTypeId": type.id,
|
||||
"paymentModeId": selectedPaymentMode.value!.id,
|
||||
"paidById": selectedPaidBy.value!.id,
|
||||
"transactionDate":
|
||||
(selectedTransactionDate.value ?? now).toUtc().toIso8601String(),
|
||||
"transactionId": transactionIdController.text,
|
||||
"description": descriptionController.text,
|
||||
"location": locationController.text,
|
||||
"supplerName": supplierController.text,
|
||||
"amount": double.parse(amountController.text.trim()),
|
||||
"noOfPersons": type.noOfPersonsRequired == true
|
||||
? int.tryParse(noOfPersonsController.text.trim()) ?? 0
|
||||
: 0,
|
||||
"billAttachments": [
|
||||
...existingPayload,
|
||||
...newPayload,
|
||||
].isEmpty
|
||||
? null
|
||||
: [...existingPayload, ...newPayload],
|
||||
};
|
||||
}
|
||||
|
||||
String validateForm() {
|
||||
final missing = <String>[];
|
||||
|
||||
if (selectedProject.value.isEmpty) missing.add("Project");
|
||||
if (selectedExpenseType.value == null) missing.add("Expense Type");
|
||||
if (selectedPaymentMode.value == null) missing.add("Payment Mode");
|
||||
if (selectedPaidBy.value == null) missing.add("Paid By");
|
||||
if (amountController.text.trim().isEmpty) missing.add("Amount");
|
||||
if (descriptionController.text.trim().isEmpty) missing.add("Description");
|
||||
|
||||
if (selectedTransactionDate.value == null) {
|
||||
missing.add("Transaction Date");
|
||||
} else if (selectedTransactionDate.value!.isAfter(DateTime.now())) {
|
||||
missing.add("Valid Transaction Date");
|
||||
}
|
||||
|
||||
if (double.tryParse(amountController.text.trim()) == null) {
|
||||
missing.add("Valid Amount");
|
||||
}
|
||||
|
||||
final hasActiveExisting =
|
||||
existingAttachments.any((e) => e['isActive'] != false);
|
||||
if (attachments.isEmpty && !hasActiveExisting) {
|
||||
missing.add("Attachment");
|
||||
}
|
||||
|
||||
return missing.isEmpty ? '' : "Please provide: ${missing.join(', ')}.";
|
||||
}
|
||||
|
||||
// --- Snackbar Helper ---
|
||||
void _errorSnackbar(String msg, [String title = "Error"]) {
|
||||
showAppSnackbar(title: title, message: msg, type: SnackbarType.error);
|
||||
}
|
||||
}
|
@ -1,187 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/model/expense/expense_detail_model.dart';
|
||||
import 'package:marco/model/employees/employee_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ExpenseDetailController extends GetxController {
|
||||
final Rx<ExpenseDetailModel?> expense = Rx<ExpenseDetailModel?>(null);
|
||||
final RxBool isLoading = false.obs;
|
||||
final RxString errorMessage = ''.obs;
|
||||
final Rx<EmployeeModel?> selectedReimbursedBy = Rx<EmployeeModel?>(null);
|
||||
final RxList<EmployeeModel> allEmployees = <EmployeeModel>[].obs;
|
||||
final RxList<EmployeeModel> employeeSearchResults = <EmployeeModel>[].obs;
|
||||
late String _expenseId;
|
||||
bool _isInitialized = false;
|
||||
final employeeSearchController = TextEditingController();
|
||||
final isSearchingEmployees = false.obs;
|
||||
|
||||
/// Call this once from the screen (NOT inside build) to initialize
|
||||
void init(String expenseId) {
|
||||
if (_isInitialized) return;
|
||||
|
||||
_isInitialized = true;
|
||||
_expenseId = expenseId;
|
||||
|
||||
// Use Future.wait to fetch details and employees concurrently
|
||||
Future.wait([
|
||||
fetchExpenseDetails(),
|
||||
fetchAllEmployees(),
|
||||
]);
|
||||
}
|
||||
|
||||
/// Generic method to handle API calls with loading and error states
|
||||
Future<T?> _apiCallWrapper<T>(
|
||||
Future<T?> Function() apiCall, String operationName) async {
|
||||
isLoading.value = true;
|
||||
errorMessage.value = ''; // Clear previous errors
|
||||
|
||||
try {
|
||||
logSafe("Initiating $operationName...");
|
||||
final result = await apiCall();
|
||||
logSafe("$operationName completed successfully.");
|
||||
return result;
|
||||
} catch (e, stack) {
|
||||
errorMessage.value =
|
||||
'An unexpected error occurred during $operationName.';
|
||||
logSafe("Exception in $operationName: $e", level: LogLevel.error);
|
||||
logSafe("StackTrace: $stack", level: LogLevel.debug);
|
||||
return null;
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch expense details by stored ID
|
||||
Future<void> fetchExpenseDetails() async {
|
||||
final result = await _apiCallWrapper(
|
||||
() => ApiService.getExpenseDetailsApi(expenseId: _expenseId),
|
||||
"fetch expense details");
|
||||
|
||||
if (result != null) {
|
||||
try {
|
||||
expense.value = ExpenseDetailModel.fromJson(result);
|
||||
logSafe("Expense details loaded successfully: ${expense.value?.id}");
|
||||
} catch (e) {
|
||||
errorMessage.value = 'Failed to parse expense details: $e';
|
||||
logSafe("Parse error in fetchExpenseDetails: $e",
|
||||
level: LogLevel.error);
|
||||
}
|
||||
} else {
|
||||
errorMessage.value = 'Failed to fetch expense details from server.';
|
||||
logSafe("fetchExpenseDetails failed: null response",
|
||||
level: LogLevel.error);
|
||||
}
|
||||
}
|
||||
|
||||
// This method seems like a utility and might be better placed in a helper or utility class
|
||||
// if it's used across multiple controllers. Keeping it here for now as per original code.
|
||||
List<String> parsePermissionIds(dynamic permissionData) {
|
||||
if (permissionData == null) return [];
|
||||
if (permissionData is List) {
|
||||
return permissionData
|
||||
.map((e) => e.toString().trim())
|
||||
.where((e) => e.isNotEmpty)
|
||||
.toList();
|
||||
}
|
||||
if (permissionData is String) {
|
||||
final clean = permissionData.replaceAll(RegExp(r'[\[\]]'), '');
|
||||
return clean
|
||||
.split(',')
|
||||
.map((e) => e.trim())
|
||||
.where((e) => e.isNotEmpty)
|
||||
.toList();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
Future<void> searchEmployees(String query) async {
|
||||
if (query.trim().isEmpty) return employeeSearchResults.clear();
|
||||
isSearchingEmployees.value = true;
|
||||
try {
|
||||
final data =
|
||||
await ApiService.searchEmployeesBasic(searchString: query.trim());
|
||||
employeeSearchResults.assignAll(
|
||||
(data ?? []).map((e) => EmployeeModel.fromJson(e)),
|
||||
);
|
||||
} catch (e) {
|
||||
logSafe("Error searching employees: $e", level: LogLevel.error);
|
||||
employeeSearchResults.clear();
|
||||
} finally {
|
||||
isSearchingEmployees.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch all employees
|
||||
Future<void> fetchAllEmployees() async {
|
||||
final response = await _apiCallWrapper(
|
||||
() => ApiService.getAllEmployees(), "fetch all employees");
|
||||
|
||||
if (response != null && response.isNotEmpty) {
|
||||
try {
|
||||
allEmployees.assignAll(response.map((e) => EmployeeModel.fromJson(e)));
|
||||
logSafe("All Employees fetched: ${allEmployees.length}",
|
||||
level: LogLevel.info);
|
||||
} catch (e) {
|
||||
errorMessage.value = 'Failed to parse employee data: $e';
|
||||
logSafe("Parse error in fetchAllEmployees: $e", level: LogLevel.error);
|
||||
}
|
||||
} else {
|
||||
allEmployees.clear();
|
||||
logSafe("No employees found.", level: LogLevel.warning);
|
||||
}
|
||||
// `update()` is typically not needed for RxList directly unless you have specific GetBuilder/Obx usage that requires it
|
||||
// If you are using Obx widgets, `allEmployees.assignAll` will automatically trigger a rebuild.
|
||||
}
|
||||
|
||||
/// Update expense with reimbursement info and status
|
||||
Future<bool> updateExpenseStatusWithReimbursement({
|
||||
required String comment,
|
||||
required String reimburseTransactionId,
|
||||
required String reimburseDate,
|
||||
required String reimburseById,
|
||||
required String statusId,
|
||||
}) async {
|
||||
final success = await _apiCallWrapper(
|
||||
() => ApiService.updateExpenseStatusApi(
|
||||
expenseId: _expenseId,
|
||||
statusId: statusId,
|
||||
comment: comment,
|
||||
reimburseTransactionId: reimburseTransactionId,
|
||||
reimburseDate: reimburseDate,
|
||||
reimbursedById: reimburseById,
|
||||
),
|
||||
"submit reimbursement",
|
||||
);
|
||||
|
||||
if (success == true) {
|
||||
// Explicitly check for true as _apiCallWrapper returns T?
|
||||
await fetchExpenseDetails(); // Refresh details after successful update
|
||||
return true;
|
||||
} else {
|
||||
errorMessage.value = "Failed to submit reimbursement.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Update status for this specific expense
|
||||
Future<bool> updateExpenseStatus(String statusId, {String? comment}) async {
|
||||
final success = await _apiCallWrapper(
|
||||
() => ApiService.updateExpenseStatusApi(
|
||||
expenseId: _expenseId,
|
||||
statusId: statusId,
|
||||
comment: comment,
|
||||
),
|
||||
"update expense status",
|
||||
);
|
||||
|
||||
if (success == true) {
|
||||
await fetchExpenseDetails();
|
||||
return true;
|
||||
} else {
|
||||
errorMessage.value = "Failed to update expense status.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,357 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/model/expense/expense_list_model.dart';
|
||||
import 'package:marco/model/expense/payment_types_model.dart';
|
||||
import 'package:marco/model/expense/expense_type_model.dart';
|
||||
import 'package:marco/model/expense/expense_status_model.dart';
|
||||
import 'package:marco/model/employees/employee_model.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ExpenseController extends GetxController {
|
||||
final RxList<ExpenseModel> expenses = <ExpenseModel>[].obs;
|
||||
final RxBool isLoading = false.obs;
|
||||
final RxString errorMessage = ''.obs;
|
||||
|
||||
// Master data
|
||||
final RxList<ExpenseTypeModel> expenseTypes = <ExpenseTypeModel>[].obs;
|
||||
final RxList<PaymentModeModel> paymentModes = <PaymentModeModel>[].obs;
|
||||
final RxList<ExpenseStatusModel> expenseStatuses = <ExpenseStatusModel>[].obs;
|
||||
final RxList<String> globalProjects = <String>[].obs;
|
||||
final RxMap<String, String> projectsMap = <String, String>{}.obs;
|
||||
RxList<EmployeeModel> allEmployees = <EmployeeModel>[].obs;
|
||||
|
||||
// Persistent Filter States
|
||||
final RxString selectedProject = ''.obs;
|
||||
final RxString selectedStatus = ''.obs;
|
||||
final Rx<DateTime?> startDate = Rx<DateTime?>(null);
|
||||
final Rx<DateTime?> endDate = Rx<DateTime?>(null);
|
||||
final RxList<EmployeeModel> selectedPaidByEmployees = <EmployeeModel>[].obs;
|
||||
final RxList<EmployeeModel> selectedCreatedByEmployees =
|
||||
<EmployeeModel>[].obs;
|
||||
final RxString selectedDateType = 'Transaction Date'.obs;
|
||||
|
||||
final employeeSearchController = TextEditingController();
|
||||
final isSearchingEmployees = false.obs;
|
||||
final employeeSearchResults = <EmployeeModel>[].obs;
|
||||
|
||||
final List<String> dateTypes = [
|
||||
'Transaction Date',
|
||||
'Created At',
|
||||
];
|
||||
|
||||
int _pageSize = 20;
|
||||
int _pageNumber = 1;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
loadInitialMasterData();
|
||||
fetchAllEmployees();
|
||||
employeeSearchController.addListener(() {
|
||||
searchEmployees(employeeSearchController.text);
|
||||
});
|
||||
}
|
||||
|
||||
bool get isFilterApplied {
|
||||
return selectedProject.value.isNotEmpty ||
|
||||
selectedStatus.value.isNotEmpty ||
|
||||
startDate.value != null ||
|
||||
endDate.value != null ||
|
||||
selectedPaidByEmployees.isNotEmpty ||
|
||||
selectedCreatedByEmployees.isNotEmpty;
|
||||
}
|
||||
|
||||
/// Load master data
|
||||
Future<void> loadInitialMasterData() async {
|
||||
await fetchGlobalProjects();
|
||||
await fetchMasterData();
|
||||
}
|
||||
|
||||
Future<void> deleteExpense(String expenseId) async {
|
||||
try {
|
||||
logSafe("Attempting to delete expense: $expenseId");
|
||||
final success = await ApiService.deleteExpense(expenseId);
|
||||
if (success) {
|
||||
expenses.removeWhere((e) => e.id == expenseId);
|
||||
logSafe("Expense deleted successfully.");
|
||||
showAppSnackbar(
|
||||
title: "Deleted",
|
||||
message: "Expense has been deleted successfully.",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
} else {
|
||||
logSafe("Failed to delete expense: $expenseId", level: LogLevel.error);
|
||||
showAppSnackbar(
|
||||
title: "Failed",
|
||||
message: "Failed to delete expense.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
logSafe("Exception in deleteExpense: $e", level: LogLevel.error);
|
||||
logSafe("StackTrace: $stack", level: LogLevel.debug);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Something went wrong while deleting.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> searchEmployees(String searchQuery) async {
|
||||
if (searchQuery.trim().isEmpty) {
|
||||
employeeSearchResults.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
isSearchingEmployees.value = true;
|
||||
try {
|
||||
final results = await ApiService.searchEmployeesBasic(
|
||||
searchString: searchQuery.trim(),
|
||||
);
|
||||
|
||||
if (results != null) {
|
||||
employeeSearchResults.assignAll(
|
||||
results.map((e) => EmployeeModel.fromJson(e)),
|
||||
);
|
||||
} else {
|
||||
employeeSearchResults.clear();
|
||||
}
|
||||
} catch (e) {
|
||||
logSafe("Error searching employees: $e", level: LogLevel.error);
|
||||
employeeSearchResults.clear();
|
||||
} finally {
|
||||
isSearchingEmployees.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch expenses using filters
|
||||
Future<void> fetchExpenses({
|
||||
List<String>? projectIds,
|
||||
List<String>? statusIds,
|
||||
List<String>? createdByIds,
|
||||
List<String>? paidByIds,
|
||||
DateTime? startDate,
|
||||
DateTime? endDate,
|
||||
int pageSize = 20,
|
||||
int pageNumber = 1,
|
||||
}) async {
|
||||
isLoading.value = true;
|
||||
errorMessage.value = '';
|
||||
expenses.clear();
|
||||
_pageSize = pageSize;
|
||||
_pageNumber = pageNumber;
|
||||
|
||||
final Map<String, dynamic> filterMap = {
|
||||
"projectIds": projectIds ??
|
||||
(selectedProject.value.isEmpty
|
||||
? []
|
||||
: [projectsMap[selectedProject.value] ?? '']),
|
||||
"statusIds": statusIds ??
|
||||
(selectedStatus.value.isEmpty ? [] : [selectedStatus.value]),
|
||||
"createdByIds":
|
||||
createdByIds ?? selectedCreatedByEmployees.map((e) => e.id).toList(),
|
||||
"paidByIds":
|
||||
paidByIds ?? selectedPaidByEmployees.map((e) => e.id).toList(),
|
||||
"startDate": (startDate ?? this.startDate.value)?.toIso8601String(),
|
||||
"endDate": (endDate ?? this.endDate.value)?.toIso8601String(),
|
||||
"isTransactionDate": selectedDateType.value == 'Transaction Date',
|
||||
};
|
||||
|
||||
try {
|
||||
logSafe("Fetching expenses with filter: ${jsonEncode(filterMap)}");
|
||||
|
||||
final result = await ApiService.getExpenseListApi(
|
||||
filter: jsonEncode(filterMap),
|
||||
pageSize: _pageSize,
|
||||
pageNumber: _pageNumber,
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
try {
|
||||
final expenseResponse = ExpenseResponse.fromJson(result);
|
||||
|
||||
// If the backend returns no data, treat it as empty list
|
||||
if (expenseResponse.data.data.isEmpty) {
|
||||
expenses.clear();
|
||||
errorMessage.value = ''; // no error
|
||||
logSafe("Expense list is empty.");
|
||||
} else {
|
||||
expenses.assignAll(expenseResponse.data.data);
|
||||
logSafe("Expenses loaded: ${expenses.length}");
|
||||
logSafe(
|
||||
"Pagination Info: Page ${expenseResponse.data.currentPage} of ${expenseResponse.data.totalPages} | Total: ${expenseResponse.data.totalEntites}");
|
||||
}
|
||||
} catch (e) {
|
||||
errorMessage.value = 'Failed to parse expenses: $e';
|
||||
logSafe("Parse error in fetchExpenses: $e", level: LogLevel.error);
|
||||
}
|
||||
} else {
|
||||
// Only treat as error if this means a network or server failure
|
||||
errorMessage.value = 'Unable to connect to the server.';
|
||||
logSafe("fetchExpenses failed: null response", level: LogLevel.error);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
errorMessage.value = 'An unexpected error occurred.';
|
||||
logSafe("Exception in fetchExpenses: $e", level: LogLevel.error);
|
||||
logSafe("StackTrace: $stack", level: LogLevel.debug);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Clear all filters
|
||||
void clearFilters() {
|
||||
selectedProject.value = '';
|
||||
selectedStatus.value = '';
|
||||
startDate.value = null;
|
||||
endDate.value = null;
|
||||
selectedPaidByEmployees.clear();
|
||||
selectedCreatedByEmployees.clear();
|
||||
}
|
||||
|
||||
/// Fetch master data: expense types, payment modes, and expense status
|
||||
Future<void> fetchMasterData() async {
|
||||
try {
|
||||
final expenseTypesData = await ApiService.getMasterExpenseTypes();
|
||||
if (expenseTypesData is List) {
|
||||
expenseTypes.value =
|
||||
expenseTypesData.map((e) => ExpenseTypeModel.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
final paymentModesData = await ApiService.getMasterPaymentModes();
|
||||
if (paymentModesData is List) {
|
||||
paymentModes.value =
|
||||
paymentModesData.map((e) => PaymentModeModel.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
final expenseStatusData = await ApiService.getMasterExpenseStatus();
|
||||
if (expenseStatusData is List) {
|
||||
expenseStatuses.value = expenseStatusData
|
||||
.map((e) => ExpenseStatusModel.fromJson(e))
|
||||
.toList();
|
||||
}
|
||||
} catch (e) {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to fetch master data: $e",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch global projects
|
||||
Future<void> fetchGlobalProjects() async {
|
||||
try {
|
||||
final response = await ApiService.getGlobalProjects();
|
||||
if (response != null) {
|
||||
final names = <String>[];
|
||||
for (var item in response) {
|
||||
final name = item['name']?.toString().trim();
|
||||
final id = item['id']?.toString().trim();
|
||||
if (name != null && id != null && name.isNotEmpty) {
|
||||
projectsMap[name] = id;
|
||||
names.add(name);
|
||||
}
|
||||
}
|
||||
globalProjects.assignAll(names);
|
||||
logSafe("Fetched ${names.length} global projects");
|
||||
}
|
||||
} catch (e) {
|
||||
logSafe("Failed to fetch global projects: $e", level: LogLevel.error);
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch all employees
|
||||
Future<void> fetchAllEmployees() async {
|
||||
isLoading.value = true;
|
||||
try {
|
||||
final response = await ApiService.getAllEmployees();
|
||||
if (response != null && response.isNotEmpty) {
|
||||
allEmployees
|
||||
.assignAll(response.map((json) => EmployeeModel.fromJson(json)));
|
||||
logSafe(
|
||||
"All Employees fetched for Manage Bucket: ${allEmployees.length}",
|
||||
level: LogLevel.info,
|
||||
);
|
||||
} else {
|
||||
allEmployees.clear();
|
||||
logSafe("No employees found for Manage Bucket.",
|
||||
level: LogLevel.warning);
|
||||
}
|
||||
} catch (e) {
|
||||
allEmployees.clear();
|
||||
logSafe("Error fetching employees in Manage Bucket",
|
||||
level: LogLevel.error, error: e);
|
||||
}
|
||||
isLoading.value = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> loadMoreExpenses() async {
|
||||
if (isLoading.value) return;
|
||||
|
||||
_pageNumber += 1;
|
||||
isLoading.value = true;
|
||||
|
||||
final Map<String, dynamic> filterMap = {
|
||||
"projectIds": selectedProject.value.isEmpty
|
||||
? []
|
||||
: [projectsMap[selectedProject.value] ?? ''],
|
||||
"statusIds": selectedStatus.value.isEmpty ? [] : [selectedStatus.value],
|
||||
"createdByIds": selectedCreatedByEmployees.map((e) => e.id).toList(),
|
||||
"paidByIds": selectedPaidByEmployees.map((e) => e.id).toList(),
|
||||
"startDate": startDate.value?.toIso8601String(),
|
||||
"endDate": endDate.value?.toIso8601String(),
|
||||
"isTransactionDate": selectedDateType.value == 'Transaction Date',
|
||||
};
|
||||
|
||||
try {
|
||||
final result = await ApiService.getExpenseListApi(
|
||||
filter: jsonEncode(filterMap),
|
||||
pageSize: _pageSize,
|
||||
pageNumber: _pageNumber,
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
final expenseResponse = ExpenseResponse.fromJson(result);
|
||||
expenses.addAll(expenseResponse.data.data);
|
||||
}
|
||||
} catch (e) {
|
||||
logSafe("Error in loadMoreExpenses: $e", level: LogLevel.error);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Update expense status
|
||||
Future<bool> updateExpenseStatus(String expenseId, String statusId) async {
|
||||
isLoading.value = true;
|
||||
errorMessage.value = '';
|
||||
try {
|
||||
logSafe("Updating status for expense: $expenseId -> $statusId");
|
||||
final success = await ApiService.updateExpenseStatusApi(
|
||||
expenseId: expenseId,
|
||||
statusId: statusId,
|
||||
);
|
||||
if (success) {
|
||||
logSafe("Expense status updated successfully.");
|
||||
await fetchExpenses();
|
||||
return true;
|
||||
} else {
|
||||
errorMessage.value = "Failed to update expense status.";
|
||||
return false;
|
||||
}
|
||||
} catch (e, stack) {
|
||||
errorMessage.value = 'An unexpected error occurred.';
|
||||
logSafe("Exception in updateExpenseStatus: $e", level: LogLevel.error);
|
||||
logSafe("StackTrace: $stack", level: LogLevel.debug);
|
||||
return false;
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
}
|
17
lib/controller/extra_pages/time_line_controller.dart
Normal file
@ -0,0 +1,17 @@
|
||||
import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/helpers/widgets/my_text_utils.dart';
|
||||
import 'package:marco/model/time_line.dart';
|
||||
|
||||
class TimeLineController extends MyController {
|
||||
List<TimeLineModel> timeline = [];
|
||||
List<String> dummyTexts = List.generate(12, (index) => MyTextUtils.getDummyText(60));
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
TimeLineModel.dummyList.then((value) {
|
||||
timeline = value.sublist(0, 6);
|
||||
update();
|
||||
});
|
||||
super.onInit();
|
||||
}
|
||||
}
|
@ -1,112 +1,46 @@
|
||||
import 'package:marco/helpers/theme/theme_customizer.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/theme/theme_customizer.dart';
|
||||
import 'package:marco/model/project_model.dart';
|
||||
|
||||
class LayoutController extends GetxController {
|
||||
// Theme Customization
|
||||
ThemeCustomizer themeCustomizer = ThemeCustomizer();
|
||||
|
||||
// Global Keys
|
||||
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
|
||||
final GlobalKey<State<StatefulWidget>> scrollKey = GlobalKey();
|
||||
|
||||
// Scroll
|
||||
final ScrollController scrollController = ScrollController();
|
||||
|
||||
// Reactive State
|
||||
final RxBool isLoading = true.obs;
|
||||
final RxBool isLoadingProjects = true.obs;
|
||||
final RxBool isProjectSelectionExpanded = true.obs;
|
||||
final RxBool isProjectListExpanded = false.obs;
|
||||
final RxBool isProjectDropdownExpanded = false.obs;
|
||||
final RxList<ProjectModel> projects = <ProjectModel>[].obs;
|
||||
final RxMap<String, RxBool> uploadingStates = <String, RxBool>{}.obs;
|
||||
|
||||
// Selected Project
|
||||
RxString? selectedProjectId;
|
||||
ScrollController scrollController = ScrollController();
|
||||
|
||||
bool isLastIndex = false;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchProjects();
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
ThemeCustomizer.addListener(onChangeTheme);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
ThemeCustomizer.removeListener(onChangeTheme);
|
||||
scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// Fetch project list from API and initialize the selection.
|
||||
Future<void> fetchProjects() async {
|
||||
isLoading.value = true;
|
||||
isLoadingProjects.value = true;
|
||||
|
||||
try {
|
||||
final response = await ApiService.getProjects();
|
||||
|
||||
if (response != null && response.isNotEmpty) {
|
||||
final fetchedProjects = response.map((json) => ProjectModel.fromJson(json)).toList();
|
||||
projects.assignAll(fetchedProjects);
|
||||
selectedProjectId = RxString(fetchedProjects.first.id.toString());
|
||||
|
||||
logSafe("Projects fetched: ${fetchedProjects.length}", level: LogLevel.info);
|
||||
} else {
|
||||
logSafe("No projects found or API call failed.", level: LogLevel.warning);
|
||||
}
|
||||
} catch (e, st) {
|
||||
logSafe("Error fetching projects", level: LogLevel.error, error: e, stackTrace: st);
|
||||
}
|
||||
|
||||
isLoadingProjects.value = false;
|
||||
isLoading.value = false;
|
||||
update(['dashboard_controller']);
|
||||
}
|
||||
|
||||
/// Update selected project ID
|
||||
void updateSelectedProject(String projectId) {
|
||||
selectedProjectId?.value = projectId;
|
||||
logSafe("Selected project updated", level: LogLevel.info);
|
||||
}
|
||||
|
||||
/// Toggle expansion of the project list section
|
||||
void toggleProjectListExpanded() {
|
||||
isProjectListExpanded.toggle();
|
||||
logSafe("Project list expanded: ${isProjectListExpanded.value}", level: LogLevel.debug);
|
||||
}
|
||||
|
||||
/// Handle theme changes (light/dark, drawer toggles)
|
||||
void onChangeTheme(ThemeCustomizer oldVal, ThemeCustomizer newVal) {
|
||||
themeCustomizer = newVal;
|
||||
update();
|
||||
|
||||
if (newVal.rightBarOpen) {
|
||||
scaffoldKey.currentState?.openEndDrawer();
|
||||
logSafe("Theme changed — end drawer opened", level: LogLevel.debug);
|
||||
} else {
|
||||
scaffoldKey.currentState?.closeEndDrawer();
|
||||
logSafe("Theme changed — end drawer closed", level: LogLevel.debug);
|
||||
}
|
||||
}
|
||||
|
||||
/// Optional notification toggles (placeholder)
|
||||
void enableNotificationShade() {
|
||||
logSafe("Notification shade enabled (not implemented)", level: LogLevel.verbose);
|
||||
enableNotificationShade() {
|
||||
// SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom, SystemUiOverlay.top]);
|
||||
}
|
||||
|
||||
void disableNotificationShade() {
|
||||
logSafe("Notification shade disabled (not implemented)", level: LogLevel.verbose);
|
||||
disableNotificationShade() {
|
||||
// SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
ThemeCustomizer.removeListener(onChangeTheme);
|
||||
scrollController.dispose();
|
||||
}
|
||||
}
|
||||
|
@ -2,74 +2,26 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
|
||||
import 'package:marco/helpers/services/permission_service.dart';
|
||||
import 'package:marco/model/user_permission.dart';
|
||||
import 'package:marco/model/employees/employee_info.dart';
|
||||
import 'package:marco/model/employee_info.dart';
|
||||
import 'package:marco/model/projects_model.dart';
|
||||
|
||||
final log = Logger();
|
||||
|
||||
class PermissionController extends GetxController {
|
||||
var permissions = <UserPermission>[].obs;
|
||||
var employeeInfo = Rxn<EmployeeInfo>();
|
||||
var projectsInfo = <ProjectInfo>[].obs;
|
||||
Timer? _refreshTimer;
|
||||
var isLoading = true.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
_initialize();
|
||||
}
|
||||
|
||||
Future<void> _initialize() async {
|
||||
final token = await _getAuthToken();
|
||||
if (token?.isNotEmpty ?? false) {
|
||||
await loadData(token!);
|
||||
_startAutoRefresh();
|
||||
} else {
|
||||
logSafe("Token is null or empty. Skipping API load and auto-refresh.",
|
||||
level: LogLevel.warning);
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> _getAuthToken() async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final token = prefs.getString('jwt_token');
|
||||
logSafe("Auth token retrieved: $token", level: LogLevel.debug);
|
||||
return token;
|
||||
} catch (e, stacktrace) {
|
||||
logSafe("Error retrieving auth token",
|
||||
level: LogLevel.error, error: e, stackTrace: stacktrace);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadData(String token) async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
final userData = await PermissionService.fetchAllUserData(token);
|
||||
_updateState(userData);
|
||||
await _storeData();
|
||||
logSafe("Data loaded and state updated successfully.");
|
||||
} catch (e, stacktrace) {
|
||||
logSafe("Error loading data from API",
|
||||
level: LogLevel.error, error: e, stackTrace: stacktrace);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
void _updateState(Map<String, dynamic> userData) {
|
||||
try {
|
||||
permissions.assignAll(userData['permissions']);
|
||||
employeeInfo.value = userData['employeeInfo'];
|
||||
projectsInfo.assignAll(userData['projects']);
|
||||
logSafe("State updated with user data.");
|
||||
} catch (e, stacktrace) {
|
||||
logSafe("Error updating state",
|
||||
level: LogLevel.error, error: e, stackTrace: stacktrace);
|
||||
}
|
||||
_loadDataFromAPI();
|
||||
_startAutoRefresh();
|
||||
}
|
||||
|
||||
Future<void> _storeData() async {
|
||||
@ -95,61 +47,76 @@ class PermissionController extends GetxController {
|
||||
);
|
||||
}
|
||||
|
||||
logSafe("User data successfully stored in SharedPreferences.");
|
||||
log.i("User data successfully stored in SharedPreferences.");
|
||||
} catch (e, stacktrace) {
|
||||
logSafe("Error storing data",
|
||||
level: LogLevel.error, error: e, stackTrace: stacktrace);
|
||||
log.e("Error storing data", error: e, stackTrace: stacktrace);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadDataFromAPI() async {
|
||||
final token = await _getAuthToken();
|
||||
if (token?.isNotEmpty ?? false) {
|
||||
await loadData(token!);
|
||||
} else {
|
||||
log.w("No token found for loading API data.");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadData(String token) async {
|
||||
try {
|
||||
final userData = await PermissionService.fetchAllUserData(token);
|
||||
_updateState(userData);
|
||||
await _storeData();
|
||||
log.i("Data loaded and state updated successfully.");
|
||||
} catch (e, stacktrace) {
|
||||
log.e("Error loading data from API", error: e, stackTrace: stacktrace);
|
||||
}
|
||||
}
|
||||
|
||||
void _updateState(Map<String, dynamic> userData) {
|
||||
try {
|
||||
permissions.assignAll(userData['permissions']);
|
||||
employeeInfo.value = userData['employeeInfo'];
|
||||
projectsInfo.assignAll(userData['projects']);
|
||||
log.i("State updated with new user data.");
|
||||
} catch (e, stacktrace) {
|
||||
log.e("Error updating state", error: e, stackTrace: stacktrace);
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> _getAuthToken() async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getString('jwt_token');
|
||||
} catch (e, stacktrace) {
|
||||
log.e("Error retrieving auth token", error: e, stackTrace: stacktrace);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void _startAutoRefresh() {
|
||||
_refreshTimer = Timer.periodic(Duration(minutes: 30), (timer) async {
|
||||
logSafe("Auto-refresh triggered.");
|
||||
final token = await _getAuthToken();
|
||||
if (token?.isNotEmpty ?? false) {
|
||||
await loadData(token!);
|
||||
} else {
|
||||
logSafe("Token missing during auto-refresh. Skipping.",
|
||||
level: LogLevel.warning);
|
||||
}
|
||||
log.i("Auto-refresh triggered.");
|
||||
await _loadDataFromAPI();
|
||||
});
|
||||
}
|
||||
|
||||
bool hasPermission(String permissionId) {
|
||||
final hasPerm = permissions.any((p) => p.id == permissionId);
|
||||
logSafe("Checking permission $permissionId: $hasPerm",
|
||||
level: LogLevel.debug);
|
||||
log.d("Checking permission $permissionId: $hasPerm");
|
||||
return hasPerm;
|
||||
}
|
||||
|
||||
bool isUserAssignedToProject(String projectId) {
|
||||
final assigned = projectsInfo.any((project) => project.id == projectId);
|
||||
logSafe("Checking project assignment for $projectId: $assigned",
|
||||
level: LogLevel.debug);
|
||||
log.d("Checking project assignment for $projectId: $assigned");
|
||||
return assigned;
|
||||
}
|
||||
|
||||
List<String> get allowedPermissionIds {
|
||||
final ids = permissions.map((p) => p.id).toList();
|
||||
logSafe("[PermissionController] Allowed Permission IDs: $ids",
|
||||
level: LogLevel.debug);
|
||||
return ids;
|
||||
}
|
||||
|
||||
bool hasAnyPermission(List<String> ids) {
|
||||
logSafe("[PermissionController] Checking if any of these are allowed: $ids",
|
||||
level: LogLevel.debug);
|
||||
final allowed = allowedPermissionIds;
|
||||
final result = ids.any((id) => allowed.contains(id));
|
||||
logSafe("[PermissionController] Permission match result: $result",
|
||||
level: LogLevel.debug);
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
_refreshTimer?.cancel();
|
||||
logSafe("PermissionController disposed and auto-refresh timer cancelled.");
|
||||
log.i("PermissionController disposed and timer cancelled.");
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
|
@ -1,83 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/model/global_project_model.dart';
|
||||
import 'package:marco/helpers/services/storage/local_storage.dart';
|
||||
|
||||
class ProjectController extends GetxController {
|
||||
RxList<GlobalProjectModel> projects = <GlobalProjectModel>[].obs;
|
||||
RxString selectedProjectId = ''.obs;
|
||||
RxBool isProjectListExpanded = false.obs;
|
||||
RxBool isProjectSelectionExpanded = false.obs;
|
||||
|
||||
RxBool isProjectDropdownExpanded = false.obs;
|
||||
RxBool isLoading = true.obs;
|
||||
RxBool isLoadingProjects = true.obs;
|
||||
RxMap<String, RxBool> uploadingStates = <String, RxBool>{}.obs;
|
||||
|
||||
GlobalProjectModel? get selectedProject {
|
||||
if (selectedProjectId.value.isEmpty) return null;
|
||||
return projects.firstWhereOrNull((p) => p.id == selectedProjectId.value);
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchProjects();
|
||||
}
|
||||
|
||||
void clearProjects() {
|
||||
projects.clear();
|
||||
selectedProjectId.value = '';
|
||||
|
||||
isProjectSelectionExpanded.value = false;
|
||||
isProjectListExpanded.value = false;
|
||||
isProjectDropdownExpanded.value = false;
|
||||
isLoadingProjects.value = false;
|
||||
isLoading.value = false;
|
||||
uploadingStates.clear();
|
||||
|
||||
LocalStorage.saveString('selectedProjectId', '');
|
||||
|
||||
logSafe("Projects cleared and UI states reset.");
|
||||
update();
|
||||
}
|
||||
|
||||
/// Fetches projects and initializes selected project.
|
||||
Future<void> fetchProjects() async {
|
||||
isLoadingProjects.value = true;
|
||||
isLoading.value = true;
|
||||
|
||||
final response = await ApiService.getGlobalProjects();
|
||||
|
||||
if (response != null && response.isNotEmpty) {
|
||||
projects.assignAll(
|
||||
response.map((json) => GlobalProjectModel.fromJson(json)).toList(),
|
||||
);
|
||||
|
||||
String? savedId = LocalStorage.getString('selectedProjectId');
|
||||
if (savedId != null && projects.any((p) => p.id == savedId)) {
|
||||
selectedProjectId.value = savedId;
|
||||
} else {
|
||||
selectedProjectId.value = projects.first.id.toString();
|
||||
LocalStorage.saveString('selectedProjectId', selectedProjectId.value);
|
||||
}
|
||||
|
||||
isProjectSelectionExpanded.value = false;
|
||||
logSafe("Projects fetched: ${projects.length}");
|
||||
} else {
|
||||
logSafe("No Global projects found or API call failed.", level: LogLevel.warning);
|
||||
}
|
||||
|
||||
isLoadingProjects.value = false;
|
||||
isLoading.value = false;
|
||||
update(['dashboard_controller']);
|
||||
}
|
||||
|
||||
Future<void> updateSelectedProject(String projectId) async {
|
||||
selectedProjectId.value = projectId;
|
||||
await LocalStorage.saveString('selectedProjectId', projectId);
|
||||
logSafe("Selected project updated to $projectId");
|
||||
update(['selected_project']);
|
||||
}
|
||||
}
|
190
lib/controller/task_planing/daily_task_planing_controller.dart
Normal file
@ -0,0 +1,190 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/model/project_model.dart';
|
||||
import 'package:marco/model/dailyTaskPlaning/daily_task_planing_model.dart';
|
||||
import 'package:marco/model/employee_model.dart';
|
||||
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
|
||||
final Logger log = Logger();
|
||||
|
||||
class DailyTaskPlaningController extends GetxController {
|
||||
List<ProjectModel> projects = [];
|
||||
String? selectedProjectId;
|
||||
List<EmployeeModel> employees = [];
|
||||
List<TaskPlanningDetailsModel> dailyTasks = [];
|
||||
RxMap<String, RxBool> uploadingStates = <String, RxBool>{}.obs;
|
||||
MyFormValidator basicValidator = MyFormValidator();
|
||||
|
||||
List<Map<String, dynamic>> roles = [];
|
||||
RxnString selectedRoleId = RxnString();
|
||||
RxList<EmployeeModel> selectedEmployees = <EmployeeModel>[].obs;
|
||||
|
||||
void updateSelectedEmployees() {
|
||||
final selected =
|
||||
employees.where((e) => uploadingStates[e.id]?.value == true).toList();
|
||||
selectedEmployees.value = selected;
|
||||
}
|
||||
|
||||
RxBool isLoading = false.obs;
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchRoles();
|
||||
_initializeDefaults();
|
||||
}
|
||||
|
||||
void _initializeDefaults() {
|
||||
fetchProjects();
|
||||
}
|
||||
|
||||
String? formFieldValidator(String? value, {required String fieldType}) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return 'This field is required';
|
||||
}
|
||||
if (fieldType == "target") {
|
||||
if (int.tryParse(value.trim()) == null) {
|
||||
return 'Please enter a valid number';
|
||||
}
|
||||
}
|
||||
if (fieldType == "description") {
|
||||
if (value.trim().length < 5) {
|
||||
return 'Description must be at least 5 characters';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> fetchRoles() async {
|
||||
logger.i("Fetching roles...");
|
||||
final result = await ApiService.getRoles();
|
||||
if (result != null) {
|
||||
roles = List<Map<String, dynamic>>.from(result);
|
||||
logger.i("Roles fetched successfully.");
|
||||
update();
|
||||
} else {
|
||||
logger.e("Failed to fetch roles.");
|
||||
}
|
||||
}
|
||||
|
||||
void onRoleSelected(String? roleId) {
|
||||
selectedRoleId.value = roleId;
|
||||
logger.i("Role selected: $roleId");
|
||||
}
|
||||
|
||||
Future<bool> assignDailyTask({
|
||||
required String workItemId,
|
||||
required int plannedTask,
|
||||
required String description,
|
||||
required List<String> taskTeam,
|
||||
DateTime? assignmentDate,
|
||||
}) async {
|
||||
logger.i("Starting assign task...");
|
||||
|
||||
final response = await ApiService.assignDailyTask(
|
||||
workItemId: workItemId,
|
||||
plannedTask: plannedTask,
|
||||
description: description,
|
||||
taskTeam: taskTeam,
|
||||
assignmentDate: assignmentDate,
|
||||
);
|
||||
|
||||
if (response == true) {
|
||||
logger.i("Task assigned successfully.");
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "Task assigned successfully!",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
logger.e("Failed to assign task.");
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to assign task.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> fetchProjects() async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
|
||||
final response = await ApiService.getProjects();
|
||||
if (response?.isEmpty ?? true) {
|
||||
log.w("No project data found or API call failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
projects = response!.map((json) => ProjectModel.fromJson(json)).toList();
|
||||
selectedProjectId = projects.first.id.toString();
|
||||
log.i("Projects fetched: ${projects.length} projects loaded.");
|
||||
update();
|
||||
|
||||
await fetchTaskData(selectedProjectId);
|
||||
} catch (e, stack) {
|
||||
log.e("Error fetching projects", error: e, stackTrace: stack);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchTaskData(String? projectId) async {
|
||||
if (projectId == null) return;
|
||||
|
||||
try {
|
||||
isLoading.value = true;
|
||||
|
||||
final response = await ApiService.getDailyTasksDetails(projectId);
|
||||
if (response != null) {
|
||||
final data = response['data'];
|
||||
if (data != null) {
|
||||
dailyTasks = [TaskPlanningDetailsModel.fromJson(data)];
|
||||
log.i("Daily task Planning Details fetched.");
|
||||
} else {
|
||||
log.e("Data field is null");
|
||||
}
|
||||
} else {
|
||||
log.e(
|
||||
"Failed to fetch daily task planning Details for project $projectId");
|
||||
}
|
||||
} catch (e, stack) {
|
||||
log.e("Error fetching daily task data", error: e, stackTrace: stack);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchEmployeesByProject(String? projectId) async {
|
||||
if (projectId == null || projectId.isEmpty) {
|
||||
log.e("Project ID is required but was null or empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading.value = true;
|
||||
try {
|
||||
final response = await ApiService.getAllEmployeesByProject(projectId);
|
||||
if (response != null && response.isNotEmpty) {
|
||||
employees =
|
||||
response.map((json) => EmployeeModel.fromJson(json)).toList();
|
||||
for (var emp in employees) {
|
||||
uploadingStates[emp.id] = false.obs;
|
||||
}
|
||||
log.i("Employees fetched: ${employees.length} for project $projectId");
|
||||
} else {
|
||||
log.w("No employees found for project $projectId.");
|
||||
employees = [];
|
||||
}
|
||||
} catch (e) {
|
||||
log.e("Error fetching employees for project $projectId: $e");
|
||||
}
|
||||
|
||||
update();
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
242
lib/controller/task_planing/report_task_controller.dart
Normal file
@ -0,0 +1,242 @@
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/controller/task_planing/daily_task_planing_controller.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'dart:io';
|
||||
|
||||
final Logger logger = Logger();
|
||||
|
||||
enum ApiStatus { idle, loading, success, failure }
|
||||
|
||||
final DailyTaskPlaningController taskController =
|
||||
Get.put(DailyTaskPlaningController());
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
|
||||
class ReportTaskController extends MyController {
|
||||
List<PlatformFile> files = [];
|
||||
MyFormValidator basicValidator = MyFormValidator();
|
||||
RxBool isLoading = false.obs;
|
||||
Rx<ApiStatus> reportStatus = ApiStatus.idle.obs;
|
||||
Rx<ApiStatus> commentStatus = ApiStatus.idle.obs;
|
||||
|
||||
RxList<File> selectedImages = <File>[].obs;
|
||||
|
||||
// Controllers for each form field
|
||||
final assignedDateController = TextEditingController();
|
||||
final workAreaController = TextEditingController();
|
||||
final activityController = TextEditingController();
|
||||
final teamSizeController = TextEditingController();
|
||||
final taskIdController = TextEditingController();
|
||||
final assignedController = TextEditingController();
|
||||
final completedWorkController = TextEditingController();
|
||||
final commentController = TextEditingController();
|
||||
final assignedByController = TextEditingController();
|
||||
final teamMembersController = TextEditingController();
|
||||
final plannedWorkController = TextEditingController();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
logger.i("Initializing ReportTaskController...");
|
||||
|
||||
basicValidator.addField('assigned_date',
|
||||
label: "Assigned Date", controller: assignedDateController);
|
||||
basicValidator.addField('work_area',
|
||||
label: "Work Area", controller: workAreaController);
|
||||
basicValidator.addField('activity',
|
||||
label: "Activity", controller: activityController);
|
||||
basicValidator.addField('team_size',
|
||||
label: "Team Size", controller: teamSizeController);
|
||||
basicValidator.addField('task_id',
|
||||
label: "Task Id", controller: taskIdController);
|
||||
basicValidator.addField('assigned',
|
||||
label: "Assigned", controller: assignedController);
|
||||
basicValidator.addField('completed_work',
|
||||
label: "Completed Work",
|
||||
required: true,
|
||||
controller: completedWorkController);
|
||||
basicValidator.addField('comment',
|
||||
label: "Comment", required: true, controller: commentController);
|
||||
basicValidator.addField('assigned_by',
|
||||
label: "Assigned By", controller: assignedByController);
|
||||
basicValidator.addField('team_members',
|
||||
label: "Team Members", controller: teamMembersController);
|
||||
basicValidator.addField('planned_work',
|
||||
label: "Planned Work", controller: plannedWorkController);
|
||||
|
||||
logger.i(
|
||||
"Fields initialized for assigned_date, work_area, activity, team_size, assigned, completed_work, and comment.");
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
assignedDateController.dispose();
|
||||
workAreaController.dispose();
|
||||
activityController.dispose();
|
||||
teamSizeController.dispose();
|
||||
taskIdController.dispose();
|
||||
assignedController.dispose();
|
||||
completedWorkController.dispose();
|
||||
commentController.dispose();
|
||||
assignedByController.dispose();
|
||||
teamMembersController.dispose();
|
||||
plannedWorkController.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
Future<void> reportTask({
|
||||
required String projectId,
|
||||
required String comment,
|
||||
required int completedTask,
|
||||
required List<Map<String, dynamic>> checklist,
|
||||
required DateTime reportedDate,
|
||||
}) async {
|
||||
logger.i("Starting task report...");
|
||||
|
||||
final completedWork = completedWorkController.text.trim();
|
||||
|
||||
if (completedWork.isEmpty) {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Completed work is required.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final completedWorkInt = int.tryParse(completedWork);
|
||||
if (completedWorkInt == null || completedWorkInt < 0) {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Completed work must be a positive integer.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final commentField = commentController.text.trim();
|
||||
if (commentField.isEmpty) {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Comment is required.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
isLoading.value = true;
|
||||
|
||||
final success = await ApiService.reportTask(
|
||||
id: projectId,
|
||||
comment: commentField,
|
||||
completedTask: completedTask,
|
||||
checkList: checklist,
|
||||
);
|
||||
|
||||
if (success) {
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "Task reported successfully!",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
await taskController.fetchTaskData(projectId);
|
||||
} else {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to report task.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.e("Error reporting task: $e");
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "An error occurred while reporting the task.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> commentTask({
|
||||
required String projectId,
|
||||
required String comment,
|
||||
}) async {
|
||||
logger.i("Starting task comment...");
|
||||
|
||||
final commentField = commentController.text.trim();
|
||||
if (commentField.isEmpty) {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Comment is required.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
isLoading.value = true;
|
||||
|
||||
final success = await ApiService.commentTask(
|
||||
id: projectId,
|
||||
comment: commentField,
|
||||
);
|
||||
|
||||
if (success) {
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "Task commented successfully!",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
|
||||
await taskController.fetchTaskData(projectId);
|
||||
} else {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to comment task.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.e("Error commenting task: $e");
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "An error occurred while commenting the task.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> pickImages({required bool fromCamera}) async {
|
||||
if (fromCamera) {
|
||||
final pickedFile = await _picker.pickImage(
|
||||
source: ImageSource.camera,
|
||||
imageQuality: 75,
|
||||
);
|
||||
if (pickedFile != null) {
|
||||
selectedImages.add(File(pickedFile.path));
|
||||
}
|
||||
} else {
|
||||
final pickedFiles = await _picker.pickMultiImage(imageQuality: 75);
|
||||
if (pickedFiles != null && pickedFiles.isNotEmpty) {
|
||||
selectedImages.addAll(pickedFiles.map((xfile) => File(xfile.path)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeImageAt(int index) {
|
||||
if (index >= 0 && index < selectedImages.length) {
|
||||
selectedImages.removeAt(index);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,152 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/model/dailyTaskPlanning/master_work_category_model.dart';
|
||||
|
||||
class AddTaskController extends GetxController {
|
||||
RxMap<String, RxBool> uploadingStates = <String, RxBool>{}.obs;
|
||||
MyFormValidator basicValidator = MyFormValidator();
|
||||
RxnString selectedCategoryId = RxnString();
|
||||
RxnString selectedCategoryName = RxnString();
|
||||
var categoryIdNameMap = <String, String>{}.obs;
|
||||
|
||||
List<Map<String, dynamic>> roles = [];
|
||||
RxnString selectedRoleId = RxnString();
|
||||
RxBool isLoadingWorkMasterCategories = false.obs;
|
||||
RxList<WorkCategoryModel> workMasterCategories = <WorkCategoryModel>[].obs;
|
||||
|
||||
RxBool isLoading = false.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchWorkMasterCategories();
|
||||
}
|
||||
|
||||
String? formFieldValidator(String? value, {required String fieldType}) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return 'This field is required';
|
||||
}
|
||||
if (fieldType == "target" && int.tryParse(value.trim()) == null) {
|
||||
return 'Please enter a valid number';
|
||||
}
|
||||
if (fieldType == "description" && value.trim().length < 5) {
|
||||
return 'Description must be at least 5 characters';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<bool> assignDailyTask({
|
||||
required String workItemId,
|
||||
required int plannedTask,
|
||||
required String description,
|
||||
required List<String> taskTeam,
|
||||
DateTime? assignmentDate,
|
||||
}) async {
|
||||
logSafe("Starting task assignment...", level: LogLevel.info);
|
||||
|
||||
final response = await ApiService.assignDailyTask(
|
||||
workItemId: workItemId,
|
||||
plannedTask: plannedTask,
|
||||
description: description,
|
||||
taskTeam: taskTeam,
|
||||
assignmentDate: assignmentDate,
|
||||
);
|
||||
|
||||
if (response == true) {
|
||||
logSafe("Task assigned successfully.", level: LogLevel.info);
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "Task assigned successfully!",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
logSafe("Failed to assign task.", level: LogLevel.error);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to assign task.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> createTask({
|
||||
required String parentTaskId,
|
||||
required String workAreaId,
|
||||
required String activityId,
|
||||
required int plannedTask,
|
||||
required String comment,
|
||||
required String categoryId,
|
||||
DateTime? assignmentDate,
|
||||
}) async {
|
||||
logSafe("Creating new task...", level: LogLevel.info);
|
||||
|
||||
final response = await ApiService.createTask(
|
||||
parentTaskId: parentTaskId,
|
||||
plannedTask: plannedTask,
|
||||
comment: comment,
|
||||
workAreaId: workAreaId,
|
||||
activityId: activityId,
|
||||
assignmentDate: assignmentDate,
|
||||
categoryId: categoryId,
|
||||
);
|
||||
|
||||
if (response == true) {
|
||||
logSafe("Task created successfully.", level: LogLevel.info);
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "Task created successfully!",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
logSafe("Failed to create task.", level: LogLevel.error);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to create task.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchWorkMasterCategories() async {
|
||||
isLoadingWorkMasterCategories.value = true;
|
||||
|
||||
try {
|
||||
final response = await ApiService.getMasterWorkCategories();
|
||||
if (response != null) {
|
||||
final dataList = response['data'] ?? [];
|
||||
|
||||
final parsedList = List<WorkCategoryModel>.from(
|
||||
dataList.map((e) => WorkCategoryModel.fromJson(e)),
|
||||
);
|
||||
|
||||
workMasterCategories.assignAll(parsedList);
|
||||
final mapped = {for (var item in parsedList) item.id: item.name};
|
||||
categoryIdNameMap.assignAll(mapped);
|
||||
|
||||
logSafe("Work categories fetched: ${dataList.length}", level: LogLevel.info);
|
||||
} else {
|
||||
logSafe("No work categories found or API call failed.", level: LogLevel.warning);
|
||||
}
|
||||
} catch (e, st) {
|
||||
logSafe("Error parsing work categories", level: LogLevel.error, error: e, stackTrace: st);
|
||||
workMasterCategories.clear();
|
||||
categoryIdNameMap.clear();
|
||||
}
|
||||
|
||||
isLoadingWorkMasterCategories.value = false;
|
||||
update();
|
||||
}
|
||||
|
||||
void selectCategory(String id) {
|
||||
selectedCategoryId.value = id;
|
||||
selectedCategoryName.value = categoryIdNameMap[id];
|
||||
logSafe("Category selected", level: LogLevel.debug, );
|
||||
}
|
||||
}
|
@ -1,198 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/model/project_model.dart';
|
||||
import 'package:marco/model/dailyTaskPlanning/daily_task_model.dart';
|
||||
import 'package:marco/model/dailyTaskPlanning/daily_progress_report_filter_response_model.dart';
|
||||
|
||||
class DailyTaskController extends GetxController {
|
||||
List<ProjectModel> projects = [];
|
||||
String? selectedProjectId;
|
||||
|
||||
DateTime? startDateTask;
|
||||
DateTime? endDateTask;
|
||||
|
||||
List<TaskModel> dailyTasks = [];
|
||||
final RxSet<String> expandedDates = <String>{}.obs;
|
||||
|
||||
void toggleDate(String dateKey) {
|
||||
if (expandedDates.contains(dateKey)) {
|
||||
expandedDates.remove(dateKey);
|
||||
} else {
|
||||
expandedDates.add(dateKey);
|
||||
}
|
||||
}
|
||||
|
||||
RxSet<String> selectedBuildings = <String>{}.obs;
|
||||
RxSet<String> selectedFloors = <String>{}.obs;
|
||||
RxSet<String> selectedActivities = <String>{}.obs;
|
||||
RxSet<String> selectedServices = <String>{}.obs;
|
||||
|
||||
RxBool isFilterLoading = false.obs;
|
||||
RxBool isLoading = true.obs;
|
||||
RxBool isLoadingMore = false.obs;
|
||||
Map<String, List<TaskModel>> groupedDailyTasks = {};
|
||||
// Pagination
|
||||
int currentPage = 1;
|
||||
int pageSize = 20;
|
||||
bool hasMore = true;
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
_initializeDefaults();
|
||||
}
|
||||
|
||||
void _initializeDefaults() {
|
||||
_setDefaultDateRange();
|
||||
}
|
||||
|
||||
void _setDefaultDateRange() {
|
||||
final today = DateTime.now();
|
||||
startDateTask = today.subtract(const Duration(days: 7));
|
||||
endDateTask = today;
|
||||
|
||||
logSafe(
|
||||
"Default date range set: $startDateTask to $endDateTask",
|
||||
level: LogLevel.info,
|
||||
);
|
||||
}
|
||||
|
||||
void clearTaskFilters() {
|
||||
selectedBuildings.clear();
|
||||
selectedFloors.clear();
|
||||
selectedActivities.clear();
|
||||
selectedServices.clear();
|
||||
startDateTask = null;
|
||||
endDateTask = null;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> fetchTaskData(
|
||||
String projectId, {
|
||||
int pageNumber = 1,
|
||||
int pageSize = 20,
|
||||
bool isLoadMore = false,
|
||||
}) async {
|
||||
if (!isLoadMore) {
|
||||
isLoading.value = true;
|
||||
currentPage = 1;
|
||||
hasMore = true;
|
||||
groupedDailyTasks.clear();
|
||||
dailyTasks.clear();
|
||||
} else {
|
||||
isLoadingMore.value = true;
|
||||
}
|
||||
|
||||
// Create the filter object
|
||||
final filter = {
|
||||
"buildingIds": selectedBuildings.toList(),
|
||||
"floorIds": selectedFloors.toList(),
|
||||
"activityIds": selectedActivities.toList(),
|
||||
"serviceIds": selectedServices.toList(),
|
||||
"dateFrom": startDateTask?.toIso8601String(),
|
||||
"dateTo": endDateTask?.toIso8601String(),
|
||||
};
|
||||
|
||||
final response = await ApiService.getDailyTasks(
|
||||
projectId,
|
||||
filter: filter,
|
||||
pageNumber: pageNumber,
|
||||
pageSize: pageSize,
|
||||
);
|
||||
|
||||
if (response != null && response.isNotEmpty) {
|
||||
for (var task in response) {
|
||||
final assignmentDateKey =
|
||||
task.assignmentDate.toIso8601String().split('T')[0];
|
||||
groupedDailyTasks.putIfAbsent(assignmentDateKey, () => []).add(task);
|
||||
}
|
||||
dailyTasks = groupedDailyTasks.values.expand((list) => list).toList();
|
||||
currentPage = pageNumber;
|
||||
} else {
|
||||
hasMore = false;
|
||||
}
|
||||
|
||||
isLoading.value = false;
|
||||
isLoadingMore.value = false;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
FilterData? taskFilterData;
|
||||
|
||||
Future<void> fetchTaskFilter(String projectId) async {
|
||||
isFilterLoading.value = true;
|
||||
try {
|
||||
final filterResponse = await ApiService.getDailyTaskFilter(projectId);
|
||||
|
||||
if (filterResponse != null && filterResponse.success) {
|
||||
taskFilterData =
|
||||
filterResponse.data; // now taskFilterData is FilterData?
|
||||
logSafe(
|
||||
"Task filter fetched successfully. Buildings: ${taskFilterData?.buildings.length}, Floors: ${taskFilterData?.floors.length}",
|
||||
level: LogLevel.info,
|
||||
);
|
||||
} else {
|
||||
logSafe(
|
||||
"Failed to fetch task filter for projectId: $projectId",
|
||||
level: LogLevel.warning,
|
||||
);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
logSafe("Exception in fetchTaskFilter: $e", level: LogLevel.error);
|
||||
logSafe("StackTrace: $stack", level: LogLevel.debug);
|
||||
} finally {
|
||||
isFilterLoading.value = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> selectDateRangeForTaskData(
|
||||
BuildContext context,
|
||||
DailyTaskController controller,
|
||||
) async {
|
||||
final picked = await showDateRangePicker(
|
||||
context: context,
|
||||
firstDate: DateTime(2022),
|
||||
lastDate: DateTime.now(),
|
||||
initialDateRange: DateTimeRange(
|
||||
start:
|
||||
startDateTask ?? DateTime.now().subtract(const Duration(days: 7)),
|
||||
end: endDateTask ?? DateTime.now(),
|
||||
),
|
||||
);
|
||||
|
||||
if (picked == null) {
|
||||
logSafe("Date range picker cancelled by user.", level: LogLevel.debug);
|
||||
return;
|
||||
}
|
||||
|
||||
startDateTask = picked.start;
|
||||
endDateTask = picked.end;
|
||||
|
||||
logSafe(
|
||||
"Date range selected: $startDateTask to $endDateTask",
|
||||
level: LogLevel.info,
|
||||
);
|
||||
|
||||
// ✅ Add null check before calling fetchTaskData
|
||||
final projectId = controller.selectedProjectId;
|
||||
if (projectId != null && projectId.isNotEmpty) {
|
||||
await controller.fetchTaskData(projectId);
|
||||
} else {
|
||||
logSafe("Project ID is null or empty, skipping fetchTaskData",
|
||||
level: LogLevel.warning);
|
||||
}
|
||||
}
|
||||
|
||||
void refreshTasksFromNotification({
|
||||
required String projectId,
|
||||
required String taskAllocationId,
|
||||
}) async {
|
||||
// re-fetch tasks
|
||||
await fetchTaskData(projectId);
|
||||
|
||||
update(); // rebuilds UI
|
||||
}
|
||||
}
|
@ -1,264 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/model/project_model.dart';
|
||||
import 'package:marco/model/dailyTaskPlanning/daily_task_planning_model.dart';
|
||||
import 'package:marco/model/employees/employee_model.dart';
|
||||
|
||||
class DailyTaskPlanningController extends GetxController {
|
||||
List<ProjectModel> projects = [];
|
||||
RxList<EmployeeModel> employees = <EmployeeModel>[].obs;
|
||||
RxList<EmployeeModel> selectedEmployees = <EmployeeModel>[].obs;
|
||||
List<EmployeeModel> allEmployeesCache = [];
|
||||
List<TaskPlanningDetailsModel> dailyTasks = [];
|
||||
RxMap<String, RxBool> uploadingStates = <String, RxBool>{}.obs;
|
||||
|
||||
MyFormValidator basicValidator = MyFormValidator();
|
||||
List<Map<String, dynamic>> roles = [];
|
||||
RxBool isAssigningTask = false.obs;
|
||||
RxnString selectedRoleId = RxnString();
|
||||
RxBool isFetchingTasks = true.obs;
|
||||
RxBool isFetchingProjects = true.obs;
|
||||
RxBool isFetchingEmployees = true.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchRoles();
|
||||
}
|
||||
|
||||
String? formFieldValidator(String? value, {required String fieldType}) {
|
||||
if (value == null || value.trim().isEmpty) return 'This field is required';
|
||||
if (fieldType == "target" && int.tryParse(value.trim()) == null) {
|
||||
return 'Please enter a valid number';
|
||||
}
|
||||
if (fieldType == "description" && value.trim().length < 5) {
|
||||
return 'Description must be at least 5 characters';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void updateSelectedEmployees() {
|
||||
selectedEmployees.value =
|
||||
employees.where((e) => uploadingStates[e.id]?.value == true).toList();
|
||||
logSafe("Updated selected employees", level: LogLevel.debug);
|
||||
}
|
||||
|
||||
void onRoleSelected(String? roleId) {
|
||||
selectedRoleId.value = roleId;
|
||||
logSafe("Role selected", level: LogLevel.info);
|
||||
}
|
||||
|
||||
Future<void> fetchRoles() async {
|
||||
logSafe("Fetching roles...", level: LogLevel.info);
|
||||
final result = await ApiService.getRoles();
|
||||
if (result != null) {
|
||||
roles = List<Map<String, dynamic>>.from(result);
|
||||
logSafe("Roles fetched successfully", level: LogLevel.info);
|
||||
update();
|
||||
} else {
|
||||
logSafe("Failed to fetch roles", level: LogLevel.error);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> assignDailyTask({
|
||||
required String workItemId,
|
||||
required int plannedTask,
|
||||
required String description,
|
||||
required List<String> taskTeam,
|
||||
DateTime? assignmentDate,
|
||||
String? organizationId,
|
||||
String? serviceId,
|
||||
}) async {
|
||||
isAssigningTask.value = true;
|
||||
logSafe("Starting assign task...", level: LogLevel.info);
|
||||
|
||||
final response = await ApiService.assignDailyTask(
|
||||
workItemId: workItemId,
|
||||
plannedTask: plannedTask,
|
||||
description: description,
|
||||
taskTeam: taskTeam,
|
||||
assignmentDate: assignmentDate,
|
||||
organizationId: organizationId,
|
||||
serviceId: serviceId,
|
||||
);
|
||||
|
||||
isAssigningTask.value = false;
|
||||
|
||||
if (response == true) {
|
||||
logSafe("Task assigned successfully", level: LogLevel.info);
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "Task assigned successfully!",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
logSafe("Failed to assign task", level: LogLevel.error);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to assign task.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch Infra details and then tasks per work area
|
||||
Future<void> fetchTaskData(String? projectId, {String? serviceId}) async {
|
||||
if (projectId == null) return;
|
||||
|
||||
isFetchingTasks.value = true;
|
||||
try {
|
||||
final infraResponse = await ApiService.getInfraDetails(
|
||||
projectId,
|
||||
serviceId: serviceId,
|
||||
);
|
||||
final infraData = infraResponse?['data'] as List<dynamic>?;
|
||||
|
||||
if (infraData == null || infraData.isEmpty) {
|
||||
dailyTasks = [];
|
||||
return;
|
||||
}
|
||||
|
||||
dailyTasks = infraData.map((buildingJson) {
|
||||
final building = Building(
|
||||
id: buildingJson['id'],
|
||||
name: buildingJson['buildingName'],
|
||||
description: buildingJson['description'],
|
||||
floors: (buildingJson['floors'] as List<dynamic>)
|
||||
.map((floorJson) => Floor(
|
||||
id: floorJson['id'],
|
||||
floorName: floorJson['floorName'],
|
||||
workAreas: (floorJson['workAreas'] as List<dynamic>)
|
||||
.map((areaJson) => WorkArea(
|
||||
id: areaJson['id'],
|
||||
areaName: areaJson['areaName'],
|
||||
workItems: [],
|
||||
))
|
||||
.toList(),
|
||||
))
|
||||
.toList(),
|
||||
);
|
||||
return TaskPlanningDetailsModel(
|
||||
id: building.id,
|
||||
name: building.name,
|
||||
projectAddress: "",
|
||||
contactPerson: "",
|
||||
startDate: DateTime.now(),
|
||||
endDate: DateTime.now(),
|
||||
projectStatusId: "",
|
||||
buildings: [building],
|
||||
);
|
||||
}).toList();
|
||||
|
||||
await Future.wait(dailyTasks
|
||||
.expand((task) => task.buildings)
|
||||
.expand((b) => b.floors)
|
||||
.expand((f) => f.workAreas)
|
||||
.map((area) async {
|
||||
try {
|
||||
final taskResponse =
|
||||
await ApiService.getWorkItemsByWorkArea(area.id, serviceId: serviceId);
|
||||
final taskData = taskResponse?['data'] as List<dynamic>? ?? [];
|
||||
area.workItems.addAll(taskData.map((taskJson) => WorkItemWrapper(
|
||||
workItemId: taskJson['id'],
|
||||
workItem: WorkItem(
|
||||
id: taskJson['id'],
|
||||
activityMaster: taskJson['activityMaster'] != null
|
||||
? ActivityMaster.fromJson(taskJson['activityMaster'])
|
||||
: null,
|
||||
workCategoryMaster: taskJson['workCategoryMaster'] != null
|
||||
? WorkCategoryMaster.fromJson(taskJson['workCategoryMaster'])
|
||||
: null,
|
||||
plannedWork: (taskJson['plannedWork'] as num?)?.toDouble(),
|
||||
completedWork: (taskJson['completedWork'] as num?)?.toDouble(),
|
||||
todaysAssigned: (taskJson['todaysAssigned'] as num?)?.toDouble(),
|
||||
description: taskJson['description'] as String?,
|
||||
taskDate: taskJson['taskDate'] != null
|
||||
? DateTime.tryParse(taskJson['taskDate'])
|
||||
: null,
|
||||
),
|
||||
)));
|
||||
} catch (e, stack) {
|
||||
logSafe("Error fetching tasks for work area ${area.id}",
|
||||
level: LogLevel.error, error: e, stackTrace: stack);
|
||||
}
|
||||
}));
|
||||
} catch (e, stack) {
|
||||
logSafe("Error fetching daily task data",
|
||||
level: LogLevel.error, error: e, stackTrace: stack);
|
||||
} finally {
|
||||
isFetchingTasks.value = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchEmployeesByProjectService({
|
||||
required String projectId,
|
||||
String? serviceId,
|
||||
String? organizationId,
|
||||
}) async {
|
||||
isFetchingEmployees.value = true;
|
||||
|
||||
try {
|
||||
final response = await ApiService.getEmployeesByProjectService(
|
||||
projectId,
|
||||
serviceId: serviceId ?? '',
|
||||
organizationId: organizationId ?? '',
|
||||
);
|
||||
|
||||
if (response != null && response.isNotEmpty) {
|
||||
employees.assignAll(response.map((json) => EmployeeModel.fromJson(json)));
|
||||
|
||||
if (serviceId == null && organizationId == null) {
|
||||
allEmployeesCache = List.from(employees);
|
||||
}
|
||||
|
||||
final currentEmployeeIds = employees.map((e) => e.id).toSet();
|
||||
|
||||
uploadingStates.removeWhere((key, _) => !currentEmployeeIds.contains(key));
|
||||
employees.forEach((emp) {
|
||||
uploadingStates.putIfAbsent(emp.id, () => false.obs);
|
||||
});
|
||||
|
||||
selectedEmployees.removeWhere((e) => !currentEmployeeIds.contains(e.id));
|
||||
|
||||
logSafe("Employees fetched: ${employees.length}", level: LogLevel.info);
|
||||
} else {
|
||||
employees.clear();
|
||||
uploadingStates.clear();
|
||||
selectedEmployees.clear();
|
||||
logSafe(
|
||||
serviceId != null || organizationId != null
|
||||
? "Filtered employees empty"
|
||||
: "No employees found",
|
||||
level: LogLevel.warning,
|
||||
);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
logSafe("Error fetching employees", level: LogLevel.error, error: e, stackTrace: stack);
|
||||
|
||||
if (serviceId == null && organizationId == null && allEmployeesCache.isNotEmpty) {
|
||||
employees.assignAll(allEmployeesCache);
|
||||
|
||||
final cachedEmployeeIds = employees.map((e) => e.id).toSet();
|
||||
uploadingStates.removeWhere((key, _) => !cachedEmployeeIds.contains(key));
|
||||
employees.forEach((emp) {
|
||||
uploadingStates.putIfAbsent(emp.id, () => false.obs);
|
||||
});
|
||||
|
||||
selectedEmployees.removeWhere((e) => !cachedEmployeeIds.contains(e.id));
|
||||
} else {
|
||||
employees.clear();
|
||||
uploadingStates.clear();
|
||||
selectedEmployees.clear();
|
||||
}
|
||||
} finally {
|
||||
isFetchingEmployees.value = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,296 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
|
||||
import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/controller/task_Planning/daily_task_Planning_controller.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
||||
import 'package:marco/helpers/widgets/my_image_compressor.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/model/dailyTaskPlanning/work_status_model.dart';
|
||||
|
||||
enum ApiStatus { idle, loading, success, failure }
|
||||
|
||||
class ReportTaskActionController extends MyController {
|
||||
final RxBool isLoading = false.obs;
|
||||
final Rx<ApiStatus> reportStatus = ApiStatus.idle.obs;
|
||||
final Rx<ApiStatus> commentStatus = ApiStatus.idle.obs;
|
||||
|
||||
final RxList<File> selectedImages = <File>[].obs;
|
||||
final RxList<WorkStatus> workStatus = <WorkStatus>[].obs;
|
||||
final RxList<WorkStatus> workStatuses = <WorkStatus>[].obs;
|
||||
|
||||
final RxBool showAddTaskCheckbox = false.obs;
|
||||
final RxBool isAddTaskChecked = false.obs;
|
||||
|
||||
final RxBool isLoadingWorkStatus = false.obs;
|
||||
final Rxn<Map<String, dynamic>> selectedTask = Rxn<Map<String, dynamic>>();
|
||||
|
||||
final RxString selectedWorkStatusName = ''.obs;
|
||||
|
||||
final MyFormValidator basicValidator = MyFormValidator();
|
||||
final DailyTaskPlanningController taskController = Get.put(DailyTaskPlanningController());
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
|
||||
final assignedDateController = TextEditingController();
|
||||
final workAreaController = TextEditingController();
|
||||
final activityController = TextEditingController();
|
||||
final teamSizeController = TextEditingController();
|
||||
final taskIdController = TextEditingController();
|
||||
final assignedController = TextEditingController();
|
||||
final completedWorkController = TextEditingController();
|
||||
final commentController = TextEditingController();
|
||||
final assignedByController = TextEditingController();
|
||||
final teamMembersController = TextEditingController();
|
||||
final plannedWorkController = TextEditingController();
|
||||
final approvedTaskController = TextEditingController();
|
||||
|
||||
List<TextEditingController> get _allControllers => [
|
||||
assignedDateController,
|
||||
workAreaController,
|
||||
activityController,
|
||||
teamSizeController,
|
||||
taskIdController,
|
||||
assignedController,
|
||||
completedWorkController,
|
||||
commentController,
|
||||
assignedByController,
|
||||
teamMembersController,
|
||||
plannedWorkController,
|
||||
approvedTaskController,
|
||||
];
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
logSafe("Initializing ReportTaskController...");
|
||||
_initializeFormFields();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
for (final controller in _allControllers) {
|
||||
controller.dispose();
|
||||
}
|
||||
logSafe("Disposed all text controllers in ReportTaskActionController.");
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
void _initializeFormFields() {
|
||||
basicValidator
|
||||
..addField('assigned_date', label: "Assigned Date", controller: assignedDateController)
|
||||
..addField('work_area', label: "Work Area", controller: workAreaController)
|
||||
..addField('activity', label: "Activity", controller: activityController)
|
||||
..addField('team_size', label: "Team Size", controller: teamSizeController)
|
||||
..addField('task_id', label: "Task Id", controller: taskIdController)
|
||||
..addField('assigned', label: "Assigned", controller: assignedController)
|
||||
..addField('completed_work', label: "Completed Work", required: true, controller: completedWorkController)
|
||||
..addField('comment', label: "Comment", required: true, controller: commentController)
|
||||
..addField('assigned_by', label: "Assigned By", controller: assignedByController)
|
||||
..addField('team_members', label: "Team Members", controller: teamMembersController)
|
||||
..addField('planned_work', label: "Planned Work", controller: plannedWorkController)
|
||||
..addField('approved_task', label: "Approved Task", required: true, controller: approvedTaskController);
|
||||
}
|
||||
|
||||
Future<bool> approveTask({
|
||||
required String projectId,
|
||||
required String comment,
|
||||
required String reportActionId,
|
||||
required String approvedTaskCount,
|
||||
List<File>? images,
|
||||
}) async {
|
||||
logSafe("approveTask() started", sensitive: false);
|
||||
|
||||
if (projectId.isEmpty || reportActionId.isEmpty) {
|
||||
_showError("Project ID and Report Action ID are required.");
|
||||
logSafe("Missing required projectId or reportActionId", level: LogLevel.warning);
|
||||
return false;
|
||||
}
|
||||
|
||||
final approvedTaskInt = int.tryParse(approvedTaskCount);
|
||||
final completedWorkInt = int.tryParse(completedWorkController.text.trim());
|
||||
|
||||
if (approvedTaskInt == null) {
|
||||
_showError("Invalid approved task count.");
|
||||
logSafe("Invalid approvedTaskCount: $approvedTaskCount", level: LogLevel.warning);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (completedWorkInt != null && approvedTaskInt > completedWorkInt) {
|
||||
_showError("Approved task count cannot exceed completed work.");
|
||||
logSafe("Validation failed: approved > completed", level: LogLevel.warning);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (comment.trim().isEmpty) {
|
||||
_showError("Comment is required.");
|
||||
logSafe("Comment field is empty", level: LogLevel.warning);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
reportStatus.value = ApiStatus.loading;
|
||||
isLoading.value = true;
|
||||
logSafe("Calling _prepareImages() for approval...");
|
||||
final imageData = await _prepareImages(images);
|
||||
|
||||
logSafe("Calling ApiService.approveTask()");
|
||||
final success = await ApiService.approveTask(
|
||||
id: projectId,
|
||||
workStatus: reportActionId,
|
||||
approvedTask: approvedTaskInt,
|
||||
comment: comment,
|
||||
images: imageData,
|
||||
);
|
||||
|
||||
if (success) {
|
||||
logSafe("Task approved successfully");
|
||||
_showSuccess("Task approved successfully!");
|
||||
await taskController.fetchTaskData(projectId);
|
||||
return true;
|
||||
} else {
|
||||
logSafe("API returned failure on approveTask", level: LogLevel.error);
|
||||
_showError("Failed to approve task.");
|
||||
return false;
|
||||
}
|
||||
} catch (e, st) {
|
||||
logSafe("Error in approveTask: $e", level: LogLevel.error, error: e, stackTrace: st);
|
||||
_showError("An error occurred.");
|
||||
return false;
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
reportStatus.value = ApiStatus.idle;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> commentTask({
|
||||
required String projectId,
|
||||
required String comment,
|
||||
List<File>? images,
|
||||
}) async {
|
||||
logSafe("commentTask() started", sensitive: false);
|
||||
|
||||
if (commentController.text.trim().isEmpty) {
|
||||
_showError("Comment is required.");
|
||||
logSafe("Comment field is empty", level: LogLevel.warning);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
isLoading.value = true;
|
||||
|
||||
logSafe("Calling _prepareImages() for comment...");
|
||||
final imageData = await _prepareImages(images);
|
||||
|
||||
logSafe("Calling ApiService.commentTask()");
|
||||
final success = await ApiService.commentTask(
|
||||
id: projectId,
|
||||
comment: commentController.text.trim(),
|
||||
images: imageData,
|
||||
).timeout(const Duration(seconds: 30), onTimeout: () {
|
||||
throw Exception("Request timed out.");
|
||||
});
|
||||
|
||||
if (success) {
|
||||
logSafe("Comment added successfully");
|
||||
_showSuccess("Task commented successfully!");
|
||||
await taskController.fetchTaskData(projectId);
|
||||
} else {
|
||||
logSafe("API returned failure on commentTask", level: LogLevel.error);
|
||||
_showError("Failed to comment task.");
|
||||
}
|
||||
} catch (e, st) {
|
||||
logSafe("Error in commentTask: $e", level: LogLevel.error, error: e, stackTrace: st);
|
||||
_showError("An error occurred while commenting the task.");
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchWorkStatuses() async {
|
||||
logSafe("Fetching work statuses...");
|
||||
isLoadingWorkStatus.value = true;
|
||||
|
||||
final response = await ApiService.getWorkStatus();
|
||||
if (response != null) {
|
||||
final model = WorkStatusResponseModel.fromJson(response);
|
||||
workStatus.assignAll(model.data);
|
||||
logSafe("Fetched ${model.data.length} work statuses");
|
||||
} else {
|
||||
logSafe("No work statuses found or API call failed", level: LogLevel.warning);
|
||||
}
|
||||
|
||||
isLoadingWorkStatus.value = false;
|
||||
update(['dashboard_controller']);
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>?> _prepareImages(List<File>? images) async {
|
||||
if (images == null || images.isEmpty) {
|
||||
logSafe("_prepareImages: No images selected.");
|
||||
return null;
|
||||
}
|
||||
|
||||
logSafe("_prepareImages: Compressing and encoding images...");
|
||||
final results = await Future.wait(images.map((file) async {
|
||||
final compressedBytes = await compressImageToUnder100KB(file);
|
||||
if (compressedBytes == null) return null;
|
||||
|
||||
return {
|
||||
"fileName": file.path.split('/').last,
|
||||
"base64Data": base64Encode(compressedBytes),
|
||||
"contentType": _getContentTypeFromFileName(file.path),
|
||||
"fileSize": compressedBytes.lengthInBytes,
|
||||
"description": "Image uploaded for task",
|
||||
};
|
||||
}));
|
||||
|
||||
logSafe("_prepareImages: Prepared ${results.whereType<Map<String, dynamic>>().length} images.");
|
||||
return results.whereType<Map<String, dynamic>>().toList();
|
||||
}
|
||||
|
||||
String _getContentTypeFromFileName(String fileName) {
|
||||
final ext = fileName.split('.').last.toLowerCase();
|
||||
return switch (ext) {
|
||||
'jpg' || 'jpeg' => 'image/jpeg',
|
||||
'png' => 'image/png',
|
||||
'webp' => 'image/webp',
|
||||
'gif' => 'image/gif',
|
||||
_ => 'application/octet-stream',
|
||||
};
|
||||
}
|
||||
|
||||
Future<void> pickImages({required bool fromCamera}) async {
|
||||
logSafe("Opening image picker...");
|
||||
if (fromCamera) {
|
||||
final pickedFile = await _picker.pickImage(source: ImageSource.camera, imageQuality: 75);
|
||||
if (pickedFile != null) {
|
||||
selectedImages.add(File(pickedFile.path));
|
||||
logSafe("Image added from camera: ${pickedFile.path}", );
|
||||
}
|
||||
} else {
|
||||
final pickedFiles = await _picker.pickMultiImage(imageQuality: 75);
|
||||
selectedImages.addAll(pickedFiles.map((xfile) => File(xfile.path)));
|
||||
logSafe("${pickedFiles.length} images added from gallery.", );
|
||||
}
|
||||
}
|
||||
|
||||
void removeImageAt(int index) {
|
||||
if (index >= 0 && index < selectedImages.length) {
|
||||
logSafe("Removing image at index $index", );
|
||||
selectedImages.removeAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
void _showError(String message) => showAppSnackbar(
|
||||
title: "Error", message: message, type: SnackbarType.error);
|
||||
|
||||
void _showSuccess(String message) => showAppSnackbar(
|
||||
title: "Success", message: message, type: SnackbarType.success);
|
||||
}
|
@ -1,248 +0,0 @@
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/controller/task_Planning/daily_task_Planning_controller.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'dart:io';
|
||||
import 'dart:convert';
|
||||
import 'package:marco/helpers/widgets/my_image_compressor.dart';
|
||||
|
||||
enum ApiStatus { idle, loading, success, failure }
|
||||
|
||||
final DailyTaskPlanningController taskController = Get.put(DailyTaskPlanningController());
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
|
||||
class ReportTaskController extends MyController {
|
||||
List<PlatformFile> files = [];
|
||||
MyFormValidator basicValidator = MyFormValidator();
|
||||
RxBool isLoading = false.obs;
|
||||
Rx<ApiStatus> reportStatus = ApiStatus.idle.obs;
|
||||
Rx<ApiStatus> commentStatus = ApiStatus.idle.obs;
|
||||
|
||||
RxList<File> selectedImages = <File>[].obs;
|
||||
|
||||
final assignedDateController = TextEditingController();
|
||||
final workAreaController = TextEditingController();
|
||||
final activityController = TextEditingController();
|
||||
final teamSizeController = TextEditingController();
|
||||
final taskIdController = TextEditingController();
|
||||
final assignedController = TextEditingController();
|
||||
final completedWorkController = TextEditingController();
|
||||
final commentController = TextEditingController();
|
||||
final assignedByController = TextEditingController();
|
||||
final teamMembersController = TextEditingController();
|
||||
final plannedWorkController = TextEditingController();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
logSafe("Initializing ReportTaskController...");
|
||||
basicValidator
|
||||
..addField('assigned_date', label: "Assigned Date", controller: assignedDateController)
|
||||
..addField('work_area', label: "Work Area", controller: workAreaController)
|
||||
..addField('activity', label: "Activity", controller: activityController)
|
||||
..addField('team_size', label: "Team Size", controller: teamSizeController)
|
||||
..addField('task_id', label: "Task Id", controller: taskIdController)
|
||||
..addField('assigned', label: "Assigned", controller: assignedController)
|
||||
..addField('completed_work', label: "Completed Work", required: true, controller: completedWorkController)
|
||||
..addField('comment', label: "Comment", required: true, controller: commentController)
|
||||
..addField('assigned_by', label: "Assigned By", controller: assignedByController)
|
||||
..addField('team_members', label: "Team Members", controller: teamMembersController)
|
||||
..addField('planned_work', label: "Planned Work", controller: plannedWorkController);
|
||||
logSafe("Form fields initialized.");
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
[
|
||||
assignedDateController,
|
||||
workAreaController,
|
||||
activityController,
|
||||
teamSizeController,
|
||||
taskIdController,
|
||||
assignedController,
|
||||
completedWorkController,
|
||||
commentController,
|
||||
assignedByController,
|
||||
teamMembersController,
|
||||
plannedWorkController,
|
||||
].forEach((controller) => controller.dispose());
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
Future<bool> reportTask({
|
||||
required String projectId,
|
||||
required String comment,
|
||||
required int completedTask,
|
||||
required List<Map<String, dynamic>> checklist,
|
||||
required DateTime reportedDate,
|
||||
List<File>? images,
|
||||
}) async {
|
||||
logSafe("Reporting task for projectId", );
|
||||
final completedWork = completedWorkController.text.trim();
|
||||
if (completedWork.isEmpty || int.tryParse(completedWork) == null || int.parse(completedWork) < 0) {
|
||||
_showError("Completed work must be a positive number.");
|
||||
return false;
|
||||
}
|
||||
|
||||
final commentField = commentController.text.trim();
|
||||
if (commentField.isEmpty) {
|
||||
_showError("Comment is required.");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
reportStatus.value = ApiStatus.loading;
|
||||
isLoading.value = true;
|
||||
|
||||
final imageData = await _prepareImages(images, "task report");
|
||||
|
||||
final success = await ApiService.reportTask(
|
||||
id: projectId,
|
||||
comment: commentField,
|
||||
completedTask: int.parse(completedWork),
|
||||
checkList: checklist,
|
||||
images: imageData,
|
||||
);
|
||||
|
||||
if (success) {
|
||||
reportStatus.value = ApiStatus.success;
|
||||
_showSuccess("Task reported successfully!");
|
||||
await taskController.fetchTaskData(projectId);
|
||||
return true;
|
||||
} else {
|
||||
reportStatus.value = ApiStatus.failure;
|
||||
_showError("Failed to report task.");
|
||||
return false;
|
||||
}
|
||||
} catch (e, s) {
|
||||
logSafe("Exception while reporting task", level: LogLevel.error, error: e, stackTrace: s);
|
||||
reportStatus.value = ApiStatus.failure;
|
||||
_showError("An error occurred while reporting the task.");
|
||||
return false;
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
reportStatus.value = ApiStatus.idle;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> commentTask({
|
||||
required String projectId,
|
||||
required String comment,
|
||||
List<File>? images,
|
||||
}) async {
|
||||
logSafe("Submitting comment for project", );
|
||||
|
||||
final commentField = commentController.text.trim();
|
||||
if (commentField.isEmpty) {
|
||||
_showError("Comment is required.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
isLoading.value = true;
|
||||
final imageData = await _prepareImages(images, "task comment");
|
||||
|
||||
final success = await ApiService.commentTask(
|
||||
id: projectId,
|
||||
comment: commentField,
|
||||
images: imageData,
|
||||
).timeout(const Duration(seconds: 30), onTimeout: () {
|
||||
logSafe("Task comment request timed out.", level: LogLevel.error);
|
||||
throw Exception("Request timed out.");
|
||||
});
|
||||
|
||||
if (success) {
|
||||
_showSuccess("Task commented successfully!");
|
||||
await taskController.fetchTaskData(projectId);
|
||||
} else {
|
||||
_showError("Failed to comment task.");
|
||||
}
|
||||
} catch (e, s) {
|
||||
logSafe("Exception while commenting task", level: LogLevel.error, error: e, stackTrace: s);
|
||||
_showError("An error occurred while commenting the task.");
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>?> _prepareImages(List<File>? images, String context) async {
|
||||
if (images == null || images.isEmpty) return null;
|
||||
|
||||
logSafe("Preparing images for $context upload...");
|
||||
|
||||
final results = await Future.wait(images.map((file) async {
|
||||
try {
|
||||
final compressed = await compressImageToUnder100KB(file);
|
||||
if (compressed == null) return null;
|
||||
|
||||
return {
|
||||
"fileName": file.path.split('/').last,
|
||||
"base64Data": base64Encode(compressed),
|
||||
"contentType": _getContentTypeFromFileName(file.path),
|
||||
"fileSize": compressed.lengthInBytes,
|
||||
"description": "Image uploaded for $context",
|
||||
};
|
||||
} catch (e) {
|
||||
logSafe("Image processing failed: ${file.path}", level: LogLevel.warning, error: e);
|
||||
return null;
|
||||
}
|
||||
}));
|
||||
|
||||
return results.whereType<Map<String, dynamic>>().toList();
|
||||
}
|
||||
|
||||
String _getContentTypeFromFileName(String fileName) {
|
||||
final ext = fileName.split('.').last.toLowerCase();
|
||||
return switch (ext) {
|
||||
'jpg' || 'jpeg' => 'image/jpeg',
|
||||
'png' => 'image/png',
|
||||
'webp' => 'image/webp',
|
||||
'gif' => 'image/gif',
|
||||
_ => 'application/octet-stream',
|
||||
};
|
||||
}
|
||||
|
||||
Future<void> pickImages({required bool fromCamera}) async {
|
||||
try {
|
||||
if (fromCamera) {
|
||||
final pickedFile = await _picker.pickImage(source: ImageSource.camera, imageQuality: 75);
|
||||
if (pickedFile != null) {
|
||||
selectedImages.add(File(pickedFile.path));
|
||||
}
|
||||
} else {
|
||||
final pickedFiles = await _picker.pickMultiImage(imageQuality: 75);
|
||||
selectedImages.addAll(pickedFiles.map((xfile) => File(xfile.path)));
|
||||
}
|
||||
logSafe("Images picked: ${selectedImages.length}", );
|
||||
} catch (e) {
|
||||
logSafe("Error picking images", level: LogLevel.warning, error: e);
|
||||
}
|
||||
}
|
||||
|
||||
void removeImageAt(int index) {
|
||||
if (index >= 0 && index < selectedImages.length) {
|
||||
selectedImages.removeAt(index);
|
||||
logSafe("Removed image at index $index");
|
||||
}
|
||||
}
|
||||
|
||||
void _showError(String message) => showAppSnackbar(
|
||||
title: "Error",
|
||||
message: message,
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
|
||||
void _showSuccess(String message) => showAppSnackbar(
|
||||
title: "Success",
|
||||
message: message,
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/model/all_organization_model.dart';
|
||||
|
||||
class AllOrganizationController extends GetxController {
|
||||
RxList<AllOrganization> organizations = <AllOrganization>[].obs;
|
||||
Rxn<AllOrganization> selectedOrganization = Rxn<AllOrganization>();
|
||||
final isLoadingOrganizations = false.obs;
|
||||
|
||||
String? passedOrgId;
|
||||
|
||||
AllOrganizationController({this.passedOrgId});
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchAllOrganizations();
|
||||
}
|
||||
|
||||
Future<void> fetchAllOrganizations() async {
|
||||
try {
|
||||
isLoadingOrganizations.value = true;
|
||||
|
||||
final response = await ApiService.getAllOrganizations();
|
||||
if (response != null && response.data.data.isNotEmpty) {
|
||||
organizations.value = response.data.data;
|
||||
|
||||
// Select organization based on passed ID, or fallback to first
|
||||
if (passedOrgId != null) {
|
||||
selectedOrganization.value =
|
||||
organizations.firstWhere(
|
||||
(org) => org.id == passedOrgId,
|
||||
orElse: () => organizations.first,
|
||||
);
|
||||
} else {
|
||||
selectedOrganization.value ??= organizations.first;
|
||||
}
|
||||
} else {
|
||||
organizations.clear();
|
||||
selectedOrganization.value = null;
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
logSafe(
|
||||
"Failed to fetch organizations: $e",
|
||||
level: LogLevel.error,
|
||||
error: e,
|
||||
stackTrace: stackTrace,
|
||||
);
|
||||
organizations.clear();
|
||||
selectedOrganization.value = null;
|
||||
} finally {
|
||||
isLoadingOrganizations.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
void selectOrganization(AllOrganization? org) {
|
||||
selectedOrganization.value = org;
|
||||
}
|
||||
|
||||
void clearSelection() {
|
||||
selectedOrganization.value = null;
|
||||
}
|
||||
|
||||
String get currentSelection => selectedOrganization.value?.name ?? "All Organizations";
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/model/attendance/organization_per_project_list_model.dart';
|
||||
|
||||
class OrganizationController extends GetxController {
|
||||
/// List of organizations assigned to the selected project
|
||||
List<Organization> organizations = [];
|
||||
|
||||
/// Currently selected organization (reactive)
|
||||
Rxn<Organization> selectedOrganization = Rxn<Organization>();
|
||||
|
||||
/// Loading state for fetching organizations
|
||||
final isLoadingOrganizations = false.obs;
|
||||
|
||||
/// Fetch organizations assigned to a given project
|
||||
Future<void> fetchOrganizations(String projectId) async {
|
||||
try {
|
||||
isLoadingOrganizations.value = true;
|
||||
|
||||
final response = await ApiService.getAssignedOrganizations(projectId);
|
||||
if (response != null && response.data.isNotEmpty) {
|
||||
organizations = response.data;
|
||||
logSafe("Organizations fetched: ${organizations.length}");
|
||||
} else {
|
||||
organizations = [];
|
||||
logSafe("No organizations found for project $projectId",
|
||||
level: LogLevel.warning);
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
logSafe("Failed to fetch organizations: $e",
|
||||
level: LogLevel.error, error: e, stackTrace: stackTrace);
|
||||
organizations = [];
|
||||
} finally {
|
||||
isLoadingOrganizations.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Select an organization
|
||||
void selectOrganization(Organization? org) {
|
||||
selectedOrganization.value = org;
|
||||
}
|
||||
|
||||
/// Clear the selection (set to "All Organizations")
|
||||
void clearSelection() {
|
||||
selectedOrganization.value = null;
|
||||
}
|
||||
|
||||
/// Current selection name for UI
|
||||
String get currentSelection =>
|
||||
selectedOrganization.value?.name ?? "All Organizations";
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/model/tenant/tenant_services_model.dart';
|
||||
|
||||
class ServiceController extends GetxController {
|
||||
List<Service> services = [];
|
||||
Service? selectedService;
|
||||
final isLoadingServices = false.obs;
|
||||
|
||||
/// Fetch services assigned to a project
|
||||
Future<void> fetchServices(String projectId) async {
|
||||
try {
|
||||
isLoadingServices.value = true;
|
||||
final response = await ApiService.getAssignedServices(projectId);
|
||||
if (response != null) {
|
||||
services = response.data;
|
||||
logSafe("Services fetched: ${services.length}");
|
||||
} else {
|
||||
logSafe("Failed to fetch services for project $projectId",
|
||||
level: LogLevel.error);
|
||||
}
|
||||
} finally {
|
||||
isLoadingServices.value = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
/// Select a service
|
||||
void selectService(Service? service) {
|
||||
selectedService = service;
|
||||
update();
|
||||
}
|
||||
|
||||
/// Clear selection
|
||||
void clearSelection() {
|
||||
selectedService = null;
|
||||
update();
|
||||
}
|
||||
|
||||
/// Current selected name
|
||||
String get currentSelection => selectedService?.name ?? "All Services";
|
||||
}
|
@ -1,136 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/tenant_service.dart';
|
||||
import 'package:marco/model/tenant/tenant_list_model.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/helpers/services/storage/local_storage.dart';
|
||||
import 'package:marco/controller/permission_controller.dart';
|
||||
|
||||
class TenantSelectionController extends GetxController {
|
||||
final TenantService _tenantService = TenantService();
|
||||
|
||||
// Tenant list
|
||||
final tenants = <Tenant>[].obs;
|
||||
|
||||
// Loading state
|
||||
final isLoading = false.obs;
|
||||
|
||||
// Selected tenant ID
|
||||
final selectedTenantId = RxnString();
|
||||
|
||||
// Flag to indicate auto-selection (for splash screen)
|
||||
final isAutoSelecting = false.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
loadTenants();
|
||||
}
|
||||
|
||||
/// Load tenants and handle auto-selection
|
||||
Future<void> loadTenants() async {
|
||||
isLoading.value = true;
|
||||
isAutoSelecting.value = true; // show splash during auto-selection
|
||||
try {
|
||||
final data = await _tenantService.getTenants();
|
||||
if (data == null || data.isEmpty) {
|
||||
tenants.clear();
|
||||
logSafe("⚠️ No tenants found for the user.", level: LogLevel.warning);
|
||||
return;
|
||||
}
|
||||
|
||||
tenants.value = data.map((e) => Tenant.fromJson(e)).toList();
|
||||
|
||||
final recentTenantId = LocalStorage.getRecentTenantId();
|
||||
|
||||
// Auto-select if only one tenant
|
||||
if (tenants.length == 1) {
|
||||
await _selectTenant(tenants.first.id);
|
||||
}
|
||||
// Auto-select recent tenant if available
|
||||
else if (recentTenantId != null) {
|
||||
final recentTenant =
|
||||
tenants.firstWhereOrNull((t) => t.id == recentTenantId);
|
||||
if (recentTenant != null) {
|
||||
await _selectTenant(recentTenant.id);
|
||||
} else {
|
||||
_clearSelection();
|
||||
}
|
||||
}
|
||||
// No auto-selection
|
||||
else {
|
||||
_clearSelection();
|
||||
}
|
||||
} catch (e, st) {
|
||||
logSafe("❌ Exception in loadTenants",
|
||||
level: LogLevel.error, error: e, stackTrace: st);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to load organizations. Please try again.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
isAutoSelecting.value = false; // hide splash
|
||||
}
|
||||
}
|
||||
|
||||
/// User manually selects a tenant
|
||||
Future<void> onTenantSelected(String tenantId) async {
|
||||
isAutoSelecting.value = true;
|
||||
await _selectTenant(tenantId);
|
||||
isAutoSelecting.value = false;
|
||||
}
|
||||
|
||||
/// Internal tenant selection logic
|
||||
Future<void> _selectTenant(String tenantId) async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
|
||||
final success = await _tenantService.selectTenant(tenantId);
|
||||
if (!success) {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Unable to select organization. Please try again.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update tenant & persist
|
||||
final selectedTenant = tenants.firstWhere((t) => t.id == tenantId);
|
||||
TenantService.setSelectedTenant(selectedTenant);
|
||||
selectedTenantId.value = tenantId;
|
||||
await LocalStorage.setRecentTenantId(tenantId);
|
||||
|
||||
// Load permissions if token exists
|
||||
final token = LocalStorage.getJwtToken();
|
||||
if (token != null && token.isNotEmpty) {
|
||||
if (!Get.isRegistered<PermissionController>()) {
|
||||
Get.put(PermissionController());
|
||||
}
|
||||
await Get.find<PermissionController>().loadData(token);
|
||||
}
|
||||
|
||||
// Navigate **before changing isAutoSelecting**
|
||||
await Get.offAllNamed('/dashboard');
|
||||
|
||||
// Then hide splash
|
||||
isAutoSelecting.value = false;
|
||||
} catch (e) {
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "An unexpected error occurred while selecting organization.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Clear tenant selection
|
||||
void _clearSelection() {
|
||||
selectedTenantId.value = null;
|
||||
TenantService.currentTenant = null;
|
||||
}
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/tenant_service.dart';
|
||||
import 'package:marco/model/tenant/tenant_list_model.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/helpers/services/storage/local_storage.dart';
|
||||
import 'package:marco/controller/permission_controller.dart';
|
||||
|
||||
class TenantSwitchController extends GetxController {
|
||||
final TenantService _tenantService = TenantService();
|
||||
|
||||
final tenants = <Tenant>[].obs;
|
||||
final isLoading = false.obs;
|
||||
final selectedTenantId = RxnString();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
loadTenants();
|
||||
}
|
||||
|
||||
/// Load all tenants for switching (does not auto-select)
|
||||
Future<void> loadTenants() async {
|
||||
isLoading.value = true;
|
||||
try {
|
||||
final data = await _tenantService.getTenants();
|
||||
if (data == null || data.isEmpty) {
|
||||
tenants.clear();
|
||||
logSafe("⚠️ No tenants available for switching.", level: LogLevel.warning);
|
||||
return;
|
||||
}
|
||||
|
||||
tenants.value = data.map((e) => Tenant.fromJson(e)).toList();
|
||||
|
||||
// Keep current tenant as selected
|
||||
selectedTenantId.value = TenantService.currentTenant?.id;
|
||||
} catch (e, st) {
|
||||
logSafe("❌ Exception in loadTenants", level: LogLevel.error, error: e, stackTrace: st);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Failed to load organizations for switching.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Switch to a different tenant and navigate fully
|
||||
Future<void> switchTenant(String tenantId) async {
|
||||
if (TenantService.currentTenant?.id == tenantId) return;
|
||||
|
||||
isLoading.value = true;
|
||||
try {
|
||||
final success = await _tenantService.selectTenant(tenantId);
|
||||
if (!success) {
|
||||
logSafe("❌ Tenant switch failed: $tenantId", level: LogLevel.warning);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "Unable to switch organization. Try again.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final selectedTenant = tenants.firstWhere((t) => t.id == tenantId);
|
||||
TenantService.setSelectedTenant(selectedTenant);
|
||||
selectedTenantId.value = tenantId;
|
||||
|
||||
// Persist recent tenant
|
||||
await LocalStorage.setRecentTenantId(tenantId);
|
||||
|
||||
logSafe("✅ Tenant switched successfully: $tenantId");
|
||||
|
||||
// 🔹 Load permissions after tenant switch (null-safe)
|
||||
final token = await LocalStorage.getJwtToken();
|
||||
if (token != null && token.isNotEmpty) {
|
||||
if (!Get.isRegistered<PermissionController>()) {
|
||||
Get.put(PermissionController());
|
||||
logSafe("✅ PermissionController injected after tenant switch.");
|
||||
}
|
||||
await Get.find<PermissionController>().loadData(token);
|
||||
} else {
|
||||
logSafe("⚠️ JWT token is null. Cannot load permissions.", level: LogLevel.warning);
|
||||
}
|
||||
|
||||
// FULL NAVIGATION: reload app/dashboard
|
||||
Get.offAllNamed('/dashboard');
|
||||
|
||||
showAppSnackbar(
|
||||
title: "Success",
|
||||
message: "Switched to organization: ${selectedTenant.name}",
|
||||
type: SnackbarType.success,
|
||||
);
|
||||
} catch (e, st) {
|
||||
logSafe("❌ Exception in switchTenant", level: LogLevel.error, error: e, stackTrace: st);
|
||||
showAppSnackbar(
|
||||
title: "Error",
|
||||
message: "An unexpected error occurred while switching organization.",
|
||||
type: SnackbarType.error,
|
||||
);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
}
|
26
lib/controller/ui/drag_n_drop_controller.dart
Normal file
@ -0,0 +1,26 @@
|
||||
import 'package:marco/controller/my_controller.dart';
|
||||
import 'package:marco/helpers/widgets/my_text_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marco/model/drag_n_drop_model.dart';
|
||||
|
||||
class DragNDropController extends MyController {
|
||||
List<DragNDropModel> dragNDrop = [];
|
||||
final scrollController = ScrollController();
|
||||
final gridViewKey = GlobalKey();
|
||||
List<String> dummyTexts = List.generate(12, (index) => MyTextUtils.getDummyText(60));
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
DragNDropModel.dummyList.then((value) {
|
||||
dragNDrop = value;
|
||||
update();
|
||||
});
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
void onReorder(int oldIndex, int newIndex) {
|
||||
final item = dragNDrop.removeAt(oldIndex);
|
||||
dragNDrop.insert(newIndex, item);
|
||||
update();
|
||||
}
|
||||
}
|
@ -1,103 +1,26 @@
|
||||
class ApiEndpoints {
|
||||
static const String baseUrl = "https://stageapi.marcoaiot.com/api";
|
||||
// static const String baseUrl = "https://api.marcoaiot.com/api";
|
||||
// static const String baseUrl = "https://devapi.marcoaiot.com/api";
|
||||
|
||||
// Dashboard Module API Endpoints
|
||||
static const String getDashboardAttendanceOverview =
|
||||
"/dashboard/attendance-overview";
|
||||
static const String getDashboardProjectProgress = "/dashboard/progression";
|
||||
static const String getDashboardTasks = "/dashboard/tasks";
|
||||
static const String getDashboardTeams = "/dashboard/teams";
|
||||
static const String getDashboardProjects = "/dashboard/projects";
|
||||
|
||||
// Attendance Module API Endpoints
|
||||
// Attendance Screen API Endpoints
|
||||
static const String getProjects = "/project/list";
|
||||
static const String getGlobalProjects = "/project/list/basic";
|
||||
static const String getTodaysAttendance = "/attendance/project/team";
|
||||
static const String getEmployeesByProject = "/attendance/project/team";
|
||||
static const String getAttendanceLogs = "/attendance/project/log";
|
||||
static const String getAttendanceLogView = "/attendance/log/attendance";
|
||||
static const String getRegularizationLogs = "/attendance/regularize";
|
||||
static const String uploadAttendanceImage = "/attendance/record-image";
|
||||
|
||||
// Employee Screen API Endpoints
|
||||
static const String getAllEmployeesByProject = "/employee/list";
|
||||
static const String getAllEmployeesByOrganization = "/project/get/task/team";
|
||||
static const String getAllEmployeesByProject = "/Project/employees/get";
|
||||
static const String getAllEmployees = "/employee/list";
|
||||
static const String getEmployeesWithoutPermission = "/employee/basic";
|
||||
static const String getRoles = "/roles/jobrole";
|
||||
static const String createEmployee = "/employee/app/manage";
|
||||
static const String createEmployee = "/employee/manage";
|
||||
static const String getEmployeeInfo = "/employee/profile/get";
|
||||
static const String assignEmployee = "/employee/profile/get";
|
||||
static const String getAssignedProjects = "/project/assigned-projects";
|
||||
static const String assignProjects = "/project/assign-projects";
|
||||
|
||||
// Daily Task Module API Endpoints
|
||||
// Daily Task Screen API Endpoints
|
||||
static const String getDailyTask = "/task/list";
|
||||
static const String reportTask = "/task/report";
|
||||
static const String commentTask = "/task/comment";
|
||||
static const String dailyTaskDetails = "/project/details-old";
|
||||
static const String dailyTaskDetails = "/project/details";
|
||||
static const String assignDailyTask = "/task/assign";
|
||||
static const String getWorkStatus = "/master/work-status";
|
||||
static const String approveReportAction = "/task/approve";
|
||||
static const String assignTask = "/project/task";
|
||||
static const String getmasterWorkCategories = "/Master/work-categories";
|
||||
static const String getDailyTaskProjectProgressFilter = "/task/filter";
|
||||
|
||||
////// Directory Module API Endpoints ///////
|
||||
static const String getDirectoryContacts = "/directory";
|
||||
static const String getDirectoryBucketList = "/directory/buckets";
|
||||
static const String getDirectoryContactDetail = "/directory/notes";
|
||||
static const String getDirectoryContactCategory =
|
||||
"/master/contact-categories";
|
||||
static const String getDirectoryContactTags = "/master/contact-tags";
|
||||
static const String getDirectoryOrganization = "/directory/organization";
|
||||
static const String createContact = "/directory";
|
||||
static const String updateContact = "/directory";
|
||||
static const String deleteContact = "/directory";
|
||||
static const String restoreContact = "/directory/note";
|
||||
static const String getDirectoryNotes = "/directory/notes";
|
||||
static const String updateDirectoryNotes = "/directory/note";
|
||||
static const String createBucket = "/directory/bucket";
|
||||
static const String updateBucket = "/directory/bucket";
|
||||
static const String assignBucket = "/directory/assign-bucket";
|
||||
|
||||
////// Expense Module API Endpoints
|
||||
static const String getExpenseCategories = "/expense/categories";
|
||||
static const String getExpenseList = "/expense/list";
|
||||
static const String getExpenseDetails = "/expense/details";
|
||||
static const String createExpense = "/expense/create";
|
||||
static const String editExpense = "/Expense/edit";
|
||||
static const String getMasterPaymentModes = "/master/payment-modes";
|
||||
static const String getMasterExpenseStatus = "/master/expenses-status";
|
||||
static const String getMasterExpenseTypes = "/master/expenses-types";
|
||||
static const String updateExpenseStatus = "/expense/action";
|
||||
static const String deleteExpense = "/expense/delete";
|
||||
|
||||
////// Dynamic Menu Module API Endpoints
|
||||
static const String getDynamicMenu = "/appmenu/get/menu-mobile";
|
||||
|
||||
///// Document Module API Endpoints
|
||||
static const String getMasterDocumentCategories =
|
||||
"/master/document-category/list";
|
||||
static const String getMasterDocumentTags = "/document/get/tags";
|
||||
static const String getDocumentList = "/document/list";
|
||||
static const String getDocumentDetails = "/document/get/details";
|
||||
static const String uploadDocument = "/document/upload";
|
||||
static const String deleteDocument = "/document/delete";
|
||||
static const String getDocumentFilter = "/document/get/filter";
|
||||
static const String getDocumentTypesByCategory = "/master/document-type/list";
|
||||
static const String getDocumentVersion = "/document/get/version";
|
||||
static const String getDocumentVersions = "/document/list/versions";
|
||||
static const String editDocument = "/document/edit";
|
||||
static const String verifyDocument = "/document/verify";
|
||||
|
||||
/// Logs Module API Endpoints
|
||||
static const String uploadLogs = "/log";
|
||||
|
||||
static const String getAssignedOrganizations =
|
||||
"/project/get/assigned/organization";
|
||||
static const getAllOrganizations = "/organization/list";
|
||||
|
||||
static const String getAssignedServices = "/Project/get/assigned/services";
|
||||
}
|
||||
|