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

202 lines
5.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
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. 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;
use Illuminate\Support\Facades\Storage;
2023-02-16 02:36:09 +01: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;
}
2023-02-16 02:36:09 +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;
2023-02-16 02:36:09 +01:00
} elseif (strlen($settings->company_logo) >= 1) {
2021-03-01 21:15:28 +01:00
return url('') . $settings->company_logo;
2023-02-16 02:36:09 +01:00
} else {
return asset('images/blank.png');
2022-11-13 22:10:22 +01:00
}
2019-09-04 03:45:53 +02:00
}
2022-07-25 01:01:15 +02:00
public function logoDocker($settings = null)
{
if (! $settings) {
$settings = $this->entity->settings;
}
$basename = basename($this->settings->company_logo);
$logo = Storage::get("{$this->company_key}/{$basename}");
2023-02-16 02:36:09 +01:00
if (!$logo) {
2022-07-25 01:01:15 +02:00
return $this->logo($settings);
2023-02-16 02:36:09 +01:00
}
2022-07-25 01:01:15 +02:00
return "data:image/png;base64, ". base64_encode($logo);
}
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;
}
2023-02-16 02:36:09 +01:00
if (config('ninja.is_docker') || config('ninja.local_download')) {
2022-07-25 01:01:15 +02:00
return $this->logoDocker($settings);
2023-02-16 02:36:09 +01:00
}
2021-07-31 11:59:04 +02:00
2023-02-16 02:36:09 +01:00
$context_options =[
"ssl"=>[
2021-07-30 02:37:32 +02:00
"verify_peer"=>false,
"verify_peer_name"=>false,
2023-02-16 02:36:09 +01:00
],
];
2021-07-30 02:37:32 +02:00
2023-02-16 02:36:09 +01:00
if (strlen($settings->company_logo) >= 1 && (strpos($settings->company_logo, 'http') !== false)) {
return "data:image/png;base64, ". base64_encode(@file_get_contents($settings->company_logo, false, stream_context_create($context_options)));
2023-02-16 02:36:09 +01:00
} elseif (strlen($settings->company_logo) >= 1) {
return "data:image/png;base64, ". base64_encode(@file_get_contents(url('') . $settings->company_logo, false, stream_context_create($context_options)));
2023-02-16 02:36:09 +01:00
} else {
2022-11-13 22:09:08 +01:00
return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
//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.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
2022-06-30 05:34:15 +02:00
public function address1()
{
2022-06-30 06:29:18 +02:00
return $this->entity->settings->address1;
2022-06-30 05:34:15 +02:00
}
public function address2()
{
2022-06-30 06:29:18 +02:00
return $this->entity->settings->address2;
2022-06-30 05:34:15 +02:00
}
public function qr_iban()
{
2022-06-30 06:29:18 +02:00
return $this->entity->getSetting('qr_iban');
2022-06-30 05:34:15 +02:00
}
2022-06-30 08:09:06 +02:00
public function besr_id()
{
return $this->entity->getSetting('besr_id');
}
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.
2023-02-16 02:36:09 +01:00
*
* @return string
2021-09-14 11:28:10 +02:00
*/
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);
}
}