akaunting 3.0 (the last dance)
This commit is contained in:
@@ -3,14 +3,24 @@
|
||||
namespace App\Models\Setting;
|
||||
|
||||
use App\Abstracts\Model;
|
||||
use App\Builders\Category as Builder;
|
||||
use App\Models\Document\Document;
|
||||
use App\Relations\HasMany\Category as HasMany;
|
||||
use App\Scopes\Category as Scope;
|
||||
use App\Traits\Transactions;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model as EloquentModel;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
use HasFactory, Transactions;
|
||||
|
||||
public const INCOME_TYPE = 'income';
|
||||
public const EXPENSE_TYPE = 'expense';
|
||||
public const ITEM_TYPE = 'item';
|
||||
public const OTHER_TYPE = 'other';
|
||||
|
||||
protected $table = 'categories';
|
||||
|
||||
/**
|
||||
@@ -18,7 +28,7 @@ class Category extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'type', 'color', 'enabled', 'created_from', 'created_by'];
|
||||
protected $fillable = ['company_id', 'name', 'type', 'color', 'enabled', 'created_from', 'created_by', 'parent_id'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
@@ -36,6 +46,65 @@ class Category extends Model
|
||||
*/
|
||||
public $sortable = ['name', 'type', 'enabled'];
|
||||
|
||||
/**
|
||||
* The "booted" method of the model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted()
|
||||
{
|
||||
static::addGlobalScope(new Scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Eloquent query builder for the model.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return \App\Builders\Category
|
||||
*/
|
||||
public function newEloquentBuilder($query)
|
||||
{
|
||||
return new Builder($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate a new HasMany relationship.
|
||||
*
|
||||
* @param EloquentBuilder $query
|
||||
* @param EloquentModel $parent
|
||||
* @param string $foreignKey
|
||||
* @param string $localKey
|
||||
* @return HasMany
|
||||
*/
|
||||
protected function newHasMany(EloquentBuilder $query, EloquentModel $parent, $foreignKey, $localKey)
|
||||
{
|
||||
return new HasMany($query, $parent, $foreignKey, $localKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the model for a bound value.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param string|null $field
|
||||
* @return \Illuminate\Database\Eloquent\Model|null
|
||||
*/
|
||||
public function resolveRouteBinding($value, $field = null)
|
||||
{
|
||||
return $this->resolveRouteBindingQuery($this, $value, $field)
|
||||
->withoutGlobalScope(Scope::class)
|
||||
->first();
|
||||
}
|
||||
|
||||
public function categories()
|
||||
{
|
||||
return $this->hasMany(Category::class, 'parent_id')->withSubCategory();
|
||||
}
|
||||
|
||||
public function sub_categories()
|
||||
{
|
||||
return $this->hasMany(Category::class, 'parent_id')->withSubCategory()->with('categories')->orderBy('name');
|
||||
}
|
||||
|
||||
public function documents()
|
||||
{
|
||||
return $this->hasMany('App\Models\Document\Document');
|
||||
@@ -147,6 +216,50 @@ class Category extends Model
|
||||
return (int) $query->other()->pluck('id')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope gets only parent categories.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeWithSubCategory($query)
|
||||
{
|
||||
return $query->withoutGlobalScope(new Scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line actions.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLineActionsAttribute()
|
||||
{
|
||||
$actions = [];
|
||||
|
||||
$actions[] = [
|
||||
'title' => trans('general.edit'),
|
||||
'icon' => 'create',
|
||||
'url' => route('categories.edit', $this->id),
|
||||
'permission' => 'update-settings-categories',
|
||||
];
|
||||
|
||||
$transfer_id = Category::transfer();
|
||||
|
||||
if ($this->id == $transfer_id) {
|
||||
return $actions;
|
||||
}
|
||||
|
||||
$actions[] = [
|
||||
'type' => 'delete',
|
||||
'icon' => 'delete',
|
||||
'route' => 'categories.destroy',
|
||||
'permission' => 'delete-settings-categories',
|
||||
'model' => $this,
|
||||
];
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new factory instance for the model.
|
||||
*
|
||||
|
@@ -101,6 +101,18 @@ class Currency extends Model
|
||||
return $this->contacts()->whereIn('type', (array) $this->getVendorTypes());
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope currency by code.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param mixed $code
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeCode($query, $code)
|
||||
{
|
||||
return $query->where($this->qualifyColumn('code'), $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current precision.
|
||||
*
|
||||
@@ -172,15 +184,30 @@ class Currency extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope currency by code.
|
||||
* Get the line actions.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param mixed $code
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
* @return array
|
||||
*/
|
||||
public function scopeCode($query, $code)
|
||||
public function getLineActionsAttribute()
|
||||
{
|
||||
return $query->where($this->qualifyColumn('code'), $code);
|
||||
$actions = [];
|
||||
|
||||
$actions[] = [
|
||||
'title' => trans('general.edit'),
|
||||
'icon' => 'edit',
|
||||
'url' => route('currencies.edit', $this->id),
|
||||
'permission' => 'update-settings-currencies',
|
||||
];
|
||||
|
||||
$actions[] = [
|
||||
'type' => 'delete',
|
||||
'icon' => 'delete',
|
||||
'route' => 'currencies.destroy',
|
||||
'permission' => 'delete-settings-currencies',
|
||||
'model' => $this,
|
||||
];
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
71
app/Models/Setting/EmailTemplate.php
Normal file
71
app/Models/Setting/EmailTemplate.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Setting;
|
||||
|
||||
use App\Abstracts\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EmailTemplate extends Model
|
||||
{
|
||||
protected $table = 'email_templates';
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = ['title'];
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'alias', 'class', 'name', 'subject', 'body', 'params', 'created_from', 'created_by'];
|
||||
|
||||
public function getTitleAttribute()
|
||||
{
|
||||
return trans($this->name);
|
||||
}
|
||||
|
||||
public function getGroupAttribute()
|
||||
{
|
||||
if (Str::startsWith($this->alias, 'invoice_')) {
|
||||
$group = 'general.invoices';
|
||||
} elseif (Str::startsWith($this->alias, 'bill_')) {
|
||||
$group = 'general.bills';
|
||||
} elseif (Str::startsWith($this->alias, 'payment_')) {
|
||||
$group = 'general.payments';
|
||||
} else {
|
||||
$group = 'general.others';
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to only include email templates of a given alias.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param mixed $alias
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeAlias($query, $alias)
|
||||
{
|
||||
return $query->where('alias', $alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to only include email templates of a given module alias (class).
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $alias
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeModuleAlias($query, $alias)
|
||||
{
|
||||
$class = ($alias == 'core') ? 'App\\\\' : 'Modules\\\\' . Str::studly($alias) . '\\\\';
|
||||
|
||||
return $query->where('class', 'like', $class . '%');
|
||||
}
|
||||
}
|
@@ -45,7 +45,7 @@ class Tax extends Model
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany('App\Models\Common\Item');
|
||||
return $this->hasMany('App\Models\Common\ItemTax');
|
||||
}
|
||||
|
||||
public function document_items()
|
||||
@@ -136,6 +136,33 @@ class Tax extends Model
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line actions.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLineActionsAttribute()
|
||||
{
|
||||
$actions = [];
|
||||
|
||||
$actions[] = [
|
||||
'title' => trans('general.edit'),
|
||||
'icon' => 'edit',
|
||||
'url' => route('taxes.edit', $this->id),
|
||||
'permission' => 'update-settings-taxes',
|
||||
];
|
||||
|
||||
$actions[] = [
|
||||
'type' => 'delete',
|
||||
'icon' => 'delete',
|
||||
'route' => 'taxes.destroy',
|
||||
'permission' => 'delete-settings-taxes',
|
||||
'model' => $this,
|
||||
];
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new factory instance for the model.
|
||||
*
|
||||
|
Reference in New Issue
Block a user