Merge pull request #2857 from CihanSenturk/document-show-contact-link

Document show contact link
This commit is contained in:
Cüneyt Şentürk 2023-01-03 11:36:05 +03:00 committed by GitHub
commit 93dda9874d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 92 additions and 11 deletions

View File

@ -9,12 +9,12 @@ use App\Traits\Documents;
use App\Traits\Tailwind; use App\Traits\Tailwind;
use App\Traits\ViewComponents; use App\Traits\ViewComponents;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Intervention\Image\Exception\NotReadableException; use Intervention\Image\Exception\NotReadableException;
use Image; use Image;
use ReflectionProperty;
abstract class Template extends Component abstract class Template extends Component
{ {
@ -95,6 +95,9 @@ abstract class Template extends Component
/** @var string */ /** @var string */
public $textOrderNumber; public $textOrderNumber;
/** @var string */
public $showContactRoute;
public $hideItems; public $hideItems;
public $hideName; public $hideName;
@ -123,6 +126,9 @@ abstract class Template extends Component
public $hideNote; public $hideNote;
/** @var bool */
public $print;
/** /**
* Create a new component instance. * Create a new component instance.
* *
@ -135,9 +141,9 @@ abstract class Template extends Component
bool $hideContactName = false, bool $hideContactAddress = false, bool $hideContactTaxNumber = false, bool $hideContactPhone = false, bool $hideContactEmail = false, bool $hideContactName = false, bool $hideContactAddress = false, bool $hideContactTaxNumber = false, bool $hideContactPhone = false, bool $hideContactEmail = false,
bool $hideOrderNumber = false, bool $hideDocumentNumber = false, bool $hideIssuedAt = false, bool $hideDueAt = false, bool $hideOrderNumber = false, bool $hideDocumentNumber = false, bool $hideIssuedAt = false, bool $hideDueAt = false,
string $textDocumentTitle = '', string $textDocumentSubheading = '', string $textDocumentTitle = '', string $textDocumentSubheading = '',
string $textContactInfo = '', string $textDocumentNumber = '', string $textOrderNumber = '', string $textIssuedAt = '', string $textDueAt = '', string $textContactInfo = '', string $textDocumentNumber = '', string $textOrderNumber = '', string $textIssuedAt = '', string $textDueAt = '', string $showContactRoute = '',
bool $hideItems = false, bool $hideName = false, bool $hideDescription = false, bool $hideQuantity = false, bool $hidePrice = false, bool $hideDiscount = false, bool $hideAmount = false, bool $hideNote = false, bool $hideItems = false, bool $hideName = false, bool $hideDescription = false, bool $hideQuantity = false, bool $hidePrice = false, bool $hideDiscount = false, bool $hideAmount = false, bool $hideNote = false,
string $textItems = '', string $textQuantity = '', string $textPrice = '', string $textAmount = '' string $textItems = '', string $textQuantity = '', string $textPrice = '', string $textAmount = '', bool $print = false
) { ) {
$this->type = $type; $this->type = $type;
$this->item = $item; $this->item = $item;
@ -168,6 +174,7 @@ abstract class Template extends Component
$this->textDocumentTitle = $this->getTextDocumentTitle($type, $textDocumentTitle); $this->textDocumentTitle = $this->getTextDocumentTitle($type, $textDocumentTitle);
$this->textDocumentSubheading = $this->gettextDocumentSubheading($type, $textDocumentSubheading); $this->textDocumentSubheading = $this->gettextDocumentSubheading($type, $textDocumentSubheading);
$this->textContactInfo = $this->getTextContactInfo($type, $textContactInfo); $this->textContactInfo = $this->getTextContactInfo($type, $textContactInfo);
$this->showContactRoute = $this->getShowContactRoute($type, $showContactRoute);
$this->textIssuedAt = $this->getTextIssuedAt($type, $textIssuedAt); $this->textIssuedAt = $this->getTextIssuedAt($type, $textIssuedAt);
$this->textDocumentNumber = $this->getTextDocumentNumber($type, $textDocumentNumber); $this->textDocumentNumber = $this->getTextDocumentNumber($type, $textDocumentNumber);
$this->textDueAt = $this->getTextDueAt($type, $textDueAt); $this->textDueAt = $this->getTextDueAt($type, $textDueAt);
@ -187,6 +194,8 @@ abstract class Template extends Component
$this->textPrice = $this->getTextPrice($type, $textPrice); $this->textPrice = $this->getTextPrice($type, $textPrice);
$this->textAmount = $this->getTextAmount($type, $textAmount); $this->textAmount = $this->getTextAmount($type, $textAmount);
$this->print = $this->getPrint($print);
// Set Parent data // Set Parent data
//$this->setParentData(); //$this->setParentData();
} }
@ -535,6 +544,23 @@ abstract class Template extends Component
return 'general.amount'; return 'general.amount';
} }
protected function getShowContactRoute($type, $showContactRoute)
{
if (! empty($showContactRoute)) {
return $showContactRoute;
}
$route = $this->getRouteFromConfig($type, 'contact.show', 1);
if (!empty($route)) {
return $route;
}
$default_key = Str::plural(config('type.' . static::OBJECT_TYPE . '.' . $type . '.contact_type'), 2);
return $default_key . '.show';
}
protected function getHideItems($type, $hideItems, $hideName, $hideDescription) protected function getHideItems($type, $hideItems, $hideName, $hideDescription)
{ {
if (! empty($hideItems)) { if (! empty($hideItems)) {
@ -677,4 +703,22 @@ abstract class Template extends Component
// @todo what return value invoice or always false?? // @todo what return value invoice or always false??
return setting('invoice.hide_amount', $hideAmount); return setting('invoice.hide_amount', $hideAmount);
} }
protected function getPrint($print)
{
if (! empty($print)) {
return $print;
}
$self = new ReflectionProperty($this::class, 'methodCache');
$self->setAccessible(true);
$values = $self->getValue();
if (array_key_exists('App\View\Components\Layouts\Admin', $values)) {
return false;
}
return true;
}
} }

View File

@ -122,9 +122,20 @@
@stack('name_input_start') @stack('name_input_start')
@if (! $hideContactName) @if (! $hideContactName)
@if ($print)
<p> <p>
{{ $document->contact_name }} {{ $document->contact_name }}
</p> </p>
@else
<x-link href="{{ route($showContactRoute, $document->contact_id) }}"
override="class"
class="py-1.5 mb-3 sm:mb-0 text-xs bg-transparent hover:bg-transparent font-medium leading-6"
>
<x-link.hover>
{{ $document->contact_name }}
</x-link.hover>
</x-link>
@endif
@endif @endif
@stack('name_input_end') @stack('name_input_end')

View File

@ -78,12 +78,27 @@
<div class="col-60"> <div class="col-60">
<div class="text p-index-left"> <div class="text p-index-left">
@if (! $hideContactInfo) @if (! $hideContactInfo)
<p class="font-semibold mb-0">{{ trans($textContactInfo) }}</p> <p class="font-semibold mb-0">
{{ trans($textContactInfo) }}
</p>
@endif @endif
@stack('name_input_start') @stack('name_input_start')
@if (! $hideContactName) @if (! $hideContactName)
<p>{{ $document->contact_name }}</p> @if ($print)
<p>
{{ $document->contact_name }}
</p>
@else
<x-link href="{{ route($showContactRoute, $document->contact_id) }}"
override="class"
class="py-1.5 mb-3 sm:mb-0 text-xs bg-transparent hover:bg-transparent font-medium leading-6"
>
<x-link.hover>
{{ $document->contact_name }}
</x-link.hover>
</x-link>
@endif
@endif @endif
@stack('name_input_end') @stack('name_input_end')

View File

@ -91,9 +91,20 @@
@stack('name_input_start') @stack('name_input_start')
@if (! $hideContactName) @if (! $hideContactName)
@if ($print)
<p> <p>
{{ $document->contact_name }} {{ $document->contact_name }}
</p> </p>
@else
<x-link href="{{ route($showContactRoute, $document->contact_id) }}"
override="class"
class="py-1.5 mb-3 sm:mb-0 text-xs bg-transparent hover:bg-transparent font-medium leading-6"
>
<x-link.hover>
{{ $document->contact_name }}
</x-link.hover>
</x-link>
@endif
@endif @endif
@stack('name_input_end') @stack('name_input_end')