FIX: Venta nueva no se ingresaba
This commit is contained in:
@ -349,7 +349,7 @@
|
|||||||
const lines = [
|
const lines = [
|
||||||
'<label for="rut">RUT</label>',
|
'<label for="rut">RUT</label>',
|
||||||
'<div class="inline field">',
|
'<div class="inline field">',
|
||||||
'<input type="text" id="rut" name="rut" />',
|
'<input type="text" id="rut" name="rut" placeholder="00000000-0" />',
|
||||||
'<span class="ui error message" id="alert_rut">',
|
'<span class="ui error message" id="alert_rut">',
|
||||||
'<i class="exclamation triangle icon"></i>',
|
'<i class="exclamation triangle icon"></i>',
|
||||||
'RUT Inválido',
|
'RUT Inválido',
|
||||||
@ -358,25 +358,25 @@
|
|||||||
'<label for="nombres">Nombre</label>',
|
'<label for="nombres">Nombre</label>',
|
||||||
'<div class="inline fields">',
|
'<div class="inline fields">',
|
||||||
'<div class="field">',
|
'<div class="field">',
|
||||||
'<input type="text" name="nombres" id="nombres" />',
|
'<input type="text" name="nombres" id="nombres" placeholder="Nombre(s)" />',
|
||||||
'</div>',
|
'</div>',
|
||||||
'<div class="field">',
|
'<div class="field">',
|
||||||
'<input type="text" name="apellido_paterno" />',
|
'<input type="text" name="apellido_paterno" placeholder="Apellido Paterno" />',
|
||||||
'</div>',
|
'</div>',
|
||||||
'<div class="field">',
|
'<div class="field">',
|
||||||
'<input type="text" name="apellido_materno" />',
|
'<input type="text" name="apellido_materno" placeholder="Apellido Materno" />',
|
||||||
'</div>',
|
'</div>',
|
||||||
'</div>',
|
'</div>',
|
||||||
'<label for="calle">Dirección</label>',
|
'<label for="calle">Dirección</label>',
|
||||||
'<div class="inline fields">',
|
'<div class="inline fields">',
|
||||||
'<div class="eight wide field">',
|
'<div class="eight wide field">',
|
||||||
'<input type="text" name="calle" id="calle" size="16" />',
|
'<input type="text" name="calle" id="calle" size="16" placeholder="Calle" />',
|
||||||
'</div>',
|
'</div>',
|
||||||
'<div class="field">',
|
'<div class="field">',
|
||||||
'<input type="text" name="numero" size="5" />',
|
'<input type="text" name="numero" size="5" placeholder="Número" />',
|
||||||
'</div>',
|
'</div>',
|
||||||
'<div class="field">',
|
'<div class="field">',
|
||||||
'<input type="text" name="extra" />',
|
'<input type="text" name="extra" placeholder="Otros Detalles" />',
|
||||||
'</div>',
|
'</div>',
|
||||||
'</div>',
|
'</div>',
|
||||||
'<div class="inline fields">',
|
'<div class="inline fields">',
|
||||||
|
@ -240,6 +240,15 @@ GROUP BY a.`id`";*/
|
|||||||
->where('`unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?');
|
->where('`unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?');
|
||||||
return $this->fetchMany($query, [$unidad, $tipo]);
|
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
|
public function fetchIdsByUnidad(string $unidad, string $tipo): array
|
||||||
{
|
{
|
||||||
$query = $this->connection->getQueryBuilder()
|
$query = $this->connection->getQueryBuilder()
|
||||||
|
@ -22,7 +22,7 @@ class Propietario extends Ideal\Repository
|
|||||||
|
|
||||||
public function create(?array $data = null): Define\Model
|
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())
|
->register('apellido_paterno', (new Implement\Repository\Mapper())
|
||||||
->setProperty('apellidos')
|
->setProperty('apellidos')
|
||||||
->setFunction(function($data) {
|
->setFunction(function($data) {
|
||||||
@ -64,8 +64,8 @@ class Propietario extends Ideal\Repository
|
|||||||
public function save(Define\Model $model): Define\Model
|
public function save(Define\Model $model): Define\Model
|
||||||
{
|
{
|
||||||
$model->rut = $this->saveNew(
|
$model->rut = $this->saveNew(
|
||||||
['dv', 'nombres', 'apellido_paterno', 'apellido_materno', 'direccion', 'otro', 'representante'],
|
['rut', '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]
|
[$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;
|
return $model;
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,17 @@
|
|||||||
namespace Incoviba\Service;
|
namespace Incoviba\Service;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
|
use Incoviba\Common\Ideal\Service;
|
||||||
use Incoviba\Common\Implement;
|
use Incoviba\Common\Implement;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
use PhpParser\Node\Expr\AssignOp\Mod;
|
use PhpParser\Node\Expr\AssignOp\Mod;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Venta
|
class Venta extends Service
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
LoggerInterface $logger,
|
||||||
protected Repository\Venta $ventaRepository,
|
protected Repository\Venta $ventaRepository,
|
||||||
protected Repository\Venta\EstadoVenta $estadoVentaRepository,
|
protected Repository\Venta\EstadoVenta $estadoVentaRepository,
|
||||||
protected Repository\Venta\TipoEstadoVenta $tipoEstadoVentaRepository,
|
protected Repository\Venta\TipoEstadoVenta $tipoEstadoVentaRepository,
|
||||||
@ -25,7 +28,9 @@ class Venta
|
|||||||
protected Venta\BonoPie $bonoPieService,
|
protected Venta\BonoPie $bonoPieService,
|
||||||
protected Venta\Pago $pagoService,
|
protected Venta\Pago $pagoService,
|
||||||
protected Money $moneyService
|
protected Money $moneyService
|
||||||
) {}
|
) {
|
||||||
|
parent::__construct($logger);
|
||||||
|
}
|
||||||
|
|
||||||
public function getById(int $venta_id): Model\Venta
|
public function getById(int $venta_id): Model\Venta
|
||||||
{
|
{
|
||||||
@ -51,6 +56,10 @@ class Venta
|
|||||||
$ventas = $this->ventaRepository->fetchByUnidad($unidad, $tipo);
|
$ventas = $this->ventaRepository->fetchByUnidad($unidad, $tipo);
|
||||||
return array_map([$this, 'process'], $ventas);
|
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
|
public function getByPropietario(string $propietario): array
|
||||||
{
|
{
|
||||||
$ventas = $this->ventaRepository->fetchByPropietario($propietario);
|
$ventas = $this->ventaRepository->fetchByPropietario($propietario);
|
||||||
@ -89,7 +98,7 @@ class Venta
|
|||||||
'propietario' => $propietario->rut,
|
'propietario' => $propietario->rut,
|
||||||
'propiedad' => $propiedad->id,
|
'propiedad' => $propiedad->id,
|
||||||
'fecha' => $fecha->format('Y-m-d'),
|
'fecha' => $fecha->format('Y-m-d'),
|
||||||
'valor_uf' => $data['valor'],
|
'valor_uf' => $this->cleanValue($data['valor']),
|
||||||
'fecha_ingreso' => (new DateTimeImmutable())->format('Y-m-d'),
|
'fecha_ingreso' => (new DateTimeImmutable())->format('Y-m-d'),
|
||||||
'uf' => $data['uf']
|
'uf' => $data['uf']
|
||||||
];
|
];
|
||||||
@ -249,6 +258,7 @@ class Venta
|
|||||||
'cuotas',
|
'cuotas',
|
||||||
'uf'
|
'uf'
|
||||||
], $filtered_data);
|
], $filtered_data);
|
||||||
|
$mapped_data['valor'] = $this->cleanValue($mapped_data['valor']);
|
||||||
return $this->pieService->add($mapped_data);
|
return $this->pieService->add($mapped_data);
|
||||||
}
|
}
|
||||||
protected function addSubsidio(array $data): Model\Venta\Subsidio
|
protected function addSubsidio(array $data): Model\Venta\Subsidio
|
||||||
@ -307,6 +317,13 @@ class Venta
|
|||||||
$estado = $this->estadoVentaRepository->create($estadoData);
|
$estado = $this->estadoVentaRepository->create($estadoData);
|
||||||
$this->estadoVentaRepository->save($estado);
|
$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
|
public function escriturar(Model\Venta $venta, array $data): bool
|
||||||
{
|
{
|
||||||
|
@ -1,28 +1,37 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Service\Venta;
|
namespace Incoviba\Service\Venta;
|
||||||
|
|
||||||
|
use Incoviba\Common\Ideal\Service;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Propietario
|
class Propietario extends Service
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
LoggerInterface $logger,
|
||||||
protected Repository\Venta\Propietario $propietarioRepository,
|
protected Repository\Venta\Propietario $propietarioRepository,
|
||||||
protected Repository\Direccion $direccionRepository
|
protected Repository\Direccion $direccionRepository
|
||||||
) {}
|
) {
|
||||||
|
parent::__construct($logger);
|
||||||
|
}
|
||||||
|
|
||||||
public function addPropietario(array $data): Model\Venta\Propietario
|
public function addPropietario(array $data): Model\Venta\Propietario
|
||||||
{
|
{
|
||||||
$direccion = $this->addDireccion($data);
|
$direccion = $this->addDireccion($data);
|
||||||
$data['direccion'] = $direccion->id;
|
$data['direccion'] = $direccion->id;
|
||||||
|
$data['dv'] = 'i';
|
||||||
|
|
||||||
if (str_contains($data['rut'], '-')) {
|
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([
|
$fields = array_fill_keys([
|
||||||
'rut',
|
'rut',
|
||||||
|
'dv',
|
||||||
'nombres',
|
'nombres',
|
||||||
'apellido_paterno',
|
'apellido_paterno',
|
||||||
'apellido_materno',
|
'apellido_materno',
|
||||||
|
Reference in New Issue
Block a user