Skip to content

Commit

Permalink
delete job before 8 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
unimegan59781 committed Apr 24, 2024
1 parent c857dcc commit a9ccb03
Showing 1 changed file with 135 additions and 2 deletions.
137 changes: 135 additions & 2 deletions lib/pages/company/companyJob.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,93 @@ class CompanyJobState extends State<CompanyJob> {
});
}

Future<void> deleteJobDb(String jobId, bool notComplete) async {
dbhandler
.child('Jobs')
.orderByChild('job_id')
.equalTo(jobId)
.onValue
.take(1)
.listen((event) async {
if (event.snapshot.value != null) {
Map<dynamic, dynamic>? data =
event.snapshot.value as Map<dynamic, dynamic>?;
if (data != null) {
// Assuming there is only one entry, you can access it directly
var jobKey = data.keys.first;
dbhandler.child('Jobs').child(jobKey).remove();
}
}
});
dbhandler
.child('Assigned Jobs')
.orderByChild('job_id')
.equalTo(jobId)
.onValue
.take(1)
.listen((event) async {
if (event.snapshot.value != null) {
Map<dynamic, dynamic>? data =
event.snapshot.value as Map<dynamic, dynamic>?;
if (data != null) {
// Assuming there is only one entry, you can access it directly
var assignedJobKey = data.keys.first;
var assignedData = data[assignedJobKey];

bool company = assignedData['company_job_complete'];
bool worker = assignedData['company_job_complete'];

if (company && worker) {
dbhandler
.child("Risk Support Plans")
.orderByChild('job_id')
.equalTo(jobId)
.onValue
.take(1)
.listen((event) async {
if (event.snapshot.value != null) {
Map<dynamic, dynamic>? data =
event.snapshot.value as Map<dynamic, dynamic>?;
if (data != null) {
var riskSupportKey = data.keys.first;

dbhandler
.child('Risk Support Plans')
.child(riskSupportKey)
.remove();
}
}
});
}

dbhandler.child('Assigned Jobs').child(assignedJobKey).remove();
}
}
});
if (notComplete) {
dbhandler
.child("Risk Support Plans")
.orderByChild('job_id')
.equalTo(jobId)
.onValue
.take(1)
.listen((event) async {
if (event.snapshot.value != null) {
Map<dynamic, dynamic>? data =
event.snapshot.value as Map<dynamic, dynamic>?;
if (data != null) {
var riskSupportKey = data.keys.first;

dbhandler
.child('Risk Support Plans')
.child(riskSupportKey)
.remove();
}
}
});
}
}

Future<void> confirmJob(String jobId) async {
dbhandler
.child('Assigned Jobs')
Expand Down Expand Up @@ -251,6 +338,7 @@ class CompanyJobState extends State<CompanyJob> {
onPressed: () {
setState(() {
confirmJob(jobId);
deleteJobDb(jobId, false);
});
Navigator.of(context).pop();
},
Expand Down Expand Up @@ -453,11 +541,54 @@ class CompanyJobState extends State<CompanyJob> {
} else if (riskSupport == false && assigned == true) {
addRiskSupportPlans(context, jobId);
// TO DO: risk support update true
} else if ((today.isAtSameMomentAs(date) &&
(stringTimeToMins(endTime) > ((8 * 60) + stringTimeToMins(now)))) ||
date.isAfter(today)) {
deleteJob(context, jobId);
} else {
// TO DO: error message say waiting for worker to accept
// TO DO: error message
}
}

void deleteJob(BuildContext context, String jobId) async {
showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("Delete Job"),
contentPadding: EdgeInsets.zero,
content: const Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
height: 5,
),
DisplayText(
text: "Are You Sure You Want To Delete This Job?",
fontSize: 20,
colour: Colors.black),
],
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Back'),
),
TextButton(
onPressed: () async {
await deleteJobDb(jobId, true);
Navigator.of(context).pop();
},
child: const Text('Delete'),
),
],
);
},
);
}

Future<void> profileViewer(BuildContext context, String userId) async {
dbhandler
.child('Profiles')
Expand Down Expand Up @@ -486,7 +617,9 @@ class CompanyJobState extends State<CompanyJob> {
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 5,),
const SizedBox(
height: 5,
),
ProfileView(
name: name,
imgPath: imgPath,
Expand Down

0 comments on commit a9ccb03

Please sign in to comment.