Просмотр исходного кода

Add "Reject Tester Invoice" batch action

Alan Lam 6 лет назад
Родитель
Сommit
69ec76f3ce
4 измененных файлов с 50 добавлено и 8 удалено
  1. 2 2
      controllers/test_invoice.php
  2. 11 0
      controllers/tests_admin_list.php
  3. 17 6
      engine/test.php
  4. 20 0
      views/test_list.php

+ 2 - 2
controllers/test_invoice.php

@@ -67,7 +67,7 @@ $download_filename = str_replace("/", "_", $reference) . " - " . $tester->getDis
 
 // Check for existing PDF
 $directory = $test->getDirectory();
-$pdf_filepath = $directory . "/tester_invoice.pdf";
+$pdf_filepath = $test->getTesterInvoicePDFPath();
 if($test->hasTesterInvoicePDF()) {
 	http::setDownloadHeaders($download_filename);
 	header("Content-Type: application/pdf");
@@ -282,7 +282,7 @@ $test->commit();
 
 // Move photo to folder
 if($has_photo) {
-	$dst = $test->getDirectory() . "/travel_costs.jpg";
+	$dst = $test->getTravelCostsPhotoPath();
 	move_uploaded_file($photo->tmp_name, $dst);
 }
 

+ 11 - 0
controllers/tests_admin_list.php

@@ -37,6 +37,17 @@ if($submit) {
 				Core::addAlert("success", "{$actioned_count} of {$test_count} test(s) marked as paid successfully.");
 				break;
 
+			case "reject_tester_invoice":
+
+				$actioned_count = 0;
+
+				foreach($tests as $test) {
+					$actioned_count += ($test->rejectTesterInvoice()) ? 1 : 0;
+				}
+
+				Core::addAlert("success", "{$actioned_count} of {$test_count} invoices rejected successfully.");
+				break;
+
 			default:
 				throw new Exception("Invalid action.");
 		}

+ 17 - 6
engine/test.php

@@ -667,17 +667,23 @@ class Test extends Model {
 		return "/account/tests/{$this->id}/files/pdf";
 	}
 
+	public function getTesterInvoicePDFPath(): bool {
+		return sprintf("%s/tester_invoice.pdf", $this->getDirectory());
+	}
+
 	/**
 	 * @return bool
 	 */
 	public function hasTesterInvoicePDF(): bool {
-		$directory = $this->getDirectory();
-		return file_exists($directory . "/tester_invoice.pdf");
+		return file_exists($this->getTesterInvoicePDFPath());
+	}
+
+	public function getTravelCostsPhotoPath(): string {
+		return sprintf("%s/travel_costs.jpg", $this->getDirectory());
 	}
 
 	public function hasTravelCostsPhoto(): bool {
-		$path = sprintf("%s/travel_costs.jpg", $this->getDirectory());
-		return file_exists($path);
+		return file_exists($this->getTravelCostsPhotoPath());
 	}
 
 	/**
@@ -704,8 +710,13 @@ class Test extends Model {
 			$this->status_tester_invoice = Test::STATUS_TESTER_INVOICE_NONE;
 			$this->dts_tester_invoice_generated = null;
 
-			$pdf_filepath = $this->getDirectory() . "/tester_invoice.pdf";
-			unlink($pdf_filepath);
+			if($this->hasTesterInvoicePDF()) {
+				unlink($this->getTesterInvoicePDFPath());
+			}
+
+			if($this->hasTravelCostsPhoto()) {
+				unlink($this->getTravelCostsPhotoPath());
+			}
 
 			return $this->commit();
 		}

+ 20 - 0
views/test_list.php

@@ -1,4 +1,23 @@
 <?php /** @noinspection PhpUnhandledExceptionInspection */
+
+/**
+ * @var int $filter_count
+ * @var array $sorts
+ * @var string $sort
+ * @var int $status
+ * @var int $status_tester_invoice
+ * @var Customer[] $customers
+ * @var int $customer_id
+ * @var Project[] $projects
+ * @var int $project_id
+ * @var bool $pass
+ * @var int $test_id
+ * @var int $tester_id
+ * @var int $location_id
+ * @var int $location_internal_id
+ * @var int $custom
+ */
+
 $filters_collapse = $filter_count ? "collapse show" : "collapse";
 $query = $_GET;
 unset($query["path"]);
@@ -396,6 +415,7 @@ $custom_filters = [
 								<option value="">Select Action</option>
 								<option value="unassign">Unassign</option>
 								<option value="mark_tester_invoice_paid">Mark Tester Invoice as Paid</option>
+								<option value="reject_tester_invoice">Reject Tester Invoices</option>
 							</select>
 							<div class="input-group-append">
 								<button type="submit" class="btn btn-primary" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">