From ad07599e92ee451f736629c3dff5ea3056327872 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 5 Dec 2016 00:35:08 +0200 Subject: [PATCH] Hide draft invoices from the client portal --- app/Models/Invitation.php | 7 ++++++- app/Models/Invoice.php | 19 ++++++++++++++++++- app/Services/InvoiceService.php | 3 +-- resources/views/invoices/edit.blade.php | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/Models/Invitation.php b/app/Models/Invitation.php index 7e362b7ad14f..370c521b7830 100644 --- a/app/Models/Invitation.php +++ b/app/Models/Invitation.php @@ -98,7 +98,7 @@ class Invitation extends EntityModel $date = Utils::dateToString($this->$field); $hasValue = true; $parts[] = trans('texts.invitation_status_' . $status) . ': ' . $date; - } + } } return $hasValue ? implode($parts, '
') : false; @@ -123,6 +123,11 @@ class Invitation extends EntityModel $this->save(); } + public function isSent() + { + return $this->sent_date && $this->sent_date != '0000-00-00 00:00:00'; + } + public function markViewed() { $invoice = $this->invoice; diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 98e7cb6f44b8..76b21947b29a 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -415,13 +415,30 @@ class Invoice extends EntityModel implements BalanceAffecting */ public function markInvitationsSent($notify = false) { - $this->load('invitations'); + if ( ! $this->relationLoaded('invitations')) { + $this->load('invitations'); + } foreach ($this->invitations as $invitation) { $this->markInvitationSent($invitation, false, $notify); } } + public function areInvitationsSent() + { + if ( ! $this->relationLoaded('invitations')) { + $this->load('invitations'); + } + + foreach ($this->invitations as $invitation) { + if ( ! $invitation->isSent()) { + return false; + } + } + + return true; + } + /** * @param $invitation * @param bool $messageId diff --git a/app/Services/InvoiceService.php b/app/Services/InvoiceService.php index 44d16160f952..ff0ec559f5d9 100644 --- a/app/Services/InvoiceService.php +++ b/app/Services/InvoiceService.php @@ -79,7 +79,6 @@ class InvoiceService extends BaseService } } - $wasPublic = $invoice ? $invoice->is_public : false; $invoice = $this->invoiceRepo->save($data, $invoice); $client = $invoice->client; @@ -111,7 +110,7 @@ class InvoiceService extends BaseService } } - if ($invoice->is_public && ! $wasPublic) { + if ($invoice->is_public && ! $invoice->areInvitationsSent()) { $invoice->markInvitationsSent(); } diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 53271337b050..7b7e6b47eb7f 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -1274,6 +1274,7 @@ } sweetConfirm(function() { + model.invoice().is_public(true); var accountLanguageId = parseInt({{ $account->language_id ?: '0' }}); var clientLanguageId = parseInt(model.invoice().client().language_id()) || 0; var attachPDF = {{ $account->attachPDF() ? 'true' : 'false' }};