98 lines
2.5 KiB
PHP
98 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class VersamentoFiscale extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'versamenti_fiscali';
|
|
|
|
protected $fillable = [
|
|
'amministratore_id',
|
|
'fattura_id',
|
|
'tipo_versamento',
|
|
'codice_tributo',
|
|
'periodo_riferimento',
|
|
'data_versamento',
|
|
'importo_versato',
|
|
'modalita_versamento',
|
|
'numero_bonifico',
|
|
'codice_identificativo',
|
|
'note'
|
|
];
|
|
|
|
protected $casts = [
|
|
'data_versamento' => 'date',
|
|
'importo_versato' => 'decimal:2'
|
|
];
|
|
|
|
const TIPO_RITENUTA_ACCONTO = 'ritenuta_acconto';
|
|
const TIPO_IVA = 'iva';
|
|
const TIPO_INPS = 'inps';
|
|
const TIPO_INAIL = 'inail';
|
|
const TIPO_ALTRO = 'altro';
|
|
|
|
const MODALITA_F24 = 'f24';
|
|
const MODALITA_BONIFICO = 'bonifico';
|
|
const MODALITA_BOLLETTINO = 'bollettino';
|
|
|
|
public function amministratore(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Administrator::class);
|
|
}
|
|
|
|
public function fattura(): BelongsTo
|
|
{
|
|
return $this->belongsTo(FatturaFornitore::class);
|
|
}
|
|
|
|
public function scopeByTipo($query, $tipo)
|
|
{
|
|
return $query->where('tipo_versamento', $tipo);
|
|
}
|
|
|
|
public function scopeByPeriodo($query, $dataInizio, $dataFine)
|
|
{
|
|
return $query->whereBetween('data_versamento', [$dataInizio, $dataFine]);
|
|
}
|
|
|
|
public function scopeByAnno($query, $anno)
|
|
{
|
|
return $query->whereYear('data_versamento', $anno);
|
|
}
|
|
|
|
public function scopeByModalita($query, $modalita)
|
|
{
|
|
return $query->where('modalita_versamento', $modalita);
|
|
}
|
|
|
|
public function getTipoVersamentoLabelAttribute()
|
|
{
|
|
$labels = [
|
|
self::TIPO_RITENUTA_ACCONTO => 'Ritenuta d\'Acconto',
|
|
self::TIPO_IVA => 'IVA',
|
|
self::TIPO_INPS => 'INPS',
|
|
self::TIPO_INAIL => 'INAIL',
|
|
self::TIPO_ALTRO => 'Altro'
|
|
];
|
|
|
|
return $labels[$this->tipo_versamento] ?? $this->tipo_versamento;
|
|
}
|
|
|
|
public function getModalitaVersamentoLabelAttribute()
|
|
{
|
|
$labels = [
|
|
self::MODALITA_F24 => 'F24',
|
|
self::MODALITA_BONIFICO => 'Bonifico',
|
|
self::MODALITA_BOLLETTINO => 'Bollettino'
|
|
];
|
|
|
|
return $labels[$this->modalita_versamento] ?? $this->modalita_versamento;
|
|
}
|
|
}
|