diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index cf9f87688..49428a7a9 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -8,8 +8,10 @@ use App\Models\Common\Media; use File; use Image; use Storage; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\URL; use Illuminate\Support\Str; +use Intervention\Image\Exception\NotReadableException; abstract class DocumentShow extends Base { @@ -599,11 +601,26 @@ abstract class DocumentShow extends Base $path = base_path('public/img/company.png'); } - $image = Image::cache(function($image) use ($path) { - $width = $height = setting('invoice.logo_size', 128); + try { + $image = Image::cache(function($image) use ($path) { + $width = setting('invoice.logo_size_width'); + $height = setting('invoice.logo_size_height'); - $image->make($path)->resize($width, $height)->encode(); - }); + $image->make($path)->resize($width, $height)->encode(); + }); + } catch (NotReadableException | \Exception $e) { + Log::info('Company ID: ' . session('company_id') . ' components/documentshow.php exception.'); + Log::info($e->getMessage()); + + $path = base_path('public/img/company.png'); + + $image = Image::cache(function($image) use ($path) { + $width = setting('invoice.logo_size_width'); + $height = setting('invoice.logo_size_height'); + + $image->make($path)->resize($width, $height)->encode(); + }); + } if (empty($image)) { return $logo; diff --git a/app/Abstracts/View/Components/DocumentTemplate.php b/app/Abstracts/View/Components/DocumentTemplate.php index 798dcdbf8..4a29f05ac 100644 --- a/app/Abstracts/View/Components/DocumentTemplate.php +++ b/app/Abstracts/View/Components/DocumentTemplate.php @@ -6,9 +6,11 @@ use App\Abstracts\View\Components\Document as Base; use App\Traits\DateTime; use App\Models\Common\Media; use File; +use Illuminate\Support\Facades\Log; +use Illuminate\Support\Str; +use Intervention\Image\Exception\NotReadableException; use Image; use Storage; -use Illuminate\Support\Str; abstract class DocumentTemplate extends Base { @@ -202,11 +204,26 @@ abstract class DocumentTemplate extends Base $path = base_path('public/img/company.png'); } - $image = Image::cache(function($image) use ($path) { - $width = $height = setting('invoice.logo_size', 128); + try { + $image = Image::cache(function($image) use ($path) { + $width = setting('invoice.logo_size_width'); + $height = setting('invoice.logo_size_height'); - $image->make($path)->resize($width, $height)->encode(); - }); + $image->make($path)->resize($width, $height)->encode(); + }); + } catch (NotReadableException | \Exception $e) { + Log::info('Company ID: ' . session('company_id') . ' components/documentshow.php exception.'); + Log::info($e->getMessage()); + + $path = base_path('public/img/company.png'); + + $image = Image::cache(function($image) use ($path) { + $width = setting('invoice.logo_size_width'); + $height = setting('invoice.logo_size_height'); + + $image->make($path)->resize($width, $height)->encode(); + }); + } if (empty($image)) { return $logo; diff --git a/app/Http/Requests/Document/Document.php b/app/Http/Requests/Document/Document.php index fc1da618d..a82fa3f00 100644 --- a/app/Http/Requests/Document/Document.php +++ b/app/Http/Requests/Document/Document.php @@ -37,6 +37,12 @@ class Document extends FormRequest $id = null; } + $company_logo = 'nullable'; + + if ($this->request->get('company_logo', null)) { + $company_logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024; + } + $attachment = 'nullable'; if ($this->request->get('attachment', null)) { @@ -61,6 +67,7 @@ class Document extends FormRequest 'contact_id' => 'required|integer', 'contact_name' => 'required|string', 'category_id' => 'required|integer', + 'company_logo' => $company_logo, 'attachment.*' => $attachment, ]; } diff --git a/app/Http/ViewComposers/Logo.php b/app/Http/ViewComposers/Logo.php index 785153901..53a759131 100644 --- a/app/Http/ViewComposers/Logo.php +++ b/app/Http/ViewComposers/Logo.php @@ -3,10 +3,12 @@ namespace App\Http\ViewComposers; use App\Models\Common\Media; -use Illuminate\View\View; use File; use Image; use Storage; +use Illuminate\View\View; +use Illuminate\Support\Facades\Log; +use Intervention\Image\Exception\NotReadableException; class Logo { @@ -32,12 +34,26 @@ class Logo $path = base_path('public/img/company.png'); } - $image = Image::cache(function($image) use ($path) { - $width = setting('invoice.logo_size_width'); - $height = setting('invoice.logo_size_height'); + try { + $image = Image::cache(function($image) use ($path) { + $width = setting('invoice.logo_size_width'); + $height = setting('invoice.logo_size_height'); - $image->make($path)->resize($width, $height)->encode(); - }); + $image->make($path)->resize($width, $height)->encode(); + }); + } catch (NotReadableException | \Exception $e) { + Log::info('Company ID: ' . session('company_id') . ' viewcomposer/logo.php exception.'); + Log::info($e->getMessage()); + + $path = base_path('public/img/company.png'); + + $image = Image::cache(function($image) use ($path) { + $width = setting('invoice.logo_size_width'); + $height = setting('invoice.logo_size_height'); + + $image->make($path)->resize($width, $height)->encode(); + }); + } if (empty($image)) { return $logo;