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
|
|
|
|
*
|
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
|
|
|
*/
|
2018-11-02 11:54:46 +01:00
|
|
|
|
|
|
|
namespace App\Models\Presenters;
|
|
|
|
|
2019-12-16 12:34:38 +01:00
|
|
|
use App\Models\Country;
|
2022-07-25 02:47:18 +02:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2023-02-16 02:36:09 +01: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.
|
2023-08-01 12:30:47 +02:00
|
|
|
* @property \App\DataMapper\CompanySettings $settings
|
2019-01-27 00:22:57 +01:00
|
|
|
*/
|
2018-11-02 11:54:46 +01:00
|
|
|
class CompanyPresenter extends EntityPresenter
|
|
|
|
{
|
2023-08-01 12:30:47 +02:00
|
|
|
|
|
|
|
|
2019-01-27 00:22:57 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2023-08-01 12:30:47 +02:00
|
|
|
public function name(): string
|
2018-11-02 11:54:46 +01:00
|
|
|
{
|
2020-02-05 05:06:03 +01:00
|
|
|
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
|
|
|
|
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 {
|
2023-02-19 08:15:54 +01:00
|
|
|
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)) {
|
2022-03-25 05:16:39 +01:00
|
|
|
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) {
|
2022-03-25 05:16:39 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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) {
|
2022-11-30 01:46:02 +01:00
|
|
|
$str .= ctrans('texts.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
|
|
|
|
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);
|
|
|
|
}
|
2018-11-02 11:54:46 +01:00
|
|
|
}
|