diff --git a/lib/models/service_request/search_work_order.dart b/lib/models/service_request/search_work_order.dart index ac58714f..91fc0c9d 100644 --- a/lib/models/service_request/search_work_order.dart +++ b/lib/models/service_request/search_work_order.dart @@ -21,8 +21,8 @@ class SearchWorkOrders { String startofWorkTime; String endofWorkTime; double workingHours; - String travelingHours; - String travelingExpenses; + num travelingHours; + num travelingExpenses; ModelDefRelatedDefects faultDescription; List sparePartsWorkOrders; String reviewComment; @@ -509,7 +509,7 @@ class ModelDefinition { } class ModelDefRelatedDefects { - String id; + int id; String defectName; String workPerformed; String estimatedTime; diff --git a/lib/views/pages/user/requests/report/future_service_report.dart b/lib/views/pages/user/requests/report/future_service_report.dart index 5ee16ea2..15c792ea 100644 --- a/lib/views/pages/user/requests/report/future_service_report.dart +++ b/lib/views/pages/user/requests/report/future_service_report.dart @@ -5,6 +5,7 @@ import 'package:test_sa/controllers/providers/api/service_requests_provider.dart import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; import 'package:test_sa/models/service_report.dart'; +import 'package:test_sa/models/service_request/search_work_order.dart'; import 'package:test_sa/models/service_request/service_request.dart'; import 'package:test_sa/models/subtitle.dart'; import 'package:test_sa/views/widgets/loaders/app_loading.dart'; @@ -13,8 +14,9 @@ import 'package:test_sa/views/widgets/loaders/failed_loading.dart'; import 'edit_service_report.dart'; class FutureServiceReport extends StatefulWidget { final ServiceRequest request; + final SearchWorkOrders workOrder; - const FutureServiceReport({Key key, this.request}) : super(key: key); + const FutureServiceReport({Key key, this.request,this.workOrder}) : super(key: key); @override _FutureServiceReportState createState() => _FutureServiceReportState(); @@ -32,7 +34,7 @@ class _FutureServiceReportState extends State { return Scaffold( body: FutureBuilder( future: ServiceRequestsProvider().getSingleServiceReport( - reportId: widget.request.reportID, + reportId: widget.workOrder.id, user: _userProvider.user, host: _settingProvider.host, subtitle: _subtitle diff --git a/lib/views/pages/user/requests/request_details.dart b/lib/views/pages/user/requests/request_details.dart index f33ab0c9..1deaaca4 100644 --- a/lib/views/pages/user/requests/request_details.dart +++ b/lib/views/pages/user/requests/request_details.dart @@ -6,6 +6,7 @@ import 'package:test_sa/controllers/localization/localization.dart'; import 'package:test_sa/controllers/providers/api/service_requests_provider.dart'; import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; +import 'package:test_sa/extensions/int_extensions.dart'; import 'package:test_sa/models/enums/user_types.dart'; import 'package:test_sa/models/service_request/service_request.dart'; import 'package:test_sa/models/subtitle.dart'; @@ -25,17 +26,19 @@ import 'package:test_sa/views/widgets/titles/app_sub_title.dart'; import '../../../../models/service_request/search_work_order.dart'; import 'report/future_service_report.dart'; + class RequestDetailsPage extends StatelessWidget { static final String id = "/call-details"; final ServiceRequest serviceRequest; const RequestDetailsPage({Key key, this.serviceRequest}) : super(key: key); + @override Widget build(BuildContext context) { Subtitle _subtitle = AppLocalization.of(context).subtitle; UserProvider _userProvider = Provider.of(context); SettingProvider _settingProvider = Provider.of(context); - List workOrders=[]; + List workOrders = []; ServiceRequestsProvider _serviceRequestsProvider = Provider.of(context); return DefaultTabController( length: 2, @@ -44,8 +47,8 @@ class RequestDetailsPage extends StatelessWidget { child: Column( children: [ Container( - color:AColors.primaryColor, - padding: const EdgeInsets.symmetric(horizontal: 0,vertical: 4), + color: AColors.primaryColor, + padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 4), child: Row( children: [ ABackButton(), @@ -53,124 +56,129 @@ class RequestDetailsPage extends StatelessWidget { child: Center( child: Text( _subtitle.details, - style: Theme.of(context).textTheme.headline6.copyWith( - color: AColors.white, - fontStyle: FontStyle.italic - ), + style: Theme.of(context).textTheme.headline6.copyWith(color: AColors.white, fontStyle: FontStyle.italic), ), ), ), - _userProvider.user.type == UsersTypes.normal_user ? - // AIconButton( - // iconData: Icons.warning_amber_rounded, - // color: AColors.white, - // buttonSize: 42, - // backgroundColor: AColors.deepOrange, - // onPressed: (){ - // Navigator.of(context).push( - // MaterialPageRoute( - // builder: (_) => ReportIssuesPage(serviceRequest: serviceRequest,) - // ) - // ); - // }, - // ) - const SizedBox(width: 48,) - : AIconButton( - iconData: Icons.edit, - color: AColors.white, - buttonSize: 42, - backgroundColor: AColors.green, - onPressed: () async { - showModalBottomSheet( - context: context, - builder: (context){ - return ServiceRequestsUpdateDialog(request: serviceRequest,); - }); - // DateTime picked = await showDatePicker( - // context: context, - // initialDate: DateTime.now(), - // firstDate: DateTime.now(), - // lastDate: DateTime.now().add(Duration(days: 182)) - // ); - // if(picked == null){return;} - // showDialog( - // context: context, - // barrierDismissible: false, - // builder: (BuildContext context) { - // return CupertinoAlertDialog( - // title: Text(_subtitle.updatingDots), - // content: Center(child: CircularProgressIndicator()), + _userProvider.user.type == UsersTypes.normal_user + ? + // AIconButton( + // iconData: Icons.warning_amber_rounded, + // color: AColors.white, + // buttonSize: 42, + // backgroundColor: AColors.deepOrange, + // onPressed: (){ + // Navigator.of(context).push( + // MaterialPageRoute( + // builder: (_) => ReportIssuesPage(serviceRequest: serviceRequest,) + // ) // ); // }, - // ); - // int status = await _serviceRequestsProvider.updateDate( - // user: _userProvider.user, - // host: _settingProvider.host, - // request: serviceRequest, - // newDate: picked.toString().split(" ").first - // ); - // Navigator.of(context).pop(); - // Fluttertoast.showToast( - // msg: HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle), - // ); - }, - ), - SizedBox(width: 16,) + // ) + const SizedBox( + width: 48, + ) + : AIconButton( + iconData: Icons.edit, + color: AColors.white, + buttonSize: 42, + backgroundColor: AColors.green, + onPressed: () async { + showModalBottomSheet( + context: context, + builder: (context) { + return ServiceRequestsUpdateDialog( + request: serviceRequest, + ); + }); + // DateTime picked = await showDatePicker( + // context: context, + // initialDate: DateTime.now(), + // firstDate: DateTime.now(), + // lastDate: DateTime.now().add(Duration(days: 182)) + // ); + // if(picked == null){return;} + // showDialog( + // context: context, + // barrierDismissible: false, + // builder: (BuildContext context) { + // return CupertinoAlertDialog( + // title: Text(_subtitle.updatingDots), + // content: Center(child: CircularProgressIndicator()), + // ); + // }, + // ); + // int status = await _serviceRequestsProvider.updateDate( + // user: _userProvider.user, + // host: _settingProvider.host, + // request: serviceRequest, + // newDate: picked.toString().split(" ").first + // ); + // Navigator.of(context).pop(); + // Fluttertoast.showToast( + // msg: HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle), + // ); + }, + ), + SizedBox( + width: 16, + ) ], ), ), - - serviceRequest.devicePhotos.isEmpty ? SizedBox.shrink(): - Column( - children: [ - SizedBox(height: 8,), - MaterialButton( - padding: EdgeInsets.zero, - onPressed: (){ - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => Scaffold( - body: InteractiveViewer( - child: Center( - child: ImageLoader( - url: serviceRequest.devicePhotos.first, - boxFit: BoxFit.contain, - ), - ), - ), - ) - ) - ); - }, - child: SizedBox( - height: 140 * AppStyle.getScaleFactor(context), - width: MediaQuery.of(context).size.width, - child: ImageLoader( - url: serviceRequest.devicePhotos.first, - boxFit: BoxFit.cover, - ), - ), - ), - SizedBox(height: 8,), - SizedBox( - height: 60* AppStyle.getScaleFactor(context), - child: ImagesList( - images: serviceRequest.devicePhotos, + serviceRequest.devicePhotos.isEmpty + ? SizedBox.shrink() + : Column( + children: [ + SizedBox( + height: 8, + ), + MaterialButton( + padding: EdgeInsets.zero, + onPressed: () { + Navigator.of(context).push(MaterialPageRoute( + builder: (_) => Scaffold( + body: InteractiveViewer( + child: Center( + child: ImageLoader( + url: serviceRequest.devicePhotos.first, + boxFit: BoxFit.contain, + ), + ), + ), + ))); + }, + child: SizedBox( + height: 140 * AppStyle.getScaleFactor(context), + width: MediaQuery.of(context).size.width, + child: ImageLoader( + url: serviceRequest.devicePhotos.first, + boxFit: BoxFit.cover, + ), + ), + ), + SizedBox(height: 8), + SizedBox( + height: 60 * AppStyle.getScaleFactor(context), + child: ImagesList( + images: serviceRequest.devicePhotos, + ), + ), + ], ), - ), - ], - ), - - TabBar( - labelColor: AColors.primaryColor, - tabs: [ - Tab(text: _subtitle.general,), - Tab(text: _subtitle.serviceRequestInformation,), + TabBar(labelColor: AColors.primaryColor, tabs: [ + Tab( + text: _subtitle.general, + ), + Tab( + text: _subtitle.serviceRequestInformation, + ), ]), - SizedBox(height: 8,), + SizedBox( + height: 8, + ), Expanded( child: TabBarView( - children: [ ListView( padding: EdgeInsets.symmetric(horizontal: 16), @@ -189,7 +197,7 @@ class RequestDetailsPage extends StatelessWidget { ), RequestInfoRow( title: _subtitle.deviceModel, - info : serviceRequest.deviceModel, + info: serviceRequest.deviceModel, ), RequestInfoRow( title: _subtitle.engineerName, @@ -203,11 +211,12 @@ class RequestDetailsPage extends StatelessWidget { title: _subtitle.date, info: serviceRequest.date, ), - serviceRequest.nextVisitDate == null ? SizedBox.shrink() : - RequestInfoRow( - title: _subtitle.nextVisitDate, - info: DateFormat('EE dd/MM/yyyy').format(serviceRequest.nextVisitDate), - ), + serviceRequest.nextVisitDate == null + ? SizedBox.shrink() + : RequestInfoRow( + title: _subtitle.nextVisitDate, + info: DateFormat('EE dd/MM/yyyy').format(serviceRequest.nextVisitDate), + ), Row( children: [ Expanded( @@ -217,12 +226,12 @@ class RequestDetailsPage extends StatelessWidget { textScaleFactor: AppStyle.getScaleFactor(context), ), ), - StatusLabel(label: serviceRequest.statusLabel, - color: AColors.getRequestStatusColor(serviceRequest.statusValue) - ), + StatusLabel(label: serviceRequest.statusLabel, color: AColors.getRequestStatusColor(serviceRequest.statusValue)), ], ), - Divider(color: Theme.of(context).primaryColor,), + Divider( + color: Theme.of(context).primaryColor, + ), RequestInfoRow( title: _subtitle.hospital, info: serviceRequest.hospitalName, @@ -243,10 +252,10 @@ class RequestDetailsPage extends StatelessWidget { title: _subtitle.maintenanceIssue, content: serviceRequest.maintenanceIssue, ), - if(serviceRequest.audio?.isNotEmpty == true) - ASoundPlayer( - audio: serviceRequest.audio, - ), + if (serviceRequest.audio?.isNotEmpty == true) + ASoundPlayer( + audio: serviceRequest.audio, + ), // // Center( // child: Padding( @@ -290,98 +299,112 @@ class RequestDetailsPage extends StatelessWidget { ), // workOrders.isEmpty ? FutureBuilder( - future: _serviceRequestsProvider.searchWorkOrders(callId:serviceRequest.requestCode), - builder: (context, snap){ - print("${workOrders?.length}"); - workOrders= snap.data as List; - print("${workOrders?.length}"); - if(snap.connectionState==ConnectionState.done && snap.data.length != 0) - return ListView.builder( - padding: EdgeInsets.symmetric(horizontal: 16), + future: _serviceRequestsProvider.searchWorkOrders(callId: serviceRequest.requestCode), + builder: (context, snap) { + workOrders = snap.data as List; + if (snap.connectionState == ConnectionState.done && (snap.data?.length ?? 0) != 0) + return ListView.separated( + padding: EdgeInsets.all(21), itemCount: workOrders.length, - itemBuilder: (context , index){ - return Column( - children: [ - RequestInfoRow( - title: _subtitle.callId, - content:workOrders[index].id.toString(), - ), - RequestInfoRow( - title: _subtitle.orderWorkNumber, - info: "123", - ), - RequestInfoRow( - title: _subtitle.visitDate, - info: workOrders[index].visitDate, - ), - RequestInfoRow( - title: _subtitle.assignedEmployee, - info: workOrders[index].callRequest.assignedEmployee.name, - ), - RequestInfoRow( - title: _subtitle.assetSN, - info:workOrders[index].callRequest.asset.assetSerialNo, - ), - RequestInfoRow( - title: _subtitle.assetName, - info:"123", - ), - RequestInfoRow( - title: _subtitle.model, - info:"123", - ), - RequestInfoRow( - title: _subtitle.site, - info:workOrders[index].callRequest.asset.site.custName, - ), - RequestInfoRow( - title: _subtitle.maintenanceSituation, - info:"123", - ), - RequestInfoRow( - title: _subtitle.currentSituation, - info:workOrders[index].currentSituation.name??'', + separatorBuilder: (czt, index) => 21.height, + itemBuilder: (context, index) { + Color itemColor = index % 2 == 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.onPrimary; + Color onItemColor = index % 2 != 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.onPrimary; + + return ElevatedButton( + style: ElevatedButton.styleFrom( + padding: EdgeInsets.symmetric(vertical: 8, horizontal: 8), + primary: itemColor.withOpacity(.7), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), ), - _userProvider.user.type == UsersTypes.engineer - && serviceRequest.reportID != null? - Padding( + ), + //padding: EdgeInsets.symmetric(vertical: 8,horizontal: 8), + onPressed: () { + // onPressed(request); + }, + child: Column( + children: [ + RequestInfoRow( + title: _subtitle.callId, + content: workOrders[index].id.toString(), + ), + RequestInfoRow( + title: _subtitle.orderWorkNumber, + info: workOrders[index].workOrderNo.toString(), + ), + RequestInfoRow( + title: _subtitle.visitDate, + info: workOrders[index].visitDate, + ), + RequestInfoRow(title: _subtitle.assignedEmployee, info: workOrders[index].assignedEmployee.name), + RequestInfoRow( + title: _subtitle.assetSN, + info: workOrders[index].callRequest.asset.assetSerialNo, + ), + RequestInfoRow( + title: _subtitle.assetName, + info: workOrders[index].callRequest.asset.modelDefinition.assetName, + ), + RequestInfoRow( + title: _subtitle.model, + info: workOrders[index].callRequest.asset.modelDefinition.modelName, + ), + RequestInfoRow( + title: _subtitle.site, + info: workOrders[index].callRequest.asset.site.custName, + ), + RequestInfoRow( + title: _subtitle.maintenanceSituation, + info: workOrders[index].calllastSituation.name ?? '', + ), + RequestInfoRow( + title: _subtitle.currentSituation, + info: workOrders[index].currentSituation.name ?? '', + ), + _userProvider.user.type == UsersTypes.engineer && workOrders[index].workOrderNo != null + ? Padding( + padding: EdgeInsets.all(32), + child: AButton( + text: _subtitle.editServiceReport, + onPressed: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (_) => FutureServiceReport( + request: serviceRequest, + workOrder: workOrders[index], + )), + ); + }, + ), + ) + : SizedBox.shrink(), + ], + ), + ); + }, + ); + else + return _userProvider.user.type == UsersTypes.engineer + ? Center( + child: Padding( padding: EdgeInsets.all(32), child: AButton( - text: _subtitle.editServiceReport, - onPressed: (){ + text: "Create Report", + onPressed: () { Navigator.of(context).push( MaterialPageRoute( - builder: (_) => FutureServiceReport( - request: serviceRequest, - ) - ), + builder: (_) => CreateServiceReport( + request: serviceRequest, + )), ); }, ), - ): SizedBox.shrink(), - ], - ); - }, - ); - else - return _userProvider.user.type == UsersTypes.engineer ? - Center( - child: Padding( - padding: EdgeInsets.all(32), - child: AButton( - text: "Create Report", - onPressed: (){ - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => CreateServiceReport( - request: serviceRequest, - ) - ), - ); - }, - ), - ), - ): Center(child: ASubTitle(_subtitle.noDateFound),); + ), + ) + : Center( + child: ASubTitle(_subtitle.noDateFound), + ); }, ) ], @@ -393,69 +416,4 @@ class RequestDetailsPage extends StatelessWidget { ), ); } - - Widget dataList({@required Subtitle subtitle, @required List workOrders, @required UserProvider userProvider, @required BuildContext context}){ - return ListView( - padding: EdgeInsets.symmetric(horizontal: 16), - children: [ - RequestInfoRow( - title: subtitle.callId, - content:"123", - ), - RequestInfoRow( - title: subtitle.orderWorkNumber, - info: "123", - ), - RequestInfoRow( - title: subtitle.visitDate, - info: workOrders[0].visitDate??"", - ), - RequestInfoRow( - title: subtitle.assignedEmployee, - info: "123", - ), - RequestInfoRow( - title: subtitle.assetSN, - info:"123", - ), - RequestInfoRow( - title: subtitle.assetName, - info:"123", - ), - RequestInfoRow( - title: subtitle.model, - info:"123", - ), - RequestInfoRow( - title: subtitle.site, - info:"123", - ), - RequestInfoRow( - title: subtitle.maintenanceSituation, - info:"123", - ), - RequestInfoRow( - title: subtitle.currentSituation, - info:"123", - ), - userProvider.user.type == UsersTypes.engineer - && serviceRequest.reportID != null? - Padding( - padding: EdgeInsets.all(32), - child: AButton( - text: subtitle.editServiceReport, - onPressed: (){ - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => FutureServiceReport( - request: serviceRequest, - ) - ), - ); - }, - ), - ): SizedBox.shrink(), - ], - ); - } }