Merge pull request #174 from cuneytsenturk/master

Attachment manager
This commit is contained in:
Cüneyt Şentürk 2018-01-09 02:02:38 +03:00 committed by GitHub
commit 8272b31da4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
57 changed files with 1398 additions and 167 deletions

View File

@ -23,4 +23,4 @@ class Transfers extends ModelFilter
{
return $this->related('revenue', 'revenues.account_id', '=', $account_id);
}
}
}

View File

@ -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']);

View File

@ -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;

View File

@ -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');

View File

@ -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());

View File

@ -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;

View File

@ -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();

View File

@ -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;
}

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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');
}
}

View File

@ -37,5 +37,7 @@ class Version113 extends Listener
$currency->save();
}
// Update database
Artisan::call('migrate', ['--force' => true]);
}
}

View File

@ -0,0 +1,93 @@
<?php
namespace App\Listeners\Updates;
use App\Events\UpdateFinished;
use App\Models\Setting\Currency;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
class Version117 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.1.7';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(UpdateFinished $event)
{
// Check if should listen
if (!$this->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]);
}
}

View File

@ -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();
}
/**

View File

@ -0,0 +1,14 @@
<?php
namespace App\Models\Common;
use Illuminate\Database\Eloquent\SoftDeletes;
use Plank\Mediable\Media as PMedia;
class Media extends PMedia
{
use SoftDeletes;
protected $dates = ['deleted_at'];
}

View File

@ -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,22 @@ class Company extends Eloquent
->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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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',

View File

@ -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', [

View File

@ -2,6 +2,8 @@
namespace App\Traits;
use MediaUploader;
trait Uploads
{
@ -27,4 +29,21 @@ trait Uploads
return $path;
}
}
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();
}
}

View File

@ -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.*"

View File

@ -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,

228
config/mediable.php Normal file
View File

@ -0,0 +1,228 @@
<?php
return [
/*
* FQCN of the model to use for media
*
* Should extend `Plank\Mediable\Media`
*/
'model' => 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,
];

View File

@ -0,0 +1,58 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateMediableTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
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');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('mediables');
Schema::drop('media');
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class DropAttachmentColumnBillPaymentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('bill_payments', function (Blueprint $table) {
$table->dropColumn('attachment');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('bill_payments', function (Blueprint $table) {
$table->string('attachment')->nullable();
});
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class DropAttachmentColumnBillsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('bills', function (Blueprint $table) {
$table->dropColumn('attachment');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('bills', function (Blueprint $table) {
$table->string('attachment')->nullable();
});
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class DropAttachmentColumnInvoicePaymentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('invoice_payments', function (Blueprint $table) {
$table->dropColumn('attachment');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('invoice_payments', function (Blueprint $table) {
$table->string('attachment')->nullable();
});
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class DropAttachmentColumnInvoicesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('invoices', function (Blueprint $table) {
$table->dropColumn('attachment');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('invoices', function (Blueprint $table) {
$table->string('attachment')->nullable();
});
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class DropAttachmentColumnPaymentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('payments', function (Blueprint $table) {
$table->dropColumn('attachment');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('payments', function (Blueprint $table) {
$table->string('attachment')->nullable();
});
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class DropAttachmentColumnRevenuesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('revenues', function (Blueprint $table) {
$table->dropColumn('attachment');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('revenues', function (Blueprint $table) {
$table->string('attachment')->nullable();
});
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class DropPictureColumnItemsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('items', function (Blueprint $table) {
$table->dropColumn('picture');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('items', function (Blueprint $table) {
$table->string('picture')->nullable();
});
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class DropPictureColumnUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('picture');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->string('picture')->nullable();
});
}
}

View File

@ -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',

View File

@ -71,9 +71,34 @@
$('#picture').fancyfile({
text : '{{ trans('general.form.select.file') }}',
style : 'btn-default',
placeholder : '<?php echo $user->picture; ?>'
@if($user->picture)
placeholder : '<?php echo $user->picture->basename; ?>'
@else
placeholder : '{{ trans('general.form.no_file_selected') }}'
@endif
});
@if($user->picture)
picture_html = '<span class="picture">';
picture_html += ' <a href="{{ url('uploads/' . $user->picture->id . '/download') }}">';
picture_html += ' <span id="download-picture" class="text-primary">';
picture_html += ' <i class="fa fa-file-{{ $user->picture->aggregate_type }}-o"></i> {{ $user->picture->basename }}';
picture_html += ' </span>';
picture_html += ' </a>';
picture_html += ' {!! Form::open(['id' => 'picture-' . $user->picture->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $user->picture->id)], 'style' => 'display:inline']) !!}';
picture_html += ' <a id="remove-picture" href="javascript:void();">';
picture_html += ' <span class="text-danger"><i class="fa fa fa-times"></i></span>';
picture_html += ' </a>';
picture_html += ' {!! Form::close() !!}';
picture_html += '</span>';
$('.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' => '<strong>' . $user->picture->basename . '</strong>', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
});
@endif
$('input[type=checkbox]').iCheck({
checkboxClass: 'icheckbox_square-green',
radioClass: 'iradio_square-green',

View File

@ -44,7 +44,7 @@
<td>
<a href="{{ url('auth/users/' . $item->id . '/edit') }}">
@if ($item->picture)
<img src="{{ Storage::url($item->picture) }}" class="users-image" alt="{{ $item->name }}" title="{{ $item->name }}">
<img src="{{ Storage::url($item->picture->id) }}" class="users-image" alt="{{ $item->name }}" title="{{ $item->name }}">
@endif
{{ $item->name }}
</a>

View File

@ -61,8 +61,33 @@
$('#company_logo').fancyfile({
text : '{{ trans('general.form.select.file') }}',
style : 'btn-default',
placeholder : '<?php echo $company->company_logo; ?>'
@if($company->company_logo)
placeholder : '<?php echo $company->company_logo->basename; ?>'
@else
placeholder : '{{ trans('general.form.no_file_selected') }}'
@endif
});
@if($company->company_logo)
attachment_html = '<span class="attachment">';
attachment_html += ' <a href="{{ url('uploads/' . $company->company_logo->id . '/download') }}">';
attachment_html += ' <span id="download-attachment" class="text-primary">';
attachment_html += ' <i class="fa fa-file-{{ $company->company_logo->aggregate_type }}-o"></i> {{ $company->company_logo->basename }}';
attachment_html += ' </span>';
attachment_html += ' </a>';
attachment_html += ' {!! Form::open(['id' => 'attachment-' . $company->company_logo->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $company->company_logo->id)], 'style' => 'display:inline']) !!}';
attachment_html += ' <a id="remove-attachment" href="javascript:void();">';
attachment_html += ' <span class="text-danger"><i class="fa fa fa-times"></i></span>';
attachment_html += ' </a>';
attachment_html += ' {!! Form::close() !!}';
attachment_html += '</span>';
$('.fancy-file .fake-file').append(attachment_html);
$(document).on('click', '#remove-attachment', function (e) {
confirmDelete("#attachment-{!! $company->company_logo->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '<strong>' . $company->company_logo->basename . '</strong>', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
});
@endif
});
</script>
@endpush

View File

@ -62,8 +62,33 @@
$('#picture').fancyfile({
text : '{{ trans('general.form.select.file') }}',
style : 'btn-default',
placeholder : '<?php echo $user->picture; ?>'
@if($user->picture)
placeholder : '<?php echo $user->picture->basename; ?>'
@else
placeholder : '{{ trans('general.form.no_file_selected') }}'
@endif
});
@if($user->picture)
picture_html = '<span class="picture">';
picture_html += ' <a href="{{ url('uploads/' . $user->picture->id . '/download') }}">';
picture_html += ' <span id="download-picture" class="text-primary">';
picture_html += ' <i class="fa fa-file-{{ $user->picture->aggregate_type }}-o"></i> {{ $user->picture->basename }}';
picture_html += ' </span>';
picture_html += ' </a>';
picture_html += ' {!! Form::open(['id' => 'picture-' . $user->picture->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $user->picture->id)], 'style' => 'display:inline']) !!}';
picture_html += ' <a id="remove-picture" href="javascript:void();">';
picture_html += ' <span class="text-danger"><i class="fa fa fa-times"></i></span>';
picture_html += ' </a>';
picture_html += ' {!! Form::close() !!}';
picture_html += '</span>';
$('.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' => '<strong>' . $user->picture->basename . '</strong>', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
});
@endif
});
</script>
@endpush

View File

@ -204,9 +204,34 @@
$('#attachment').fancyfile({
text : '{{ trans('general.form.select.file') }}',
style : 'btn-default',
placeholder : '<?php echo $bill->attachment; ?>'
@if($bill->attachment)
placeholder : '<?php echo $bill->attachment->basename; ?>'
@else
placeholder : '{{ trans('general.form.no_file_selected') }}'
@endif
});
@if($bill->attachment)
attachment_html = '<span class="attachment">';
attachment_html += ' <a href="{{ url('uploads/' . $bill->attachment->id . '/download') }}">';
attachment_html += ' <span id="download-attachment" class="text-primary">';
attachment_html += ' <i class="fa fa-file-{{ $bill->attachment->aggregate_type }}-o"></i> {{ $bill->attachment->basename }}';
attachment_html += ' </span>';
attachment_html += ' </a>';
attachment_html += ' {!! Form::open(['id' => 'attachment-' . $bill->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $bill->attachment->id)], 'style' => 'display:inline']) !!}';
attachment_html += ' <a id="remove-attachment" href="javascript:void();">';
attachment_html += ' <span class="text-danger"><i class="fa fa fa-times"></i></span>';
attachment_html += ' </a>';
attachment_html += ' {!! Form::close() !!}';
attachment_html += '</span>';
$('.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' => '<strong>' . $bill->attachment->basename . '</strong>', '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() {

View File

@ -167,6 +167,26 @@
@endpermission
</ul>
</div>
@if($bill->attachment)
<span class="attachment">
<a href="{{ url('uploads/' . $bill->attachment->id . '/download') }}">
<span id="download-attachment" class="text-primary">
<i class="fa fa-file-{{ $bill->attachment->aggregate_type }}-o"></i> {{ $bill->attachment->basename }}
</span>
</a>
{!! Form::open([
'id' => 'attachment-' . $bill->attachment->id,
'method' => 'DELETE',
'url' => [url('uploads/' . $bill->attachment->id)],
'style' => 'display:inline'
]) !!}
<a id="remove-attachment" href="javascript:void();">
<span class="text-danger"><i class="fa fa fa-times"></i></span>
</a>
{!! Form::close() !!}
</span>
@endif
</div>
</div>
</div>
@ -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' => '<strong>' . $bill->attachment->basename . '</strong>', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
});
@endif
});
function addPayment() {

View File

@ -92,9 +92,34 @@
$('#attachment').fancyfile({
text : '{{ trans('general.form.select.file') }}',
style : 'btn-default',
placeholder : '<?php echo ($payment->attachment) ? $payment->attachment : trans('general.form.no_file_selected'); ?>'
@if($payment->attachment)
placeholder : '<?php echo $payment->attachment->basename; ?>'
@else
placeholder : '{{ trans('general.form.no_file_selected') }}'
@endif
});
@if($payment->attachment)
attachment_html = '<span class="attachment">';
attachment_html += ' <a href="{{ url('uploads/' . $payment->attachment->id . '/download') }}">';
attachment_html += ' <span id="download-attachment" class="text-primary">';
attachment_html += ' <i class="fa fa-file-{{ $payment->attachment->aggregate_type }}-o"></i> {{ $payment->attachment->basename }}';
attachment_html += ' </span>';
attachment_html += ' </a>';
attachment_html += ' {!! Form::open(['id' => 'attachment-' . $payment->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $payment->attachment->id)], 'style' => 'display:inline']) !!}';
attachment_html += ' <a id="remove-attachment" href="javascript:void();">';
attachment_html += ' <span class="text-danger"><i class="fa fa fa-times"></i></span>';
attachment_html += ' </a>';
attachment_html += ' {!! Form::close() !!}';
attachment_html += '</span>';
$('.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' => '<strong>' . $payment->attachment->basename . '</strong>', '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") }}',

View File

@ -203,9 +203,34 @@
$('#attachment').fancyfile({
text : '{{ trans('general.form.select.file') }}',
style : 'btn-default',
placeholder : '<?php echo $invoice->attachment; ?>'
@if($invoice->attachment)
placeholder : '<?php echo $invoice->attachment->basename; ?>'
@else
placeholder : '{{ trans('general.form.no_file_selected') }}'
@endif
});
@if($invoice->attachment)
attachment_html = '<span class="attachment">';
attachment_html += ' <a href="{{ url('uploads/' . $invoice->attachment->id . '/download') }}">';
attachment_html += ' <span id="download-attachment" class="text-primary">';
attachment_html += ' <i class="fa fa-file-{{ $invoice->attachment->aggregate_type }}-o"></i> {{ $invoice->attachment->basename }}';
attachment_html += ' </span>';
attachment_html += ' </a>';
attachment_html += ' {!! Form::open(['id' => 'attachment-' . $invoice->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $invoice->attachment->id)], 'style' => 'display:inline']) !!}';
attachment_html += ' <a id="remove-attachment" href="javascript:void();">';
attachment_html += ' <span class="text-danger"><i class="fa fa fa-times"></i></span>';
attachment_html += ' </a>';
attachment_html += ' {!! Form::close() !!}';
attachment_html += '</span>';
$('.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' => '<strong>' . $invoice->attachment->basename . '</strong>', '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() {

View File

@ -178,6 +178,26 @@
@endpermission
</ul>
</div>
@if($invoice->attachment)
<span class="attachment">
<a href="{{ url('uploads/' . $invoice->attachment->id . '/download') }}">
<span id="download-attachment" class="text-primary">
<i class="fa fa-file-{{ $invoice->attachment->aggregate_type }}-o"></i> {{ $invoice->attachment->basename }}
</span>
</a>
{!! Form::open([
'id' => 'attachment-' . $invoice->attachment->id,
'method' => 'DELETE',
'url' => [url('uploads/' . $invoice->attachment->id)],
'style' => 'display:inline'
]) !!}
<a id="remove-attachment" href="javascript:void();">
<span class="text-danger"><i class="fa fa fa-times"></i></span>
</a>
{!! Form::close() !!}
</span>
@endif
</div>
</div>
</section>
@ -414,6 +434,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' => '<strong>' . $invoice->attachment->basename . '</strong>', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
});
@endif
});
function addPayment() {

View File

@ -92,9 +92,34 @@
$('#attachment').fancyfile({
text : '{{ trans('general.form.select.file') }}',
style : 'btn-default',
placeholder : '<?php echo $revenue->attachment; ?>'
@if($revenue->attachment)
placeholder : '<?php echo $revenue->attachment->basename; ?>'
@else
placeholder : '{{ trans('general.form.no_file_selected') }}'
@endif
});
@if($revenue->attachment)
attachment_html = '<span class="attachment">';
attachment_html += ' <a href="{{ url('uploads/' . $revenue->attachment->id . '/download') }}">';
attachment_html += ' <span id="download-attachment" class="text-primary">';
attachment_html += ' <i class="fa fa-file-{{ $revenue->attachment->aggregate_type }}-o"></i> {{ $revenue->attachment->basename }}';
attachment_html += ' </span>';
attachment_html += ' </a>';
attachment_html += ' {!! Form::open(['id' => 'attachment-' . $revenue->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $revenue->attachment->id)], 'style' => 'display:inline']) !!}';
attachment_html += ' <a id="remove-attachment" href="javascript:void();">';
attachment_html += ' <span class="text-danger"><i class="fa fa fa-times"></i></span>';
attachment_html += ' </a>';
attachment_html += ' {!! Form::close() !!}';
attachment_html += '</span>';
$('.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' => '<strong>' . $revenue->attachment->basename . '</strong>', '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") }}',

View File

@ -70,8 +70,33 @@
$('#picture').fancyfile({
text : '{{ trans('general.form.select.file') }}',
style : 'btn-default',
placeholder : '<?php echo $item->picture; ?>'
@if($item->picture)
placeholder : '<?php echo $item->picture->basename; ?>'
@else
placeholder : '{{ trans('general.form.no_file_selected') }}'
@endif
});
@if($item->picture)
picture_html = '<span class="picture">';
picture_html += ' <a href="{{ url('uploads/' . $item->picture->id . '/download') }}">';
picture_html += ' <span id="download-picture" class="text-primary">';
picture_html += ' <i class="fa fa-file-{{ $item->picture->aggregate_type }}-o"></i> {{ $item->picture->basename }}';
picture_html += ' </span>';
picture_html += ' </a>';
picture_html += ' {!! Form::open(['id' => 'picture-' . $item->picture->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $item->picture->id)], 'style' => 'display:inline']) !!}';
picture_html += ' <a id="remove-picture" href="javascript:void();">';
picture_html += ' <span class="text-danger"><i class="fa fa fa-times"></i></span>';
picture_html += ' </a>';
picture_html += ' {!! Form::close() !!}';
picture_html += '</span>';
$('.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' => '<strong>' . $item->picture->basename . '</strong>', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
});
@endif
});
</script>
@endpush

View File

@ -46,7 +46,7 @@
<tbody>
@foreach($items as $item)
<tr>
<td class="hidden-xs"><img src="{{ $item->picture ? Storage::url($item->picture) : asset('public/img/akaunting-logo-green.png') }}" class="img-thumbnail" width="50" alt="{{ $item->name }}"></td>
<td class="hidden-xs"><img src="{{ $item->picture ? Storage::url($item->picture->id) : asset('public/img/akaunting-logo-green.png') }}" class="img-thumbnail" width="50" alt="{{ $item->name }}"></td>
<td><a href="{{ url('items/items/' . $item->id . '/edit') }}">{{ $item->name }}</a></td>
<td class="hidden-xs">{{ $item->category ? $item->category->name : trans('general.na') }}</td>
<td class="hidden-xs">{{ $item->quantity }}</td>

View File

@ -166,7 +166,7 @@
@if (setting('general.use_gravatar', '0') == '1')
<img src="{{ $user->picture }}" class="user-image" alt="User Image">
@else
<img src="{{ Storage::url($user->picture) }}" class="user-image" alt="User Image">
<img src="{{ Storage::url($user->picture->id) }}" class="user-image" alt="User Image">
@endif
@else
<i class="fa fa-user-o"></i>
@ -182,7 +182,7 @@
@if (setting('general.use_gravatar', '0') == '1')
<img src="{{ $user->picture }}" class="img-circle" alt="User Image">
@else
<img src="{{ Storage::url($user->picture) }}" class="img-circle" alt="User Image">
<img src="{{ Storage::url($user->picture->id) }}" class="img-circle" alt="User Image">
@endif
@else
<i class="fa fa-4 fa-user-o" style="color: #fff; font-size: 7em;"></i>

View File

@ -60,7 +60,7 @@
<li class="dropdown user user-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
@if ($user->picture)
<img src="{{ Storage::url($user->picture) }}" class="user-image" alt="User Image">
<img src="{{ Storage::url($user->picture->id) }}" class="user-image" alt="User Image">
@else
<i class="fa fa-user-o"></i>
@endif
@ -72,7 +72,7 @@
<!-- User image -->
<li class="user-header">
@if ($user->picture)
<img src="{{ Storage::url($user->picture) }}" class="img-circle" alt="User Image">
<img src="{{ Storage::url($user->picture->id) }}" class="img-circle" alt="User Image">
@else
<i class="fa fa-4 fa-user-o" style="color: #fff; font-size: 7em;"></i>
@endif

View File

@ -1,5 +1,5 @@
<div class="form-group {{ $col }} {{ isset($attributes['required']) ? 'required' : '' }} {{ $errors->has($name) ? 'has-error' : '' }}" style="min-height: 59px">
{!! 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, '<p class="help-block">:message</p>') !!}
</div>

View File

@ -203,15 +203,64 @@
$('#company_logo').fancyfile({
text : '{{ trans('general.form.select.file') }}',
style : 'btn-default',
placeholder : '<?php echo $setting->pull('company_logo'); ?>'
@if($setting['company_logo'])
placeholder : '<?php echo $setting['company_logo']->basename; ?>'
@else
placeholder : '{{ trans('general.form.no_file_selected') }}'
@endif
});
@if($setting['company_logo'])
company_logo_html = '<span class="company_logo">';
company_logo_html += ' <a href="{{ url('uploads/' . $setting['company_logo']->id . '/download') }}">';
company_logo_html += ' <span id="download-company_logo" class="text-primary">';
company_logo_html += ' <i class="fa fa-file-{{ $setting['company_logo']->aggregate_type }}-o"></i> {{ $setting['company_logo']->basename }}';
company_logo_html += ' </span>';
company_logo_html += ' </a>';
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 += ' <a id="remove-company_logo" href="javascript:void();">';
company_logo_html += ' <span class="text-danger"><i class="fa fa fa-times"></i></span>';
company_logo_html += ' </a>';
company_logo_html += ' {!! Form::close() !!}';
company_logo_html += '</span>';
$('#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' => '<strong>' . $setting['company_logo']->basename . '</strong>', '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 : '<?php echo $setting->pull('invoice_logo'); ?>'
@if($setting['invoice_logo'])
placeholder : '<?php echo $setting['invoice_logo']->basename; ?>'
@else
placeholder : '{{ trans('general.form.no_file_selected') }}'
@endif
});
@if($setting['invoice_logo'])
invoice_logo_html = '<span class="invoice_logo">';
invoice_logo_html += ' <a href="{{ url('uploads/' . $setting['invoice_logo']->id . '/download') }}">';
invoice_logo_html += ' <span id="download-invoice_logo" class="text-primary">';
invoice_logo_html += ' <i class="fa fa-file-{{ $setting['invoice_logo']->aggregate_type }}-o"></i> {{ $setting['invoice_logo']->basename }}';
invoice_logo_html += ' </span>';
invoice_logo_html += ' </a>';
invoice_logo_html += ' {!! Form::open(['id' => 'invoice_logo-' . $setting['invoice_logo']->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $setting['invoice_logo']->id)], 'style' => 'display:inline']) !!}';
invoice_logo_html += ' <a id="remove-invoice_logo" href="javascript:void();">';
invoice_logo_html += ' <span class="text-danger"><i class="fa fa fa-times"></i></span>';
invoice_logo_html += ' </a>';
invoice_logo_html += ' {!! Form::close() !!}';
invoice_logo_html += '</span>';
$('#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' => '<strong>' . $setting['invoice_logo']->basename . '</strong>', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
});
@endif
$("select[name='email_protocol']").on('change', function() {
var selection = $(this).val();

View File

@ -9,8 +9,9 @@
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');
});
Route::group(['middleware' => ['adminmenu', 'permission:read-admin-panel']], function () {