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/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/Common/Uploads.php b/app/Http/Controllers/Common/Uploads.php index a22904bd3..26b39e473 100644 --- a/app/Http/Controllers/Common/Uploads.php +++ b/app/Http/Controllers/Common/Uploads.php @@ -3,7 +3,9 @@ namespace App\Http\Controllers\Common; use App\Http\Controllers\Controller; +use App\Models\Common\Media; use Storage; +use File; class Uploads extends Controller { @@ -14,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; } @@ -31,16 +35,45 @@ 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; } return response()->download($path); } + /** + * Destroy the specified resource. + * + * @param $folder + * @param $file + * @return callable + */ + public function destroy($id) + { + $media = Media::find($id); + + // Get file path + 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(); + } + /** * Get the full path of resource. * @@ -48,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/Companies/Companies.php b/app/Http/Controllers/Companies/Companies.php index 2af1bdf36..908937fa0 100644 --- a/app/Http/Controllers/Companies/Companies.php +++ b/app/Http/Controllers/Companies/Companies.php @@ -59,9 +59,14 @@ 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')) { + $company_logo = $this->getMedia($request->file('company_logo'), 'settings', $company->id); + + if ($company_logo) { + $company->attachMedia($company_logo, 'company_logo'); + + setting()->set('general.company_logo', $company_logo->id); + } } setting()->set('general.default_currency', $request->get('default_currency')); @@ -135,9 +140,14 @@ 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')) { + $company_logo = $this->getMedia($request->file('company_logo'), 'settings', $company->id); + + if ($company_logo) { + $company->attachMedia($company_logo, 'company_logo'); + + setting()->set('general.company_logo', $company_logo->id); + } } setting()->set('general.default_payment_method', 'offlinepayment.cash.1'); 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/Expenses/Bills.php b/app/Http/Controllers/Expenses/Bills.php index 2bf9e84de..3ed135125 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'), 'bills'); + + $bill->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->attachMedia($media, 'attachment'); + } + // Added bill total total $bill_total = [ 'company_id' => $request['company_id'], @@ -594,13 +595,6 @@ 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']); $total_amount = $bill->amount; @@ -639,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/Expenses/Payments.php b/app/Http/Controllers/Expenses/Payments.php index 205ecb0ca..c296aabd9 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->attachMedia($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..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; @@ -137,16 +138,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'), 'invoices'); + + $invoice->attachMedia($media, 'attachment'); + } + $taxes = []; + $tax_total = 0; $sub_total = 0; @@ -349,13 +351,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 +413,13 @@ class Invoices extends Controller $invoice->update($request->input()); + // Upload attachment + if ($request->file('attachment')) { + $media = $this->getMedia($request->file('attachment'), 'invoices'); + + $invoice->attachMedia($media, 'attachment'); + } + // Delete previous invoice totals InvoiceTotal::where('invoice_id', $invoice->id)->delete(); @@ -624,13 +626,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 +664,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; @@ -783,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/app/Http/Controllers/Incomes/Revenues.php b/app/Http/Controllers/Incomes/Revenues.php index 404cfbbd4..e02c38c33 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->attachMedia($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->attachMedia($media, 'attachment'); + } + $message = trans('messages.success.updated', ['type' => trans_choice('general.revenues', 1)]); flash($message)->success(); 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/Http/Controllers/Items/Items.php b/app/Http/Controllers/Items/Items.php index 201fe9188..e2bf8be39 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 ($request->file('picture')) { + $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 ($request->file('picture')) { + $media = $this->getMedia($request->file('picture'), 'items'); + + $item->attachMedia($media, 'picture'); + } + $message = trans('messages.success.updated', ['type' => trans_choice('general.items', 1)]); flash($message)->success(); 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/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/Version117.php b/app/Listeners/Updates/Version117.php new file mode 100644 index 000000000..5a1bff775 --- /dev/null +++ b/app/Listeners/Updates/Version117.php @@ -0,0 +1,93 @@ +check($event)) { + 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', + '\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); + } + } + } + + // Update database + Artisan::call('migrate', ['--force' => true]); + } +} diff --git a/app/Models/Auth/User.php b/app/Models/Auth/User.php index b2a9f4db4..8944532d2 100644 --- a/app/Models/Auth/User.php +++ b/app/Models/Auth/User.php @@ -11,12 +11,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'; @@ -25,7 +26,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. @@ -87,7 +88,15 @@ class User extends Authenticatable } } - return $value; + if (!empty($value)) { + return $value; + } + + if (!$this->hasMedia('picture')) { + return false; + } + + return $this->getMedia('picture')->last(); } /** diff --git a/app/Models/Common/Media.php b/app/Models/Common/Media.php new file mode 100644 index 000000000..517b12394 --- /dev/null +++ b/app/Models/Common/Media.php @@ -0,0 +1,14 @@ +orderBy('value', $direction) ->select('companies.*'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getCompanyLogoAttribute($value) + { + if (!empty($value)) { + return $value; + } + + if (!$this->hasMedia('company_logo')) { + return false; + } + + return $this->getMedia('company_logo')->last(); + } } diff --git a/app/Models/Expense/Bill.php b/app/Models/Expense/Bill.php index ca4dd2be7..c44bdaf64 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'; @@ -21,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. @@ -128,4 +129,22 @@ class Bill extends Model { $this->attributes['currency_rate'] = (double) $value; } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute($value) + { + if (!empty($value)) { + return $value; + } + + 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..066d5ed45 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'; @@ -19,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() { @@ -78,4 +79,22 @@ class BillPayment extends Model { return $query->sum('amount'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute($value) + { + if (!empty($value)) { + return $value; + } + + 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..ab50ae53c 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'; @@ -19,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. @@ -91,4 +92,22 @@ class Payment extends Model { return $query->orderBy('paid_at', 'desc'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute($value) + { + if (!empty($value)) { + return $value; + } + + if (!$this->hasMedia('attachment')) { + return false; + } + + return $this->getMedia('attachment')->last(); + } } diff --git a/app/Models/Income/Invoice.php b/app/Models/Income/Invoice.php index b80575bc2..eb4ba2f4d 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']; /** @@ -22,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. @@ -130,4 +138,22 @@ class Invoice extends Model { $this->attributes['currency_rate'] = (double) $value; } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute($value) + { + if (!empty($value)) { + return $value; + } + + 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..f1bb41e2c 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'; @@ -19,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() { @@ -78,4 +79,22 @@ class InvoicePayment extends Model { return $query->sum('amount'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute($value) + { + if (!empty($value)) { + return $value; + } + + 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..955154c3b 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'; @@ -19,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. @@ -97,4 +98,22 @@ class Revenue extends Model { return $query->orderBy('paid_at', 'desc'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute($value) + { + if (!empty($value)) { + return $value; + } + + if (!$this->hasMedia('attachment')) { + return false; + } + + return $this->getMedia('attachment')->last(); + } } diff --git a/app/Models/Item/Item.php b/app/Models/Item/Item.php index 9095186b9..4fa2bdbc7 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'; @@ -18,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. @@ -111,4 +112,22 @@ class Item extends Model ->orderBy('name', $direction) ->select('items.*'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getPictureAttribute($value) + { + if (!empty($value)) { + return $value; + } + + if (!$this->hasMedia('picture')) { + return false; + } + + return $this->getMedia('picture')->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/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..8adfbd28c 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,21 @@ trait Uploads return $path; } -} \ No newline at end of file + + public function getMedia($file, $folder = 'settings', $company_id = null) + { + $path = ''; + + if (!$file || !$file->isValid()) { + return $path; + } + + if (!$company_id) { + $company_id = session('company_id'); + } + + $path = $company_id . '/' . $folder; + + return MediaUploader::fromSource($file)->toDirectory($path)->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..9f468220e --- /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' => false, +]; diff --git a/database/migrations/2017_12_30_000000_create_mediable_tables.php b/database/migrations/2017_12_30_000000_create_mediable_tables.php new file mode 100644 index 000000000..c85857724 --- /dev/null +++ b/database/migrations/2017_12_30_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->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'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('mediables'); + Schema::drop('media'); + } +} 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/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/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 @@
 : asset('public/img/akaunting-logo-green.png') }})
 : asset('public/img/akaunting-logo-green.png') }})
:message
') !!}