فهرست منبع

Add "Declined" custom filter to test list

Alan Lam 3 سال پیش
والد
کامیت
ca546405da

+ 9 - 1
controllers/account.php

@@ -92,6 +92,7 @@ Core::addBreadcrumb("/account", $page_title);
 
 
 $users_pending_verification = 0;
 $users_pending_verification = 0;
 $tests_pending_verification = 0;
 $tests_pending_verification = 0;
+$rejected_test_count = 0;
 $tests_remaining = 0;
 $tests_remaining = 0;
 
 
 $icons = [];
 $icons = [];
@@ -114,6 +115,7 @@ if($user->canAccessUsers()) {
 
 
 	$users_pending_verification = count($users);
 	$users_pending_verification = count($users);
 	$tests_pending_verification = count($tests);
 	$tests_pending_verification = count($tests);
+	$rejected_test_count = Test::count(["status" => Test::STATUS_UNASSIGNED, "dts_rejected" => Constraint::isNotNull()]);
 
 
 	$icons[] = new AccountIcon(($user->isSuperAdmin() ? __("Users") : __("Testers")), "/account/users", "users");
 	$icons[] = new AccountIcon(($user->isSuperAdmin() ? __("Users") : __("Testers")), "/account/users", "users");
 }
 }
@@ -197,7 +199,7 @@ if(!$user->terms_accepted) {
 
 
 $icons[] = new AccountIcon(__("Settings"), "/account/settings", "cog");
 $icons[] = new AccountIcon(__("Settings"), "/account/settings", "cog");
 
 
-usort($icons, function($a, $b) {
+usort($icons, static function($a, $b) {
 	return $a->name <=> $b->name;
 	return $a->name <=> $b->name;
 });
 });
 
 
@@ -228,6 +230,12 @@ if($tests_pending_verification) {
 	$to_do[] = $icon;
 	$to_do[] = $icon;
 }
 }
 
 
+if($rejected_test_count) {
+	$icon = new AccountIcon(__("Declined Tests"), "/account/tests?status=" . Test::STATUS_UNASSIGNED . "&custom=declined&sort=end", "times");
+	$icon->setCounter($rejected_test_count);
+	$to_do[] = $icon;
+}
+
 $referrals = $user->getReferrals();
 $referrals = $user->getReferrals();
 
 
 View::includeOnce("header", compact("page_title"));
 View::includeOnce("header", compact("page_title"));

+ 1 - 0
controllers/project_ajax.php

@@ -328,6 +328,7 @@ if($submit) {
 				$test->status = Test::STATUS_ASSIGNED;
 				$test->status = Test::STATUS_ASSIGNED;
 				$test->tester_id = $user->id;
 				$test->tester_id = $user->id;
 				$test->dts_assigned = Util::getDateTime();
 				$test->dts_assigned = Util::getDateTime();
+				$test->dts_rejected = null;
 				$test->dts_updated = Util::getDateTime();
 				$test->dts_updated = Util::getDateTime();
 
 
 				if($unix_due) {
 				if($unix_due) {

+ 6 - 0
controllers/tests_admin_list.php

@@ -158,6 +158,12 @@ $tests = Test::query($nvp, $query_options);
 $projects = Project::load(array_column($tests, "project_id"));
 $projects = Project::load(array_column($tests, "project_id"));
 
 
 switch($custom) {
 switch($custom) {
+	case "declined":
+		$tests = array_filter($tests, static function(Test $test): bool {
+			return (bool) $test->dts_rejected;
+		});
+		break;
+
 	case "overdue_project":
 	case "overdue_project":
 		$tests = array_filter($tests, static function(Test $test) use ($min_days_overdue) {
 		$tests = array_filter($tests, static function(Test $test) use ($min_days_overdue) {
 			if($test->isCancelled()) {
 			if($test->isCancelled()) {

+ 2 - 1
controllers/tests_available_ajax.php

@@ -35,6 +35,7 @@ switch($action) {
 			$test->status = Test::STATUS_CONFIRMED;
 			$test->status = Test::STATUS_CONFIRMED;
 			$test->tester_id = $user->id;
 			$test->tester_id = $user->id;
 			$test->dts_assigned = Util::getDateTime();
 			$test->dts_assigned = Util::getDateTime();
+			$test->dts_rejected = null;
 			$test->dts_updated = Util::getDateTime();
 			$test->dts_updated = Util::getDateTime();
 
 
 			if($unix_due) {
 			if($unix_due) {
@@ -84,4 +85,4 @@ switch($action) {
 
 
 JSON::success($response);
 JSON::success($response);
 
 
-?>
+?>

+ 11 - 0
db/migrations/20230508100430_add_dts_rejected_field_to_test_table.php

@@ -0,0 +1,11 @@
+<?php
+
+use Phinx\Migration\AbstractMigration;
+
+class AddDtsRejectedFieldToTestTable extends AbstractMigration {
+	public function change() {
+		$this->table("test")
+			->addColumn("dts_rejected", "datetime", ["null" => true, "after" => "dts_assigned"])
+			->update();
+	}
+}

+ 25 - 0
db/migrations/20230508103736_populate_test_dts_rejected_field.php

@@ -0,0 +1,25 @@
+<?php
+
+use Carbon\CarbonImmutable;
+use Phinx\Migration\AbstractMigration;
+
+class PopulateTestDtsRejectedField extends AbstractMigration {
+	public function up() {
+		$rejects = $this->fetchAll("SELECT `location_id`, MAX(`dts_last_rejected`) AS `dts_last_rejected` FROM `user_location_reject` GROUP BY `location_id`");
+		foreach($rejects as $reject) {
+			$location_id = $reject["location_id"];
+			$dts_rejected = $reject["dts_last_rejected"];
+			$dts_threshold = (string) CarbonImmutable::parse($dts_rejected, "UTC")->subDays(30);
+
+			$tests = $this->fetchAll("SELECT `id` FROM `test` WHERE `location_id`='$location_id' AND `status`='1' AND `dts_created` > '$dts_threshold'");
+			foreach($tests as $test) {
+				$test_id = $test["id"];
+				$this->execute("UPDATE `test` SET `dts_rejected`='$dts_rejected' WHERE `id`='$test_id'");
+			}
+		}
+	}
+
+	public function down() {
+		$this->execute("UPDATE `test` SET `dts_rejected`=NULL WHERE 1");
+	}
+}

+ 26 - 1
engine/test.php

@@ -40,6 +40,7 @@ use Mpdf\Mpdf;
  * @property string $dts_created
  * @property string $dts_created
  * @property string $dts_updated
  * @property string $dts_updated
  * @property string $dts_assigned
  * @property string $dts_assigned
+ * @property string $dts_rejected
  * @property string $dts_verified
  * @property string $dts_verified
  */
  */
 
 
@@ -47,7 +48,20 @@ class Test extends Model {
 
 
 	protected static $table = "test";
 	protected static $table = "test";
 	protected static $id_field = "id";
 	protected static $id_field = "id";
-	protected static $fillable_fields = ["project_id", "location_id", "tester_id", "status", "status_tester_invoice", "customer_fee", "test_fee", "test_time", "test_travel_cost", "test_travel_cost_description", "shop_left", "shop_right", "attire", "challenge_stage", "challenge_description", "challenger_name", "challenger_description", "challenger_gender", "challenger_eye_contact", "additional_notes", "dts_due", "dts_start", "dts_end", "dts_tester_invoice_generated", "dts_tester_invoice_paid", "verifier_id", "verifier_notes", "pass", "retest", "void", "void_notes", "dts_created", "dts_updated", "dts_assigned", "dts_verified"];
+	protected static $fillable_fields = [
+		"project_id", "location_id", "tester_id",
+		"status", "status_tester_invoice",
+		"customer_fee", "test_fee", "test_time", "test_travel_cost", "test_travel_cost_description",
+		"shop_left", "shop_right", "attire",
+		"challenge_stage",
+		"challenge_description", "challenger_name", "challenger_description", "challenger_gender", "challenger_eye_contact",
+		"additional_notes",
+		"dts_due", "dts_start", "dts_end", "dts_tester_invoice_generated", "dts_tester_invoice_paid",
+		"verifier_id", "verifier_notes",
+		"pass", "retest", "void", "void_notes",
+		"dts_created", "dts_updated",
+		"dts_assigned", "dts_rejected", "dts_verified"
+	];
 
 
 	public const TEST_FIELDS = ["shop_left", "shop_right", "attire", "challenge_stage", "challenge_description", "challenger_name", "challenger_description", "challenger_gender", "challenger_eye_contact", "additional_notes"];
 	public const TEST_FIELDS = ["shop_left", "shop_right", "attire", "challenge_stage", "challenge_description", "challenger_name", "challenger_description", "challenger_gender", "challenger_eye_contact", "additional_notes"];
 
 
@@ -416,6 +430,7 @@ class Test extends Model {
 		$this->tester_id = null;
 		$this->tester_id = null;
 		$this->dts_due = null;
 		$this->dts_due = null;
 		$this->dts_assigned = null;
 		$this->dts_assigned = null;
+		$this->dts_rejected = Util::getDateTime();
 		$this->dts_updated = Util::getDateTime();
 		$this->dts_updated = Util::getDateTime();
 		$this->commit();
 		$this->commit();
 
 
@@ -596,6 +611,7 @@ class Test extends Model {
 	public function assignTester(User $tester): bool {
 	public function assignTester(User $tester): bool {
 		$this->tester_id = $tester->id;
 		$this->tester_id = $tester->id;
 		$this->dts_assigned = Util::getDateTime();
 		$this->dts_assigned = Util::getDateTime();
+		$this->dts_rejected = null;
 		// TODO: Notify tester
 		// TODO: Notify tester
 
 
 		return $this->commit();
 		return $this->commit();
@@ -631,6 +647,7 @@ class Test extends Model {
 		$this->tester_id = null;
 		$this->tester_id = null;
 		$this->dts_due = null;
 		$this->dts_due = null;
 		$this->dts_assigned = null;
 		$this->dts_assigned = null;
+		$this->dts_rejected = null;
 		return $this->commit();
 		return $this->commit();
 	}
 	}
 
 
@@ -886,4 +903,12 @@ class Test extends Model {
 		return $this->getProject()->getTemplate()->getTesterInvoiceCosts($this->getValues(true));
 		return $this->getProject()->getTemplate()->getTesterInvoiceCosts($this->getValues(true));
 	}
 	}
 
 
+	public function getDateTimeRejected(): ?CarbonImmutable {
+		if(!$this->dts_rejected) {
+			return null;
+		}
+
+		return CarbonImmutable::parse($this->dts_rejected, "UTC");
+	}
+
 }
 }

+ 1 - 0
views/test_list.php

@@ -35,6 +35,7 @@ $result_options = [
 $custom_filters = [
 $custom_filters = [
 	"overdue_project" => "Overdue (Project Deadline)",
 	"overdue_project" => "Overdue (Project Deadline)",
 	"overdue_test" => "Overdue (Test Due Date)",
 	"overdue_test" => "Overdue (Test Due Date)",
+	"declined" => "Declined",
 ];
 ];
 
 
 $customer_options = [];
 $customer_options = [];