mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Add labels for tasks and expenses
This commit is contained in:
parent
751ff62632
commit
ffd7e7bdc6
@ -221,6 +221,53 @@ class Expense extends EntityModel
|
|||||||
|
|
||||||
return $statuses;
|
return $statuses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function calcStatusLabel($shouldBeInvoiced, $invoiceId, $balance)
|
||||||
|
{
|
||||||
|
if ($invoiceId) {
|
||||||
|
if (floatval($balance) > 0) {
|
||||||
|
$label = 'invoiced';
|
||||||
|
} else {
|
||||||
|
$label = 'paid';
|
||||||
|
}
|
||||||
|
} elseif ($shouldBeInvoiced) {
|
||||||
|
$label = 'pending';
|
||||||
|
} else {
|
||||||
|
$label = 'logged';
|
||||||
|
}
|
||||||
|
|
||||||
|
return trans("texts.{$label}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function calcStatusClass($shouldBeInvoiced, $invoiceId, $balance)
|
||||||
|
{
|
||||||
|
if ($invoiceId) {
|
||||||
|
if (floatval($balance) > 0) {
|
||||||
|
return 'default';
|
||||||
|
} else {
|
||||||
|
return 'success';
|
||||||
|
}
|
||||||
|
} elseif ($shouldBeInvoiced) {
|
||||||
|
return 'warning';
|
||||||
|
} else {
|
||||||
|
return 'primary';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function statusClass()
|
||||||
|
{
|
||||||
|
$balance = $this->invoice ? $this->invoice->balance : 0;
|
||||||
|
|
||||||
|
return static::calcStatusClass($this->should_be_invoiced, $this->invoice_id, $balance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function statusLabel()
|
||||||
|
{
|
||||||
|
$balance = $this->invoice ? $this->invoice->balance : 0;
|
||||||
|
|
||||||
|
return static::calcStatusLabel($this->should_be_invoiced, $this->invoice_id, $balance);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Expense::creating(function ($expense) {
|
Expense::creating(function ($expense) {
|
||||||
|
@ -215,8 +215,64 @@ class Task extends EntityModel
|
|||||||
return $statuses;
|
return $statuses;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public static function calcStatusLabel($isRunning, $balance, $invoiceNumber)
|
||||||
|
{
|
||||||
|
if ($invoiceNumber) {
|
||||||
|
if (floatval($balance) > 0) {
|
||||||
|
$label = 'invoiced';
|
||||||
|
} else {
|
||||||
|
$label = 'paid';
|
||||||
|
}
|
||||||
|
} elseif ($isRunning) {
|
||||||
|
$label = 'running';
|
||||||
|
} else {
|
||||||
|
$label = 'logged';
|
||||||
|
}
|
||||||
|
|
||||||
|
return trans("texts.{$label}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function calcStatusClass($isRunning, $balance, $invoiceNumber)
|
||||||
|
{
|
||||||
|
if ($invoiceNumber) {
|
||||||
|
if (floatval($balance)) {
|
||||||
|
return 'default';
|
||||||
|
} else {
|
||||||
|
return 'success';
|
||||||
|
}
|
||||||
|
} elseif ($isRunning) {
|
||||||
|
return 'primary';
|
||||||
|
} else {
|
||||||
|
return 'warning';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function statusClass()
|
||||||
|
{
|
||||||
|
if ($this->invoice) {
|
||||||
|
$balance = $this->invoice->balance;
|
||||||
|
$invoiceNumber = $this->invoice->invoice_number;
|
||||||
|
} else {
|
||||||
|
$balance = 0;
|
||||||
|
$invoiceNumber = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return static::calcStatusClass($this->is_running, $balance, $invoiceNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function statusLabel()
|
||||||
|
{
|
||||||
|
if ($this->invoice) {
|
||||||
|
$balance = $this->invoice->balance;
|
||||||
|
$invoiceNumber = $this->invoice->invoice_number;
|
||||||
|
} else {
|
||||||
|
$balance = 0;
|
||||||
|
$invoiceNumber = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return static::calcStatusLabel($this->is_running, $balance, $invoiceNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Task::created(function ($task) {
|
Task::created(function ($task) {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
use Utils;
|
use Utils;
|
||||||
use URL;
|
use URL;
|
||||||
use Auth;
|
use Auth;
|
||||||
|
use App\Models\Expense;
|
||||||
|
|
||||||
class ExpenseDatatable extends EntityDatatable
|
class ExpenseDatatable extends EntityDatatable
|
||||||
{
|
{
|
||||||
@ -123,24 +124,10 @@ class ExpenseDatatable extends EntityDatatable
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function getStatusLabel($invoiceId, $shouldBeInvoiced, $balance)
|
private function getStatusLabel($invoiceId, $shouldBeInvoiced, $balance)
|
||||||
{
|
{
|
||||||
if ($invoiceId) {
|
$label = Expense::calcStatusLabel($shouldBeInvoiced, $invoiceId, $balance);
|
||||||
if (floatval($balance)) {
|
$class = Expense::calcStatusClass($shouldBeInvoiced, $invoiceId, $balance);
|
||||||
$label = trans('texts.invoiced');
|
|
||||||
$class = 'default';
|
|
||||||
} else {
|
|
||||||
$label = trans('texts.paid');
|
|
||||||
$class = 'success';
|
|
||||||
}
|
|
||||||
} elseif ($shouldBeInvoiced) {
|
|
||||||
$label = trans('texts.pending');
|
|
||||||
$class = 'warning';
|
|
||||||
} else {
|
|
||||||
$label = trans('texts.logged');
|
|
||||||
$class = 'primary';
|
|
||||||
}
|
|
||||||
|
|
||||||
return "<h4><div class=\"label label-{$class}\">$label</div></h4>";
|
return "<h4><div class=\"label label-{$class}\">$label</div></h4>";
|
||||||
}
|
}
|
||||||
|
@ -108,21 +108,8 @@ class TaskDatatable extends EntityDatatable
|
|||||||
|
|
||||||
private function getStatusLabel($model)
|
private function getStatusLabel($model)
|
||||||
{
|
{
|
||||||
if ($model->invoice_number) {
|
$label = Task::calcStatusLabel($model->is_running, $model->balance, $model->invoice_number);
|
||||||
if (floatval($model->balance)) {
|
$class = Task::calcStatusClass($model->is_running, $model->balance, $model->invoice_number);
|
||||||
$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 = 'warning';
|
|
||||||
$label = trans('texts.logged');
|
|
||||||
}
|
|
||||||
|
|
||||||
return "<h4><div class=\"label label-{$class}\">$label</div></h4>";
|
return "<h4><div class=\"label label-{$class}\">$label</div></h4>";
|
||||||
}
|
}
|
||||||
|
@ -34,4 +34,19 @@ class ExpensePresenter extends EntityPresenter
|
|||||||
return $this->entity->expense_category ? $this->entity->expense_category->name : '';
|
return $this->entity->expense_category ? $this->entity->expense_category->name : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function statusLabel()
|
||||||
|
{
|
||||||
|
if ($label = parent::statusLabel()) {
|
||||||
|
return $label;
|
||||||
|
}
|
||||||
|
|
||||||
|
$class = $this->entity->statusClass();
|
||||||
|
$label = $this->entity->statusLabel();
|
||||||
|
|
||||||
|
return "<span style=\"font-size:13px\" class=\"label label-{$class}\">{$label}</span>";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -57,24 +57,20 @@ class TaskPresenter extends EntityPresenter
|
|||||||
return implode("\n", $times);
|
return implode("\n", $times);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function status()
|
public function statusLabel()
|
||||||
{
|
{
|
||||||
$class = $text = '';
|
if ($label = parent::statusLabel()) {
|
||||||
|
return $label;
|
||||||
if ($this->entity->is_deleted) {
|
|
||||||
$class = 'danger';
|
|
||||||
$text = trans('texts.deleted');
|
|
||||||
} elseif ($this->entity->trashed()) {
|
|
||||||
$class = 'warning';
|
|
||||||
$text = trans('texts.archived');
|
|
||||||
} else {
|
|
||||||
$class = 'success';
|
|
||||||
$text = trans('texts.active');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "<span class=\"label label-{$class}\">{$text}</span>";
|
$class = $this->entity->statusClass();
|
||||||
|
$label = $this->entity->statusLabel();
|
||||||
|
|
||||||
|
return "<span style=\"font-size:13px\" class=\"label label-{$class}\">{$label}</span>";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user