diff --git a/app/Http/Controllers/ClientPortalController.php b/app/Http/Controllers/ClientPortalController.php index 3bfd6e01e1..9e8b1d3129 100644 --- a/app/Http/Controllers/ClientPortalController.php +++ b/app/Http/Controllers/ClientPortalController.php @@ -67,21 +67,17 @@ class ClientPortalController extends BaseController $account = $invitation->account; $proposal = $invitation->proposal; + $invitation = Invitation::whereContactId($invitation->contact_id) + ->whereInvoiceId($proposal->invoice_id) + ->firstOrFail(); $data = [ 'proposalInvitation' => $invitation, 'proposal' => $proposal, 'account' => $account, + 'invitation' => $invitation, ]; - if (request()->raw) { - return view('invited.proposal_raw', $data); - } - - $data['invitation'] = Invitation::whereContactId($invitation->contact_id) - ->whereInvoiceId($proposal->invoice_id) - ->firstOrFail(); - return view('invited.proposal', $data); } diff --git a/app/Http/Controllers/ProposalController.php b/app/Http/Controllers/ProposalController.php index 8c29c9da05..96dd3861ca 100644 --- a/app/Http/Controllers/ProposalController.php +++ b/app/Http/Controllers/ProposalController.php @@ -60,7 +60,7 @@ class ProposalController extends BaseController 'method' => 'POST', 'url' => 'proposals', 'title' => trans('texts.new_proposal'), - 'invoices' => Invoice::scope()->with('client.contacts')->quotes()->orderBy('id')->get(), + 'invoices' => Invoice::scope()->with('client.contacts')->unapprovedQuotes()->orderBy('id')->get(), 'templates' => ProposalTemplate::whereAccountId($account->id)->orWhereNull('account_id')->orderBy('name')->get(), 'invoicePublicId' => $request->invoicee_id, ]; @@ -86,7 +86,7 @@ class ProposalController extends BaseController 'method' => 'PUT', 'url' => 'proposals/' . $proposal->public_id, 'title' => trans('texts.edit_proposal'), - 'invoices' => Invoice::scope()->with('client.contacts')->quotes()->orderBy('id')->get(), + 'invoices' => Invoice::scope()->with('client.contacts')->unapprovedQuotes($proposal->invoice_id)->orderBy('id')->get(), 'templates' => ProposalTemplate::whereAccountId($account->id)->orWhereNull('account_id')->orderBy('name')->get(), 'invoicePublicId' => $proposal->invoice ? $proposal->invoice->public_id : null, 'templatePublicId' => $proposal->proposal_template ? $proposal->proposal_template->public_id : null, diff --git a/app/Jobs/PurgeAccountData.php b/app/Jobs/PurgeAccountData.php index 6f4e2d32b5..01e5f89a33 100644 --- a/app/Jobs/PurgeAccountData.php +++ b/app/Jobs/PurgeAccountData.php @@ -54,6 +54,7 @@ class PurgeAccountData extends Job 'proposal_templates', 'proposal_snippets', 'proposal_categories', + 'proposal_invitations', ]; foreach ($tables as $table) { diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 7856c8cc92..ef75dc8b6e 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -451,6 +451,23 @@ class Invoice extends EntityModel implements BalanceAffecting ->where('is_recurring', '=', false); } + /** + * @param $query + * + * @return mixed + */ + public function scopeUnapprovedQuotes($query, $includeInvoiceId = false) + { + return $query->quotes() + ->where(function ($query) use ($includeInvoiceId) { + $query->whereId($includeInvoiceId) + ->orWhere(function ($query) { + $query->where('invoice_status_id', '<', INVOICE_STATUS_APPROVED) + ->whereNull('quote_invoice_id'); + }); + }); + } + /** * @param $query * @param $typeId @@ -846,7 +863,7 @@ class Invoice extends EntityModel implements BalanceAffecting */ public function isApproved() { - return $this->invoice_status_id >= INVOICE_STATUS_APPROVED; + return $this->invoice_status_id >= INVOICE_STATUS_APPROVED || $this->quote_invoice_id; } /** diff --git a/resources/views/invited/proposal.blade.php b/resources/views/invited/proposal.blade.php index 4bd3f1bc70..4d7dacbc3f 100644 --- a/resources/views/invited/proposal.blade.php +++ b/resources/views/invited/proposal.blade.php @@ -9,22 +9,13 @@ @endif