diff --git a/lib/controllers/providers/api/service_requests_provider.dart b/lib/controllers/providers/api/service_requests_provider.dart index d8c01d6f..bdd12b03 100644 --- a/lib/controllers/providers/api/service_requests_provider.dart +++ b/lib/controllers/providers/api/service_requests_provider.dart @@ -319,11 +319,11 @@ class ServiceRequestsProvider extends ChangeNotifier { "reason": report.reason?.toMap(), "startofWorkTime": report.startDate?.toIso8601String() ?? "", "endofWorkTime": report.endDate?.toIso8601String() ?? "", - "workingHours": report.timer?.durationInSecond, + "workingHours": ((report?.endDate?.difference(report?.startDate)?.inMinutes ?? 0) / 60), "travelingHours": report.travelingHours, "travelingExpenses": report.travelingExpense ?? 0, "faultDescription": { - "id": report.faultDescriptionId ?? 0, + "id": report.faultDescriptionId, "defectName": report.type?.name, "workPerformed": report.workPreformed, "estimatedTime": report.operatingHours, @@ -331,8 +331,8 @@ class ServiceRequestsProvider extends ChangeNotifier { "sparePartsWorkOrders": report.parts ?.map( (p) => { - "id": p.id, - "sparePart": {"id": p.reportPartID ?? 0, "partNo": p.code, "partName": p.name}, + "id": p.reportPartID ?? 0, + "sparePart": {"id": p.id, "partNo": p.code, "partName": p.name}, "qty": p.quantity }, ) diff --git a/lib/models/service_report.dart b/lib/models/service_report.dart index 7024bd49..28b117d1 100644 --- a/lib/models/service_report.dart +++ b/lib/models/service_report.dart @@ -10,7 +10,7 @@ import 'package:test_sa/models/timer_model.dart'; class ServiceReport { int id; - String operatingHours; + double operatingHours; DateTime visitDate; DateTime endDate; DateTime startDate; @@ -25,7 +25,7 @@ class ServiceReport { String workPreformed; //String workHours; - String travelingHours; + double travelingHours; String invoiceNumber; String invoiceCode; List parts; @@ -89,7 +89,7 @@ class ServiceReport { _map["endofWorkTime"] = (timer.endAt ?? DateTime.now()).toIso8601String(); _map["workingHours"] = (timer.durationInSecond / 60 / 60).toStringAsFixed(5); } - if (travelingHours != null && travelingHours.isNotEmpty) _map["traveling_hours"] = travelingHours; + if (travelingHours != null && travelingHours.toString().isNotEmpty) _map["traveling_hours"] = travelingHours; // if(workPreformed != null && workPreformed.isNotEmpty){ // _map["faultDescription"] = { // //"id":faultDescriptionId ?? 0, diff --git a/lib/views/pages/user/requests/report/create_service_report.dart b/lib/views/pages/user/requests/report/create_service_report.dart index 477bba08..84d22d83 100644 --- a/lib/views/pages/user/requests/report/create_service_report.dart +++ b/lib/views/pages/user/requests/report/create_service_report.dart @@ -101,6 +101,7 @@ class _CreateServiceReportState extends State with TickerPr child: Stack( children: [ ListView( + padding: const EdgeInsets.all(16), children: [ //AppNameBar(), const SizedBox( @@ -115,22 +116,22 @@ class _CreateServiceReportState extends State with TickerPr ), ), ), - Container( - padding: const EdgeInsets.symmetric(horizontal: 16), - margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 16), - decoration: BoxDecoration(color: AColors.grey, borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), boxShadow: [ - const BoxShadow( - color: AColors.grey, - offset: Offset(0, -1), - ) - ]), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox( - height: 8, - ), - Wrap( + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ASubTitle("Caller Info"), + const SizedBox(height: 8), + Container( + width: double.infinity, + padding: const EdgeInsets.all(16), + margin: const EdgeInsets.symmetric(vertical: 16), + decoration: BoxDecoration(color: AColors.grey, borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), boxShadow: const [ + BoxShadow( + color: AColors.grey, + offset: Offset(0, -1), + ) + ]), + child: Wrap( spacing: 10, children: [ ASubTitle( @@ -153,157 +154,138 @@ class _CreateServiceReportState extends State with TickerPr ) ], ), - const Divider(), + ), - // Report type and Reasons - Row( + ASubTitle("Work Order Details"), + Container( + width: double.infinity, + padding: const EdgeInsets.all(16), + margin: const EdgeInsets.symmetric(vertical: 16), + decoration: BoxDecoration(color: AColors.grey, borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), boxShadow: [ + BoxShadow( + color: AColors.grey, + offset: Offset(0, -1), + ), + ]), + child: Column( + mainAxisSize: MainAxisSize.min, children: [ - // Report Status - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(_subtitle.reportType), - // _validate && _serviceReport.type == null ? - // ASubTitle(_subtitle.requiredWord,color: Colors.red,): - // const SizedBox.shrink(), - // const SizedBox(height: 4,), - // ServiceReportTypeMenu( - // initialValue: _serviceReport.type, - // onSelect: (status){ - // _serviceReport.type = status; - // }, - // ), - // ], - // ), - // ), - // const SizedBox(width: 8,), - // visit date - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(_subtitle.visitDate), - _validate && _serviceReport.visitDate == null - ? ASubTitle( - _subtitle.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - Row( + // Report type and Reasons + Row( + children: [ + // Report Status + // Expanded( + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // ASubTitle(_subtitle.reportType), + // _validate && _serviceReport.type == null ? + // ASubTitle(_subtitle.requiredWord,color: Colors.red,): + // const SizedBox.shrink(), + // const SizedBox(height: 4,), + // ServiceReportTypeMenu( + // initialValue: _serviceReport.type, + // onSelect: (status){ + // _serviceReport.type = status; + // }, + // ), + // ], + // ), + // ), + // const SizedBox(width: 8,), + // visit date + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Expanded( - child: ADatePicker( - date: _serviceReport.visitDate, - from: DateTime.now().subtract(const Duration(days: 365)), - to: DateTime.now().add(const Duration(days: 365)), - onDatePicker: (date) { - _serviceReport.visitDate = date; - setState(() {}); - }, - ), + ASubTitle(_subtitle.visitDate), + _validate && _serviceReport.visitDate == null + ? ASubTitle( + _subtitle.requiredWord, + color: Colors.red, + ) + : const SizedBox.shrink(), + Row( + children: [ + Expanded( + child: ADatePicker( + date: _serviceReport.visitDate, + from: DateTime.now().subtract(const Duration(days: 365)), + to: DateTime.now().add(const Duration(days: 365)), + onDatePicker: (date) { + _serviceReport.visitDate = date; + setState(() {}); + }, + ), + ), + ], ), ], ), - ], - ), + ), + ], ), - ], - ), - const SizedBox( - height: 8, - ), - // device sn - Visibility( - visible: widget.request.deviceSerialNumber == null, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(_subtitle.deviceSN), - _validate && _serviceReport.device?.id == null - ? ASubTitle( - _subtitle.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - AutoCompleteDeviceField( - hospitalId: widget.request.hospitalId, - initialValue: _serviceReport.device, - onPick: (id) { - _serviceReport.device.id = id; - }, - ), - const SizedBox( - height: 8, - ), - ], - ), - ), - const SizedBox( - height: 8, - ), - ASubTitle(_subtitle.serviceType), - _validate && _serviceReport.assetType == null - ? ASubTitle( - _subtitle.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - const SizedBox( - height: 4, - ), - ServiceAssetTypeMenu( - initialValue: _serviceReport.assetType, - onSelect: (status) { - _serviceReport.assetType = status; - }, - ), - const SizedBox( - height: 8, - ), - // Report status and Service Type - Row( - children: [ - // report status - Expanded( + const SizedBox( + height: 8, + ), + // device sn + Visibility( + visible: widget.request.deviceSerialNumber == null, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - ASubTitle(_subtitle.reportStatus), - _validate && _serviceReport.status == null + ASubTitle(_subtitle.deviceSN), + _validate && _serviceReport.device?.id == null ? ASubTitle( _subtitle.requiredWord, color: Colors.red, ) : const SizedBox.shrink(), - const SizedBox( - height: 4, - ), - ServiceReportStatusMenu( - report: _serviceReport, - request: widget.request, - onSelect: (status) { - _serviceReport.status = status; + AutoCompleteDeviceField( + hospitalId: widget.request.hospitalId, + initialValue: _serviceReport.device, + onPick: (id) { + _serviceReport.device.id = id; }, ), + const SizedBox( + height: 8, + ), ], ), ), const SizedBox( - width: 8, - ), - // Provider.of(context).isLoading == null - // ? const SizedBox.shrink(): - // Call's last Situation - Consumer( - builder: (_, provider, __) { - if (provider.isLoading == null) return const SizedBox.shrink(); - return Expanded( + height: 8, + ), + ASubTitle(_subtitle.serviceType), + _validate && _serviceReport.assetType == null + ? ASubTitle( + _subtitle.requiredWord, + color: Colors.red, + ) + : const SizedBox.shrink(), + const SizedBox( + height: 4, + ), + ServiceAssetTypeMenu( + initialValue: _serviceReport.assetType, + onSelect: (status) { + _serviceReport.assetType = status; + }, + ), + const SizedBox( + height: 8, + ), + // Report status and Service Type + Row( + children: [ + // report status + Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - ASubTitle(_subtitle.callLastSituation), - _validate && _serviceReport.callLastSituation == null + ASubTitle(_subtitle.reportStatus), + _validate && _serviceReport.status == null ? ASubTitle( _subtitle.requiredWord, color: Colors.red, @@ -312,566 +294,582 @@ class _CreateServiceReportState extends State with TickerPr const SizedBox( height: 4, ), - ServiceReportLastCallsMenu( + ServiceReportStatusMenu( report: _serviceReport, + request: widget.request, onSelect: (status) { - if (status?.value == 12 || _serviceReport.callLastSituation?.value == 12) { - _serviceReport.callLastSituation = status; - setState(() {}); - } else { - _serviceReport.callLastSituation = status; - } + _serviceReport.status = status; }, ), ], ), - ); - }, + ), + const SizedBox( + width: 8, + ), + // Provider.of(context).isLoading == null + // ? const SizedBox.shrink(): + // Call's last Situation + Consumer( + builder: (_, provider, __) { + if (provider.isLoading == null) return const SizedBox.shrink(); + return Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ASubTitle(_subtitle.callLastSituation), + _validate && _serviceReport.callLastSituation == null + ? ASubTitle( + _subtitle.requiredWord, + color: Colors.red, + ) + : const SizedBox.shrink(), + const SizedBox( + height: 4, + ), + ServiceReportLastCallsMenu( + report: _serviceReport, + onSelect: (status) { + if (status?.value == 12 || _serviceReport.callLastSituation?.value == 12) { + _serviceReport.callLastSituation = status; + setState(() {}); + } else { + _serviceReport.callLastSituation = status; + } + }, + ), + ], + ), + ); + }, + ), + ], ), - ], - ), - SizedBox( - height: 8 * AppStyle.getScaleFactor(context), - ), - Row( - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - const ASubTitle("Start of Work"), - SizedBox( - height: 8 * AppStyle.getScaleFactor(context), - ), - ADateTimePicker( - date: _serviceReport.startDate, - from: DateTime.now().subtract(const Duration(days: 365)), - to: DateTime.now().add(const Duration(days: 365)), - onDateTimePicker: (date) { - _serviceReport.startDate = date; - setState(() {}); - }, - ), - ], - ), + SizedBox( + height: 8 * AppStyle.getScaleFactor(context), ), - const SizedBox(width: 8), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - const ASubTitle("End of Work"), - SizedBox( - height: 8 * AppStyle.getScaleFactor(context), + Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const ASubTitle("Start of Work"), + SizedBox( + height: 8 * AppStyle.getScaleFactor(context), + ), + ADateTimePicker( + date: _serviceReport.startDate, + from: DateTime.now().subtract(const Duration(days: 365)), + to: DateTime.now().add(const Duration(days: 365)), + onDateTimePicker: (date) { + _serviceReport.startDate = date; + setState(() {}); + }, + ), + ], ), - ADateTimePicker( - date: _serviceReport.endDate, - from: DateTime.now().subtract(const Duration(days: 365)), - to: DateTime.now().add(const Duration(days: 365)), - onDateTimePicker: (date) { - _serviceReport.endDate = date; - setState(() {}); - }, + ), + const SizedBox(width: 8), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const ASubTitle("End of Work"), + SizedBox( + height: 8 * AppStyle.getScaleFactor(context), + ), + ADateTimePicker( + date: _serviceReport.endDate, + from: DateTime.now().subtract(const Duration(days: 365)), + to: DateTime.now().add(const Duration(days: 365)), + onDateTimePicker: (date) { + _serviceReport.endDate = date; + setState(() {}); + }, + ), + ], ), - ], - ), + ), + ], + ), + ASubTitle(_subtitle.workingHours), + const SizedBox(height: 4), + ATextFormField( + initialValue: null, + textAlign: TextAlign.center, + hintText: _serviceReport.startDate == null + ? "0" + : ((_serviceReport?.endDate?.difference(_serviceReport?.startDate)?.inMinutes ?? 0) / 60)?.toStringAsFixed(2)?.toString() ?? "0", + enable: false, + style: Theme.of(context).textTheme.subtitle1, + validator: (value) => Validator.isNumeric(value) ? null : _subtitle.requiredWord, + textInputType: TextInputType.number, + onSaved: (value) { + // _serviceReport.workHours = value; + }, ), - ], - ), - ASubTitle(_subtitle.workingHours), - const SizedBox(height: 4), - ATextFormField( - initialValue: null, - textAlign: TextAlign.center, - hintText: _serviceReport.startDate == null ? "0" : _serviceReport?.endDate?.difference(_serviceReport?.startDate)?.inHours?.toString() ?? "0", - enable: false, - style: Theme.of(context).textTheme.subtitle1, - validator: (value) => Validator.isNumeric(value) ? null : _subtitle.requiredWord, - textInputType: TextInputType.number, - onSaved: (value) { - // _serviceReport.workHours = value; - }, - ), - SizedBox( - height: 8 * AppStyle.getScaleFactor(context), - ), - // const ASubTitle("Assigned Employee"), - // const SizedBox( - // height: 8, - // ), - // _validate && _serviceReport.engineer == null - // ? ASubTitle( - // _subtitle.requiredWord, - // color: Colors.red, - // ) - // : const SizedBox.shrink(), - // const SizedBox( - // height: 4, - // ), - // EngineersMenu( - // initialValue: _serviceReport.engineer, - // onSelect: (engineer) { - // _serviceReport.engineer = engineer; - // }, - // ), - // const SizedBox( - // height: 8, - // ), - // invoice number & code - _serviceReport.callLastSituation?.id != 12 - ? const SizedBox.shrink() - : Row( - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(_subtitle.invoiceNumber), - const SizedBox( - height: 8, + SizedBox( + height: 8 * AppStyle.getScaleFactor(context), + ), + const ASubTitle("Assigned Employee"), + const SizedBox(height: 8), + _validate && _serviceReport.engineer == null + ? ASubTitle( + _subtitle.requiredWord, + color: Colors.red, + ) + : const SizedBox.shrink(), + const SizedBox(height: 4), + EngineersMenu( + initialValue: _serviceReport.engineer, + onSelect: (engineer) { + _serviceReport.engineer = engineer; + }, + ), + const SizedBox(height: 8), + // invoice number & code + _serviceReport.callLastSituation?.id != 12 + ? const SizedBox.shrink() + : Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ASubTitle(_subtitle.invoiceNumber), + const SizedBox( + height: 8, + ), + ATextFormField( + initialValue: _serviceReport?.invoiceNumber, + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.subtitle1, + validator: (value) => Validator.hasValue(value) ? null : _subtitle.requiredWord, + textInputType: TextInputType.number, + onSaved: (value) { + _serviceReport.invoiceNumber = value; + }, + ), + ], ), - ATextFormField( - initialValue: _serviceReport?.invoiceNumber, - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.subtitle1, - validator: (value) => Validator.hasValue(value) ? null : _subtitle.requiredWord, - textInputType: TextInputType.number, - onSaved: (value) { - _serviceReport.invoiceNumber = value; - }, + ), + const SizedBox(width: 8), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ASubTitle(_subtitle.invoiceCode), + const SizedBox(height: 4), + ATextFormField( + initialValue: _serviceReport?.invoiceCode, + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.subtitle1, + validator: (value) => Validator.hasValue(value) ? null : _subtitle.requiredWord, + textInputType: TextInputType.text, + onSaved: (value) { + _serviceReport.invoiceCode = value; + }, + ), + ], ), - ], - ), - ), - const SizedBox( - width: 8, + ), + ], ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(_subtitle.invoiceCode), - const SizedBox( - height: 4, - ), - ATextFormField( - initialValue: _serviceReport?.invoiceCode, - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.subtitle1, - validator: (value) => Validator.hasValue(value) ? null : _subtitle.requiredWord, - textInputType: TextInputType.text, - onSaved: (value) { - _serviceReport.invoiceCode = value; - }, - ), - ], + const SizedBox(height: 8), + Row( + children: [ + ASubTitle(_subtitle.faultDescription), + Expanded( + child: SizedBox( + height: 32 * AppStyle.getScaleFactor(context), + child: SpeechToTextButton( + controller: _faultController, + mini: true, ), ), - ], - ), - const SizedBox(height: 8), - Row( - children: [ - ASubTitle(_subtitle.faultDescription), - Expanded( - child: SizedBox( - height: 32 * AppStyle.getScaleFactor(context), - child: SpeechToTextButton( - controller: _faultController, - mini: true, ), - ), + ], ), - ], - ), - const SizedBox( - height: 4, - ), - ATextFormField( - initialValue: _serviceReport?.faultDescriptionId?.toString(), - textAlign: TextAlign.center, - controller: _faultController, - style: Theme.of(context).textTheme.titleMedium, - validator: (value) => Validator.hasValue(value) ? null : _subtitle.requiredWord, - textInputType: TextInputType.multiline, - onSaved: (value) { - _serviceReport.faultDescriptionId = int.tryParse(value) ?? 0; - }, - ), - const SizedBox( - height: 8, - ), - Row( - children: [ - ASubTitle(_subtitle.workPreformed), - Expanded( - child: SizedBox( - height: 32 * AppStyle.getScaleFactor(context), - child: SpeechToTextButton( - controller: _workPreformedController, - mini: true, + const SizedBox(height: 4), + ATextFormField( + initialValue: _serviceReport?.faultDescriptionId?.toString(), + textAlign: TextAlign.center, + controller: _faultController, + style: Theme.of(context).textTheme.titleMedium, + validator: (value) => Validator.hasValue(value) ? null : _subtitle.requiredWord, + textInputType: TextInputType.multiline, + onSaved: (value) { + _serviceReport.faultDescriptionId = int.tryParse(value) ?? 0; + }, + ), + const SizedBox(height: 8), + Row( + children: [ + ASubTitle(_subtitle.workPreformed), + Expanded( + child: SizedBox( + height: 32 * AppStyle.getScaleFactor(context), + child: SpeechToTextButton( + controller: _workPreformedController, + mini: true, + ), + ), ), - ), + ], ), - ], - ), - const SizedBox( - height: 4, - ), - ATextFormField( - initialValue: _serviceReport?.workPreformed, - textAlign: TextAlign.center, - controller: _workPreformedController, - style: Theme.of(context).textTheme.subtitle1, - validator: (value) => Validator.hasValue(value) ? null : _subtitle.requiredWord, - textInputType: TextInputType.multiline, - onSaved: (value) { - _serviceReport.workPreformed = value; - }, - ), - const SizedBox( - height: 8, - ), + const SizedBox(height: 4), + ATextFormField( + initialValue: _serviceReport?.workPreformed, + textAlign: TextAlign.center, + controller: _workPreformedController, + style: Theme.of(context).textTheme.subtitle1, + validator: (value) => Validator.hasValue(value) ? null : _subtitle.requiredWord, + textInputType: TextInputType.multiline, + onSaved: (value) { + _serviceReport.workPreformed = value; + }, + ), + const SizedBox(height: 8), - const SizedBox( - height: 8, - ), - Row( - children: [ - // reasons - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(_subtitle.reasons), - const SizedBox( - height: 4, + const SizedBox(height: 8), + Row( + children: [ + // reasons + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ASubTitle(_subtitle.reasons), + const SizedBox(height: 4), + ServiceReportReasonsMenu( + initialValue: _serviceReport.reason, + onSelect: (status) { + _serviceReport.reason = status; + }, + ), + ], ), - ServiceReportReasonsMenu( - initialValue: _serviceReport.reason, - onSelect: (status) { - _serviceReport.reason = status; - }, + ), + const SizedBox(width: 8), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ASubTitle(_subtitle.attachImage), + AMiniOneImagePicker( + //error: _validate && _serviceReport.image == null, + image: _image, + onPick: (image) { + _image = image; + _serviceReport.image = "${image.path.split("/").last}|${base64Encode(image.readAsBytesSync())}"; + }, + ), + ], ), - ], - ), + ), + ], + ), + const SizedBox(height: 8), + ASubTitle(_subtitle.repairLocation), + const SizedBox(height: 4), + ServiceReportRepairLocation( + initialValue: _serviceReport.repairLocation, + onSelect: (status) { + _serviceReport.repairLocation = status; + }, ), + const SizedBox(height: 16), + ASubTitle(_subtitle.travelingExpense), const SizedBox( - width: 8, + height: 4, ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(_subtitle.attachImage), - AMiniOneImagePicker( - //error: _validate && _serviceReport.image == null, - image: _image, - onPick: (image) { - _image = image; - _serviceReport.image = "${image.path.split("/").last}|${base64Encode(image.readAsBytesSync())}"; - }, - ), - ], - ), + ATextFormField( + initialValue: _serviceReport?.travelingExpense?.toString(), + hintText: _subtitle.travelingExpense, + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.titleMedium, + textInputType: TextInputType.number, + onSaved: (value) { + _serviceReport.travelingExpense = int.tryParse(value) ?? 0; + }, ), - ], - ), - const SizedBox( - height: 8, - ), - ASubTitle(_subtitle.repairLocation), - const SizedBox( - height: 4, - ), - ServiceReportRepairLocation( - initialValue: _serviceReport.repairLocation, - onSelect: (status) { - _serviceReport.repairLocation = status; - }, - ), - const SizedBox( - height: 16, - ), - ASubTitle(_subtitle.travelingExpense), - const SizedBox( - height: 4, - ), - ATextFormField( - initialValue: _serviceReport?.travelingExpense?.toString(), - hintText: _subtitle.travelingExpense, - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.titleMedium, - textInputType: TextInputType.number, - onSaved: (value) { - _serviceReport.travelingExpense = int.tryParse(value) ?? 0; - }, - ), - const SizedBox( - height: 8, - ), - // Traveling Hours & Working Hours - Row( - children: [ - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(_subtitle.workingHours), - // const SizedBox( - // height: 8, + const SizedBox( + height: 8, + ), + // Traveling Hours & Working Hours + Row( + children: [ + // Expanded( + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // ASubTitle(_subtitle.workingHours), + // const SizedBox( + // height: 8, + // ), + // Row( + // children: [ + // Expanded( + // child: AppTimer( + // timer: _serviceReport.timer, + // onChange: (timer) async { + // _serviceReport.timer = timer; + // return true; + // }, + // ), + // ), + // ], + // ), + // // ATextFormField( + // // initialValue: _serviceReport?.workHours, + // // textAlign: TextAlign.center, + // // hintText: "i.e 3, 3.5, 4", + // // style: Theme.of(context).textTheme.subtitle1, + // // validator: (value) => + // // Validator.isNumeric(value) + // // ? null : _subtitle.requiredWord, + // // textInputType: TextInputType.number, + // // onSaved: (value){ + // // _serviceReport.workHours = value; + // // }, + // // ), + // ], + // ), + // ), + // const SizedBox(width: 8,), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ASubTitle(_subtitle.travelingHours), + const SizedBox( + height: 4, + ), + ATextFormField( + initialValue: _serviceReport?.travelingHours?.toString(), + textAlign: TextAlign.center, + hintText: "i.e 3, 3.5, 4", + style: Theme.of(context).textTheme.subtitle1, + // validator: (value) => + // Validator.isNumeric(value) + // ? null : _subtitle.requiredWord, + textInputType: TextInputType.number, + onSaved: (value) { + _serviceReport.travelingHours = double.tryParse(value) ?? 0.0; + }, + ), + ], + ), + ), + ], + ), + const SizedBox( + height: 8, + ), + // Operating Hours and Job Sheet Number + // Row( + // children: [ + // Expanded( + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // ASubTitle(_subtitle.operatingHours), + // const SizedBox(height: 4,), + // ATextFormField( + // initialValue: _serviceReport?.operatingHours, + // textAlign: TextAlign.center, + // hintText: "i.e 3, 3.5, 4", + // style: Theme.of(context).textTheme.subtitle1, + // validator: (value) => + // Validator.isNumeric(value) + // ? null : _subtitle.requiredWord, + // textInputType: TextInputType.number, + // onSaved: (value){ + // _serviceReport.operatingHours = value; + // }, + // ), + // ], // ), - // Row( + // ), + // const SizedBox(width: 8,), + // Expanded( + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, // children: [ - // Expanded( - // child: AppTimer( - // timer: _serviceReport.timer, - // onChange: (timer) async { - // _serviceReport.timer = timer; - // return true; - // }, - // ), + // ASubTitle(_subtitle.jobSheetNumber), + // const SizedBox(height: 4,), + // ATextFormField( + // initialValue: _serviceReport?.jobSheetNumber, + // textAlign: TextAlign.center, + // style: Theme.of(context).textTheme.subtitle1, + // textInputType: TextInputType.name, + // onSaved: (value){ + // _serviceReport.jobSheetNumber = value; + // }, // ), // ], // ), - // // ATextFormField( - // // initialValue: _serviceReport?.workHours, - // // textAlign: TextAlign.center, - // // hintText: "i.e 3, 3.5, 4", - // // style: Theme.of(context).textTheme.subtitle1, - // // validator: (value) => - // // Validator.isNumeric(value) - // // ? null : _subtitle.requiredWord, - // // textInputType: TextInputType.number, - // // onSaved: (value){ - // // _serviceReport.workHours = value; - // // }, - // // ), - // ], - // ), + // ), + // ], // ), - // const SizedBox(width: 8,), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(_subtitle.travelingHours), - const SizedBox( - height: 4, - ), - ATextFormField( - initialValue: _serviceReport?.travelingHours, - textAlign: TextAlign.center, - hintText: "i.e 3, 3.5, 4", - style: Theme.of(context).textTheme.subtitle1, - // validator: (value) => - // Validator.isNumeric(value) - // ? null : _subtitle.requiredWord, - textInputType: TextInputType.number, - onSaved: (value) { - _serviceReport.travelingHours = value; - }, - ), - ], - ), + + const SizedBox(height: 8), + ASubTitle(_subtitle.comment), + const SizedBox(height: 4), + ATextFormField( + initialValue: _serviceReport?.comment, + hintText: "Technical Comment", + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.titleMedium, + textInputType: TextInputType.multiline, + onSaved: (value) { + _serviceReport.comment = value; + }, + ), + const SizedBox(height: 8), + const ASubTitle("Nurse Signature"), + ESignature( + oldSignature: _serviceReport.signatureNurse, + newSignature: _serviceReport.localNurseSignature, + onSaved: (signature) { + if (signature == null || signature.isEmpty) { + return; + } + _serviceReport.localNurseSignature = signature; + _serviceReport.signatureNurse = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + }, + ), + const SizedBox(height: 8), + const ASubTitle("Engineer Signature"), + ESignature( + oldSignature: _serviceReport.signatureEngineer, + newSignature: _serviceReport.localNurseSignature, + onSaved: (signature) { + if (signature == null || signature.isEmpty) { + return; + } + _serviceReport.localNurseSignature = signature; + _serviceReport.signatureEngineer = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + }, + ), + const SizedBox( + height: 8, ), ], ), - const SizedBox( - height: 8, - ), - // Operating Hours and Job Sheet Number - // Row( - // children: [ - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(_subtitle.operatingHours), - // const SizedBox(height: 4,), - // ATextFormField( - // initialValue: _serviceReport?.operatingHours, - // textAlign: TextAlign.center, - // hintText: "i.e 3, 3.5, 4", - // style: Theme.of(context).textTheme.subtitle1, - // validator: (value) => - // Validator.isNumeric(value) - // ? null : _subtitle.requiredWord, - // textInputType: TextInputType.number, - // onSaved: (value){ - // _serviceReport.operatingHours = value; - // }, - // ), - // ], - // ), - // ), - // const SizedBox(width: 8,), - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(_subtitle.jobSheetNumber), - // const SizedBox(height: 4,), - // ATextFormField( - // initialValue: _serviceReport?.jobSheetNumber, - // textAlign: TextAlign.center, - // style: Theme.of(context).textTheme.subtitle1, - // textInputType: TextInputType.name, - // onSaved: (value){ - // _serviceReport.jobSheetNumber = value; - // }, - // ), - // ], - // ), - // ), - // ], - // ), + ), - const SizedBox( - height: 8, - ), - ASubTitle(_subtitle.comment), - const SizedBox( - height: 4, - ), - ATextFormField( - initialValue: _serviceReport?.comment, - hintText: "Technical Comment", - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.titleMedium, - textInputType: TextInputType.multiline, - onSaved: (value) { - _serviceReport.comment = value; - }, - ), - const SizedBox(height: 8), - const ASubTitle("Nurse Signature"), - ESignature( - oldSignature: _serviceReport.signatureNurse, - newSignature: _serviceReport.localNurseSignature, - onSaved: (signature) { - if (signature == null || signature.isEmpty) { - return; - } - _serviceReport.localNurseSignature = signature; - _serviceReport.signatureNurse = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; - }, - ), - const SizedBox( - height: 8, - ), - const ASubTitle("Engineer Signature"), - ESignature( - oldSignature: _serviceReport.signatureEngineer, - newSignature: _serviceReport.localNurseSignature, - onSaved: (signature) { - if (signature == null || signature.isEmpty) { - return; - } - _serviceReport.localNurseSignature = signature; - _serviceReport.signatureEngineer = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; - }, - ), - const SizedBox( - height: 8, - ), - // Part Number and Quantity - Row( + // Part Number and Quantity + ASubTitle("Spare Parts"), + Container( + width: double.infinity, + padding: const EdgeInsets.all(16), + margin: const EdgeInsets.symmetric(vertical: 16), + decoration: BoxDecoration(color: AColors.grey, borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), boxShadow: [ + BoxShadow( + color: AColors.grey, + offset: Offset(0, -1), + ) + ]), + child: Column( + mainAxisSize: MainAxisSize.min, children: [ - Expanded( - flex: 3, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(_subtitle.partNumber), - _validate && _serviceReport.parts == null - ? ASubTitle( - _subtitle.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - const SizedBox( - height: 4, - ), - AutoCompletePartsField( - onPick: (part) { - _serviceReport.parts.add(part); - }, + Row( + children: [ + Expanded( + flex: 3, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ASubTitle(_subtitle.partNumber), + _validate && _serviceReport.parts == null + ? ASubTitle( + _subtitle.requiredWord, + color: Colors.red, + ) + : const SizedBox.shrink(), + const SizedBox( + height: 4, + ), + AutoCompletePartsField( + onPick: (part) { + _serviceReport.parts.add(part); + }, + ), + ], ), - ], - ), + ), + ], + ), + SizedBox( + height: 8 * AppStyle.getScaleFactor(context), + ), + Row( + children: [ + Expanded(flex: 3, child: Text(_subtitle.number)), + Expanded(flex: 1, child: Text(_subtitle.quantity)), + ], + ), + Column( + children: List.generate(_serviceReport.parts.length, (index) { + Part _part = _serviceReport.parts[index]; + return PartItem( + part: _part, + onDelete: (part) { + _serviceReport.parts.remove(part); + setState(() {}); + }, + ); + }), + ), + const SizedBox( + height: 16, ), ], ), - SizedBox( - height: 8 * AppStyle.getScaleFactor(context), - ), - Row( - children: [ - Expanded(flex: 3, child: Text(_subtitle.number)), - Expanded(flex: 1, child: Text(_subtitle.quantity)), - ], - ), - Column( - children: List.generate(_serviceReport.parts.length, (index) { - Part _part = _serviceReport.parts[index]; - return PartItem( - part: _part, - onDelete: (part) { - _serviceReport.parts.remove(part); - setState(() {}); - }, - ); - }), - ), - const SizedBox( - height: 16, - ), - ], - ), + ), + ], ), - Padding( - padding: const EdgeInsets.all(16.0), - child: AButton( - text: _subtitle.submit, - onPressed: () async { - _validate = true; - if (!_formKey.currentState.validate()) { - setState(() {}); - return; - } - if (!_serviceReport.validate()) return; - _formKey.currentState.save(); + AButton( + text: _subtitle.submit, + onPressed: () async { + _validate = true; + // if (!_formKey.currentState.validate()) { + // setState(() {}); + // return; + // } + if (!_serviceReport.validate()) return; + _formKey.currentState.save(); - _isLoading = true; - setState(() {}); + _isLoading = true; + setState(() {}); - int status = await _serviceRequestsProvider.createServiceReport( - user: _userProvider.user, - host: _settingProvider.host, - report: _serviceReport, - request: widget.request, + int status = await _serviceRequestsProvider.createServiceReport( + user: _userProvider.user, + host: _settingProvider.host, + report: _serviceReport, + request: widget.request, + ); + print(6); + print(status); + _isLoading = false; + setState(() {}); + if (status >= 200 && status < 300) { + Fluttertoast.showToast( + msg: _subtitle.requestCompleteSuccessfully, ); - print(6); - print(status); - _isLoading = false; - setState(() {}); - if (status >= 200 && status < 300) { - Fluttertoast.showToast( - msg: _subtitle.requestCompleteSuccessfully, - ); - Navigator.of(context).pop(); - Navigator.of(context).pop(); - } else { - String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle); - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text(errorMessage), - )); - } - }, - ), + Navigator.of(context).pop(); + Navigator.of(context).pop(); + } else { + String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle); + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text(errorMessage), + )); + } + }, ), const SizedBox( height: 300,