1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Models/Presenters/CompanyPresenter.php

163 lines
4.5 KiB
PHP
Raw Normal View History

<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2019-05-11 05:32:07 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @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
*/
namespace App\Models\Presenters;
use App\Models\Country;
2021-09-14 11:28:10 +02:00
use Illuminate\Support\Str;
2019-01-27 00:22:57 +01:00
/**
* Class CompanyPresenter.
2019-01-27 00:22:57 +01:00
*/
class CompanyPresenter extends EntityPresenter
{
2019-01-27 00:22:57 +01:00
/**
* @return string
*/
public function name()
{
$settings = $this->entity->settings;
return $this->settings->name ?: ctrans('texts.untitled_account');
}
2021-07-24 09:43:16 +02:00
public function logo($settings = null)
2019-09-04 03:45:53 +02:00
{
if (! $settings) {
$settings = $this->entity->settings;
}
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
}
public function address($settings = null)
2019-08-21 06:29:07 +02:00
{
$str = '';
$company = $this->entity;
if (! $settings) {
$settings = $this->entity->settings;
}
if ($address1 = $settings->address1) {
$str .= e($address1).'<br/>';
}
if ($address2 = $settings->address2) {
$str .= e($address2).'<br/>';
}
if ($cityState = $this->getCompanyCityState($settings)) {
$str .= e($cityState).'<br/>';
}
2020-08-07 23:44:49 +02:00
if ($country = Country::find($settings->country_id)) {
$str .= e($country->name).'<br/>';
}
if ($settings->phone) {
$str .= ctrans('texts.work_phone').': '.e($settings->phone).'<br/>';
}
if ($settings->email) {
$str .= ctrans('texts.work_email').': '.e($settings->email).'<br/>';
}
return $str;
2019-08-21 06:29:07 +02:00
}
public function getCompanyCityState($settings = null)
{
if (! $settings) {
$settings = $this->entity->settings;
}
$country = Country::find($settings->country_id);
$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;
}
}
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);
}
}