2017-01-30 21:40:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Ninja\Presenters;
|
2016-01-06 20:52:09 +01:00
|
|
|
|
2017-01-22 12:09:29 +02:00
|
|
|
use Carbon;
|
2017-01-30 21:40:43 +02:00
|
|
|
use Utils;
|
2016-01-06 20:52:09 +01:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
2017-01-30 21:40:43 +02:00
|
|
|
* Class ExpensePresenter.
|
2016-07-03 18:11:58 +02:00
|
|
|
*/
|
|
|
|
|
class ExpensePresenter extends EntityPresenter
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2016-01-06 20:52:09 +01:00
|
|
|
public function vendor()
|
|
|
|
|
{
|
|
|
|
|
return $this->entity->vendor ? $this->entity->vendor->getDisplayName() : '';
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* @return \DateTime|string
|
|
|
|
|
*/
|
2016-01-06 20:52:09 +01:00
|
|
|
public function expense_date()
|
|
|
|
|
{
|
|
|
|
|
return Utils::fromSqlDate($this->entity->expense_date);
|
|
|
|
|
}
|
2016-01-21 22:36:49 +02:00
|
|
|
|
2017-04-19 17:18:24 +03:00
|
|
|
/**
|
|
|
|
|
* @return \DateTime|string
|
|
|
|
|
*/
|
|
|
|
|
public function payment_date()
|
|
|
|
|
{
|
|
|
|
|
return Utils::fromSqlDate($this->entity->payment_date);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-22 12:09:29 +02:00
|
|
|
public function month()
|
|
|
|
|
{
|
2018-03-21 18:11:44 +02:00
|
|
|
return Carbon::parse($this->entity->expense_date)->format('Y m');
|
2017-01-22 12:09:29 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-05 20:35:01 +02:00
|
|
|
public function amount()
|
|
|
|
|
{
|
2018-01-23 20:32:11 +02:00
|
|
|
return Utils::formatMoney($this->entity->amountWithTax(), $this->entity->expense_currency_id);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-25 13:18:21 +03:00
|
|
|
public function currencyCode()
|
|
|
|
|
{
|
|
|
|
|
return Utils::getFromCache($this->entity->expense_currency_id, 'currencies')->code;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-23 20:32:11 +02:00
|
|
|
public function taxAmount()
|
|
|
|
|
{
|
|
|
|
|
return Utils::formatMoney($this->entity->taxAmount(), $this->entity->expense_currency_id);
|
2016-12-05 20:35:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function category()
|
|
|
|
|
{
|
|
|
|
|
return $this->entity->expense_category ? $this->entity->expense_category->name : '';
|
|
|
|
|
}
|
2017-09-12 13:43:59 +03:00
|
|
|
|
2018-04-15 13:02:40 +03:00
|
|
|
public function payment_type()
|
|
|
|
|
{
|
|
|
|
|
if (! $this->payment_type_id) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Utils::getFromCache($this->payment_type_id, 'paymentTypes')->name;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-13 00:20:18 +03:00
|
|
|
public function calendarEvent($subColors = false)
|
2017-09-12 13:43:59 +03:00
|
|
|
{
|
|
|
|
|
$data = parent::calendarEvent();
|
|
|
|
|
$expense = $this->entity;
|
|
|
|
|
|
|
|
|
|
$data->title = trans('texts.expense') . ' ' . $this->amount() . ' | ' . $this->category();
|
|
|
|
|
|
|
|
|
|
$data->title = trans('texts.expense') . ' ' . $this->amount();
|
|
|
|
|
if ($category = $this->category()) {
|
|
|
|
|
$data->title .= ' | ' . $category;
|
|
|
|
|
}
|
|
|
|
|
if ($this->public_notes) {
|
|
|
|
|
$data->title .= ' | ' . $this->public_notes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data->start = $expense->expense_date;
|
2017-09-13 00:20:18 +03:00
|
|
|
|
|
|
|
|
if ($subColors && $expense->expense_category_id) {
|
|
|
|
|
$data->borderColor = $data->backgroundColor = Utils::brewerColor($expense->expense_category->public_id);
|
|
|
|
|
} else {
|
2017-09-18 08:27:40 +03:00
|
|
|
$data->borderColor = $data->backgroundColor = '#d95d02';
|
2017-09-13 00:20:18 +03:00
|
|
|
}
|
2017-09-12 13:43:59 +03:00
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
2016-05-23 12:26:08 +03:00
|
|
|
}
|