diff --git a/app/Http/Controllers/Expenses/Bills.php b/app/Http/Controllers/Expenses/Bills.php index 5330d572e..f938875a4 100644 --- a/app/Http/Controllers/Expenses/Bills.php +++ b/app/Http/Controllers/Expenses/Bills.php @@ -511,9 +511,7 @@ class Bills extends Controller { $bill = $this->prepareBill($bill); - $logo = $this->getLogo($bill); - - return view($bill->template_path, compact('bill', 'logo')); + return view($bill->template_path, compact('bill')); } /** @@ -527,9 +525,7 @@ class Bills extends Controller { $bill = $this->prepareBill($bill); - $logo = $this->getLogo($bill); - - $html = view($bill->template_path, compact('bill', 'logo'))->render(); + $html = view($bill->template_path, compact('bill'))->render(); $pdf = \App::make('dompdf.wrapper'); $pdf->loadHTML($html); @@ -736,39 +732,4 @@ class Bills extends Controller 'sort_order' => $sort_order, ]); } - - protected function getLogo($bill) - { - $logo = ''; - - $media_id = setting('general.company_logo'); - - if (isset($bill->vendor->logo) && !empty($bill->vendor->logo->id)) { - $media_id = $bill->vendor->logo->id; - } - - $media = Media::find($media_id); - - if (!empty($media)) { - $path = Storage::path($media->getDiskPath()); - - if (!is_file($path)) { - return $logo; - } - } else { - $path = asset('public/img/company.png'); - } - - $image = Image::make($path)->encode()->getEncoded(); - - if (empty($image)) { - return $logo; - } - - $extension = File::extension($path); - - $logo = 'data:image/' . $extension . ';base64,' . base64_encode($image); - - return $logo; - } } diff --git a/app/Http/Controllers/Incomes/Invoices.php b/app/Http/Controllers/Incomes/Invoices.php index 0be49efa2..6837ba86a 100644 --- a/app/Http/Controllers/Incomes/Invoices.php +++ b/app/Http/Controllers/Incomes/Invoices.php @@ -107,17 +107,9 @@ class Invoices extends Controller $categories = Category::enabled()->type('income')->pluck('name', 'id'); - $recurrings = [ - '0' => trans('general.no'), - '1' => trans('recurring.weekly'), - '2' => trans('recurring.monthly'), - '3' => trans('recurring.yearly'), - '4' => trans('recurring.custom'), - ]; - $number = $this->getNextInvoiceNumber(); - return view('incomes.invoices.create', compact('customers', 'currencies', 'items', 'taxes', 'categories', 'recurrings', 'number')); + return view('incomes.invoices.create', compact('customers', 'currencies', 'items', 'taxes', 'categories', 'number')); } /** @@ -554,9 +546,7 @@ class Invoices extends Controller $invoice = $this->prepareInvoice($invoice); - $logo = $this->getLogo(); - - $html = view($invoice->template_path, compact('invoice', 'logo'))->render(); + $html = view($invoice->template_path, compact('invoice'))->render(); $pdf = \App::make('dompdf.wrapper'); $pdf->loadHTML($html); @@ -610,9 +600,7 @@ class Invoices extends Controller { $invoice = $this->prepareInvoice($invoice); - $logo = $this->getLogo(); - - return view($invoice->template_path, compact('invoice', 'logo')); + return view($invoice->template_path, compact('invoice')); } /** @@ -626,9 +614,7 @@ class Invoices extends Controller { $invoice = $this->prepareInvoice($invoice); - $logo = $this->getLogo(); - - $html = view($invoice->template_path, compact('invoice', 'logo'))->render(); + $html = view($invoice->template_path, compact('invoice'))->render(); $pdf = \App::make('dompdf.wrapper'); $pdf->loadHTML($html); @@ -877,39 +863,4 @@ class Invoices extends Controller 'sort_order' => $sort_order, ]); } - - protected function getLogo() - { - $logo = ''; - - $media_id = setting('general.company_logo'); - - if (setting('general.invoice_logo')) { - $media_id = setting('general.invoice_logo'); - } - - $media = Media::find($media_id); - - if (!empty($media)) { - $path = Storage::path($media->getDiskPath()); - - if (!is_file($path)) { - return $logo; - } - } else { - $path = asset('public/img/company.png'); - } - - $image = Image::make($path)->encode()->getEncoded(); - - if (empty($image)) { - return $logo; - } - - $extension = File::extension($path); - - $logo = 'data:image/' . $extension . ';base64,' . base64_encode($image); - - return $logo; - } } diff --git a/app/Http/ViewComposers/Logo.php b/app/Http/ViewComposers/Logo.php new file mode 100644 index 000000000..8d3b7f681 --- /dev/null +++ b/app/Http/ViewComposers/Logo.php @@ -0,0 +1,54 @@ +getDiskPath()); + + if (!is_file($path)) { + return $logo; + } + } else { + $path = asset('public/img/company.png'); + } + + $image = Image::make($path)->encode()->getEncoded(); + + if (empty($image)) { + return $logo; + } + + $extension = File::extension($path); + + $logo = 'data:image/' . $extension . ';base64,' . base64_encode($image); + + $view->with(['logo' => $logo]); + } +} diff --git a/app/Providers/ViewComposerServiceProvider.php b/app/Providers/ViewComposerServiceProvider.php index fc9574a5e..97e01dc2e 100644 --- a/app/Providers/ViewComposerServiceProvider.php +++ b/app/Providers/ViewComposerServiceProvider.php @@ -38,6 +38,11 @@ class ViewComposerServiceProvider extends ServiceProvider View::composer( 'modules.*', 'App\Http\ViewComposers\Modules' ); + + // Add logo + View::composer( + ['incomes.invoices.invoice', 'expenses.bills.bill'], 'App\Http\ViewComposers\Logo' + ); } /**