From 43e617b254f11bb870107218201c1d4086729526 Mon Sep 17 00:00:00 2001
From: shoaib-mohmad <shoaib.mohmad@tarento.com>
Date: Tue, 8 Mar 2022 13:36:34 +0530
Subject: [PATCH] L2 completed.

---
 lib/constants/app_constants.dart             |  1 +
 lib/l10n/app_en.arb                          |  1 +
 lib/models/application_model.dart            |  4 ++
 lib/pages/application_details_page.dart      | 59 ++++++++++++++++----
 lib/repositories/application_repository.dart |  1 +
 lib/util/helper.dart                         | 19 +++++--
 lib/widgets/application_card.dart            | 19 ++++++-
 lib/widgets/assistant_inspector_dialog.dart  | 22 +++++++-
 8 files changed, 105 insertions(+), 21 deletions(-)

diff --git a/lib/constants/app_constants.dart b/lib/constants/app_constants.dart
index b1b4aa3..1109546 100644
--- a/lib/constants/app_constants.dart
+++ b/lib/constants/app_constants.dart
@@ -21,6 +21,7 @@ class InspectionStatus {
   static const String newInspection = 'NEW';
   static const String sentForInspection = 'SENTFORINS';
   static const String inspectionCompleted = 'INSCOMPLETED';
+  static const String leadInspectorCompleted = 'LEADINSCOMPLETED';
   static const String inspectionPending = 'PENDING';
   static const String returned = 'RETURNED';
 }
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb
index 7abaf43..acbfc98 100644
--- a/lib/l10n/app_en.arb
+++ b/lib/l10n/app_en.arb
@@ -15,6 +15,7 @@
     "next": "Next",
     "previous": "previous",
     "inspectionCompleted": "Inspection completed",
+    "leadInspectorCompleted": "Lead inspector completed",
     "completed": "Completed",
     "sentForInspection": "Sent for inspection",
     "noApplications": "No applications at the moment",
diff --git a/lib/models/application_model.dart b/lib/models/application_model.dart
index 54c4743..f1ecb95 100644
--- a/lib/models/application_model.dart
+++ b/lib/models/application_model.dart
@@ -11,6 +11,7 @@ class Application {
   final List leadInspector;
   final Map inspectorDataObject;
   final Map inspectorSummaryDataObject;
+  final String inspectionStatus;
   final String scheduledDate;
   final String createdDate;
   final String createdBy;
@@ -26,6 +27,7 @@ class Application {
     required this.leadInspector,
     required this.inspectorDataObject,
     required this.inspectorSummaryDataObject,
+    required this.inspectionStatus,
     required this.scheduledDate,
     required this.createdDate,
     required this.createdBy,
@@ -45,6 +47,7 @@ class Application {
           ? json['inspectorDataObject']['dataObject']
           : {},
       inspectorSummaryDataObject: json['inspectorSummaryDataObject'] ?? {},
+      inspectionStatus: json['inspection']['status'] ?? '',
       scheduledDate: json['inspection']['scheduledDate'] ?? '',
       createdDate: json['createdDate'],
       createdBy: json['createdBy'],
@@ -62,6 +65,7 @@ class Application {
         leadInspector,
         inspectorDataObject,
         inspectorSummaryDataObject,
+        inspectionStatus,
         scheduledDate,
         createdDate,
         createdBy
diff --git a/lib/pages/application_details_page.dart b/lib/pages/application_details_page.dart
index d0a8659..d115763 100644
--- a/lib/pages/application_details_page.dart
+++ b/lib/pages/application_details_page.dart
@@ -50,6 +50,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
   final List<Map> _inspectors = [];
   String _inspectionSummary = '';
   String _errorMessage = '';
+  String _inspectionStatus = '';
 
   @override
   void initState() {
@@ -87,6 +88,18 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
         'name':
             '${widget.application.inspectors[i]['firstName']} ${widget.application.inspectors[i]['lastName']}',
       });
+      if (widget.application.inspectors[i]['id'] == userId &&
+          !_isleadInspector) {
+        _note = widget.application.inspectors[i]['comments'] ?? '';
+        _inspectionStatus = widget.application.inspectors[i]['status'] ?? false;
+        _iConcent =
+            widget.application.inspectors[i]['consentApplication'] ?? false;
+        if (widget.application.inspectors[i]['consentApplication'] != null) {
+          _iDisagree = widget.application.inspectors[i]['consentApplication']
+              ? false
+              : true;
+        }
+      }
       setState(() {});
     }
   }
@@ -234,6 +247,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
         builder: (context) => StatefulBuilder(builder: (context, setState) {
               return AssistantInspectorDialog(
                 noteText: _note,
+                status: _inspectionStatus,
                 parentAction: triggerUpdate,
               );
             }));
@@ -247,7 +261,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
 
   @override
   Widget build(BuildContext context) {
-    // print(widget.applicationFields);
+    // print(widget.application.inspectorDataObject);
     return Scaffold(
       key: _scaffoldKey,
       appBar: AppBar(
@@ -633,7 +647,14 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
                                                         field.keys
                                                             .elementAt(i)],
                                                     applicationStatus: widget
-                                                        .application.status,
+                                                                .application
+                                                                .inspectionStatus ==
+                                                            InspectionStatus
+                                                                .leadInspectorCompleted
+                                                        ? InspectionStatus
+                                                            .inspectionCompleted
+                                                        : widget
+                                                            .application.status,
                                                     parentAction: updateField,
                                                   )
                                                 : widget.application.status ==
@@ -691,12 +712,19 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
                               ? ButtonTheme(
                                   child: OutlinedButton(
                                       onPressed: () {
-                                        if (!_iDisagree) {
+                                        if (!_iDisagree &&
+                                            _inspectionStatus !=
+                                                InspectionStatus
+                                                    .inspectionCompleted) {
                                           _displayCommentDialog();
                                         }
-                                        setState(() {
-                                          _iDisagree = !_iDisagree;
-                                        });
+                                        if (_inspectionStatus !=
+                                            InspectionStatus
+                                                .inspectionCompleted) {
+                                          setState(() {
+                                            _iDisagree = !_iDisagree;
+                                          });
+                                        }
                                       },
                                       style: OutlinedButton.styleFrom(
                                         backgroundColor: _iDisagree
@@ -743,12 +771,19 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
                                   padding: const EdgeInsets.only(left: 10),
                                   child: TextButton(
                                       onPressed: () {
-                                        if (!_iConcent) {
+                                        if (!_iConcent &&
+                                            _inspectionStatus !=
+                                                InspectionStatus
+                                                    .inspectionCompleted) {
                                           _displayCommentDialog();
                                         }
-                                        setState(() {
-                                          _iConcent = !_iConcent;
-                                        });
+                                        if (_inspectionStatus !=
+                                            InspectionStatus
+                                                .inspectionCompleted) {
+                                          setState(() {
+                                            _iConcent = !_iConcent;
+                                          });
+                                        }
                                       },
                                       style: TextButton.styleFrom(
                                         // primary: Colors.white,
@@ -863,7 +898,9 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
                                 ],
                               ))
                           : widget.application.status !=
-                                  InspectionStatus.inspectionCompleted
+                                      InspectionStatus.inspectionCompleted &&
+                                  widget.application.inspectionStatus !=
+                                      InspectionStatus.leadInspectorCompleted
                               ? TextButton(
                                   onPressed: () {
                                     _submitInspection();
diff --git a/lib/repositories/application_repository.dart b/lib/repositories/application_repository.dart
index a970840..90b4687 100644
--- a/lib/repositories/application_repository.dart
+++ b/lib/repositories/application_repository.dart
@@ -6,6 +6,7 @@ import 'package:smf_mobile/database/offline_model.dart';
 import 'package:smf_mobile/models/application_model.dart';
 import 'package:smf_mobile/services/application_service.dart';
 import 'package:smf_mobile/util/helper.dart';
+import 'dart:developer' as developer;
 
 class ApplicationRespository with ChangeNotifier {
   late Map _data;
diff --git a/lib/util/helper.dart b/lib/util/helper.dart
index 3b6cb3f..ecebd84 100644
--- a/lib/util/helper.dart
+++ b/lib/util/helper.dart
@@ -76,12 +76,19 @@ class Helper {
 
   static getInspectionStatus(BuildContext context, String status) {
     String _inspectionStatus = '';
-    if (status == InspectionStatus.inspectionCompleted) {
-      _inspectionStatus = AppLocalizations.of(context)!.completed;
-    } else if (status == InspectionStatus.sentForInspection) {
-      _inspectionStatus = AppLocalizations.of(context)!.sentForInspection;
-    } else {
-      _inspectionStatus = capitalize(status);
+    switch (status) {
+      case InspectionStatus.inspectionCompleted:
+        _inspectionStatus = AppLocalizations.of(context)!.completed;
+        break;
+      case InspectionStatus.sentForInspection:
+        _inspectionStatus = AppLocalizations.of(context)!.sentForInspection;
+        break;
+      case InspectionStatus.leadInspectorCompleted:
+        _inspectionStatus =
+            AppLocalizations.of(context)!.leadInspectorCompleted;
+        break;
+      default:
+        _inspectionStatus = capitalize(status);
     }
     // print(_inspectionStatus);
     return _inspectionStatus;
diff --git a/lib/widgets/application_card.dart b/lib/widgets/application_card.dart
index 5e8b2d5..26534f7 100644
--- a/lib/widgets/application_card.dart
+++ b/lib/widgets/application_card.dart
@@ -1,5 +1,6 @@
 import 'package:flutter/material.dart';
 import 'package:google_fonts/google_fonts.dart';
+import 'package:smf_mobile/constants/app_constants.dart';
 import 'package:smf_mobile/constants/app_urls.dart';
 import 'package:smf_mobile/constants/color_constants.dart';
 import 'package:smf_mobile/models/application_model.dart';
@@ -23,6 +24,19 @@ class _ApplicationCardState extends State<ApplicationCard> {
     super.initState();
   }
 
+  String _getApplicationStatus(String inspetionStatus, String actualStatus) {
+    String status = '';
+    if (actualStatus == InspectionStatus.inspectionCompleted) {
+      status = InspectionStatus.inspectionCompleted;
+    }
+    if (inspetionStatus == InspectionStatus.leadInspectorCompleted) {
+      status = InspectionStatus.leadInspectorCompleted;
+    } else {
+      status = actualStatus;
+    }
+    return status;
+  }
+
   @override
   Widget build(BuildContext context) {
     return InkWell(
@@ -96,7 +110,10 @@ class _ApplicationCardState extends State<ApplicationCard> {
                     padding: const EdgeInsets.only(bottom: 10),
                     child: Text(
                         Helper.getInspectionStatus(
-                            context, widget.application.status),
+                            context,
+                            _getApplicationStatus(
+                                widget.application.inspectionStatus,
+                                widget.application.status)),
                         style: GoogleFonts.lato(
                           color: AppColors.black60,
                           fontSize: 14.0,
diff --git a/lib/widgets/assistant_inspector_dialog.dart b/lib/widgets/assistant_inspector_dialog.dart
index b279de8..b927e4a 100644
--- a/lib/widgets/assistant_inspector_dialog.dart
+++ b/lib/widgets/assistant_inspector_dialog.dart
@@ -1,15 +1,18 @@
 import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
 import 'package:google_fonts/google_fonts.dart';
+import 'package:smf_mobile/constants/app_constants.dart';
 import 'package:smf_mobile/constants/color_constants.dart';
 // import 'package:flutter_gen/gen_l10n/app_localizations.dart';
 
 class AssistantInspectorDialog extends StatefulWidget {
   final String noteText;
+  final String status;
   final ValueChanged<Map> parentAction;
   const AssistantInspectorDialog({
     Key? key,
     required this.noteText,
+    required this.status,
     required this.parentAction,
   }) : super(key: key);
 
@@ -83,6 +86,10 @@ class _AssistantInspectorDialogState extends State<AssistantInspectorDialog> {
                                 child: Focus(
                                   child: TextFormField(
                                     // autofocus: true,
+                                    enabled: widget.status ==
+                                            InspectionStatus.inspectionCompleted
+                                        ? false
+                                        : true,
                                     controller: _noteController,
                                     textCapitalization:
                                         TextCapitalization.sentences,
@@ -121,7 +128,10 @@ class _AssistantInspectorDialogState extends State<AssistantInspectorDialog> {
                               child: OutlinedButton(
                                 onPressed: () {
                                   Navigator.of(context).pop(false);
-                                  _saveData(false);
+                                  if (widget.status !=
+                                      InspectionStatus.inspectionCompleted) {
+                                    _saveData(false);
+                                  }
                                 },
                                 style: OutlinedButton.styleFrom(
                                   // primary: Colors.white,
@@ -146,7 +156,10 @@ class _AssistantInspectorDialogState extends State<AssistantInspectorDialog> {
                               child: OutlinedButton(
                                 onPressed: () {
                                   Navigator.of(context).pop(false);
-                                  _saveData(true);
+                                  if (widget.status !=
+                                      InspectionStatus.inspectionCompleted) {
+                                    _saveData(true);
+                                  }
                                 },
                                 style: OutlinedButton.styleFrom(
                                   // primary: Colors.white,
@@ -171,7 +184,10 @@ class _AssistantInspectorDialogState extends State<AssistantInspectorDialog> {
                               child: TextButton(
                                 onPressed: () {
                                   Navigator.of(context).pop(false);
-                                  _saveData(true);
+                                  if (widget.status !=
+                                      InspectionStatus.inspectionCompleted) {
+                                    _saveData(true);
+                                  }
                                 },
                                 style: TextButton.styleFrom(
                                   // primary: Colors.white,
-- 
GitLab