Introduzione copiaIn per articoli e righe

Introduzione della funzione copiaIn per le componenti contabili, per future semplificazioni del sistema di riporto tra i vari documenti.
This commit is contained in:
Thomas Zilio 2018-12-25 13:58:40 +01:00
parent 1594b8c07e
commit 26c67a9f8e
3 changed files with 53 additions and 6 deletions

View File

@ -143,4 +143,30 @@ abstract class Article extends Row
{
return $this->belongsTo(Original::class, 'idarticolo');
}
public function copiaIn(Document $document)
{
$class = get_class($document);
$namespace = implode('\\', explode('\\', $class, -1));
$current = get_class($this);
$pieces = explode('\\', $current);
$type = end($pieces);
$object = $namespace.'\\Components\\'.$type;
$attributes = $this->getAttributes();
unset($attributes['id']);
$model = $object::make($document, $this->articolo);
$model->save();
$model = $object::find($model->id);
$accepted = $model->getAttributes();
$attributes = array_intersect_key($attributes, $accepted);
$model->fill($attributes);
return $model;
}
}

View File

@ -8,6 +8,8 @@ use Common\Document;
abstract class Description extends Model
{
protected $guarded = [];
protected static function boot($bypass = false)
{
parent::boot();
@ -51,8 +53,32 @@ abstract class Description extends Model
$this->save();
}
public function copiaIn(Document $document)
{
$class = get_class($document);
$namespace = implode('\\', explode('\\', $class, -1));
$current = get_class($this);
$pieces = explode('\\', $current);
$type = end($pieces);
$object = $namespace.'\\Components\\'.$type;
$attributes = $this->getAttributes();
unset($attributes['id']);
$model = $object::make($document);
$model->save();
$model = $object::find($model->id);
$accepted = $model->getAttributes();
$attributes = array_intersect_key($attributes, $accepted);
$model->fill($attributes);
return $model;
}
abstract public function parent();
abstract public function getParentID();
}

View File

@ -16,11 +16,6 @@ class Anagrafica extends Model
protected $primaryKey = 'idanagrafica';
protected $module = 'Anagrafiche';
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];
protected $appends = [