From d4c31e3bbeced6765be88e57321251a5c56de157 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 25 May 2014 19:23:07 +0300 Subject: [PATCH] Bug fixes --- app/controllers/InvoiceController.php | 15 +++++++++++++-- app/controllers/PaymentController.php | 3 --- app/models/Activity.php | 1 + app/models/Invoice.php | 5 +++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index 1797102a04..265f7cd5b9 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -85,8 +85,7 @@ class InvoiceController extends \BaseController { public function view($invitationKey) { - $invitation = Invitation::withTrashed()->with('user', 'invoice.invoice_items', 'invoice.account.country', 'invoice.client.contacts', 'invoice.client.country') - ->where('invitation_key', '=', $invitationKey)->firstOrFail(); + $invitation = Invitation::withTrashed()->where('invitation_key', '=', $invitationKey)->firstOrFail(); $invoice = $invitation->invoice; @@ -95,6 +94,18 @@ class InvoiceController extends \BaseController { return View::make('invoices.deleted'); } + if ($invoice->is_quote && $invoice->quote_invoice_id) + { + $invoice = Invoice::scope($invoice->quote_invoice_id, $invoice->account_id)->firstOrFail(); + + if (!$invoice || $invoice->is_deleted) + { + return View::make('invoices.deleted'); + } + } + + $invoice->load('user', 'invoice_items', 'account.country', 'client.contacts', 'client.country'); + $client = $invoice->client; if (!$client || $client->is_deleted) diff --git a/app/controllers/PaymentController.php b/app/controllers/PaymentController.php index 749781149b..b520599ac7 100755 --- a/app/controllers/PaymentController.php +++ b/app/controllers/PaymentController.php @@ -431,9 +431,6 @@ class PaymentController extends \BaseController $payment->save(); - $invoice->invoice_status_id = INVOICE_STATUS_PAID; - $invoice->save(); - Event::fire('invoice.paid', $payment); return $payment; diff --git a/app/models/Activity.php b/app/models/Activity.php index 69572401a9..8724b3eab1 100755 --- a/app/models/Activity.php +++ b/app/models/Activity.php @@ -289,6 +289,7 @@ class Activity extends Eloquent $invoice = $payment->invoice; $invoice->balance = $invoice->balance - $payment->amount; + $invoice->invoice_status_id = ($invoice->balance > 0) ? INVOICE_STATUS_PARTIAL : INVOICE_STATUS_PAID; $invoice->save(); } diff --git a/app/models/Invoice.php b/app/models/Invoice.php index 063253cbd5..29ac65b3a2 100755 --- a/app/models/Invoice.php +++ b/app/models/Invoice.php @@ -7,6 +7,11 @@ class Invoice extends EntityModel return $this->belongsTo('Account'); } + public function user() + { + return $this->belongsTo('User'); + } + public function client() { return $this->belongsTo('Client')->withTrashed();