소스 검색

Prepend location name to address when creating a document

Alan Lam 3 년 전
부모
커밋
2ecb0b50e2
2개의 변경된 파일과 18개의 추가작업 그리고 13개의 파일을 삭제
  1. 5 2
      controllers/document.php
  2. 13 11
      engine/Address.php

+ 5 - 2
controllers/document.php

@@ -170,8 +170,11 @@ $controller = new class($document_type, $document_number) {
 
 		if($location) {
 			$address = $location->getAddress();
-			$document->billing_address = (string) $address;
-			$document->delivery_address = (string) $address;
+			$lines = array_merge([$location->name], $address->getLines());
+			$address_string = implode("\n", $lines);
+
+			$document->billing_address = $address_string;
+			$document->delivery_address = $address_string;
 		}
 
 		$document->type = $type;

+ 13 - 11
engine/Address.php

@@ -47,17 +47,7 @@ class Address extends Model {
 
 	// Magic methods
 	public function __toString(): string {
-		$county_parts = array_filter([$this->county, $this->state, $this->postal_code]);
-
-		$lines = array_filter([
-			$this->address_1,
-			$this->address_2,
-			$this->city,
-			implode(", ", $county_parts),
-			$this->getDisplayCountry()
-		]);
-
-		return implode("\n", $lines);
+		return implode("\n", $this->getLines());
 	}
 
 	// Object methods
@@ -88,4 +78,16 @@ class Address extends Model {
 		return "";
 	}
 
+	public function getLines(): array {
+		$county_parts = array_filter([$this->county, $this->state, $this->postal_code]);
+
+		return array_filter([
+			$this->address_1,
+			$this->address_2,
+			$this->city,
+			implode(", ", $county_parts),
+			$this->getDisplayCountry()
+		]);
+	}
+
 }