diff --git a/app/Http/Controllers/ExpenseController.php b/app/Http/Controllers/ExpenseController.php index 25f78be2d361..c3dc77b23ec2 100644 --- a/app/Http/Controllers/ExpenseController.php +++ b/app/Http/Controllers/ExpenseController.php @@ -48,6 +48,7 @@ class ExpenseController extends BaseController 'columns' => Utils::trans([ 'checkbox', 'vendor', + 'client', 'expense_date', 'amount', 'public_notes', diff --git a/app/Ninja/Repositories/ExpenseRepository.php b/app/Ninja/Repositories/ExpenseRepository.php index 8b47a48e5aff..3c65f1c2520b 100644 --- a/app/Ninja/Repositories/ExpenseRepository.php +++ b/app/Ninja/Repositories/ExpenseRepository.php @@ -51,10 +51,19 @@ class ExpenseRepository extends BaseRepository $query = DB::table('expenses') ->join('accounts', 'accounts.id', '=', 'expenses.account_id') ->leftjoin('clients', 'clients.id', '=', 'expenses.client_id') + ->leftJoin('contacts', 'contacts.client_id', '=', 'clients.id') ->leftjoin('vendors', 'vendors.id', '=', 'expenses.vendor_id') ->leftJoin('invoices', 'invoices.id', '=', 'expenses.invoice_id') ->where('expenses.account_id', '=', $accountid) - ->select('expenses.account_id', + ->where('contacts.deleted_at', '=', null) + ->where('vendors.deleted_at', '=', null) + ->where('clients.deleted_at', '=', null) + ->where(function ($query) { + $query->where('contacts.is_primary', '=', true) + ->orWhere('contacts.is_primary', '=', null); + }) + ->select( + 'expenses.account_id', 'expenses.amount', 'expenses.currency_id', 'expenses.deleted_at', @@ -69,10 +78,15 @@ class ExpenseRepository extends BaseRepository 'expenses.should_be_invoiced', 'expenses.vendor_id', 'invoices.public_id as invoice_public_id', - 'vendors.name as vendor_name', - 'vendors.public_id as vendor_public_id', 'accounts.country_id as account_country_id', 'accounts.currency_id as account_currency_id', + 'vendors.name as vendor_name', + 'vendors.public_id as vendor_public_id', + 'clients.name as client_name', + 'clients.public_id as client_public_id', + 'contacts.first_name', + 'contacts.email', + 'contacts.last_name', 'clients.country_id as client_country_id' ); @@ -109,6 +123,10 @@ class ExpenseRepository extends BaseRepository $expense->public_notes = trim($input['public_notes']); $expense->should_be_invoiced = isset($input['should_be_invoiced']) || $expense->client_id ? true : false; + if (! $expense->currency_id) { + $expense->currency_id = \Auth::user()->account->getCurrencyId(); + } + $rate = isset($input['exchange_rate']) ? Utils::parseFloat($input['exchange_rate']) : 1; $expense->exchange_rate = round($rate, 4); $expense->amount = round(Utils::parseFloat($input['amount']), 2); diff --git a/app/Ninja/Repositories/TaskRepository.php b/app/Ninja/Repositories/TaskRepository.php index f6a13c527000..47a052378ff1 100644 --- a/app/Ninja/Repositories/TaskRepository.php +++ b/app/Ninja/Repositories/TaskRepository.php @@ -23,7 +23,23 @@ class TaskRepository }) ->where('contacts.deleted_at', '=', null) ->where('clients.deleted_at', '=', null) - ->select('tasks.public_id', 'clients.name as client_name', 'clients.public_id as client_public_id', 'contacts.first_name', 'contacts.email', 'contacts.last_name', 'invoices.invoice_status_id', 'tasks.description', 'tasks.is_deleted', 'tasks.deleted_at', 'invoices.invoice_number', 'invoices.public_id as invoice_public_id', 'tasks.is_running', 'tasks.time_log', 'tasks.created_at'); + ->select( + 'tasks.public_id', + 'clients.name as client_name', + 'clients.public_id as client_public_id', + 'contacts.first_name', + 'contacts.email', + 'contacts.last_name', + 'invoices.invoice_status_id', + 'tasks.description', + 'tasks.is_deleted', + 'tasks.deleted_at', + 'invoices.invoice_number', + 'invoices.public_id as invoice_public_id', + 'tasks.is_running', + 'tasks.time_log', + 'tasks.created_at' + ); if ($clientPublicId) { $query->where('clients.public_id', '=', $clientPublicId); diff --git a/app/Services/ExpenseService.php b/app/Services/ExpenseService.php index 4680bfc0fedd..7df356931470 100644 --- a/app/Services/ExpenseService.php +++ b/app/Services/ExpenseService.php @@ -53,26 +53,37 @@ class ExpenseService extends BaseService 'vendor_name', function ($model) { - if($model->vendor_public_id) { + if ($model->vendor_public_id) { return link_to("vendors/{$model->vendor_public_id}", $model->vendor_name); } else { - return 'No vendor' ; + return ''; + } + } + ], + [ + 'client_name', + function ($model) + { + if ($model->client_public_id) { + return link_to("clients/{$model->client_public_id}", Utils::getClientDisplayName($model)); + } else { + return ''; } } ], [ 'expense_date', function ($model) { - return Utils::fromSqlDate($model->expense_date); + return link_to("expenses/{$model->public_id}/edit", Utils::fromSqlDate($model->expense_date)); } ], [ 'amount', function ($model) { // show both the amount and the converted amount - $str = Utils::formatMoney($model->amount, $model->account_currency_id, $model->account_country_id, true); + $str = Utils::formatMoney($model->amount, $model->account_currency_id, $model->account_country_id); if ($model->exchange_rate != 1) { - $str .= ' | ' . Utils::formatMoney(round($model->amount * $model->exchange_rate,2), $model->currency_id, $model->client_country_id, true); + $str .= ' | ' . Utils::formatMoney(round($model->amount * $model->exchange_rate,2), $model->currency_id, $model->client_country_id); } return $str; } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index be6ce2cc9d4b..067edccbeac2 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -1054,7 +1054,7 @@ return array( 'restore_expense' => 'Restore Expense', 'invoice_expense' => 'Invoice Expense', 'expense_error_multiple_clients' =>'The expenses can\'t belong to different clients', - 'expense_error_invoiced' => 'Expense have already been invoiced', + 'expense_error_invoiced' => 'Expense has already been invoiced', 'convert_currency' => 'Convert currency', // Payment terms diff --git a/resources/views/list.blade.php b/resources/views/list.blade.php index 222090ab1a79..d7b298957cc3 100644 --- a/resources/views/list.blade.php +++ b/resources/views/list.blade.php @@ -29,10 +29,12 @@
- @if (Auth::user()->isPro() && $entityType == ENTITY_INVOICE) + @if (Auth::user()->isPro() && $entityType == ENTITY_INVOICE) {!! Button::normal(trans('texts.quotes'))->asLinkTo(URL::to('/quotes'))->appendIcon(Icon::create('list')) !!} {!! Button::normal(trans('texts.recurring'))->asLinkTo(URL::to('/recurring_invoices'))->appendIcon(Icon::create('list')) !!} - @elseif ($entityType == ENTITY_CLIENT) + @elseif ($entityType == ENTITY_EXPENSE) + {!! Button::normal(trans('texts.vendors'))->asLinkTo(URL::to('/vendors'))->appendIcon(Icon::create('list')) !!} + @elseif ($entityType == ENTITY_CLIENT) {!! Button::normal(trans('texts.credits'))->asLinkTo(URL::to('/credits'))->appendIcon(Icon::create('list')) !!} @endif