unassignTester(); $actioned_count += $success; } Core::addAlert("success", "$actioned_count of $test_count test(s) unassigned successfully."); break; case "mark_tester_invoice_paid": foreach($tests as $test) { $actioned_count += ($test->markTesterInvoicePaid()) ? 1 : 0; } Core::addAlert("success", "{$actioned_count} of {$test_count} test(s) marked as paid successfully."); break; case "reject_tester_invoice": foreach($tests as $test) { $actioned_count += ($test->rejectTesterInvoice()) ? 1 : 0; } Core::addAlert("success", "{$actioned_count} of {$test_count} invoices rejected successfully."); break; case "send_test_assigned_email": foreach($tests as $test) { $tester = $test->getTester(); if($tester) { $test->sendAssignEmail(""); $actioned_count++; } } Core::addAlert("success", "{$actioned_count} of {$test_count} emails sent successfully."); break; default: throw new RuntimeException("Invalid action."); } HTTP::redirect($_SERVER["REQUEST_URI"]); } catch(Exception $e) { Core::addAlert("danger", $e->getMessage()); } } // Batch Action End $status = http::value("status", "int"); $status_tester_invoice = http::value("status_tester_invoice"); $customer_id = http::value("customer_id", "int"); $project_id = http::value("project_id", "int"); $location_id = http::value("location_id", "int"); $location_name = http::value("location_name", "trim"); $test_id = http::value("test_id", "int"); $tester_id = http::value("tester_id", "int"); $location_internal_id = http::value("location_internal_id", "int"); $pass = http::value("pass", "int"); $retest = http::value("retest", "int"); $void = http::value("void", "int"); $min_days_overdue = http::value("min_days_overdue", "int"); $custom = http::value("custom"); $filter_count_offset = 0; $nvp = []; // Status if(strlen($status) > 0) $nvp["status"] = $status; else { $nvp["status"] = Constraint::notEquals(Test::STATUS_CANCELLED); $filter_count_offset--; } // Status Tester Invoice if(strlen($status_tester_invoice)) { $status_tester_invoice = (int) $status_tester_invoice; $nvp["status_tester_invoice"] = $status_tester_invoice; } // Project if($project_id) $nvp["project_id"] = $project_id; else if($customer_id) { $projects = Project::query(["customer_id" => $customer_id]); $nvp["project_id"] = array_column($projects, "id"); } // Location if($location_id) { $nvp["location_id"] = $location_id; } else if($location_internal_id) { $locations = Location::query(["internal_id" => $location_internal_id]); $nvp["location_id"] = $locations ? array_column($locations, "id") : "0"; } else if($location_name) { $locations = Location::query([ "name" => Constraint::like("%" . DB::escape($location_name) . "%") ]); $nvp["location_id"] = $locations ? array_column($locations, "id") : "0"; } // Test ID if($test_id) $nvp["id"] = $test_id; // Tester ID if($tester_id) $nvp["tester_id"] = $tester_id; // Pass if(strlen($pass) > 0) $nvp["pass"] = $pass; if(isset($retest)) { if($retest === 0) { $nvp["retest"] = 0; } if($retest === 1) { $nvp["retest"] = 1; } } // Void if(isset($void)) { $nvp["void"] = (int) $void; } $filter_count = count($nvp); $sort = http::value("sort"); switch($sort) { case "updated": $query_options = ["sort" => "dts_updated", "order" => "desc"]; break; case "due": $query_options = ["sort" => "dts_due", "order" => "asc"]; break; case "end": $query_options = ["sort" => "dts_end", "order" => "desc"]; break; default: $sort = "status"; $query_options = ["sort" => "status", "order" => "asc"]; break; } $tests = Test::query($nvp, $query_options); $projects = Project::load(array_column($tests, "project_id")); switch($custom) { case "declined": $tests = array_filter($tests, static function(Test $test): bool { return (bool) $test->dts_rejected; }); break; case "overdue_project": $tests = array_filter($tests, static function(Test $test) use ($min_days_overdue) { if($test->isCancelled()) { return false; } if($test->isCompleted()) { return false; } $project = $test->getProject(); $dt_deadline = $project->getDateTimeDeadline(); if(!$dt_deadline) { return false; } if(!$project->isOverdue()) { return false; } $days_overdue = $dt_deadline->diffInDays(null, true); if($min_days_overdue > 0 && $days_overdue > $min_days_overdue) { return false; } return true; }); $filter_count++; break; case "overdue_test": $tests = array_filter($tests, static function(Test $test) use ($min_days_overdue) { if($test->isCancelled()) { return false; } if($test->hasDueDateTime() === false) { return false; } $dt_due = $test->getDateTimeDue(); if(!$dt_due) { return false; } if(!($test->hasNotStarted() && $test->isOverdue())) { return false; } $days_overdue = $dt_due->diffInDays(null, true); if($min_days_overdue > 0 && $days_overdue < $min_days_overdue) { return false; } return true; }); $filter_count++; break; case "payment_required_paid": $tests = array_filter($tests, static function(Test $test): bool { if(!$test->payment_required) { return false; } if($test->payment_required && $test->dts_paid) { return true; } return false; }); $filter_count++; break; case "payment_required_unpaid": $tests = array_filter($tests, static function(Test $test): bool { if($test->payment_required && !$test->dts_paid) { return true; } return false; }); $filter_count++; break; } $filter_count += $filter_count_offset; if(!$filter_count) $filter_count = ""; $pagination_object = Util::getPaginationObject(count($tests)); $tests = array_slice($tests, $pagination_object->offset, $pagination_object->pageSize); $testers = User::load(array_column($tests, "tester_id")); $customers = Customer::query([], ["sort" => "name"]); usort($projects, static function(Project $a, Project $b): int { return $a->name <=> $b->name; }); $sorts = [ "status" => "Status", "updated" => "Recently updated", "end" => "Test date", "due" => "Test due date", ]; Core::addScript("public/js/app-test-list.js"); View::includeOnce("header", compact("page_title")); View::include("test_list", compact("tests", "pagination_object", "sort", "sorts", "projects", "customers", "customer_id", "project_id", "location_id", "location_internal_id", "location_name", "pass", "retest", "void", "min_days_overdue", "custom", "test_id", "tester_id", "filter_count", "status", "status_tester_invoice"));