ppm multi timer added.

main_design2.0
Sikander Saleem 2 years ago
parent e304a252d6
commit e212cf75b1

@ -1,8 +1,8 @@
class URLs { class URLs {
URLs._(); URLs._();
static const host1 = "https://atomsm.hmg.com"; // production url // static const host1 = "https://atomsm.hmg.com"; // production url
// static const host1 = "https://atomsmdev.hmg.com"; // local UAT url static const host1 = "https://atomsmdev.hmg.com"; // local UAT url
static String _baseUrl = "$_host/mobile"; static String _baseUrl = "$_host/mobile";
@ -16,6 +16,7 @@ class URLs {
// API Routes // API Routes
static get login => "$_baseUrl/MobileAuth/Login"; // web login static get login => "$_baseUrl/MobileAuth/Login"; // web login
static get checkLoginValidation => "$_baseUrl/Account/Authenticate "; // web login
// static get login => "$_baseUrl/MobileAuth/LoginIntegration"; // mobile login // static get login => "$_baseUrl/MobileAuth/LoginIntegration"; // mobile login
static get register => "$_baseUrl/handle/create/user"; // post static get register => "$_baseUrl/handle/create/user"; // post
static get updateProfile => "$_baseUrl/update/user/profile"; // post static get updateProfile => "$_baseUrl/update/user/profile"; // post

@ -170,6 +170,14 @@ class PpmProvider extends ChangeNotifier {
@required Ppm ppm, @required Ppm ppm,
}) async { }) async {
try { try {
ppm.visitTimers.add(
VisitTimers(
id: 0,
startDateTime: ppm.tbsTimer?.startAt?.toIso8601String(),
endDateTime: ppm.tbsTimer?.endAt?.toIso8601String(),
workingHours: ((ppm.tbsTimer?.durationInSecond ?? 0) / 60 / 60),
),
);
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading()); showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
Response response; Response response;
Map<String, dynamic> body = ppm.copyWith(assignedEmployeeId: user.userName, tbsTimer: ppm.tbsTimer).toJson(); Map<String, dynamic> body = ppm.copyWith(assignedEmployeeId: user.userName, tbsTimer: ppm.tbsTimer).toJson();

@ -16,7 +16,7 @@ extension StringExtensions on String {
DateTime dateTime = DateTime.tryParse(this); DateTime dateTime = DateTime.tryParse(this);
return "${DateFormat('dd MMM, yyyy').format(dateTime)} ${DateFormat('hh:mm a').format(dateTime)}"; return "${DateFormat('dd MMM, yyyy').format(dateTime)} ${DateFormat('hh:mm a').format(dateTime)}";
} catch (e) { } catch (e) {
return "null"; return "";
} }
} }
@ -45,7 +45,7 @@ extension StringExtensions on String {
sub = sub.replaceAll("fileName=", ""); sub = sub.replaceAll("fileName=", "");
return sub; return sub;
} else { } else {
this; return this;
} }
} catch (e) { } catch (e) {
return this; return this;

@ -12,6 +12,31 @@ import 'package:test_sa/models/ppm/ppm_contacts.dart';
import 'package:test_sa/models/ppm/ppm_kit.dart'; import 'package:test_sa/models/ppm/ppm_kit.dart';
import 'package:test_sa/models/timer_model.dart'; import 'package:test_sa/models/timer_model.dart';
class VisitTimers {
int id;
String startDateTime;
String endDateTime;
double workingHours;
VisitTimers({this.id, this.startDateTime, this.endDateTime, this.workingHours});
VisitTimers.fromJson(Map<String, dynamic> json) {
id = json['id'];
startDateTime = json['startDateTime'];
endDateTime = json['endDateTime'];
workingHours = json['workingHours'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['startDateTime'] = this.startDateTime;
data['endDateTime'] = this.endDateTime;
data['workingHours'] = this.workingHours;
return data;
}
}
class Ppm { class Ppm {
Ppm({ Ppm({
this.id, this.id,
@ -37,6 +62,7 @@ class Ppm {
this.vChecklists, this.vChecklists,
this.files, this.files,
this.visitStatusId, this.visitStatusId,
this.visitTimers,
this.startDate, this.startDate,
this.endDate, this.endDate,
this.workingHours, this.workingHours,
@ -87,9 +113,9 @@ class Ppm {
this.safetyName, this.safetyName,
this.siteId, this.siteId,
this.siteName, this.siteName,
this. buildingName, this.buildingName,
this. floorName, this.floorName,
this. roomName, this.roomName,
this.supplierName, this.supplierName,
this.suppPerson, this.suppPerson,
this.taskStatusName, this.taskStatusName,
@ -151,18 +177,25 @@ class Ppm {
}); });
} }
visitStatusId = json['visitStatusId']; visitStatusId = json['visitStatusId'];
visitTimers = <VisitTimers>[];
if (json['visitTimers'] != null) {
json['visitTimers'].forEach((v) {
visitTimers.add(VisitTimers.fromJson(v));
});
}
startDate = json['startDate']; startDate = json['startDate'];
endDate = json['endDate']; endDate = json['endDate'];
workingHours = json['workingHours']; workingHours = json['workingHours'];
try { tbsTimer= TimerModel();
tbsTimer = TimerModel(startAt: DateTime.tryParse(startDate ?? ""), endAt: DateTime.tryParse(endDate ?? "")); // try {
if (tbsTimer.endAt != null && tbsTimer.startAt != null) { // tbsTimer = TimerModel(startAt: DateTime.tryParse(startDate ?? ""), endAt: DateTime.tryParse(endDate ?? ""));
tbsTimer.durationInSecond = (tbsTimer.endAt.difference(tbsTimer.startAt))?.inSeconds; // if (tbsTimer.endAt != null && tbsTimer.startAt != null) {
workingHours = (((tbsTimer.durationInSecond ?? 0) / 60) / 60).toStringAsFixed(2); // tbsTimer.durationInSecond = (tbsTimer.endAt.difference(tbsTimer.startAt))?.inSeconds;
} // workingHours = (((tbsTimer.durationInSecond ?? 0) / 60) / 60).toStringAsFixed(2);
} catch (e) { // }
print(e.toString()); // } catch (e) {
} // print(e.toString());
// }
travelingHours = json['travelingHours']; travelingHours = json['travelingHours'];
deviceStatusId = json['deviceStatusId']; deviceStatusId = json['deviceStatusId'];
comments = json['comments']; comments = json['comments'];
@ -255,6 +288,8 @@ class Ppm {
List<PpmChecklists> vChecklists; List<PpmChecklists> vChecklists;
List<PpmAttachments> files; List<PpmAttachments> files;
num visitStatusId; num visitStatusId;
List<VisitTimers> visitTimers;
String startDate; String startDate;
String endDate; String endDate;
String workingHours; String workingHours;
@ -347,6 +382,7 @@ class Ppm {
List<PpmChecklists> vChecklists, List<PpmChecklists> vChecklists,
List<PpmAttachments> files, List<PpmAttachments> files,
num visitStatusId, num visitStatusId,
List<VisitTimers> visitTimers,
String startDate, String startDate,
String endDate, String endDate,
String workingHours, String workingHours,
@ -437,6 +473,7 @@ class Ppm {
vChecklists: vChecklists ?? this.vChecklists, vChecklists: vChecklists ?? this.vChecklists,
files: files ?? this.files, files: files ?? this.files,
visitStatusId: visitStatusId ?? this.visitStatusId, visitStatusId: visitStatusId ?? this.visitStatusId,
visitTimers: visitTimers ?? this.visitTimers,
startDate: startDate ?? this.startDate, startDate: startDate ?? this.startDate,
endDate: endDate ?? this.endDate, endDate: endDate ?? this.endDate,
workingHours: workingHours ?? this.workingHours, workingHours: workingHours ?? this.workingHours,
@ -541,9 +578,12 @@ class Ppm {
.toList(); .toList();
} }
map['visitStatusId'] = visitStatusId; map['visitStatusId'] = visitStatusId;
map['startDate'] = tbsTimer?.startAt?.toIso8601String(); if (this.visitTimers != null) {
map['endDate'] = tbsTimer?.endAt?.toIso8601String(); map['visitTimers'] = this.visitTimers.map((v) => v.toJson()).toList();
map['workingHours'] = ((tbsTimer?.durationInSecond ?? 0) / 60 / 60).toStringAsFixed(5); }
// map['startDate'] = tbsTimer?.startAt?.toIso8601String();
// map['endDate'] = tbsTimer?.endAt?.toIso8601String();
// map['workingHours'] = ((tbsTimer?.durationInSecond ?? 0) / 60 / 60).toStringAsFixed(5);
map['travelingHours'] = travelingHours; map['travelingHours'] = travelingHours;
map['deviceStatusId'] = deviceStatusId; map['deviceStatusId'] = deviceStatusId;
map['comments'] = comments; map['comments'] = comments;
@ -555,7 +595,6 @@ class Ppm {
map['suppEndDate'] = externalEngineerTimer?.endAt?.toIso8601String(); map['suppEndDate'] = externalEngineerTimer?.endAt?.toIso8601String();
map['suppWorkingHours'] = ((externalEngineerTimer?.durationInSecond ?? 0) / 60 / 60).toStringAsFixed(5); map['suppWorkingHours'] = ((externalEngineerTimer?.durationInSecond ?? 0) / 60 / 60).toStringAsFixed(5);
map['taskStatusId'] = taskStatusId; map['taskStatusId'] = taskStatusId;
map['engSignature'] = engSignature; map['engSignature'] = engSignature;
map['nurseSignature'] = nurseSignature; map['nurseSignature'] = nurseSignature;

@ -8,6 +8,7 @@ import 'package:test_sa/extensions/string_extensions.dart';
import 'package:test_sa/models/ppm/ppm.dart'; import 'package:test_sa/models/ppm/ppm.dart';
import 'package:test_sa/models/ppm/ppm_attachment.dart'; import 'package:test_sa/models/ppm/ppm_attachment.dart';
import 'package:test_sa/models/service_request/supplier_details.dart'; import 'package:test_sa/models/service_request/supplier_details.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/providers/loading_list_notifier.dart'; import 'package:test_sa/providers/loading_list_notifier.dart';
import 'package:test_sa/providers/ppm_asset_availability_provider.dart'; import 'package:test_sa/providers/ppm_asset_availability_provider.dart';
import 'package:test_sa/providers/ppm_electrical_safety_provider.dart'; import 'package:test_sa/providers/ppm_electrical_safety_provider.dart';
@ -43,6 +44,10 @@ class _PentryTBSFormState extends State<PentryTBSForm> {
widget.model?.files ??= []; widget.model?.files ??= [];
widget.model?.files = (widget.model.files ?? []).where((element) => element.attachmentName != null && element.attachmentName.isNotEmpty).toList(); widget.model?.files = (widget.model.files ?? []).where((element) => element.attachmentName != null && element.attachmentName.isNotEmpty).toList();
double totalWorkingHours = widget.model.visitTimers.fold(0.0, (sum, item) => sum + DateTime.parse(item.endDateTime).difference(DateTime.parse(item.startDateTime)).inSeconds);
totalWorkingHours = totalWorkingHours;
return SingleChildScrollView( return SingleChildScrollView(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
@ -66,6 +71,33 @@ class _PentryTBSFormState extends State<PentryTBSForm> {
}, },
), ),
8.height, 8.height,
if (totalWorkingHours > 0.0) ...[
Container(
height: 50.toScreenHeight,
padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth),
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: context.isDark ? AppColor.neutral40 : AppColor.background(context),
borderRadius: BorderRadius.circular(10),
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Total Working Time",
style: Theme.of(context).textTheme.bodySmall?.copyWith(color: context.isDark ? null : AppColor.neutral20, fontWeight: FontWeight.w500),
),
Text(
" ${formatDuration(totalWorkingHours.round())}",
style: Theme.of(context).textTheme.bodyLarge,
),
],
),
),
8.height,
],
AppTimer( AppTimer(
label: context.translation.timer, label: context.translation.timer,
timer: widget.model.tbsTimer, timer: widget.model.tbsTimer,
@ -148,7 +180,6 @@ class _PentryTBSFormState extends State<PentryTBSForm> {
}, },
), ),
8.height, 8.height,
if (widget.model?.typeOfServiceId == 66) ...[ if (widget.model?.typeOfServiceId == 66) ...[
SingleItemDropDownMenu<SupplierDetails, VendorProvider>( SingleItemDropDownMenu<SupplierDetails, VendorProvider>(
context: context, context: context,
@ -291,4 +322,44 @@ class _PentryTBSFormState extends State<PentryTBSForm> {
), ),
); );
} }
String formatDuration1(int seconds) {
int hours = seconds ~/ 3600;
int minutes = (seconds % 3600) ~/ 60;
String formattedDuration = '';
if (hours > 0) {
formattedDuration += '$hours hour${hours > 1 ? 's' : ''} ';
}
if (minutes > 0) {
formattedDuration += '$minutes minute${minutes > 1 ? 's' : ''} ';
}
if (formattedDuration.isEmpty) {
formattedDuration = 'Less than a minute';
}
return formattedDuration.trim();
}
String formatDuration(int seconds) {
int hours = seconds ~/ 3600;
int minutes = (seconds % 3600) ~/ 60;
int remainingSeconds = seconds % 60;
String formattedDuration = '';
if (hours > 0) {
formattedDuration += '$hours hour${hours > 1 ? 's' : ''} ';
}
if (minutes > 0) {
formattedDuration += '$minutes minute${minutes > 1 ? 's' : ''} ';
}
if (remainingSeconds > 0) {
formattedDuration += '$remainingSeconds second${remainingSeconds > 1 ? 's' : ''} ';
}
if (formattedDuration.isEmpty) {
formattedDuration = 'Less than a second';
}
return formattedDuration.trim();
}
} }

@ -162,7 +162,7 @@ class _RecordSoundState extends State<RecordSound> {
alignment: AlignmentDirectional.centerEnd, alignment: AlignmentDirectional.centerEnd,
children: [ children: [
AppTextFormField( AppTextFormField(
enable: false, enable: widget.enabled,
controller: _timeController, controller: _timeController,
labelText: context.translation.recordVoice, labelText: context.translation.recordVoice,
initialValue: (_timeController?.text?.isEmpty ?? true) ? "00:00" : _timeController?.text, initialValue: (_timeController?.text?.isEmpty ?? true) ? "00:00" : _timeController?.text,

Loading…
Cancel
Save