diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index 0d3742e1a833..da4b361d1be8 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -64,7 +64,12 @@ class InvoiceController extends \BaseController { //$accountId = Auth::user()->account_id; $search = Input::get('sSearch'); $invitationKey = Session::get('invitation_key'); - $invitation = Invitation::where('invitation_key', '=', $invitationKey)->firstOrFail(); + $invitation = Invitation::where('invitation_key', '=', $invitationKey)->first(); + + if (!$invitation || $invitation->is_deleted) + { + return []; + } $invoice = $invitation->invoice; diff --git a/app/controllers/PaymentController.php b/app/controllers/PaymentController.php index c59aa61d79b6..21d16340f80b 100755 --- a/app/controllers/PaymentController.php +++ b/app/controllers/PaymentController.php @@ -77,7 +77,12 @@ class PaymentController extends \BaseController { $search = Input::get('sSearch'); $invitationKey = Session::get('invitation_key'); - $invitation = Invitation::where('invitation_key', '=', $invitationKey)->with('contact.client')->firstOrFail(); + $invitation = Invitation::where('invitation_key', '=', $invitationKey)->with('contact.client')->first(); + + if (!$invitation) + { + return []; + } $invoice = $invitation->invoice; @@ -86,10 +91,10 @@ class PaymentController extends \BaseController return []; } - $payments = $this->paymentRepo->find($invitation->contact->client->public_id, Input::get('sSearch')); + $payments = $this->paymentRepo->findForContact($invitation->contact->id, Input::get('sSearch')); return Datatable::query($payments) - ->addColumn('invoice_number', function($model) { return $model->invoice_number; }) + ->addColumn('invoice_number', function($model) { return $model->invitation_key ? link_to('/view/' . $model->invitation_key, $model->invoice_number) : $model->invoice_number; }) ->addColumn('transaction_reference', function($model) { return $model->transaction_reference ? $model->transaction_reference : 'Manual entry'; }) ->addColumn('payment_type', function($model) { return $model->payment_type ? $model->payment_type : ($model->account_gateway_id ? 'Online payment' : ''); }) ->addColumn('amount', function($model) { return Utils::formatMoney($model->amount, $model->currency_id); }) diff --git a/app/controllers/QuoteController.php b/app/controllers/QuoteController.php index 66e8d1f1830e..e7634429db17 100644 --- a/app/controllers/QuoteController.php +++ b/app/controllers/QuoteController.php @@ -72,7 +72,12 @@ class QuoteController extends \BaseController { { $search = Input::get('sSearch'); $invitationKey = Session::get('invitation_key'); - $invitation = Invitation::where('invitation_key', '=', $invitationKey)->firstOrFail(); + $invitation = Invitation::where('invitation_key', '=', $invitationKey)->first(); + + if (!$invitation || $invitation->is_deleted) + { + return []; + } $invoice = $invitation->invoice; diff --git a/app/ninja/repositories/PaymentRepository.php b/app/ninja/repositories/PaymentRepository.php index 31126b13c868..39563106ade8 100755 --- a/app/ninja/repositories/PaymentRepository.php +++ b/app/ninja/repositories/PaymentRepository.php @@ -8,8 +8,8 @@ use Utils; class PaymentRepository { - public function find($clientPublicId = null, $filter = null) - { + public function find($clientPublicId = null, $filter = null) + { $query = \DB::table('payments') ->join('clients', 'clients.id', '=','payments.client_id') ->join('invoices', 'invoices.id', '=','payments.invoice_id') @@ -39,7 +39,37 @@ class PaymentRepository } return $query; - } + } + + public function findForContact($contactId = null, $filter = null) + { + $query = \DB::table('payments') + ->join('clients', 'clients.id', '=','payments.client_id') + ->join('invoices', 'invoices.id', '=','payments.invoice_id') + ->join('contacts', 'contacts.client_id', '=', 'clients.id') + ->leftJoin('invitations', function($join) + { + $join->on('invitations.invoice_id', '=', 'invoices.id') + ->on('invitations.contact_id', '=', 'contacts.id'); + }) + ->leftJoin('payment_types', 'payment_types.id', '=', 'payments.payment_type_id') + ->where('payments.account_id', '=', \Auth::user()->account_id) + ->where('clients.is_deleted', '=', false) + ->where('payments.is_deleted', '=', false) + ->where('invitations.deleted_at', '=', null) + ->where('contacts.id', '=', $contactId) + ->select('invitations.invitation_key', 'payments.public_id', 'payments.transaction_reference', 'clients.name as client_name', 'clients.public_id as client_public_id', 'payments.amount', 'payments.payment_date', 'invoices.public_id as invoice_public_id', 'invoices.invoice_number', 'clients.currency_id', 'contacts.first_name', 'contacts.last_name', 'contacts.email', 'payment_types.name as payment_type', 'payments.account_gateway_id'); + + if ($filter) + { + $query->where(function($query) use ($filter) + { + $query->where('clients.name', 'like', '%'.$filter.'%'); + }); + } + + return $query; + } public function getErrors($input) { diff --git a/app/routes.php b/app/routes.php index ad470fd641d9..f8b70dcb2777 100755 --- a/app/routes.php +++ b/app/routes.php @@ -1,5 +1,6 @@ id === 1) } */ - diff --git a/app/views/master.blade.php b/app/views/master.blade.php index ca92bcfde0e2..e04a38d9c7c6 100755 --- a/app/views/master.blade.php +++ b/app/views/master.blade.php @@ -45,6 +45,7 @@ /* Set the defaults for DataTables initialisation */ $.extend( true, $.fn.dataTable.defaults, { + "bSortClasses": false, "sDom": "t<'row-fluid'<'span6'i><'span6'p>>", "sPaginationType": "bootstrap", "bInfo": true, diff --git a/app/views/payments/payment.blade.php b/app/views/payments/payment.blade.php index a992a97f3920..98a04302b6e5 100755 --- a/app/views/payments/payment.blade.php +++ b/app/views/payments/payment.blade.php @@ -66,7 +66,7 @@