. */ namespace Modules\Iva; use Common\SimpleModelTrait; use Illuminate\Database\Eloquent\Model; class Aliquota extends Model { use SimpleModelTrait; protected $table = 'co_iva'; public static function build($esente = null, $percentuale = null, $indetraibile = null, $dicitura = null, $codice = null, $codice_natura_fe = null, $esigibilita = null) { $model = new static(); $model->esente = $esente; $model->percentuale = $percentuale; $model->indetraibile = $indetraibile; $model->dicitura = $dicitura; $model->codice = $codice; $model->codice_natura_fe = $codice_natura_fe; $model->esigibilita = $esigibilita; $model->save(); return $model; } /** * Ritorna l'attributo name dell'aliquota IVA. * * @return string */ public function getNameAttribute() { return database()->table($this->table.'_lang') ->select('name') ->where('id_record', '=', $this->id) ->where('id_lang', '=', \App::getLang()) ->first()->name; } /** * Ritorna l'id dell'aliquota IVA. * * @param string $name il nome da ricercare * * @return \Illuminate\Support\Collection */ public function getByName($name) { return database()->table($this->table.'_lang') ->select('id_record') ->where('name', '=', $name) ->where('id_lang', '=', \App::getLang()) ->first(); } /** * Imposta l'attributo name dell'aliquota. */ public function setNameAttribute($value) { $table = database()->table($this->table.'_lang'); $translated = $table ->where('id_record', '=', $this->id) ->where('id_lang', '=', \App::getLang()); if ($translated->count() > 0) { $translated->update([ 'name' => $value ]); } else { $table->insert([ 'id_record' => $this->id, 'id_lang' => \App::getLang(), 'name' => $value ]); } } }