Merge branch 'zaid-development' into 'master'

Preventive Maintenance Screen

See merge request haroon6138/cloudsolutions-atoms!8
merge-requests/9/merge
Sikander Saleem 2 years ago
commit af5726fe38

@ -72,11 +72,9 @@ class RegularVisitsProvider extends ChangeNotifier {
if (response.statusCode >= 200 && response.statusCode < 300) {
// client's request was successfully received
try {
List requestsListJson =
json.decode(utf8.decode(response.bodyBytes).replaceAll("\\", ""));
List<Visit> visits =
requestsListJson.map((request) => Visit.fromJson(request)).toList();
visits.addAll(visits);
List requestsListJson = json.decode(utf8.decode(response.bodyBytes).replaceAll("\\", ""));
List<Visit> visitsList = requestsListJson.map((request) => Visit.fromJson(request)).toList();
visits.addAll(visitsList);
if (visits.length == pageItemNumber) {
nextPage = true;
} else {
@ -149,22 +147,22 @@ class RegularVisitsProvider extends ChangeNotifier {
}
Future<int> updatePentry({
required String host,
required User user,
required Pentry pentry,
required Visit visit,
required String? host,
required User? user,
required Pentry? pentry,
required Visit? visit,
}) async {
try {
Response response;
Map<String, String> body = pentry.toMap();
body["uid"] = user.id ?? "";
body["token"] = user.token ?? "";
Map<String, String>? body = pentry?.toMap();
body?["uid"] = user?.id ?? "";
body?["token"] = user?.token ?? "";
response = await post(
Uri.parse("$host${URLs.updatePentry}/${visit.id}"),
Uri.parse("$host${URLs.updatePentry}/${visit?.id}"),
body: body,
);
if (response.statusCode >= 200 && response.statusCode < 300) {
visit.status = pentry.ppmVisitStatus;
visit?.status = pentry?.ppmVisitStatus;
notifyListeners();
}
return response.statusCode;

@ -44,21 +44,15 @@ class Pentry {
Map<String, String> toMap() {
Map<String, String> map = {};
if (ppmVisitStatus != null)
map["visit_status"] = ppmVisitStatus!.id.toString();
if (ppmVisitStatus != null) map["visit_status"] = ppmVisitStatus!.id.toString();
if (status != null) map["pentry_status"] = status!.id.toString();
if (travelingHours != null) map["traveling_hours"] = travelingHours!;
if (imageFile != null)
map["file_attachement"] = base64Encode(imageFile!.readAsBytesSync());
map["actual_date"] = ((actualVisitDate?.millisecondsSinceEpoch ?? 0) / 1000)
.toStringAsFixed(0);
if (imageFile != null) map["file_attachement"] = base64Encode(imageFile!.readAsBytesSync());
map["actual_date"] = ((actualVisitDate?.millisecondsSinceEpoch ?? 0) / 1000).toStringAsFixed(0);
if (timer != null) {
map["start_date"] =
((timer!.startAt?.millisecondsSinceEpoch??0) / 1000).toStringAsFixed(0);
map["end_date"] =
(((timer!.endAt)?.millisecondsSinceEpoch??0) / 1000).toStringAsFixed(0);
map["working_hours"] =
((timer!.durationInSecond??0) / 60 / 60).toStringAsFixed(5);
map["start_date"] = ((timer!.startAt?.millisecondsSinceEpoch ?? 0) / 1000).toStringAsFixed(0);
map["end_date"] = (((timer!.endAt)?.millisecondsSinceEpoch ?? 0) / 1000).toStringAsFixed(0);
map["working_hours"] = ((timer!.durationInSecond ?? 0) / 60 / 60).toStringAsFixed(5);
}
// if(contacts?.isNotEmpty == true) {
// for(int i = 0;i<contacts.length;i++){
@ -67,10 +61,8 @@ class Pentry {
// });
// }
// }
map["ppmCheckLists"] =
jsonEncode(ppmCheckLists?.map((e) => e.toMap()).toList());
map["calibrationTools"] =
jsonEncode(calibrationTools?.map((e) => e.toMap()).toList());
map["ppmCheckLists"] = jsonEncode(ppmCheckLists?.map((e) => e.toMap()).toList());
map["calibrationTools"] = jsonEncode(calibrationTools?.map((e) => e.toMap()).toList());
map["pmKits"] = jsonEncode(pmKits?.map((e) => e.toMap()).toList());
return map;
}
@ -85,34 +77,24 @@ class Pentry {
List<PMKit> pmKits = [];
if (map['pmKits'] != null) {
pmKits = (map['pmKits'] as List<dynamic>)
.map((e) => PMKit.fromMap(e as Map<String, dynamic>))
.toList();
pmKits = (map['pmKits'] as List<dynamic>).map((e) => PMKit.fromMap(e as Map<String, dynamic>)).toList();
}
List<PPMCheckList> ppmCheckLists = [];
if (map['ppmCheckLists'] != null) {
ppmCheckLists = (map['ppmCheckLists'] as List<dynamic>)
.map((e) => PPMCheckList.fromMap(e as Map<String, dynamic>))
.toList();
ppmCheckLists = (map['ppmCheckLists'] as List<dynamic>).map((e) => PPMCheckList.fromMap(e as Map<String, dynamic>)).toList();
}
List<CalibrationTool> calibrationTools = [];
if (map['calibrationTools'] != null) {
calibrationTools = (map['calibrationTools'] as List<dynamic>)
.map((e) => CalibrationTool.fromMap(e as Map<String, dynamic>))
.toList();
calibrationTools = (map['calibrationTools'] as List<dynamic>).map((e) => CalibrationTool.fromMap(e as Map<String, dynamic>)).toList();
}
return Pentry(
status: Lookup.fromJson(map["pentry_status"]),
ppmVisitStatus: Lookup.fromJson(map["visit_status"]),
actualVisitDate: getDate(map["actual_date"]),
travelingHours: map["traveling_hours"],
timer: TimerModel(
startAt: getDate(map["start_date"]),
endAt: getDate(map["end_date"]),
durationInSecond:
(int.tryParse(map["working_hours"] ?? "") ?? 0) * 60 * 60),
timer: TimerModel(startAt: getDate(map["start_date"]), endAt: getDate(map["end_date"]), durationInSecond: (int.tryParse(map["working_hours"] ?? "") ?? 0) * 60 * 60),
// contacts: contacts,
ppmCheckLists: ppmCheckLists,
calibrationTools: calibrationTools,
@ -120,9 +102,7 @@ class Pentry {
);
}
static getDate(String date) {
return date.isEmpty
? null
: DateTime.fromMillisecondsSinceEpoch((int.tryParse(date) ?? 0) * 1000);
static getDate(String? date) {
return date == null || date.isEmpty ? null : DateTime.fromMillisecondsSinceEpoch((int.tryParse(date) ?? 0) * 1000);
}
}

@ -1,4 +1,3 @@
import '../lookup.dart';
class PMKit {
@ -10,15 +9,7 @@ class PMKit{
String? quantityNeeded;
String? quantityReserved;
PMKit({
this.itemCode,
this.itemName,
this.preparationTimeFrame,
this.kitFrequencyDemand,
this.availability,
this.quantityNeeded,
this.quantityReserved
});
PMKit({this.itemCode, this.itemName, this.preparationTimeFrame, this.kitFrequencyDemand, this.availability, this.quantityNeeded, this.quantityReserved});
Map<String, String> toMap() {
return {
@ -35,12 +26,12 @@ class PMKit{
factory PMKit.fromMap(Map<String, dynamic> map) {
return PMKit(
itemCode: Lookup.fromJson(map['itemCode']),
itemName: map['itemName'] as String,
preparationTimeFrame: map['preparationTimeFrame'] as String,
kitFrequencyDemand: map['kitFrequencyDemand'] as String,
availability: map['availability'] as String,
quantityNeeded: map['quantityNeeded'] as String,
quantityReserved: map['quantityReserved'] as String,
itemName: map['itemName'] as String?,
preparationTimeFrame: map['preparationTimeFrame'] as String?,
kitFrequencyDemand: map['kitFrequencyDemand'] as String?,
availability: map['availability'] as String?,
quantityNeeded: map['quantityNeeded'] as String?,
quantityReserved: map['quantityReserved'] as String?,
);
}
}

@ -1,4 +1,3 @@
import '../lookup.dart';
class PPMCheckList {
@ -26,9 +25,9 @@ class PPMCheckList{
factory PPMCheckList.fromMap(Map<String, dynamic> map) {
return PPMCheckList(
status: Lookup.fromJson(map['status']),
title: map['title'] as String,
comment: map['comment'] as String,
measuredValue: map['measuredValue'] as String,
title: map['title'] as String?,
comment: map['comment'] as String?,
measuredValue: map['measuredValue'] as String?,
);
}
}

@ -1,4 +1,3 @@
import '../lookup.dart';
class Visit {

@ -20,6 +20,7 @@ import '../../../../widgets/pentry/pentry_ppm_check_list_form.dart';
class EditPentry extends StatefulWidget {
final Pentry? pentry;
final Visit? visit;
const EditPentry({Key? key, this.pentry, this.visit}) : super(key: key);
@override
@ -29,18 +30,19 @@ class EditPentry extends StatefulWidget {
class _EditPentryState extends State<EditPentry> with SingleTickerProviderStateMixin {
bool _isLoading = false;
bool _validate = false;
late Subtitle _subtitle;
Subtitle? _subtitle;
late UserProvider _userProvider;
late SettingProvider _settingProvider;
late RegularVisitsProvider _regularVisitsProvider;
late Pentry _pentry;
Pentry? _pentry;
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
late TabController _tabController;
late final TabController _tabController;
_onSubmit() async {
_validate = true;
if(!_pentry.validate()) {
if (!(_pentry?.validate() ?? false)) {
setState(() {});
return;
}
@ -48,22 +50,18 @@ class _EditPentryState extends State<EditPentry> with SingleTickerProviderStateM
_isLoading = true;
setState(() {});
int status = await _regularVisitsProvider.updatePentry(
user: _userProvider.user!,
host: _settingProvider.host??"",
pentry: _pentry,
visit: widget.visit!
);
int status = await _regularVisitsProvider.updatePentry(user: _userProvider.user, host: _settingProvider.host, pentry: _pentry, visit: widget.visit);
_isLoading = false;
setState(() {});
if (status >= 200 && status < 300) {
if (_subtitle != null) {
Fluttertoast.showToast(
msg: _subtitle.requestCompleteSuccessfully,
msg: _subtitle!.requestCompleteSuccessfully,
);
}
// Navigator.of(context).pop();
} else {
String errorMessage = HttpStatusManger.getStatusMessage(
status: status, subtitle: _subtitle);
String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle);
Fluttertoast.showToast(
msg: errorMessage,
);
@ -72,7 +70,7 @@ class _EditPentryState extends State<EditPentry> with SingleTickerProviderStateM
@override
void initState() {
_pentry = widget.pentry!;
_pentry = widget.pentry;
_tabController = TabController(length: 4, vsync: this);
super.initState();
}
@ -85,7 +83,7 @@ class _EditPentryState extends State<EditPentry> with SingleTickerProviderStateM
@override
Widget build(BuildContext context) {
_subtitle = AppLocalization.of(context)!.subtitle!;
_subtitle = AppLocalization.of(context)?.subtitle;
_userProvider = Provider.of<UserProvider>(context);
_settingProvider = Provider.of<SettingProvider>(context);
_regularVisitsProvider = Provider.of<RegularVisitsProvider>(context);
@ -110,10 +108,18 @@ class _EditPentryState extends State<EditPentry> with SingleTickerProviderStateM
setState(() {});
},
tabs: const [
Tab(text: "PPM Check List",),
Tab(text: "Calibration Tools",),
Tab(text: "PK Kits",),
Tab(text: "Pentry",),
Tab(
text: "PPM Check List",
),
Tab(
text: "Calibration Tools",
),
Tab(
text: "PK Kits",
),
Tab(
text: "Pentry",
),
]),
),
),
@ -125,15 +131,15 @@ class _EditPentryState extends State<EditPentry> with SingleTickerProviderStateM
controller: _tabController,
children: [
PentryPPMCheckListForm(
models: _pentry.ppmCheckLists,
models: _pentry?.ppmCheckLists,
enableValidate: _validate,
),
PentryCalibrationToolForm(
models: _pentry.calibrationTools,
models: _pentry?.calibrationTools,
enableValidate: _validate,
),
PentryPMKitForm(
models: _pentry.pmKits,
models: _pentry?.pmKits,
enableValidate: _validate,
),
PentryInfoForm(
@ -150,24 +156,28 @@ class _EditPentryState extends State<EditPentry> with SingleTickerProviderStateM
children: [
if (_tabController.index != 0)
ASmallButton(
text: _subtitle.back,
text: _subtitle?.back,
onPressed: () {
_tabController.animateTo(_tabController.index - 1,);
_tabController.animateTo(
_tabController.index - 1,
);
setState(() {});
},
),
const Spacer(),
if (_tabController.index != _tabController.length - 1)
ASmallButton(
text: _subtitle.next,
text: _subtitle?.next,
onPressed: () {
_tabController.animateTo(_tabController.index + 1,);
_tabController.animateTo(
_tabController.index + 1,
);
setState(() {});
},
),
if (_tabController.index == _tabController.length - 1)
ASmallButton(
text: _subtitle.update,
text: _subtitle?.update,
onPressed: _onSubmit,
),
],
@ -177,12 +187,10 @@ class _EditPentryState extends State<EditPentry> with SingleTickerProviderStateM
],
),
),
],
)
),
),
),
);
}
}

@ -4,20 +4,22 @@ import '../../../controllers/localization/localization.dart';
import '../../../models/subtitle.dart';
import '../../app_style/sizing.dart';
import 'date_picker.dart';
class FromToDateBar extends StatefulWidget {
final DateTime from;
final DateTime to;
final DateTime? from;
final DateTime? to;
final Function(DateTime)? onPickFrom;
final Function(DateTime)? onPickTo;
const FromToDateBar({Key? key, required this.from, required this.to, this.onPickFrom, this.onPickTo}) : super(key: key);
@override
_FromToDateBarState createState() => _FromToDateBarState();
}
class _FromToDateBarState extends State<FromToDateBar> {
late DateTime _from;
late DateTime _to;
late DateTime? _from;
late DateTime? _to;
@override
void initState() {
@ -32,16 +34,12 @@ class _FromToDateBarState extends State<FromToDateBar> {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_subtitle?.from ?? '',
style: Theme.of(context).textTheme.bodyText1?.copyWith(
fontSize: 12,
fontWeight: FontWeight.normal
),
style: Theme.of(context).textTheme.bodyText1?.copyWith(fontSize: 12, fontWeight: FontWeight.normal),
textScaleFactor: AppStyle.getScaleFactor(context),
),
ADatePicker(
@ -60,10 +58,7 @@ class _FromToDateBarState extends State<FromToDateBar> {
children: [
Text(
_subtitle?.to ?? "",
style: Theme.of(context).textTheme.bodyText1?.copyWith(
fontSize: 12,
fontWeight: FontWeight.normal
),
style: Theme.of(context).textTheme.bodyText1?.copyWith(fontSize: 12, fontWeight: FontWeight.normal),
textScaleFactor: AppStyle.getScaleFactor(context),
),
ADatePicker(

@ -13,7 +13,9 @@ class PentryPPMCheckListForm extends StatefulWidget {
final List<PPMCheckList>? models;
final bool? enableValidate;
const PentryPPMCheckListForm({
Key? key, this.models, this.enableValidate,
Key? key,
this.models,
this.enableValidate,
}) : super(key: key);
@override
@ -21,30 +23,24 @@ class PentryPPMCheckListForm extends StatefulWidget {
}
class _PentryPPMCheckListFormState extends State<PentryPPMCheckListForm> {
@override
Widget build(BuildContext context) {
final subtitle = AppLocalization.of(context)?.subtitle;
return ListView.builder(
padding: EdgeInsets.only(
top: 12 * AppStyle.getScaleFactor(context),
left: 12 * AppStyle.getScaleFactor(context),
right: 12 * AppStyle.getScaleFactor(context),
bottom: 80 * AppStyle.getScaleFactor(context)
),
top: 12 * AppStyle.getScaleFactor(context), left: 12 * AppStyle.getScaleFactor(context), right: 12 * AppStyle.getScaleFactor(context), bottom: 80 * AppStyle.getScaleFactor(context)),
itemCount: (widget.models?.length ?? 0) + 1,
itemBuilder: (context, index) {
if (index == widget.models?.length) {
return AButton(
text: subtitle?.add ?? "",
onPressed: () {
widget.models!.add(PPMCheckList());
widget.models?.add(PPMCheckList());
setState(() {});
},
);
}
final model = widget.models![index];
final model = widget.models?[index];
return ListView(
shrinkWrap: true,
physics: const ClampingScrollPhysics(),
@ -56,64 +52,83 @@ class _PentryPPMCheckListFormState extends State<PentryPPMCheckListForm> {
if (index != 0)
ASmallButton(
color: Theme.of(context).colorScheme.error,
text: subtitle!.delete,
text: subtitle?.delete,
onPressed: () {
widget.models!.remove(model);
widget.models?.remove(model);
setState(() {});
},
),
],
),
const SizedBox(height: 8,),
const SizedBox(
height: 8,
),
const ASubTitle("Task"),
const SizedBox(height: 4,),
const SizedBox(
height: 4,
),
ATextFormField(
initialValue: (model.title ?? "").toString(),
initialValue: (model?.title ?? "").toString(),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.subtitle1,
textInputType: TextInputType.text,
onChange: (value) {
model.title = value;
model?.title = value;
},
),
const SizedBox(height: 8,),
const SizedBox(
height: 8,
),
ASubTitle(subtitle?.status ?? ""),
const SizedBox(height: 4,),
const SizedBox(
height: 4,
),
PentryTaskStatusMenu(
initialValue: model.status,
initialValue: model?.status,
onSelect: (status) {
model.status = status;
model?.status = status;
},
),
const SizedBox(height: 8,),
const SizedBox(
height: 8,
),
const ASubTitle("Comment"),
const SizedBox(height: 4,),
const SizedBox(
height: 4,
),
ATextFormField(
initialValue: (model.comment ?? "").toString(),
initialValue: (model?.comment ?? "").toString(),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.subtitle1,
textInputType: TextInputType.text,
onChange: (value) {
model.comment = value;
model?.comment = value;
},
),
const SizedBox(height: 8,),
const SizedBox(
height: 8,
),
const ASubTitle("Measured Value"),
const SizedBox(height: 4,),
const SizedBox(
height: 4,
),
ATextFormField(
initialValue: (model.measuredValue ?? "").toString(),
initialValue: (model?.measuredValue ?? "").toString(),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.subtitle1,
textInputType: TextInputType.text,
onChange: (value) {
model.measuredValue = value;
model?.measuredValue = value;
},
),
const SizedBox(height: 8,),
Divider(color: Theme.of(context).textTheme.titleMedium?.color,),
const SizedBox(
height: 8,
),
Divider(
color: Theme.of(context).textTheme.titleMedium?.color,
),
],
);
}
);
});
}
}

@ -29,8 +29,7 @@ class VisitsSearchDialog extends StatefulWidget {
VisitsSearchDialogState createState() => VisitsSearchDialogState();
}
class VisitsSearchDialogState extends State<VisitsSearchDialog>
with TickerProviderStateMixin {
class VisitsSearchDialogState extends State<VisitsSearchDialog> with TickerProviderStateMixin {
VisitsSearch? _search;
List<Lookup> status = const [
Lookup(
@ -195,8 +194,7 @@ class VisitsSearchDialogState extends State<VisitsSearchDialog>
children: List.generate(
contactStatus.length,
(index) {
bool isSelected =
_search?.contactStatus == contactStatus[index].key;
bool isSelected = _search?.contactStatus == contactStatus[index].key;
return FilterItem(
isSelected: isSelected,
onSelected: () {
@ -220,8 +218,8 @@ class VisitsSearchDialogState extends State<VisitsSearchDialog>
height: 4.0 * AppStyle.getScaleFactor(context),
),
FromToDateBar(
from: _search!.actualDateFrom!,
to: _search!.actualDateTo!,
from: _search?.actualDateFrom,
to: _search?.actualDateTo,
onPickFrom: (date) {
_search?.actualDateFrom = date;
},
@ -237,11 +235,8 @@ class VisitsSearchDialogState extends State<VisitsSearchDialog>
height: 4.0 * AppStyle.getScaleFactor(context),
),
FromToDateBar(
from: _search?.expectedDateFrom ??
DateTime(today.year, today.month, 1),
to: _search?.expectedDateTo ??
DateTime(today.year, (today.month + 1).clamp(1, 12),
today.month == 12 ? 31 : 0),
from: _search?.expectedDateFrom ?? DateTime(today.year, today.month, 1),
to: _search?.expectedDateTo ?? DateTime(today.year, (today.month + 1).clamp(1, 12), today.month == 12 ? 31 : 0),
onPickFrom: (date) {
_search?.expectedDateFrom = date;
},
@ -252,8 +247,7 @@ class VisitsSearchDialogState extends State<VisitsSearchDialog>
Visibility(
visible: _search?.toSearchString().isNotEmpty ?? false,
child: Padding(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: AButton(
padding: EdgeInsets.zero,
text: subtitle?.clearSearch ?? '',

@ -26,11 +26,11 @@ class SingleStatusMenuState extends State<SingleStatusMenu> {
@override
void didUpdateWidget(covariant SingleStatusMenu oldWidget) {
if (widget.initialStatus != null) {
_selectedStatus = widget.statuses?.firstWhere((element) {
_selectedStatus = widget.initialStatus?.id != null
? widget.statuses?.firstWhere((element) {
return element.id == widget.initialStatus?.id;
});
} else {
_selectedStatus = null;
})
: null;
}
super.didUpdateWidget(oldWidget);
}
@ -38,9 +38,11 @@ class SingleStatusMenuState extends State<SingleStatusMenu> {
@override
void initState() {
if (widget.initialStatus != null) {
_selectedStatus = widget.statuses?.firstWhere((element) {
_selectedStatus = widget.initialStatus?.id != null
? widget.statuses?.firstWhere((element) {
return element.id == widget.initialStatus?.id;
});
})
: null;
}
super.initState();
@ -87,9 +89,7 @@ class SingleStatusMenuState extends State<SingleStatusMenu> {
value: value,
child: Text(
value.label ?? '',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.w600),
style: Theme.of(context).textTheme.titleMedium?.copyWith(color: Theme.of(context).primaryColor, fontWeight: FontWeight.w600),
),
);
}).toList(),

Loading…
Cancel
Save