Ventas->Listado->Ventas
This commit is contained in:
26
app/src/Controller/Ventas.php
Normal file
26
app/src/Controller/Ventas.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Ventas
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Proyecto $proyectoService): ResponseInterface
|
||||
{
|
||||
$proyectos = array_map(function(Model\Proyecto $proyecto) {return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];}, $proyectoService->getVendibles());
|
||||
return $view->render($response, 'ventas.list', compact('proyectos'));
|
||||
}
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$ventas = $service->getByProyecto($proyecto_id);
|
||||
$response->getBody()->write(json_encode(['ventas' => $ventas, 'total' => count($ventas)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -12,6 +12,12 @@ class Cierres
|
||||
{
|
||||
return $view->render($response, 'ventas.cierres.list');
|
||||
}
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Ventas\Cierre $service, int $cierre_id): ResponseInterface
|
||||
{
|
||||
$cierre = $service->getById($cierre_id);
|
||||
return $view->render($response, 'ventas.cierres.show', compact('cierre'));
|
||||
}
|
||||
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Ventas\Cierre $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
|
@ -1,16 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Precios
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view): ResponseInterface
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Proyecto $proyectoService): ResponseInterface
|
||||
{
|
||||
return $view->render($response, 'ventas.precios.list');
|
||||
$proyectos = array_map(function(Model\Proyecto $proyecto) {return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];}, $proyectoService->getVendibles());
|
||||
return $view->render($response, 'ventas.precios.list', compact('proyectos'));
|
||||
}
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Ventas\Precio $precioService): ResponseInterface
|
||||
{
|
||||
@ -21,4 +23,10 @@ class Precios
|
||||
$response->getBody()->write(json_encode(['precios' => $precios, 'total' => count($precios)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Ventas\Precio $precioService, int $unidad_id): ResponseInterface
|
||||
{
|
||||
$precio = $precioService->getByUnidad($unidad_id);
|
||||
$response->getBody()->write(json_encode(['precio' => $precio]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
25
app/src/Middleware/NotFound.php
Normal file
25
app/src/Middleware/NotFound.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseFactoryInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Slim\Exception\HttpNotFoundException;
|
||||
use Incoviba\Common\Alias\View;
|
||||
|
||||
class NotFound
|
||||
{
|
||||
public function __construct(protected LoggerInterface $logger, protected ResponseFactoryInterface $responseFactory, protected View $view) {}
|
||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
try {
|
||||
return $handler->handle($request);
|
||||
} catch (HttpNotFoundException $exception) {
|
||||
$this->logger->warning($exception);
|
||||
$response = $this->responseFactory->createResponse(404);
|
||||
return $this->view->render($response, 'not_found');
|
||||
}
|
||||
}
|
||||
}
|
@ -15,4 +15,8 @@ class Comuna extends Model
|
||||
'provincia' => $this->provincia
|
||||
]);
|
||||
}
|
||||
public function __toString(): string
|
||||
{
|
||||
return implode(', ', [$this->descripcion, '' . $this->provincia]);
|
||||
}
|
||||
}
|
||||
|
@ -19,4 +19,18 @@ class Direccion extends Model
|
||||
'comuna' => $this->comuna
|
||||
]);
|
||||
}
|
||||
public function __toString(): string
|
||||
{
|
||||
$array = [
|
||||
implode(' ', [
|
||||
$this->calle,
|
||||
$this->numero
|
||||
])
|
||||
];
|
||||
if ($this->extra !== '') {
|
||||
$array[]= $this->extra;
|
||||
}
|
||||
$array []= '' . $this->comuna;
|
||||
return implode(', ', $array);
|
||||
}
|
||||
}
|
||||
|
@ -15,4 +15,8 @@ class Provincia extends Model
|
||||
'region' => $this->region
|
||||
]);
|
||||
}
|
||||
public function __toString(): string
|
||||
{
|
||||
return implode(', ', [$this->descripcion, '' . $this->region]);
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,15 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
use Incoviba\Model\Proyecto\Superficie;
|
||||
use Incoviba\Model\Proyecto\Terreno;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Proyecto extends Model
|
||||
class Proyecto extends Ideal\Model
|
||||
{
|
||||
public Inmobiliaria $inmobiliaria;
|
||||
public string $descripcion;
|
||||
public Direccion $direccion;
|
||||
public Terreno $terreno;
|
||||
public Superficie $superficie;
|
||||
public Proyecto\Terreno $terreno;
|
||||
public Proyecto\Superficie $superficie;
|
||||
public float $corredor;
|
||||
public int $pisos;
|
||||
public int $subterraneos;
|
||||
|
@ -17,4 +17,8 @@ class Region extends Model
|
||||
'numeracion' => $this->numeracion ?? 0
|
||||
]);
|
||||
}
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->descripcion;
|
||||
}
|
||||
}
|
||||
|
34
app/src/Model/Venta.php
Normal file
34
app/src/Model/Venta.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Venta extends Ideal\Model
|
||||
{
|
||||
public Venta\Propietario $propietario;
|
||||
public Venta\Propiedad $propiedad;
|
||||
public Venta\FormaPago $formaPago;
|
||||
public DateTimeInterface $fecha;
|
||||
public DateTimeInterface $fechaIngreso;
|
||||
public float $valor;
|
||||
public bool $relacionado;
|
||||
|
||||
public array $estados;
|
||||
public Venta\EstadoVenta $currentEstado;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'propietario' => $this->propietario,
|
||||
'propiedad' => $this->propiedad,
|
||||
'forma_pago' => $this->formaPago,
|
||||
'fecha' => $this->fecha->format('Y-m-d'),
|
||||
'fecha_ingreso' => $this->fechaIngreso->format('Y-m-d'),
|
||||
'valor' => $this->valor,
|
||||
'relacionado' => $this->relacionado,
|
||||
'estados' => $this->estados,
|
||||
'current_estado' => $this->currentEstado
|
||||
]);
|
||||
}
|
||||
}
|
8
app/src/Model/Venta/BonoPie.php
Normal file
8
app/src/Model/Venta/BonoPie.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class BonoPie extends Ideal\Model
|
||||
{
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use stdClass;
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
@ -17,6 +18,28 @@ class Cierre extends Ideal\Model
|
||||
public ?EstadoCierre $current = null;
|
||||
|
||||
public array $unidades = [];
|
||||
public array $valoresCierre = [];
|
||||
|
||||
public function neto(): float
|
||||
{
|
||||
$sum = $this->precio;
|
||||
$bonos = array_filter($this->valoresCierre, function(ValorCierre $valorCierre) {return $valorCierre->tipoValorCierre->descripcion === 'bono pie';});
|
||||
$sum -= array_reduce($bonos, function($sum, ValorCierre $bono) {return $sum + $bono->valor;}, 0);
|
||||
$unidades = array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion !== 'departamento';});
|
||||
$sum -= array_reduce($unidades, function($sum, Unidad $unidad) {return $sum + ($unidad->currentPrecio->valor ?? 0);});
|
||||
return $sum;
|
||||
}
|
||||
|
||||
public function principal(): stdClass
|
||||
{
|
||||
$unidades = array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento';});
|
||||
$output = [
|
||||
'descripcion' => implode(' - ', array_map(function(Unidad $unidad) {return $unidad->descripcion;}, $unidades)),
|
||||
'vendible' => array_reduce($unidades, function($sum, Unidad $unidad) {return $sum + $unidad->proyectoTipoUnidad->vendible();}, 0),
|
||||
'precio' => array_reduce($unidades, function($sum, Unidad $unidad) {return $sum + $unidad->currentPrecio->valor;}, 0)
|
||||
];
|
||||
return (object) $output;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
@ -28,7 +51,8 @@ class Cierre extends Ideal\Model
|
||||
'propietario' => $this->propietario->rut,
|
||||
'estados' => $this->estados,
|
||||
'estado_cierre' => $this->current,
|
||||
'unidades' => $this->unidades
|
||||
'unidades' => $this->unidades,
|
||||
'valores_cierre' => $this->valoresCierre
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
7
app/src/Model/Venta/Credito.php
Normal file
7
app/src/Model/Venta/Credito.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Credito extends Ideal\Model
|
||||
{}
|
21
app/src/Model/Venta/Entrega.php
Normal file
21
app/src/Model/Venta/Entrega.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Entrega extends Ideal\Model
|
||||
{
|
||||
public DateTimeInterface $fecha;
|
||||
public ?Pago $operacion;
|
||||
public ?Pago $reserva;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'fecha' => $this->fecha->format('Y-m-d'),
|
||||
'operacion' => $this->operacion,
|
||||
'reserva' => $this->reserva
|
||||
]);
|
||||
}
|
||||
}
|
7
app/src/Model/Venta/Escritura.php
Normal file
7
app/src/Model/Venta/Escritura.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Escritura extends Ideal\Model
|
||||
{}
|
22
app/src/Model/Venta/EstadoVenta.php
Normal file
22
app/src/Model/Venta/EstadoVenta.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class EstadoVenta extends Ideal\Model
|
||||
{
|
||||
public Model\Venta $venta;
|
||||
public TipoEstadoVenta $tipoEstadoVenta;
|
||||
public DateTimeInterface $fecha;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'venta_id' => $this->venta->id,
|
||||
'tipo_estado_venta' => $this->tipoEstadoVenta,
|
||||
'fecha' => $this->fecha->format('Y-m-d')
|
||||
]);
|
||||
}
|
||||
}
|
24
app/src/Model/Venta/FormaPago.php
Normal file
24
app/src/Model/Venta/FormaPago.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
class FormaPago implements JsonSerializable
|
||||
{
|
||||
public ?Pie $pie;
|
||||
public ?BonoPie $bonoPie;
|
||||
public ?Credito $credito;
|
||||
public ?Escritura $escritura;
|
||||
public ?Subsidio $subsidio;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'pie' => $this->pie ?? null,
|
||||
'bono_pie' => $this->bonoPie ?? null,
|
||||
'credito' => $this->credito ?? null,
|
||||
'escritura' => $this->escritura ?? null,
|
||||
'subsidio' => $this->subsidio ?? null
|
||||
];
|
||||
}
|
||||
}
|
47
app/src/Model/Venta/Propiedad.php
Normal file
47
app/src/Model/Venta/Propiedad.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Propiedad extends Ideal\Model
|
||||
{
|
||||
public array $unidades;
|
||||
|
||||
public function departamentos(): array
|
||||
{
|
||||
return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento';});
|
||||
}
|
||||
public function estacionamientos(): array
|
||||
{
|
||||
return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'estacionamiento';});
|
||||
}
|
||||
public function bodegas(): array
|
||||
{
|
||||
return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'bodega';});
|
||||
}
|
||||
|
||||
public function summary(): string
|
||||
{
|
||||
return implode(' - ', array_merge(
|
||||
array_map(function(Unidad $unidad) {
|
||||
return $unidad->descripcion;
|
||||
}, $this->departamentos()),
|
||||
array_map(function(Unidad $unidad) {
|
||||
return "E{$unidad->descripcion}";
|
||||
}, $this->estacionamientos()),
|
||||
array_map(function(Unidad $unidad) {
|
||||
return "B{$unidad->descripcion}";
|
||||
}, $this->bodegas())
|
||||
));
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'departamentos' => $this->departamentos(),
|
||||
'estacionamientos' => $this->estacionamientos(),
|
||||
'bodegas' => $this->bodegas(),
|
||||
'summary' => $this->summary()
|
||||
];
|
||||
}
|
||||
}
|
18
app/src/Model/Venta/Subsidio.php
Normal file
18
app/src/Model/Venta/Subsidio.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Subsidio extends Ideal\Model
|
||||
{
|
||||
public Pago $ahorro;
|
||||
public Pago $subsidio;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'ahorro' => $this->ahorro,
|
||||
'subsidio' => $this->subsidio
|
||||
]);
|
||||
}
|
||||
}
|
16
app/src/Model/Venta/TipoEstadoVenta.php
Normal file
16
app/src/Model/Venta/TipoEstadoVenta.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Model\Tipo;
|
||||
|
||||
class TipoEstadoVenta extends Tipo
|
||||
{
|
||||
public bool $activa;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'activa' => $this->activa
|
||||
]);
|
||||
}
|
||||
}
|
7
app/src/Model/Venta/TipoValorCierre.php
Normal file
7
app/src/Model/Venta/TipoValorCierre.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Model\Tipo;
|
||||
|
||||
class TipoValorCierre extends Tipo
|
||||
{}
|
@ -12,6 +12,9 @@ class Unidad extends Ideal\Model
|
||||
public ?string $orientacion = '';
|
||||
public Model\Proyecto\ProyectoTipoUnidad $proyectoTipoUnidad;
|
||||
|
||||
public array $precios = [];
|
||||
public ?Precio $currentPrecio = null;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
|
20
app/src/Model/Venta/ValorCierre.php
Normal file
20
app/src/Model/Venta/ValorCierre.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class ValorCierre extends Ideal\Model
|
||||
{
|
||||
public Cierre $cierre;
|
||||
public TipoValorCierre $tipoValorCierre;
|
||||
public float $valor;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'cierre_id' => $this->cierre->id,
|
||||
'tipo_valor_cierre' => $this->tipoValorCierre,
|
||||
'valor' => $this->valor
|
||||
]);
|
||||
}
|
||||
}
|
155
app/src/Repository/Venta.php
Normal file
155
app/src/Repository/Venta.php
Normal file
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Venta extends Ideal\Repository
|
||||
{
|
||||
public function __construct(
|
||||
Define\Connection $connection,
|
||||
protected Venta\Propietario $propietarioRepository,
|
||||
protected Venta\Propiedad $propiedadRepository,
|
||||
protected Venta\Pie $pieRepository,
|
||||
protected Venta\BonoPie $bonoPieRepository,
|
||||
protected Venta\Credito $creditoRepository,
|
||||
protected Venta\Escritura $escrituraRepository,
|
||||
protected Venta\Subsidio $subsidioRepository,
|
||||
protected Venta\Entrega $entregaRepository,
|
||||
protected Venta\Pago $pagoRepository
|
||||
)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('venta');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'propietario' => [
|
||||
'function' => function($data) {
|
||||
return $this->propietarioRepository->fetchById($data['propietario']);
|
||||
}
|
||||
],
|
||||
'propiedad' => [
|
||||
'function' => function($data) {
|
||||
return $this->propiedadRepository->fetchById($data['propiedad']);
|
||||
}
|
||||
],
|
||||
'pie' => [
|
||||
'property' => 'formaPago',
|
||||
'function' => function($data) {
|
||||
$fp = new Model\Venta\FormaPago();
|
||||
$map = [
|
||||
'pie' => [
|
||||
'repository' => $this->pieRepository
|
||||
],
|
||||
'bono_pie' => [
|
||||
'property' => 'bonoPie',
|
||||
'repository' => $this->bonoPieRepository
|
||||
],
|
||||
'credito' => [
|
||||
'repository' => $this->creditoRepository
|
||||
],
|
||||
'escritura' => [
|
||||
'repository' => $this->escrituraRepository
|
||||
],
|
||||
'subsidio' => [
|
||||
'repository' => $this->subsidioRepository
|
||||
]
|
||||
];
|
||||
foreach ($map as $column => $settings) {
|
||||
if ($data[$column] !== null and $data[$column] !== 0) {
|
||||
$fp->{$settings['property'] ?? $column} = $settings['repository']->fetchById($data[$column]);
|
||||
}
|
||||
}
|
||||
return $fp;
|
||||
}
|
||||
],
|
||||
'escriturado' => [
|
||||
'function' => function($data) {
|
||||
return $data['escritura'] !== null;
|
||||
}
|
||||
],
|
||||
'entrega' => [
|
||||
'function' => function($data) {
|
||||
if ($data['entrega'] !== null and $data['entrega'] !== 0) {
|
||||
return $this->entregaRepository->fetchById($data['entrega']);
|
||||
}
|
||||
}
|
||||
],
|
||||
'entregado' => [
|
||||
'function' => function($data) {
|
||||
if ($data['entrega'] !== null and $data['entrega'] !== 0) {
|
||||
return $data['entrega'] !== null;
|
||||
}
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
],
|
||||
'valor_uf' => [
|
||||
'property' => 'valor'
|
||||
],
|
||||
//'estado' => [],
|
||||
'fecha_ingreso' => [
|
||||
'property' => 'fechaIngreso',
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha_ingreso']);
|
||||
}
|
||||
],
|
||||
/*'avalchile' => [
|
||||
|
||||
],*/
|
||||
//'agente',
|
||||
//'uf',
|
||||
'relacionado' => [
|
||||
'function' => function($data) {
|
||||
return $data['relacionado'] !== 0;
|
||||
}
|
||||
],
|
||||
//'promocion',
|
||||
//'resciliacion',
|
||||
//'devolucion'
|
||||
];
|
||||
return $this->parseData(new Model\Venta(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$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->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]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['propietario', 'propiedad', 'pie', 'bono_pie', 'credito', 'escritura', 'subsidio', 'escriturado',
|
||||
'entrega', 'entregado', 'fecha', 'valor_uf', 'estado', 'fecha_ingreso', 'avalchile', 'agente', 'uf',
|
||||
'relacionado', 'promocion', 'resciliacion', 'devolucion'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
|
||||
JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`
|
||||
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
|
||||
WHERE ptu.`proyecto` = ? AND tev.`activa`
|
||||
GROUP BY a.`id`";
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
}
|
39
app/src/Repository/Venta/BonoPie.php
Normal file
39
app/src/Repository/Venta/BonoPie.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class BonoPie extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('bono_pie');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\BonoPie(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['valor', 'pago'],
|
||||
[$model->pago->valor, $model->pago->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['valor', 'pago'], $new_data);
|
||||
}
|
||||
}
|
39
app/src/Repository/Venta/Credito.php
Normal file
39
app/src/Repository/Venta/Credito.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Credito extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('credito');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Credito(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$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]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['banco', 'valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data);
|
||||
}
|
||||
}
|
38
app/src/Repository/Venta/Entrega.php
Normal file
38
app/src/Repository/Venta/Entrega.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Entrega extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('entrega');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = ['fecha', 'fondo_operacion', 'fondo_reserva', 'fecha_fondo_operacion', 'fecha_fondo_reserva',
|
||||
'pago_operacion', 'pago_reserva'];
|
||||
return $this->parseData(new Model\Venta\Entrega(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['fecha', 'fondo_operacion', 'fondo_reserva', 'fecha_fondo_operacion', 'fecha_fondo_reserva',
|
||||
'pago_operacion', 'pago_reserva'],
|
||||
[$model->fecha->format('Y-m-d'), $model->operacion->valor, $model->reserva->valor,
|
||||
$model->operacion->fecha('Y-m-d'), $model->reserva->fecha('Y-m-d'), $model->operacion->id,
|
||||
$model->reserva->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['fecha', 'fondo_operacion', 'fondo_reserva', 'fecha_fondo_operacion',
|
||||
'fecha_fondo_reserva', 'pago_operacion', 'pago_reserva'], $new_data);
|
||||
}
|
||||
}
|
39
app/src/Repository/Venta/Escritura.php
Normal file
39
app/src/Repository/Venta/Escritura.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Escritura extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('escritura');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Escritura(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'],
|
||||
[$model->pago->valor, $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
|
||||
{
|
||||
return $this->update($model, ['valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data);
|
||||
}
|
||||
}
|
67
app/src/Repository/Venta/EstadoVenta.php
Normal file
67
app/src/Repository/Venta/EstadoVenta.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class EstadoVenta extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Venta $ventaRepository,
|
||||
protected TipoEstadoVenta $tipoEstadoVentaRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('estado_venta');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'venta' => [
|
||||
'function' => function($data) {
|
||||
return $this->ventaRepository->fetchById($data['venta']);
|
||||
}
|
||||
],
|
||||
'estado' => [
|
||||
'property' => 'tipoEstadoVenta',
|
||||
'function' => function($data) {
|
||||
return $this->tipoEstadoVentaRepository->fetchById($data['estado']);
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\EstadoVenta(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['venta', 'estado', 'fecha'],
|
||||
[$model->venta->id, $model->tipoEstadoVenta->id, $model->fecha->format('Y-m-d')]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['venta', 'estado', 'fecha'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByVenta(int $venta_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `venta` = ?";
|
||||
return $this->fetchMany($query, [$venta_id]);
|
||||
}
|
||||
public function fetchCurrentByVenta(int $venta_id): Define\Model
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `{$this->getTable()}` GROUP BY `venta`) e0 ON e0.`id` = a.`id`
|
||||
WHERE a.`venta` = ?";
|
||||
return $this->fetchOne($query, [$venta_id]);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
@ -52,4 +53,22 @@ WHERE ptu.`proyecto` = ? AND tep.`descripcion` = 'vigente'
|
||||
ORDER BY tu.`orden`, ptu.`nombre`, `unidad`.`subtipo`, LPAD(`unidad`.`descripcion`, 4, '0')";
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchByUnidad(int $unidad_id): Define\Model
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT e1.* FROM `estado_precio` e1 JOIN (SELECT MAX(`id`) AS 'id', `precio` FROM `estado_precio` GROUP BY `precio`) e0 ON e0.`id` = e1.`id`) ep ON ep.`precio` = a.`id`
|
||||
JOIN `tipo_estado_precio` tep ON tep.`id` = ep.`estado`
|
||||
WHERE `unidad` = ? AND tep.`descripcion` = 'vigente'";
|
||||
return $this->fetchOne($query, [$unidad_id]);
|
||||
}
|
||||
public function fetchByUnidadAndDate(int $unidad_id, string $date_time): Define\Model
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT e1.* FROM `estado_precio` e1 JOIN (SELECT MAX(`id`) AS 'id', `precio` FROM `estado_precio` GROUP BY `precio`) e0 ON e0.`id` = e1.`id`) ep ON ep.`precio` = a.`id`
|
||||
JOIN `tipo_estado_precio` tep ON tep.`id` = ep.`estado`
|
||||
WHERE `unidad` = ? AND ep.`fecha` <= ? AND tep.`descripcion` = 'vigente'";
|
||||
return $this->fetchOne($query, [$unidad_id, $date_time]);
|
||||
}
|
||||
}
|
||||
|
45
app/src/Repository/Venta/Propiedad.php
Normal file
45
app/src/Repository/Venta/Propiedad.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Propiedad extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Unidad $unidadRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('propiedad');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'unidad_principal' => [
|
||||
'property' => 'unidades',
|
||||
'function' => function($data) {
|
||||
return $this->unidadRepository->fetchByPropiedad($data['id']);
|
||||
}
|
||||
],
|
||||
'estado' => [
|
||||
'function' => function($data) {
|
||||
return true;
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Propiedad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['unidad_principal', 'estacionamientos', 'bodegas', 'estado'],
|
||||
[$model->departamentos()[0]->id, null, null, 1]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['unidad_principal', 'estacionamientos', 'bodegas', 'estado'], $new_data);
|
||||
}
|
||||
}
|
33
app/src/Repository/Venta/Subsidio.php
Normal file
33
app/src/Repository/Venta/Subsidio.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Subsidio extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('subsidio');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = ['pago', 'subsidio'];
|
||||
return $this->parseData(new Model\Venta\Subsidio(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['pago', 'subsidio'],
|
||||
[$model->ahorro->id, $model->subsidio->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['pago', 'subsidio'], $new_data);
|
||||
}
|
||||
}
|
40
app/src/Repository/Venta/TipoEstadoVenta.php
Normal file
40
app/src/Repository/Venta/TipoEstadoVenta.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoEstadoVenta extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_estado_venta');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'activa' => [
|
||||
'function' => function($data) {
|
||||
return $data['activa'] !== 0;
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\TipoEstadoVenta(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion', 'activa'],
|
||||
[$model->descripcion, $model->activa ? 1 : 0]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'activa'], $new_data);
|
||||
}
|
||||
}
|
35
app/src/Repository/Venta/TipoValorCierre.php
Normal file
35
app/src/Repository/Venta/TipoValorCierre.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoValorCierre extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_valor_cierre');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => []
|
||||
];
|
||||
return $this->parseData(new Model\Venta\TipoValorCierre(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion'],
|
||||
[$model->descripcion]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion'], $new_data);
|
||||
}
|
||||
}
|
@ -43,6 +43,15 @@ class Unidad extends Ideal\Repository
|
||||
return $this->update($model, ['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByPropiedad(int $propiedad_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propiedad_unidad` pu ON pu.`unidad` = a.`id`
|
||||
WHERE pu.`propiedad` = ?
|
||||
GROUP BY a.`id`";
|
||||
return $this->fetchMany($query, [$propiedad_id]);
|
||||
}
|
||||
public function fetchByCierre(int $cierre_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
@ -51,6 +60,7 @@ FROM `{$this->getTable()}` a
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt`
|
||||
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`
|
||||
WHERE uc.`cierre` = ?
|
||||
GROUP BY a.`id`
|
||||
ORDER BY tu.`orden`, LPAD(a.`descripcion`, 4, '0')";
|
||||
return $this->fetchMany($query, [$cierre_id]);
|
||||
}
|
||||
|
55
app/src/Repository/Venta/ValorCierre.php
Normal file
55
app/src/Repository/Venta/ValorCierre.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class ValorCierre extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection,
|
||||
protected Repository\Venta\Cierre $cierreRepository,
|
||||
protected Repository\Venta\TipoValorCierre $tipoValorCierreRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('valor_cierre');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'cierre' => [
|
||||
'function' => function($data) {
|
||||
return $this->cierreRepository->fetchById($data['cierre']);
|
||||
}
|
||||
],
|
||||
'tipo' => [
|
||||
'property' => 'tipoValorCierre',
|
||||
'function' => function($data) {
|
||||
return $this->tipoValorCierreRepository->fetchById($data['tipo']);
|
||||
}
|
||||
],
|
||||
'valor' => []
|
||||
];
|
||||
return $this->parseData(new Model\Venta\ValorCierre(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['cierre', 'tipo', 'valor'],
|
||||
[$model->cierre->id, $model->tipoValorCierre->id, $model->valor]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['cierre', 'tipo', 'valor'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByCierre(int $cierre_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `cierre` = ?";
|
||||
return $this->fetchMany($query, [$cierre_id]);
|
||||
}
|
||||
}
|
13
app/src/Service/Proyecto.php
Normal file
13
app/src/Service/Proyecto.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Proyecto
|
||||
{
|
||||
public function __construct(protected Repository\Proyecto $proyectoRepository) {}
|
||||
public function getVendibles(): array
|
||||
{
|
||||
return $this->proyectoRepository->fetchAllActive();
|
||||
}
|
||||
}
|
22
app/src/Service/Venta.php
Normal file
22
app/src/Service/Venta.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Venta
|
||||
{
|
||||
public function __construct(
|
||||
protected Repository\Venta $ventaRepository,
|
||||
protected Repository\Venta\EstadoVenta $estadoVentaRepository
|
||||
) {}
|
||||
|
||||
public function getByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$ventas = $this->ventaRepository->fetchByProyecto($proyecto_id);
|
||||
foreach ($ventas as &$venta) {
|
||||
$venta->estados = $this->estadoVentaRepository->fetchByVenta($venta->id);
|
||||
$venta->currentEstado = $this->estadoVentaRepository->fetchCurrentByVenta($venta->id);
|
||||
}
|
||||
return $ventas;
|
||||
}
|
||||
}
|
@ -2,13 +2,17 @@
|
||||
namespace Incoviba\Service\Ventas;
|
||||
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Cierre
|
||||
{
|
||||
public function __construct(
|
||||
protected Repository\Venta\Cierre $cierreRepository,
|
||||
protected Repository\Venta\EstadoCierre $estadoCierreRepository,
|
||||
protected Repository\Venta\Unidad $unidadRepository) {}
|
||||
protected Repository\Venta\Unidad $unidadRepository,
|
||||
protected Repository\Venta\ValorCierre $valorCierreRepository,
|
||||
protected Repository\Venta\Precio $precioRepository
|
||||
) {}
|
||||
|
||||
public function getByProyecto(int $proyecto_id): array
|
||||
{
|
||||
@ -20,4 +24,16 @@ class Cierre
|
||||
}
|
||||
return $cierres;
|
||||
}
|
||||
public function getById(int $cierre_id): Model\Venta\Cierre
|
||||
{
|
||||
$cierre = $this->cierreRepository->fetchById($cierre_id);
|
||||
$cierre->estados = $this->estadoCierreRepository->fetchByCierre($cierre_id);
|
||||
$cierre->current = $this->estadoCierreRepository->fetchCurrentByCierre($cierre_id);
|
||||
$cierre->unidades = $this->unidadRepository->fetchByCierre($cierre_id);
|
||||
foreach ($cierre->unidades as &$unidad) {
|
||||
$unidad->currentPrecio = $this->precioRepository->fetchByUnidadAndDate($unidad->id, $cierre->dateTime->format('Y-m-d'));
|
||||
}
|
||||
$cierre->valoresCierre = $this->valorCierreRepository->fetchByCierre($cierre_id);
|
||||
return $cierre;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
namespace Incoviba\Service\Ventas;
|
||||
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Precio
|
||||
{
|
||||
@ -16,4 +17,11 @@ class Precio
|
||||
}
|
||||
return $precios;
|
||||
}
|
||||
public function getByUnidad(int $unidad_id): Model\Venta\Precio
|
||||
{
|
||||
$precio = $this->precioRepository->fetchByUnidad($unidad_id);
|
||||
$precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id);
|
||||
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
|
||||
return $precio;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user