mirror of
https://github.com/crater-invoice/crater.git
synced 2025-12-15 09:52:55 -05:00
build version 400
This commit is contained in:
81
app/Models/TaxType.php
Normal file
81
app/Models/TaxType.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\Tax;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class TaxType extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'percent',
|
||||
'company_id',
|
||||
'compound_tax',
|
||||
'collective_tax',
|
||||
'description'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'percent' => 'float'
|
||||
];
|
||||
|
||||
public function taxes()
|
||||
{
|
||||
return $this->hasMany(Tax::class);
|
||||
}
|
||||
|
||||
public function scopeWhereCompany($query, $company_id)
|
||||
{
|
||||
$query->where('company_id', $company_id);
|
||||
}
|
||||
|
||||
public function scopeWhereTaxType($query, $tax_type_id)
|
||||
{
|
||||
$query->orWhere('id', $tax_type_id);
|
||||
}
|
||||
|
||||
public function scopeApplyFilters($query, array $filters)
|
||||
{
|
||||
$filters = collect($filters);
|
||||
|
||||
if ($filters->get('tax_type_id')) {
|
||||
$query->whereTaxType($filters->get('tax_type_id'));
|
||||
}
|
||||
|
||||
if ($filters->get('company_id')) {
|
||||
$query->whereCompany($filters->get('company_id'));
|
||||
}
|
||||
|
||||
if ($filters->get('search')) {
|
||||
$query->whereSearch($filters->get('search'));
|
||||
}
|
||||
|
||||
if ($filters->get('orderByField') || $filters->get('orderBy')) {
|
||||
$field = $filters->get('orderByField') ? $filters->get('orderByField') : 'payment_number';
|
||||
$orderBy = $filters->get('orderBy') ? $filters->get('orderBy') : 'asc';
|
||||
$query->whereOrder($field, $orderBy);
|
||||
}
|
||||
}
|
||||
|
||||
public function scopeWhereOrder($query, $orderByField, $orderBy)
|
||||
{
|
||||
$query->orderBy($orderByField, $orderBy);
|
||||
}
|
||||
|
||||
public function scopeWhereSearch($query, $search)
|
||||
{
|
||||
$query->where('name', 'LIKE', '%' . $search . '%');
|
||||
}
|
||||
|
||||
public function scopePaginateData($query, $limit)
|
||||
{
|
||||
if ($limit == 'all') {
|
||||
return collect(['data' => $query->get()]);
|
||||
}
|
||||
|
||||
return $query->paginate($limit);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user