Browse Source

Add "Value" column to leads table

Alan Lam 3 years ago
parent
commit
535c9f624a
3 changed files with 25 additions and 2 deletions
  1. 12 0
      engine/Sale.php
  2. 6 0
      engine/Util.php
  3. 7 2
      views/sales_table.php

+ 12 - 0
engine/Sale.php

@@ -156,4 +156,16 @@ class Sale extends Model {
 		]);
 	}
 
+	public function getAmount(): string {
+		$value = "0.00";
+		foreach($this->getItems() as $item) {
+			$value = bcadd($item->getAmount(), $value, 2);
+		}
+		return $value;
+	}
+
+	public function getDisplayAmount(): string {
+		return Util::getCurrencyFormatter()->formatCurrency($this->getAmount(), $this->getCurrency());
+	}
+
 }

+ 6 - 0
engine/Util.php

@@ -2,6 +2,8 @@
 
 namespace App;
 
+use NumberFormatter;
+
 class Util {
 
 	public static function slug(string $string, string $glue = "-"): string {
@@ -13,4 +15,8 @@ class Util {
 		return !mkdir($path, 0777, true) && !is_dir($path);
 	}
 
+	public static function getCurrencyFormatter(): NumberFormatter {
+		return new NumberFormatter("en_GB", NumberFormatter::CURRENCY);
+	}
+
 }

+ 7 - 2
views/sales_table.php

@@ -13,8 +13,9 @@ $user = $core->getUser();
 	<colgroup>
 		<col style="width: 1%"/>
 		<col style="width: 15%"/>
-		<col style="width: 40%"/>
-		<col style="width: 15%"/>
+		<col style="width: 35%"/>
+		<col style="width: 10%"/>
+		<col style="width: 10%"/>
 		<col style="width: 15%"/>
 		<col style="width: 15%"/>
 		<col style="width: 1%"/>
@@ -25,6 +26,7 @@ $user = $core->getUser();
 		<th><?=htmlspecialchars(__("Date"))?></th>
 		<th><?=htmlspecialchars(__("Location"))?></th>
 		<th><?=htmlspecialchars(__("Status"))?></th>
+		<th><?=htmlspecialchars(__("Value"))?></th>
 		<th><?=htmlspecialchars(__("Predicted Sold Date"))?></th>
 		<th><?=htmlspecialchars(__("Last Updated"))?></th>
 		<th><?=htmlspecialchars(__("Actions"))?></th>
@@ -50,6 +52,9 @@ $user = $core->getUser();
 			<td>
 				<?=htmlspecialchars($sale->getDisplayStatus())?>
 			</td>
+			<td class="text-end">
+				<?=htmlspecialchars($sale->getDisplayAmount())?>
+			</td>
 			<td>
 				<?=htmlspecialchars($sale->getDisplayPredictedSoldDate())?>
 			</td>