From 97afc50cfa41106d77ff9e6918ba22ba4c42ba6f Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Thu, 28 Dec 2017 17:20:16 +0300 Subject: [PATCH 01/13] Attachment system some file --- app/Http/Controllers/Expenses/Bills.php | 43 ++-- app/Http/Controllers/Expenses/Payments.php | 26 +- app/Http/Controllers/Incomes/Invoices.php | 43 ++-- app/Http/Controllers/Incomes/Revenues.php | 26 +- app/Http/Controllers/Items/Items.php | 26 +- app/Models/Income/Invoice.php | 24 +- app/Providers/FormServiceProvider.php | 2 +- app/Traits/Uploads.php | 17 +- composer.json | 3 +- config/app.php | 2 + config/mediable.php | 228 ++++++++++++++++++ ...16_06_27_000000_create_mediable_tables.php | 58 +++++ database/seeds/Roles.php | 1 + .../views/incomes/invoices/edit.blade.php | 2 +- .../views/partials/form/file_group.blade.php | 2 +- routes/web.php | 1 + 16 files changed, 420 insertions(+), 84 deletions(-) create mode 100644 config/mediable.php create mode 100644 database/migrations/2016_06_27_000000_create_mediable_tables.php diff --git a/app/Http/Controllers/Expenses/Bills.php b/app/Http/Controllers/Expenses/Bills.php index 2bf9e84de..c9ca41933 100644 --- a/app/Http/Controllers/Expenses/Bills.php +++ b/app/Http/Controllers/Expenses/Bills.php @@ -128,16 +128,17 @@ class Bills extends Controller $request['amount'] = 0; - // Upload attachment - $attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'bills'); - - if ($attachment_path) { - $request['attachment'] = $attachment_path; - } - $bill = Bill::create($request->input()); + // Upload attachment + if ($request->file('attachment')) { + $media = $this->getMedia($request->file('attachment'), 'revenues'); + + $invoice->attachMedia($media, 'attachment'); + } + $taxes = []; + $tax_total = 0; $sub_total = 0; @@ -357,13 +358,6 @@ class Bills extends Controller $request['amount'] = 0; - // Upload attachment - $attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'bills'); - - if ($attachment_path) { - $request['attachment'] = $attachment_path; - } - $taxes = []; $tax_total = 0; $sub_total = 0; @@ -460,6 +454,13 @@ class Bills extends Controller $bill->update($request->input()); + // Upload attachment + if ($request->file('attachment')) { + $media = $this->getMedia($request->file('attachment'), 'bills'); + + $bill->syncMedia($media, 'attachment'); + } + // Added bill total total $bill_total = [ 'company_id' => $request['company_id'], @@ -594,15 +595,15 @@ class Bills extends Controller $request['currency_code'] = $currency->code; $request['currency_rate'] = $currency->rate; - // Upload attachment - $attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'revenues'); - - if ($attachment_path) { - $request['attachment'] = $attachment_path; - } - $bill = Bill::find($request['bill_id']); + // Upload attachment + if ($request->file('attachment')) { + $media = $this->getMedia($request->file('attachment'), 'payments'); + + $bill->attachMedia($media, 'attachment'); + } + $total_amount = $bill->amount; $amount = (double) $request['amount']; diff --git a/app/Http/Controllers/Expenses/Payments.php b/app/Http/Controllers/Expenses/Payments.php index 205ecb0ca..5df48b396 100644 --- a/app/Http/Controllers/Expenses/Payments.php +++ b/app/Http/Controllers/Expenses/Payments.php @@ -77,13 +77,14 @@ class Payments extends Controller $request['currency_code'] = $currency->code; $request['currency_rate'] = $currency->rate; - // Upload attachment - $attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'payments'); - if ($attachment_path) { - $request['attachment'] = $attachment_path; - } + $payment = Payment::create($request->input()); - Payment::create($request->input()); + // Upload attachment + $media = $this->getMedia($request->file('attachment'), 'payments'); + + if ($media) { + $payment->attachMedia($media, 'attachment'); + } $message = trans('messages.success.added', ['type' => trans_choice('general.payments', 1)]); @@ -175,14 +176,15 @@ class Payments extends Controller $request['currency_code'] = $currency->code; $request['currency_rate'] = $currency->rate; - // Upload attachment - $attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'payments'); - if ($attachment_path) { - $request['attachment'] = $attachment_path; - } - $payment->update($request->input()); + // Upload attachment + if ($request->file('attachment')) { + $media = $this->getMedia($request->file('attachment'), 'payments'); + + $payment->syncMedia($media, 'attachment'); + } + $message = trans('messages.success.updated', ['type' => trans_choice('general.payments', 1)]); flash($message)->success(); diff --git a/app/Http/Controllers/Incomes/Invoices.php b/app/Http/Controllers/Incomes/Invoices.php index daafba8a2..40215ef9e 100644 --- a/app/Http/Controllers/Incomes/Invoices.php +++ b/app/Http/Controllers/Incomes/Invoices.php @@ -137,16 +137,17 @@ class Invoices extends Controller $request['amount'] = 0; - // Upload attachment - $attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'invoices'); - - if ($attachment_path) { - $request['attachment'] = $attachment_path; - } - $invoice = Invoice::create($request->input()); + // Upload attachment + if ($request->file('attachment')) { + $media = $this->getMedia($request->file('attachment'), 'revenues'); + + $invoice->attachMedia($media, 'attachment'); + } + $taxes = []; + $tax_total = 0; $sub_total = 0; @@ -349,13 +350,6 @@ class Invoices extends Controller $request['currency_code'] = $currency->code; $request['currency_rate'] = $currency->rate; - // Upload attachment - $attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'invoices'); - - if ($attachment_path) { - $request['attachment'] = $attachment_path; - } - $taxes = []; $tax_total = 0; $sub_total = 0; @@ -418,6 +412,13 @@ class Invoices extends Controller $invoice->update($request->input()); + // Upload attachment + if ($request->file('attachment')) { + $media = $this->getMedia($request->file('attachment'), 'invoices'); + + $invoice->syncMedia($media, 'attachment'); + } + // Delete previous invoice totals InvoiceTotal::where('invoice_id', $invoice->id)->delete(); @@ -624,13 +625,6 @@ class Invoices extends Controller $request['currency_code'] = $currency->code; $request['currency_rate'] = $currency->rate; - // Upload attachment - $attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'invoices'); - - if ($attachment_path) { - $request['attachment'] = $attachment_path; - } - $invoice = Invoice::find($request['invoice_id']); $total_amount = $invoice->amount; @@ -669,6 +663,13 @@ class Invoices extends Controller $invoice_payment = InvoicePayment::create($request->input()); + // Upload attachment + if ($request->file('attachment')) { + $media = $this->getMedia($request->file('attachment'), 'invoices'); + + $invoice_payment->attachMedia($media, 'attachment'); + } + $request['status_code'] = $invoice->invoice_status_code; $request['notify'] = 0; diff --git a/app/Http/Controllers/Incomes/Revenues.php b/app/Http/Controllers/Incomes/Revenues.php index 404cfbbd4..a02a8dd83 100644 --- a/app/Http/Controllers/Incomes/Revenues.php +++ b/app/Http/Controllers/Incomes/Revenues.php @@ -79,13 +79,14 @@ class Revenues extends Controller $request['currency_code'] = $currency->code; $request['currency_rate'] = $currency->rate; - // Upload attachment - $attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'revenues'); - if ($attachment_path) { - $request['attachment'] = $attachment_path; - } + $revenue = Revenue::create($request->input()); - Revenue::create($request->input()); + // Upload attachment + if ($request->file('attachment')) { + $media = $this->getMedia($request->file('attachment'), 'revenues'); + + $revenue->syncMedia($media, 'attachment'); + } $message = trans('messages.success.added', ['type' => trans_choice('general.revenues', 1)]); @@ -177,14 +178,15 @@ class Revenues extends Controller $request['currency_code'] = $currency->code; $request['currency_rate'] = $currency->rate; - // Upload attachment - $attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'revenues'); - if ($attachment_path) { - $request['attachment'] = $attachment_path; - } - $revenue->update($request->input()); + // Upload attachment + if ($request->file('attachment')) { + $media = $this->getMedia($request->file('attachment'), 'revenues'); + + $revenue->syncMedia($media, 'attachment'); + } + $message = trans('messages.success.updated', ['type' => trans_choice('general.revenues', 1)]); flash($message)->success(); diff --git a/app/Http/Controllers/Items/Items.php b/app/Http/Controllers/Items/Items.php index 201fe9188..075d2a6c6 100644 --- a/app/Http/Controllers/Items/Items.php +++ b/app/Http/Controllers/Items/Items.php @@ -53,13 +53,14 @@ class Items extends Controller */ public function store(Request $request) { - // Upload picture - $picture_path = $this->getUploadedFilePath($request->file('picture'), 'items'); - if ($picture_path) { - $request['picture'] = $picture_path; - } + $item = Item::create($request->input()); - Item::create($request->input()); + // Upload picture + if ($media) { + $media = $this->getMedia($request->file('picture'), 'items'); + + $item->attachMedia($media, 'picture'); + } $message = trans('messages.success.added', ['type' => trans_choice('general.items', 1)]); @@ -137,14 +138,15 @@ class Items extends Controller */ public function update(Item $item, Request $request) { - // Upload picture - $picture_path = $this->getUploadedFilePath($request->file('picture'), 'items'); - if ($picture_path) { - $request['picture'] = $picture_path; - } - $item->update($request->input()); + // Upload picture + if ($media) { + $media = $this->getMedia($request->file('picture'), 'items'); + + $item->syncMedia($media, 'picture'); + } + $message = trans('messages.success.updated', ['type' => trans_choice('general.items', 1)]); flash($message)->success(); diff --git a/app/Models/Income/Invoice.php b/app/Models/Income/Invoice.php index b80575bc2..e17bbfc6d 100644 --- a/app/Models/Income/Invoice.php +++ b/app/Models/Income/Invoice.php @@ -8,13 +8,21 @@ use App\Traits\DateTime; use App\Traits\Incomes; use Bkwld\Cloner\Cloneable; use Sofa\Eloquence\Eloquence; +use Plank\Mediable\Mediable; class Invoice extends Model { - use Cloneable, Currencies, DateTime, Eloquence, Incomes; + use Cloneable, Currencies, DateTime, Eloquence, Incomes, Mediable; protected $table = 'invoices'; + /** + * The accessors to append to the model's array form. + * + * @var array + */ + protected $appends = ['attachment']; + protected $dates = ['deleted_at', 'invoiced_at', 'due_at']; /** @@ -130,4 +138,18 @@ class Invoice extends Model { $this->attributes['currency_rate'] = (double) $value; } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute() + { + if (!$this->hasMedia('attachment')) { + return false; + } + + return $this->getMedia('attachment')->first(); + } } diff --git a/app/Providers/FormServiceProvider.php b/app/Providers/FormServiceProvider.php index 666f674d2..680e9c7e6 100644 --- a/app/Providers/FormServiceProvider.php +++ b/app/Providers/FormServiceProvider.php @@ -44,7 +44,7 @@ class FormServiceProvider extends ServiceProvider ]); Form::component('fileGroup', 'partials.form.file_group', [ - 'name', 'text', 'attributes' => [], 'col' => 'col-md-6', + 'name', 'text', 'attributes' => [], 'value' => null, 'col' => 'col-md-6', ]); Form::component('deleteButton', 'partials.form.delete_button', [ diff --git a/app/Traits/Uploads.php b/app/Traits/Uploads.php index 07c1e0648..07c5074ec 100644 --- a/app/Traits/Uploads.php +++ b/app/Traits/Uploads.php @@ -2,6 +2,8 @@ namespace App\Traits; +use MediaUploader; + trait Uploads { @@ -27,4 +29,17 @@ trait Uploads return $path; } -} \ No newline at end of file + + public function getMedia($file, $folder, $company_id = null) + { + if (!$company_id) { + $company_id = session('company_id'); + } + + $path = config('filesystems.disks.uploads.root') . '/' . $company_id . '/' . $folder; + + config(['filesystems.disks.uploads.root' => $path]); + + return MediaUploader::fromSource($file)->upload(); + } +} diff --git a/composer.json b/composer.json index bfe3a069c..a919032fa 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "nwidart/laravel-modules": "1.*", "santigarcor/laratrust": "4.0.*", "sofa/eloquence": "5.4.*", - "tucker-eric/eloquentfilter": "1.1.*" + "tucker-eric/eloquentfilter": "1.1.*", + "plank/laravel-mediable": "2.5.*" }, "require-dev": { "fzaninotto/faker": "1.6.*" diff --git a/config/app.php b/config/app.php index fbfa3c154..e2fce1615 100644 --- a/config/app.php +++ b/config/app.php @@ -203,6 +203,7 @@ return [ Nwidart\Menus\MenusServiceProvider::class, Nwidart\Modules\LaravelModulesServiceProvider::class, Sofa\Eloquence\ServiceProvider::class, + Plank\Mediable\MediableServiceProvider::class, ], @@ -238,6 +239,7 @@ return [ 'Lang' => Illuminate\Support\Facades\Lang::class, 'Log' => Illuminate\Support\Facades\Log::class, 'Mail' => Illuminate\Support\Facades\Mail::class, + 'MediaUploader' => Plank\Mediable\MediaUploaderFacade::class, 'Notification' => Illuminate\Support\Facades\Notification::class, 'Password' => Illuminate\Support\Facades\Password::class, 'Queue' => Illuminate\Support\Facades\Queue::class, diff --git a/config/mediable.php b/config/mediable.php new file mode 100644 index 000000000..e28f8dd8c --- /dev/null +++ b/config/mediable.php @@ -0,0 +1,228 @@ + Plank\Mediable\Media::class, + + /* + * Filesystem disk to use if none is specified + */ + 'default_disk' => 'uploads', + + /* + * Filesystems that can be used for media storage + * + * Uploader will throw an exception if a disk not in this list is selected + */ + 'allowed_disks' => [ + 'uploads', + ], + + /* + * The maximum file size in bytes for a single uploaded file + */ + 'max_size' => 1024 * 1024 * 10, + + /* + * What to do if a duplicate file is uploaded. + * + * Options include: + * + * * `'increment'`: the new file's name is given an incrementing suffix + * * `'replace'` : the old file and media model is deleted + * * `'error'`: an Exception is thrown + */ + 'on_duplicate' => Plank\Mediable\MediaUploader::ON_DUPLICATE_INCREMENT, + + /* + * Reject files unless both their mime and extension are recognized and both match a single aggregate type + */ + 'strict_type_checking' => false, + + /* + * Reject files whose mime type or extension is not recognized + * if true, files will be given a type of `'other'` + */ + 'allow_unrecognized_types' => false, + + /* + * Only allow files with specific MIME type(s) to be uploaded + */ + 'allowed_mime_types' => [], + + /* + * Only allow files with specific file extension(s) to be uploaded + */ + 'allowed_extensions' => [], + + /* + * Only allow files matching specific aggregate type(s) to be uploaded + */ + 'allowed_aggregate_types' => [], + + /* + * List of aggregate types recognized by the application + * + * Each type should list the MIME types and extensions + * that should be recognized for the type + */ + 'aggregate_types' => [ + Plank\Mediable\Media::TYPE_IMAGE => [ + 'mime_types' => [ + 'image/jpeg', + 'image/png', + 'image/gif', + ], + 'extensions' => [ + 'jpg', + 'jpeg', + 'png', + 'gif', + ] + ], + Plank\Mediable\Media::TYPE_IMAGE_VECTOR => [ + 'mime_types' => [ + 'image/svg+xml', + ], + 'extensions' => [ + 'svg', + ] + ], + Plank\Mediable\Media::TYPE_PDF => [ + 'mime_types' => [ + 'application/pdf', + ], + 'extensions' => [ + 'pdf', + ] + ], + Plank\Mediable\Media::TYPE_AUDIO => [ + 'mime_types' => [ + 'audio/aac', + 'audio/ogg', + 'audio/mpeg', + 'audio/mp3', + 'audio/mpeg', + 'audio/wav' + ], + 'extensions' => [ + 'aac', + 'ogg', + 'oga', + 'mp3', + 'wav', + ] + ], + Plank\Mediable\Media::TYPE_VIDEO => [ + 'mime_types' => [ + 'video/mp4', + 'video/mpeg', + 'video/ogg', + 'video/webm' + ], + 'extensions' => [ + 'mp4', + 'm4v', + 'mov', + 'ogv', + 'webm' + ] + ], + Plank\Mediable\Media::TYPE_ARCHIVE => [ + 'mime_types' => [ + 'application/zip', + 'application/x-compressed-zip', + 'multipart/x-zip', + ], + 'extensions' => [ + 'zip', + ] + ], + Plank\Mediable\Media::TYPE_DOCUMENT => [ + 'mime_types' => [ + 'text/plain', + 'application/plain', + 'text/xml', + 'text/json', + 'application/json', + 'application/msword', + 'application/application/vnd.openxmlformats-officedocument.wordprocessingml.document' + ], + 'extensions' => [ + 'doc', + 'docx', + 'txt', + 'text', + 'xml', + 'json', + ] + ], + Plank\Mediable\Media::TYPE_SPREADSHEET => [ + 'mime_types' => [ + 'application/vnd.ms-excel', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + ], + 'extensions' => [ + 'xls', + 'xlsx', + ] + ], + Plank\Mediable\Media::TYPE_PRESENTATION => [ + 'mime_types' => + [ + 'application/vnd.ms-powerpoint', + 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' + ], + 'extensions' => + [ + 'ppt', + 'pptx', + 'ppsx', + ] + ], + ], + + /* + * List of adapters to use for various source inputs + * + * Adapters can map either to a class or a pattern (regex) + */ + 'source_adapters' => [ + 'class' => [ + Symfony\Component\HttpFoundation\File\UploadedFile::class => Plank\Mediable\SourceAdapters\UploadedFileAdapter::class, + Symfony\Component\HttpFoundation\File\File::class => Plank\Mediable\SourceAdapters\FileAdapter::class, + Psr\Http\Message\StreamInterface::class => Plank\Mediable\SourceAdapters\StreamAdapter::class, + ], + 'pattern' => [ + '^https?://' => Plank\Mediable\SourceAdapters\RemoteUrlAdapter::class, + '^/' => Plank\Mediable\SourceAdapters\LocalPathAdapter::class, + '^[a-zA-Z]:\\' => Plank\Mediable\SourceAdapters\LocalPathAdapter::class + ], + ], + + /* + * List of URL Generators to use for handling various filesystem drivers + * + */ + 'url_generators' => [ + 'local' => Plank\Mediable\UrlGenerators\LocalUrlGenerator::class, + 's3' => Plank\Mediable\UrlGenerators\S3UrlGenerator::class, + ], + + /** + * Should mediable instances automatically reload their media relationships after modification are made to a tag. + * + * If true, will automatically reload media the next time `getMedia()`, `getMediaMatchAll()` or `getAllMediaByTag()` are called. + */ + 'rehydrate_media' => true, + + /** + * Detach associated media when mediable model is soft deleted. + */ + 'detach_on_soft_delete' => true, +]; diff --git a/database/migrations/2016_06_27_000000_create_mediable_tables.php b/database/migrations/2016_06_27_000000_create_mediable_tables.php new file mode 100644 index 000000000..b35c40ecd --- /dev/null +++ b/database/migrations/2016_06_27_000000_create_mediable_tables.php @@ -0,0 +1,58 @@ +increments('id'); + $table->string('disk', 32); + $table->string('directory'); + $table->string('filename'); + $table->string('extension', 32); + $table->string('mime_type', 128); + $table->string('aggregate_type', 32); + $table->integer('size')->unsigned(); + $table->timestamps(); + + $table->index(['disk', 'directory']); + $table->unique(['disk', 'directory', 'filename', 'extension']); + $table->index('aggregate_type'); + }); + + Schema::create('mediables', function (Blueprint $table) { + $table->integer('media_id')->unsigned(); + $table->string('mediable_type'); + $table->integer('mediable_id')->unsigned(); + $table->string('tag'); + $table->integer('order')->unsigned(); + + $table->primary(['media_id', 'mediable_type', 'mediable_id', 'tag']); + $table->index(['mediable_id', 'mediable_type']); + $table->index('tag'); + $table->index('order'); + $table->foreign('media_id')->references('id')->on('media') + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('mediables'); + Schema::drop('media'); + } +} diff --git a/database/seeds/Roles.php b/database/seeds/Roles.php index db424e010..736d6b682 100644 --- a/database/seeds/Roles.php +++ b/database/seeds/Roles.php @@ -36,6 +36,7 @@ class Roles extends Seeder 'auth-profile' => 'r,u', 'companies-companies' => 'c,r,u,d', 'common-import' => 'c', + 'common-uploads' => 'd', 'items-items' => 'c,r,u,d', 'incomes-invoices' => 'c,r,u,d', 'incomes-revenues' => 'c,r,u,d', diff --git a/resources/views/incomes/invoices/edit.blade.php b/resources/views/incomes/invoices/edit.blade.php index 5c42c5520..0c49c53c5 100644 --- a/resources/views/incomes/invoices/edit.blade.php +++ b/resources/views/incomes/invoices/edit.blade.php @@ -203,7 +203,7 @@ $('#attachment').fancyfile({ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', - placeholder : 'attachment; ?>' + placeholder : 'attachment->basename; ?>' }); var autocomplete_path = "{{ url('items/items/autocomplete') }}"; diff --git a/resources/views/partials/form/file_group.blade.php b/resources/views/partials/form/file_group.blade.php index 59656ce85..cc110eed1 100644 --- a/resources/views/partials/form/file_group.blade.php +++ b/resources/views/partials/form/file_group.blade.php @@ -1,5 +1,5 @@
{!! Form::label($name, $text, ['class' => 'control-label']) !!} - {!! Form::file($name, null, array_merge(['class' => 'form-control'], $attributes)) !!} + {!! Form::file($name, $value, array_merge(['class' => 'form-control'], $attributes)) !!} {!! $errors->first($name, '

:message

') !!}
diff --git a/routes/web.php b/routes/web.php index 251ee0d1f..91e744610 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,6 +11,7 @@ Route::group(['middleware' => 'language'], function () { Route::group(['prefix' => 'uploads'], function () { Route::get('{folder}/{file}', 'Common\Uploads@get'); Route::get('{folder}/{file}/download', 'Common\Uploads@download'); + Route::get('{folder}/{file}/destroy', 'Common\Uploads@destroy'); }); Route::group(['middleware' => ['adminmenu', 'permission:read-admin-panel']], function () { From 94b7e9ec647dfa15d58156e623634f40055ff51f Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Thu, 28 Dec 2017 17:45:34 +0300 Subject: [PATCH 02/13] some changes for attachment --- resources/views/incomes/invoices/edit.blade.php | 2 ++ resources/views/incomes/invoices/show.blade.php | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/resources/views/incomes/invoices/edit.blade.php b/resources/views/incomes/invoices/edit.blade.php index 0c49c53c5..cf713c298 100644 --- a/resources/views/incomes/invoices/edit.blade.php +++ b/resources/views/incomes/invoices/edit.blade.php @@ -203,7 +203,9 @@ $('#attachment').fancyfile({ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', + @if($invoice->attachment) placeholder : 'attachment->basename; ?>' + @endif }); var autocomplete_path = "{{ url('items/items/autocomplete') }}"; diff --git a/resources/views/incomes/invoices/show.blade.php b/resources/views/incomes/invoices/show.blade.php index bdeb10362..1b4cbaaa5 100644 --- a/resources/views/incomes/invoices/show.blade.php +++ b/resources/views/incomes/invoices/show.blade.php @@ -178,6 +178,12 @@ @endpermission + + @if($invoice->attachment) + + {{ $invoice->attachment->basename }} + + @endif From 3e04f1295b7b06369342e987e27dcbf21df6fdc9 Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Fri, 29 Dec 2017 19:56:56 +0300 Subject: [PATCH 03/13] Attachment file update --- app/Http/Controllers/Common/Uploads.php | 26 +++++++++++++++++++ app/Models/Common/Media.php | 14 ++++++++++ app/Models/Income/Invoice.php | 2 +- config/mediable.php | 2 +- ...7_12_30_000000_create_mediable_tables.php} | 1 + .../views/incomes/invoices/show.blade.php | 24 +++++++++++++++-- routes/web.php | 2 +- 7 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 app/Models/Common/Media.php rename database/migrations/{2016_06_27_000000_create_mediable_tables.php => 2017_12_30_000000_create_mediable_tables.php} (98%) diff --git a/app/Http/Controllers/Common/Uploads.php b/app/Http/Controllers/Common/Uploads.php index a22904bd3..0b3a975c2 100644 --- a/app/Http/Controllers/Common/Uploads.php +++ b/app/Http/Controllers/Common/Uploads.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Common; use App\Http\Controllers\Controller; +use App\Models\Common\Media; use Storage; class Uploads extends Controller @@ -41,6 +42,31 @@ class Uploads extends Controller return response()->download($path); } + /** + * Destroy the specified resource. + * + * @param $folder + * @param $file + * @return callable + */ + public function destroy($folder, $id) + { + $media = Media::find($id); + + // Get file path + /*if (!$path = $this->getPath($folder, $id)) { + $message = trans('messages.warning.deleted', ['name' => $file, 'text' => $file]); + + flash($message)->warning(); + + return back(); + }*/ + + $media->delete(); //will not delete files + + return back(); + } + /** * Get the full path of resource. * diff --git a/app/Models/Common/Media.php b/app/Models/Common/Media.php new file mode 100644 index 000000000..744d67644 --- /dev/null +++ b/app/Models/Common/Media.php @@ -0,0 +1,14 @@ +getMedia('attachment')->first(); + return $this->getMedia('attachment')->last(); } } diff --git a/config/mediable.php b/config/mediable.php index e28f8dd8c..9f468220e 100644 --- a/config/mediable.php +++ b/config/mediable.php @@ -224,5 +224,5 @@ return [ /** * Detach associated media when mediable model is soft deleted. */ - 'detach_on_soft_delete' => true, + 'detach_on_soft_delete' => false, ]; diff --git a/database/migrations/2016_06_27_000000_create_mediable_tables.php b/database/migrations/2017_12_30_000000_create_mediable_tables.php similarity index 98% rename from database/migrations/2016_06_27_000000_create_mediable_tables.php rename to database/migrations/2017_12_30_000000_create_mediable_tables.php index b35c40ecd..f9dd1f1a4 100644 --- a/database/migrations/2016_06_27_000000_create_mediable_tables.php +++ b/database/migrations/2017_12_30_000000_create_mediable_tables.php @@ -23,6 +23,7 @@ class CreateMediableTables extends Migration $table->string('aggregate_type', 32); $table->integer('size')->unsigned(); $table->timestamps(); + $table->softDeletes(); $table->index(['disk', 'directory']); $table->unique(['disk', 'directory', 'filename', 'extension']); diff --git a/resources/views/incomes/invoices/show.blade.php b/resources/views/incomes/invoices/show.blade.php index 1b4cbaaa5..1e0cc2dbd 100644 --- a/resources/views/incomes/invoices/show.blade.php +++ b/resources/views/incomes/invoices/show.blade.php @@ -180,8 +180,23 @@ @if($invoice->attachment) - - {{ $invoice->attachment->basename }} + + + + {{ $invoice->attachment->basename }} + + + {!! Form::open([ + 'id' => 'attachment-' . $invoice->attachment->id, + 'method' => 'DELETE', + 'url' => [url('uploads/invoices/' . $invoice->attachment->id)], + 'style' => 'display:inline' + ]) !!} + {{ Form::hidden('id', $invoice->id) }} + + + + {!! Form::close() !!} @endif @@ -420,6 +435,11 @@ $('#email-modal').modal('show'); }); + @if($invoice->attachment) + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $invoice->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $invoice->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif }); function addPayment() { diff --git a/routes/web.php b/routes/web.php index 91e744610..b09ee7557 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,7 +11,7 @@ Route::group(['middleware' => 'language'], function () { Route::group(['prefix' => 'uploads'], function () { Route::get('{folder}/{file}', 'Common\Uploads@get'); Route::get('{folder}/{file}/download', 'Common\Uploads@download'); - Route::get('{folder}/{file}/destroy', 'Common\Uploads@destroy'); + Route::delete('{folder}/{id}', 'Common\Uploads@destroy'); }); Route::group(['middleware' => ['adminmenu', 'permission:read-admin-panel']], function () { From 6429a699b272dceb6453097d03121a8ecfccec5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Tue, 2 Jan 2018 07:34:22 +0300 Subject: [PATCH 04/13] fixed attachment path --- resources/views/incomes/invoices/show.blade.php | 2 +- routes/web.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/incomes/invoices/show.blade.php b/resources/views/incomes/invoices/show.blade.php index 1e0cc2dbd..18109d0bb 100644 --- a/resources/views/incomes/invoices/show.blade.php +++ b/resources/views/incomes/invoices/show.blade.php @@ -181,7 +181,7 @@ @if($invoice->attachment) - + {{ $invoice->attachment->basename }} diff --git a/routes/web.php b/routes/web.php index b09ee7557..ecd605e03 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,7 +11,7 @@ Route::group(['middleware' => 'language'], function () { Route::group(['prefix' => 'uploads'], function () { Route::get('{folder}/{file}', 'Common\Uploads@get'); Route::get('{folder}/{file}/download', 'Common\Uploads@download'); - Route::delete('{folder}/{id}', 'Common\Uploads@destroy'); + Route::delete('{id}', 'Common\Uploads@destroy'); }); Route::group(['middleware' => ['adminmenu', 'permission:read-admin-panel']], function () { From ddd18c7ea6f872540c293f40d99c987842ac0f6f Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Tue, 2 Jan 2018 16:22:30 +0300 Subject: [PATCH 05/13] Invoice path --- app/Http/Controllers/Common/Uploads.php | 34 +++++++++++-------- app/Http/Controllers/Incomes/Invoices.php | 2 +- app/Http/Controllers/Items/Items.php | 4 +-- app/Models/Common/Media.php | 2 +- app/Traits/Uploads.php | 6 ++-- .../views/incomes/invoices/show.blade.php | 2 +- routes/web.php | 4 +-- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/Common/Uploads.php b/app/Http/Controllers/Common/Uploads.php index 0b3a975c2..26b39e473 100644 --- a/app/Http/Controllers/Common/Uploads.php +++ b/app/Http/Controllers/Common/Uploads.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Common; use App\Http\Controllers\Controller; use App\Models\Common\Media; use Storage; +use File; class Uploads extends Controller { @@ -15,10 +16,12 @@ class Uploads extends Controller * @param $file * @return boolean|Response */ - public function get($folder, $file) + public function get($id) { + $media = Media::find($id); + // Get file path - if (!$path = $this->getPath($folder, $file)) { + if (!$path = $this->getPath($media)) { return false; } @@ -32,10 +35,12 @@ class Uploads extends Controller * @param $file * @return boolean|Response */ - public function download($folder, $file) + public function download($id) { + $media = Media::find($id); + // Get file path - if (!$path = $this->getPath($folder, $file)) { + if (!$path = $this->getPath($media)) { return false; } @@ -49,21 +54,23 @@ class Uploads extends Controller * @param $file * @return callable */ - public function destroy($folder, $id) + public function destroy($id) { $media = Media::find($id); // Get file path - /*if (!$path = $this->getPath($folder, $id)) { - $message = trans('messages.warning.deleted', ['name' => $file, 'text' => $file]); + if (!$path = $this->getPath($media)) { + $message = trans('messages.warning.deleted', ['name' => $media->basename, 'text' => $media->basename]); flash($message)->warning(); return back(); - }*/ + } $media->delete(); //will not delete files + File::delete($path); + return back(); } @@ -74,14 +81,13 @@ class Uploads extends Controller * @param $file * @return boolean|string */ - protected function getPath($folder, $file) + protected function getPath($media) { - // Add company id - if ($folder != 'users') { - $folder = session('company_id') . '/' . $folder; - } + $path = $media->basename; - $path = $folder . '/' . $file; + if (!empty($media->directory)) { + $path = $media->directory . '/' . $media->basename; + } if (!Storage::exists($path)) { return false; diff --git a/app/Http/Controllers/Incomes/Invoices.php b/app/Http/Controllers/Incomes/Invoices.php index 40215ef9e..870c7625f 100644 --- a/app/Http/Controllers/Incomes/Invoices.php +++ b/app/Http/Controllers/Incomes/Invoices.php @@ -416,7 +416,7 @@ class Invoices extends Controller if ($request->file('attachment')) { $media = $this->getMedia($request->file('attachment'), 'invoices'); - $invoice->syncMedia($media, 'attachment'); + $invoice->attachMedia($media, 'attachment'); } // Delete previous invoice totals diff --git a/app/Http/Controllers/Items/Items.php b/app/Http/Controllers/Items/Items.php index 075d2a6c6..c9d7b3ad0 100644 --- a/app/Http/Controllers/Items/Items.php +++ b/app/Http/Controllers/Items/Items.php @@ -56,7 +56,7 @@ class Items extends Controller $item = Item::create($request->input()); // Upload picture - if ($media) { + if ($request->file('picture')) { $media = $this->getMedia($request->file('picture'), 'items'); $item->attachMedia($media, 'picture'); @@ -141,7 +141,7 @@ class Items extends Controller $item->update($request->input()); // Upload picture - if ($media) { + if ($request->file('picture')) { $media = $this->getMedia($request->file('picture'), 'items'); $item->syncMedia($media, 'picture'); diff --git a/app/Models/Common/Media.php b/app/Models/Common/Media.php index 744d67644..517b12394 100644 --- a/app/Models/Common/Media.php +++ b/app/Models/Common/Media.php @@ -11,4 +11,4 @@ class Media extends PMedia protected $dates = ['deleted_at']; -} \ No newline at end of file +} diff --git a/app/Traits/Uploads.php b/app/Traits/Uploads.php index 07c5074ec..a4364158b 100644 --- a/app/Traits/Uploads.php +++ b/app/Traits/Uploads.php @@ -36,10 +36,8 @@ trait Uploads $company_id = session('company_id'); } - $path = config('filesystems.disks.uploads.root') . '/' . $company_id . '/' . $folder; + $path = $company_id . '/' . $folder; - config(['filesystems.disks.uploads.root' => $path]); - - return MediaUploader::fromSource($file)->upload(); + return MediaUploader::fromSource($file)->toDirectory($path)->upload(); } } diff --git a/resources/views/incomes/invoices/show.blade.php b/resources/views/incomes/invoices/show.blade.php index 18109d0bb..e0d324c4a 100644 --- a/resources/views/incomes/invoices/show.blade.php +++ b/resources/views/incomes/invoices/show.blade.php @@ -189,7 +189,7 @@ {!! Form::open([ 'id' => 'attachment-' . $invoice->attachment->id, 'method' => 'DELETE', - 'url' => [url('uploads/invoices/' . $invoice->attachment->id)], + 'url' => [url('uploads/' . $invoice->attachment->id)], 'style' => 'display:inline' ]) !!} {{ Form::hidden('id', $invoice->id) }} diff --git a/routes/web.php b/routes/web.php index ecd605e03..c8802ee7c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -9,8 +9,8 @@ Route::group(['middleware' => 'language'], function () { Route::group(['middleware' => 'auth'], function () { Route::group(['prefix' => 'uploads'], function () { - Route::get('{folder}/{file}', 'Common\Uploads@get'); - Route::get('{folder}/{file}/download', 'Common\Uploads@download'); + Route::get('{id}', 'Common\Uploads@get'); + Route::get('{id}/download', 'Common\Uploads@download'); Route::delete('{id}', 'Common\Uploads@destroy'); }); From dd686409ef8ae224bcb1407b06435a60671fc260 Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Tue, 2 Jan 2018 17:54:10 +0300 Subject: [PATCH 06/13] 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() { From 675b1ba42ad94155797de7fab4be7aae4e3bd59f Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Tue, 2 Jan 2018 18:20:52 +0300 Subject: [PATCH 07/13] Other file added --- app/Models/Expense/Bill.php | 17 ++++++++++++- app/Models/Expense/BillPayment.php | 17 ++++++++++++- app/Models/Expense/Payment.php | 17 ++++++++++++- app/Models/Income/InvoicePayment.php | 17 ++++++++++++- app/Models/Income/Revenue.php | 17 ++++++++++++- resources/views/expenses/bills/edit.blade.php | 25 ++++++++++++++++++- resources/views/expenses/bills/show.blade.php | 25 +++++++++++++++++++ .../views/expenses/payments/edit.blade.php | 25 ++++++++++++++++++- .../views/incomes/invoices/edit.blade.php | 5 +++- .../views/incomes/invoices/show.blade.php | 1 - .../views/incomes/revenues/edit.blade.php | 25 ++++++++++++++++++- 11 files changed, 181 insertions(+), 10 deletions(-) diff --git a/app/Models/Expense/Bill.php b/app/Models/Expense/Bill.php index ca4dd2be7..8a4eb4d76 100644 --- a/app/Models/Expense/Bill.php +++ b/app/Models/Expense/Bill.php @@ -7,10 +7,11 @@ use App\Traits\Currencies; use App\Traits\DateTime; use Bkwld\Cloner\Cloneable; use Sofa\Eloquence\Eloquence; +use Plank\Mediable\Mediable; class Bill extends Model { - use Cloneable, Currencies, DateTime, Eloquence; + use Cloneable, Currencies, DateTime, Eloquence, Mediable; protected $table = 'bills'; @@ -128,4 +129,18 @@ class Bill extends Model { $this->attributes['currency_rate'] = (double) $value; } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute() + { + if (!$this->hasMedia('attachment')) { + return false; + } + + return $this->getMedia('attachment')->last(); + } } diff --git a/app/Models/Expense/BillPayment.php b/app/Models/Expense/BillPayment.php index 4397bddf6..b0f9c6dca 100644 --- a/app/Models/Expense/BillPayment.php +++ b/app/Models/Expense/BillPayment.php @@ -5,10 +5,11 @@ namespace App\Models\Expense; use App\Models\Model; use App\Traits\Currencies; use App\Traits\DateTime; +use Plank\Mediable\Mediable; class BillPayment extends Model { - use Currencies, DateTime; + use Currencies, DateTime, Mediable; protected $table = 'bill_payments'; @@ -78,4 +79,18 @@ class BillPayment extends Model { return $query->sum('amount'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute() + { + if (!$this->hasMedia('attachment')) { + return false; + } + + return $this->getMedia('attachment')->last(); + } } diff --git a/app/Models/Expense/Payment.php b/app/Models/Expense/Payment.php index ae3e230c8..f10133066 100644 --- a/app/Models/Expense/Payment.php +++ b/app/Models/Expense/Payment.php @@ -7,10 +7,11 @@ use App\Traits\Currencies; use App\Traits\DateTime; use Bkwld\Cloner\Cloneable; use Sofa\Eloquence\Eloquence; +use Plank\Mediable\Mediable; class Payment extends Model { - use Cloneable, Currencies, DateTime, Eloquence; + use Cloneable, Currencies, DateTime, Eloquence, Mediable; protected $table = 'payments'; @@ -91,4 +92,18 @@ class Payment extends Model { return $query->orderBy('paid_at', 'desc'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute() + { + if (!$this->hasMedia('attachment')) { + return false; + } + + return $this->getMedia('attachment')->last(); + } } diff --git a/app/Models/Income/InvoicePayment.php b/app/Models/Income/InvoicePayment.php index 615b65a90..ed7977ffd 100644 --- a/app/Models/Income/InvoicePayment.php +++ b/app/Models/Income/InvoicePayment.php @@ -5,10 +5,11 @@ namespace App\Models\Income; use App\Models\Model; use App\Traits\Currencies; use App\Traits\DateTime; +use Plank\Mediable\Mediable; class InvoicePayment extends Model { - use Currencies, DateTime; + use Currencies, DateTime, Mediable; protected $table = 'invoice_payments'; @@ -78,4 +79,18 @@ class InvoicePayment extends Model { return $query->sum('amount'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute() + { + if (!$this->hasMedia('attachment')) { + return false; + } + + return $this->getMedia('attachment')->last(); + } } diff --git a/app/Models/Income/Revenue.php b/app/Models/Income/Revenue.php index 60c4f8b89..221c54632 100644 --- a/app/Models/Income/Revenue.php +++ b/app/Models/Income/Revenue.php @@ -7,10 +7,11 @@ use App\Traits\Currencies; use App\Traits\DateTime; use Bkwld\Cloner\Cloneable; use Sofa\Eloquence\Eloquence; +use Plank\Mediable\Mediable; class Revenue extends Model { - use Cloneable, Currencies, DateTime, Eloquence; + use Cloneable, Currencies, DateTime, Eloquence, Mediable; protected $table = 'revenues'; @@ -97,4 +98,18 @@ class Revenue extends Model { return $query->orderBy('paid_at', 'desc'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute() + { + if (!$this->hasMedia('attachment')) { + return false; + } + + return $this->getMedia('attachment')->last(); + } } diff --git a/resources/views/expenses/bills/edit.blade.php b/resources/views/expenses/bills/edit.blade.php index d0dc1ebb0..5c87e0524 100644 --- a/resources/views/expenses/bills/edit.blade.php +++ b/resources/views/expenses/bills/edit.blade.php @@ -204,9 +204,32 @@ $('#attachment').fancyfile({ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', - placeholder : 'attachment; ?>' + @if($bill->attachment) + placeholder : 'attachment->basename; ?>' + @endif }); + @if($bill->attachment) + attachment_html = ''; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {{ $bill->attachment->basename }}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::open(['id' => 'attachment-' . $bill->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $bill->attachment->id)], 'style' => 'display:inline']) !!}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::close() !!}'; + attachment_html += ''; + + $('.fancy-file .fake-file').append(attachment_html); + + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $bill->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $bill->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif + var autocomplete_path = "{{ url('items/items/autocomplete') }}"; $(document).on('click', '.form-control.typeahead', function() { diff --git a/resources/views/expenses/bills/show.blade.php b/resources/views/expenses/bills/show.blade.php index a32104653..46508b6e2 100644 --- a/resources/views/expenses/bills/show.blade.php +++ b/resources/views/expenses/bills/show.blade.php @@ -167,6 +167,26 @@ @endpermission + + @if($bill->attachment) + + + + {{ $bill->attachment->basename }} + + + {!! Form::open([ + 'id' => 'attachment-' . $bill->attachment->id, + 'method' => 'DELETE', + 'url' => [url('uploads/' . $bill->attachment->id)], + 'style' => 'display:inline' + ]) !!} + + + + {!! Form::close() !!} + + @endif @@ -403,6 +423,11 @@ $('#email-modal').modal('show'); }); + @if($bill->attachment) + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $bill->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $bill->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif }); function addPayment() { diff --git a/resources/views/expenses/payments/edit.blade.php b/resources/views/expenses/payments/edit.blade.php index b86844a92..92f723f77 100644 --- a/resources/views/expenses/payments/edit.blade.php +++ b/resources/views/expenses/payments/edit.blade.php @@ -92,9 +92,32 @@ $('#attachment').fancyfile({ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', - placeholder : 'attachment) ? $payment->attachment : trans('general.form.no_file_selected'); ?>' + @if($payment->attachment) + placeholder : 'attachment->basename; ?>' + @endif }); + @if($payment->attachment) + attachment_html = ''; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {{ $payment->attachment->basename }}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::open(['id' => 'attachment-' . $payment->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $payment->attachment->id)], 'style' => 'display:inline']) !!}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::close() !!}'; + attachment_html += ''; + + $('.fancy-file .fake-file').append(attachment_html); + + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $payment->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $payment->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif + $(document).on('change', '#account_id', function (e) { $.ajax({ url: '{{ url("settings/currencies/currency") }}', diff --git a/resources/views/incomes/invoices/edit.blade.php b/resources/views/incomes/invoices/edit.blade.php index e87f6c95c..7834e0cf8 100644 --- a/resources/views/incomes/invoices/edit.blade.php +++ b/resources/views/incomes/invoices/edit.blade.php @@ -216,7 +216,6 @@ 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 += ' '; @@ -224,6 +223,10 @@ attachment_html += ''; $('.fancy-file .fake-file').append(attachment_html); + + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $invoice->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $invoice->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); @endif var autocomplete_path = "{{ url('items/items/autocomplete') }}"; diff --git a/resources/views/incomes/invoices/show.blade.php b/resources/views/incomes/invoices/show.blade.php index e0d324c4a..fdbd4e8f7 100644 --- a/resources/views/incomes/invoices/show.blade.php +++ b/resources/views/incomes/invoices/show.blade.php @@ -192,7 +192,6 @@ 'url' => [url('uploads/' . $invoice->attachment->id)], 'style' => 'display:inline' ]) !!} - {{ Form::hidden('id', $invoice->id) }} diff --git a/resources/views/incomes/revenues/edit.blade.php b/resources/views/incomes/revenues/edit.blade.php index e49e88645..c25a3d437 100644 --- a/resources/views/incomes/revenues/edit.blade.php +++ b/resources/views/incomes/revenues/edit.blade.php @@ -92,9 +92,32 @@ $('#attachment').fancyfile({ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', - placeholder : 'attachment; ?>' + @if($revenue->attachment) + placeholder : 'attachment->basename; ?>' + @endif }); + @if($revenue->attachment) + attachment_html = ''; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {{ $revenue->attachment->basename }}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::open(['id' => 'attachment-' . $revenue->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $revenue->attachment->id)], 'style' => 'display:inline']) !!}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::close() !!}'; + attachment_html += ''; + + $('.fancy-file .fake-file').append(attachment_html); + + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $revenue->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $revenue->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif + $(document).on('change', '#account_id', function (e) { $.ajax({ url: '{{ url("settings/currencies/currency") }}', From e3b736d3e8f9a95cd377f4e167230d734f55e64e Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Tue, 2 Jan 2018 19:00:07 +0300 Subject: [PATCH 08/13] Company logo added media manager --- app/Http/Controllers/Companies/Companies.php | 26 ++++++++++++++----- app/Models/Company/Company.php | 17 +++++++++++- app/Traits/Uploads.php | 8 +++++- .../views/companies/companies/edit.blade.php | 25 +++++++++++++++++- 4 files changed, 67 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Companies/Companies.php b/app/Http/Controllers/Companies/Companies.php index 2af1bdf36..c36f832a4 100644 --- a/app/Http/Controllers/Companies/Companies.php +++ b/app/Http/Controllers/Companies/Companies.php @@ -59,9 +59,16 @@ class Companies extends Controller setting()->set('general.company_email', $request->get('company_email')); setting()->set('general.company_address', $request->get('company_address')); - $logo_path = $this->getUploadedFilePath($request->file('company_logo'), 'settings', $company->id); - if ($logo_path) { - setting()->set('general.company_logo', $logo_path); + if ($request->file('company_logo')) { + $logo = $this->getMedia($request->file('company_logo'), 'settings', $company->id); + + if ($logo) { + $company->attachMedia($logo, 'logo'); + + $logo_path = $logo->directory . '/' . $logo->basename; + + setting()->set('general.company_logo', $logo_path); + } } setting()->set('general.default_currency', $request->get('default_currency')); @@ -135,9 +142,16 @@ class Companies extends Controller setting()->set('general.company_email', $request->get('company_email')); setting()->set('general.company_address', $request->get('company_address')); - $logo_path = $this->getUploadedFilePath($request->file('company_logo'), 'settings', $company->id); - if ($logo_path) { - setting()->set('general.company_logo', $logo_path); + if ($request->file('company_logo')) { + $logo = $this->getMedia($request->file('company_logo'), 'settings', $company->id); + + if ($logo) { + $company->attachMedia($logo, 'logo'); + + $logo_path = $logo->directory . '/' . $logo->basename; + + setting()->set('general.company_logo', $logo_path); + } } setting()->set('general.default_payment_method', 'offlinepayment.cash.1'); diff --git a/app/Models/Company/Company.php b/app/Models/Company/Company.php index 893778fe5..3c0953e73 100644 --- a/app/Models/Company/Company.php +++ b/app/Models/Company/Company.php @@ -7,10 +7,11 @@ use EloquentFilter\Filterable; use Illuminate\Database\Eloquent\Model as Eloquent; use Illuminate\Database\Eloquent\SoftDeletes; use Kyslik\ColumnSortable\Sortable; +use Plank\Mediable\Mediable; class Company extends Eloquent { - use Filterable, SoftDeletes, Sortable; + use Filterable, SoftDeletes, Sortable, Mediable; protected $table = 'companies'; @@ -229,4 +230,18 @@ class Company extends Eloquent ->orderBy('value', $direction) ->select('companies.*'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getLogoAttribute() + { + if (!$this->hasMedia('logo')) { + return false; + } + + return $this->getMedia('logo')->last(); + } } diff --git a/app/Traits/Uploads.php b/app/Traits/Uploads.php index a4364158b..8adfbd28c 100644 --- a/app/Traits/Uploads.php +++ b/app/Traits/Uploads.php @@ -30,8 +30,14 @@ trait Uploads return $path; } - public function getMedia($file, $folder, $company_id = null) + public function getMedia($file, $folder = 'settings', $company_id = null) { + $path = ''; + + if (!$file || !$file->isValid()) { + return $path; + } + if (!$company_id) { $company_id = session('company_id'); } diff --git a/resources/views/companies/companies/edit.blade.php b/resources/views/companies/companies/edit.blade.php index ad66c0155..f3f64f50b 100644 --- a/resources/views/companies/companies/edit.blade.php +++ b/resources/views/companies/companies/edit.blade.php @@ -61,8 +61,31 @@ $('#company_logo').fancyfile({ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', - placeholder : 'company_logo; ?>' + @if($company->logo) + placeholder : 'logo->basename; ?>' + @endif }); + + @if($company->logo) + attachment_html = ''; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {{ $company->logo->basename }}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::open(['id' => 'attachment-' . $company->logo->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $company->logo->id)], 'style' => 'display:inline']) !!}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::close() !!}'; + attachment_html += ''; + + $('.fancy-file .fake-file').append(attachment_html); + + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $company->logo->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $company->logo->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif }); @endpush From 43619d1db46e8ebdeaa2a2f8daf573625b05ed1d Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Wed, 3 Jan 2018 14:02:27 +0300 Subject: [PATCH 09/13] Add User, Companies, Settings picture media manager --- app/Http/Controllers/Auth/Users.php | 37 +++++++------ app/Http/Controllers/Companies/Companies.php | 8 +-- app/Http/Controllers/Expenses/Bills.php | 16 +++--- app/Http/Controllers/Incomes/Invoices.php | 2 +- app/Http/Controllers/Settings/Settings.php | 30 +++++++++-- app/Models/Auth/User.php | 9 +++- app/Models/Item/Item.php | 17 +++++- resources/views/auth/users/edit.blade.php | 27 +++++++++- resources/views/auth/users/index.blade.php | 2 +- .../views/companies/companies/edit.blade.php | 2 + .../views/customers/profile/edit.blade.php | 4 ++ resources/views/expenses/bills/edit.blade.php | 2 + .../views/expenses/payments/edit.blade.php | 2 + .../views/incomes/invoices/edit.blade.php | 2 + .../views/incomes/revenues/edit.blade.php | 2 + resources/views/items/items/edit.blade.php | 27 +++++++++- resources/views/items/items/index.blade.php | 2 +- .../views/partials/admin/header.blade.php | 4 +- .../views/partials/customer/header.blade.php | 4 +- .../views/settings/settings/edit.blade.php | 53 ++++++++++++++++++- 20 files changed, 205 insertions(+), 47 deletions(-) diff --git a/app/Http/Controllers/Auth/Users.php b/app/Http/Controllers/Auth/Users.php index 75933b591..af89e32f6 100644 --- a/app/Http/Controllers/Auth/Users.php +++ b/app/Http/Controllers/Auth/Users.php @@ -7,11 +7,14 @@ use App\Http\Requests\Auth\User as Request; use Illuminate\Http\Request as ARequest; use App\Models\Auth\User; use App\Models\Auth\Role; +use App\Traits\Uploads; use Auth; class Users extends Controller { + use Uploads; + /** * Display a listing of the resource. * @@ -34,11 +37,12 @@ class Users extends Controller */ public function create() { - $roles = Role::all()->reject(function($r) { + $roles = Role::all()->reject(function ($r) { return $r->hasPermission('read-customer-panel'); }); $companies = Auth::user()->companies()->get()->sortBy('name'); + foreach ($companies as $company) { $company->setSettings(); } @@ -55,15 +59,16 @@ class Users extends Controller */ public function store(Request $request) { - // Upload picture - $picture = $request->file('picture'); - if ($picture && $picture->isValid()) { - $request['picture'] = $picture->store('uploads/users'); - } - // Create user $user = User::create($request->input()); + // Upload picture + if ($request->file('picture')) { + $media = $this->getMedia($request->file('picture'), 'users'); + + $user->attachMedia($media, 'picture'); + } + // Attach roles $user->roles()->attach($request['roles']); @@ -88,17 +93,18 @@ class Users extends Controller { if ($user->customer) { // Show only roles with customer permission - $roles = Role::all()->reject(function($r) { + $roles = Role::all()->reject(function ($r) { return !$r->hasPermission('read-customer-panel'); }); } else { // Don't show roles with customer permission - $roles = Role::all()->reject(function($r) { + $roles = Role::all()->reject(function ($r) { return $r->hasPermission('read-customer-panel'); }); } $companies = Auth::user()->companies()->get()->sortBy('name'); + foreach ($companies as $company) { $company->setSettings(); } @@ -116,12 +122,6 @@ class Users extends Controller */ public function update(User $user, Request $request) { - // Upload picture - $picture = $request->file('picture'); - if ($picture && $picture->isValid()) { - $request['picture'] = $picture->store('users'); - } - // Do not reset password if not entered/changed if (empty($request['password'])) { unset($request['password']); @@ -131,6 +131,13 @@ class Users extends Controller // Update user $user->update($request->input()); + // Upload picture + if ($request->file('picture')) { + $media = $this->getMedia($request->file('picture'), 'users'); + + $user->attachMedia($media, 'picture'); + } + // Sync roles $user->roles()->sync($request['roles']); diff --git a/app/Http/Controllers/Companies/Companies.php b/app/Http/Controllers/Companies/Companies.php index c36f832a4..4ca09d084 100644 --- a/app/Http/Controllers/Companies/Companies.php +++ b/app/Http/Controllers/Companies/Companies.php @@ -65,9 +65,7 @@ class Companies extends Controller if ($logo) { $company->attachMedia($logo, 'logo'); - $logo_path = $logo->directory . '/' . $logo->basename; - - setting()->set('general.company_logo', $logo_path); + setting()->set('general.company_logo', $logo->id); } } @@ -148,9 +146,7 @@ class Companies extends Controller if ($logo) { $company->attachMedia($logo, 'logo'); - $logo_path = $logo->directory . '/' . $logo->basename; - - setting()->set('general.company_logo', $logo_path); + setting()->set('general.company_logo', $logo->id); } } diff --git a/app/Http/Controllers/Expenses/Bills.php b/app/Http/Controllers/Expenses/Bills.php index 2e389ac66..3ed135125 100644 --- a/app/Http/Controllers/Expenses/Bills.php +++ b/app/Http/Controllers/Expenses/Bills.php @@ -132,7 +132,7 @@ class Bills extends Controller // Upload attachment if ($request->file('attachment')) { - $media = $this->getMedia($request->file('attachment'), 'revenues'); + $media = $this->getMedia($request->file('attachment'), 'bills'); $bill->attachMedia($media, 'attachment'); } @@ -597,13 +597,6 @@ class Bills extends Controller $bill = Bill::find($request['bill_id']); - // Upload attachment - if ($request->file('attachment')) { - $media = $this->getMedia($request->file('attachment'), 'payments'); - - $bill->attachMedia($media, 'attachment'); - } - $total_amount = $bill->amount; $amount = (double) $request['amount']; @@ -640,6 +633,13 @@ class Bills extends Controller $bill_payment = BillPayment::create($request->input()); + // Upload attachment + if ($request->file('attachment')) { + $media = $this->getMedia($request->file('attachment'), 'bills'); + + $bill_payment->attachMedia($media, 'attachment'); + } + $request['status_code'] = $bill->bill_status_code; $request['notify'] = 0; diff --git a/app/Http/Controllers/Incomes/Invoices.php b/app/Http/Controllers/Incomes/Invoices.php index 870c7625f..772216f00 100644 --- a/app/Http/Controllers/Incomes/Invoices.php +++ b/app/Http/Controllers/Incomes/Invoices.php @@ -141,7 +141,7 @@ class Invoices extends Controller // Upload attachment if ($request->file('attachment')) { - $media = $this->getMedia($request->file('attachment'), 'revenues'); + $media = $this->getMedia($request->file('attachment'), 'invoices'); $invoice->attachMedia($media, 'attachment'); } diff --git a/app/Http/Controllers/Settings/Settings.php b/app/Http/Controllers/Settings/Settings.php index aeb075f48..5f7c849e2 100644 --- a/app/Http/Controllers/Settings/Settings.php +++ b/app/Http/Controllers/Settings/Settings.php @@ -8,6 +8,7 @@ use App\Models\Banking\Account; use App\Models\Company\Company; use App\Models\Setting\Currency; use App\Models\Setting\Setting; +use App\Models\Common\Media; use App\Models\Setting\Tax; use App\Traits\DateTime; use App\Traits\Uploads; @@ -26,11 +27,20 @@ class Settings extends Controller public function edit() { /*$setting = Setting::all()->pluck('value', 'key');*/ - $setting = Setting::all()->map(function($s) { + $setting = Setting::all()->map(function ($s) { $s->key = str_replace('general.', '', $s->key); + return $s; })->pluck('value', 'key'); + $company_logo = $setting->pull('company_logo'); + + $setting['company_logo'] = Media::find($company_logo); + + $invoice_logo = $setting->pull('invoice_logo'); + + $setting['invoice_logo'] = Media::find($invoice_logo); + $timezones = $this->getTimezones(); $accounts = Account::enabled()->pluck('name', 'id'); @@ -88,7 +98,13 @@ class Settings extends Controller { $fields = $request->all(); $company_id = $request->get('company_id'); - + + if (empty($company_id)) { + $company_id = session('company_id'); + } + + $company = Company::find($company_id); + $skip_keys = ['company_id', '_method', '_token']; $file_keys = ['company_logo', 'invoice_logo']; @@ -102,7 +118,14 @@ class Settings extends Controller // Process file uploads if (in_array($key, $file_keys)) { - $value = $this->getUploadedFilePath($request->file($key), 'settings'); + // Upload attachment + if ($request->file($key)) { + $media = $this->getMedia($request->file($key), 'settings'); + + $company->attachMedia($media, $key); + + $value = $media->id; + } // Prevent reset if (empty($value)) { @@ -133,5 +156,4 @@ class Settings extends Controller return redirect('settings/settings'); } - } diff --git a/app/Models/Auth/User.php b/app/Models/Auth/User.php index e760f724d..ce0b5f87d 100644 --- a/app/Models/Auth/User.php +++ b/app/Models/Auth/User.php @@ -12,12 +12,13 @@ use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laratrust\Traits\LaratrustUserTrait; use Kyslik\ColumnSortable\Sortable; +use Plank\Mediable\Mediable; use Request; use Route; class User extends Authenticatable { - use Filterable, LaratrustUserTrait, Notifiable, SoftDeletes, Sortable; + use Filterable, LaratrustUserTrait, Notifiable, SoftDeletes, Sortable, Mediable; protected $table = 'users'; @@ -88,7 +89,11 @@ class User extends Authenticatable } } - return $value; + if (!$this->hasMedia('picture')) { + return false; + } + + return $this->getMedia('picture')->last(); } /** diff --git a/app/Models/Item/Item.php b/app/Models/Item/Item.php index 9095186b9..8ab9706d3 100644 --- a/app/Models/Item/Item.php +++ b/app/Models/Item/Item.php @@ -6,10 +6,11 @@ use App\Models\Model; use App\Traits\Currencies; use Bkwld\Cloner\Cloneable; use Sofa\Eloquence\Eloquence; +use Plank\Mediable\Mediable; class Item extends Model { - use Cloneable, Currencies, Eloquence; + use Cloneable, Currencies, Eloquence, Mediable; protected $table = 'items'; @@ -111,4 +112,18 @@ class Item extends Model ->orderBy('name', $direction) ->select('items.*'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getPictureAttribute() + { + if (!$this->hasMedia('picture')) { + return false; + } + + return $this->getMedia('picture')->last(); + } } diff --git a/resources/views/auth/users/edit.blade.php b/resources/views/auth/users/edit.blade.php index ba44e9bf7..1c2d1b9b0 100644 --- a/resources/views/auth/users/edit.blade.php +++ b/resources/views/auth/users/edit.blade.php @@ -71,9 +71,34 @@ $('#picture').fancyfile({ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', - placeholder : 'picture; ?>' + @if($user->picture) + placeholder : 'picture->basename; ?>' + @else + placeholder : '{{ trans('general.form.no_file_selected') }}' + @endif }); + @if($user->picture) + picture_html = ''; + picture_html += ' '; + picture_html += ' '; + picture_html += ' {{ $user->picture->basename }}'; + picture_html += ' '; + picture_html += ' '; + picture_html += ' {!! Form::open(['id' => 'picture-' . $user->picture->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $user->picture->id)], 'style' => 'display:inline']) !!}'; + picture_html += ' '; + picture_html += ' '; + picture_html += ' '; + picture_html += ' {!! Form::close() !!}'; + picture_html += ''; + + $('.fancy-file .fake-file').append(picture_html); + + $(document).on('click', '#remove-picture', function (e) { + confirmDelete("#picture-{!! $user->picture->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $user->picture->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif + $('input[type=checkbox]').iCheck({ checkboxClass: 'icheckbox_square-green', radioClass: 'iradio_square-green', diff --git a/resources/views/auth/users/index.blade.php b/resources/views/auth/users/index.blade.php index 5504819a4..6b71dedab 100644 --- a/resources/views/auth/users/index.blade.php +++ b/resources/views/auth/users/index.blade.php @@ -44,7 +44,7 @@ @if ($item->picture) - {{ $item->name }} + {{ $item->name }} @endif {{ $item->name }} diff --git a/resources/views/companies/companies/edit.blade.php b/resources/views/companies/companies/edit.blade.php index f3f64f50b..3cb4cdc69 100644 --- a/resources/views/companies/companies/edit.blade.php +++ b/resources/views/companies/companies/edit.blade.php @@ -63,6 +63,8 @@ style : 'btn-default', @if($company->logo) placeholder : 'logo->basename; ?>' + @else + placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); diff --git a/resources/views/customers/profile/edit.blade.php b/resources/views/customers/profile/edit.blade.php index aaf544b35..72bcf67d2 100644 --- a/resources/views/customers/profile/edit.blade.php +++ b/resources/views/customers/profile/edit.blade.php @@ -62,7 +62,11 @@ $('#picture').fancyfile({ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', + @if($user->picture) placeholder : 'picture; ?>' + @else + placeholder : '{{ trans('general.form.no_file_selected') }}' + @endif }); }); diff --git a/resources/views/expenses/bills/edit.blade.php b/resources/views/expenses/bills/edit.blade.php index 5c87e0524..93d52a6a6 100644 --- a/resources/views/expenses/bills/edit.blade.php +++ b/resources/views/expenses/bills/edit.blade.php @@ -206,6 +206,8 @@ style : 'btn-default', @if($bill->attachment) placeholder : 'attachment->basename; ?>' + @else + placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); diff --git a/resources/views/expenses/payments/edit.blade.php b/resources/views/expenses/payments/edit.blade.php index 92f723f77..f32d3fdc1 100644 --- a/resources/views/expenses/payments/edit.blade.php +++ b/resources/views/expenses/payments/edit.blade.php @@ -94,6 +94,8 @@ style : 'btn-default', @if($payment->attachment) placeholder : 'attachment->basename; ?>' + @else + placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); diff --git a/resources/views/incomes/invoices/edit.blade.php b/resources/views/incomes/invoices/edit.blade.php index 7834e0cf8..a5b949116 100644 --- a/resources/views/incomes/invoices/edit.blade.php +++ b/resources/views/incomes/invoices/edit.blade.php @@ -205,6 +205,8 @@ style : 'btn-default', @if($invoice->attachment) placeholder : 'attachment->basename; ?>' + @else + placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); diff --git a/resources/views/incomes/revenues/edit.blade.php b/resources/views/incomes/revenues/edit.blade.php index c25a3d437..1fa8bac12 100644 --- a/resources/views/incomes/revenues/edit.blade.php +++ b/resources/views/incomes/revenues/edit.blade.php @@ -94,6 +94,8 @@ style : 'btn-default', @if($revenue->attachment) placeholder : 'attachment->basename; ?>' + @else + placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); diff --git a/resources/views/items/items/edit.blade.php b/resources/views/items/items/edit.blade.php index f85595288..555b74e36 100644 --- a/resources/views/items/items/edit.blade.php +++ b/resources/views/items/items/edit.blade.php @@ -70,8 +70,33 @@ $('#picture').fancyfile({ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', - placeholder : 'picture; ?>' + @if($item->picture) + placeholder : 'picture->basename; ?>' + @else + placeholder : '{{ trans('general.form.no_file_selected') }}' + @endif }); + + @if($item->picture) + picture_html = ''; + picture_html += ' '; + picture_html += ' '; + picture_html += ' {{ $item->picture->basename }}'; + picture_html += ' '; + picture_html += ' '; + picture_html += ' {!! Form::open(['id' => 'picture-' . $item->picture->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $item->picture->id)], 'style' => 'display:inline']) !!}'; + picture_html += ' '; + picture_html += ' '; + picture_html += ' '; + picture_html += ' {!! Form::close() !!}'; + picture_html += ''; + + $('.fancy-file .fake-file').append(picture_html); + + $(document).on('click', '#remove-picture', function (e) { + confirmDelete("#picture-{!! $item->picture->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $item->picture->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif }); @endpush diff --git a/resources/views/items/items/index.blade.php b/resources/views/items/items/index.blade.php index 74271f61e..bedfa54b6 100644 --- a/resources/views/items/items/index.blade.php +++ b/resources/views/items/items/index.blade.php @@ -46,7 +46,7 @@ @foreach($items as $item) - {{ $item->name }} + {{ $item->name }} {{ $item->name }} {{ $item->category ? $item->category->name : trans('general.na') }} {{ $item->quantity }} diff --git a/resources/views/partials/admin/header.blade.php b/resources/views/partials/admin/header.blade.php index da4735265..7da62347f 100644 --- a/resources/views/partials/admin/header.blade.php +++ b/resources/views/partials/admin/header.blade.php @@ -166,7 +166,7 @@ @if (setting('general.use_gravatar', '0') == '1') User Image @else - User Image + User Image @endif @else @@ -182,7 +182,7 @@ @if (setting('general.use_gravatar', '0') == '1') User Image @else - User Image + User Image @endif @else diff --git a/resources/views/partials/customer/header.blade.php b/resources/views/partials/customer/header.blade.php index 27d5c3437..f7cd661bf 100644 --- a/resources/views/partials/customer/header.blade.php +++ b/resources/views/partials/customer/header.blade.php @@ -60,7 +60,7 @@
  • @if ($user->picture) - User Image + User Image @else @endif diff --git a/resources/views/settings/settings/edit.blade.php b/resources/views/settings/settings/edit.blade.php index bea4802c4..1ecbeca75 100644 --- a/resources/views/settings/settings/edit.blade.php +++ b/resources/views/settings/settings/edit.blade.php @@ -203,15 +203,64 @@ $('#company_logo').fancyfile({ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', - placeholder : 'pull('company_logo'); ?>' + @if($setting['company_logo']) + placeholder : 'basename; ?>' + @else + placeholder : '{{ trans('general.form.no_file_selected') }}' + @endif }); + @if($setting['company_logo']) + company_logo_html = ''; + company_logo_html += ' '; + company_logo_html += ' '; + company_logo_html += ' {!! Form::open(['id' => 'company_logo-' . $setting['company_logo']->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $setting['company_logo']->id)], 'style' => 'display:inline']) !!}'; + company_logo_html += ' '; + company_logo_html += ' {!! Form::close() !!}'; + company_logo_html += ''; + + $('#company .fancy-file .fake-file').append(company_logo_html); + + $(document).on('click', '#remove-company_logo', function (e) { + confirmDelete("#company_logo-{!! $setting['company_logo']->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $setting['company_logo']->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif + $('#invoice_logo').fancyfile({ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', - placeholder : 'pull('invoice_logo'); ?>' + @if($setting['invoice_logo']) + placeholder : 'basename; ?>' + @else + placeholder : '{{ trans('general.form.no_file_selected') }}' + @endif }); + @if($setting['invoice_logo']) + invoice_logo_html = ''; + + $('#invoice .fancy-file .fake-file').append(invoice_logo_html); + + $(document).on('click', '#remove-invoice_logo', function (e) { + confirmDelete("#invoice_logo-{!! $setting['invoice_logo']->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $setting['invoice_logo']->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif $("select[name='email_protocol']").on('change', function() { var selection = $(this).val(); From 3ffdb98a4b318a1964c42e1f938b6d782f387f7e Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Wed, 3 Jan 2018 15:21:50 +0300 Subject: [PATCH 10/13] Invoice logo and Customer profile picture --- app/Http/Controllers/Customers/Profile.php | 15 +++++++----- app/Http/Controllers/Incomes/Invoices.php | 17 ++++++++++---- .../views/customers/profile/edit.blade.php | 23 ++++++++++++++++++- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Customers/Profile.php b/app/Http/Controllers/Customers/Profile.php index b75ad6d17..7fea1c08f 100644 --- a/app/Http/Controllers/Customers/Profile.php +++ b/app/Http/Controllers/Customers/Profile.php @@ -5,9 +5,11 @@ namespace App\Http\Controllers\Customers; use App\Http\Controllers\Controller; use App\Http\Requests\Customer\Profile as Request; use App\Models\Auth\User; +use App\Traits\Uploads; class Profile extends Controller { + use Uploads; public function index() { @@ -42,12 +44,6 @@ class Profile extends Controller { $user = auth()->user(); - // Upload picture - $picture = $request->file('picture'); - if ($picture && $picture->isValid()) { - $request['picture'] = $picture->store('users'); - } - // Do not reset password if not entered/changed if (empty($request['password'])) { unset($request['password']); @@ -57,6 +53,13 @@ class Profile extends Controller // Update user $user->update($request->input()); + // Upload picture + if ($request->file('picture')) { + $media = $this->getMedia($request->file('picture'), 'users'); + + $user->attachMedia($media, 'picture'); + } + // Update customer $user->customer->update($request->input()); diff --git a/app/Http/Controllers/Incomes/Invoices.php b/app/Http/Controllers/Incomes/Invoices.php index 772216f00..e14fe096c 100644 --- a/app/Http/Controllers/Incomes/Invoices.php +++ b/app/Http/Controllers/Incomes/Invoices.php @@ -20,6 +20,7 @@ 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\Notifications\Income\Invoice as Notification; use App\Notifications\Item\Item as ItemNotification; use App\Traits\Currencies; @@ -784,18 +785,26 @@ class Invoices extends Controller { $logo = ''; + $media_id = setting('general.company_logo'); + if (setting('general.invoice_logo')) { - $file = session('company_id') . '/' . setting('general.invoice_logo'); - } else { - $file = session('company_id') . '/' . setting('general.company_logo'); + $media_id = setting('general.invoice_logo'); } - $path = Storage::path($file); + $media = Media::find($media_id); + + if (empty($media)) { + return $logo; + } + + $path = Storage::path($media->getDiskPath()); + if (!is_file($path)) { return $logo; } $image = Image::make($path)->encode()->getEncoded(); + if (empty($image)) { return $logo; } diff --git a/resources/views/customers/profile/edit.blade.php b/resources/views/customers/profile/edit.blade.php index 72bcf67d2..fbe8b774f 100644 --- a/resources/views/customers/profile/edit.blade.php +++ b/resources/views/customers/profile/edit.blade.php @@ -63,11 +63,32 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($user->picture) - placeholder : 'picture; ?>' + placeholder : 'picture->basename; ?>' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); + + @if($user->picture) + picture_html = ''; + picture_html += ' '; + picture_html += ' '; + picture_html += ' {{ $user->picture->basename }}'; + picture_html += ' '; + picture_html += ' '; + picture_html += ' {!! Form::open(['id' => 'picture-' . $user->picture->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $user->picture->id)], 'style' => 'display:inline']) !!}'; + picture_html += ' '; + picture_html += ' '; + picture_html += ' '; + picture_html += ' {!! Form::close() !!}'; + picture_html += ''; + + $('.fancy-file .fake-file').append(picture_html); + + $(document).on('click', '#remove-picture', function (e) { + confirmDelete("#picture-{!! $user->picture->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $user->picture->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif }); @endpush From 3c15d3e96ffbf3f6a64bf9209f429b8ffb6b8d7c Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Wed, 3 Jan 2018 17:54:02 +0300 Subject: [PATCH 11/13] Drop columns and company logo change variable name. --- app/Http/Controllers/Companies/Companies.php | 16 +++++----- app/Listeners/Updates/Version116.php | 28 ++++++++++++++++ app/Models/Company/Company.php | 6 ++-- app/Providers/EventServiceProvider.php | 1 + ...17_12_30_000000_create_mediable_tables.php | 3 +- ..._attachment_column_bill_payments_table.php | 32 +++++++++++++++++++ ...000_drop_attachment_column_bills_table.php | 32 +++++++++++++++++++ ...tachment_column_invoice_payments_table.php | 32 +++++++++++++++++++ ..._drop_attachment_column_invoices_table.php | 32 +++++++++++++++++++ ..._drop_attachment_column_payments_table.php | 32 +++++++++++++++++++ ..._drop_attachment_column_revenues_table.php | 32 +++++++++++++++++++ ...000000_drop_picture_column_items_table.php | 32 +++++++++++++++++++ ...000000_drop_picture_column_users_table.php | 32 +++++++++++++++++++ .../views/companies/companies/edit.blade.php | 14 ++++---- 14 files changed, 304 insertions(+), 20 deletions(-) create mode 100644 app/Listeners/Updates/Version116.php create mode 100644 database/migrations/2018_01_03_000000_drop_attachment_column_bill_payments_table.php create mode 100644 database/migrations/2018_01_03_000000_drop_attachment_column_bills_table.php create mode 100644 database/migrations/2018_01_03_000000_drop_attachment_column_invoice_payments_table.php create mode 100644 database/migrations/2018_01_03_000000_drop_attachment_column_invoices_table.php create mode 100644 database/migrations/2018_01_03_000000_drop_attachment_column_payments_table.php create mode 100644 database/migrations/2018_01_03_000000_drop_attachment_column_revenues_table.php create mode 100644 database/migrations/2018_01_03_000000_drop_picture_column_items_table.php create mode 100644 database/migrations/2018_01_03_000000_drop_picture_column_users_table.php diff --git a/app/Http/Controllers/Companies/Companies.php b/app/Http/Controllers/Companies/Companies.php index 4ca09d084..908937fa0 100644 --- a/app/Http/Controllers/Companies/Companies.php +++ b/app/Http/Controllers/Companies/Companies.php @@ -60,12 +60,12 @@ class Companies extends Controller setting()->set('general.company_address', $request->get('company_address')); if ($request->file('company_logo')) { - $logo = $this->getMedia($request->file('company_logo'), 'settings', $company->id); + $company_logo = $this->getMedia($request->file('company_logo'), 'settings', $company->id); - if ($logo) { - $company->attachMedia($logo, 'logo'); + if ($company_logo) { + $company->attachMedia($company_logo, 'company_logo'); - setting()->set('general.company_logo', $logo->id); + setting()->set('general.company_logo', $company_logo->id); } } @@ -141,12 +141,12 @@ class Companies extends Controller setting()->set('general.company_address', $request->get('company_address')); if ($request->file('company_logo')) { - $logo = $this->getMedia($request->file('company_logo'), 'settings', $company->id); + $company_logo = $this->getMedia($request->file('company_logo'), 'settings', $company->id); - if ($logo) { - $company->attachMedia($logo, 'logo'); + if ($company_logo) { + $company->attachMedia($company_logo, 'company_logo'); - setting()->set('general.company_logo', $logo->id); + setting()->set('general.company_logo', $company_logo->id); } } diff --git a/app/Listeners/Updates/Version116.php b/app/Listeners/Updates/Version116.php new file mode 100644 index 000000000..9dc267726 --- /dev/null +++ b/app/Listeners/Updates/Version116.php @@ -0,0 +1,28 @@ +check($event)) { + return; + } + + } +} diff --git a/app/Models/Company/Company.php b/app/Models/Company/Company.php index 3c0953e73..e04dfe1bc 100644 --- a/app/Models/Company/Company.php +++ b/app/Models/Company/Company.php @@ -236,12 +236,12 @@ class Company extends Eloquent * * @return string */ - public function getLogoAttribute() + public function getCompanyLogoAttribute() { - if (!$this->hasMedia('logo')) { + if (!$this->hasMedia('company_logo')) { return false; } - return $this->getMedia('logo')->last(); + return $this->getMedia('company_logo')->last(); } } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index d76187cda..8ecb8073e 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -21,6 +21,7 @@ class EventServiceProvider extends ServiceProvider 'App\Listeners\Updates\Version110', 'App\Listeners\Updates\Version112', 'App\Listeners\Updates\Version113', + 'App\Listeners\Updates\Version116', ], 'Illuminate\Auth\Events\Login' => [ 'App\Listeners\Auth\Login', diff --git a/database/migrations/2017_12_30_000000_create_mediable_tables.php b/database/migrations/2017_12_30_000000_create_mediable_tables.php index f9dd1f1a4..c85857724 100644 --- a/database/migrations/2017_12_30_000000_create_mediable_tables.php +++ b/database/migrations/2017_12_30_000000_create_mediable_tables.php @@ -41,8 +41,7 @@ class CreateMediableTables extends Migration $table->index(['mediable_id', 'mediable_type']); $table->index('tag'); $table->index('order'); - $table->foreign('media_id')->references('id')->on('media') - ->onDelete('cascade'); + $table->foreign('media_id')->references('id')->on('media')->onDelete('cascade'); }); } diff --git a/database/migrations/2018_01_03_000000_drop_attachment_column_bill_payments_table.php b/database/migrations/2018_01_03_000000_drop_attachment_column_bill_payments_table.php new file mode 100644 index 000000000..b7565245d --- /dev/null +++ b/database/migrations/2018_01_03_000000_drop_attachment_column_bill_payments_table.php @@ -0,0 +1,32 @@ +dropColumn('attachment'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('bill_payments', function (Blueprint $table) { + $table->string('attachment')->nullable(); + }); + } +} diff --git a/database/migrations/2018_01_03_000000_drop_attachment_column_bills_table.php b/database/migrations/2018_01_03_000000_drop_attachment_column_bills_table.php new file mode 100644 index 000000000..d62157b79 --- /dev/null +++ b/database/migrations/2018_01_03_000000_drop_attachment_column_bills_table.php @@ -0,0 +1,32 @@ +dropColumn('attachment'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('bills', function (Blueprint $table) { + $table->string('attachment')->nullable(); + }); + } +} diff --git a/database/migrations/2018_01_03_000000_drop_attachment_column_invoice_payments_table.php b/database/migrations/2018_01_03_000000_drop_attachment_column_invoice_payments_table.php new file mode 100644 index 000000000..87ac83f49 --- /dev/null +++ b/database/migrations/2018_01_03_000000_drop_attachment_column_invoice_payments_table.php @@ -0,0 +1,32 @@ +dropColumn('attachment'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('invoice_payments', function (Blueprint $table) { + $table->string('attachment')->nullable(); + }); + } +} diff --git a/database/migrations/2018_01_03_000000_drop_attachment_column_invoices_table.php b/database/migrations/2018_01_03_000000_drop_attachment_column_invoices_table.php new file mode 100644 index 000000000..be24b7b6e --- /dev/null +++ b/database/migrations/2018_01_03_000000_drop_attachment_column_invoices_table.php @@ -0,0 +1,32 @@ +dropColumn('attachment'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('invoices', function (Blueprint $table) { + $table->string('attachment')->nullable(); + }); + } +} diff --git a/database/migrations/2018_01_03_000000_drop_attachment_column_payments_table.php b/database/migrations/2018_01_03_000000_drop_attachment_column_payments_table.php new file mode 100644 index 000000000..1cc7fb1ad --- /dev/null +++ b/database/migrations/2018_01_03_000000_drop_attachment_column_payments_table.php @@ -0,0 +1,32 @@ +dropColumn('attachment'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('payments', function (Blueprint $table) { + $table->string('attachment')->nullable(); + }); + } +} diff --git a/database/migrations/2018_01_03_000000_drop_attachment_column_revenues_table.php b/database/migrations/2018_01_03_000000_drop_attachment_column_revenues_table.php new file mode 100644 index 000000000..fc890fb6f --- /dev/null +++ b/database/migrations/2018_01_03_000000_drop_attachment_column_revenues_table.php @@ -0,0 +1,32 @@ +dropColumn('attachment'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('revenues', function (Blueprint $table) { + $table->string('attachment')->nullable(); + }); + } +} diff --git a/database/migrations/2018_01_03_000000_drop_picture_column_items_table.php b/database/migrations/2018_01_03_000000_drop_picture_column_items_table.php new file mode 100644 index 000000000..5afe8311b --- /dev/null +++ b/database/migrations/2018_01_03_000000_drop_picture_column_items_table.php @@ -0,0 +1,32 @@ +dropColumn('picture'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('items', function (Blueprint $table) { + $table->string('picture')->nullable(); + }); + } +} diff --git a/database/migrations/2018_01_03_000000_drop_picture_column_users_table.php b/database/migrations/2018_01_03_000000_drop_picture_column_users_table.php new file mode 100644 index 000000000..ed91f6820 --- /dev/null +++ b/database/migrations/2018_01_03_000000_drop_picture_column_users_table.php @@ -0,0 +1,32 @@ +dropColumn('picture'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->string('picture')->nullable(); + }); + } +} diff --git a/resources/views/companies/companies/edit.blade.php b/resources/views/companies/companies/edit.blade.php index 3cb4cdc69..a1ccf03d5 100644 --- a/resources/views/companies/companies/edit.blade.php +++ b/resources/views/companies/companies/edit.blade.php @@ -61,21 +61,21 @@ $('#company_logo').fancyfile({ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', - @if($company->logo) - placeholder : 'logo->basename; ?>' + @if($company->company_logo) + placeholder : 'company_logo->basename; ?>' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); - @if($company->logo) + @if($company->company_logo) attachment_html = ''; - attachment_html += ' '; + attachment_html += ' '; attachment_html += ' '; - attachment_html += ' {{ $company->logo->basename }}'; + attachment_html += ' {{ $company->company_logo->basename }}'; attachment_html += ' '; attachment_html += ' '; - attachment_html += ' {!! Form::open(['id' => 'attachment-' . $company->logo->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $company->logo->id)], 'style' => 'display:inline']) !!}'; + attachment_html += ' {!! Form::open(['id' => 'attachment-' . $company->company_logo->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $company->company_logo->id)], 'style' => 'display:inline']) !!}'; attachment_html += ' '; attachment_html += ' '; attachment_html += ' '; @@ -85,7 +85,7 @@ $('.fancy-file .fake-file').append(attachment_html); $(document).on('click', '#remove-attachment', function (e) { - confirmDelete("#attachment-{!! $company->logo->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $company->logo->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + confirmDelete("#attachment-{!! $company->company_logo->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $company->company_logo->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); }); @endif }); From 5788233c2e3c14b88e4107714e07b015cd9e6fbb Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Wed, 3 Jan 2018 20:08:56 +0300 Subject: [PATCH 12/13] Migration move media table and fixed attribute issue --- app/Listeners/Updates/Version116.php | 28 ++++++++++++++++++++++++++++ app/Models/Auth/User.php | 4 ++++ app/Models/Company/Company.php | 6 +++++- app/Models/Expense/Bill.php | 6 +++++- app/Models/Expense/BillPayment.php | 6 +++++- app/Models/Expense/Payment.php | 6 +++++- app/Models/Income/Invoice.php | 6 +++++- app/Models/Income/InvoicePayment.php | 6 +++++- app/Models/Income/Revenue.php | 6 +++++- app/Models/Item/Item.php | 6 +++++- 10 files changed, 72 insertions(+), 8 deletions(-) diff --git a/app/Listeners/Updates/Version116.php b/app/Listeners/Updates/Version116.php index 9dc267726..7fa0afead 100644 --- a/app/Listeners/Updates/Version116.php +++ b/app/Listeners/Updates/Version116.php @@ -24,5 +24,33 @@ class Version116 extends Listener return; } + $migrations = [ + '\App\Models\Auth\User' => 'picture', + '\App\Models\Item\Item' => 'picture', + '\App\Models\Expense\Bill' => 'attachment', + '\App\Models\Expense\BillPayment' => 'attachment', + '\App\Models\Expense\Payment' => 'attachment', + '\App\Models\Income\Invoice' => 'attachment', + '\App\Models\Income\InvoicePayment' => 'attachment', + '\App\Models\Income\Revenue' => 'attachment', + ]; + + foreach ($migrations as $model => $name) { + if ($model != '\App\Models\Auth\User') { + $items = $model::where('company_id', '<>', '0')->get(); + } else { + $items = $model::all(); + } + + foreach ($items as $item) { + if ($item->$name) { + $path = explode('uploads/', $item->$name); + + $media = MediaUploader::importPath(config('mediable.default_disk'), $path[1]); + + $item->attachMedia($media, $name); + } + } + } } } diff --git a/app/Models/Auth/User.php b/app/Models/Auth/User.php index ce0b5f87d..5367d36ff 100644 --- a/app/Models/Auth/User.php +++ b/app/Models/Auth/User.php @@ -89,6 +89,10 @@ class User extends Authenticatable } } + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('picture')) { return false; } diff --git a/app/Models/Company/Company.php b/app/Models/Company/Company.php index e04dfe1bc..59c28e13e 100644 --- a/app/Models/Company/Company.php +++ b/app/Models/Company/Company.php @@ -236,8 +236,12 @@ class Company extends Eloquent * * @return string */ - public function getCompanyLogoAttribute() + public function getCompanyLogoAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('company_logo')) { return false; } diff --git a/app/Models/Expense/Bill.php b/app/Models/Expense/Bill.php index 8a4eb4d76..10d6731bb 100644 --- a/app/Models/Expense/Bill.php +++ b/app/Models/Expense/Bill.php @@ -135,8 +135,12 @@ class Bill extends Model * * @return string */ - public function getAttachmentAttribute() + public function getAttachmentAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('attachment')) { return false; } diff --git a/app/Models/Expense/BillPayment.php b/app/Models/Expense/BillPayment.php index b0f9c6dca..e0d0c2702 100644 --- a/app/Models/Expense/BillPayment.php +++ b/app/Models/Expense/BillPayment.php @@ -85,8 +85,12 @@ class BillPayment extends Model * * @return string */ - public function getAttachmentAttribute() + public function getAttachmentAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('attachment')) { return false; } diff --git a/app/Models/Expense/Payment.php b/app/Models/Expense/Payment.php index f10133066..c61e8f767 100644 --- a/app/Models/Expense/Payment.php +++ b/app/Models/Expense/Payment.php @@ -98,8 +98,12 @@ class Payment extends Model * * @return string */ - public function getAttachmentAttribute() + public function getAttachmentAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('attachment')) { return false; } diff --git a/app/Models/Income/Invoice.php b/app/Models/Income/Invoice.php index 0cbd0c98f..7e88969ab 100644 --- a/app/Models/Income/Invoice.php +++ b/app/Models/Income/Invoice.php @@ -144,8 +144,12 @@ class Invoice extends Model * * @return string */ - public function getAttachmentAttribute() + public function getAttachmentAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('attachment')) { return false; } diff --git a/app/Models/Income/InvoicePayment.php b/app/Models/Income/InvoicePayment.php index ed7977ffd..ce59d42a6 100644 --- a/app/Models/Income/InvoicePayment.php +++ b/app/Models/Income/InvoicePayment.php @@ -85,8 +85,12 @@ class InvoicePayment extends Model * * @return string */ - public function getAttachmentAttribute() + public function getAttachmentAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('attachment')) { return false; } diff --git a/app/Models/Income/Revenue.php b/app/Models/Income/Revenue.php index 221c54632..7a363482d 100644 --- a/app/Models/Income/Revenue.php +++ b/app/Models/Income/Revenue.php @@ -104,8 +104,12 @@ class Revenue extends Model * * @return string */ - public function getAttachmentAttribute() + public function getAttachmentAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('attachment')) { return false; } diff --git a/app/Models/Item/Item.php b/app/Models/Item/Item.php index 8ab9706d3..c6dec6741 100644 --- a/app/Models/Item/Item.php +++ b/app/Models/Item/Item.php @@ -118,8 +118,12 @@ class Item extends Model * * @return string */ - public function getPictureAttribute() + public function getPictureAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('picture')) { return false; } From edc464e947515d424b88aa5859222586cc413198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Tue, 9 Jan 2018 01:10:43 +0300 Subject: [PATCH 13/13] update files --- app/Http/Controllers/Install/Updates.php | 3 -- app/Listeners/Updates/Version113.php | 2 + .../{Version116.php => Version117.php} | 41 ++++++++++++++++++- app/Models/Auth/User.php | 2 +- app/Models/Expense/Bill.php | 2 +- app/Models/Expense/BillPayment.php | 2 +- app/Models/Expense/Payment.php | 2 +- app/Models/Income/Invoice.php | 2 +- app/Models/Income/InvoicePayment.php | 2 +- app/Models/Income/Revenue.php | 2 +- app/Models/Item/Item.php | 2 +- 11 files changed, 49 insertions(+), 13 deletions(-) rename app/Listeners/Updates/{Version116.php => Version117.php} (50%) diff --git a/app/Http/Controllers/Install/Updates.php b/app/Http/Controllers/Install/Updates.php index 9a35c0b09..72cc61546 100644 --- a/app/Http/Controllers/Install/Updates.php +++ b/app/Http/Controllers/Install/Updates.php @@ -111,9 +111,6 @@ class Updates extends Controller // Clear cache after update Artisan::call('cache:clear'); - // Update database - Artisan::call('migrate', ['--force' => true]); - event(new UpdateFinished($alias, $old, $new)); flash(trans('updates.success'))->success(); diff --git a/app/Listeners/Updates/Version113.php b/app/Listeners/Updates/Version113.php index ec04aeeb4..d6955bd51 100644 --- a/app/Listeners/Updates/Version113.php +++ b/app/Listeners/Updates/Version113.php @@ -37,5 +37,7 @@ class Version113 extends Listener $currency->save(); } + // Update database + Artisan::call('migrate', ['--force' => true]); } } diff --git a/app/Listeners/Updates/Version116.php b/app/Listeners/Updates/Version117.php similarity index 50% rename from app/Listeners/Updates/Version116.php rename to app/Listeners/Updates/Version117.php index 7fa0afead..5a1bff775 100644 --- a/app/Listeners/Updates/Version116.php +++ b/app/Listeners/Updates/Version117.php @@ -5,11 +5,14 @@ namespace App\Listeners\Updates; use App\Events\UpdateFinished; use App\Models\Setting\Currency; -class Version116 extends Listener +use Illuminate\Support\Facades\Schema; +use Illuminate\Database\Schema\Blueprint; + +class Version117 extends Listener { const ALIAS = 'core'; - const VERSION = '1.1.6'; + const VERSION = '1.1.7'; /** * Handle the event. @@ -24,6 +27,37 @@ class Version116 extends Listener return; } + Schema::create('media', function (Blueprint $table) { + $table->increments('id'); + $table->string('disk', 32); + $table->string('directory'); + $table->string('filename'); + $table->string('extension', 32); + $table->string('mime_type', 128); + $table->string('aggregate_type', 32); + $table->integer('size')->unsigned(); + $table->timestamps(); + $table->softDeletes(); + + $table->index(['disk', 'directory']); + $table->unique(['disk', 'directory', 'filename', 'extension']); + $table->index('aggregate_type'); + }); + + Schema::create('mediables', function (Blueprint $table) { + $table->integer('media_id')->unsigned(); + $table->string('mediable_type'); + $table->integer('mediable_id')->unsigned(); + $table->string('tag'); + $table->integer('order')->unsigned(); + + $table->primary(['media_id', 'mediable_type', 'mediable_id', 'tag']); + $table->index(['mediable_id', 'mediable_type']); + $table->index('tag'); + $table->index('order'); + $table->foreign('media_id')->references('id')->on('media')->onDelete('cascade'); + }); + $migrations = [ '\App\Models\Auth\User' => 'picture', '\App\Models\Item\Item' => 'picture', @@ -52,5 +86,8 @@ class Version116 extends Listener } } } + + // Update database + Artisan::call('migrate', ['--force' => true]); } } diff --git a/app/Models/Auth/User.php b/app/Models/Auth/User.php index 5367d36ff..2f7fce918 100644 --- a/app/Models/Auth/User.php +++ b/app/Models/Auth/User.php @@ -27,7 +27,7 @@ class User extends Authenticatable * * @var array */ - protected $fillable = ['name', 'email', 'password', 'locale', 'picture', 'enabled']; + protected $fillable = ['name', 'email', 'password', 'locale', 'enabled']; /** * The attributes that should be hidden for arrays. diff --git a/app/Models/Expense/Bill.php b/app/Models/Expense/Bill.php index 10d6731bb..c44bdaf64 100644 --- a/app/Models/Expense/Bill.php +++ b/app/Models/Expense/Bill.php @@ -22,7 +22,7 @@ class Bill extends Model * * @var array */ - protected $fillable = ['company_id', 'bill_number', 'order_number', 'bill_status_code', 'billed_at', 'due_at', 'amount', 'currency_code', 'currency_rate', 'vendor_id', 'vendor_name', 'vendor_email', 'vendor_tax_number', 'vendor_phone', 'vendor_address', 'notes', 'attachment']; + protected $fillable = ['company_id', 'bill_number', 'order_number', 'bill_status_code', 'billed_at', 'due_at', 'amount', 'currency_code', 'currency_rate', 'vendor_id', 'vendor_name', 'vendor_email', 'vendor_tax_number', 'vendor_phone', 'vendor_address', 'notes']; /** * Sortable columns. diff --git a/app/Models/Expense/BillPayment.php b/app/Models/Expense/BillPayment.php index e0d0c2702..066d5ed45 100644 --- a/app/Models/Expense/BillPayment.php +++ b/app/Models/Expense/BillPayment.php @@ -20,7 +20,7 @@ class BillPayment extends Model * * @var array */ - protected $fillable = ['company_id', 'bill_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'description', 'payment_method', 'reference', 'attachment']; + protected $fillable = ['company_id', 'bill_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'description', 'payment_method', 'reference']; public function account() { diff --git a/app/Models/Expense/Payment.php b/app/Models/Expense/Payment.php index c61e8f767..ab50ae53c 100644 --- a/app/Models/Expense/Payment.php +++ b/app/Models/Expense/Payment.php @@ -20,7 +20,7 @@ class Payment extends Model * * @var array */ - protected $fillable = ['company_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'vendor_id', 'description', 'category_id', 'payment_method', 'reference', 'attachment']; + protected $fillable = ['company_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'vendor_id', 'description', 'category_id', 'payment_method', 'reference']; /** * Sortable columns. diff --git a/app/Models/Income/Invoice.php b/app/Models/Income/Invoice.php index 7e88969ab..eb4ba2f4d 100644 --- a/app/Models/Income/Invoice.php +++ b/app/Models/Income/Invoice.php @@ -30,7 +30,7 @@ class Invoice extends Model * * @var array */ - protected $fillable = ['company_id', 'invoice_number', 'order_number', 'invoice_status_code', 'invoiced_at', 'due_at', 'amount', 'currency_code', 'currency_rate', 'customer_id', 'customer_name', 'customer_email', 'customer_tax_number', 'customer_phone', 'customer_address', 'notes', 'attachment']; + protected $fillable = ['company_id', 'invoice_number', 'order_number', 'invoice_status_code', 'invoiced_at', 'due_at', 'amount', 'currency_code', 'currency_rate', 'customer_id', 'customer_name', 'customer_email', 'customer_tax_number', 'customer_phone', 'customer_address', 'notes']; /** * Sortable columns. diff --git a/app/Models/Income/InvoicePayment.php b/app/Models/Income/InvoicePayment.php index ce59d42a6..f1bb41e2c 100644 --- a/app/Models/Income/InvoicePayment.php +++ b/app/Models/Income/InvoicePayment.php @@ -20,7 +20,7 @@ class InvoicePayment extends Model * * @var array */ - protected $fillable = ['company_id', 'invoice_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'description', 'payment_method', 'reference', 'attachment']; + protected $fillable = ['company_id', 'invoice_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'description', 'payment_method', 'reference']; public function account() { diff --git a/app/Models/Income/Revenue.php b/app/Models/Income/Revenue.php index 7a363482d..955154c3b 100644 --- a/app/Models/Income/Revenue.php +++ b/app/Models/Income/Revenue.php @@ -20,7 +20,7 @@ class Revenue extends Model * * @var array */ - protected $fillable = ['company_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'customer_id', 'description', 'category_id', 'payment_method', 'reference', 'attachment']; + protected $fillable = ['company_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'customer_id', 'description', 'category_id', 'payment_method', 'reference']; /** * Sortable columns. diff --git a/app/Models/Item/Item.php b/app/Models/Item/Item.php index c6dec6741..4fa2bdbc7 100644 --- a/app/Models/Item/Item.php +++ b/app/Models/Item/Item.php @@ -19,7 +19,7 @@ class Item extends Model * * @var array */ - protected $fillable = ['company_id', 'name', 'sku', 'description', 'sale_price', 'purchase_price', 'quantity', 'category_id', 'tax_id', 'picture', 'enabled']; + protected $fillable = ['company_id', 'name', 'sku', 'description', 'sale_price', 'purchase_price', 'quantity', 'category_id', 'tax_id', 'enabled']; /** * Sortable columns.