Procházet zdrojové kódy

Prefix proforma PDF filenames with `pf-`

Alan Lam před 2 roky
rodič
revize
8ee1c73246
2 změnil soubory, kde provedl 9 přidání a 4 odebrání
  1. 1 1
      controllers/document.php
  2. 8 3
      engine/Document.php

+ 1 - 1
controllers/document.php

@@ -391,7 +391,7 @@ $controller = new class($document_type, $document_number) {
 		$output_path = $document->generatePdf($variant);
 
 		if(file_exists($output_path)) {
-			Http::downloadFile($output_path, $document->getPdfFilename(), "application/pdf");
+			Http::downloadFile($output_path, $document->getPdfFilename($variant), "application/pdf");
 		}
 		else {
 			header("Content-Type: text/plain");

+ 8 - 3
engine/Document.php

@@ -263,9 +263,14 @@ class Document extends Model {
 		return sha1($this->dts_created . $this->number);
 	}
 
-	public function getPdfFilename(): string {
-		$type_slug = Util::slug($this->getDisplayType());
-		return sprintf("%s-%d.pdf", $type_slug, $this->number);
+	public function getPdfFilename(?string $variant): string {
+		$prefix = Util::slug($this->getDisplayType());
+
+		if($this->isSalesOrder() && $variant !== "commercial") {
+			$prefix = "pf-" . $prefix;
+		}
+
+		return sprintf("%s-%d.pdf", $prefix, $this->number);
 	}
 
 	/**