From 97a56fac13f8542d6a223c01502185eaa2475aaf Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 20 Jul 2016 10:05:19 +0300 Subject: [PATCH] Fix for approving quotes --- app/Events/QuoteInvitationWasApproved.php | 8 +------- app/Services/InvoiceService.php | 20 ++++++-------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/app/Events/QuoteInvitationWasApproved.php b/app/Events/QuoteInvitationWasApproved.php index e5532352e1..c7237b3120 100644 --- a/app/Events/QuoteInvitationWasApproved.php +++ b/app/Events/QuoteInvitationWasApproved.php @@ -11,11 +11,6 @@ class QuoteInvitationWasApproved extends Event public $quote; - /** - * @var Invoice - */ - public $invoice; - /** * @var Invitation */ @@ -28,10 +23,9 @@ class QuoteInvitationWasApproved extends Event * @param Invoice $invoice * @param Invitation $invitation */ - public function __construct($quote, Invoice $invoice, Invitation $invitation) + public function __construct(Invoice $quote, Invitation $invitation) { $this->quote = $quote; - $this->invoice = $invoice; $this->invitation = $invitation; } } diff --git a/app/Services/InvoiceService.php b/app/Services/InvoiceService.php index 7238d51553..0d6bb9822c 100644 --- a/app/Services/InvoiceService.php +++ b/app/Services/InvoiceService.php @@ -127,11 +127,11 @@ class InvoiceService extends BaseService { $account = $quote->account; - if (!$quote->isType(INVOICE_TYPE_QUOTE) || $quote->quote_invoice_id) { + if ( ! $account->hasFeature(FEATURE_QUOTES) || ! $quote->isType(INVOICE_TYPE_QUOTE) || $quote->quote_invoice_id) { return null; } - if ($account->auto_convert_quote || ! $account->hasFeature(FEATURE_QUOTES)) { + if ($account->auto_convert_quote) { $invoice = $this->convertQuote($quote); foreach ($invoice->invitations as $invoiceInvitation) { @@ -139,21 +139,13 @@ class InvoiceService extends BaseService $invitation = $invoiceInvitation; } } - - event(new QuoteInvitationWasApproved($quote, $invoice, $invitation)); - - return $invoice; } else { $quote->markApproved(); - - event(new QuoteInvitationWasApproved($quote, null, $invitation)); - - foreach ($quote->invitations as $invoiceInvitation) { - if ($invitation->contact_id == $invoiceInvitation->contact_id) { - return $invoiceInvitation->invitation_key; - } - } } + + event(new QuoteInvitationWasApproved($quote, $invitation)); + + return $invitation->invitation_key; } public function getDatatable($accountId, $clientPublicId = null, $entityType, $search)