mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-11-03 22:13:18 -05:00 
			
		
		
		
	
		
			
				
	
	
		
			88 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			88 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace Crater\Models;
 | 
						|
 | 
						|
use Illuminate\Database\Eloquent\Factories\HasFactory;
 | 
						|
use Illuminate\Database\Eloquent\Model;
 | 
						|
 | 
						|
class TaxType extends Model
 | 
						|
{
 | 
						|
    use HasFactory;
 | 
						|
 | 
						|
    protected $fillable = [
 | 
						|
        'name',
 | 
						|
        'percent',
 | 
						|
        'company_id',
 | 
						|
        'compound_tax',
 | 
						|
        'collective_tax',
 | 
						|
        'description',
 | 
						|
    ];
 | 
						|
 | 
						|
    protected $casts = [
 | 
						|
        'percent' => 'float',
 | 
						|
        'compound_tax' => 'boolean'
 | 
						|
    ];
 | 
						|
 | 
						|
    public function taxes()
 | 
						|
    {
 | 
						|
        return $this->hasMany(Tax::class);
 | 
						|
    }
 | 
						|
 | 
						|
    public function company()
 | 
						|
    {
 | 
						|
        return $this->belongsTo(Company::class);
 | 
						|
    }
 | 
						|
 | 
						|
    public function scopeWhereCompany($query)
 | 
						|
    {
 | 
						|
        $query->where('company_id', request()->header('company'));
 | 
						|
    }
 | 
						|
 | 
						|
    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 $query->get();
 | 
						|
        }
 | 
						|
 | 
						|
        return $query->paginate($limit);
 | 
						|
    }
 | 
						|
}
 |