close #231 : Bill attachment not working
This commit is contained in:
parent
f394a61773
commit
0f87195254
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Expenses;
|
||||
|
||||
use App\Events\BillCreated;
|
||||
//use App\Events\BillPrinting;
|
||||
use App\Events\BillUpdated;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Expense\Bill as Request;
|
||||
@ -19,12 +20,16 @@ use App\Models\Item\Item;
|
||||
use App\Models\Setting\Category;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Models\Setting\Tax;
|
||||
use App\Models\Common\Media;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
use App\Traits\Uploads;
|
||||
use App\Utilities\ImportFile;
|
||||
use App\Utilities\Modules;
|
||||
use Date;
|
||||
use File;
|
||||
use Image;
|
||||
use Storage;
|
||||
|
||||
class Bills extends Controller
|
||||
{
|
||||
@ -394,10 +399,10 @@ class Bills extends Controller
|
||||
$bill->attachMedia($media, 'attachment');
|
||||
}
|
||||
|
||||
// Delete previous invoice totals
|
||||
// Delete previous bill totals
|
||||
BillTotal::where('bill_id', $bill->id)->delete();
|
||||
|
||||
// Add invoice totals
|
||||
// Add bill totals
|
||||
$this->addTotals($bill, $request, $taxes, $sub_total, $tax_total);
|
||||
|
||||
// Fire the event to make it extendible
|
||||
@ -465,17 +470,11 @@ class Bills extends Controller
|
||||
*/
|
||||
public function printBill(Bill $bill)
|
||||
{
|
||||
$paid = 0;
|
||||
$bill = $this->prepareBill($bill);
|
||||
|
||||
foreach ($bill->payments as $item) {
|
||||
$item->default_currency_code = $bill->currency_code;
|
||||
$logo = $this->getLogo($bill);
|
||||
|
||||
$paid += $item->getDynamicConvertedAmount();
|
||||
}
|
||||
|
||||
$bill->paid = $paid;
|
||||
|
||||
return view('expenses.bills.bill', compact('bill'));
|
||||
return view($bill->template_path, compact('bill', 'logo'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -487,22 +486,16 @@ class Bills extends Controller
|
||||
*/
|
||||
public function pdfBill(Bill $bill)
|
||||
{
|
||||
$paid = 0;
|
||||
$bill = $this->prepareBill($bill);
|
||||
|
||||
foreach ($bill->payments as $item) {
|
||||
$item->default_currency_code = $bill->currency_code;
|
||||
$logo = $this->getLogo($bill);
|
||||
|
||||
$paid += $item->getDynamicConvertedAmount();
|
||||
}
|
||||
|
||||
$bill->paid = $paid;
|
||||
|
||||
$html = view('expenses.bills.bill', compact('bill'))->render();
|
||||
$html = view($bill->template_path, compact('bill', 'logo'))->render();
|
||||
|
||||
$pdf = \App::make('dompdf.wrapper');
|
||||
$pdf->loadHTML($html);
|
||||
|
||||
$file_name = 'bill_'.time().'.pdf';
|
||||
$file_name = 'bill_' . time() . '.pdf';
|
||||
|
||||
return $pdf->download($file_name);
|
||||
}
|
||||
@ -615,6 +608,25 @@ class Bills extends Controller
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
protected function prepareBill(Bill $bill)
|
||||
{
|
||||
$paid = 0;
|
||||
|
||||
foreach ($bill->payments as $item) {
|
||||
$item->default_currency_code = $bill->currency_code;
|
||||
|
||||
$paid += $item->getDynamicConvertedAmount();
|
||||
}
|
||||
|
||||
$bill->paid = $paid;
|
||||
|
||||
$bill->template_path = 'expenses.bills.bill';
|
||||
|
||||
//event(new BillPrinting($bill));
|
||||
|
||||
return $bill;
|
||||
}
|
||||
|
||||
protected function addTotals($bill, $request, $taxes, $sub_total, $tax_total)
|
||||
{
|
||||
$sort_order = 1;
|
||||
@ -658,26 +670,26 @@ class Bills extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getLogo()
|
||||
protected function getLogo($bill)
|
||||
{
|
||||
$logo = '';
|
||||
|
||||
$media_id = setting('general.company_logo');
|
||||
|
||||
if (setting('general.invoice_logo')) {
|
||||
$media_id = setting('general.invoice_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)) {
|
||||
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,12 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Expense\Vendor as Request;
|
||||
use App\Models\Expense\Vendor;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Traits\Uploads;
|
||||
use App\Utilities\ImportFile;
|
||||
|
||||
class Vendors extends Controller
|
||||
{
|
||||
use Uploads;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
@ -48,7 +50,14 @@ class Vendors extends Controller
|
||||
$request['email'] = '';
|
||||
}
|
||||
|
||||
Vendor::create($request->all());
|
||||
$vendor = Vendor::create($request->all());
|
||||
|
||||
// Upload logo
|
||||
if ($request->file('logo')) {
|
||||
$media = $this->getMedia($request->file('logo'), 'vendors');
|
||||
|
||||
$vendor->attachMedia($media, 'logo');
|
||||
}
|
||||
|
||||
$message = trans('messages.success.added', ['type' => trans_choice('general.vendors', 1)]);
|
||||
|
||||
@ -135,6 +144,13 @@ class Vendors extends Controller
|
||||
|
||||
$vendor->update($request->all());
|
||||
|
||||
// Upload logo
|
||||
if ($request->file('logo')) {
|
||||
$media = $this->getMedia($request->file('logo'), 'vendors');
|
||||
|
||||
$vendor->attachMedia($media, 'logo');
|
||||
}
|
||||
|
||||
$message = trans('messages.success.updated', ['type' => trans_choice('general.vendors', 1)]);
|
||||
|
||||
flash($message)->success();
|
||||
|
@ -5,10 +5,11 @@ namespace App\Models\Expense;
|
||||
use App\Models\Model;
|
||||
use Bkwld\Cloner\Cloneable;
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
use App\Traits\Media;
|
||||
|
||||
class Vendor extends Model
|
||||
{
|
||||
use Cloneable, Eloquence;
|
||||
use Cloneable, Eloquence, Media;
|
||||
|
||||
protected $table = 'vendors';
|
||||
|
||||
@ -53,4 +54,20 @@ class Vendor extends Model
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current balance.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLogoAttribute($value)
|
||||
{
|
||||
if (!empty($value) && !$this->hasMedia('logo')) {
|
||||
return $value;
|
||||
} elseif (!$this->hasMedia('logo')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->getMedia('logo')->last();
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ return [
|
||||
'companies' => 'Company|Companies',
|
||||
'profits' => 'Profit|Profits',
|
||||
'taxes' => 'Tax|Taxes',
|
||||
'logos' => 'Logo|Logos',
|
||||
'pictures' => 'Picture|Pictures',
|
||||
'types' => 'Type|Types',
|
||||
'payment_methods' => 'Payment Method|Payment Methods',
|
||||
|
@ -6,10 +6,8 @@
|
||||
<section class="bill">
|
||||
<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" />
|
||||
@if ($logo)
|
||||
<img src="{{ $logo }}" class="invoice-logo" />
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-xs-5 invoice-company">
|
||||
|
@ -9,10 +9,10 @@
|
||||
|
||||
<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" />
|
||||
@if (isset($bill->vendor->logo) && !empty($bill->vendor->logo->id))
|
||||
<img src="{{ Storage::url($bill->vendor->logo->id) }}" 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">
|
||||
|
@ -5,7 +5,7 @@
|
||||
@section('content')
|
||||
<!-- Default box -->
|
||||
<div class="box box-success">
|
||||
{!! Form::open(['url' => 'expenses/vendors', 'role' => 'form']) !!}
|
||||
{!! Form::open(['url' => 'expenses/vendors', 'files' => true, 'role' => 'form']) !!}
|
||||
|
||||
<div class="box-body">
|
||||
{{ Form::textGroup('name', trans('general.name'), 'id-card-o') }}
|
||||
@ -22,6 +22,8 @@
|
||||
|
||||
{{ Form::textareaGroup('address', trans('general.address')) }}
|
||||
|
||||
{{ Form::fileGroup('logo', trans_choice('general.pictures', 1)) }}
|
||||
|
||||
{{ Form::radioGroup('enabled', trans('general.enabled')) }}
|
||||
</div>
|
||||
<!-- /.box-body -->
|
||||
@ -35,6 +37,14 @@
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('js')
|
||||
<script src="{{ asset('public/js/bootstrap-fancyfile.js') }}"></script>
|
||||
@endpush
|
||||
|
||||
@push('css')
|
||||
<link rel="stylesheet" href="{{ asset('public/css/bootstrap-fancyfile.css') }}">
|
||||
@endpush
|
||||
|
||||
@push('scripts')
|
||||
<script type="text/javascript">
|
||||
var text_yes = '{{ trans('general.yes') }}';
|
||||
@ -48,6 +58,12 @@
|
||||
$("#currency_code").select2({
|
||||
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.currencies', 1)]) }}"
|
||||
});
|
||||
|
||||
$('#logo').fancyfile({
|
||||
text : '{{ trans('general.form.select.file') }}',
|
||||
style : 'btn-default',
|
||||
placeholder : '{{ trans('general.form.no_file_selected') }}'
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
|
42
resources/views/expenses/vendors/edit.blade.php
vendored
42
resources/views/expenses/vendors/edit.blade.php
vendored
@ -7,6 +7,7 @@
|
||||
<div class="box box-success">
|
||||
{!! Form::model($vendor, [
|
||||
'method' => 'PATCH',
|
||||
'files' => true,
|
||||
'url' => ['expenses/vendors', $vendor->id],
|
||||
'role' => 'form'
|
||||
]) !!}
|
||||
@ -26,6 +27,8 @@
|
||||
|
||||
{{ Form::textareaGroup('address', trans('general.address')) }}
|
||||
|
||||
{{ Form::fileGroup('logo', trans_choice('general.logos', 1)) }}
|
||||
|
||||
{{ Form::radioGroup('enabled', trans('general.enabled')) }}
|
||||
</div>
|
||||
<!-- /.box-body -->
|
||||
@ -40,6 +43,14 @@
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('js')
|
||||
<script src="{{ asset('public/js/bootstrap-fancyfile.js') }}"></script>
|
||||
@endpush
|
||||
|
||||
@push('css')
|
||||
<link rel="stylesheet" href="{{ asset('public/css/bootstrap-fancyfile.css') }}">
|
||||
@endpush
|
||||
|
||||
@push('scripts')
|
||||
<script type="text/javascript">
|
||||
var text_yes = '{{ trans('general.yes') }}';
|
||||
@ -49,6 +60,37 @@
|
||||
$("#currency_code").select2({
|
||||
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.currencies', 1)]) }}"
|
||||
});
|
||||
|
||||
$('#logo').fancyfile({
|
||||
text : '{{ trans('general.form.select.file') }}',
|
||||
style : 'btn-default',
|
||||
@if($vendor->logo)
|
||||
placeholder : '<?php echo $vendor->logo->basename; ?>'
|
||||
@else
|
||||
placeholder : '{{ trans('general.form.no_file_selected') }}'
|
||||
@endif
|
||||
});
|
||||
|
||||
@if($vendor->logo)
|
||||
logo_html = '<span class="logo">';
|
||||
logo_html += ' <a href="{{ url('uploads/' . $vendor->logo->id . '/download') }}">';
|
||||
logo_html += ' <span id="download-logo" class="text-primary">';
|
||||
logo_html += ' <i class="fa fa-file-{{ $vendor->logo->aggregate_type }}-o"></i> {{ $vendor->logo->basename }}';
|
||||
logo_html += ' </span>';
|
||||
logo_html += ' </a>';
|
||||
logo_html += ' {!! Form::open(['id' => 'logo-' . $vendor->logo->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $vendor->logo->id)], 'style' => 'display:inline']) !!}';
|
||||
logo_html += ' <a id="remove-logo" href="javascript:void();">';
|
||||
logo_html += ' <span class="text-danger"><i class="fa fa fa-times"></i></span>';
|
||||
logo_html += ' </a>';
|
||||
logo_html += ' {!! Form::close() !!}';
|
||||
logo_html += '</span>';
|
||||
|
||||
$('.fancy-file .fake-file').append(logo_html);
|
||||
|
||||
$(document).on('click', '#remove-logo', function (e) {
|
||||
confirmDelete("#logo-{!! $vendor->logo->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '<strong>' . $vendor->logo->basename . '</strong>', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
|
||||
});
|
||||
@endif
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
|
Loading…
x
Reference in New Issue
Block a user