close #222 Fixed: invoice logo in customer account
This commit is contained in:
parent
0f87195254
commit
71e5c80296
@ -3,16 +3,21 @@
|
||||
namespace App\Http\Controllers\Customers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Events\InvoicePrinting;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Models\Income\Customer;
|
||||
use App\Models\Income\Invoice;
|
||||
use App\Models\Income\InvoiceStatus;
|
||||
use App\Models\Setting\Category;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Models\Common\Media;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
use App\Traits\Uploads;
|
||||
use App\Utilities\Modules;
|
||||
use File;
|
||||
use Image;
|
||||
use Storage;
|
||||
|
||||
class Invoices extends Controller
|
||||
{
|
||||
@ -42,25 +47,15 @@ class Invoices extends Controller
|
||||
*/
|
||||
public function show(Invoice $invoice)
|
||||
{
|
||||
$sub_total = 0;
|
||||
$tax_total = 0;
|
||||
$paid = 0;
|
||||
|
||||
foreach ($invoice->items as $item) {
|
||||
$sub_total += ($item->price * $item->quantity);
|
||||
$tax_total += ($item->tax * $item->quantity);
|
||||
}
|
||||
|
||||
foreach ($invoice->payments as $item) {
|
||||
$item->default_currency_code = $invoice->currency_code;
|
||||
|
||||
$paid += $item->getDynamicConvertedAmount();
|
||||
}
|
||||
|
||||
$invoice->sub_total = $sub_total;
|
||||
$invoice->tax_total = $tax_total;
|
||||
$invoice->paid = $paid;
|
||||
$invoice->grand_total = (($sub_total + $tax_total) - $paid);
|
||||
|
||||
$accounts = Account::enabled()->pluck('name', 'id');
|
||||
|
||||
@ -86,27 +81,11 @@ class Invoices extends Controller
|
||||
*/
|
||||
public function printInvoice(Invoice $invoice)
|
||||
{
|
||||
$sub_total = 0;
|
||||
$tax_total = 0;
|
||||
$paid = 0;
|
||||
$invoice = $this->prepareInvoice($invoice);
|
||||
|
||||
foreach ($invoice->items as $item) {
|
||||
$sub_total += ($item->price * $item->quantity);
|
||||
$tax_total += ($item->tax * $item->quantity);
|
||||
}
|
||||
$logo = $this->getLogo();
|
||||
|
||||
foreach ($invoice->payments as $item) {
|
||||
$item->default_currency_code = $invoice->currency_code;
|
||||
|
||||
$paid += $item->getDynamicConvertedAmount();
|
||||
}
|
||||
|
||||
$invoice->sub_total = $sub_total;
|
||||
$invoice->tax_total = $tax_total;
|
||||
$invoice->paid = $paid;
|
||||
$invoice->grand_total = (($sub_total + $tax_total) - $paid);
|
||||
|
||||
return view('customers.invoices.invoice', compact('invoice'));
|
||||
return view($invoice->template_path, compact('invoice', 'logo'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,14 +97,25 @@ class Invoices extends Controller
|
||||
*/
|
||||
public function pdfInvoice(Invoice $invoice)
|
||||
{
|
||||
$sub_total = 0;
|
||||
$tax_total = 0;
|
||||
$paid = 0;
|
||||
$invoice = $this->prepareInvoice($invoice);
|
||||
|
||||
foreach ($invoice->items as $item) {
|
||||
$sub_total += ($item->price * $item->quantity);
|
||||
$tax_total += ($item->tax * $item->quantity);
|
||||
}
|
||||
$logo = $this->getLogo();
|
||||
|
||||
$html = view($invoice->template_path, compact('invoice', 'logo'))->render();
|
||||
|
||||
$pdf = \App::make('dompdf.wrapper');
|
||||
$pdf->loadHTML($html);
|
||||
|
||||
//$pdf->setPaper('A4', 'portrait');
|
||||
|
||||
$file_name = 'invoice_' . time() . '.pdf';
|
||||
|
||||
return $pdf->download($file_name);
|
||||
}
|
||||
|
||||
protected function prepareInvoice(Invoice $invoice)
|
||||
{
|
||||
$paid = 0;
|
||||
|
||||
foreach ($invoice->payments as $item) {
|
||||
$item->default_currency_code = $invoice->currency_code;
|
||||
@ -133,18 +123,47 @@ class Invoices extends Controller
|
||||
$paid += $item->getDynamicConvertedAmount();
|
||||
}
|
||||
|
||||
$invoice->sub_total = $sub_total;
|
||||
$invoice->tax_total = $tax_total;
|
||||
$invoice->paid = $paid;
|
||||
$invoice->grand_total = (($sub_total + $tax_total) - $paid);
|
||||
|
||||
$html = view('incomes.invoices.invoice', compact('invoice'))->render();
|
||||
$invoice->template_path = 'incomes.invoices.invoice';
|
||||
|
||||
$pdf = \App::make('dompdf.wrapper');
|
||||
$pdf->loadHTML($html);
|
||||
event(new InvoicePrinting($invoice));
|
||||
|
||||
$file_name = 'invoice_'.time().'.pdf';
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
return $pdf->download($file_name);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -793,14 +793,14 @@ class Invoices extends Controller
|
||||
|
||||
$media = Media::find($media_id);
|
||||
|
||||
if (empty($media)) {
|
||||
return $logo;
|
||||
}
|
||||
if (!empty($media)) {
|
||||
$path = Storage::path($media->getDiskPath());
|
||||
|
||||
$path = Storage::path($media->getDiskPath());
|
||||
|
||||
if (!is_file($path)) {
|
||||
return $logo;
|
||||
if (!is_file($path)) {
|
||||
return $logo;
|
||||
}
|
||||
} else {
|
||||
$path = asset('public/img/company.png');
|
||||
}
|
||||
|
||||
$image = Image::make($path)->encode()->getEncoded();
|
||||
|
@ -6,10 +6,8 @@
|
||||
<section class="invoice">
|
||||
<div class="row invoice-header">
|
||||
<div class="col-xs-7">
|
||||
@if (setting('general.invoice_logo'))
|
||||
<img src="{{ asset(setting('general.invoice_logo')) }}" class="invoice-logo" />
|
||||
@else
|
||||
<img src="{{ asset(setting('general.company_logo')) }}" class="invoice-logo" />
|
||||
@if ($logo)
|
||||
<img src="{{ $logo }}" class="invoice-logo" />
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-xs-5 invoice-company">
|
||||
@ -92,7 +90,7 @@
|
||||
</td>
|
||||
<td class="text-center">{{ $item->quantity }}</td>
|
||||
<td class="text-right">@money($item->price, $invoice->currency_code, true)</td>
|
||||
<td class="text-right">@money($item->total - $item->tax, $invoice->currency_code, true)</td>
|
||||
<td class="text-right">@money($item->total, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
@ -114,24 +112,25 @@
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th style="max-width: 214px">{{ trans('invoices.sub_total') }}:</th>
|
||||
<td class="text-right">@money($invoice->sub_total, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{{ trans('invoices.tax_total') }}:</th>
|
||||
<td class="text-right">@money($invoice->tax_total, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
@if($invoice->paid)
|
||||
<tr>
|
||||
<th>{{ trans('invoices.paid') }}:</th>
|
||||
<td class="text-right">@money('-' . $invoice->paid, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
@endif
|
||||
<tr>
|
||||
<th>{{ trans('invoices.total') }}:</th>
|
||||
<td class="text-right">@money($invoice->grand_total, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
@foreach($invoice->totals as $total)
|
||||
@if($total->code != 'total')
|
||||
<tr>
|
||||
<th>{{ trans($total['name']) }}:</th>
|
||||
<td class="text-right">@money($total->amount, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
@else
|
||||
@if ($invoice->paid)
|
||||
<tr class="text-success">
|
||||
<th>{{ trans('invoices.paid') }}:</th>
|
||||
<td class="text-right">- @money($invoice->paid, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
@endif
|
||||
<tr>
|
||||
<th>{{ trans($total['name']) }}:</th>
|
||||
<td class="text-right">@money($total->amount - $invoice->paid, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
@endif
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -10,9 +10,11 @@
|
||||
<div class="row invoice-header">
|
||||
<div class="col-xs-7">
|
||||
@if (setting('general.invoice_logo'))
|
||||
<img src="{{ asset(setting('general.invoice_logo')) }}" class="invoice-logo" />
|
||||
<img src="{{ Storage::url(setting('general.invoice_logo')) }}" class="invoice-logo" />
|
||||
@elseif (setting('general.company_logo'))
|
||||
<img src="{{ Storage::url(setting('general.company_logo')) }}" class="invoice-logo" />
|
||||
@else
|
||||
<img src="{{ asset(setting('general.company_logo')) }}" class="invoice-logo" />
|
||||
<img src="{{ asset('public/img/company.png') }}" class="invoice-logo" />
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-xs-5 invoice-company">
|
||||
@ -95,7 +97,7 @@
|
||||
</td>
|
||||
<td class="text-center">{{ $item->quantity }}</td>
|
||||
<td class="text-right">@money($item->price, $invoice->currency_code, true)</td>
|
||||
<td class="text-right">@money($item->total - $item->tax, $invoice->currency_code, true)</td>
|
||||
<td class="text-right">@money($item->total, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
@ -117,24 +119,25 @@
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>{{ trans('invoices.sub_total') }}:</th>
|
||||
<td class="text-right">@money($invoice->sub_total, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{{ trans('invoices.tax_total') }}:</th>
|
||||
<td class="text-right">@money($invoice->tax_total, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
@if ($invoice->paid)
|
||||
<tr>
|
||||
<th>{{ trans('invoices.paid') }}:</th>
|
||||
<td class="text-right">@money('-' . $invoice->paid, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
@endif
|
||||
<tr>
|
||||
<th>{{ trans('invoices.total') }}:</th>
|
||||
<td class="text-right">@money($invoice->grand_total, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
@foreach($invoice->totals as $total)
|
||||
@if($total->code != 'total')
|
||||
<tr>
|
||||
<th>{{ trans($total['name']) }}:</th>
|
||||
<td class="text-right">@money($total->amount, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
@else
|
||||
@if ($invoice->paid)
|
||||
<tr class="text-success">
|
||||
<th>{{ trans('invoices.paid') }}:</th>
|
||||
<td class="text-right">- @money($invoice->paid, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
@endif
|
||||
<tr>
|
||||
<th>{{ trans($total['name']) }}:</th>
|
||||
<td class="text-right">@money($total->amount - $invoice->paid, $invoice->currency_code, true)</td>
|
||||
</tr>
|
||||
@endif
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@ -143,10 +146,10 @@
|
||||
|
||||
<div class="box-footer row no-print">
|
||||
<div class="col-md-10">
|
||||
<a href="{{ url('incomes/invoices/' . $invoice->id . '/print') }}" target="_blank" class="btn btn-default">
|
||||
<a href="{{ url('customers/invoices/' . $invoice->id . '/print') }}" target="_blank" class="btn btn-default">
|
||||
<i class="fa fa-print"></i> {{ trans('general.print') }}
|
||||
</a>
|
||||
<a href="{{ url('incomes/invoices/' . $invoice->id . '/pdf') }}" class="btn btn-default" data-toggle="tooltip" title="{{ trans('invoices.download_pdf') }}">
|
||||
<a href="{{ url('customers/invoices/' . $invoice->id . '/pdf') }}" class="btn btn-default" data-toggle="tooltip" title="{{ trans('invoices.download_pdf') }}">
|
||||
<i class="fa fa-file-pdf-o"></i> {{ trans('general.download') }}
|
||||
</a>
|
||||
</div>
|
||||
|
@ -10,9 +10,11 @@
|
||||
<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" />
|
||||
<img src="{{ Storage::url(setting('general.invoice_logo')) }}" class="invoice-logo" />
|
||||
@elseif (setting('general.company_logo'))
|
||||
<img src="{{ Storage::url(setting('general.company_logo')) }}" class="invoice-logo" />
|
||||
@else
|
||||
<img src="{{ Storage::url(setting('general.company_logo')) }}" class="invoice-logo" />
|
||||
<img src="{{ asset('public/img/company.png') }}" class="invoice-logo" />
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-xs-5 invoice-company">
|
||||
|
Loading…
x
Reference in New Issue
Block a user