2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Presenters;
|
2015-11-12 21:36:28 +01:00
|
|
|
|
2017-08-13 15:03:00 +02:00
|
|
|
use Utils;
|
|
|
|
|
2017-01-30 17:05:31 +01:00
|
|
|
class ClientPresenter extends EntityPresenter
|
|
|
|
{
|
2015-11-12 21:36:28 +01:00
|
|
|
public function country()
|
|
|
|
{
|
2018-01-21 07:55:40 +01:00
|
|
|
return $this->entity->country ? $this->entity->country->getName() : '';
|
2015-11-12 21:36:28 +01:00
|
|
|
}
|
2016-02-04 19:36:39 +01:00
|
|
|
|
2017-11-19 13:52:42 +01:00
|
|
|
public function shipping_country()
|
|
|
|
{
|
2018-01-21 07:55:40 +01:00
|
|
|
return $this->entity->shipping_country ? $this->entity->shipping_country->getName() : '';
|
2017-11-19 13:52:42 +01:00
|
|
|
}
|
|
|
|
|
2016-08-07 21:42:32 +02:00
|
|
|
public function balance()
|
|
|
|
{
|
|
|
|
$client = $this->entity;
|
|
|
|
$account = $client->account;
|
|
|
|
|
|
|
|
return $account->formatMoney($client->balance, $client);
|
|
|
|
}
|
|
|
|
|
2017-08-13 15:03:00 +02:00
|
|
|
public function websiteLink()
|
|
|
|
{
|
|
|
|
$client = $this->entity;
|
|
|
|
|
|
|
|
if (! $client->website) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$link = Utils::addHttp($client->website);
|
|
|
|
|
|
|
|
return link_to($link, $client->website, ['target' => '_blank']);
|
|
|
|
}
|
|
|
|
|
2016-08-07 21:42:32 +02:00
|
|
|
public function paid_to_date()
|
|
|
|
{
|
|
|
|
$client = $this->entity;
|
|
|
|
$account = $client->account;
|
|
|
|
|
|
|
|
return $account->formatMoney($client->paid_to_date, $client);
|
|
|
|
}
|
2017-02-01 12:09:26 +01:00
|
|
|
|
|
|
|
public function paymentTerms()
|
|
|
|
{
|
|
|
|
$client = $this->entity;
|
|
|
|
|
|
|
|
if (! $client->payment_terms) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf('%s: %s %s', trans('texts.payment_terms'), trans('texts.payment_terms_net'), $client->defaultDaysDue());
|
|
|
|
}
|
2017-11-05 11:29:29 +01:00
|
|
|
|
2018-02-14 13:05:40 +01:00
|
|
|
public function address($addressType = ADDRESS_BILLING, $showHeader = false)
|
2017-11-19 13:52:42 +01:00
|
|
|
{
|
|
|
|
$str = '';
|
|
|
|
$prefix = $addressType == ADDRESS_BILLING ? '' : 'shipping_';
|
|
|
|
$client = $this->entity;
|
|
|
|
|
|
|
|
if ($address1 = $client->{$prefix . 'address1'}) {
|
|
|
|
$str .= e($address1) . '<br/>';
|
|
|
|
}
|
|
|
|
if ($address2 = $client->{$prefix . 'address2'}) {
|
|
|
|
$str .= e($address2) . '<br/>';
|
|
|
|
}
|
|
|
|
if ($cityState = $this->getCityState($addressType)) {
|
|
|
|
$str .= e($cityState) . '<br/>';
|
|
|
|
}
|
|
|
|
if ($country = $client->{$prefix . 'country'}) {
|
2018-01-21 07:55:40 +01:00
|
|
|
$str .= e($country->getName()) . '<br/>';
|
2017-11-19 13:52:42 +01:00
|
|
|
}
|
|
|
|
|
2018-02-14 13:05:40 +01:00
|
|
|
if ($str && $showHeader) {
|
2017-11-19 13:52:42 +01:00
|
|
|
$str = '<b>' . trans('texts.' . $addressType) . '</b><br/>' . $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getCityState($addressType = ADDRESS_BILLING)
|
|
|
|
{
|
|
|
|
$client = $this->entity;
|
|
|
|
$prefix = $addressType == ADDRESS_BILLING ? '' : 'shipping_';
|
|
|
|
$swap = $client->{$prefix . 'country'} && $client->{$prefix . 'country'}->swap_postal_code;
|
|
|
|
|
|
|
|
$city = e($client->{$prefix . 'city'});
|
|
|
|
$state = e($client->{$prefix . 'state'});
|
|
|
|
$postalCode = e($client->{$prefix . 'post_code'});
|
|
|
|
|
2017-11-19 18:52:28 +01:00
|
|
|
if ($city || $state || $postalCode) {
|
|
|
|
return Utils::cityStateZip($city, $state, $postalCode, $swap);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2017-11-19 13:52:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-05 11:29:29 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function taskRate()
|
|
|
|
{
|
2017-12-25 11:24:39 +01:00
|
|
|
if (floatval($this->entity->task_rate)) {
|
2017-11-05 11:29:29 +01:00
|
|
|
return Utils::roundSignificant($this->entity->task_rate);
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
2017-12-25 11:24:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function defaultTaskRate()
|
|
|
|
{
|
|
|
|
if ($rate = $this->taskRate()) {
|
|
|
|
return $rate;
|
|
|
|
} else {
|
|
|
|
return $this->entity->account->present()->taskRate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-23 11:26:08 +02:00
|
|
|
}
|