diff --git a/app/Ninja/Datatables/ExpenseDatatable.php b/app/Ninja/Datatables/ExpenseDatatable.php index 29bbbe0c08..a832ceee06 100644 --- a/app/Ninja/Datatables/ExpenseDatatable.php +++ b/app/Ninja/Datatables/ExpenseDatatable.php @@ -75,7 +75,7 @@ class ExpenseDatatable extends EntityDatatable [ 'expense_status_id', function ($model) { - return self::getStatusLabel($model->invoice_id, $model->should_be_invoiced); + return self::getStatusLabel($model->invoice_id, $model->should_be_invoiced, $model->balance); } ], ]; @@ -115,11 +115,16 @@ class ExpenseDatatable extends EntityDatatable } - private function getStatusLabel($invoiceId, $shouldBeInvoiced) + private function getStatusLabel($invoiceId, $shouldBeInvoiced, $balance) { if ($invoiceId) { - $label = trans('texts.invoiced'); - $class = 'success'; + if (floatval($balance)) { + $label = trans('texts.invoiced'); + $class = 'default'; + } else { + $label = trans('texts.paid'); + $class = 'success'; + } } elseif ($shouldBeInvoiced) { $label = trans('texts.pending'); $class = 'warning'; diff --git a/app/Ninja/Datatables/TaskDatatable.php b/app/Ninja/Datatables/TaskDatatable.php index 6f460b418e..0ce2fe4699 100644 --- a/app/Ninja/Datatables/TaskDatatable.php +++ b/app/Ninja/Datatables/TaskDatatable.php @@ -96,13 +96,18 @@ class TaskDatatable extends EntityDatatable private function getStatusLabel($model) { if ($model->invoice_number) { - $class = 'success'; - $label = trans('texts.invoiced'); + if (floatval($model->balance)) { + $label = trans('texts.invoiced'); + $class = 'default'; + } else { + $class = 'success'; + $label = trans('texts.paid'); + } } elseif ($model->is_running) { $class = 'primary'; $label = trans('texts.running'); } else { - $class = 'default'; + $class = 'warning'; $label = trans('texts.logged'); } diff --git a/app/Ninja/Repositories/ExpenseRepository.php b/app/Ninja/Repositories/ExpenseRepository.php index 23b164b41b..9492770d30 100644 --- a/app/Ninja/Repositories/ExpenseRepository.php +++ b/app/Ninja/Repositories/ExpenseRepository.php @@ -79,6 +79,7 @@ class ExpenseRepository extends BaseRepository 'expenses.user_id', 'invoices.public_id as invoice_public_id', 'invoices.user_id as invoice_user_id', + 'invoices.balance', 'vendors.name as vendor_name', 'vendors.public_id as vendor_public_id', 'vendors.user_id as vendor_user_id', @@ -158,7 +159,7 @@ class ExpenseRepository extends BaseRepository } } } - + // prevent loading all of the documents if we don't have to if ( ! $expense->wasRecentlyCreated) { foreach ($expense->documents as $document){ diff --git a/app/Ninja/Repositories/TaskRepository.php b/app/Ninja/Repositories/TaskRepository.php index 3a5eca04a1..477b2aa510 100644 --- a/app/Ninja/Repositories/TaskRepository.php +++ b/app/Ninja/Repositories/TaskRepository.php @@ -38,6 +38,7 @@ class TaskRepository 'invoices.invoice_number', 'invoices.public_id as invoice_public_id', 'invoices.user_id as invoice_user_id', + 'invoices.balance', 'tasks.is_running', 'tasks.time_log', 'tasks.created_at', @@ -89,7 +90,7 @@ class TaskRepository } else { $timeLog = []; } - + array_multisort($timeLog); if (isset($data['action'])) {