From dd686409ef8ae224bcb1407b06435a60671fc260 Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Tue, 2 Jan 2018 17:54:10 +0300 Subject: [PATCH] Add edit page attachment --- app/Filters/Banking/Transfers.php | 2 +- app/Http/Controllers/Expenses/Bills.php | 4 ++-- app/Http/Controllers/Expenses/Payments.php | 2 +- app/Http/Controllers/Incomes/Revenues.php | 4 ++-- app/Http/Controllers/Items/Items.php | 2 +- .../views/incomes/invoices/edit.blade.php | 18 ++++++++++++++++++ 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/Filters/Banking/Transfers.php b/app/Filters/Banking/Transfers.php index 28c103a12..594d4ee01 100644 --- a/app/Filters/Banking/Transfers.php +++ b/app/Filters/Banking/Transfers.php @@ -23,4 +23,4 @@ class Transfers extends ModelFilter { return $this->related('revenue', 'revenues.account_id', '=', $account_id); } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Expenses/Bills.php b/app/Http/Controllers/Expenses/Bills.php index c9ca41933..2e389ac66 100644 --- a/app/Http/Controllers/Expenses/Bills.php +++ b/app/Http/Controllers/Expenses/Bills.php @@ -134,7 +134,7 @@ class Bills extends Controller if ($request->file('attachment')) { $media = $this->getMedia($request->file('attachment'), 'revenues'); - $invoice->attachMedia($media, 'attachment'); + $bill->attachMedia($media, 'attachment'); } $taxes = []; @@ -458,7 +458,7 @@ class Bills extends Controller if ($request->file('attachment')) { $media = $this->getMedia($request->file('attachment'), 'bills'); - $bill->syncMedia($media, 'attachment'); + $bill->attachMedia($media, 'attachment'); } // Added bill total total diff --git a/app/Http/Controllers/Expenses/Payments.php b/app/Http/Controllers/Expenses/Payments.php index 5df48b396..c296aabd9 100644 --- a/app/Http/Controllers/Expenses/Payments.php +++ b/app/Http/Controllers/Expenses/Payments.php @@ -182,7 +182,7 @@ class Payments extends Controller if ($request->file('attachment')) { $media = $this->getMedia($request->file('attachment'), 'payments'); - $payment->syncMedia($media, 'attachment'); + $payment->attachMedia($media, 'attachment'); } $message = trans('messages.success.updated', ['type' => trans_choice('general.payments', 1)]); diff --git a/app/Http/Controllers/Incomes/Revenues.php b/app/Http/Controllers/Incomes/Revenues.php index a02a8dd83..e02c38c33 100644 --- a/app/Http/Controllers/Incomes/Revenues.php +++ b/app/Http/Controllers/Incomes/Revenues.php @@ -85,7 +85,7 @@ class Revenues extends Controller if ($request->file('attachment')) { $media = $this->getMedia($request->file('attachment'), 'revenues'); - $revenue->syncMedia($media, 'attachment'); + $revenue->attachMedia($media, 'attachment'); } $message = trans('messages.success.added', ['type' => trans_choice('general.revenues', 1)]); @@ -184,7 +184,7 @@ class Revenues extends Controller if ($request->file('attachment')) { $media = $this->getMedia($request->file('attachment'), 'revenues'); - $revenue->syncMedia($media, 'attachment'); + $revenue->attachMedia($media, 'attachment'); } $message = trans('messages.success.updated', ['type' => trans_choice('general.revenues', 1)]); diff --git a/app/Http/Controllers/Items/Items.php b/app/Http/Controllers/Items/Items.php index c9d7b3ad0..e2bf8be39 100644 --- a/app/Http/Controllers/Items/Items.php +++ b/app/Http/Controllers/Items/Items.php @@ -144,7 +144,7 @@ class Items extends Controller if ($request->file('picture')) { $media = $this->getMedia($request->file('picture'), 'items'); - $item->syncMedia($media, 'picture'); + $item->attachMedia($media, 'picture'); } $message = trans('messages.success.updated', ['type' => trans_choice('general.items', 1)]); diff --git a/resources/views/incomes/invoices/edit.blade.php b/resources/views/incomes/invoices/edit.blade.php index cf713c298..e87f6c95c 100644 --- a/resources/views/incomes/invoices/edit.blade.php +++ b/resources/views/incomes/invoices/edit.blade.php @@ -208,6 +208,24 @@ @endif }); + @if($invoice->attachment) + attachment_html = ''; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {{ $invoice->attachment->basename }}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::open(['id' => 'attachment-' . $invoice->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $invoice->attachment->id)], 'style' => 'display:inline']) !!}'; + attachment_html += ' {{ Form::hidden('id', $invoice->id) }}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::close() !!}'; + attachment_html += ''; + + $('.fancy-file .fake-file').append(attachment_html); + @endif + var autocomplete_path = "{{ url('items/items/autocomplete') }}"; $(document).on('click', '.form-control.typeahead', function() {