first commit
This commit is contained in:
80
app/Models/Setting/Category.php
Normal file
80
app/Models/Setting/Category.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Setting;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Models\Item\Item;
|
||||
use App\Models\Expense\Payment;
|
||||
use App\Models\Income\Revenue;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
protected $table = 'categories';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'type', 'color', 'enabled'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['name', 'type', 'enabled'];
|
||||
|
||||
public function revenues()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Revenue');
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Payment');
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany('App\Models\Item\Item');
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
$items = $this->items();
|
||||
if ($items->count()) {
|
||||
$error['items'] = $items->count();
|
||||
}
|
||||
|
||||
$payments = $this->payments();
|
||||
if ($payments->count()) {
|
||||
$error['payments'] = $payments->count();
|
||||
}
|
||||
|
||||
$revenues = $this->revenues();
|
||||
if ($revenues->count()) {
|
||||
$error['revenues'] = $revenues->count();
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to only include categories of a given type.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param mixed $type
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeType($query, $type)
|
||||
{
|
||||
return $query->where('type', $type);
|
||||
}
|
||||
}
|
55
app/Models/Setting/Currency.php
Normal file
55
app/Models/Setting/Currency.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Setting;
|
||||
|
||||
use App\Models\Model;
|
||||
|
||||
class Currency extends Model
|
||||
{
|
||||
|
||||
protected $table = 'currencies';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'code', 'rate', 'enabled'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['name', 'code', 'rate', 'enabled'];
|
||||
|
||||
public function accounts()
|
||||
{
|
||||
return $this->hasMany('App\Models\Banking\Account');
|
||||
}
|
||||
|
||||
public function customers()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Customer');
|
||||
}
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Invoice', 'code', 'currency_code');
|
||||
}
|
||||
|
||||
public function revenues()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Revenue', 'code', 'currency_code');
|
||||
}
|
||||
|
||||
public function bills()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Bill', 'code', 'currency_code');
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Payment', 'code', 'currency_code');
|
||||
}
|
||||
}
|
59
app/Models/Setting/Setting.php
Normal file
59
app/Models/Setting/Setting.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Setting;
|
||||
|
||||
use App\Scopes\Company;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
|
||||
protected $table = 'settings';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'key', 'value'];
|
||||
|
||||
/**
|
||||
* The "booting" method of the model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::addGlobalScope(new Company);
|
||||
}
|
||||
|
||||
public static function all($code = 'general')
|
||||
{
|
||||
return static::where('key', 'like', $code . '.%')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Global company relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Company\Company');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to only include company data.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param $company_id
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeCompanyId($query, $company_id)
|
||||
{
|
||||
return $query->where($this->table . '.company_id', '=', $company_id);
|
||||
}
|
||||
}
|
69
app/Models/Setting/Tax.php
Normal file
69
app/Models/Setting/Tax.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Setting;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Models\Item\Item;
|
||||
use App\Models\Expense\Bill;
|
||||
use App\Models\Income\Invoice;
|
||||
|
||||
class Tax extends Model
|
||||
{
|
||||
|
||||
protected $table = 'taxes';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'rate', 'enabled'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['name', 'rate', 'enabled'];
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany('App\Models\Item\Item');
|
||||
}
|
||||
|
||||
public function bills()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Bill');
|
||||
}
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Invoice');
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
$items = $this->items();
|
||||
if ($items->count()) {
|
||||
$error['items'] = $items->count();
|
||||
}
|
||||
|
||||
$bills = $this->bills();
|
||||
if ($bills->count()) {
|
||||
$error['bills'] = $bills->count();
|
||||
}
|
||||
|
||||
$invoices = $this->invoices();
|
||||
if ($invoices->count()) {
|
||||
$error['invoices'] = $invoices->count();
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user