Add ‘View Invoice’ button in portal to approved quote

This commit is contained in:
Hillel Coren 2018-05-14 12:17:03 +03:00
parent a678044b4b
commit 96666a3af8
2 changed files with 23 additions and 0 deletions

View File

@ -1594,6 +1594,27 @@ class Invoice extends EntityModel implements BalanceAffecting
return $this->isSent() && ! $this->is_recurring; 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) { Invoice::creating(function ($invoice) {

View File

@ -164,6 +164,8 @@
{!! Button::normal(trans('texts.download'))->withAttributes(['onclick' => 'onDownloadClick()'])->large() !!}   {!! Button::normal(trans('texts.download'))->withAttributes(['onclick' => 'onDownloadClick()'])->large() !!}  
@if ($showApprove) @if ($showApprove)
{!! Button::success(trans('texts.approve'))->withAttributes(['id' => 'approveButton', 'onclick' => 'onApproveClick()'])->large() !!} {!! 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 @endif
@elseif ( ! $invoice->canBePaid()) @elseif ( ! $invoice->canBePaid())
{!! Button::normal(trans('texts.download'))->withAttributes(['onclick' => 'onDownloadClick()'])->large() !!} {!! Button::normal(trans('texts.download'))->withAttributes(['onclick' => 'onDownloadClick()'])->large() !!}