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
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-11 05:32:07 +02:00
|
|
|
*/
|
2018-11-02 11:54:46 +01:00
|
|
|
|
|
|
|
namespace App\Models\Presenters;
|
|
|
|
|
2019-12-16 12:34:38 +01:00
|
|
|
use App\Models\Country;
|
2021-09-14 11:28:10 +02:00
|
|
|
use Illuminate\Support\Str;
|
2019-12-16 12:34:38 +01:00
|
|
|
|
2019-01-27 00:22:57 +01:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Class CompanyPresenter.
|
2019-01-27 00:22:57 +01:00
|
|
|
*/
|
2018-11-02 11:54:46 +01:00
|
|
|
class CompanyPresenter extends EntityPresenter
|
|
|
|
{
|
2019-01-27 00:22:57 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-11-02 11:54:46 +01:00
|
|
|
public function name()
|
|
|
|
{
|
2020-02-05 05:06:03 +01:00
|
|
|
$settings = $this->entity->settings;
|
|
|
|
|
|
|
|
return $this->settings->name ?: ctrans('texts.untitled_account');
|
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
}
|
|
|
|
|
2021-07-24 09:43:16 +02:00
|
|
|
|
|
|
|
public function logo($settings = null)
|
2019-09-04 03:45:53 +02:00
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $settings) {
|
2019-12-16 12:34:38 +01:00
|
|
|
$settings = $this->entity->settings;
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-12-16 12:34:38 +01:00
|
|
|
|
2021-03-09 21:56:23 +01:00
|
|
|
if(strlen($settings->company_logo) >= 1 && (strpos($settings->company_logo, 'http') !== false))
|
2021-03-01 21:15:28 +01:00
|
|
|
return $settings->company_logo;
|
|
|
|
else if(strlen($settings->company_logo) >= 1)
|
|
|
|
return url('') . $settings->company_logo;
|
2021-03-01 12:00:07 +01:00
|
|
|
else
|
2021-06-21 07:01:15 +02:00
|
|
|
return asset('images/new_logo.png');
|
2021-03-01 12:00:07 +01:00
|
|
|
|
2019-09-04 03:45:53 +02:00
|
|
|
}
|
|
|
|
|
2021-07-24 09:43:16 +02:00
|
|
|
/**
|
|
|
|
* Test for using base64 encoding
|
|
|
|
*/
|
2021-07-25 13:51:41 +02:00
|
|
|
public function logo_base64($settings = null)
|
2021-07-24 09:29:33 +02:00
|
|
|
{
|
|
|
|
if (! $settings) {
|
|
|
|
$settings = $this->entity->settings;
|
|
|
|
}
|
|
|
|
|
2021-09-05 11:40:50 +02:00
|
|
|
if(config('ninja.is_docker') || config('ninja.local_download'))
|
2021-07-31 11:59:04 +02:00
|
|
|
return $this->logo($settings);
|
|
|
|
|
2021-07-30 02:37:32 +02:00
|
|
|
$context_options =array(
|
|
|
|
"ssl"=>array(
|
|
|
|
"verify_peer"=>false,
|
|
|
|
"verify_peer_name"=>false,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-07-24 09:29:33 +02:00
|
|
|
if(strlen($settings->company_logo) >= 1 && (strpos($settings->company_logo, 'http') !== false))
|
2021-07-30 02:37:32 +02:00
|
|
|
return "data:image/png;base64, ". base64_encode(file_get_contents($settings->company_logo, false, stream_context_create($context_options)));
|
2021-07-24 09:29:33 +02:00
|
|
|
else if(strlen($settings->company_logo) >= 1)
|
2021-07-30 02:37:32 +02:00
|
|
|
return "data:image/png;base64, ". base64_encode(file_get_contents(url('') . $settings->company_logo, false, stream_context_create($context_options)));
|
2021-07-24 09:29:33 +02:00
|
|
|
else
|
2021-07-30 02:37:32 +02:00
|
|
|
return "data:image/png;base64, ". base64_encode(file_get_contents(asset('images/new_logo.png'), false, stream_context_create($context_options)));
|
2021-07-24 09:29:33 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-12-16 12:34:38 +01:00
|
|
|
public function address($settings = null)
|
2019-08-21 06:29:07 +02:00
|
|
|
{
|
2019-08-21 23:46:11 +02:00
|
|
|
$str = '';
|
|
|
|
$company = $this->entity;
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $settings) {
|
2019-12-16 12:34:38 +01:00
|
|
|
$settings = $this->entity->settings;
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-12-16 12:34:38 +01:00
|
|
|
|
|
|
|
if ($address1 = $settings->address1) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($address1).'<br/>';
|
2019-08-21 23:46:11 +02:00
|
|
|
}
|
2019-12-16 12:34:38 +01:00
|
|
|
if ($address2 = $settings->address2) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($address2).'<br/>';
|
2019-08-21 23:46:11 +02:00
|
|
|
}
|
2019-12-16 12:34:38 +01:00
|
|
|
if ($cityState = $this->getCompanyCityState($settings)) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($cityState).'<br/>';
|
2019-08-21 23:46:11 +02:00
|
|
|
}
|
2020-08-07 23:44:49 +02:00
|
|
|
if ($country = Country::find($settings->country_id)) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= e($country->name).'<br/>';
|
2019-08-21 23:46:11 +02:00
|
|
|
}
|
2019-12-16 12:34:38 +01:00
|
|
|
if ($settings->phone) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= ctrans('texts.work_phone').': '.e($settings->phone).'<br/>';
|
2019-08-21 23:46:11 +02:00
|
|
|
}
|
2019-12-16 12:34:38 +01:00
|
|
|
if ($settings->email) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$str .= ctrans('texts.work_email').': '.e($settings->email).'<br/>';
|
2019-08-21 23:46:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $str;
|
2019-08-21 06:29:07 +02:00
|
|
|
}
|
|
|
|
|
2019-12-16 12:34:38 +01:00
|
|
|
public function getCompanyCityState($settings = null)
|
2019-10-04 14:37:40 +02:00
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $settings) {
|
2019-12-16 12:34:38 +01:00
|
|
|
$settings = $this->entity->settings;
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-12-16 12:34:38 +01:00
|
|
|
|
2020-10-18 23:21:14 +02:00
|
|
|
$country = Country::find($settings->country_id);
|
2019-10-04 14:37:40 +02:00
|
|
|
|
2019-12-16 12:34:38 +01:00
|
|
|
$swap = $country && $country->swap_postal_code;
|
2019-10-04 14:37:40 +02:00
|
|
|
|
2019-12-16 12:34:38 +01:00
|
|
|
$city = e($settings->city);
|
|
|
|
$state = e($settings->state);
|
|
|
|
$postalCode = e($settings->postal_code);
|
2019-10-04 14:37:40 +02:00
|
|
|
|
|
|
|
if ($city || $state || $postalCode) {
|
|
|
|
return $this->cityStateZip($city, $state, $postalCode, $swap);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2021-01-21 13:34:21 +01:00
|
|
|
|
2021-03-26 20:30:46 +01:00
|
|
|
public function getSpcQrCode($client_currency, $invoice_number, $balance_due_raw, $user_iban)
|
2021-01-21 13:34:21 +01:00
|
|
|
{
|
|
|
|
$settings = $this->entity->settings;
|
|
|
|
|
2021-06-21 07:01:15 +02:00
|
|
|
return
|
2021-01-21 13:34:21 +01:00
|
|
|
|
2021-03-26 20:21:47 +01:00
|
|
|
"SPC\n0200\n1\n{$user_iban}\nK\n{$this->name}\n{$settings->address1}\n{$settings->postal_code} {$settings->city}\n\n\nCH\n\n\n\n\n\n\n\n{$balance_due_raw}\n{$client_currency}\n\n\n\n\n\n\n\nNON\n\n{$invoice_number}\nEPD\n";
|
2021-01-21 13:34:21 +01:00
|
|
|
}
|
|
|
|
|
2021-05-06 06:39:18 +02:00
|
|
|
public function size()
|
|
|
|
{
|
|
|
|
return $this->entity->size ? $this->entity->size->name : '';
|
|
|
|
}
|
2021-09-14 11:28:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return company website URL.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function website(): string
|
|
|
|
{
|
|
|
|
$website = $this->entity->getSetting('website');
|
|
|
|
|
|
|
|
if (empty($website)) {
|
|
|
|
return $website;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Str::contains($website, ['http', 'https'])) {
|
|
|
|
return $website;
|
|
|
|
}
|
|
|
|
|
|
|
|
return \sprintf('http://%s', $website);
|
|
|
|
}
|
2018-11-02 11:54:46 +01:00
|
|
|
}
|