',
'',
'RUT Inválido',
@@ -358,25 +358,25 @@
'',
'',
'
',
- '',
+ '',
'
',
'
',
- '',
+ '',
'
',
'
',
- '',
+ '',
'
',
'
',
'',
'',
'
',
- '',
+ '',
'
',
'
',
- '',
+ '',
'
',
'
',
- '',
+ '',
'
',
'
',
'',
diff --git a/app/src/Repository/Venta.php b/app/src/Repository/Venta.php
index c4aa63b..6d6a54a 100644
--- a/app/src/Repository/Venta.php
+++ b/app/src/Repository/Venta.php
@@ -240,6 +240,15 @@ GROUP BY a.`id`";*/
->where('`unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?');
return $this->fetchMany($query, [$unidad, $tipo]);
}
+ public function fetchByUnidadId(int $unidad_id): Model\Venta
+ {
+ $query = $this->connection->getQueryBuilder()
+ ->select('a.*')
+ ->from("{$this->getTable()} a")
+ ->joined('JOIN propiedad_unidad pu ON pu.propiedad = a.propiedad')
+ ->where('pu.unidad = ?');
+ return $this->fetchOne($query, [$unidad_id]);
+ }
public function fetchIdsByUnidad(string $unidad, string $tipo): array
{
$query = $this->connection->getQueryBuilder()
diff --git a/app/src/Repository/Venta/Propietario.php b/app/src/Repository/Venta/Propietario.php
index 5b0f5dc..ff23398 100644
--- a/app/src/Repository/Venta/Propietario.php
+++ b/app/src/Repository/Venta/Propietario.php
@@ -22,7 +22,7 @@ class Propietario extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
- $map = (new Implement\Repository\MapperParser(['dv', 'nombres']))
+ $map = (new Implement\Repository\MapperParser(['rut', 'dv', 'nombres']))
->register('apellido_paterno', (new Implement\Repository\Mapper())
->setProperty('apellidos')
->setFunction(function($data) {
@@ -64,8 +64,8 @@ class Propietario extends Ideal\Repository
public function save(Define\Model $model): Define\Model
{
$model->rut = $this->saveNew(
- ['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]
+ ['rut', 'dv', 'nombres', 'apellido_paterno', 'apellido_materno', 'direccion', 'otro', 'representante'],
+ [$model->rut, $model->dv, $model->nombres, $model->apellidos['paterno'], $model->apellidos['materno'], $model->datos->direccion->id, $model->otro->rut ?? 0, $model->representante->rut ?? 0]
);
return $model;
}
diff --git a/app/src/Service/Venta.php b/app/src/Service/Venta.php
index 9697d0d..d694ad6 100644
--- a/app/src/Service/Venta.php
+++ b/app/src/Service/Venta.php
@@ -2,14 +2,17 @@
namespace Incoviba\Service;
use DateTimeImmutable;
+use Incoviba\Common\Ideal\Service;
use Incoviba\Common\Implement;
use Incoviba\Repository;
use Incoviba\Model;
use PhpParser\Node\Expr\AssignOp\Mod;
+use Psr\Log\LoggerInterface;
-class Venta
+class Venta extends Service
{
public function __construct(
+ LoggerInterface $logger,
protected Repository\Venta $ventaRepository,
protected Repository\Venta\EstadoVenta $estadoVentaRepository,
protected Repository\Venta\TipoEstadoVenta $tipoEstadoVentaRepository,
@@ -25,7 +28,9 @@ class Venta
protected Venta\BonoPie $bonoPieService,
protected Venta\Pago $pagoService,
protected Money $moneyService
- ) {}
+ ) {
+ parent::__construct($logger);
+ }
public function getById(int $venta_id): Model\Venta
{
@@ -51,6 +56,10 @@ class Venta
$ventas = $this->ventaRepository->fetchByUnidad($unidad, $tipo);
return array_map([$this, 'process'], $ventas);
}
+ public function getByUnidadId(int $unidad_id): Model\Venta
+ {
+ return $this->process($this->ventaRepository->fetchByUnidadId($unidad_id));
+ }
public function getByPropietario(string $propietario): array
{
$ventas = $this->ventaRepository->fetchByPropietario($propietario);
@@ -89,7 +98,7 @@ class Venta
'propietario' => $propietario->rut,
'propiedad' => $propiedad->id,
'fecha' => $fecha->format('Y-m-d'),
- 'valor_uf' => $data['valor'],
+ 'valor_uf' => $this->cleanValue($data['valor']),
'fecha_ingreso' => (new DateTimeImmutable())->format('Y-m-d'),
'uf' => $data['uf']
];
@@ -249,6 +258,7 @@ class Venta
'cuotas',
'uf'
], $filtered_data);
+ $mapped_data['valor'] = $this->cleanValue($mapped_data['valor']);
return $this->pieService->add($mapped_data);
}
protected function addSubsidio(array $data): Model\Venta\Subsidio
@@ -307,6 +317,13 @@ class Venta
$estado = $this->estadoVentaRepository->create($estadoData);
$this->estadoVentaRepository->save($estado);
}
+ protected function cleanValue($value): float
+ {
+ if ((float) $value == $value) {
+ return (float) $value;
+ }
+ return (float) str_replace(['.', ','], ['', '.'], $value);
+ }
public function escriturar(Model\Venta $venta, array $data): bool
{
diff --git a/app/src/Service/Venta/Propietario.php b/app/src/Service/Venta/Propietario.php
index 699ad70..68db0f8 100644
--- a/app/src/Service/Venta/Propietario.php
+++ b/app/src/Service/Venta/Propietario.php
@@ -1,28 +1,37 @@
addDireccion($data);
$data['direccion'] = $direccion->id;
+ $data['dv'] = 'i';
if (str_contains($data['rut'], '-')) {
- $data['rut'] = explode('-', $data['rut'])[0];
+ list($rut, $dv) = explode('-', $data['rut']);
+ $data['rut'] = $rut;
+ $data['dv'] = $dv;
}
$fields = array_fill_keys([
'rut',
+ 'dv',
'nombres',
'apellido_paterno',
'apellido_materno',