1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Ninja/Presenters/InvoicePresenter.php

85 lines
2.1 KiB
PHP
Raw Normal View History

2015-11-08 09:43:49 +01:00
<?php namespace App\Ninja\Presenters;
2016-02-25 22:33:48 +01:00
use URL;
2015-11-08 09:43:49 +01:00
use Utils;
use Laracasts\Presenter\Presenter;
class InvoicePresenter extends Presenter {
2015-11-12 21:36:28 +01:00
public function client()
{
return $this->entity->client ? $this->entity->client->getDisplayName() : '';
}
public function user()
{
return $this->entity->user->getDisplayName();
}
2015-12-02 14:26:06 +01:00
public function balanceDueLabel()
{
if ($this->entity->partial) {
2016-03-18 13:34:46 +01:00
return 'partial_due';
2015-12-02 14:26:06 +01:00
} elseif ($this->entity->is_quote) {
return 'total';
} else {
return 'balance_due';
}
}
2015-12-16 12:49:26 +01:00
// https://schema.org/PaymentStatusType
public function paymentStatus()
{
if ( ! $this->entity->balance) {
return 'PaymentComplete';
} elseif ($this->entity->isOverdue()) {
return 'PaymentPastDue';
} else {
return 'PaymentDue';
}
}
2015-11-12 21:36:28 +01:00
public function status()
{
2016-02-25 10:25:07 +01:00
if ($this->entity->is_deleted) {
return trans('texts.deleted');
} elseif ($this->entity->trashed()) {
return trans('texts.archived');
} else {
$status = $this->entity->invoice_status ? $this->entity->invoice_status->name : 'draft';
$status = strtolower($status);
return trans("texts.status_{$status}");
}
2015-11-12 21:36:28 +01:00
}
public function invoice_date()
{
return Utils::fromSqlDate($this->entity->invoice_date);
}
public function due_date()
{
return Utils::fromSqlDate($this->entity->due_date);
}
2016-02-25 10:25:07 +01:00
public function frequency()
{
return $this->entity->frequency ? $this->entity->frequency->name : '';
}
2016-02-25 22:33:48 +01:00
public function url()
{
return URL::to('/invoices/' . $this->entity->public_id);
}
2016-02-23 22:32:39 +01:00
public function link()
{
return link_to('/invoices/' . $this->entity->public_id, $this->entity->invoice_number);
}
2016-02-25 10:25:07 +01:00
public function email()
{
$client = $this->entity->client;
return count($client->contacts) ? $client->contacts[0]->email : '';
}
2015-11-08 09:43:49 +01:00
}