Auth, Login, Home, Venta->Listados->Precios
This commit is contained in:
90
app/src/Controller/Base.php
Normal file
90
app/src/Controller/Base.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Base
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Login $service, Repository\Venta\Cuota $cuotaRepository, Repository\Venta\Cierre $cierreRepository): ResponseInterface
|
||||
{
|
||||
if ($service->isIn()) {
|
||||
return $this->home($response, $view, $cuotaRepository, $cierreRepository);
|
||||
}
|
||||
return $this->login($response, $view);
|
||||
}
|
||||
|
||||
protected function home(ResponseInterface $response, View $view, Repository\Venta\Cuota $cuotaRepository, Repository\Venta\Cierre $cierreRepository): ResponseInterface
|
||||
{
|
||||
$cuotas_hoy = count($cuotaRepository->fetchHoy()) ?? 0;
|
||||
$cuotas_pendientes = count($cuotaRepository->fetchPendientes()) ?? 0;
|
||||
$cuotas_por_vencer = $this->getCuotasPorVencer($cuotaRepository);
|
||||
$cierres_vigentes = $this->getCierresVigentes($cierreRepository);
|
||||
return $view->render($response, 'home', compact('cuotas_hoy', 'cuotas_pendientes', 'cuotas_por_vencer', 'cierres_vigentes'));
|
||||
}
|
||||
protected function login(ResponseInterface $response, View $view): ResponseInterface
|
||||
{
|
||||
return $view->render($response, 'guest');
|
||||
}
|
||||
protected function getCuotasPorVencer(Repository\Venta\Cuota $cuotaRepository): array
|
||||
{
|
||||
$cuotas = $cuotaRepository->fetchDatosPorVencer();
|
||||
$output = [];
|
||||
foreach ($cuotas as $row) {
|
||||
$fecha = $row['Fecha'];
|
||||
$date = new DateTimeImmutable($fecha);
|
||||
if (($weekday = $date->format('N')) > 5) {
|
||||
$day_diff = 7 - $weekday + 1;
|
||||
$date = $date->add(new DateInterval("P{$day_diff}D"));
|
||||
$fecha = $date->format('Y-m-d');
|
||||
}
|
||||
if (!isset($output[$fecha])) {
|
||||
$output[$fecha] = [];
|
||||
}
|
||||
if (!isset($output[$fecha][$row['Proyecto']])) {
|
||||
$output[$fecha][$row['Proyecto']] = 0;
|
||||
}
|
||||
$output[$fecha][$row['Proyecto']] += $row['Cantidad'];
|
||||
}
|
||||
foreach ($output as $fecha => $day) {
|
||||
uksort($day, function($a, $b) {
|
||||
return strcmp($a, $b);
|
||||
});
|
||||
$output[$fecha] = $day;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
protected function getCierresVigentes(Repository\Venta\Cierre $cierreRepository): array
|
||||
{
|
||||
$cierres = $cierreRepository->fetchDatosVigentes();
|
||||
$output = [];
|
||||
$estados = [
|
||||
'revisado' => 'pendientes',
|
||||
'rechazado' => 'rechazados',
|
||||
'aprobado' => 'pendientes',
|
||||
'vendido' => 'promesados',
|
||||
'abandonado' => 'rechazados',
|
||||
'promesado' => 'promesados',
|
||||
'resciliado' => 'rechazados'
|
||||
];
|
||||
foreach ($cierres as $row) {
|
||||
if (!isset($output[$row['Proyecto']])) {
|
||||
$output[$row['Proyecto']] = [
|
||||
'promesados' => 0,
|
||||
'pendientes' => 0,
|
||||
'rechazados' => 0,
|
||||
'total' => 0
|
||||
];
|
||||
}
|
||||
$estado = $estados[$row['Estado']];
|
||||
$output[$row['Proyecto']][$estado] += $row['Cantidad'];
|
||||
$output[$row['Proyecto']]['total'] += $row['Cantidad'];
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
55
app/src/Controller/Login.php
Normal file
55
app/src/Controller/Login.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use PDOException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Login
|
||||
{
|
||||
public function form(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Login $service): ResponseInterface
|
||||
{
|
||||
$redirect_uri = $request->hasHeader('Referer') ? $request->getHeaderLine('Referer') : $view->get('urls')->base;
|
||||
if ($service->isIn()) {
|
||||
$redirect_uri = str_replace('/login', '', $redirect_uri);
|
||||
return $response->withStatus(301)->withHeader('Location', $redirect_uri);
|
||||
}
|
||||
if ($request->hasHeader('X-Redirect-URI')) {
|
||||
$redirect_uri = $request->getHeaderLine('X-Redirect-URI');
|
||||
}
|
||||
return $view->render($response, 'login.form', compact('redirect_uri'));
|
||||
}
|
||||
public function login(ServerRequestInterface $request, ResponseInterface $response, Repository\User $userRepository, Service\Login $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$user = $userRepository->fetchByName($body['name']);
|
||||
$output = [
|
||||
'name' => $user->name,
|
||||
'login' => false
|
||||
];
|
||||
if ($user->validate($body['password'])) {
|
||||
$output['login'] = $service->login($user);
|
||||
}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function logout(ServerRequestInterface $request, ResponseInterface $response, Repository\Login $loginRepository, Service\Login $service): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'name' => '',
|
||||
'logout' => false
|
||||
];
|
||||
try {
|
||||
$user = $service->getUser();
|
||||
$output = [
|
||||
'name' => $user->name,
|
||||
'logout' => $service->logout($user)
|
||||
];
|
||||
} catch (PDOException) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
21
app/src/Controller/Proyectos.php
Normal file
21
app/src/Controller/Proyectos.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Proyectos
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view): ResponseInterface
|
||||
{
|
||||
return $view->render($response, 'proyectos.list');
|
||||
}
|
||||
public function list(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$proyectos = $proyectoRepository->fetchAllActive();
|
||||
$response->getBody()->write(json_encode(['proyectos' => $proyectos, 'total' => count($proyectos)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
11
app/src/Controller/Users.php
Normal file
11
app/src/Controller/Users.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Users
|
||||
{
|
||||
}
|
60
app/src/Controller/Ventas/Cuotas.php
Normal file
60
app/src/Controller/Ventas/Cuotas.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use IntlDateFormatter;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Cuotas
|
||||
{
|
||||
public function pendientes(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Venta\Cuota $cuotaRepository): ResponseInterface
|
||||
{
|
||||
$cuotas = $cuotaRepository->fetchPendientes();
|
||||
$cuotas_pendientes = [];
|
||||
$today = new DateTimeImmutable();
|
||||
$formatter = new IntlDateFormatter('es_ES');
|
||||
$formatter->setPattern('EEEE dd');
|
||||
foreach ($cuotas as $cuota) {
|
||||
$date = new DateTimeImmutable($cuota['fecha']);
|
||||
$day = clone $date;
|
||||
$weekday = $date->format('N');
|
||||
if ($weekday > 5) {
|
||||
$diff = 7 - $weekday + 1;
|
||||
$day = $day->add(new DateInterval("P{$diff}D"));
|
||||
}
|
||||
$cuotas_pendientes []= [
|
||||
'id' => $cuota['cuota_id'],
|
||||
'venta_id' => $cuota['venta_id'],
|
||||
'Proyecto' => $cuota['Proyecto'],
|
||||
'Departamento' => $cuota['Departamento'],
|
||||
'Valor' => $cuota['Valor'],
|
||||
'Dia' => $formatter->format($day),
|
||||
'Numero' => $cuota['Numero'],
|
||||
'Propietario' => $cuota['Propietario'],
|
||||
'Banco' => $cuota['Banco'],
|
||||
'Fecha Cheque' => $date->format('d-m-Y'),
|
||||
'Vencida' => $today->diff($date)->days,
|
||||
'Fecha ISO' => $date->format('Y-m-d')
|
||||
];
|
||||
}
|
||||
return $view->render($response, 'ventas.cuotas.pendientes', compact('cuotas_pendientes'));
|
||||
}
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Ventas\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$cuota_id = $json->cuota_id;
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output = [
|
||||
'cuota_id' => $cuota_id,
|
||||
'depositada' => $pagoService->depositar($cuota->pago)
|
||||
];
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
24
app/src/Controller/Ventas/Precios.php
Normal file
24
app/src/Controller/Ventas/Precios.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Precios
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view): ResponseInterface
|
||||
{
|
||||
return $view->render($response, 'ventas.precios.list');
|
||||
}
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Ventas\Precio $precioService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$precios = $precioService->getByProyecto($proyecto_id);
|
||||
$response->getBody()->write(json_encode(['precios' => $precios, 'total' => count($precios)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
48
app/src/Middleware/Authentication.php
Normal file
48
app/src/Middleware/Authentication.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?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 Incoviba\Service;
|
||||
|
||||
class Authentication
|
||||
{
|
||||
public function __construct(protected ResponseFactoryInterface $responseFactory, protected Service\Login $service, protected string $login_url) {}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
if ($this->service->isIn() or $this->isValid($request)) {
|
||||
return $handler->handle($request);
|
||||
}
|
||||
$response = $this->responseFactory->createResponse(301, 'Not logged in');
|
||||
return $response->withHeader('Location', $this->login_url)
|
||||
->withHeader('X-Redirected-URI', (string) $request->getUri());
|
||||
}
|
||||
|
||||
protected function isValid(ServerRequestInterface $request): bool
|
||||
{
|
||||
$uri = $request->getUri();
|
||||
$current_path = $uri->getPath();
|
||||
$current_url = implode('', [
|
||||
"{$uri->getScheme()}://",
|
||||
$uri->getHost() . ($uri->getPort() !== null ? ":{$uri->getPort()}" : ''),
|
||||
$uri->getPath()
|
||||
]);
|
||||
|
||||
$valid_paths = [
|
||||
'/',
|
||||
];
|
||||
if (in_array($current_path, $valid_paths, true)) {
|
||||
return true;
|
||||
}
|
||||
$valid_uris = [
|
||||
$this->login_url,
|
||||
];
|
||||
if (in_array($current_url, $valid_uris, true)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
16
app/src/Model/Banco.php
Normal file
16
app/src/Model/Banco.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class Banco extends Model
|
||||
{
|
||||
public ?string $nombre;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'nombre' => $this->nombre ?? ''
|
||||
]);
|
||||
}
|
||||
}
|
18
app/src/Model/Comuna.php
Normal file
18
app/src/Model/Comuna.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class Comuna extends Model
|
||||
{
|
||||
public string $descripcion;
|
||||
public Provincia $provincia;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'descripcion' => $this->descripcion,
|
||||
'provincia' => $this->provincia
|
||||
]);
|
||||
}
|
||||
}
|
22
app/src/Model/Direccion.php
Normal file
22
app/src/Model/Direccion.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class Direccion extends Model
|
||||
{
|
||||
public string $calle;
|
||||
public int $numero;
|
||||
public string $extra;
|
||||
public Comuna $comuna;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'calle' => $this->calle,
|
||||
'numero' => $this->numero,
|
||||
'extra' => $this->extra,
|
||||
'comuna' => $this->comuna
|
||||
]);
|
||||
}
|
||||
}
|
38
app/src/Model/Inmobiliaria.php
Normal file
38
app/src/Model/Inmobiliaria.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
use Incoviba\Model\Inmobiliaria\TipoSociedad;
|
||||
|
||||
class Inmobiliaria extends Model
|
||||
{
|
||||
public int $rut;
|
||||
public ?string $dv;
|
||||
public ?string $razon;
|
||||
public ?string $abreviacion;
|
||||
public ?string $cuenta;
|
||||
public ?Banco $banco;
|
||||
public ?TipoSociedad $tipoSociedad;
|
||||
|
||||
public function rut(): string
|
||||
{
|
||||
return implode('-', [
|
||||
number_format($this->rut, 0, ',', '.'),
|
||||
$this->dv
|
||||
]);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'rut' => $this->rut,
|
||||
'dv' => $this->dv ?? '',
|
||||
'rut_formateado' => $this->rut(),
|
||||
'razon' => $this->razon ?? '',
|
||||
'abreviacion' => $this->abreviacion ?? '',
|
||||
'cuenta' => $this->cuenta ?? '',
|
||||
'banco' => $this->banco ?? '',
|
||||
'tipo_sociedad' => $this->tipoSociedad ?? ''
|
||||
];
|
||||
}
|
||||
}
|
16
app/src/Model/Inmobiliaria/TipoSociedad.php
Normal file
16
app/src/Model/Inmobiliaria/TipoSociedad.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Inmobiliaria;
|
||||
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoSociedad extends Model\Tipo
|
||||
{
|
||||
public string $abreviacion;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'abreviacion' => $this->abreviacion
|
||||
]);
|
||||
}
|
||||
}
|
25
app/src/Model/Login.php
Normal file
25
app/src/Model/Login.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Login extends Ideal\Model
|
||||
{
|
||||
public User $user;
|
||||
public string $selector;
|
||||
public string $token;
|
||||
public DateTimeInterface $dateTime;
|
||||
public bool $status;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'user_id' => $this->user->id,
|
||||
'selector' => $this->selector,
|
||||
'token' => $this->token,
|
||||
'date_time' => $this->dateTime->format('Y-m-d H:i:s'),
|
||||
'status' => $this->status
|
||||
]);
|
||||
}
|
||||
}
|
18
app/src/Model/Provincia.php
Normal file
18
app/src/Model/Provincia.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class Provincia extends Model
|
||||
{
|
||||
public string $descripcion;
|
||||
public Region $region;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'descripcion' => $this->descripcion,
|
||||
'region' => $this->region
|
||||
]);
|
||||
}
|
||||
}
|
32
app/src/Model/Proyecto.php
Normal file
32
app/src/Model/Proyecto.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
use Incoviba\Model\Proyecto\Superficie;
|
||||
use Incoviba\Model\Proyecto\Terreno;
|
||||
|
||||
class Proyecto extends Model
|
||||
{
|
||||
public Inmobiliaria $inmobiliaria;
|
||||
public string $descripcion;
|
||||
public Direccion $direccion;
|
||||
public Terreno $terreno;
|
||||
public Superficie $superficie;
|
||||
public float $corredor;
|
||||
public int $pisos;
|
||||
public int $subterraneos;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'inmobiliaria' => $this->inmobiliaria,
|
||||
'descripcion' => $this->descripcion,
|
||||
'direccion' => $this->direccion,
|
||||
'terreno' => $this->terreno,
|
||||
'superficie' => $this->superficie,
|
||||
'corredor' => $this->corredor,
|
||||
'pisos' => $this->pisos,
|
||||
'subterraneos' => $this->subterraneos
|
||||
]);
|
||||
}
|
||||
}
|
42
app/src/Model/Proyecto/ProyectoTipoUnidad.php
Normal file
42
app/src/Model/Proyecto/ProyectoTipoUnidad.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class ProyectoTipoUnidad extends Ideal\Model
|
||||
{
|
||||
public Model\Proyecto $proyecto;
|
||||
public Model\Venta\TipoUnidad $tipoUnidad;
|
||||
public string $nombre;
|
||||
public string $abreviacion;
|
||||
public float $util;
|
||||
public float $logia;
|
||||
public float $terraza;
|
||||
public string $descripcion;
|
||||
|
||||
public function superficie(): float
|
||||
{
|
||||
return array_reduce([$this->util, $this->logia, $this->terraza], function($sum, $item) {return $sum + $item;}, 0);
|
||||
}
|
||||
public function vendible(): float
|
||||
{
|
||||
return array_reduce([$this->util, $this->logia, $this->terraza / 2], function($sum, $item) {return $sum + $item;}, 0);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'proyecto' => $this->proyecto,
|
||||
'tipo_unidad' => $this->tipoUnidad,
|
||||
'nombre' => $this->nombre,
|
||||
'abreviacion' => $this->abreviacion,
|
||||
'util' => $this->util,
|
||||
'logia' => $this->logia,
|
||||
'terraza' => $this->terraza,
|
||||
'superficie' => $this->superficie(),
|
||||
'vendible' => $this->vendible(),
|
||||
'descripcion' => $this->descripcion
|
||||
]);
|
||||
}
|
||||
}
|
8
app/src/Model/Proyecto/Superficie.php
Normal file
8
app/src/Model/Proyecto/Superficie.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
class Superficie
|
||||
{
|
||||
public float $sobre_nivel;
|
||||
public float $bajo_nivel;
|
||||
}
|
8
app/src/Model/Proyecto/Terreno.php
Normal file
8
app/src/Model/Proyecto/Terreno.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
class Terreno
|
||||
{
|
||||
public float $superficie;
|
||||
public float $valor;
|
||||
}
|
20
app/src/Model/Region.php
Normal file
20
app/src/Model/Region.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class Region extends Model
|
||||
{
|
||||
public string $descripcion;
|
||||
public string $numeral;
|
||||
public ?int $numeracion;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'descripcion' => $this->descripcion,
|
||||
'numeral' => $this->numeral,
|
||||
'numeracion' => $this->numeracion ?? 0
|
||||
]);
|
||||
}
|
||||
}
|
7
app/src/Model/Role.php
Normal file
7
app/src/Model/Role.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class Role extends Model
|
||||
{}
|
16
app/src/Model/Tipo.php
Normal file
16
app/src/Model/Tipo.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
abstract class Tipo extends Ideal\Model
|
||||
{
|
||||
public string $descripcion;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'descripcion' => $this->descripcion
|
||||
]);
|
||||
}
|
||||
}
|
28
app/src/Model/User.php
Normal file
28
app/src/Model/User.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use function password_verify;
|
||||
|
||||
class User extends Ideal\Model
|
||||
{
|
||||
public string $name;
|
||||
public string $password;
|
||||
public bool $enabled;
|
||||
|
||||
public function validate(string $provided_password): bool
|
||||
{
|
||||
return password_verify($provided_password, $this->password);
|
||||
}
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'name' => $this->name
|
||||
]);
|
||||
}
|
||||
}
|
26
app/src/Model/Venta/Cierre.php
Normal file
26
app/src/Model/Venta/Cierre.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Cierre extends Ideal\Model
|
||||
{
|
||||
public Model\Proyecto $proyecto;
|
||||
public float $precio;
|
||||
public DateTimeInterface $dateTime;
|
||||
public bool $relacionado;
|
||||
public Propietario $propietario;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'proyecto_id' => $this->proyecto->id,
|
||||
'precio' => $this->precio,
|
||||
'date_time' => $this->dateTime->format('Y-m-d H:i:s'),
|
||||
'relacionado' => $this->relacionado,
|
||||
'propietario' => $this->propietario->rut
|
||||
]);
|
||||
}
|
||||
}
|
38
app/src/Model/Venta/Cuota.php
Normal file
38
app/src/Model/Venta/Cuota.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
use Incoviba\Model\Banco;
|
||||
|
||||
class Cuota extends Model
|
||||
{
|
||||
public Pie $pie;
|
||||
public DateTimeInterface $fecha;
|
||||
public float $valor;
|
||||
public ?bool $estado;
|
||||
public ?Banco $banco;
|
||||
public ?DateTimeInterface $fechaPago;
|
||||
public ?bool $abonado;
|
||||
public ?DateTimeInterface $fechaAbonado;
|
||||
public ?float $uf;
|
||||
public ?Pago $pago;
|
||||
public ?int $numero;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'pie_id' => $this->pie->id,
|
||||
'fecha' => $this->fecha->format('Y-m-d H:i:s'),
|
||||
'valor' => $this->valor,
|
||||
'estado' => $this->estado ?? false,
|
||||
'banco' => $this->banco,
|
||||
'fecha_pago' => $this->fechaPago->format('Y-m-d H:i:s') ?? '',
|
||||
'abonado' => $this->abonado ?? false,
|
||||
'fecha_abonado' => $this->fechaAbonado->format('Y-m-d H:i:s') ?? '',
|
||||
'uf' => $this->uf ?? 1,
|
||||
'pago' => $this->pago ?? '',
|
||||
'numero' => $this->numero ?? ''
|
||||
]);
|
||||
}
|
||||
}
|
27
app/src/Model/Venta/Datos.php
Normal file
27
app/src/Model/Venta/Datos.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use JsonSerializable;
|
||||
use Incoviba\Model\Direccion;
|
||||
|
||||
class Datos
|
||||
{
|
||||
public ?string $sexo;
|
||||
public ?string $estado_civil;
|
||||
public ?string $profesion;
|
||||
public ?Direccion $direccion;
|
||||
public ?int $telefono;
|
||||
public ?string $email;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'sexo' => $this->sexo ?? '',
|
||||
'estado_civil' => $this->estado_civil ?? '',
|
||||
'profesion' => $this->profesion ?? '',
|
||||
'direccion' => $this->direccion ?? '',
|
||||
'telefono' => $this->telefono ?? '',
|
||||
'email' => $this->email ?? ''
|
||||
];
|
||||
}
|
||||
}
|
22
app/src/Model/Venta/EstadoPago.php
Normal file
22
app/src/Model/Venta/EstadoPago.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class EstadoPago extends Model
|
||||
{
|
||||
public Pago $pago;
|
||||
public DateTimeInterface $fecha;
|
||||
public TipoEstadoPago $tipoEstadoPago;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'pago_id' => $this->pago->id,
|
||||
'fecha' => $this->fecha->format('Y-m-d'),
|
||||
'tipo_estado_pago_id' => $this->tipoEstadoPago->id
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
21
app/src/Model/Venta/EstadoPrecio.php
Normal file
21
app/src/Model/Venta/EstadoPrecio.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class EstadoPrecio extends Ideal\Model
|
||||
{
|
||||
public Precio $precio;
|
||||
public TipoEstadoPrecio $tipoEstadoPrecio;
|
||||
public DateTimeInterface $fecha;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'precio_id' => $this->precio->id,
|
||||
'tipo_estado_precio' => $this->tipoEstadoPrecio,
|
||||
'fecha' => $this->fecha->format('Y-m-d')
|
||||
]);
|
||||
}
|
||||
}
|
32
app/src/Model/Venta/Pago.php
Normal file
32
app/src/Model/Venta/Pago.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
use Incoviba\Model\Banco;
|
||||
|
||||
class Pago extends Model
|
||||
{
|
||||
public float $valor;
|
||||
public ?Banco $banco;
|
||||
public ?TipoPago $tipoPago;
|
||||
public ?string $identificador;
|
||||
public ?DateTimeInterface $fecha;
|
||||
public ?float $uf;
|
||||
public ?string $pagador;
|
||||
public ?Pago $asociado;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'valor' => $this->valor,
|
||||
'banco' => $this->banco ?? '',
|
||||
'tipo_pago' => $this->tipoPago ?? '',
|
||||
'identificador' => $this->identificador ?? '',
|
||||
'fecha' => $this->fecha->format('Y-m-d H:i:S') ?? '',
|
||||
'uf' => $this->uf ?? 1,
|
||||
'pagador' => $this->pagador ?? '',
|
||||
'asociado' => $this->asociado ?? ''
|
||||
]);
|
||||
}
|
||||
}
|
27
app/src/Model/Venta/Pie.php
Normal file
27
app/src/Model/Venta/Pie.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class Pie extends Model
|
||||
{
|
||||
public DateTimeInterface $fecha;
|
||||
public float $valor;
|
||||
public ?float $uf;
|
||||
public int $cuotas;
|
||||
public ?Pie $asociado;
|
||||
public ?Pago $reajuste;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'fecha' => $this->fecha->format('Y-m-d H:i:s'),
|
||||
'valor' => $this->valor,
|
||||
'uf' => $this->uf ?? 1,
|
||||
'cuotas' => $this->cuotas,
|
||||
'asociado' => $this->asociado ?? '',
|
||||
'reajuste' => $this->reajuste ?? ''
|
||||
]);
|
||||
}
|
||||
}
|
23
app/src/Model/Venta/Precio.php
Normal file
23
app/src/Model/Venta/Precio.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Precio extends Ideal\Model
|
||||
{
|
||||
public Unidad $unidad;
|
||||
public float $valor;
|
||||
|
||||
public array $estados;
|
||||
public EstadoPrecio $current;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'unidad' => $this->unidad,
|
||||
'valor' => $this->valor,
|
||||
'estado_precio' => $this->current ?? [],
|
||||
'estados' => $this->estados ?? null
|
||||
]);
|
||||
}
|
||||
}
|
46
app/src/Model/Venta/Propietario.php
Normal file
46
app/src/Model/Venta/Propietario.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
use Incoviba\Model\Direccion;
|
||||
|
||||
class Propietario extends Model
|
||||
{
|
||||
public int $rut;
|
||||
public string $dv;
|
||||
public string $nombres;
|
||||
public array $apellidos;
|
||||
public Datos $datos;
|
||||
public ?Propietario $representante;
|
||||
public ?bool $otro;
|
||||
|
||||
public function rut(): string
|
||||
{
|
||||
return implode('-', [
|
||||
number_format($this->rut, 0, ',', '.'),
|
||||
$this->dv
|
||||
]);
|
||||
}
|
||||
public function nombreCompleto(): string
|
||||
{
|
||||
return implode(' ', [
|
||||
$this->nombres,
|
||||
implode(' ', $this->apellidos)
|
||||
]);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge([
|
||||
'rut' => $this->rut,
|
||||
'dv' => $this->dv,
|
||||
'rut_formateado' => $this->rut(),
|
||||
'nombres' => $this->nombres,
|
||||
'apellidos' => $this->apellidos,
|
||||
'nombre_completo' => $this->nombreCompleto(),
|
||||
], $this->datos->jsonSerialize(), [
|
||||
'representante' => $this->representante ?? '',
|
||||
'otro' => $this->otro ?? ''
|
||||
]);
|
||||
}
|
||||
}
|
8
app/src/Model/Venta/TipoEstadoPago.php
Normal file
8
app/src/Model/Venta/TipoEstadoPago.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoEstadoPago extends Model\Tipo
|
||||
{
|
||||
}
|
7
app/src/Model/Venta/TipoEstadoPrecio.php
Normal file
7
app/src/Model/Venta/TipoEstadoPrecio.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Model\Tipo;
|
||||
|
||||
class TipoEstadoPrecio extends Tipo
|
||||
{}
|
8
app/src/Model/Venta/TipoPago.php
Normal file
8
app/src/Model/Venta/TipoPago.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoPago extends Model\Tipo
|
||||
{
|
||||
}
|
16
app/src/Model/Venta/TipoUnidad.php
Normal file
16
app/src/Model/Venta/TipoUnidad.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoUnidad extends Model\Tipo
|
||||
{
|
||||
public int $orden;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'orden' => $this->orden
|
||||
]);
|
||||
}
|
||||
}
|
25
app/src/Model/Venta/Unidad.php
Normal file
25
app/src/Model/Venta/Unidad.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Unidad extends Ideal\Model
|
||||
{
|
||||
public ?string $subtipo = '';
|
||||
public int $piso;
|
||||
public string $descripcion;
|
||||
public ?string $orientacion = '';
|
||||
public Model\Proyecto\ProyectoTipoUnidad $proyectoTipoUnidad;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'subtipo' => $this->subtipo,
|
||||
'piso' => $this->piso,
|
||||
'descripcion' => $this->descripcion,
|
||||
'orientacion' => $this->orientacion,
|
||||
'proyecto_tipo_unidad' => $this->proyectoTipoUnidad
|
||||
]);
|
||||
}
|
||||
}
|
35
app/src/Repository/Banco.php
Normal file
35
app/src/Repository/Banco.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Banco extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('banco');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'nombre' => []
|
||||
];
|
||||
return $this->parseData(new Model\Banco(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['nombre'],
|
||||
[$model->nombre]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['nombre'], $new_data);
|
||||
}
|
||||
}
|
51
app/src/Repository/Comuna.php
Normal file
51
app/src/Repository/Comuna.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Comuna extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Provincia $provinciaRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('comuna');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'provincia' => [
|
||||
'function' => function($data) {
|
||||
return $this->provinciaRepository->fetchById($data['provincia']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Comuna(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion', 'provincia'],
|
||||
[$model->descripcion, $model->provincia->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'provincia'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByDescripcion(string $descripcion): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `descripcion` = ?";
|
||||
return $this->fetchOne($query, [$descripcion]);
|
||||
}
|
||||
public function fetchByProvincia(int $provincia_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `provincia` = ?";
|
||||
return $this->fetchMany($query, [$provincia_id]);
|
||||
}
|
||||
}
|
48
app/src/Repository/Direccion.php
Normal file
48
app/src/Repository/Direccion.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Direccion extends Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Comuna $comunaRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('direccion');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'calle' => [],
|
||||
'numero' => [],
|
||||
'extra' => [],
|
||||
'comuna' => [
|
||||
'function' => function($data) {
|
||||
return $this->comunaRepository->fetchById($data['comuna']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Direccion(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['calle', 'numero', 'extra', 'comuna'],
|
||||
[$model->calle, $model->numero, $model->extra, $model->comuna->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['calle', 'numero', 'extra', 'comuna'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByCalleAndNumero(string $calle, int $numero): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `calle` = ? AND `numero` = ?";
|
||||
return $this->fetchMany($query, [$calle, $numero]);
|
||||
}
|
||||
}
|
55
app/src/Repository/Inmobiliaria.php
Normal file
55
app/src/Repository/Inmobiliaria.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Inmobiliaria extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Banco $bancoRepository, protected Repository\Inmobiliaria\TipoSociedad $tipoSociedadRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('inmobiliaria');
|
||||
}
|
||||
|
||||
protected function getKey(): string
|
||||
{
|
||||
return 'rut';
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'dv' => [],
|
||||
'razon' => [],
|
||||
'abreviacion' => [],
|
||||
'cuenta' => [],
|
||||
'banco' => [
|
||||
'function' => function($data) {
|
||||
return $this->bancoRepository->fetchById($data['banco']);
|
||||
}
|
||||
],
|
||||
'sociedad' => [
|
||||
'property' => 'tipoSociedad',
|
||||
'function' => function($data) {
|
||||
return $this->tipoSociedadRepository->fetchById($data['sociedad']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Inmobiliaria(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->rut = $this->saveNew(
|
||||
['dv', 'razon', 'abreviacion', 'cuenta', 'banco', 'sociedad'],
|
||||
[$model->dv, $model->razon, $model->abreviacion, $model->cuenta, $model->banco->id, $model->tipoSociedad->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['dv', 'razon', 'abreviacion', 'cuenta', 'banco', 'sociedad'], $new_data);
|
||||
}
|
||||
}
|
36
app/src/Repository/Inmobiliaria/TipoSociedad.php
Normal file
36
app/src/Repository/Inmobiliaria/TipoSociedad.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoSociedad extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_sociedad');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'abreviacion' => []
|
||||
];
|
||||
return $this->parseData(new Model\Inmobiliaria\TipoSociedad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion', 'abreviacion'],
|
||||
[$model->descripcion, $model->abreviacion]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'abreviacion'], $new_data);
|
||||
}
|
||||
}
|
77
app/src/Repository/Login.php
Normal file
77
app/src/Repository/Login.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Login extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected User $userRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('logins');
|
||||
}
|
||||
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'user_id' => [
|
||||
'property' => 'user',
|
||||
'function' => function($data) {
|
||||
return $this->userRepository->fetchById($data['user_id']);
|
||||
}
|
||||
],
|
||||
'selector' => [],
|
||||
'token' => [],
|
||||
'time' => [
|
||||
'property' => 'dateTime',
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['time']);
|
||||
}
|
||||
],
|
||||
'status' => [
|
||||
'function' => function($data) {
|
||||
return $data['status'] != 0;
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Login(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['user_id', 'selector', 'token', 'time', 'status'],
|
||||
[$model->user->id, $model->selector, $model->token, $model->dateTime->format('Y-m-d H:i:s'), $model->status ? 1 : 0]);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['user_id', 'selector', 'token', 'time', 'status'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByUser(int $user_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `user_id` = ?";
|
||||
return $this->fetchMany($query, [$user_id]);
|
||||
}
|
||||
public function fetchActiveByUser(int $user_id): Model\Login
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `user_id` = ? AND `status` = 1";
|
||||
return $this->fetchOne($query, [$user_id]);
|
||||
}
|
||||
public function fetchBySelectorAndToken(string $selector, string $token): Model\Login
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `selector` = ? AND `token` = ?";
|
||||
return $this->fetchOne($query, [$selector, $token]);
|
||||
}
|
||||
public function fetchActiveBySelector(string $selector): Model\Login
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `selector` = ? AND `status` = 1";
|
||||
return $this->fetchOne($query, [$selector]);
|
||||
}
|
||||
}
|
51
app/src/Repository/Provincia.php
Normal file
51
app/src/Repository/Provincia.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Provincia extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Region $regionRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('provincia');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'region' => [
|
||||
'function' => function($data) {
|
||||
return $this->regionRepository->fetchById($data['region']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Provincia(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion', 'region'],
|
||||
[$model->descripcion, $model->region->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'region'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByDescripcion(string $description): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `descripcion` = ?";
|
||||
return $this->fetchOne($query, [$description]);
|
||||
}
|
||||
public function fetchByRegion(int $region_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `region` = ?";
|
||||
return $this->fetchMany($query, [$region_id]);
|
||||
}
|
||||
}
|
88
app/src/Repository/Proyecto.php
Normal file
88
app/src/Repository/Proyecto.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Proyecto extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Inmobiliaria $inmobiliariaRepository, protected Direccion $direccionRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('proyecto');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'inmobiliaria' => [
|
||||
'function' => function($data) {
|
||||
return $this->inmobiliariaRepository->fetchById($data['inmobiliaria']);
|
||||
}
|
||||
],
|
||||
'descripcion' => [],
|
||||
'direccion' => [
|
||||
'function' => function($data) {
|
||||
return $this->direccionRepository->fetchById($data['direccion']);
|
||||
}
|
||||
],
|
||||
'superficie_terreno' => [
|
||||
'property' => 'terreno',
|
||||
'function' => function($data) {
|
||||
$terreno = new Model\Proyecto\Terreno();
|
||||
$terreno->superficie = $data['superficie_terreno'];
|
||||
$terreno->valor = $data['valor_terreno'];
|
||||
return $terreno;
|
||||
}
|
||||
],
|
||||
'superficie_sobre_nivel' => [
|
||||
'property' => 'superficie',
|
||||
'function' => function($data) {
|
||||
$superficie = new Model\Proyecto\Superficie();
|
||||
$superficie->sobre_nivel = $data['superficie_sobre_nivel'];
|
||||
$superficie->bajo_nivel = $data['superficie_bajo_nivel'];
|
||||
return $superficie;
|
||||
}
|
||||
],
|
||||
'corredor' => [],
|
||||
'pisos' => [],
|
||||
'subterraneos' => []
|
||||
];
|
||||
return $this->parseData(new Model\Proyecto(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['inmobiliaria', 'descripcion', 'direccion', 'superficie_terreno', 'valor_terreno', 'corredor',
|
||||
'superficie_sobre_nivel', 'superficie_bajo_nivel', 'pisos', 'subterraneos'],
|
||||
[$model->inmobiliaria->rut, $model->descripcion, $model->direccion->id, $model->terreno->superficie,
|
||||
$model->terreno->valor, $model->corredor, $model->superficie->sobre_nivel,
|
||||
$model->superficie->bajo_nivel, $model->pisos, $model->subterraneos]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['inmobiliaria', 'descripcion', 'direccion', 'superficie_terreno',
|
||||
'valor_terreno', 'corredor', 'superficie_sobre_nivel', 'superficie_bajo_nivel', 'pisos',
|
||||
'subterraneos'], $new_data);
|
||||
}
|
||||
public function fetchByName(string $name): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `name` = ?";
|
||||
return $this->fetchOne($query, [$name]);
|
||||
}
|
||||
public function fetchAllActive(): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT e1.* FROM `estado_proyecto` e1 JOIN (SELECT MAX(`id`) AS 'id', `proyecto` FROM `estado_proyecto` GROUP BY `proyecto`) e0 ON e0.`id` = e1.`id`) ep ON ep.`proyecto` = a.`id`
|
||||
JOIN `tipo_estado_proyecto` tep ON tep.`id` = ep.`estado`
|
||||
JOIN `etapa_proyecto` et ON et.`id` = tep.`etapa`
|
||||
WHERE et.`orden` BETWEEN 4 AND 8
|
||||
ORDER BY a.`descripcion`";
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
}
|
54
app/src/Repository/Proyecto/ProyectoTipoUnidad.php
Normal file
54
app/src/Repository/Proyecto/ProyectoTipoUnidad.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class ProyectoTipoUnidad extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Proyecto $proyectoRepository, protected Repository\Venta\TipoUnidad $tipoUnidadRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('proyecto_tipo_unidad');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'proyecto' => [
|
||||
'function' => function($data) {
|
||||
return $this->proyectoRepository->fetchById($data['proyecto']);
|
||||
}
|
||||
],
|
||||
'tipo' => [
|
||||
'property' => 'tipoUnidad',
|
||||
'function' => function($data) {
|
||||
return $this->tipoUnidadRepository->fetchById($data['tipo']);
|
||||
}
|
||||
],
|
||||
'nombre' => [],
|
||||
'abreviacion' => [],
|
||||
'm2' => [
|
||||
'property' => 'util'
|
||||
],
|
||||
'logia' => [],
|
||||
'terraza' => [],
|
||||
'descripcion' => []
|
||||
];
|
||||
return $this->parseData(new Model\Proyecto\ProyectoTipoUnidad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['proyecto', 'tipo', 'nombre', 'abreviacion', 'm2', 'logia', 'terraza', 'descripcion'],
|
||||
[$model->proyecto->id, $model->tipoUnidad->id, $model->nombre, $model->abreviacion, $model->util, $model->logia, $model->terraza, $model->descripcion]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['proyecto', 'tipo', 'nombre', 'abreviacion', 'util', 'logia', 'terraza', 'descripcion'], $new_data);
|
||||
}
|
||||
}
|
53
app/src/Repository/Region.php
Normal file
53
app/src/Repository/Region.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Region extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('region');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'numeral' => [],
|
||||
'numeracion' => []
|
||||
];
|
||||
return $this->parseData(new Model\Region(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion', 'numeral', 'numeracion'],
|
||||
[$model->descripcion, $model->numeral, $model->numeracion]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'numeral', 'numeracion'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByDescripcion(string $descripcion): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `descripcion` = ?";
|
||||
return $this->fetchOne($query, [$descripcion]);
|
||||
}
|
||||
public function fetchByNumeral(string $numeral): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `numeral` = ?";
|
||||
return $this->fetchOne($query, [$numeral]);
|
||||
}
|
||||
public function fetchByNumeracion(int $numeracion): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `numeracion` = ?";
|
||||
return $this->fetchOne($query, [$numeracion]);
|
||||
}
|
||||
}
|
46
app/src/Repository/User.php
Normal file
46
app/src/Repository/User.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class User extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('users');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'name' => [],
|
||||
'password' => [],
|
||||
'enabled' => [
|
||||
'function' => function($data) {
|
||||
return $data['enabled'] != 0;
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\User(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(['name', 'password', 'enabled'], [$model->name, $model->password, $model->enabled ? 1 : 0]);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['name', 'password', 'enabled'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByName(string $name): Model\User
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `name` = ?";
|
||||
return $this->fetchOne($query, [$name]);
|
||||
}
|
||||
}
|
82
app/src/Repository/Venta/Cierre.php
Normal file
82
app/src/Repository/Venta/Cierre.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use PDO;
|
||||
|
||||
class Cierre extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection,
|
||||
protected Repository\Proyecto $proyectoRepository,
|
||||
protected Repository\Venta\Propietario $propietarioRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('cierre');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'proyecto' => [
|
||||
'function' => function($data) {
|
||||
return $this->proyectoRepository->fetchById($data['proyecto']);
|
||||
}
|
||||
],
|
||||
'precio' => [],
|
||||
'fecha' => [
|
||||
'property' => 'dateTime',
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
],
|
||||
'relacionado' => [
|
||||
'function' => function($data) {
|
||||
return $data['relacionado'] !== 0;
|
||||
}
|
||||
],
|
||||
'propietario' => [
|
||||
'function' => function($data) {
|
||||
return $this->propietarioRepository->fetchById($data['propietario']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Cierre(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['proyecto', 'precio', 'fecha', 'relacionado', 'propietario'],
|
||||
[$model->proyecto->id, $model->precio, $model->fecha->format('Y-m-d H:i:s'), $model->relacionado ? 1 : 0, $model->propietario->rut]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['proyecto', 'precio', 'fecha', 'relacionado', 'propietario'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchDatosVigentes(): array
|
||||
{
|
||||
$query = "
|
||||
SELECT `proyecto`.`descripcion` AS 'Proyecto', tec.`descripcion` AS 'Estado', COUNT(a.`id`) AS 'Cantidad'
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT e1.*
|
||||
FROM `estado_cierre` e1
|
||||
JOIN (SELECT MAX(`id`) AS id, `cierre` FROM `estado_cierre` GROUP BY `cierre`) e0 ON e0.`id` = e1.`id`) ec ON ec.`cierre` = a.`id`
|
||||
JOIN `tipo_estado_cierre` tec ON tec.`id` = ec.`tipo`
|
||||
JOIN `proyecto` ON `proyecto`.`id` = a.`proyecto`
|
||||
GROUP BY `proyecto`.`descripcion`, tec.`descripcion`";
|
||||
$results = $this->connection->execute($query)->fetchAll(PDO::FETCH_ASSOC);
|
||||
if ($results === false) {
|
||||
throw new EmptyResult($query);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
161
app/src/Repository/Venta/Cuota.php
Normal file
161
app/src/Repository/Venta/Cuota.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PDO;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Cuota extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pie $pieRepository, protected Repository\Banco $bancoRepository, protected Pago $pagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('cuota');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pie' => [
|
||||
'function' => function($data) {
|
||||
return $this->pieRepository->fetchById($data['pie']);
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
],
|
||||
'valor' => [],
|
||||
'estado' => [
|
||||
'function' => function($data) {
|
||||
return $data['estado'] !== 0;
|
||||
}
|
||||
],
|
||||
'banco' => [
|
||||
'function' => function($data) {
|
||||
if ($data['banco'] === null or $data['banco'] === '') {
|
||||
return null;
|
||||
}
|
||||
return $this->bancoRepository->fetchById($data['banco']);
|
||||
}
|
||||
],
|
||||
'fecha_pago' => [
|
||||
'property' => 'fechaPago',
|
||||
'function' => function($data) {
|
||||
if ($data['fecha_pago'] === null) {
|
||||
return null;
|
||||
}
|
||||
return new DateTimeImmutable($data['fecha_pago']);
|
||||
}
|
||||
],
|
||||
'abonado' => [
|
||||
'function' => function($data) {
|
||||
if ($data['abonado'] === null) {
|
||||
return null;
|
||||
}
|
||||
return $data['abonado'] !== 0;
|
||||
}
|
||||
],
|
||||
'fecha_abonado' => [
|
||||
'property' => 'fechaAbonado',
|
||||
'function' => function($data) {
|
||||
if ($data['fecha_abonado'] === null) {
|
||||
return null;
|
||||
}
|
||||
return new DateTimeImmutable($data['fecha_abonado']);
|
||||
}
|
||||
],
|
||||
'uf' => [],
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
if ($data['pago'] === null) {
|
||||
return null;
|
||||
}
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
],
|
||||
'numero' => []
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Cuota(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$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]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['pie', 'fecha', 'valor', 'estado', 'banco', 'fecha_pago', 'abonado', 'fecha_abonado', 'uf', 'pago', 'numero'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchHoy(): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `pago` ON `pago`.`id` = a.`pago`
|
||||
JOIN (SELECT e1.* FROM `estado_pago` e1 JOIN (SELECT MAX(`id`) AS `id`, `pago` FROM `estado_pago` GROUP BY `pago`) e0 ON e0.`id` = e1.`id`) ep ON ep.`pago` = `pago`.`id`
|
||||
JOIN `tipo_estado_pago` tep ON tep.`id` = ep.`estado`
|
||||
JOIN `venta` ON `venta`.`pie` = a.`pie`
|
||||
JOIN (SELECT ev1.* FROM `estado_venta` ev1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) ev0 ON ev0.`id` = ev1.`id`) ev ON ev.`venta` = `venta`.`id`
|
||||
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
|
||||
WHERE tep.`descripcion` = 'no pagado' AND `pago`.`fecha` = CURDATE()
|
||||
AND tev.`descripcion` IN ('vigente', 'escriturando', 'firmado por inmobiliaria')";
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
public function fetchPendientes(): array
|
||||
{
|
||||
$query = "SELECT a.`id` AS 'cuota_id', `venta`.`id` AS 'venta_id', `proyecto`.`descripcion` AS 'Proyecto', `unidad`.`descripcion` AS 'Departamento',
|
||||
`pago`.`valor` AS 'Valor', `pago`.`fecha`, CONCAT_WS(' - ', a.`numero`, `pie`.`cuotas`) AS 'Numero', `banco`.`nombre` AS 'Banco',
|
||||
CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) AS 'Propietario'
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `pago` ON `pago`.`id` = a.`pago`
|
||||
JOIN (SELECT e1.* FROM `estado_pago` e1 JOIN (SELECT MAX(`id`) AS 'id', `pago` FROM `estado_pago` GROUP BY `pago`) e0 ON e0.`id` = e1.`id`) ep ON ep.`pago` = `pago`.`id`
|
||||
JOIN `tipo_estado_pago` tep ON tep.`id` = ep.`estado`
|
||||
JOIN `pie` ON `pie`.`id` = a.`pie`
|
||||
JOIN `venta` ON `venta`.`pie` = a.`pie`
|
||||
JOIN (SELECT ev1.* FROM `estado_venta` ev1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) ev0 ON ev0.`id` = ev1.`id`) ev ON ev.`venta` = `venta`.`id`
|
||||
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
|
||||
JOIN `propietario` ON `propietario`.`rut` = `venta`.`propietario`
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = `venta`.`propiedad`
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
|
||||
JOIN `proyecto` ON `proyecto`.`id` = ptu.`proyecto`
|
||||
JOIN `banco` ON `banco`.`id` = `pago`.`banco`
|
||||
WHERE tep.`descripcion` = 'no pagado' AND `pago`.`fecha` < CURDATE()
|
||||
AND tev.`descripcion` IN ('vigente', 'escriturando', 'firmado por inmobiliaria')
|
||||
ORDER BY `pago`.`fecha` DESC";
|
||||
return $this->fetchAsArray($query);
|
||||
}
|
||||
public function fetchDatosPorVencer(): array
|
||||
{
|
||||
$query = "SELECT `pago`.`fecha` AS 'Fecha', `proyecto`.`descripcion` AS 'Proyecto', COUNT(a.`id`) AS 'Cantidad'
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `pago` ON `pago`.`id` = a.`pago`
|
||||
JOIN (SELECT e1.* FROM `estado_pago` e1 JOIN (SELECT MAX(`id`) AS 'id', `pago` FROM `estado_pago` GROUP BY `pago`) e0 ON e0.`id` = e1.`id`) ep ON ep.`pago` = `pago`.`id`
|
||||
JOIN `tipo_estado_pago` tep ON tep.`id` = ep.`estado`
|
||||
JOIN `venta` ON `venta`.`pie` = a.`pie`
|
||||
JOIN (SELECT ev1.* FROM `estado_venta` ev1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) ev0 ON ev0.`id` = ev1.`id`) ev ON ev.`venta` = `venta`.`id`
|
||||
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = `venta`.`propiedad` AND pu.`principal` = 1
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad`
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
|
||||
JOIN `proyecto` ON `proyecto`.`id` = ptu.`proyecto`
|
||||
WHERE tep.`descripcion` = 'no pagado' AND `pago`.`fecha` BETWEEN DATE_ADD(CURDATE(), INTERVAL 1 DAY) AND DATE_ADD(CURDATE(), INTERVAL 1 MONTH)
|
||||
AND tev.`descripcion` IN ('vigente', 'escriturando', 'firmado por inmobiliaria')
|
||||
GROUP BY `pago`.`fecha`, `proyecto`.`descripcion`
|
||||
ORDER BY `pago`.`fecha`, `proyecto`.`descripcion`";
|
||||
return $this->fetchAsArray($query);
|
||||
}
|
||||
}
|
67
app/src/Repository/Venta/EstadoPago.php
Normal file
67
app/src/Repository/Venta/EstadoPago.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class EstadoPago extends Ideal\Repository
|
||||
{
|
||||
public function __construct(protected Define\Connection $connection,
|
||||
protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('estado_pago');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
],
|
||||
'estado' => [
|
||||
'property' => 'tipoEstadoPago',
|
||||
'function' => function($data) {
|
||||
return $this->tipoEstadoPagoRepository->fetchById($data['estado']);
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\EstadoPago(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['pago', 'estado', 'fecha'],
|
||||
[$model->pago->id, $model->tipoEstadoPago->id, $model->fecha->format('Y-m-d')]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['pago', 'estado', 'fecha'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByPago(int $pago_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pago` = ?";
|
||||
return $this->fetchMany($query, [$pago_id]);
|
||||
}
|
||||
public function fetchByPagoAndEstado(int $pago_id, int $estado_id): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pago` = ? AND `estado` = ?";
|
||||
return $this->fetchOne($query, [$pago_id, $estado_id]);
|
||||
}
|
||||
}
|
65
app/src/Repository/Venta/EstadoPrecio.php
Normal file
65
app/src/Repository/Venta/EstadoPrecio.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class EstadoPrecio extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Venta\Precio $precioRepository, protected Repository\Venta\TipoEstadoPrecio $tipoEstadoPrecioRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('estado_precio');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'precio' => [
|
||||
'function' => function($data) {
|
||||
return $this->precioRepository->fetchById($data['precio']);
|
||||
}
|
||||
],
|
||||
'estado' => [
|
||||
'property' => 'tipoEstadoPrecio',
|
||||
'function' => function($data) {
|
||||
return $this->tipoEstadoPrecioRepository->fetchById($data['estado']);
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\EstadoPrecio(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['precio', 'estado', 'fecha'],
|
||||
[$model->precio->id, $model->tipoEstadoPrecio->id, $model->fecha->format('Y-m-d')]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['precio', 'estado', 'fecha'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByPrecio(int $precio_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `precio` = ?";
|
||||
return $this->fetchMany($query, [$precio_id]);
|
||||
}
|
||||
public function fetchCurrentByPrecio(int $precio_id): Define\Model
|
||||
{
|
||||
$query = "SELECT e1.*
|
||||
FROM `{$this->getTable()}` e1 JOIN (SELECT MAX(`id`) AS 'id', `precio` FROM `{$this->getTable()}` GROUP BY `precio`) e0 ON e0.`id` = e1.`id`
|
||||
WHERE e1.`precio` = ?";
|
||||
return $this->fetchOne($query, [$precio_id]);
|
||||
}
|
||||
}
|
73
app/src/Repository/Venta/Pago.php
Normal file
73
app/src/Repository/Venta/Pago.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Pago extends Ideal\Repository
|
||||
{
|
||||
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
|
||||
{
|
||||
$map = [
|
||||
'valor' => [],
|
||||
'banco' => [
|
||||
'function' => function($data) {
|
||||
if ($data['banco'] === null or $data['banco'] === 0) {
|
||||
return null;
|
||||
}
|
||||
return $this->bancoRepository->fetchById($data['banco']);
|
||||
}
|
||||
],
|
||||
'tipo' => [
|
||||
'property' => 'tipoPago',
|
||||
'function' => function($data) {
|
||||
if ($data['tipo'] === null) {
|
||||
return null;
|
||||
}
|
||||
return $this->tipoPagoRepository->fetchById($data['tipo']);
|
||||
}
|
||||
],
|
||||
'identificador' => [],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
if ($data['fecha'] === null) {
|
||||
return null;
|
||||
}
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
],
|
||||
'uf' => [],
|
||||
'pagador' => [],
|
||||
'asociado' => [
|
||||
'function' => function($data) {
|
||||
if ($data['asociado'] === null) {
|
||||
return null;
|
||||
}
|
||||
return $this->fetchById($data['asociado']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Pago(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$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]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['valor', 'banco', 'tipo', 'identificador', 'fecha', 'uf', 'pagador', 'asociado'], $new_data);
|
||||
}
|
||||
}
|
60
app/src/Repository/Venta/Pie.php
Normal file
60
app/src/Repository/Venta/Pie.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Pie extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('pie');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
],
|
||||
'valor' => [],
|
||||
'uf' => [],
|
||||
'cuotas' => [],
|
||||
'asociado' => [
|
||||
'function' => function($data) {
|
||||
if ($data['asociado'] === null or $data['asociado'] === 0) {
|
||||
return null;
|
||||
}
|
||||
return $this->fetchById($data['asociado']);
|
||||
}
|
||||
],
|
||||
'reajuste' => [
|
||||
'function' => function($data) {
|
||||
if ($data['reajuste'] === null or $data['reajuste'] === 0) {
|
||||
return null;
|
||||
}
|
||||
return $this->pagoRepository->fetchById($data['reajuste']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Pie(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$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]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['fecha', 'valor', 'uf', 'cuotas', 'asociado', 'reajuste'], $new_data);
|
||||
}
|
||||
}
|
55
app/src/Repository/Venta/Precio.php
Normal file
55
app/src/Repository/Venta/Precio.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 Precio extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Venta\Unidad $unidadRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('precio');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'unidad' => [
|
||||
'function' => function($data) {
|
||||
return $this->unidadRepository->fetchById($data['unidad']);
|
||||
}
|
||||
],
|
||||
'valor' => []
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Precio(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['unidad', 'valor'],
|
||||
[$model->unidad->id, $model->valor]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['unidad', 'valor'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$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`
|
||||
JOIN `unidad` ON `unidad`.`id` = a.`unidad`
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
|
||||
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`
|
||||
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]);
|
||||
}
|
||||
}
|
82
app/src/Repository/Venta/Propietario.php
Normal file
82
app/src/Repository/Venta/Propietario.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Propietario extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Direccion $direccionRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('propietario');
|
||||
}
|
||||
|
||||
protected function getKey(): string
|
||||
{
|
||||
return 'rut';
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'dv' => [],
|
||||
'nombres' => [],
|
||||
'apellido_paterno' => [
|
||||
'property' => 'apellidos',
|
||||
'function' => function($data) {
|
||||
$arr = [
|
||||
'paterno' => $data['apellido_paterno']
|
||||
];
|
||||
if ($data['apellido_materno'] !== '') {
|
||||
$arr['materno'] = $data['apellido_materno'];
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
],
|
||||
'direccion' => [
|
||||
'property' => 'datos',
|
||||
'function' => function($data) {
|
||||
$datos = new Model\Venta\Datos();
|
||||
if ($data['direccion'] !== null and $data['direccion'] !== 0) {
|
||||
$datos->direccion = $this->direccionRepository->fetchById($data['direccion']);
|
||||
}
|
||||
return $datos;
|
||||
}
|
||||
],
|
||||
'representante' => [
|
||||
'function' => function($data) {
|
||||
if ($data['representante'] === null or $data['representante'] === 0) {
|
||||
return null;
|
||||
}
|
||||
return $this->fetchById($data['representante']);
|
||||
}
|
||||
],
|
||||
'otro' => [
|
||||
'function' => function($data) {
|
||||
if ($data['otro'] === null) {
|
||||
return null;
|
||||
}
|
||||
return $data['otro'] !== 0;
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Propietario(), $data, $map);
|
||||
}
|
||||
|
||||
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']]
|
||||
);
|
||||
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);
|
||||
}
|
||||
}
|
40
app/src/Repository/Venta/TipoEstadoPago.php
Normal file
40
app/src/Repository/Venta/TipoEstadoPago.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoEstadoPago extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_estado_pago');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = ['descripcion' => []];
|
||||
return $this->parseData(new Model\Venta\TipoEstadoPago(), $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);
|
||||
}
|
||||
|
||||
public function fetchByDescripcion(string $descripcion): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `descripcion` = ?";
|
||||
return $this->fetchOne($query, [$descripcion]);
|
||||
}
|
||||
}
|
35
app/src/Repository/Venta/TipoEstadoPrecio.php
Normal file
35
app/src/Repository/Venta/TipoEstadoPrecio.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoEstadoPrecio extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_estado_precio');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => []
|
||||
];
|
||||
return $this->parseData(new Model\Venta\TipoEstadoPrecio(), $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);
|
||||
}
|
||||
}
|
35
app/src/Repository/Venta/TipoPago.php
Normal file
35
app/src/Repository/Venta/TipoPago.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoPago extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_pago');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => []
|
||||
];
|
||||
return $this->parseData(new Model\Venta\TipoPago(), $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);
|
||||
}
|
||||
}
|
39
app/src/Repository/Venta/TipoUnidad.php
Normal file
39
app/src/Repository/Venta/TipoUnidad.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class TipoUnidad extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_unidad');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'orden' => []
|
||||
];
|
||||
return $this->parseData(new Model\Venta\TipoUnidad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion', 'orden'],
|
||||
[$model->descripcion, $model->orden]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'orden'], $new_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
47
app/src/Repository/Venta/Unidad.php
Normal file
47
app/src/Repository/Venta/Unidad.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Unidad extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Proyecto\ProyectoTipoUnidad $proyectoTipoUnidadRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('unidad');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'subtipo' => [],
|
||||
'piso' => [],
|
||||
'descripcion' => [],
|
||||
'orientacion' => [],
|
||||
'pt' => [
|
||||
'property' => 'proyectoTipoUnidad',
|
||||
'function' => function($data) {
|
||||
return $this->proyectoTipoUnidadRepository->fetchById($data['pt']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Unidad(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'],
|
||||
[$model->subtipo, $model->piso, $model->descripcion, $model->orientacion, $model->proyectoTipoUnidad->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'], $new_data);
|
||||
}
|
||||
}
|
24
app/src/Service/Format.php
Normal file
24
app/src/Service/Format.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use IntlDateFormatter;
|
||||
|
||||
class Format
|
||||
{
|
||||
public function localDate(string $valor, string $format, bool $print = false): string
|
||||
{
|
||||
$date = new DateTimeImmutable($valor);
|
||||
$formatter = new IntlDateFormatter('es_ES');
|
||||
if ($format == null) {
|
||||
$format = 'DD [de] MMMM [de] YYYY';
|
||||
}
|
||||
$formatter->setPattern($format);
|
||||
return $formatter->format($date);
|
||||
|
||||
}
|
||||
public function pesos(string $valor): string
|
||||
{
|
||||
return '$' . number_format($valor, 0, ',', '.');
|
||||
}
|
||||
}
|
135
app/src/Service/Login.php
Normal file
135
app/src/Service/Login.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Exception;
|
||||
use PDOException;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use PhpParser\Node\Expr\AssignOp\Mod;
|
||||
use function random_bytes;
|
||||
use function password_hash;
|
||||
use function setcookie;
|
||||
|
||||
class Login
|
||||
{
|
||||
public function __construct(protected Repository\Login $repository, protected string $cookie_name, protected int $max_login_time, protected string $domain = '', protected string $path = '', protected string $cookie_separator = ':')
|
||||
{
|
||||
$this->loadCookie();
|
||||
}
|
||||
|
||||
protected string $selector = '';
|
||||
protected string $token = '';
|
||||
|
||||
public function isIn(): bool
|
||||
{
|
||||
try {
|
||||
$login = $this->repository->fetchActiveBySelector($this->selector);
|
||||
if (!$this->validToken($login)) {
|
||||
return false;
|
||||
}
|
||||
$now = new DateTimeImmutable();
|
||||
if ($login->dateTime->add(new DateInterval("PT{$this->max_login_time}H")) > $now) {
|
||||
return true;
|
||||
}
|
||||
} catch (PDOException|EmptyResult) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function getUser(): Model\User
|
||||
{
|
||||
$login = $this->repository->fetchActiveBySelector($this->selector);
|
||||
if (!$this->validToken($login)) {
|
||||
throw new Exception('User not found');
|
||||
}
|
||||
return $login->user;
|
||||
}
|
||||
|
||||
public function login(Model\User $user): bool
|
||||
{
|
||||
try {
|
||||
$login = $this->repository->fetchActiveByUser($user->id);
|
||||
$this->logout($login->user);
|
||||
} catch (PDOException|EmptyResult) {
|
||||
}
|
||||
|
||||
try {
|
||||
$now = new DateTimeImmutable();
|
||||
$login = $this->repository->create([
|
||||
'user_id' => $user->id,
|
||||
'time' => $now->format('Y-m-d H:i:s'),
|
||||
'status' => 1
|
||||
]);
|
||||
list('selector' => $selector, 'token' => $token) = $this->generateToken($login);
|
||||
$login->selector = $selector;
|
||||
$login->token = password_hash($token, PASSWORD_DEFAULT);
|
||||
$this->repository->save($login);
|
||||
$this->saveCookie($selector, $token, $login->dateTime->add(new DateInterval("PT{$this->max_login_time}H")));
|
||||
return true;
|
||||
} catch (PDOException|Exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function logout(Model\User $user): bool
|
||||
{
|
||||
$this->removeCookie();
|
||||
try {
|
||||
$logins = $this->repository->fetchByUser($user->id);
|
||||
} catch (PDOException) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
foreach ($logins as $login) {
|
||||
$this->repository->edit($login, ['status' => 0]);
|
||||
}
|
||||
return true;
|
||||
} catch (PDOException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected function loadCookie(): void
|
||||
{
|
||||
if (!isset($_COOKIE[$this->cookie_name])) {
|
||||
return;
|
||||
}
|
||||
$cookie = $_COOKIE[$this->cookie_name];
|
||||
list($this->selector, $this->token) = explode($this->cookie_separator, $cookie);
|
||||
}
|
||||
protected function saveCookie(string $selector, string $token, DateTimeInterface $expires): void
|
||||
{
|
||||
setcookie(
|
||||
$this->cookie_name,
|
||||
implode($this->cookie_separator, [$selector, $token]),
|
||||
$expires->getTimestamp(),
|
||||
$this->path,
|
||||
$this->domain
|
||||
);
|
||||
$this->selector = $selector;
|
||||
$this->token = $token;
|
||||
}
|
||||
protected function removeCookie(): void
|
||||
{
|
||||
setcookie(
|
||||
$this->cookie_name,
|
||||
'',
|
||||
(new DateTimeImmutable())->getTimestamp(),
|
||||
$this->path,
|
||||
$this->domain
|
||||
);
|
||||
}
|
||||
|
||||
protected function validToken(Model\Login $login): bool
|
||||
{
|
||||
return password_verify($this->token, $login->token);
|
||||
}
|
||||
protected function generateToken(Model\Login $login)
|
||||
{
|
||||
$selector = bin2hex(random_bytes(12));
|
||||
$token = bin2hex(random_bytes(20));
|
||||
return ['selector' => $selector, 'token' => $token];
|
||||
}
|
||||
}
|
31
app/src/Service/Ventas/Pago.php
Normal file
31
app/src/Service/Ventas/Pago.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PDOException;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Pago
|
||||
{
|
||||
public function __construct(protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository) {}
|
||||
|
||||
public function depositar(Model\Venta\Pago $pago): bool
|
||||
{
|
||||
$tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('depositado');
|
||||
$data = [
|
||||
'pago' => $pago->id,
|
||||
'estado' => $tipo_estado->id,
|
||||
'fecha' => (new DateTimeImmutable())->format('Y-m-d')
|
||||
];
|
||||
try {
|
||||
$estado = $this->estadoPagoRepository->create($data);
|
||||
$this->estadoPagoRepository->save($estado);
|
||||
return true;
|
||||
} catch (PDOException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
19
app/src/Service/Ventas/Precio.php
Normal file
19
app/src/Service/Ventas/Precio.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Ventas;
|
||||
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Precio
|
||||
{
|
||||
public function __construct(protected Repository\Venta\Precio $precioRepository, protected Repository\Venta\EstadoPrecio $estadoPrecioRepository) {}
|
||||
|
||||
public function getByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$precios = $this->precioRepository->fetchByProyecto($proyecto_id);
|
||||
foreach ($precios as &$precio) {
|
||||
$precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id);
|
||||
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
|
||||
}
|
||||
return $precios;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user