diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 8e596489e515..4ddcdebbee35 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -1594,6 +1594,27 @@ class Invoice extends EntityModel implements BalanceAffecting return $this->isSent() && ! $this->is_recurring; } + + public function getInvoiceLinkForQuote($contactId) + { + if (! $this->quote_invoice_id) { + return false; + } + + $invoice = static::scope($this->quote_invoice_id)->with('invitations')->first(); + + if (! $invoice) { + return false; + } + + foreach ($invoice->invitations as $invitation) { + if ($invitation->contact_id == $contactId) { + return $invitation->getLink(); + } + } + + return false; + } } Invoice::creating(function ($invoice) { diff --git a/resources/views/invoices/view.blade.php b/resources/views/invoices/view.blade.php index 3ac1001d71f3..67fc533ae7c9 100644 --- a/resources/views/invoices/view.blade.php +++ b/resources/views/invoices/view.blade.php @@ -164,6 +164,8 @@ {!! Button::normal(trans('texts.download'))->withAttributes(['onclick' => 'onDownloadClick()'])->large() !!}   @if ($showApprove) {!! Button::success(trans('texts.approve'))->withAttributes(['id' => 'approveButton', 'onclick' => 'onApproveClick()'])->large() !!} + @elseif ($invoiceLink = $invoice->getInvoiceLinkForQuote($contact->id)) + {!! Button::success(trans('texts.view_invoice'))->asLinkTo($invoiceLink)->large() !!} @endif @elseif ( ! $invoice->canBePaid()) {!! Button::normal(trans('texts.download'))->withAttributes(['onclick' => 'onDownloadClick()'])->large() !!}