1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Models/Presenters/CompanyPresenter.php
Benjamin Beganović 8a3f06c039
Merge pull request #6090 from beganovich/v5-2106-change-default-email-logo
(v5) Change default company logo
2021-06-21 14:22:35 +02:00

114 lines
3.1 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Models\Presenters;
use App\Models\Country;
/**
* Class CompanyPresenter.
*/
class CompanyPresenter extends EntityPresenter
{
/**
* @return string
*/
public function name()
{
$settings = $this->entity->settings;
return $this->settings->name ?: ctrans('texts.untitled_account');
//return $this->entity->name ?: ctrans('texts.untitled_account');
}
public function logo($settings = null)
{
if (! $settings) {
$settings = $this->entity->settings;
}
if(strlen($settings->company_logo) >= 1 && (strpos($settings->company_logo, 'http') !== false))
return $settings->company_logo;
else if(strlen($settings->company_logo) >= 1)
return url('') . $settings->company_logo;
else
return asset('images/new_logo.png');
}
public function address($settings = null)
{
$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/>';
}
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;
}
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;
}
}
public function getSpcQrCode($client_currency, $invoice_number, $balance_due_raw, $user_iban)
{
$settings = $this->entity->settings;
return
"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";
}
public function size()
{
return $this->entity->size ? $this->entity->size->name : '';
}
}