|
|
|
|
@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:test_sa/controllers/providers/api/service_requests_provider.dart';
|
|
|
|
|
import 'package:test_sa/models/lookup.dart';
|
|
|
|
|
import 'package:test_sa/models/service_request/search_work_order.dart';
|
|
|
|
|
import 'package:test_sa/models/subtitle.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/app_text_form_field.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/buttons/app_button.dart';
|
|
|
|
|
@ -10,6 +12,7 @@ import 'package:test_sa/views/widgets/status/report/service_report_repair_locati
|
|
|
|
|
|
|
|
|
|
import '../../../controllers/api_routes/http_status_manger.dart';
|
|
|
|
|
import '../../../controllers/localization/localization.dart';
|
|
|
|
|
import '../../../models/engineer.dart';
|
|
|
|
|
import '../../../models/service_report.dart';
|
|
|
|
|
import '../../app_style/sizing.dart';
|
|
|
|
|
import '../../widgets/date_and_time/time_picker.dart';
|
|
|
|
|
@ -17,7 +20,8 @@ import '../../widgets/status/report/service_report_all_users.dart';
|
|
|
|
|
import '../../widgets/titles/app_sub_title.dart';
|
|
|
|
|
|
|
|
|
|
class WorkOrderDetailsBottomSheet extends StatefulWidget {
|
|
|
|
|
const WorkOrderDetailsBottomSheet({Key key}) : super(key: key);
|
|
|
|
|
final SearchWorkOrders workOrder;
|
|
|
|
|
const WorkOrderDetailsBottomSheet({this.workOrder, Key key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<WorkOrderDetailsBottomSheet> createState() => _WorkOrderDetailsBottomSheetState();
|
|
|
|
|
@ -25,6 +29,15 @@ class WorkOrderDetailsBottomSheet extends StatefulWidget {
|
|
|
|
|
|
|
|
|
|
class _WorkOrderDetailsBottomSheetState extends State<WorkOrderDetailsBottomSheet> {
|
|
|
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
|
|
|
|
SearchWorkOrders _workOrder;
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_workOrder = widget.workOrder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final size = MediaQuery.of(context).size;
|
|
|
|
|
@ -56,14 +69,16 @@ class _WorkOrderDetailsBottomSheetState extends State<WorkOrderDetailsBottomShee
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
const ATextFormField(enable: false, hintText: "Assigned Employee: ${123}"),
|
|
|
|
|
ATextFormField(enable: false, hintText: "Assigned Employee: ${_workOrder.assignedEmployee?.name}"),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
const ASubTitle("Assistant Employee"),
|
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
|
ServiceReportAllUsers(
|
|
|
|
|
// initialValue: _searchWorkOrders.assignedEmployee == null ? null : Engineer(id: _searchWorkOrders.assignedEmployee.id, name: _searchWorkOrders.assignedEmployee.name),
|
|
|
|
|
initialValue: _workOrder.assistantEmployees == null || _workOrder.assistantEmployees.isEmpty
|
|
|
|
|
? null
|
|
|
|
|
: Engineer(id: _workOrder.assistantEmployees?.first?.id, name: _workOrder.assistantEmployees?.first?.name),
|
|
|
|
|
onSelect: (engineer) {
|
|
|
|
|
// _searchWorkOrders.assignedEmployee = AssignedEmployee(id: engineer.id, name: engineer.name);
|
|
|
|
|
_workOrder.assistantEmployees = [AssignedEmployee(id: engineer.id, name: engineer.name)];
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
@ -78,12 +93,12 @@ class _WorkOrderDetailsBottomSheetState extends State<WorkOrderDetailsBottomShee
|
|
|
|
|
height: 8 * AppStyle.getScaleFactor(context),
|
|
|
|
|
),
|
|
|
|
|
ADateTimePicker(
|
|
|
|
|
// date: _gasRefillProvider.startDate,
|
|
|
|
|
date: DateTime.tryParse(_workOrder.startDate ?? ""),
|
|
|
|
|
from: DateTime.now().subtract(const Duration(days: 365)),
|
|
|
|
|
to: DateTime.now().add(const Duration(days: 365)),
|
|
|
|
|
onDateTimePicker: (date) {
|
|
|
|
|
// _gasRefillProvider.startDate = date;
|
|
|
|
|
// setState(() {});
|
|
|
|
|
_workOrder.startDate = date?.toIso8601String();
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
@ -99,12 +114,12 @@ class _WorkOrderDetailsBottomSheetState extends State<WorkOrderDetailsBottomShee
|
|
|
|
|
height: 8 * AppStyle.getScaleFactor(context),
|
|
|
|
|
),
|
|
|
|
|
ADateTimePicker(
|
|
|
|
|
// date: _gasRefillProvider.endDate,
|
|
|
|
|
date: DateTime.tryParse(_workOrder.endDate ?? ""),
|
|
|
|
|
from: DateTime.now().subtract(const Duration(days: 365)),
|
|
|
|
|
to: DateTime.now().add(const Duration(days: 365)),
|
|
|
|
|
onDateTimePicker: (date) {
|
|
|
|
|
// _gasRefillProvider.endDate = date;
|
|
|
|
|
// setState(() {});
|
|
|
|
|
_workOrder.endDate = date?.toIso8601String();
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
@ -118,53 +133,66 @@ class _WorkOrderDetailsBottomSheetState extends State<WorkOrderDetailsBottomShee
|
|
|
|
|
ATextFormField(
|
|
|
|
|
initialValue: null,
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
// hintText: _gasRefillProvider.startDate == null
|
|
|
|
|
// ? "0"
|
|
|
|
|
// : ((_gasRefillProvider.endDate?.difference(_gasRefillProvider.startDate)?.inMinutes ?? 0) / 60)?.toStringAsFixed(2)?.toString() ?? "0",
|
|
|
|
|
hintText: _workOrder.startDate == null
|
|
|
|
|
? "0"
|
|
|
|
|
: ((DateTime.tryParse(_workOrder.endDate)?.difference(DateTime.tryParse(_workOrder.startDate ?? ""))?.inMinutes ?? 0) / 60)?.toStringAsFixed(2)?.toString() ?? "0",
|
|
|
|
|
enable: false,
|
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
|
// validator: (value) => Validator.isNumeric(value) ? null : _subtitle.requiredWord,
|
|
|
|
|
textInputType: TextInputType.number,
|
|
|
|
|
onSaved: (value) {
|
|
|
|
|
// _serviceReport.workHours = value;
|
|
|
|
|
_workOrder.workingHours = double.tryParse(value);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
const ATextFormField(
|
|
|
|
|
ATextFormField(
|
|
|
|
|
labelText: "Travel Hours",
|
|
|
|
|
initialValue: _workOrder.travelingHours?.toString(),
|
|
|
|
|
textInputType: TextInputType.number,
|
|
|
|
|
onSaved: (value) {
|
|
|
|
|
_workOrder.travelingHours = num.tryParse(value);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
const ATextFormField(
|
|
|
|
|
ATextFormField(
|
|
|
|
|
labelText: "Travel Expense",
|
|
|
|
|
initialValue: _workOrder.travelingExpenses?.toString(),
|
|
|
|
|
textInputType: TextInputType.number,
|
|
|
|
|
onSaved: (value) {
|
|
|
|
|
_workOrder.travelingExpenses = num.tryParse(value);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
ASubTitle(subtitle.callLastSituation),
|
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
|
ServiceReportMaintenanceSituation(
|
|
|
|
|
initialValue: null /*_searchWorkOrders.calllastSituation*/,
|
|
|
|
|
initialValue: _workOrder.calllastSituation,
|
|
|
|
|
onSelect: (status) {
|
|
|
|
|
// if (status?.value == 12 || _searchWorkOrders.calllastSituation?.value == 12) {
|
|
|
|
|
// _searchWorkOrders.calllastSituation = status;
|
|
|
|
|
// setState(() {});
|
|
|
|
|
// } else {
|
|
|
|
|
// _searchWorkOrders.calllastSituation = status;
|
|
|
|
|
// }
|
|
|
|
|
if (status?.value == 12 || _workOrder.calllastSituation?.value == 12) {
|
|
|
|
|
_workOrder.calllastSituation = status;
|
|
|
|
|
setState(() {});
|
|
|
|
|
} else {
|
|
|
|
|
_workOrder.calllastSituation = status;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
const ASubTitle("Repair Location"),
|
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
|
ServiceReportRepairLocation(
|
|
|
|
|
// initialValue: _serviceReport.repairLocation,
|
|
|
|
|
initialValue: _workOrder.repairLocation != null ? Lookup(name: _workOrder.repairLocation) : null,
|
|
|
|
|
onSelect: (status) {
|
|
|
|
|
// _serviceReport.repairLocation = status;
|
|
|
|
|
_workOrder.repairLocation = status.name;
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
const ATextFormField(
|
|
|
|
|
ATextFormField(
|
|
|
|
|
labelText: "Technical Comments",
|
|
|
|
|
hintText: "Add Some Text",
|
|
|
|
|
initialValue: _workOrder.reviewComment,
|
|
|
|
|
textInputType: TextInputType.multiline,
|
|
|
|
|
onSaved: (value) {
|
|
|
|
|
_workOrder.reviewComment = value;
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
|
],
|
|
|
|
|
@ -186,11 +214,11 @@ class _WorkOrderDetailsBottomSheetState extends State<WorkOrderDetailsBottomShee
|
|
|
|
|
// }
|
|
|
|
|
_formKey.currentState.save();
|
|
|
|
|
|
|
|
|
|
// _isLoading = true;
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
setState(() {});
|
|
|
|
|
|
|
|
|
|
int status = await Provider.of<ServiceRequestsProvider>(context).updateServiceReport(report: ServiceReport());
|
|
|
|
|
// _isLoading = false;
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
setState(() {});
|
|
|
|
|
if (status >= 200 && status < 300) {
|
|
|
|
|
Fluttertoast.showToast(msg: subtitle.requestCompleteSuccessfully);
|
|
|
|
|
|