Skip to content

Commit

Permalink
fixed #71
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Dec 15, 2017
1 parent 51eb9ed commit e033739
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
41 changes: 38 additions & 3 deletions app/Http/Controllers/Incomes/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
use App\Utilities\Modules;
use Date;
use File;
use Image;
use Storage;

class Invoices extends Controller
{
Expand Down Expand Up @@ -489,7 +491,9 @@ public function emailInvoice(Invoice $invoice)
{
$invoice = $this->prepareInvoice($invoice);

$html = view($invoice->template_path, compact('invoice'))->render();
$logo = $this->getLogo();

$html = view($invoice->template_path, compact('invoice', 'logo'))->render();

$pdf = \App::make('dompdf.wrapper');
$pdf->loadHTML($html);
Expand Down Expand Up @@ -531,7 +535,9 @@ public function printInvoice(Invoice $invoice)
{
$invoice = $this->prepareInvoice($invoice);

return view($invoice->template_path, compact('invoice'));
$logo = $this->getLogo();

return view($invoice->template_path, compact('invoice', 'logo'));
}

/**
Expand All @@ -545,7 +551,9 @@ public function pdfInvoice(Invoice $invoice)
{
$invoice = $this->prepareInvoice($invoice);

$html = view($invoice->template_path, compact('invoice'))->render();
$logo = $this->getLogo();

$html = view($invoice->template_path, compact('invoice', 'logo'))->render();

$pdf = \App::make('dompdf.wrapper');
$pdf->loadHTML($html);
Expand Down Expand Up @@ -759,4 +767,31 @@ protected function addTotals($invoice, $request, $taxes, $sub_total, $tax_total)
'sort_order' => $sort_order,
]);
}

protected function getLogo()
{
$logo = '';

if (setting('general.invoice_logo')) {
$file = session('company_id') . '/' . setting('general.invoice_logo');
} else {
$file = session('company_id') . '/' . setting('general.company_logo');
}

$path = Storage::path($file);
if (!$path) {
return $logo;
}

$extension = File::extension($path);

$image = Image::make($path)->encode()->getEncoded();
if (empty($image)) {
return $logo;
}

$logo = 'data:image/' . $extension . ';base64,' . base64_encode($image);

return $logo;
}
}
6 changes: 1 addition & 5 deletions resources/views/incomes/invoices/invoice.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
<section class="invoice">
<div class="row invoice-header">
<div class="col-xs-7">
@if (setting('general.invoice_logo'))
<img src="{{ Storage::url(setting('general.invoice_logo')) }}" class="invoice-logo" />
@else
<img src="{{ Storage::url(setting('general.company_logo')) }}" class="invoice-logo" />
@endif
<img src="{{ $logo }}" class="invoice-logo" />
</div>
<div class="col-xs-5 invoice-company">
<address>
Expand Down

0 comments on commit e033739

Please sign in to comment.