2023-09-12
This commit is contained in:
@ -27,9 +27,9 @@ class Venta extends Ideal\Repository
|
||||
$this->setTable('venta');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Venta
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
$map = (new Implement\Repository\MapperParser(['uf']))
|
||||
->register('propietario', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->propietarioRepository, 'fetchById'])
|
||||
@ -65,7 +65,7 @@ class Venta extends Ideal\Repository
|
||||
]
|
||||
];
|
||||
foreach ($map as $column => $settings) {
|
||||
if ($data[$column] !== null and $data[$column] !== 0) {
|
||||
if (isset($data[$column]) and $data[$column] !== 0) {
|
||||
if (isset($settings['repository'])) {
|
||||
$fp->{$settings['property'] ?? $column} = $settings['repository']->fetchById($data[$column]);
|
||||
continue;
|
||||
@ -89,7 +89,7 @@ class Venta extends Ideal\Repository
|
||||
->setFunction(function($data) {
|
||||
return $data['escritura'] !== null;
|
||||
}))*/
|
||||
->register('entrega', (new Implement\Repository\Mapper())
|
||||
/*->register('entrega', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable(function($entrega_id) {
|
||||
if ($entrega_id !== null and $entrega_id !== 0) {
|
||||
@ -97,7 +97,8 @@ class Venta extends Ideal\Repository
|
||||
}
|
||||
return null;
|
||||
})
|
||||
->setArgs([$data['entrega']])))
|
||||
->setArgs([$data['entrega']]))
|
||||
->setDefault(null))*/
|
||||
/*->register('entregado', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable(function($entrega_id) {
|
||||
@ -114,28 +115,27 @@ class Venta extends Ideal\Repository
|
||||
->register('fecha_ingreso', new Implement\Repository\Mapper\DateTime('fecha_ingreso', 'fechaIngreso'))
|
||||
//->register('avalchile')
|
||||
//->register('agente')
|
||||
//->register('uf')
|
||||
->register('relacionado', new Implement\Repository\Mapper\Boolean('relacionado'));
|
||||
//->register('promocion')
|
||||
//->register('resciliacion')
|
||||
//->register('devolucion');
|
||||
return $this->parseData(new Model\Venta(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
public function save(Define\Model $model): Model\Venta
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['propietario', 'propiedad', 'pie', 'bono_pie', 'credito', 'escritura', 'subsidio', 'escriturado',
|
||||
'entrega', 'entregado', 'fecha', 'valor_uf', 'estado', 'fecha_ingreso', 'avalchile', 'agente', 'uf',
|
||||
'relacionado', 'promocion', 'resciliacion', 'devolucion'],
|
||||
[$model->propietario->rut, $model->propiedad()->id, $model->formaPago()->Pie?->id, $model->formaPago()->bonoPie?->id,
|
||||
[$model->propietario()->rut, $model->propiedad()->id, $model->formaPago()->pie?->id, $model->formaPago()->bonoPie?->id,
|
||||
$model->formaPago()->credito?->id, $model->formaPago()->escritura?->id, $model->formaPago()->subsidio?->id,
|
||||
$model->formaPago()->escritura !== null ? 1 : 0, null, 0, $model->fecha->format('Y-m-d'), $model->valor,
|
||||
$model->currentEstado->vigente ? 1 : 0, $model->fechaIngreso->format('Y-m-d'), '', null, 0,
|
||||
$model->relacionado ? 1 : 0, null, null, null]
|
||||
$model->formaPago()->escritura !== null ? $model->formaPago()->escritura->pago->fecha->format('Y-m-d') : null,
|
||||
null, null, $model->fecha->format('Y-m-d'), $model->valor, 1, $model->fechaIngreso->format('Y-m-d'),
|
||||
null, null, $model->uf, $model->relacionado ? 1 : 0, null, null, null]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta
|
||||
{
|
||||
return $this->update($model, ['propietario', 'propiedad', 'pie', 'bono_pie', 'credito', 'escritura', 'subsidio', 'escriturado',
|
||||
'entrega', 'entregado', 'fecha', 'valor_uf', 'estado', 'fecha_ingreso', 'avalchile', 'agente', 'uf',
|
||||
@ -155,7 +155,7 @@ WHERE ptu.`proyecto` = ? AND tev.`activa`
|
||||
GROUP BY a.`id`";
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Define\Model
|
||||
public function fetchByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Model\Venta
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
@ -168,4 +168,9 @@ FROM `{$this->getTable()}` a
|
||||
WHERE `proyecto`.`descripcion` = ? AND `unidad`.`descripcion` = ? AND tev.`activa`";
|
||||
return $this->fetchOne($query, [$proyecto_nombre, $unidad_descripcion]);
|
||||
}
|
||||
public function fetchByPie(int $pie_id): Model\Venta
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pie` = ?";
|
||||
return $this->fetchOne($query, [$pie_id]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user