Ventas
This commit is contained in:
@ -18,7 +18,10 @@ class Base
|
||||
}
|
||||
return $this->login($response, $view);
|
||||
}
|
||||
|
||||
public function construccion(ServerRequestInterface $request, ResponseInterface $response, View $view): ResponseInterface
|
||||
{
|
||||
return $view->render($response, 'construccion');
|
||||
}
|
||||
protected function home(ResponseInterface $response, View $view, Repository\Venta\Cuota $cuotaRepository, Repository\Venta\Cierre $cierreRepository): ResponseInterface
|
||||
{
|
||||
$cuotas_hoy = count($cuotaRepository->fetchHoy()) ?? 0;
|
||||
|
28
app/src/Controller/Provincias.php
Normal file
28
app/src/Controller/Provincias.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Provincias
|
||||
{
|
||||
public function comunas(ServerRequestInterface $request, ResponseInterface $response, Repository\Comuna $comunaRepository, int $provincia_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'provincia_id' => $provincia_id,
|
||||
'comunas' => []
|
||||
];
|
||||
try {
|
||||
$comunas = $comunaRepository->fetchByProvincia($provincia_id);
|
||||
usort($comunas, function(Model\Comuna $a, Model\Comuna $b) {
|
||||
return strcmp($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$output['comunas'] = $comunas;
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Proyectos
|
||||
{
|
||||
@ -24,4 +25,27 @@ class Proyectos
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0];
|
||||
try {
|
||||
$unidades = $unidadRepository->fetchByProyecto($proyecto_id);
|
||||
$tipos = [];
|
||||
foreach ($unidades as $unidad) {
|
||||
if (!isset($tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion])) {
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] = [];
|
||||
}
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] []= $unidad;
|
||||
}
|
||||
foreach ($tipos as &$subtipo) {
|
||||
usort($subtipo, function(Model\Venta\Unidad $a, Model\Venta\Unidad $b) {
|
||||
return strcmp(str_pad($a->descripcion, 4, '0', STR_PAD_LEFT), str_pad($b->descripcion, 4, '0', STR_PAD_LEFT));
|
||||
});
|
||||
}
|
||||
$output['unidades'] = $tipos;
|
||||
$output['total'] = count($unidades);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
28
app/src/Controller/Regiones.php
Normal file
28
app/src/Controller/Regiones.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Regiones
|
||||
{
|
||||
public function provincias(ServerRequestInterface $request, ResponseInterface $response, Repository\Provincia $provinciaRepository, int $region_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'region_id' => $region_id,
|
||||
'provincias' => []
|
||||
];
|
||||
try {
|
||||
$provincias = $provinciaRepository->fetchByRegion($region_id);
|
||||
usort($provincias, function(Model\Provincia $a, Model\Provincia $b) {
|
||||
return strcmp($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$output['provincias'] = $provincias;
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -102,4 +102,13 @@ class Ventas
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Region $regionRepository, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$regiones = $regionRepository->fetchAll();
|
||||
usort($regiones, function(Model\Region $a, Model\Region $b) {
|
||||
return $a->numeracion - $b->numeracion;
|
||||
});
|
||||
$proyectos = $proyectoRepository->fetchAllActive();
|
||||
return $view->render($response, 'ventas.add', compact('regiones', 'proyectos'));
|
||||
}
|
||||
}
|
||||
|
@ -2,61 +2,72 @@
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use IntlDateFormatter;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
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
|
||||
public function pendientes(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta\Cuota $cuotaService): 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')
|
||||
];
|
||||
}
|
||||
$cuotas_pendientes = $cuotaService->pendientes();
|
||||
return $view->render($response, 'ventas.cuotas.pendientes', compact('cuotas_pendientes'));
|
||||
}
|
||||
public function depositadas(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta\Cuota $cuotaService): ResponseInterface
|
||||
{
|
||||
$cuotas_depositadas = $cuotaService->depositadas();
|
||||
return $view->render($response, 'ventas.cuotas.abonar', compact('cuotas_depositadas'));
|
||||
}
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$cuota_id = $json->cuota_id;
|
||||
$fecha = new DateTimeImmutable($json->fecha);
|
||||
$output = [
|
||||
'cuota_id' => $cuota_id,
|
||||
'depositada' => false
|
||||
];
|
||||
try{
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output['depositada'] = $pagoService->depositar($cuota->pago);
|
||||
$output['depositada'] = $pagoService->depositar($cuota->pago, $fecha);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function abonar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$cuota_id = $json->cuota_id;
|
||||
$fecha = new DateTimeImmutable($json->fecha);
|
||||
$output = [
|
||||
'cuota_id' => $cuota_id,
|
||||
'abonada' => false
|
||||
];
|
||||
try{
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output['abonada'] = $pagoService->abonar($cuota->pago, $fecha);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function devolver(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$cuota_id = $json->cuota_id;
|
||||
$fecha = new DateTimeImmutable($json->fecha);
|
||||
$output = [
|
||||
'cuota_id' => $cuota_id,
|
||||
'devuelta' => false
|
||||
];
|
||||
try{
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output['devuelta'] = $pagoService->devolver($cuota->pago, $fecha);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
|
@ -4,10 +4,16 @@ namespace Incoviba\Controller\Ventas;
|
||||
use DateTimeImmutable;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Pagos
|
||||
{
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||
public function pendientes(ServerRequestInterface $request, ResponseInterface $response, View $view): ResponseInterface
|
||||
{
|
||||
return $view->render($response, 'ventas.pagos.pendientes');
|
||||
}
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
@ -15,7 +21,7 @@ class Pagos
|
||||
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function abonar(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||
public function abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
@ -23,4 +29,40 @@ class Pagos
|
||||
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function para_pendientes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$pagos = $pagoService->getPendientes();
|
||||
$pagos_pendientes = [];
|
||||
foreach ($pagos as $pago) {
|
||||
$pagos_pendientes []= [
|
||||
'id' => $pago->id
|
||||
];
|
||||
}
|
||||
$response->getBody()->write(json_encode(['pagos' => $pagos_pendientes, 'total' => count($pagos_pendientes)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function para_abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$pagos = $pagoService->getDepositados();
|
||||
$pagos_depositados = [];
|
||||
foreach ($pagos as $pago) {
|
||||
$pagos_depositados []= [
|
||||
'id' => $pago->id
|
||||
];
|
||||
}
|
||||
$response->getBody()->write(json_encode(['pagos' => $pagos_depositados, 'total' => count($pagos_depositados)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function rebotes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$pagos = $pagoService->getRebotes();
|
||||
$rebotes = [];
|
||||
foreach ($pagos as $pago) {
|
||||
$rebotes []= [
|
||||
'id' => $pago->id
|
||||
];
|
||||
}
|
||||
$response->getBody()->write(json_encode(['pagos' => $rebotes, 'total' => count($rebotes)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
@ -12,4 +13,16 @@ class Propietarios
|
||||
$propietario = $propietarioRepository->fetchById($propietario_rut);
|
||||
return $view->render($response, 'ventas.propietarios.show', compact('propietario'));
|
||||
}
|
||||
}
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Propietario $propietarioRepository, int $propietario_rut): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'rut' => $propietario_rut,
|
||||
'propietario' => null
|
||||
];
|
||||
try {
|
||||
$output['propietario'] = $propietarioRepository->fetchById($propietario_rut);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
7
app/src/Model/Menu.php
Normal file
7
app/src/Model/Menu.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Menu extends Ideal\Model
|
||||
{}
|
@ -22,7 +22,7 @@ class Inmobiliaria extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['db', 'razon', 'abreviacion', 'cuenta']))
|
||||
$map = (new Implement\Repository\MapperParser(['dv', 'razon', 'abreviacion', 'cuenta']))
|
||||
->register('banco', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->bancoRepository->fetchById($data['banco']);
|
||||
|
62
app/src/Repository/Menu.php
Normal file
62
app/src/Repository/Menu.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Menu extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('menus');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['title']))
|
||||
->register('url', (new Implement\Repository\Mapper())
|
||||
->setDefault(''));
|
||||
$model = $this->parseData(new Model\Menu(), $data, $map);
|
||||
$model->children = $this->fetchChildren($model->id);
|
||||
return $model;
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['title', 'url'],
|
||||
[$model->title, $model->url]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['title', 'url'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByUser(int $user_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `menu_permissions` mp ON mp.`menu_id` = a.`id`
|
||||
JOIN `permissions` ON `permissions`.`id` = mp.`permission_id`
|
||||
LEFT JOIN `users` u1 ON u1.`id` = `permissions`.`'ext_id` AND `permissions`.`type` = 2
|
||||
LEFT JOIN (SELECT u2.* FROM `roles` ON `roles`.`id` = `permissions`.`ext_id` AND `permissions`.`type` = 1
|
||||
JOIN `user_roles` ur ON ur.`role` = `role`.`id`
|
||||
JOIN `users` u2 ON u2.`id` = ur.`user`) us
|
||||
LEFT JOIN `menu_relations` mr ON mr.`child_id` = a.`id`
|
||||
WHERE u1.`id` = ? OR us.`id` = ? AND mr.`id` IS NULL";
|
||||
return $this->fetchMany($query, [$user_id, $user_id]);
|
||||
}
|
||||
public function fetchChildren(int $menu_id): array
|
||||
{
|
||||
$query = "SELECT sm.* FROM `menu_relations` mr WHERE mr.`parent_id` = ?";
|
||||
try {
|
||||
return $this->fetchMany($query, [$menu_id]);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
15
app/src/Repository/Permission.php
Normal file
15
app/src/Repository/Permission.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Permission extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('permissions');
|
||||
}
|
||||
}
|
@ -23,8 +23,8 @@ class Proyecto extends Ideal\Repository
|
||||
->setArgs([$data['inmobiliaria']])))
|
||||
->register('direccion', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->inmobiliariaRepository, 'fetchById'])
|
||||
->setArgs([$data['inmobiliaria']])))
|
||||
->setCallable([$this->direccionRepository, 'fetchById'])
|
||||
->setArgs([$data['direccion']])))
|
||||
->register('superficie_terreno', (new Implement\Repository\Mapper())
|
||||
->setProperty('terreno')
|
||||
->setFunction(function($data) {
|
||||
|
@ -106,6 +106,30 @@ FROM `{$this->getTable()}` a
|
||||
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 fetchDepositadas(): 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', ep.`fecha` AS 'Fecha Depositada',
|
||||
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` = 'depositado' AND `pago`.`fecha` < CURDATE()
|
||||
AND tev.`descripcion` IN ('vigente', 'escriturando', 'firmado por inmobiliaria')
|
||||
ORDER BY `pago`.`fecha` DESC";
|
||||
return $this->fetchAsArray($query);
|
||||
}
|
||||
|
44
app/src/Service/Menu.php
Normal file
44
app/src/Service/Menu.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Menu
|
||||
{
|
||||
public function __construct(protected Repository\Menu $menuRepository, protected Permission $permissionService, protected object $urls) {}
|
||||
|
||||
public function build(int $user_id): string
|
||||
{
|
||||
$menus = $this->getValid($user_id);
|
||||
$output = [];
|
||||
foreach ($menus as $menu) {
|
||||
$output []= $this->buildItem($menu);
|
||||
}
|
||||
return implode(PHP_EOL, $output);
|
||||
}
|
||||
protected function buildItem(mixed $item): string
|
||||
{
|
||||
if (isset($item->submenus)) {
|
||||
return $this->buildDropdown($item);
|
||||
}
|
||||
return "<a class=\"item\" href=\"{{$this->urls->base}}/{{$item->url}}\">{{$item->title}}</a>";
|
||||
}
|
||||
protected function buildDropdown(mixed $item): string
|
||||
{
|
||||
$output []= '<div class="ui simple dropdown item">';
|
||||
$output []= $item->title;
|
||||
$output []= '<i class="dropdown icon"></i>';
|
||||
$output []= '<div class="menu">';
|
||||
foreach ($item->submenus as $menu) {
|
||||
$output []= $this->buildItem($menu);
|
||||
}
|
||||
$output []= '</div>';
|
||||
$output []= '</div>';
|
||||
return implode(PHP_EOL, $output);
|
||||
}
|
||||
|
||||
public function getValid(int $user_id): array
|
||||
{
|
||||
return $this->menuRepository->fetchByUser($user_id);
|
||||
}
|
||||
}
|
9
app/src/Service/Permission.php
Normal file
9
app/src/Service/Permission.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Permission
|
||||
{
|
||||
public function __construct(protected Repository\Permission $permissionRepository) {}
|
||||
}
|
71
app/src/Service/Venta/Cuota.php
Normal file
71
app/src/Service/Venta/Cuota.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use IntlDateFormatter;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Cuota
|
||||
{
|
||||
public function __construct(protected Repository\Venta\Cuota $cuotaRepository) {}
|
||||
|
||||
public function pendientes(): array
|
||||
{
|
||||
$cuotas = $this->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 $cuotas_pendientes;
|
||||
}
|
||||
public function depositadas(): array
|
||||
{
|
||||
$cuotas = $this->cuotaRepository->fetchDepositadas();
|
||||
$cuotas_depositadas = [];
|
||||
$today = new DateTimeImmutable();
|
||||
$formatter = new IntlDateFormatter('es_ES');
|
||||
$formatter->setPattern('EEEE dd');
|
||||
foreach ($cuotas as $cuota) {
|
||||
$date = new DateTimeImmutable($cuota['fecha']);
|
||||
$deposito = new DateTimeImmutable($cuota['Fecha Depositada']);
|
||||
$cuotas_depositadas []= [
|
||||
'id' => $cuota['cuota_id'],
|
||||
'venta_id' => $cuota['venta_id'],
|
||||
'Proyecto' => $cuota['Proyecto'],
|
||||
'Departamento' => $cuota['Departamento'],
|
||||
'Valor' => $cuota['Valor'],
|
||||
'Numero' => $cuota['Numero'],
|
||||
'Propietario' => $cuota['Propietario'],
|
||||
'Banco' => $cuota['Banco'],
|
||||
'Fecha Cheque' => $date->format('d-m-Y'),
|
||||
'Fecha ISO' => $date->format('Y-m-d'),
|
||||
'Fecha Depositada' => $deposito->format('d-m-Y')
|
||||
];
|
||||
}
|
||||
return $cuotas_depositadas;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use PDOException;
|
||||
use Incoviba\Repository;
|
||||
@ -12,13 +13,45 @@ class Pago
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository) {}
|
||||
|
||||
public function depositar(Model\Venta\Pago $pago): bool
|
||||
public function depositar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
||||
{
|
||||
$tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('depositado');
|
||||
$data = [
|
||||
'pago' => $pago->id,
|
||||
'estado' => $tipo_estado->id,
|
||||
'fecha' => (new DateTimeImmutable())->format('Y-m-d')
|
||||
'fecha' => $fecha->format('Y-m-d')
|
||||
];
|
||||
try {
|
||||
$estado = $this->estadoPagoRepository->create($data);
|
||||
$this->estadoPagoRepository->save($estado);
|
||||
return true;
|
||||
} catch (PDOException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function abonar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
||||
{
|
||||
$tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('abonado');
|
||||
$data = [
|
||||
'pago' => $pago->id,
|
||||
'estado' => $tipo_estado->id,
|
||||
'fecha' => $fecha->format('Y-m-d')
|
||||
];
|
||||
try {
|
||||
$estado = $this->estadoPagoRepository->create($data);
|
||||
$this->estadoPagoRepository->save($estado);
|
||||
return true;
|
||||
} catch (PDOException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function devolver(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
||||
{
|
||||
$tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('devuelto');
|
||||
$data = [
|
||||
'pago' => $pago->id,
|
||||
'estado' => $tipo_estado->id,
|
||||
'fecha' => $fecha->format('Y-m-d')
|
||||
];
|
||||
try {
|
||||
$estado = $this->estadoPagoRepository->create($data);
|
||||
@ -35,4 +68,17 @@ class Pago
|
||||
$pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago_id);
|
||||
return $pago;
|
||||
}
|
||||
|
||||
public function getPendientes(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
public function getDepositados(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
public function getRebotes(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user