83 lines
2.7 KiB
PHP
83 lines
2.7 KiB
PHP
![]() |
<?php
|
||
|
namespace Incoviba\Repository\Venta;
|
||
|
|
||
|
use Incoviba\Common\Define;
|
||
|
use Incoviba\Common\Ideal;
|
||
|
use Incoviba\Model;
|
||
|
use Incoviba\Repository;
|
||
|
|
||
|
class Propietario extends Ideal\Repository
|
||
|
{
|
||
|
public function __construct(Define\Connection $connection, protected Repository\Direccion $direccionRepository)
|
||
|
{
|
||
|
parent::__construct($connection);
|
||
|
$this->setTable('propietario');
|
||
|
}
|
||
|
|
||
|
protected function getKey(): string
|
||
|
{
|
||
|
return 'rut';
|
||
|
}
|
||
|
|
||
|
public function create(?array $data = null): Define\Model
|
||
|
{
|
||
|
$map = [
|
||
|
'dv' => [],
|
||
|
'nombres' => [],
|
||
|
'apellido_paterno' => [
|
||
|
'property' => 'apellidos',
|
||
|
'function' => function($data) {
|
||
|
$arr = [
|
||
|
'paterno' => $data['apellido_paterno']
|
||
|
];
|
||
|
if ($data['apellido_materno'] !== '') {
|
||
|
$arr['materno'] = $data['apellido_materno'];
|
||
|
}
|
||
|
return $arr;
|
||
|
}
|
||
|
],
|
||
|
'direccion' => [
|
||
|
'property' => 'datos',
|
||
|
'function' => function($data) {
|
||
|
$datos = new Model\Venta\Datos();
|
||
|
if ($data['direccion'] !== null and $data['direccion'] !== 0) {
|
||
|
$datos->direccion = $this->direccionRepository->fetchById($data['direccion']);
|
||
|
}
|
||
|
return $datos;
|
||
|
}
|
||
|
],
|
||
|
'representante' => [
|
||
|
'function' => function($data) {
|
||
|
if ($data['representante'] === null or $data['representante'] === 0) {
|
||
|
return null;
|
||
|
}
|
||
|
return $this->fetchById($data['representante']);
|
||
|
}
|
||
|
],
|
||
|
'otro' => [
|
||
|
'function' => function($data) {
|
||
|
if ($data['otro'] === null) {
|
||
|
return null;
|
||
|
}
|
||
|
return $data['otro'] !== 0;
|
||
|
}
|
||
|
]
|
||
|
];
|
||
|
return $this->parseData(new Model\Venta\Propietario(), $data, $map);
|
||
|
}
|
||
|
|
||
|
public function save(Define\Model $model): Define\Model
|
||
|
{
|
||
|
$model->rut = $this->saveNew(
|
||
|
['dv', 'nombres', 'apellido_paterno', 'apellido_materno'],
|
||
|
[$model->dv, $model->nombres, $model->apellidos['paterno'], $model->apellidos['materno']]
|
||
|
);
|
||
|
return $model;
|
||
|
}
|
||
|
|
||
|
public function edit(Define\Model $model, array $new_data): Define\Model
|
||
|
{
|
||
|
return $this->update($model, ['dv', 'nombres', 'apellido_paterno', 'apellido_materno'], $new_data);
|
||
|
}
|
||
|
}
|