2023-09-12
This commit is contained in:
@ -15,7 +15,7 @@ class Credito extends Ideal\Repository
|
||||
$this->setTable('credito');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Venta\Credito
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('pago', (new Implement\Repository\Mapper())
|
||||
@ -24,15 +24,15 @@ class Credito extends Ideal\Repository
|
||||
}));
|
||||
return $this->parseData(new Model\Venta\Credito(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
public function save(Define\Model $model): Model\Venta\Credito
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['banco', 'valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'],
|
||||
[$model->pago->banco->id, $model->pago->valor, $model->pago->fecha->format('Y-m-d'), $model->pago->uf, null, null, $model->pago->id]
|
||||
[$model->pago->banco?->id, $model->valor ?? (($model->pago->uf > 0) ? $model->pago->valor / $model->pago->uf : null), $model->pago->fecha->format('Y-m-d'), $model->pago->uf, null, null, $model->pago->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\Credito
|
||||
{
|
||||
return $this->update($model, ['banco', 'valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data);
|
||||
}
|
||||
|
@ -23,14 +23,17 @@ class Cuota extends Ideal\Repository
|
||||
$this->setTable('cuota');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Venta\Cuota
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['valor', 'uf', 'numero']))
|
||||
$map = (new Implement\Repository\MapperParser(['uf', 'numero']))
|
||||
->register('pie', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->pieRepository->fetchById($data['pie']);
|
||||
}))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||
->register('valor_$', (new Implement\Repository\Mapper())
|
||||
->setProperty('valor')
|
||||
)
|
||||
->register('estado', new Implement\Repository\Mapper\Boolean('estado'))
|
||||
->register('banco', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
@ -55,18 +58,18 @@ class Cuota extends Ideal\Repository
|
||||
return $this->parseData(new Model\Venta\Cuota(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
public function save(Define\Model $model): Model\Venta\Cuota
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['pie', 'fecha', 'valor', 'estado', 'banco', 'fecha_pago', 'abonado', 'fecha_abonado', 'uf', 'pago', 'numero'],
|
||||
[$model->pie->id, $model->fecha->format('Y-m-d H:i:s'), $model->valor, $model->estado ? 1 : 0, $model?->banco->id,
|
||||
$model?->fechaPago->format('Y-m-d H:i:s'), $model?->abonado ? 1 : 0, $model?->fechaAbonado->format('Y-m-d H:i:s'),
|
||||
$model?->uf, $model?->pago->id, $model?->numero]
|
||||
['pie', 'fecha', 'valor_$', 'estado', 'banco', 'fecha_pago', 'abonado', 'fecha_abono', 'uf', 'pago', 'numero'],
|
||||
[$model->pie->id, $model->fecha->format('Y-m-d H:i:s'), $model->valor, $model->estado ? 1 : 0, $model->banco?->id,
|
||||
null, null, null,
|
||||
$model->uf, $model->pago->id, $model->numero]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\Cuota
|
||||
{
|
||||
return $this->update($model, ['pie', 'fecha', 'valor', 'estado', 'banco', 'fecha_pago', 'abonado', 'fecha_abonado', 'uf', 'pago', 'numero'], $new_data);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ class EstadoPago extends Ideal\Repository
|
||||
$this->setTable('estado_pago');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Venta\EstadoPago
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('pago', (new Implement\Repository\Mapper())
|
||||
@ -34,7 +34,7 @@ class EstadoPago extends Ideal\Repository
|
||||
return $this->parseData(new Model\Venta\EstadoPago(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
public function save(Define\Model $model): Model\Venta\EstadoPago
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['pago', 'estado', 'fecha'],
|
||||
@ -43,7 +43,7 @@ class EstadoPago extends Ideal\Repository
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\EstadoPago
|
||||
{
|
||||
return $this->update($model, ['pago', 'estado', 'fecha'], $new_data);
|
||||
}
|
||||
@ -53,7 +53,7 @@ class EstadoPago extends Ideal\Repository
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pago` = ?";
|
||||
return $this->fetchMany($query, [$pago_id]);
|
||||
}
|
||||
public function fetchCurrentByPago(int $pago_id): Define\Model
|
||||
public function fetchCurrentByPago(int $pago_id): Model\Venta\EstadoPago
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
@ -61,7 +61,7 @@ FROM `{$this->getTable()}` a
|
||||
WHERE a.`pago` = ?";
|
||||
return $this->fetchOne($query, [$pago_id]);
|
||||
}
|
||||
public function fetchByPagoAndEstado(int $pago_id, int $estado_id): Define\Model
|
||||
public function fetchByPagoAndEstado(int $pago_id, int $estado_id): Model\Venta\EstadoPago
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pago` = ? AND `estado` = ?";
|
||||
return $this->fetchOne($query, [$pago_id, $estado_id]);
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
@ -10,13 +9,17 @@ use Incoviba\Repository;
|
||||
|
||||
class Pago extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Banco $bancoRepository, protected TipoPago $tipoPagoRepository)
|
||||
public function __construct(
|
||||
Define\Connection $connection,
|
||||
protected Repository\Banco $bancoRepository,
|
||||
protected TipoPago $tipoPagoRepository
|
||||
)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('pago');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Venta\Pago
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['valor', 'identificador', 'uf', 'pagador']))
|
||||
->register('banco', (new Implement\Repository\Mapper())
|
||||
@ -45,15 +48,15 @@ class Pago extends Ideal\Repository
|
||||
}));
|
||||
return $this->parseData(new Model\Venta\Pago(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
public function save(Define\Model $model): Model\Venta\Pago
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['valor', 'banco', 'tipo', 'identificador', 'fecha', 'uf', 'pagador', 'asociado'],
|
||||
[$model->valor, $model?->banco->id, $model?->tipoPago->id, $model?->identificador, $model?->fecha->format('Y-m-d H:i:s'), $model?->uf, $model?->pagador, $model?->asociado->id]
|
||||
[$model->valor, $model->banco?->id, $model->tipoPago?->id, $model->identificador, $model->fecha?->format('Y-m-d H:i:s'), $model->uf, $model->pagador, $model->asociado?->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\Pago
|
||||
{
|
||||
return $this->update($model, ['valor', 'banco', 'tipo', 'identificador', 'fecha', 'uf', 'pagador', 'asociado'], $new_data);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class Pie extends Ideal\Repository
|
||||
$this->setTable('pie');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Venta\Pie
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['valor', 'uf', 'cuotas']))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||
@ -35,15 +35,15 @@ class Pie extends Ideal\Repository
|
||||
}));
|
||||
return $this->parseData(new Model\Venta\Pie(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
public function save(Define\Model $model): Model\Venta\Pie
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['fecha', 'valor', 'uf', 'cuotas', 'asociado', 'reajuste'],
|
||||
[$model->fecha->format('Y-m-d H:i:s'), $model->valor, $model?->uf, $model->cuotas, $model?->asociado->id, $model?->reajuste->id]
|
||||
[$model->fecha->format('Y-m-d H:i:s'), $model->valor, $model->uf, $model->cuotas, $model->asociado?->id, $model->reajuste?->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\Pie
|
||||
{
|
||||
return $this->update($model, ['fecha', 'valor', 'uf', 'cuotas', 'asociado', 'reajuste'], $new_data);
|
||||
}
|
||||
|
@ -15,27 +15,39 @@ class Propiedad extends Ideal\Repository
|
||||
$this->setTable('propiedad');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Venta\Propiedad
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('unidad_principal', (new Implement\Repository\Mapper())
|
||||
->setProperty('unidades')
|
||||
->setFunction(function($data) {
|
||||
return $this->unidadService->getByPropiedad($data['id']);
|
||||
if (isset($data['id'])) {
|
||||
return $this->unidadService->getByPropiedad($data['id']);
|
||||
}
|
||||
return [$this->unidadService->getById($data['unidad_principal'])];
|
||||
}))
|
||||
->register('estado', new Implement\Repository\Mapper\Boolean('estado'));
|
||||
return $this->parseData(new Model\Venta\Propiedad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
public function save(Define\Model $model): Model\Venta\Propiedad
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['unidad_principal', 'estacionamientos', 'bodegas', 'estado'],
|
||||
[$model->departamentos()[0]->id, null, null, 1]
|
||||
[$model->departamentos()[0]->id,
|
||||
implode(',', array_map(function(Model\Venta\Unidad $unidad) {return $unidad->id;}, $model->estacionamientos())),
|
||||
implode(',', array_map(function(Model\Venta\Unidad $unidad) {return $unidad->id;}, $model->bodegas())),
|
||||
1]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\Propiedad
|
||||
{
|
||||
return $this->update($model, ['unidad_principal', 'estacionamientos', 'bodegas', 'estado'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchVigenteByUnidad(int $unidad_id): Model\Venta\Propiedad
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `unidad_principal` = ?";
|
||||
return $this->fetchOne($query, [$unidad_id]);
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,13 @@ class Propietario extends Ideal\Repository
|
||||
}
|
||||
return $this->fetchById($data['representante']);
|
||||
}))
|
||||
->register('otro', (new Implement\Repository\Mapper\Boolean('otro'))
|
||||
->register('otro', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
if ($data['otro'] === null or $data['otro'] === 0) {
|
||||
return null;
|
||||
}
|
||||
return $this->fetchById($data['otro']);
|
||||
})
|
||||
->setDefault(null));
|
||||
return $this->parseData(new Model\Venta\Propietario(), $data, $map);
|
||||
}
|
||||
@ -58,14 +64,14 @@ class Propietario extends Ideal\Repository
|
||||
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']]
|
||||
['dv', 'nombres', 'apellido_paterno', 'apellido_materno', 'direccion', 'otro', 'representante'],
|
||||
[$model->dv, $model->nombres, $model->apellidos['paterno'], $model->apellidos['materno'], $model->datos->direccion->id, $model->otro->rut ?? 0, $model->representante->rut ?? 0]
|
||||
);
|
||||
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);
|
||||
return $this->update($model, ['dv', 'nombres', 'apellido_paterno', 'apellido_materno', 'direccion', 'otro', 'representante'], $new_data);
|
||||
}
|
||||
}
|
||||
|
@ -14,12 +14,12 @@ class Subsidio extends Ideal\Repository
|
||||
$this->setTable('subsidio');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Venta\Subsidio
|
||||
{
|
||||
$map = new Implement\Repository\MapperParser(['pago', 'subsidio']);
|
||||
return $this->parseData(new Model\Venta\Subsidio(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
public function save(Define\Model $model): Model\Venta\Subsidio
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['pago', 'subsidio'],
|
||||
@ -27,7 +27,7 @@ class Subsidio extends Ideal\Repository
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\Subsidio
|
||||
{
|
||||
return $this->update($model, ['pago', 'subsidio'], $new_data);
|
||||
}
|
||||
|
@ -14,13 +14,13 @@ class TipoEstadoVenta extends Ideal\Repository
|
||||
$this->setTable('tipo_estado_venta');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Venta\TipoEstadoVenta
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion']))
|
||||
->register('activa', new Implement\Repository\Mapper\Boolean('activa'));
|
||||
return $this->parseData(new Model\Venta\TipoEstadoVenta(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
public function save(Define\Model $model): Model\Venta\TipoEstadoVenta
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion', 'activa'],
|
||||
@ -28,8 +28,14 @@ class TipoEstadoVenta extends Ideal\Repository
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\TipoEstadoVenta
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'activa'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByDescripcion(string $descripcion): Model\Venta\TipoEstadoVenta
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `descripcion` = ?";
|
||||
return $this->fetchOne($query, [$descripcion]);
|
||||
}
|
||||
}
|
||||
|
@ -14,12 +14,12 @@ class TipoPago extends Ideal\Repository
|
||||
$this->setTable('tipo_pago');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Venta\TipoPago
|
||||
{
|
||||
$map = new Implement\Repository\MapperParser(['descripcion']);
|
||||
return $this->parseData(new Model\Venta\TipoPago(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
public function save(Define\Model $model): Model\Venta\TipoPago
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion'],
|
||||
@ -27,8 +27,14 @@ class TipoPago extends Ideal\Repository
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\TipoPago
|
||||
{
|
||||
return $this->update($model, ['descripcion'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByDescripcion(string $descripcion): Model\Venta\TipoPago
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `descripcion` = ?";
|
||||
return $this->fetchOne($query, [$descripcion]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user