2018-11-02 11:54:46 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2018-11-02 11:54:46 +01:00
|
|
|
|
|
|
|
namespace App\Models\Presenters;
|
|
|
|
|
2019-10-05 03:48:00 +02:00
|
|
|
use App\Models\Country;
|
|
|
|
|
2019-01-27 00:22:57 +01:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Class ClientPresenter.
|
2019-01-27 00:22:57 +01:00
|
|
|
*/
|
2018-11-02 11:54:46 +01:00
|
|
|
class ClientPresenter extends EntityPresenter
|
|
|
|
{
|
2019-01-27 00:22:57 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-11-07 06:22:36 +01:00
|
|
|
public function name()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
if ($this->entity->name) {
|
2020-06-08 23:55:31 +02:00
|
|
|
return $this->entity->name;
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|
2020-06-08 23:55:31 +02:00
|
|
|
|
2021-05-04 14:20:55 +02:00
|
|
|
//$contact = $this->entity->primary_contact->first();
|
|
|
|
$contact = $this->entity->contacts->first();
|
2019-10-02 12:22:10 +02:00
|
|
|
|
|
|
|
$contact_name = 'No Contact Set';
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if ($contact && (strlen($contact->first_name) >= 1 || strlen($contact->last_name) >= 1)) {
|
|
|
|
$contact_name = $contact->first_name.' '.$contact->last_name;
|
|
|
|
} elseif ($contact && (strlen($contact->email))) {
|
2020-06-08 23:55:31 +02:00
|
|
|
$contact_name = $contact->email;
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|
2019-10-02 12:22:10 +02:00
|
|
|
|
2020-06-08 23:55:31 +02:00
|
|
|
return $contact_name;
|
2018-11-07 06:22:36 +01:00
|
|
|
}
|
2019-08-21 06:29:07 +02:00
|
|
|
|
2019-09-02 07:08:26 +02:00
|
|
|
public function primary_contact_name()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
return $this->entity->primary_contact->first() !== null ? $this->entity->primary_contact->first()->first_name.' '.$this->entity->primary_contact->first()->last_name : 'No primary contact set';
|
2019-09-02 07:08:26 +02:00
|
|
|
}
|
|
|
|
|
2019-09-16 06:59:59 +02:00
|
|
|
public function email()
|
|
|
|
{
|
|
|
|
return $this->entity->primary_contact->first() !== null ? $this->entity->primary_contact->first()->email : 'No Email Set';
|
|
|
|
}
|
|
|
|
|
2019-08-21 06:29:07 +02:00
|
|
|
public function address()
|
|
|
|
{
|
|
|
|
$str = '';
|
|
|
|
$client = $this->entity;
|
|
|
|
|
|
|
|
if ($address1 = $client->address1) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($address1).'<br/>';
|
2019-08-21 06:29:07 +02:00
|
|
|
}
|
|
|
|
if ($address2 = $client->address2) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($address2).'<br/>';
|
2019-08-21 06:29:07 +02:00
|
|
|
}
|
|
|
|
if ($cityState = $this->getCityState()) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($cityState).'<br/>';
|
2019-08-21 06:29:07 +02:00
|
|
|
}
|
|
|
|
if ($country = $client->country) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($country->name).'<br/>';
|
2019-08-21 06:29:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
2019-08-29 06:58:04 +02:00
|
|
|
public function shipping_address()
|
|
|
|
{
|
|
|
|
$str = '';
|
|
|
|
$client = $this->entity;
|
|
|
|
|
|
|
|
if ($address1 = $client->shipping_address1) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($address1).'<br/>';
|
2019-08-29 06:58:04 +02:00
|
|
|
}
|
|
|
|
if ($address2 = $client->shipping_address2) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($address2).'<br/>';
|
2019-08-29 06:58:04 +02:00
|
|
|
}
|
|
|
|
if ($cityState = $this->getCityState()) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($cityState).'<br/>';
|
2019-08-29 06:58:04 +02:00
|
|
|
}
|
|
|
|
if ($country = $client->country) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($country->name).'<br/>';
|
2019-08-29 06:58:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
2019-09-04 01:16:23 +02:00
|
|
|
public function phone()
|
|
|
|
{
|
|
|
|
return $this->entity->phone ?: '';
|
|
|
|
}
|
2019-08-21 06:29:07 +02:00
|
|
|
|
2019-09-04 01:16:23 +02:00
|
|
|
public function website()
|
|
|
|
{
|
|
|
|
return $this->entity->website ?: '';
|
|
|
|
}
|
2019-10-05 03:48:00 +02:00
|
|
|
|
|
|
|
/**
|
2019-12-30 22:59:12 +01:00
|
|
|
* Calculated company data fields
|
2020-09-06 11:38:10 +02:00
|
|
|
* using settings.
|
2019-10-05 03:48:00 +02:00
|
|
|
*/
|
|
|
|
public function company_name()
|
|
|
|
{
|
|
|
|
$settings = $this->entity->getMergedSettings();
|
|
|
|
|
|
|
|
return $settings->name ?: ctrans('texts.untitled_account');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function company_address()
|
|
|
|
{
|
|
|
|
$settings = $this->entity->getMergedSettings();
|
|
|
|
|
|
|
|
$str = '';
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-10-05 03:48:00 +02:00
|
|
|
if ($settings->address1) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($settings->address1).'<br/>';
|
2019-10-05 03:48:00 +02:00
|
|
|
}
|
|
|
|
if ($settings->address2) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($settings->address2).'<br/>';
|
2019-10-05 03:48:00 +02:00
|
|
|
}
|
|
|
|
if ($cityState = $this->getCityState()) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($cityState).'<br/>';
|
2019-10-05 03:48:00 +02:00
|
|
|
}
|
|
|
|
if ($country = Country::find($settings->country_id)) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($country->name).'<br/>';
|
2019-10-05 03:48:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCityState()
|
|
|
|
{
|
|
|
|
$settings = $this->entity->getMergedSettings();
|
|
|
|
|
|
|
|
$country = false;
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($settings->country_id) {
|
2019-10-05 03:48:00 +02:00
|
|
|
$country = Country::find($settings->country_id);
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-10-05 03:48:00 +02:00
|
|
|
|
|
|
|
$swap = $country && $country->swap_postal_code;
|
|
|
|
|
|
|
|
$city = e($settings->city ?: '');
|
|
|
|
$state = e($settings->state ?: '');
|
|
|
|
$postalCode = e($settings->postal_code ?: '');
|
|
|
|
|
|
|
|
if ($city || $state || $postalCode) {
|
|
|
|
return $this->cityStateZip($city, $state, $postalCode, $swap);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-11-02 11:54:46 +01:00
|
|
|
}
|