added ownership

This commit is contained in:
Denis Duliçi
2021-06-17 10:59:07 +03:00
parent de0d26b803
commit a3572de1ec
54 changed files with 253 additions and 37 deletions

View File

@ -15,8 +15,6 @@ class Permission extends LaratrustPermission
protected $table = 'permissions';
protected $tenantable = false;
/**
* The accessors to append to the model's array form.
*

View File

@ -15,8 +15,6 @@ class Role extends LaratrustRole
protected $table = 'roles';
protected $tenantable = false;
/**
* The attributes that are mass assignable.
*

View File

@ -6,7 +6,7 @@ use App\Traits\Tenants;
use App\Notifications\Auth\Reset;
use App\Traits\Media;
use App\Traits\Users;
use Date;
use App\Utilities\Date;
use Illuminate\Contracts\Translation\HasLocalePreference;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
@ -22,8 +22,6 @@ class User extends Authenticatable implements HasLocalePreference
protected $table = 'users';
protected $tenantable = false;
/**
* The attributes that are mass assignable.
*

View File

@ -24,7 +24,7 @@ class Account extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'name', 'number', 'currency_code', 'opening_balance', 'bank_name', 'bank_phone', 'bank_address', 'enabled'];
protected $fillable = ['company_id', 'name', 'number', 'currency_code', 'opening_balance', 'bank_name', 'bank_phone', 'bank_address', 'enabled', 'created_by'];
/**
* The attributes that should be cast.

View File

@ -15,7 +15,7 @@ class Reconciliation extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'account_id', 'started_at', 'ended_at', 'closing_balance', 'reconciled'];
protected $fillable = ['company_id', 'account_id', 'started_at', 'ended_at', 'closing_balance', 'reconciled', 'created_by'];
/**
* The attributes that should be cast.

View File

@ -28,7 +28,23 @@ class Transaction extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'type', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'document_id', 'contact_id', 'description', 'category_id', 'payment_method', 'reference', 'parent_id'];
protected $fillable = [
'company_id',
'type',
'account_id',
'paid_at',
'amount',
'currency_code',
'currency_rate',
'document_id',
'contact_id',
'description',
'category_id',
'payment_method',
'reference',
'parent_id',
'created_by',
];
/**
* The attributes that should be cast.

View File

@ -18,7 +18,7 @@ class Transfer extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'expense_transaction_id', 'income_transaction_id'];
protected $fillable = ['company_id', 'expense_transaction_id', 'income_transaction_id', 'created_by'];
/**
* Sortable columns.

View File

@ -9,25 +9,25 @@ use App\Events\Common\CompanyMakingCurrent;
use App\Models\Document\Document;
use App\Traits\Contacts;
use App\Traits\Media;
use App\Traits\Owners;
use App\Traits\Tenants;
use App\Traits\Transactions;
use App\Utilities\Overrider;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Eloquent\SoftDeletes;
use Kyslik\ColumnSortable\Sortable;
use Laratrust\Contracts\Ownable;
use Lorisleiva\LaravelSearchString\Concerns\SearchString;
class Company extends Eloquent
class Company extends Eloquent implements Ownable
{
use Contacts, Media, SearchString, SoftDeletes, Sortable, Tenants, Transactions;
use Contacts, Media, Owners, SearchString, SoftDeletes, Sortable, Tenants, Transactions;
protected $table = 'companies';
protected $tenantable = false;
protected $dates = ['deleted_at'];
protected $fillable = ['domain', 'enabled'];
protected $fillable = ['domain', 'enabled', 'created_by'];
protected $casts = [
'enabled' => 'boolean',
@ -518,4 +518,23 @@ class Company extends Eloquent
{
return static::getCurrent() !== null;
}
public function scopeIsOwner($query)
{
return $query->where('created_by', user_id());
}
public function scopeIsNotOwner($query)
{
return $query->where('created_by', '<>', user_id());
}
public function ownerKey($owner)
{
if ($this->isNotOwnable()) {
return 0;
}
return $this->created_by;
}
}

View File

@ -24,7 +24,21 @@ class Contact extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'type', 'name', 'email', 'user_id', 'tax_number', 'phone', 'address', 'website', 'currency_code', 'reference', 'enabled'];
protected $fillable = [
'company_id',
'type',
'name',
'email',
'user_id',
'tax_number',
'phone',
'address',
'website',
'currency_code',
'reference',
'enabled',
'created_by',
];
/**
* The attributes that should be cast.

View File

@ -18,7 +18,7 @@ class Dashboard extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'name', 'enabled'];
protected $fillable = ['company_id', 'name', 'enabled', 'created_by'];
/**
* The attributes that should be cast.

View File

@ -27,7 +27,7 @@ class Item extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'name', 'description', 'sale_price', 'purchase_price', 'category_id', 'enabled'];
protected $fillable = ['company_id', 'name', 'description', 'sale_price', 'purchase_price', 'category_id', 'enabled', 'created_by'];
/**
* The attributes that should be cast.

View File

@ -18,7 +18,6 @@ class Recurring extends Model
*/
protected $fillable = ['company_id', 'recurable_id', 'recurable_type', 'frequency', 'interval', 'started_at', 'count'];
/**
* Get all of the owning recurable models.
*/

View File

@ -17,7 +17,7 @@ class Report extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'class', 'name', 'description', 'settings'];
protected $fillable = ['company_id', 'class', 'name', 'description', 'settings', 'created_by'];
/**
* The attributes that should be cast.

View File

@ -16,7 +16,7 @@ class Widget extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'dashboard_id', 'class', 'name', 'sort', 'settings'];
protected $fillable = ['company_id', 'dashboard_id', 'class', 'name', 'sort', 'settings', 'created_by'];
/**
* The attributes that should be cast.

View File

@ -41,6 +41,7 @@ class Document extends Model
'amount',
'currency_code',
'currency_rate',
'category_id',
'contact_id',
'contact_name',
'contact_email',
@ -48,9 +49,9 @@ class Document extends Model
'contact_phone',
'contact_address',
'notes',
'category_id',
'parent_id',
'footer',
'parent_id',
'created_by',
];
/**

View File

@ -18,7 +18,7 @@ class Category extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'name', 'type', 'color', 'enabled'];
protected $fillable = ['company_id', 'name', 'type', 'color', 'enabled', 'created_by'];
/**
* The attributes that should be cast.

View File

@ -19,7 +19,19 @@ class Currency extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'name', 'code', 'rate', 'enabled', 'precision', 'symbol', 'symbol_first', 'decimal_mark', 'thousands_separator'];
protected $fillable = [
'company_id',
'name',
'code',
'rate',
'enabled',
'precision',
'symbol',
'symbol_first',
'decimal_mark',
'thousands_separator',
'created_by',
];
/**
* The attributes that should be cast.

View File

@ -11,8 +11,6 @@ class Setting extends Eloquent
protected $table = 'settings';
protected $tenantable = true;
/**
* Attributes that should be mass-assignable.
*

View File

@ -24,7 +24,7 @@ class Tax extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'name', 'rate', 'type', 'enabled'];
protected $fillable = ['company_id', 'name', 'rate', 'type', 'enabled', 'created_by'];
/**
* The attributes that should be cast.