mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-22 14:27:42 +01:00
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:
parent
1594b8c07e
commit
26c67a9f8e
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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 = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user