Kaynağa Gözat

Added alerts for when no invoice address or payment method is found. Auto-use only address on account as invoice address.

Alan Lam 8 yıl önce
ebeveyn
işleme
0d9f7733d5

+ 3 - 1
controllers/tests_completed.php

@@ -16,8 +16,10 @@ $tests = array_slice($tests, $pagination_object->offset, $pagination_object->pag
 
 $projects = Project::load(array_column($tests, "project_id"));
 
+$can_invoice = Core::$user->getInvoiceAddress() && Core::$user->hasValidPaymentMethod();
+
 View::includeOnce("header", compact("page_title"));
-View::include("test_list_completed", compact("tests", "pagination_object"));
+View::include("test_list_completed", compact("tests", "can_invoice", "pagination_object"));
 View::include("modal_test_invoice");
 View::includeOnce("footer");
 

+ 10 - 2
engine/user.php

@@ -323,10 +323,18 @@ class User extends Model {
 	}
 
 	public function getInvoiceAddress() {
-		return UserAddress::queryOne([
+		$addresses = UserAddress::query([
 			"user_id" => $this->id,
-			"invoice" => 1
 		]);
+
+		foreach($addresses as $address) {
+			if($address->invoice) return $address;
+		}
+
+		// If only one address in account, just return it
+		if(count($addresses) == 1) return array_shift($addresses);
+
+		return false;
 	}
 
 	public function getCustomers() {

+ 20 - 1
views/test_list_completed.php

@@ -19,6 +19,25 @@
 		?>
 		</div>
 
+		<?php
+		if(!Core::$user->getInvoiceAddress()) {
+			?>
+			<div class="alert alert-warning">
+				<i class="fal fa-fw fa-exclamation-triangle"></i>
+				You have multiple addresses. <a href="/account/addresses">Click here</a> to manage your addresses and set one as the invoice address to enable the invoice link.
+			</div>
+			<?php
+		}
+		if(!Core::$user->hasValidPaymentMethod()) {
+			?>
+			<div class="alert alert-warning">
+				<i class="fal fa-fw fa-exclamation-triangle"></i>
+				You have no valid payment method. <a href="/account/settings">Click here</a> and verify your payment method settings are correct to enable the invoice link.
+			</div>
+			<?php
+		}
+		?>
+
 		<div class="list-group">
 		<?php
 
@@ -76,7 +95,7 @@
 								<div class="col order-1 order-sm-1">
 									<strong>ID: <?=$test->id?></strong><br />
 									<?php
-									if($test->status == Test::STATUS_COMPLETED) {
+									if($test->status == Test::STATUS_COMPLETED && $can_invoice) {
 										?>
 										<a href="#" data-toggle="modal" data-target="#modal-test-invoice" data-invoice data-id="<?=$test->id?>">
 											<i class="fal fa-fw fa-external-link"></i> Invoice