mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Show invoice status labels
This commit is contained in:
parent
fffc198433
commit
988ef9af66
@ -64,6 +64,14 @@ class Invoice extends EntityModel implements BalanceAffecting
|
||||
'date:',
|
||||
];
|
||||
|
||||
public static $statusClasses = [
|
||||
INVOICE_STATUS_SENT => 'info',
|
||||
INVOICE_STATUS_VIEWED => 'warning',
|
||||
INVOICE_STATUS_APPROVED => 'success',
|
||||
INVOICE_STATUS_PARTIAL => 'primary',
|
||||
INVOICE_STATUS_PAID => 'success',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@ -553,6 +561,56 @@ class Invoice extends EntityModel implements BalanceAffecting
|
||||
return floatval($this->balance) > 0 && ! $this->is_deleted && $this->isInvoice();
|
||||
}
|
||||
|
||||
public static function calcStatusLabel($status, $class, $entityType, $quoteInvoiceId)
|
||||
{
|
||||
if ($quoteInvoiceId) {
|
||||
$label = 'converted';
|
||||
} else if ($class == 'danger') {
|
||||
$label = $entityType == ENTITY_INVOICE ? 'overdue' : 'expired';
|
||||
} else {
|
||||
$label = 'status_' . strtolower($status);
|
||||
}
|
||||
|
||||
return trans("texts.{$label}");
|
||||
}
|
||||
|
||||
public static function calcStatusClass($statusId, $balance, $dueDate)
|
||||
{
|
||||
if (static::calcIsOverdue($balance, $dueDate)) {
|
||||
return 'danger';
|
||||
}
|
||||
|
||||
if (isset(static::$statusClasses[$statusId])) {
|
||||
return static::$statusClasses[$statusId];
|
||||
}
|
||||
|
||||
return 'default';
|
||||
}
|
||||
|
||||
public static function calcIsOverdue($balance, $dueDate)
|
||||
{
|
||||
if ( ! Utils::parseFloat($balance) > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! $dueDate || $dueDate == '0000-00-00') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// it isn't considered overdue until the end of the day
|
||||
return time() > (strtotime($dueDate) + (60*60*24));
|
||||
}
|
||||
|
||||
public function statusClass()
|
||||
{
|
||||
return static::calcStatusClass($this->invoice_status_id, $this->balance, $this->due_date);
|
||||
}
|
||||
|
||||
public function statusLabel()
|
||||
{
|
||||
return static::calcStatusLabel($this->invoice_status->name, $this->statusClass(), $this->getEntityType(), $this->quote_invoice_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $invoice
|
||||
* @return string
|
||||
@ -633,11 +691,7 @@ class Invoice extends EntityModel implements BalanceAffecting
|
||||
*/
|
||||
public function isOverdue()
|
||||
{
|
||||
if ( ! $this->due_date) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return time() > strtotime($this->due_date);
|
||||
return static::calcIsOverdue($this->balance, $this->due_date);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,6 +3,7 @@
|
||||
use Utils;
|
||||
use URL;
|
||||
use Auth;
|
||||
use App\Models\Invoice;
|
||||
|
||||
class InvoiceDatatable extends EntityDatatable
|
||||
{
|
||||
@ -167,35 +168,8 @@ class InvoiceDatatable extends EntityDatatable
|
||||
|
||||
private function getStatusLabel($model)
|
||||
{
|
||||
$entityType = $this->entityType;
|
||||
|
||||
// check if invoice is overdue
|
||||
if (Utils::parseFloat($model->balance) && $model->due_date && $model->due_date != '0000-00-00') {
|
||||
if (\DateTime::createFromFormat('Y-m-d', $model->due_date) < new \DateTime('now')) {
|
||||
$label = $entityType == ENTITY_INVOICE ? trans('texts.overdue') : trans('texts.expired');
|
||||
return '<h4><div class="label label-danger">' . $label . '</div></h4>';
|
||||
}
|
||||
}
|
||||
|
||||
$label = trans('texts.status_' . strtolower($model->invoice_status_name));
|
||||
$class = 'default';
|
||||
switch ($model->invoice_status_id) {
|
||||
case INVOICE_STATUS_SENT:
|
||||
$class = 'info';
|
||||
break;
|
||||
case INVOICE_STATUS_VIEWED:
|
||||
$class = 'warning';
|
||||
break;
|
||||
case INVOICE_STATUS_APPROVED:
|
||||
$class = 'success';
|
||||
break;
|
||||
case INVOICE_STATUS_PARTIAL:
|
||||
$class = 'primary';
|
||||
break;
|
||||
case INVOICE_STATUS_PAID:
|
||||
$class = 'success';
|
||||
break;
|
||||
}
|
||||
$class = Invoice::calcStatusClass($model->invoice_status_id, $model->balance, $model->due_date);
|
||||
$label = Invoice::calcStatusLabel($model->invoice_status_name, $class, $this->entityType, $model->quote_invoice_id);
|
||||
|
||||
return "<h4><div class=\"label label-{$class}\">$label</div></h4>";
|
||||
}
|
||||
|
@ -34,8 +34,7 @@ class EntityPresenter extends Presenter
|
||||
$class = 'warning';
|
||||
$text = trans('texts.archived');
|
||||
} else {
|
||||
//$class = 'success';
|
||||
//$text = trans('texts.active');
|
||||
return '';
|
||||
}
|
||||
|
||||
return "<span style=\"font-size:13px\" class=\"label label-{$class}\">{$text}</span>";
|
||||
|
@ -90,6 +90,18 @@ class InvoicePresenter extends EntityPresenter {
|
||||
}
|
||||
}
|
||||
|
||||
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>";
|
||||
}
|
||||
|
||||
public function invoice_date()
|
||||
{
|
||||
return Utils::fromSqlDate($this->entity->invoice_date);
|
||||
|
Loading…
Reference in New Issue
Block a user