1
0
Эх сурвалжийг харах

Fix default billing entity not taking effect if creating a sales order directly

Alan Lam 2 жил өмнө
parent
commit
3080f0e24c
1 өөрчлөгдсөн 20 нэмэгдсэн , 5 устгасан
  1. 20 5
      controllers/document.php

+ 20 - 5
controllers/document.php

@@ -137,12 +137,27 @@ $controller = new class($document_type, $document_number) {
 
 		if($location) {
 			$customer = $location->getCustomer();
-			$address = $location->getAddress();
-			$lines = array_merge([$location->name], $address->getLines());
-			$address_string = implode("\n", $lines);
 
-			$document->billing_address = $address_string;
-			$document->delivery_address = $address_string;
+			$delivery_address = $location->getAddress();
+
+			$billing_entity = $location->getBillingEntity();
+			if($billing_entity) {
+				$billing_name = $billing_entity->name;
+				$billing_address = $billing_entity->getAddress();
+			}
+			else {
+				$billing_name = $customer->name;
+				$billing_address = $customer->getAddress();
+			}
+
+			$billing_lines = array_merge([$billing_name], $billing_address->getLines());
+			$billing_address_string = implode("\n", $billing_lines);
+
+			$delivery_lines = array_merge([$location->name], $delivery_address->getLines());
+			$delivery_address_string = implode("\n", $delivery_lines);
+
+			$document->billing_address = $billing_address_string;
+			$document->delivery_address = $delivery_address_string;
 			$document->vat_number = $customer->vat_number;
 		}