2015-11-08 09:43:49 +01:00
|
|
|
<?php namespace App\Ninja\Presenters;
|
|
|
|
|
|
|
|
use Utils;
|
2016-08-10 14:57:34 +02:00
|
|
|
use App\Libraries\Skype\InvoiceCard;
|
2015-11-08 09:43:49 +01:00
|
|
|
|
2016-05-23 11:26:08 +02:00
|
|
|
class InvoicePresenter extends EntityPresenter {
|
2015-11-08 09:43:49 +01:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-08-04 19:01:30 +02:00
|
|
|
public function amount()
|
|
|
|
{
|
|
|
|
$invoice = $this->entity;
|
|
|
|
$account = $invoice->account;
|
|
|
|
|
|
|
|
return $account->formatMoney($invoice->amount, $invoice->client);
|
|
|
|
}
|
|
|
|
|
2016-08-10 14:57:34 +02:00
|
|
|
public function requestedAmount()
|
|
|
|
{
|
|
|
|
$invoice = $this->entity;
|
|
|
|
$account = $invoice->account;
|
|
|
|
|
|
|
|
return $account->formatMoney($invoice->getRequestedAmount(), $invoice->client);
|
|
|
|
}
|
|
|
|
|
2015-12-02 14:26:06 +01:00
|
|
|
public function balanceDueLabel()
|
|
|
|
{
|
2016-05-05 18:43:44 +02:00
|
|
|
if ($this->entity->partial > 0) {
|
2016-03-18 13:34:46 +01:00
|
|
|
return 'partial_due';
|
2016-05-26 16:56:54 +02:00
|
|
|
} elseif ($this->entity->isType(INVOICE_TYPE_QUOTE)) {
|
2015-12-02 14:26:06 +01:00
|
|
|
return 'total';
|
|
|
|
} else {
|
|
|
|
return 'balance_due';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-10 14:57:34 +02:00
|
|
|
public function dueDateLabel()
|
|
|
|
{
|
|
|
|
if ($this->entity->isType(INVOICE_TYPE_STANDARD)) {
|
|
|
|
return trans('texts.due_date');
|
|
|
|
} else {
|
|
|
|
return trans('texts.valid_until');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function discount()
|
|
|
|
{
|
|
|
|
$invoice = $this->entity;
|
|
|
|
|
|
|
|
if ($invoice->is_amount_discount) {
|
|
|
|
return $invoice->account->formatMoney($invoice->discount);
|
|
|
|
} else {
|
|
|
|
return $invoice->discount . '%';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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');
|
2016-05-22 19:01:37 +02:00
|
|
|
} elseif ($this->entity->is_recurring) {
|
|
|
|
return trans('texts.active');
|
2016-02-25 10:25:07 +01:00
|
|
|
} 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()
|
|
|
|
{
|
2016-07-01 23:19:09 +02:00
|
|
|
$frequency = $this->entity->frequency ? $this->entity->frequency->name : '';
|
|
|
|
$frequency = strtolower($frequency);
|
2016-07-02 23:18:13 +02:00
|
|
|
return trans('texts.freq_'.$frequency);
|
2016-02-25 10:25:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function email()
|
|
|
|
{
|
|
|
|
$client = $this->entity->client;
|
|
|
|
return count($client->contacts) ? $client->contacts[0]->email : '';
|
|
|
|
}
|
2016-06-26 11:59:42 +02:00
|
|
|
|
|
|
|
public function autoBillEmailMessage()
|
|
|
|
{
|
|
|
|
$client = $this->entity->client;
|
|
|
|
$paymentMethod = $client->defaultPaymentMethod();
|
|
|
|
|
|
|
|
if ( ! $paymentMethod) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($paymentMethod->payment_type_id == PAYMENT_TYPE_ACH) {
|
|
|
|
$paymentMethodString = trans('texts.auto_bill_payment_method_bank_transfer');
|
|
|
|
} elseif ($paymentMethod->payment_type_id == PAYMENT_TYPE_PAYPAL) {
|
|
|
|
$paymentMethodString = trans('texts.auto_bill_payment_method_paypal');
|
|
|
|
} else {
|
|
|
|
$paymentMethodString = trans('texts.auto_bill_payment_method_credit_card');
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'payment_method' => $paymentMethodString,
|
|
|
|
'due_date' => $this->due_date(),
|
|
|
|
];
|
|
|
|
|
|
|
|
return trans('texts.auto_bill_notification', $data);
|
|
|
|
}
|
2016-08-10 14:57:34 +02:00
|
|
|
|
|
|
|
public function skypeBot()
|
|
|
|
{
|
|
|
|
return new InvoiceCard($this->entity);
|
|
|
|
}
|
2016-05-22 19:01:37 +02:00
|
|
|
}
|