FIX: Venta nueva no se ingresaba
This commit is contained in:
@ -349,7 +349,7 @@
|
||||
const lines = [
|
||||
'<label for="rut">RUT</label>',
|
||||
'<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">',
|
||||
'<i class="exclamation triangle icon"></i>',
|
||||
'RUT Inválido',
|
||||
@ -358,25 +358,25 @@
|
||||
'<label for="nombres">Nombre</label>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="nombres" id="nombres" />',
|
||||
'<input type="text" name="nombres" id="nombres" placeholder="Nombre(s)" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="apellido_paterno" />',
|
||||
'<input type="text" name="apellido_paterno" placeholder="Apellido Paterno" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="apellido_materno" />',
|
||||
'<input type="text" name="apellido_materno" placeholder="Apellido Materno" />',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<label for="calle">Dirección</label>',
|
||||
'<div class="inline fields">',
|
||||
'<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 class="field">',
|
||||
'<input type="text" name="numero" size="5" />',
|
||||
'<input type="text" name="numero" size="5" placeholder="Número" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="extra" />',
|
||||
'<input type="text" name="extra" placeholder="Otros Detalles" />',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<div class="inline fields">',
|
||||
|
@ -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()
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -1,28 +1,37 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal\Service;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Propietario
|
||||
class Propietario extends Service
|
||||
{
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
protected Repository\Venta\Propietario $propietarioRepository,
|
||||
protected Repository\Direccion $direccionRepository
|
||||
) {}
|
||||
) {
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function addPropietario(array $data): Model\Venta\Propietario
|
||||
{
|
||||
$direccion = $this->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',
|
||||
|
Reference in New Issue
Block a user