From 6ab24c89614efe27a968266eb9054ecd5329d5ec Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Fri, 23 Jun 2023 11:36:44 -0400 Subject: [PATCH 001/163] Command return --- app/Command/Money/Get.php | 1 + app/Command/Money/Lookup.php | 1 + 2 files changed, 2 insertions(+) diff --git a/app/Command/Money/Get.php b/app/Command/Money/Get.php index 9228582..0b2efbd 100644 --- a/app/Command/Money/Get.php +++ b/app/Command/Money/Get.php @@ -41,6 +41,7 @@ class Get extends Command } } $this->updateUF(); + return Command::SUCCESS; } protected function getDates(): array diff --git a/app/Command/Money/Lookup.php b/app/Command/Money/Lookup.php index 43b85b9..0e9ce4d 100644 --- a/app/Command/Money/Lookup.php +++ b/app/Command/Money/Lookup.php @@ -31,6 +31,7 @@ class Lookup extends Command $io->note($this->runGetUF()); } } + return Command::SUCCESS; } protected function hasPendingMoney(): bool From be33305cf130497c2ec2456fbc32cc354444aa05 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Mon, 24 Jul 2023 20:41:38 -0400 Subject: [PATCH 002/163] config --- app_old/.adminer.env.sample | 2 + app_old/.db.env.sample | 4 + app_old/.env.sample | 2 + app_old/.gitignore | 10 + app_old/aldarien/asset/.gitignore | 11 + app_old/aldarien/asset/LICENSE | 21 + app_old/aldarien/asset/README.md | 2 + app_old/aldarien/asset/app/Contract/Asset.php | 21 + .../aldarien/asset/app/Helper/functions.php | 5 + app_old/aldarien/asset/app/Service/Asset.php | 88 ++ app_old/aldarien/asset/composer.json | 26 + app_old/aldarien/asset/phpunit.xml | 17 + app_old/aldarien/asset/tests/AssetTest.php | 25 + app_old/aldarien/config/.gitignore | 13 + app_old/aldarien/config/.travis.yml | 3 + app_old/aldarien/config/LICENSE | 21 + app_old/aldarien/config/README.md | 4 + .../aldarien/config/app/Contract/Config.php | 31 + .../config/app/Contract/YamlWrapper.php | 21 + .../aldarien/config/app/Helper/functions.php | 9 + .../aldarien/config/app/Service/Config.php | 150 ++++ .../aldarien/config/bootstrap/autoload.php | 3 + app_old/aldarien/config/composer.json | 28 + app_old/aldarien/config/phpunit.xml | 17 + app_old/aldarien/config/tests/ConfigTest.php | 90 ++ app_old/aldarien/contract/.gitignore | 6 + app_old/aldarien/contract/LICENSE | 21 + .../contract/app/Definition/Contract.php | 20 + app_old/aldarien/contract/composer.json | 18 + app_old/aldarien/format/.gitignore | 11 + app_old/aldarien/format/LICENSE | 21 + app_old/aldarien/format/README.md | 2 + app_old/aldarien/format/app/Helper/Format.php | 43 + app_old/aldarien/format/composer.json | 23 + app_old/aldarien/format/config/app.php | 5 + app_old/aldarien/format/phpunit.xml | 17 + app_old/aldarien/format/tests/FormatTest.php | 59 ++ app_old/aldarien/response/.gitignore | 7 + app_old/aldarien/response/LICENSE | 21 + app_old/aldarien/response/README.md | 2 + .../response/app/Contract/Response.php | 27 + .../response/app/Helper/functions.php | 11 + .../response/app/Service/Response.php | 62 ++ .../aldarien/response/bootstrap/autoload.php | 3 + app_old/aldarien/response/composer.json | 26 + app_old/aldarien/response/phpunit.xml | 17 + .../aldarien/response/tests/ResponseTest.php | 22 + app_old/aldarien/root/.gitignore | 5 + app_old/aldarien/root/LICENSE | 21 + app_old/aldarien/root/README.md | 22 + .../aldarien/root/app/Helper/functions.php | 5 + app_old/aldarien/root/composer.json | 21 + app_old/aldarien/root/phpunit.xml | 19 + app_old/aldarien/root/src/Root.php | 48 + app_old/aldarien/root/tests/RootTest.php | 61 ++ app_old/aldarien/session/.gitignore | 11 + app_old/aldarien/session/LICENSE | 21 + app_old/aldarien/session/README.md | 2 + .../aldarien/session/app/Contract/Session.php | 29 + app_old/aldarien/session/composer.json | 24 + app_old/aldarien/url/.gitignore | 12 + app_old/aldarien/url/LICENSE | 21 + app_old/aldarien/url/README.md | 2 + app_old/aldarien/url/app/Contract/URL.php | 21 + app_old/aldarien/url/app/Helper/functions.php | 8 + app_old/aldarien/url/app/Service/URL.php | 83 ++ app_old/aldarien/url/composer.json | 29 + app_old/aldarien/view/.gitignore | 10 + app_old/aldarien/view/LICENSE | 21 + app_old/aldarien/view/README.md | 2 + app_old/aldarien/view/app/Contract/View.php | 30 + .../aldarien/view/app/Helper/functions.php | 5 + app_old/aldarien/view/app/Service/View.php | 27 + app_old/aldarien/view/composer.json | 28 + app_old/aldarien/view/config/locations.php | 8 + app_old/aldarien/view/phpunit.xml | 17 + app_old/aldarien/view/public/index.php | 5 + .../view/resources/views/base.blade.php | 9 + app_old/aldarien/view/tests/ViewTest.php | 22 + app_old/app/Alias/Connection.php | 50 ++ app_old/app/Alias/Excel/Style/Mes.php | 18 + app_old/app/Alias/Format.php | 17 + app_old/app/Alias/Model.php | 87 ++ app_old/app/Alias/NewEstado.php | 21 + app_old/app/Alias/NewModel.php | 9 + app_old/app/Alias/NewTipo.php | 15 + app_old/app/Alias/OldModel.php | 8 + app_old/app/Alias/PHPExcel.php | 155 ++++ app_old/app/Alias/RemoteConnection.php | 17 + app_old/app/Command/Money/Get.php | 87 ++ app_old/app/Command/Money/Lookup.php | 52 ++ app_old/app/Contract/Auth.php | 27 + app_old/app/Contract/Route.php | 27 + app_old/app/Controller/API/Unidades.php | 41 + .../less => app_old/app}/Controller/Admin.php | 0 .../less => app_old/app}/Controller/Ajax.php | 0 app_old/app/Controller/Auth.php | 59 ++ app_old/app/Controller/Bonos.php | 67 ++ .../app}/Controller/Buscar.php | 0 app_old/app/Controller/Cierres.php | 428 +++++++++ .../app}/Controller/Comentarios.php | 0 app_old/app/Controller/Contabilidad.php | 100 +++ .../app}/Controller/Creditos.php | 0 .../app}/Controller/Cuotas.php | 0 .../app}/Controller/Devoluciones.php | 0 .../app}/Controller/Escrituras.php | 0 .../app}/Controller/FormaPago.php | 0 app_old/app/Controller/Home.php | 85 ++ app_old/app/Controller/Informes.php | 830 ++++++++++++++++++ .../app}/Controller/Inmobiliarias.php | 0 .../app}/Controller/Operadores.php | 0 .../less => app_old/app}/Controller/Other.php | 0 .../app}/Controller/Pagares.php | 0 .../less => app_old/app}/Controller/Pagos.php | 0 .../less => app_old/app}/Controller/Pies.php | 0 .../app}/Controller/Postventas.php | 0 app_old/app/Controller/Precios.php | 177 ++++ .../app}/Controller/Propietarios.php | 0 .../app}/Controller/ProyectoTipoUnidades.php | 0 app_old/app/Controller/Proyectos.php | 327 +++++++ .../app}/Controller/Reajustes.php | 0 .../app}/Controller/Registros.php | 0 .../app}/Controller/Subsidios.php | 0 .../less => app_old/app}/Controller/Temas.php | 0 .../app}/Controller/Unidades.php | 0 .../app}/Controller/UnidadesBloqueadas.php | 0 app_old/app/Controller/Ventas.php | 605 +++++++++++++ app_old/app/Definition/Controller.php | 31 + app_old/app/Definition/hasEstado.php | 38 + app_old/app/Definition/hasRUT.php | 20 + app_old/app/Exception/PropertyNotFound.php | 16 + app_old/app/Helper/Color.php | 169 ++++ app_old/app/Helper/Line.php | 61 ++ app_old/app/Helper/functions.php | 128 +++ app_old/app/Middleware/Auth.php | 38 + app_old/app/Service/Auth.php | 165 ++++ app_old/app/Service/Borrador.php | 118 +++ app_old/app/Service/DBToModel.php | 158 ++++ app_old/app/Service/Factory.php | 204 +++++ app_old/app/Service/Informador.php | 463 ++++++++++ .../Service/Informe/Contabilidad/Resumen.php | 190 ++++ app_old/app/Service/Informe/Informe.php | 55 ++ app_old/app/Service/Money.php | 55 ++ app_old/app/Service/Register.php | 34 + app_old/app/Service/Remote.php | 19 + app_old/app/Service/Replacer.php | 127 +++ app_old/app/Service/Route.php | 131 +++ app_old/bin/Pipfile | 12 + app_old/bin/console | 3 + app_old/bin/index.php | 8 + app_old/bin/informes/Pipfile | 16 + app_old/bin/informes/app.py | 14 + app_old/bin/informes/controllers/ventas.py | 141 +++ app_old/bootstrap/autoload.php | 8 + app_old/bootstrap/database.php | 29 + app_old/bootstrap/dotenv.php | 12 + app_old/bootstrap/errors.php | 7 + app_old/bootstrap/logs.php | 26 + app_old/bootstrap/routes.php | 21 + setup/cli.app.php => app_old/cli/app.php | 0 {setup => app_old/cli}/cli/config.php | 0 {setup => app_old/cli}/cli/middlewares.php | 0 {setup => app_old/cli}/cli/setups.php | 11 +- {setup => app_old/cli}/composer.php | 0 app_old/composer.json | 69 ++ app_old/config/app.php | 9 + app_old/config/databases.php | 24 + app_old/config/incoviba.php | 6 + app_old/config/locations.php | 16 + app_old/fontify.json | 7 + .../incoviba}/modelos/.gitignore | 0 .../incoviba}/modelos/common/Alias/Model.php | 0 .../modelos/common/Alias/NewEstado.php | 0 .../modelos/common/Alias/NewModel.php | 0 .../modelos/common/Alias/NewTipo.php | 0 .../modelos/common/Alias/OldModel.php | 0 .../modelos/common/Factory/Model.php | 0 .../incoviba}/modelos/composer.json | 0 .../incoviba}/modelos/src/common/Action.php | 0 .../incoviba}/modelos/src/common/Auth.php | 0 .../incoviba}/modelos/src/common/Location.php | 0 .../modelos/src/common/Permission.php | 0 .../incoviba}/modelos/src/common/Registry.php | 0 .../modelos/src/common/RegistryData.php | 0 .../incoviba}/modelos/src/common/Role.php | 0 .../incoviba}/modelos/src/common/User.php | 0 .../incoviba}/modelos/src/common/UserRole.php | 0 .../modelos/src/nuevo/Common/Banco.php | 0 .../modelos/src/nuevo/Common/Comuna.php | 0 .../modelos/src/nuevo/Common/Direccion.php | 0 .../incoviba}/modelos/src/nuevo/Common/M2.php | 0 .../modelos/src/nuevo/Common/Provincia.php | 0 .../modelos/src/nuevo/Common/Region.php | 0 .../incoviba}/modelos/src/nuevo/Common/UF.php | 0 .../modelos/src/nuevo/Inmobiliaria/Agente.php | 0 .../Inmobiliaria/CategoriaCuentaContable.php | 0 .../modelos/src/nuevo/Inmobiliaria/Cobro.php | 0 .../src/nuevo/Inmobiliaria/Contrato.php | 0 .../modelos/src/nuevo/Inmobiliaria/Cuenta.php | 0 .../src/nuevo/Inmobiliaria/CuentaContable.php | 0 .../src/nuevo/Inmobiliaria/EstadoCobro.php | 0 .../src/nuevo/Inmobiliaria/Inmobiliaria.php | 0 .../src/nuevo/Inmobiliaria/Participacion.php | 0 .../src/nuevo/Inmobiliaria/Representante.php | 0 .../modelos/src/nuevo/Inmobiliaria/Socio.php | 0 .../src/nuevo/Inmobiliaria/TipoAgente.php | 0 .../src/nuevo/Inmobiliaria/TipoCobro.php | 0 .../src/nuevo/Inmobiliaria/TipoContrato.php | 0 .../nuevo/Inmobiliaria/TipoEstadoCobro.php | 0 .../Inmobiliaria/TransaccionContable.php | 0 .../src/nuevo/Proyecto/EstadoProyecto.php | 0 .../modelos/src/nuevo/Proyecto/Etapa.php | 0 .../modelos/src/nuevo/Proyecto/Participe.php | 0 .../modelos/src/nuevo/Proyecto/Proyecto.php | 0 .../src/nuevo/Proyecto/ProyectoParticipe.php | 0 .../modelos/src/nuevo/Proyecto/Tema.php | 0 .../src/nuevo/Proyecto/TipoEstadoProyecto.php | 0 .../modelos/src/nuevo/Proyecto/TipoUnidad.php | 0 .../src/nuevo/Proyecto/UnidadProyecto.php | 0 .../modelos/src/nuevo/Venta/Cierre.php | 0 .../modelos/src/nuevo/Venta/Comentario.php | 0 .../modelos/src/nuevo/Venta/Cuota.php | 0 .../modelos/src/nuevo/Venta/Entrega.php | 0 .../modelos/src/nuevo/Venta/EstadoCierre.php | 0 .../src/nuevo/Venta/EstadoObservacion.php | 0 .../modelos/src/nuevo/Venta/EstadoPago.php | 0 .../src/nuevo/Venta/EstadoPostventa.php | 0 .../modelos/src/nuevo/Venta/EstadoVenta.php | 0 .../modelos/src/nuevo/Venta/FondoVenta.php | 0 .../modelos/src/nuevo/Venta/FormaPago.php | 0 .../modelos/src/nuevo/Venta/Medicion.php | 0 .../modelos/src/nuevo/Venta/Observacion.php | 0 .../modelos/src/nuevo/Venta/Pago.php | 0 .../incoviba}/modelos/src/nuevo/Venta/Pie.php | 0 .../modelos/src/nuevo/Venta/Postventa.php | 0 .../src/nuevo/Venta/PostventaObservacion.php | 0 .../modelos/src/nuevo/Venta/Premio.php | 0 .../modelos/src/nuevo/Venta/Propiedad.php | 0 .../modelos/src/nuevo/Venta/Propietario.php | 0 .../src/nuevo/Venta/ProyectoTipoMedicion.php | 0 .../modelos/src/nuevo/Venta/Reserva.php | 0 .../src/nuevo/Venta/TipoEstadoCierre.php | 0 .../src/nuevo/Venta/TipoEstadoObservacion.php | 0 .../src/nuevo/Venta/TipoEstadoPago.php | 0 .../src/nuevo/Venta/TipoEstadoPostventa.php | 0 .../src/nuevo/Venta/TipoEstadoVenta.php | 0 .../modelos/src/nuevo/Venta/TipoFondo.php | 0 .../modelos/src/nuevo/Venta/TipoMedicion.php | 0 .../modelos/src/nuevo/Venta/TipoPago.php | 0 .../modelos/src/nuevo/Venta/TipoPremio.php | 0 .../modelos/src/nuevo/Venta/Unidad.php | 0 .../src/nuevo/Venta/UnidadPropiedad.php | 0 .../modelos/src/nuevo/Venta/UnidadReserva.php | 0 .../modelos/src/nuevo/Venta/Venta.php | 0 .../modelos/src/old/Common/Banco.php | 0 .../modelos/src/old/Common/Comuna.php | 0 .../modelos/src/old/Common/Direccion.php | 0 .../modelos/src/old/Common/Provincia.php | 0 .../modelos/src/old/Common/Region.php | 0 .../modelos/src/old/Inmobiliaria/Cuenta.php | 0 .../src/old/Inmobiliaria/Inmobiliaria.php | 0 .../Inmobiliaria/RelacionInmobiliarias.php | 0 .../src/old/Inmobiliaria/TipoSociedad.php | 0 .../modelos/src/old/Proyecto/Agente.php | 0 .../modelos/src/old/Proyecto/AgenteTipo.php | 0 .../src/old/Proyecto/AvanceConstruccion.php | 0 .../modelos/src/old/Proyecto/Cobro.php | 0 .../modelos/src/old/Proyecto/Costo.php | 0 .../modelos/src/old/Proyecto/EstadoCobro.php | 0 .../src/old/Proyecto/EstadoProyecto.php | 0 .../src/old/Proyecto/EstadoProyectoAgente.php | 0 .../src/old/Proyecto/EtapaProyecto.php | 0 .../modelos/src/old/Proyecto/Pagare.php | 0 .../modelos/src/old/Proyecto/Proyectista.php | 0 .../modelos/src/old/Proyecto/Proyectistas.php | 0 .../modelos/src/old/Proyecto/Proyecto.php | 0 .../src/old/Proyecto/ProyectoAgente.php | 0 .../src/old/Proyecto/ProyectoTipoUnidad.php | 0 .../src/old/Proyecto/RelacionAgentes.php | 0 .../src/old/Proyecto/RenovacionPagare.php | 0 .../modelos/src/old/Proyecto/TipoAgente.php | 0 .../modelos/src/old/Proyecto/TipoCobro.php | 0 .../modelos/src/old/Proyecto/TipoElemento.php | 0 .../src/old/Proyecto/TipoEstadoCobro.php | 0 .../src/old/Proyecto/TipoEstadoProyecto.php | 0 .../old/Proyecto/TipoEstadoProyectoAgente.php | 0 .../src/old/Proyecto/TipoMonedaPagare.php | 0 .../src/old/Proyecto/TipoProyectista.php | 0 .../src/old/Proyecto/TipoTipologia.php | 0 .../modelos/src/old/Proyecto/Tipologia.php | 0 .../modelos/src/old/Venta/BonoPie.php | 0 .../modelos/src/old/Venta/Cierre.php | 0 .../modelos/src/old/Venta/Comentario.php | 0 .../modelos/src/old/Venta/Credito.php | 0 .../incoviba}/modelos/src/old/Venta/Cuota.php | 0 .../modelos/src/old/Venta/Entrega.php | 0 .../modelos/src/old/Venta/Escritura.php | 0 .../modelos/src/old/Venta/EstadoCierre.php | 0 .../modelos/src/old/Venta/EstadoPago.php | 0 .../modelos/src/old/Venta/EstadoPrecio.php | 0 .../modelos/src/old/Venta/EstadoProblema.php | 0 .../src/old/Venta/EstadoUnidadBloqueada.php | 0 .../modelos/src/old/Venta/EstadoVenta.php | 0 .../incoviba}/modelos/src/old/Venta/Pago.php | 0 .../incoviba}/modelos/src/old/Venta/Pie.php | 0 .../modelos/src/old/Venta/Precio.php | 0 .../modelos/src/old/Venta/Problema.php | 0 .../modelos/src/old/Venta/Promocion.php | 0 .../modelos/src/old/Venta/PromocionVenta.php | 0 .../modelos/src/old/Venta/Propiedad.php | 0 .../modelos/src/old/Venta/PropiedadUnidad.php | 0 .../modelos/src/old/Venta/Propietario.php | 0 .../modelos/src/old/Venta/Subsidio.php | 0 .../src/old/Venta/TipoEstadoCierre.php | 0 .../modelos/src/old/Venta/TipoEstadoPago.php | 0 .../src/old/Venta/TipoEstadoPrecio.php | 0 .../old/Venta/TipoEstadoUnidadBloqueada.php | 0 .../modelos/src/old/Venta/TipoEstadoVenta.php | 0 .../modelos/src/old/Venta/TipoPago.php | 0 .../modelos/src/old/Venta/TipoUnidad.php | 0 .../modelos/src/old/Venta/TipoValorCierre.php | 0 .../modelos/src/old/Venta/Unidad.php | 0 .../modelos/src/old/Venta/UnidadBloqueada.php | 0 .../modelos/src/old/Venta/UnidadCierre.php | 0 .../modelos/src/old/Venta/ValorCierre.php | 0 .../incoviba}/modelos/src/old/Venta/Venta.php | 0 .../modelos/src/old/Venta/Venta.php.save | 0 package.json => app_old/package.json | 0 {public => app_old/public}/Pipfile | 0 {public => app_old/public}/api/.htaccess | 0 {public => app_old/public}/api/index.php | 0 {public => app_old/public}/api/keys | 0 {public => app_old/public}/css/app.css | 0 {public => app_old/public}/css/custom.css | 0 .../public}/fonts/FontAwesome.otf | Bin .../public}/fonts/fontawesome-webfont.eot | Bin .../public}/fonts/fontawesome-webfont.svg | 0 .../public}/fonts/fontawesome-webfont.ttf | Bin .../public}/fonts/fontawesome-webfont.woff | Bin .../public}/fonts/fontawesome-webfont.woff2 | Bin .../fonts/glyphicons-halflings-regular.eot | Bin .../fonts/glyphicons-halflings-regular.svg | 0 .../fonts/glyphicons-halflings-regular.ttf | Bin .../fonts/glyphicons-halflings-regular.woff | Bin .../fonts/glyphicons-halflings-regular.woff2 | Bin .../public}/images/Isotipo 16.png | Bin .../public}/images/Isotipo 32.png | Bin .../public}/images/Isotipo 64.png | Bin .../public}/images/logo_cabezal.png | Bin app_old/public/index.php | 8 + .../index.php => app_old/public/index.php.old | 0 .../public}/install/create_admin.php | 0 .../public}/install/create_guest.php | 0 .../public}/install/create_user_base.php | 0 .../public}/install/end_install.php | 0 {public => app_old/public}/install/index.php | 0 .../public}/install/log_locations.php | 0 .../public}/install/next_step.php | 0 {public => app_old/public}/js/admin.js | 0 {public => app_old/public}/js/app.js | 0 .../public}/js/ventas/pies/cuotas/add.js | 0 {public => app_old/public}/links.log | 0 {public => app_old/public}/precios.csv | 0 {resources => app_old/resources}/js/app.js | 0 .../resources}/js/binaryIndexOf.js | 0 .../resources}/js/bootstrap.js | 0 {resources => app_old/resources}/js/chart.js | 0 .../resources}/js/jquery.filterTable.js | 0 app_old/resources/less/Controller/Admin.php | 233 +++++ app_old/resources/less/Controller/Ajax.php | 215 +++++ .../resources}/less/Controller/Auth.php | 0 .../resources}/less/Controller/Bonos.php | 0 app_old/resources/less/Controller/Buscar.php | 340 +++++++ .../resources}/less/Controller/Cierres.php | 0 .../resources/less/Controller/Comentarios.php | 39 + .../less/Controller/Contabilidad.php | 0 .../resources/less/Controller/Creditos.php | 207 +++++ app_old/resources/less/Controller/Cuotas.php | 230 +++++ .../less/Controller/Devoluciones.php | 19 + .../resources/less/Controller/Escrituras.php | 212 +++++ .../resources/less/Controller/FormaPago.php | 98 +++ .../resources}/less/Controller/Informes.php | 9 +- .../less/Controller/Informes.php.save | 0 .../less/Controller/Inmobiliarias.php | 74 ++ .../resources/less/Controller/Operadores.php | 47 + app_old/resources/less/Controller/Other.php | 71 ++ app_old/resources/less/Controller/Pagares.php | 271 ++++++ app_old/resources/less/Controller/Pagos.php | 358 ++++++++ app_old/resources/less/Controller/Pies.php | 104 +++ .../resources/less/Controller/Postventas.php | 69 ++ .../resources}/less/Controller/Precios.php | 0 .../less/Controller/Propietarios.php | 129 +++ .../less/Controller/ProyectoTipoUnidades.php | 77 ++ .../resources}/less/Controller/Proyectos.php | 0 .../resources/less/Controller/Reajustes.php | 90 ++ .../resources/less/Controller/Registros.php | 39 + .../resources/less/Controller/Subsidios.php | 184 ++++ app_old/resources/less/Controller/Temas.php | 111 +++ .../resources/less/Controller/Unidades.php | 126 +++ .../less/Controller/UnidadesBloqueadas.php | 83 ++ .../resources}/less/Controller/Ventas.php | 0 .../resources}/less/_variables.less | 0 .../resources}/less/app.less | 0 .../resources}/less/bootstrap.less | 0 .../resources}/less/custom.less | 0 .../resources}/less/print.less | 0 .../resources}/less/submenu.less | 0 .../resources}/routes/api.php | 0 .../resources}/routes/api/unidades.php | 0 .../resources}/routes/cli.php | 0 app_old/resources/routes/ui/01_auth.php | 15 + app_old/resources/routes/ui/99_base.php | 4 + .../resources}/views/admin/base.blade.php | 0 .../resources}/views/admin/menu.blade.php | 0 .../views/admin/menu/models.blade.php | 0 .../views/admin/menu/registros.blade.php | 0 .../views/admin/menu/roles.blade.php | 0 .../views/admin/menu/users.blade.php | 0 .../resources}/views/admin/models.blade.php | 0 .../registros/controles_avance.blade.php | 0 .../views/admin/registros/list.blade.php | 0 .../views/admin/registros/show.blade.php | 0 .../views/admin/roles/add.blade.php | 0 .../admin/roles/add_permissions.blade.php | 0 .../views/admin/roles/add_users.blade.php | 0 .../views/admin/roles/list.blade.php | 0 .../views/admin/roles/show.blade.php | 0 .../views/admin/users/add.blade.php | 0 .../views/admin/users/add_role.blade.php | 0 .../views/admin/users/list.blade.php | 0 .../views/admin/users/show.blade.php | 0 .../resources}/views/auth/base.blade.php | 12 +- .../views/auth/change_pass.blade.php | 0 app_old/resources/views/auth/login.blade.php | 17 + .../resources}/views/benchmark.blade.php | 0 .../resources}/views/buscar/buscar.blade.php | 0 .../views/buscar/resultado.blade.php | 0 .../resources}/views/calendario.blade.php | 0 .../resources}/views/cierres.blade.php | 0 .../resources}/views/construccion.blade.php | 0 .../views/contabilidad/pago.blade.php | 0 .../views/contabilidad/pagos.blade.php | 0 .../resources}/views/form/fecha.blade.php | 0 .../resources}/views/guest.blade.php | 14 +- .../resources}/views/home.blade.php | 2 +- .../views/informes/comisiones.blade.php | 0 .../views/informes/contabilidad.blade.php | 0 .../views/informes/escrituras.blade.php | 0 .../views/informes/gantt_entregas.blade.php | 0 .../views/informes/para_comision.blade.php | 0 .../views/informes/proyectos.blade.php | 0 .../views/informes/resciliaciones.blade.php | 0 .../informes/resumen_contabilidad.blade.php | 0 .../views/informes/ventas.blade.php | 0 .../views/inmobiliarias/add.blade.php | 0 .../views/inmobiliarias/edit.blade.php | 0 .../views/inmobiliarias/list.blade.php | 0 .../views/inmobiliarias/show.blade.php | 0 .../resources}/views/install/admin.blade.php | 0 .../resources}/views/install/base.blade.php | 0 .../resources}/views/install/end.blade.php | 0 .../resources}/views/install/start.blade.php | 0 .../resources}/views/layout/base.blade.php | 0 .../resources}/views/layout/footer.blade.php | 0 .../resources}/views/layout/header.blade.php | 0 .../views/layout/icons/abonar.blade.php | 0 .../views/layout/icons/add.blade.php | 0 .../views/layout/icons/edit.blade.php | 0 .../views/layout/icons/pagar.blade.php | 0 .../views/layout/icons/remove.blade.php | 0 .../views/layout/icons/show.blade.php | 0 .../resources}/views/layout/menu.blade.php | 2 +- .../views/layout/menu.blade.php.save | 0 .../views/layout/menu/herramientas.blade.php | 0 .../views/layout/menu/informes.blade.php | 0 .../views/layout/menu/inmobiliarias.blade.php | 0 .../views/layout/menu/login.blade.php | 8 + .../views/layout/menu/operadores.blade.php | 0 .../views/layout/menu/proyectos.blade.php | 0 .../views/layout/menu/ventas.blade.php | 0 .../views/other/capacidades.blade.php | 0 .../views/other/entregar_multiple.blade.php | 0 .../views/print/devolucion.blade.php | 0 .../resources}/views/proyectos/add.blade.php | 0 .../views/proyectos/advance.blade.php | 0 .../views/proyectos/avance.blade.php | 0 .../views/proyectos/avances/edit.blade.php | 0 .../views/proyectos/avances_row.blade.php | 0 .../views/proyectos/construccion.blade.php | 0 .../views/proyectos/disponibles.blade.php | 0 .../views/proyectos/estimado.blade.php | 0 .../views/proyectos/historia.blade.php | 0 .../views/proyectos/historia.blade.php.old | 0 .../resources}/views/proyectos/list.blade.php | 0 .../views/proyectos/operadores/add.blade.php | 0 .../views/proyectos/pagares/add.blade.php | 0 .../pagares/add_renovacion.blade.php | 0 .../views/proyectos/pagares/edit.blade.php | 0 .../pagares/edit_renovacion.blade.php | 0 .../views/proyectos/pagares/show.blade.php | 0 .../views/proyectos/por_vender.blade.php | 0 .../views/proyectos/reservas/base.blade.php | 0 .../resources}/views/proyectos/show.blade.php | 0 .../views/proyectos/superficies.blade.php | 0 .../proyectos/tipo_unidades/add.blade.php | 0 .../proyectos/tipo_unidades/edit.blade.php | 0 .../views/proyectos/unidades/add.blade.php | 0 .../views/proyectos/unidades/add2.blade.php | 0 .../views/proyectos/unidades/assign.blade.php | 0 .../views/proyectos/unidades/edit.blade.php | 0 .../views/proyectos/unidades/list.blade.php | 0 .../proyectos/unidades/proyectos.blade.php | 0 .../views/proyectos/ventas.blade.php | 0 .../resources}/views/temas/add.blade.php | 0 .../resources}/views/temas/edit.blade.php | 0 .../resources}/views/temas/list.blade.php | 0 .../resources}/views/ventas/add.blade.php | 0 .../views/ventas/archivar.blade.php | 0 .../views/ventas/bonos/add.blade.php | 0 .../views/ventas/bonos/edit.blade.php | 0 .../resources}/views/ventas/ceder.blade.php | 0 .../views/ventas/cierres/add.blade.php | 0 .../views/ventas/cierres/edit.blade.php | 0 .../views/ventas/cierres/evaluar.blade.php | 0 .../views/ventas/cierres/list.blade.php | 0 .../views/ventas/cierres/show.blade.php | 0 .../views/ventas/comentarios/add.blade.php | 0 .../views/ventas/consolidacion/pago.blade.php | 0 .../ventas/consolidacion/proyectos.blade.php | 0 .../views/ventas/consolidacion/show.blade.php | 0 .../views/ventas/creditos/abonar.blade.php | 0 .../views/ventas/creditos/add.blade.php | 0 .../views/ventas/creditos/edit.blade.php | 0 .../views/ventas/creditos/pagar.blade.php | 0 .../ventas/creditos/pendientes.blade.php | 0 .../views/ventas/creditos/show.blade.php | 0 .../resources}/views/ventas/desist.blade.php | 0 .../views/ventas/devolucion.blade.php | 0 .../resources}/views/ventas/edit.blade.php | 0 .../views/ventas/entregar.blade.php | 0 .../views/ventas/escrituras/abonar.blade.php | 0 .../views/ventas/escrituras/add.blade.php | 0 .../views/ventas/escrituras/edit.blade.php | 0 .../views/ventas/escrituras/informe.blade.php | 0 .../views/ventas/escrituras/pagar.blade.php | 0 .../resources}/views/ventas/firmar.blade.php | 0 .../views/ventas/forma_pago.blade.php | 0 .../views/ventas/forma_pago/edit.blade.php | 0 .../resources}/views/ventas/list.blade.php | 0 .../operadores/unidades/bloquear.blade.php | 0 .../ventas/operadores/unidades/list.blade.php | 0 .../views/ventas/pagos/edit.blade.php | 0 .../views/ventas/pagos/pendientes.blade.php | 0 .../views/ventas/pagos/show.blade.php | 0 .../views/ventas/pies/cuotas/abonar.blade.php | 0 .../views/ventas/pies/cuotas/add.blade.php | 0 .../views/ventas/pies/cuotas/edit.blade.php | 0 .../views/ventas/pies/cuotas/estado.blade.php | 0 .../ventas/pies/cuotas/pendientes.blade.php | 0 .../views/ventas/pies/cuotas/show.blade.php | 0 .../views/ventas/pies/edit.blade.php | 0 .../views/ventas/pies/reajustar.blade.php | 0 .../ventas/pies/reajustes/abonar.blade.php | 0 .../ventas/pies/reajustes/edit.blade.php | 0 .../ventas/pies/reajustes/pagar.blade.php | 0 .../views/ventas/pies/resumen.blade.php | 0 .../views/ventas/pies/totales.blade.php | 0 .../views/ventas/postventas/add.blade.php | 0 .../views/ventas/postventas/show.blade.php | 0 .../views/ventas/precios/add.blade.php | 0 .../views/ventas/precios/import.blade.php | 0 .../views/ventas/precios/list.blade.php | 0 .../views/ventas/precios/proyectos.blade.php | 0 .../views/ventas/propietarios/edit.blade.php | 0 .../views/ventas/proyectos.blade.php | 0 .../views/ventas/resciliaciones.blade.php | 0 .../resources}/views/ventas/show.blade.php | 0 .../views/ventas/sort_title.blade.php | 0 .../views/ventas/subsidios/abonar.blade.php | 0 .../views/ventas/subsidios/add.blade.php | 0 .../views/ventas/subsidios/edit.blade.php | 0 .../views/ventas/subsidios/pagar.blade.php | 0 {setup => app_old/setup}/api/config.php | 0 {setup => app_old/setup}/api/setups.php | 0 app_old/setup/app.php | 61 ++ {setup => app_old/setup}/common/config.php | 0 app_old/setup/composer.php | 6 + {setup => app_old/setup}/database.php | 0 {setup => app_old/setup}/env/config.php | 0 {setup => app_old/setup}/router.php | 0 {setup => app_old/setup}/settings/01_env.php | 0 .../setup}/settings/02_common.php | 0 {setup => app_old/setup}/settings/03_api.php | 0 {setup => app_old/setup}/settings/04_ui.php | 0 {setup => app_old/setup}/setups/04_ui.php | 0 app_old/ui/app.php | 45 + app_old/ui/composer.php | 6 + app_old/ui/middlewares/01_auth.php | 2 + app_old/ui/middlewares/02_databases.php | 20 + app_old/ui/middlewares/98_logs.php | 2 + app_old/ui/middlewares/99_routes.php | 15 + app_old/ui/settings/01_env.php | 4 + app_old/ui/settings/02_folders.php | 12 + app_old/ui/settings/03_urls.php | 8 + app_old/ui/settings/04_databases.php | 20 + app_old/ui/setups/01_views.php | 20 + app_old/ui/setups/03_services.php | 8 + app_old/ui/setups/98_logs.php | 30 + .../webpack.config.js | 0 resources/views/auth/login.blade.php | 17 - resources/views/layout/menu/login.blade.php | 8 - setup/app.php | 57 -- 612 files changed, 11436 insertions(+), 107 deletions(-) create mode 100644 app_old/.adminer.env.sample create mode 100644 app_old/.db.env.sample create mode 100644 app_old/.env.sample create mode 100644 app_old/.gitignore create mode 100644 app_old/aldarien/asset/.gitignore create mode 100644 app_old/aldarien/asset/LICENSE create mode 100644 app_old/aldarien/asset/README.md create mode 100644 app_old/aldarien/asset/app/Contract/Asset.php create mode 100644 app_old/aldarien/asset/app/Helper/functions.php create mode 100644 app_old/aldarien/asset/app/Service/Asset.php create mode 100644 app_old/aldarien/asset/composer.json create mode 100644 app_old/aldarien/asset/phpunit.xml create mode 100644 app_old/aldarien/asset/tests/AssetTest.php create mode 100644 app_old/aldarien/config/.gitignore create mode 100644 app_old/aldarien/config/.travis.yml create mode 100644 app_old/aldarien/config/LICENSE create mode 100644 app_old/aldarien/config/README.md create mode 100644 app_old/aldarien/config/app/Contract/Config.php create mode 100644 app_old/aldarien/config/app/Contract/YamlWrapper.php create mode 100644 app_old/aldarien/config/app/Helper/functions.php create mode 100644 app_old/aldarien/config/app/Service/Config.php create mode 100644 app_old/aldarien/config/bootstrap/autoload.php create mode 100644 app_old/aldarien/config/composer.json create mode 100644 app_old/aldarien/config/phpunit.xml create mode 100644 app_old/aldarien/config/tests/ConfigTest.php create mode 100644 app_old/aldarien/contract/.gitignore create mode 100644 app_old/aldarien/contract/LICENSE create mode 100644 app_old/aldarien/contract/app/Definition/Contract.php create mode 100644 app_old/aldarien/contract/composer.json create mode 100644 app_old/aldarien/format/.gitignore create mode 100644 app_old/aldarien/format/LICENSE create mode 100644 app_old/aldarien/format/README.md create mode 100644 app_old/aldarien/format/app/Helper/Format.php create mode 100644 app_old/aldarien/format/composer.json create mode 100644 app_old/aldarien/format/config/app.php create mode 100644 app_old/aldarien/format/phpunit.xml create mode 100644 app_old/aldarien/format/tests/FormatTest.php create mode 100644 app_old/aldarien/response/.gitignore create mode 100644 app_old/aldarien/response/LICENSE create mode 100644 app_old/aldarien/response/README.md create mode 100644 app_old/aldarien/response/app/Contract/Response.php create mode 100644 app_old/aldarien/response/app/Helper/functions.php create mode 100644 app_old/aldarien/response/app/Service/Response.php create mode 100644 app_old/aldarien/response/bootstrap/autoload.php create mode 100644 app_old/aldarien/response/composer.json create mode 100644 app_old/aldarien/response/phpunit.xml create mode 100644 app_old/aldarien/response/tests/ResponseTest.php create mode 100644 app_old/aldarien/root/.gitignore create mode 100644 app_old/aldarien/root/LICENSE create mode 100644 app_old/aldarien/root/README.md create mode 100644 app_old/aldarien/root/app/Helper/functions.php create mode 100644 app_old/aldarien/root/composer.json create mode 100644 app_old/aldarien/root/phpunit.xml create mode 100644 app_old/aldarien/root/src/Root.php create mode 100644 app_old/aldarien/root/tests/RootTest.php create mode 100644 app_old/aldarien/session/.gitignore create mode 100644 app_old/aldarien/session/LICENSE create mode 100644 app_old/aldarien/session/README.md create mode 100644 app_old/aldarien/session/app/Contract/Session.php create mode 100644 app_old/aldarien/session/composer.json create mode 100644 app_old/aldarien/url/.gitignore create mode 100644 app_old/aldarien/url/LICENSE create mode 100644 app_old/aldarien/url/README.md create mode 100644 app_old/aldarien/url/app/Contract/URL.php create mode 100644 app_old/aldarien/url/app/Helper/functions.php create mode 100644 app_old/aldarien/url/app/Service/URL.php create mode 100644 app_old/aldarien/url/composer.json create mode 100644 app_old/aldarien/view/.gitignore create mode 100644 app_old/aldarien/view/LICENSE create mode 100644 app_old/aldarien/view/README.md create mode 100644 app_old/aldarien/view/app/Contract/View.php create mode 100644 app_old/aldarien/view/app/Helper/functions.php create mode 100644 app_old/aldarien/view/app/Service/View.php create mode 100644 app_old/aldarien/view/composer.json create mode 100644 app_old/aldarien/view/config/locations.php create mode 100644 app_old/aldarien/view/phpunit.xml create mode 100644 app_old/aldarien/view/public/index.php create mode 100644 app_old/aldarien/view/resources/views/base.blade.php create mode 100644 app_old/aldarien/view/tests/ViewTest.php create mode 100644 app_old/app/Alias/Connection.php create mode 100644 app_old/app/Alias/Excel/Style/Mes.php create mode 100644 app_old/app/Alias/Format.php create mode 100644 app_old/app/Alias/Model.php create mode 100644 app_old/app/Alias/NewEstado.php create mode 100644 app_old/app/Alias/NewModel.php create mode 100644 app_old/app/Alias/NewTipo.php create mode 100644 app_old/app/Alias/OldModel.php create mode 100644 app_old/app/Alias/PHPExcel.php create mode 100644 app_old/app/Alias/RemoteConnection.php create mode 100644 app_old/app/Command/Money/Get.php create mode 100644 app_old/app/Command/Money/Lookup.php create mode 100644 app_old/app/Contract/Auth.php create mode 100644 app_old/app/Contract/Route.php create mode 100644 app_old/app/Controller/API/Unidades.php rename {resources/less => app_old/app}/Controller/Admin.php (100%) rename {resources/less => app_old/app}/Controller/Ajax.php (100%) create mode 100644 app_old/app/Controller/Auth.php create mode 100644 app_old/app/Controller/Bonos.php rename {resources/less => app_old/app}/Controller/Buscar.php (100%) create mode 100644 app_old/app/Controller/Cierres.php rename {resources/less => app_old/app}/Controller/Comentarios.php (100%) create mode 100644 app_old/app/Controller/Contabilidad.php rename {resources/less => app_old/app}/Controller/Creditos.php (100%) rename {resources/less => app_old/app}/Controller/Cuotas.php (100%) rename {resources/less => app_old/app}/Controller/Devoluciones.php (100%) rename {resources/less => app_old/app}/Controller/Escrituras.php (100%) rename {resources/less => app_old/app}/Controller/FormaPago.php (100%) create mode 100644 app_old/app/Controller/Home.php create mode 100644 app_old/app/Controller/Informes.php rename {resources/less => app_old/app}/Controller/Inmobiliarias.php (100%) rename {resources/less => app_old/app}/Controller/Operadores.php (100%) rename {resources/less => app_old/app}/Controller/Other.php (100%) rename {resources/less => app_old/app}/Controller/Pagares.php (100%) rename {resources/less => app_old/app}/Controller/Pagos.php (100%) rename {resources/less => app_old/app}/Controller/Pies.php (100%) rename {resources/less => app_old/app}/Controller/Postventas.php (100%) create mode 100644 app_old/app/Controller/Precios.php rename {resources/less => app_old/app}/Controller/Propietarios.php (100%) rename {resources/less => app_old/app}/Controller/ProyectoTipoUnidades.php (100%) create mode 100644 app_old/app/Controller/Proyectos.php rename {resources/less => app_old/app}/Controller/Reajustes.php (100%) rename {resources/less => app_old/app}/Controller/Registros.php (100%) rename {resources/less => app_old/app}/Controller/Subsidios.php (100%) rename {resources/less => app_old/app}/Controller/Temas.php (100%) rename {resources/less => app_old/app}/Controller/Unidades.php (100%) rename {resources/less => app_old/app}/Controller/UnidadesBloqueadas.php (100%) create mode 100644 app_old/app/Controller/Ventas.php create mode 100644 app_old/app/Definition/Controller.php create mode 100644 app_old/app/Definition/hasEstado.php create mode 100644 app_old/app/Definition/hasRUT.php create mode 100644 app_old/app/Exception/PropertyNotFound.php create mode 100644 app_old/app/Helper/Color.php create mode 100644 app_old/app/Helper/Line.php create mode 100644 app_old/app/Helper/functions.php create mode 100644 app_old/app/Middleware/Auth.php create mode 100644 app_old/app/Service/Auth.php create mode 100644 app_old/app/Service/Borrador.php create mode 100644 app_old/app/Service/DBToModel.php create mode 100644 app_old/app/Service/Factory.php create mode 100644 app_old/app/Service/Informador.php create mode 100644 app_old/app/Service/Informe/Contabilidad/Resumen.php create mode 100644 app_old/app/Service/Informe/Informe.php create mode 100644 app_old/app/Service/Money.php create mode 100644 app_old/app/Service/Register.php create mode 100644 app_old/app/Service/Remote.php create mode 100644 app_old/app/Service/Replacer.php create mode 100644 app_old/app/Service/Route.php create mode 100644 app_old/bin/Pipfile create mode 100644 app_old/bin/console create mode 100644 app_old/bin/index.php create mode 100644 app_old/bin/informes/Pipfile create mode 100644 app_old/bin/informes/app.py create mode 100644 app_old/bin/informes/controllers/ventas.py create mode 100644 app_old/bootstrap/autoload.php create mode 100644 app_old/bootstrap/database.php create mode 100644 app_old/bootstrap/dotenv.php create mode 100644 app_old/bootstrap/errors.php create mode 100644 app_old/bootstrap/logs.php create mode 100644 app_old/bootstrap/routes.php rename setup/cli.app.php => app_old/cli/app.php (100%) rename {setup => app_old/cli}/cli/config.php (100%) rename {setup => app_old/cli}/cli/middlewares.php (100%) rename {setup => app_old/cli}/cli/setups.php (82%) rename {setup => app_old/cli}/composer.php (100%) create mode 100644 app_old/composer.json create mode 100644 app_old/config/app.php create mode 100644 app_old/config/databases.php create mode 100644 app_old/config/incoviba.php create mode 100644 app_old/config/locations.php create mode 100644 app_old/fontify.json rename {incoviba => app_old/incoviba}/modelos/.gitignore (100%) rename {incoviba => app_old/incoviba}/modelos/common/Alias/Model.php (100%) rename {incoviba => app_old/incoviba}/modelos/common/Alias/NewEstado.php (100%) rename {incoviba => app_old/incoviba}/modelos/common/Alias/NewModel.php (100%) rename {incoviba => app_old/incoviba}/modelos/common/Alias/NewTipo.php (100%) rename {incoviba => app_old/incoviba}/modelos/common/Alias/OldModel.php (100%) rename {incoviba => app_old/incoviba}/modelos/common/Factory/Model.php (100%) rename {incoviba => app_old/incoviba}/modelos/composer.json (100%) rename {incoviba => app_old/incoviba}/modelos/src/common/Action.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/common/Auth.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/common/Location.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/common/Permission.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/common/Registry.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/common/RegistryData.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/common/Role.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/common/User.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/common/UserRole.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Common/Banco.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Common/Comuna.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Common/Direccion.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Common/M2.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Common/Provincia.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Common/Region.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Common/UF.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/Agente.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/CategoriaCuentaContable.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/Cobro.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/Contrato.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/Cuenta.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/CuentaContable.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/EstadoCobro.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/Inmobiliaria.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/Participacion.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/Representante.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/Socio.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/TipoAgente.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/TipoCobro.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/TipoContrato.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/TipoEstadoCobro.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Inmobiliaria/TransaccionContable.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Proyecto/EstadoProyecto.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Proyecto/Etapa.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Proyecto/Participe.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Proyecto/Proyecto.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Proyecto/ProyectoParticipe.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Proyecto/Tema.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Proyecto/TipoEstadoProyecto.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Proyecto/TipoUnidad.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Proyecto/UnidadProyecto.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/Cierre.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/Comentario.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/Cuota.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/Entrega.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/EstadoCierre.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/EstadoObservacion.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/EstadoPago.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/EstadoPostventa.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/EstadoVenta.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/FondoVenta.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/FormaPago.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/Medicion.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/Observacion.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/Pago.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/Pie.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/Postventa.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/PostventaObservacion.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/Premio.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/Propiedad.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/Propietario.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/ProyectoTipoMedicion.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/Reserva.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/TipoEstadoCierre.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/TipoEstadoObservacion.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/TipoEstadoPago.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/TipoEstadoPostventa.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/TipoEstadoVenta.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/TipoFondo.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/TipoMedicion.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/TipoPago.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/TipoPremio.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/Unidad.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/UnidadPropiedad.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/UnidadReserva.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/nuevo/Venta/Venta.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Common/Banco.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Common/Comuna.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Common/Direccion.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Common/Provincia.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Common/Region.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Inmobiliaria/Cuenta.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Inmobiliaria/Inmobiliaria.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Inmobiliaria/RelacionInmobiliarias.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Inmobiliaria/TipoSociedad.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/Agente.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/AgenteTipo.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/AvanceConstruccion.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/Cobro.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/Costo.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/EstadoCobro.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/EstadoProyecto.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/EstadoProyectoAgente.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/EtapaProyecto.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/Pagare.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/Proyectista.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/Proyectistas.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/Proyecto.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/ProyectoAgente.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/ProyectoTipoUnidad.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/RelacionAgentes.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/RenovacionPagare.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/TipoAgente.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/TipoCobro.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/TipoElemento.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/TipoEstadoCobro.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/TipoEstadoProyecto.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/TipoEstadoProyectoAgente.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/TipoMonedaPagare.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/TipoProyectista.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/TipoTipologia.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Proyecto/Tipologia.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/BonoPie.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Cierre.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Comentario.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Credito.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Cuota.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Entrega.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Escritura.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/EstadoCierre.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/EstadoPago.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/EstadoPrecio.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/EstadoProblema.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/EstadoUnidadBloqueada.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/EstadoVenta.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Pago.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Pie.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Precio.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Problema.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Promocion.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/PromocionVenta.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Propiedad.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/PropiedadUnidad.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Propietario.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Subsidio.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/TipoEstadoCierre.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/TipoEstadoPago.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/TipoEstadoPrecio.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/TipoEstadoUnidadBloqueada.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/TipoEstadoVenta.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/TipoPago.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/TipoUnidad.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/TipoValorCierre.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Unidad.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/UnidadBloqueada.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/UnidadCierre.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/ValorCierre.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Venta.php (100%) rename {incoviba => app_old/incoviba}/modelos/src/old/Venta/Venta.php.save (100%) rename package.json => app_old/package.json (100%) rename {public => app_old/public}/Pipfile (100%) rename {public => app_old/public}/api/.htaccess (100%) rename {public => app_old/public}/api/index.php (100%) rename {public => app_old/public}/api/keys (100%) rename {public => app_old/public}/css/app.css (100%) rename {public => app_old/public}/css/custom.css (100%) rename {public => app_old/public}/fonts/FontAwesome.otf (100%) rename {public => app_old/public}/fonts/fontawesome-webfont.eot (100%) rename {public => app_old/public}/fonts/fontawesome-webfont.svg (100%) rename {public => app_old/public}/fonts/fontawesome-webfont.ttf (100%) rename {public => app_old/public}/fonts/fontawesome-webfont.woff (100%) rename {public => app_old/public}/fonts/fontawesome-webfont.woff2 (100%) rename {public => app_old/public}/fonts/glyphicons-halflings-regular.eot (100%) rename {public => app_old/public}/fonts/glyphicons-halflings-regular.svg (100%) rename {public => app_old/public}/fonts/glyphicons-halflings-regular.ttf (100%) rename {public => app_old/public}/fonts/glyphicons-halflings-regular.woff (100%) rename {public => app_old/public}/fonts/glyphicons-halflings-regular.woff2 (100%) rename {public => app_old/public}/images/Isotipo 16.png (100%) rename {public => app_old/public}/images/Isotipo 32.png (100%) rename {public => app_old/public}/images/Isotipo 64.png (100%) rename {public => app_old/public}/images/logo_cabezal.png (100%) create mode 100644 app_old/public/index.php rename public/index.php => app_old/public/index.php.old (100%) rename {public => app_old/public}/install/create_admin.php (100%) rename {public => app_old/public}/install/create_guest.php (100%) rename {public => app_old/public}/install/create_user_base.php (100%) rename {public => app_old/public}/install/end_install.php (100%) rename {public => app_old/public}/install/index.php (100%) rename {public => app_old/public}/install/log_locations.php (100%) rename {public => app_old/public}/install/next_step.php (100%) rename {public => app_old/public}/js/admin.js (100%) rename {public => app_old/public}/js/app.js (100%) rename {public => app_old/public}/js/ventas/pies/cuotas/add.js (100%) rename {public => app_old/public}/links.log (100%) rename {public => app_old/public}/precios.csv (100%) rename {resources => app_old/resources}/js/app.js (100%) rename {resources => app_old/resources}/js/binaryIndexOf.js (100%) rename {resources => app_old/resources}/js/bootstrap.js (100%) rename {resources => app_old/resources}/js/chart.js (100%) rename {resources => app_old/resources}/js/jquery.filterTable.js (100%) create mode 100644 app_old/resources/less/Controller/Admin.php create mode 100644 app_old/resources/less/Controller/Ajax.php rename {resources => app_old/resources}/less/Controller/Auth.php (100%) rename {resources => app_old/resources}/less/Controller/Bonos.php (100%) create mode 100644 app_old/resources/less/Controller/Buscar.php rename {resources => app_old/resources}/less/Controller/Cierres.php (100%) create mode 100644 app_old/resources/less/Controller/Comentarios.php rename {resources => app_old/resources}/less/Controller/Contabilidad.php (100%) create mode 100644 app_old/resources/less/Controller/Creditos.php create mode 100644 app_old/resources/less/Controller/Cuotas.php create mode 100644 app_old/resources/less/Controller/Devoluciones.php create mode 100644 app_old/resources/less/Controller/Escrituras.php create mode 100644 app_old/resources/less/Controller/FormaPago.php rename {resources => app_old/resources}/less/Controller/Informes.php (99%) rename {resources => app_old/resources}/less/Controller/Informes.php.save (100%) create mode 100644 app_old/resources/less/Controller/Inmobiliarias.php create mode 100644 app_old/resources/less/Controller/Operadores.php create mode 100644 app_old/resources/less/Controller/Other.php create mode 100644 app_old/resources/less/Controller/Pagares.php create mode 100644 app_old/resources/less/Controller/Pagos.php create mode 100644 app_old/resources/less/Controller/Pies.php create mode 100644 app_old/resources/less/Controller/Postventas.php rename {resources => app_old/resources}/less/Controller/Precios.php (100%) create mode 100644 app_old/resources/less/Controller/Propietarios.php create mode 100644 app_old/resources/less/Controller/ProyectoTipoUnidades.php rename {resources => app_old/resources}/less/Controller/Proyectos.php (100%) create mode 100644 app_old/resources/less/Controller/Reajustes.php create mode 100644 app_old/resources/less/Controller/Registros.php create mode 100644 app_old/resources/less/Controller/Subsidios.php create mode 100644 app_old/resources/less/Controller/Temas.php create mode 100644 app_old/resources/less/Controller/Unidades.php create mode 100644 app_old/resources/less/Controller/UnidadesBloqueadas.php rename {resources => app_old/resources}/less/Controller/Ventas.php (100%) rename {resources => app_old/resources}/less/_variables.less (100%) rename {resources => app_old/resources}/less/app.less (100%) rename {resources => app_old/resources}/less/bootstrap.less (100%) rename {resources => app_old/resources}/less/custom.less (100%) rename {resources => app_old/resources}/less/print.less (100%) rename {resources => app_old/resources}/less/submenu.less (100%) rename {resources => app_old/resources}/routes/api.php (100%) rename {resources => app_old/resources}/routes/api/unidades.php (100%) rename {resources => app_old/resources}/routes/cli.php (100%) create mode 100644 app_old/resources/routes/ui/01_auth.php create mode 100644 app_old/resources/routes/ui/99_base.php rename {resources => app_old/resources}/views/admin/base.blade.php (100%) rename {resources => app_old/resources}/views/admin/menu.blade.php (100%) rename {resources => app_old/resources}/views/admin/menu/models.blade.php (100%) rename {resources => app_old/resources}/views/admin/menu/registros.blade.php (100%) rename {resources => app_old/resources}/views/admin/menu/roles.blade.php (100%) rename {resources => app_old/resources}/views/admin/menu/users.blade.php (100%) rename {resources => app_old/resources}/views/admin/models.blade.php (100%) rename {resources => app_old/resources}/views/admin/registros/controles_avance.blade.php (100%) rename {resources => app_old/resources}/views/admin/registros/list.blade.php (100%) rename {resources => app_old/resources}/views/admin/registros/show.blade.php (100%) rename {resources => app_old/resources}/views/admin/roles/add.blade.php (100%) rename {resources => app_old/resources}/views/admin/roles/add_permissions.blade.php (100%) rename {resources => app_old/resources}/views/admin/roles/add_users.blade.php (100%) rename {resources => app_old/resources}/views/admin/roles/list.blade.php (100%) rename {resources => app_old/resources}/views/admin/roles/show.blade.php (100%) rename {resources => app_old/resources}/views/admin/users/add.blade.php (100%) rename {resources => app_old/resources}/views/admin/users/add_role.blade.php (100%) rename {resources => app_old/resources}/views/admin/users/list.blade.php (100%) rename {resources => app_old/resources}/views/admin/users/show.blade.php (100%) rename {resources => app_old/resources}/views/auth/base.blade.php (72%) rename {resources => app_old/resources}/views/auth/change_pass.blade.php (100%) create mode 100644 app_old/resources/views/auth/login.blade.php rename {resources => app_old/resources}/views/benchmark.blade.php (100%) rename {resources => app_old/resources}/views/buscar/buscar.blade.php (100%) rename {resources => app_old/resources}/views/buscar/resultado.blade.php (100%) rename {resources => app_old/resources}/views/calendario.blade.php (100%) rename {resources => app_old/resources}/views/cierres.blade.php (100%) rename {resources => app_old/resources}/views/construccion.blade.php (100%) rename {resources => app_old/resources}/views/contabilidad/pago.blade.php (100%) rename {resources => app_old/resources}/views/contabilidad/pagos.blade.php (100%) rename {resources => app_old/resources}/views/form/fecha.blade.php (100%) rename {resources => app_old/resources}/views/guest.blade.php (71%) rename {resources => app_old/resources}/views/home.blade.php (60%) rename {resources => app_old/resources}/views/informes/comisiones.blade.php (100%) rename {resources => app_old/resources}/views/informes/contabilidad.blade.php (100%) rename {resources => app_old/resources}/views/informes/escrituras.blade.php (100%) rename {resources => app_old/resources}/views/informes/gantt_entregas.blade.php (100%) rename {resources => app_old/resources}/views/informes/para_comision.blade.php (100%) rename {resources => app_old/resources}/views/informes/proyectos.blade.php (100%) rename {resources => app_old/resources}/views/informes/resciliaciones.blade.php (100%) rename {resources => app_old/resources}/views/informes/resumen_contabilidad.blade.php (100%) rename {resources => app_old/resources}/views/informes/ventas.blade.php (100%) rename {resources => app_old/resources}/views/inmobiliarias/add.blade.php (100%) rename {resources => app_old/resources}/views/inmobiliarias/edit.blade.php (100%) rename {resources => app_old/resources}/views/inmobiliarias/list.blade.php (100%) rename {resources => app_old/resources}/views/inmobiliarias/show.blade.php (100%) rename {resources => app_old/resources}/views/install/admin.blade.php (100%) rename {resources => app_old/resources}/views/install/base.blade.php (100%) rename {resources => app_old/resources}/views/install/end.blade.php (100%) rename {resources => app_old/resources}/views/install/start.blade.php (100%) rename {resources => app_old/resources}/views/layout/base.blade.php (100%) rename {resources => app_old/resources}/views/layout/footer.blade.php (100%) rename {resources => app_old/resources}/views/layout/header.blade.php (100%) rename {resources => app_old/resources}/views/layout/icons/abonar.blade.php (100%) rename {resources => app_old/resources}/views/layout/icons/add.blade.php (100%) rename {resources => app_old/resources}/views/layout/icons/edit.blade.php (100%) rename {resources => app_old/resources}/views/layout/icons/pagar.blade.php (100%) rename {resources => app_old/resources}/views/layout/icons/remove.blade.php (100%) rename {resources => app_old/resources}/views/layout/icons/show.blade.php (100%) rename {resources => app_old/resources}/views/layout/menu.blade.php (96%) rename {resources => app_old/resources}/views/layout/menu.blade.php.save (100%) rename {resources => app_old/resources}/views/layout/menu/herramientas.blade.php (100%) rename {resources => app_old/resources}/views/layout/menu/informes.blade.php (100%) rename {resources => app_old/resources}/views/layout/menu/inmobiliarias.blade.php (100%) create mode 100644 app_old/resources/views/layout/menu/login.blade.php rename {resources => app_old/resources}/views/layout/menu/operadores.blade.php (100%) rename {resources => app_old/resources}/views/layout/menu/proyectos.blade.php (100%) rename {resources => app_old/resources}/views/layout/menu/ventas.blade.php (100%) rename {resources => app_old/resources}/views/other/capacidades.blade.php (100%) rename {resources => app_old/resources}/views/other/entregar_multiple.blade.php (100%) rename {resources => app_old/resources}/views/print/devolucion.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/add.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/advance.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/avance.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/avances/edit.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/avances_row.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/construccion.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/disponibles.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/estimado.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/historia.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/historia.blade.php.old (100%) rename {resources => app_old/resources}/views/proyectos/list.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/operadores/add.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/pagares/add.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/pagares/add_renovacion.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/pagares/edit.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/pagares/edit_renovacion.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/pagares/show.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/por_vender.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/reservas/base.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/show.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/superficies.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/tipo_unidades/add.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/tipo_unidades/edit.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/unidades/add.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/unidades/add2.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/unidades/assign.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/unidades/edit.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/unidades/list.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/unidades/proyectos.blade.php (100%) rename {resources => app_old/resources}/views/proyectos/ventas.blade.php (100%) rename {resources => app_old/resources}/views/temas/add.blade.php (100%) rename {resources => app_old/resources}/views/temas/edit.blade.php (100%) rename {resources => app_old/resources}/views/temas/list.blade.php (100%) rename {resources => app_old/resources}/views/ventas/add.blade.php (100%) rename {resources => app_old/resources}/views/ventas/archivar.blade.php (100%) rename {resources => app_old/resources}/views/ventas/bonos/add.blade.php (100%) rename {resources => app_old/resources}/views/ventas/bonos/edit.blade.php (100%) rename {resources => app_old/resources}/views/ventas/ceder.blade.php (100%) rename {resources => app_old/resources}/views/ventas/cierres/add.blade.php (100%) rename {resources => app_old/resources}/views/ventas/cierres/edit.blade.php (100%) rename {resources => app_old/resources}/views/ventas/cierres/evaluar.blade.php (100%) rename {resources => app_old/resources}/views/ventas/cierres/list.blade.php (100%) rename {resources => app_old/resources}/views/ventas/cierres/show.blade.php (100%) rename {resources => app_old/resources}/views/ventas/comentarios/add.blade.php (100%) rename {resources => app_old/resources}/views/ventas/consolidacion/pago.blade.php (100%) rename {resources => app_old/resources}/views/ventas/consolidacion/proyectos.blade.php (100%) rename {resources => app_old/resources}/views/ventas/consolidacion/show.blade.php (100%) rename {resources => app_old/resources}/views/ventas/creditos/abonar.blade.php (100%) rename {resources => app_old/resources}/views/ventas/creditos/add.blade.php (100%) rename {resources => app_old/resources}/views/ventas/creditos/edit.blade.php (100%) rename {resources => app_old/resources}/views/ventas/creditos/pagar.blade.php (100%) rename {resources => app_old/resources}/views/ventas/creditos/pendientes.blade.php (100%) rename {resources => app_old/resources}/views/ventas/creditos/show.blade.php (100%) rename {resources => app_old/resources}/views/ventas/desist.blade.php (100%) rename {resources => app_old/resources}/views/ventas/devolucion.blade.php (100%) rename {resources => app_old/resources}/views/ventas/edit.blade.php (100%) rename {resources => app_old/resources}/views/ventas/entregar.blade.php (100%) rename {resources => app_old/resources}/views/ventas/escrituras/abonar.blade.php (100%) rename {resources => app_old/resources}/views/ventas/escrituras/add.blade.php (100%) rename {resources => app_old/resources}/views/ventas/escrituras/edit.blade.php (100%) rename {resources => app_old/resources}/views/ventas/escrituras/informe.blade.php (100%) rename {resources => app_old/resources}/views/ventas/escrituras/pagar.blade.php (100%) rename {resources => app_old/resources}/views/ventas/firmar.blade.php (100%) rename {resources => app_old/resources}/views/ventas/forma_pago.blade.php (100%) rename {resources => app_old/resources}/views/ventas/forma_pago/edit.blade.php (100%) rename {resources => app_old/resources}/views/ventas/list.blade.php (100%) rename {resources => app_old/resources}/views/ventas/operadores/unidades/bloquear.blade.php (100%) rename {resources => app_old/resources}/views/ventas/operadores/unidades/list.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pagos/edit.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pagos/pendientes.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pagos/show.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pies/cuotas/abonar.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pies/cuotas/add.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pies/cuotas/edit.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pies/cuotas/estado.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pies/cuotas/pendientes.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pies/cuotas/show.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pies/edit.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pies/reajustar.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pies/reajustes/abonar.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pies/reajustes/edit.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pies/reajustes/pagar.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pies/resumen.blade.php (100%) rename {resources => app_old/resources}/views/ventas/pies/totales.blade.php (100%) rename {resources => app_old/resources}/views/ventas/postventas/add.blade.php (100%) rename {resources => app_old/resources}/views/ventas/postventas/show.blade.php (100%) rename {resources => app_old/resources}/views/ventas/precios/add.blade.php (100%) rename {resources => app_old/resources}/views/ventas/precios/import.blade.php (100%) rename {resources => app_old/resources}/views/ventas/precios/list.blade.php (100%) rename {resources => app_old/resources}/views/ventas/precios/proyectos.blade.php (100%) rename {resources => app_old/resources}/views/ventas/propietarios/edit.blade.php (100%) rename {resources => app_old/resources}/views/ventas/proyectos.blade.php (100%) rename {resources => app_old/resources}/views/ventas/resciliaciones.blade.php (100%) rename {resources => app_old/resources}/views/ventas/show.blade.php (100%) rename {resources => app_old/resources}/views/ventas/sort_title.blade.php (100%) rename {resources => app_old/resources}/views/ventas/subsidios/abonar.blade.php (100%) rename {resources => app_old/resources}/views/ventas/subsidios/add.blade.php (100%) rename {resources => app_old/resources}/views/ventas/subsidios/edit.blade.php (100%) rename {resources => app_old/resources}/views/ventas/subsidios/pagar.blade.php (100%) rename {setup => app_old/setup}/api/config.php (100%) rename {setup => app_old/setup}/api/setups.php (100%) create mode 100644 app_old/setup/app.php rename {setup => app_old/setup}/common/config.php (100%) create mode 100644 app_old/setup/composer.php rename {setup => app_old/setup}/database.php (100%) rename {setup => app_old/setup}/env/config.php (100%) rename {setup => app_old/setup}/router.php (100%) rename {setup => app_old/setup}/settings/01_env.php (100%) rename {setup => app_old/setup}/settings/02_common.php (100%) rename {setup => app_old/setup}/settings/03_api.php (100%) rename {setup => app_old/setup}/settings/04_ui.php (100%) rename {setup => app_old/setup}/setups/04_ui.php (100%) create mode 100644 app_old/ui/app.php create mode 100644 app_old/ui/composer.php create mode 100644 app_old/ui/middlewares/01_auth.php create mode 100644 app_old/ui/middlewares/02_databases.php create mode 100644 app_old/ui/middlewares/98_logs.php create mode 100644 app_old/ui/middlewares/99_routes.php create mode 100644 app_old/ui/settings/01_env.php create mode 100644 app_old/ui/settings/02_folders.php create mode 100644 app_old/ui/settings/03_urls.php create mode 100644 app_old/ui/settings/04_databases.php create mode 100644 app_old/ui/setups/01_views.php create mode 100644 app_old/ui/setups/03_services.php create mode 100644 app_old/ui/setups/98_logs.php rename webpack.config.js => app_old/webpack.config.js (100%) delete mode 100644 resources/views/auth/login.blade.php delete mode 100644 resources/views/layout/menu/login.blade.php delete mode 100644 setup/app.php diff --git a/app_old/.adminer.env.sample b/app_old/.adminer.env.sample new file mode 100644 index 0000000..7e78794 --- /dev/null +++ b/app_old/.adminer.env.sample @@ -0,0 +1,2 @@ +ADMINER_DESIGN=dracula +ADMINER_PLUGINS=dump-json diff --git a/app_old/.db.env.sample b/app_old/.db.env.sample new file mode 100644 index 0000000..18b1117 --- /dev/null +++ b/app_old/.db.env.sample @@ -0,0 +1,4 @@ +MYSQL_DATABASE= +MYSQL_PASSWORD= +MYSQL_ROOT_PASSWORD= +MYSQL_USER= diff --git a/app_old/.env.sample b/app_old/.env.sample new file mode 100644 index 0000000..31fe938 --- /dev/null +++ b/app_old/.env.sample @@ -0,0 +1,2 @@ +BASE_URL= +MYSQL_HOST= diff --git a/app_old/.gitignore b/app_old/.gitignore new file mode 100644 index 0000000..94a1003 --- /dev/null +++ b/app_old/.gitignore @@ -0,0 +1,10 @@ +**/*.env +**/vendor/ +**/composer.lock +**/node_modules/ +**/package-lock.json +**/Pipfile.lock +**/logs/ +**/cache/ +**/modules/ +**/.idea/ diff --git a/app_old/aldarien/asset/.gitignore b/app_old/aldarien/asset/.gitignore new file mode 100644 index 0000000..3b12249 --- /dev/null +++ b/app_old/aldarien/asset/.gitignore @@ -0,0 +1,11 @@ +composer.phar +/vendor/ + +# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file +# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file +# composer.lock + +#Eclipse IDE +.settings +.buildpath +.project diff --git a/app_old/aldarien/asset/LICENSE b/app_old/aldarien/asset/LICENSE new file mode 100644 index 0000000..55dc05a --- /dev/null +++ b/app_old/aldarien/asset/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Aldarien + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/app_old/aldarien/asset/README.md b/app_old/aldarien/asset/README.md new file mode 100644 index 0000000..1580798 --- /dev/null +++ b/app_old/aldarien/asset/README.md @@ -0,0 +1,2 @@ +# asset +Asset manager module for my apps diff --git a/app_old/aldarien/asset/app/Contract/Asset.php b/app_old/aldarien/asset/app/Contract/Asset.php new file mode 100644 index 0000000..30b02c2 --- /dev/null +++ b/app_old/aldarien/asset/app/Contract/Asset.php @@ -0,0 +1,21 @@ +get($identifier); + } +} +?> diff --git a/app_old/aldarien/asset/app/Helper/functions.php b/app_old/aldarien/asset/app/Helper/functions.php new file mode 100644 index 0000000..b0688e2 --- /dev/null +++ b/app_old/aldarien/asset/app/Helper/functions.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/app_old/aldarien/asset/app/Service/Asset.php b/app_old/aldarien/asset/app/Service/Asset.php new file mode 100644 index 0000000..e7c36b7 --- /dev/null +++ b/app_old/aldarien/asset/app/Service/Asset.php @@ -0,0 +1,88 @@ +dir = config('locations.public'); + } + public function get($identifier) + { + $asset = $this->find($identifier); + return $asset->url; + } + protected function find($identifier) + { + $type = $this->getType($identifier); + $asset = null; + if ($type == false) { + foreach (array_keys($this->assets) as $type) { + if (($asset = $this->getAsset($identifier, $type))) { + break; + } + } + } else { + $asset = $this->getAsset($identifier, $type); + } + return $asset; + } + protected function getType($identifier) + { + if (strpos($identifier, '.') !== false) { + list($name, $ext) = explode('.', $identifier); + return $ext; + } + return false; + } + protected function getAsset($identifier, $type) + { + if (!isset($this->assets[$type])) { + $this->loadAssets($type); + } + if (!isset($this->assets[$type])) { + return null; + } + + foreach ($this->assets[$type] as $asset) { + if ($this->compareIdentifier($asset, $identifier)) { + return $asset; + } + } + return null; + } + protected function loadAssets($type) + { + $dir = $this->dir . '/' . $type . '/*.' . $type; + $files = glob($dir); + foreach ($files as $file) { + $url = $this->url($file); + $identifier = pathinfo($file)['filename']; + + $this->assets[$type] []= (object) ['identifier' => $identifier, 'url' => $url, 'type' => $type]; + } + } + protected function url($file) + { + $url = '/' . config('app.project') . '/' . str_replace('\\', '/', str_replace(realpath(config('locations.public')), '', dirname(realpath($file)))) . '/' . basename(realpath($file)); + $url = preg_replace('/\/+/', '/', $url); + return $url; + } + protected function compareIdentifier($asset, $identifier) + { + if (strpos($identifier, '.') !== false) { + list($name, $ext) = explode('.', $identifier); + if ($asset->identifier == $name and $asset->type == $ext) { + return true; + } + } else { + if ($asset->identifier == $identifier) { + return true; + } + } + return false; + } +} diff --git a/app_old/aldarien/asset/composer.json b/app_old/aldarien/asset/composer.json new file mode 100644 index 0000000..dd2c217 --- /dev/null +++ b/app_old/aldarien/asset/composer.json @@ -0,0 +1,26 @@ +{ + "name" : "aldarien/asset", + "description" : "Asset manager module for my apps", + "type" : "library", + "require" : { + "aldarien/config" : "*", + "aldarien/contract" : "*" + }, + "require-dev" : { + "phpunit/phpunit" : "*" + }, + "license" : "MIT", + "authors" : [{ + "name" : "Aldarien", + "email" : "aldarien85@gmail.com" + } + ], + "autoload" : { + "psr-4" : { + "App\\" : "app" + }, + "files": [ + "app/Helper/functions.php" + ] + } +} diff --git a/app_old/aldarien/asset/phpunit.xml b/app_old/aldarien/asset/phpunit.xml new file mode 100644 index 0000000..e60ecbd --- /dev/null +++ b/app_old/aldarien/asset/phpunit.xml @@ -0,0 +1,17 @@ + + + + + ./tests/ + + + + + ./app + + + \ No newline at end of file diff --git a/app_old/aldarien/asset/tests/AssetTest.php b/app_old/aldarien/asset/tests/AssetTest.php new file mode 100644 index 0000000..e53f0ad --- /dev/null +++ b/app_old/aldarien/asset/tests/AssetTest.php @@ -0,0 +1,25 @@ +assertEquals(asset('style.css'), '/css/style.css'); + } +} +?> \ No newline at end of file diff --git a/app_old/aldarien/config/.gitignore b/app_old/aldarien/config/.gitignore new file mode 100644 index 0000000..47c4114 --- /dev/null +++ b/app_old/aldarien/config/.gitignore @@ -0,0 +1,13 @@ +composer.phar +/vendor/ + +# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file +# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file +# composer.lock + +config + +# Eclipse IDE +.settings +.buildpath +.project \ No newline at end of file diff --git a/app_old/aldarien/config/.travis.yml b/app_old/aldarien/config/.travis.yml new file mode 100644 index 0000000..a792980 --- /dev/null +++ b/app_old/aldarien/config/.travis.yml @@ -0,0 +1,3 @@ +language: php +php: '7.1' +install: composer update diff --git a/app_old/aldarien/config/LICENSE b/app_old/aldarien/config/LICENSE new file mode 100644 index 0000000..55dc05a --- /dev/null +++ b/app_old/aldarien/config/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Aldarien + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/app_old/aldarien/config/README.md b/app_old/aldarien/config/README.md new file mode 100644 index 0000000..dfed35b --- /dev/null +++ b/app_old/aldarien/config/README.md @@ -0,0 +1,4 @@ +# config +Config module that recovers configuration files + +[![Build Status](https://travis-ci.org/Aldarien/config.svg?branch=1.0.1)](https://travis-ci.org/Aldarien/config) diff --git a/app_old/aldarien/config/app/Contract/Config.php b/app_old/aldarien/config/app/Contract/Config.php new file mode 100644 index 0000000..9664aca --- /dev/null +++ b/app_old/aldarien/config/app/Contract/Config.php @@ -0,0 +1,31 @@ +get($name); + } + public static function set($name, $value) + { + $instance = self::getInstance(); + return $instance->set($name, $value); + } + public static function addFile($filename) + { + $instance = self::getInstance(); + return $instance->loadFile($filename); + } +} +?> diff --git a/app_old/aldarien/config/app/Contract/YamlWrapper.php b/app_old/aldarien/config/app/Contract/YamlWrapper.php new file mode 100644 index 0000000..0ab60f6 --- /dev/null +++ b/app_old/aldarien/config/app/Contract/YamlWrapper.php @@ -0,0 +1,21 @@ + \ No newline at end of file diff --git a/app_old/aldarien/config/app/Helper/functions.php b/app_old/aldarien/config/app/Helper/functions.php new file mode 100644 index 0000000..e073f18 --- /dev/null +++ b/app_old/aldarien/config/app/Helper/functions.php @@ -0,0 +1,9 @@ + diff --git a/app_old/aldarien/config/app/Service/Config.php b/app_old/aldarien/config/app/Service/Config.php new file mode 100644 index 0000000..072e38f --- /dev/null +++ b/app_old/aldarien/config/app/Service/Config.php @@ -0,0 +1,150 @@ +dir = $dir; + $this->load(); + } + protected function load() + { + $files = glob($this->dir . '/*.{php,json,yml}', GLOB_BRACE); + foreach ($files as $file) { + $info = pathinfo($file); + $name = $info['filename']; + + $d = $this->getData($file); + $data[$name] = $d; + $data = array_merge($data, $this->translateArray($d, $name)); + foreach ($data as $key => $value) { + $this->add($key, $value); + } + } + } + public function loadFile(string $filename) + { + if (!file_exists(realpath($filename))) { + return false; + } + $info = pathinfo($filename); + $name = $info['filename']; + $d = $this->getData($filename); + $data[$name] = $d; + $data = array_merge($data, $this->translateArray($d, $name)); + foreach ($data as $key => $value) { + $this->add($key, $value); + } + return true; + } + protected function getData($filename) + { + $info = pathinfo($filename); + + switch ($info['extension']) { + case 'php': + return include_once $filename; + case 'json': + return json_decode(file_get_contents($filename), true); + case 'yml': + return YamlWrapper::load($filename); + default: + throw new \DomainException('Invalid file extension for ' . $filename); + } + } + protected function translateArray($array, $level) + { + $output = []; + foreach ($array as $k1 => $l1) { + $key = $level . '.' . $k1; + if (is_array($l1)) { + $output[$key] = $l1; + $output = array_merge($output, $this->translateArray($l1, $key)); + } else { + $output[$key] = $l1; + } + } + return $output; + } + protected function add($field, $value) + { + if (isset($this->data[$field])) { + if ($this->data[$field] == $value) { + return; + } + if (is_array($this->data[$field])) { + $this->data[$field] = $this->merge($this->data[$field], $this->replace($value)); + } else { + $this->data[$field] = $this->replace($value); + } + } else { + $this->data[$field] = $this->replace($value); + } + } + protected function merge($arr1, $arr2) + { + $output = $arr1; + foreach ($arr2 as $k => $value) { + if (isset($arr1[$k])) { + if ($arr1[$k] == $value) { + continue; + } + if (is_array($arr1[$k])) { + $output[$k] = $this->merge($arr1[$k], $value); + } else { + $output[$k] = array_merge([$arr1[$k]], $value); + } + } else { + $output[$k] = $value; + } + } + return $output; + } + protected function replace($value) + { + if (is_array($value)) { + foreach ($value as $k => $v) { + $value[$k] = $this->replace($v); + } + return $value; + } + if (strpos($value, '{') !== false) { + while(strpos($value, '{') !== false) { + $ini = strpos($value, '{') + 1; + $end = strpos($value, '}', $ini); + $rep = substr($value, $ini, $end - $ini); + $new = $this->get($rep); + if ($new === null) { + $new = ''; + } + $value = str_replace('{' . $rep . '}', $new, $value); + } + } + return $value; + } + + public function get($name = null) + { + if ($name == null) { + return $this->data; + } + if (isset($this->data[$name])) { + return $this->data[$name]; + } + return null; + } + public function set($name, $value) + { + $this->add($name, $value); + } +} +?> diff --git a/app_old/aldarien/config/bootstrap/autoload.php b/app_old/aldarien/config/bootstrap/autoload.php new file mode 100644 index 0000000..42765bd --- /dev/null +++ b/app_old/aldarien/config/bootstrap/autoload.php @@ -0,0 +1,3 @@ + diff --git a/app_old/aldarien/config/composer.json b/app_old/aldarien/config/composer.json new file mode 100644 index 0000000..ff4255b --- /dev/null +++ b/app_old/aldarien/config/composer.json @@ -0,0 +1,28 @@ +{ + "name": "aldarien/config", + "description": "Config module for my apps", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Aldarien", + "email": "aldarien85@gmail.com" + } + ], + "require": { + "aldarien/contract": "*", + "aldarien/root": "*", + "symfony/yaml": "*" + }, + "autoload": { + "psr-4": { + "App\\": "app" + }, + "files": [ + "app/Helper/functions.php" + ] + }, + "require-dev": { + "phpunit/phpunit": "^6.3" + } +} diff --git a/app_old/aldarien/config/phpunit.xml b/app_old/aldarien/config/phpunit.xml new file mode 100644 index 0000000..db312e1 --- /dev/null +++ b/app_old/aldarien/config/phpunit.xml @@ -0,0 +1,17 @@ + + + + + ./tests/ + + + + + ./app + + + \ No newline at end of file diff --git a/app_old/aldarien/config/tests/ConfigTest.php b/app_old/aldarien/config/tests/ConfigTest.php new file mode 100644 index 0000000..187e0a3 --- /dev/null +++ b/app_old/aldarien/config/tests/ConfigTest.php @@ -0,0 +1,90 @@ + 'Config', 'test_array' => ['data1' => 1, 'data2' => 2]]; ?>"; + file_put_contents(dirname(__DIR__) . '/config/app.php', $str); + $data = ['name' => 'Config', 'test_array' => ['data1' => 1, 'data2' => 2]]; + file_put_contents(dirname(__DIR__) . '/config/json.json', json_encode($data)); + file_put_contents(dirname(__DIR__) . '/config/yaml.yml', YamlWrapper::dump($data)); + $data = ['last_name' => 'Config']; + file_put_contents(dirname(__DIR__) . '/config/yaml.json', json_encode($data)); + } + public function testGetNamePhp() + { + $name = 'Config'; + + $this->assertEquals($name, config('app.name')); + } + public function testGetNameJson() + { + $name = 'Config'; + + $this->assertEquals($name, config('json.name')); + } + public function testGetNameYaml() + { + $name = 'Config'; + + $this->assertEquals($name, config('yaml.name')); + } + public function testSetNamehp() + { + $new_name = 'Config_Test'; + config('app.name', $new_name); + $this->assertEquals($new_name, config('app.name')); + } + public function testSetNameJson() + { + $new_name = 'Config_Test'; + config('json.name', $new_name); + $this->assertEquals($new_name, config('json.name')); + } + public function testSetNameYaml() + { + $new_name = 'Config_Test'; + config('yaml.name', $new_name); + $this->assertEquals($new_name, config('yaml.name')); + } + public function testArrayGetPhp() + { + $this->assertArrayHasKey('data1', config('app.test_array')); + } + public function testArrayGetJson() + { + $this->assertArrayHasKey('data1', config('json.test_array')); + } + public function testArrayGetYaml() + { + $this->assertArrayHasKey('data1', config('yaml.test_array')); + } + public function testSameSectionName() + { + $this->assertEquals('Config', config('yaml.last_name')); + } + public function testDuplicateValue() + { + config('json.name', 'Config2'); + $this->assertEquals('Config2', config('json.name')); + } + public function testAddFile() + { + $filename = dirname(__DIR__) . '/composer.json'; + App\Contract\Config::addFile($filename); + $this->assertEquals('aldarien/config', config('composer.name')); + } + public function tearDown() + { + unlink(dirname(__DIR__) . '/config/app.php'); + unlink(dirname(__DIR__) . '/config/json.json'); + unlink(dirname(__DIR__) . '/config/yaml.yml'); + unlink(dirname(__DIR__) . '/config/yaml.json'); + rmdir(dirname(__DIR__) . '/config'); + } +} +?> \ No newline at end of file diff --git a/app_old/aldarien/contract/.gitignore b/app_old/aldarien/contract/.gitignore new file mode 100644 index 0000000..c422267 --- /dev/null +++ b/app_old/aldarien/contract/.gitignore @@ -0,0 +1,6 @@ +composer.phar +/vendor/ + +# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file +# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file +# composer.lock diff --git a/app_old/aldarien/contract/LICENSE b/app_old/aldarien/contract/LICENSE new file mode 100644 index 0000000..55dc05a --- /dev/null +++ b/app_old/aldarien/contract/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Aldarien + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/app_old/aldarien/contract/app/Definition/Contract.php b/app_old/aldarien/contract/app/Definition/Contract.php new file mode 100644 index 0000000..4cc88ca --- /dev/null +++ b/app_old/aldarien/contract/app/Definition/Contract.php @@ -0,0 +1,20 @@ + diff --git a/app_old/aldarien/contract/composer.json b/app_old/aldarien/contract/composer.json new file mode 100644 index 0000000..96ef067 --- /dev/null +++ b/app_old/aldarien/contract/composer.json @@ -0,0 +1,18 @@ +{ + "name": "aldarien/contract", + "description": "Contract trait for my apps", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Aldarien", + "email": "aldarien85@gmail.com" + } + ], + "require": {}, + "autoload": { + "psr-4": { + "App\\": "app" + } + } +} diff --git a/app_old/aldarien/format/.gitignore b/app_old/aldarien/format/.gitignore new file mode 100644 index 0000000..6ee50e6 --- /dev/null +++ b/app_old/aldarien/format/.gitignore @@ -0,0 +1,11 @@ +composer.phar +/vendor/ + +# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file +# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file +# composer.lock + +# Eclipse IDE +.settings +.buildpath +.project \ No newline at end of file diff --git a/app_old/aldarien/format/LICENSE b/app_old/aldarien/format/LICENSE new file mode 100644 index 0000000..55dc05a --- /dev/null +++ b/app_old/aldarien/format/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Aldarien + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/app_old/aldarien/format/README.md b/app_old/aldarien/format/README.md new file mode 100644 index 0000000..d4f839f --- /dev/null +++ b/app_old/aldarien/format/README.md @@ -0,0 +1,2 @@ +# format +Module for formatting data, mostly numbers diff --git a/app_old/aldarien/format/app/Helper/Format.php b/app_old/aldarien/format/app/Helper/Format.php new file mode 100644 index 0000000..9836f38 --- /dev/null +++ b/app_old/aldarien/format/app/Helper/Format.php @@ -0,0 +1,43 @@ +format("d \d\\e F Y"); + } + public static function shortDate(string $date) + { + $d = \Carbon\Carbon::parse($date, config('app.timezone')); + return $d->format('d-m-Y'); + } + public static function localDate(string $date) + { + $d = \Carbon\Carbon::parse($date, config('app.timezone')); + setlocale(LC_TIME, 'es'); + return $d->formatLocalized('%d de %B de %Y'); + } + public static function m2(float $number, bool $print = false) + { + return self::number($number, 2) . (($print) ? ' m²' : ''); + } + public static function percent(float $number, bool $print = false) + { + return self::number($number, 2) . (($print) ? '%' : ''); + } +} +?> \ No newline at end of file diff --git a/app_old/aldarien/format/composer.json b/app_old/aldarien/format/composer.json new file mode 100644 index 0000000..59d058d --- /dev/null +++ b/app_old/aldarien/format/composer.json @@ -0,0 +1,23 @@ +{ + "name" : "aldarien/format", + "description" : "Module for formatting data, mostly numbers", + "type" : "library", + "require-dev" : { + "phpunit/phpunit" : "*", + "aldarien/config": "*" + }, + "license" : "MIT", + "authors" : [{ + "name" : "Aldarien", + "email" : "aldarien85@gmail.com" + } + ], + "autoload" : { + "psr-4" : { + "App\\" : "app" + } + }, + "require": { + "nesbot/carbon": "^2" + } +} diff --git a/app_old/aldarien/format/config/app.php b/app_old/aldarien/format/config/app.php new file mode 100644 index 0000000..9e747f9 --- /dev/null +++ b/app_old/aldarien/format/config/app.php @@ -0,0 +1,5 @@ + 'America/Santiago' +]; +?> \ No newline at end of file diff --git a/app_old/aldarien/format/phpunit.xml b/app_old/aldarien/format/phpunit.xml new file mode 100644 index 0000000..e60ecbd --- /dev/null +++ b/app_old/aldarien/format/phpunit.xml @@ -0,0 +1,17 @@ + + + + + ./tests/ + + + + + ./app + + + \ No newline at end of file diff --git a/app_old/aldarien/format/tests/FormatTest.php b/app_old/aldarien/format/tests/FormatTest.php new file mode 100644 index 0000000..bcc6bd5 --- /dev/null +++ b/app_old/aldarien/format/tests/FormatTest.php @@ -0,0 +1,59 @@ +number, 3); + $this->assertEquals($output, $result); + } + public function testPesosPrint() + { + $output = '$ 5.049.872'; + $result = Format::pesos($this->number, true); + $this->assertEquals($output, $result); + } + public function testUFPrint() + { + $output = '5.049.872,32 UF'; + $result = Format::ufs($this->number, true); + $this->assertEquals($output, $result); + } + public function testDate() + { + $output = '25 de March 2016'; + $result = Format::date($this->date); + $this->assertEquals($output, $result); + } + public function testShortDate() + { + $output = '25-03-2016'; + $result = Format::shortDate($this->date); + $this->assertEquals($output, $result); + } + public function testLocalDate() + { + $output = '25 de marzo de 2016'; + $result = Format::localDate($this->date); + $this->assertEquals($output, $result); + } + public function testM2Print() + { + $output = '5.049.872,32 m²'; + $result = Format::m2($this->number, true); + $this->assertEquals($output, $result); + } + public function testPercentPrint() + { + $output = '5.049.872,32%'; + $result = Format::percent($this->number, true); + $this->assertEquals($output, $result); + } +} +?> \ No newline at end of file diff --git a/app_old/aldarien/response/.gitignore b/app_old/aldarien/response/.gitignore new file mode 100644 index 0000000..265bf84 --- /dev/null +++ b/app_old/aldarien/response/.gitignore @@ -0,0 +1,7 @@ +#Eclipse IDE +.settings +.buildpath +.project + +#Composer +vendor diff --git a/app_old/aldarien/response/LICENSE b/app_old/aldarien/response/LICENSE new file mode 100644 index 0000000..55dc05a --- /dev/null +++ b/app_old/aldarien/response/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Aldarien + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/app_old/aldarien/response/README.md b/app_old/aldarien/response/README.md new file mode 100644 index 0000000..80c6096 --- /dev/null +++ b/app_old/aldarien/response/README.md @@ -0,0 +1,2 @@ +# response +Response handler module for my apps diff --git a/app_old/aldarien/response/app/Contract/Response.php b/app_old/aldarien/response/app/Contract/Response.php new file mode 100644 index 0000000..4b0089e --- /dev/null +++ b/app_old/aldarien/response/app/Contract/Response.php @@ -0,0 +1,27 @@ + \ No newline at end of file diff --git a/app_old/aldarien/response/app/Helper/functions.php b/app_old/aldarien/response/app/Helper/functions.php new file mode 100644 index 0000000..32c48f8 --- /dev/null +++ b/app_old/aldarien/response/app/Helper/functions.php @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/app_old/aldarien/response/app/Service/Response.php b/app_old/aldarien/response/app/Service/Response.php new file mode 100644 index 0000000..d0f3e24 --- /dev/null +++ b/app_old/aldarien/response/app/Service/Response.php @@ -0,0 +1,62 @@ +gump = new \GUMP(); + } + public function sanitize() + { + if ($_POST) { + $this->post = $this->correctNumbers($this->gump->sanitize($_POST)); + } + if ($_GET) { + $this->get = $this->correctNumbers($this->gump->sanitize($_GET)); + } + } + public function correctNumbers(array $data) + { + $output = []; + foreach ($data as $key => $value) { + if (is_float(str_replace(',', '.', $value))) { + $output[$key] = str_replace(',', '.', $value); + } else { + $output[$key] = $value; + } + } + return $output; + } + public function get($query = null) + { + if ($this->get == null) { + $this->sanitize(); + } + if ($query == null) { + return $this->get; + } + if (isset($this->get[$query])) { + return $this->get[$query]; + } + return false; + } + public function post($query = null) + { + if ($this->post == null) { + $this->sanitize(); + } + if ($query == null) { + return $this->post; + } + if (isset($this->post[$query])) { + return $this->post[$query]; + } + return false; + } +} +?> diff --git a/app_old/aldarien/response/bootstrap/autoload.php b/app_old/aldarien/response/bootstrap/autoload.php new file mode 100644 index 0000000..b5e8220 --- /dev/null +++ b/app_old/aldarien/response/bootstrap/autoload.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app_old/aldarien/response/composer.json b/app_old/aldarien/response/composer.json new file mode 100644 index 0000000..a337f86 --- /dev/null +++ b/app_old/aldarien/response/composer.json @@ -0,0 +1,26 @@ +{ + "name" : "aldarien/response", + "description" : "Response handler module for my apps", + "type" : "library", + "require" : { + "wixel/gump" : "^2.0.0", + "aldarien/contract" : "*" + }, + "require-dev" : { + "phpunit/phpunit" : "*" + }, + "license" : "MIT", + "authors" : [{ + "name" : "Aldarien", + "email" : "jpvial@gmail.com" + } + ], + "autoload" : { + "psr-4" : { + "App\\" : "app" + }, + "files": [ + "app/Helper/functions.php" + ] + } +} diff --git a/app_old/aldarien/response/phpunit.xml b/app_old/aldarien/response/phpunit.xml new file mode 100644 index 0000000..db312e1 --- /dev/null +++ b/app_old/aldarien/response/phpunit.xml @@ -0,0 +1,17 @@ + + + + + ./tests/ + + + + + ./app + + + \ No newline at end of file diff --git a/app_old/aldarien/response/tests/ResponseTest.php b/app_old/aldarien/response/tests/ResponseTest.php new file mode 100644 index 0000000..67d603c --- /dev/null +++ b/app_old/aldarien/response/tests/ResponseTest.php @@ -0,0 +1,22 @@ +value; + $_POST['test'] = $this->value; + } + public function testGet() + { + $this->assertEquals($this->value, get('test')); + } + public function testPost() + { + $this->assertEquals($this->value, post('test')); + } +} +?> \ No newline at end of file diff --git a/app_old/aldarien/root/.gitignore b/app_old/aldarien/root/.gitignore new file mode 100644 index 0000000..f7e7961 --- /dev/null +++ b/app_old/aldarien/root/.gitignore @@ -0,0 +1,5 @@ +.buildpath +.project +.settings +*.lock +vendor \ No newline at end of file diff --git a/app_old/aldarien/root/LICENSE b/app_old/aldarien/root/LICENSE new file mode 100644 index 0000000..55dc05a --- /dev/null +++ b/app_old/aldarien/root/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Aldarien + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/app_old/aldarien/root/README.md b/app_old/aldarien/root/README.md new file mode 100644 index 0000000..039cbc3 --- /dev/null +++ b/app_old/aldarien/root/README.md @@ -0,0 +1,22 @@ +# root +get root directory path for your project + +## Usage + +add `Root::root('project')` or `root('project')` or `Root::root()` or `root()` where you need the root directory of your proyect. + +## Example + +For the structure: + +~~~ +/usr/share/www/projects +- myProject +-- src +-- tests +~~~ + +using `Root::root('myProject')` + +outputs: +`/usr/share/www/projects/myProject` diff --git a/app_old/aldarien/root/app/Helper/functions.php b/app_old/aldarien/root/app/Helper/functions.php new file mode 100644 index 0000000..86fd2eb --- /dev/null +++ b/app_old/aldarien/root/app/Helper/functions.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/app_old/aldarien/root/composer.json b/app_old/aldarien/root/composer.json new file mode 100644 index 0000000..784dfb7 --- /dev/null +++ b/app_old/aldarien/root/composer.json @@ -0,0 +1,21 @@ +{ + "name" : "aldarien/root", + "description" : "Find the root path for your proyect", + "authors" : [{ + "name" : "Aldarien" + } + ], + "license": "MIT", + "require-dev" : { + "phpunit/phpunit" : "*", + "kint-php/kint" : "*" + }, + "autoload" : { + "psr-4" : { + "Proyect\\Root\\" : "src" + }, + "files": [ + "app/Helper/functions.php" + ] + } +} diff --git a/app_old/aldarien/root/phpunit.xml b/app_old/aldarien/root/phpunit.xml new file mode 100644 index 0000000..63ecd1c --- /dev/null +++ b/app_old/aldarien/root/phpunit.xml @@ -0,0 +1,19 @@ + + + + tests + + + + + src + + + diff --git a/app_old/aldarien/root/src/Root.php b/app_old/aldarien/root/src/Root.php new file mode 100644 index 0000000..13058df --- /dev/null +++ b/app_old/aldarien/root/src/Root.php @@ -0,0 +1,48 @@ +$proyect_name/public/index.php calls for $proyect_name/bootstrap/autoload.php, + * you just need to + * + * include root() . '/bootstrap/autoload.php' + * + * @param string $proyect_name + * @return string + */ + public static function root(string $proyect_name = '') + { + $dir = realpath(__DIR__); + if ($proyect_name == '') { + return self::findComposerFile($dir); + } else { + $ini = strpos($dir, $proyect_name) + strlen($proyect_name); + } + $path = substr($dir, $ini); + $cnt = substr_count($path, DIRECTORY_SEPARATOR); + $root = DIRECTORY_SEPARATOR; + for ($i = 0; $i < $cnt; $i ++) { + $root .= '..' . DIRECTORY_SEPARATOR; + } + + return realpath($dir . $root); + } + protected static function findComposerFile($dir) + { + if (file_exists($dir . '/vendor/')) { + return $dir; + } + + $root = realpath('/'); + if (realpath($dir) == $root) { + return null; + } + + $dir = dirname($dir); + return self::findComposerFile($dir); + } +} +?> diff --git a/app_old/aldarien/root/tests/RootTest.php b/app_old/aldarien/root/tests/RootTest.php new file mode 100644 index 0000000..1deed6c --- /dev/null +++ b/app_old/aldarien/root/tests/RootTest.php @@ -0,0 +1,61 @@ +getCurrentDir(); + $this->assertEquals($this->getRoot(), $this->current_dir); + $this->assertEquals($this->getBaseRoot(), $this->current_dir); + } + public function testBaseRootFunction() + { + $this->getCurrentDir(); + $this->assertEquals($this->getFRoot(), $this->current_dir); + $this->assertEquals($this->getFBaseRoot(), $this->current_dir); + } + public function testSrcRoot() + { + $this->changeDir('src'); + $this->assertEquals(realpath($this->getRoot() . '/src'), $this->current_dir); + $this->assertEquals(realpath($this->getBaseRoot() . '/src'), $this->current_dir); + } + public function testSrcRootFunction() + { + $this->changeDir('src'); + $this->assertEquals(realpath($this->getFRoot() . '/src'), $this->current_dir); + $this->assertEquals(realpath($this->getFBaseRoot() . '/src'), $this->current_dir); + } + + private function getCurrentDir() + { + $this->current_dir = getcwd(); + } + private function changeDir($dir) + { + chdir($dir); + $this->getCurrentDir(); + } + private function getRoot() + { + return Root::root($this->proyect_name); + } + private function getBaseRoot() + { + return Root::root(); + } + private function getFRoot() + { + return root($this->proyect_name); + } + private function getFBaseRoot() + { + return root(); + } +} +?> \ No newline at end of file diff --git a/app_old/aldarien/session/.gitignore b/app_old/aldarien/session/.gitignore new file mode 100644 index 0000000..6ee50e6 --- /dev/null +++ b/app_old/aldarien/session/.gitignore @@ -0,0 +1,11 @@ +composer.phar +/vendor/ + +# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file +# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file +# composer.lock + +# Eclipse IDE +.settings +.buildpath +.project \ No newline at end of file diff --git a/app_old/aldarien/session/LICENSE b/app_old/aldarien/session/LICENSE new file mode 100644 index 0000000..55dc05a --- /dev/null +++ b/app_old/aldarien/session/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Aldarien + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/app_old/aldarien/session/README.md b/app_old/aldarien/session/README.md new file mode 100644 index 0000000..6825213 --- /dev/null +++ b/app_old/aldarien/session/README.md @@ -0,0 +1,2 @@ +# session +Session wrapper for aura/session diff --git a/app_old/aldarien/session/app/Contract/Session.php b/app_old/aldarien/session/app/Contract/Session.php new file mode 100644 index 0000000..2968a8f --- /dev/null +++ b/app_old/aldarien/session/app/Contract/Session.php @@ -0,0 +1,29 @@ +newInstance($_COOKIE); + } + public static function get($segment, $name) + { + $instance = self::getInstance(); + $segment = $instance->getSegment($segment); + return $segment->get($name); + } + public static function set($segment, $name, $value) + { + $instance = self::getInstance(); + $segment = $instance->getSegment($segment); + $segment->set($name, $value); + } +} +?> \ No newline at end of file diff --git a/app_old/aldarien/session/composer.json b/app_old/aldarien/session/composer.json new file mode 100644 index 0000000..7fe764d --- /dev/null +++ b/app_old/aldarien/session/composer.json @@ -0,0 +1,24 @@ +{ + "name": "aldarien/session", + "description": "Session wrapper for aura/session", + "type": "library", + "require": { + "aura/session": "*", + "aldarien/contract": "*" + }, + "require-dev": { + "phpunit/phpunit": "*" + }, + "license": "MIT", + "authors": [ + { + "name": "Aldarien", + "email": "aldarien85@gmail.com" + } + ], + "autoload": { + "psr-4": { + "App\\": "app" + } + } +} diff --git a/app_old/aldarien/url/.gitignore b/app_old/aldarien/url/.gitignore new file mode 100644 index 0000000..a06a2f1 --- /dev/null +++ b/app_old/aldarien/url/.gitignore @@ -0,0 +1,12 @@ +composer.phar +/vendor/ + +# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file +# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file +# composer.lock + +.settings +.buildpath +.project + +# Eclipse IDE \ No newline at end of file diff --git a/app_old/aldarien/url/LICENSE b/app_old/aldarien/url/LICENSE new file mode 100644 index 0000000..55dc05a --- /dev/null +++ b/app_old/aldarien/url/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Aldarien + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/app_old/aldarien/url/README.md b/app_old/aldarien/url/README.md new file mode 100644 index 0000000..0c1a426 --- /dev/null +++ b/app_old/aldarien/url/README.md @@ -0,0 +1,2 @@ +# url +Get relative path url diff --git a/app_old/aldarien/url/app/Contract/URL.php b/app_old/aldarien/url/app/Contract/URL.php new file mode 100644 index 0000000..14d7ef0 --- /dev/null +++ b/app_old/aldarien/url/app/Contract/URL.php @@ -0,0 +1,21 @@ +url($path, $variables); + } +} +?> \ No newline at end of file diff --git a/app_old/aldarien/url/app/Helper/functions.php b/app_old/aldarien/url/app/Helper/functions.php new file mode 100644 index 0000000..6e9435e --- /dev/null +++ b/app_old/aldarien/url/app/Helper/functions.php @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/app_old/aldarien/url/app/Service/URL.php b/app_old/aldarien/url/app/Service/URL.php new file mode 100644 index 0000000..49a601d --- /dev/null +++ b/app_old/aldarien/url/app/Service/URL.php @@ -0,0 +1,83 @@ +root = $this->findRoot(); + $this->relative = $this->findRelative(); + } + + protected function findRoot() + { + $base = $_SERVER['HTTP_HOST'] . ((isset($_SERVER['HTTP_PORT'])) ? ':' . $_SERVER['HTTP_PORT'] : ''); + $scheme = 'http'; + if (isset($_SERVER['REQUEST_SCHEME'])) { + $scheme = $_SERVER['REQUEST_SCHEME']; + } + if (isset($_SERVER['HTTPS'])) { + $scheme = 'https'; + } + $uri = Http::createFromString(\Sabre\Uri\resolve($scheme . '://' . $base, $_SERVER['SCRIPT_NAME'])); + $host = new Host($uri->getHost()); + if ($host->isAbsolute()) { + return $host->getRegistrableDomain(); + } + $base = $host . (($uri->getPort()) ? ':' . $uri->getPort() : ''); + return ($uri->getScheme() ?: 'http') . '://' . $base; + } + protected function findRelative() + { + $uri = Http::createFromString($_SERVER['SCRIPT_NAME']); + $normalized = (new HierarchicalPath($uri->getPath()))->withoutLeadingSlash()->withoutTrailingSlash()->withoutDotSegments()->withoutEmptySegments(); + if ($normalized->getDirname() == '.') { + return ''; + } + return $normalized->getDirname(); + } + + + public function url($path = '', $variables = null) + { + $uri = Http::createFromString($path); + if ($uri->getHost() != $this->root and $uri->getHost() != '') { + return $path; + } + + $uri = \Sabre\Uri\resolve($this->getBaseUrl(), $path); + try { + $host = new Host(Http::createFromString($uri)->getHost()); + } catch (\League\Uri\Exception $e) { + $uri = \Sabre\Uri\resolve($this->getBaseUrl(), '../../') . '/' . basename($path); + $host = new Host(Http::createFromString($uri)->getHost()); + } + + $base = new Host(Http::createFromString($this->root)->getHost()); + if ($host . '' != $base . '') { + $host = new Host(Http::createFromString($this->root)->getHost()); + $page = str_replace($this->root, '', $uri); + $uri = \Sabre\Uri\resolve(Http::createFromString($this->root)->getScheme() . '://' . $host->getRegistrableDomain(). '/', $page); + } + + if ($variables != null) { + $uri = \Sabre\Uri\resolve($uri, '?' . http_build_query($variables)); + } + $uri = \Sabre\Uri\normalize($uri); + + return $uri; + } + protected function getBaseUrl() + { + $url = \Sabre\Uri\normalize(trim($this->root . '/' . $this->relative, '/') . '/'); + return $url; + } +} +?> diff --git a/app_old/aldarien/url/composer.json b/app_old/aldarien/url/composer.json new file mode 100644 index 0000000..779ed73 --- /dev/null +++ b/app_old/aldarien/url/composer.json @@ -0,0 +1,29 @@ +{ + "name" : "aldarien/url", + "description" : "Get relative path uri", + "type" : "library", + "require" : { + "aldarien/contract" : "*", + "aldarien/root" : "*", + "league/uri": "*", + "league/uri-components": "*", + "sabre/uri": "*" + }, + "require-dev" : { + "phpunit/phpunit" : "*" + }, + "license" : "MIT", + "authors" : [{ + "name" : "Aldarien", + "email" : "jpvial@gmail.com" + } + ], + "autoload" : { + "psr-4" : { + "App\\" : "app" + }, + "files": [ + "app/Helper/functions.php" + ] + } +} diff --git a/app_old/aldarien/view/.gitignore b/app_old/aldarien/view/.gitignore new file mode 100644 index 0000000..120b68f --- /dev/null +++ b/app_old/aldarien/view/.gitignore @@ -0,0 +1,10 @@ +composer.phar +/vendor/ + +# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file +# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file +# composer.lock + +.settings +.buildpath +.project diff --git a/app_old/aldarien/view/LICENSE b/app_old/aldarien/view/LICENSE new file mode 100644 index 0000000..55dc05a --- /dev/null +++ b/app_old/aldarien/view/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Aldarien + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/app_old/aldarien/view/README.md b/app_old/aldarien/view/README.md new file mode 100644 index 0000000..b888dbd --- /dev/null +++ b/app_old/aldarien/view/README.md @@ -0,0 +1,2 @@ +# view +View module for my apps diff --git a/app_old/aldarien/view/app/Contract/View.php b/app_old/aldarien/view/app/Contract/View.php new file mode 100644 index 0000000..1d0c5b9 --- /dev/null +++ b/app_old/aldarien/view/app/Contract/View.php @@ -0,0 +1,30 @@ + "http://{$remote->getIP()}:8008", + 'headers' => ['Accept' => 'application/json'] + ]))); + return new ViewService(['money' => $money]); + } + public static function show($template, $variables = null) + { + $instance = self::getInstance(); + return $instance->show($template, $variables); + } +} +?> diff --git a/app_old/aldarien/view/app/Helper/functions.php b/app_old/aldarien/view/app/Helper/functions.php new file mode 100644 index 0000000..ba0e9e1 --- /dev/null +++ b/app_old/aldarien/view/app/Helper/functions.php @@ -0,0 +1,5 @@ + diff --git a/app_old/aldarien/view/app/Service/View.php b/app_old/aldarien/view/app/Service/View.php new file mode 100644 index 0000000..7217696 --- /dev/null +++ b/app_old/aldarien/view/app/Service/View.php @@ -0,0 +1,27 @@ +views = config('locations.views'); + $this->cache = config('locations.cache'); + + $this->blade = new BladeOne($this->views, $this->cache, null, $variables); + } + public function show($template, $vars = null) + { + if ($vars) { + return $this->blade->run($template, $vars); + } + return $this->blade->run($template); + } +} +?> diff --git a/app_old/aldarien/view/composer.json b/app_old/aldarien/view/composer.json new file mode 100644 index 0000000..5d283ab --- /dev/null +++ b/app_old/aldarien/view/composer.json @@ -0,0 +1,28 @@ +{ + "name": "aldarien/view", + "description": "View module for my apps", + "type": "library", + "require": { + "eftec/bladeone": "*", + "aldarien/contract": "*", + "aldarien/config": "*" + }, + "license": "MIT", + "authors": [ + { + "name": "Aldarien", + "email": "aldarien85@gmail.com" + } + ], + "autoload": { + "psr-4": { + "App\\": "app" + }, + "files": [ + "app/Helper/functions.php" + ] + }, + "require-dev": { + "phpunit/phpunit": "*" + } +} diff --git a/app_old/aldarien/view/config/locations.php b/app_old/aldarien/view/config/locations.php new file mode 100644 index 0000000..1dd0425 --- /dev/null +++ b/app_old/aldarien/view/config/locations.php @@ -0,0 +1,8 @@ + root(), + 'cache' => '{locations.base}/cache', + 'resources' => '{locations.base}/resources', + 'views' => '{locations.resources}/views' +]; +?> \ No newline at end of file diff --git a/app_old/aldarien/view/phpunit.xml b/app_old/aldarien/view/phpunit.xml new file mode 100644 index 0000000..e60ecbd --- /dev/null +++ b/app_old/aldarien/view/phpunit.xml @@ -0,0 +1,17 @@ + + + + + ./tests/ + + + + + ./app + + + \ No newline at end of file diff --git a/app_old/aldarien/view/public/index.php b/app_old/aldarien/view/public/index.php new file mode 100644 index 0000000..1070f11 --- /dev/null +++ b/app_old/aldarien/view/public/index.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/app_old/aldarien/view/resources/views/base.blade.php b/app_old/aldarien/view/resources/views/base.blade.php new file mode 100644 index 0000000..8cafca1 --- /dev/null +++ b/app_old/aldarien/view/resources/views/base.blade.php @@ -0,0 +1,9 @@ + + + + View + + +View test + + \ No newline at end of file diff --git a/app_old/aldarien/view/tests/ViewTest.php b/app_old/aldarien/view/tests/ViewTest.php new file mode 100644 index 0000000..85f4aa6 --- /dev/null +++ b/app_old/aldarien/view/tests/ViewTest.php @@ -0,0 +1,22 @@ + + + + View + + +View test + + +DATA; + $this->assertEquals($output, view('base')); + } +} +?> \ No newline at end of file diff --git a/app_old/app/Alias/Connection.php b/app_old/app/Alias/Connection.php new file mode 100644 index 0000000..1eea52a --- /dev/null +++ b/app_old/app/Alias/Connection.php @@ -0,0 +1,50 @@ +connection)) { + $r = 0; + $exception = null; + while ($r < $this->retries) { + try { + $dsn = $this->getDsn(); + $this->connection = new PDO($dsn, $this->username, $this->password); + return $this->connection; + } catch (PDOException $e) { + if ($exception !== null) { + $e = new PDOException($e->getMessage(), $e->getCode(), $exception); + } + $exception = $e; + usleep(500); + } + $r ++; + } + throw $exception; + } + return $this->connection; + } + protected function getDsn(): string + { + $dsn = "mysql:host={$this->host};dbname={$this->database}"; + if (isset($this->port)) { + $dsn .= ";port={$this->port}"; + } + return $dsn; + } +} diff --git a/app_old/app/Alias/Excel/Style/Mes.php b/app_old/app/Alias/Excel/Style/Mes.php new file mode 100644 index 0000000..368246b --- /dev/null +++ b/app_old/app/Alias/Excel/Style/Mes.php @@ -0,0 +1,18 @@ +setNumFormat('mmm-YY'); + $format->setAlign('center'); + } +} diff --git a/app_old/app/Alias/Format.php b/app_old/app/Alias/Format.php new file mode 100644 index 0000000..0ca615c --- /dev/null +++ b/app_old/app/Alias/Format.php @@ -0,0 +1,17 @@ + diff --git a/app_old/app/Alias/Model.php b/app_old/app/Alias/Model.php new file mode 100644 index 0000000..59ada5e --- /dev/null +++ b/app_old/app/Alias/Model.php @@ -0,0 +1,87 @@ +id; + $orm = $this->orm; + $ref = new \ReflectionObject($orm); + if (!$ref->hasProperty('_dirty_fields')) { + return; + } + $dirty = $ref->getProperty('_dirty_fields'); + $dirty->setAccessible(true); + $new_values = $dirty->getValue($orm); + $changes = array_combine(array_keys($new_values), array_fill(0, count($new_values), ['old' => '', 'new' => ''])); + if ($this->isNew()) { + $old = (object) array_combine(array_keys($new_values), array_fill(0, count($new_values), '')); + } else { + $old = model(get_called_class())->findOne($this->{$this->getId()}); + } + foreach ($new_values as $column => $value) { + $changes[$column] = ['column' => $column, 'old' => $old->$column, 'new' => $value]; + } + $action = '[' . get_called_class() . ']'; + doLog($user, $action, $changes); + } + public function getId() + { + if (property_exists(get_called_class(), '_id_column')) { + return static::$_id_column; + } + return $this->id; + } + public function save() + { + $ref = new \ReflectionObject($this); + if ($ref->hasProperty('_timestamps')) { + $ref = $ref->getProperty('_timestamps'); + $ref->setAccessible(true); + if ($ref->getValue()) { + if ($this->is_new()) { + $this->setExpr('created_at', 'NOW()'); + } + $this->setExpr('updated_at', 'NOW()'); + } + } + if (!\ORM::getDb()->inTransaction()) { + \ORM::getDb()->beginTransaction(); + } + try { + parent::save(); + if (\ORM::getDb()->inTransaction()) { + \ORM::getDb()->commit(); + } + } catch (\Exception $e) { + if (\ORM::getDb()->inTransaction()) { + \ORM::getDb()->rollBack(); + } + throw $e; + } + $this->log(); + } + public function __call($method, $args) + { + if (!method_exists($this, $method)) { + $str = '' . Stringy::create($method)->underscored(); + if (method_exists($this, $str)) { + return call_user_func_array([$this, $str], $args); + } + throw new \BadMethodCallException($method . ' not found in ' . get_class($this)); + } + return call_user_func_array([$this, $str], $args); + } +} +?> diff --git a/app_old/app/Alias/NewEstado.php b/app_old/app/Alias/NewEstado.php new file mode 100644 index 0000000..d884bb6 --- /dev/null +++ b/app_old/app/Alias/NewEstado.php @@ -0,0 +1,21 @@ +fecha, config('app.timezone')); + } +} +?> diff --git a/app_old/app/Alias/NewModel.php b/app_old/app/Alias/NewModel.php new file mode 100644 index 0000000..1c513b4 --- /dev/null +++ b/app_old/app/Alias/NewModel.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/app_old/app/Alias/NewTipo.php b/app_old/app/Alias/NewTipo.php new file mode 100644 index 0000000..b5fa3fb --- /dev/null +++ b/app_old/app/Alias/NewTipo.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/app_old/app/Alias/OldModel.php b/app_old/app/Alias/OldModel.php new file mode 100644 index 0000000..b3f9730 --- /dev/null +++ b/app_old/app/Alias/OldModel.php @@ -0,0 +1,8 @@ + diff --git a/app_old/app/Alias/PHPExcel.php b/app_old/app/Alias/PHPExcel.php new file mode 100644 index 0000000..ab98f53 --- /dev/null +++ b/app_old/app/Alias/PHPExcel.php @@ -0,0 +1,155 @@ +name = $name; + $this->filename = $filename; + } + public function addColumns($fields) + { + $columns = []; + foreach ($fields as $i => $field) { + if (is_object($field)) { + if (isset($field->style)) { + $style = $this->getExcelStyle($field->style); + } else { + $style = $this->getExcelStyle(); + } + $column = new ExcelHelper\Column($field->name, $field->name, 10, $style); + } elseif (is_array($field)) { + if (isset($field['style'])) { + $style = $this->getExcelStyle($field['style']); + } else { + $style = $this->getExcelStyle(); + } + $column = new ExcelHelper\Column($field['name'], $field['name'], 10, $style); + } else { + $style = $this->getExcelStyle(); + $column = new ExcelHelper\Column($field, $field, 10, $style); + } + $columns []= $column; + } + $collection = new ExcelHelper\ColumnCollection($columns); + $this->columns = $collection; + } + protected function getExcelStyle($style = 'text') + { + switch (strtolower($style)) { + case 'date': + return new ExcelHelper\CellStyle\Date(); + case 'mes': + return new \App\Alias\Excel\Style\Mes(); + case 'currency': + case 'amount': + return new ExcelHelper\CellStyle\Amount(); + case 'number': + case 'integer': + return new ExcelHelper\CellStyle\Integer(); + case 'percent': + case 'percentage': + return new ExcelHelper\CellStyle\Percentage(); + case 'text': + case 'string': + default: + return new ExcelHelper\CellStyle\Text(); + } + } + public function addData($data) + { + if ($this->data == null) { + $this->data = []; + } + $this->data = array_merge($data); + } + public function addRow($rowData) + { + if ($this->data == null) { + $this->data = []; + } + $this->data []= $rowData; + } + public function addTotals($totals) + { + $columns = (array) $this->columns; + $columns = array_pop($columns); + $ts = []; + foreach ($columns as $column) { + $col = $column->getHeading(); + if (isset($totals[$col])) { + $ts[$col] = $this->getTotal($col, $totals[$col]); + continue; + } + $ts[$col] = ''; + } + $this->data []= $ts; + } + protected function getTotal($col, $aggr) + { + $col_num = $this->getColNumber($col); + $col = $this->getColName($col_num); + switch(strtolower($aggr)) { + case 'sum': + $num = 109; + break; + case 'count': + $num = 102; + break; + case 'counta': + $num = 103; + break; + default: + $num = 0; + } + if ($num > 0) { + $end = count($this->data) + 2; + $str = "=SUBTOTAL({$num};{$col}3:{$col}{$end})"; + return $str; + } + return $aggr; + } + protected function getColNumber($col) + { + $columns = (array) $this->columns; + $columns = array_keys(array_pop($columns)); + return array_search($col, $columns); + } + protected function getColName($col_num) + { + $cols = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $N = strlen($cols); + $name = ''; + if ($col_num > $N) { + $name .= $cols[floor($col_num / $N)]; + $col_num = $N * ($col_num / $N - floor($col_num / $N)); + } + $name .= $cols[$col_num]; + return $name; + } + public function informe() + { + header("Content-Type: application/octet-stream; charset=utf-8"); + header('Content-Transfer-Encoding: binary'); + header('Content-Disposition: attachment; filename="' . $this->filename . '"'); + header('Cache-Control: max-age=0'); + + $pE = new ExcelHelper\TableWorkbook('php://output'); + $ws = $pE->addWorksheet($this->name); + + $table = new ExcelHelper\Table($ws, 0, 0, $this->name, new \ArrayIterator($this->data)); + $table->setColumnCollection($this->columns); + + $pE->writeTable($table); + + $pE->close(); + } +} diff --git a/app_old/app/Alias/RemoteConnection.php b/app_old/app/Alias/RemoteConnection.php new file mode 100644 index 0000000..475225e --- /dev/null +++ b/app_old/app/Alias/RemoteConnection.php @@ -0,0 +1,17 @@ +retries + ); + } +} diff --git a/app_old/app/Command/Money/Get.php b/app_old/app/Command/Money/Get.php new file mode 100644 index 0000000..606c8b1 --- /dev/null +++ b/app_old/app/Command/Money/Get.php @@ -0,0 +1,87 @@ +title('Get Money'); + + $dates = $this->getDates(); + foreach ($dates as $date_string => $ids) { + $date = $this->parseDate($date_string); + $response = $this->service->getUF($date); + if ($response->total === 0) { + continue; + } + foreach ($ids as $id) { + $this->queueUpdate($id, $response->uf->value); + } + } + $this->updateUF(); + return Command::SUCCESS; + } + + protected function getDates(): array + { + $query = "SELECT id, fecha FROM pago WHERE uf IS NULL AND fecha BETWEEN 0 AND DATE_ADD(CURDATE(), INTERVAL 9 DAY) ORDER BY fecha"; + $statement = $this->connection->connect()->query($query); + $rows = $statement->fetchAll(PDO::FETCH_ASSOC); + if (count($rows) === 0) { + return []; + } + $dates = []; + foreach ($rows as $row) { + if (!isset($dates[$row['fecha']])) { + $dates[$row['fecha']] = []; + } + $dates[$row['fecha']] []= (int) $row['id']; + } + return $dates; + } + protected function parseDate(string $date_string): DateTimeInterface + { + return new DateTimeImmutable($date_string); + } + protected array $rows; + protected function queueUpdate(int $id, float $value): void + { + $this->rows []= [$value, $id]; + } + protected function updateUF(): void + { + $query = "UPDATE pago SET uf = ? WHERE id = ?"; + $statement = $this->connection->connect()->prepare($query); + foreach ($this->rows as $row) { + $this->connection->connect()->beginTransaction(); + try { + $statement->execute($row); + $this->connection->connect()->commit(); + } catch (PDOException $e) { + $this->connection->connect()->rollBack(); + } + } + } +} diff --git a/app_old/app/Command/Money/Lookup.php b/app_old/app/Command/Money/Lookup.php new file mode 100644 index 0000000..2b87b28 --- /dev/null +++ b/app_old/app/Command/Money/Lookup.php @@ -0,0 +1,52 @@ +title('Lookup Money'); + + while (true) { + $io->info('Checking pending'); + if ($this->hasPendingMoney()) { + $io->success('Running money get UF'); + $io->note($this->runGetUF()); + } + } + return Command::SUCCESS; + } + + protected function hasPendingMoney(): bool + { + $query = "SELECT 1 FROM pago WHERE uf IS NULL AND fecha BETWEEN 0 AND DATE_ADD(CURDATE(), INTERVAL 9 DAY)"; + $statement = $this->connection->connect()->query($query); + return $statement->rowCount() > 0; + } + protected function runGetUF(): string + { + $command = "/code/bin/console money:uf:get"; + $result = shell_exec($command); + if (!$result or $result === null) { + throw new \Exception(); + } + return $result; + } +} diff --git a/app_old/app/Contract/Auth.php b/app_old/app/Contract/Auth.php new file mode 100644 index 0000000..fb2e3b6 --- /dev/null +++ b/app_old/app/Contract/Auth.php @@ -0,0 +1,27 @@ + \ No newline at end of file diff --git a/app_old/app/Contract/Route.php b/app_old/app/Contract/Route.php new file mode 100644 index 0000000..fd4a84c --- /dev/null +++ b/app_old/app/Contract/Route.php @@ -0,0 +1,27 @@ + \ No newline at end of file diff --git a/app_old/app/Controller/API/Unidades.php b/app_old/app/Controller/API/Unidades.php new file mode 100644 index 0000000..b7abead --- /dev/null +++ b/app_old/app/Controller/API/Unidades.php @@ -0,0 +1,41 @@ +findOne($id_proyecto); + if (!$proyecto) { + throw new \InvalidArgumentException('Proyecto identificado por ' . $id_proyecto . ' no existe.'); + } + $unidades = $proyecto->unidades($id_tipo); + $unidades = array_filter($unidades, function($item) { + return !$item->isVendida() and !$item->isReservada(); + }); + $unidades = array_map(function($item) { + return $item->asArray(); + }, $unidades); + usort($unidades, function($a, $b) { + $ap = strpos($a['descripcion'], ' '); + $ad = $a['descripcion']; + if ($ap != false) { + $ad = substr($ad, 0, $ap); + } + $bd = $b['descripcion']; + $bp = strpos($b['descripcion'], ' '); + if ($bp != false) { + $bd = substr($bd, 0, $bp); + } + return strcmp( + str_pad($ad, 4, '0', \STR_PAD_LEFT), + str_pad($bd, 4, '0', \STR_PAD_LEFT) + ); + }); + $output = array_values($unidades); + $response->getBody()->write(\json_encode($output)); + return $response->withHeader('Content-Type', 'application/json'); + } +} diff --git a/resources/less/Controller/Admin.php b/app_old/app/Controller/Admin.php similarity index 100% rename from resources/less/Controller/Admin.php rename to app_old/app/Controller/Admin.php diff --git a/resources/less/Controller/Ajax.php b/app_old/app/Controller/Ajax.php similarity index 100% rename from resources/less/Controller/Ajax.php rename to app_old/app/Controller/Ajax.php diff --git a/app_old/app/Controller/Auth.php b/app_old/app/Controller/Auth.php new file mode 100644 index 0000000..74c9d78 --- /dev/null +++ b/app_old/app/Controller/Auth.php @@ -0,0 +1,59 @@ +render($response, 'auth.login'); + } + public function do_login(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface + { + $post = $request->getParsedBody(); + $name = $post['name']; + $password = $post['password']; + $bool = sAuth::login($name, $password); + if ($bool) { + return $response->withStatus(301)->withHeader('Location', '/'); + } + return $response->withStatus(301)->withHeader('Location', '/auth/login'); + } + public function logout(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface + { + sAuth::logout(); + return $response + ->withStatus(301) + ->withHeader('Location', '/'); + } + public function check_pass(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface + { + if (\password_verify(post('password'), sAuth::User()->password)) { + $response->getBody()->write('OK'); + } else { + $response->getBody()->write('KO'); + } + return $response; + } + public function change_pass(ServerRequestInterface $request, ResponseInterface $response, View $view): ResponseInterface + { + return $view->render($response, 'auth.change_pass'); + } + public function do_change_pass(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface + { + $post = $request->getParsedBody(); + if (\password_verify($post['old'], sAuth::User()->password)) { + if ($post['new'] == $post['new2']) { + $user = sAuth::User(); + $user->password($post['new']); + $user->save(); + return $response->withStatus(301)->withHeader('Location', '/'); + } + } + return $response->withStatus(301)->withHeader('Location', '/auth/change_pass'); + } +} diff --git a/app_old/app/Controller/Bonos.php b/app_old/app/Controller/Bonos.php new file mode 100644 index 0000000..32daaa5 --- /dev/null +++ b/app_old/app/Controller/Bonos.php @@ -0,0 +1,67 @@ +findOne($id_venta); + return view('ventas.bonos.add', compact('venta')); + } + public static function do_add() + { + $id_venta = get('venta'); + $venta = model(Venta::class)->findOne($id_venta); + if ($venta->bono_pie != 0) { + header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); + return; + } + $uf = uf($venta->fecha()); + $valor = post('valor'); + $data = [ + 'fecha' => $venta->fecha, + 'valor' => $valor * $uf->uf->value, + 'tipo' => 8, + 'uf' => $uf->uf->value + ]; + $pago = model(Pago::class)->create($data); + $pago->save(); + $data = [ + 'valor' => $valor, + 'pago' => $pago->id + ]; + $bono = model(BonoPie::class)->create($data); + $bono->save(); + $venta->bono_pie = $bono->id; + $venta->save(); + header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); + } + public static function edit() + { + $id_venta = get('venta'); + $venta = model(Venta::class)->findOne($id_venta); + return view('ventas.bonos.edit', compact('venta')); + } + public static function do_edit() + { + $id_venta = get('venta'); + $venta = model(Venta::class)->findOne($id_venta); + $bono = $venta->bonoPie(); + $valor = post('valor') * $bono->pago()->uf(); + $pago = $bono->pago(); + if ($valor != $bono->pago()->valor()) { + $pago->valor = $valor; + $pago->save(); + } + header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); + exit(); + } +} diff --git a/resources/less/Controller/Buscar.php b/app_old/app/Controller/Buscar.php similarity index 100% rename from resources/less/Controller/Buscar.php rename to app_old/app/Controller/Buscar.php diff --git a/app_old/app/Controller/Cierres.php b/app_old/app/Controller/Cierres.php new file mode 100644 index 0000000..46a76b9 --- /dev/null +++ b/app_old/app/Controller/Cierres.php @@ -0,0 +1,428 @@ +select('proyecto.*') + ->join('estado_proyecto', ['estado.proyecto', '=', 'proyecto.id'], 'estado') + ->join('tipo_estado_proyecto', ['tipo.id', '=', 'estado.estado'], 'tipo') + ->join('etapa_proyecto', ['etapa.id', '=', 'tipo.etapa'], 'etapa') + ->whereGte('etapa.orden', 3) + ->orderByAsc('proyecto.descripcion') + ->groupBy('proyecto.id') + ->findMany(); + $regiones = model(Region::class)->order_by_asc('numeracion')->findMany(); + return view('ventas.cierres.add', compact('proyectos', 'regiones')); + } + public static function agregar() + { + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $id_proyecto = post('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id_proyecto); + $id_agente = post('agente'); + $agente = model(Agente::class)->findOne($id_agente); + + $direccion = model(Direccion::class) + ->where('calle', post('calle')) + ->where('numero', post('numero')) + ->where('extra', post('extra')) + ->where('comuna', post('comuna')) + ->findOne(); + if (!$direccion) { + $data = [ + 'calle' => post('calle'), + 'numero' => post('numero'), + 'extra' => post('extra'), + 'comuna' => post('comuna') + ]; + $direccion = model(Direccion::class)->create($data); + $direccion->save(); + } + + list($rut, $dv) = explode('-', str_replace('.', '', post('rut'))); + $propietario = model(Propietario::class)->findOne($rut); + if (!$propietario) { + $data = [ + 'rut' => $rut, + 'dv' => $dv, + 'nombres' => trim(post('nombres')), + 'apellido_paterno' => post('paterno'), + 'apellido_materno' => post('materno'), + 'sexo' => post('sexo'), + 'estado_civil' => post('estado_civil'), + 'profesion' => post('profesion'), + 'direccion' => $direccion->id, + 'telefono' => post('codigo_telefono') . post('telefono'), + 'email' => post('email') . '@' . post('email_domain'), + 'representante' => 0, + 'otro' => 0 + ]; + $propietario = model(Propietario::class)->create($data); + $propietario->save(); + } + + $unis = json_decode(post('unidades')); + $id_principal = array_shift($unis); + $unidad = model(Unidad::class)->findOne(post('unidad' . $id_principal)); + $u = model(U::class)->findOne($unidad->id); + if (!$u) { + $unidad->save(); + } + $data = [ + 'unidad_id' => $unidad->id + ]; + $reserva = model(Reserva::class)->create($data); + $reserva->save(); + foreach ($unis as $id_unidad) { + $unidad = model(Unidad::class)->findOne(post('unidad' . $id_unidad)); + $data = [ + 'reserva_id' => $reserva->id, + 'unidad_id' => $unidad->id + ]; + $ur = model(UnidadReserva::class)->create($data); + $ur->save(); + } + + $data = [ + 'proyecto_id' => $proyecto->id, + 'agente_id' => $agente->id, + 'propietario_rut' => $propietario->rut, + 'reserva_id' => $reserva->id, + 'fecha' => $f->format('Y-m-d'), + 'valor' => correctNumber(post('valor')), + 'pie' => correctNumber(post('pie')), + 'credito' => correctNumber(post('credito')), + 'estado' => 1 + ]; + $cierre = model(Cierre::class)->create($data); + $cierre->save(); + header('Location: ' . url('', ['p' => 'cierres', 'a' => 'list'])); + } + public static function list() + { + $proyectos = Cierre::proyectos(); + + return view('ventas.cierres.list', compact('proyectos')); + } + public static function show() + { + $id = get('cierre'); + $cierre = model(Cierre::class)->findOne($id); + + return view('ventas.cierres.show', compact('cierre')); + } + public static function guardar() + { + $proyecto = \model(Proyecto::class)->findOne(post('proyecto')); + $fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $unidad = \model(Unidad::class)->findOne(post('departamento')); + $relacionado = (post('relacionado') === true) ? true : false; + $subrelacionado = (post('subrelacionado') === true) ? true : false; + $precio = (float) post('precio') ?: 0; + $input = [ + 'proyecto' => $proyecto, + 'fecha' => $fecha, + 'departamento' => $unidad, + 'precio' => $precio, + 'relacionado' => $relacionado, + 'subrelacionado' => $subrelacionado, + 'unidades' => [], + 'pie' => (float) post('pie') + ]; + $ebs = 0; + if (post('unidades') != '') { + $unidades = json_decode(html_entity_decode(post('unidades')), true); + foreach ($unidades as $un) { + $u = \model(Unidad::class)->findOne($un); + $input['unidades'] []= $u; + if ($u->precio($fecha) !== false) { + $ebs += $u->precio($fecha)->valor; + } + } + } + $promo = 0; + if (post('promocion') != null) { + $promo = (float) post('promocion'); + $input['promocion'] = $promo; + } + $bono = 0; + if (post('bono') != null) { + $bono = (float) post('bono'); + $input['bono'] = $bono; + } + $operador = 0; + if (post('operador') != null) { + $operador = ($precio - $bono - $promo) * (float) post('operador') / 100; + $input['operador'] = $operador; + } + + $cierre = Cierre::find($proyecto, $unidad, $precio)->findOne(); + if ($cierre === false) { + $cierre = model(Cierre::class)->create(); + $cierre->guardar((object) $input); + } + $output = ['status' => 'ok', 'cierre' => $cierre->asArray()]; + return json_encode($output); + } + public static function aprobar() + { + $fecha = Carbon::today(config('app.timezone')); + $cierre = model(Cierre::class)->findOne(post('cierre')); + if ($cierre->estado()->tipo()->descripcion == "revisado" or $cierre->estado()->tipo()->descripcion == "rechazado") { + $cierre->aprobar($fecha); + return json_encode(['estado' => 'aprobado']); + } + return json_encode(['estado' => 'no vigente']); + } + public static function rechazar() + { + $fecha = Carbon::today(config('app.timezone')); + $cierre = model(Cierre::class)->findOne(post('cierre')); + if ($cierre->estado()->tipo()->vigente == 1) { + $cierre->rechazar($fecha); + return json_encode(['estado' => 'rechazado']); + } + return json_encode(['estado' => 'no vigente']); + } + public static function abandonar() + { + $id = get('cierre'); + $cierre = model(Cierre::class)->findOne($id); + $tipo = model(TipoEstadoCierre::class)->where('descripcion', 'abandonado')->findOne(); + $today = Carbon::today(config('app.timezone')); + $data = [ + 'cierre' => $cierre->id, + 'tipo' => $tipo->id, + 'fecha' => $today->format('Y-m-d') + ]; + $estado = model(EstadoCierre::class)->create($data); + $estado->save(); + header('Location: ' . url('', ['p' => 'cierres', 'a' => 'list'])); + } + public static function promesar() + { + $id = get('cierre'); + $cierre = model(Cierre::class)->findOne($id); + $tipo = model(TipoEstadoCierre::class)->where('descripcion', 'promesado')->findOne(); + $today = Carbon::today(config('app.timezone')); + $data = [ + 'cierre' => $cierre->id, + 'tipo' => $tipo->id, + 'fecha' => $today->format('Y-m-d') + ]; + $estado = model(EstadoCierre::class)->create($data); + $estado->save(); + header('Location: ' . url('', ['p' => 'cierres', 'a' => 'show', 'cierre' => $cierre->id])); + } + public static function borrador() + { + $id = get('cierre'); + $cierre = model(Cierre::class)->findOne($id); + + $borrador = new Borrador($cierre); + d($borrador->show()); + $borrador->create(); + } + public static function evalue() + { + $proyectos = \model(Proyecto::class)->orderByAsc('descripcion')->findMany(); + return view('ventas.cierres.evaluar', ['proyectos' => $proyectos, 'locations' => config('locations')]); + } + public static function evaluar() + { + $proyecto = \model(Proyecto::class)->findOne(post('proyecto')); + $fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $unidad = \model(Unidad::class)->findOne(post('departamento')); + $relacionado = (post('relacionado') === 'true') ? true : false; + $subrelacionado = (post('subrelacionado') === 'true') ? true : false; + $precio = (float) post('precio') ?: 0; + $neto = $precio; + $ebs = 0; + if (post('unidades') != '') { + $unidades = json_decode(html_entity_decode(post('unidades')), true); + foreach ($unidades as $un) { + $u = \model(Unidad::class)->findOne($un); + if ($u->precio($fecha) !== false) { + $ebs += $u->precio($fecha)->valor; + } + } + } + $promocion = 0; + if (post('promocion') != null) { + $promocion = (float) post('promocion'); + } + $bono = 0; + if (post('bono') != null) { + $bono = (float) post('bono'); + } + $operador = 0; + if (post('operador') != null) { + $operador = ($precio - $bono - $promocion) * (float) post('operador') / 100; + } + $rel = 0; + if ($relacionado) { + $rel = ($unidad->precio($fecha)->valor) * 6 / 100; + } + if ($subrelacionado) { + $rel = ($unidad->precio($fecha)->valor) * 3 / 100; + } + $neto = $precio - $bono - $promocion - $operador - $ebs; + + $output = [ + 'unidad' => [ + 'tipo' => [ + 'nombre' => $unidad->tipologia()->nombre, + 'tipologia' => $unidad->tipologia()->tipologia()->descripcion + ], + 'superficie' => format('m2', $unidad->m2()) . ' m²' + ], + 'oferta' => [ + 'bruto' => format('ufs', $precio, null, true), + 'neto' => format('ufs', $neto, null, true), + 'uf_m2' => format('ufs', $neto / $unidad->m2('vendible'), null, true) . '/m²', + 'fecha' => format('shortDate', $unidad->precio($fecha)->inicio()->fecha()) + ], + 'lista' => [ + 'precio' => format('ufs', $unidad->precio($fecha)->valor, null, true), + 'uf_m2' => format('ufs', $unidad->precio($fecha)->valor / $unidad->m2('vendible'), null, true) . '/m²' + ], + 'precios' => [ + 'bruto' => format('ufs', $precio, null, true), + 'neto' => format('ufs', $neto, null, true), + 'departamento' => format('ufs', $unidad->precio($fecha)->valor, null, true), + 'relacionado' => format('ufs', $unidad->precio($fecha)->valor - $rel, null, true), + 'fecha' => format('shortDate', $unidad->precio($fecha)->inicio()->fecha()) + ], + 'uf_m2' => [ + 'neto' => format('ufs', $neto / $unidad->m2('vendible'), null, true) . '/m²', + 'departamento' => format('ufs', $unidad->precio($fecha)->valor / $unidad->m2('vendible'), null, true) . '/m²', + 'relacionado' => format('ufs', ($unidad->precio($fecha)->valor - $rel) / $unidad->m2('vendible'), null, true) . '/²' + ], + 'evaluacion' => Cierre::evaluar($neto, $unidad, $fecha, $rel), + 'estado' => ['id' => 0, 'descripcion' => 'no existe'] + ]; + if ($rel > 0) { + $output ['relacionado'] = [ + 'precio' => format('ufs', $unidad->precio($fecha)->valor - $rel, null, true), + 'uf_m2' => format('ufs', ($unidad->precio($fecha)->valor - $rel) / $unidad->m2('vendible'), null, true) . '/²' + ]; + } + $estado = Cierre::find($proyecto, $unidad, $precio)->findOne(); + if ($estado) { + $output['estado'] = [ + 'id' => $estado->estado()->tipo()->id, + 'cierre' => $estado->id, + 'descripcion' => $estado->estado()->tipo()->descripcion, + 'fecha' => format('shortDate', $estado->estado()->fecha) + ]; + } + + return json_encode($output); + } + public static function edit() + { + $cierre = model(Cierre::class)->findOne(get('cierre')); + $proyectos = model(Proyecto::class)->findMany(); + $regiones = model(Region::class)->findMany(); + $valores = model(TipoValorCierre::class)->findMany(); + return view('ventas.cierres.edit', compact('cierre', 'proyectos', 'regiones', 'valores')); + } + public static function do_edit() + { + $cierre = model(Cierre::class)->findOne(get('cierre')); + + $data = [ + 'calle' => post('calle'), + 'numero' => post('numero'), + 'extra' => post('extra'), + 'comuna' => post('comuna') + ]; + $direccion = (new Factory(Direccion::class))->where($data)->find(); + if (!$direccion) { + $direccion = model(Direccion::class)->create($data); + $direccion->save(); + } + if (post('rut') != '') { + $data = [ + 'rut' => explode('-', str_replace('.', '', post('rut')))[0], + ]; + $propietario = (new Factory(Propietario::class))->where($data)->find(); + if (!$propietario) { + $data = array_merge($data, [ + 'nombres' => post('nombres'), + 'apellido_paterno' => post('paterno'), + 'apellido_materno' => post('materno'), + 'dv' => (post('rut')) ? explode('-', str_replace('.', '', post('rut')))[1] : '', + 'sexo' => post('sexo'), + 'estado_civil' => post('estado_civil'), + 'profesion' => post('profesion'), + 'telefono' => post('codigo_telefono') . post('telefono'), + 'email' => post('email') . '@' . post('email_domain'), + 'direccion' => $direccion->id + ]); + $propietario = model(Propietario::class)->create($data); + $propietario->save(); + } + } + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $data = [ + 'proyecto' => post('proyecto'), + 'precio' => post('precio'), + 'fecha' => $f->format('Y-m-d'), + 'relacionado' => (post('relacionado')) ? 1 : 0, + 'propietario' => (isset($propietario) and $propietario) ? $propietario->rut : 0 + ]; + foreach ($data as $field => $value) { + if ($value != $cierre->$field) { + $cierre->$field = $value; + } + } + $cierre->save(); + + $valores = model(TipoValorCierre::class)->findMany(); + foreach ($valores as $valor) { + if (post($valor->descripcion) == '') { + continue; + } + if ($cierre->valor($valor->descripcion)) { + if ($cierre->valor($valor->descripcion)->valor != post($valor->descripcion)) { + $v = $cierre->valor($valor->descripcion); + $v->valor = post($valor->descripcion); + $v->save(); + } + continue; + } + $data = [ + 'tipo' => $valor->descripcion, + 'valor' => post($valor->descripcion) + ]; + $cierre->addValor($data); + } + header('Location: ' . nUrl('cierres', 'show', ['cierre' => $cierre->id])); + } +} +?> diff --git a/resources/less/Controller/Comentarios.php b/app_old/app/Controller/Comentarios.php similarity index 100% rename from resources/less/Controller/Comentarios.php rename to app_old/app/Controller/Comentarios.php diff --git a/app_old/app/Controller/Contabilidad.php b/app_old/app/Controller/Contabilidad.php new file mode 100644 index 0000000..4b19a77 --- /dev/null +++ b/app_old/app/Controller/Contabilidad.php @@ -0,0 +1,100 @@ +orderByAsc('descripcion')->findMany(); + foreach ($proyectos as &$proyecto) { + $arr = $proyecto->asArray(); + $arr['direccion'] = $proyecto->direccion()->asArray(); + $arr['direccion']['comuna'] = $proyecto->direccion()->comuna()->asArray(); + $arr['inmobiliaria'] = $proyecto->inmobiliaria()->asArray(); + $proyecto = $arr; + } + return json_encode(compact('proyectos')); + } + public static function get_fechas() { + $id_proyecto = get('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id_proyecto); + $cuotas = []; + foreach ($proyecto->ventas() as $venta) { + $cs = $venta->pie()->cuotas(); + $cuotas = array_merge($cs, array_filter($cs, function($item) { + $tipo = $item->pago()->estado()->tipo(); + return ($tipo == 'depositado' or $tipo == 'abonado'); + })); + } + $fechas = array_map(function($item) { + return [ + 'timestamp' => $item->pago()->estado()->fecha()->timestamp, + 'short' => $item->pago()->estado()->fecha()->format('Y-m-d'), + 'long' => $item->pago()->estado()->fecha()->format('d / m / Y') + ]; + }, $cuotas); + usort($fechas, function($a, $b) { + return $b['timestamp'] - $a['timestamp']; + }); + return json_encode(compact('fechas')); + } + public static function get_pagos_fechas() { + $id_proyecto = get('proyecto'); + $fecha = Carbon::parse(get('fecha')); + $proyecto = model(Proyecto::class)->findOne($id_proyecto); + $pagos = []; + foreach ($proyecto->ventas() as $venta) { + foreach ($venta->pie()->cuotas() as $cuota) { + if ($cuota->pago()->estado()->fecha() == $fecha) { + $pagos []= [ + 'Departamento' => $venta->propiedad()->unidad()->descripcion, + 'Valor' => [ + 'UF' => $cuota->pago()->valor('ufs'), + 'Pesos' => $cuota->pago()->valor() + ], + 'Numero' => $cuota->numero(), + 'Total' => $venta->pie()->cuotas + ]; + break; + } + } + } + return json_encode(compact('pagos')); + } + public static function pagos_fecha() { + $fecha = Carbon::now(); + return view('contabilidad.pagos', compact('fecha')); + } + public static function show_pagos() { + $id_proyecto = get('proyecto'); + $fecha = Carbon::parse(get('fecha')); + $proyecto = model(Proyecto::class)->findOne($id_proyecto); + $pagos = []; + foreach ($proyecto->ventas() as $venta) { + foreach ($venta->pie()->cuotas() as $cuota) { + if ($cuota->pago()->estado()->fecha() == $fecha) { + $pagos []= (object) [ + 'Departamento' => $venta->propiedad()->unidad()->descripcion, + 'Valor' => (object) [ + 'UF' => $cuota->pago()->valor('ufs'), + 'Pesos' => $cuota->pago()->valor() + ], + 'Numero' => $cuota->numero(), + 'Total' => $venta->pie()->cuotas + ]; + break; + } + } + } + return view('contabilidad.pago', compact('proyecto', 'fecha', 'pagos')); + } +} diff --git a/resources/less/Controller/Creditos.php b/app_old/app/Controller/Creditos.php similarity index 100% rename from resources/less/Controller/Creditos.php rename to app_old/app/Controller/Creditos.php diff --git a/resources/less/Controller/Cuotas.php b/app_old/app/Controller/Cuotas.php similarity index 100% rename from resources/less/Controller/Cuotas.php rename to app_old/app/Controller/Cuotas.php diff --git a/resources/less/Controller/Devoluciones.php b/app_old/app/Controller/Devoluciones.php similarity index 100% rename from resources/less/Controller/Devoluciones.php rename to app_old/app/Controller/Devoluciones.php diff --git a/resources/less/Controller/Escrituras.php b/app_old/app/Controller/Escrituras.php similarity index 100% rename from resources/less/Controller/Escrituras.php rename to app_old/app/Controller/Escrituras.php diff --git a/resources/less/Controller/FormaPago.php b/app_old/app/Controller/FormaPago.php similarity index 100% rename from resources/less/Controller/FormaPago.php rename to app_old/app/Controller/FormaPago.php diff --git a/app_old/app/Controller/Home.php b/app_old/app/Controller/Home.php new file mode 100644 index 0000000..fa31ea6 --- /dev/null +++ b/app_old/app/Controller/Home.php @@ -0,0 +1,85 @@ +getCantidadCuotasDias(); + $cierres = $this->getCierres(); + $pendientes = $this->getCantidadCuotasPendientes(); + $hoy = $this->getCantidadCuotasHoy(); + return $view->render($response, 'home', compact('pendientes', 'hoy', 'dias', 'cierres')); + } + + protected array $proyectos; + protected function getProyectos(): array + { + if (!isset($this->proyectos)) { + $this->proyectos = model(Proyecto::class)->findMany(); + } + return $this->proyectos; + } + protected function getCantidadCuotasPendientes(): int + { + $pendientes = 0; + $proyectos = $this->getProyectos(); + foreach ($proyectos as $proyecto) { + $pendientes += $proyecto->cuotasPendientes(); + } + return $pendientes; + } + protected function getCantidadCuotasDias(): array + { + $dias = []; + $proyectos = $this->getProyectos(); + foreach ($proyectos as $proyecto) { + foreach ($proyecto->cuotasMes() as $cuota) { + $f = $cuota->pago()->fecha(); + if ($f->isoWeekday() == 6 or $f->isoWeekDay() == 7) { + $f = $f->copy()->addDays(2)->startOfWeek(); + } + $dia = $f->format('Y-m-d'); + if (!isset($dias[$dia])) { + $dias[$dia] = [$proyecto->descripcion => 0]; + } + if (!isset($dias[$dia][$proyecto->descripcion])) { + $dias[$dia][$proyecto->descripcion] = 0; + } + $dias[$dia][$proyecto->descripcion] ++; + } + } + uksort($dias, function($a, $b) { + return strcmp($a, $b); + }); + return $dias; + } + protected function getCantidadCuotasHoy(): int + { + $hoy = 0; + $proyectos = $this->getProyectos(); + foreach ($proyectos as $proyecto) { + $hoy += $proyecto->cuotasHoy(); + } + return $hoy; + } + protected function getCierres(): array + { + $cierres = []; + $proyectos = $this->getProyectos(); + foreach ($proyectos as $proyecto) { + if (count($proyecto->cierres()) > 0) { + $cierres[$proyecto->descripcion] = (object) ['total' => count($proyecto->cierres()),'vigentes' => $proyecto->cierres(3), 'rechazados' => $proyecto->cierres(-1), 'pendientes' => $proyecto->cierres(2)]; + } + } + uksort($cierres, function($a, $b) { + return strcmp($a, $b); + }); + return $cierres; + } +} diff --git a/app_old/app/Controller/Informes.php b/app_old/app/Controller/Informes.php new file mode 100644 index 0000000..4ab5631 --- /dev/null +++ b/app_old/app/Controller/Informes.php @@ -0,0 +1,830 @@ +find_one($id_proyecto); + $ini = \Carbon\Carbon::parse($proyecto->estado()->fecha, config('app.timezone')); + #$informe = new Informador('Carta Gantt Proyecto - ' . $proyecto->descripcion); + $name = 'Carta Gantt Proyecto - ' . $proyecto->descripcion; + $hoy = Carbon::now(config('app.timezone')); + $filename = str_replace('ñ', 'n', $name . ' - ' . $hoy->format('Y-m-d') . '.xls'); + $informe = new PHPExcel($name, $filename); + + $columnas = ['Departamento', 'Propietario', 'Entrega', 'Estado']; + $today = \Carbon\Carbon::today(config('app.timezone')); + $end = $today->copy()->addDays(30); + $dif = $end->diffInDays($ini); + for ($i = 0; $i <= $dif; $i ++) { + $f = $ini->copy()->addDays($i); + if ($f->isWeekend()) { + continue; + } + $columnas []= $f->format('Y-m-d'); + } + $informe->addColumns($columnas); + + $data = []; + foreach ($proyecto->entregas() as $venta) { + $info = []; + $info []= $venta->unidad()->descripcion; + $info []= $venta->propietario()->findOne()->nombreCompleto(); + $fe = Carbon::parse($venta->entrega()->find_one()->fecha, config('app.timezone')); + $info []= $fe->format('Y-m-d'); + $info []= ''; + + for ($i = 0; $i <= $dif; $i ++) { + $f = $ini->copy()->addDays($i); + if ($f->isWeekend()) { + continue; + } + if ($f >= $fe and $f <= $fe->copy()->addDays(14)) { + $info []= 'X'; + } else { + $info []= ''; + } + } + + $data []= $info; + } + $informe->addDatas($data); + + return $informe->informe(); + } else { + $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many(); + return view('informes.gantt_entregas', compact('proyectos')); + } + } + public static function escrituras() + { + if (get('proyecto')) { + set_time_limit(60); + $id_proyecto = get('proyecto'); + $proyecto = model(Proyecto::class)->find_one($id_proyecto); + + #$informe = new Informador('Escrituras - ' . $proyecto->descripcion); + $name = 'Escrituras'; + $hoy = Carbon::now(config('app.timezone')); + $filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls'); + $informe = new PHPExcel($name, $filename); + + $columnas = [ + 'Departamento', + 'Estacionamientos', + 'Bodegas', + 'Propietario', + (object) ['name' => 'Promesa', 'style' => 'number'], + ['name' => 'Bono Pie', 'style' => 'amount'], + ['name' => 'Pie Pagado', 'style' => 'amount'], + ['name' => 'Reajuste', 'style' => 'amount'], + ['name' => 'Abono Contado', 'style' => 'amount'], + ['name' => 'Subsidio', 'style' => 'amount'], + 'Estado Subsidio', + ['name' => 'Credito', 'style' => 'amount'], + 'Banco', + 'Estado Credito', + ['name' => 'Saldo', 'style' => 'amount'], + ['name' => 'Escritura', 'style' => 'amount'], + ['name' => 'Entrega', 'style' => 'date'] + ]; + $informe->addColumns($columnas); + + //$ventas = $proyecto->escrituras(); + $ventas = $proyecto->ventas(); + + $data = []; + foreach ($ventas as $venta) { + $info = []; + $info['Departamento'] = $venta->unidad()->descripcion; + $ests = []; + foreach ($venta->propiedad()->estacionamientos() as $e) { + $ests []= $e->descripcion; + } + $bods = []; + foreach ($venta->propiedad()->bodegas() as $b) { + $bods []= $b->descripcion; + } + $info['Estacionamientos'] = implode(' - ', $ests); + $info['Bodegas'] = implode(' - ', $bods); + $info['Propietario'] = $venta->propietario()->nombreCompleto(); + $info['Promesa'] = $venta->valor_uf; + $saldo = $venta->valor_uf; + $info['Bono Pie'] = ''; + if ($venta->bono_pie != 0) { + $info['Bono Pie'] = $venta->bonoPie()->pago()->valor('ufs'); + $saldo -= $venta->bonoPie()->pago()->valor('ufs'); + } + $info['Pie'] = ''; + $info['Reajuste'] = ''; + if ($venta->pie != 0) { + $info['Pie'] = $venta->pie()->valorPagado(); + $saldo -= $venta->pie()->valorPagado(); + if ($venta->pie()->reajuste != 0) { + $info['Reajuste'] = $venta->pie()->reajuste()->valor('ufs'); + $saldo -= $venta->pie()->reajuste()->valor('ufs'); + } + } + $info['Abono Contado'] = ''; + if ($venta->escritura != 0) { + $info['Abono Contado'] = $venta->escritura()->pago()->valor('ufs'); + $saldo -= $venta->escritura()->pago()->valor('ufs'); + } + $info['Subsidio'] = ''; + $info['Estado Subsidio'] = ''; + if ($venta->subsidio != 0) { + $info['Subsidio'] = $venta->subsidio()->total('ufs'); + $info['Estado Subsidio'] = implode(' - ', [ + $venta->subsidio()->subsidio()->estado()->tipo()->descripcion, + $venta->subsidio()->pago()->estado()->tipo()->descripcion + ]); + $saldo -= $venta->subsidio()->total('ufs'); + } + $info['Credito'] = ''; + $info['Banco'] = ''; + $info['Estado Credito'] = ''; + if ($venta->credito != 0) { + $info['Credito'] = $venta->credito()->pago()->valor('ufs'); + $saldo -= $venta->credito()->pago()->valor('ufs'); + if ($venta->credito()->pago()->banco != 0) { + $info['Banco'] = $venta->credito()->pago()->banco()->nombre; + } + $info['Estado Credito'] = $venta->credito()->pago()->estado()->tipo()->descripcion; + } + $info['Saldo'] = -$saldo; + $info['Escritura'] = ''; + if ($venta->escriturado != 0) { + $info['Escritura'] = $venta->escriturado; + } + $info['Entrega'] = ''; + if ($venta->entregado != 0) { + $info['Entrega'] = $venta->entregado; + } + + $data []= $info; + } + $informe->addData($data); + + return $informe->informe(); + } else { + $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many(); + return view('informes.escrituras', compact('proyectos')); + } + } + public static function consolidacion() + { + $id_proyecto = get('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id_proyecto); + + $ventas = $proyecto->ventas(); + set_time_limit(count($ventas)); + + $f = Carbon::today(config('app.timezone')); + setlocale(LC_TIME, 'es'); + + $data = [ + [$proyecto->descripcion], + [strftime('%d de %B de %Y', $f->timestamp)], + [''], + [''] + ]; + $columns = [ + ['name' => 'Fecha', 'style' => 'date'], + 'Glosa', + ['name' => 'Debe', 'style' => 'number'], + ['name' => 'Haber', 'style' => 'number'], + ['name' => 'Saldo', 'style' => 'number'], + 'Comentario' + ]; + $bold_rows = []; + + foreach ($ventas as $venta) { + $data []= ['Departamento ' . $venta->unidad()->descripcion . ' (' . format('ufs', $venta->valor_uf) . ' UF)']; + $data []= $columns; + $bold_rows []= count($data) - 1; + $ufs = 0; + $debe = 0; + $haber = 0; + $sum = 0; + if ($venta->pie != 0) { + $cuotas = $venta->pie()->cuotas(); + foreach ($cuotas as $cuota) { + $sum += $cuota->pago()->valor(); + $ufs += $cuota->pago()->valor('ufs'); + $haber += $cuota->pago()->valor(); + $info = [ + $cuota->pago()->estado()->fecha, + 'Pie - Cuota ' . $cuota->numero() . ' - ' . $venta->pie()->cuotas . ' (' . format('ufs', $cuota->pago()->valor('ufs')) . ' UF)', + '', + $cuota->pago()->valor(), + $sum + ]; + if ($cuota->pago()->estado()->estado < 2) { + $info []= 'No ha sido abonada.'; + } + $data []= $info; + } + if ($venta->pie()->reajuste != 0) { + $sum += $venta->pie()->reajuste()->valor(); + $ufs += $venta->pie()->reajuste()->valor('ufs'); + $haber += $venta->pie()->reajuste()->valor(); + $info = [ + $venta->pie()->reajuste()->estado()->fecha, + 'Reajuste (' . format('ufs', $venta->pie()->reajuste()->valor('ufs')) . ' UF)', + '', + $venta->pie()->reajuste()->valor(), + $sum + ]; + if ($venta->pie()->reajuste()->estado()->estado < 2) { + $info []= 'No ha sido abonado.'; + } + $data []= $info; + } + } + if ($venta->escritura != 0) { + $sum += $venta->escritura()->pago()->valor(); + $ufs += $venta->escritura()->pago()->valor('ufs'); + $haber += $venta->escritura()->pago()->valor(); + $info = [ + $venta->escritura()->pago()->estado()->fecha, + 'Abono Escritura (' . format('ufs', $venta->escritura()->pago()->valor('ufs')) . ' UF)', + '', + $venta->escritura()->pago()->valor(), + $sum + ]; + if ($venta->escritura()->pago()->estado()->estado < 2) { + $info []= 'No ha sido abonado.'; + } + $data []= $info; + } + if ($venta->credito != 0) { + $sum += $venta->credito()->pago()->valor(); + $ufs += $venta->credito()->pago()->valor('ufs'); + $haber += $venta->credito()->pago()->valor(); + $info = [ + $venta->credito()->pago()->estado()->fecha, + 'Crédito (' . format('ufs', $venta->credito()->pago()->valor('ufs')) . ' UF)', + '', + $venta->credito()->pago()->valor(), + $sum + ]; + if ($venta->credito()->pago()->estado()->estado < 2) { + $info []= 'No ha sido pagado.'; + } + $data []= $info; + } + if ($venta->bono_pie != 0) { + try { + $sum -= $venta->bonoPie()->pago()->valor(); + $debe += $venta->bonoPie()->pago()->valor(); + $info = [ + $venta->bonoPie()->pago()->estado()->fecha, + 'Bono Pie (' . format('ufs', $venta->bonoPie()->pago()->valor('ufs')) . ' UF)'. + $venta->bonoPie()->pago()->valor(), + '', + $sum + ]; + $data []= $info; + $sum += $venta->bonoPie()->pago()->valor(); + $haber += $venta->bonoPie()->pago()->valor(); + $info = [ + $venta->bonoPie()->pago()->estado()->fecha, + 'Bono Pie (' . format('ufs', $venta->bonoPie()->pago()->valor('ufs')) . ' UF)'. + '', + $venta->bonoPie()->pago()->valor(), + $sum + ]; + $data []= $info; + } catch (\Exception $e) { + + } + } + $info = [ + '', + 'TOTAL (' . format('ufs', $ufs) . ' UF)', + $debe, + $haber, + $sum + ]; + $data []= $info; + $bold_rows []= count($data) - 1; + + $data []= ['']; + } + /** + * Departamento # + * Fecha |Glosa |Debe |Haber |Saldo + * |Pie - Cuota 1 - n (# UF) |- |$# | + * |Reajuste (# UF) |- |$# | + * |Abono Escritura (# UF) |- |$# | + * |Crédito (# UF) |- |$# | + * |Bono Pie (# UF) |$# |- | + * |Bono Pie (# UF) |- |$# | + * |Devolución (# UF) |$# |- | + * - |TOTAL (# UF) | | | + */ + + array_walk($data, function(&$e, $i) use ($columns) { + if (count($e) < count($columns)) { + $n = count($columns) - count($e); + for ($j = 0; $j < $n; $j ++) { + $e []= ''; + } + } + }); + + #$informe = new Informador('Consolidación - ' . $proyecto->descripcion); + $name = 'Consolidación'; + $hoy = Carbon::now(config('app.timezone')); + $filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls'); + $informe = new PHPExcel($name, $filename); + $informe->addColumns($columns); + $informe->addData($data); + + return $informe->informe(); + } + public static function creditos_pendientes() + { + function creditos() { + $creditos = model(Credito::class) + ->select('credito.*') + ->join('venta', ['venta.credito', '=', 'credito.id']) + ->join('pago', ['pago.id', '=', 'credito.pago']) + ->rawJoin('JOIN (SELECT ep.* FROM (SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago ep ON ep.id = e0.id)', ['estado_pago.pago', '=', 'pago.id'], 'estado_pago') + ->whereLt('estado_pago.estado', 2) + ->where('venta.estado', 1) + ->orderByAsc('estado_pago.fecha') + ->findMany(); + foreach ($creditos as $credito) { + yield $credito; + } + } + $informe = new Informador('Créditos Pendientes'); + + $columnas = ['Proyecto', 'Departamento', 'Valor', 'Fecha Escritura', 'Estado']; + $informe->addColumns($columnas); + + $row = 0; + foreach (creditos() as $credito) { + $informe->addData($row, $credito->venta()->proyecto()->descripcion, 'Proyecto'); + $informe->addData($row, $credito->venta()->unidad()->descripcion, 'Departamento'); + $informe->addData($row, $credito->pago()->valor('ufs'), 'Valor'); + $informe->addData($row, (($credito->venta()->escriturado) ? $credito->venta()->escriturado : $credito->pago()->estado()->fecha), 'Fecha Escritura'); + $informe->addData($row, ucwords($credito->pago()->estado()->tipo()->descripcion), 'Estado'); + + $row ++; + } + + $date = [ + 'numberFormat' => ['short-date'] + ]; + $ufs = [ + 'numberFormat' => ['thousands'] + ]; + $formats = ['Valor' => $ufs, 'Fecha Escritura' => $date]; + $informe->addFormats($formats); + + return $informe->informe(); + } + public static function ventas() + { + if (get('proyecto')) { + ini_set('memory_limit', "1G"); + ini_set('max_execution_time', '3600'); + $id = get('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id); + $ventas = $proyecto->ventas(); + + /*usort($ventas, function($a, $b) { + return $a->fecha()->timestamp - $b->fecha()->timestamp; + });*/ + + $procasa = model(Agente::class)->findOne(1); + $pa = model(ProyectoAgente::class)->where('agente', $procasa->id)->where('proyecto', $proyecto->id)->findOne(); + if ($pa) { + $comision = $pa->comision / 100; + } else { + $comision = 0.03; + } + + #$informe = new Informador('Ventas - ' . $proyecto->descripcion); + $name = 'Informe de Ventas'; + $hoy = Carbon::now(config('app.timezone')); + $filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xlsx'); + //$informe = new PHPExcel($name, $filename); + + $columnas = [ + 'Propietario', + 'Departamento', + ['name' => 'Estacionamientos', 'style' => 'number'], + ['name' => 'Bodegas', 'style' => 'number'], + 'Fecha Venta', + ['name' => 'Mes', 'style' => 'mes'], + 'Tipo', + ['name' => 'm² Ponderados', 'style' => 'amount'], + ['name' => 'Valor Promesa', 'style' => 'amount'], + ['name' => 'Pie', 'style' => 'amount'], + ['name' => 'Pie Pagado', 'style' => 'amount'], + ['name' => '% Pie Pagado', 'style' => 'percent'], + ['name' => 'Bono Pie', 'style' => 'amount'], + 'Operador', + ['name' => 'Valor Operador', 'style' => 'amount'], + ['name' => 'Premios', 'style' => 'amount'], + ['name' => 'Subsidio', 'style' => 'amount'], + ['name' => 'Ahorro', 'style' => 'amount'], + ['name' => 'Credito', 'style' => 'amount'], + 'Banco', + ['name' => 'Valor Ests & Bods', 'style' => 'amount'], + ['name' => 'Valor Neto', 'style' => 'amount'], + ['name' => 'UF/m²*', 'style' => 'amount'], + ['name' => 'Comision', 'style' => 'amount'], + ['name' => 'Venta s/Comision', 'style' => 'amount'], + ['name' => 'Precio', 'style' => 'Amount'] + ]; + //$informe->addColumns($columnas); + + $data = []; + foreach ($ventas as $venta) { + $info = []; + $info['Propietario'] = mb_strtoupper($venta->propietario()->nombreCompleto()); + $info['Departamento'] = implode(' - ', array_map(function($item) { + return $item->descripcion; + }, $venta->propiedad()->departamentos())); + $es = $venta->propiedad()->estacionamientos(); + $info['Estacionamientos'] = implode(', ', array_map(function($item) { + return $item->descripcion; + }, $es)); + $bs = $venta->propiedad()->bodegas(); + $info['Bodegas'] = implode(', ', array_map(function($item) { + return $item->descripcion; + }, $bs)); + $info['Fecha Venta'] = $venta->fecha()->format('Y-m-d'); + $info['Mes'] = $venta->fecha()->format('M-y'); + $info['Tipo'] = $venta->unidad()->abreviacion; + $info['m² Ponderados'] = $venta->unidad()->m2('vendible'); + $info['Valor Promesa'] = $venta->valor_uf; + $info['Pie'] = 0; + if ($venta->pie()) { + $info['Pie'] = $venta->pie()->valor; + } + $info['Pie Pagado'] = 0; + $info['% Pie Pagado'] = 0; + if ($venta->pie()) { + $info['Pie Pagado'] = $venta->pie()->valorPagado('uf'); + $info['% Pie Pagado'] = $venta->pie()->valorPagado('uf') / $venta->valor_uf; + } + + $info['Bono Pie'] = ($venta->bono_pie == 0 or $venta->bonoPie() === false) ? '' : $venta->bonoPie()->pago()->valor('ufs'); + $info['Operador'] = ($venta->agente and $venta->agente()->agente()->tipo == 19) ? $venta->agente()->agente()->descripcion : ''; + $info['Valor Operador'] = $venta->valorComision(); + //$promos = 0; + $ps = $venta->promociones(); + $info['Premios'] = array_reduce($ps, function($sum, $item) { + return $sum + $item->valor; + }); + $info['Subsidio'] = 0; + $info['Ahorro'] = 0; + if ($venta->subsidio != 0) { + $info['Subsidio'] = $venta->subsidio()->subsidio()->valor('ufs'); + $info['Ahorro'] = $venta->subsidio()->pago()->valor('ufs'); + } + $info['Credito'] = 0; + $info['Banco'] = ''; + if ($venta->credito != 0 and $venta->credito()->pago()) { + $info['Credito'] = $venta->credito()?->pago()->valor('ufs'); + if ($venta->credito()?->pago()->banco != 0) { + $info['Banco'] = $venta->credito()?->pago()->banco()->nombre; + } + } + $info['Valor Ests & Bods'] = $venta->valorEstacionamientosYBodegas(); + $info['Valor Neto'] = $venta->valorFinal(); + $info['UF/m²*'] = $venta->uf_m2(); + $info['Comision'] = $venta->valorFinal() * $comision; + $info['Venta s/Comision'] = $venta->valorFinal() - $info['Comision']; + $fecha = $venta->fecha(); + $info['Precio'] = 0; + try { + $info['Precio'] = array_reduce($venta->propiedad()->departamentos(), function($sum, $item) use ($fecha) { + if (!$item->precio($fecha)) { + return $sum; + } + return $sum + $item->precio($fecha)->valor; + }); + } catch (\Exception $e) { + } + + $data []= $info; + } + + $body = [ + "Proyecto" => $proyecto->descripcion, + "Compañía" => $proyecto->inmobiliaria()->abreviacion, + "data" => $data + ]; + $client = new Client(['base_uri' => "{$_ENV['PYTHON_HOST']}"]); + $response = $client->post('/ventas', ['json' => $body]); + + header("Content-Type: application/octet-stream; charset=utf-8"); + header('Content-Transfer-Encoding: binary'); + header('Content-Disposition: attachment; filename="' . $filename . '"'); + header('Cache-Control: max-age=0'); + return $response->getBody(); + //file_put_contents('php://output', $output); + + } else { + $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many(); + return view('informes.ventas', compact('proyectos')); + } + } + public static function resumen_contabilidad() + { + if (get('proyecto')) { + $id = get('proyecto'); + $fecha = get('fecha'); + + $service = new Resumen(); + $service->build($id, new \DateTimeImmutable($fecha)); + return ''; + } else { + $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many(); + return view('informes.resumen_contabilidad', compact('proyectos')); + } + } + public static function contabilidad() + { + if (get('proyecto')) { + $id = get('proyecto'); + $fecha = get('fecha'); + $mes = null; + if ($fecha != null) { + $mes = Carbon::parse($fecha); + } + $proyecto = model(Proyecto::class)->findOne($id); + $q = "SELECT pago.*, venta.id AS vid, venta.tipo AS ctipo, venta.pie AS pie + FROM ( + SELECT pago.id, banco.nombre AS banco, pago.fecha, pago.valor, pago.uf, ep.estado, ep.fecha AS efecha + FROM pago JOIN banco ON banco.id = pago.banco JOIN (( + SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago ep ON ep.id = e0.id) ON ep.pago = pago.id + WHERE ep.estado > 0 "; + if ($mes != null) { + $q .= "AND (pago.fecha BETWEEN '" . $mes->format('Y-m-01') . "' AND '" . $mes->format('Y-m-t') . "' + OR ep.fecha BETWEEN '" . $mes->format('Y-m-01') . "' AND '" . $mes->format('Y-m-t') . "')"; + } + $q .= ") pago JOIN (SELECT venta.* + FROM (( + SELECT venta.id, venta.pie, venta.propiedad, credito.pago, 'credito' AS tipo + FROM venta JOIN credito ON credito.id = venta.credito) + UNION ALL ( + SELECT venta.id, venta.pie, venta.propiedad, escritura.pago, 'escritura' AS tipo + FROM venta JOIN escritura ON escritura.id = venta.escritura) + UNION ALL ( + SELECT venta.id, venta.pie, venta.propiedad, cuota.pago, 'cuota' AS tipo + FROM venta JOIN cuota ON cuota.pie = venta.pie)) venta + JOIN propiedad ON propiedad.id = venta.propiedad + JOIN unidad ON unidad.id = propiedad.unidad_principal + WHERE unidad.proyecto = ?) venta + ON venta.pago = pago.id"; + $st = \ORM::getDB()->prepare($q); + $st->execute([$id]); + if ($st->rowCount() > 0) { + $R = $st->fetchAll(\PDO::FETCH_OBJ); + + //$informe = new Informador('Contabilidad - ' . (($mes != null) ? $mes->format('Y-m') . ' - ' : '') . $proyecto->descripcion); + $name = 'Contabilidad'; + $hoy = Carbon::now(config('app.timezone')); + $filename = str_replace('ñ', 'n', 'Contabilidad - ' . (($mes != null) ? $mes->format('Y-m') . ' - ' : '') . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls'); + + $informe = new PHPExcel($name, $filename); + + $columnas = ['Proyecto', 'Fecha', 'Banco', 'Departamento', 'RUT', 'Propietario', 'Glosa', 'Glosa2', (object) ['name' => 'Valor', 'style' => 'integer'], (object) ['name' => 'Valor UF', 'style' => 'currency']]; + $informe->addColumns($columnas); + $data = []; + foreach ($R as $r) { + $info = []; + $info['Proyecto'] = $proyecto->descripcion; + $f1 = \Carbon\Carbon::parse($r->fecha, config('app.timezone')); + $f2 = \Carbon\Carbon::parse($r->efecha, config('app.timezone')); + $info['Fecha'] = ($f1->max($f2))->format('Y-m-d'); + $info['Banco'] = $r->banco; + $venta = model(Venta::class)->findOne($r->vid); + $info['Departamento'] = $venta->unidad()->descripcion; + $info['RUT'] = $venta->propietario()->rut(); + $info['Propietario'] = $venta->propietario()->nombreCompleto(); + $info['Glosa'] = ucwords($r->ctipo); + $info['Glosa2'] = ''; + if ($r->ctipo == 'cuota') { + $cuota = model(Cuota::class)->where('pago', $r->id)->findOne(); + + $info['Glosa'] = 'Pie - ' . format('ufs', $cuota->pie()->valor('ufs'), null, true); + + $info['Glosa2'] = $cuota->numero() . ' - ' . $cuota->pie()->cuotas; + } + $info['Valor'] = $r->valor; + $info['Valor UF'] = '0'; + if ($r->uf > 0) { + $info['Valor UF'] = $r->valor / $r->uf; + } + $data []= $info; + } + + $informe->addData($data); + + return $informe->informe(); + } + } else { + setlocale(LC_TIME, 'es_ES'); + $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many(); + return view('informes.contabilidad', compact('proyectos')); + } + } + public static function para_comision() + { + $proyectos = model(Proyecto::class)->orderByAsc('descripcion')->findMany(); + return view('informes.para_comision', compact('proyectos')); + } + public static function comisiones() + { + $id = post('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id); + $unidades = explode('-', str_replace([';', '.', ':', ' ', PHP_EOL, '|', '+', ','], '-', post('unidades'))); + $ventas = model(Venta::class) + ->select('venta.*') + ->join('propiedad', ['propiedad.id', '=', 'venta.propiedad']) + ->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal']) + ->where('unidad.proyecto', $proyecto->id) + ->where('venta.estado', 1) + ->whereIn('unidad.descripcion', $unidades) + ->orderByExpr('FIELD(unidad.descripcion, ' . implode(', ', $unidades) . ')') + ->findMany(); + $ids = []; + $totales = (object) ['precio' => 0, 'neto' => 0, 'comision' => 0]; + foreach ($ventas as $venta) { + $ids []= $venta->id; + $totales->precio += $venta->valor_uf; + $totales->neto += $venta->valorCorredora(); + $totales->comision += $venta->valorCorredora() * 1.5 / 100; + } + return view('informes.comisiones', compact('ventas', 'proyecto', 'totales', 'ids')); + } + public static function comisiones_xlsx() + { + $id_ventas = explode(',', get('ventas')); + $ventas = model(Venta::class) + ->whereIn('id', $id_ventas) + ->orderByExpr('FIELD(id, ' . implode(', ', $id_ventas) . ')') + ->findMany(); + + $informe = new Informador('Comisiones - ' . $ventas[0]->proyecto()->descripcion); + $columnas = ['Departamento', 'Estacionamientos', 'Bodegas', 'Propietario', 'Precio', '% Com', 'Com UF']; + $informe->addColumns($columnas); + $data = []; + foreach ($ventas as $venta) { + $info = []; + $info['Departamento'] = $venta->unidad()->descripcion; + $info['Estacionamientos'] = implode(' - ', $venta->propiedad()->estacionamientos('array')); + $info['Bodegas'] = implode(' - ', $venta->propiedad()->bodegas('array')); + $info['Propietario'] = $venta->propietario()->nombreCompleto(); + $info['Precio'] = "'" . format('ufs', $venta->valorCorredora()); + $info['% Com'] = '1,5 %'; + $info['Com UF'] = "'" . format('ufs', $venta->valorCorredora() * 1.5 / 100); + $data []= $info; + } + + $informe->addDatas($data); + + return $informe->informe(); + } + public static function cuotas() + { + $id_venta = get('venta'); + $venta = model(Venta::class)->findOne($id_venta); + + $name = 'Cuotas - ' . $venta->unidad()->descripcion; + $hoy = Carbon::now(config('app.timezone')); + $filename = str_replace('ñ', 'n', $name . ' - ' . $venta->proyecto()->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls'); + $informe = new PHPExcel($name, $filename); + $columnas = [ + ['name' => 'Cuota', 'style' => 'number'], + ['name' => 'Fecha Cuota', 'style' => 'date'], + 'Banco', + 'Identificador', + ['name' => 'Valor $', 'style' => 'number'], + ['name' => 'Valor UF', 'style' => 'currency'], + ['name' => 'Fecha Pago', 'style' => 'date'] + ]; + $informe->addColumns($columnas); + $data = []; + foreach ($venta->pie()->cuotas() as $cuota) { + $info = []; + $info['Cuota'] = $cuota->numero(); + $info['Fecha Cuota'] = $cuota->pago()->fecha()->format('Y-m-d'); + $info['Banco'] = $cuota->pago()->banco()->descripcion; + $info['Identificador'] = $cuota->pago()->identificador; + $info['Valor $'] = $cuota->pago()->valor(); + $info['Valor UF'] = $cuota->pago()->valor('ufs'); + $info['Fecha Pago'] = $cuota->pago()->estado()->fecha()->format('Y-m-d'); + $data []= $info; + } + $informe->addData($data); + + return $informe->informe(); + } + public static function resciliaciones() + { + if (get('proyecto')) { + $id = get('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id); + $ventas = $proyecto->resciliaciones(); + + usort($ventas, function($a, $b) { + return $a->fecha()->timestamp - $b->fecha()->timestamp; + }); + + $name = 'Resciliaciones'; + $hoy = Carbon::now(config('app.timezone')); + $filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls'); + $informe = new PHPExcel($name, $filename); + + $columnas = [ + 'Propietario', + ['name' => 'Departamento', 'style' => 'number'], + ['name' => 'Estacionamientos', 'style' => 'number'], + ['name' => 'Bodegas', 'style' => 'number'], + 'Fecha Venta', + 'Fecha Resciliación', + ['name' => 'Mes', 'style' => 'mes'], + 'Tipo', + ['name' => 'm² Ponderados', 'style' => 'amount'], + ['name' => 'Valor Promesa', 'style' => 'amount'], + ]; + $informe->addColumns($columnas); + + $data = []; + foreach ($ventas as $venta) { + $info = []; + $info['Propietario'] = mb_strtoupper($venta->propietario()->nombreCompleto()); + $info['Departamento'] = $venta->unidad()->descripcion; + $ests = []; + if ($venta->propiedad()->estacionamientos != '') { + $es = $venta->propiedad()->estacionamientos(); + foreach ($es as $e) { + $ests []= $e->descripcion; + } + } + $info['Estacionamientos'] = implode(', ', $ests); + $bods = []; + if ($venta->propiedad()->bodegas != '') { + $bs = $venta->propiedad()->bodegas(); + foreach ($bs as $b) { + $bods []= $b->descripcion; + } + } + $info['Bodegas'] = implode(', ', $bods); + $info['Fecha Venta'] = $venta->fecha()->format('d.m.Y'); + $info['Fecha Resciliación'] = $venta->estado()->fecha()->format('d.m.Y'); + $info['Mes'] = $venta->estado()->fecha()->format('M-y'); + $info['Tipo'] = $venta->unidad()->abreviacion; + $info['m² Ponderados'] = $venta->unidad()->m2('vendible'); + $info['Valor Promesa'] = $venta->valor_uf; + + $data []= $info; + } + $informe->addData($data); + + $totals = [ + 'Departamento' => 'count', + 'Estacionamientos' => 'count', + 'Bodegas' => 'count', + 'm² Ponderados' => 'sum', + 'Valor Promesa' => 'sum' + ]; + $informe->addTotals($totals); + + return $informe->informe(); + } else { + $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many(); + return view('informes.resciliaciones', compact('proyectos')); + } + } +} diff --git a/resources/less/Controller/Inmobiliarias.php b/app_old/app/Controller/Inmobiliarias.php similarity index 100% rename from resources/less/Controller/Inmobiliarias.php rename to app_old/app/Controller/Inmobiliarias.php diff --git a/resources/less/Controller/Operadores.php b/app_old/app/Controller/Operadores.php similarity index 100% rename from resources/less/Controller/Operadores.php rename to app_old/app/Controller/Operadores.php diff --git a/resources/less/Controller/Other.php b/app_old/app/Controller/Other.php similarity index 100% rename from resources/less/Controller/Other.php rename to app_old/app/Controller/Other.php diff --git a/resources/less/Controller/Pagares.php b/app_old/app/Controller/Pagares.php similarity index 100% rename from resources/less/Controller/Pagares.php rename to app_old/app/Controller/Pagares.php diff --git a/resources/less/Controller/Pagos.php b/app_old/app/Controller/Pagos.php similarity index 100% rename from resources/less/Controller/Pagos.php rename to app_old/app/Controller/Pagos.php diff --git a/resources/less/Controller/Pies.php b/app_old/app/Controller/Pies.php similarity index 100% rename from resources/less/Controller/Pies.php rename to app_old/app/Controller/Pies.php diff --git a/resources/less/Controller/Postventas.php b/app_old/app/Controller/Postventas.php similarity index 100% rename from resources/less/Controller/Postventas.php rename to app_old/app/Controller/Postventas.php diff --git a/app_old/app/Controller/Precios.php b/app_old/app/Controller/Precios.php new file mode 100644 index 0000000..20db97b --- /dev/null +++ b/app_old/app/Controller/Precios.php @@ -0,0 +1,177 @@ +orderByAsc('descripcion')->findMany(); + return view('ventas.precios.proyectos', compact('proyectos')); + } + public static function list() + { + $proyecto = \model(Proyecto::class)->findOne(get('proyecto')); + return view('ventas.precios.list', compact('proyecto')); + } + public static function import() + { + $proyectos = \model(Proyecto::class)->orderByAsc('descripcion')->findMany(); + return view('ventas.precios.import', compact('proyectos')); + } + public static function importar() + { + $proyecto = \model(Proyecto::class)->findOne(post('proyecto')); + $fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $file = explode(PHP_EOL, trim(file_get_contents($_FILES['archivo']['tmp_name']))); + $columnas = explode(';', array_shift($file)); + $tr = model(TipoEstadoPrecio::class)->where('descripcion', 'reemplazado')->findOne()->id; + $tv = model(TipoEstadoPrecio::class)->where('descripcion', 'vigente')->findOne()->id; + foreach ($file as $line) { + if (trim($line) == '') { + continue; + } + $info = explode(';', $line); + $tipo = \model(TipoUnidad::class)->where('descripcion', $info[0])->findOne(); + $unidad = \model(Unidad::class)->where('tipo', $tipo->id)->where('descripcion', $info[1])->where('proyecto', $proyecto->id)->findOne(); + if (!$unidad) { + continue; + } + + try { + self::reemplazar($unidad->id, $info[2], $fecha, $tr, $tv); + } catch (\Exception $e) { + continue; + } + } + header('Location: ' . nUrl('precios', 'list', ['proyecto' => $proyecto->id])); + } + public static function add() + { + $proyecto = \model(Proyecto::class)->findOne(get('proyecto')); + return view('ventas.precios.add', compact('proyecto')); + } + public static function agregar() + { + $proyecto = get('proyecto'); + $fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $precios = []; + foreach (post() as $name => $valor) { + if ($valor == '' or strpos($name, 'precio') === false) { + continue; + } + list($tipo, $id) = explode(':', $name); + $tipo = trim(str_replace('precio', '', $tipo), '_'); + $id = explode('-', $id); + switch (count($id)) { + case 1: + $precios []= ['tipo' => 'pt', 'id' => $id[0], 'valor' => $valor]; + break; + case 2: + $exists = false; + foreach ($precios as $precio) { + if ($precio['tipo'] == 'pt' and $precio['id'] == $id[0]) { + $exists = true; + break; + } + } + if (!$exists) { + $precios []= ['tipo' => 'subtipo', 'id' => $id[1], 'pt' => $id[0], 'valor' => $valor]; + } + break; + case 3: + $exists = false; + foreach ($precios as $precio) { + if ($precio['tipo'] == 'pt' and $precio['id'] == $id[0]) { + $exists = true; + break; + } + if ($precio['tipo'] == 'subtipo' and 'id' == $id[1] and 'pt' == $id[0]) { + $exists = true; + break; + } + } + if (!$exists) { + $precios []= ['tipo' => 'unidad', 'id' => $id[2], 'valor' => $valor]; + } + break; + } + } + foreach ($precios as $precio) { + $precio = (object) $precio; + try { + switch ($precio->tipo) { + case 'pt': + $pt = model(ProyectoTipoUnidad::class)->findOne($precio->id); + $pt->setPrecios($fecha, $precio->valor); + break; + case 'subtipo': + $pt = model(ProyectoTipoUnidad::class)->findOne($precio->pt); + $pt->setPreciosSubtipo($precios->id, $fecha, $precio->valor); + break; + case 'unidad': + $unidad = model(Unidad::class)->findOne($precio->id); + $unidad->setPrecio($fecha, $precio->valor); + break; + } + } catch(\Exception $e) { + continue; + } + } + header('Location: ' . nUrl('precios', 'list', ['proyecto' => $proyecto])); + } + protected static function reemplazar(int $unidad_id, float $valor, \DateTime $fecha, int $tr = 0, int $tv = 0) + { + if ($tr == 0) { + $tr = model(TipoEstadoPrecio::class)->where('descripcion', 'reemplazado')->findOne()->id; + } + if ($tv == 0) { + $tv = model(TipoEstadoPrecio::class)->where('descripcion', 'vigente')->findOne()->id; + } + $olds = \model(Precio::class)->where('unidad', $unidad_id)->findMany(); + if ($olds !== false) { + foreach ($olds as $old) { + if (!$old->vigente()) { + continue; + } + $data = [ + 'precio' => $old->id, + 'fecha' => $fecha->format('Y-m-d'), + 'estado' => $tr + ]; + $estado = \model(EstadoPrecio::class)->create($data); + $estado->save(); + } + } + $data = [ + 'unidad' => $unidad_id, + 'valor' => $valor + ]; + $precio = (new Factory(Precio::class))->where($data)->find(); + if (!$precio) { + $precio = \model(Precio::class)->create($data); + $precio->save(); + } + $data = [ + 'precio' => $precio->id, + 'fecha' => $fecha->format('Y-m-d'), + 'estado' => $tv + ]; + $estado = \model(EstadoPrecio::class)->create($data); + $estado->save(); + } +} diff --git a/resources/less/Controller/Propietarios.php b/app_old/app/Controller/Propietarios.php similarity index 100% rename from resources/less/Controller/Propietarios.php rename to app_old/app/Controller/Propietarios.php diff --git a/resources/less/Controller/ProyectoTipoUnidades.php b/app_old/app/Controller/ProyectoTipoUnidades.php similarity index 100% rename from resources/less/Controller/ProyectoTipoUnidades.php rename to app_old/app/Controller/ProyectoTipoUnidades.php diff --git a/app_old/app/Controller/Proyectos.php b/app_old/app/Controller/Proyectos.php new file mode 100644 index 0000000..9c69ad5 --- /dev/null +++ b/app_old/app/Controller/Proyectos.php @@ -0,0 +1,327 @@ +where('inmobiliaria', $id_inmobiliaria); + } else { + $proyectos = model(Proyecto::class); + } + $proyectos = $proyectos->order_by_asc('descripcion')->findMany(); + return view('proyectos.list', compact('proyectos')); + } + public static function show() + { + $id_proyecto = get('proyecto'); + if ($id_proyecto == null) { + header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'list'])); + } + $proyecto = model(Proyecto::class)->findOne($id_proyecto); + $estados = model(TipoEstadoProyecto::class)->findMany(); + foreach ($estados as &$estado) { + $estado = $estado->asArray()['orden'] + 1; + } + $colors = []; + + $ventas_pt = (object) ['fields' => [], 'data' => [], 'totales' => [], 'vendidas' => []]; + $ventas = $proyecto->ventas('fecha'); + $months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; + if (count($ventas) > 0) { + $inicio = $ventas[0]->fecha()->format('Y'); + $fin = $ventas[count($ventas) - 1]->fecha()->format('Y'); + $end = $ventas[count($ventas) - 1]->fecha()->format('M'); + for ($y = $inicio; $y <= $fin; $y ++) { + foreach ($months as $month) { + $ventas_pt->fields []= $y . ' ' . $month; + if ($y == $fin and $month == $end) { + break; + } + } + } + } + + foreach ($proyecto->tipologias() as $tipo) { + if (!isset($ventas_pt->data[$tipo->tipologia->descripcion])) { + $ventas_pt->data[$tipo->tipologia->descripcion] = []; + $ventas_pt->data[$tipo->tipologia->descripcion] = array_fill(0, count($ventas_pt->fields), 0); + $ventas_pt->totales[$tipo->tipologia->descripcion] = 0; + $ventas_pt->vendidas[$tipo->tipologia->descripcion] = 0; + } + foreach ($tipo->tipos as $pt) { + foreach ($pt->ventas('fecha') as $venta) { + $ventas_pt->data[$tipo->tipologia->descripcion][array_search($venta->fecha()->format('Y M'), $ventas_pt->fields)] ++; + $ventas_pt->vendidas[$tipo->tipologia->descripcion] ++; + } + $ventas_pt->totales[$tipo->tipologia->descripcion] += count($pt->unidades()); + } + } + foreach ($ventas_pt->data as $tipo => $data) { + $acum = 0; + foreach ($data as $i => $cantidad) { + $acum += $cantidad; + $ventas_pt->data[$tipo][$i] = round($acum / $ventas_pt->totales[$tipo] * 100, 2); + } + } + $meses = ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic']; + array_walk($ventas_pt->fields, function(&$item) use ($meses, $months) { + $item = str_replace($months, $meses, $item); + }); + + for ($i = 0; $i < 10; $i ++) { + $colors[$i] = 'rgb(' . mt_rand(0, 255) . ', ' . mt_rand(0, 255) . ', ' . mt_rand(0, 255) . ')'; + } + return view('proyectos.show', compact('proyecto', 'estados', 'colors', 'ventas_pt')); + } + public static function historial() + { + $proyecto = model(Proyecto::class)->findOne(get('proyecto')); + return view('proyectos.historia', compact('proyecto')); + } + public static function advance() + { + $id_proyecto = get('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id_proyecto); + $estados = model(TipoEstadoProyecto::class)->whereGt('orden', $proyecto->estado()->tipo()->orden)->orderByAsc('orden')->findMany(); + + return view('proyectos.advance', compact('proyecto', 'estados')); + } + public static function avanzar() + { + $id_proyecto = get('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id_proyecto); + $id_tipo = post('estado'); + $tipo = model(TipoEstadoProyecto::class)->findOne($id_tipo); + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + + $tipos = model(TipoEstadoProyecto::class) + ->whereGt('orden', $proyecto->estado()->tipo()->orden) + ->whereLte('orden', $tipo->orden) + ->orderByAsc('orden') + ->findMany(); + + foreach ($tipos as $t) { + $estado = model(EstadoProyecto::class)->create(); + $estado->proyecto = $proyecto->id; + $estado->estado = $t->id; + $estado->fecha = $f->format('Y-m-d'); + $estado->save(); + } + header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'show', 'proyecto' => $proyecto->id])); + } + public static function avance() + { + $id = get('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id); + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $av = post('avance') / 100; + $ep = (double) post('estado_pago'); + $avance = model(AvanceConstruccion::class) + ->where('proyecto', $proyecto->id) + ->where('fecha', $f->format('Y-m-d')) + ->findOne(); + if (!$avance) { + $data = [ + 'proyecto' => $proyecto->id, + 'fecha' => $f->format('Y-m-d'), + 'numero' => post('numero'), + 'avance' => $av, + 'estado_pago' => $ep + ]; + $avance = model(AvanceConstruccion::class)->create($data); + } + $avance->save(); + header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'historial', 'proyecto' => $proyecto->id])); + } + public static function add() + { + $rut = get('inmobiliaria'); + + $inmobiliarias = model(Inmobiliaria::class)->orderByAsc('abreviacion')->findMany(); + $regiones = model(Region::class)->orderByAsc('numeracion')->findMany(); + + return view('proyectos.add', compact('inmobiliarias', 'rut', 'regiones')); + } + public static function agregar() + { + $proyecto = model(Proyecto::class)->where('descripcion', post('descripcion'))->where('inmobiliaria', post('inmobiliaria'))->find_one(); + if ($proyecto) { + header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'show', 'proyecto' => $proyecto->id])); + die(); + } + $proyecto = model(Proyecto::class)->create(); + $proyecto->descripcion = post('descripcion'); + $proyecto->inmobiliaria = post('inmobiliaria'); + + $direccion = model(Direccion::class) + ->where('calle', post('calle')) + ->where('numero', post('numero')) + ->where('extra', post('extra')) + ->where('comuna', post('comuna')) + ->findOne(); + if (!$direccion) { + $direccion = model(Direccion::class)->create(); + $direccion->calle = post('calle'); + $direccion->numero = post('numero'); + $direccion->extra = post('extra'); + $direccion->comuna = post('comuna'); + $direccion->save(); + } + + $proyecto->direccion = $direccion->id; + $proyecto->save(); + + $fecha = Carbon::parse(post('year'), post('month'), post('day'), config('app.timezone')); + $estado = model(EstadoProyecto::class)->create(); + $estado->proyecto = $proyecto->id; + $estado->estado = 1; + $estado->fecha = $fecha->format('Y-m-d'); + $estado->save(); + header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'show', 'proyecto' => $proyecto->id])); + } + public static function disponibles() + { + $id = get('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id); + + return view('proyectos.disponibles', compact('proyecto')); + } + public static function list_unidades() + { + $id = get('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id); + $libres = model(Unidad::class)->where('proyecto', $proyecto->id)->where('pt', 0)->findMany(); + + return view('proyectos.unidades.list', compact('proyecto', 'libres')); + } + public static function add_tipo_unidad() + { + $id = get('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id); + $tipos = model(TipoUnidad::class)->findMany(); + + return view('proyectos.tipo_unidades.add', compact('proyecto', 'tipos')); + } + public static function agregar_tipo_unidad() + { + $id = get('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id); + $data = post(); + $data['proyecto'] = $proyecto->id; + $tipo = model(ProyectoTipoUnidad::class)->where('proyecto', $data['proyecto']) + ->where('tipo', $data['tipo'])->where('nombre', $data['nombre'])->findOne(); + if ($tipo === false) { + $tipo = model(ProyectoTipoUnidad::class)->create($data); + $tipo->save(); + } + header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $proyecto->id])); + } + public static function construccion() + { + $id = get('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id); + return view('proyectos.construccion', compact('proyecto')); + } + public static function editar_avance() + { + $avance = model(AvanceConstruccion::class)->findOne(get('avance')); + return view('proyectos.avances.edit', compact('avance')); + } + public static function edit_avance() + { + $avance = model(AvanceConstruccion::class)->findOne(get('avance')); + $cols = [ + 'day', + 'month', + 'year', + 'avance', + 'estado_pago', + 'pagado', + 'day_pago', + 'month_pago', + 'year_pago' + ]; + $data = array_filter(post(), function($key) use ($cols) { + return (array_search($key, $cols) !== false); + }, \ARRAY_FILTER_USE_KEY); + $data['fecha'] = implode('-', [$data['year'], $data['month'], $data['day']]); + unset($data['year']); + unset($data['month']); + unset($data['day']); + $data['fecha_pagado'] = implode('-', [$data['year_pago'], $data['month_pago'], $data['day_pago']]); + unset($data['year_pago']); + unset($data['month_pago']); + unset($data['day_pago']); + $data['avance'] /= 100; + $avance->edit($data); + + header('Location: ' . nUrl('proyectos', 'construccion', ['proyecto' => $avance->proyecto])); + } + public static function reservas() + { + $proyecto = model(Proyecto::class)->findOne(get('proyecto')); + $pisos = []; + $totales = []; + foreach ($proyecto->unidades('departamento') as $unidad) { + if (!isset($pisos[$unidad->piso - 1])) { + $piso = (object) ['descripcion' => $unidad->piso, 'unidades' => []]; + $pisos[$unidad->piso - 1] = $piso; + } + if (!isset($totales[$unidad->linea()])) { + $totales[$unidad->linea()] = (object) ['ventas' => 0, 'reservas' => 0]; + } + $pisos[$unidad->piso - 1]->unidades[$unidad->linea()] = $unidad; + if ($unidad->isVendida()) { + $totales[$unidad->linea()]->ventas ++; + } + if ($unidad->isReservada()) { + $totales[$unidad->linea()]->reservas ++; + } + } + ksort($pisos); + $max_unidades = 0; + foreach ($pisos as $piso) { + if (count($piso->unidades) > $max_unidades) { + $max_unidades = count($piso->unidades); + } + } + return view('proyectos.reservas.base', compact('proyecto', 'pisos', 'max_unidades', 'totales')); + } + public static function unidades() + { + if (get('proyecto')) { + $proyecto = model(Proyecto::class)->findOne(get('proyecto')); + $libres = model(Unidad::class)->where('proyecto', $proyecto->id)->where('pt', 0)->findMany(); + + return view('proyectos.unidades.list', compact('proyecto', 'libres')); + } + $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->findMany(); + return view('proyectos.unidades.proyectos', compact('proyectos')); + } +} +?> diff --git a/resources/less/Controller/Reajustes.php b/app_old/app/Controller/Reajustes.php similarity index 100% rename from resources/less/Controller/Reajustes.php rename to app_old/app/Controller/Reajustes.php diff --git a/resources/less/Controller/Registros.php b/app_old/app/Controller/Registros.php similarity index 100% rename from resources/less/Controller/Registros.php rename to app_old/app/Controller/Registros.php diff --git a/resources/less/Controller/Subsidios.php b/app_old/app/Controller/Subsidios.php similarity index 100% rename from resources/less/Controller/Subsidios.php rename to app_old/app/Controller/Subsidios.php diff --git a/resources/less/Controller/Temas.php b/app_old/app/Controller/Temas.php similarity index 100% rename from resources/less/Controller/Temas.php rename to app_old/app/Controller/Temas.php diff --git a/resources/less/Controller/Unidades.php b/app_old/app/Controller/Unidades.php similarity index 100% rename from resources/less/Controller/Unidades.php rename to app_old/app/Controller/Unidades.php diff --git a/resources/less/Controller/UnidadesBloqueadas.php b/app_old/app/Controller/UnidadesBloqueadas.php similarity index 100% rename from resources/less/Controller/UnidadesBloqueadas.php rename to app_old/app/Controller/UnidadesBloqueadas.php diff --git a/app_old/app/Controller/Ventas.php b/app_old/app/Controller/Ventas.php new file mode 100644 index 0000000..31f1e61 --- /dev/null +++ b/app_old/app/Controller/Ventas.php @@ -0,0 +1,605 @@ +findOne($proyecto); + $ventas = $proyecto->ventas(); + self::sort($ventas); + return view('ventas.list', compact('proyecto', 'ventas')); + } + protected static function sort(&$ventas) + { + $sort = get('sort'); + if ($sort == null) { + $sort = 'departamento'; + } + $direction = get('sort_dir'); + if ($direction == null) { + $direction = 1; + } + switch ($sort) { + case 'departamento': + usort($ventas, function($a, $b) use ($direction) { + return ($a->propiedad()->unidad()->descripcion - $b->propiedad()->unidad()->descripcion) * $direction; + }); + break; + case 'propietario': + usort($ventas, function($a, $b) use ($direction) { + $pa = trim($a->propietario()->nombreCompleto(true), ', '); + $pb = trim($b->propietario()->nombreCompleto(true), ', '); + return $direction * strcasecmp($pa, $pb); + }); + break; + case 'valor_uf': + usort($ventas, function($a, $b) use ($direction) { + return $direction * ($a->valor_uf - $b->valor_uf); + }); + break; + case 'uf_m2': + usort($ventas, function($a, $b) use ($direction) { + return $direction * ($a->uf_m2() - $b->uf_m2()); + }); + break; + case 'fecha_venta': + usort($ventas, function($a, $b) use ($direction) { + return ($a->fecha()->timestamp - $b->fecha()->timestamp) * $direction; + }); + break; + } + if ($direction == 'desc') { + $ventas = array_reverse($ventas); + } + } + public static function listProyectos() + { + $proyectos = model(Proyecto::class) + ->select('proyecto.*') + ->join('estado_proyecto', ['estado.proyecto', '=', 'proyecto.id'], 'estado') + ->join('tipo_estado_proyecto', ['tipo.id', '=', 'estado.estado'], 'tipo') + ->join('etapa_proyecto', ['etapa.id', '=', 'tipo.etapa'], 'etapa') + ->whereGte('etapa.orden', 4) + ->orderByAsc('proyecto.descripcion') + ->groupBy('proyecto.id') + ->findMany(); + echo view('ventas.proyectos', compact('proyectos')); + } + public static function show() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + return view('ventas.show', compact('venta')); + } + public static function new() + { + $proyectos = model(Proyecto::class) + ->select('proyecto.*') + ->join('estado_proyecto', ['estado.proyecto', '=', 'proyecto.id'], 'estado') + ->join('tipo_estado_proyecto', ['tipo.id', '=', 'estado.estado'], 'tipo') + ->join('etapa_proyecto', ['etapa.id', '=', 'tipo.etapa'], 'etapa') + ->whereGte('etapa.orden', 3) + ->orderByAsc('proyecto.descripcion') + ->groupBy('proyecto.id') + ->findMany(); + $regiones = model(Region::class)->order_by_asc('numeracion')->findMany(); + return view('ventas.add', compact('proyectos', 'regiones')); + } + public static function agregar() + { + error_log(var_export(post(), true)); + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $t = Carbon::today(config('app.timezone')); + $uf = uf($f); + error_log(var_export($uf, true)); + + $calle = trim(post('calle')); + $numero = post('numero'); + $extra = trim(post('extra')); + $comuna = post('comuna'); + $direccion = model(Direccion::class) + ->where('calle', $calle) + ->where('numero', $numero) + ->where('extra', $extra) + ->where('comuna', $comuna) + ->findOne(); + if (!$direccion) { + $direccion = model(Direccion::class)->create(); + $direccion->calle = $calle; + $direccion->numero = $numero; + $direccion->extra = $extra; + $direccion->comuna = $comuna; + $direccion->save(); + } + + list($rut, $dv) = explode('-', str_replace('.', '', post('rut'))); + $propietario = model(Propietario::class)->where('rut', $rut)->findOne(); + if (!$propietario) { + $propietario = model(Propietario::class)->create(); + $propietario->rut = $rut; + $propietario->dv = $dv; + $propietario->nombres = trim(post('nombres')); + $propietario->apellido_paterno = trim(post('paterno')); + $propietario->apellido_materno = trim(post('materno')); + $propietario->direccion = $direccion->id; + if (post('otro') != null) { + $propietario->otro = 1; + } + + $propietario->save(); + } + + $unis = json_decode(post('unidades')); + $id_principal = array_shift($unis); + $principal = model(Unidad::class)->findOne(post('unidad' . $id_principal)); + // Revisar si existe la propiedad y si está vigente. + $propiedad = model(Propiedad::class)->create(); + $propiedad->unidad_principal = $principal->id; + $propiedad->save(); + $data = [ + 'propiedad' => $propiedad->id, + 'unidad' => $principal->id, + 'principal' => 1 + ]; + $pu = model(PropiedadUnidad::class)->create($data); + $pu->save(); + foreach ($unis as $id_unidad) { + $data = [ + 'propiedad' => $propiedad->id, + 'unidad' => post('unidad' . $id_unidad), + 'principal' => 0 + ]; + $pu = model(PropiedadUnidad::class)->create($data); + $pu->save(); + } + + $venta = model(Venta::class)->create(); + $venta->propietario = $propietario->rut; + $venta->propiedad = $propiedad->id; + if (post('pie')) { + $pie = model(Pie::class)->create(); + $pie->valor = post('pie'); + $pie->fecha = $f->format('Y-m-d'); + $pie->cuotas = post('cuotas'); + if ($uf->total > 0) { + $pie->uf = $uf->uf->value; + } + $pie->save(); + + $venta->pie = $pie->id; + } + if (post('bono_pie')) { + $bono = model(BonoPie::class)->create(); + $bono->valor = post('bono_pie'); + + $pago = model(Pago::class)->create(); + $pago->fecha = $f->format('Y-m-d'); + if ($uf->total > 0) { + $pago->uf = $uf->uf->value; + } + $pago->valor = $bono->valor * $uf->uf->value; + $pago->tipo = 8; + $pago->new(); + + $bono->pago = $pago->id; + $bono->save(); + + $venta->bono_pie = $bono->id; + } + if (post('credito')) { + $pago = model(Pago::class)->create(); + $pago->fecha = $f->format('Y-m-d'); + if ($uf->total > 0) { + $pago->uf = $uf->uf->value; + } + $pago->valor = post('credito') * $uf->uf->value; + $pago->tipo = 2; + $pago->new(); + + $credito = model(Credito::class)->create(); + $credito->pago = $pago->id; + $credito->save(); + + $venta->credito = $credito->id; + } + + $venta->fecha = $f->format('Y-m-d'); + $venta->valor_uf = str_replace(',', '.', post('valor')); + $venta->fecha_ingreso = $t->format('Y-m-d'); + if (post('operador') != 0) { + $venta->agente = post('operador'); + } + if ($uf->total > 0) { + $venta->uf = $uf->uf->value; + } + $venta->new(); + + if (post('promociones') != 0) { + $promos = json_decode(post('promociones')); + foreach ($promos as $id_promo) { + $promocion = model(Promocion::class)->findOne(post('promocion' . $id_promo)); + $promo = model(PromocionVenta::class)->create(); + $promo->promocion = $promocion->id; + $promo->venta = $venta->id; + $promo->valor = post('promo' . $id_promo); + $promo->save(); + } + } + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function edit() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->findMany(); + $regiones = model(Region::class)->order_by_asc('numeracion')->findMany(); + return view('ventas.edit', compact('venta', 'proyectos', 'regiones')); + } + public static function editar() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $uf = uf($f); + + $valor = correctNumber(post('valor')); + $change = false; + if ($venta->fecha != $f->format('Y-m-d')) { + $venta->fecha = $f->format('Y-m-d'); + $venta->uf = $uf->uf->value; + $change = true; + } + if ($venta->valor_uf != $valor) { + $venta->valor_uf = $valor; + $change = true; + } + if ($change) { + $venta->save(); + } + + $direccion = $venta->propietario()->direccion(); + $calle = post('calle'); + $numero = post('numero'); + $extra = post('extra'); + $comuna = post('comuna'); + $change = false; + if ($direccion->calle != $calle) { + $direccion->calle = $calle; + $change = true; + } + if ($direccion->numero != $numero) { + $direccion->numero = $numero; + $change = true; + } + if ($direccion->extra != $extra) { + $direccion->extra = $extra; + $change = true; + } + if ($direccion->comuna != $comuna) { + $direccion->comuna = $comuna; + $change = true; + } + if ($change) { + $direccion->save(); + } + + $propietario = $venta->propietario(); + list($rut, $dv) = explode('-', str_replace('.', '', post('rut'))); + $nombres = post('nombres'); + $paterno = post('paterno'); + $materno = post('materno'); + $change = false; + if ($propietario->rut != $rut) { + $propietario->rut = $rut; + $propietario->dv = $dv; + $venta->propietario = $rut; + $venta->save(); + $change = true; + } + if ($propietario->nombres != $nombres) { + $propietario->nombres = $nombres; + $change = true; + } + if ($propietario->apellido_paterno != $paterno) { + $propietario->apellido_paterno = $paterno; + $change = true; + } + if ($propietario->apellido_materno != $materno) { + $propietario->apellido_materno = $materno; + $change = true; + } + if ($change) { + $propietario->save(); + } + + $unidades = json_decode(post('unidades')); + if (count($unidades) > 0) { + $propiedad = $venta->propiedad(); + $ests = explode(';', $propiedad->estacionamientos); + $bods = explode(';', $propiedad->bodegas); + $change = false; + foreach ($unidades as $n) { + $id = post('unidad' . $n); + $unidad = model(Unidad::class)->findOne($id); + if ($unidad->tipo == 1 and $propiedad->unidad_principal != $unidad->id) { + $propiedad->unidad_principal = $unidad->id; + $change = true; + } + if ($unidad->tipo == 2 and array_search($unidad->id, $ests) === false) { + $ests []= $unidad->id; + } + if ($unidad->tipo == 3 and array_search($unidad->id, $bods) === false) { + $bods []= $unidad->id; + } + } + $ests = implode(';', $ests); + $bods = implode(';', $bods); + if ($propiedad->estacionamientos != $ests) { + $propiedad->estacionamientos = $ests; + $change = true; + } + if ($propiedad->bodegas != $bods) { + $propiedad->bodegas = $bods; + $change = true; + } + if ($change) { + $propiedad->save(); + } + } + + if (post('pie')) { + $pie = $venta->pie(); + $valor = correctNumber(post('pie')); + $cuotas = post('cuotas'); + $change = false; + if ($pie->valor != $valor) { + $pie->valor = $valor; + $change = true; + } + if ($pie->cuotas != $cuotas) { + $pie->cuotas = $cuotas; + $change = true; + } + if ($change) { + $pie->save(); + } + } + + $credito = $venta->credito(); + $valor = post('credito'); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function desistir() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + return view('ventas.desist', compact('venta')); + } + public static function desistiendo() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $valor = correctNumber(post('pago')); + $uf = uf($f); + + $venta->estado = 0; + $tipo = model(TipoEstadoVenta::class)->where('descripcion', 'desistida')->findOne(); + $data = [ + 'venta' => $venta->id, + 'estado' => $tipo->id, + 'fecha' => $f->format('Y-m-d') + ]; + $estado = model(EstadoVenta::class)->create($data); + $propiedad = $venta->propiedad(); + $propiedad->estado = 0; + $pago = model(Pago::class)->create(); + $pago->fecha = $f->format('Y-m-d'); + $pago->valor = (double) $valor; + $pago->uf = $uf->uf->value; + $pago->tipo = 1; + + $pago->new(); + $propiedad->save(); + $estado->save(); + $venta->resciliacion = $pago->id; + $venta->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function ceder() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + return view('ventas.ceder', compact('venta')); + } + public static function cediendo() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + $nueva_venta = model(Venta::class)->create(); + + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + + list($rut, $dv) = explode('-', str_replace('.', '', post('rut'))); + $propietario = model(Propietario::class)->where('rut', $rut)->findOne(); + if (!$propietario) { + $propietario = model(Propietario::class)->create(); + $propietario->rut = $rut; + $propietario->dv = $dv; + $propietario->nombres = trim(post('nombres')); + $propietario->apellido_paterno = trim(post('paterno')); + $propietario->apellido_materno = trim(post('materno')); + $propietario->direccion = $direccion->id; + if (post('otro') != null) { + $propietario->otro = 1; + } + + $propietario->save(); + } + + $nueva_venta->fecha_ingreso = $f->format(); + $nueva_venta->estado = 1; + $cols = [ + 'propiedad', + 'pie', + 'bono_pie', + 'credito', + 'escritura', + 'subsidio', + 'fecha', + 'valor_uf', + 'agente', + 'uf' + ]; + foreach ($cols as $col) { + $nueva_venta->{$col} = $venta->{$col}; + } + $nueva_venta->new(); + + $venta->estado = -1; + $tipo = model(TipoEstadoVenta::class)->where('descripcion', 'cedida')->findOne(); + $data = [ + 'venta' => $venta->id, + 'estado' => $tipo->id, + 'fecha' => $f->format('Y-m-d') + ]; + $estado = model(EstadoVenta::class)->create($data); + $estado->save(); + + $venta->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function entregar() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + return view('ventas.entregar', compact('venta')); + } + public static function consolidacion() + { + if (get('proyecto')) { + $id_proyecto = get('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id_proyecto); + + $ventas = $proyecto->ventas(); + set_time_limit(count($ventas)); + + $f = Carbon::today(config('app.timezone')); + setlocale(LC_TIME, 'es'); + + return view('ventas.consolidacion.show', compact('ventas', 'f')); + } else { + $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many(); + return view('ventas.consolidacion.proyectos', compact('proyectos')); + } + } + public static function devolucion() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + $uf = uf(Carbon::now(config('app.config')))->uf->value; + $valor = round($venta->saldo() * $uf); + + return view('ventas.devolucion', compact('venta', 'valor', 'uf')); + } + public static function devolver() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $uf = uf($f); + $valor = correctNumber(post('valor')); + + $data = [ + 'fecha' => $f->format('Y-m-d'), + 'valor' => $valor, + 'tipo' => 1, + 'uf' => $uf->uf->value, + 'identificador' => post('identificador'), + 'banco' => 0 + ]; + + $banco = model(Banco::class)->where('nombre', post('banco'))->findOne(); + if ($banco) { + $data['banco'] = $banco->id; + } + + $pago = model(Pago::class)->create($data); + $pago->newPagado(); + + $venta->devolucion = $pago->id; + $venta->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function resciliaciones() + { + $resciliaciones = model(Venta::class)->where('estado', 0)->findMany(); + + return view('ventas.resciliaciones', compact('resciliaciones')); + } + public static function firmar() + { + $venta = \model(Venta::class)->findOne(get('venta')); + return view('ventas.firmar', compact('venta')); + } + public static function firmando() + { + $venta = \model(Venta::class)->findOne(get('venta')); + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $venta->firmar($f); + header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); + + } + public static function archivar() + { + $venta = \model(Venta::class)->findOne(get('venta')); + return view('ventas.archivar', compact('venta')); + } + public static function archivando() + { + $venta = \model(Venta::class)->findOne(get('venta')); + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $venta->archivar($f); + header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); + } +} +?> diff --git a/app_old/app/Definition/Controller.php b/app_old/app/Definition/Controller.php new file mode 100644 index 0000000..c0e3dae --- /dev/null +++ b/app_old/app/Definition/Controller.php @@ -0,0 +1,31 @@ +isPublic()) { + + return self::{$action}(); + } + } + if (self::$default == null and \method_exists(self::class, 'setDefault')) { + self::setDefault(); + } + if (self::$default == null) { + header('Location: .'); + return; + } + return self::$default; + } +} +?> \ No newline at end of file diff --git a/app_old/app/Definition/hasEstado.php b/app_old/app/Definition/hasEstado.php new file mode 100644 index 0000000..014fe8a --- /dev/null +++ b/app_old/app/Definition/hasEstado.php @@ -0,0 +1,38 @@ +getTable(); + $self = Stringy::create(get_class($this)); + $ns = $self->substr(0, $self->indexOfLast('\\')); + $self = $self->substr($self->indexOfLast('\\') + 1); + $column = $self->underscored(); + $class = $ns . '\\Estado' . $self; + if (substr($table, -1, 1) == 's') { + $column .= '_id'; + } + + return $this->has_many($class, $column)->findMany(); + } + public function estado() + { + $table = $this->getTable(); + $self = Stringy::create(get_class($this)); + $ns = $self->substr(0, $self->indexOfLast('\\')); + $self = $self->substr($self->indexOfLast('\\') + 1); + $column = $self->underscored(); + $class = $ns . '\\Estado' . $self; + if (substr($table, -1, 1) == 's') { + $column .= '_id'; + } + + $id = $this->has_many($class, $column)->max('id'); + return $this->has_many($class, $column)->findOne($id); + } +} +?> \ No newline at end of file diff --git a/app_old/app/Definition/hasRUT.php b/app_old/app/Definition/hasRUT.php new file mode 100644 index 0000000..8ba3d80 --- /dev/null +++ b/app_old/app/Definition/hasRUT.php @@ -0,0 +1,20 @@ +rut) . '-' . $this->dv; + } +} +?> \ No newline at end of file diff --git a/app_old/app/Exception/PropertyNotFound.php b/app_old/app/Exception/PropertyNotFound.php new file mode 100644 index 0000000..a35e537 --- /dev/null +++ b/app_old/app/Exception/PropertyNotFound.php @@ -0,0 +1,16 @@ +class = $class; + $this->property = $property; + $msg = "Property '" . $property . "' for class '" . $class . "' not found."; + parent::__construct($msg); + } +} \ No newline at end of file diff --git a/app_old/app/Helper/Color.php b/app_old/app/Helper/Color.php new file mode 100644 index 0000000..68c3199 --- /dev/null +++ b/app_old/app/Helper/Color.php @@ -0,0 +1,169 @@ +color = $args[0]; + break; + } + $this->color = $this->hex2dec($this->hex2array($args[0])); + break; + case 2: + if (is_array($args[0])) { + $this->color = $args[0]; + $this->color []= $args[1]; + break; + } + $color = $this->hex2array($args[0]); + $color []= $args[1]; + $this->color = $this->hex2dec($color); + break; + case 3: + case 4: + if (is_numeric($args[0])) { + $this->color = $args; + break; + } + $this->color = $this->hex2dec($args); + break; + } + } + protected function hex2dec(array $hex) + { + return array_map('hexdec', $hex); + } + protected function dec2hex(array $bin) + { + return array_map('dechex', $bin); + } + protected function hex2array(string $hex) + { + switch (strlen($hex)) { + case 3: + case 4: + case 6: + case 7: + return str_split($hex, 2); + default: + throw new OutOfBoundsException('The string ' . $hex . ' is not a correct color code.'); + } + } + protected function array2hex(array $arr) + { + return implode('', $arr); + } + + public function convertTo($type) + { + switch (strtolower($type)) { + case 'hex': + if (is_numeric($this->color[0])) { + $this->color = $this->dec2hex($this->color); + } + break; + case 'dec': + if (!is_numeric($this->color[0])) { + $this->color = $this->hex2dec($this->color); + } + break; + default: + throw new InvalidArgumentException($type . ' is not a valid argument.'); + } + } + public function add($base_color, $amount) + { + $changed = false; + if (!is_numeric($this->color)) { + $this->convertTo('dec'); + $changed = true; + } + switch (strtolower($base_color)) { + case 'r': + $base_color = 0; + break; + case 'g': + $base_color = 1; + break; + case 'b': + $base_color = 2; + break; + case 'a': + $base_color = 3; + break; + default: + throw new OutOfBoundsException("Base color '" . $base_color . "' does not exist."); + } + $this->color[$base_color] += $amount; + if ($changed) { + $this->convertTo('hex'); + } + } + public function print() + { + $this->convertTo('hex'); + return implode('', $this->color); + } + public function toRGB() + { + $changed = false; + $this->convertTo('dec'); + $str = 'rgb(' . implode(', ', array_map(function($a) { + return round($a, 2); + }, $this->color)) . ')'; + if ($changed) { + $this->convertTo('hex'); + } + return $str; + } + public function __toString() + { + return $this->print(); + } + public function toArray() + { + return $this->color; + } + public function toVector() + { + $changed = false; + $this->convertTo('dec'); + $arr = $this->toArray(); + if ($changed) { + $this->convertTo('hex'); + } + return $arr; + } + public function luminosity() + { + $changed = false; + $this->convertTo('dec'); + //sqrt( 0.299*R^2 + 0.587*G^2 + 0.114*B^2 ) + $str = sqrt(0.299 * pow($this->color[0], 2) + 0.587 * pow($this->color[1], 2) + 0.114 * pow($this->color[2], 2)) / 255 * 100; + if ($changed) { + $this->convertTo('hex'); + } + return $str; + } + public function isDark() + { + if ($this->luminosity() < 50) { + return true; + } + return false; + } + public function isBright() + { + if ($this->luminosity() > 75) { + return true; + } + return false; + } +} diff --git a/app_old/app/Helper/Line.php b/app_old/app/Helper/Line.php new file mode 100644 index 0000000..02cc0d9 --- /dev/null +++ b/app_old/app/Helper/Line.php @@ -0,0 +1,61 @@ +origin = $point_a; + $this->length = $this->distance($point_a, $point_b); + $this->direction = $this->gradient($point_a, $point_b); + } + public function origin() + { + return $this->origin; + } + public function length() + { + return $this->length; + } + public function direction() + { + return $this->direction; + } + /** + * Calculate the gradient to move from point a to point b + * @param array $point_a [Vector] + * @param array $point_b [Vector] + * @return array [Vector] + */ + public function gradient($point_a, $point_b) + { + $distance = $this->distance($point_a, $point_b); + return array_map(function($a, $b) use ($distance) { + return ($a - $b) / $distance; + }, $point_b, $point_a); + } + // sqrt((a0-b0)²+(a1-b1)²+(a2-b2)²) + public function distance($point_a, $point_b) + { + return sqrt(array_sum(array_map(function($a, $b) { + return pow($a - $b, 2); + }, $point_a, $point_b))); + } + /** + * Move from point in the direction of the gradient acording to step_size + * @param array $point [Vector] + * @param int $step_size [step size] + * @return array [Vector] + */ + public function move($point, $step_size) + { + $gradient = $this->direction; + return array_map(function($a, $b) use ($step_size) { + return $a + $b * $step_size; + }, $point, $gradient); + } +} diff --git a/app_old/app/Helper/functions.php b/app_old/app/Helper/functions.php new file mode 100644 index 0000000..1ba6021 --- /dev/null +++ b/app_old/app/Helper/functions.php @@ -0,0 +1,128 @@ + "http://{$remote->getIP()}:8080", + 'headers' => [ + 'Accept' => 'application/json' + ] + ])))->getUF($date); +} +function format($tipo, $valor, $format = null, $print = false) { + if ($valor === null) { + $valor = 0; + } + if (strtolower($tipo) == 'localdate') { + $d = \Carbon\Carbon::parse($valor); + $d->locale('es_ES'); + if ($format == null) { + $format = 'DD [de] MMMM [de] YYYY'; + } + return $d->isoFormat($format); + } + if (method_exists('\App\Helper\Format', $tipo)) { + if ($print) { + return \App\Helper\Format::$tipo($valor, $print); + } else { + return \App\Helper\Format::$tipo($valor); + } + } else { + switch ($tipo) { + case 'localDate': + if (isset($format)) { + $intl = new IntlDateFormatter('es_ES', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, 'America/Santiago'); + $intl->setPattern($format); + return ucwords($intl->format($valor)); + } + case 'percent': + return \App\Helper\Format::number($valor, 2); + case 'rut': + return \App\Helper\Format::number($valor, 0); + } + } +} +function model(string $class_name) { + return \Model::factory($class_name); +} +function correctNumber($number) { + if (strpos($number, ',') !== false) { + return str_replace(',', '.', str_replace('.', '', $number)); + } elseif (substr_count($number, '.') > 1) { + return str_replace('.', '', $number); + } + return $number; +} +function parseRanges($range, $numeric = true, $negatives = true) { + $rns = preg_split('/[,;]+/', $range); + $data = []; + foreach ($rns as $p) { + if (!$negatives) { + if (strpos($p, '-') !== false) { + list($ini, $end) = explode('-', $p); + $data = array_merge($data, range($ini, $end)); + continue; + } + } + if ($numeric) { + $data []= (float) $p; + continue; + } + $data []= $p; + } + return $data; +} +function nUrl($p, $a = null, $data = null) { + $query = ['p' => $p]; + if ($a != null) { + $query['a'] = $a; + if ($data != null) { + $query = array_merge($query, $data); + } + } + return url('', $query); +} +function api($p, $a, $data = null) { + $url = baseUrl() . '/' . 'api'; + $url .= '?' . 'p=' . $p . '&a=' . $a . '&API_KEY=1'; + if ($data != null) { + $url .= '&' . implode('&', array_map(function($val, $k) { + return $k . '=' . $val; + }, $data)); + } + return $url; +} +function doLog($user, $action, $variables) { + App\Service\Register::log($user, $action, $variables); +} +?> diff --git a/app_old/app/Middleware/Auth.php b/app_old/app/Middleware/Auth.php new file mode 100644 index 0000000..523c942 --- /dev/null +++ b/app_old/app/Middleware/Auth.php @@ -0,0 +1,38 @@ +skipRoutes($request) or $this->service->isIn()) { + return $handler->handle($request); + } + return $this->redirect('guest'); + } + + protected function skipRoutes(ServerRequestInterface $request): bool + { + $uri = $request->getUri(); + $route = $uri->getPath(); + $routes = [ + '/guest', + '/auth/login' + ]; + return in_array($route, $routes, true); + } + protected function redirect(string $route): ResponseInterface + { + $response = $this->responseFactory->createResponse(301, 'Not authorized'); + return $this->view->render($response, $route); + } +} diff --git a/app_old/app/Service/Auth.php b/app_old/app/Service/Auth.php new file mode 100644 index 0000000..7f021ac --- /dev/null +++ b/app_old/app/Service/Auth.php @@ -0,0 +1,165 @@ +getCookie(); + } + protected function getCookie() + { + if (isset($_COOKIE['rememberMe'])) { + list($s, $t) = \explode(':', $_COOKIE['rememberMe']); + $this->selector = $s; + $this->token = $t; + } + } + protected function saveCookie() + { + $now = \Carbon\Carbon::now(config('app.timezone')); + $exp = $now->addHours(config('app.login_hours')); + \setcookie('rememberMe', $this->selector . ':' . $this->token, $exp->timestamp); + } + protected function clearCookie() + { + \setcookie('rememberMe', '', \Carbon\Carbon::now(config('app.timezone'))->timestamp); + } + protected function generateToken() + { + $this->selector = bin2hex(\random_bytes(12)); + $this->token = bin2hex(\random_bytes(20)); + } + public function login($username, $password) + { + $user = \Model::factory(User::class)->where('name', $username)->where('enabled', 1)->findOne(); + if ($user !== false) { + if (\password_verify($password, $user->password) === false) { + $this->clearCookie(); + return false; + } + + $this->generateToken(); + $now = \Carbon\Carbon::now(config('app.timezone')); + $exp = $now->addHours(-config('app.login_hours')); + $auth = \Model::factory(\Incoviba\common\Auth::class)->where('user_id', $user->id)->whereGt('time', $exp->timestamp)->where('status', 1)->findOne(); + if ($auth !== false) { + $auth->time('now'); + $auth->selector = $this->selector; + $auth->token($this->token); + $auth->save(); + $this->saveCookie(); + return true; + } + + $auth = \Model::factory(\Incoviba\common\Auth::class)->create(); + $auth->user_id = $user->id; + $auth->time('now'); + $auth->selector = $this->selector; + $auth->token($this->token); + + try { + $auth->save(); + $this->saveCookie(); + return true; + } catch (\Exception $e) { + $this->clearCookie(); + return false; + } + } + return false; + } + public function isIn() + { + if ($this->selector == null) { + return false; + } + $auths = \Model::factory(\Incoviba\common\Auth::class)->where('selector', $this->selector)->findMany(); + if ($auths === false) { + $this->clearCookie(); + return false; + } + foreach ($auths as $auth) { + if (\password_verify($this->token, $auth->token)) { + return $auth->isIn(); + } + } + return false; + } + public function User() + { + if ($this->selector == null) { + return false; + } + $auths = \Model::factory(\Incoviba\common\Auth::class)->where('selector', $this->selector)->findMany(); + if ($auths === false) { + return false; + } + foreach ($auths as $auth) { + if (\password_verify($this->token, $auth->token)) { + return $auth->user(); + } + } + return false; + } + public function hasAccess() + { + if ($this->selector == null) { + return false; + } + $auths = \Model::factory(\Incoviba\common\Auth::class)->where('selector', $this->selector)->findMany(); + if ($auths === false) { + return false; + } + foreach ($auths as $auth) { + if (\password_verify($this->token, $auth->token)) { + return $auth->user()->hasAccess(); + } + } + return false; + } + public function checkAccess($controller, $action = null) + { + if ($this->selector == null) { + return false; + } + $auths = \Model::factory(\Incoviba\common\Auth::class)->where('selector', $this->selector)->findMany(); + if ($auths === false) { + return false; + } + foreach ($auths as $auth) { + if (\password_verify($this->token, $auth->token)) { + return $auth->user()->checkAccess($controller, $action); + } + } + return false; + } + public function logout() + { + $this->clearCookie(); + if ($this->selector == null) { + return true; + } + $auths = \Model::factory(\Incoviba\common\Auth::class)->where('selector', $this->selector)->findMany(); + if ($auths === false) { + return true; + } + foreach ($auths as $auth) { + if (\password_verify($this->token, $auth->token)) { + $auth->status = 0; + try { + $auth->save(); + return true; + } catch (\Exception $e) { + return false; + } + } + } + return true; + } +} diff --git a/app_old/app/Service/Borrador.php b/app_old/app/Service/Borrador.php new file mode 100644 index 0000000..4f4b3af --- /dev/null +++ b/app_old/app/Service/Borrador.php @@ -0,0 +1,118 @@ +cierre = $cierre; + $this->lineas = []; + } + protected function add(string $str, int $new_line = 0) + { + $this->lineas []= $str; + if ($new_line > 0) { + $this->newLine($new_line); + } + } + protected function newLine($n = 1) + { + for ($i = 0; $i < $n; $i ++) { + $this->lineas []= ''; + } + } + protected function load() + { + $this->word = IOFactory::load('borrador-' . $this->cierre->proyecto()->nombre . '.docx'); + } + protected function extract() + { + $this->load(); + $data = []; + foreach ($this->word->getSections() as $section) { + foreach ($section->getElements() as $element) { + $r = $this->elementGet($element); + $data []= $r; + } + } + if (count($data) > 0) { + $this->text = $data; + } + } + protected function elementGet($element) + { + if ($element instanceof TextBreak) { + return PHP_EOL; + } + if ($element instanceof TextRun) { + $data = []; + foreach ($element->getElements() as $e) { + $data []= $this->elementGet($e); + } + return implode('', $data); + } + if (!method_exists($element, 'getText')) { + d($element); + } + return $element->getText(); + } + protected function build() + { + if ($this->text == null) { + $this->extract(); + } + foreach ($this->text as $line) { + if ($line == PHP_EOL) { + $this->newLine(); + continue; + } + if (strpos($line, '[[') !== false) { + $replacer = new Replacer(); + $this->add($replacer->replace($line, $this->cierre)); + continue; + } + $this->add($line); + } + } + public function create() + { + $output = new PhpWord(); + + $output->getSettings()->setDecimalSymbol(','); + $output->getSettings()->setThemeFontLang(new Language(Language::ES_ES)); + + $section = $output->addSection(); + foreach ($this->lineas as $linea) { + if ($linea == '') { + $section->addTextBreak(); + continue; + } + $section->addText($linea); + } + + $output->getSettings()->setTrackRevisions(true); + + $writer = IOFactory::createWriter($output); + $filename = 'Borrador ' . $this->cierre->propietario()->nombreCompleto() . ' con ' . $this->cierre->proyecto()->inmobiliaria()->razon_social . '.docx'; + $writer->save($filename); + } + public function show() + { + $this->build(); + return implode(PHP_EOL, $this->lineas); + } +} +?> \ No newline at end of file diff --git a/app_old/app/Service/DBToModel.php b/app_old/app/Service/DBToModel.php new file mode 100644 index 0000000..158e85c --- /dev/null +++ b/app_old/app/Service/DBToModel.php @@ -0,0 +1,158 @@ +name = $name; + $this->db = \ORM::get_db($name); + } + + public function run() + { + $this->getTables(); + foreach ($this->tables as $table) { + if ($this->createClass($table)) { + echo 'ok
', PHP_EOL; + } + } + } + protected function getType($type) + { + if (strpos($type, '(') !== false) { + $type = substr($type, 0, strpos($type, '(')); + } + if (strpos($type, ' ') !== false) { + $type = substr($type, 0, strpos($type, ' ')); + } + switch ($type) { + case 'int': + case 'float': + case 'double': + case 'char': + return trim($type); + case 'date': + case 'datetime': + return trim(strtolower($type)); + case 'varchar': + case 'text': + case 'blob': + return 'string'; + case 'bigint': + case 'tinyint': + case 'enum': + return 'int'; + default: + d($type); + } + } + protected function getTables() + { + $q = "SHOW TABLES"; + $st = $this->db->query($q); + $results = $st->fetchAll(\PDO::FETCH_COLUMN); + $this->tables = []; + foreach ($results as $result) { + $this->tables []= $result; + } + } + protected function getColumns($table) + { + $q = "SHOW COLUMNS FROM `" . $table . "`"; + $st = $this->db->query($q); + $results = $st->fetchAll(\PDO::FETCH_OBJ); + return $results; + } + protected function phpDoc($columns) + { + $str = ['/**']; + $str []= ' *'; + foreach ($columns as $column) { + $str []= ' * @property ' . $this->getType($column->Type) . ' ' . $column->Field; + } + $str []= ' *'; + $str []= ' */'; + + return implode(PHP_EOL, $str); + } + protected function className($table) + { + $name = Stringy::create($table)->upperCamelize(); + return $name; + } + protected function createClass($table) + { + $class = '' . $this->className($table); + $columns = $this->getColumns($table); + $docs = $this->phpDoc($columns); + + $output = ['name}';"; + $output []= '}'; + $output []= '?>'; + + //d(implode(PHP_EOL, $output)); + + $filename = realpath(root() . '/src') . DIRECTORY_SEPARATOR . $class . '.php'; + return file_put_contents($filename, implode(PHP_EOL, $output)); + } + public function create($namespace, $table) + { + $class = '' . $this->className($table); + $columns = $this->getColumns($table); + $docs = $this->phpDoc($columns); + + $namespace = trim($namespace, '\\'); + + $output = ['name}';"; + $output []= '}'; + $output []= '?>'; + $output = implode(PHP_EOL, $output); + + $namespace = explode('\\', $namespace); + array_shift($namespace); + $namespace = implode('/', $namespace); + + $filename = realpath(root() . '/src/' . $namespace) . DIRECTORY_SEPARATOR . $class . '.php'; + + $result = [ + 'result' => false, + 'filename' => $filename, + 'output' => $output + ]; + if (!file_exists($filename)) { + $result['result'] = file_put_contents($filename, $output); + } else { + $result['result'] = true; + } + return json_encode($result); + } + public function list() + { + $this->getTables(); + $output = []; + foreach ($this->tables as $table) { + $output []= ['table' => $table, 'model' => '' . $this->className($table)]; + } + + return json_encode(['models' => $output]); + } +} +?> \ No newline at end of file diff --git a/app_old/app/Service/Factory.php b/app_old/app/Service/Factory.php new file mode 100644 index 0000000..ac7386a --- /dev/null +++ b/app_old/app/Service/Factory.php @@ -0,0 +1,204 @@ +class = $class; + $this->is_aggregator = true; + if (is_subclass_of($class, 'Model')) { + $this->is_aggregator = false; + } + } + public function new() + { + $class = $this->class; + if ($this->is_aggregator) { + return new $class(); + } + return model($class)->create(); + } + public function create($data) + { + $class = $this->class; + if ($this->is_aggregator) { + $obj = new $class(); + $obj->create($data); + return $obj; + } + return model($class)->create($data); + } + /** + * [column => value, column => [value, operator]] + * @var array + */ + protected $conditions; + public function where(array $data) + { + if ($this->conditions == null) { + $this->conditions = $data; + return $this; + } + $this->conditions = array_merge($this->conditions, $data); + return $this; + } + /** + * [column, column => order] + * @var array + */ + protected $order; + public function order(array $data) + { + if ($this->order == null) { + $this->order = $data; + return $this; + } + $this->order = array_merge($this->order, $data); + return $this; + } + protected $limit; + public function limit(array $data) + { + if (!isset($data['limit'])) { + $data['limit'] = $data[0]; + } + if (!isset($data['offset'])) { + $data['offset'] = 0; + if (isset($data[1])) { + $data['offset'] = $data[1]; + } + } + $this->limit = (object) ['limit' => $data['limit'], 'offset' => $data['offset']]; + return $this; + } + protected $many; + public function find($many = false) + { + $this->many = $many; + if ($this->is_aggregator) { + return $this->findAggregator(); + } + return $this->findModel(); + } + + protected function findModel() + { + $objs = model($this->class); + $objs = $this->parseLimit($this->parseOrder($this->parseConditions($objs))); + + if ($this->many) { + return $objs->findMany(); + } + return $objs->findOne(); + } + protected function parseConditions($orm) + { + if ($this->conditions == null) { + return $orm; + } + foreach ($this->conditions as $column => $value) { + if (is_array($value)) { + list($value, $op) = $value; + switch ($op) { + case '>': + case 'gt': + $orm = $orm->whereGt($column, $value); + break; + } + } else { + $orm = $orm->where($column, $value); + } + } + return $orm; + } + protected function parseOrder($orm) + { + if ($this->order == null) { + return $orm; + } + foreach ($this->order as $column => $order) { + if (is_numeric($column)) { + $column = $order; + $order = 'asc'; + } + switch (strtolower($order)) { + case 'asc': + default: + $orm = $orm->orderByAsc($column); + break; + case 'desc': + $orm = $orm->orderByDesc($column); + break; + case 'expr': + $orm = $orm->orderByExpr($column); + break; + } + } + return $orm; + } + protected function parseLimit($orm) + { + if ($this->limit == null) { + return $orm; + } + $orm = $orm->limit($this->limit->limit); + if (isset($this->limit->offset)) { + $orm = $orm->offset($this->limit->offset); + } + return $orm; + } + protected function findAggregator() + { + $model = $this->modelName($this->class); + $ids = $this->getIds($model); + $class = $this->class; + if (count($ids) == 0) { + return false; + } + if ($this->many) { + $objs = []; + foreach ($ids as $id) { + $objs []= new $class($id); + } + } else { + $objs = new $class($ids[0]); + } + return $objs; + } + protected function getIds($model) + { + $id = $this->getModelId($model); + $table = $this->getTable($model); + $st = \ORM::forTable($table)->select($id); + $st = $this->parseConditions($st); + $results = $st->findArray(); + $output = array_map(function($a) use($id) { + return $a[$id]; + }, $results); + return $output; + } + protected function modelName($class) + { + $arr = explode("\\", $class); + \array_push($arr, end($arr)); + return implode("\\", $arr); + } + protected function getModelId($model) + { + $table = $this->getTable($model); + $query = "SHOW KEYS FROM {$table} WHERE Key_name = 'PRIMARY'"; + $st = \ORM::getDb()->query($query); + $results = $st->fetchAll(\PDO::FETCH_OBJ); + return $results[0]->Column_name; + } + protected function getTable($model) + { + $arr = explode("\\", $model); + return Stringy::create(end($arr))->toLowerCase() . ''; + } +} diff --git a/app_old/app/Service/Informador.php b/app_old/app/Service/Informador.php new file mode 100644 index 0000000..c64db26 --- /dev/null +++ b/app_old/app/Service/Informador.php @@ -0,0 +1,463 @@ +title = $title; + } else { + $this->title = 'Informe'; + } + } + + public function addColumn(string $title, $col = '') + { + if ($col == '') { + if ($this->columns == null) { + $i = 0; + } else{ + $i = count($this->columns); + } + $col = $this->mapColumn($i); + } + + if (isset($this->columns[$col])) { + $columns = []; + foreach ($this->columns as $c => $data) { + if (ord($c) < ord($col)) { + $columns[$c] = $data; + } elseif (ord($c) == ord($col)) { + $columns[$col] = $title; + } else { + $columns[chr(ord($c) + 1)] = $data; + } + } + $this->columns = $columns; + } else { + $this->columns[$col] = $title; + } + } + public function mapColumn($n) + { + $letters = range('A', 'Z'); + $max = count($letters); + $r = $n / $max + 1; + $p = floor($r - 1) - 1; + $i = $n % $max; + if ($r >= 2) { + return $letters[$p] . $letters[$i]; + } + return $letters[$i]; + } + public function getColumn($col_title) + { + return array_search($col_title, $this->columns); + } + public function getColumnNumber($col) + { + $letters = range('A', 'Z'); + if (strlen($col) > 1) { + $ls = str_split($col); + $n = 0; + foreach ($ls as $i => $l) { + $n += array_search($l, $letters) + $i * count($letters) + 1; + } + return $n; + } + return array_search($col, $letters); + } + public function addColumns(array $columns) + { + foreach ($columns as $column) { + $this->addColumn($column); + } + } + public function addData(int $row, $data, $col = '') + { + if (!isset($this->data[$row])) { + $this->data[$row] = []; + } + if ($col == '') { + $i = count($this->data[$row]); + $col = $this->mapColumn($i); + } elseif (ctype_print($col)) { + $col = $this->getColumn($col); + } else { + $col = $this->mapColumn($col); + } + + if (isset($this->data[$row][$col])) { + $data_array = []; + foreach ($this->data[$row] as $c => $d) { + if (ord($c) < ord($col)) { + $data_array[$c] = $d; + } elseif (ord($c) == ord($col)) { + $data_array[$col] = $this->parseData($data); + } else { + $data_array[chr(ord($c) + 1)] = $d; + } + } + $this->data[$row] = $data_array; + } else { + $this->data[$row][$col] = $this->parseData($data); + } + } + protected function parseData($data) + { + if ($this->isDate($data)) { + // Date + return Date::PHPToExcel($data); + } + return $data; + } + protected function isDate($data) + { + try { + if (strpos($data, '-') === false) { + return false; + } + $fecha = explode('-', $data); + if (count($fecha) != 3) { + return false; + } + list($year, $month, $day) = $fecha; + if (strlen($year) == 4 and strlen($month) <= 2 and strlen($day) <= 2) { + return true; + } + if (ctype_digit($year) and ctype_digit($month) and ctype_digit($day)) { + $f = Carbon::parse($data, config('app.timezone')); + return true; + } + return false; + } catch(\Exception $e) { + return false; + } + return false; + } + public function addDataRow(int $row, array $data_array) + { + foreach ($data_array as $data) { + $this->addData($row, $data); + } + } + public function addDatas(array $data_matrix) + { + foreach ($data_matrix as $row => $data_array) { + $this->addDataRow($row, $data_array); + } + } + protected function findTitleColumn($title) + { + return array_search($title, $this->columns); + } + public function addFormat($format, $title = '') + { + $col = 'A'; + if ($title == '') { + $i = count($this->col_formats); + $col = $this->mapColumn($i); + } else { + $col = $this->findTitleColumn($title); + } + + if (isset($this->col_formats[$col])) { + $columns = []; + foreach ($this->col_formats as $c => $data) { + if (ord($c) < ord($col)) { + $columns[$c] = $data; + } elseif (ord($c) == ord($col)) { + $columns[$col] = $this->translateFormat($format); + } else { + $columns[chr(ord($c) + 1)] = $data; + } + } + $this->col_formats = $columns; + } else { + $this->col_formats[$col] = $this->translateFormat($format); + } + + uksort($this->col_formats, function($ak, $bk) { + return strcmp($ak, $bk); + }); + } + protected function translateFormat(array $format) + { + $translated = []; + foreach ($format as $category => $values) { + switch ($category) { + case 'numberFormat': + $data = $this->translateNumberFormat($values); + break; + case 'alignment': + $data = $this->translateAlignment($values); + break; + case 'font': + $data = $this->translateFont($values); + break; + case 'fill': + $data = $this->translateFill($values); + break; + case 'borders': + $data = $this->translateBorders($values); + break; + } + $translated[$category] = $data; + } + return $translated; + } + protected function translateNumberFormat(array $values) + { + $translated = []; + foreach ($values as $value) { + switch ($value) { + case 'short-date': + $translated['formatCode'] = 'dd-mm-yyyy'; + break; + case 'date': + $translated['formatCode'] = 'dd mmmm, yyyy'; + break; + case 'thousands': + $translated['formatCode'] = NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1; + break; + case 'pesos': + $translated['formatCode'] = '$ #.###'; + break; + default: + $translated['formatCode'] = $value; + } + } + return $translated; + } + protected function translateAlignment(array $values) + { + $translated = []; + foreach ($values as $type => $value) { + switch ($type) { + case 'horizontal': + switch ($value) { + case 'center': + $new = Alignment::HORIZONTAL_CENTER; + break; + } + break; + case 'vertical': + switch ($value) { + case 'middle': + case 'center': + $new = Alignment::VERTICAL_CENTER; + } + default: + $new = $value; + break; + } + $translated[$type] = $new; + } + return $translated; + } + protected function translateFont(array $values) + { + $translated = []; + foreach ($values as $type => $value) { + switch ($type) { + case 'color': + $new = $this->translateColor($value); + break; + default: + $new = $value; + break; + } + $translated[$type] = $new; + } + return $translated; + } + protected function translateFill(array $values) + { + $translated = []; + foreach ($values as $type => $value) { + switch ($type) { + case 'fillType': + switch ($value) { + case 'solid': + $new = Fill::FILL_SOLID; + break; + default: + $new = $value; + break; + } + break; + case 'color': + $new = $this->translateColor($value); + break; + default: + $new = $value; + break; + } + $translated[$type] = $new; + } + return $translated; + } + protected function translateBorders(array $values) + { + $translated = []; + foreach ($format as $category => $value) { + switch ($category) { + case 'allBorders': + case 'left': + case 'right': + case 'top': + case 'bottom': + case 'diagonal': + case 'vertical': + case 'horizontal': + $data = $this->translateBorder($value); + break; + default: + $data = $value; + } + $translated[$category] = $data; + } + return $translated; + } + protected function translateBorder(array $values) + { + $translated = []; + foreach ($values as $type => $value) { + switch ($type) { + case 'color': + $new = $this->translateColor($value); + break; + default: + $new = $value; + break; + } + $translated[$type] = $new; + } + return $translated; + } + protected function translateColor($color) + { + $color_definitions = [ + 'red' => 'ff0000', + 'light-red' => 'ffcccc', + 'dark-red' => 'a00000' + ]; + if (is_array($color)) { + $t = dechex(255 * $color['transparency'] / 100); + $c = $color_definitions[$color['color']]; + $hex = $t . $c; + return ['argb' => $hex]; + } + return ['rgb' => $color_definitions[$color]]; + } + public function addFormats(array $formats) + { + foreach ($formats as $title => $format) { + $this->addFormat($format, $title); + } + } + public function addTotal(string $col) + { + if (isset($this->columns[$col])) { + $sum = 0; + foreach ($this->data as $row => $data) { + $sum += $data[$col]; + } + $this->totals[$col] = $sum; + } + } + public function addAverage(string $col) + { + $this->addTotal($col); + $this->totals[$col] /= count($this->data); + } + + protected function fillData() + { + foreach ($this->data as $row => $data) { + $this->data[$row] = $this->fillAndSort($data); + } + if (count($this->totals) > 0) { + $this->totals = $this->fillAndSort($this->totals); + } + } + protected function fillAndSort(array $row) + { + foreach ($this->columns as $val) { + if (!isset($row[$val])) { + $row[$val] = ''; + } + } + function sortArrayByArray(Array $array, Array $orderArray) { + $ordered = array(); + foreach($orderArray as $key) { + if(array_key_exists($key, $array)) { + $ordered[$key] = $array[$key]; + unset($array[$key]); + } + } + return $ordered + $array; + } + $row = sortArrayByArray($row, $this->columns); + + return $row; + } + + public function informe() + { + $ea = new Spreadsheet(); + $ea->getProperties()->setCreator('Juan Pablo Vial B.'); + $ea->getProperties()->setTitle($this->title); + $ea->getProperties()->setCompany('Incoviba S.A.'); + + $ews = $ea->getActiveSheet(); + + $ews->fromArray(array($this->columns), '', 'A1'); + $ews->fromArray($this->data, '', 'A2'); + $end = 2; + if ($this->totals != null and count($this->totals) > 0) { + $ews->fromArray($this->totals, '', 'A' . count($data) + 2); + $end = 3; + } + + if ($this->col_formats != null and count($this->col_formats) > 0) { + foreach ($this->col_formats as $col => $format) { + $ews->getStyleByColumnAndRow($this->getColumnNumber($col), 2, $this->getColumnNumber($col), count($this->data) + $end)->applyFromArray($format); + } + } + + for ($col = 0; $col < count($this->columns); $col ++) { + $ews->getColumnDimensionByColumn($col)->setAutoSize(true); + } + + $ews->setAutoFilterByColumnAndRow(0, 1, count($this->columns) - 1, count($this->data)); + + $hoy = Carbon::now(config('app.timezone')); + $filename = str_replace('ñ', 'n', $this->title . ' - ' . $hoy->format('Y-m-d') . '.xlsx'); + + $writer = IOFactory::createWriter($ea, "Xlsx"); + + header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8"); + header('Content-Transfer-Encoding: binary'); + header('Content-Disposition: attachment; filename="' . $filename . '"'); + header('Cache-Control: max-age=0'); + + $writer->save('php://output'); + } +} +?> diff --git a/app_old/app/Service/Informe/Contabilidad/Resumen.php b/app_old/app/Service/Informe/Contabilidad/Resumen.php new file mode 100644 index 0000000..e20266a --- /dev/null +++ b/app_old/app/Service/Informe/Contabilidad/Resumen.php @@ -0,0 +1,190 @@ +separator = $separator; + } + + protected function getVentas($id_proyecto) + { + $proyecto = model(Proyecto::class)->findOne($id_proyecto); + $ventas = $proyecto->ventas(); + $output = []; + foreach ($ventas as $venta) { + $found = false; + foreach ($output as $v) { + if ($v->unidad()->descripcion == $venta->unidad()->descripcion) { + $found = true; + break; + } + } + if (!$found) { + $output []= $venta; + } + } + return $output; + } + protected function startOfYear(DateTimeInterface $up_to) + { + return new DateTimeImmutable((clone $up_to)->sub(new DateInterval('P1Y'))->format('31-12-Y')); + } + protected function defaultValueDate(DateTimeInterface $up_to, $glosa = '') + { + return (object) ['fecha' => $this->startOfYear($up_to), 'valor' => 0, 'glosa' => $glosa, 'estado' => '']; + } + protected function extractValueDate(Pago $pago, $glosa = '') + { + return (object) ['fecha' => $pago->fecha(), 'valor' => $pago->valor, 'glosa' => $glosa, 'estado' => $pago->estado()->tipo()->descripcion]; + } + protected function getAnticipos(Venta $venta, DateTimeInterface $up_to) + { + if ($venta->pie == 0) { + return [$this->defaultValueDate($up_to)]; + } + $cuotas = $venta->pie()->cuotas('fecha', $up_to); + $ly = $this->startOfYear($up_to); + $older = array_reduce($cuotas, function($sum, $item) use ($ly) { + if ($item->pago()->estado()->tipo()->active != 1 or strtolower($item->pago()->estado()->tipo()->descripcion) == 'no pagado') { + return $sum; + } + if ($item->pago()->fecha() >= $ly) { + return $sum; + } + return $sum + $item->pago()->valor; + }); + $current = array_filter($cuotas, function($item) use ($ly) { + return $item->pago()->fecha() >= $ly; + }); + foreach ($current as &$item) { + $item = $this->extractValueDate($item->pago(), "Cuota {$item->numero}"); + } + return array_merge([(object) ['fecha' => $ly, 'valor' => $older, 'glosa' => 'Anticipo acumulado', 'estado' => 'Pagado']], $current); + } + protected function getReajuste(Venta $venta, DateTimeInterface $up_to) + { + if ($venta->pie == 0 or $venta->pie()->reajuste == null) { + return $this->defaultValueDate($up_to, 'Reajuste'); + } + return $this->extractValueDate($venta->pie()->reajuste(), 'Reajuste'); + } + protected function getAbono(Venta $venta, DateTimeInterface $up_to) + { + if ($venta->escritura == 0) { + return $this->defaultValueDate($up_to, 'Abono'); + } + return $this->extractValueDate($venta->escritura()->pago(), 'Abono'); + } + protected function getBono(Venta $venta, DateTimeInterface $up_to) + { + if ($venta->bono_pie == 0) { + return $this->defaultValueDate($up_to, 'Bono Pie'); + } + return $this->extractValueDate($venta->bonoPie()->pago(), 'Bono Pie'); + } + protected function getCredito(Venta $venta, DateTimeInterface $up_to) + { + if ($venta->credito == 0) { + return $this->defaultValueDate($up_to, 'Credito'); + } + return $this->extractValueDate($venta->credito()->pago(), 'Credito'); + } + protected function getSubsidio(Venta $venta, DateTimeInterface $up_to) + { + if ($venta->subsidio == 0) { + return [$this->defaultValueDate($up_to, 'Ahorro'), $this->defaultValueDate($up_to, 'Subsidio')]; + } + return [$this->extractValueDate($venta->subsidio()->pago(), 'Ahorro'), $this->extractValueDate($venta->subsidio()->subsidio(), 'Subsidio')]; + } + protected function getResciliacion(Venta $venta, DateTimeInterface $up_to) + { + if ($venta->resciliacion == null) { + return $this->defaultValueDate($up_to, 'Resciliacion'); + } + return $this->extractValueDate($venta->resciliacion()->pago(), 'Resciliacion'); + } + protected function getPagos(Venta $venta, DateTimeInterface $up_to) + { + $pagos = []; + $pagos = array_merge($pagos, $this->getAnticipos($venta, $up_to)); + $pagos []= $this->getReajuste($venta, $up_to); + $pagos []= $this->getAbono($venta, $up_to); + $pagos []= $this->getBono($venta, $up_to); + $pagos []= $this->getCredito($venta, $up_to); + $pagos = array_merge($pagos, $this->getSubsidio($venta, $up_to)); + return array_filter($pagos, function($item) { + return $item->valor != 0; + }); + } + + protected function buildLine(Venta $venta, $pago) + { + if ($pago->valor > 0) { + return ['', $venta->unidad()->descripcion, $pago->fecha->format('d/m/Y'), $pago->glosa, '', $pago->valor, $pago->estado]; + } + return ['', $venta->unidad()->descripcion, $pago->fecha->format('d/m/Y'), $pago->glosa, -$pago->valor, '', $pago->estado]; + } + protected function buildLibro(Venta $venta, DateTimeInterface $up_to) + { + $pagos = $this->getPagos($venta, $up_to); + $output = [ + ['', "Cuenta: Anticipos Dpto {$venta->unidad()->descripcion}"], + ['', 'Fecha', 'Glosa', 'Haber', 'Debe', 'Estado'] + ]; + $debe = 0; + $haber = 0; + foreach ($pagos as $pago) { + $output []= $this->buildLine($venta, $pago); + if ($pago->valor > 0) { + $debe += $pago->valor; + } + else { + $haber -= $pago->valor; + } + } + $output []= ['', '', '', 'Total', $haber, $debe]; + return $output; + } + + public function build(int $id_proyecto, DateTimeInterface $up_to) + { + ini_set('max_execution_time', 60 * 60); + $ventas = $this->getVentas($id_proyecto); + + $output = ["Libro Mayor {$ventas[0]->proyecto()->descripcion}", '']; + foreach ($ventas as $venta) { + $output = array_merge($output, $this->buildLibro($venta, $up_to)); + } + + $filename = "Contabilidad - Resumen - {$ventas[0]->proyecto()->descripcion} - {$up_to->format('Y-m-d')}.xlsx"; + $informe = new Informe(); + $informe->createSpreadsheet() + ->addArray($output) + ->formatColumn('E') + ->formatColumn('F') + ->send($filename); + } +} diff --git a/app_old/app/Service/Informe/Informe.php b/app_old/app/Service/Informe/Informe.php new file mode 100644 index 0000000..8254a10 --- /dev/null +++ b/app_old/app/Service/Informe/Informe.php @@ -0,0 +1,55 @@ +spreadsheet = new Spreadsheet(); + return $this; + } + protected function formatArray(array $data) + { + $maxCols = 0; + foreach ($data as $row) { + if (!is_array($row)) { + continue; + } + if (count($row) > $maxCols) { + $maxCols = count($row); + } + } + foreach ($data as &$row) { + if (!is_array($row)) { + $row = [$row]; + } + if (count($row) < $maxCols) { + $row = array_merge($row, array_fill(0, $maxCols - count($row), '')); + } + } + return $data; + } + public function addArray(array $data, string $start = 'A1') + { + $this->spreadsheet->getActiveSheet()->fromArray($this->formatArray($data), null, $start); + return $this; + } + public function formatColumn(string $column) + { + $this->spreadsheet->getActiveSheet()->getStyle("{$column}:{$column}")->getNumberFormat()->setFormatCode('#,##0'); + return $this; + } + public function send(string $filename) + { + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header("Content-Disposition: attachment;filename=\"{$filename}\""); + header('Cache-Control: max-age=0'); + + $writer = IOFactory::createWriter($this->spreadsheet, 'Xlsx'); + $writer->save('php://output'); + } +} diff --git a/app_old/app/Service/Money.php b/app_old/app/Service/Money.php new file mode 100644 index 0000000..2472e62 --- /dev/null +++ b/app_old/app/Service/Money.php @@ -0,0 +1,55 @@ +parseDate($date); + if (!$this->checkNextMonthValueCalculationByDate($date)) { + return $this->emptyResult(); + } + + $response = $this->client->get('api/uf/value/' . $date->format('Y-m-d')); + + if (!$this->isOk($response)) { + return $this->emptyResult(); + } + + $body = $response->getBody()->getContents(); + if (trim($response->getBody()) === '') { + return $this->emptyResult(); + } + return json_decode($body); + } + + protected function parseDate(string|DateTimeInterface $date): DateTimeInterface + { + if (is_string($date)) { + $date = Carbon::parse($date, config('app.timezone')); + } + return $date; + } + protected function checkNextMonthValueCalculationByDate(DateTimeInterface $date): bool + { + $next_m_9 = Carbon::today(config('app.timezone'))->copy()->endOfMonth()->addDays(9); + $date = Carbon::parse($date); + return $date->lessThan($next_m_9); + } + protected function isOk(ResponseInterface $response): bool + { + $statusCode = $response->getStatusCode(); + return $statusCode >= 200 and $statusCode < 300; + } + protected function emptyResult(): object + { + return (object) ['total' => 0]; + } +} diff --git a/app_old/app/Service/Register.php b/app_old/app/Service/Register.php new file mode 100644 index 0000000..03f96e0 --- /dev/null +++ b/app_old/app/Service/Register.php @@ -0,0 +1,34 @@ + $user, + 'action' => $action, + 'time' => Carbon::now(config('app.timezone'))->toDateTimeString()//->format('Y-m-d HH:mm:ss') + ]; + $registry = model(RModel::class) + ->where('user', $user) + ->where('action', $action) + ->where('time', $data['time']) + ->findOne(); + if (!$registry) { + $registry = model(RModel::class)->create($data); + $registry->save(); + } + foreach ($variables as $data) { + $data['registry'] = $registry->id; + $log = (new Factory(RegistryData::class))->where($data)->find(); + if (!$log) { + $log = model(RegistryData::class)->create($data); + $log->save(); + } + } + } +} diff --git a/app_old/app/Service/Remote.php b/app_old/app/Service/Remote.php new file mode 100644 index 0000000..77418a2 --- /dev/null +++ b/app_old/app/Service/Remote.php @@ -0,0 +1,19 @@ +connection->connect(); + $statement = $connection->query($query); + $result = $statement->fetch(PDO::FETCH_ASSOC); + return $result['ip']; + } +} diff --git a/app_old/app/Service/Replacer.php b/app_old/app/Service/Replacer.php new file mode 100644 index 0000000..bf61513 --- /dev/null +++ b/app_old/app/Service/Replacer.php @@ -0,0 +1,127 @@ +parseLine($line); + + $output = $line; + foreach ($instructions as $instruction) { + $output = str_replace($instruction['original'], $this->buildLine($instruction['instruction'], $data), $output); + } + return $output; + } + protected function parseLine($line) + { + $ini_el = '[['; + $end_el = ']]'; + + $instructions = []; + $offset = 0; + while (strpos($line, $ini_el, $offset) !== false) { + $ini = strpos($line, $ini_el, $offset) + strlen($ini_el); + $end = strpos($line, $end_el, $offset); + $find = substr($line, $ini, $end - $ini); + $instructions []= ['original' => $ini_el . $find . $end_el, 'instruction' => $find]; + $offset = $end + 1; + } + return $instructions; + } + protected function buildLine($instructions, $data) + { + if (strpos($instructions, '|') !== false) { + $instructions = explode('|', $instructions); + } else { + $instructions = [$instructions]; + } + $output = ''; + foreach ($instructions as $instruction) { + $output = $this->buildReplace($instruction, $data, $output); + } + return $output; + } + protected function buildReplace($instruction, $data, $output = null) + { + if (strpos($instruction, '(') !== false) { + $ini = strpos($instruction, '(') + 1; + $end = strpos($instruction, ')'); + $mod = substr($instruction, $ini, $end - $ini); + $instruction = substr($instruction, 0, $ini - 1); + } + switch ($instruction) { + case 'UPPER': + return strtoupper($output); + case 'LOWER': + return strtolower($output); + case 'ISSET': + if ($output != '') { + return ', ' . $output; + } + return ''; + case 'UFS': + return format('ufs', $output); + case 'PESOS': + return format('pesos', $output); + } + + if (isset($mod)) { + $obj = $this->find($instruction . '(' . $mod .')', $data); + } else { + $obj = $this->find($instruction, $data); + } + if ($obj) { + return $obj; + } + if (is_object($output) and method_exists($output, $instruction)) { + if (isset($mod)) { + return $output->$instruction($mod); + } + return $output->$instruction(); + } + if (is_object($output) and isset($output->$instruction)) { + return $output->$instruction; + } + if ($instruction == 'strftime') { + setlocale(LC_TIME, 'es-CL', 'es'); + $f = Carbon::parse($output, config('app.timezone')); + $output = strftime($mod, $f->timestamp); + return $output; + } + + d($output, $instruction, function_exists($instruction), is_object($output), is_object($output) and isset($output->$instruction)); + } + protected function find($instruction, $data) + { + if (strpos($instruction, '(') !== false) { + $ini = strpos($instruction, '(') + 1; + $end = strpos($instruction, ')'); + $mod = substr($instruction, $ini, $end - $ini); + $instruction = substr($instruction, 0, $ini - 1); + } + if (method_exists($data, $instruction)) { + if (isset($mod)) { + return $data->$instruction($mod); + } + return $data->$instruction(); + } + if (isset($data->$instruction)) { + return $data->$instruction; + } + switch ($instruction) { + case 'Unidades': + $str = 'Departamento ' . $data->reserva()->unidad()->numeracion; + foreach ($data->reserva()->unidades() as $unidad) { + $str .= ', ' . ucwords($unidad->unidadProyecto()->tipo()->descripcion) . ' ' . $unidad->numeracion; + } + return $str; + case 'inmobiliaria': + return $data->proyecto()->inmobiliaria(); + } + return false; + } +} +?> \ No newline at end of file diff --git a/app_old/app/Service/Route.php b/app_old/app/Service/Route.php new file mode 100644 index 0000000..f910f87 --- /dev/null +++ b/app_old/app/Service/Route.php @@ -0,0 +1,131 @@ +add($t, $query, $callback); + } + } else { + switch (strtoupper($type)) { + case 'GET': + $this->get($query, $callback); + break; + case 'POST': + $this->post($query, $callback); + break; + } + } + } + public function get($query, $callback) + { + if ($this->exists('get', $query)) { + return; + } + $this->routes['get'][$query] = (object) ['query' => $query, 'callback' => $this->parseCallback($callback)]; + } + public function post($query, $callback) + { + if ($this->exists('post', $query)) { + return; + } + $this->routes['post'][$query] = (object) ['query' => $query, 'callback' => $this->parseCallback($callback)]; + } + protected function exists($type, $query) + { + return isset($this->routes['post'][$query]); + } + protected function parseCallback($callback) + { + if (is_callable($callback)) { + return $callback; + } + elseif (is_object($callback)) { + return [$callback, 'index']; + } + elseif (is_string($callback) and strpos($callback, '@') !== false) { + list($class, $method) = explode('@', $callback); + $class = '\\App\\Controller\\' . $class; + if (method_exists($class, $method)) { + return [$class, $method]; + } + } + elseif (is_string($callback)) { + $class = '\\App\\Controller\\' . $callback; + return [$class, 'index']; + } + } + public function route() + { + $url = $_SERVER['SCRIPT_NAME']; + $query = $_SERVER['QUERY_STRING']; + $method = $_SERVER['REQUEST_METHOD']; + $route = null; + switch (strtoupper($method)) { + case 'GET': + $route = $this->getGet($url, $query); + break; + case 'POST': + $route = $this->getPost($url, $query); + break; + } + if ($route) { + return $this->run($route->callback); + } + return false; + } + protected function getGet($url, $query) + { + if (isset($this->routes['get'][$url])) { + return $this->routes['get'][$url]; + } + $p = get('p'); + if ($p == null) { + $p = get('page'); + if ($p == null) { + $p = get('m'); + if ($p == null) { + $p = get('module'); + } + } + } + if (isset($this->routes['get'][$p])) { + return $this->routes['get'][$p]; + } + return false; + } + protected function getPost($url, $query) + { + if (isset($this->routes['post'][$url])) { + return $this->routes['post'][$url]; + } + $p = get('p'); + if ($p == null) { + $p = get('page'); + if ($p == null) { + $p = get('m'); + if ($p == null) { + $p = get('module'); + } + } + } + if (isset($this->routes['post'][$p])) { + return $this->routes['post'][$p]; + } + return false; + } + protected function run($callback) + { + return call_user_func($callback); + } +} +?> \ No newline at end of file diff --git a/app_old/bin/Pipfile b/app_old/bin/Pipfile new file mode 100644 index 0000000..8108982 --- /dev/null +++ b/app_old/bin/Pipfile @@ -0,0 +1,12 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] +gunicorn = "*" + +[requires] +python_version = "3.8" diff --git a/app_old/bin/console b/app_old/bin/console new file mode 100644 index 0000000..11aaaef --- /dev/null +++ b/app_old/bin/console @@ -0,0 +1,3 @@ +#!/bin/bash + +php /code/bin/index.php "$@" diff --git a/app_old/bin/index.php b/app_old/bin/index.php new file mode 100644 index 0000000..ff23b96 --- /dev/null +++ b/app_old/bin/index.php @@ -0,0 +1,8 @@ +run(); diff --git a/app_old/bin/informes/Pipfile b/app_old/bin/informes/Pipfile new file mode 100644 index 0000000..e8687af --- /dev/null +++ b/app_old/bin/informes/Pipfile @@ -0,0 +1,16 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] +pandas = "*" +xlsxwriter = "*" +httpx = "*" +flask = "*" +numpy = "*" + +[requires] +python_version = "3.8" diff --git a/app_old/bin/informes/app.py b/app_old/bin/informes/app.py new file mode 100644 index 0000000..ff2a8f0 --- /dev/null +++ b/app_old/bin/informes/app.py @@ -0,0 +1,14 @@ +import argparse +from flask import Flask +from controllers.ventas import ventas_blueprint + + +app = Flask(__name__) +app.register_blueprint(ventas_blueprint, url_prefix='/ventas') + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('-p', '--port', default=8011) + args = parser.parse_args() + app.run(port=args.port, debug=True) diff --git a/app_old/bin/informes/controllers/ventas.py b/app_old/bin/informes/controllers/ventas.py new file mode 100644 index 0000000..ab3ffce --- /dev/null +++ b/app_old/bin/informes/controllers/ventas.py @@ -0,0 +1,141 @@ +from flask import Blueprint, request, Response +import io +import json +import pandas as pd +import numpy as np +import datetime + + +ventas_blueprint = Blueprint('ventas', __name__,) + + +def format_data(data): + df = pd.DataFrame(data) + int_columns = ['Departamento', 'Estacionamientos', 'Bodegas'] + for col in int_columns: + df[col] = pd.to_numeric(df[col], errors='ignore') + float_columns = ['Valor Promesa', 'Pie', 'Pie Pagado', '% Pie Pagado', 'Bono Pie', 'Valor Operador', + 'Premios', 'Subsidio', 'Ahorro', 'Credito', 'Valor Ests & Bods', 'Valor Neto', + 'UF/m²*', 'Comision', 'Venta s/Comision', 'Precio'] + for col in float_columns: + if col in df.columns: + df[col] = pd.to_numeric(df[col], errors='coerce') + df = df.replace(np.nan, 0, regex=True) + + df['Fecha Venta'] = pd.to_datetime(df['Fecha Venta'], format='%Y-%m-%d') + df = df.sort_values(by=['Fecha Venta', 'Departamento']) + df['Fecha Venta'] = df['Fecha Venta'].dt.strftime('%d.%m.%Y') + + return df + + +def format_columns(workbook, columns): + column_settings = [{'header': column} for column in columns] + + center_format = workbook.add_format({'align': 'center'}) + amount_format = workbook.add_format({'num_format': '#,##0.00'}) + percent_format = workbook.add_format({'num_format': '0.00%'}) + + amount_columns = ['m² Ponderados', 'Valor Promesa', 'Pie', 'Pie Pagado', 'Bono Pie', 'Valor Operador', 'Premios', + 'Subsidio', 'Ahorro', 'Credito', 'Valor Ests & Bods', 'Valor Neto', 'UF/m²*', 'Comision', + 'Venta s/Comision', 'Precio'] + center_columns = ['Departamento', 'Estacionamientos', 'Bodegas'] + sum_columns = ['m² Ponderados', 'Valor Promesa', 'Pie', 'Pie Pagado', 'Bono Pie', 'Subsidio', 'Ahorro', 'Credito', + 'Valor Operador', 'Premios', 'Valor Ests & Bods', 'Valor Neto', 'Comision'] + count_columns = ['Departamento', 'Estacionamientos', 'Bodegas'] + + for (k, col) in enumerate(column_settings): + if col['header'] in amount_columns: + column_settings[k]['format'] = amount_format + if col['header'] in center_columns: + column_settings[k]['format'] = center_format + if col['header'] in sum_columns: + column_settings[k]['total_function'] = 'sum' + if col['header'] in count_columns: + column_settings[k]['total_function'] = 'count' + if col['header'] == '% Pie Pagado': + column_settings[k]['format'] = percent_format + if col['header'] == 'Propietario': + column_settings[k]['total_string'] = 'TOTAL' + + return column_settings + + +def format_excel(workbook, worksheet, data): + center_format = workbook.add_format({'align': 'center'}) + amount_format = workbook.add_format({'num_format': '#,##0.00'}) + percent_format = workbook.add_format({'num_format': '0.00%'}) + + amount_columns = ['m² Ponderados', 'Valor Promesa', 'Pie', 'Pie Pagado', 'Bono Pie', 'Valor Operador', 'Premios', + 'Subsidio', 'Ahorro', 'Credito', 'Valor Ests & Bods', 'Valor Neto', 'UF/m²*', 'Comision', + 'Venta s/Comision', 'Precio'] + center_columns = ['Departamento', 'Estacionamientos', 'Bodegas'] + + for col in amount_columns: + if col not in data.columns: + continue + k = data.columns.get_loc(col) + 1 + worksheet.set_column(k, k, cell_format=amount_format) + for col in center_columns: + if col not in data.columns: + continue + k = data.columns.get_loc(col) + 1 + worksheet.set_column(k, k, cell_format=center_format) + col = '% Pie Pagado' + k = data.columns.get_loc(col) + 1 + worksheet.set_column(k, k, cell_format=percent_format) + + return worksheet + + +@ventas_blueprint.route('', methods=['POST']) +def ventas(): + data = json.loads(request.data) + output = io.BytesIO() + writer = pd.ExcelWriter('tmp.xlsx', engine='xlsxwriter') + df = format_data(data['data']) + + start_row = 4 + if 'Compañía' in data: + start_row += 1 + df.to_excel(writer, startrow=start_row+1, startcol=1, header=False, index=False, sheet_name='Ventas') + wb = writer.book + wb.filename = output + + title_format = wb.add_format({'font_size': 16, 'bold': True}) + ws = writer.sheets['Ventas'] + (max_row, max_col) = df.shape + + if 'Compañía' in data: + ws.merge_range(1, 1, 1, max_col, data['Compañía']) + ws.merge_range(start_row-3, 1, start_row-3, max_col, data['Proyecto'], cell_format=title_format) + ws.write_string(start_row-2, 1, 'Ventas') + column_settings = format_columns(wb, df.columns) + ws.add_table(start_row, 1, max_row+start_row+1, max_col, {'name': 'Ventas', 'total_row': 1, + 'columns': column_settings, + 'style': 'Table Style Medium 1'}) + ws = format_excel(wb, ws, df) + + column_widths = { + 'B': 46, + 'C': 16, + 'D': 18, + 'E': 10, + 'F': 13, + 'G': 7, + 'H': 8, + 'I': 16, + 'J': 16, + 'K': 13, + 'L': 14 + } + for (col, wd) in column_widths.items(): + ws.set_column('{0}:{0}'.format(col), wd) + + writer.save() + output.seek(0) + date = datetime.date.today() + filename = "Informe de Ventas - {0} - {1}.xlsx".format(data['Proyecto'], date.strftime('%Y-%m-%d')) + return Response(output, mimetype="application/ms-excel", + headers={"Content-Disposition": "attachment;filename={0}".format(filename), + "Content-Type": 'application/octet-stream; charset=utf-8'}) diff --git a/app_old/bootstrap/autoload.php b/app_old/bootstrap/autoload.php new file mode 100644 index 0000000..318f80d --- /dev/null +++ b/app_old/bootstrap/autoload.php @@ -0,0 +1,8 @@ + diff --git a/app_old/bootstrap/database.php b/app_old/bootstrap/database.php new file mode 100644 index 0000000..4372bf2 --- /dev/null +++ b/app_old/bootstrap/database.php @@ -0,0 +1,29 @@ + $data) { + load($data, $name); +} + +function load($data, $name = '') { + if (!isset($data['port'])) { + $port = 3306; + } else { + $port = $data['port']; + } + $dsn = 'mysql:host=' . $data['host'] . ';port=' . $port . ';dbname=' . $data['database'] . ';charset=utf8'; + + if ($name != '') { + ORM::configure($dsn, null, $name); + ORM::configure('username', $data['username'], $name); + ORM::configure('password', $data['password'], $name); + } else { + ORM::configure($dsn, null); + ORM::configure('username', $data['username']); + ORM::configure('password', $data['password']); + } +} + +Model::$short_table_names = true; diff --git a/app_old/bootstrap/dotenv.php b/app_old/bootstrap/dotenv.php new file mode 100644 index 0000000..799a5b1 --- /dev/null +++ b/app_old/bootstrap/dotenv.php @@ -0,0 +1,12 @@ +isDir() or $file->getExtension() != 'env') { + continue; + } + $env = Dotenv::createImmutable($file->getPath(), $file->getBasename()); + $env->load(); +} diff --git a/app_old/bootstrap/errors.php b/app_old/bootstrap/errors.php new file mode 100644 index 0000000..0e54dc4 --- /dev/null +++ b/app_old/bootstrap/errors.php @@ -0,0 +1,7 @@ +pushHandler(new \Whoops\Handler\PrettyPageHandler); + $whoops->register(); +}*/ +?> diff --git a/app_old/bootstrap/logs.php b/app_old/bootstrap/logs.php new file mode 100644 index 0000000..249be53 --- /dev/null +++ b/app_old/bootstrap/logs.php @@ -0,0 +1,26 @@ +underscored(); + Route::add(['GET', 'POST'], $route, $name); +} + +Route::add(['GET', 'POST'], 'buscar', 'Buscar'); +?> \ No newline at end of file diff --git a/setup/cli.app.php b/app_old/cli/app.php similarity index 100% rename from setup/cli.app.php rename to app_old/cli/app.php diff --git a/setup/cli/config.php b/app_old/cli/cli/config.php similarity index 100% rename from setup/cli/config.php rename to app_old/cli/cli/config.php diff --git a/setup/cli/middlewares.php b/app_old/cli/cli/middlewares.php similarity index 100% rename from setup/cli/middlewares.php rename to app_old/cli/cli/middlewares.php diff --git a/setup/cli/setups.php b/app_old/cli/cli/setups.php similarity index 82% rename from setup/cli/setups.php rename to app_old/cli/cli/setups.php index 33b847a..6c4a99f 100644 --- a/setup/cli/setups.php +++ b/app_old/cli/cli/setups.php @@ -1,4 +1,5 @@ function(ContainerInterface $container) { - return new App\Alias\RemoteConnection(); + \App\Alias\RemoteConnection::class => function(ContainerInterface $container) { + return new \App\Alias\RemoteConnection(); }, App\Service\Remote::class => function(ContainerInterface $container) { - return new App\Service\Remote($container->get(App\Alias\RemoteConnection::class)); + return new App\Service\Remote($container->get(\App\Alias\RemoteConnection::class)); }, App\Service\Money::class => function(ContainerInterface $container) { return new App\Service\Money($container->get(GuzzleHttp\Client::class)); }, - App\Alias\Connection::class => function(ContainerInterface $container) { + \App\Alias\Connection::class => function(ContainerInterface $container) { $data = $container->get('databases')->get(ORM::DEFAULT_CONNECTION); - return new App\Alias\Connection( + return new \App\Alias\Connection( $data->get('host'), $data->get('database'), $data->get('username'), diff --git a/setup/composer.php b/app_old/cli/composer.php similarity index 100% rename from setup/composer.php rename to app_old/cli/composer.php diff --git a/app_old/composer.json b/app_old/composer.json new file mode 100644 index 0000000..bfbfb8e --- /dev/null +++ b/app_old/composer.json @@ -0,0 +1,69 @@ +{ + "name" : "aldarien/incoviba", + "description" : "Intranet portal for Incoviba", + "type" : "project", + "require" : { + "aldarien/asset": "*", + "aldarien/config": "*", + "aldarien/format": "*", + "aldarien/response": "*", + "aldarien/session": "*", + "aldarien/url": "*", + "aldarien/view": "*", + "berrnd/slim-blade-view": "^0.1.1", + "guzzlehttp/guzzle": "*", + "incoviba/modelos": "*", + "j4mie/paris": "^1.5", + "monolog/monolog": "^3", + "nesbot/carbon": "^2", + "nyholm/psr7": "*", + "nyholm/psr7-server": "*", + "php-di/php-di": "*", + "php-di/slim-bridge": "*", + "phpoffice/phpspreadsheet": "^1", + "phpoffice/phpword": "^0", + "rubellum/slim-blade-view": "*", + "slam/php-excel": "^4.4", + "slim/slim": "^4", + "symfony/console": "6.4.x-dev", + "vlucas/phpdotenv": "^5.3", + "voku/stringy": "^6" + }, + "require-dev" : { + "phpunit/phpunit" : "*", + "kint-php/kint" : "*", + "filp/whoops" : "*" + }, + "license" : "GNU AGPLv3", + "authors" : [{ + "name" : "Aldarien", + "email" : "jpvial@gmail.com" + } + ], + "autoload" : { + "psr-4" : { + "App\\" : "app/", + "ProVM\\Common\\": "provm/common/" + }, + "files" : [ + "app/Helper/functions.php" + ] + }, + "minimum-stability": "dev", + "repositories": [ + { + "type": "path", + "url": "./aldarien/**", + "options": { + "symlink": true + } + }, + { + "type": "path", + "url": "./incoviba/modelos" + } + ], + "config": { + "sort-packages": true + } +} diff --git a/app_old/config/app.php b/app_old/config/app.php new file mode 100644 index 0000000..4db5c28 --- /dev/null +++ b/app_old/config/app.php @@ -0,0 +1,9 @@ + 'America/Santiago', + 'locale' => 'es', + 'database' => 'mysql', + 'debug' => false, + 'benchmark' => false, + 'login_hours' => 5*24 +]; diff --git a/app_old/config/databases.php b/app_old/config/databases.php new file mode 100644 index 0000000..14e279f --- /dev/null +++ b/app_old/config/databases.php @@ -0,0 +1,24 @@ + [ + 'host' => $_ENV['MYSQL_HOST'], + 'database' => $_ENV['MYSQL_DATABASE'], + 'username' => $_ENV['MYSQL_USER'], + 'password' => $_ENV['MYSQL_PASSWORD'] + ], + 'mysql_copy' => [ + 'host' => 'localhost', + 'database' => 'incoviba3', + 'username' => 'incoviba', + 'password' => $_ENV['MYSQL_PASSWORD'] + ] + ]; + if (isset($_ENV['MYSQL_PORT'])) { + $arr['mysql']['port'] = $_ENV['MYSQL_PORT']; + } + return $arr; +} +return buildDatabaseConfig(); diff --git a/app_old/config/incoviba.php b/app_old/config/incoviba.php new file mode 100644 index 0000000..d21d9e8 --- /dev/null +++ b/app_old/config/incoviba.php @@ -0,0 +1,6 @@ + [ + 'caducidad' => 30 + ] +]; diff --git a/app_old/config/locations.php b/app_old/config/locations.php new file mode 100644 index 0000000..05442b6 --- /dev/null +++ b/app_old/config/locations.php @@ -0,0 +1,16 @@ + root(), + 'cache' => '{locations.base}/cache', + 'public' => '{locations.base}/public', + 'resources' => '{locations.base}/resources', + 'views' => '{locations.resources}/views', + 'src' => '{locations.base}/src', + //'languages' => '{locations.resources}/languages' + 'app' => '{locations.base}/app', + 'controllers' => '{locations.app}/Controller', + 'money' => 'provm.cl/optimus/money', + 'api' => '192.168.1.100/intranet/api', + 'api_url' => '/api' +]; +?> diff --git a/app_old/fontify.json b/app_old/fontify.json new file mode 100644 index 0000000..923703c --- /dev/null +++ b/app_old/fontify.json @@ -0,0 +1,7 @@ +{ + "modules": [ + "bootstrap", + "font-awesome" + ], + "dest": "public" +} \ No newline at end of file diff --git a/incoviba/modelos/.gitignore b/app_old/incoviba/modelos/.gitignore similarity index 100% rename from incoviba/modelos/.gitignore rename to app_old/incoviba/modelos/.gitignore diff --git a/incoviba/modelos/common/Alias/Model.php b/app_old/incoviba/modelos/common/Alias/Model.php similarity index 100% rename from incoviba/modelos/common/Alias/Model.php rename to app_old/incoviba/modelos/common/Alias/Model.php diff --git a/incoviba/modelos/common/Alias/NewEstado.php b/app_old/incoviba/modelos/common/Alias/NewEstado.php similarity index 100% rename from incoviba/modelos/common/Alias/NewEstado.php rename to app_old/incoviba/modelos/common/Alias/NewEstado.php diff --git a/incoviba/modelos/common/Alias/NewModel.php b/app_old/incoviba/modelos/common/Alias/NewModel.php similarity index 100% rename from incoviba/modelos/common/Alias/NewModel.php rename to app_old/incoviba/modelos/common/Alias/NewModel.php diff --git a/incoviba/modelos/common/Alias/NewTipo.php b/app_old/incoviba/modelos/common/Alias/NewTipo.php similarity index 100% rename from incoviba/modelos/common/Alias/NewTipo.php rename to app_old/incoviba/modelos/common/Alias/NewTipo.php diff --git a/incoviba/modelos/common/Alias/OldModel.php b/app_old/incoviba/modelos/common/Alias/OldModel.php similarity index 100% rename from incoviba/modelos/common/Alias/OldModel.php rename to app_old/incoviba/modelos/common/Alias/OldModel.php diff --git a/incoviba/modelos/common/Factory/Model.php b/app_old/incoviba/modelos/common/Factory/Model.php similarity index 100% rename from incoviba/modelos/common/Factory/Model.php rename to app_old/incoviba/modelos/common/Factory/Model.php diff --git a/incoviba/modelos/composer.json b/app_old/incoviba/modelos/composer.json similarity index 100% rename from incoviba/modelos/composer.json rename to app_old/incoviba/modelos/composer.json diff --git a/incoviba/modelos/src/common/Action.php b/app_old/incoviba/modelos/src/common/Action.php similarity index 100% rename from incoviba/modelos/src/common/Action.php rename to app_old/incoviba/modelos/src/common/Action.php diff --git a/incoviba/modelos/src/common/Auth.php b/app_old/incoviba/modelos/src/common/Auth.php similarity index 100% rename from incoviba/modelos/src/common/Auth.php rename to app_old/incoviba/modelos/src/common/Auth.php diff --git a/incoviba/modelos/src/common/Location.php b/app_old/incoviba/modelos/src/common/Location.php similarity index 100% rename from incoviba/modelos/src/common/Location.php rename to app_old/incoviba/modelos/src/common/Location.php diff --git a/incoviba/modelos/src/common/Permission.php b/app_old/incoviba/modelos/src/common/Permission.php similarity index 100% rename from incoviba/modelos/src/common/Permission.php rename to app_old/incoviba/modelos/src/common/Permission.php diff --git a/incoviba/modelos/src/common/Registry.php b/app_old/incoviba/modelos/src/common/Registry.php similarity index 100% rename from incoviba/modelos/src/common/Registry.php rename to app_old/incoviba/modelos/src/common/Registry.php diff --git a/incoviba/modelos/src/common/RegistryData.php b/app_old/incoviba/modelos/src/common/RegistryData.php similarity index 100% rename from incoviba/modelos/src/common/RegistryData.php rename to app_old/incoviba/modelos/src/common/RegistryData.php diff --git a/incoviba/modelos/src/common/Role.php b/app_old/incoviba/modelos/src/common/Role.php similarity index 100% rename from incoviba/modelos/src/common/Role.php rename to app_old/incoviba/modelos/src/common/Role.php diff --git a/incoviba/modelos/src/common/User.php b/app_old/incoviba/modelos/src/common/User.php similarity index 100% rename from incoviba/modelos/src/common/User.php rename to app_old/incoviba/modelos/src/common/User.php diff --git a/incoviba/modelos/src/common/UserRole.php b/app_old/incoviba/modelos/src/common/UserRole.php similarity index 100% rename from incoviba/modelos/src/common/UserRole.php rename to app_old/incoviba/modelos/src/common/UserRole.php diff --git a/incoviba/modelos/src/nuevo/Common/Banco.php b/app_old/incoviba/modelos/src/nuevo/Common/Banco.php similarity index 100% rename from incoviba/modelos/src/nuevo/Common/Banco.php rename to app_old/incoviba/modelos/src/nuevo/Common/Banco.php diff --git a/incoviba/modelos/src/nuevo/Common/Comuna.php b/app_old/incoviba/modelos/src/nuevo/Common/Comuna.php similarity index 100% rename from incoviba/modelos/src/nuevo/Common/Comuna.php rename to app_old/incoviba/modelos/src/nuevo/Common/Comuna.php diff --git a/incoviba/modelos/src/nuevo/Common/Direccion.php b/app_old/incoviba/modelos/src/nuevo/Common/Direccion.php similarity index 100% rename from incoviba/modelos/src/nuevo/Common/Direccion.php rename to app_old/incoviba/modelos/src/nuevo/Common/Direccion.php diff --git a/incoviba/modelos/src/nuevo/Common/M2.php b/app_old/incoviba/modelos/src/nuevo/Common/M2.php similarity index 100% rename from incoviba/modelos/src/nuevo/Common/M2.php rename to app_old/incoviba/modelos/src/nuevo/Common/M2.php diff --git a/incoviba/modelos/src/nuevo/Common/Provincia.php b/app_old/incoviba/modelos/src/nuevo/Common/Provincia.php similarity index 100% rename from incoviba/modelos/src/nuevo/Common/Provincia.php rename to app_old/incoviba/modelos/src/nuevo/Common/Provincia.php diff --git a/incoviba/modelos/src/nuevo/Common/Region.php b/app_old/incoviba/modelos/src/nuevo/Common/Region.php similarity index 100% rename from incoviba/modelos/src/nuevo/Common/Region.php rename to app_old/incoviba/modelos/src/nuevo/Common/Region.php diff --git a/incoviba/modelos/src/nuevo/Common/UF.php b/app_old/incoviba/modelos/src/nuevo/Common/UF.php similarity index 100% rename from incoviba/modelos/src/nuevo/Common/UF.php rename to app_old/incoviba/modelos/src/nuevo/Common/UF.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/Agente.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Agente.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/Agente.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Agente.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/CategoriaCuentaContable.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/CategoriaCuentaContable.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/CategoriaCuentaContable.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/CategoriaCuentaContable.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/Cobro.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Cobro.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/Cobro.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Cobro.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/Contrato.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Contrato.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/Contrato.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Contrato.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/Cuenta.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Cuenta.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/Cuenta.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Cuenta.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/CuentaContable.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/CuentaContable.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/CuentaContable.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/CuentaContable.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/EstadoCobro.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/EstadoCobro.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/EstadoCobro.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/EstadoCobro.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/Inmobiliaria.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Inmobiliaria.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/Inmobiliaria.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Inmobiliaria.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/Participacion.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Participacion.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/Participacion.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Participacion.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/Representante.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Representante.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/Representante.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Representante.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/Socio.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Socio.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/Socio.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Socio.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/TipoAgente.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/TipoAgente.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/TipoAgente.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/TipoAgente.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/TipoCobro.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/TipoCobro.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/TipoCobro.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/TipoCobro.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/TipoContrato.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/TipoContrato.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/TipoContrato.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/TipoContrato.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/TipoEstadoCobro.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/TipoEstadoCobro.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/TipoEstadoCobro.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/TipoEstadoCobro.php diff --git a/incoviba/modelos/src/nuevo/Inmobiliaria/TransaccionContable.php b/app_old/incoviba/modelos/src/nuevo/Inmobiliaria/TransaccionContable.php similarity index 100% rename from incoviba/modelos/src/nuevo/Inmobiliaria/TransaccionContable.php rename to app_old/incoviba/modelos/src/nuevo/Inmobiliaria/TransaccionContable.php diff --git a/incoviba/modelos/src/nuevo/Proyecto/EstadoProyecto.php b/app_old/incoviba/modelos/src/nuevo/Proyecto/EstadoProyecto.php similarity index 100% rename from incoviba/modelos/src/nuevo/Proyecto/EstadoProyecto.php rename to app_old/incoviba/modelos/src/nuevo/Proyecto/EstadoProyecto.php diff --git a/incoviba/modelos/src/nuevo/Proyecto/Etapa.php b/app_old/incoviba/modelos/src/nuevo/Proyecto/Etapa.php similarity index 100% rename from incoviba/modelos/src/nuevo/Proyecto/Etapa.php rename to app_old/incoviba/modelos/src/nuevo/Proyecto/Etapa.php diff --git a/incoviba/modelos/src/nuevo/Proyecto/Participe.php b/app_old/incoviba/modelos/src/nuevo/Proyecto/Participe.php similarity index 100% rename from incoviba/modelos/src/nuevo/Proyecto/Participe.php rename to app_old/incoviba/modelos/src/nuevo/Proyecto/Participe.php diff --git a/incoviba/modelos/src/nuevo/Proyecto/Proyecto.php b/app_old/incoviba/modelos/src/nuevo/Proyecto/Proyecto.php similarity index 100% rename from incoviba/modelos/src/nuevo/Proyecto/Proyecto.php rename to app_old/incoviba/modelos/src/nuevo/Proyecto/Proyecto.php diff --git a/incoviba/modelos/src/nuevo/Proyecto/ProyectoParticipe.php b/app_old/incoviba/modelos/src/nuevo/Proyecto/ProyectoParticipe.php similarity index 100% rename from incoviba/modelos/src/nuevo/Proyecto/ProyectoParticipe.php rename to app_old/incoviba/modelos/src/nuevo/Proyecto/ProyectoParticipe.php diff --git a/incoviba/modelos/src/nuevo/Proyecto/Tema.php b/app_old/incoviba/modelos/src/nuevo/Proyecto/Tema.php similarity index 100% rename from incoviba/modelos/src/nuevo/Proyecto/Tema.php rename to app_old/incoviba/modelos/src/nuevo/Proyecto/Tema.php diff --git a/incoviba/modelos/src/nuevo/Proyecto/TipoEstadoProyecto.php b/app_old/incoviba/modelos/src/nuevo/Proyecto/TipoEstadoProyecto.php similarity index 100% rename from incoviba/modelos/src/nuevo/Proyecto/TipoEstadoProyecto.php rename to app_old/incoviba/modelos/src/nuevo/Proyecto/TipoEstadoProyecto.php diff --git a/incoviba/modelos/src/nuevo/Proyecto/TipoUnidad.php b/app_old/incoviba/modelos/src/nuevo/Proyecto/TipoUnidad.php similarity index 100% rename from incoviba/modelos/src/nuevo/Proyecto/TipoUnidad.php rename to app_old/incoviba/modelos/src/nuevo/Proyecto/TipoUnidad.php diff --git a/incoviba/modelos/src/nuevo/Proyecto/UnidadProyecto.php b/app_old/incoviba/modelos/src/nuevo/Proyecto/UnidadProyecto.php similarity index 100% rename from incoviba/modelos/src/nuevo/Proyecto/UnidadProyecto.php rename to app_old/incoviba/modelos/src/nuevo/Proyecto/UnidadProyecto.php diff --git a/incoviba/modelos/src/nuevo/Venta/Cierre.php b/app_old/incoviba/modelos/src/nuevo/Venta/Cierre.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/Cierre.php rename to app_old/incoviba/modelos/src/nuevo/Venta/Cierre.php diff --git a/incoviba/modelos/src/nuevo/Venta/Comentario.php b/app_old/incoviba/modelos/src/nuevo/Venta/Comentario.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/Comentario.php rename to app_old/incoviba/modelos/src/nuevo/Venta/Comentario.php diff --git a/incoviba/modelos/src/nuevo/Venta/Cuota.php b/app_old/incoviba/modelos/src/nuevo/Venta/Cuota.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/Cuota.php rename to app_old/incoviba/modelos/src/nuevo/Venta/Cuota.php diff --git a/incoviba/modelos/src/nuevo/Venta/Entrega.php b/app_old/incoviba/modelos/src/nuevo/Venta/Entrega.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/Entrega.php rename to app_old/incoviba/modelos/src/nuevo/Venta/Entrega.php diff --git a/incoviba/modelos/src/nuevo/Venta/EstadoCierre.php b/app_old/incoviba/modelos/src/nuevo/Venta/EstadoCierre.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/EstadoCierre.php rename to app_old/incoviba/modelos/src/nuevo/Venta/EstadoCierre.php diff --git a/incoviba/modelos/src/nuevo/Venta/EstadoObservacion.php b/app_old/incoviba/modelos/src/nuevo/Venta/EstadoObservacion.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/EstadoObservacion.php rename to app_old/incoviba/modelos/src/nuevo/Venta/EstadoObservacion.php diff --git a/incoviba/modelos/src/nuevo/Venta/EstadoPago.php b/app_old/incoviba/modelos/src/nuevo/Venta/EstadoPago.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/EstadoPago.php rename to app_old/incoviba/modelos/src/nuevo/Venta/EstadoPago.php diff --git a/incoviba/modelos/src/nuevo/Venta/EstadoPostventa.php b/app_old/incoviba/modelos/src/nuevo/Venta/EstadoPostventa.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/EstadoPostventa.php rename to app_old/incoviba/modelos/src/nuevo/Venta/EstadoPostventa.php diff --git a/incoviba/modelos/src/nuevo/Venta/EstadoVenta.php b/app_old/incoviba/modelos/src/nuevo/Venta/EstadoVenta.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/EstadoVenta.php rename to app_old/incoviba/modelos/src/nuevo/Venta/EstadoVenta.php diff --git a/incoviba/modelos/src/nuevo/Venta/FondoVenta.php b/app_old/incoviba/modelos/src/nuevo/Venta/FondoVenta.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/FondoVenta.php rename to app_old/incoviba/modelos/src/nuevo/Venta/FondoVenta.php diff --git a/incoviba/modelos/src/nuevo/Venta/FormaPago.php b/app_old/incoviba/modelos/src/nuevo/Venta/FormaPago.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/FormaPago.php rename to app_old/incoviba/modelos/src/nuevo/Venta/FormaPago.php diff --git a/incoviba/modelos/src/nuevo/Venta/Medicion.php b/app_old/incoviba/modelos/src/nuevo/Venta/Medicion.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/Medicion.php rename to app_old/incoviba/modelos/src/nuevo/Venta/Medicion.php diff --git a/incoviba/modelos/src/nuevo/Venta/Observacion.php b/app_old/incoviba/modelos/src/nuevo/Venta/Observacion.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/Observacion.php rename to app_old/incoviba/modelos/src/nuevo/Venta/Observacion.php diff --git a/incoviba/modelos/src/nuevo/Venta/Pago.php b/app_old/incoviba/modelos/src/nuevo/Venta/Pago.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/Pago.php rename to app_old/incoviba/modelos/src/nuevo/Venta/Pago.php diff --git a/incoviba/modelos/src/nuevo/Venta/Pie.php b/app_old/incoviba/modelos/src/nuevo/Venta/Pie.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/Pie.php rename to app_old/incoviba/modelos/src/nuevo/Venta/Pie.php diff --git a/incoviba/modelos/src/nuevo/Venta/Postventa.php b/app_old/incoviba/modelos/src/nuevo/Venta/Postventa.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/Postventa.php rename to app_old/incoviba/modelos/src/nuevo/Venta/Postventa.php diff --git a/incoviba/modelos/src/nuevo/Venta/PostventaObservacion.php b/app_old/incoviba/modelos/src/nuevo/Venta/PostventaObservacion.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/PostventaObservacion.php rename to app_old/incoviba/modelos/src/nuevo/Venta/PostventaObservacion.php diff --git a/incoviba/modelos/src/nuevo/Venta/Premio.php b/app_old/incoviba/modelos/src/nuevo/Venta/Premio.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/Premio.php rename to app_old/incoviba/modelos/src/nuevo/Venta/Premio.php diff --git a/incoviba/modelos/src/nuevo/Venta/Propiedad.php b/app_old/incoviba/modelos/src/nuevo/Venta/Propiedad.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/Propiedad.php rename to app_old/incoviba/modelos/src/nuevo/Venta/Propiedad.php diff --git a/incoviba/modelos/src/nuevo/Venta/Propietario.php b/app_old/incoviba/modelos/src/nuevo/Venta/Propietario.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/Propietario.php rename to app_old/incoviba/modelos/src/nuevo/Venta/Propietario.php diff --git a/incoviba/modelos/src/nuevo/Venta/ProyectoTipoMedicion.php b/app_old/incoviba/modelos/src/nuevo/Venta/ProyectoTipoMedicion.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/ProyectoTipoMedicion.php rename to app_old/incoviba/modelos/src/nuevo/Venta/ProyectoTipoMedicion.php diff --git a/incoviba/modelos/src/nuevo/Venta/Reserva.php b/app_old/incoviba/modelos/src/nuevo/Venta/Reserva.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/Reserva.php rename to app_old/incoviba/modelos/src/nuevo/Venta/Reserva.php diff --git a/incoviba/modelos/src/nuevo/Venta/TipoEstadoCierre.php b/app_old/incoviba/modelos/src/nuevo/Venta/TipoEstadoCierre.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/TipoEstadoCierre.php rename to app_old/incoviba/modelos/src/nuevo/Venta/TipoEstadoCierre.php diff --git a/incoviba/modelos/src/nuevo/Venta/TipoEstadoObservacion.php b/app_old/incoviba/modelos/src/nuevo/Venta/TipoEstadoObservacion.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/TipoEstadoObservacion.php rename to app_old/incoviba/modelos/src/nuevo/Venta/TipoEstadoObservacion.php diff --git a/incoviba/modelos/src/nuevo/Venta/TipoEstadoPago.php b/app_old/incoviba/modelos/src/nuevo/Venta/TipoEstadoPago.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/TipoEstadoPago.php rename to app_old/incoviba/modelos/src/nuevo/Venta/TipoEstadoPago.php diff --git a/incoviba/modelos/src/nuevo/Venta/TipoEstadoPostventa.php b/app_old/incoviba/modelos/src/nuevo/Venta/TipoEstadoPostventa.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/TipoEstadoPostventa.php rename to app_old/incoviba/modelos/src/nuevo/Venta/TipoEstadoPostventa.php diff --git a/incoviba/modelos/src/nuevo/Venta/TipoEstadoVenta.php b/app_old/incoviba/modelos/src/nuevo/Venta/TipoEstadoVenta.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/TipoEstadoVenta.php rename to app_old/incoviba/modelos/src/nuevo/Venta/TipoEstadoVenta.php diff --git a/incoviba/modelos/src/nuevo/Venta/TipoFondo.php b/app_old/incoviba/modelos/src/nuevo/Venta/TipoFondo.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/TipoFondo.php rename to app_old/incoviba/modelos/src/nuevo/Venta/TipoFondo.php diff --git a/incoviba/modelos/src/nuevo/Venta/TipoMedicion.php b/app_old/incoviba/modelos/src/nuevo/Venta/TipoMedicion.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/TipoMedicion.php rename to app_old/incoviba/modelos/src/nuevo/Venta/TipoMedicion.php diff --git a/incoviba/modelos/src/nuevo/Venta/TipoPago.php b/app_old/incoviba/modelos/src/nuevo/Venta/TipoPago.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/TipoPago.php rename to app_old/incoviba/modelos/src/nuevo/Venta/TipoPago.php diff --git a/incoviba/modelos/src/nuevo/Venta/TipoPremio.php b/app_old/incoviba/modelos/src/nuevo/Venta/TipoPremio.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/TipoPremio.php rename to app_old/incoviba/modelos/src/nuevo/Venta/TipoPremio.php diff --git a/incoviba/modelos/src/nuevo/Venta/Unidad.php b/app_old/incoviba/modelos/src/nuevo/Venta/Unidad.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/Unidad.php rename to app_old/incoviba/modelos/src/nuevo/Venta/Unidad.php diff --git a/incoviba/modelos/src/nuevo/Venta/UnidadPropiedad.php b/app_old/incoviba/modelos/src/nuevo/Venta/UnidadPropiedad.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/UnidadPropiedad.php rename to app_old/incoviba/modelos/src/nuevo/Venta/UnidadPropiedad.php diff --git a/incoviba/modelos/src/nuevo/Venta/UnidadReserva.php b/app_old/incoviba/modelos/src/nuevo/Venta/UnidadReserva.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/UnidadReserva.php rename to app_old/incoviba/modelos/src/nuevo/Venta/UnidadReserva.php diff --git a/incoviba/modelos/src/nuevo/Venta/Venta.php b/app_old/incoviba/modelos/src/nuevo/Venta/Venta.php similarity index 100% rename from incoviba/modelos/src/nuevo/Venta/Venta.php rename to app_old/incoviba/modelos/src/nuevo/Venta/Venta.php diff --git a/incoviba/modelos/src/old/Common/Banco.php b/app_old/incoviba/modelos/src/old/Common/Banco.php similarity index 100% rename from incoviba/modelos/src/old/Common/Banco.php rename to app_old/incoviba/modelos/src/old/Common/Banco.php diff --git a/incoviba/modelos/src/old/Common/Comuna.php b/app_old/incoviba/modelos/src/old/Common/Comuna.php similarity index 100% rename from incoviba/modelos/src/old/Common/Comuna.php rename to app_old/incoviba/modelos/src/old/Common/Comuna.php diff --git a/incoviba/modelos/src/old/Common/Direccion.php b/app_old/incoviba/modelos/src/old/Common/Direccion.php similarity index 100% rename from incoviba/modelos/src/old/Common/Direccion.php rename to app_old/incoviba/modelos/src/old/Common/Direccion.php diff --git a/incoviba/modelos/src/old/Common/Provincia.php b/app_old/incoviba/modelos/src/old/Common/Provincia.php similarity index 100% rename from incoviba/modelos/src/old/Common/Provincia.php rename to app_old/incoviba/modelos/src/old/Common/Provincia.php diff --git a/incoviba/modelos/src/old/Common/Region.php b/app_old/incoviba/modelos/src/old/Common/Region.php similarity index 100% rename from incoviba/modelos/src/old/Common/Region.php rename to app_old/incoviba/modelos/src/old/Common/Region.php diff --git a/incoviba/modelos/src/old/Inmobiliaria/Cuenta.php b/app_old/incoviba/modelos/src/old/Inmobiliaria/Cuenta.php similarity index 100% rename from incoviba/modelos/src/old/Inmobiliaria/Cuenta.php rename to app_old/incoviba/modelos/src/old/Inmobiliaria/Cuenta.php diff --git a/incoviba/modelos/src/old/Inmobiliaria/Inmobiliaria.php b/app_old/incoviba/modelos/src/old/Inmobiliaria/Inmobiliaria.php similarity index 100% rename from incoviba/modelos/src/old/Inmobiliaria/Inmobiliaria.php rename to app_old/incoviba/modelos/src/old/Inmobiliaria/Inmobiliaria.php diff --git a/incoviba/modelos/src/old/Inmobiliaria/RelacionInmobiliarias.php b/app_old/incoviba/modelos/src/old/Inmobiliaria/RelacionInmobiliarias.php similarity index 100% rename from incoviba/modelos/src/old/Inmobiliaria/RelacionInmobiliarias.php rename to app_old/incoviba/modelos/src/old/Inmobiliaria/RelacionInmobiliarias.php diff --git a/incoviba/modelos/src/old/Inmobiliaria/TipoSociedad.php b/app_old/incoviba/modelos/src/old/Inmobiliaria/TipoSociedad.php similarity index 100% rename from incoviba/modelos/src/old/Inmobiliaria/TipoSociedad.php rename to app_old/incoviba/modelos/src/old/Inmobiliaria/TipoSociedad.php diff --git a/incoviba/modelos/src/old/Proyecto/Agente.php b/app_old/incoviba/modelos/src/old/Proyecto/Agente.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/Agente.php rename to app_old/incoviba/modelos/src/old/Proyecto/Agente.php diff --git a/incoviba/modelos/src/old/Proyecto/AgenteTipo.php b/app_old/incoviba/modelos/src/old/Proyecto/AgenteTipo.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/AgenteTipo.php rename to app_old/incoviba/modelos/src/old/Proyecto/AgenteTipo.php diff --git a/incoviba/modelos/src/old/Proyecto/AvanceConstruccion.php b/app_old/incoviba/modelos/src/old/Proyecto/AvanceConstruccion.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/AvanceConstruccion.php rename to app_old/incoviba/modelos/src/old/Proyecto/AvanceConstruccion.php diff --git a/incoviba/modelos/src/old/Proyecto/Cobro.php b/app_old/incoviba/modelos/src/old/Proyecto/Cobro.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/Cobro.php rename to app_old/incoviba/modelos/src/old/Proyecto/Cobro.php diff --git a/incoviba/modelos/src/old/Proyecto/Costo.php b/app_old/incoviba/modelos/src/old/Proyecto/Costo.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/Costo.php rename to app_old/incoviba/modelos/src/old/Proyecto/Costo.php diff --git a/incoviba/modelos/src/old/Proyecto/EstadoCobro.php b/app_old/incoviba/modelos/src/old/Proyecto/EstadoCobro.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/EstadoCobro.php rename to app_old/incoviba/modelos/src/old/Proyecto/EstadoCobro.php diff --git a/incoviba/modelos/src/old/Proyecto/EstadoProyecto.php b/app_old/incoviba/modelos/src/old/Proyecto/EstadoProyecto.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/EstadoProyecto.php rename to app_old/incoviba/modelos/src/old/Proyecto/EstadoProyecto.php diff --git a/incoviba/modelos/src/old/Proyecto/EstadoProyectoAgente.php b/app_old/incoviba/modelos/src/old/Proyecto/EstadoProyectoAgente.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/EstadoProyectoAgente.php rename to app_old/incoviba/modelos/src/old/Proyecto/EstadoProyectoAgente.php diff --git a/incoviba/modelos/src/old/Proyecto/EtapaProyecto.php b/app_old/incoviba/modelos/src/old/Proyecto/EtapaProyecto.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/EtapaProyecto.php rename to app_old/incoviba/modelos/src/old/Proyecto/EtapaProyecto.php diff --git a/incoviba/modelos/src/old/Proyecto/Pagare.php b/app_old/incoviba/modelos/src/old/Proyecto/Pagare.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/Pagare.php rename to app_old/incoviba/modelos/src/old/Proyecto/Pagare.php diff --git a/incoviba/modelos/src/old/Proyecto/Proyectista.php b/app_old/incoviba/modelos/src/old/Proyecto/Proyectista.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/Proyectista.php rename to app_old/incoviba/modelos/src/old/Proyecto/Proyectista.php diff --git a/incoviba/modelos/src/old/Proyecto/Proyectistas.php b/app_old/incoviba/modelos/src/old/Proyecto/Proyectistas.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/Proyectistas.php rename to app_old/incoviba/modelos/src/old/Proyecto/Proyectistas.php diff --git a/incoviba/modelos/src/old/Proyecto/Proyecto.php b/app_old/incoviba/modelos/src/old/Proyecto/Proyecto.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/Proyecto.php rename to app_old/incoviba/modelos/src/old/Proyecto/Proyecto.php diff --git a/incoviba/modelos/src/old/Proyecto/ProyectoAgente.php b/app_old/incoviba/modelos/src/old/Proyecto/ProyectoAgente.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/ProyectoAgente.php rename to app_old/incoviba/modelos/src/old/Proyecto/ProyectoAgente.php diff --git a/incoviba/modelos/src/old/Proyecto/ProyectoTipoUnidad.php b/app_old/incoviba/modelos/src/old/Proyecto/ProyectoTipoUnidad.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/ProyectoTipoUnidad.php rename to app_old/incoviba/modelos/src/old/Proyecto/ProyectoTipoUnidad.php diff --git a/incoviba/modelos/src/old/Proyecto/RelacionAgentes.php b/app_old/incoviba/modelos/src/old/Proyecto/RelacionAgentes.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/RelacionAgentes.php rename to app_old/incoviba/modelos/src/old/Proyecto/RelacionAgentes.php diff --git a/incoviba/modelos/src/old/Proyecto/RenovacionPagare.php b/app_old/incoviba/modelos/src/old/Proyecto/RenovacionPagare.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/RenovacionPagare.php rename to app_old/incoviba/modelos/src/old/Proyecto/RenovacionPagare.php diff --git a/incoviba/modelos/src/old/Proyecto/TipoAgente.php b/app_old/incoviba/modelos/src/old/Proyecto/TipoAgente.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/TipoAgente.php rename to app_old/incoviba/modelos/src/old/Proyecto/TipoAgente.php diff --git a/incoviba/modelos/src/old/Proyecto/TipoCobro.php b/app_old/incoviba/modelos/src/old/Proyecto/TipoCobro.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/TipoCobro.php rename to app_old/incoviba/modelos/src/old/Proyecto/TipoCobro.php diff --git a/incoviba/modelos/src/old/Proyecto/TipoElemento.php b/app_old/incoviba/modelos/src/old/Proyecto/TipoElemento.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/TipoElemento.php rename to app_old/incoviba/modelos/src/old/Proyecto/TipoElemento.php diff --git a/incoviba/modelos/src/old/Proyecto/TipoEstadoCobro.php b/app_old/incoviba/modelos/src/old/Proyecto/TipoEstadoCobro.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/TipoEstadoCobro.php rename to app_old/incoviba/modelos/src/old/Proyecto/TipoEstadoCobro.php diff --git a/incoviba/modelos/src/old/Proyecto/TipoEstadoProyecto.php b/app_old/incoviba/modelos/src/old/Proyecto/TipoEstadoProyecto.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/TipoEstadoProyecto.php rename to app_old/incoviba/modelos/src/old/Proyecto/TipoEstadoProyecto.php diff --git a/incoviba/modelos/src/old/Proyecto/TipoEstadoProyectoAgente.php b/app_old/incoviba/modelos/src/old/Proyecto/TipoEstadoProyectoAgente.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/TipoEstadoProyectoAgente.php rename to app_old/incoviba/modelos/src/old/Proyecto/TipoEstadoProyectoAgente.php diff --git a/incoviba/modelos/src/old/Proyecto/TipoMonedaPagare.php b/app_old/incoviba/modelos/src/old/Proyecto/TipoMonedaPagare.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/TipoMonedaPagare.php rename to app_old/incoviba/modelos/src/old/Proyecto/TipoMonedaPagare.php diff --git a/incoviba/modelos/src/old/Proyecto/TipoProyectista.php b/app_old/incoviba/modelos/src/old/Proyecto/TipoProyectista.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/TipoProyectista.php rename to app_old/incoviba/modelos/src/old/Proyecto/TipoProyectista.php diff --git a/incoviba/modelos/src/old/Proyecto/TipoTipologia.php b/app_old/incoviba/modelos/src/old/Proyecto/TipoTipologia.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/TipoTipologia.php rename to app_old/incoviba/modelos/src/old/Proyecto/TipoTipologia.php diff --git a/incoviba/modelos/src/old/Proyecto/Tipologia.php b/app_old/incoviba/modelos/src/old/Proyecto/Tipologia.php similarity index 100% rename from incoviba/modelos/src/old/Proyecto/Tipologia.php rename to app_old/incoviba/modelos/src/old/Proyecto/Tipologia.php diff --git a/incoviba/modelos/src/old/Venta/BonoPie.php b/app_old/incoviba/modelos/src/old/Venta/BonoPie.php similarity index 100% rename from incoviba/modelos/src/old/Venta/BonoPie.php rename to app_old/incoviba/modelos/src/old/Venta/BonoPie.php diff --git a/incoviba/modelos/src/old/Venta/Cierre.php b/app_old/incoviba/modelos/src/old/Venta/Cierre.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Cierre.php rename to app_old/incoviba/modelos/src/old/Venta/Cierre.php diff --git a/incoviba/modelos/src/old/Venta/Comentario.php b/app_old/incoviba/modelos/src/old/Venta/Comentario.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Comentario.php rename to app_old/incoviba/modelos/src/old/Venta/Comentario.php diff --git a/incoviba/modelos/src/old/Venta/Credito.php b/app_old/incoviba/modelos/src/old/Venta/Credito.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Credito.php rename to app_old/incoviba/modelos/src/old/Venta/Credito.php diff --git a/incoviba/modelos/src/old/Venta/Cuota.php b/app_old/incoviba/modelos/src/old/Venta/Cuota.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Cuota.php rename to app_old/incoviba/modelos/src/old/Venta/Cuota.php diff --git a/incoviba/modelos/src/old/Venta/Entrega.php b/app_old/incoviba/modelos/src/old/Venta/Entrega.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Entrega.php rename to app_old/incoviba/modelos/src/old/Venta/Entrega.php diff --git a/incoviba/modelos/src/old/Venta/Escritura.php b/app_old/incoviba/modelos/src/old/Venta/Escritura.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Escritura.php rename to app_old/incoviba/modelos/src/old/Venta/Escritura.php diff --git a/incoviba/modelos/src/old/Venta/EstadoCierre.php b/app_old/incoviba/modelos/src/old/Venta/EstadoCierre.php similarity index 100% rename from incoviba/modelos/src/old/Venta/EstadoCierre.php rename to app_old/incoviba/modelos/src/old/Venta/EstadoCierre.php diff --git a/incoviba/modelos/src/old/Venta/EstadoPago.php b/app_old/incoviba/modelos/src/old/Venta/EstadoPago.php similarity index 100% rename from incoviba/modelos/src/old/Venta/EstadoPago.php rename to app_old/incoviba/modelos/src/old/Venta/EstadoPago.php diff --git a/incoviba/modelos/src/old/Venta/EstadoPrecio.php b/app_old/incoviba/modelos/src/old/Venta/EstadoPrecio.php similarity index 100% rename from incoviba/modelos/src/old/Venta/EstadoPrecio.php rename to app_old/incoviba/modelos/src/old/Venta/EstadoPrecio.php diff --git a/incoviba/modelos/src/old/Venta/EstadoProblema.php b/app_old/incoviba/modelos/src/old/Venta/EstadoProblema.php similarity index 100% rename from incoviba/modelos/src/old/Venta/EstadoProblema.php rename to app_old/incoviba/modelos/src/old/Venta/EstadoProblema.php diff --git a/incoviba/modelos/src/old/Venta/EstadoUnidadBloqueada.php b/app_old/incoviba/modelos/src/old/Venta/EstadoUnidadBloqueada.php similarity index 100% rename from incoviba/modelos/src/old/Venta/EstadoUnidadBloqueada.php rename to app_old/incoviba/modelos/src/old/Venta/EstadoUnidadBloqueada.php diff --git a/incoviba/modelos/src/old/Venta/EstadoVenta.php b/app_old/incoviba/modelos/src/old/Venta/EstadoVenta.php similarity index 100% rename from incoviba/modelos/src/old/Venta/EstadoVenta.php rename to app_old/incoviba/modelos/src/old/Venta/EstadoVenta.php diff --git a/incoviba/modelos/src/old/Venta/Pago.php b/app_old/incoviba/modelos/src/old/Venta/Pago.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Pago.php rename to app_old/incoviba/modelos/src/old/Venta/Pago.php diff --git a/incoviba/modelos/src/old/Venta/Pie.php b/app_old/incoviba/modelos/src/old/Venta/Pie.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Pie.php rename to app_old/incoviba/modelos/src/old/Venta/Pie.php diff --git a/incoviba/modelos/src/old/Venta/Precio.php b/app_old/incoviba/modelos/src/old/Venta/Precio.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Precio.php rename to app_old/incoviba/modelos/src/old/Venta/Precio.php diff --git a/incoviba/modelos/src/old/Venta/Problema.php b/app_old/incoviba/modelos/src/old/Venta/Problema.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Problema.php rename to app_old/incoviba/modelos/src/old/Venta/Problema.php diff --git a/incoviba/modelos/src/old/Venta/Promocion.php b/app_old/incoviba/modelos/src/old/Venta/Promocion.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Promocion.php rename to app_old/incoviba/modelos/src/old/Venta/Promocion.php diff --git a/incoviba/modelos/src/old/Venta/PromocionVenta.php b/app_old/incoviba/modelos/src/old/Venta/PromocionVenta.php similarity index 100% rename from incoviba/modelos/src/old/Venta/PromocionVenta.php rename to app_old/incoviba/modelos/src/old/Venta/PromocionVenta.php diff --git a/incoviba/modelos/src/old/Venta/Propiedad.php b/app_old/incoviba/modelos/src/old/Venta/Propiedad.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Propiedad.php rename to app_old/incoviba/modelos/src/old/Venta/Propiedad.php diff --git a/incoviba/modelos/src/old/Venta/PropiedadUnidad.php b/app_old/incoviba/modelos/src/old/Venta/PropiedadUnidad.php similarity index 100% rename from incoviba/modelos/src/old/Venta/PropiedadUnidad.php rename to app_old/incoviba/modelos/src/old/Venta/PropiedadUnidad.php diff --git a/incoviba/modelos/src/old/Venta/Propietario.php b/app_old/incoviba/modelos/src/old/Venta/Propietario.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Propietario.php rename to app_old/incoviba/modelos/src/old/Venta/Propietario.php diff --git a/incoviba/modelos/src/old/Venta/Subsidio.php b/app_old/incoviba/modelos/src/old/Venta/Subsidio.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Subsidio.php rename to app_old/incoviba/modelos/src/old/Venta/Subsidio.php diff --git a/incoviba/modelos/src/old/Venta/TipoEstadoCierre.php b/app_old/incoviba/modelos/src/old/Venta/TipoEstadoCierre.php similarity index 100% rename from incoviba/modelos/src/old/Venta/TipoEstadoCierre.php rename to app_old/incoviba/modelos/src/old/Venta/TipoEstadoCierre.php diff --git a/incoviba/modelos/src/old/Venta/TipoEstadoPago.php b/app_old/incoviba/modelos/src/old/Venta/TipoEstadoPago.php similarity index 100% rename from incoviba/modelos/src/old/Venta/TipoEstadoPago.php rename to app_old/incoviba/modelos/src/old/Venta/TipoEstadoPago.php diff --git a/incoviba/modelos/src/old/Venta/TipoEstadoPrecio.php b/app_old/incoviba/modelos/src/old/Venta/TipoEstadoPrecio.php similarity index 100% rename from incoviba/modelos/src/old/Venta/TipoEstadoPrecio.php rename to app_old/incoviba/modelos/src/old/Venta/TipoEstadoPrecio.php diff --git a/incoviba/modelos/src/old/Venta/TipoEstadoUnidadBloqueada.php b/app_old/incoviba/modelos/src/old/Venta/TipoEstadoUnidadBloqueada.php similarity index 100% rename from incoviba/modelos/src/old/Venta/TipoEstadoUnidadBloqueada.php rename to app_old/incoviba/modelos/src/old/Venta/TipoEstadoUnidadBloqueada.php diff --git a/incoviba/modelos/src/old/Venta/TipoEstadoVenta.php b/app_old/incoviba/modelos/src/old/Venta/TipoEstadoVenta.php similarity index 100% rename from incoviba/modelos/src/old/Venta/TipoEstadoVenta.php rename to app_old/incoviba/modelos/src/old/Venta/TipoEstadoVenta.php diff --git a/incoviba/modelos/src/old/Venta/TipoPago.php b/app_old/incoviba/modelos/src/old/Venta/TipoPago.php similarity index 100% rename from incoviba/modelos/src/old/Venta/TipoPago.php rename to app_old/incoviba/modelos/src/old/Venta/TipoPago.php diff --git a/incoviba/modelos/src/old/Venta/TipoUnidad.php b/app_old/incoviba/modelos/src/old/Venta/TipoUnidad.php similarity index 100% rename from incoviba/modelos/src/old/Venta/TipoUnidad.php rename to app_old/incoviba/modelos/src/old/Venta/TipoUnidad.php diff --git a/incoviba/modelos/src/old/Venta/TipoValorCierre.php b/app_old/incoviba/modelos/src/old/Venta/TipoValorCierre.php similarity index 100% rename from incoviba/modelos/src/old/Venta/TipoValorCierre.php rename to app_old/incoviba/modelos/src/old/Venta/TipoValorCierre.php diff --git a/incoviba/modelos/src/old/Venta/Unidad.php b/app_old/incoviba/modelos/src/old/Venta/Unidad.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Unidad.php rename to app_old/incoviba/modelos/src/old/Venta/Unidad.php diff --git a/incoviba/modelos/src/old/Venta/UnidadBloqueada.php b/app_old/incoviba/modelos/src/old/Venta/UnidadBloqueada.php similarity index 100% rename from incoviba/modelos/src/old/Venta/UnidadBloqueada.php rename to app_old/incoviba/modelos/src/old/Venta/UnidadBloqueada.php diff --git a/incoviba/modelos/src/old/Venta/UnidadCierre.php b/app_old/incoviba/modelos/src/old/Venta/UnidadCierre.php similarity index 100% rename from incoviba/modelos/src/old/Venta/UnidadCierre.php rename to app_old/incoviba/modelos/src/old/Venta/UnidadCierre.php diff --git a/incoviba/modelos/src/old/Venta/ValorCierre.php b/app_old/incoviba/modelos/src/old/Venta/ValorCierre.php similarity index 100% rename from incoviba/modelos/src/old/Venta/ValorCierre.php rename to app_old/incoviba/modelos/src/old/Venta/ValorCierre.php diff --git a/incoviba/modelos/src/old/Venta/Venta.php b/app_old/incoviba/modelos/src/old/Venta/Venta.php similarity index 100% rename from incoviba/modelos/src/old/Venta/Venta.php rename to app_old/incoviba/modelos/src/old/Venta/Venta.php diff --git a/incoviba/modelos/src/old/Venta/Venta.php.save b/app_old/incoviba/modelos/src/old/Venta/Venta.php.save similarity index 100% rename from incoviba/modelos/src/old/Venta/Venta.php.save rename to app_old/incoviba/modelos/src/old/Venta/Venta.php.save diff --git a/package.json b/app_old/package.json similarity index 100% rename from package.json rename to app_old/package.json diff --git a/public/Pipfile b/app_old/public/Pipfile similarity index 100% rename from public/Pipfile rename to app_old/public/Pipfile diff --git a/public/api/.htaccess b/app_old/public/api/.htaccess similarity index 100% rename from public/api/.htaccess rename to app_old/public/api/.htaccess diff --git a/public/api/index.php b/app_old/public/api/index.php similarity index 100% rename from public/api/index.php rename to app_old/public/api/index.php diff --git a/public/api/keys b/app_old/public/api/keys similarity index 100% rename from public/api/keys rename to app_old/public/api/keys diff --git a/public/css/app.css b/app_old/public/css/app.css similarity index 100% rename from public/css/app.css rename to app_old/public/css/app.css diff --git a/public/css/custom.css b/app_old/public/css/custom.css similarity index 100% rename from public/css/custom.css rename to app_old/public/css/custom.css diff --git a/public/fonts/FontAwesome.otf b/app_old/public/fonts/FontAwesome.otf similarity index 100% rename from public/fonts/FontAwesome.otf rename to app_old/public/fonts/FontAwesome.otf diff --git a/public/fonts/fontawesome-webfont.eot b/app_old/public/fonts/fontawesome-webfont.eot similarity index 100% rename from public/fonts/fontawesome-webfont.eot rename to app_old/public/fonts/fontawesome-webfont.eot diff --git a/public/fonts/fontawesome-webfont.svg b/app_old/public/fonts/fontawesome-webfont.svg similarity index 100% rename from public/fonts/fontawesome-webfont.svg rename to app_old/public/fonts/fontawesome-webfont.svg diff --git a/public/fonts/fontawesome-webfont.ttf b/app_old/public/fonts/fontawesome-webfont.ttf similarity index 100% rename from public/fonts/fontawesome-webfont.ttf rename to app_old/public/fonts/fontawesome-webfont.ttf diff --git a/public/fonts/fontawesome-webfont.woff b/app_old/public/fonts/fontawesome-webfont.woff similarity index 100% rename from public/fonts/fontawesome-webfont.woff rename to app_old/public/fonts/fontawesome-webfont.woff diff --git a/public/fonts/fontawesome-webfont.woff2 b/app_old/public/fonts/fontawesome-webfont.woff2 similarity index 100% rename from public/fonts/fontawesome-webfont.woff2 rename to app_old/public/fonts/fontawesome-webfont.woff2 diff --git a/public/fonts/glyphicons-halflings-regular.eot b/app_old/public/fonts/glyphicons-halflings-regular.eot similarity index 100% rename from public/fonts/glyphicons-halflings-regular.eot rename to app_old/public/fonts/glyphicons-halflings-regular.eot diff --git a/public/fonts/glyphicons-halflings-regular.svg b/app_old/public/fonts/glyphicons-halflings-regular.svg similarity index 100% rename from public/fonts/glyphicons-halflings-regular.svg rename to app_old/public/fonts/glyphicons-halflings-regular.svg diff --git a/public/fonts/glyphicons-halflings-regular.ttf b/app_old/public/fonts/glyphicons-halflings-regular.ttf similarity index 100% rename from public/fonts/glyphicons-halflings-regular.ttf rename to app_old/public/fonts/glyphicons-halflings-regular.ttf diff --git a/public/fonts/glyphicons-halflings-regular.woff b/app_old/public/fonts/glyphicons-halflings-regular.woff similarity index 100% rename from public/fonts/glyphicons-halflings-regular.woff rename to app_old/public/fonts/glyphicons-halflings-regular.woff diff --git a/public/fonts/glyphicons-halflings-regular.woff2 b/app_old/public/fonts/glyphicons-halflings-regular.woff2 similarity index 100% rename from public/fonts/glyphicons-halflings-regular.woff2 rename to app_old/public/fonts/glyphicons-halflings-regular.woff2 diff --git a/public/images/Isotipo 16.png b/app_old/public/images/Isotipo 16.png similarity index 100% rename from public/images/Isotipo 16.png rename to app_old/public/images/Isotipo 16.png diff --git a/public/images/Isotipo 32.png b/app_old/public/images/Isotipo 32.png similarity index 100% rename from public/images/Isotipo 32.png rename to app_old/public/images/Isotipo 32.png diff --git a/public/images/Isotipo 64.png b/app_old/public/images/Isotipo 64.png similarity index 100% rename from public/images/Isotipo 64.png rename to app_old/public/images/Isotipo 64.png diff --git a/public/images/logo_cabezal.png b/app_old/public/images/logo_cabezal.png similarity index 100% rename from public/images/logo_cabezal.png rename to app_old/public/images/logo_cabezal.png diff --git a/app_old/public/index.php b/app_old/public/index.php new file mode 100644 index 0000000..7c36a8c --- /dev/null +++ b/app_old/public/index.php @@ -0,0 +1,8 @@ +run(); diff --git a/public/index.php b/app_old/public/index.php.old similarity index 100% rename from public/index.php rename to app_old/public/index.php.old diff --git a/public/install/create_admin.php b/app_old/public/install/create_admin.php similarity index 100% rename from public/install/create_admin.php rename to app_old/public/install/create_admin.php diff --git a/public/install/create_guest.php b/app_old/public/install/create_guest.php similarity index 100% rename from public/install/create_guest.php rename to app_old/public/install/create_guest.php diff --git a/public/install/create_user_base.php b/app_old/public/install/create_user_base.php similarity index 100% rename from public/install/create_user_base.php rename to app_old/public/install/create_user_base.php diff --git a/public/install/end_install.php b/app_old/public/install/end_install.php similarity index 100% rename from public/install/end_install.php rename to app_old/public/install/end_install.php diff --git a/public/install/index.php b/app_old/public/install/index.php similarity index 100% rename from public/install/index.php rename to app_old/public/install/index.php diff --git a/public/install/log_locations.php b/app_old/public/install/log_locations.php similarity index 100% rename from public/install/log_locations.php rename to app_old/public/install/log_locations.php diff --git a/public/install/next_step.php b/app_old/public/install/next_step.php similarity index 100% rename from public/install/next_step.php rename to app_old/public/install/next_step.php diff --git a/public/js/admin.js b/app_old/public/js/admin.js similarity index 100% rename from public/js/admin.js rename to app_old/public/js/admin.js diff --git a/public/js/app.js b/app_old/public/js/app.js similarity index 100% rename from public/js/app.js rename to app_old/public/js/app.js diff --git a/public/js/ventas/pies/cuotas/add.js b/app_old/public/js/ventas/pies/cuotas/add.js similarity index 100% rename from public/js/ventas/pies/cuotas/add.js rename to app_old/public/js/ventas/pies/cuotas/add.js diff --git a/public/links.log b/app_old/public/links.log similarity index 100% rename from public/links.log rename to app_old/public/links.log diff --git a/public/precios.csv b/app_old/public/precios.csv similarity index 100% rename from public/precios.csv rename to app_old/public/precios.csv diff --git a/resources/js/app.js b/app_old/resources/js/app.js similarity index 100% rename from resources/js/app.js rename to app_old/resources/js/app.js diff --git a/resources/js/binaryIndexOf.js b/app_old/resources/js/binaryIndexOf.js similarity index 100% rename from resources/js/binaryIndexOf.js rename to app_old/resources/js/binaryIndexOf.js diff --git a/resources/js/bootstrap.js b/app_old/resources/js/bootstrap.js similarity index 100% rename from resources/js/bootstrap.js rename to app_old/resources/js/bootstrap.js diff --git a/resources/js/chart.js b/app_old/resources/js/chart.js similarity index 100% rename from resources/js/chart.js rename to app_old/resources/js/chart.js diff --git a/resources/js/jquery.filterTable.js b/app_old/resources/js/jquery.filterTable.js similarity index 100% rename from resources/js/jquery.filterTable.js rename to app_old/resources/js/jquery.filterTable.js diff --git a/app_old/resources/less/Controller/Admin.php b/app_old/resources/less/Controller/Admin.php new file mode 100644 index 0000000..137057c --- /dev/null +++ b/app_old/resources/less/Controller/Admin.php @@ -0,0 +1,233 @@ +list(); + } + public static function listNamespaces() + { + $base = [ + 'Common', + 'Inmobiliaria', + 'Proyecto', + 'Venta' + ]; + $nss = [ + 'Incoviba' => [ + 'old' => $base, + 'new' => $base + ] + ]; + + echo json_encode(['namespaces' => self::collapseMultiArray($nss)]); + } + protected static function collapseMultiArray($array, $level = '') + { + $output = []; + foreach ($array as $key => $subarray) { + if (is_array($subarray)) { + $output = array_merge($output, self::collapseMultiArray($subarray, $level . '\\' . $key)); + } else { + $output []= $level . '\\' . $subarray; + } + } + + return $output; + } + public static function createModel() + { + $db = post('database'); + $ns = post('namespace'); + $table = post('table'); + + $modeler = new DBToModel($db); + echo $modeler->create($ns, $table); + } + public static function list_roles() + { + $roles = \Model::factory(\Incoviba\common\Role::class)->findMany(); + echo view('admin.roles.list', compact('roles')); + } + public static function add_role() + { + echo view('admin.roles.add'); + } + public static function do_add_role() + { + $role = \Model::factory(\Incoviba\common\Role::class)->where('description', post('description'))->findOne(); + if ($role === false) { + $role = \Model::factory(\Incoviba\common\Role::class)->create(['description' => post('description')]); + $role->save(); + } + header('Location: ' . nUrl('admin', 'add_role')); + } + public static function role() + { + $role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role')); + $actions = model(Action::class)->orderByAsc('description')->findMany(); + $permissions = []; + foreach ($actions as $action) { + $permissions []= (object) ['description' => $action->description, 'status' => false, 'inherited' => false]; + } + array_walk($permissions, function(&$el, $i, $role) { + if ($role->checkAccess($el->description)) { + $el->status = true; + if ($role->isInherited($el->description)) { + $el->inherited = true; + } + } + }, $role); + echo view('admin.roles.show', compact('role', 'permissions')); + } + public static function add_role_permissions() + { + $role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role')); + $locations = \Model::factory(\Incoviba\common\Location::class)->findMany(); + $actions = model(\Incoviba\common\Action::class)->findMany(); + echo view('admin.roles.add_permissions', compact('role', 'locations', 'actions')); + } + public static function do_add_role_permissions() + { + $role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role')); + $actions = model(\Incoviba\common\Action::class)->findMany(); + foreach ($actions as $action) { + $p = \Model::factory(\Incoviba\common\Permission::class)->where('type', 2)->where('ext_id', $role->id)->where('action_id', $action->id)->findOne(); + if (array_search($action->id, post('allowed'))) { + if (!$p) { + $data = [ + 'type' => 2, + 'ext_id' => $role->id, + 'action_id' => $action->id + ]; + $p = model(\Incoviba\common\Permission::class)->create($data); + } + $p->status = 1; + } else { + if ($p !== false) { + $p->status = 0; + } + } + if ($p !== false) { + $p->save(); + } + } + header('Location: ' . nUrl('admin', 'role', ['role' => $role->id])); + } + public static function list_users() + { + $users = \Model::factory(\Incoviba\common\User::class)->orderByAsc('name')->findMany(); + echo view('admin.users.list', compact('users')); + } + public static function add_user() + { + echo view('admin.users.add'); + } + public static function do_add_user() + { + $user = \Model::factory(\Incoviba\common\User::class)->where('name', post('name'))->findOne(); + if ($user === false) { + $user = \Model::factory(\Incoviba\common\User::class)->create(); + $user->name = post('name'); + $user->password(post('password')); + + $user->save(); + } + header('Location: ' . url('', ['p' => 'admin', 'a' => 'add_user'])); + } + public static function user() + { + $user = \Model::factory(\Incoviba\common\User::class)->findOne(get('user')); + echo view('admin.users.show', compact('user')); + } + public static function add_user_role() + { + if (get('user') !== false) { + $user = \Model::factory(\Incoviba\common\User::class)->findOne(get('user')); + $roles = \Model::factory(\Incoviba\common\Role::class)->findMany(); + return view('admin.users.add_role', compact('user', 'roles')); + } elseif (get('role') !== false) { + $role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role')); + $users = \Model::factory(\Incoviba\common\User::class)->findMany(); + return view('admin.roles.add_users', compact('users', 'role')); + } + } + public static function do_add_user_role() + { + if (get('user') !== false) { + $user = \Model::factory(\Incoviba\common\User::class)->findOne(get('user')); + foreach (post('role') as $r_id) { + $role = \Model::factory(\Incoviba\common\Role::class)->findOne($r_id); + + $usrRl = \Model::factory(\Incoviba\common\UserRole::class)->where('user', $user->id)->where('role', $role->id)->findOne(); + if ($usrRl === false) { + $usrRl = \Model::factory(\Incoviba\common\UserRole::class)->create(['user' => $user->id, 'role' => $role->id]); + $usrRl->save(); + } + } + header('Location: ' . url('', ['p' => 'admin', 'a' => 'user', 'user' => $user->id])); + } elseif (get('role') !== false) { + $role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role')); + foreach (post('users') as $u_id) { + $user = \Model::factory(\Incoviba\common\User::class)->findOne($u_id); + + $usrRl = \Model::factory(\Incoviba\common\UserRole::class)->where('user', $user->id)->where('role', $role->id)->findOne(); + if ($usrRl === false) { + $usrRl = \Model::factory(\Incoviba\common\UserRole::class)->create(['user' => $user->id, 'role' => $role->id]); + $usrRl->save(); + } + } + header('Location: ' . url('', ['p' => 'admin', 'a' => 'role', 'role' => $role->id])); + } + } + public static function remove_user_role() + { + $q = "DELETE FROM user_roles WHERE user = ? AND role = ?"; + $st = \ORM::getDb()->prepare($q); + $st->execute([get('user'), get('role')]); + header('Location: ' . nUrl('admin')); + } + public static function delete_user() + { + $q = "DELETE FROM user_roles WHERE user = ?"; + $st = \ORM::getDb()->prepare($q); + $st->execute([get('user')]); + $q = "DELETE FROM logins WHERE user = ?"; + $st = \ORM::getDb()->prepare($q); + $st->execute([get('user')]); + $q = "DELETE FROM permissions WHERE type = 1 AND ext_id = ?"; + $st = \ORM::getDb()->prepare($q); + $st->execute([get('user')]); + $user = \model(\Incoviba\common\User::class)->findOne(get('user')); + $user->delete(); + header('Location: ' . nUrl('admin', 'list_users')); + } + public static function reset_user() + { + $user = model(\Incoviba\common\User::class)->findOne(get('user')); + $user->password('123456'); + $user->save(); + header('Location: ' . nUrl('admin', 'user', ['user' => $user->id])); + } +} +?> diff --git a/app_old/resources/less/Controller/Ajax.php b/app_old/resources/less/Controller/Ajax.php new file mode 100644 index 0000000..912c979 --- /dev/null +++ b/app_old/resources/less/Controller/Ajax.php @@ -0,0 +1,215 @@ +whereNotEqual('nombre', '')->order_by_asc('nombre')->findMany(); + foreach ($bancos as &$banco) { + $banco = $banco->as_array('nombre')['nombre']; + } + return json_encode($bancos); + } + protected static function buscarBanco() + { + $q = get('q'); + if ($q == null) { + $q = get('query'); + if ($q == null) { + return ''; + } + } + $bancos = \Model::factory(\Incoviba\old\Common\Banco::class)->whereLike('nombre', '%' . $q . '%')->order_by_asc('nombre')->findMany(); + foreach ($bancos as &$banco) { + $banco = $banco->as_array('nombre')['nombre']; + } + return json_encode($bancos); + } + public static function comunas() + { + $id = post('region'); + $comunas = \Model::factory(\Incoviba\old\Common\Comuna::class) + ->select('comuna.*') + ->join('provincia', ['provincia.id', '=', 'comuna.provincia']) + ->where('provincia.region', $id) + ->order_by_asc('comuna.descripcion') + ->findMany(); + + foreach ($comunas as &$comuna) { + $comuna = $comuna->as_array('id', 'descripcion'); + } + return json_encode($comunas); + } + public static function propietario() + { + $id = post('rut'); + $propietario = \Model::factory(\Incoviba\old\Venta\Propietario::class)->where('rut', $id)->findOne(); + if ($propietario) { + $propietario = $propietario->as_array(); + return json_encode($propietario); + } + return null; + } + public static function direccion() + { + $id = post('direccion'); + $direccion = \Model::factory(\Incoviba\old\Common\Direccion::class)->findOne($id); + $comuna = $direccion->comuna(); + $provincia = $comuna->provincia(); + $region = $provincia->region(); + $direccion = $direccion->as_array(); + $direccion['comuna'] = $comuna->as_array(); + $direccion['comuna']['provincia'] = $provincia->as_array(); + $direccion['comuna']['provincia']['region'] = $region->as_array(); + return json_encode($direccion); + } + public static function tipo_unidades() + { + $id = post('proyecto'); + $proyecto = \Model::factory(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id); + $tipos = $proyecto->tipoUnidades(); + foreach ($tipos as &$tipo) { + $tipo = $tipo->as_array(); + } + return json_encode($tipos); + } + public static function unidades() + { + $id_proyecto = post('proyecto'); + $id_tipo = post('tipo'); + + $proyecto = model(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id_proyecto); + $unidades = $proyecto->unidadesDisponibles($id_tipo); + foreach ($unidades as &$unidad) { + $tipologia = $unidad->tipologia(); + $unidad = $unidad->as_array(); + $unidad['tipologia'] = $tipologia->as_array(); + if ($tipologia->tipologia()) { + $unidad['tipologia']['tipologia'] = (array) $tipologia->tipologia(); + continue; + } + $unidad['tipologia']['tipologia'] = ['descripcion' => $tipologia->abreviacion]; + } + return json_encode($unidades); + } + public static function unidades_precios() + { + $proyecto = model(\Incoviba\old\Proyecto\Proyecto::class)->findOne(post('proyecto')); + $unidades = $proyecto->unidades(); + usort($unidades, function($a, $b) { + $t = $a->tipo - $b->tipo; + if ($t == 0) { + return (int) $a->descripcion - (int) $b->descripcion; + } + return $t; + }); + $output = []; + foreach ($unidades as $u) { + $info = [ + 'id' => $u->id, + 'abreviacion' => $u->abreviacion, + 'descripcion' => $u->descripcion, + 'valor' => '--' + ]; + if ($u->precio()) { + $info['valor'] = format('ufs', $u->precio()->valor, null, true); + } + $output []= $info; + } + return json_encode($output); + } + public static function operadores() + { + $id_proyecto = post('proyecto'); + $proyecto = \Model::factory(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id_proyecto); + $operadores = $proyecto->operadores(); + foreach ($operadores as &$operador) { + $operador = [ + 'id' => $operador->id, + 'abreviacion' => $operador->abreviacion + ]; + } + return json_encode($operadores); + } + public static function promociones() + { + $id = post('proyecto'); + $proyecto = \Model::factory(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id); + $promociones = $proyecto->promociones(); + foreach ($promociones as &$promocion) { + $promocion = $promocion->as_array(); + } + return json_encode($promociones); + } + public static function nombres() + { + $nss = model(Propietario::class)->select('nombres')->orderByAsc('nombres')->findMany(); + $nombres = []; + foreach ($nss as $n) { + $ns = explode(' ', $n->nombres); + foreach ($ns as $nombre) { + $nombres []= $nombre; + } + } + $nombres = array_values(array_unique($nombres)); + return json_encode($nombres); + } + public static function apellidos() + { + $aps = model(Propietario::class)->select('apellido_paterno')->orderByAsc('apellido_paterno')->findMany(); + $apellidos = []; + foreach ($aps as $ap) { + $apellidos []= $ap->apellido_paterno; + } + $aps = model(Propietario::class)->select('apellido_materno')->orderByAsc('apellido_materno')->findMany(); + foreach ($aps as $ap) { + $apellidos []= $ap->apellido_paterno; + } + $apellidos = array_values(array_unique($apellidos)); + sort($apellidos); + return json_encode($apellidos); + } + public static function calles() + { + $results = model(Direccion::class)->select('calle')->orderByAsc('calle')->findMany(); + $calles = []; + foreach ($results as $result) { + $calles []= $result->calle; + } + $calles = array_values(array_unique($calles)); + return json_encode($calles); + } + public static function inmobiliarias() + { + $q = post('rut'); + $inmobiliaria = model(Inmobiliaria::class)->findOne($q); + return json_encode($inmobiliaria->as_array()); + } +} +?> diff --git a/resources/less/Controller/Auth.php b/app_old/resources/less/Controller/Auth.php similarity index 100% rename from resources/less/Controller/Auth.php rename to app_old/resources/less/Controller/Auth.php diff --git a/resources/less/Controller/Bonos.php b/app_old/resources/less/Controller/Bonos.php similarity index 100% rename from resources/less/Controller/Bonos.php rename to app_old/resources/less/Controller/Bonos.php diff --git a/app_old/resources/less/Controller/Buscar.php b/app_old/resources/less/Controller/Buscar.php new file mode 100644 index 0000000..ef62a9e --- /dev/null +++ b/app_old/resources/less/Controller/Buscar.php @@ -0,0 +1,340 @@ + $results]); + } + protected static function getResults() + { + $q = get('q'); + if ($q == null) { + $q = get('query'); + } + $t = get('t'); + if ($t == null) { + $t = get('tipo'); + } + $t = urldecode($t); + if ($t == null) { + $t = 'cualquiera'; + } + + $results = null; + if ($q != null) { + $q = urldecode($q); + $results = self::buscar($q, $t); + } + return $results; + } + public static function buscar($query, $tipo) + { + $method = 'buscar' . str_replace(' ', '', ucwords($tipo)); + if (is_callable(['self', $method])) { + $results = self::$method(self::prepareQuery($query)); + $results = self::removeDuplicates($results); + $results = self::sort($results); + return $results; + } + return []; + } + protected static function prepareQuery($query) + { + $query = str_replace('"', '"', $query); + $data = explode(' ', $query); + $regex = "~(?=\\S)[^'\"\\s]*(?:'[^']*'[^'\"\\s]*|\"[^\"]*\"[^'\"\\s]*)*~"; + preg_match_all($regex, $query, $data); + $data = $data[0]; + foreach ($data as &$l) { + $l = str_replace('"', '', str_replace("'", '', $l)); + } + if (is_array($data) and count($data) == 1) { + $data = $data[0]; + } + return $data; + } + protected static function removeDuplicates($results) + { + $output = []; + foreach ($results as $result) { + if (array_search($result, $output) === false) { + $output []= $result; + } + } + return $output; + } + protected static function sort($results) + { + usort($results, function($a, $b) { + $py = strcmp($a->proyecto()->descripcion, $b->proyecto()->descripcion); + if ($py == 0) { + if (!method_exists($a, 'unidad') and !method_exists($b, 'unidad')) { + return $a->descripcion - $b->descripcion; + } + if (!method_exists($a, 'unidad')) { + return $a->descripcion - $b->unidad()->descripcion; + } + if (!method_exists($b, 'unidad')) { + return $a->unidad()->descripcion - $b->descripcion; + } + + $u = $a->unidad()->descripcion - $b->unidad()->descripcion; + if ($u == 0) { + return strcmp($a->propietario()->apellido_paterno, $b->propietario()->apellido_paterno); + } + return $u; + } + return $py; + }); + return $results; + } + protected static function buscarCualquiera($query) + { + $results = []; + foreach (self::$tipos as $tipo) { + if ($tipo == 'cualquiera') { + continue; + } + $method = 'buscar' . str_replace(' ', '', ucwords($tipo)); + + if (is_callable(['self', $method])) { + $results = array_merge($results, self::$method($query)); + } + } + return $results; + } + protected static function buscarDepartamento($query) + { + if (is_array($query)) { + $results = []; + foreach ($query as $segment) { + $results = array_merge($results, self::buscarDepartamento($segment)); + } + } else { + $results = \Model::factory(Venta::class) + ->select('venta.*') + ->join('propiedad', ['propiedad.id', '=', 'venta.propiedad']) + ->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal']) + ->whereLike('unidad.descripcion', '%' . $query . '%') + ->findMany(); + } + return $results; + } + protected static function buscarEstacionamiento($query) + { + if (is_array($query)) { + $results = []; + foreach ($query as $segment) { + $results = array_merge($results, self::buscarEstacionamiento($segment)); + } + } else { + $results = \Model::factory(Venta::class) + ->select('venta.*') + ->join('propiedad', ['propiedad.id', '=', 'venta.propiedad']) + ->join('unidad', "`propiedad`.`estacionamientos` LIKE `unidad`.`id` OR `propiedad`.`estacionamientos` LIKE CONCAT('%;', `unidad`.`id`) OR `propiedad`.`estacionamientos` LIKE CONCAT(`unidad`.`id`, ';%') OR `propiedad`.`estacionamientos` LIKE CONCAT('%;', `unidad`.`id`, ';%')") + ->where('unidad.descripcion', $query) + ->findMany(); + } + return $results; + } + protected static function buscarBodega($query) + { + if (is_array($query)) { + $results = []; + foreach ($query as $segment) { + $results = array_merge($results, self::buscarBodega($segment)); + } + } else { + $results = \Model::factory(Venta::class) + ->select('venta.*') + ->join('propiedad', ['propiedad.id', '=', 'venta.propiedad']) + ->join('unidad', "`propiedad`.`bodegas` LIKE `unidad`.`id` OR `propiedad`.`bodegas` LIKE CONCAT('%;', `unidad`.`id`) OR `propiedad`.`bodegas` LIKE CONCAT(`unidad`.`id`, ';%') OR `propiedad`.`bodegas` LIKE CONCAT('%;', `unidad`.`id`, ';%')") + ->where('unidad.descripcion', $query) + ->findMany(); + } + return $results; + } + protected static function buscarPropietario($query) + { + if (is_array($query)) { + $results = []; + foreach ($query as $segment) { + $results = array_merge($results, self::buscarPropietario($segment)); + } + } else { + $results = self::buscarPropietarioNombres($query); + $results = array_merge($results, self::buscarPropietarioApellido($query)); + $results = array_merge($results, self::buscarPropietarioNombreCompleto($query)); + } + return $results; + } + protected static function buscarPropietarioNombres($query) + { + $results = \Model::factory(Venta::class) + ->select('venta.*') + ->join('propietario', ['propietario.rut', '=', 'venta.propietario']) + ->whereLike('propietario.nombres', '%' . $query . '%') + ->findMany(); + return $results; + } + protected static function buscarPropietarioApellido($query) + { + $results = \Model::factory(Venta::class) + ->select('venta.*') + ->join('propietario', ['propietario.rut', '=', 'venta.propietario']) + ->whereAnyIs([ + ['propietario.apellido_paterno' => '%' . $query . '%'], + ['propietario.apellido_materno' => '%' . $query . '%'] + ], 'LIKE') + ->findMany(); + return $results; + } + protected static function buscarPropietarioNombreCompleto($query) + { + $results = \Model::factory(Venta::class) + ->select('venta.*') + ->join('propietario', ['propietario.rut', '=', 'venta.propietario']) + ->whereRaw("CONCAT_WS(' ', propietario.nombres, propietario.apellido_paterno, propietario.apellido_materno) LIKE '%" . $query . "%'") + ->findMany(); + return $results; + } + protected static function buscarPrecioVenta($query) + { + if (is_array($query)) { + $results = []; + foreach ($query as $segment) { + $results = array_merge($results, self::buscarPrecioVenta($segment)); + } + } else { + $query = str_replace([',', '.'], ['.', ''], $query); + $results = \Model::factory(Venta::class)->where('valor_uf', $query)->findMany(); + } + return $results; + } + protected static function buscarProyecto($query) + { + if (is_array($query)) { + $results = []; + foreach ($query as $segment) { + $results = array_merge($results, self::buscarProyecto($segment)); + } + } else { + $results = model(Venta::class) + ->select('venta.*') + ->join('propiedad', ['propiedad.id', '=', 'venta.propiedad']) + ->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal']) + ->join('proyecto', ['proyecto.id', '=', 'unidad.proyecto']) + ->whereLike('proyecto.descripcion', '%' . $query . '%') + ->findMany(); + } + return $results; + } + protected static function buscarPago($query) + { + if (is_array($query)) { + $results = []; + foreach ($query as $segment) { + $results = array_merge($results, self::buscarPrecioVenta($segment)); + } + } else { + $query = str_replace(',', '.', str_replace('.', '', $query)); + $query2 = (float) $query; + if ($query != $query2) { + return []; + } + if (!is_float($query2)) { + return []; + } + $query = $query2; + $results = self::buscarValorCuota($query); + $results = array_merge($results, self::buscarReajuste($query)); + $results = array_merge($results, self::buscarEscritura($query)); + $results = array_merge($results, self::buscarSubsidio($query)); + $results = array_merge($results, self::buscarCredito($query)); + } + return $results; + } + protected static function buscarValorCuota($query) + { + $results = \Model::factory(Venta::class) + ->select('venta.*') + ->join('cuota', ['cuota.pie', '=', 'venta.pie']) + ->join('pago', ['pago.id', '=', 'cuota.pago']) + ->whereRaw("`pago`.`valor` = " . $query . " OR `pago`.`valor` / `pago`.`uf` = " . $query) + ->findMany(); + return $results; + } + protected static function buscarReajuste($query) + { + $results = \Model::factory(Venta::class) + ->select('venta.*') + ->join('pie', ['pie.id', '=', 'venta.pie']) + ->join('pago', ['pago.id', '=', 'pie.reajuste']) + ->whereRaw("`pago`.`valor` = " . $query . " OR `pago`.`valor` / `pago`.`uf` = " . $query) + ->findMany(); + return $results; + } + protected static function buscarEscritura($query) + { + $results = \Model::factory(Venta::class) + ->select('venta.*') + ->join('escritura', ['escritura.id', '=', 'venta.escritura']) + ->join('pago', ['pago.id', '=', 'escritura.pago']) + ->whereRaw("`pago`.`valor` = " . $query . " OR `pago`.`valor` / `pago`.`uf` = " . $query) + ->findMany(); + return $results; + } + protected static function buscarSubsidio($query) + { + $results = \Model::factory(Venta::class) + ->select('venta.*') + ->join('subsidio', ['subsidio.id', '=', 'venta.subsidio']) + ->join('pago', ['pago.id', '=', 'subsidio.pago']) + ->whereRaw("`pago`.`valor` = " . $query . " OR `pago`.`valor` / `pago`.`uf` = " . $query) + ->findMany(); + return $results; + } + protected static function buscarCredito($query) + { + $results = \Model::factory(Venta::class) + ->select('venta.*') + ->join('credito', ['credito.id', '=', 'venta.credito']) + ->join('pago', ['pago.id', '=', 'credito.pago']) + ->whereRaw("`pago`.`valor` = " . $query . " OR `pago`.`valor` / `pago`.`uf` = " . $query) + ->findMany(); + return $results; + } + protected static function buscarUnidad($query) + { + if (is_array($query)) { + $results = []; + foreach ($query as $segment) { + $results = array_merge($results, self::buscarUnidad($segment)); + } + } else { + $results = model(Unidad::class)->where('descripcion', $query)->findMany(); + foreach ($results as $i => $u) { + if ($u->venta()) { + unset($results[$i]); + } + } + } + return $results; + } +} +?> diff --git a/resources/less/Controller/Cierres.php b/app_old/resources/less/Controller/Cierres.php similarity index 100% rename from resources/less/Controller/Cierres.php rename to app_old/resources/less/Controller/Cierres.php diff --git a/app_old/resources/less/Controller/Comentarios.php b/app_old/resources/less/Controller/Comentarios.php new file mode 100644 index 0000000..494fcc6 --- /dev/null +++ b/app_old/resources/less/Controller/Comentarios.php @@ -0,0 +1,39 @@ +findOne(get('venta')); + echo view('ventas.comentarios.add', compact('venta')); + } + public static function agregar() + { + $venta = \Model::factory(\Incoviba\old\Venta\Venta::class)->findOne(get('venta')); + if ($venta === false) { + throw new Exception('Venta no existe.'); + } + $data = [ + 'venta' => $venta->id, + 'fecha' => \Carbon\Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s'), + 'texto' => post('comentario') + ]; + $comentario = \Model::factory(\Incoviba\old\Venta\Comentario::class)->create($data); + $comentario->save(); + header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); + } + public static function delete() + { + $comentario = \Model::factory(\Incoviba\old\Venta\Comentario::class)->findOne(get('comentario')); + $venta = $comentario->venta(); + $comentario->estado = 0; + $comentario->save(); + header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); + } +} +?> diff --git a/resources/less/Controller/Contabilidad.php b/app_old/resources/less/Controller/Contabilidad.php similarity index 100% rename from resources/less/Controller/Contabilidad.php rename to app_old/resources/less/Controller/Contabilidad.php diff --git a/app_old/resources/less/Controller/Creditos.php b/app_old/resources/less/Controller/Creditos.php new file mode 100644 index 0000000..60a72da --- /dev/null +++ b/app_old/resources/less/Controller/Creditos.php @@ -0,0 +1,207 @@ +findOne($id); + return view('ventas.creditos.add', compact('venta')); + } + public static function agregado() + { + $id = get('venta'); + if ($id == null) { + header('Location: .'); + } + $venta = \Model::factory(Venta::class)->findOne($id); + + $banco = \Model::factory(Banco::class)->where('nombre', post('banco'))->findOne(); + $f = Carbon::createFromDate(post('y'), post('m'), post('d'), config('app.timezone')); + $uf = uf($f); + + $pago = \Model::factory(Pago::class)->create(); + $pago->banco = $banco->id; + $pago->fecha = $f->format('Y-m-d'); + $pago->uf = $uf->uf->value; + $pago->valor = post('valor') * $pago->uf; + $pago->tipo = 2; + + $credito = \Model::factory(Credito::class)->create(); + $credito->banco = $pago->banco; + $credito->valor = $pago->valor; + $credito->fecha = $pago->fecha; + $credito->uf = $pago->uf; + + $pago->new(); + + $credito->pago = $pago->id; + $credito->save(); + + $venta->credito = $credito->id; + $venta->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function pagar() + { + $id = get('venta'); + $venta = \Model::factory(Venta::class)->findOne($id); + return view('ventas.creditos.pagar', compact('venta')); + } + public static function pagando() + { + $id = get('venta'); + $venta = \Model::factory(Venta::class)->findOne($id); + $valor = str_replace(',', '.', str_replace('.', '', post('valor'))); + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + + $pago = $venta->credito()->pago(); + if ($pago->valor != $valor) { + $pago->valor = $valor; + } + + $estado = \Model::factory(EstadoPago::class)->create(); + $estado->pago = $pago->id; + $estado->fecha = $f->format('Y-m-d'); + $estado->estado = 1; + $estado->save(); + + if ($pago->is_dirty('valor')) { + $pago->save(); + } + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function abonar() + { + $id = get('venta'); + $venta = \Model::factory(Venta::class)->findOne($id); + return view('ventas.creditos.abonar', compact('venta')); + } + public static function abonando() + { + $id = get('venta'); + $venta = \Model::factory(Venta::class)->findOne($id); + $valor = str_replace(',', '.', str_replace('.', '', post('valor'))); + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + + $pago = $venta->credito()->pago(); + if ($pago->valor != $valor) { + $pago->valor = $valor; + } + + $estado = \Model::factory(EstadoPago::class)->create(); + $estado->pago = $pago->id; + $estado->fecha = $f->format('Y-m-d'); + $estado->estado = 2; + + $estado->save(); + + if ($pago->is_dirty('valor')) { + $pago->save(); + } + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function show() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + return view('ventas.creditos.show', compact('venta')); + } + public static function edit() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + return view('ventas.creditos.edit', compact('venta')); + } + public static function editado() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + $pago = $venta->credito()->pago(); + + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $uf = uf($f); + $banco = model(Banco::class)->where('nombre', post('banco'))->findOne(); + $valor = correctNumber(post('valor')) * $uf->uf->value; + + $fields = ['valor', 'uf', 'fecha', 'banco']; + $data = ['valor' => $valor, 'uf' => $uf->uf->value, 'fecha' => $f->format('Y-m-d'), 'banco' => $banco->id]; + + $change = false; + foreach ($fields as $field) { + if ($pago->$field != $data[$field]) { + $change = true; + $pago->$field = $data[$field]; + if ($field == 'fecha') { + $eps = $pago->estados(); + foreach ($eps as $ep) { + if ($ep->estado == 0) { + $ep->fecha = $data[$field]; + $ep->save(); + break; + } + } + } + } + } + + if ($change) { + $pago->save(); + } + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function remove() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + $pago = $venta->credito()->pago(); + $f = Carbon::today(config('app.timezone')); + + $data = [ + 'pago' => $pago->id, + 'estado' => -3, + 'fecha' => $f->format('Y-m-d') + ]; + $estado = model(EstadoPago::class)->create($data); + $estado->save(); + $venta->credito = 0; + $venta->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function pendientes() + { + $creditos = model(Credito::class) + ->select('credito.*') + ->join('venta', ['venta.credito', '=', 'credito.id']) + ->join('pago', ['pago.id', '=', 'credito.pago']) + ->rawJoin('JOIN (SELECT ep.* FROM (SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago ep ON ep.id = e0.id)', ['estado_pago.pago', '=', 'pago.id'], 'estado_pago') + ->whereLt('estado_pago.estado', 2) + ->where('venta.estado', 1) + ->orderByAsc('estado_pago.fecha') + ->findMany(); + return view('ventas.creditos.pendientes', compact('creditos')); + } +} +?> diff --git a/app_old/resources/less/Controller/Cuotas.php b/app_old/resources/less/Controller/Cuotas.php new file mode 100644 index 0000000..4d457ba --- /dev/null +++ b/app_old/resources/less/Controller/Cuotas.php @@ -0,0 +1,230 @@ +findOne($id); + + return view('ventas.pies.cuotas.show', compact('cuota')); + } + public static function edit() + { + $id = get('cuota'); + $cuota = \Model::factory(Cuota::class)->findOne($id); + return view('ventas.pies.cuotas.edit', compact('cuota')); + } + public static function editar() + { + $id = get('cuota'); + $cuota = \Model::factory(Cuota::class)->findOne($id); + + $cuota->numero = post('numero'); + $cuota->{'valor_$'} = post('valor'); + $banco = \Model::factory(\Incoviba\old\Common\Banco::class)->where('nombre', post('banco'))->findOne(); + if ($banco) { + $cuota->banco = $banco->id; + } else { + $cuota->banco = 0; + } + $f = \Carbon\Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $cuota->fecha = $f->format('Y-m-d'); + $pago = $cuota->pago(); + $pago->valor = post('valor'); + $pago->banco = $banco->id; + $pago->identificador = post('identificador'); + $pago->fecha = $f->format('Y-m-d'); + $uf = uf($f); + if ($uf->total > 0) { + $pago->uf = $uf->uf->value; + } else { + $pago->uf = 0; + } + + $pago->save(); + $cuota->save(); + header('Location: ' . url('', ['p' => 'pies', 'a' => 'resumen', 'pie' => $cuota->pie()->id])); + } + public static function edited() + { + $id = get('cuota'); + $cuota = \Model::factory(Cuota::class)->findOne($id); + $pago = $cuota->pago(); + foreach ($_POST as $key => $value) { + $pago->$key = $value; + } + $pago->save(); + } + public static function pendientes() + { + $f = \Carbon\Carbon::today(config('app.timezone')); + $cuotas = \Model::factory(Cuota::class) + ->select('cuota.*') + ->join('pago', ['pago.id', '=', 'cuota.pago']) + ->join('venta', ['venta.pie', '=', 'cuota.pie']) + ->raw_join('JOIN (SELECT e1.* FROM (SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago e1 ON e1.id = e0.id)', ['ep.pago', '=', 'pago.id'], 'ep') + ->where('ep.estado', 0) + ->where('venta.estado', 1) + ->whereLte('pago.fecha', $f->format('Y-m-d')) + ->order_by_asc('pago.fecha') + ->findMany(); + $sum = 0; + if (count($cuotas) > 0) { + $sum = array_reduce($cuotas, function($carry, $item) { + $carry += $item->pago()->valor; + return $carry; + }); + } + setlocale(LC_TIME, 'es'); + return view('ventas.pies.cuotas.pendientes', compact('cuotas', 'sum')); + } + public static function depositar() + { + $id = post('cuota'); + $cuota = \Model::factory(Cuota::class)->findOne($id); + if ($cuota->pago()->estado()->estado == 1) { + return 'ok'; + } + $estado = \Model::factory(EstadoPago::class)->create(); + $estado->pago = $cuota->pago()->id; + $estado->estado = 1; + $f = Carbon::parse(post('fecha'), config('app.timezone')); + $estado->fecha = $f->format('Y-m-d'); + $estado->save(); + return 'ok'; + } + public static function remove() + { + $id = get('cuota'); + $cuota = \Model::factory(Cuota::class)->findOne($id); + + $estado = \Model::factory(EstadoPago::class)->create(); + $estado->pago = $cuota->pago()->id; + $estado->estado = -3; + $f = Carbon::today(config('app.timezone')); + $estado->fecha = $f->format('Y-m-d'); + $estado->save(); + header('Location: ' . url('', ['p' => 'pies', 'a' => 'resumen', 'pie' => $cuota->pie()->id])); + } + public static function para_abonar() + { + $cuotas = \Model::factory(Cuota::class) + ->select('cuota.*') + ->join('pago', ['pago.id', '=', 'cuota.pago']) + ->join('venta', ['venta.pie', '=', 'cuota.pie']) + ->raw_join('JOIN (SELECT e1.* FROM (SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago e1 ON e1.id = e0.id)', ['ep.pago', '=', 'pago.id'], 'ep') + ->where('ep.estado', 1) + ->where('venta.estado', 1) + ->order_by_asc('ep.fecha') + ->findMany(); + $ini = get('start'); + if ($ini == null) { + $ini = 0; + } + $n = get('step'); + if ($n == 0) { + $n = 30; + } + $total = count($cuotas); + $cuotas = array_slice($cuotas, $ini, $n); + $pages = ceil($total / $n); + $current = ($ini + $n) / $n; + return view('ventas.pies.cuotas.abonar', compact('cuotas', 'total', 'pages', 'current')); + } + public static function abonar() + { + $id = post('cuota'); + $cuota = \Model::factory(Cuota::class)->findOne($id); + if ($cuota->pago()->estado()->estado == 2) { + return 'ok'; + } + $estado = \Model::factory(EstadoPago::class)->create(); + $estado->pago = $cuota->pago()->id; + $estado->estado = 2; + $f = Carbon::parse(post('fecha'), config('app.timezone')); + $estado->fecha = $f->format('Y-m-d'); + $estado->save(); + return 'ok'; + } + public static function rebotar() + { + $id = post('cuota'); + $cuota = \Model::factory(Cuota::class)->findOne($id); + if ($cuota->pago()->estado()->estado == -1) { + return 'ok'; + } + $estado = \Model::factory(EstadoPago::class)->create(); + $estado->pago = $cuota->pago()->id; + $estado->estado = -1; + $f = Carbon::parse(post('fecha'), config('app.timezone')); + $estado->fecha = $f->format('Y-m-d'); + $estado->save(); + return 'ok'; + } + public static function add() + { + $id = get('pie'); + $pie = \Model::factory(Pie::class)->findOne($id); + return view('ventas.pies.cuotas.add', compact('pie')); + } + public static function agregar() + { + $id = get('pie'); + $pie = \Model::factory(Pie::class)->findOne($id); + + $cant = $pie->cuotas - count($pie->cuotas()); + for ($i = 0; $i < $cant; $i ++) { + if (trim(post('valor' . $i)) == '') { + continue; + } + $banco = \Model::factory(Banco::class)->where('nombre', post('banco' . $i))->findOne(); + $f = Carbon::createFromDate(post('year' . $i), post('month' . $i), post('day' . $i), config('app.timezone')); + $uf = uf($f); + $valor = correctNumber(post('valor' . $i)); + + $pago = \Model::factory(Pago::class)->create(); + $pago->banco = $banco->id; + $pago->fecha = $f->format('Y-m-d'); + if ($uf and $uf->total > 0) { + $pago->uf = $uf->uf->value; + } else { + $pago->uf = 0; + } + $pago->tipo = 1; + $pago->valor = $valor; + $pago->identificador = post('identificador' . $i); + + $cuota = \Model::factory(Cuota::class)->create(); + $cuota->pie = $pie->id; + $cuota->fecha = $pago->fecha; + $cuota->{'valor_$'} = $pago->valor; + $cuota->estado = 0; + $cuota->banco = $pago->banco; + $cuota->uf = $pago->uf; + $cuota->numero = post('numero' . $i); + + $pago->new(); + + $cuota->pago = $pago->id; + $cuota->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $pie->venta()->id])); + } + } +} +?> diff --git a/app_old/resources/less/Controller/Devoluciones.php b/app_old/resources/less/Controller/Devoluciones.php new file mode 100644 index 0000000..8d9c41c --- /dev/null +++ b/app_old/resources/less/Controller/Devoluciones.php @@ -0,0 +1,19 @@ +findOne($id); + + return view('print.devolucion', compact('venta')); + } +} +?> diff --git a/app_old/resources/less/Controller/Escrituras.php b/app_old/resources/less/Controller/Escrituras.php new file mode 100644 index 0000000..f2cb056 --- /dev/null +++ b/app_old/resources/less/Controller/Escrituras.php @@ -0,0 +1,212 @@ +findOne($id); + return view('ventas.escrituras.add', compact('venta')); + } + public static function agregar() + { + $id = get('venta'); + $venta = \Model::factory(Venta::class)->findOne($id); + + $f = Carbon::createFromDate(post('escritura_year'), post('escritura_month'), post('escritura_day'), config('app.timezone')); + $venta->escriturado = $f->format('Y-m-d'); + + if (post('valor_reajuste')) { + $reajuste = \Model::factory(Pago::class)->create(); + $reajuste->valor = correctNumber(post('valor_reajuste')); + $fp = Carbon::createFromDate(post('reajuste_year'), post('reajuste_month'), post('reajuste_day'), config('app.timezone')); + $reajuste->fecha = $fp->format('Y-m-d'); + $reajuste->uf = (float) uf($fp)->uf->value; + $reajuste->newPagado(); + + $pie = $venta->pie(); + $pie->reajuste = $reajuste->id; + $pie->save(); + } + if (post('escritura_valor') or post('escritura_valor_uf')) { + $pago = \Model::factory(Pago::class)->create(); + $fp = Carbon::createFromDate(post('pago_escritura_year'), post('pago_escritura_month'), post('pago_escritura_day'), config('app.timezone')); + $pago->fecha = $fp->format('Y-m-d'); + $pago->uf = (float) uf($fp)->uf->value; + if (post('escritura_valor')) { + $pago->valor = correctNumber(post('escritura_valor')); + $pago->newPagado(); + } else { + $pago->valor = correctNumber(post('escritura_valor_uf')) * $pago->uf; + $pago->new(); + } + + $escritura = \Model::factory(Escritura::class)->create(); + $escritura->pago = $pago->id; + $escritura->valor = $pago->valor('uf'); + $escritura->fecha = $pago->fecha; + $escritura->save(); + + $venta->escritura = $escritura->id; + } + if (post('subsidio_ahorrado') or post('subsidio_valor')) { + $total = post('subsidio_ahorrado') + post('subsidio_valor'); + $subsidio = \Model::factory(Subsidio::class)->create(); + $pago = \Model::factory(Pago::class)->create(); + $pago->fecha = $f->format('Y-m-d'); + $pago->uf = (float) uf($f)->uf->value; + $pago->valor = correctNumber(post('subsidio_ahorrado')) * $pago->uf; + $pago->new(); + $subsidio->pago = $pago->id; + $pago = \Model::factory(Pago::class)->create(); + $pago->fecha = $f->format('Y-m-d'); + $pago->uf = (float) uf($f)->uf->value; + $pago->valor = correctNumber(post('subsidio_valor')) * $pago->uf; + $pago->new(); + $subsidio->subsidio = $pago->id; + $subsidio->save(); + + $venta->subsidio = $subsidio->id; + } + if (post('credito_valor')) { + $pago = \Model::factory(Pago::class)->create(); + $pago->fecha = $f->format('Y-m-d'); + $pago->uf = (float) uf($f)->uf->value; + $valor = post('credito_valor'); + if (strpos($valor, ',') !== false) { + $valor = correctNumber($valor); + } + $pago->valor = $valor * $pago->uf; + $banco = \Model::factory(Banco::class)->where('nombre', post('credito_banco'))->findOne(); + $pago->banco = $banco->id; + $pago->new(); + + $credito = \Model::factory(Credito::class)->create(); + $credito->pago = $pago->id; + $credito->save(); + + $venta->credito = $credito->id; + } elseif (post('credito_banco')) { + $pago = $venta->credito()->pago(); + $banco = \Model::factory(Banco::class)->where('nombre', post('credito_banco'))->findOne(); + $pago->banco = $banco->id; + $pago->save(); + } + + $tipo = \Model::factory(TipoEstadoVenta::class)->where('descripcion', 'escriturando')->findOne(); + $data = [ + 'venta' => $venta->id, + 'estado' => $tipo->id, + 'fecha' => $venta->escriturado + ]; + $estado = \Model::factory(EstadoVenta::class)->create($data); + $estado->save(); + $venta->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function edit() + { + $id = get('venta'); + $venta = \Model::factory(Venta::class)->findOne($id); + echo view('ventas.escrituras.edit', compact('venta')); + } + public static function editar() + { + $id = get('venta'); + $venta = \Model::factory(Venta::class)->findOne($id); + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $uf = uf($f); + + $valor = correctNumber(post('valor')); + if ($valor == '') { + $valor_uf = correctNumber(post('valor_uf')); + $valor = $valor_uf * $uf->uf->value; + } + $pago = $venta->escritura()->pago(); + if ($pago->valor != $valor) { + $pago->valor = $valor; + } + if ($pago->fecha != $f->format('Y-m-d')) { + $pago->fecha = $f->format('Y-m-d'); + $pago->uf = $uf->uf->value; + } + + $pago->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function informe() + { + $id = get('venta'); + $venta = \Model::factory(Venta::class)->findOne($id); + return view('ventas.escrituras.informe', compact('venta')); + } + public static function pagar() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + return view('ventas.escrituras.pagar', compact('venta')); + } + public static function pagado() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + + $data = [ + 'pago' => $venta->escritura()->pago()->id, + 'fecha' => $f->format('Y-m-d'), + 'estado' => 1 + ]; + $estado = model(EstadoPago::class)->create($data); + $estado->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function abonar() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + return view('ventas.escrituras.abonar', compact('venta')); + } + public static function abonado() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + + $data = [ + 'pago' => $venta->escritura()->pago()->id, + 'fecha' => $f->format('Y-m-d'), + 'estado' => 2 + ]; + $estado = model(EstadoPago::class)->create($data); + $estado->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } +} +?> diff --git a/app_old/resources/less/Controller/FormaPago.php b/app_old/resources/less/Controller/FormaPago.php new file mode 100644 index 0000000..6ccc7b3 --- /dev/null +++ b/app_old/resources/less/Controller/FormaPago.php @@ -0,0 +1,98 @@ +findOne($id); + + return view('ventas.forma_pago.edit', compact('venta')); + } + public static function editar() + { + d(post()); + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + $valor = correctNumber(post('valor_pie')); + $cuotas = post('cuotas_pie'); + if ($venta->pie != 0) { + $pie = $venta->pie(); + $changed = false; + if ($pie->valor != $valor) { + $pie->valor = $valor; + $changed = true; + } + if ($pie->cuotas != $cuotas) { + $pie->cuotas = $cuotas; + $changed = true; + } + if ($changed) { + d($pie); + } + + $valor = correctNumber(post('valor_reajuste')); + $f = Carbon::createFromDate(post('year_reajuste'), post('month_reajuste'), post('day_reajuste'), config('app.timezone')); + $uf = uf($f); + $reajuste = $pie->reajuste(); + $changed = false; + if ($reajuste->valor != $valor) { + $reajuste->valor = $valor; + $changed = true; + } + if ($reajuste->fecha != $f->format('Y-m-d')) { + $reajuste->fecha = $f->format('Y-m-d'); + $reajuste->uf = $uf->uf->value; + $changed = true; + } + if ($changed) { + d($reajuste); + } + } elseif ($valor != '') { + $f = Carbon::parse($venta->fecha, config('app.timezone')); + $uf = uf($f); + $data = [ + 'valor' => $valor, + 'cuotas' => $cuotas, + 'uf' => $uf->uf->value, + 'fecha' => $f->format('Y-m-d') + ]; + $pie = model(Pie::class)->create($data); + d($pie); + } + + $valor = correctNumber(post('valor_escritura')); + $f = Carbon::createFromDate(post('year_escritura'), post('month_escritura'), post('day_escritura'), config('app.timezone')); + if ($venta->escritura != 0) { + $escritura = $venta->escritura(); + d($escritura); + } elseif ($valor != '') { + $data = [ + 'valor' => $valor, + 'fecha' => $f->format('Y-m-d'), + 'uf' => $uf->uf->value, + 'tipo' => 7 + ]; + $pago = model(Pago::class)->create($data); + $pago->newPagado(); + $data['pago'] = $pago->id; + unset($data['tipo']); + $escritura = model(Escritura::class)->create($data); + $escritura->save(); + $venta->escritura = $escritura->id; + $venta->save(); + } + } +} +?> diff --git a/resources/less/Controller/Informes.php b/app_old/resources/less/Controller/Informes.php similarity index 99% rename from resources/less/Controller/Informes.php rename to app_old/resources/less/Controller/Informes.php index 965a88b..e93d4c8 100644 --- a/resources/less/Controller/Informes.php +++ b/app_old/resources/less/Controller/Informes.php @@ -1,17 +1,16 @@ orderByAsc('abreviacion')->findMany(); + return view('inmobiliarias.list', compact('inmobiliarias')); + } + public static function show() + { + $rut = get('rut'); + $inmobiliaria = model(Inmobiliaria::class)->findOne($rut); + return view('inmobiliarias.show', compact('inmobiliaria')); + } + public static function add() + { + $sociedades = model(TipoSociedad::class)->findMany(); + return view('inmobiliarias.add', compact('sociedades')); + } + public static function agregar() + { + list($rut, $dv) = explode('-', str_replace('.', '', post('rut'))); + + $inmobiliaria = model(Inmobiliaria::class)->findOne($rut); + if ($inmobiliaria) { + header('Location: ' . url('', ['p' => 'inmobiliarias', 'a' => 'show', 'rut' => $inmobiliaria->rut])); + die(); + } + + $inmobiliaria = model(Inmobiliaria::class)->create(); + $inmobiliaria->rut = $rut; + $inmobiliaria->dv = $dv; + $inmobiliaria->razon = post('razon'); + $inmobiliaria->abreviacion = post('abrev'); + $inmobiliaria->sociedad = post('sociedad'); + + $inmobiliaria->save(); + header('Location: ' . url('', ['p' => 'inmobiliarias', 'a' => 'show', 'rut' => $inmobiliaria->rut])); + } + public static function edit() + { + $sociedades = model(TipoSociedad::class)->findMany(); + $rut = get('rut'); + $inmobiliaria = model(Inmobiliaria::class)->findOne($rut); + $bancos = model(Banco::class)->findMany(); + usort($bancos, function($a, $b) { + return strcmp($a->nombre, $b->nombre); + }); + return view('inmobiliarias.edit', compact('inmobiliaria', 'bancos', 'sociedades')); + } + public static function do_edit() + { + $rut = get('rut'); + $inmobiliaria = model(Inmobiliaria::class)->findOne($rut); + foreach (post() as $field => $value) { + if ($value != '' and $inmobiliaria->{$field} != $value) { + $inmobiliaria->{$field} = $value; + } + } + + $inmobiliaria->save(); + header('Location: ' . nUrl('inmobiliarias', 'show', ['rut' => $inmobiliaria->rut])); + } +} +?> diff --git a/app_old/resources/less/Controller/Operadores.php b/app_old/resources/less/Controller/Operadores.php new file mode 100644 index 0000000..765ba2a --- /dev/null +++ b/app_old/resources/less/Controller/Operadores.php @@ -0,0 +1,47 @@ +findOne(get('proyecto')); + $operadores = model(Agente::class) + ->select('agente.*') + ->join('agente_tipo', ['agente_tipo.agente', '=', 'agente.id']) + ->join('tipo_agente', ['tipo_agente.id', '=', 'agente_tipo.tipo']) + ->where('tipo_agente.descripcion', 'operador') + ->orderByAsc('agente.abreviacion') + ->findMany(); + $vigentes = array_map(function($item) { + return $item->agente()->agente(); + }, $proyecto->operadoresVigentes()); + echo view('proyectos.operadores.add', compact('proyecto', 'operadores', 'vigentes')); + } + public static function add() + { + $proyecto = model(Proyecto::class)->findOne(get('proyecto')); + $fecha = Carbon::today(config('app.timezone')); + foreach (post('operadores') as $op) { + $operador = model(Agente::class)->findOne($op); + $at = $operador->tipos(19); + $data = [ + 'proyecto' => $proyecto->id, + 'agente' => $at->id, + 'fecha' => $fecha->format('Y-m-d'), + 'comision' => 2 + ]; + $pa = model(ProyectoAgente::class)->create($data); + $pa->new(); + } + header('Location: ' . nUrl('proyectos', 'show', ['proyecto' => $proyecto->id])); + } +} diff --git a/app_old/resources/less/Controller/Other.php b/app_old/resources/less/Controller/Other.php new file mode 100644 index 0000000..eb90f31 --- /dev/null +++ b/app_old/resources/less/Controller/Other.php @@ -0,0 +1,71 @@ +create(); + $unidad = \Model::factory(Unidad::class)->where('descripcion', $info[0])->where('proyecto', post('proyecto'))->find_one(); + if (!$unidad->venta()->find_one()) { + echo 'x'; + continue; + } + $venta = $unidad->venta()->find_one(); + $entrega->fecha = \Carbon\Carbon::parse($info[1])->format('Y-m-d'); + if ($venta->entrega == '0') { + $entrega->save(); + $venta->entrega = $entrega->id; + $venta->save(); + echo '.'; + } else { + echo 'x'; + } + } + } else { + $proyectos = \Model::factory(Proyecto::class)->order_by_asc('descripcion')->find_many(); + return view('other.entregar_multiple', compact('proyectos')); + } + } + public static function capacidades() + { + $capacidades = []; + $controllers = glob(config('locations.app') . '/Controller/*.php'); + foreach ($controllers as $controller) { + if (basename($controller) == 'Admin.php' or basename($controller) == 'Other.php') { + continue; + } + $class = Stringy::create($controller)->replace(config('locations.app'), '/App')->replace('.php', '')->replace('/', '\\')->__toString(); + $ref = new \ReflectionClass($class); + $static = $ref->getMethods(\ReflectionMethod::IS_STATIC && \ReflectionMethod::IS_PUBLIC); + foreach ($static as $method) { + if ($method->name == 'setDefault' or $method->name == 'index') { + continue; + } + $capacidades []= $method; + } + } + return view('other.capacidades', compact('capacidades')); + } +} +?> \ No newline at end of file diff --git a/app_old/resources/less/Controller/Pagares.php b/app_old/resources/less/Controller/Pagares.php new file mode 100644 index 0000000..f05b24e --- /dev/null +++ b/app_old/resources/less/Controller/Pagares.php @@ -0,0 +1,271 @@ +findOne(get('pagare')); + return view('proyectos.pagares.show', compact('pagare')); + } + public static function add() + { + $proyecto = model(Proyecto::class)->findOne(get('proyecto')); + return view('proyectos.pagares.add', compact('proyecto')); + } + public static function do_add() + { + $proyecto = model(Proyecto::class)->findOne(get('proyecto')); + $data = post(); + + $data['id'] = $data['numero']; + unset($data['numero']); + $data['proyecto'] = $proyecto->id; + $moneda = model(TipoMonedaPagare::class)->where('descripcion', $data['moneda'])->findOne(); + $data['moneda'] = $moneda->id; + + $fecha = ['year', 'month', 'day']; + $fecha_arr = array_filter($data, function($item) use ($fecha) { + return (array_search($item, $fecha) !== false); + }, \ARRAY_FILTER_USE_KEY); + uksort($fecha_arr, function($a, $b) use ($fecha) { + return array_search($a, $fecha) - array_search($b, $fecha); + }); + foreach ($fecha as $f) { + unset($data[$f]); + } + array_walk($fecha_arr, function(&$item) { + if (strlen($item) < 4) { + $item = str_pad($item, 2, '0', \STR_PAD_LEFT); + } + }); + $data['fecha'] = implode('-', $fecha_arr); + + foreach ($fecha as &$key) { + $key .= '_banco'; + } + $fecha_arr = array_filter($data, function($item) use ($fecha) { + return (array_search($item, $fecha) !== false); + }, \ARRAY_FILTER_USE_KEY); + uksort($fecha_arr, function($a, $b) use ($fecha) { + return array_search($a, $fecha) - array_search($b, $fecha); + }); + foreach ($fecha as $f) { + unset($data[$f]); + } + array_walk($fecha_arr, function(&$item) { + if (strlen($item) < 4) { + $item = str_pad($item, 2, '0', \STR_PAD_LEFT); + } + }); + $data['fecha_banco'] = implode('-', $fecha_arr); + + $data['abonado'] = (int) $data['abonado']; + if ($data['abonado'] == 0) { + $data['fecha'] = '0000-00-00'; + } + + $pagare = model(Pagare::class)->create($data); + $pagare->save(); + header('Location: ' . nUrl('pagares', 'show', ['pagare' => $pagare->id])); + } + public static function edit() + { + $pagare = model(Pagare::class)->findOne(get('pagare')); + return view('proyectos.pagares.edit', compact('pagare')); + } + public static function do_edit() + { + $pagare = model(Pagare::class)->findOne(get('pagare')); + + $data = post(); + if ($pagare->id != $data['numero']) { + foreach ($pagare->renovaciones() as $renovacion) { + $renovacion->pagare = $data['numero']; + $renovacion->save(); + } + $pagare->id = $data['numero']; + $changed = true; + } + unset($data['numero']); + $moneda = model(TipoMonedaPagare::class)->where('descripcion', $data['moneda'])->findOne(); + $data['moneda'] = $moneda->id; + $fecha = ['year', 'month', 'day']; + $fecha_arr = array_filter($data, function($item) use ($fecha) { + return (array_search($item, $fecha) !== false); + }, \ARRAY_FILTER_USE_KEY); + uksort($fecha_arr, function($a, $b) use ($fecha) { + return array_search($a, $fecha) - array_search($b, $fecha); + }); + foreach ($fecha as $f) { + unset($data[$f]); + } + array_walk($fecha_arr, function(&$item) { + if (strlen($item) < 4) { + $item = str_pad($item, 2, '0', \STR_PAD_LEFT); + } + }); + $data['fecha'] = implode('-', $fecha_arr); + + foreach ($fecha as &$key) { + $key .= '_banco'; + } + $fecha_arr = array_filter($data, function($item) use ($fecha) { + return (array_search($item, $fecha) !== false); + }, \ARRAY_FILTER_USE_KEY); + uksort($fecha_arr, function($a, $b) use ($fecha) { + return array_search($a, $fecha) - array_search($b, $fecha); + }); + foreach ($fecha as $f) { + unset($data[$f]); + } + array_walk($fecha_arr, function(&$item) { + if (strlen($item) < 4) { + $item = str_pad($item, 2, '0', \STR_PAD_LEFT); + } + }); + $data['fecha_banco'] = implode('-', $fecha_arr); + + $data['abonado'] = (int) $data['abonado']; + if ($data['abonado'] == 0) { + $data['fecha'] = '0000-00-00'; + } + + $changed = false; + foreach ($data as $k => $v) { + if ($pagare->$k != $v) { + $pagare->$k = $v; + $changed = true; + if (strpos($k, 'fecha') !== false) { + $pagare->uf = 0; + } + } + } + + if ($changed) { + $pagare->save(); + } + header('Location: ' . nUrl('pagares', 'show', ['pagare' => $pagare->id])); + } + public static function edit_renovacion() + { + $renovacion = model(RenovacionPagare::class)->findOne(get('renovacion')); + return view('proyectos.pagares.edit_renovacion', compact('renovacion')); + } + public static function do_edit_renovacion() + { + $renovacion = model(RenovacionPagare::class)->findOne(get('renovacion')); + + $data = post(); + $fecha = ['year', 'month', 'day']; + $fecha_arr = array_filter($data, function($item) use ($fecha) { + return (array_search($item, $fecha) !== false); + }, \ARRAY_FILTER_USE_KEY); + uksort($fecha_arr, function($a, $b) use ($fecha) { + return array_search($a, $fecha) - array_search($b, $fecha); + }); + foreach ($fecha as $f) { + unset($data[$f]); + } + array_walk($fecha_arr, function(&$item) { + if (strlen($item) < 4) { + $item = str_pad($item, 2, '0', \STR_PAD_LEFT); + } + }); + $data['fecha'] = implode('-', $fecha_arr); + + foreach ($fecha as &$key) { + $key .= '_banco'; + } + $fecha_arr = array_filter($data, function($item) use ($fecha) { + return (array_search($item, $fecha) !== false); + }, \ARRAY_FILTER_USE_KEY); + uksort($fecha_arr, function($a, $b) use ($fecha) { + return array_search($a, $fecha) - array_search($b, $fecha); + }); + foreach ($fecha as $f) { + unset($data[$f]); + } + array_walk($fecha_arr, function(&$item) { + if (strlen($item) < 4) { + $item = str_pad($item, 2, '0', \STR_PAD_LEFT); + } + }); + $data['fecha_banco'] = implode('-', $fecha_arr); + + $changed = false; + foreach ($data as $k => $v) { + if ($renovacion->$k != $v) { + $renovacion->$k = $v; + $changed = true; + if (strpos($k, 'fecha') !== false) { + $renovacion->uf = 0; + } + } + } + if ($changed) { + $renovacion->save(); + } + header('Location: ' . nUrl('pagares', 'show', ['pagare' => $renovacion->pagare])); + } + public static function add_renovacion() + { + $pagare = model(Pagare::class)->findOne(get('pagare')); + return view('proyectos.pagares.add_renovacion', compact('pagare')); + } + public static function do_add_renovacion() + { + $pagare = model(Pagare::class)->findOne(get('pagare')); + $data = post(); + + $data['pagare'] = $pagare->id; + $fecha = ['year', 'month', 'day']; + $fecha_arr = array_filter($data, function($item) use ($fecha) { + return (array_search($item, $fecha) !== false); + }, \ARRAY_FILTER_USE_KEY); + uksort($fecha_arr, function($a, $b) use ($fecha) { + return array_search($a, $fecha) - array_search($b, $fecha); + }); + foreach ($fecha as $f) { + unset($data[$f]); + } + array_walk($fecha_arr, function(&$item) { + if (strlen($item) < 4) { + $item = str_pad($item, 2, '0', \STR_PAD_LEFT); + } + }); + $data['fecha'] = implode('-', $fecha_arr); + + foreach ($fecha as &$key) { + $key .= '_banco'; + } + $fecha_arr = array_filter($data, function($item) use ($fecha) { + return (array_search($item, $fecha) !== false); + }, \ARRAY_FILTER_USE_KEY); + uksort($fecha_arr, function($a, $b) use ($fecha) { + return array_search($a, $fecha) - array_search($b, $fecha); + }); + foreach ($fecha as $f) { + unset($data[$f]); + } + array_walk($fecha_arr, function(&$item) { + if (strlen($item) < 4) { + $item = str_pad($item, 2, '0', \STR_PAD_LEFT); + } + }); + $data['fecha_banco'] = implode('-', $fecha_arr); + + $renovacion = model(RenovacionPagare::class)->create($data); + $renovacion->save(); + + header('Location: ' . nUrl('pagares', 'show', ['pagare' => $renovacion->pagare])); + } +} diff --git a/app_old/resources/less/Controller/Pagos.php b/app_old/resources/less/Controller/Pagos.php new file mode 100644 index 0000000..f279b9e --- /dev/null +++ b/app_old/resources/less/Controller/Pagos.php @@ -0,0 +1,358 @@ +findOne($id); + $tipos = model(TipoPago::class)->orderByAsc('descripcion')->findMany(); + $estados = model(TipoEstadoPago::class)->orderByAsc('descripcion')->findMany(); + + return view('ventas.pagos.edit', compact('pago', 'asociado', 'id_asociado', 'tipos', 'estados')); + } + public static function editar() + { + $id = get('pago'); + $pago = model(Pago::class)->findOne($id); + + $fp = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $tipo = model(TipoPago::class)->findOne(post('tipo')); + $valor = correctNumber(post('valor')); + $banco = model(Banco::class)->where('nombre', post('banco'))->findOne(); + + $fe = Carbon::createFromDate(post('yearestado'), post('monthestado'), post('dayestado'), config('app.timezone')); + $estado = model(TipoEstadoPago::class)->findOne(post('estado')); + $uf = uf($fe); + + $est = $pago->estado(); + if ($est->fecha != $fe->format('Y-m-d')) { + $est->fecha = $fe->format('Y-m-d'); + $pago->uf = $uf->uf->value; + } + if ($est->estado != $estado->id) { + $est->estado = $estado->id; + } + + if ($pago->fecha != $fp->format('Y-m-d')) { + $pago->fecha = $fp->format('Y-m-d'); + } + if ($pago->tipo != $tipo->id) { + $pago->tipo = $tipo->id; + } + if ($pago->valor != $valor) { + $pago->valor = $valor; + } + if ($pago->identificador != post('identificador')) { + $pago->identificador = post('identificador'); + } + if ($pago->pagador != post('pagador')) { + $pago->pagador = post('pagador'); + } + if ($pago->banco != $banco->id) { + $pago->banco = $banco->id; + } + + $est->save(); + $pago->save(); + header('Location: ' . url('', ['p' => get('asociado') . 's', 'a' => 'show', get('asociado') => get(get('asociado'))])); + } + public static function pendientes() + { + $ventas = model(Venta::class) + ->select('venta.*') + ->rawJoin('JOIN (SELECT e1.* FROM estado_venta e1 JOIN (SELECT venta, MAX(id) AS id FROM estado_venta GROUP BY venta) e0 ON e0.id = e1.id)', ['ev.venta', '=', 'venta.id'], 'ev') + ->join('tipo_estado_venta', ['te.id', '=', 'ev.estado'], 'te') + ->join('propiedad', ['propiedad.id', '=', 'venta.propiedad']) + ->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal']) + ->join('proyecto', ['proyecto.id', '=', 'unidad.proyecto']) + ->where('te.activa', 1) + ->orderByAsc('proyecto.descripcion') + ->orderByExpr('LPAD(unidad.descripcion, 4, "0")') + ->findMany(); + $n = 30; + $mod = floor(count($ventas) / $n); + $i_rest = count($ventas) - count($ventas) % $mod + 1; + $rest = count($ventas) - $i_rest; + $lots = (object) ['size' => $mod, 'N' => $n, 'rest' => (object) [ + 'size' => $rest, + 'start' => $i_rest + ] + ]; + return view('ventas.pagos.pendientes', compact('ventas', 'lots')); + } + public static function para_pendientes() + { + $timezone = config('app.timezone'); + $today = Carbon::today($timezone); + $days = []; + $fechas = []; + for ($i = $today->copy()->subDays(15); $i <= $today->copy()->addDays(15); $i = $i->copy()->addDay()) { + $days []= $i->format('Y-m-d'); + $fechas []= $i->format('d-m-Y'); + } + $pagos_pendientes = model(Pago::class) + ->select('estado_pago.fecha') + ->selectExpr('COUNT(pago.id)', 'cantidad') + ->join('cuota', ['cuota.pago', '=', 'pago.id']) + ->join('venta', ['venta.pie', '=', 'cuota.pie']) + ->filter('filterEstado') + ->where('estado_pago.estado', 0) + ->where('venta.estado', 1) + ->whereGte('estado_pago.fecha', $today->copy()->subDays(15)->format('Y-m-d')) + ->whereLte('estado_pago.fecha', $today->copy()->addDays(15)->format('Y-m-d')) + ->orderByAsc('estado_pago.fecha') + ->groupBy('estado_pago.fecha') + ->findMany(); + $valores = array_fill(0, count($days), 0); + $anteriores = model(Pago::class) + ->join('cuota', ['cuota.pago', '=', 'pago.id']) + ->join('venta', ['venta.pie', '=', 'cuota.pie']) + ->filter('filterEstado') + ->where('estado_pago.estado', 0) + ->where('venta.estado', 1) + ->whereLt('estado_pago.fecha', $today->copy()->subDays(15)->format('Y-m-d')) + ->count(); + foreach ($pagos_pendientes as $pago) { + $valores[array_search($pago->fecha()->format('Y-m-d'), $days)] = $pago->cantidad; + } + $acum = []; + $sum = 0; + foreach ($valores as $valor) { + $sum += $valor; + $acum []= $sum; + } + $t = array_search($today->format('Y-m-d'), $days); + $color = array_merge( + array_fill(0, $t, 'red'), + ['blue'], + array_fill(0, count($days) - $t, 'green') + ); + $pagos = ['data' => $acum, 'historico' => $anteriores, 'backgroundColor' => $color]; + $abonos_pendientes = model(Pago::class) + ->select('estado_pago.fecha') + ->selectExpr('COUNT(pago.id)', 'cantidad') + ->filter('filterEstado') + ->where('estado_pago.estado', 1) + ->whereGte('estado_pago.fecha', $today->copy()->subDays(15)->format('Y-m-d')) + ->whereLt('estado_pago.fecha', $today->copy()->format('Y-m-d')) + ->orderByAsc('estado_pago.fecha') + ->groupBy('estado_pago.fecha') + ->findMany(); + $anteriores = model(Pago::class) + ->join('cuota', ['cuota.pago', '=', 'pago.id']) + ->join('venta', ['venta.pie', '=', 'cuota.pie']) + ->filter('filterEstado') + ->where('estado_pago.estado', 1) + ->where('venta.estado', 1) + ->whereLt('estado_pago.fecha', $today->copy()->subDays(15)->format('Y-m-d')) + ->count(); + $valores = array_fill(0, count($days), 0); + foreach ($abonos_pendientes as $pago) { + $valores[array_search($pago->fecha()->format('Y-m-d'), $days)] = $pago->cantidad; + } + $acum = []; + $sum = 0; + foreach ($valores as $valor) { + $sum += $valor; + $acum []= $sum; + } + $color = array_fill(0, count($pagos), 'rgb(200, 0, 0)'); + $abonos = ['data' => $acum, 'historico' => $anteriores, 'backgroundColor' => $color]; + $output = ['count' => count($days), 'fechas' => $fechas, 'pagos' => $pagos, 'abonos' => $abonos]; + echo json_encode($output); + } + public static function para_abonar() + { + $ids = json_decode(post('ids')); + //$id = get('id'); + function checkPago(&$pagos, $tipo, $pago) { + if (!$pago) { + return; + } + if (!$pago->estado()) { + $pagos []= [ + 'tipo' => $tipo, + 'pago' => $pago->asArray(), + 'estado' => -1 + ]; + return; + } + if ($pago->estado()->tipo()->descripcion == 'depositado') { + $pagos []= [ + 'tipo' => $tipo, + 'pago' => $pago->asArray(), + 'fecha' => format('shortDate', $pago->estado()->fecha), + 'valor' => format('pesos', $pago->valor, true), + 'estado' => 1 + ]; + } + } + $output = []; + foreach ($ids as $id) { + $venta = model(Venta::class)->findOne($id); + if ($venta->estado()->tipo()->activa == 0) { + $output []= ['status' => -1, 'venta' => $venta->id]; + continue; + } + $pagos = []; + if ($venta->pie()) { + foreach ($venta->pie()->cuotas() as $cuota) { + checkPago($pagos, 'Pie', $cuota->pago()); + } + if ($venta->pie()->reajuste()) { + checkPago($pagos, 'Reajuste', $venta->pie()->reajuste()); + } + } + if ($venta->credito()) { + checkPago($pagos, 'Credito', $venta->credito()->pago()); + } + if ($venta->escritura()) { + checkPago($pagos, 'Abono Escritura', $venta->escritura()->pago()); + } + if ($venta->subsidio()) { + checkPago($pagos, 'Subsidio', $venta->subsidio()->subsidio()); + checkPago($pagos, 'Ahorro', $venta->subsidio()->pago()); + } + if (count($pagos) <= 0) { + $output []= ['status' => -1, 'venta' => $venta->id]; + continue; + } + $output []= [ + 'status' => 1, + 'proyecto' => $venta->proyecto()->descripcion, + 'venta' => $venta->id, + 'propietario' => $venta->propietario()->nombreCompleto(), + 'departamento' => $venta->unidad()->descripcion, + 'pagos' => $pagos + ]; + } + return json_encode($output); + } + public static function rebotes() + { + $ids = json_decode(post('ids')); + $response = []; + foreach ($ids as $id) { + //$id = get('id'); + $venta = model(Venta::class)->findOne($id); + $rebotes = $venta->pagos(-1); + if (count($rebotes) < 1) { + $response []= ['status' => -1, 'venta' => $venta->id]; + continue; + } + usort($rebotes, function($a, $b) { + return $b->estado()->fecha()->diffInDays($a->estado()->fecha(), false); + }); + + $output = []; + $textos = []; + foreach ($rebotes as $rebote) { + $fuente = $rebote->fuente()[0]; + $text = '' . ucwords(str_replace('_', ' ', $fuente->tipo)) . ''; + $info = ['tipo' => ucwords(str_replace('_', ' ', $fuente->tipo))]; + switch ($fuente->tipo) { + case('cuota'): + $text .= '' . $fuente->obj->pie()->venta()->proyecto()->descripcion + . '' . $fuente->obj->pie()->venta()->unidad()->descripcion . '' + . $fuente->obj->pie()->venta()->propietario()->nombreCompleto() + . '' . format('shortDate', $rebote->estado()->fecha) . ''; + $info['proyecto'] = $fuente->obj->pie()->venta()->proyecto()->descripcion; + $info['venta'] = $fuente->obj->pie()->venta()->id; + $info['departamento'] = $fuente->obj->pie()->venta()->unidad()->descripcion; + $info['propietario'] = $fuente->obj->pie()->venta()->propietario()->nombreCompleto(); + $info['fecha'] = format('shortDate', $rebote->estado()->fecha); + break; + } + $text .= '' . format('pesos', $rebote->valor('pesos'), true) . ''; + $info['valor'] = format('pesos', $rebote->valor('pesos'), true); + $output []= array_merge(['id' => $rebote->id], $info); + $textos []= ['id' => $rebote->id, 'text' => $text]; + } + $response []= ['status' => 1, 'venta' => $venta->id, 'textos' => $textos, 'rebotes' => $output]; + } + + return json_encode($response); + } + public static function show() + { + $id = get('pago'); + $asociado = get('asociado'); + $id_asociado = get($asociado); + + $pago = model(Pago::class)->findOne($id); + + return view('ventas.pagos.show', compact('pago', 'asociado', 'id_asociado')); + } + public static function pagar() + { + $id = get('pago'); + $pago = model(Pago::class)->findOne($id); + $asociado = get('asociado'); + $id_asociado = get($asociado); + + return view('ventas.pagos.pagar', compact('pago', 'asociado', 'id_asociado')); + } + public static function pagando() + { + $id = get('pago'); + $pago = model(Pago::class)->findOne($id); + $asociado = get('asociado'); + $id_asociado = get($asociado); + + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $data = [ + 'fecha' => $f->format('Y-m-d'), + 'pago' => $pago->id, + 'estado' => 1 + ]; + $estado = model(EstadoPago::class)->create($data); + + $estado->save(); + header('Location: ' . url('', ['p' => $asociado . 's', 'a' => 'show', $asociado => $id_asociado])); + } + public static function abonar() + { + $id = get('pago'); + $pago = model(Pago::class)->findOne($id); + $asociado = get('asociado'); + $id_asociado = get($asociado); + + return view('ventas.pagos.abonar', compact('pago', 'asociado', 'id_asociado')); + } + public static function abonando() + { + $id = get('pago'); + $pago = model(Pago::class)->findOne($id); + $asociado = get('asociado'); + $id_asociado = get($asociado); + + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $data = [ + 'fecha' => $f->format('Y-m-d'), + 'pago' => $pago->id, + 'estado' => 2 + ]; + $estado = model(EstadoPago::class)->create($data); + + $estado->save(); + header('Location: ' . url('', ['p' => $asociado . 's', 'a' => 'show', $asociado => $id_asociado])); + } +} +?> diff --git a/app_old/resources/less/Controller/Pies.php b/app_old/resources/less/Controller/Pies.php new file mode 100644 index 0000000..38c2fcb --- /dev/null +++ b/app_old/resources/less/Controller/Pies.php @@ -0,0 +1,104 @@ +findOne($proyecto); + $ventas = $proyecto->ventas(); + self::sort($ventas); + return view('ventas.list', compact('proyecto', 'ventas')); + } + public static function listProyectos() + { + $proyectos = \Model::factory(Proyecto::class) + ->select('proyecto.*') + ->join('estado_proyecto', ['estado.proyecto', '=', 'proyecto.id'], 'estado') + ->join('tipo_estado_proyecto', ['tipo.id', '=', 'estado.estado'], 'tipo') + ->join('etapa_proyecto', ['etapa.id', '=', 'tipo.etapa'], 'etapa') + ->whereGte('etapa.orden', 4) + ->groupBy('proyecto.id') + ->findMany(); + echo view('ventas.proyectos', compact('proyectos')); + } + public static function resumen() + { + $id = get('pie'); + $pie = \Model::factory(\Incoviba\old\Venta\Pie::class)->findOne($id); + $venta = $pie->venta(); + return view('ventas.pies.resumen', compact('venta')); + } + public static function reajustar() + { + $id = get('venta'); + $venta = \Model::factory(Venta::class)->findOne($id); + return view('ventas.pies.reajustar', compact('venta')); + } + public static function reajuste() + { + $id = get('venta'); + $venta = \Model::factory(Venta::class)->findOne($id); + + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $pago = \Model::factory(Pago::class)->create(); + $pago->fecha = $f->format('Y-m-d'); + $pago->uf = (float) uf($f)->uf->value; + $pago->valor = str_replace('.', '', post('valor')); + + $pago->new(); + + $pie = $venta->pie(); + $pie->reajuste = $pago->id; + $pie->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function edit() + { + $id = get('venta'); + $venta = \Model::factory(Venta::class)->findOne($id); + return view('ventas.pies.edit', compact('venta')); + } + public static function editar() + { + $id = get('venta'); + $venta = \Model::factory(Venta::class)->findOne($id); + $pie = $venta->pie(); + $valor = correctNumber(post('valor')); + if ($pie->valor != $valor) { + $pie->valor = $valor; + } + if ($pie->cuotas != post('cuotas')) { + $pie->cuotas = post('cuotas'); + } + + $pie->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function asociar() + { + $id = get('pie'); + $pie = \Model::factory(Pie::class)->findOne($id); + $pie->asociado = post('asociado'); + + $pie->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $pie->venta()->id])); + } +} +?> diff --git a/app_old/resources/less/Controller/Postventas.php b/app_old/resources/less/Controller/Postventas.php new file mode 100644 index 0000000..7b38cb6 --- /dev/null +++ b/app_old/resources/less/Controller/Postventas.php @@ -0,0 +1,69 @@ +findOne($id); + + return view('ventas.postventas.add', compact('venta')); + } + public static function agregar() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $observaciones = json_decode(post('observaciones')); + $postventa = model(Postventa::class)->create(); + $postventa->venta_id = $venta->id; + $postventa->save(); + + $estado = model(EstadoPostventa::class)->create(); + $estado->postventa_id = $postventa->id; + $estado->tipo_estado_postventa_id = 1; + $estado->fecha = $f->format('Y-m-d'); + $estado->save(); + + foreach ($observaciones as $o) { + $observacion = model(Observacion::class)->create(); + $observacion->texto = post('observacion' . $o); + + $observacion->save(); + + $estado = model(EstadoObservacion::class)->create(); + $estado->observacion_id = $observacion->id; + $estado->tipo_estado_observacion_id = 1; + $estado->fecha = $f->format('Y-m-d'); + $estado->save(); + + $po = model(PostventaObservacion::class)->create(); + $po->postventa_id = $postventa->id; + $po->observacion_id = $observacion->id; + $po->save(); + } + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function show() + { + $id = get('postventa'); + $postventa = model(Postventa::class)->findOne($id); + $venta = model(Venta::class)->findOne($postventa->venta_id); + + return view('ventas.postventas.show', compact('postventa', 'venta')); + } +} +?> diff --git a/resources/less/Controller/Precios.php b/app_old/resources/less/Controller/Precios.php similarity index 100% rename from resources/less/Controller/Precios.php rename to app_old/resources/less/Controller/Precios.php diff --git a/app_old/resources/less/Controller/Propietarios.php b/app_old/resources/less/Controller/Propietarios.php new file mode 100644 index 0000000..5d38ee7 --- /dev/null +++ b/app_old/resources/less/Controller/Propietarios.php @@ -0,0 +1,129 @@ +findOne($id); + $propietario = $venta->propietario(); + $regiones = model(Region::class)->orderByAsc('numeracion')->findMany(); + + return view('ventas.propietarios.edit', compact('venta', 'propietario', 'regiones')); + } + public static function editar() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + $info = post(); + list($info['rut'], $info['dv']) = explode('-', str_replace('.', '', $info['rut'])); + $propietario = model(Propietario::class)->findOne($info['rut']); + if (!$propietario) { + $propietario = model(Propietario::class)->create(); + } + if ($propietario->direccion != 0) { + $direccion = $propietario->direccion(); + } else { + $direccion = model(Direccion::class) + ->where('calle', post('calle')) + ->where('numero', post('numero')) + ->where('extra', post('extra')) + ->where('comuna', post('comuna')) + ->findOne(); + if (!$direccion) { + $data = [ + 'calle' => post('calle'), + 'numero' => post('numero'), + 'extra' => post('extra'), + 'comuna' => post('comuna') + ]; + $direccion = model(Direccion::class)->create($data); + } + } + + if (isset($info['empresa'])) { + $info['apellido_paterno'] = ''; + $info['apellido_materno'] = ''; + } + + if ($propietario->representante != 0) { + list($info['rep_rut'], $info['rep_dv']) = explode('-', str_replace('.', '', $info['rep_rut'])); + $representante = $propietario->representante(); + } elseif (isset($info['rep_rut'])) { + list($info['rep_rut'], $info['rep_dv']) = explode('-', str_replace('.', '', $info['rep_rut'])); + $representante= model(Propietario::class)->findOne($info['rep_rut']); + if (!$representante) { + $representante= model(Propietario::class)->create(); + } + } + + $fields = ['rut', 'dv', 'nombres', 'apellido_paterno', 'apellido_materno']; + $change = false; + foreach ($fields as $key) { + if ($propietario->$key != $info[$key]) { + $propietario->$key = $info[$key]; + $change = true; + } + } + if ($direccion->isNew()) { + $direccion->save(); + } + if ($propietario->direccion != $direccion->id) { + $propietario->direccion = $direccion->id; + $change = true; + } + if ($change) { + d($propietario); + $propietario->save(); + } + + if (isset($info['rep_rut'])) { + $change = false; + if ($representante->rut != $info['rep_rut']) { + $representante->rut = $info['rep_rut']; + $representante->dv = $info['rep_dv']; + $change = true; + } + if ($representante->nombres != $info['rep_nombres']) { + $representante->nombres = $info['rep_nombres']; + $change = true; + } + if ($representante->apellido_paterno != $info['rep_apaterno']) { + $representante->apellido_paterno = $info['rep_apaterno']; + $change = true; + } + if ($representante->apellido_materno != $info['rep_amaterno']) { + $representante->apellido_materno = $info['rep_amaterno']; + $change = true; + } + if ($representante->direccion != $direccion->id) { + $representante->direccion = $direccion->id; + $change = true; + } + if ($change) { + $representante->save(); + } + if ($propietario->representante != $representante->rut) { + $propietario->representante = $representante->rut; + $propietario->save(); + } + } + + if ($venta->propietario != $propietario->rut) { + $venta->propietario = $propietario->rut; + $venta->save(); + } + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } +} +?> diff --git a/app_old/resources/less/Controller/ProyectoTipoUnidades.php b/app_old/resources/less/Controller/ProyectoTipoUnidades.php new file mode 100644 index 0000000..32c0c1d --- /dev/null +++ b/app_old/resources/less/Controller/ProyectoTipoUnidades.php @@ -0,0 +1,77 @@ +findOne($id); + $tipos = model(TipoUnidad::class)->findMany(); + + return view('proyectos.tipo_unidades.edit', compact('tipo', 'tipos')); + } + public static function editar() + { + $id = get('tipo_unidad'); + $tipo = model(ProyectoTipoUnidad::class)->findOne($id); + + $changed = false; + foreach (post() as $field => $value) { + if ($tipo->{$field} != $value) { + $tipo->{$field} = $value; + $changed = true; + } + } + if ($changed) { + $tipo->save(); + } + header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $tipo->proyecto()->id])); + } + public static function add_unidad() + { + $id = get('tipo_unidad'); + $tipo = model(ProyectoTipoUnidad::class)->findOne($id); + if ($tipo->tipo()->descripcion == 'departamento') { + return view('proyectos.unidades.add', compact('tipo')); + } + return view('proyectos.unidades.add2', compact('tipo')); + } + public static function assign() + { + $id = get('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id); + $tipos = model(ProyectoTipoUnidad::class)->where('proyecto', $proyecto->id)->findMany(); + $libres = model(Unidad::class)->where('proyecto', $proyecto->id)->where('pt', 0)->findMany(); + + return view('proyectos.unidades.assign', compact('proyecto', 'tipos', 'libres')); + } + public static function asignar() + { + $id = get('proyecto'); + $proyecto = model(Proyecto::class)->findOne($id); + + $libres = model(Unidad::class)->where('proyecto', $proyecto->id)->where('pt', 0)->findMany(); + foreach ($libres as $unidad) { + $unidad->pt = post('tipo' . $unidad->id); + $unidad->save(); + } + header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $proyecto->id])); + } +} diff --git a/resources/less/Controller/Proyectos.php b/app_old/resources/less/Controller/Proyectos.php similarity index 100% rename from resources/less/Controller/Proyectos.php rename to app_old/resources/less/Controller/Proyectos.php diff --git a/app_old/resources/less/Controller/Reajustes.php b/app_old/resources/less/Controller/Reajustes.php new file mode 100644 index 0000000..4c6c938 --- /dev/null +++ b/app_old/resources/less/Controller/Reajustes.php @@ -0,0 +1,90 @@ +findOne($id); + return view('ventas.pies.reajustes.edit', compact('venta')); + } + public static function editar() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $uf = uf($f); + + $valor = correctNumber(post('valor')); + if ($valor == '') { + $valor_uf = correctNumber(post('valor_uf')); + $valor = $valor_uf * $uf->uf->value; + } + $pago = $venta->pie()->reajuste(); + if ($pago->valor != $valor) { + $pago->valor = $valor; + } + if ($pago->fecha != $f->format('Y-m-d')) { + $pago->fecha = $f->format('Y-m-d'); + $pago->uf = $uf->uf->value; + } + + $pago->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function pagar() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + return view('ventas.pies.reajustes.pagar', compact('venta')); + } + public static function pagado() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + + $data = [ + 'pago' => $venta->pie()->reajuste()->id, + 'fecha' => $f->format('Y-m-d'), + 'estado' => 1 + ]; + $estado = model(EstadoPago::class)->create($data); + $estado->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } + public static function abonar() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + return view('ventas.pies.reajustes.abonar', compact('venta')); + } + public static function abonado() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + + $data = [ + 'pago' => $venta->pie()->reajuste()->id, + 'fecha' => $f->format('Y-m-d'), + 'estado' => 2 + ]; + $estado = model(EstadoPago::class)->create($data); + $estado->save(); + header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); + } +} +?> diff --git a/app_old/resources/less/Controller/Registros.php b/app_old/resources/less/Controller/Registros.php new file mode 100644 index 0000000..546fece --- /dev/null +++ b/app_old/resources/less/Controller/Registros.php @@ -0,0 +1,39 @@ +orderByDesc('time')->findMany(); + $ini = new Color(0, 100, 0); + $end = new Color(255, 255, 255); + $colores = self::colores($end, $ini, 100); + return view('admin.registros.list', compact('registros', 'colores')); + } + public static function show() + { + $registro = model(RModel::class)->findOne(get('registro')); + $ini = new Color(0, 100, 0); + $end = new Color(255, 255, 255); + $colores = self::colores($end, $ini, 100); + return view('admin.registros.show', compact('registro', 'colores')); + } + protected static function colores($ini, $end, $max) + { + $current = $ini->toVector(); + $colores = []; + $line = new Line($ini->toVector(), $end->toVector()); + for ($i = 0; $i < $max; $i ++) { + $colores[$i] = new Color($current); + $current = $line->move($current, $line->length() / $max); + } + return $colores; + } +} diff --git a/app_old/resources/less/Controller/Subsidios.php b/app_old/resources/less/Controller/Subsidios.php new file mode 100644 index 0000000..5107fc3 --- /dev/null +++ b/app_old/resources/less/Controller/Subsidios.php @@ -0,0 +1,184 @@ +findOne($id); + echo view('ventas.subsidios.add', compact('venta')); + } + public static function do_add() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $uf = uf($f); + + $pago1 = model(Pago::class)->create(); + $valor = post('ahorro_uf') * $uf->uf->value; + if (post('ahorro') != null) { + $valor = post('ahorro'); + } + $pago1->valor = $valor; + $pago1->fecha = $f->format('Y-m-d'); + $pago1->uf = $uf->uf->value; + + $pago2 = model(Pago::class)->create(); + $valor = post('subsidio_uf') * $uf->uf->value; + if (post('subsidio') != null) { + $valor = post('subsidio'); + } + $pago2->valor = $valor; + $pago2->fecha = $f->format('Y-m-d'); + $pago2->uf = $uf->uf->value; + + $pago1->new(); + $pago2->new(); + + $subsidio = model(Subsidio::class)->create(); + $subsidio->pago = $pago1->id; + $subsidio->subsidio = $pago2->id; + + $subsidio->save(); + $venta->subsidio = $subsidio->id(); + $venta->save(); + header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); + } + public static function edit() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + echo view('ventas.subsidios.edit', compact('venta')); + } + public static function do_edit() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $uf = uf($f); + + $pago1 = $venta->subsidio()->pago(); + $valor = post('ahorro_uf') * $uf->uf->value; + if (post('ahorro') != null) { + $valor = post('ahorro'); + } + $pago1->valor = $valor; + $pago1->fecha = $f->format('Y-m-d'); + $pago1->uf = $uf->uf->value; + + $pago2 = $venta->subsidio()->subsidio(); + $valor = post('subsidio_uf') * $uf->uf->value; + if (post('subsidio') != null) { + $valor = post('subsidio'); + } + $pago2->valor = $valor; + $pago2->fecha = $f->format('Y-m-d'); + $pago2->uf = $uf->uf->value; + + $pago1->save(); + $pago2->save(); + header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); + } + public static function pagar() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + $tipo = get('tipo'); + switch($tipo) { + case 'subsidio': + $pago = $venta->subsidio()->subsidio(); + break; + case 'pago': + $pago = $venta->subsidio()->pago(); + break; + default: + $pago = null; + } + echo view('ventas.subsidios.pagar', compact('venta', 'pago')); + } + public static function do_pagar() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $tipo = post('tipo'); + switch($tipo) { + case 'subsidio': + $pago = $venta->subsidio()->subsidio(); + break; + case 'pago': + $pago = $venta->subsidio()->pago(); + break; + default: + $pago = null; + } + $pago->valor = post('valor'); + $tipo = model(TipoEstadoPago::class)->where('descripcion', 'depositado')->findOne(); + $data = [ + 'pago' => $pago->id, + 'fecha' => $f->format('Y-m-d'), + 'estado' => $tipo->id + ]; + $estado = model(EstadoPago::class)->create($data); + $pago->save(); + $estado->save(); + header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); + } + public static function abonar() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + $tipo = get('tipo'); + switch($tipo) { + case 'subsidio': + $pago = $venta->subsidio()->subsidio(); + break; + case 'pago': + $pago = $venta->subsidio()->pago(); + break; + default: + $pago = null; + } + echo view('ventas.subsidios.abonar', compact('venta', 'pago')); + } + public static function do_abonar() + { + $id = get('venta'); + $venta = model(Venta::class)->findOne($id); + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $tipo = post('tipo'); + switch($tipo) { + case 'subsidio': + $pago = $venta->subsidio()->subsidio(); + break; + case 'pago': + $pago = $venta->subsidio()->pago(); + break; + default: + $pago = null; + } + $pago->valor = post('valor'); + $tipo = model(TipoEstadoPago::class)->where('descripcion', 'abonado')->findOne(); + $data = [ + 'pago' => $pago->id, + 'fecha' => $f->format('Y-m-d'), + 'estado' => $tipo->id + ]; + $estado = model(EstadoPago::class)->create($data); + $pago->save(); + $estado->save(); + header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); + } +} diff --git a/app_old/resources/less/Controller/Temas.php b/app_old/resources/less/Controller/Temas.php new file mode 100644 index 0000000..24b121a --- /dev/null +++ b/app_old/resources/less/Controller/Temas.php @@ -0,0 +1,111 @@ +orderByAsc('descripcion')->findMany(); + return view('temas.add', compact('proyectos')); + } + public static function agregar() + { + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $data = [ + "proyecto_id" => post('proyecto'), + "inicio" => $f->format('Y-m-d'), + "texto" => post('texto') + ]; + $tema = model(Tema::class)->create($data); + + $tema->save(); + header('Location: ' . url('', ['p' => 'temas', 'a' => 'list'])); + } + public static function list() + { + $temas = model(Tema::class)->findMany(); + $t = Carbon::today(config('app.timezone')); + foreach ($temas as $i => $tema) { + if ($tema->cierre()->year != -1 and $t->diff($tema->cierre())->days > 10) { + unset($temas[$i]); + } + } + $temas = array_values($temas); + usort($temas, function($a, $b) { + $p = strcmp($a->proyecto()->descripcion, $b->proyecto()->descripcion); + if ($p == 0) { + $f = $b->inicio()->diff($a->inicio())->format('%r%a'); + if ($f == 0) { + return $a->id - $b->id; + } + return $f; + } + return $p; + }); + + return view('temas.list', compact('temas')); + } + public static function edit() + { + $id = get('tema'); + $tema = model(Tema::class)->findOne($id); + $proyectos = model(Proyecto::class)->orderByAsc('descripcion')->findMany(); + return view('temas.edit', compact('tema', 'proyectos')); + } + public static function editar() + { + $id = get('tema'); + $tema = model(Tema::class)->findOne($id); + + $proyecto = post('proyecto'); + $changed = false; + if ($tema->proyecto_id != $proyecto) { + $tema->proyecto_id = $proyecto; + $changed = true; + } + $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + if ($tema->inicio() != $f) { + $tema->inicio = $f->format('Y-m-d'); + $changed = true; + } + $texto = post('texto'); + if ($tema->texto != $texto) { + $tema->texto = $texto; + $changed = true; + } + + if ($changed) { + $tema->save(); + } + header('Location: ' . url('', ['p' => 'temas', 'a' => 'list'])); + } + public static function cerrar() + { + $id = get('tema'); + $tema = model(Tema::class)->findOne($id); + $f = Carbon::today(config('app.timezone')); + $tema->cierre = $f->format('Y-m-d'); + + $tema->save(); + header('Location: ' . url('', ['p' => 'temas', 'a' => 'list'])); + } + public static function abrir() + { + $id = get('tema'); + $tema = model(Tema::class)->findOne($id)->as_array(); + unset($tema['id'], $tema['cierre'], $tema['created_at'], $tema['updated_at']); + + $tema = model(Tema::class)->create($tema); + + $tema->save(); + header('Location: ' . url('', ['p' => 'temas', 'a' => 'list'])); + } +} +?> diff --git a/app_old/resources/less/Controller/Unidades.php b/app_old/resources/less/Controller/Unidades.php new file mode 100644 index 0000000..9f0da01 --- /dev/null +++ b/app_old/resources/less/Controller/Unidades.php @@ -0,0 +1,126 @@ +findOne($id); + $len = strlen(post('total')); + + $unis = json_decode(post('unidades')); + $data = []; + foreach ($unis as $n_unidad) { + if ($tipo->tipo()->descripcion == 'departamento') { + $ini = post('piso_ini' . $n_unidad); + $end = post('piso_end' . $n_unidad); + $subtipo = post('linea' . $n_unidad); + $orientacion = post('orientacion' . $n_unidad); + for ($piso = $ini; $piso <= $end; $piso ++) { + $descripcion = $piso . str_pad(post('linea' . $n_unidad), $len, '0', \STR_PAD_LEFT); + + $data []= [ + 'proyecto' => $tipo->proyecto()->id, + 'tipo' => $tipo->tipo()->id, + 'subtipo' => $subtipo, + 'piso' => $piso, + 'descripcion' => $descripcion, + 'abreviacion' => $tipo->abreviacion, + 'm2' => $tipo->m2, + 'terraza' => $tipo->terraza, + 'logia' => $tipo->logia, + 'orientacion' => $orientacion, + 'pt' => $tipo->id + ]; + } + } else { + $descripcion = post('descripcion' . $n_unidad); + $piso = post('piso' . $n_unidad); + $data []= [ + 'proyecto' => $tipo->proyecto()->id, + 'tipo' => $tipo->tipo()->id, + 'piso' => $piso, + 'descripcion' => $descripcion, + 'abreviacion' => $tipo->abreviacion, + 'm2' => $tipo->m2, + 'terraza' => $tipo->terraza, + 'logia' => $tipo->logia, + 'pt' => $tipo->id + ]; + } + } + + foreach ($data as $uni) { + $unidad = model(Unidad::class) + ->where('descripcion', $uni['descripcion']) + ->where('proyecto', $uni['proyecto']) + ->where('tipo', $uni['tipo']) + ->findOne(); + if ($unidad) { + continue; + } + $unidad = model(Unidad::class)->create($uni); + $unidad->save(); + } + header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'list_unidades', 'proyecto' => $tipo->proyecto()->id])); + } + public static function edit() + { + $id = get('unidad'); + $unidad = model(Unidad::class)->findOne($id); + $tipos = model(ProyectoTipoUnidad::class)->where('proyecto', $unidad->proyecto()->id)->findMany(); + $abreviaciones = ['N', 'NE', 'E', 'SE', 'S', 'SO', 'O', 'NO']; + $descripciones = ['Norte', 'Noreste', 'Este', 'Sureste', 'Sur', 'Suroeste', 'Oeste', 'Noroeste']; + $orientaciones = []; + foreach ($abreviaciones as $i => $ab) { + $orientaciones []= (object) ['abreviacion' => $ab, 'descripcion' => $descripciones[$i]]; + } + + return view('proyectos.unidades.edit', compact('unidad', 'tipos', 'orientaciones')); + } + public static function editar() + { + $id = get('unidad'); + $unidad = model(Unidad::class)->findOne($id); + + $change = false; + $fields = ['descripcion', 'tipo', 'piso', 'linea', 'orientacion']; + foreach ($fields as $field) { + $f = $field; + if ($f == 'tipo') { + $f = 'pt'; + } + if ($f == 'linea') { + $f = 'subtipo'; + } + if ($unidad->{$f} != post($field)) { + $unidad->{$f} = post($field); + $change = true; + } + } + + if ($change) { + $unidad->save(); + } + header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $unidad->proyecto()->id])); + } + public static function remove() + { + $id = get('unidad'); + $unidad = model(Unidad::class)->findOne($id); + $unidad->delete(); + + $id = get('proyecto'); + header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $id])); + } +} +?> diff --git a/app_old/resources/less/Controller/UnidadesBloqueadas.php b/app_old/resources/less/Controller/UnidadesBloqueadas.php new file mode 100644 index 0000000..9bd4107 --- /dev/null +++ b/app_old/resources/less/Controller/UnidadesBloqueadas.php @@ -0,0 +1,83 @@ +findMany(); + echo view('ventas.operadores.unidades.list', compact('proyectos')); + } + public static function add() + { + $proyectos = model(Proyecto::class)->findMany(); + echo view('ventas.operadores.unidades.add', compact('proyectos')); + } + public static function bloquear() + { + $operador = model(ProyectoAgente::class)->findOne(get('operador')); + echo view('ventas.operadores.unidades.bloquear', compact('operador')); + } + public static function do_bloquear() + { + $operador = model(ProyectoAgente::class)->findOne(get('operador')); + $fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); + $unidades = self::getUnidades([], 'departamentos', 1); + $unidades = self::getUnidades($unidades, 'estacionamientos', 2); + $unidades = self::getUnidades($unidades, 'bodegas', 3); + if (post('unidad') != null) { + foreach (post('unidad') as $u) { + $unidad = model(Unidad::class)->findOne($u); + if (array_search($unidad, $unidades) === false) { + $unidades []= $unidad; + } + } + } + + foreach ($unidades as $unidad) { + $data = [ + 'agente' => $operador->id, + 'unidad' => $unidad->id + ]; + $ub = model(UnidadBloqueada::class)->create($data); + $ub->new($fecha); + } + header('Location: ' . nUrl('unidades_bloqueadas', 'list')); + } + protected static function getUnidades(array $unidades, string $name, int $tipo): array + { + if (trim(post($name)) == '') { + return $unidades; + } + $unis = []; + $separators = [PHP_EOL, ';', ',', '-']; + foreach ($separators as $separator) { + if (strpos(post($name), $separator) !== false) { + $unis = explode($separator, post($name)); + break; + } + } + if (count($unis) == 0) { + return $unidades; + } + array_walk($unis, function(&$item) { + $item = trim($item); + $item = model(Unidad::class)->where('descripcion', $item)->where('tipo', 1)->findOne(); + }); + foreach ($unis as $uni) { + if (array_search($uni, $unidades) === false) { + $unidades []= $uni; + } + } + return $unidades; + } +} diff --git a/resources/less/Controller/Ventas.php b/app_old/resources/less/Controller/Ventas.php similarity index 100% rename from resources/less/Controller/Ventas.php rename to app_old/resources/less/Controller/Ventas.php diff --git a/resources/less/_variables.less b/app_old/resources/less/_variables.less similarity index 100% rename from resources/less/_variables.less rename to app_old/resources/less/_variables.less diff --git a/resources/less/app.less b/app_old/resources/less/app.less similarity index 100% rename from resources/less/app.less rename to app_old/resources/less/app.less diff --git a/resources/less/bootstrap.less b/app_old/resources/less/bootstrap.less similarity index 100% rename from resources/less/bootstrap.less rename to app_old/resources/less/bootstrap.less diff --git a/resources/less/custom.less b/app_old/resources/less/custom.less similarity index 100% rename from resources/less/custom.less rename to app_old/resources/less/custom.less diff --git a/resources/less/print.less b/app_old/resources/less/print.less similarity index 100% rename from resources/less/print.less rename to app_old/resources/less/print.less diff --git a/resources/less/submenu.less b/app_old/resources/less/submenu.less similarity index 100% rename from resources/less/submenu.less rename to app_old/resources/less/submenu.less diff --git a/resources/routes/api.php b/app_old/resources/routes/api.php similarity index 100% rename from resources/routes/api.php rename to app_old/resources/routes/api.php diff --git a/resources/routes/api/unidades.php b/app_old/resources/routes/api/unidades.php similarity index 100% rename from resources/routes/api/unidades.php rename to app_old/resources/routes/api/unidades.php diff --git a/resources/routes/cli.php b/app_old/resources/routes/cli.php similarity index 100% rename from resources/routes/cli.php rename to app_old/resources/routes/cli.php diff --git a/app_old/resources/routes/ui/01_auth.php b/app_old/resources/routes/ui/01_auth.php new file mode 100644 index 0000000..0c2ce0e --- /dev/null +++ b/app_old/resources/routes/ui/01_auth.php @@ -0,0 +1,15 @@ +group('/auth', function($app) { + $app->group('/login', function($app) { + $app->get('[/]', [Auth::class, 'login']); + $app->post('[/]', [Auth::class, 'do_login']); + }); + $app->get('/logout[/]', [Auth::class, 'logout']); + $app->group('/pass', function($app) { + $app->get('/check', [Auth::class, 'check_pass']); + $app->get('[/]', [Auth::class, 'change_pass']); + $app->post('[/]', [Auth::class, 'do_change_pass']); + }); +}); diff --git a/app_old/resources/routes/ui/99_base.php b/app_old/resources/routes/ui/99_base.php new file mode 100644 index 0000000..b57230d --- /dev/null +++ b/app_old/resources/routes/ui/99_base.php @@ -0,0 +1,4 @@ +get('[/]', Home::class); diff --git a/resources/views/admin/base.blade.php b/app_old/resources/views/admin/base.blade.php similarity index 100% rename from resources/views/admin/base.blade.php rename to app_old/resources/views/admin/base.blade.php diff --git a/resources/views/admin/menu.blade.php b/app_old/resources/views/admin/menu.blade.php similarity index 100% rename from resources/views/admin/menu.blade.php rename to app_old/resources/views/admin/menu.blade.php diff --git a/resources/views/admin/menu/models.blade.php b/app_old/resources/views/admin/menu/models.blade.php similarity index 100% rename from resources/views/admin/menu/models.blade.php rename to app_old/resources/views/admin/menu/models.blade.php diff --git a/resources/views/admin/menu/registros.blade.php b/app_old/resources/views/admin/menu/registros.blade.php similarity index 100% rename from resources/views/admin/menu/registros.blade.php rename to app_old/resources/views/admin/menu/registros.blade.php diff --git a/resources/views/admin/menu/roles.blade.php b/app_old/resources/views/admin/menu/roles.blade.php similarity index 100% rename from resources/views/admin/menu/roles.blade.php rename to app_old/resources/views/admin/menu/roles.blade.php diff --git a/resources/views/admin/menu/users.blade.php b/app_old/resources/views/admin/menu/users.blade.php similarity index 100% rename from resources/views/admin/menu/users.blade.php rename to app_old/resources/views/admin/menu/users.blade.php diff --git a/resources/views/admin/models.blade.php b/app_old/resources/views/admin/models.blade.php similarity index 100% rename from resources/views/admin/models.blade.php rename to app_old/resources/views/admin/models.blade.php diff --git a/resources/views/admin/registros/controles_avance.blade.php b/app_old/resources/views/admin/registros/controles_avance.blade.php similarity index 100% rename from resources/views/admin/registros/controles_avance.blade.php rename to app_old/resources/views/admin/registros/controles_avance.blade.php diff --git a/resources/views/admin/registros/list.blade.php b/app_old/resources/views/admin/registros/list.blade.php similarity index 100% rename from resources/views/admin/registros/list.blade.php rename to app_old/resources/views/admin/registros/list.blade.php diff --git a/resources/views/admin/registros/show.blade.php b/app_old/resources/views/admin/registros/show.blade.php similarity index 100% rename from resources/views/admin/registros/show.blade.php rename to app_old/resources/views/admin/registros/show.blade.php diff --git a/resources/views/admin/roles/add.blade.php b/app_old/resources/views/admin/roles/add.blade.php similarity index 100% rename from resources/views/admin/roles/add.blade.php rename to app_old/resources/views/admin/roles/add.blade.php diff --git a/resources/views/admin/roles/add_permissions.blade.php b/app_old/resources/views/admin/roles/add_permissions.blade.php similarity index 100% rename from resources/views/admin/roles/add_permissions.blade.php rename to app_old/resources/views/admin/roles/add_permissions.blade.php diff --git a/resources/views/admin/roles/add_users.blade.php b/app_old/resources/views/admin/roles/add_users.blade.php similarity index 100% rename from resources/views/admin/roles/add_users.blade.php rename to app_old/resources/views/admin/roles/add_users.blade.php diff --git a/resources/views/admin/roles/list.blade.php b/app_old/resources/views/admin/roles/list.blade.php similarity index 100% rename from resources/views/admin/roles/list.blade.php rename to app_old/resources/views/admin/roles/list.blade.php diff --git a/resources/views/admin/roles/show.blade.php b/app_old/resources/views/admin/roles/show.blade.php similarity index 100% rename from resources/views/admin/roles/show.blade.php rename to app_old/resources/views/admin/roles/show.blade.php diff --git a/resources/views/admin/users/add.blade.php b/app_old/resources/views/admin/users/add.blade.php similarity index 100% rename from resources/views/admin/users/add.blade.php rename to app_old/resources/views/admin/users/add.blade.php diff --git a/resources/views/admin/users/add_role.blade.php b/app_old/resources/views/admin/users/add_role.blade.php similarity index 100% rename from resources/views/admin/users/add_role.blade.php rename to app_old/resources/views/admin/users/add_role.blade.php diff --git a/resources/views/admin/users/list.blade.php b/app_old/resources/views/admin/users/list.blade.php similarity index 100% rename from resources/views/admin/users/list.blade.php rename to app_old/resources/views/admin/users/list.blade.php diff --git a/resources/views/admin/users/show.blade.php b/app_old/resources/views/admin/users/show.blade.php similarity index 100% rename from resources/views/admin/users/show.blade.php rename to app_old/resources/views/admin/users/show.blade.php diff --git a/resources/views/auth/base.blade.php b/app_old/resources/views/auth/base.blade.php similarity index 72% rename from resources/views/auth/base.blade.php rename to app_old/resources/views/auth/base.blade.php index cef48cf..c1e7338 100644 --- a/resources/views/auth/base.blade.php +++ b/app_old/resources/views/auth/base.blade.php @@ -1,5 +1,5 @@ - + @@ -7,9 +7,9 @@ {{$titulo}} - @endif Incoviba S. A. - - - + + + @stack('styles') @@ -19,7 +19,7 @@
- + Logo
@@ -36,7 +36,7 @@ @include('layout.menu.login') @else -
  • Ingresar
  • +
  • Ingresar
  • @endif diff --git a/resources/views/auth/change_pass.blade.php b/app_old/resources/views/auth/change_pass.blade.php similarity index 100% rename from resources/views/auth/change_pass.blade.php rename to app_old/resources/views/auth/change_pass.blade.php diff --git a/app_old/resources/views/auth/login.blade.php b/app_old/resources/views/auth/login.blade.php new file mode 100644 index 0000000..d36013e --- /dev/null +++ b/app_old/resources/views/auth/login.blade.php @@ -0,0 +1,17 @@ +@extends('auth.base') + +@section('content') +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +@endsection diff --git a/resources/views/benchmark.blade.php b/app_old/resources/views/benchmark.blade.php similarity index 100% rename from resources/views/benchmark.blade.php rename to app_old/resources/views/benchmark.blade.php diff --git a/resources/views/buscar/buscar.blade.php b/app_old/resources/views/buscar/buscar.blade.php similarity index 100% rename from resources/views/buscar/buscar.blade.php rename to app_old/resources/views/buscar/buscar.blade.php diff --git a/resources/views/buscar/resultado.blade.php b/app_old/resources/views/buscar/resultado.blade.php similarity index 100% rename from resources/views/buscar/resultado.blade.php rename to app_old/resources/views/buscar/resultado.blade.php diff --git a/resources/views/calendario.blade.php b/app_old/resources/views/calendario.blade.php similarity index 100% rename from resources/views/calendario.blade.php rename to app_old/resources/views/calendario.blade.php diff --git a/resources/views/cierres.blade.php b/app_old/resources/views/cierres.blade.php similarity index 100% rename from resources/views/cierres.blade.php rename to app_old/resources/views/cierres.blade.php diff --git a/resources/views/construccion.blade.php b/app_old/resources/views/construccion.blade.php similarity index 100% rename from resources/views/construccion.blade.php rename to app_old/resources/views/construccion.blade.php diff --git a/resources/views/contabilidad/pago.blade.php b/app_old/resources/views/contabilidad/pago.blade.php similarity index 100% rename from resources/views/contabilidad/pago.blade.php rename to app_old/resources/views/contabilidad/pago.blade.php diff --git a/resources/views/contabilidad/pagos.blade.php b/app_old/resources/views/contabilidad/pagos.blade.php similarity index 100% rename from resources/views/contabilidad/pagos.blade.php rename to app_old/resources/views/contabilidad/pagos.blade.php diff --git a/resources/views/form/fecha.blade.php b/app_old/resources/views/form/fecha.blade.php similarity index 100% rename from resources/views/form/fecha.blade.php rename to app_old/resources/views/form/fecha.blade.php diff --git a/resources/views/guest.blade.php b/app_old/resources/views/guest.blade.php similarity index 71% rename from resources/views/guest.blade.php rename to app_old/resources/views/guest.blade.php index fc12734..6692a1e 100644 --- a/resources/views/guest.blade.php +++ b/app_old/resources/views/guest.blade.php @@ -1,5 +1,5 @@ - + @@ -7,9 +7,9 @@ {{$titulo}} - @endif Incoviba S. A. - - - + + + @stack('styles') @@ -19,7 +19,7 @@
    - + Logo
    @@ -36,7 +36,7 @@ @include('layout.menu.login') @else -
  • Ingresar
  • +
  • Ingresar
  • @endif @@ -54,4 +54,4 @@ @include('layout.footer') @stack('scripts') - \ No newline at end of file + diff --git a/resources/views/home.blade.php b/app_old/resources/views/home.blade.php similarity index 60% rename from resources/views/home.blade.php rename to app_old/resources/views/home.blade.php index 1f7015e..ccc52ff 100644 --- a/resources/views/home.blade.php +++ b/app_old/resources/views/home.blade.php @@ -8,7 +8,7 @@ @endif @if ($pendientes > 0) @endif diff --git a/resources/views/informes/comisiones.blade.php b/app_old/resources/views/informes/comisiones.blade.php similarity index 100% rename from resources/views/informes/comisiones.blade.php rename to app_old/resources/views/informes/comisiones.blade.php diff --git a/resources/views/informes/contabilidad.blade.php b/app_old/resources/views/informes/contabilidad.blade.php similarity index 100% rename from resources/views/informes/contabilidad.blade.php rename to app_old/resources/views/informes/contabilidad.blade.php diff --git a/resources/views/informes/escrituras.blade.php b/app_old/resources/views/informes/escrituras.blade.php similarity index 100% rename from resources/views/informes/escrituras.blade.php rename to app_old/resources/views/informes/escrituras.blade.php diff --git a/resources/views/informes/gantt_entregas.blade.php b/app_old/resources/views/informes/gantt_entregas.blade.php similarity index 100% rename from resources/views/informes/gantt_entregas.blade.php rename to app_old/resources/views/informes/gantt_entregas.blade.php diff --git a/resources/views/informes/para_comision.blade.php b/app_old/resources/views/informes/para_comision.blade.php similarity index 100% rename from resources/views/informes/para_comision.blade.php rename to app_old/resources/views/informes/para_comision.blade.php diff --git a/resources/views/informes/proyectos.blade.php b/app_old/resources/views/informes/proyectos.blade.php similarity index 100% rename from resources/views/informes/proyectos.blade.php rename to app_old/resources/views/informes/proyectos.blade.php diff --git a/resources/views/informes/resciliaciones.blade.php b/app_old/resources/views/informes/resciliaciones.blade.php similarity index 100% rename from resources/views/informes/resciliaciones.blade.php rename to app_old/resources/views/informes/resciliaciones.blade.php diff --git a/resources/views/informes/resumen_contabilidad.blade.php b/app_old/resources/views/informes/resumen_contabilidad.blade.php similarity index 100% rename from resources/views/informes/resumen_contabilidad.blade.php rename to app_old/resources/views/informes/resumen_contabilidad.blade.php diff --git a/resources/views/informes/ventas.blade.php b/app_old/resources/views/informes/ventas.blade.php similarity index 100% rename from resources/views/informes/ventas.blade.php rename to app_old/resources/views/informes/ventas.blade.php diff --git a/resources/views/inmobiliarias/add.blade.php b/app_old/resources/views/inmobiliarias/add.blade.php similarity index 100% rename from resources/views/inmobiliarias/add.blade.php rename to app_old/resources/views/inmobiliarias/add.blade.php diff --git a/resources/views/inmobiliarias/edit.blade.php b/app_old/resources/views/inmobiliarias/edit.blade.php similarity index 100% rename from resources/views/inmobiliarias/edit.blade.php rename to app_old/resources/views/inmobiliarias/edit.blade.php diff --git a/resources/views/inmobiliarias/list.blade.php b/app_old/resources/views/inmobiliarias/list.blade.php similarity index 100% rename from resources/views/inmobiliarias/list.blade.php rename to app_old/resources/views/inmobiliarias/list.blade.php diff --git a/resources/views/inmobiliarias/show.blade.php b/app_old/resources/views/inmobiliarias/show.blade.php similarity index 100% rename from resources/views/inmobiliarias/show.blade.php rename to app_old/resources/views/inmobiliarias/show.blade.php diff --git a/resources/views/install/admin.blade.php b/app_old/resources/views/install/admin.blade.php similarity index 100% rename from resources/views/install/admin.blade.php rename to app_old/resources/views/install/admin.blade.php diff --git a/resources/views/install/base.blade.php b/app_old/resources/views/install/base.blade.php similarity index 100% rename from resources/views/install/base.blade.php rename to app_old/resources/views/install/base.blade.php diff --git a/resources/views/install/end.blade.php b/app_old/resources/views/install/end.blade.php similarity index 100% rename from resources/views/install/end.blade.php rename to app_old/resources/views/install/end.blade.php diff --git a/resources/views/install/start.blade.php b/app_old/resources/views/install/start.blade.php similarity index 100% rename from resources/views/install/start.blade.php rename to app_old/resources/views/install/start.blade.php diff --git a/resources/views/layout/base.blade.php b/app_old/resources/views/layout/base.blade.php similarity index 100% rename from resources/views/layout/base.blade.php rename to app_old/resources/views/layout/base.blade.php diff --git a/resources/views/layout/footer.blade.php b/app_old/resources/views/layout/footer.blade.php similarity index 100% rename from resources/views/layout/footer.blade.php rename to app_old/resources/views/layout/footer.blade.php diff --git a/resources/views/layout/header.blade.php b/app_old/resources/views/layout/header.blade.php similarity index 100% rename from resources/views/layout/header.blade.php rename to app_old/resources/views/layout/header.blade.php diff --git a/resources/views/layout/icons/abonar.blade.php b/app_old/resources/views/layout/icons/abonar.blade.php similarity index 100% rename from resources/views/layout/icons/abonar.blade.php rename to app_old/resources/views/layout/icons/abonar.blade.php diff --git a/resources/views/layout/icons/add.blade.php b/app_old/resources/views/layout/icons/add.blade.php similarity index 100% rename from resources/views/layout/icons/add.blade.php rename to app_old/resources/views/layout/icons/add.blade.php diff --git a/resources/views/layout/icons/edit.blade.php b/app_old/resources/views/layout/icons/edit.blade.php similarity index 100% rename from resources/views/layout/icons/edit.blade.php rename to app_old/resources/views/layout/icons/edit.blade.php diff --git a/resources/views/layout/icons/pagar.blade.php b/app_old/resources/views/layout/icons/pagar.blade.php similarity index 100% rename from resources/views/layout/icons/pagar.blade.php rename to app_old/resources/views/layout/icons/pagar.blade.php diff --git a/resources/views/layout/icons/remove.blade.php b/app_old/resources/views/layout/icons/remove.blade.php similarity index 100% rename from resources/views/layout/icons/remove.blade.php rename to app_old/resources/views/layout/icons/remove.blade.php diff --git a/resources/views/layout/icons/show.blade.php b/app_old/resources/views/layout/icons/show.blade.php similarity index 100% rename from resources/views/layout/icons/show.blade.php rename to app_old/resources/views/layout/icons/show.blade.php diff --git a/resources/views/layout/menu.blade.php b/app_old/resources/views/layout/menu.blade.php similarity index 96% rename from resources/views/layout/menu.blade.php rename to app_old/resources/views/layout/menu.blade.php index d1e442b..e4fef47 100644 --- a/resources/views/layout/menu.blade.php +++ b/app_old/resources/views/layout/menu.blade.php @@ -61,7 +61,7 @@ @include('layout.menu.login') @if (\App\Contract\Auth::checkAccess('buscar')) -
  • +
  •  
  • @endif diff --git a/resources/views/layout/menu.blade.php.save b/app_old/resources/views/layout/menu.blade.php.save similarity index 100% rename from resources/views/layout/menu.blade.php.save rename to app_old/resources/views/layout/menu.blade.php.save diff --git a/resources/views/layout/menu/herramientas.blade.php b/app_old/resources/views/layout/menu/herramientas.blade.php similarity index 100% rename from resources/views/layout/menu/herramientas.blade.php rename to app_old/resources/views/layout/menu/herramientas.blade.php diff --git a/resources/views/layout/menu/informes.blade.php b/app_old/resources/views/layout/menu/informes.blade.php similarity index 100% rename from resources/views/layout/menu/informes.blade.php rename to app_old/resources/views/layout/menu/informes.blade.php diff --git a/resources/views/layout/menu/inmobiliarias.blade.php b/app_old/resources/views/layout/menu/inmobiliarias.blade.php similarity index 100% rename from resources/views/layout/menu/inmobiliarias.blade.php rename to app_old/resources/views/layout/menu/inmobiliarias.blade.php diff --git a/app_old/resources/views/layout/menu/login.blade.php b/app_old/resources/views/layout/menu/login.blade.php new file mode 100644 index 0000000..5329249 --- /dev/null +++ b/app_old/resources/views/layout/menu/login.blade.php @@ -0,0 +1,8 @@ + diff --git a/resources/views/layout/menu/operadores.blade.php b/app_old/resources/views/layout/menu/operadores.blade.php similarity index 100% rename from resources/views/layout/menu/operadores.blade.php rename to app_old/resources/views/layout/menu/operadores.blade.php diff --git a/resources/views/layout/menu/proyectos.blade.php b/app_old/resources/views/layout/menu/proyectos.blade.php similarity index 100% rename from resources/views/layout/menu/proyectos.blade.php rename to app_old/resources/views/layout/menu/proyectos.blade.php diff --git a/resources/views/layout/menu/ventas.blade.php b/app_old/resources/views/layout/menu/ventas.blade.php similarity index 100% rename from resources/views/layout/menu/ventas.blade.php rename to app_old/resources/views/layout/menu/ventas.blade.php diff --git a/resources/views/other/capacidades.blade.php b/app_old/resources/views/other/capacidades.blade.php similarity index 100% rename from resources/views/other/capacidades.blade.php rename to app_old/resources/views/other/capacidades.blade.php diff --git a/resources/views/other/entregar_multiple.blade.php b/app_old/resources/views/other/entregar_multiple.blade.php similarity index 100% rename from resources/views/other/entregar_multiple.blade.php rename to app_old/resources/views/other/entregar_multiple.blade.php diff --git a/resources/views/print/devolucion.blade.php b/app_old/resources/views/print/devolucion.blade.php similarity index 100% rename from resources/views/print/devolucion.blade.php rename to app_old/resources/views/print/devolucion.blade.php diff --git a/resources/views/proyectos/add.blade.php b/app_old/resources/views/proyectos/add.blade.php similarity index 100% rename from resources/views/proyectos/add.blade.php rename to app_old/resources/views/proyectos/add.blade.php diff --git a/resources/views/proyectos/advance.blade.php b/app_old/resources/views/proyectos/advance.blade.php similarity index 100% rename from resources/views/proyectos/advance.blade.php rename to app_old/resources/views/proyectos/advance.blade.php diff --git a/resources/views/proyectos/avance.blade.php b/app_old/resources/views/proyectos/avance.blade.php similarity index 100% rename from resources/views/proyectos/avance.blade.php rename to app_old/resources/views/proyectos/avance.blade.php diff --git a/resources/views/proyectos/avances/edit.blade.php b/app_old/resources/views/proyectos/avances/edit.blade.php similarity index 100% rename from resources/views/proyectos/avances/edit.blade.php rename to app_old/resources/views/proyectos/avances/edit.blade.php diff --git a/resources/views/proyectos/avances_row.blade.php b/app_old/resources/views/proyectos/avances_row.blade.php similarity index 100% rename from resources/views/proyectos/avances_row.blade.php rename to app_old/resources/views/proyectos/avances_row.blade.php diff --git a/resources/views/proyectos/construccion.blade.php b/app_old/resources/views/proyectos/construccion.blade.php similarity index 100% rename from resources/views/proyectos/construccion.blade.php rename to app_old/resources/views/proyectos/construccion.blade.php diff --git a/resources/views/proyectos/disponibles.blade.php b/app_old/resources/views/proyectos/disponibles.blade.php similarity index 100% rename from resources/views/proyectos/disponibles.blade.php rename to app_old/resources/views/proyectos/disponibles.blade.php diff --git a/resources/views/proyectos/estimado.blade.php b/app_old/resources/views/proyectos/estimado.blade.php similarity index 100% rename from resources/views/proyectos/estimado.blade.php rename to app_old/resources/views/proyectos/estimado.blade.php diff --git a/resources/views/proyectos/historia.blade.php b/app_old/resources/views/proyectos/historia.blade.php similarity index 100% rename from resources/views/proyectos/historia.blade.php rename to app_old/resources/views/proyectos/historia.blade.php diff --git a/resources/views/proyectos/historia.blade.php.old b/app_old/resources/views/proyectos/historia.blade.php.old similarity index 100% rename from resources/views/proyectos/historia.blade.php.old rename to app_old/resources/views/proyectos/historia.blade.php.old diff --git a/resources/views/proyectos/list.blade.php b/app_old/resources/views/proyectos/list.blade.php similarity index 100% rename from resources/views/proyectos/list.blade.php rename to app_old/resources/views/proyectos/list.blade.php diff --git a/resources/views/proyectos/operadores/add.blade.php b/app_old/resources/views/proyectos/operadores/add.blade.php similarity index 100% rename from resources/views/proyectos/operadores/add.blade.php rename to app_old/resources/views/proyectos/operadores/add.blade.php diff --git a/resources/views/proyectos/pagares/add.blade.php b/app_old/resources/views/proyectos/pagares/add.blade.php similarity index 100% rename from resources/views/proyectos/pagares/add.blade.php rename to app_old/resources/views/proyectos/pagares/add.blade.php diff --git a/resources/views/proyectos/pagares/add_renovacion.blade.php b/app_old/resources/views/proyectos/pagares/add_renovacion.blade.php similarity index 100% rename from resources/views/proyectos/pagares/add_renovacion.blade.php rename to app_old/resources/views/proyectos/pagares/add_renovacion.blade.php diff --git a/resources/views/proyectos/pagares/edit.blade.php b/app_old/resources/views/proyectos/pagares/edit.blade.php similarity index 100% rename from resources/views/proyectos/pagares/edit.blade.php rename to app_old/resources/views/proyectos/pagares/edit.blade.php diff --git a/resources/views/proyectos/pagares/edit_renovacion.blade.php b/app_old/resources/views/proyectos/pagares/edit_renovacion.blade.php similarity index 100% rename from resources/views/proyectos/pagares/edit_renovacion.blade.php rename to app_old/resources/views/proyectos/pagares/edit_renovacion.blade.php diff --git a/resources/views/proyectos/pagares/show.blade.php b/app_old/resources/views/proyectos/pagares/show.blade.php similarity index 100% rename from resources/views/proyectos/pagares/show.blade.php rename to app_old/resources/views/proyectos/pagares/show.blade.php diff --git a/resources/views/proyectos/por_vender.blade.php b/app_old/resources/views/proyectos/por_vender.blade.php similarity index 100% rename from resources/views/proyectos/por_vender.blade.php rename to app_old/resources/views/proyectos/por_vender.blade.php diff --git a/resources/views/proyectos/reservas/base.blade.php b/app_old/resources/views/proyectos/reservas/base.blade.php similarity index 100% rename from resources/views/proyectos/reservas/base.blade.php rename to app_old/resources/views/proyectos/reservas/base.blade.php diff --git a/resources/views/proyectos/show.blade.php b/app_old/resources/views/proyectos/show.blade.php similarity index 100% rename from resources/views/proyectos/show.blade.php rename to app_old/resources/views/proyectos/show.blade.php diff --git a/resources/views/proyectos/superficies.blade.php b/app_old/resources/views/proyectos/superficies.blade.php similarity index 100% rename from resources/views/proyectos/superficies.blade.php rename to app_old/resources/views/proyectos/superficies.blade.php diff --git a/resources/views/proyectos/tipo_unidades/add.blade.php b/app_old/resources/views/proyectos/tipo_unidades/add.blade.php similarity index 100% rename from resources/views/proyectos/tipo_unidades/add.blade.php rename to app_old/resources/views/proyectos/tipo_unidades/add.blade.php diff --git a/resources/views/proyectos/tipo_unidades/edit.blade.php b/app_old/resources/views/proyectos/tipo_unidades/edit.blade.php similarity index 100% rename from resources/views/proyectos/tipo_unidades/edit.blade.php rename to app_old/resources/views/proyectos/tipo_unidades/edit.blade.php diff --git a/resources/views/proyectos/unidades/add.blade.php b/app_old/resources/views/proyectos/unidades/add.blade.php similarity index 100% rename from resources/views/proyectos/unidades/add.blade.php rename to app_old/resources/views/proyectos/unidades/add.blade.php diff --git a/resources/views/proyectos/unidades/add2.blade.php b/app_old/resources/views/proyectos/unidades/add2.blade.php similarity index 100% rename from resources/views/proyectos/unidades/add2.blade.php rename to app_old/resources/views/proyectos/unidades/add2.blade.php diff --git a/resources/views/proyectos/unidades/assign.blade.php b/app_old/resources/views/proyectos/unidades/assign.blade.php similarity index 100% rename from resources/views/proyectos/unidades/assign.blade.php rename to app_old/resources/views/proyectos/unidades/assign.blade.php diff --git a/resources/views/proyectos/unidades/edit.blade.php b/app_old/resources/views/proyectos/unidades/edit.blade.php similarity index 100% rename from resources/views/proyectos/unidades/edit.blade.php rename to app_old/resources/views/proyectos/unidades/edit.blade.php diff --git a/resources/views/proyectos/unidades/list.blade.php b/app_old/resources/views/proyectos/unidades/list.blade.php similarity index 100% rename from resources/views/proyectos/unidades/list.blade.php rename to app_old/resources/views/proyectos/unidades/list.blade.php diff --git a/resources/views/proyectos/unidades/proyectos.blade.php b/app_old/resources/views/proyectos/unidades/proyectos.blade.php similarity index 100% rename from resources/views/proyectos/unidades/proyectos.blade.php rename to app_old/resources/views/proyectos/unidades/proyectos.blade.php diff --git a/resources/views/proyectos/ventas.blade.php b/app_old/resources/views/proyectos/ventas.blade.php similarity index 100% rename from resources/views/proyectos/ventas.blade.php rename to app_old/resources/views/proyectos/ventas.blade.php diff --git a/resources/views/temas/add.blade.php b/app_old/resources/views/temas/add.blade.php similarity index 100% rename from resources/views/temas/add.blade.php rename to app_old/resources/views/temas/add.blade.php diff --git a/resources/views/temas/edit.blade.php b/app_old/resources/views/temas/edit.blade.php similarity index 100% rename from resources/views/temas/edit.blade.php rename to app_old/resources/views/temas/edit.blade.php diff --git a/resources/views/temas/list.blade.php b/app_old/resources/views/temas/list.blade.php similarity index 100% rename from resources/views/temas/list.blade.php rename to app_old/resources/views/temas/list.blade.php diff --git a/resources/views/ventas/add.blade.php b/app_old/resources/views/ventas/add.blade.php similarity index 100% rename from resources/views/ventas/add.blade.php rename to app_old/resources/views/ventas/add.blade.php diff --git a/resources/views/ventas/archivar.blade.php b/app_old/resources/views/ventas/archivar.blade.php similarity index 100% rename from resources/views/ventas/archivar.blade.php rename to app_old/resources/views/ventas/archivar.blade.php diff --git a/resources/views/ventas/bonos/add.blade.php b/app_old/resources/views/ventas/bonos/add.blade.php similarity index 100% rename from resources/views/ventas/bonos/add.blade.php rename to app_old/resources/views/ventas/bonos/add.blade.php diff --git a/resources/views/ventas/bonos/edit.blade.php b/app_old/resources/views/ventas/bonos/edit.blade.php similarity index 100% rename from resources/views/ventas/bonos/edit.blade.php rename to app_old/resources/views/ventas/bonos/edit.blade.php diff --git a/resources/views/ventas/ceder.blade.php b/app_old/resources/views/ventas/ceder.blade.php similarity index 100% rename from resources/views/ventas/ceder.blade.php rename to app_old/resources/views/ventas/ceder.blade.php diff --git a/resources/views/ventas/cierres/add.blade.php b/app_old/resources/views/ventas/cierres/add.blade.php similarity index 100% rename from resources/views/ventas/cierres/add.blade.php rename to app_old/resources/views/ventas/cierres/add.blade.php diff --git a/resources/views/ventas/cierres/edit.blade.php b/app_old/resources/views/ventas/cierres/edit.blade.php similarity index 100% rename from resources/views/ventas/cierres/edit.blade.php rename to app_old/resources/views/ventas/cierres/edit.blade.php diff --git a/resources/views/ventas/cierres/evaluar.blade.php b/app_old/resources/views/ventas/cierres/evaluar.blade.php similarity index 100% rename from resources/views/ventas/cierres/evaluar.blade.php rename to app_old/resources/views/ventas/cierres/evaluar.blade.php diff --git a/resources/views/ventas/cierres/list.blade.php b/app_old/resources/views/ventas/cierres/list.blade.php similarity index 100% rename from resources/views/ventas/cierres/list.blade.php rename to app_old/resources/views/ventas/cierres/list.blade.php diff --git a/resources/views/ventas/cierres/show.blade.php b/app_old/resources/views/ventas/cierres/show.blade.php similarity index 100% rename from resources/views/ventas/cierres/show.blade.php rename to app_old/resources/views/ventas/cierres/show.blade.php diff --git a/resources/views/ventas/comentarios/add.blade.php b/app_old/resources/views/ventas/comentarios/add.blade.php similarity index 100% rename from resources/views/ventas/comentarios/add.blade.php rename to app_old/resources/views/ventas/comentarios/add.blade.php diff --git a/resources/views/ventas/consolidacion/pago.blade.php b/app_old/resources/views/ventas/consolidacion/pago.blade.php similarity index 100% rename from resources/views/ventas/consolidacion/pago.blade.php rename to app_old/resources/views/ventas/consolidacion/pago.blade.php diff --git a/resources/views/ventas/consolidacion/proyectos.blade.php b/app_old/resources/views/ventas/consolidacion/proyectos.blade.php similarity index 100% rename from resources/views/ventas/consolidacion/proyectos.blade.php rename to app_old/resources/views/ventas/consolidacion/proyectos.blade.php diff --git a/resources/views/ventas/consolidacion/show.blade.php b/app_old/resources/views/ventas/consolidacion/show.blade.php similarity index 100% rename from resources/views/ventas/consolidacion/show.blade.php rename to app_old/resources/views/ventas/consolidacion/show.blade.php diff --git a/resources/views/ventas/creditos/abonar.blade.php b/app_old/resources/views/ventas/creditos/abonar.blade.php similarity index 100% rename from resources/views/ventas/creditos/abonar.blade.php rename to app_old/resources/views/ventas/creditos/abonar.blade.php diff --git a/resources/views/ventas/creditos/add.blade.php b/app_old/resources/views/ventas/creditos/add.blade.php similarity index 100% rename from resources/views/ventas/creditos/add.blade.php rename to app_old/resources/views/ventas/creditos/add.blade.php diff --git a/resources/views/ventas/creditos/edit.blade.php b/app_old/resources/views/ventas/creditos/edit.blade.php similarity index 100% rename from resources/views/ventas/creditos/edit.blade.php rename to app_old/resources/views/ventas/creditos/edit.blade.php diff --git a/resources/views/ventas/creditos/pagar.blade.php b/app_old/resources/views/ventas/creditos/pagar.blade.php similarity index 100% rename from resources/views/ventas/creditos/pagar.blade.php rename to app_old/resources/views/ventas/creditos/pagar.blade.php diff --git a/resources/views/ventas/creditos/pendientes.blade.php b/app_old/resources/views/ventas/creditos/pendientes.blade.php similarity index 100% rename from resources/views/ventas/creditos/pendientes.blade.php rename to app_old/resources/views/ventas/creditos/pendientes.blade.php diff --git a/resources/views/ventas/creditos/show.blade.php b/app_old/resources/views/ventas/creditos/show.blade.php similarity index 100% rename from resources/views/ventas/creditos/show.blade.php rename to app_old/resources/views/ventas/creditos/show.blade.php diff --git a/resources/views/ventas/desist.blade.php b/app_old/resources/views/ventas/desist.blade.php similarity index 100% rename from resources/views/ventas/desist.blade.php rename to app_old/resources/views/ventas/desist.blade.php diff --git a/resources/views/ventas/devolucion.blade.php b/app_old/resources/views/ventas/devolucion.blade.php similarity index 100% rename from resources/views/ventas/devolucion.blade.php rename to app_old/resources/views/ventas/devolucion.blade.php diff --git a/resources/views/ventas/edit.blade.php b/app_old/resources/views/ventas/edit.blade.php similarity index 100% rename from resources/views/ventas/edit.blade.php rename to app_old/resources/views/ventas/edit.blade.php diff --git a/resources/views/ventas/entregar.blade.php b/app_old/resources/views/ventas/entregar.blade.php similarity index 100% rename from resources/views/ventas/entregar.blade.php rename to app_old/resources/views/ventas/entregar.blade.php diff --git a/resources/views/ventas/escrituras/abonar.blade.php b/app_old/resources/views/ventas/escrituras/abonar.blade.php similarity index 100% rename from resources/views/ventas/escrituras/abonar.blade.php rename to app_old/resources/views/ventas/escrituras/abonar.blade.php diff --git a/resources/views/ventas/escrituras/add.blade.php b/app_old/resources/views/ventas/escrituras/add.blade.php similarity index 100% rename from resources/views/ventas/escrituras/add.blade.php rename to app_old/resources/views/ventas/escrituras/add.blade.php diff --git a/resources/views/ventas/escrituras/edit.blade.php b/app_old/resources/views/ventas/escrituras/edit.blade.php similarity index 100% rename from resources/views/ventas/escrituras/edit.blade.php rename to app_old/resources/views/ventas/escrituras/edit.blade.php diff --git a/resources/views/ventas/escrituras/informe.blade.php b/app_old/resources/views/ventas/escrituras/informe.blade.php similarity index 100% rename from resources/views/ventas/escrituras/informe.blade.php rename to app_old/resources/views/ventas/escrituras/informe.blade.php diff --git a/resources/views/ventas/escrituras/pagar.blade.php b/app_old/resources/views/ventas/escrituras/pagar.blade.php similarity index 100% rename from resources/views/ventas/escrituras/pagar.blade.php rename to app_old/resources/views/ventas/escrituras/pagar.blade.php diff --git a/resources/views/ventas/firmar.blade.php b/app_old/resources/views/ventas/firmar.blade.php similarity index 100% rename from resources/views/ventas/firmar.blade.php rename to app_old/resources/views/ventas/firmar.blade.php diff --git a/resources/views/ventas/forma_pago.blade.php b/app_old/resources/views/ventas/forma_pago.blade.php similarity index 100% rename from resources/views/ventas/forma_pago.blade.php rename to app_old/resources/views/ventas/forma_pago.blade.php diff --git a/resources/views/ventas/forma_pago/edit.blade.php b/app_old/resources/views/ventas/forma_pago/edit.blade.php similarity index 100% rename from resources/views/ventas/forma_pago/edit.blade.php rename to app_old/resources/views/ventas/forma_pago/edit.blade.php diff --git a/resources/views/ventas/list.blade.php b/app_old/resources/views/ventas/list.blade.php similarity index 100% rename from resources/views/ventas/list.blade.php rename to app_old/resources/views/ventas/list.blade.php diff --git a/resources/views/ventas/operadores/unidades/bloquear.blade.php b/app_old/resources/views/ventas/operadores/unidades/bloquear.blade.php similarity index 100% rename from resources/views/ventas/operadores/unidades/bloquear.blade.php rename to app_old/resources/views/ventas/operadores/unidades/bloquear.blade.php diff --git a/resources/views/ventas/operadores/unidades/list.blade.php b/app_old/resources/views/ventas/operadores/unidades/list.blade.php similarity index 100% rename from resources/views/ventas/operadores/unidades/list.blade.php rename to app_old/resources/views/ventas/operadores/unidades/list.blade.php diff --git a/resources/views/ventas/pagos/edit.blade.php b/app_old/resources/views/ventas/pagos/edit.blade.php similarity index 100% rename from resources/views/ventas/pagos/edit.blade.php rename to app_old/resources/views/ventas/pagos/edit.blade.php diff --git a/resources/views/ventas/pagos/pendientes.blade.php b/app_old/resources/views/ventas/pagos/pendientes.blade.php similarity index 100% rename from resources/views/ventas/pagos/pendientes.blade.php rename to app_old/resources/views/ventas/pagos/pendientes.blade.php diff --git a/resources/views/ventas/pagos/show.blade.php b/app_old/resources/views/ventas/pagos/show.blade.php similarity index 100% rename from resources/views/ventas/pagos/show.blade.php rename to app_old/resources/views/ventas/pagos/show.blade.php diff --git a/resources/views/ventas/pies/cuotas/abonar.blade.php b/app_old/resources/views/ventas/pies/cuotas/abonar.blade.php similarity index 100% rename from resources/views/ventas/pies/cuotas/abonar.blade.php rename to app_old/resources/views/ventas/pies/cuotas/abonar.blade.php diff --git a/resources/views/ventas/pies/cuotas/add.blade.php b/app_old/resources/views/ventas/pies/cuotas/add.blade.php similarity index 100% rename from resources/views/ventas/pies/cuotas/add.blade.php rename to app_old/resources/views/ventas/pies/cuotas/add.blade.php diff --git a/resources/views/ventas/pies/cuotas/edit.blade.php b/app_old/resources/views/ventas/pies/cuotas/edit.blade.php similarity index 100% rename from resources/views/ventas/pies/cuotas/edit.blade.php rename to app_old/resources/views/ventas/pies/cuotas/edit.blade.php diff --git a/resources/views/ventas/pies/cuotas/estado.blade.php b/app_old/resources/views/ventas/pies/cuotas/estado.blade.php similarity index 100% rename from resources/views/ventas/pies/cuotas/estado.blade.php rename to app_old/resources/views/ventas/pies/cuotas/estado.blade.php diff --git a/resources/views/ventas/pies/cuotas/pendientes.blade.php b/app_old/resources/views/ventas/pies/cuotas/pendientes.blade.php similarity index 100% rename from resources/views/ventas/pies/cuotas/pendientes.blade.php rename to app_old/resources/views/ventas/pies/cuotas/pendientes.blade.php diff --git a/resources/views/ventas/pies/cuotas/show.blade.php b/app_old/resources/views/ventas/pies/cuotas/show.blade.php similarity index 100% rename from resources/views/ventas/pies/cuotas/show.blade.php rename to app_old/resources/views/ventas/pies/cuotas/show.blade.php diff --git a/resources/views/ventas/pies/edit.blade.php b/app_old/resources/views/ventas/pies/edit.blade.php similarity index 100% rename from resources/views/ventas/pies/edit.blade.php rename to app_old/resources/views/ventas/pies/edit.blade.php diff --git a/resources/views/ventas/pies/reajustar.blade.php b/app_old/resources/views/ventas/pies/reajustar.blade.php similarity index 100% rename from resources/views/ventas/pies/reajustar.blade.php rename to app_old/resources/views/ventas/pies/reajustar.blade.php diff --git a/resources/views/ventas/pies/reajustes/abonar.blade.php b/app_old/resources/views/ventas/pies/reajustes/abonar.blade.php similarity index 100% rename from resources/views/ventas/pies/reajustes/abonar.blade.php rename to app_old/resources/views/ventas/pies/reajustes/abonar.blade.php diff --git a/resources/views/ventas/pies/reajustes/edit.blade.php b/app_old/resources/views/ventas/pies/reajustes/edit.blade.php similarity index 100% rename from resources/views/ventas/pies/reajustes/edit.blade.php rename to app_old/resources/views/ventas/pies/reajustes/edit.blade.php diff --git a/resources/views/ventas/pies/reajustes/pagar.blade.php b/app_old/resources/views/ventas/pies/reajustes/pagar.blade.php similarity index 100% rename from resources/views/ventas/pies/reajustes/pagar.blade.php rename to app_old/resources/views/ventas/pies/reajustes/pagar.blade.php diff --git a/resources/views/ventas/pies/resumen.blade.php b/app_old/resources/views/ventas/pies/resumen.blade.php similarity index 100% rename from resources/views/ventas/pies/resumen.blade.php rename to app_old/resources/views/ventas/pies/resumen.blade.php diff --git a/resources/views/ventas/pies/totales.blade.php b/app_old/resources/views/ventas/pies/totales.blade.php similarity index 100% rename from resources/views/ventas/pies/totales.blade.php rename to app_old/resources/views/ventas/pies/totales.blade.php diff --git a/resources/views/ventas/postventas/add.blade.php b/app_old/resources/views/ventas/postventas/add.blade.php similarity index 100% rename from resources/views/ventas/postventas/add.blade.php rename to app_old/resources/views/ventas/postventas/add.blade.php diff --git a/resources/views/ventas/postventas/show.blade.php b/app_old/resources/views/ventas/postventas/show.blade.php similarity index 100% rename from resources/views/ventas/postventas/show.blade.php rename to app_old/resources/views/ventas/postventas/show.blade.php diff --git a/resources/views/ventas/precios/add.blade.php b/app_old/resources/views/ventas/precios/add.blade.php similarity index 100% rename from resources/views/ventas/precios/add.blade.php rename to app_old/resources/views/ventas/precios/add.blade.php diff --git a/resources/views/ventas/precios/import.blade.php b/app_old/resources/views/ventas/precios/import.blade.php similarity index 100% rename from resources/views/ventas/precios/import.blade.php rename to app_old/resources/views/ventas/precios/import.blade.php diff --git a/resources/views/ventas/precios/list.blade.php b/app_old/resources/views/ventas/precios/list.blade.php similarity index 100% rename from resources/views/ventas/precios/list.blade.php rename to app_old/resources/views/ventas/precios/list.blade.php diff --git a/resources/views/ventas/precios/proyectos.blade.php b/app_old/resources/views/ventas/precios/proyectos.blade.php similarity index 100% rename from resources/views/ventas/precios/proyectos.blade.php rename to app_old/resources/views/ventas/precios/proyectos.blade.php diff --git a/resources/views/ventas/propietarios/edit.blade.php b/app_old/resources/views/ventas/propietarios/edit.blade.php similarity index 100% rename from resources/views/ventas/propietarios/edit.blade.php rename to app_old/resources/views/ventas/propietarios/edit.blade.php diff --git a/resources/views/ventas/proyectos.blade.php b/app_old/resources/views/ventas/proyectos.blade.php similarity index 100% rename from resources/views/ventas/proyectos.blade.php rename to app_old/resources/views/ventas/proyectos.blade.php diff --git a/resources/views/ventas/resciliaciones.blade.php b/app_old/resources/views/ventas/resciliaciones.blade.php similarity index 100% rename from resources/views/ventas/resciliaciones.blade.php rename to app_old/resources/views/ventas/resciliaciones.blade.php diff --git a/resources/views/ventas/show.blade.php b/app_old/resources/views/ventas/show.blade.php similarity index 100% rename from resources/views/ventas/show.blade.php rename to app_old/resources/views/ventas/show.blade.php diff --git a/resources/views/ventas/sort_title.blade.php b/app_old/resources/views/ventas/sort_title.blade.php similarity index 100% rename from resources/views/ventas/sort_title.blade.php rename to app_old/resources/views/ventas/sort_title.blade.php diff --git a/resources/views/ventas/subsidios/abonar.blade.php b/app_old/resources/views/ventas/subsidios/abonar.blade.php similarity index 100% rename from resources/views/ventas/subsidios/abonar.blade.php rename to app_old/resources/views/ventas/subsidios/abonar.blade.php diff --git a/resources/views/ventas/subsidios/add.blade.php b/app_old/resources/views/ventas/subsidios/add.blade.php similarity index 100% rename from resources/views/ventas/subsidios/add.blade.php rename to app_old/resources/views/ventas/subsidios/add.blade.php diff --git a/resources/views/ventas/subsidios/edit.blade.php b/app_old/resources/views/ventas/subsidios/edit.blade.php similarity index 100% rename from resources/views/ventas/subsidios/edit.blade.php rename to app_old/resources/views/ventas/subsidios/edit.blade.php diff --git a/resources/views/ventas/subsidios/pagar.blade.php b/app_old/resources/views/ventas/subsidios/pagar.blade.php similarity index 100% rename from resources/views/ventas/subsidios/pagar.blade.php rename to app_old/resources/views/ventas/subsidios/pagar.blade.php diff --git a/setup/api/config.php b/app_old/setup/api/config.php similarity index 100% rename from setup/api/config.php rename to app_old/setup/api/config.php diff --git a/setup/api/setups.php b/app_old/setup/api/setups.php similarity index 100% rename from setup/api/setups.php rename to app_old/setup/api/setups.php diff --git a/app_old/setup/app.php b/app_old/setup/app.php new file mode 100644 index 0000000..f386aef --- /dev/null +++ b/app_old/setup/app.php @@ -0,0 +1,61 @@ +addDefinitions(['environment' => $__environment]); + } + $folders = [ + 'settings', + 'setups' + ]; + foreach ($folders as $f) { + $folder = implode(DIRECTORY_SEPARATOR, [ + __DIR__, + $f + ]); + if (!file_exists($folder)) { + continue; + } + $files = new DirectoryIterator($folder); + foreach ($files as $file) { + if ($file->isDir() or $file->getExtension() != 'php') { + continue; + } + $builder->addDefinitions($file->getRealPath()); + } + } + + $container = $builder->build(); + $app = Bridge::create($container); + if ($app->getContainer()->has('base_url') and $app->getContainer()->get('base_url') != '') { + $app->setBasePath($app->getContainer()->get('base_url')); + } + $app->addRoutingMiddleware(); + + foreach ($folders as $folder) { + $filename = implode(DIRECTORY_SEPARATOR, [ + __DIR__, + $folder, + 'middleware.php' + ]); + if (!file_exists($filename)) { + continue; + } + include_once $filename; + } + + $app->addErrorMiddleware(true, true, true); + + include_once 'database.php'; + + include_once 'router.php'; + + return $app; +} + +return buildApp($__environment); diff --git a/setup/common/config.php b/app_old/setup/common/config.php similarity index 100% rename from setup/common/config.php rename to app_old/setup/common/config.php diff --git a/app_old/setup/composer.php b/app_old/setup/composer.php new file mode 100644 index 0000000..2d27ee1 --- /dev/null +++ b/app_old/setup/composer.php @@ -0,0 +1,6 @@ +isDir()) { + continue; + } + $builder->addDefinitions($file->getRealPath()); + } +} + +$app = Bridge::create($builder->build()); + +$folder = implode(DIRECTORY_SEPARATOR, [ + __DIR__, + 'middlewares' +]); +if (file_exists($folder)) { + $files = new FilesystemIterator($folder); + foreach ($files as $file) { + if ($file->isDir()) { + continue; + } + require_once $file->getRealPath(); + } +} + +return $app; diff --git a/app_old/ui/composer.php b/app_old/ui/composer.php new file mode 100644 index 0000000..2d27ee1 --- /dev/null +++ b/app_old/ui/composer.php @@ -0,0 +1,6 @@ +add($app->getContainer()->get(App\Middleware\Auth::class)); diff --git a/app_old/ui/middlewares/02_databases.php b/app_old/ui/middlewares/02_databases.php new file mode 100644 index 0000000..3d0841f --- /dev/null +++ b/app_old/ui/middlewares/02_databases.php @@ -0,0 +1,20 @@ +port)) { + $port = $settings->port; + } + $dsn = 'mysql:host=' . $settings->host . ';port=' . $port . ';dbname=' . $settings->database . ';charset=utf8'; + + ORM::configure($dsn, null, $name); + ORM::configure('username', $settings->username, $name); + ORM::configure('password', $settings->password, $name); +} + +$databases = $app->getContainer()->get('databases'); +foreach ($databases as $name => $settings) { + loadDatabase($settings, $name); +} + +Model::$short_table_names = true; diff --git a/app_old/ui/middlewares/98_logs.php b/app_old/ui/middlewares/98_logs.php new file mode 100644 index 0000000..b81e521 --- /dev/null +++ b/app_old/ui/middlewares/98_logs.php @@ -0,0 +1,2 @@ +getContainer()->get(Psr\Log\LoggerInterface::class)); diff --git a/app_old/ui/middlewares/99_routes.php b/app_old/ui/middlewares/99_routes.php new file mode 100644 index 0000000..e3b3da5 --- /dev/null +++ b/app_old/ui/middlewares/99_routes.php @@ -0,0 +1,15 @@ +getContainer()->get('folders')->get('routes'), + 'ui' + ]); + $files = new FilesystemIterator($folder); + foreach ($files as $file) { + if ($file->isDir()) { + continue; + } + include_once $file->getRealPath(); + } +} +buildRoutes($app); diff --git a/app_old/ui/settings/01_env.php b/app_old/ui/settings/01_env.php new file mode 100644 index 0000000..9ee040b --- /dev/null +++ b/app_old/ui/settings/01_env.php @@ -0,0 +1,4 @@ + $_ENV +]; diff --git a/app_old/ui/settings/02_folders.php b/app_old/ui/settings/02_folders.php new file mode 100644 index 0000000..b216fc3 --- /dev/null +++ b/app_old/ui/settings/02_folders.php @@ -0,0 +1,12 @@ + function() { + return new DI\Container([ + 'base' => dirname(__FILE__, 3), + 'resources' => DI\String('{base}/resources'), + 'routes' => DI\String('{resources}/routes'), + 'templates' => DI\String('{resources}/views'), + 'cache' => DI\String('{base}/cache') + ]); + } +]; diff --git a/app_old/ui/settings/03_urls.php b/app_old/ui/settings/03_urls.php new file mode 100644 index 0000000..55d2969 --- /dev/null +++ b/app_old/ui/settings/03_urls.php @@ -0,0 +1,8 @@ + function() { + return [ + 'base' => 'http://localhost:8080' + ]; + } +]; diff --git a/app_old/ui/settings/04_databases.php b/app_old/ui/settings/04_databases.php new file mode 100644 index 0000000..54d689e --- /dev/null +++ b/app_old/ui/settings/04_databases.php @@ -0,0 +1,20 @@ + function(ContainerInterface $container) { + $env = $container->get('env'); + $arr = [ + ORM::DEFAULT_CONNECTION => (object) [ + 'host' => $env['MYSQL_HOST'], + 'database' => $env['MYSQL_DATABASE'], + 'username' => $env['MYSQL_USER'], + 'password' => $env['MYSQL_PASSWORD'] + ] + ]; + if (isset($env['MYSQL_PORT'])) { + $arr[ORM::DEFAULT_CONNECTION]->port = $env['MYSQL_PORT']; + } + return (object) $arr; + } +]; diff --git a/app_old/ui/setups/01_views.php b/app_old/ui/setups/01_views.php new file mode 100644 index 0000000..4a20566 --- /dev/null +++ b/app_old/ui/setups/01_views.php @@ -0,0 +1,20 @@ + function(ContainerInterface $container) { + $folders = $container->get('folders'); + return new Slim\Views\Blade( + $folders->get('templates'), + $folders->get('cache'), + null, + $container->has('urls') ? $container->get('urls') : [] + ); + }, + eftec\bladeone\BladeOne::class => function(ContainerInterface $container) { + return new eftec\bladeone\BladeOne( + $container->get('folders')->get('templates'), + $container->get('folders')->get('cache') + ); + } +]; diff --git a/app_old/ui/setups/03_services.php b/app_old/ui/setups/03_services.php new file mode 100644 index 0000000..af7ff76 --- /dev/null +++ b/app_old/ui/setups/03_services.php @@ -0,0 +1,8 @@ + function(ContainerInterface $container) { + return $container->get(Nyholm\Psr7\Factory\Psr17Factory::class); + } +]; diff --git a/app_old/ui/setups/98_logs.php b/app_old/ui/setups/98_logs.php new file mode 100644 index 0000000..224590a --- /dev/null +++ b/app_old/ui/setups/98_logs.php @@ -0,0 +1,30 @@ + function(ContainerInterface $container) { + return new Monolog\Logger('ui', [ + new Monolog\Handler\FilterHandler( + new Monolog\Handler\RotatingFileHandler('/logs/ui.debug.log'), + Monolog\Level::Debug, + Monolog\Level::Notice + ), + new Monolog\Handler\FilterHandler( + (new Monolog\Handler\RotatingFileHandler('/logs/ui.error.log')) + ->setFormatter(new Monolog\Formatter\LineFormatter(null, null, true)), + Monolog\Level::Warning, + Monolog\Level::Error + ), + new Monolog\Handler\FilterHandler( + new Monolog\Handler\RotatingFileHandler('/logs/ui.critical.log'), + Monolog\Level::Critical + ) + ], [ + $container->get(Monolog\Processor\PsrLogMessageProcessor::class), + $container->get(Monolog\Processor\WebProcessor::class), + $container->get(Monolog\Processor\IntrospectionProcessor::class), + $container->get(Monolog\Processor\MemoryUsageProcessor::class), + $container->get(Monolog\Processor\MemoryPeakUsageProcessor::class) + ]); + } +]; diff --git a/webpack.config.js b/app_old/webpack.config.js similarity index 100% rename from webpack.config.js rename to app_old/webpack.config.js diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php deleted file mode 100644 index 4e2cbdd..0000000 --- a/resources/views/auth/login.blade.php +++ /dev/null @@ -1,17 +0,0 @@ -@extends('auth.base') - -@section('content') - -
    -
    Usuario
    -
    -
    -
    -
    Cláve
    -
    -
    -
    -
    -
    - -@endsection diff --git a/resources/views/layout/menu/login.blade.php b/resources/views/layout/menu/login.blade.php deleted file mode 100644 index 2e310b1..0000000 --- a/resources/views/layout/menu/login.blade.php +++ /dev/null @@ -1,8 +0,0 @@ - diff --git a/setup/app.php b/setup/app.php deleted file mode 100644 index 42a9b0e..0000000 --- a/setup/app.php +++ /dev/null @@ -1,57 +0,0 @@ -addDefinitions(['environment' => $__environment]); -} -foreach ($folders as $f) { - $folder = implode(DIRECTORY_SEPARATOR, [ - __DIR__, - $f - ]); - if (!file_exists($folder)) { - continue; - } - $files = new DirectoryIterator($folder); - foreach ($files as $file) { - if ($file->isDir() or $file->getExtension() != 'php') { - continue; - } - $builder->addDefinitions($file->getRealPath()); - } -} - -$container = $builder->build(); -$app = Bridge::create($container); -if ($app->getContainer()->has('base_url') and $app->getContainer()->get('base_url') != '') { - $app->setBasePath($app->getContainer()->get('base_url')); -} -$app->addRoutingMiddleware(); - -foreach ($folders as $folder) { - $filename = implode(DIRECTORY_SEPARATOR, [ - __DIR__, - $folder, - 'middleware.php' - ]); - if (!file_exists($filename)) { - continue; - } - include_once $filename; -} - -$app->addErrorMiddleware(true, true, true); - -include_once 'database.php'; - -include_once 'router.php'; - -return $app; From b7fc538e782db2e05f8fcef9c57313e86efa3e79 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Mon, 24 Jul 2023 20:52:13 -0400 Subject: [PATCH 003/163] Old Version --- .adminer.env | 2 - .adminer.env.sample | 2 - .db.env | 5 - .db.env.sample | 4 - .env.sample | 3 - aldarien/asset/.gitignore | 11 - aldarien/asset/LICENSE | 21 - aldarien/asset/README.md | 2 - aldarien/asset/app/Contract/Asset.php | 21 - aldarien/asset/app/Helper/functions.php | 5 - aldarien/asset/app/Service/Asset.php | 88 -- aldarien/asset/composer.json | 26 - aldarien/asset/phpunit.xml | 17 - aldarien/asset/tests/AssetTest.php | 25 - aldarien/config/.gitignore | 13 - aldarien/config/.travis.yml | 3 - aldarien/config/LICENSE | 21 - aldarien/config/README.md | 4 - aldarien/config/app/Contract/Config.php | 31 - aldarien/config/app/Contract/YamlWrapper.php | 21 - aldarien/config/app/Helper/functions.php | 9 - aldarien/config/app/Service/Config.php | 150 ---- aldarien/config/bootstrap/autoload.php | 3 - aldarien/config/composer.json | 28 - aldarien/config/phpunit.xml | 17 - aldarien/config/tests/ConfigTest.php | 90 -- aldarien/contract/.gitignore | 6 - aldarien/contract/LICENSE | 21 - aldarien/contract/app/Definition/Contract.php | 20 - aldarien/contract/composer.json | 18 - aldarien/format/.gitignore | 11 - aldarien/format/LICENSE | 21 - aldarien/format/README.md | 2 - aldarien/format/app/Helper/Format.php | 43 - aldarien/format/composer.json | 23 - aldarien/format/config/app.php | 5 - aldarien/format/phpunit.xml | 17 - aldarien/format/tests/FormatTest.php | 59 -- aldarien/response/.gitignore | 7 - aldarien/response/LICENSE | 21 - aldarien/response/README.md | 2 - aldarien/response/app/Contract/Response.php | 27 - aldarien/response/app/Helper/functions.php | 11 - aldarien/response/app/Service/Response.php | 62 -- aldarien/response/bootstrap/autoload.php | 3 - aldarien/response/composer.json | 26 - aldarien/response/phpunit.xml | 17 - aldarien/response/tests/ResponseTest.php | 22 - aldarien/root/.gitignore | 5 - aldarien/root/LICENSE | 21 - aldarien/root/README.md | 22 - aldarien/root/app/Helper/functions.php | 5 - aldarien/root/composer.json | 21 - aldarien/root/phpunit.xml | 19 - aldarien/root/src/Root.php | 48 - aldarien/root/tests/RootTest.php | 61 -- aldarien/session/.gitignore | 11 - aldarien/session/LICENSE | 21 - aldarien/session/README.md | 2 - aldarien/session/app/Contract/Session.php | 29 - aldarien/session/composer.json | 24 - aldarien/url/.gitignore | 12 - aldarien/url/LICENSE | 21 - aldarien/url/README.md | 2 - aldarien/url/app/Contract/URL.php | 21 - aldarien/url/app/Helper/functions.php | 8 - aldarien/url/app/Service/URL.php | 83 -- aldarien/url/composer.json | 29 - aldarien/view/.gitignore | 10 - aldarien/view/LICENSE | 21 - aldarien/view/README.md | 2 - aldarien/view/app/Contract/View.php | 30 - aldarien/view/app/Helper/functions.php | 5 - aldarien/view/app/Service/View.php | 27 - ...fae499b6e99106ff3bd673b8eb7319ae68e7ae.php | 9 - aldarien/view/composer.json | 28 - aldarien/view/config/locations.php | 8 - aldarien/view/phpunit.xml | 17 - aldarien/view/public/index.php | 5 - aldarien/view/resources/views/base.blade.php | 9 - aldarien/view/tests/ViewTest.php | 22 - app/Alias/Connection.php | 50 -- app/Alias/Excel/Style/Mes.php | 18 - app/Alias/Format.php | 12 - app/Alias/Model.php | 87 -- app/Alias/NewEstado.php | 20 - app/Alias/NewModel.php | 9 - app/Alias/NewTipo.php | 15 - app/Alias/OldModel.php | 8 - app/Alias/PHPExcel.php | 155 ---- app/Alias/RemoteConnection.php | 17 - app/Command/Money/Get.php | 87 -- app/Command/Money/Lookup.php | 52 -- app/Contract/Auth.php | 27 - app/Contract/Route.php | 27 - app/Controller/API/Unidades.php | 41 - app/Controller/Admin.php | 233 ----- app/Controller/Ajax.php | 215 ----- app/Controller/Auth.php | 56 -- app/Controller/Bonos.php | 67 -- app/Controller/Buscar.php | 340 ------- app/Controller/Cierres.php | 428 --------- app/Controller/Comentarios.php | 39 - app/Controller/Contabilidad.php | 100 --- app/Controller/Creditos.php | 207 ----- app/Controller/Cuotas.php | 230 ----- app/Controller/Devoluciones.php | 19 - app/Controller/Escrituras.php | 212 ----- app/Controller/FormaPago.php | 98 --- app/Controller/Informes.php | 832 ------------------ app/Controller/Inmobiliarias.php | 74 -- app/Controller/Operadores.php | 47 - app/Controller/Other.php | 71 -- app/Controller/Pagares.php | 271 ------ app/Controller/Pagos.php | 358 -------- app/Controller/Pies.php | 104 --- app/Controller/Postventas.php | 69 -- app/Controller/Precios.php | 177 ---- app/Controller/Propietarios.php | 129 --- app/Controller/ProyectoTipoUnidades.php | 77 -- app/Controller/Proyectos.php | 327 ------- app/Controller/Reajustes.php | 90 -- app/Controller/Registros.php | 39 - app/Controller/Subsidios.php | 184 ---- app/Controller/Temas.php | 111 --- app/Controller/Unidades.php | 126 --- app/Controller/UnidadesBloqueadas.php | 83 -- app/Controller/Ventas.php | 605 ------------- app/Definition/Controller.php | 31 - app/Definition/hasEstado.php | 38 - app/Definition/hasRUT.php | 20 - app/Exception/PropertyNotFound.php | 16 - app/Helper/Color.php | 169 ---- app/Helper/Line.php | 61 -- app/Helper/functions.php | 128 --- app/Service/Auth.php | 163 ---- app/Service/Borrador.php | 118 --- app/Service/DBToModel.php | 158 ---- app/Service/Factory.php | 204 ----- app/Service/Informador.php | 463 ---------- app/Service/Informe/Contabilidad/Resumen.php | 190 ---- app/Service/Informe/Informe.php | 55 -- app/Service/Money.php | 55 -- app/Service/Register.php | 34 - app/Service/Remote.php | 19 - app/Service/Replacer.php | 127 --- app/Service/Route.php | 131 --- bin/Pipfile | 12 - bin/console | 3 - bin/index.php | 8 - bin/informes/Pipfile | 16 - bin/informes/app.py | 14 - bin/informes/controllers/ventas.py | 141 --- bootstrap/autoload.php | 8 - bootstrap/database.php | 29 - bootstrap/dotenv.php | 12 - bootstrap/errors.php | 7 - bootstrap/logs.php | 26 - bootstrap/routes.php | 21 - composer.json | 68 -- config/app.php | 9 - config/databases.php | 24 - config/incoviba.php | 6 - config/locations.php | 16 - fontify.json | 7 - 165 files changed, 10974 deletions(-) delete mode 100644 .adminer.env delete mode 100644 .adminer.env.sample delete mode 100644 .db.env delete mode 100644 .db.env.sample delete mode 100644 .env.sample delete mode 100644 aldarien/asset/.gitignore delete mode 100644 aldarien/asset/LICENSE delete mode 100644 aldarien/asset/README.md delete mode 100644 aldarien/asset/app/Contract/Asset.php delete mode 100644 aldarien/asset/app/Helper/functions.php delete mode 100644 aldarien/asset/app/Service/Asset.php delete mode 100644 aldarien/asset/composer.json delete mode 100644 aldarien/asset/phpunit.xml delete mode 100644 aldarien/asset/tests/AssetTest.php delete mode 100644 aldarien/config/.gitignore delete mode 100644 aldarien/config/.travis.yml delete mode 100644 aldarien/config/LICENSE delete mode 100644 aldarien/config/README.md delete mode 100644 aldarien/config/app/Contract/Config.php delete mode 100644 aldarien/config/app/Contract/YamlWrapper.php delete mode 100644 aldarien/config/app/Helper/functions.php delete mode 100644 aldarien/config/app/Service/Config.php delete mode 100644 aldarien/config/bootstrap/autoload.php delete mode 100644 aldarien/config/composer.json delete mode 100644 aldarien/config/phpunit.xml delete mode 100644 aldarien/config/tests/ConfigTest.php delete mode 100644 aldarien/contract/.gitignore delete mode 100644 aldarien/contract/LICENSE delete mode 100644 aldarien/contract/app/Definition/Contract.php delete mode 100644 aldarien/contract/composer.json delete mode 100644 aldarien/format/.gitignore delete mode 100644 aldarien/format/LICENSE delete mode 100644 aldarien/format/README.md delete mode 100644 aldarien/format/app/Helper/Format.php delete mode 100644 aldarien/format/composer.json delete mode 100644 aldarien/format/config/app.php delete mode 100644 aldarien/format/phpunit.xml delete mode 100644 aldarien/format/tests/FormatTest.php delete mode 100644 aldarien/response/.gitignore delete mode 100644 aldarien/response/LICENSE delete mode 100644 aldarien/response/README.md delete mode 100644 aldarien/response/app/Contract/Response.php delete mode 100644 aldarien/response/app/Helper/functions.php delete mode 100644 aldarien/response/app/Service/Response.php delete mode 100644 aldarien/response/bootstrap/autoload.php delete mode 100644 aldarien/response/composer.json delete mode 100644 aldarien/response/phpunit.xml delete mode 100644 aldarien/response/tests/ResponseTest.php delete mode 100644 aldarien/root/.gitignore delete mode 100644 aldarien/root/LICENSE delete mode 100644 aldarien/root/README.md delete mode 100644 aldarien/root/app/Helper/functions.php delete mode 100644 aldarien/root/composer.json delete mode 100644 aldarien/root/phpunit.xml delete mode 100644 aldarien/root/src/Root.php delete mode 100644 aldarien/root/tests/RootTest.php delete mode 100644 aldarien/session/.gitignore delete mode 100644 aldarien/session/LICENSE delete mode 100644 aldarien/session/README.md delete mode 100644 aldarien/session/app/Contract/Session.php delete mode 100644 aldarien/session/composer.json delete mode 100644 aldarien/url/.gitignore delete mode 100644 aldarien/url/LICENSE delete mode 100644 aldarien/url/README.md delete mode 100644 aldarien/url/app/Contract/URL.php delete mode 100644 aldarien/url/app/Helper/functions.php delete mode 100644 aldarien/url/app/Service/URL.php delete mode 100644 aldarien/url/composer.json delete mode 100644 aldarien/view/.gitignore delete mode 100644 aldarien/view/LICENSE delete mode 100644 aldarien/view/README.md delete mode 100644 aldarien/view/app/Contract/View.php delete mode 100644 aldarien/view/app/Helper/functions.php delete mode 100644 aldarien/view/app/Service/View.php delete mode 100644 aldarien/view/cache/26fae499b6e99106ff3bd673b8eb7319ae68e7ae.php delete mode 100644 aldarien/view/composer.json delete mode 100644 aldarien/view/config/locations.php delete mode 100644 aldarien/view/phpunit.xml delete mode 100644 aldarien/view/public/index.php delete mode 100644 aldarien/view/resources/views/base.blade.php delete mode 100644 aldarien/view/tests/ViewTest.php delete mode 100644 app/Alias/Connection.php delete mode 100644 app/Alias/Excel/Style/Mes.php delete mode 100644 app/Alias/Format.php delete mode 100644 app/Alias/Model.php delete mode 100644 app/Alias/NewEstado.php delete mode 100644 app/Alias/NewModel.php delete mode 100644 app/Alias/NewTipo.php delete mode 100644 app/Alias/OldModel.php delete mode 100644 app/Alias/PHPExcel.php delete mode 100644 app/Alias/RemoteConnection.php delete mode 100644 app/Command/Money/Get.php delete mode 100644 app/Command/Money/Lookup.php delete mode 100644 app/Contract/Auth.php delete mode 100644 app/Contract/Route.php delete mode 100644 app/Controller/API/Unidades.php delete mode 100644 app/Controller/Admin.php delete mode 100644 app/Controller/Ajax.php delete mode 100644 app/Controller/Auth.php delete mode 100644 app/Controller/Bonos.php delete mode 100644 app/Controller/Buscar.php delete mode 100644 app/Controller/Cierres.php delete mode 100644 app/Controller/Comentarios.php delete mode 100644 app/Controller/Contabilidad.php delete mode 100644 app/Controller/Creditos.php delete mode 100644 app/Controller/Cuotas.php delete mode 100644 app/Controller/Devoluciones.php delete mode 100644 app/Controller/Escrituras.php delete mode 100644 app/Controller/FormaPago.php delete mode 100644 app/Controller/Informes.php delete mode 100644 app/Controller/Inmobiliarias.php delete mode 100644 app/Controller/Operadores.php delete mode 100644 app/Controller/Other.php delete mode 100644 app/Controller/Pagares.php delete mode 100644 app/Controller/Pagos.php delete mode 100644 app/Controller/Pies.php delete mode 100644 app/Controller/Postventas.php delete mode 100644 app/Controller/Precios.php delete mode 100644 app/Controller/Propietarios.php delete mode 100644 app/Controller/ProyectoTipoUnidades.php delete mode 100644 app/Controller/Proyectos.php delete mode 100644 app/Controller/Reajustes.php delete mode 100644 app/Controller/Registros.php delete mode 100644 app/Controller/Subsidios.php delete mode 100644 app/Controller/Temas.php delete mode 100644 app/Controller/Unidades.php delete mode 100644 app/Controller/UnidadesBloqueadas.php delete mode 100644 app/Controller/Ventas.php delete mode 100644 app/Definition/Controller.php delete mode 100644 app/Definition/hasEstado.php delete mode 100644 app/Definition/hasRUT.php delete mode 100644 app/Exception/PropertyNotFound.php delete mode 100644 app/Helper/Color.php delete mode 100644 app/Helper/Line.php delete mode 100644 app/Helper/functions.php delete mode 100644 app/Service/Auth.php delete mode 100644 app/Service/Borrador.php delete mode 100644 app/Service/DBToModel.php delete mode 100644 app/Service/Factory.php delete mode 100644 app/Service/Informador.php delete mode 100644 app/Service/Informe/Contabilidad/Resumen.php delete mode 100644 app/Service/Informe/Informe.php delete mode 100644 app/Service/Money.php delete mode 100644 app/Service/Register.php delete mode 100644 app/Service/Remote.php delete mode 100644 app/Service/Replacer.php delete mode 100644 app/Service/Route.php delete mode 100644 bin/Pipfile delete mode 100644 bin/console delete mode 100644 bin/index.php delete mode 100644 bin/informes/Pipfile delete mode 100644 bin/informes/app.py delete mode 100644 bin/informes/controllers/ventas.py delete mode 100644 bootstrap/autoload.php delete mode 100644 bootstrap/database.php delete mode 100644 bootstrap/dotenv.php delete mode 100644 bootstrap/errors.php delete mode 100644 bootstrap/logs.php delete mode 100644 bootstrap/routes.php delete mode 100644 composer.json delete mode 100644 config/app.php delete mode 100644 config/databases.php delete mode 100644 config/incoviba.php delete mode 100644 config/locations.php delete mode 100644 fontify.json diff --git a/.adminer.env b/.adminer.env deleted file mode 100644 index 7e78794..0000000 --- a/.adminer.env +++ /dev/null @@ -1,2 +0,0 @@ -ADMINER_DESIGN=dracula -ADMINER_PLUGINS=dump-json diff --git a/.adminer.env.sample b/.adminer.env.sample deleted file mode 100644 index 7e78794..0000000 --- a/.adminer.env.sample +++ /dev/null @@ -1,2 +0,0 @@ -ADMINER_DESIGN=dracula -ADMINER_PLUGINS=dump-json diff --git a/.db.env b/.db.env deleted file mode 100644 index 16b5aed..0000000 --- a/.db.env +++ /dev/null @@ -1,5 +0,0 @@ -MYSQL_DATABASE=incoviba -MYSQL_PASSWORD=5GQYFvRjVw2A4KcD -MYSQL_ROOT_PASSWORD=password -MYSQL_USER=incoviba -MYSQL_PORT=3307 diff --git a/.db.env.sample b/.db.env.sample deleted file mode 100644 index 18b1117..0000000 --- a/.db.env.sample +++ /dev/null @@ -1,4 +0,0 @@ -MYSQL_DATABASE= -MYSQL_PASSWORD= -MYSQL_ROOT_PASSWORD= -MYSQL_USER= diff --git a/.env.sample b/.env.sample deleted file mode 100644 index 76074d2..0000000 --- a/.env.sample +++ /dev/null @@ -1,3 +0,0 @@ -COMPOSE_PROFILES= -BASE_URL= -MYSQL_HOST= diff --git a/aldarien/asset/.gitignore b/aldarien/asset/.gitignore deleted file mode 100644 index 3b12249..0000000 --- a/aldarien/asset/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -composer.phar -/vendor/ - -# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file -# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file -# composer.lock - -#Eclipse IDE -.settings -.buildpath -.project diff --git a/aldarien/asset/LICENSE b/aldarien/asset/LICENSE deleted file mode 100644 index 55dc05a..0000000 --- a/aldarien/asset/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2017 Aldarien - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/aldarien/asset/README.md b/aldarien/asset/README.md deleted file mode 100644 index 1580798..0000000 --- a/aldarien/asset/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# asset -Asset manager module for my apps diff --git a/aldarien/asset/app/Contract/Asset.php b/aldarien/asset/app/Contract/Asset.php deleted file mode 100644 index 30b02c2..0000000 --- a/aldarien/asset/app/Contract/Asset.php +++ /dev/null @@ -1,21 +0,0 @@ -get($identifier); - } -} -?> diff --git a/aldarien/asset/app/Helper/functions.php b/aldarien/asset/app/Helper/functions.php deleted file mode 100644 index b0688e2..0000000 --- a/aldarien/asset/app/Helper/functions.php +++ /dev/null @@ -1,5 +0,0 @@ - \ No newline at end of file diff --git a/aldarien/asset/app/Service/Asset.php b/aldarien/asset/app/Service/Asset.php deleted file mode 100644 index e7c36b7..0000000 --- a/aldarien/asset/app/Service/Asset.php +++ /dev/null @@ -1,88 +0,0 @@ -dir = config('locations.public'); - } - public function get($identifier) - { - $asset = $this->find($identifier); - return $asset->url; - } - protected function find($identifier) - { - $type = $this->getType($identifier); - $asset = null; - if ($type == false) { - foreach (array_keys($this->assets) as $type) { - if (($asset = $this->getAsset($identifier, $type))) { - break; - } - } - } else { - $asset = $this->getAsset($identifier, $type); - } - return $asset; - } - protected function getType($identifier) - { - if (strpos($identifier, '.') !== false) { - list($name, $ext) = explode('.', $identifier); - return $ext; - } - return false; - } - protected function getAsset($identifier, $type) - { - if (!isset($this->assets[$type])) { - $this->loadAssets($type); - } - if (!isset($this->assets[$type])) { - return null; - } - - foreach ($this->assets[$type] as $asset) { - if ($this->compareIdentifier($asset, $identifier)) { - return $asset; - } - } - return null; - } - protected function loadAssets($type) - { - $dir = $this->dir . '/' . $type . '/*.' . $type; - $files = glob($dir); - foreach ($files as $file) { - $url = $this->url($file); - $identifier = pathinfo($file)['filename']; - - $this->assets[$type] []= (object) ['identifier' => $identifier, 'url' => $url, 'type' => $type]; - } - } - protected function url($file) - { - $url = '/' . config('app.project') . '/' . str_replace('\\', '/', str_replace(realpath(config('locations.public')), '', dirname(realpath($file)))) . '/' . basename(realpath($file)); - $url = preg_replace('/\/+/', '/', $url); - return $url; - } - protected function compareIdentifier($asset, $identifier) - { - if (strpos($identifier, '.') !== false) { - list($name, $ext) = explode('.', $identifier); - if ($asset->identifier == $name and $asset->type == $ext) { - return true; - } - } else { - if ($asset->identifier == $identifier) { - return true; - } - } - return false; - } -} diff --git a/aldarien/asset/composer.json b/aldarien/asset/composer.json deleted file mode 100644 index dd2c217..0000000 --- a/aldarien/asset/composer.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name" : "aldarien/asset", - "description" : "Asset manager module for my apps", - "type" : "library", - "require" : { - "aldarien/config" : "*", - "aldarien/contract" : "*" - }, - "require-dev" : { - "phpunit/phpunit" : "*" - }, - "license" : "MIT", - "authors" : [{ - "name" : "Aldarien", - "email" : "aldarien85@gmail.com" - } - ], - "autoload" : { - "psr-4" : { - "App\\" : "app" - }, - "files": [ - "app/Helper/functions.php" - ] - } -} diff --git a/aldarien/asset/phpunit.xml b/aldarien/asset/phpunit.xml deleted file mode 100644 index e60ecbd..0000000 --- a/aldarien/asset/phpunit.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - ./tests/ - - - - - ./app - - - \ No newline at end of file diff --git a/aldarien/asset/tests/AssetTest.php b/aldarien/asset/tests/AssetTest.php deleted file mode 100644 index e53f0ad..0000000 --- a/aldarien/asset/tests/AssetTest.php +++ /dev/null @@ -1,25 +0,0 @@ -assertEquals(asset('style.css'), '/css/style.css'); - } -} -?> \ No newline at end of file diff --git a/aldarien/config/.gitignore b/aldarien/config/.gitignore deleted file mode 100644 index 47c4114..0000000 --- a/aldarien/config/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -composer.phar -/vendor/ - -# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file -# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file -# composer.lock - -config - -# Eclipse IDE -.settings -.buildpath -.project \ No newline at end of file diff --git a/aldarien/config/.travis.yml b/aldarien/config/.travis.yml deleted file mode 100644 index a792980..0000000 --- a/aldarien/config/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: php -php: '7.1' -install: composer update diff --git a/aldarien/config/LICENSE b/aldarien/config/LICENSE deleted file mode 100644 index 55dc05a..0000000 --- a/aldarien/config/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2017 Aldarien - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/aldarien/config/README.md b/aldarien/config/README.md deleted file mode 100644 index dfed35b..0000000 --- a/aldarien/config/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# config -Config module that recovers configuration files - -[![Build Status](https://travis-ci.org/Aldarien/config.svg?branch=1.0.1)](https://travis-ci.org/Aldarien/config) diff --git a/aldarien/config/app/Contract/Config.php b/aldarien/config/app/Contract/Config.php deleted file mode 100644 index 9664aca..0000000 --- a/aldarien/config/app/Contract/Config.php +++ /dev/null @@ -1,31 +0,0 @@ -get($name); - } - public static function set($name, $value) - { - $instance = self::getInstance(); - return $instance->set($name, $value); - } - public static function addFile($filename) - { - $instance = self::getInstance(); - return $instance->loadFile($filename); - } -} -?> diff --git a/aldarien/config/app/Contract/YamlWrapper.php b/aldarien/config/app/Contract/YamlWrapper.php deleted file mode 100644 index 0ab60f6..0000000 --- a/aldarien/config/app/Contract/YamlWrapper.php +++ /dev/null @@ -1,21 +0,0 @@ - \ No newline at end of file diff --git a/aldarien/config/app/Helper/functions.php b/aldarien/config/app/Helper/functions.php deleted file mode 100644 index e073f18..0000000 --- a/aldarien/config/app/Helper/functions.php +++ /dev/null @@ -1,9 +0,0 @@ - diff --git a/aldarien/config/app/Service/Config.php b/aldarien/config/app/Service/Config.php deleted file mode 100644 index 072e38f..0000000 --- a/aldarien/config/app/Service/Config.php +++ /dev/null @@ -1,150 +0,0 @@ -dir = $dir; - $this->load(); - } - protected function load() - { - $files = glob($this->dir . '/*.{php,json,yml}', GLOB_BRACE); - foreach ($files as $file) { - $info = pathinfo($file); - $name = $info['filename']; - - $d = $this->getData($file); - $data[$name] = $d; - $data = array_merge($data, $this->translateArray($d, $name)); - foreach ($data as $key => $value) { - $this->add($key, $value); - } - } - } - public function loadFile(string $filename) - { - if (!file_exists(realpath($filename))) { - return false; - } - $info = pathinfo($filename); - $name = $info['filename']; - $d = $this->getData($filename); - $data[$name] = $d; - $data = array_merge($data, $this->translateArray($d, $name)); - foreach ($data as $key => $value) { - $this->add($key, $value); - } - return true; - } - protected function getData($filename) - { - $info = pathinfo($filename); - - switch ($info['extension']) { - case 'php': - return include_once $filename; - case 'json': - return json_decode(file_get_contents($filename), true); - case 'yml': - return YamlWrapper::load($filename); - default: - throw new \DomainException('Invalid file extension for ' . $filename); - } - } - protected function translateArray($array, $level) - { - $output = []; - foreach ($array as $k1 => $l1) { - $key = $level . '.' . $k1; - if (is_array($l1)) { - $output[$key] = $l1; - $output = array_merge($output, $this->translateArray($l1, $key)); - } else { - $output[$key] = $l1; - } - } - return $output; - } - protected function add($field, $value) - { - if (isset($this->data[$field])) { - if ($this->data[$field] == $value) { - return; - } - if (is_array($this->data[$field])) { - $this->data[$field] = $this->merge($this->data[$field], $this->replace($value)); - } else { - $this->data[$field] = $this->replace($value); - } - } else { - $this->data[$field] = $this->replace($value); - } - } - protected function merge($arr1, $arr2) - { - $output = $arr1; - foreach ($arr2 as $k => $value) { - if (isset($arr1[$k])) { - if ($arr1[$k] == $value) { - continue; - } - if (is_array($arr1[$k])) { - $output[$k] = $this->merge($arr1[$k], $value); - } else { - $output[$k] = array_merge([$arr1[$k]], $value); - } - } else { - $output[$k] = $value; - } - } - return $output; - } - protected function replace($value) - { - if (is_array($value)) { - foreach ($value as $k => $v) { - $value[$k] = $this->replace($v); - } - return $value; - } - if (strpos($value, '{') !== false) { - while(strpos($value, '{') !== false) { - $ini = strpos($value, '{') + 1; - $end = strpos($value, '}', $ini); - $rep = substr($value, $ini, $end - $ini); - $new = $this->get($rep); - if ($new === null) { - $new = ''; - } - $value = str_replace('{' . $rep . '}', $new, $value); - } - } - return $value; - } - - public function get($name = null) - { - if ($name == null) { - return $this->data; - } - if (isset($this->data[$name])) { - return $this->data[$name]; - } - return null; - } - public function set($name, $value) - { - $this->add($name, $value); - } -} -?> diff --git a/aldarien/config/bootstrap/autoload.php b/aldarien/config/bootstrap/autoload.php deleted file mode 100644 index 42765bd..0000000 --- a/aldarien/config/bootstrap/autoload.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/aldarien/config/composer.json b/aldarien/config/composer.json deleted file mode 100644 index ff4255b..0000000 --- a/aldarien/config/composer.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "aldarien/config", - "description": "Config module for my apps", - "type": "library", - "license": "MIT", - "authors": [ - { - "name": "Aldarien", - "email": "aldarien85@gmail.com" - } - ], - "require": { - "aldarien/contract": "*", - "aldarien/root": "*", - "symfony/yaml": "*" - }, - "autoload": { - "psr-4": { - "App\\": "app" - }, - "files": [ - "app/Helper/functions.php" - ] - }, - "require-dev": { - "phpunit/phpunit": "^6.3" - } -} diff --git a/aldarien/config/phpunit.xml b/aldarien/config/phpunit.xml deleted file mode 100644 index db312e1..0000000 --- a/aldarien/config/phpunit.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - ./tests/ - - - - - ./app - - - \ No newline at end of file diff --git a/aldarien/config/tests/ConfigTest.php b/aldarien/config/tests/ConfigTest.php deleted file mode 100644 index 187e0a3..0000000 --- a/aldarien/config/tests/ConfigTest.php +++ /dev/null @@ -1,90 +0,0 @@ - 'Config', 'test_array' => ['data1' => 1, 'data2' => 2]]; ?>"; - file_put_contents(dirname(__DIR__) . '/config/app.php', $str); - $data = ['name' => 'Config', 'test_array' => ['data1' => 1, 'data2' => 2]]; - file_put_contents(dirname(__DIR__) . '/config/json.json', json_encode($data)); - file_put_contents(dirname(__DIR__) . '/config/yaml.yml', YamlWrapper::dump($data)); - $data = ['last_name' => 'Config']; - file_put_contents(dirname(__DIR__) . '/config/yaml.json', json_encode($data)); - } - public function testGetNamePhp() - { - $name = 'Config'; - - $this->assertEquals($name, config('app.name')); - } - public function testGetNameJson() - { - $name = 'Config'; - - $this->assertEquals($name, config('json.name')); - } - public function testGetNameYaml() - { - $name = 'Config'; - - $this->assertEquals($name, config('yaml.name')); - } - public function testSetNamehp() - { - $new_name = 'Config_Test'; - config('app.name', $new_name); - $this->assertEquals($new_name, config('app.name')); - } - public function testSetNameJson() - { - $new_name = 'Config_Test'; - config('json.name', $new_name); - $this->assertEquals($new_name, config('json.name')); - } - public function testSetNameYaml() - { - $new_name = 'Config_Test'; - config('yaml.name', $new_name); - $this->assertEquals($new_name, config('yaml.name')); - } - public function testArrayGetPhp() - { - $this->assertArrayHasKey('data1', config('app.test_array')); - } - public function testArrayGetJson() - { - $this->assertArrayHasKey('data1', config('json.test_array')); - } - public function testArrayGetYaml() - { - $this->assertArrayHasKey('data1', config('yaml.test_array')); - } - public function testSameSectionName() - { - $this->assertEquals('Config', config('yaml.last_name')); - } - public function testDuplicateValue() - { - config('json.name', 'Config2'); - $this->assertEquals('Config2', config('json.name')); - } - public function testAddFile() - { - $filename = dirname(__DIR__) . '/composer.json'; - App\Contract\Config::addFile($filename); - $this->assertEquals('aldarien/config', config('composer.name')); - } - public function tearDown() - { - unlink(dirname(__DIR__) . '/config/app.php'); - unlink(dirname(__DIR__) . '/config/json.json'); - unlink(dirname(__DIR__) . '/config/yaml.yml'); - unlink(dirname(__DIR__) . '/config/yaml.json'); - rmdir(dirname(__DIR__) . '/config'); - } -} -?> \ No newline at end of file diff --git a/aldarien/contract/.gitignore b/aldarien/contract/.gitignore deleted file mode 100644 index c422267..0000000 --- a/aldarien/contract/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -composer.phar -/vendor/ - -# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file -# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file -# composer.lock diff --git a/aldarien/contract/LICENSE b/aldarien/contract/LICENSE deleted file mode 100644 index 55dc05a..0000000 --- a/aldarien/contract/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2017 Aldarien - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/aldarien/contract/app/Definition/Contract.php b/aldarien/contract/app/Definition/Contract.php deleted file mode 100644 index 4cc88ca..0000000 --- a/aldarien/contract/app/Definition/Contract.php +++ /dev/null @@ -1,20 +0,0 @@ - diff --git a/aldarien/contract/composer.json b/aldarien/contract/composer.json deleted file mode 100644 index 96ef067..0000000 --- a/aldarien/contract/composer.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "aldarien/contract", - "description": "Contract trait for my apps", - "type": "library", - "license": "MIT", - "authors": [ - { - "name": "Aldarien", - "email": "aldarien85@gmail.com" - } - ], - "require": {}, - "autoload": { - "psr-4": { - "App\\": "app" - } - } -} diff --git a/aldarien/format/.gitignore b/aldarien/format/.gitignore deleted file mode 100644 index 6ee50e6..0000000 --- a/aldarien/format/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -composer.phar -/vendor/ - -# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file -# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file -# composer.lock - -# Eclipse IDE -.settings -.buildpath -.project \ No newline at end of file diff --git a/aldarien/format/LICENSE b/aldarien/format/LICENSE deleted file mode 100644 index 55dc05a..0000000 --- a/aldarien/format/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2017 Aldarien - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/aldarien/format/README.md b/aldarien/format/README.md deleted file mode 100644 index d4f839f..0000000 --- a/aldarien/format/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# format -Module for formatting data, mostly numbers diff --git a/aldarien/format/app/Helper/Format.php b/aldarien/format/app/Helper/Format.php deleted file mode 100644 index 9836f38..0000000 --- a/aldarien/format/app/Helper/Format.php +++ /dev/null @@ -1,43 +0,0 @@ -format("d \d\\e F Y"); - } - public static function shortDate(string $date) - { - $d = \Carbon\Carbon::parse($date, config('app.timezone')); - return $d->format('d-m-Y'); - } - public static function localDate(string $date) - { - $d = \Carbon\Carbon::parse($date, config('app.timezone')); - setlocale(LC_TIME, 'es'); - return $d->formatLocalized('%d de %B de %Y'); - } - public static function m2(float $number, bool $print = false) - { - return self::number($number, 2) . (($print) ? ' m²' : ''); - } - public static function percent(float $number, bool $print = false) - { - return self::number($number, 2) . (($print) ? '%' : ''); - } -} -?> \ No newline at end of file diff --git a/aldarien/format/composer.json b/aldarien/format/composer.json deleted file mode 100644 index 59d058d..0000000 --- a/aldarien/format/composer.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name" : "aldarien/format", - "description" : "Module for formatting data, mostly numbers", - "type" : "library", - "require-dev" : { - "phpunit/phpunit" : "*", - "aldarien/config": "*" - }, - "license" : "MIT", - "authors" : [{ - "name" : "Aldarien", - "email" : "aldarien85@gmail.com" - } - ], - "autoload" : { - "psr-4" : { - "App\\" : "app" - } - }, - "require": { - "nesbot/carbon": "^2" - } -} diff --git a/aldarien/format/config/app.php b/aldarien/format/config/app.php deleted file mode 100644 index 9e747f9..0000000 --- a/aldarien/format/config/app.php +++ /dev/null @@ -1,5 +0,0 @@ - 'America/Santiago' -]; -?> \ No newline at end of file diff --git a/aldarien/format/phpunit.xml b/aldarien/format/phpunit.xml deleted file mode 100644 index e60ecbd..0000000 --- a/aldarien/format/phpunit.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - ./tests/ - - - - - ./app - - - \ No newline at end of file diff --git a/aldarien/format/tests/FormatTest.php b/aldarien/format/tests/FormatTest.php deleted file mode 100644 index bcc6bd5..0000000 --- a/aldarien/format/tests/FormatTest.php +++ /dev/null @@ -1,59 +0,0 @@ -number, 3); - $this->assertEquals($output, $result); - } - public function testPesosPrint() - { - $output = '$ 5.049.872'; - $result = Format::pesos($this->number, true); - $this->assertEquals($output, $result); - } - public function testUFPrint() - { - $output = '5.049.872,32 UF'; - $result = Format::ufs($this->number, true); - $this->assertEquals($output, $result); - } - public function testDate() - { - $output = '25 de March 2016'; - $result = Format::date($this->date); - $this->assertEquals($output, $result); - } - public function testShortDate() - { - $output = '25-03-2016'; - $result = Format::shortDate($this->date); - $this->assertEquals($output, $result); - } - public function testLocalDate() - { - $output = '25 de marzo de 2016'; - $result = Format::localDate($this->date); - $this->assertEquals($output, $result); - } - public function testM2Print() - { - $output = '5.049.872,32 m²'; - $result = Format::m2($this->number, true); - $this->assertEquals($output, $result); - } - public function testPercentPrint() - { - $output = '5.049.872,32%'; - $result = Format::percent($this->number, true); - $this->assertEquals($output, $result); - } -} -?> \ No newline at end of file diff --git a/aldarien/response/.gitignore b/aldarien/response/.gitignore deleted file mode 100644 index 265bf84..0000000 --- a/aldarien/response/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -#Eclipse IDE -.settings -.buildpath -.project - -#Composer -vendor diff --git a/aldarien/response/LICENSE b/aldarien/response/LICENSE deleted file mode 100644 index 55dc05a..0000000 --- a/aldarien/response/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2017 Aldarien - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/aldarien/response/README.md b/aldarien/response/README.md deleted file mode 100644 index 80c6096..0000000 --- a/aldarien/response/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# response -Response handler module for my apps diff --git a/aldarien/response/app/Contract/Response.php b/aldarien/response/app/Contract/Response.php deleted file mode 100644 index 4b0089e..0000000 --- a/aldarien/response/app/Contract/Response.php +++ /dev/null @@ -1,27 +0,0 @@ - \ No newline at end of file diff --git a/aldarien/response/app/Helper/functions.php b/aldarien/response/app/Helper/functions.php deleted file mode 100644 index 32c48f8..0000000 --- a/aldarien/response/app/Helper/functions.php +++ /dev/null @@ -1,11 +0,0 @@ - \ No newline at end of file diff --git a/aldarien/response/app/Service/Response.php b/aldarien/response/app/Service/Response.php deleted file mode 100644 index d0f3e24..0000000 --- a/aldarien/response/app/Service/Response.php +++ /dev/null @@ -1,62 +0,0 @@ -gump = new \GUMP(); - } - public function sanitize() - { - if ($_POST) { - $this->post = $this->correctNumbers($this->gump->sanitize($_POST)); - } - if ($_GET) { - $this->get = $this->correctNumbers($this->gump->sanitize($_GET)); - } - } - public function correctNumbers(array $data) - { - $output = []; - foreach ($data as $key => $value) { - if (is_float(str_replace(',', '.', $value))) { - $output[$key] = str_replace(',', '.', $value); - } else { - $output[$key] = $value; - } - } - return $output; - } - public function get($query = null) - { - if ($this->get == null) { - $this->sanitize(); - } - if ($query == null) { - return $this->get; - } - if (isset($this->get[$query])) { - return $this->get[$query]; - } - return false; - } - public function post($query = null) - { - if ($this->post == null) { - $this->sanitize(); - } - if ($query == null) { - return $this->post; - } - if (isset($this->post[$query])) { - return $this->post[$query]; - } - return false; - } -} -?> diff --git a/aldarien/response/bootstrap/autoload.php b/aldarien/response/bootstrap/autoload.php deleted file mode 100644 index b5e8220..0000000 --- a/aldarien/response/bootstrap/autoload.php +++ /dev/null @@ -1,3 +0,0 @@ - \ No newline at end of file diff --git a/aldarien/response/composer.json b/aldarien/response/composer.json deleted file mode 100644 index a337f86..0000000 --- a/aldarien/response/composer.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name" : "aldarien/response", - "description" : "Response handler module for my apps", - "type" : "library", - "require" : { - "wixel/gump" : "^2.0.0", - "aldarien/contract" : "*" - }, - "require-dev" : { - "phpunit/phpunit" : "*" - }, - "license" : "MIT", - "authors" : [{ - "name" : "Aldarien", - "email" : "jpvial@gmail.com" - } - ], - "autoload" : { - "psr-4" : { - "App\\" : "app" - }, - "files": [ - "app/Helper/functions.php" - ] - } -} diff --git a/aldarien/response/phpunit.xml b/aldarien/response/phpunit.xml deleted file mode 100644 index db312e1..0000000 --- a/aldarien/response/phpunit.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - ./tests/ - - - - - ./app - - - \ No newline at end of file diff --git a/aldarien/response/tests/ResponseTest.php b/aldarien/response/tests/ResponseTest.php deleted file mode 100644 index 67d603c..0000000 --- a/aldarien/response/tests/ResponseTest.php +++ /dev/null @@ -1,22 +0,0 @@ -value; - $_POST['test'] = $this->value; - } - public function testGet() - { - $this->assertEquals($this->value, get('test')); - } - public function testPost() - { - $this->assertEquals($this->value, post('test')); - } -} -?> \ No newline at end of file diff --git a/aldarien/root/.gitignore b/aldarien/root/.gitignore deleted file mode 100644 index f7e7961..0000000 --- a/aldarien/root/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.buildpath -.project -.settings -*.lock -vendor \ No newline at end of file diff --git a/aldarien/root/LICENSE b/aldarien/root/LICENSE deleted file mode 100644 index 55dc05a..0000000 --- a/aldarien/root/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2017 Aldarien - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/aldarien/root/README.md b/aldarien/root/README.md deleted file mode 100644 index 039cbc3..0000000 --- a/aldarien/root/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# root -get root directory path for your project - -## Usage - -add `Root::root('project')` or `root('project')` or `Root::root()` or `root()` where you need the root directory of your proyect. - -## Example - -For the structure: - -~~~ -/usr/share/www/projects -- myProject --- src --- tests -~~~ - -using `Root::root('myProject')` - -outputs: -`/usr/share/www/projects/myProject` diff --git a/aldarien/root/app/Helper/functions.php b/aldarien/root/app/Helper/functions.php deleted file mode 100644 index 86fd2eb..0000000 --- a/aldarien/root/app/Helper/functions.php +++ /dev/null @@ -1,5 +0,0 @@ - \ No newline at end of file diff --git a/aldarien/root/composer.json b/aldarien/root/composer.json deleted file mode 100644 index 784dfb7..0000000 --- a/aldarien/root/composer.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name" : "aldarien/root", - "description" : "Find the root path for your proyect", - "authors" : [{ - "name" : "Aldarien" - } - ], - "license": "MIT", - "require-dev" : { - "phpunit/phpunit" : "*", - "kint-php/kint" : "*" - }, - "autoload" : { - "psr-4" : { - "Proyect\\Root\\" : "src" - }, - "files": [ - "app/Helper/functions.php" - ] - } -} diff --git a/aldarien/root/phpunit.xml b/aldarien/root/phpunit.xml deleted file mode 100644 index 63ecd1c..0000000 --- a/aldarien/root/phpunit.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - tests - - - - - src - - - diff --git a/aldarien/root/src/Root.php b/aldarien/root/src/Root.php deleted file mode 100644 index 13058df..0000000 --- a/aldarien/root/src/Root.php +++ /dev/null @@ -1,48 +0,0 @@ -$proyect_name/public/index.php calls for $proyect_name/bootstrap/autoload.php, - * you just need to - * - * include root() . '/bootstrap/autoload.php' - * - * @param string $proyect_name - * @return string - */ - public static function root(string $proyect_name = '') - { - $dir = realpath(__DIR__); - if ($proyect_name == '') { - return self::findComposerFile($dir); - } else { - $ini = strpos($dir, $proyect_name) + strlen($proyect_name); - } - $path = substr($dir, $ini); - $cnt = substr_count($path, DIRECTORY_SEPARATOR); - $root = DIRECTORY_SEPARATOR; - for ($i = 0; $i < $cnt; $i ++) { - $root .= '..' . DIRECTORY_SEPARATOR; - } - - return realpath($dir . $root); - } - protected static function findComposerFile($dir) - { - if (file_exists($dir . '/vendor/')) { - return $dir; - } - - $root = realpath('/'); - if (realpath($dir) == $root) { - return null; - } - - $dir = dirname($dir); - return self::findComposerFile($dir); - } -} -?> diff --git a/aldarien/root/tests/RootTest.php b/aldarien/root/tests/RootTest.php deleted file mode 100644 index 1deed6c..0000000 --- a/aldarien/root/tests/RootTest.php +++ /dev/null @@ -1,61 +0,0 @@ -getCurrentDir(); - $this->assertEquals($this->getRoot(), $this->current_dir); - $this->assertEquals($this->getBaseRoot(), $this->current_dir); - } - public function testBaseRootFunction() - { - $this->getCurrentDir(); - $this->assertEquals($this->getFRoot(), $this->current_dir); - $this->assertEquals($this->getFBaseRoot(), $this->current_dir); - } - public function testSrcRoot() - { - $this->changeDir('src'); - $this->assertEquals(realpath($this->getRoot() . '/src'), $this->current_dir); - $this->assertEquals(realpath($this->getBaseRoot() . '/src'), $this->current_dir); - } - public function testSrcRootFunction() - { - $this->changeDir('src'); - $this->assertEquals(realpath($this->getFRoot() . '/src'), $this->current_dir); - $this->assertEquals(realpath($this->getFBaseRoot() . '/src'), $this->current_dir); - } - - private function getCurrentDir() - { - $this->current_dir = getcwd(); - } - private function changeDir($dir) - { - chdir($dir); - $this->getCurrentDir(); - } - private function getRoot() - { - return Root::root($this->proyect_name); - } - private function getBaseRoot() - { - return Root::root(); - } - private function getFRoot() - { - return root($this->proyect_name); - } - private function getFBaseRoot() - { - return root(); - } -} -?> \ No newline at end of file diff --git a/aldarien/session/.gitignore b/aldarien/session/.gitignore deleted file mode 100644 index 6ee50e6..0000000 --- a/aldarien/session/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -composer.phar -/vendor/ - -# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file -# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file -# composer.lock - -# Eclipse IDE -.settings -.buildpath -.project \ No newline at end of file diff --git a/aldarien/session/LICENSE b/aldarien/session/LICENSE deleted file mode 100644 index 55dc05a..0000000 --- a/aldarien/session/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2017 Aldarien - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/aldarien/session/README.md b/aldarien/session/README.md deleted file mode 100644 index 6825213..0000000 --- a/aldarien/session/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# session -Session wrapper for aura/session diff --git a/aldarien/session/app/Contract/Session.php b/aldarien/session/app/Contract/Session.php deleted file mode 100644 index 2968a8f..0000000 --- a/aldarien/session/app/Contract/Session.php +++ /dev/null @@ -1,29 +0,0 @@ -newInstance($_COOKIE); - } - public static function get($segment, $name) - { - $instance = self::getInstance(); - $segment = $instance->getSegment($segment); - return $segment->get($name); - } - public static function set($segment, $name, $value) - { - $instance = self::getInstance(); - $segment = $instance->getSegment($segment); - $segment->set($name, $value); - } -} -?> \ No newline at end of file diff --git a/aldarien/session/composer.json b/aldarien/session/composer.json deleted file mode 100644 index 7fe764d..0000000 --- a/aldarien/session/composer.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "aldarien/session", - "description": "Session wrapper for aura/session", - "type": "library", - "require": { - "aura/session": "*", - "aldarien/contract": "*" - }, - "require-dev": { - "phpunit/phpunit": "*" - }, - "license": "MIT", - "authors": [ - { - "name": "Aldarien", - "email": "aldarien85@gmail.com" - } - ], - "autoload": { - "psr-4": { - "App\\": "app" - } - } -} diff --git a/aldarien/url/.gitignore b/aldarien/url/.gitignore deleted file mode 100644 index a06a2f1..0000000 --- a/aldarien/url/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -composer.phar -/vendor/ - -# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file -# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file -# composer.lock - -.settings -.buildpath -.project - -# Eclipse IDE \ No newline at end of file diff --git a/aldarien/url/LICENSE b/aldarien/url/LICENSE deleted file mode 100644 index 55dc05a..0000000 --- a/aldarien/url/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2017 Aldarien - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/aldarien/url/README.md b/aldarien/url/README.md deleted file mode 100644 index 0c1a426..0000000 --- a/aldarien/url/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# url -Get relative path url diff --git a/aldarien/url/app/Contract/URL.php b/aldarien/url/app/Contract/URL.php deleted file mode 100644 index 14d7ef0..0000000 --- a/aldarien/url/app/Contract/URL.php +++ /dev/null @@ -1,21 +0,0 @@ -url($path, $variables); - } -} -?> \ No newline at end of file diff --git a/aldarien/url/app/Helper/functions.php b/aldarien/url/app/Helper/functions.php deleted file mode 100644 index 6e9435e..0000000 --- a/aldarien/url/app/Helper/functions.php +++ /dev/null @@ -1,8 +0,0 @@ - \ No newline at end of file diff --git a/aldarien/url/app/Service/URL.php b/aldarien/url/app/Service/URL.php deleted file mode 100644 index 49a601d..0000000 --- a/aldarien/url/app/Service/URL.php +++ /dev/null @@ -1,83 +0,0 @@ -root = $this->findRoot(); - $this->relative = $this->findRelative(); - } - - protected function findRoot() - { - $base = $_SERVER['HTTP_HOST'] . ((isset($_SERVER['HTTP_PORT'])) ? ':' . $_SERVER['HTTP_PORT'] : ''); - $scheme = 'http'; - if (isset($_SERVER['REQUEST_SCHEME'])) { - $scheme = $_SERVER['REQUEST_SCHEME']; - } - if (isset($_SERVER['HTTPS'])) { - $scheme = 'https'; - } - $uri = Http::createFromString(\Sabre\Uri\resolve($scheme . '://' . $base, $_SERVER['SCRIPT_NAME'])); - $host = new Host($uri->getHost()); - if ($host->isAbsolute()) { - return $host->getRegistrableDomain(); - } - $base = $host . (($uri->getPort()) ? ':' . $uri->getPort() : ''); - return ($uri->getScheme() ?: 'http') . '://' . $base; - } - protected function findRelative() - { - $uri = Http::createFromString($_SERVER['SCRIPT_NAME']); - $normalized = (new HierarchicalPath($uri->getPath()))->withoutLeadingSlash()->withoutTrailingSlash()->withoutDotSegments()->withoutEmptySegments(); - if ($normalized->getDirname() == '.') { - return ''; - } - return $normalized->getDirname(); - } - - - public function url($path = '', $variables = null) - { - $uri = Http::createFromString($path); - if ($uri->getHost() != $this->root and $uri->getHost() != '') { - return $path; - } - - $uri = \Sabre\Uri\resolve($this->getBaseUrl(), $path); - try { - $host = new Host(Http::createFromString($uri)->getHost()); - } catch (\League\Uri\Exception $e) { - $uri = \Sabre\Uri\resolve($this->getBaseUrl(), '../../') . '/' . basename($path); - $host = new Host(Http::createFromString($uri)->getHost()); - } - - $base = new Host(Http::createFromString($this->root)->getHost()); - if ($host . '' != $base . '') { - $host = new Host(Http::createFromString($this->root)->getHost()); - $page = str_replace($this->root, '', $uri); - $uri = \Sabre\Uri\resolve(Http::createFromString($this->root)->getScheme() . '://' . $host->getRegistrableDomain(). '/', $page); - } - - if ($variables != null) { - $uri = \Sabre\Uri\resolve($uri, '?' . http_build_query($variables)); - } - $uri = \Sabre\Uri\normalize($uri); - - return $uri; - } - protected function getBaseUrl() - { - $url = \Sabre\Uri\normalize(trim($this->root . '/' . $this->relative, '/') . '/'); - return $url; - } -} -?> diff --git a/aldarien/url/composer.json b/aldarien/url/composer.json deleted file mode 100644 index 779ed73..0000000 --- a/aldarien/url/composer.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name" : "aldarien/url", - "description" : "Get relative path uri", - "type" : "library", - "require" : { - "aldarien/contract" : "*", - "aldarien/root" : "*", - "league/uri": "*", - "league/uri-components": "*", - "sabre/uri": "*" - }, - "require-dev" : { - "phpunit/phpunit" : "*" - }, - "license" : "MIT", - "authors" : [{ - "name" : "Aldarien", - "email" : "jpvial@gmail.com" - } - ], - "autoload" : { - "psr-4" : { - "App\\" : "app" - }, - "files": [ - "app/Helper/functions.php" - ] - } -} diff --git a/aldarien/view/.gitignore b/aldarien/view/.gitignore deleted file mode 100644 index 120b68f..0000000 --- a/aldarien/view/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -composer.phar -/vendor/ - -# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file -# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file -# composer.lock - -.settings -.buildpath -.project diff --git a/aldarien/view/LICENSE b/aldarien/view/LICENSE deleted file mode 100644 index 55dc05a..0000000 --- a/aldarien/view/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2017 Aldarien - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/aldarien/view/README.md b/aldarien/view/README.md deleted file mode 100644 index b888dbd..0000000 --- a/aldarien/view/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# view -View module for my apps diff --git a/aldarien/view/app/Contract/View.php b/aldarien/view/app/Contract/View.php deleted file mode 100644 index 1d0c5b9..0000000 --- a/aldarien/view/app/Contract/View.php +++ /dev/null @@ -1,30 +0,0 @@ - "http://{$remote->getIP()}:8008", - 'headers' => ['Accept' => 'application/json'] - ]))); - return new ViewService(['money' => $money]); - } - public static function show($template, $variables = null) - { - $instance = self::getInstance(); - return $instance->show($template, $variables); - } -} -?> diff --git a/aldarien/view/app/Helper/functions.php b/aldarien/view/app/Helper/functions.php deleted file mode 100644 index ba0e9e1..0000000 --- a/aldarien/view/app/Helper/functions.php +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/aldarien/view/app/Service/View.php b/aldarien/view/app/Service/View.php deleted file mode 100644 index 7217696..0000000 --- a/aldarien/view/app/Service/View.php +++ /dev/null @@ -1,27 +0,0 @@ -views = config('locations.views'); - $this->cache = config('locations.cache'); - - $this->blade = new BladeOne($this->views, $this->cache, null, $variables); - } - public function show($template, $vars = null) - { - if ($vars) { - return $this->blade->run($template, $vars); - } - return $this->blade->run($template); - } -} -?> diff --git a/aldarien/view/cache/26fae499b6e99106ff3bd673b8eb7319ae68e7ae.php b/aldarien/view/cache/26fae499b6e99106ff3bd673b8eb7319ae68e7ae.php deleted file mode 100644 index 8cafca1..0000000 --- a/aldarien/view/cache/26fae499b6e99106ff3bd673b8eb7319ae68e7ae.php +++ /dev/null @@ -1,9 +0,0 @@ - - - - View - - -View test - - \ No newline at end of file diff --git a/aldarien/view/composer.json b/aldarien/view/composer.json deleted file mode 100644 index 5d283ab..0000000 --- a/aldarien/view/composer.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "aldarien/view", - "description": "View module for my apps", - "type": "library", - "require": { - "eftec/bladeone": "*", - "aldarien/contract": "*", - "aldarien/config": "*" - }, - "license": "MIT", - "authors": [ - { - "name": "Aldarien", - "email": "aldarien85@gmail.com" - } - ], - "autoload": { - "psr-4": { - "App\\": "app" - }, - "files": [ - "app/Helper/functions.php" - ] - }, - "require-dev": { - "phpunit/phpunit": "*" - } -} diff --git a/aldarien/view/config/locations.php b/aldarien/view/config/locations.php deleted file mode 100644 index 1dd0425..0000000 --- a/aldarien/view/config/locations.php +++ /dev/null @@ -1,8 +0,0 @@ - root(), - 'cache' => '{locations.base}/cache', - 'resources' => '{locations.base}/resources', - 'views' => '{locations.resources}/views' -]; -?> \ No newline at end of file diff --git a/aldarien/view/phpunit.xml b/aldarien/view/phpunit.xml deleted file mode 100644 index e60ecbd..0000000 --- a/aldarien/view/phpunit.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - ./tests/ - - - - - ./app - - - \ No newline at end of file diff --git a/aldarien/view/public/index.php b/aldarien/view/public/index.php deleted file mode 100644 index 1070f11..0000000 --- a/aldarien/view/public/index.php +++ /dev/null @@ -1,5 +0,0 @@ - \ No newline at end of file diff --git a/aldarien/view/resources/views/base.blade.php b/aldarien/view/resources/views/base.blade.php deleted file mode 100644 index 8cafca1..0000000 --- a/aldarien/view/resources/views/base.blade.php +++ /dev/null @@ -1,9 +0,0 @@ - - - - View - - -View test - - \ No newline at end of file diff --git a/aldarien/view/tests/ViewTest.php b/aldarien/view/tests/ViewTest.php deleted file mode 100644 index 85f4aa6..0000000 --- a/aldarien/view/tests/ViewTest.php +++ /dev/null @@ -1,22 +0,0 @@ - - - - View - - -View test - - -DATA; - $this->assertEquals($output, view('base')); - } -} -?> \ No newline at end of file diff --git a/app/Alias/Connection.php b/app/Alias/Connection.php deleted file mode 100644 index 1eea52a..0000000 --- a/app/Alias/Connection.php +++ /dev/null @@ -1,50 +0,0 @@ -connection)) { - $r = 0; - $exception = null; - while ($r < $this->retries) { - try { - $dsn = $this->getDsn(); - $this->connection = new PDO($dsn, $this->username, $this->password); - return $this->connection; - } catch (PDOException $e) { - if ($exception !== null) { - $e = new PDOException($e->getMessage(), $e->getCode(), $exception); - } - $exception = $e; - usleep(500); - } - $r ++; - } - throw $exception; - } - return $this->connection; - } - protected function getDsn(): string - { - $dsn = "mysql:host={$this->host};dbname={$this->database}"; - if (isset($this->port)) { - $dsn .= ";port={$this->port}"; - } - return $dsn; - } -} diff --git a/app/Alias/Excel/Style/Mes.php b/app/Alias/Excel/Style/Mes.php deleted file mode 100644 index 368246b..0000000 --- a/app/Alias/Excel/Style/Mes.php +++ /dev/null @@ -1,18 +0,0 @@ -setNumFormat('mmm-YY'); - $format->setAlign('center'); - } -} diff --git a/app/Alias/Format.php b/app/Alias/Format.php deleted file mode 100644 index f2067aa..0000000 --- a/app/Alias/Format.php +++ /dev/null @@ -1,12 +0,0 @@ - \ No newline at end of file diff --git a/app/Alias/Model.php b/app/Alias/Model.php deleted file mode 100644 index 9f8f579..0000000 --- a/app/Alias/Model.php +++ /dev/null @@ -1,87 +0,0 @@ -id; - $orm = $this->orm; - $ref = new \ReflectionObject($orm); - if (!$ref->hasProperty('_dirty_fields')) { - return; - } - $dirty = $ref->getProperty('_dirty_fields'); - $dirty->setAccessible(true); - $new_values = $dirty->getValue($orm); - $changes = array_combine(array_keys($new_values), array_fill(0, count($new_values), ['old' => '', 'new' => ''])); - if ($this->isNew()) { - $old = (object) array_combine(array_keys($new_values), array_fill(0, count($new_values), '')); - } else { - $old = model(get_called_class())->findOne($this->{$this->getId()}); - } - foreach ($new_values as $column => $value) { - $changes[$column] = ['column' => $column, 'old' => $old->$column, 'new' => $value]; - } - $action = '[' . get_called_class() . ']'; - doLog($user, $action, $changes); - } - public function getId() - { - if (property_exists(get_called_class(), '_id_column')) { - return static::$_id_column; - } - return $this->id; - } - public function save() - { - $ref = new \ReflectionObject($this); - if ($ref->hasProperty('_timestamps')) { - $ref = $ref->getProperty('_timestamps'); - $ref->setAccessible(true); - if ($ref->getValue()) { - if ($this->is_new()) { - $this->setExpr('created_at', 'NOW()'); - } - $this->setExpr('updated_at', 'NOW()'); - } - } - if (!\ORM::getDb()->inTransaction()) { - \ORM::getDb()->beginTransaction(); - } - try { - parent::save(); - if (\ORM::getDb()->inTransaction()) { - \ORM::getDb()->commit(); - } - } catch (\Exception $e) { - if (\ORM::getDb()->inTransaction()) { - \ORM::getDb()->rollBack(); - } - throw $e; - } - $this->log(); - } - public function __call($method, $args) - { - if (!method_exists($this, $method)) { - $str = '' . Stringy::create($method)->underscored(); - if (method_exists($this, $str)) { - return call_user_func_array([$this, $str], $args); - } - throw new \BadMethodCallException($method . ' not found in ' . get_class($this)); - } - return call_user_func_array([$this, $str], $args); - } -} -?> diff --git a/app/Alias/NewEstado.php b/app/Alias/NewEstado.php deleted file mode 100644 index 4bf9089..0000000 --- a/app/Alias/NewEstado.php +++ /dev/null @@ -1,20 +0,0 @@ -fecha, config('app.timezone')); - } -} -?> \ No newline at end of file diff --git a/app/Alias/NewModel.php b/app/Alias/NewModel.php deleted file mode 100644 index 1c513b4..0000000 --- a/app/Alias/NewModel.php +++ /dev/null @@ -1,9 +0,0 @@ - \ No newline at end of file diff --git a/app/Alias/NewTipo.php b/app/Alias/NewTipo.php deleted file mode 100644 index b5fa3fb..0000000 --- a/app/Alias/NewTipo.php +++ /dev/null @@ -1,15 +0,0 @@ - \ No newline at end of file diff --git a/app/Alias/OldModel.php b/app/Alias/OldModel.php deleted file mode 100644 index b3f9730..0000000 --- a/app/Alias/OldModel.php +++ /dev/null @@ -1,8 +0,0 @@ - diff --git a/app/Alias/PHPExcel.php b/app/Alias/PHPExcel.php deleted file mode 100644 index de0ac75..0000000 --- a/app/Alias/PHPExcel.php +++ /dev/null @@ -1,155 +0,0 @@ -name = $name; - $this->filename = $filename; - } - public function addColumns($fields) - { - $columns = []; - foreach ($fields as $i => $field) { - if (is_object($field)) { - if (isset($field->style)) { - $style = $this->getExcelStyle($field->style); - } else { - $style = $this->getExcelStyle(); - } - $column = new ExcelHelper\Column($field->name, $field->name, 10, $style); - } elseif (is_array($field)) { - if (isset($field['style'])) { - $style = $this->getExcelStyle($field['style']); - } else { - $style = $this->getExcelStyle(); - } - $column = new ExcelHelper\Column($field['name'], $field['name'], 10, $style); - } else { - $style = $this->getExcelStyle(); - $column = new ExcelHelper\Column($field, $field, 10, $style); - } - $columns []= $column; - } - $collection = new ExcelHelper\ColumnCollection($columns); - $this->columns = $collection; - } - protected function getExcelStyle($style = 'text') - { - switch (strtolower($style)) { - case 'date': - return new ExcelHelper\CellStyle\Date(); - case 'mes': - return new Excel\Style\Mes(); - case 'currency': - case 'amount': - return new ExcelHelper\CellStyle\Amount(); - case 'number': - case 'integer': - return new ExcelHelper\CellStyle\Integer(); - case 'percent': - case 'percentage': - return new ExcelHelper\CellStyle\Percentage(); - case 'text': - case 'string': - default: - return new ExcelHelper\CellStyle\Text(); - } - } - public function addData($data) - { - if ($this->data == null) { - $this->data = []; - } - $this->data = array_merge($data); - } - public function addRow($rowData) - { - if ($this->data == null) { - $this->data = []; - } - $this->data []= $rowData; - } - public function addTotals($totals) - { - $columns = (array) $this->columns; - $columns = array_pop($columns); - $ts = []; - foreach ($columns as $column) { - $col = $column->getHeading(); - if (isset($totals[$col])) { - $ts[$col] = $this->getTotal($col, $totals[$col]); - continue; - } - $ts[$col] = ''; - } - $this->data []= $ts; - } - protected function getTotal($col, $aggr) - { - $col_num = $this->getColNumber($col); - $col = $this->getColName($col_num); - switch(strtolower($aggr)) { - case 'sum': - $num = 109; - break; - case 'count': - $num = 102; - break; - case 'counta': - $num = 103; - break; - default: - $num = 0; - } - if ($num > 0) { - $end = count($this->data) + 2; - $str = "=SUBTOTAL({$num};{$col}3:{$col}{$end})"; - return $str; - } - return $aggr; - } - protected function getColNumber($col) - { - $columns = (array) $this->columns; - $columns = array_keys(array_pop($columns)); - return array_search($col, $columns); - } - protected function getColName($col_num) - { - $cols = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $N = strlen($cols); - $name = ''; - if ($col_num > $N) { - $name .= $cols[floor($col_num / $N)]; - $col_num = $N * ($col_num / $N - floor($col_num / $N)); - } - $name .= $cols[$col_num]; - return $name; - } - public function informe() - { - header("Content-Type: application/octet-stream; charset=utf-8"); - header('Content-Transfer-Encoding: binary'); - header('Content-Disposition: attachment; filename="' . $this->filename . '"'); - header('Cache-Control: max-age=0'); - - $pE = new ExcelHelper\TableWorkbook('php://output'); - $ws = $pE->addWorksheet($this->name); - - $table = new ExcelHelper\Table($ws, 0, 0, $this->name, new \ArrayIterator($this->data)); - $table->setColumnCollection($this->columns); - - $pE->writeTable($table); - - $pE->close(); - } -} diff --git a/app/Alias/RemoteConnection.php b/app/Alias/RemoteConnection.php deleted file mode 100644 index 475225e..0000000 --- a/app/Alias/RemoteConnection.php +++ /dev/null @@ -1,17 +0,0 @@ -retries - ); - } -} diff --git a/app/Command/Money/Get.php b/app/Command/Money/Get.php deleted file mode 100644 index 0b2efbd..0000000 --- a/app/Command/Money/Get.php +++ /dev/null @@ -1,87 +0,0 @@ -title('Get Money'); - - $dates = $this->getDates(); - foreach ($dates as $date_string => $ids) { - $date = $this->parseDate($date_string); - $response = $this->service->getUF($date); - if ($response->total === 0) { - continue; - } - foreach ($ids as $id) { - $this->queueUpdate($id, $response->uf->value); - } - } - $this->updateUF(); - return Command::SUCCESS; - } - - protected function getDates(): array - { - $query = "SELECT id, fecha FROM pago WHERE uf IS NULL AND fecha BETWEEN 0 AND DATE_ADD(CURDATE(), INTERVAL 9 DAY) ORDER BY fecha"; - $statement = $this->connection->connect()->query($query); - $rows = $statement->fetchAll(PDO::FETCH_ASSOC); - if (count($rows) === 0) { - return []; - } - $dates = []; - foreach ($rows as $row) { - if (!isset($dates[$row['fecha']])) { - $dates[$row['fecha']] = []; - } - $dates[$row['fecha']] []= (int) $row['id']; - } - return $dates; - } - protected function parseDate(string $date_string): DateTimeInterface - { - return new DateTimeImmutable($date_string); - } - protected array $rows; - protected function queueUpdate(int $id, float $value): void - { - $this->rows []= [$value, $id]; - } - protected function updateUF(): void - { - $query = "UPDATE pago SET uf = ? WHERE id = ?"; - $statement = $this->connection->connect()->prepare($query); - foreach ($this->rows as $row) { - $this->connection->connect()->beginTransaction(); - try { - $statement->execute($row); - $this->connection->connect()->commit(); - } catch (PDOException $e) { - $this->connection->connect()->rollBack(); - } - } - } -} diff --git a/app/Command/Money/Lookup.php b/app/Command/Money/Lookup.php deleted file mode 100644 index 0e9ce4d..0000000 --- a/app/Command/Money/Lookup.php +++ /dev/null @@ -1,52 +0,0 @@ -title('Lookup Money'); - - while (true) { - $io->info('Checking pending'); - if ($this->hasPendingMoney()) { - $io->success('Running money get UF'); - $io->note($this->runGetUF()); - } - } - return Command::SUCCESS; - } - - protected function hasPendingMoney(): bool - { - $query = "SELECT 1 FROM pago WHERE uf IS NULL AND fecha BETWEEN 0 AND DATE_ADD(CURDATE(), INTERVAL 9 DAY)"; - $statement = $this->connection->connect()->query($query); - return $statement->rowCount() > 0; - } - protected function runGetUF(): string - { - $command = "/code/bin/console money:uf:get"; - $result = shell_exec($command); - if (!$result or $result === null) { - throw new \Exception(); - } - return $result; - } -} diff --git a/app/Contract/Auth.php b/app/Contract/Auth.php deleted file mode 100644 index fb2e3b6..0000000 --- a/app/Contract/Auth.php +++ /dev/null @@ -1,27 +0,0 @@ - \ No newline at end of file diff --git a/app/Contract/Route.php b/app/Contract/Route.php deleted file mode 100644 index fd4a84c..0000000 --- a/app/Contract/Route.php +++ /dev/null @@ -1,27 +0,0 @@ - \ No newline at end of file diff --git a/app/Controller/API/Unidades.php b/app/Controller/API/Unidades.php deleted file mode 100644 index b7abead..0000000 --- a/app/Controller/API/Unidades.php +++ /dev/null @@ -1,41 +0,0 @@ -findOne($id_proyecto); - if (!$proyecto) { - throw new \InvalidArgumentException('Proyecto identificado por ' . $id_proyecto . ' no existe.'); - } - $unidades = $proyecto->unidades($id_tipo); - $unidades = array_filter($unidades, function($item) { - return !$item->isVendida() and !$item->isReservada(); - }); - $unidades = array_map(function($item) { - return $item->asArray(); - }, $unidades); - usort($unidades, function($a, $b) { - $ap = strpos($a['descripcion'], ' '); - $ad = $a['descripcion']; - if ($ap != false) { - $ad = substr($ad, 0, $ap); - } - $bd = $b['descripcion']; - $bp = strpos($b['descripcion'], ' '); - if ($bp != false) { - $bd = substr($bd, 0, $bp); - } - return strcmp( - str_pad($ad, 4, '0', \STR_PAD_LEFT), - str_pad($bd, 4, '0', \STR_PAD_LEFT) - ); - }); - $output = array_values($unidades); - $response->getBody()->write(\json_encode($output)); - return $response->withHeader('Content-Type', 'application/json'); - } -} diff --git a/app/Controller/Admin.php b/app/Controller/Admin.php deleted file mode 100644 index 137057c..0000000 --- a/app/Controller/Admin.php +++ /dev/null @@ -1,233 +0,0 @@ -list(); - } - public static function listNamespaces() - { - $base = [ - 'Common', - 'Inmobiliaria', - 'Proyecto', - 'Venta' - ]; - $nss = [ - 'Incoviba' => [ - 'old' => $base, - 'new' => $base - ] - ]; - - echo json_encode(['namespaces' => self::collapseMultiArray($nss)]); - } - protected static function collapseMultiArray($array, $level = '') - { - $output = []; - foreach ($array as $key => $subarray) { - if (is_array($subarray)) { - $output = array_merge($output, self::collapseMultiArray($subarray, $level . '\\' . $key)); - } else { - $output []= $level . '\\' . $subarray; - } - } - - return $output; - } - public static function createModel() - { - $db = post('database'); - $ns = post('namespace'); - $table = post('table'); - - $modeler = new DBToModel($db); - echo $modeler->create($ns, $table); - } - public static function list_roles() - { - $roles = \Model::factory(\Incoviba\common\Role::class)->findMany(); - echo view('admin.roles.list', compact('roles')); - } - public static function add_role() - { - echo view('admin.roles.add'); - } - public static function do_add_role() - { - $role = \Model::factory(\Incoviba\common\Role::class)->where('description', post('description'))->findOne(); - if ($role === false) { - $role = \Model::factory(\Incoviba\common\Role::class)->create(['description' => post('description')]); - $role->save(); - } - header('Location: ' . nUrl('admin', 'add_role')); - } - public static function role() - { - $role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role')); - $actions = model(Action::class)->orderByAsc('description')->findMany(); - $permissions = []; - foreach ($actions as $action) { - $permissions []= (object) ['description' => $action->description, 'status' => false, 'inherited' => false]; - } - array_walk($permissions, function(&$el, $i, $role) { - if ($role->checkAccess($el->description)) { - $el->status = true; - if ($role->isInherited($el->description)) { - $el->inherited = true; - } - } - }, $role); - echo view('admin.roles.show', compact('role', 'permissions')); - } - public static function add_role_permissions() - { - $role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role')); - $locations = \Model::factory(\Incoviba\common\Location::class)->findMany(); - $actions = model(\Incoviba\common\Action::class)->findMany(); - echo view('admin.roles.add_permissions', compact('role', 'locations', 'actions')); - } - public static function do_add_role_permissions() - { - $role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role')); - $actions = model(\Incoviba\common\Action::class)->findMany(); - foreach ($actions as $action) { - $p = \Model::factory(\Incoviba\common\Permission::class)->where('type', 2)->where('ext_id', $role->id)->where('action_id', $action->id)->findOne(); - if (array_search($action->id, post('allowed'))) { - if (!$p) { - $data = [ - 'type' => 2, - 'ext_id' => $role->id, - 'action_id' => $action->id - ]; - $p = model(\Incoviba\common\Permission::class)->create($data); - } - $p->status = 1; - } else { - if ($p !== false) { - $p->status = 0; - } - } - if ($p !== false) { - $p->save(); - } - } - header('Location: ' . nUrl('admin', 'role', ['role' => $role->id])); - } - public static function list_users() - { - $users = \Model::factory(\Incoviba\common\User::class)->orderByAsc('name')->findMany(); - echo view('admin.users.list', compact('users')); - } - public static function add_user() - { - echo view('admin.users.add'); - } - public static function do_add_user() - { - $user = \Model::factory(\Incoviba\common\User::class)->where('name', post('name'))->findOne(); - if ($user === false) { - $user = \Model::factory(\Incoviba\common\User::class)->create(); - $user->name = post('name'); - $user->password(post('password')); - - $user->save(); - } - header('Location: ' . url('', ['p' => 'admin', 'a' => 'add_user'])); - } - public static function user() - { - $user = \Model::factory(\Incoviba\common\User::class)->findOne(get('user')); - echo view('admin.users.show', compact('user')); - } - public static function add_user_role() - { - if (get('user') !== false) { - $user = \Model::factory(\Incoviba\common\User::class)->findOne(get('user')); - $roles = \Model::factory(\Incoviba\common\Role::class)->findMany(); - return view('admin.users.add_role', compact('user', 'roles')); - } elseif (get('role') !== false) { - $role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role')); - $users = \Model::factory(\Incoviba\common\User::class)->findMany(); - return view('admin.roles.add_users', compact('users', 'role')); - } - } - public static function do_add_user_role() - { - if (get('user') !== false) { - $user = \Model::factory(\Incoviba\common\User::class)->findOne(get('user')); - foreach (post('role') as $r_id) { - $role = \Model::factory(\Incoviba\common\Role::class)->findOne($r_id); - - $usrRl = \Model::factory(\Incoviba\common\UserRole::class)->where('user', $user->id)->where('role', $role->id)->findOne(); - if ($usrRl === false) { - $usrRl = \Model::factory(\Incoviba\common\UserRole::class)->create(['user' => $user->id, 'role' => $role->id]); - $usrRl->save(); - } - } - header('Location: ' . url('', ['p' => 'admin', 'a' => 'user', 'user' => $user->id])); - } elseif (get('role') !== false) { - $role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role')); - foreach (post('users') as $u_id) { - $user = \Model::factory(\Incoviba\common\User::class)->findOne($u_id); - - $usrRl = \Model::factory(\Incoviba\common\UserRole::class)->where('user', $user->id)->where('role', $role->id)->findOne(); - if ($usrRl === false) { - $usrRl = \Model::factory(\Incoviba\common\UserRole::class)->create(['user' => $user->id, 'role' => $role->id]); - $usrRl->save(); - } - } - header('Location: ' . url('', ['p' => 'admin', 'a' => 'role', 'role' => $role->id])); - } - } - public static function remove_user_role() - { - $q = "DELETE FROM user_roles WHERE user = ? AND role = ?"; - $st = \ORM::getDb()->prepare($q); - $st->execute([get('user'), get('role')]); - header('Location: ' . nUrl('admin')); - } - public static function delete_user() - { - $q = "DELETE FROM user_roles WHERE user = ?"; - $st = \ORM::getDb()->prepare($q); - $st->execute([get('user')]); - $q = "DELETE FROM logins WHERE user = ?"; - $st = \ORM::getDb()->prepare($q); - $st->execute([get('user')]); - $q = "DELETE FROM permissions WHERE type = 1 AND ext_id = ?"; - $st = \ORM::getDb()->prepare($q); - $st->execute([get('user')]); - $user = \model(\Incoviba\common\User::class)->findOne(get('user')); - $user->delete(); - header('Location: ' . nUrl('admin', 'list_users')); - } - public static function reset_user() - { - $user = model(\Incoviba\common\User::class)->findOne(get('user')); - $user->password('123456'); - $user->save(); - header('Location: ' . nUrl('admin', 'user', ['user' => $user->id])); - } -} -?> diff --git a/app/Controller/Ajax.php b/app/Controller/Ajax.php deleted file mode 100644 index 912c979..0000000 --- a/app/Controller/Ajax.php +++ /dev/null @@ -1,215 +0,0 @@ -whereNotEqual('nombre', '')->order_by_asc('nombre')->findMany(); - foreach ($bancos as &$banco) { - $banco = $banco->as_array('nombre')['nombre']; - } - return json_encode($bancos); - } - protected static function buscarBanco() - { - $q = get('q'); - if ($q == null) { - $q = get('query'); - if ($q == null) { - return ''; - } - } - $bancos = \Model::factory(\Incoviba\old\Common\Banco::class)->whereLike('nombre', '%' . $q . '%')->order_by_asc('nombre')->findMany(); - foreach ($bancos as &$banco) { - $banco = $banco->as_array('nombre')['nombre']; - } - return json_encode($bancos); - } - public static function comunas() - { - $id = post('region'); - $comunas = \Model::factory(\Incoviba\old\Common\Comuna::class) - ->select('comuna.*') - ->join('provincia', ['provincia.id', '=', 'comuna.provincia']) - ->where('provincia.region', $id) - ->order_by_asc('comuna.descripcion') - ->findMany(); - - foreach ($comunas as &$comuna) { - $comuna = $comuna->as_array('id', 'descripcion'); - } - return json_encode($comunas); - } - public static function propietario() - { - $id = post('rut'); - $propietario = \Model::factory(\Incoviba\old\Venta\Propietario::class)->where('rut', $id)->findOne(); - if ($propietario) { - $propietario = $propietario->as_array(); - return json_encode($propietario); - } - return null; - } - public static function direccion() - { - $id = post('direccion'); - $direccion = \Model::factory(\Incoviba\old\Common\Direccion::class)->findOne($id); - $comuna = $direccion->comuna(); - $provincia = $comuna->provincia(); - $region = $provincia->region(); - $direccion = $direccion->as_array(); - $direccion['comuna'] = $comuna->as_array(); - $direccion['comuna']['provincia'] = $provincia->as_array(); - $direccion['comuna']['provincia']['region'] = $region->as_array(); - return json_encode($direccion); - } - public static function tipo_unidades() - { - $id = post('proyecto'); - $proyecto = \Model::factory(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id); - $tipos = $proyecto->tipoUnidades(); - foreach ($tipos as &$tipo) { - $tipo = $tipo->as_array(); - } - return json_encode($tipos); - } - public static function unidades() - { - $id_proyecto = post('proyecto'); - $id_tipo = post('tipo'); - - $proyecto = model(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id_proyecto); - $unidades = $proyecto->unidadesDisponibles($id_tipo); - foreach ($unidades as &$unidad) { - $tipologia = $unidad->tipologia(); - $unidad = $unidad->as_array(); - $unidad['tipologia'] = $tipologia->as_array(); - if ($tipologia->tipologia()) { - $unidad['tipologia']['tipologia'] = (array) $tipologia->tipologia(); - continue; - } - $unidad['tipologia']['tipologia'] = ['descripcion' => $tipologia->abreviacion]; - } - return json_encode($unidades); - } - public static function unidades_precios() - { - $proyecto = model(\Incoviba\old\Proyecto\Proyecto::class)->findOne(post('proyecto')); - $unidades = $proyecto->unidades(); - usort($unidades, function($a, $b) { - $t = $a->tipo - $b->tipo; - if ($t == 0) { - return (int) $a->descripcion - (int) $b->descripcion; - } - return $t; - }); - $output = []; - foreach ($unidades as $u) { - $info = [ - 'id' => $u->id, - 'abreviacion' => $u->abreviacion, - 'descripcion' => $u->descripcion, - 'valor' => '--' - ]; - if ($u->precio()) { - $info['valor'] = format('ufs', $u->precio()->valor, null, true); - } - $output []= $info; - } - return json_encode($output); - } - public static function operadores() - { - $id_proyecto = post('proyecto'); - $proyecto = \Model::factory(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id_proyecto); - $operadores = $proyecto->operadores(); - foreach ($operadores as &$operador) { - $operador = [ - 'id' => $operador->id, - 'abreviacion' => $operador->abreviacion - ]; - } - return json_encode($operadores); - } - public static function promociones() - { - $id = post('proyecto'); - $proyecto = \Model::factory(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id); - $promociones = $proyecto->promociones(); - foreach ($promociones as &$promocion) { - $promocion = $promocion->as_array(); - } - return json_encode($promociones); - } - public static function nombres() - { - $nss = model(Propietario::class)->select('nombres')->orderByAsc('nombres')->findMany(); - $nombres = []; - foreach ($nss as $n) { - $ns = explode(' ', $n->nombres); - foreach ($ns as $nombre) { - $nombres []= $nombre; - } - } - $nombres = array_values(array_unique($nombres)); - return json_encode($nombres); - } - public static function apellidos() - { - $aps = model(Propietario::class)->select('apellido_paterno')->orderByAsc('apellido_paterno')->findMany(); - $apellidos = []; - foreach ($aps as $ap) { - $apellidos []= $ap->apellido_paterno; - } - $aps = model(Propietario::class)->select('apellido_materno')->orderByAsc('apellido_materno')->findMany(); - foreach ($aps as $ap) { - $apellidos []= $ap->apellido_paterno; - } - $apellidos = array_values(array_unique($apellidos)); - sort($apellidos); - return json_encode($apellidos); - } - public static function calles() - { - $results = model(Direccion::class)->select('calle')->orderByAsc('calle')->findMany(); - $calles = []; - foreach ($results as $result) { - $calles []= $result->calle; - } - $calles = array_values(array_unique($calles)); - return json_encode($calles); - } - public static function inmobiliarias() - { - $q = post('rut'); - $inmobiliaria = model(Inmobiliaria::class)->findOne($q); - return json_encode($inmobiliaria->as_array()); - } -} -?> diff --git a/app/Controller/Auth.php b/app/Controller/Auth.php deleted file mode 100644 index c7ca497..0000000 --- a/app/Controller/Auth.php +++ /dev/null @@ -1,56 +0,0 @@ - 'auth', 'a' => 'login'])); - } - } - public static function logout() - { - sAuth::logout(); - header('Location: .'); - } - public static function check_pass() - { - if (\password_verify(post('password'), sAuth::User()->password)) { - return 'OK'; - } - return 'KO'; - } - public static function change_pass() - { - return view('auth.change_pass'); - } - public static function do_change_pass() - { - if (\password_verify(post('old'), sAuth::User()->password)) { - if (post('new') == post('new2')) { - $user = sAuth::User(); - $user->password(post('new')); - $user->save(); - header('Location: .'); - die(); - } - } - header('Location: ' . url('', ['p' => 'auth', 'a' => 'change_pass'])); - } -} -?> diff --git a/app/Controller/Bonos.php b/app/Controller/Bonos.php deleted file mode 100644 index 32daaa5..0000000 --- a/app/Controller/Bonos.php +++ /dev/null @@ -1,67 +0,0 @@ -findOne($id_venta); - return view('ventas.bonos.add', compact('venta')); - } - public static function do_add() - { - $id_venta = get('venta'); - $venta = model(Venta::class)->findOne($id_venta); - if ($venta->bono_pie != 0) { - header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); - return; - } - $uf = uf($venta->fecha()); - $valor = post('valor'); - $data = [ - 'fecha' => $venta->fecha, - 'valor' => $valor * $uf->uf->value, - 'tipo' => 8, - 'uf' => $uf->uf->value - ]; - $pago = model(Pago::class)->create($data); - $pago->save(); - $data = [ - 'valor' => $valor, - 'pago' => $pago->id - ]; - $bono = model(BonoPie::class)->create($data); - $bono->save(); - $venta->bono_pie = $bono->id; - $venta->save(); - header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); - } - public static function edit() - { - $id_venta = get('venta'); - $venta = model(Venta::class)->findOne($id_venta); - return view('ventas.bonos.edit', compact('venta')); - } - public static function do_edit() - { - $id_venta = get('venta'); - $venta = model(Venta::class)->findOne($id_venta); - $bono = $venta->bonoPie(); - $valor = post('valor') * $bono->pago()->uf(); - $pago = $bono->pago(); - if ($valor != $bono->pago()->valor()) { - $pago->valor = $valor; - $pago->save(); - } - header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); - exit(); - } -} diff --git a/app/Controller/Buscar.php b/app/Controller/Buscar.php deleted file mode 100644 index ef62a9e..0000000 --- a/app/Controller/Buscar.php +++ /dev/null @@ -1,340 +0,0 @@ - $results]); - } - protected static function getResults() - { - $q = get('q'); - if ($q == null) { - $q = get('query'); - } - $t = get('t'); - if ($t == null) { - $t = get('tipo'); - } - $t = urldecode($t); - if ($t == null) { - $t = 'cualquiera'; - } - - $results = null; - if ($q != null) { - $q = urldecode($q); - $results = self::buscar($q, $t); - } - return $results; - } - public static function buscar($query, $tipo) - { - $method = 'buscar' . str_replace(' ', '', ucwords($tipo)); - if (is_callable(['self', $method])) { - $results = self::$method(self::prepareQuery($query)); - $results = self::removeDuplicates($results); - $results = self::sort($results); - return $results; - } - return []; - } - protected static function prepareQuery($query) - { - $query = str_replace('"', '"', $query); - $data = explode(' ', $query); - $regex = "~(?=\\S)[^'\"\\s]*(?:'[^']*'[^'\"\\s]*|\"[^\"]*\"[^'\"\\s]*)*~"; - preg_match_all($regex, $query, $data); - $data = $data[0]; - foreach ($data as &$l) { - $l = str_replace('"', '', str_replace("'", '', $l)); - } - if (is_array($data) and count($data) == 1) { - $data = $data[0]; - } - return $data; - } - protected static function removeDuplicates($results) - { - $output = []; - foreach ($results as $result) { - if (array_search($result, $output) === false) { - $output []= $result; - } - } - return $output; - } - protected static function sort($results) - { - usort($results, function($a, $b) { - $py = strcmp($a->proyecto()->descripcion, $b->proyecto()->descripcion); - if ($py == 0) { - if (!method_exists($a, 'unidad') and !method_exists($b, 'unidad')) { - return $a->descripcion - $b->descripcion; - } - if (!method_exists($a, 'unidad')) { - return $a->descripcion - $b->unidad()->descripcion; - } - if (!method_exists($b, 'unidad')) { - return $a->unidad()->descripcion - $b->descripcion; - } - - $u = $a->unidad()->descripcion - $b->unidad()->descripcion; - if ($u == 0) { - return strcmp($a->propietario()->apellido_paterno, $b->propietario()->apellido_paterno); - } - return $u; - } - return $py; - }); - return $results; - } - protected static function buscarCualquiera($query) - { - $results = []; - foreach (self::$tipos as $tipo) { - if ($tipo == 'cualquiera') { - continue; - } - $method = 'buscar' . str_replace(' ', '', ucwords($tipo)); - - if (is_callable(['self', $method])) { - $results = array_merge($results, self::$method($query)); - } - } - return $results; - } - protected static function buscarDepartamento($query) - { - if (is_array($query)) { - $results = []; - foreach ($query as $segment) { - $results = array_merge($results, self::buscarDepartamento($segment)); - } - } else { - $results = \Model::factory(Venta::class) - ->select('venta.*') - ->join('propiedad', ['propiedad.id', '=', 'venta.propiedad']) - ->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal']) - ->whereLike('unidad.descripcion', '%' . $query . '%') - ->findMany(); - } - return $results; - } - protected static function buscarEstacionamiento($query) - { - if (is_array($query)) { - $results = []; - foreach ($query as $segment) { - $results = array_merge($results, self::buscarEstacionamiento($segment)); - } - } else { - $results = \Model::factory(Venta::class) - ->select('venta.*') - ->join('propiedad', ['propiedad.id', '=', 'venta.propiedad']) - ->join('unidad', "`propiedad`.`estacionamientos` LIKE `unidad`.`id` OR `propiedad`.`estacionamientos` LIKE CONCAT('%;', `unidad`.`id`) OR `propiedad`.`estacionamientos` LIKE CONCAT(`unidad`.`id`, ';%') OR `propiedad`.`estacionamientos` LIKE CONCAT('%;', `unidad`.`id`, ';%')") - ->where('unidad.descripcion', $query) - ->findMany(); - } - return $results; - } - protected static function buscarBodega($query) - { - if (is_array($query)) { - $results = []; - foreach ($query as $segment) { - $results = array_merge($results, self::buscarBodega($segment)); - } - } else { - $results = \Model::factory(Venta::class) - ->select('venta.*') - ->join('propiedad', ['propiedad.id', '=', 'venta.propiedad']) - ->join('unidad', "`propiedad`.`bodegas` LIKE `unidad`.`id` OR `propiedad`.`bodegas` LIKE CONCAT('%;', `unidad`.`id`) OR `propiedad`.`bodegas` LIKE CONCAT(`unidad`.`id`, ';%') OR `propiedad`.`bodegas` LIKE CONCAT('%;', `unidad`.`id`, ';%')") - ->where('unidad.descripcion', $query) - ->findMany(); - } - return $results; - } - protected static function buscarPropietario($query) - { - if (is_array($query)) { - $results = []; - foreach ($query as $segment) { - $results = array_merge($results, self::buscarPropietario($segment)); - } - } else { - $results = self::buscarPropietarioNombres($query); - $results = array_merge($results, self::buscarPropietarioApellido($query)); - $results = array_merge($results, self::buscarPropietarioNombreCompleto($query)); - } - return $results; - } - protected static function buscarPropietarioNombres($query) - { - $results = \Model::factory(Venta::class) - ->select('venta.*') - ->join('propietario', ['propietario.rut', '=', 'venta.propietario']) - ->whereLike('propietario.nombres', '%' . $query . '%') - ->findMany(); - return $results; - } - protected static function buscarPropietarioApellido($query) - { - $results = \Model::factory(Venta::class) - ->select('venta.*') - ->join('propietario', ['propietario.rut', '=', 'venta.propietario']) - ->whereAnyIs([ - ['propietario.apellido_paterno' => '%' . $query . '%'], - ['propietario.apellido_materno' => '%' . $query . '%'] - ], 'LIKE') - ->findMany(); - return $results; - } - protected static function buscarPropietarioNombreCompleto($query) - { - $results = \Model::factory(Venta::class) - ->select('venta.*') - ->join('propietario', ['propietario.rut', '=', 'venta.propietario']) - ->whereRaw("CONCAT_WS(' ', propietario.nombres, propietario.apellido_paterno, propietario.apellido_materno) LIKE '%" . $query . "%'") - ->findMany(); - return $results; - } - protected static function buscarPrecioVenta($query) - { - if (is_array($query)) { - $results = []; - foreach ($query as $segment) { - $results = array_merge($results, self::buscarPrecioVenta($segment)); - } - } else { - $query = str_replace([',', '.'], ['.', ''], $query); - $results = \Model::factory(Venta::class)->where('valor_uf', $query)->findMany(); - } - return $results; - } - protected static function buscarProyecto($query) - { - if (is_array($query)) { - $results = []; - foreach ($query as $segment) { - $results = array_merge($results, self::buscarProyecto($segment)); - } - } else { - $results = model(Venta::class) - ->select('venta.*') - ->join('propiedad', ['propiedad.id', '=', 'venta.propiedad']) - ->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal']) - ->join('proyecto', ['proyecto.id', '=', 'unidad.proyecto']) - ->whereLike('proyecto.descripcion', '%' . $query . '%') - ->findMany(); - } - return $results; - } - protected static function buscarPago($query) - { - if (is_array($query)) { - $results = []; - foreach ($query as $segment) { - $results = array_merge($results, self::buscarPrecioVenta($segment)); - } - } else { - $query = str_replace(',', '.', str_replace('.', '', $query)); - $query2 = (float) $query; - if ($query != $query2) { - return []; - } - if (!is_float($query2)) { - return []; - } - $query = $query2; - $results = self::buscarValorCuota($query); - $results = array_merge($results, self::buscarReajuste($query)); - $results = array_merge($results, self::buscarEscritura($query)); - $results = array_merge($results, self::buscarSubsidio($query)); - $results = array_merge($results, self::buscarCredito($query)); - } - return $results; - } - protected static function buscarValorCuota($query) - { - $results = \Model::factory(Venta::class) - ->select('venta.*') - ->join('cuota', ['cuota.pie', '=', 'venta.pie']) - ->join('pago', ['pago.id', '=', 'cuota.pago']) - ->whereRaw("`pago`.`valor` = " . $query . " OR `pago`.`valor` / `pago`.`uf` = " . $query) - ->findMany(); - return $results; - } - protected static function buscarReajuste($query) - { - $results = \Model::factory(Venta::class) - ->select('venta.*') - ->join('pie', ['pie.id', '=', 'venta.pie']) - ->join('pago', ['pago.id', '=', 'pie.reajuste']) - ->whereRaw("`pago`.`valor` = " . $query . " OR `pago`.`valor` / `pago`.`uf` = " . $query) - ->findMany(); - return $results; - } - protected static function buscarEscritura($query) - { - $results = \Model::factory(Venta::class) - ->select('venta.*') - ->join('escritura', ['escritura.id', '=', 'venta.escritura']) - ->join('pago', ['pago.id', '=', 'escritura.pago']) - ->whereRaw("`pago`.`valor` = " . $query . " OR `pago`.`valor` / `pago`.`uf` = " . $query) - ->findMany(); - return $results; - } - protected static function buscarSubsidio($query) - { - $results = \Model::factory(Venta::class) - ->select('venta.*') - ->join('subsidio', ['subsidio.id', '=', 'venta.subsidio']) - ->join('pago', ['pago.id', '=', 'subsidio.pago']) - ->whereRaw("`pago`.`valor` = " . $query . " OR `pago`.`valor` / `pago`.`uf` = " . $query) - ->findMany(); - return $results; - } - protected static function buscarCredito($query) - { - $results = \Model::factory(Venta::class) - ->select('venta.*') - ->join('credito', ['credito.id', '=', 'venta.credito']) - ->join('pago', ['pago.id', '=', 'credito.pago']) - ->whereRaw("`pago`.`valor` = " . $query . " OR `pago`.`valor` / `pago`.`uf` = " . $query) - ->findMany(); - return $results; - } - protected static function buscarUnidad($query) - { - if (is_array($query)) { - $results = []; - foreach ($query as $segment) { - $results = array_merge($results, self::buscarUnidad($segment)); - } - } else { - $results = model(Unidad::class)->where('descripcion', $query)->findMany(); - foreach ($results as $i => $u) { - if ($u->venta()) { - unset($results[$i]); - } - } - } - return $results; - } -} -?> diff --git a/app/Controller/Cierres.php b/app/Controller/Cierres.php deleted file mode 100644 index 46a76b9..0000000 --- a/app/Controller/Cierres.php +++ /dev/null @@ -1,428 +0,0 @@ -select('proyecto.*') - ->join('estado_proyecto', ['estado.proyecto', '=', 'proyecto.id'], 'estado') - ->join('tipo_estado_proyecto', ['tipo.id', '=', 'estado.estado'], 'tipo') - ->join('etapa_proyecto', ['etapa.id', '=', 'tipo.etapa'], 'etapa') - ->whereGte('etapa.orden', 3) - ->orderByAsc('proyecto.descripcion') - ->groupBy('proyecto.id') - ->findMany(); - $regiones = model(Region::class)->order_by_asc('numeracion')->findMany(); - return view('ventas.cierres.add', compact('proyectos', 'regiones')); - } - public static function agregar() - { - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $id_proyecto = post('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id_proyecto); - $id_agente = post('agente'); - $agente = model(Agente::class)->findOne($id_agente); - - $direccion = model(Direccion::class) - ->where('calle', post('calle')) - ->where('numero', post('numero')) - ->where('extra', post('extra')) - ->where('comuna', post('comuna')) - ->findOne(); - if (!$direccion) { - $data = [ - 'calle' => post('calle'), - 'numero' => post('numero'), - 'extra' => post('extra'), - 'comuna' => post('comuna') - ]; - $direccion = model(Direccion::class)->create($data); - $direccion->save(); - } - - list($rut, $dv) = explode('-', str_replace('.', '', post('rut'))); - $propietario = model(Propietario::class)->findOne($rut); - if (!$propietario) { - $data = [ - 'rut' => $rut, - 'dv' => $dv, - 'nombres' => trim(post('nombres')), - 'apellido_paterno' => post('paterno'), - 'apellido_materno' => post('materno'), - 'sexo' => post('sexo'), - 'estado_civil' => post('estado_civil'), - 'profesion' => post('profesion'), - 'direccion' => $direccion->id, - 'telefono' => post('codigo_telefono') . post('telefono'), - 'email' => post('email') . '@' . post('email_domain'), - 'representante' => 0, - 'otro' => 0 - ]; - $propietario = model(Propietario::class)->create($data); - $propietario->save(); - } - - $unis = json_decode(post('unidades')); - $id_principal = array_shift($unis); - $unidad = model(Unidad::class)->findOne(post('unidad' . $id_principal)); - $u = model(U::class)->findOne($unidad->id); - if (!$u) { - $unidad->save(); - } - $data = [ - 'unidad_id' => $unidad->id - ]; - $reserva = model(Reserva::class)->create($data); - $reserva->save(); - foreach ($unis as $id_unidad) { - $unidad = model(Unidad::class)->findOne(post('unidad' . $id_unidad)); - $data = [ - 'reserva_id' => $reserva->id, - 'unidad_id' => $unidad->id - ]; - $ur = model(UnidadReserva::class)->create($data); - $ur->save(); - } - - $data = [ - 'proyecto_id' => $proyecto->id, - 'agente_id' => $agente->id, - 'propietario_rut' => $propietario->rut, - 'reserva_id' => $reserva->id, - 'fecha' => $f->format('Y-m-d'), - 'valor' => correctNumber(post('valor')), - 'pie' => correctNumber(post('pie')), - 'credito' => correctNumber(post('credito')), - 'estado' => 1 - ]; - $cierre = model(Cierre::class)->create($data); - $cierre->save(); - header('Location: ' . url('', ['p' => 'cierres', 'a' => 'list'])); - } - public static function list() - { - $proyectos = Cierre::proyectos(); - - return view('ventas.cierres.list', compact('proyectos')); - } - public static function show() - { - $id = get('cierre'); - $cierre = model(Cierre::class)->findOne($id); - - return view('ventas.cierres.show', compact('cierre')); - } - public static function guardar() - { - $proyecto = \model(Proyecto::class)->findOne(post('proyecto')); - $fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $unidad = \model(Unidad::class)->findOne(post('departamento')); - $relacionado = (post('relacionado') === true) ? true : false; - $subrelacionado = (post('subrelacionado') === true) ? true : false; - $precio = (float) post('precio') ?: 0; - $input = [ - 'proyecto' => $proyecto, - 'fecha' => $fecha, - 'departamento' => $unidad, - 'precio' => $precio, - 'relacionado' => $relacionado, - 'subrelacionado' => $subrelacionado, - 'unidades' => [], - 'pie' => (float) post('pie') - ]; - $ebs = 0; - if (post('unidades') != '') { - $unidades = json_decode(html_entity_decode(post('unidades')), true); - foreach ($unidades as $un) { - $u = \model(Unidad::class)->findOne($un); - $input['unidades'] []= $u; - if ($u->precio($fecha) !== false) { - $ebs += $u->precio($fecha)->valor; - } - } - } - $promo = 0; - if (post('promocion') != null) { - $promo = (float) post('promocion'); - $input['promocion'] = $promo; - } - $bono = 0; - if (post('bono') != null) { - $bono = (float) post('bono'); - $input['bono'] = $bono; - } - $operador = 0; - if (post('operador') != null) { - $operador = ($precio - $bono - $promo) * (float) post('operador') / 100; - $input['operador'] = $operador; - } - - $cierre = Cierre::find($proyecto, $unidad, $precio)->findOne(); - if ($cierre === false) { - $cierre = model(Cierre::class)->create(); - $cierre->guardar((object) $input); - } - $output = ['status' => 'ok', 'cierre' => $cierre->asArray()]; - return json_encode($output); - } - public static function aprobar() - { - $fecha = Carbon::today(config('app.timezone')); - $cierre = model(Cierre::class)->findOne(post('cierre')); - if ($cierre->estado()->tipo()->descripcion == "revisado" or $cierre->estado()->tipo()->descripcion == "rechazado") { - $cierre->aprobar($fecha); - return json_encode(['estado' => 'aprobado']); - } - return json_encode(['estado' => 'no vigente']); - } - public static function rechazar() - { - $fecha = Carbon::today(config('app.timezone')); - $cierre = model(Cierre::class)->findOne(post('cierre')); - if ($cierre->estado()->tipo()->vigente == 1) { - $cierre->rechazar($fecha); - return json_encode(['estado' => 'rechazado']); - } - return json_encode(['estado' => 'no vigente']); - } - public static function abandonar() - { - $id = get('cierre'); - $cierre = model(Cierre::class)->findOne($id); - $tipo = model(TipoEstadoCierre::class)->where('descripcion', 'abandonado')->findOne(); - $today = Carbon::today(config('app.timezone')); - $data = [ - 'cierre' => $cierre->id, - 'tipo' => $tipo->id, - 'fecha' => $today->format('Y-m-d') - ]; - $estado = model(EstadoCierre::class)->create($data); - $estado->save(); - header('Location: ' . url('', ['p' => 'cierres', 'a' => 'list'])); - } - public static function promesar() - { - $id = get('cierre'); - $cierre = model(Cierre::class)->findOne($id); - $tipo = model(TipoEstadoCierre::class)->where('descripcion', 'promesado')->findOne(); - $today = Carbon::today(config('app.timezone')); - $data = [ - 'cierre' => $cierre->id, - 'tipo' => $tipo->id, - 'fecha' => $today->format('Y-m-d') - ]; - $estado = model(EstadoCierre::class)->create($data); - $estado->save(); - header('Location: ' . url('', ['p' => 'cierres', 'a' => 'show', 'cierre' => $cierre->id])); - } - public static function borrador() - { - $id = get('cierre'); - $cierre = model(Cierre::class)->findOne($id); - - $borrador = new Borrador($cierre); - d($borrador->show()); - $borrador->create(); - } - public static function evalue() - { - $proyectos = \model(Proyecto::class)->orderByAsc('descripcion')->findMany(); - return view('ventas.cierres.evaluar', ['proyectos' => $proyectos, 'locations' => config('locations')]); - } - public static function evaluar() - { - $proyecto = \model(Proyecto::class)->findOne(post('proyecto')); - $fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $unidad = \model(Unidad::class)->findOne(post('departamento')); - $relacionado = (post('relacionado') === 'true') ? true : false; - $subrelacionado = (post('subrelacionado') === 'true') ? true : false; - $precio = (float) post('precio') ?: 0; - $neto = $precio; - $ebs = 0; - if (post('unidades') != '') { - $unidades = json_decode(html_entity_decode(post('unidades')), true); - foreach ($unidades as $un) { - $u = \model(Unidad::class)->findOne($un); - if ($u->precio($fecha) !== false) { - $ebs += $u->precio($fecha)->valor; - } - } - } - $promocion = 0; - if (post('promocion') != null) { - $promocion = (float) post('promocion'); - } - $bono = 0; - if (post('bono') != null) { - $bono = (float) post('bono'); - } - $operador = 0; - if (post('operador') != null) { - $operador = ($precio - $bono - $promocion) * (float) post('operador') / 100; - } - $rel = 0; - if ($relacionado) { - $rel = ($unidad->precio($fecha)->valor) * 6 / 100; - } - if ($subrelacionado) { - $rel = ($unidad->precio($fecha)->valor) * 3 / 100; - } - $neto = $precio - $bono - $promocion - $operador - $ebs; - - $output = [ - 'unidad' => [ - 'tipo' => [ - 'nombre' => $unidad->tipologia()->nombre, - 'tipologia' => $unidad->tipologia()->tipologia()->descripcion - ], - 'superficie' => format('m2', $unidad->m2()) . ' m²' - ], - 'oferta' => [ - 'bruto' => format('ufs', $precio, null, true), - 'neto' => format('ufs', $neto, null, true), - 'uf_m2' => format('ufs', $neto / $unidad->m2('vendible'), null, true) . '/m²', - 'fecha' => format('shortDate', $unidad->precio($fecha)->inicio()->fecha()) - ], - 'lista' => [ - 'precio' => format('ufs', $unidad->precio($fecha)->valor, null, true), - 'uf_m2' => format('ufs', $unidad->precio($fecha)->valor / $unidad->m2('vendible'), null, true) . '/m²' - ], - 'precios' => [ - 'bruto' => format('ufs', $precio, null, true), - 'neto' => format('ufs', $neto, null, true), - 'departamento' => format('ufs', $unidad->precio($fecha)->valor, null, true), - 'relacionado' => format('ufs', $unidad->precio($fecha)->valor - $rel, null, true), - 'fecha' => format('shortDate', $unidad->precio($fecha)->inicio()->fecha()) - ], - 'uf_m2' => [ - 'neto' => format('ufs', $neto / $unidad->m2('vendible'), null, true) . '/m²', - 'departamento' => format('ufs', $unidad->precio($fecha)->valor / $unidad->m2('vendible'), null, true) . '/m²', - 'relacionado' => format('ufs', ($unidad->precio($fecha)->valor - $rel) / $unidad->m2('vendible'), null, true) . '/²' - ], - 'evaluacion' => Cierre::evaluar($neto, $unidad, $fecha, $rel), - 'estado' => ['id' => 0, 'descripcion' => 'no existe'] - ]; - if ($rel > 0) { - $output ['relacionado'] = [ - 'precio' => format('ufs', $unidad->precio($fecha)->valor - $rel, null, true), - 'uf_m2' => format('ufs', ($unidad->precio($fecha)->valor - $rel) / $unidad->m2('vendible'), null, true) . '/²' - ]; - } - $estado = Cierre::find($proyecto, $unidad, $precio)->findOne(); - if ($estado) { - $output['estado'] = [ - 'id' => $estado->estado()->tipo()->id, - 'cierre' => $estado->id, - 'descripcion' => $estado->estado()->tipo()->descripcion, - 'fecha' => format('shortDate', $estado->estado()->fecha) - ]; - } - - return json_encode($output); - } - public static function edit() - { - $cierre = model(Cierre::class)->findOne(get('cierre')); - $proyectos = model(Proyecto::class)->findMany(); - $regiones = model(Region::class)->findMany(); - $valores = model(TipoValorCierre::class)->findMany(); - return view('ventas.cierres.edit', compact('cierre', 'proyectos', 'regiones', 'valores')); - } - public static function do_edit() - { - $cierre = model(Cierre::class)->findOne(get('cierre')); - - $data = [ - 'calle' => post('calle'), - 'numero' => post('numero'), - 'extra' => post('extra'), - 'comuna' => post('comuna') - ]; - $direccion = (new Factory(Direccion::class))->where($data)->find(); - if (!$direccion) { - $direccion = model(Direccion::class)->create($data); - $direccion->save(); - } - if (post('rut') != '') { - $data = [ - 'rut' => explode('-', str_replace('.', '', post('rut')))[0], - ]; - $propietario = (new Factory(Propietario::class))->where($data)->find(); - if (!$propietario) { - $data = array_merge($data, [ - 'nombres' => post('nombres'), - 'apellido_paterno' => post('paterno'), - 'apellido_materno' => post('materno'), - 'dv' => (post('rut')) ? explode('-', str_replace('.', '', post('rut')))[1] : '', - 'sexo' => post('sexo'), - 'estado_civil' => post('estado_civil'), - 'profesion' => post('profesion'), - 'telefono' => post('codigo_telefono') . post('telefono'), - 'email' => post('email') . '@' . post('email_domain'), - 'direccion' => $direccion->id - ]); - $propietario = model(Propietario::class)->create($data); - $propietario->save(); - } - } - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $data = [ - 'proyecto' => post('proyecto'), - 'precio' => post('precio'), - 'fecha' => $f->format('Y-m-d'), - 'relacionado' => (post('relacionado')) ? 1 : 0, - 'propietario' => (isset($propietario) and $propietario) ? $propietario->rut : 0 - ]; - foreach ($data as $field => $value) { - if ($value != $cierre->$field) { - $cierre->$field = $value; - } - } - $cierre->save(); - - $valores = model(TipoValorCierre::class)->findMany(); - foreach ($valores as $valor) { - if (post($valor->descripcion) == '') { - continue; - } - if ($cierre->valor($valor->descripcion)) { - if ($cierre->valor($valor->descripcion)->valor != post($valor->descripcion)) { - $v = $cierre->valor($valor->descripcion); - $v->valor = post($valor->descripcion); - $v->save(); - } - continue; - } - $data = [ - 'tipo' => $valor->descripcion, - 'valor' => post($valor->descripcion) - ]; - $cierre->addValor($data); - } - header('Location: ' . nUrl('cierres', 'show', ['cierre' => $cierre->id])); - } -} -?> diff --git a/app/Controller/Comentarios.php b/app/Controller/Comentarios.php deleted file mode 100644 index 494fcc6..0000000 --- a/app/Controller/Comentarios.php +++ /dev/null @@ -1,39 +0,0 @@ -findOne(get('venta')); - echo view('ventas.comentarios.add', compact('venta')); - } - public static function agregar() - { - $venta = \Model::factory(\Incoviba\old\Venta\Venta::class)->findOne(get('venta')); - if ($venta === false) { - throw new Exception('Venta no existe.'); - } - $data = [ - 'venta' => $venta->id, - 'fecha' => \Carbon\Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s'), - 'texto' => post('comentario') - ]; - $comentario = \Model::factory(\Incoviba\old\Venta\Comentario::class)->create($data); - $comentario->save(); - header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); - } - public static function delete() - { - $comentario = \Model::factory(\Incoviba\old\Venta\Comentario::class)->findOne(get('comentario')); - $venta = $comentario->venta(); - $comentario->estado = 0; - $comentario->save(); - header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); - } -} -?> diff --git a/app/Controller/Contabilidad.php b/app/Controller/Contabilidad.php deleted file mode 100644 index 4b19a77..0000000 --- a/app/Controller/Contabilidad.php +++ /dev/null @@ -1,100 +0,0 @@ -orderByAsc('descripcion')->findMany(); - foreach ($proyectos as &$proyecto) { - $arr = $proyecto->asArray(); - $arr['direccion'] = $proyecto->direccion()->asArray(); - $arr['direccion']['comuna'] = $proyecto->direccion()->comuna()->asArray(); - $arr['inmobiliaria'] = $proyecto->inmobiliaria()->asArray(); - $proyecto = $arr; - } - return json_encode(compact('proyectos')); - } - public static function get_fechas() { - $id_proyecto = get('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id_proyecto); - $cuotas = []; - foreach ($proyecto->ventas() as $venta) { - $cs = $venta->pie()->cuotas(); - $cuotas = array_merge($cs, array_filter($cs, function($item) { - $tipo = $item->pago()->estado()->tipo(); - return ($tipo == 'depositado' or $tipo == 'abonado'); - })); - } - $fechas = array_map(function($item) { - return [ - 'timestamp' => $item->pago()->estado()->fecha()->timestamp, - 'short' => $item->pago()->estado()->fecha()->format('Y-m-d'), - 'long' => $item->pago()->estado()->fecha()->format('d / m / Y') - ]; - }, $cuotas); - usort($fechas, function($a, $b) { - return $b['timestamp'] - $a['timestamp']; - }); - return json_encode(compact('fechas')); - } - public static function get_pagos_fechas() { - $id_proyecto = get('proyecto'); - $fecha = Carbon::parse(get('fecha')); - $proyecto = model(Proyecto::class)->findOne($id_proyecto); - $pagos = []; - foreach ($proyecto->ventas() as $venta) { - foreach ($venta->pie()->cuotas() as $cuota) { - if ($cuota->pago()->estado()->fecha() == $fecha) { - $pagos []= [ - 'Departamento' => $venta->propiedad()->unidad()->descripcion, - 'Valor' => [ - 'UF' => $cuota->pago()->valor('ufs'), - 'Pesos' => $cuota->pago()->valor() - ], - 'Numero' => $cuota->numero(), - 'Total' => $venta->pie()->cuotas - ]; - break; - } - } - } - return json_encode(compact('pagos')); - } - public static function pagos_fecha() { - $fecha = Carbon::now(); - return view('contabilidad.pagos', compact('fecha')); - } - public static function show_pagos() { - $id_proyecto = get('proyecto'); - $fecha = Carbon::parse(get('fecha')); - $proyecto = model(Proyecto::class)->findOne($id_proyecto); - $pagos = []; - foreach ($proyecto->ventas() as $venta) { - foreach ($venta->pie()->cuotas() as $cuota) { - if ($cuota->pago()->estado()->fecha() == $fecha) { - $pagos []= (object) [ - 'Departamento' => $venta->propiedad()->unidad()->descripcion, - 'Valor' => (object) [ - 'UF' => $cuota->pago()->valor('ufs'), - 'Pesos' => $cuota->pago()->valor() - ], - 'Numero' => $cuota->numero(), - 'Total' => $venta->pie()->cuotas - ]; - break; - } - } - } - return view('contabilidad.pago', compact('proyecto', 'fecha', 'pagos')); - } -} diff --git a/app/Controller/Creditos.php b/app/Controller/Creditos.php deleted file mode 100644 index 60a72da..0000000 --- a/app/Controller/Creditos.php +++ /dev/null @@ -1,207 +0,0 @@ -findOne($id); - return view('ventas.creditos.add', compact('venta')); - } - public static function agregado() - { - $id = get('venta'); - if ($id == null) { - header('Location: .'); - } - $venta = \Model::factory(Venta::class)->findOne($id); - - $banco = \Model::factory(Banco::class)->where('nombre', post('banco'))->findOne(); - $f = Carbon::createFromDate(post('y'), post('m'), post('d'), config('app.timezone')); - $uf = uf($f); - - $pago = \Model::factory(Pago::class)->create(); - $pago->banco = $banco->id; - $pago->fecha = $f->format('Y-m-d'); - $pago->uf = $uf->uf->value; - $pago->valor = post('valor') * $pago->uf; - $pago->tipo = 2; - - $credito = \Model::factory(Credito::class)->create(); - $credito->banco = $pago->banco; - $credito->valor = $pago->valor; - $credito->fecha = $pago->fecha; - $credito->uf = $pago->uf; - - $pago->new(); - - $credito->pago = $pago->id; - $credito->save(); - - $venta->credito = $credito->id; - $venta->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function pagar() - { - $id = get('venta'); - $venta = \Model::factory(Venta::class)->findOne($id); - return view('ventas.creditos.pagar', compact('venta')); - } - public static function pagando() - { - $id = get('venta'); - $venta = \Model::factory(Venta::class)->findOne($id); - $valor = str_replace(',', '.', str_replace('.', '', post('valor'))); - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - - $pago = $venta->credito()->pago(); - if ($pago->valor != $valor) { - $pago->valor = $valor; - } - - $estado = \Model::factory(EstadoPago::class)->create(); - $estado->pago = $pago->id; - $estado->fecha = $f->format('Y-m-d'); - $estado->estado = 1; - $estado->save(); - - if ($pago->is_dirty('valor')) { - $pago->save(); - } - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function abonar() - { - $id = get('venta'); - $venta = \Model::factory(Venta::class)->findOne($id); - return view('ventas.creditos.abonar', compact('venta')); - } - public static function abonando() - { - $id = get('venta'); - $venta = \Model::factory(Venta::class)->findOne($id); - $valor = str_replace(',', '.', str_replace('.', '', post('valor'))); - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - - $pago = $venta->credito()->pago(); - if ($pago->valor != $valor) { - $pago->valor = $valor; - } - - $estado = \Model::factory(EstadoPago::class)->create(); - $estado->pago = $pago->id; - $estado->fecha = $f->format('Y-m-d'); - $estado->estado = 2; - - $estado->save(); - - if ($pago->is_dirty('valor')) { - $pago->save(); - } - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function show() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - return view('ventas.creditos.show', compact('venta')); - } - public static function edit() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - return view('ventas.creditos.edit', compact('venta')); - } - public static function editado() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - $pago = $venta->credito()->pago(); - - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $uf = uf($f); - $banco = model(Banco::class)->where('nombre', post('banco'))->findOne(); - $valor = correctNumber(post('valor')) * $uf->uf->value; - - $fields = ['valor', 'uf', 'fecha', 'banco']; - $data = ['valor' => $valor, 'uf' => $uf->uf->value, 'fecha' => $f->format('Y-m-d'), 'banco' => $banco->id]; - - $change = false; - foreach ($fields as $field) { - if ($pago->$field != $data[$field]) { - $change = true; - $pago->$field = $data[$field]; - if ($field == 'fecha') { - $eps = $pago->estados(); - foreach ($eps as $ep) { - if ($ep->estado == 0) { - $ep->fecha = $data[$field]; - $ep->save(); - break; - } - } - } - } - } - - if ($change) { - $pago->save(); - } - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function remove() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - $pago = $venta->credito()->pago(); - $f = Carbon::today(config('app.timezone')); - - $data = [ - 'pago' => $pago->id, - 'estado' => -3, - 'fecha' => $f->format('Y-m-d') - ]; - $estado = model(EstadoPago::class)->create($data); - $estado->save(); - $venta->credito = 0; - $venta->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function pendientes() - { - $creditos = model(Credito::class) - ->select('credito.*') - ->join('venta', ['venta.credito', '=', 'credito.id']) - ->join('pago', ['pago.id', '=', 'credito.pago']) - ->rawJoin('JOIN (SELECT ep.* FROM (SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago ep ON ep.id = e0.id)', ['estado_pago.pago', '=', 'pago.id'], 'estado_pago') - ->whereLt('estado_pago.estado', 2) - ->where('venta.estado', 1) - ->orderByAsc('estado_pago.fecha') - ->findMany(); - return view('ventas.creditos.pendientes', compact('creditos')); - } -} -?> diff --git a/app/Controller/Cuotas.php b/app/Controller/Cuotas.php deleted file mode 100644 index 4d457ba..0000000 --- a/app/Controller/Cuotas.php +++ /dev/null @@ -1,230 +0,0 @@ -findOne($id); - - return view('ventas.pies.cuotas.show', compact('cuota')); - } - public static function edit() - { - $id = get('cuota'); - $cuota = \Model::factory(Cuota::class)->findOne($id); - return view('ventas.pies.cuotas.edit', compact('cuota')); - } - public static function editar() - { - $id = get('cuota'); - $cuota = \Model::factory(Cuota::class)->findOne($id); - - $cuota->numero = post('numero'); - $cuota->{'valor_$'} = post('valor'); - $banco = \Model::factory(\Incoviba\old\Common\Banco::class)->where('nombre', post('banco'))->findOne(); - if ($banco) { - $cuota->banco = $banco->id; - } else { - $cuota->banco = 0; - } - $f = \Carbon\Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $cuota->fecha = $f->format('Y-m-d'); - $pago = $cuota->pago(); - $pago->valor = post('valor'); - $pago->banco = $banco->id; - $pago->identificador = post('identificador'); - $pago->fecha = $f->format('Y-m-d'); - $uf = uf($f); - if ($uf->total > 0) { - $pago->uf = $uf->uf->value; - } else { - $pago->uf = 0; - } - - $pago->save(); - $cuota->save(); - header('Location: ' . url('', ['p' => 'pies', 'a' => 'resumen', 'pie' => $cuota->pie()->id])); - } - public static function edited() - { - $id = get('cuota'); - $cuota = \Model::factory(Cuota::class)->findOne($id); - $pago = $cuota->pago(); - foreach ($_POST as $key => $value) { - $pago->$key = $value; - } - $pago->save(); - } - public static function pendientes() - { - $f = \Carbon\Carbon::today(config('app.timezone')); - $cuotas = \Model::factory(Cuota::class) - ->select('cuota.*') - ->join('pago', ['pago.id', '=', 'cuota.pago']) - ->join('venta', ['venta.pie', '=', 'cuota.pie']) - ->raw_join('JOIN (SELECT e1.* FROM (SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago e1 ON e1.id = e0.id)', ['ep.pago', '=', 'pago.id'], 'ep') - ->where('ep.estado', 0) - ->where('venta.estado', 1) - ->whereLte('pago.fecha', $f->format('Y-m-d')) - ->order_by_asc('pago.fecha') - ->findMany(); - $sum = 0; - if (count($cuotas) > 0) { - $sum = array_reduce($cuotas, function($carry, $item) { - $carry += $item->pago()->valor; - return $carry; - }); - } - setlocale(LC_TIME, 'es'); - return view('ventas.pies.cuotas.pendientes', compact('cuotas', 'sum')); - } - public static function depositar() - { - $id = post('cuota'); - $cuota = \Model::factory(Cuota::class)->findOne($id); - if ($cuota->pago()->estado()->estado == 1) { - return 'ok'; - } - $estado = \Model::factory(EstadoPago::class)->create(); - $estado->pago = $cuota->pago()->id; - $estado->estado = 1; - $f = Carbon::parse(post('fecha'), config('app.timezone')); - $estado->fecha = $f->format('Y-m-d'); - $estado->save(); - return 'ok'; - } - public static function remove() - { - $id = get('cuota'); - $cuota = \Model::factory(Cuota::class)->findOne($id); - - $estado = \Model::factory(EstadoPago::class)->create(); - $estado->pago = $cuota->pago()->id; - $estado->estado = -3; - $f = Carbon::today(config('app.timezone')); - $estado->fecha = $f->format('Y-m-d'); - $estado->save(); - header('Location: ' . url('', ['p' => 'pies', 'a' => 'resumen', 'pie' => $cuota->pie()->id])); - } - public static function para_abonar() - { - $cuotas = \Model::factory(Cuota::class) - ->select('cuota.*') - ->join('pago', ['pago.id', '=', 'cuota.pago']) - ->join('venta', ['venta.pie', '=', 'cuota.pie']) - ->raw_join('JOIN (SELECT e1.* FROM (SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago e1 ON e1.id = e0.id)', ['ep.pago', '=', 'pago.id'], 'ep') - ->where('ep.estado', 1) - ->where('venta.estado', 1) - ->order_by_asc('ep.fecha') - ->findMany(); - $ini = get('start'); - if ($ini == null) { - $ini = 0; - } - $n = get('step'); - if ($n == 0) { - $n = 30; - } - $total = count($cuotas); - $cuotas = array_slice($cuotas, $ini, $n); - $pages = ceil($total / $n); - $current = ($ini + $n) / $n; - return view('ventas.pies.cuotas.abonar', compact('cuotas', 'total', 'pages', 'current')); - } - public static function abonar() - { - $id = post('cuota'); - $cuota = \Model::factory(Cuota::class)->findOne($id); - if ($cuota->pago()->estado()->estado == 2) { - return 'ok'; - } - $estado = \Model::factory(EstadoPago::class)->create(); - $estado->pago = $cuota->pago()->id; - $estado->estado = 2; - $f = Carbon::parse(post('fecha'), config('app.timezone')); - $estado->fecha = $f->format('Y-m-d'); - $estado->save(); - return 'ok'; - } - public static function rebotar() - { - $id = post('cuota'); - $cuota = \Model::factory(Cuota::class)->findOne($id); - if ($cuota->pago()->estado()->estado == -1) { - return 'ok'; - } - $estado = \Model::factory(EstadoPago::class)->create(); - $estado->pago = $cuota->pago()->id; - $estado->estado = -1; - $f = Carbon::parse(post('fecha'), config('app.timezone')); - $estado->fecha = $f->format('Y-m-d'); - $estado->save(); - return 'ok'; - } - public static function add() - { - $id = get('pie'); - $pie = \Model::factory(Pie::class)->findOne($id); - return view('ventas.pies.cuotas.add', compact('pie')); - } - public static function agregar() - { - $id = get('pie'); - $pie = \Model::factory(Pie::class)->findOne($id); - - $cant = $pie->cuotas - count($pie->cuotas()); - for ($i = 0; $i < $cant; $i ++) { - if (trim(post('valor' . $i)) == '') { - continue; - } - $banco = \Model::factory(Banco::class)->where('nombre', post('banco' . $i))->findOne(); - $f = Carbon::createFromDate(post('year' . $i), post('month' . $i), post('day' . $i), config('app.timezone')); - $uf = uf($f); - $valor = correctNumber(post('valor' . $i)); - - $pago = \Model::factory(Pago::class)->create(); - $pago->banco = $banco->id; - $pago->fecha = $f->format('Y-m-d'); - if ($uf and $uf->total > 0) { - $pago->uf = $uf->uf->value; - } else { - $pago->uf = 0; - } - $pago->tipo = 1; - $pago->valor = $valor; - $pago->identificador = post('identificador' . $i); - - $cuota = \Model::factory(Cuota::class)->create(); - $cuota->pie = $pie->id; - $cuota->fecha = $pago->fecha; - $cuota->{'valor_$'} = $pago->valor; - $cuota->estado = 0; - $cuota->banco = $pago->banco; - $cuota->uf = $pago->uf; - $cuota->numero = post('numero' . $i); - - $pago->new(); - - $cuota->pago = $pago->id; - $cuota->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $pie->venta()->id])); - } - } -} -?> diff --git a/app/Controller/Devoluciones.php b/app/Controller/Devoluciones.php deleted file mode 100644 index 8d9c41c..0000000 --- a/app/Controller/Devoluciones.php +++ /dev/null @@ -1,19 +0,0 @@ -findOne($id); - - return view('print.devolucion', compact('venta')); - } -} -?> diff --git a/app/Controller/Escrituras.php b/app/Controller/Escrituras.php deleted file mode 100644 index f2cb056..0000000 --- a/app/Controller/Escrituras.php +++ /dev/null @@ -1,212 +0,0 @@ -findOne($id); - return view('ventas.escrituras.add', compact('venta')); - } - public static function agregar() - { - $id = get('venta'); - $venta = \Model::factory(Venta::class)->findOne($id); - - $f = Carbon::createFromDate(post('escritura_year'), post('escritura_month'), post('escritura_day'), config('app.timezone')); - $venta->escriturado = $f->format('Y-m-d'); - - if (post('valor_reajuste')) { - $reajuste = \Model::factory(Pago::class)->create(); - $reajuste->valor = correctNumber(post('valor_reajuste')); - $fp = Carbon::createFromDate(post('reajuste_year'), post('reajuste_month'), post('reajuste_day'), config('app.timezone')); - $reajuste->fecha = $fp->format('Y-m-d'); - $reajuste->uf = (float) uf($fp)->uf->value; - $reajuste->newPagado(); - - $pie = $venta->pie(); - $pie->reajuste = $reajuste->id; - $pie->save(); - } - if (post('escritura_valor') or post('escritura_valor_uf')) { - $pago = \Model::factory(Pago::class)->create(); - $fp = Carbon::createFromDate(post('pago_escritura_year'), post('pago_escritura_month'), post('pago_escritura_day'), config('app.timezone')); - $pago->fecha = $fp->format('Y-m-d'); - $pago->uf = (float) uf($fp)->uf->value; - if (post('escritura_valor')) { - $pago->valor = correctNumber(post('escritura_valor')); - $pago->newPagado(); - } else { - $pago->valor = correctNumber(post('escritura_valor_uf')) * $pago->uf; - $pago->new(); - } - - $escritura = \Model::factory(Escritura::class)->create(); - $escritura->pago = $pago->id; - $escritura->valor = $pago->valor('uf'); - $escritura->fecha = $pago->fecha; - $escritura->save(); - - $venta->escritura = $escritura->id; - } - if (post('subsidio_ahorrado') or post('subsidio_valor')) { - $total = post('subsidio_ahorrado') + post('subsidio_valor'); - $subsidio = \Model::factory(Subsidio::class)->create(); - $pago = \Model::factory(Pago::class)->create(); - $pago->fecha = $f->format('Y-m-d'); - $pago->uf = (float) uf($f)->uf->value; - $pago->valor = correctNumber(post('subsidio_ahorrado')) * $pago->uf; - $pago->new(); - $subsidio->pago = $pago->id; - $pago = \Model::factory(Pago::class)->create(); - $pago->fecha = $f->format('Y-m-d'); - $pago->uf = (float) uf($f)->uf->value; - $pago->valor = correctNumber(post('subsidio_valor')) * $pago->uf; - $pago->new(); - $subsidio->subsidio = $pago->id; - $subsidio->save(); - - $venta->subsidio = $subsidio->id; - } - if (post('credito_valor')) { - $pago = \Model::factory(Pago::class)->create(); - $pago->fecha = $f->format('Y-m-d'); - $pago->uf = (float) uf($f)->uf->value; - $valor = post('credito_valor'); - if (strpos($valor, ',') !== false) { - $valor = correctNumber($valor); - } - $pago->valor = $valor * $pago->uf; - $banco = \Model::factory(Banco::class)->where('nombre', post('credito_banco'))->findOne(); - $pago->banco = $banco->id; - $pago->new(); - - $credito = \Model::factory(Credito::class)->create(); - $credito->pago = $pago->id; - $credito->save(); - - $venta->credito = $credito->id; - } elseif (post('credito_banco')) { - $pago = $venta->credito()->pago(); - $banco = \Model::factory(Banco::class)->where('nombre', post('credito_banco'))->findOne(); - $pago->banco = $banco->id; - $pago->save(); - } - - $tipo = \Model::factory(TipoEstadoVenta::class)->where('descripcion', 'escriturando')->findOne(); - $data = [ - 'venta' => $venta->id, - 'estado' => $tipo->id, - 'fecha' => $venta->escriturado - ]; - $estado = \Model::factory(EstadoVenta::class)->create($data); - $estado->save(); - $venta->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function edit() - { - $id = get('venta'); - $venta = \Model::factory(Venta::class)->findOne($id); - echo view('ventas.escrituras.edit', compact('venta')); - } - public static function editar() - { - $id = get('venta'); - $venta = \Model::factory(Venta::class)->findOne($id); - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $uf = uf($f); - - $valor = correctNumber(post('valor')); - if ($valor == '') { - $valor_uf = correctNumber(post('valor_uf')); - $valor = $valor_uf * $uf->uf->value; - } - $pago = $venta->escritura()->pago(); - if ($pago->valor != $valor) { - $pago->valor = $valor; - } - if ($pago->fecha != $f->format('Y-m-d')) { - $pago->fecha = $f->format('Y-m-d'); - $pago->uf = $uf->uf->value; - } - - $pago->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function informe() - { - $id = get('venta'); - $venta = \Model::factory(Venta::class)->findOne($id); - return view('ventas.escrituras.informe', compact('venta')); - } - public static function pagar() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - return view('ventas.escrituras.pagar', compact('venta')); - } - public static function pagado() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - - $data = [ - 'pago' => $venta->escritura()->pago()->id, - 'fecha' => $f->format('Y-m-d'), - 'estado' => 1 - ]; - $estado = model(EstadoPago::class)->create($data); - $estado->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function abonar() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - return view('ventas.escrituras.abonar', compact('venta')); - } - public static function abonado() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - - $data = [ - 'pago' => $venta->escritura()->pago()->id, - 'fecha' => $f->format('Y-m-d'), - 'estado' => 2 - ]; - $estado = model(EstadoPago::class)->create($data); - $estado->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } -} -?> diff --git a/app/Controller/FormaPago.php b/app/Controller/FormaPago.php deleted file mode 100644 index 6ccc7b3..0000000 --- a/app/Controller/FormaPago.php +++ /dev/null @@ -1,98 +0,0 @@ -findOne($id); - - return view('ventas.forma_pago.edit', compact('venta')); - } - public static function editar() - { - d(post()); - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - $valor = correctNumber(post('valor_pie')); - $cuotas = post('cuotas_pie'); - if ($venta->pie != 0) { - $pie = $venta->pie(); - $changed = false; - if ($pie->valor != $valor) { - $pie->valor = $valor; - $changed = true; - } - if ($pie->cuotas != $cuotas) { - $pie->cuotas = $cuotas; - $changed = true; - } - if ($changed) { - d($pie); - } - - $valor = correctNumber(post('valor_reajuste')); - $f = Carbon::createFromDate(post('year_reajuste'), post('month_reajuste'), post('day_reajuste'), config('app.timezone')); - $uf = uf($f); - $reajuste = $pie->reajuste(); - $changed = false; - if ($reajuste->valor != $valor) { - $reajuste->valor = $valor; - $changed = true; - } - if ($reajuste->fecha != $f->format('Y-m-d')) { - $reajuste->fecha = $f->format('Y-m-d'); - $reajuste->uf = $uf->uf->value; - $changed = true; - } - if ($changed) { - d($reajuste); - } - } elseif ($valor != '') { - $f = Carbon::parse($venta->fecha, config('app.timezone')); - $uf = uf($f); - $data = [ - 'valor' => $valor, - 'cuotas' => $cuotas, - 'uf' => $uf->uf->value, - 'fecha' => $f->format('Y-m-d') - ]; - $pie = model(Pie::class)->create($data); - d($pie); - } - - $valor = correctNumber(post('valor_escritura')); - $f = Carbon::createFromDate(post('year_escritura'), post('month_escritura'), post('day_escritura'), config('app.timezone')); - if ($venta->escritura != 0) { - $escritura = $venta->escritura(); - d($escritura); - } elseif ($valor != '') { - $data = [ - 'valor' => $valor, - 'fecha' => $f->format('Y-m-d'), - 'uf' => $uf->uf->value, - 'tipo' => 7 - ]; - $pago = model(Pago::class)->create($data); - $pago->newPagado(); - $data['pago'] = $pago->id; - unset($data['tipo']); - $escritura = model(Escritura::class)->create($data); - $escritura->save(); - $venta->escritura = $escritura->id; - $venta->save(); - } - } -} -?> diff --git a/app/Controller/Informes.php b/app/Controller/Informes.php deleted file mode 100644 index bc40396..0000000 --- a/app/Controller/Informes.php +++ /dev/null @@ -1,832 +0,0 @@ -find_one($id_proyecto); - $ini = \Carbon\Carbon::parse($proyecto->estado()->fecha, config('app.timezone')); - #$informe = new Informador('Carta Gantt Proyecto - ' . $proyecto->descripcion); - $name = 'Carta Gantt Proyecto - ' . $proyecto->descripcion; - $hoy = Carbon::now(config('app.timezone')); - $filename = str_replace('ñ', 'n', $name . ' - ' . $hoy->format('Y-m-d') . '.xls'); - $informe = new PHPExcel($name, $filename); - - $columnas = ['Departamento', 'Propietario', 'Entrega', 'Estado']; - $today = \Carbon\Carbon::today(config('app.timezone')); - $end = $today->copy()->addDays(30); - $dif = $end->diffInDays($ini); - for ($i = 0; $i <= $dif; $i ++) { - $f = $ini->copy()->addDays($i); - if ($f->isWeekend()) { - continue; - } - $columnas []= $f->format('Y-m-d'); - } - $informe->addColumns($columnas); - - $data = []; - foreach ($proyecto->entregas() as $venta) { - $info = []; - $info []= $venta->unidad()->descripcion; - $info []= $venta->propietario()->findOne()->nombreCompleto(); - $fe = Carbon::parse($venta->entrega()->find_one()->fecha, config('app.timezone')); - $info []= $fe->format('Y-m-d'); - $info []= ''; - - for ($i = 0; $i <= $dif; $i ++) { - $f = $ini->copy()->addDays($i); - if ($f->isWeekend()) { - continue; - } - if ($f >= $fe and $f <= $fe->copy()->addDays(14)) { - $info []= 'X'; - } else { - $info []= ''; - } - } - - $data []= $info; - } - $informe->addDatas($data); - - return $informe->informe(); - } else { - $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many(); - return view('informes.gantt_entregas', compact('proyectos')); - } - } - public static function escrituras() - { - if (get('proyecto')) { - set_time_limit(60); - $id_proyecto = get('proyecto'); - $proyecto = model(Proyecto::class)->find_one($id_proyecto); - - #$informe = new Informador('Escrituras - ' . $proyecto->descripcion); - $name = 'Escrituras'; - $hoy = Carbon::now(config('app.timezone')); - $filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls'); - $informe = new PHPExcel($name, $filename); - - $columnas = [ - 'Departamento', - 'Estacionamientos', - 'Bodegas', - 'Propietario', - (object) ['name' => 'Promesa', 'style' => 'number'], - ['name' => 'Bono Pie', 'style' => 'amount'], - ['name' => 'Pie Pagado', 'style' => 'amount'], - ['name' => 'Reajuste', 'style' => 'amount'], - ['name' => 'Abono Contado', 'style' => 'amount'], - ['name' => 'Subsidio', 'style' => 'amount'], - 'Estado Subsidio', - ['name' => 'Credito', 'style' => 'amount'], - 'Banco', - 'Estado Credito', - ['name' => 'Saldo', 'style' => 'amount'], - ['name' => 'Escritura', 'style' => 'amount'], - ['name' => 'Entrega', 'style' => 'date'] - ]; - $informe->addColumns($columnas); - - //$ventas = $proyecto->escrituras(); - $ventas = $proyecto->ventas(); - - $data = []; - foreach ($ventas as $venta) { - $info = []; - $info['Departamento'] = $venta->unidad()->descripcion; - $ests = []; - foreach ($venta->propiedad()->estacionamientos() as $e) { - $ests []= $e->descripcion; - } - $bods = []; - foreach ($venta->propiedad()->bodegas() as $b) { - $bods []= $b->descripcion; - } - $info['Estacionamientos'] = implode(' - ', $ests); - $info['Bodegas'] = implode(' - ', $bods); - $info['Propietario'] = $venta->propietario()->nombreCompleto(); - $info['Promesa'] = $venta->valor_uf; - $saldo = $venta->valor_uf; - $info['Bono Pie'] = ''; - if ($venta->bono_pie != 0) { - $info['Bono Pie'] = $venta->bonoPie()->pago()->valor('ufs'); - $saldo -= $venta->bonoPie()->pago()->valor('ufs'); - } - $info['Pie'] = ''; - $info['Reajuste'] = ''; - if ($venta->pie != 0) { - $info['Pie'] = $venta->pie()->valorPagado(); - $saldo -= $venta->pie()->valorPagado(); - if ($venta->pie()->reajuste != 0) { - $info['Reajuste'] = $venta->pie()->reajuste()->valor('ufs'); - $saldo -= $venta->pie()->reajuste()->valor('ufs'); - } - } - $info['Abono Contado'] = ''; - if ($venta->escritura != 0) { - $info['Abono Contado'] = $venta->escritura()->pago()->valor('ufs'); - $saldo -= $venta->escritura()->pago()->valor('ufs'); - } - $info['Subsidio'] = ''; - $info['Estado Subsidio'] = ''; - if ($venta->subsidio != 0) { - $info['Subsidio'] = $venta->subsidio()->total('ufs'); - $info['Estado Subsidio'] = implode(' - ', [ - $venta->subsidio()->subsidio()->estado()->tipo()->descripcion, - $venta->subsidio()->pago()->estado()->tipo()->descripcion - ]); - $saldo -= $venta->subsidio()->total('ufs'); - } - $info['Credito'] = ''; - $info['Banco'] = ''; - $info['Estado Credito'] = ''; - if ($venta->credito != 0) { - $info['Credito'] = $venta->credito()->pago()->valor('ufs'); - $saldo -= $venta->credito()->pago()->valor('ufs'); - if ($venta->credito()->pago()->banco != 0) { - $info['Banco'] = $venta->credito()->pago()->banco()->nombre; - } - $info['Estado Credito'] = $venta->credito()->pago()->estado()->tipo()->descripcion; - } - $info['Saldo'] = -$saldo; - $info['Escritura'] = ''; - if ($venta->escriturado != 0) { - $info['Escritura'] = $venta->escriturado; - } - $info['Entrega'] = ''; - if ($venta->entregado != 0) { - $info['Entrega'] = $venta->entregado; - } - - $data []= $info; - } - $informe->addData($data); - - return $informe->informe(); - } else { - $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many(); - return view('informes.escrituras', compact('proyectos')); - } - } - public static function consolidacion() - { - $id_proyecto = get('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id_proyecto); - - $ventas = $proyecto->ventas(); - set_time_limit(count($ventas)); - - $f = Carbon::today(config('app.timezone')); - setlocale(LC_TIME, 'es'); - - $data = [ - [$proyecto->descripcion], - [strftime('%d de %B de %Y', $f->timestamp)], - [''], - [''] - ]; - $columns = [ - ['name' => 'Fecha', 'style' => 'date'], - 'Glosa', - ['name' => 'Debe', 'style' => 'number'], - ['name' => 'Haber', 'style' => 'number'], - ['name' => 'Saldo', 'style' => 'number'], - 'Comentario' - ]; - $bold_rows = []; - - foreach ($ventas as $venta) { - $data []= ['Departamento ' . $venta->unidad()->descripcion . ' (' . format('ufs', $venta->valor_uf) . ' UF)']; - $data []= $columns; - $bold_rows []= count($data) - 1; - $ufs = 0; - $debe = 0; - $haber = 0; - $sum = 0; - if ($venta->pie != 0) { - $cuotas = $venta->pie()->cuotas(); - foreach ($cuotas as $cuota) { - $sum += $cuota->pago()->valor(); - $ufs += $cuota->pago()->valor('ufs'); - $haber += $cuota->pago()->valor(); - $info = [ - $cuota->pago()->estado()->fecha, - 'Pie - Cuota ' . $cuota->numero() . ' - ' . $venta->pie()->cuotas . ' (' . format('ufs', $cuota->pago()->valor('ufs')) . ' UF)', - '', - $cuota->pago()->valor(), - $sum - ]; - if ($cuota->pago()->estado()->estado < 2) { - $info []= 'No ha sido abonada.'; - } - $data []= $info; - } - if ($venta->pie()->reajuste != 0) { - $sum += $venta->pie()->reajuste()->valor(); - $ufs += $venta->pie()->reajuste()->valor('ufs'); - $haber += $venta->pie()->reajuste()->valor(); - $info = [ - $venta->pie()->reajuste()->estado()->fecha, - 'Reajuste (' . format('ufs', $venta->pie()->reajuste()->valor('ufs')) . ' UF)', - '', - $venta->pie()->reajuste()->valor(), - $sum - ]; - if ($venta->pie()->reajuste()->estado()->estado < 2) { - $info []= 'No ha sido abonado.'; - } - $data []= $info; - } - } - if ($venta->escritura != 0) { - $sum += $venta->escritura()->pago()->valor(); - $ufs += $venta->escritura()->pago()->valor('ufs'); - $haber += $venta->escritura()->pago()->valor(); - $info = [ - $venta->escritura()->pago()->estado()->fecha, - 'Abono Escritura (' . format('ufs', $venta->escritura()->pago()->valor('ufs')) . ' UF)', - '', - $venta->escritura()->pago()->valor(), - $sum - ]; - if ($venta->escritura()->pago()->estado()->estado < 2) { - $info []= 'No ha sido abonado.'; - } - $data []= $info; - } - if ($venta->credito != 0) { - $sum += $venta->credito()->pago()->valor(); - $ufs += $venta->credito()->pago()->valor('ufs'); - $haber += $venta->credito()->pago()->valor(); - $info = [ - $venta->credito()->pago()->estado()->fecha, - 'Crédito (' . format('ufs', $venta->credito()->pago()->valor('ufs')) . ' UF)', - '', - $venta->credito()->pago()->valor(), - $sum - ]; - if ($venta->credito()->pago()->estado()->estado < 2) { - $info []= 'No ha sido pagado.'; - } - $data []= $info; - } - if ($venta->bono_pie != 0) { - try { - $sum -= $venta->bonoPie()->pago()->valor(); - $debe += $venta->bonoPie()->pago()->valor(); - $info = [ - $venta->bonoPie()->pago()->estado()->fecha, - 'Bono Pie (' . format('ufs', $venta->bonoPie()->pago()->valor('ufs')) . ' UF)'. - $venta->bonoPie()->pago()->valor(), - '', - $sum - ]; - $data []= $info; - $sum += $venta->bonoPie()->pago()->valor(); - $haber += $venta->bonoPie()->pago()->valor(); - $info = [ - $venta->bonoPie()->pago()->estado()->fecha, - 'Bono Pie (' . format('ufs', $venta->bonoPie()->pago()->valor('ufs')) . ' UF)'. - '', - $venta->bonoPie()->pago()->valor(), - $sum - ]; - $data []= $info; - } catch (\Exception $e) { - - } - } - $info = [ - '', - 'TOTAL (' . format('ufs', $ufs) . ' UF)', - $debe, - $haber, - $sum - ]; - $data []= $info; - $bold_rows []= count($data) - 1; - - $data []= ['']; - } - /** - * Departamento # - * Fecha |Glosa |Debe |Haber |Saldo - * |Pie - Cuota 1 - n (# UF) |- |$# | - * |Reajuste (# UF) |- |$# | - * |Abono Escritura (# UF) |- |$# | - * |Crédito (# UF) |- |$# | - * |Bono Pie (# UF) |$# |- | - * |Bono Pie (# UF) |- |$# | - * |Devolución (# UF) |$# |- | - * - |TOTAL (# UF) | | | - */ - - array_walk($data, function(&$e, $i) use ($columns) { - if (count($e) < count($columns)) { - $n = count($columns) - count($e); - for ($j = 0; $j < $n; $j ++) { - $e []= ''; - } - } - }); - - #$informe = new Informador('Consolidación - ' . $proyecto->descripcion); - $name = 'Consolidación'; - $hoy = Carbon::now(config('app.timezone')); - $filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls'); - $informe = new PHPExcel($name, $filename); - $informe->addColumns($columns); - $informe->addData($data); - - return $informe->informe(); - } - public static function creditos_pendientes() - { - function creditos() { - $creditos = model(Credito::class) - ->select('credito.*') - ->join('venta', ['venta.credito', '=', 'credito.id']) - ->join('pago', ['pago.id', '=', 'credito.pago']) - ->rawJoin('JOIN (SELECT ep.* FROM (SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago ep ON ep.id = e0.id)', ['estado_pago.pago', '=', 'pago.id'], 'estado_pago') - ->whereLt('estado_pago.estado', 2) - ->where('venta.estado', 1) - ->orderByAsc('estado_pago.fecha') - ->findMany(); - foreach ($creditos as $credito) { - yield $credito; - } - } - $informe = new Informador('Créditos Pendientes'); - - $columnas = ['Proyecto', 'Departamento', 'Valor', 'Fecha Escritura', 'Estado']; - $informe->addColumns($columnas); - - $row = 0; - foreach (creditos() as $credito) { - $informe->addData($row, $credito->venta()->proyecto()->descripcion, 'Proyecto'); - $informe->addData($row, $credito->venta()->unidad()->descripcion, 'Departamento'); - $informe->addData($row, $credito->pago()->valor('ufs'), 'Valor'); - $informe->addData($row, (($credito->venta()->escriturado) ? $credito->venta()->escriturado : $credito->pago()->estado()->fecha), 'Fecha Escritura'); - $informe->addData($row, ucwords($credito->pago()->estado()->tipo()->descripcion), 'Estado'); - - $row ++; - } - - $date = [ - 'numberFormat' => ['short-date'] - ]; - $ufs = [ - 'numberFormat' => ['thousands'] - ]; - $formats = ['Valor' => $ufs, 'Fecha Escritura' => $date]; - $informe->addFormats($formats); - - return $informe->informe(); - } - public static function ventas() - { - if (get('proyecto')) { - ini_set('memory_limit', "1G"); - ini_set('max_execution_time', '3600'); - $id = get('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id); - $ventas = $proyecto->ventas(); - - /*usort($ventas, function($a, $b) { - return $a->fecha()->timestamp - $b->fecha()->timestamp; - });*/ - - $procasa = model(Agente::class)->findOne(1); - $pa = model(ProyectoAgente::class)->where('agente', $procasa->id)->where('proyecto', $proyecto->id)->findOne(); - if ($pa) { - $comision = $pa->comision / 100; - } else { - $comision = 0.03; - } - - #$informe = new Informador('Ventas - ' . $proyecto->descripcion); - $name = 'Informe de Ventas'; - $hoy = Carbon::now(config('app.timezone')); - $filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xlsx'); - //$informe = new PHPExcel($name, $filename); - - $columnas = [ - 'Propietario', - 'Departamento', - ['name' => 'Estacionamientos', 'style' => 'number'], - ['name' => 'Bodegas', 'style' => 'number'], - 'Fecha Venta', - ['name' => 'Mes', 'style' => 'mes'], - 'Tipo', - ['name' => 'm² Ponderados', 'style' => 'amount'], - ['name' => 'Valor Promesa', 'style' => 'amount'], - ['name' => 'Pie', 'style' => 'amount'], - ['name' => 'Pie Pagado', 'style' => 'amount'], - ['name' => '% Pie Pagado', 'style' => 'percent'], - ['name' => 'Bono Pie', 'style' => 'amount'], - 'Operador', - ['name' => 'Valor Operador', 'style' => 'amount'], - ['name' => 'Premios', 'style' => 'amount'], - ['name' => 'Subsidio', 'style' => 'amount'], - ['name' => 'Ahorro', 'style' => 'amount'], - ['name' => 'Credito', 'style' => 'amount'], - 'Banco', - ['name' => 'Valor Ests & Bods', 'style' => 'amount'], - ['name' => 'Valor Neto', 'style' => 'amount'], - ['name' => 'UF/m²*', 'style' => 'amount'], - ['name' => 'Comision', 'style' => 'amount'], - ['name' => 'Venta s/Comision', 'style' => 'amount'], - ['name' => 'Precio', 'style' => 'Amount'] - ]; - //$informe->addColumns($columnas); - - $data = []; - foreach ($ventas as $venta) { - $info = []; - $info['Propietario'] = mb_strtoupper($venta->propietario()->nombreCompleto()); - $info['Departamento'] = implode(' - ', array_map(function($item) { - return $item->descripcion; - }, $venta->propiedad()->departamentos())); - $es = $venta->propiedad()->estacionamientos(); - $info['Estacionamientos'] = implode(', ', array_map(function($item) { - return $item->descripcion; - }, $es)); - $bs = $venta->propiedad()->bodegas(); - $info['Bodegas'] = implode(', ', array_map(function($item) { - return $item->descripcion; - }, $bs)); - $info['Fecha Venta'] = $venta->fecha()->format('Y-m-d'); - $info['Mes'] = $venta->fecha()->format('M-y'); - $info['Tipo'] = $venta->unidad()->abreviacion; - $info['m² Ponderados'] = $venta->unidad()->m2('vendible'); - $info['Valor Promesa'] = $venta->valor_uf; - $info['Pie'] = 0; - if ($venta->pie()) { - $info['Pie'] = $venta->pie()->valor; - } - $info['Pie Pagado'] = 0; - $info['% Pie Pagado'] = 0; - if ($venta->pie()) { - $info['Pie Pagado'] = $venta->pie()->valorPagado('uf'); - $info['% Pie Pagado'] = $venta->pie()->valorPagado('uf') / $venta->valor_uf; - } - - $info['Bono Pie'] = ($venta->bono_pie == 0 or $venta->bonoPie() === false) ? '' : $venta->bonoPie()->pago()->valor('ufs'); - $info['Operador'] = ($venta->agente and $venta->agente()->agente()->tipo == 19) ? $venta->agente()->agente()->descripcion : ''; - $info['Valor Operador'] = $venta->valorComision(); - //$promos = 0; - $ps = $venta->promociones(); - $info['Premios'] = array_reduce($ps, function($sum, $item) { - return $sum + $item->valor; - }); - $info['Subsidio'] = 0; - $info['Ahorro'] = 0; - if ($venta->subsidio != 0) { - $info['Subsidio'] = $venta->subsidio()->subsidio()->valor('ufs'); - $info['Ahorro'] = $venta->subsidio()->pago()->valor('ufs'); - } - $info['Credito'] = 0; - $info['Banco'] = ''; - if ($venta->credito != 0 and $venta->credito()->pago()) { - $info['Credito'] = $venta->credito()?->pago()->valor('ufs'); - if ($venta->credito()?->pago()->banco != 0) { - $info['Banco'] = $venta->credito()?->pago()->banco()->nombre; - } - } - $info['Valor Ests & Bods'] = $venta->valorEstacionamientosYBodegas(); - $info['Valor Neto'] = $venta->valorFinal(); - $info['UF/m²*'] = $venta->uf_m2(); - $info['Comision'] = $venta->valorFinal() * $comision; - $info['Venta s/Comision'] = $venta->valorFinal() - $info['Comision']; - $fecha = $venta->fecha(); - $info['Precio'] = 0; - try { - $info['Precio'] = array_reduce($venta->propiedad()->departamentos(), function($sum, $item) use ($fecha) { - if (!$item->precio($fecha)) { - return $sum; - } - return $sum + $item->precio($fecha)->valor; - }); - } catch (\Exception $e) { - } - - $data []= $info; - } - - $body = [ - "Proyecto" => $proyecto->descripcion, - "Compañía" => $proyecto->inmobiliaria()->abreviacion, - "data" => $data - ]; - $client = new Client(['base_uri' => "{$_ENV['PYTHON_HOST']}"]); - $response = $client->post('/ventas', ['json' => $body]); - - header("Content-Type: application/octet-stream; charset=utf-8"); - header('Content-Transfer-Encoding: binary'); - header('Content-Disposition: attachment; filename="' . $filename . '"'); - header('Cache-Control: max-age=0'); - return $response->getBody(); - //file_put_contents('php://output', $output); - - } else { - $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many(); - return view('informes.ventas', compact('proyectos')); - } - } - public static function resumen_contabilidad() - { - if (get('proyecto')) { - $id = get('proyecto'); - $fecha = get('fecha'); - - $service = new Resumen(); - $service->build($id, new \DateTimeImmutable($fecha)); - return ''; - } else { - $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many(); - return view('informes.resumen_contabilidad', compact('proyectos')); - } - } - public static function contabilidad() - { - if (get('proyecto')) { - $id = get('proyecto'); - $fecha = get('fecha'); - $mes = null; - if ($fecha != null) { - $mes = Carbon::parse($fecha); - } - $proyecto = model(Proyecto::class)->findOne($id); - $q = "SELECT pago.*, venta.id AS vid, venta.tipo AS ctipo, venta.pie AS pie - FROM ( - SELECT pago.id, banco.nombre AS banco, pago.fecha, pago.valor, pago.uf, ep.estado, ep.fecha AS efecha - FROM pago JOIN banco ON banco.id = pago.banco JOIN (( - SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago ep ON ep.id = e0.id) ON ep.pago = pago.id - WHERE ep.estado > 0 "; - if ($mes != null) { - $q .= "AND (pago.fecha BETWEEN '" . $mes->format('Y-m-01') . "' AND '" . $mes->format('Y-m-t') . "' - OR ep.fecha BETWEEN '" . $mes->format('Y-m-01') . "' AND '" . $mes->format('Y-m-t') . "')"; - } - $q .= ") pago JOIN (SELECT venta.* - FROM (( - SELECT venta.id, venta.pie, venta.propiedad, credito.pago, 'credito' AS tipo - FROM venta JOIN credito ON credito.id = venta.credito) - UNION ALL ( - SELECT venta.id, venta.pie, venta.propiedad, escritura.pago, 'escritura' AS tipo - FROM venta JOIN escritura ON escritura.id = venta.escritura) - UNION ALL ( - SELECT venta.id, venta.pie, venta.propiedad, cuota.pago, 'cuota' AS tipo - FROM venta JOIN cuota ON cuota.pie = venta.pie)) venta - JOIN propiedad ON propiedad.id = venta.propiedad - JOIN unidad ON unidad.id = propiedad.unidad_principal - WHERE unidad.proyecto = ?) venta - ON venta.pago = pago.id"; - $st = \ORM::getDB()->prepare($q); - $st->execute([$id]); - if ($st->rowCount() > 0) { - $R = $st->fetchAll(\PDO::FETCH_OBJ); - - //$informe = new Informador('Contabilidad - ' . (($mes != null) ? $mes->format('Y-m') . ' - ' : '') . $proyecto->descripcion); - $name = 'Contabilidad'; - $hoy = Carbon::now(config('app.timezone')); - $filename = str_replace('ñ', 'n', 'Contabilidad - ' . (($mes != null) ? $mes->format('Y-m') . ' - ' : '') . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls'); - - $informe = new PHPExcel($name, $filename); - - $columnas = ['Proyecto', 'Fecha', 'Banco', 'Departamento', 'RUT', 'Propietario', 'Glosa', 'Glosa2', (object) ['name' => 'Valor', 'style' => 'integer'], (object) ['name' => 'Valor UF', 'style' => 'currency']]; - $informe->addColumns($columnas); - $data = []; - foreach ($R as $r) { - $info = []; - $info['Proyecto'] = $proyecto->descripcion; - $f1 = \Carbon\Carbon::parse($r->fecha, config('app.timezone')); - $f2 = \Carbon\Carbon::parse($r->efecha, config('app.timezone')); - $info['Fecha'] = ($f1->max($f2))->format('Y-m-d'); - $info['Banco'] = $r->banco; - $venta = model(Venta::class)->findOne($r->vid); - $info['Departamento'] = $venta->unidad()->descripcion; - $info['RUT'] = $venta->propietario()->rut(); - $info['Propietario'] = $venta->propietario()->nombreCompleto(); - $info['Glosa'] = ucwords($r->ctipo); - $info['Glosa2'] = ''; - if ($r->ctipo == 'cuota') { - $cuota = model(Cuota::class)->where('pago', $r->id)->findOne(); - - $info['Glosa'] = 'Pie - ' . format('ufs', $cuota->pie()->valor('ufs'), null, true); - - $info['Glosa2'] = $cuota->numero() . ' - ' . $cuota->pie()->cuotas; - } - $info['Valor'] = $r->valor; - $info['Valor UF'] = '0'; - if ($r->uf > 0) { - $info['Valor UF'] = $r->valor / $r->uf; - } - $data []= $info; - } - - $informe->addData($data); - - return $informe->informe(); - } - } else { - setlocale(LC_TIME, 'es_ES'); - $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many(); - return view('informes.contabilidad', compact('proyectos')); - } - } - public static function para_comision() - { - $proyectos = model(Proyecto::class)->orderByAsc('descripcion')->findMany(); - return view('informes.para_comision', compact('proyectos')); - } - public static function comisiones() - { - $id = post('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id); - $unidades = explode('-', str_replace([';', '.', ':', ' ', PHP_EOL, '|', '+', ','], '-', post('unidades'))); - $ventas = model(Venta::class) - ->select('venta.*') - ->join('propiedad', ['propiedad.id', '=', 'venta.propiedad']) - ->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal']) - ->where('unidad.proyecto', $proyecto->id) - ->where('venta.estado', 1) - ->whereIn('unidad.descripcion', $unidades) - ->orderByExpr('FIELD(unidad.descripcion, ' . implode(', ', $unidades) . ')') - ->findMany(); - $ids = []; - $totales = (object) ['precio' => 0, 'neto' => 0, 'comision' => 0]; - foreach ($ventas as $venta) { - $ids []= $venta->id; - $totales->precio += $venta->valor_uf; - $totales->neto += $venta->valorCorredora(); - $totales->comision += $venta->valorCorredora() * 1.5 / 100; - } - return view('informes.comisiones', compact('ventas', 'proyecto', 'totales', 'ids')); - } - public static function comisiones_xlsx() - { - $id_ventas = explode(',', get('ventas')); - $ventas = model(Venta::class) - ->whereIn('id', $id_ventas) - ->orderByExpr('FIELD(id, ' . implode(', ', $id_ventas) . ')') - ->findMany(); - - $informe = new Informador('Comisiones - ' . $ventas[0]->proyecto()->descripcion); - $columnas = ['Departamento', 'Estacionamientos', 'Bodegas', 'Propietario', 'Precio', '% Com', 'Com UF']; - $informe->addColumns($columnas); - $data = []; - foreach ($ventas as $venta) { - $info = []; - $info['Departamento'] = $venta->unidad()->descripcion; - $info['Estacionamientos'] = implode(' - ', $venta->propiedad()->estacionamientos('array')); - $info['Bodegas'] = implode(' - ', $venta->propiedad()->bodegas('array')); - $info['Propietario'] = $venta->propietario()->nombreCompleto(); - $info['Precio'] = "'" . format('ufs', $venta->valorCorredora()); - $info['% Com'] = '1,5 %'; - $info['Com UF'] = "'" . format('ufs', $venta->valorCorredora() * 1.5 / 100); - $data []= $info; - } - - $informe->addDatas($data); - - return $informe->informe(); - } - public static function cuotas() - { - $id_venta = get('venta'); - $venta = model(Venta::class)->findOne($id_venta); - - $name = 'Cuotas - ' . $venta->unidad()->descripcion; - $hoy = Carbon::now(config('app.timezone')); - $filename = str_replace('ñ', 'n', $name . ' - ' . $venta->proyecto()->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls'); - $informe = new PHPExcel($name, $filename); - $columnas = [ - ['name' => 'Cuota', 'style' => 'number'], - ['name' => 'Fecha Cuota', 'style' => 'date'], - 'Banco', - 'Identificador', - ['name' => 'Valor $', 'style' => 'number'], - ['name' => 'Valor UF', 'style' => 'currency'], - ['name' => 'Fecha Pago', 'style' => 'date'] - ]; - $informe->addColumns($columnas); - $data = []; - foreach ($venta->pie()->cuotas() as $cuota) { - $info = []; - $info['Cuota'] = $cuota->numero(); - $info['Fecha Cuota'] = $cuota->pago()->fecha()->format('Y-m-d'); - $info['Banco'] = $cuota->pago()->banco()->descripcion; - $info['Identificador'] = $cuota->pago()->identificador; - $info['Valor $'] = $cuota->pago()->valor(); - $info['Valor UF'] = $cuota->pago()->valor('ufs'); - $info['Fecha Pago'] = $cuota->pago()->estado()->fecha()->format('Y-m-d'); - $data []= $info; - } - $informe->addData($data); - - return $informe->informe(); - } - public static function resciliaciones() - { - if (get('proyecto')) { - $id = get('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id); - $ventas = $proyecto->resciliaciones(); - - usort($ventas, function($a, $b) { - return $a->fecha()->timestamp - $b->fecha()->timestamp; - }); - - $name = 'Resciliaciones'; - $hoy = Carbon::now(config('app.timezone')); - $filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls'); - $informe = new PHPExcel($name, $filename); - - $columnas = [ - 'Propietario', - ['name' => 'Departamento', 'style' => 'number'], - ['name' => 'Estacionamientos', 'style' => 'number'], - ['name' => 'Bodegas', 'style' => 'number'], - 'Fecha Venta', - 'Fecha Resciliación', - ['name' => 'Mes', 'style' => 'mes'], - 'Tipo', - ['name' => 'm² Ponderados', 'style' => 'amount'], - ['name' => 'Valor Promesa', 'style' => 'amount'], - ]; - $informe->addColumns($columnas); - - $data = []; - foreach ($ventas as $venta) { - $info = []; - $info['Propietario'] = mb_strtoupper($venta->propietario()->nombreCompleto()); - $info['Departamento'] = $venta->unidad()->descripcion; - $ests = []; - if ($venta->propiedad()->estacionamientos != '') { - $es = $venta->propiedad()->estacionamientos(); - foreach ($es as $e) { - $ests []= $e->descripcion; - } - } - $info['Estacionamientos'] = implode(', ', $ests); - $bods = []; - if ($venta->propiedad()->bodegas != '') { - $bs = $venta->propiedad()->bodegas(); - foreach ($bs as $b) { - $bods []= $b->descripcion; - } - } - $info['Bodegas'] = implode(', ', $bods); - $info['Fecha Venta'] = $venta->fecha()->format('d.m.Y'); - $info['Fecha Resciliación'] = $venta->estado()->fecha()->format('d.m.Y'); - $info['Mes'] = $venta->estado()->fecha()->format('M-y'); - $info['Tipo'] = $venta->unidad()->abreviacion; - $info['m² Ponderados'] = $venta->unidad()->m2('vendible'); - $info['Valor Promesa'] = $venta->valor_uf; - - $data []= $info; - } - $informe->addData($data); - - $totals = [ - 'Departamento' => 'count', - 'Estacionamientos' => 'count', - 'Bodegas' => 'count', - 'm² Ponderados' => 'sum', - 'Valor Promesa' => 'sum' - ]; - $informe->addTotals($totals); - - return $informe->informe(); - } else { - $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many(); - return view('informes.resciliaciones', compact('proyectos')); - } - } -} diff --git a/app/Controller/Inmobiliarias.php b/app/Controller/Inmobiliarias.php deleted file mode 100644 index f0b8910..0000000 --- a/app/Controller/Inmobiliarias.php +++ /dev/null @@ -1,74 +0,0 @@ -orderByAsc('abreviacion')->findMany(); - return view('inmobiliarias.list', compact('inmobiliarias')); - } - public static function show() - { - $rut = get('rut'); - $inmobiliaria = model(Inmobiliaria::class)->findOne($rut); - return view('inmobiliarias.show', compact('inmobiliaria')); - } - public static function add() - { - $sociedades = model(TipoSociedad::class)->findMany(); - return view('inmobiliarias.add', compact('sociedades')); - } - public static function agregar() - { - list($rut, $dv) = explode('-', str_replace('.', '', post('rut'))); - - $inmobiliaria = model(Inmobiliaria::class)->findOne($rut); - if ($inmobiliaria) { - header('Location: ' . url('', ['p' => 'inmobiliarias', 'a' => 'show', 'rut' => $inmobiliaria->rut])); - die(); - } - - $inmobiliaria = model(Inmobiliaria::class)->create(); - $inmobiliaria->rut = $rut; - $inmobiliaria->dv = $dv; - $inmobiliaria->razon = post('razon'); - $inmobiliaria->abreviacion = post('abrev'); - $inmobiliaria->sociedad = post('sociedad'); - - $inmobiliaria->save(); - header('Location: ' . url('', ['p' => 'inmobiliarias', 'a' => 'show', 'rut' => $inmobiliaria->rut])); - } - public static function edit() - { - $sociedades = model(TipoSociedad::class)->findMany(); - $rut = get('rut'); - $inmobiliaria = model(Inmobiliaria::class)->findOne($rut); - $bancos = model(Banco::class)->findMany(); - usort($bancos, function($a, $b) { - return strcmp($a->nombre, $b->nombre); - }); - return view('inmobiliarias.edit', compact('inmobiliaria', 'bancos', 'sociedades')); - } - public static function do_edit() - { - $rut = get('rut'); - $inmobiliaria = model(Inmobiliaria::class)->findOne($rut); - foreach (post() as $field => $value) { - if ($value != '' and $inmobiliaria->{$field} != $value) { - $inmobiliaria->{$field} = $value; - } - } - - $inmobiliaria->save(); - header('Location: ' . nUrl('inmobiliarias', 'show', ['rut' => $inmobiliaria->rut])); - } -} -?> diff --git a/app/Controller/Operadores.php b/app/Controller/Operadores.php deleted file mode 100644 index 765ba2a..0000000 --- a/app/Controller/Operadores.php +++ /dev/null @@ -1,47 +0,0 @@ -findOne(get('proyecto')); - $operadores = model(Agente::class) - ->select('agente.*') - ->join('agente_tipo', ['agente_tipo.agente', '=', 'agente.id']) - ->join('tipo_agente', ['tipo_agente.id', '=', 'agente_tipo.tipo']) - ->where('tipo_agente.descripcion', 'operador') - ->orderByAsc('agente.abreviacion') - ->findMany(); - $vigentes = array_map(function($item) { - return $item->agente()->agente(); - }, $proyecto->operadoresVigentes()); - echo view('proyectos.operadores.add', compact('proyecto', 'operadores', 'vigentes')); - } - public static function add() - { - $proyecto = model(Proyecto::class)->findOne(get('proyecto')); - $fecha = Carbon::today(config('app.timezone')); - foreach (post('operadores') as $op) { - $operador = model(Agente::class)->findOne($op); - $at = $operador->tipos(19); - $data = [ - 'proyecto' => $proyecto->id, - 'agente' => $at->id, - 'fecha' => $fecha->format('Y-m-d'), - 'comision' => 2 - ]; - $pa = model(ProyectoAgente::class)->create($data); - $pa->new(); - } - header('Location: ' . nUrl('proyectos', 'show', ['proyecto' => $proyecto->id])); - } -} diff --git a/app/Controller/Other.php b/app/Controller/Other.php deleted file mode 100644 index eb90f31..0000000 --- a/app/Controller/Other.php +++ /dev/null @@ -1,71 +0,0 @@ -create(); - $unidad = \Model::factory(Unidad::class)->where('descripcion', $info[0])->where('proyecto', post('proyecto'))->find_one(); - if (!$unidad->venta()->find_one()) { - echo 'x'; - continue; - } - $venta = $unidad->venta()->find_one(); - $entrega->fecha = \Carbon\Carbon::parse($info[1])->format('Y-m-d'); - if ($venta->entrega == '0') { - $entrega->save(); - $venta->entrega = $entrega->id; - $venta->save(); - echo '.'; - } else { - echo 'x'; - } - } - } else { - $proyectos = \Model::factory(Proyecto::class)->order_by_asc('descripcion')->find_many(); - return view('other.entregar_multiple', compact('proyectos')); - } - } - public static function capacidades() - { - $capacidades = []; - $controllers = glob(config('locations.app') . '/Controller/*.php'); - foreach ($controllers as $controller) { - if (basename($controller) == 'Admin.php' or basename($controller) == 'Other.php') { - continue; - } - $class = Stringy::create($controller)->replace(config('locations.app'), '/App')->replace('.php', '')->replace('/', '\\')->__toString(); - $ref = new \ReflectionClass($class); - $static = $ref->getMethods(\ReflectionMethod::IS_STATIC && \ReflectionMethod::IS_PUBLIC); - foreach ($static as $method) { - if ($method->name == 'setDefault' or $method->name == 'index') { - continue; - } - $capacidades []= $method; - } - } - return view('other.capacidades', compact('capacidades')); - } -} -?> \ No newline at end of file diff --git a/app/Controller/Pagares.php b/app/Controller/Pagares.php deleted file mode 100644 index f05b24e..0000000 --- a/app/Controller/Pagares.php +++ /dev/null @@ -1,271 +0,0 @@ -findOne(get('pagare')); - return view('proyectos.pagares.show', compact('pagare')); - } - public static function add() - { - $proyecto = model(Proyecto::class)->findOne(get('proyecto')); - return view('proyectos.pagares.add', compact('proyecto')); - } - public static function do_add() - { - $proyecto = model(Proyecto::class)->findOne(get('proyecto')); - $data = post(); - - $data['id'] = $data['numero']; - unset($data['numero']); - $data['proyecto'] = $proyecto->id; - $moneda = model(TipoMonedaPagare::class)->where('descripcion', $data['moneda'])->findOne(); - $data['moneda'] = $moneda->id; - - $fecha = ['year', 'month', 'day']; - $fecha_arr = array_filter($data, function($item) use ($fecha) { - return (array_search($item, $fecha) !== false); - }, \ARRAY_FILTER_USE_KEY); - uksort($fecha_arr, function($a, $b) use ($fecha) { - return array_search($a, $fecha) - array_search($b, $fecha); - }); - foreach ($fecha as $f) { - unset($data[$f]); - } - array_walk($fecha_arr, function(&$item) { - if (strlen($item) < 4) { - $item = str_pad($item, 2, '0', \STR_PAD_LEFT); - } - }); - $data['fecha'] = implode('-', $fecha_arr); - - foreach ($fecha as &$key) { - $key .= '_banco'; - } - $fecha_arr = array_filter($data, function($item) use ($fecha) { - return (array_search($item, $fecha) !== false); - }, \ARRAY_FILTER_USE_KEY); - uksort($fecha_arr, function($a, $b) use ($fecha) { - return array_search($a, $fecha) - array_search($b, $fecha); - }); - foreach ($fecha as $f) { - unset($data[$f]); - } - array_walk($fecha_arr, function(&$item) { - if (strlen($item) < 4) { - $item = str_pad($item, 2, '0', \STR_PAD_LEFT); - } - }); - $data['fecha_banco'] = implode('-', $fecha_arr); - - $data['abonado'] = (int) $data['abonado']; - if ($data['abonado'] == 0) { - $data['fecha'] = '0000-00-00'; - } - - $pagare = model(Pagare::class)->create($data); - $pagare->save(); - header('Location: ' . nUrl('pagares', 'show', ['pagare' => $pagare->id])); - } - public static function edit() - { - $pagare = model(Pagare::class)->findOne(get('pagare')); - return view('proyectos.pagares.edit', compact('pagare')); - } - public static function do_edit() - { - $pagare = model(Pagare::class)->findOne(get('pagare')); - - $data = post(); - if ($pagare->id != $data['numero']) { - foreach ($pagare->renovaciones() as $renovacion) { - $renovacion->pagare = $data['numero']; - $renovacion->save(); - } - $pagare->id = $data['numero']; - $changed = true; - } - unset($data['numero']); - $moneda = model(TipoMonedaPagare::class)->where('descripcion', $data['moneda'])->findOne(); - $data['moneda'] = $moneda->id; - $fecha = ['year', 'month', 'day']; - $fecha_arr = array_filter($data, function($item) use ($fecha) { - return (array_search($item, $fecha) !== false); - }, \ARRAY_FILTER_USE_KEY); - uksort($fecha_arr, function($a, $b) use ($fecha) { - return array_search($a, $fecha) - array_search($b, $fecha); - }); - foreach ($fecha as $f) { - unset($data[$f]); - } - array_walk($fecha_arr, function(&$item) { - if (strlen($item) < 4) { - $item = str_pad($item, 2, '0', \STR_PAD_LEFT); - } - }); - $data['fecha'] = implode('-', $fecha_arr); - - foreach ($fecha as &$key) { - $key .= '_banco'; - } - $fecha_arr = array_filter($data, function($item) use ($fecha) { - return (array_search($item, $fecha) !== false); - }, \ARRAY_FILTER_USE_KEY); - uksort($fecha_arr, function($a, $b) use ($fecha) { - return array_search($a, $fecha) - array_search($b, $fecha); - }); - foreach ($fecha as $f) { - unset($data[$f]); - } - array_walk($fecha_arr, function(&$item) { - if (strlen($item) < 4) { - $item = str_pad($item, 2, '0', \STR_PAD_LEFT); - } - }); - $data['fecha_banco'] = implode('-', $fecha_arr); - - $data['abonado'] = (int) $data['abonado']; - if ($data['abonado'] == 0) { - $data['fecha'] = '0000-00-00'; - } - - $changed = false; - foreach ($data as $k => $v) { - if ($pagare->$k != $v) { - $pagare->$k = $v; - $changed = true; - if (strpos($k, 'fecha') !== false) { - $pagare->uf = 0; - } - } - } - - if ($changed) { - $pagare->save(); - } - header('Location: ' . nUrl('pagares', 'show', ['pagare' => $pagare->id])); - } - public static function edit_renovacion() - { - $renovacion = model(RenovacionPagare::class)->findOne(get('renovacion')); - return view('proyectos.pagares.edit_renovacion', compact('renovacion')); - } - public static function do_edit_renovacion() - { - $renovacion = model(RenovacionPagare::class)->findOne(get('renovacion')); - - $data = post(); - $fecha = ['year', 'month', 'day']; - $fecha_arr = array_filter($data, function($item) use ($fecha) { - return (array_search($item, $fecha) !== false); - }, \ARRAY_FILTER_USE_KEY); - uksort($fecha_arr, function($a, $b) use ($fecha) { - return array_search($a, $fecha) - array_search($b, $fecha); - }); - foreach ($fecha as $f) { - unset($data[$f]); - } - array_walk($fecha_arr, function(&$item) { - if (strlen($item) < 4) { - $item = str_pad($item, 2, '0', \STR_PAD_LEFT); - } - }); - $data['fecha'] = implode('-', $fecha_arr); - - foreach ($fecha as &$key) { - $key .= '_banco'; - } - $fecha_arr = array_filter($data, function($item) use ($fecha) { - return (array_search($item, $fecha) !== false); - }, \ARRAY_FILTER_USE_KEY); - uksort($fecha_arr, function($a, $b) use ($fecha) { - return array_search($a, $fecha) - array_search($b, $fecha); - }); - foreach ($fecha as $f) { - unset($data[$f]); - } - array_walk($fecha_arr, function(&$item) { - if (strlen($item) < 4) { - $item = str_pad($item, 2, '0', \STR_PAD_LEFT); - } - }); - $data['fecha_banco'] = implode('-', $fecha_arr); - - $changed = false; - foreach ($data as $k => $v) { - if ($renovacion->$k != $v) { - $renovacion->$k = $v; - $changed = true; - if (strpos($k, 'fecha') !== false) { - $renovacion->uf = 0; - } - } - } - if ($changed) { - $renovacion->save(); - } - header('Location: ' . nUrl('pagares', 'show', ['pagare' => $renovacion->pagare])); - } - public static function add_renovacion() - { - $pagare = model(Pagare::class)->findOne(get('pagare')); - return view('proyectos.pagares.add_renovacion', compact('pagare')); - } - public static function do_add_renovacion() - { - $pagare = model(Pagare::class)->findOne(get('pagare')); - $data = post(); - - $data['pagare'] = $pagare->id; - $fecha = ['year', 'month', 'day']; - $fecha_arr = array_filter($data, function($item) use ($fecha) { - return (array_search($item, $fecha) !== false); - }, \ARRAY_FILTER_USE_KEY); - uksort($fecha_arr, function($a, $b) use ($fecha) { - return array_search($a, $fecha) - array_search($b, $fecha); - }); - foreach ($fecha as $f) { - unset($data[$f]); - } - array_walk($fecha_arr, function(&$item) { - if (strlen($item) < 4) { - $item = str_pad($item, 2, '0', \STR_PAD_LEFT); - } - }); - $data['fecha'] = implode('-', $fecha_arr); - - foreach ($fecha as &$key) { - $key .= '_banco'; - } - $fecha_arr = array_filter($data, function($item) use ($fecha) { - return (array_search($item, $fecha) !== false); - }, \ARRAY_FILTER_USE_KEY); - uksort($fecha_arr, function($a, $b) use ($fecha) { - return array_search($a, $fecha) - array_search($b, $fecha); - }); - foreach ($fecha as $f) { - unset($data[$f]); - } - array_walk($fecha_arr, function(&$item) { - if (strlen($item) < 4) { - $item = str_pad($item, 2, '0', \STR_PAD_LEFT); - } - }); - $data['fecha_banco'] = implode('-', $fecha_arr); - - $renovacion = model(RenovacionPagare::class)->create($data); - $renovacion->save(); - - header('Location: ' . nUrl('pagares', 'show', ['pagare' => $renovacion->pagare])); - } -} diff --git a/app/Controller/Pagos.php b/app/Controller/Pagos.php deleted file mode 100644 index f279b9e..0000000 --- a/app/Controller/Pagos.php +++ /dev/null @@ -1,358 +0,0 @@ -findOne($id); - $tipos = model(TipoPago::class)->orderByAsc('descripcion')->findMany(); - $estados = model(TipoEstadoPago::class)->orderByAsc('descripcion')->findMany(); - - return view('ventas.pagos.edit', compact('pago', 'asociado', 'id_asociado', 'tipos', 'estados')); - } - public static function editar() - { - $id = get('pago'); - $pago = model(Pago::class)->findOne($id); - - $fp = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $tipo = model(TipoPago::class)->findOne(post('tipo')); - $valor = correctNumber(post('valor')); - $banco = model(Banco::class)->where('nombre', post('banco'))->findOne(); - - $fe = Carbon::createFromDate(post('yearestado'), post('monthestado'), post('dayestado'), config('app.timezone')); - $estado = model(TipoEstadoPago::class)->findOne(post('estado')); - $uf = uf($fe); - - $est = $pago->estado(); - if ($est->fecha != $fe->format('Y-m-d')) { - $est->fecha = $fe->format('Y-m-d'); - $pago->uf = $uf->uf->value; - } - if ($est->estado != $estado->id) { - $est->estado = $estado->id; - } - - if ($pago->fecha != $fp->format('Y-m-d')) { - $pago->fecha = $fp->format('Y-m-d'); - } - if ($pago->tipo != $tipo->id) { - $pago->tipo = $tipo->id; - } - if ($pago->valor != $valor) { - $pago->valor = $valor; - } - if ($pago->identificador != post('identificador')) { - $pago->identificador = post('identificador'); - } - if ($pago->pagador != post('pagador')) { - $pago->pagador = post('pagador'); - } - if ($pago->banco != $banco->id) { - $pago->banco = $banco->id; - } - - $est->save(); - $pago->save(); - header('Location: ' . url('', ['p' => get('asociado') . 's', 'a' => 'show', get('asociado') => get(get('asociado'))])); - } - public static function pendientes() - { - $ventas = model(Venta::class) - ->select('venta.*') - ->rawJoin('JOIN (SELECT e1.* FROM estado_venta e1 JOIN (SELECT venta, MAX(id) AS id FROM estado_venta GROUP BY venta) e0 ON e0.id = e1.id)', ['ev.venta', '=', 'venta.id'], 'ev') - ->join('tipo_estado_venta', ['te.id', '=', 'ev.estado'], 'te') - ->join('propiedad', ['propiedad.id', '=', 'venta.propiedad']) - ->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal']) - ->join('proyecto', ['proyecto.id', '=', 'unidad.proyecto']) - ->where('te.activa', 1) - ->orderByAsc('proyecto.descripcion') - ->orderByExpr('LPAD(unidad.descripcion, 4, "0")') - ->findMany(); - $n = 30; - $mod = floor(count($ventas) / $n); - $i_rest = count($ventas) - count($ventas) % $mod + 1; - $rest = count($ventas) - $i_rest; - $lots = (object) ['size' => $mod, 'N' => $n, 'rest' => (object) [ - 'size' => $rest, - 'start' => $i_rest - ] - ]; - return view('ventas.pagos.pendientes', compact('ventas', 'lots')); - } - public static function para_pendientes() - { - $timezone = config('app.timezone'); - $today = Carbon::today($timezone); - $days = []; - $fechas = []; - for ($i = $today->copy()->subDays(15); $i <= $today->copy()->addDays(15); $i = $i->copy()->addDay()) { - $days []= $i->format('Y-m-d'); - $fechas []= $i->format('d-m-Y'); - } - $pagos_pendientes = model(Pago::class) - ->select('estado_pago.fecha') - ->selectExpr('COUNT(pago.id)', 'cantidad') - ->join('cuota', ['cuota.pago', '=', 'pago.id']) - ->join('venta', ['venta.pie', '=', 'cuota.pie']) - ->filter('filterEstado') - ->where('estado_pago.estado', 0) - ->where('venta.estado', 1) - ->whereGte('estado_pago.fecha', $today->copy()->subDays(15)->format('Y-m-d')) - ->whereLte('estado_pago.fecha', $today->copy()->addDays(15)->format('Y-m-d')) - ->orderByAsc('estado_pago.fecha') - ->groupBy('estado_pago.fecha') - ->findMany(); - $valores = array_fill(0, count($days), 0); - $anteriores = model(Pago::class) - ->join('cuota', ['cuota.pago', '=', 'pago.id']) - ->join('venta', ['venta.pie', '=', 'cuota.pie']) - ->filter('filterEstado') - ->where('estado_pago.estado', 0) - ->where('venta.estado', 1) - ->whereLt('estado_pago.fecha', $today->copy()->subDays(15)->format('Y-m-d')) - ->count(); - foreach ($pagos_pendientes as $pago) { - $valores[array_search($pago->fecha()->format('Y-m-d'), $days)] = $pago->cantidad; - } - $acum = []; - $sum = 0; - foreach ($valores as $valor) { - $sum += $valor; - $acum []= $sum; - } - $t = array_search($today->format('Y-m-d'), $days); - $color = array_merge( - array_fill(0, $t, 'red'), - ['blue'], - array_fill(0, count($days) - $t, 'green') - ); - $pagos = ['data' => $acum, 'historico' => $anteriores, 'backgroundColor' => $color]; - $abonos_pendientes = model(Pago::class) - ->select('estado_pago.fecha') - ->selectExpr('COUNT(pago.id)', 'cantidad') - ->filter('filterEstado') - ->where('estado_pago.estado', 1) - ->whereGte('estado_pago.fecha', $today->copy()->subDays(15)->format('Y-m-d')) - ->whereLt('estado_pago.fecha', $today->copy()->format('Y-m-d')) - ->orderByAsc('estado_pago.fecha') - ->groupBy('estado_pago.fecha') - ->findMany(); - $anteriores = model(Pago::class) - ->join('cuota', ['cuota.pago', '=', 'pago.id']) - ->join('venta', ['venta.pie', '=', 'cuota.pie']) - ->filter('filterEstado') - ->where('estado_pago.estado', 1) - ->where('venta.estado', 1) - ->whereLt('estado_pago.fecha', $today->copy()->subDays(15)->format('Y-m-d')) - ->count(); - $valores = array_fill(0, count($days), 0); - foreach ($abonos_pendientes as $pago) { - $valores[array_search($pago->fecha()->format('Y-m-d'), $days)] = $pago->cantidad; - } - $acum = []; - $sum = 0; - foreach ($valores as $valor) { - $sum += $valor; - $acum []= $sum; - } - $color = array_fill(0, count($pagos), 'rgb(200, 0, 0)'); - $abonos = ['data' => $acum, 'historico' => $anteriores, 'backgroundColor' => $color]; - $output = ['count' => count($days), 'fechas' => $fechas, 'pagos' => $pagos, 'abonos' => $abonos]; - echo json_encode($output); - } - public static function para_abonar() - { - $ids = json_decode(post('ids')); - //$id = get('id'); - function checkPago(&$pagos, $tipo, $pago) { - if (!$pago) { - return; - } - if (!$pago->estado()) { - $pagos []= [ - 'tipo' => $tipo, - 'pago' => $pago->asArray(), - 'estado' => -1 - ]; - return; - } - if ($pago->estado()->tipo()->descripcion == 'depositado') { - $pagos []= [ - 'tipo' => $tipo, - 'pago' => $pago->asArray(), - 'fecha' => format('shortDate', $pago->estado()->fecha), - 'valor' => format('pesos', $pago->valor, true), - 'estado' => 1 - ]; - } - } - $output = []; - foreach ($ids as $id) { - $venta = model(Venta::class)->findOne($id); - if ($venta->estado()->tipo()->activa == 0) { - $output []= ['status' => -1, 'venta' => $venta->id]; - continue; - } - $pagos = []; - if ($venta->pie()) { - foreach ($venta->pie()->cuotas() as $cuota) { - checkPago($pagos, 'Pie', $cuota->pago()); - } - if ($venta->pie()->reajuste()) { - checkPago($pagos, 'Reajuste', $venta->pie()->reajuste()); - } - } - if ($venta->credito()) { - checkPago($pagos, 'Credito', $venta->credito()->pago()); - } - if ($venta->escritura()) { - checkPago($pagos, 'Abono Escritura', $venta->escritura()->pago()); - } - if ($venta->subsidio()) { - checkPago($pagos, 'Subsidio', $venta->subsidio()->subsidio()); - checkPago($pagos, 'Ahorro', $venta->subsidio()->pago()); - } - if (count($pagos) <= 0) { - $output []= ['status' => -1, 'venta' => $venta->id]; - continue; - } - $output []= [ - 'status' => 1, - 'proyecto' => $venta->proyecto()->descripcion, - 'venta' => $venta->id, - 'propietario' => $venta->propietario()->nombreCompleto(), - 'departamento' => $venta->unidad()->descripcion, - 'pagos' => $pagos - ]; - } - return json_encode($output); - } - public static function rebotes() - { - $ids = json_decode(post('ids')); - $response = []; - foreach ($ids as $id) { - //$id = get('id'); - $venta = model(Venta::class)->findOne($id); - $rebotes = $venta->pagos(-1); - if (count($rebotes) < 1) { - $response []= ['status' => -1, 'venta' => $venta->id]; - continue; - } - usort($rebotes, function($a, $b) { - return $b->estado()->fecha()->diffInDays($a->estado()->fecha(), false); - }); - - $output = []; - $textos = []; - foreach ($rebotes as $rebote) { - $fuente = $rebote->fuente()[0]; - $text = ''; - $info = ['tipo' => ucwords(str_replace('_', ' ', $fuente->tipo))]; - switch ($fuente->tipo) { - case('cuota'): - $text .= ''; - $info['proyecto'] = $fuente->obj->pie()->venta()->proyecto()->descripcion; - $info['venta'] = $fuente->obj->pie()->venta()->id; - $info['departamento'] = $fuente->obj->pie()->venta()->unidad()->descripcion; - $info['propietario'] = $fuente->obj->pie()->venta()->propietario()->nombreCompleto(); - $info['fecha'] = format('shortDate', $rebote->estado()->fecha); - break; - } - $text .= ''; - $info['valor'] = format('pesos', $rebote->valor('pesos'), true); - $output []= array_merge(['id' => $rebote->id], $info); - $textos []= ['id' => $rebote->id, 'text' => $text]; - } - $response []= ['status' => 1, 'venta' => $venta->id, 'textos' => $textos, 'rebotes' => $output]; - } - - return json_encode($response); - } - public static function show() - { - $id = get('pago'); - $asociado = get('asociado'); - $id_asociado = get($asociado); - - $pago = model(Pago::class)->findOne($id); - - return view('ventas.pagos.show', compact('pago', 'asociado', 'id_asociado')); - } - public static function pagar() - { - $id = get('pago'); - $pago = model(Pago::class)->findOne($id); - $asociado = get('asociado'); - $id_asociado = get($asociado); - - return view('ventas.pagos.pagar', compact('pago', 'asociado', 'id_asociado')); - } - public static function pagando() - { - $id = get('pago'); - $pago = model(Pago::class)->findOne($id); - $asociado = get('asociado'); - $id_asociado = get($asociado); - - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $data = [ - 'fecha' => $f->format('Y-m-d'), - 'pago' => $pago->id, - 'estado' => 1 - ]; - $estado = model(EstadoPago::class)->create($data); - - $estado->save(); - header('Location: ' . url('', ['p' => $asociado . 's', 'a' => 'show', $asociado => $id_asociado])); - } - public static function abonar() - { - $id = get('pago'); - $pago = model(Pago::class)->findOne($id); - $asociado = get('asociado'); - $id_asociado = get($asociado); - - return view('ventas.pagos.abonar', compact('pago', 'asociado', 'id_asociado')); - } - public static function abonando() - { - $id = get('pago'); - $pago = model(Pago::class)->findOne($id); - $asociado = get('asociado'); - $id_asociado = get($asociado); - - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $data = [ - 'fecha' => $f->format('Y-m-d'), - 'pago' => $pago->id, - 'estado' => 2 - ]; - $estado = model(EstadoPago::class)->create($data); - - $estado->save(); - header('Location: ' . url('', ['p' => $asociado . 's', 'a' => 'show', $asociado => $id_asociado])); - } -} -?> diff --git a/app/Controller/Pies.php b/app/Controller/Pies.php deleted file mode 100644 index 38c2fcb..0000000 --- a/app/Controller/Pies.php +++ /dev/null @@ -1,104 +0,0 @@ -findOne($proyecto); - $ventas = $proyecto->ventas(); - self::sort($ventas); - return view('ventas.list', compact('proyecto', 'ventas')); - } - public static function listProyectos() - { - $proyectos = \Model::factory(Proyecto::class) - ->select('proyecto.*') - ->join('estado_proyecto', ['estado.proyecto', '=', 'proyecto.id'], 'estado') - ->join('tipo_estado_proyecto', ['tipo.id', '=', 'estado.estado'], 'tipo') - ->join('etapa_proyecto', ['etapa.id', '=', 'tipo.etapa'], 'etapa') - ->whereGte('etapa.orden', 4) - ->groupBy('proyecto.id') - ->findMany(); - echo view('ventas.proyectos', compact('proyectos')); - } - public static function resumen() - { - $id = get('pie'); - $pie = \Model::factory(\Incoviba\old\Venta\Pie::class)->findOne($id); - $venta = $pie->venta(); - return view('ventas.pies.resumen', compact('venta')); - } - public static function reajustar() - { - $id = get('venta'); - $venta = \Model::factory(Venta::class)->findOne($id); - return view('ventas.pies.reajustar', compact('venta')); - } - public static function reajuste() - { - $id = get('venta'); - $venta = \Model::factory(Venta::class)->findOne($id); - - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $pago = \Model::factory(Pago::class)->create(); - $pago->fecha = $f->format('Y-m-d'); - $pago->uf = (float) uf($f)->uf->value; - $pago->valor = str_replace('.', '', post('valor')); - - $pago->new(); - - $pie = $venta->pie(); - $pie->reajuste = $pago->id; - $pie->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function edit() - { - $id = get('venta'); - $venta = \Model::factory(Venta::class)->findOne($id); - return view('ventas.pies.edit', compact('venta')); - } - public static function editar() - { - $id = get('venta'); - $venta = \Model::factory(Venta::class)->findOne($id); - $pie = $venta->pie(); - $valor = correctNumber(post('valor')); - if ($pie->valor != $valor) { - $pie->valor = $valor; - } - if ($pie->cuotas != post('cuotas')) { - $pie->cuotas = post('cuotas'); - } - - $pie->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function asociar() - { - $id = get('pie'); - $pie = \Model::factory(Pie::class)->findOne($id); - $pie->asociado = post('asociado'); - - $pie->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $pie->venta()->id])); - } -} -?> diff --git a/app/Controller/Postventas.php b/app/Controller/Postventas.php deleted file mode 100644 index 7b38cb6..0000000 --- a/app/Controller/Postventas.php +++ /dev/null @@ -1,69 +0,0 @@ -findOne($id); - - return view('ventas.postventas.add', compact('venta')); - } - public static function agregar() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $observaciones = json_decode(post('observaciones')); - $postventa = model(Postventa::class)->create(); - $postventa->venta_id = $venta->id; - $postventa->save(); - - $estado = model(EstadoPostventa::class)->create(); - $estado->postventa_id = $postventa->id; - $estado->tipo_estado_postventa_id = 1; - $estado->fecha = $f->format('Y-m-d'); - $estado->save(); - - foreach ($observaciones as $o) { - $observacion = model(Observacion::class)->create(); - $observacion->texto = post('observacion' . $o); - - $observacion->save(); - - $estado = model(EstadoObservacion::class)->create(); - $estado->observacion_id = $observacion->id; - $estado->tipo_estado_observacion_id = 1; - $estado->fecha = $f->format('Y-m-d'); - $estado->save(); - - $po = model(PostventaObservacion::class)->create(); - $po->postventa_id = $postventa->id; - $po->observacion_id = $observacion->id; - $po->save(); - } - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function show() - { - $id = get('postventa'); - $postventa = model(Postventa::class)->findOne($id); - $venta = model(Venta::class)->findOne($postventa->venta_id); - - return view('ventas.postventas.show', compact('postventa', 'venta')); - } -} -?> diff --git a/app/Controller/Precios.php b/app/Controller/Precios.php deleted file mode 100644 index 20db97b..0000000 --- a/app/Controller/Precios.php +++ /dev/null @@ -1,177 +0,0 @@ -orderByAsc('descripcion')->findMany(); - return view('ventas.precios.proyectos', compact('proyectos')); - } - public static function list() - { - $proyecto = \model(Proyecto::class)->findOne(get('proyecto')); - return view('ventas.precios.list', compact('proyecto')); - } - public static function import() - { - $proyectos = \model(Proyecto::class)->orderByAsc('descripcion')->findMany(); - return view('ventas.precios.import', compact('proyectos')); - } - public static function importar() - { - $proyecto = \model(Proyecto::class)->findOne(post('proyecto')); - $fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $file = explode(PHP_EOL, trim(file_get_contents($_FILES['archivo']['tmp_name']))); - $columnas = explode(';', array_shift($file)); - $tr = model(TipoEstadoPrecio::class)->where('descripcion', 'reemplazado')->findOne()->id; - $tv = model(TipoEstadoPrecio::class)->where('descripcion', 'vigente')->findOne()->id; - foreach ($file as $line) { - if (trim($line) == '') { - continue; - } - $info = explode(';', $line); - $tipo = \model(TipoUnidad::class)->where('descripcion', $info[0])->findOne(); - $unidad = \model(Unidad::class)->where('tipo', $tipo->id)->where('descripcion', $info[1])->where('proyecto', $proyecto->id)->findOne(); - if (!$unidad) { - continue; - } - - try { - self::reemplazar($unidad->id, $info[2], $fecha, $tr, $tv); - } catch (\Exception $e) { - continue; - } - } - header('Location: ' . nUrl('precios', 'list', ['proyecto' => $proyecto->id])); - } - public static function add() - { - $proyecto = \model(Proyecto::class)->findOne(get('proyecto')); - return view('ventas.precios.add', compact('proyecto')); - } - public static function agregar() - { - $proyecto = get('proyecto'); - $fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $precios = []; - foreach (post() as $name => $valor) { - if ($valor == '' or strpos($name, 'precio') === false) { - continue; - } - list($tipo, $id) = explode(':', $name); - $tipo = trim(str_replace('precio', '', $tipo), '_'); - $id = explode('-', $id); - switch (count($id)) { - case 1: - $precios []= ['tipo' => 'pt', 'id' => $id[0], 'valor' => $valor]; - break; - case 2: - $exists = false; - foreach ($precios as $precio) { - if ($precio['tipo'] == 'pt' and $precio['id'] == $id[0]) { - $exists = true; - break; - } - } - if (!$exists) { - $precios []= ['tipo' => 'subtipo', 'id' => $id[1], 'pt' => $id[0], 'valor' => $valor]; - } - break; - case 3: - $exists = false; - foreach ($precios as $precio) { - if ($precio['tipo'] == 'pt' and $precio['id'] == $id[0]) { - $exists = true; - break; - } - if ($precio['tipo'] == 'subtipo' and 'id' == $id[1] and 'pt' == $id[0]) { - $exists = true; - break; - } - } - if (!$exists) { - $precios []= ['tipo' => 'unidad', 'id' => $id[2], 'valor' => $valor]; - } - break; - } - } - foreach ($precios as $precio) { - $precio = (object) $precio; - try { - switch ($precio->tipo) { - case 'pt': - $pt = model(ProyectoTipoUnidad::class)->findOne($precio->id); - $pt->setPrecios($fecha, $precio->valor); - break; - case 'subtipo': - $pt = model(ProyectoTipoUnidad::class)->findOne($precio->pt); - $pt->setPreciosSubtipo($precios->id, $fecha, $precio->valor); - break; - case 'unidad': - $unidad = model(Unidad::class)->findOne($precio->id); - $unidad->setPrecio($fecha, $precio->valor); - break; - } - } catch(\Exception $e) { - continue; - } - } - header('Location: ' . nUrl('precios', 'list', ['proyecto' => $proyecto])); - } - protected static function reemplazar(int $unidad_id, float $valor, \DateTime $fecha, int $tr = 0, int $tv = 0) - { - if ($tr == 0) { - $tr = model(TipoEstadoPrecio::class)->where('descripcion', 'reemplazado')->findOne()->id; - } - if ($tv == 0) { - $tv = model(TipoEstadoPrecio::class)->where('descripcion', 'vigente')->findOne()->id; - } - $olds = \model(Precio::class)->where('unidad', $unidad_id)->findMany(); - if ($olds !== false) { - foreach ($olds as $old) { - if (!$old->vigente()) { - continue; - } - $data = [ - 'precio' => $old->id, - 'fecha' => $fecha->format('Y-m-d'), - 'estado' => $tr - ]; - $estado = \model(EstadoPrecio::class)->create($data); - $estado->save(); - } - } - $data = [ - 'unidad' => $unidad_id, - 'valor' => $valor - ]; - $precio = (new Factory(Precio::class))->where($data)->find(); - if (!$precio) { - $precio = \model(Precio::class)->create($data); - $precio->save(); - } - $data = [ - 'precio' => $precio->id, - 'fecha' => $fecha->format('Y-m-d'), - 'estado' => $tv - ]; - $estado = \model(EstadoPrecio::class)->create($data); - $estado->save(); - } -} diff --git a/app/Controller/Propietarios.php b/app/Controller/Propietarios.php deleted file mode 100644 index 5d38ee7..0000000 --- a/app/Controller/Propietarios.php +++ /dev/null @@ -1,129 +0,0 @@ -findOne($id); - $propietario = $venta->propietario(); - $regiones = model(Region::class)->orderByAsc('numeracion')->findMany(); - - return view('ventas.propietarios.edit', compact('venta', 'propietario', 'regiones')); - } - public static function editar() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - $info = post(); - list($info['rut'], $info['dv']) = explode('-', str_replace('.', '', $info['rut'])); - $propietario = model(Propietario::class)->findOne($info['rut']); - if (!$propietario) { - $propietario = model(Propietario::class)->create(); - } - if ($propietario->direccion != 0) { - $direccion = $propietario->direccion(); - } else { - $direccion = model(Direccion::class) - ->where('calle', post('calle')) - ->where('numero', post('numero')) - ->where('extra', post('extra')) - ->where('comuna', post('comuna')) - ->findOne(); - if (!$direccion) { - $data = [ - 'calle' => post('calle'), - 'numero' => post('numero'), - 'extra' => post('extra'), - 'comuna' => post('comuna') - ]; - $direccion = model(Direccion::class)->create($data); - } - } - - if (isset($info['empresa'])) { - $info['apellido_paterno'] = ''; - $info['apellido_materno'] = ''; - } - - if ($propietario->representante != 0) { - list($info['rep_rut'], $info['rep_dv']) = explode('-', str_replace('.', '', $info['rep_rut'])); - $representante = $propietario->representante(); - } elseif (isset($info['rep_rut'])) { - list($info['rep_rut'], $info['rep_dv']) = explode('-', str_replace('.', '', $info['rep_rut'])); - $representante= model(Propietario::class)->findOne($info['rep_rut']); - if (!$representante) { - $representante= model(Propietario::class)->create(); - } - } - - $fields = ['rut', 'dv', 'nombres', 'apellido_paterno', 'apellido_materno']; - $change = false; - foreach ($fields as $key) { - if ($propietario->$key != $info[$key]) { - $propietario->$key = $info[$key]; - $change = true; - } - } - if ($direccion->isNew()) { - $direccion->save(); - } - if ($propietario->direccion != $direccion->id) { - $propietario->direccion = $direccion->id; - $change = true; - } - if ($change) { - d($propietario); - $propietario->save(); - } - - if (isset($info['rep_rut'])) { - $change = false; - if ($representante->rut != $info['rep_rut']) { - $representante->rut = $info['rep_rut']; - $representante->dv = $info['rep_dv']; - $change = true; - } - if ($representante->nombres != $info['rep_nombres']) { - $representante->nombres = $info['rep_nombres']; - $change = true; - } - if ($representante->apellido_paterno != $info['rep_apaterno']) { - $representante->apellido_paterno = $info['rep_apaterno']; - $change = true; - } - if ($representante->apellido_materno != $info['rep_amaterno']) { - $representante->apellido_materno = $info['rep_amaterno']; - $change = true; - } - if ($representante->direccion != $direccion->id) { - $representante->direccion = $direccion->id; - $change = true; - } - if ($change) { - $representante->save(); - } - if ($propietario->representante != $representante->rut) { - $propietario->representante = $representante->rut; - $propietario->save(); - } - } - - if ($venta->propietario != $propietario->rut) { - $venta->propietario = $propietario->rut; - $venta->save(); - } - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } -} -?> diff --git a/app/Controller/ProyectoTipoUnidades.php b/app/Controller/ProyectoTipoUnidades.php deleted file mode 100644 index 32c0c1d..0000000 --- a/app/Controller/ProyectoTipoUnidades.php +++ /dev/null @@ -1,77 +0,0 @@ -findOne($id); - $tipos = model(TipoUnidad::class)->findMany(); - - return view('proyectos.tipo_unidades.edit', compact('tipo', 'tipos')); - } - public static function editar() - { - $id = get('tipo_unidad'); - $tipo = model(ProyectoTipoUnidad::class)->findOne($id); - - $changed = false; - foreach (post() as $field => $value) { - if ($tipo->{$field} != $value) { - $tipo->{$field} = $value; - $changed = true; - } - } - if ($changed) { - $tipo->save(); - } - header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $tipo->proyecto()->id])); - } - public static function add_unidad() - { - $id = get('tipo_unidad'); - $tipo = model(ProyectoTipoUnidad::class)->findOne($id); - if ($tipo->tipo()->descripcion == 'departamento') { - return view('proyectos.unidades.add', compact('tipo')); - } - return view('proyectos.unidades.add2', compact('tipo')); - } - public static function assign() - { - $id = get('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id); - $tipos = model(ProyectoTipoUnidad::class)->where('proyecto', $proyecto->id)->findMany(); - $libres = model(Unidad::class)->where('proyecto', $proyecto->id)->where('pt', 0)->findMany(); - - return view('proyectos.unidades.assign', compact('proyecto', 'tipos', 'libres')); - } - public static function asignar() - { - $id = get('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id); - - $libres = model(Unidad::class)->where('proyecto', $proyecto->id)->where('pt', 0)->findMany(); - foreach ($libres as $unidad) { - $unidad->pt = post('tipo' . $unidad->id); - $unidad->save(); - } - header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $proyecto->id])); - } -} diff --git a/app/Controller/Proyectos.php b/app/Controller/Proyectos.php deleted file mode 100644 index 9c69ad5..0000000 --- a/app/Controller/Proyectos.php +++ /dev/null @@ -1,327 +0,0 @@ -where('inmobiliaria', $id_inmobiliaria); - } else { - $proyectos = model(Proyecto::class); - } - $proyectos = $proyectos->order_by_asc('descripcion')->findMany(); - return view('proyectos.list', compact('proyectos')); - } - public static function show() - { - $id_proyecto = get('proyecto'); - if ($id_proyecto == null) { - header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'list'])); - } - $proyecto = model(Proyecto::class)->findOne($id_proyecto); - $estados = model(TipoEstadoProyecto::class)->findMany(); - foreach ($estados as &$estado) { - $estado = $estado->asArray()['orden'] + 1; - } - $colors = []; - - $ventas_pt = (object) ['fields' => [], 'data' => [], 'totales' => [], 'vendidas' => []]; - $ventas = $proyecto->ventas('fecha'); - $months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; - if (count($ventas) > 0) { - $inicio = $ventas[0]->fecha()->format('Y'); - $fin = $ventas[count($ventas) - 1]->fecha()->format('Y'); - $end = $ventas[count($ventas) - 1]->fecha()->format('M'); - for ($y = $inicio; $y <= $fin; $y ++) { - foreach ($months as $month) { - $ventas_pt->fields []= $y . ' ' . $month; - if ($y == $fin and $month == $end) { - break; - } - } - } - } - - foreach ($proyecto->tipologias() as $tipo) { - if (!isset($ventas_pt->data[$tipo->tipologia->descripcion])) { - $ventas_pt->data[$tipo->tipologia->descripcion] = []; - $ventas_pt->data[$tipo->tipologia->descripcion] = array_fill(0, count($ventas_pt->fields), 0); - $ventas_pt->totales[$tipo->tipologia->descripcion] = 0; - $ventas_pt->vendidas[$tipo->tipologia->descripcion] = 0; - } - foreach ($tipo->tipos as $pt) { - foreach ($pt->ventas('fecha') as $venta) { - $ventas_pt->data[$tipo->tipologia->descripcion][array_search($venta->fecha()->format('Y M'), $ventas_pt->fields)] ++; - $ventas_pt->vendidas[$tipo->tipologia->descripcion] ++; - } - $ventas_pt->totales[$tipo->tipologia->descripcion] += count($pt->unidades()); - } - } - foreach ($ventas_pt->data as $tipo => $data) { - $acum = 0; - foreach ($data as $i => $cantidad) { - $acum += $cantidad; - $ventas_pt->data[$tipo][$i] = round($acum / $ventas_pt->totales[$tipo] * 100, 2); - } - } - $meses = ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic']; - array_walk($ventas_pt->fields, function(&$item) use ($meses, $months) { - $item = str_replace($months, $meses, $item); - }); - - for ($i = 0; $i < 10; $i ++) { - $colors[$i] = 'rgb(' . mt_rand(0, 255) . ', ' . mt_rand(0, 255) . ', ' . mt_rand(0, 255) . ')'; - } - return view('proyectos.show', compact('proyecto', 'estados', 'colors', 'ventas_pt')); - } - public static function historial() - { - $proyecto = model(Proyecto::class)->findOne(get('proyecto')); - return view('proyectos.historia', compact('proyecto')); - } - public static function advance() - { - $id_proyecto = get('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id_proyecto); - $estados = model(TipoEstadoProyecto::class)->whereGt('orden', $proyecto->estado()->tipo()->orden)->orderByAsc('orden')->findMany(); - - return view('proyectos.advance', compact('proyecto', 'estados')); - } - public static function avanzar() - { - $id_proyecto = get('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id_proyecto); - $id_tipo = post('estado'); - $tipo = model(TipoEstadoProyecto::class)->findOne($id_tipo); - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - - $tipos = model(TipoEstadoProyecto::class) - ->whereGt('orden', $proyecto->estado()->tipo()->orden) - ->whereLte('orden', $tipo->orden) - ->orderByAsc('orden') - ->findMany(); - - foreach ($tipos as $t) { - $estado = model(EstadoProyecto::class)->create(); - $estado->proyecto = $proyecto->id; - $estado->estado = $t->id; - $estado->fecha = $f->format('Y-m-d'); - $estado->save(); - } - header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'show', 'proyecto' => $proyecto->id])); - } - public static function avance() - { - $id = get('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id); - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $av = post('avance') / 100; - $ep = (double) post('estado_pago'); - $avance = model(AvanceConstruccion::class) - ->where('proyecto', $proyecto->id) - ->where('fecha', $f->format('Y-m-d')) - ->findOne(); - if (!$avance) { - $data = [ - 'proyecto' => $proyecto->id, - 'fecha' => $f->format('Y-m-d'), - 'numero' => post('numero'), - 'avance' => $av, - 'estado_pago' => $ep - ]; - $avance = model(AvanceConstruccion::class)->create($data); - } - $avance->save(); - header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'historial', 'proyecto' => $proyecto->id])); - } - public static function add() - { - $rut = get('inmobiliaria'); - - $inmobiliarias = model(Inmobiliaria::class)->orderByAsc('abreviacion')->findMany(); - $regiones = model(Region::class)->orderByAsc('numeracion')->findMany(); - - return view('proyectos.add', compact('inmobiliarias', 'rut', 'regiones')); - } - public static function agregar() - { - $proyecto = model(Proyecto::class)->where('descripcion', post('descripcion'))->where('inmobiliaria', post('inmobiliaria'))->find_one(); - if ($proyecto) { - header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'show', 'proyecto' => $proyecto->id])); - die(); - } - $proyecto = model(Proyecto::class)->create(); - $proyecto->descripcion = post('descripcion'); - $proyecto->inmobiliaria = post('inmobiliaria'); - - $direccion = model(Direccion::class) - ->where('calle', post('calle')) - ->where('numero', post('numero')) - ->where('extra', post('extra')) - ->where('comuna', post('comuna')) - ->findOne(); - if (!$direccion) { - $direccion = model(Direccion::class)->create(); - $direccion->calle = post('calle'); - $direccion->numero = post('numero'); - $direccion->extra = post('extra'); - $direccion->comuna = post('comuna'); - $direccion->save(); - } - - $proyecto->direccion = $direccion->id; - $proyecto->save(); - - $fecha = Carbon::parse(post('year'), post('month'), post('day'), config('app.timezone')); - $estado = model(EstadoProyecto::class)->create(); - $estado->proyecto = $proyecto->id; - $estado->estado = 1; - $estado->fecha = $fecha->format('Y-m-d'); - $estado->save(); - header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'show', 'proyecto' => $proyecto->id])); - } - public static function disponibles() - { - $id = get('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id); - - return view('proyectos.disponibles', compact('proyecto')); - } - public static function list_unidades() - { - $id = get('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id); - $libres = model(Unidad::class)->where('proyecto', $proyecto->id)->where('pt', 0)->findMany(); - - return view('proyectos.unidades.list', compact('proyecto', 'libres')); - } - public static function add_tipo_unidad() - { - $id = get('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id); - $tipos = model(TipoUnidad::class)->findMany(); - - return view('proyectos.tipo_unidades.add', compact('proyecto', 'tipos')); - } - public static function agregar_tipo_unidad() - { - $id = get('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id); - $data = post(); - $data['proyecto'] = $proyecto->id; - $tipo = model(ProyectoTipoUnidad::class)->where('proyecto', $data['proyecto']) - ->where('tipo', $data['tipo'])->where('nombre', $data['nombre'])->findOne(); - if ($tipo === false) { - $tipo = model(ProyectoTipoUnidad::class)->create($data); - $tipo->save(); - } - header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $proyecto->id])); - } - public static function construccion() - { - $id = get('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id); - return view('proyectos.construccion', compact('proyecto')); - } - public static function editar_avance() - { - $avance = model(AvanceConstruccion::class)->findOne(get('avance')); - return view('proyectos.avances.edit', compact('avance')); - } - public static function edit_avance() - { - $avance = model(AvanceConstruccion::class)->findOne(get('avance')); - $cols = [ - 'day', - 'month', - 'year', - 'avance', - 'estado_pago', - 'pagado', - 'day_pago', - 'month_pago', - 'year_pago' - ]; - $data = array_filter(post(), function($key) use ($cols) { - return (array_search($key, $cols) !== false); - }, \ARRAY_FILTER_USE_KEY); - $data['fecha'] = implode('-', [$data['year'], $data['month'], $data['day']]); - unset($data['year']); - unset($data['month']); - unset($data['day']); - $data['fecha_pagado'] = implode('-', [$data['year_pago'], $data['month_pago'], $data['day_pago']]); - unset($data['year_pago']); - unset($data['month_pago']); - unset($data['day_pago']); - $data['avance'] /= 100; - $avance->edit($data); - - header('Location: ' . nUrl('proyectos', 'construccion', ['proyecto' => $avance->proyecto])); - } - public static function reservas() - { - $proyecto = model(Proyecto::class)->findOne(get('proyecto')); - $pisos = []; - $totales = []; - foreach ($proyecto->unidades('departamento') as $unidad) { - if (!isset($pisos[$unidad->piso - 1])) { - $piso = (object) ['descripcion' => $unidad->piso, 'unidades' => []]; - $pisos[$unidad->piso - 1] = $piso; - } - if (!isset($totales[$unidad->linea()])) { - $totales[$unidad->linea()] = (object) ['ventas' => 0, 'reservas' => 0]; - } - $pisos[$unidad->piso - 1]->unidades[$unidad->linea()] = $unidad; - if ($unidad->isVendida()) { - $totales[$unidad->linea()]->ventas ++; - } - if ($unidad->isReservada()) { - $totales[$unidad->linea()]->reservas ++; - } - } - ksort($pisos); - $max_unidades = 0; - foreach ($pisos as $piso) { - if (count($piso->unidades) > $max_unidades) { - $max_unidades = count($piso->unidades); - } - } - return view('proyectos.reservas.base', compact('proyecto', 'pisos', 'max_unidades', 'totales')); - } - public static function unidades() - { - if (get('proyecto')) { - $proyecto = model(Proyecto::class)->findOne(get('proyecto')); - $libres = model(Unidad::class)->where('proyecto', $proyecto->id)->where('pt', 0)->findMany(); - - return view('proyectos.unidades.list', compact('proyecto', 'libres')); - } - $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->findMany(); - return view('proyectos.unidades.proyectos', compact('proyectos')); - } -} -?> diff --git a/app/Controller/Reajustes.php b/app/Controller/Reajustes.php deleted file mode 100644 index 4c6c938..0000000 --- a/app/Controller/Reajustes.php +++ /dev/null @@ -1,90 +0,0 @@ -findOne($id); - return view('ventas.pies.reajustes.edit', compact('venta')); - } - public static function editar() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $uf = uf($f); - - $valor = correctNumber(post('valor')); - if ($valor == '') { - $valor_uf = correctNumber(post('valor_uf')); - $valor = $valor_uf * $uf->uf->value; - } - $pago = $venta->pie()->reajuste(); - if ($pago->valor != $valor) { - $pago->valor = $valor; - } - if ($pago->fecha != $f->format('Y-m-d')) { - $pago->fecha = $f->format('Y-m-d'); - $pago->uf = $uf->uf->value; - } - - $pago->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function pagar() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - return view('ventas.pies.reajustes.pagar', compact('venta')); - } - public static function pagado() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - - $data = [ - 'pago' => $venta->pie()->reajuste()->id, - 'fecha' => $f->format('Y-m-d'), - 'estado' => 1 - ]; - $estado = model(EstadoPago::class)->create($data); - $estado->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function abonar() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - return view('ventas.pies.reajustes.abonar', compact('venta')); - } - public static function abonado() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - - $data = [ - 'pago' => $venta->pie()->reajuste()->id, - 'fecha' => $f->format('Y-m-d'), - 'estado' => 2 - ]; - $estado = model(EstadoPago::class)->create($data); - $estado->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } -} -?> diff --git a/app/Controller/Registros.php b/app/Controller/Registros.php deleted file mode 100644 index 546fece..0000000 --- a/app/Controller/Registros.php +++ /dev/null @@ -1,39 +0,0 @@ -orderByDesc('time')->findMany(); - $ini = new Color(0, 100, 0); - $end = new Color(255, 255, 255); - $colores = self::colores($end, $ini, 100); - return view('admin.registros.list', compact('registros', 'colores')); - } - public static function show() - { - $registro = model(RModel::class)->findOne(get('registro')); - $ini = new Color(0, 100, 0); - $end = new Color(255, 255, 255); - $colores = self::colores($end, $ini, 100); - return view('admin.registros.show', compact('registro', 'colores')); - } - protected static function colores($ini, $end, $max) - { - $current = $ini->toVector(); - $colores = []; - $line = new Line($ini->toVector(), $end->toVector()); - for ($i = 0; $i < $max; $i ++) { - $colores[$i] = new Color($current); - $current = $line->move($current, $line->length() / $max); - } - return $colores; - } -} diff --git a/app/Controller/Subsidios.php b/app/Controller/Subsidios.php deleted file mode 100644 index 5107fc3..0000000 --- a/app/Controller/Subsidios.php +++ /dev/null @@ -1,184 +0,0 @@ -findOne($id); - echo view('ventas.subsidios.add', compact('venta')); - } - public static function do_add() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $uf = uf($f); - - $pago1 = model(Pago::class)->create(); - $valor = post('ahorro_uf') * $uf->uf->value; - if (post('ahorro') != null) { - $valor = post('ahorro'); - } - $pago1->valor = $valor; - $pago1->fecha = $f->format('Y-m-d'); - $pago1->uf = $uf->uf->value; - - $pago2 = model(Pago::class)->create(); - $valor = post('subsidio_uf') * $uf->uf->value; - if (post('subsidio') != null) { - $valor = post('subsidio'); - } - $pago2->valor = $valor; - $pago2->fecha = $f->format('Y-m-d'); - $pago2->uf = $uf->uf->value; - - $pago1->new(); - $pago2->new(); - - $subsidio = model(Subsidio::class)->create(); - $subsidio->pago = $pago1->id; - $subsidio->subsidio = $pago2->id; - - $subsidio->save(); - $venta->subsidio = $subsidio->id(); - $venta->save(); - header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); - } - public static function edit() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - echo view('ventas.subsidios.edit', compact('venta')); - } - public static function do_edit() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $uf = uf($f); - - $pago1 = $venta->subsidio()->pago(); - $valor = post('ahorro_uf') * $uf->uf->value; - if (post('ahorro') != null) { - $valor = post('ahorro'); - } - $pago1->valor = $valor; - $pago1->fecha = $f->format('Y-m-d'); - $pago1->uf = $uf->uf->value; - - $pago2 = $venta->subsidio()->subsidio(); - $valor = post('subsidio_uf') * $uf->uf->value; - if (post('subsidio') != null) { - $valor = post('subsidio'); - } - $pago2->valor = $valor; - $pago2->fecha = $f->format('Y-m-d'); - $pago2->uf = $uf->uf->value; - - $pago1->save(); - $pago2->save(); - header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); - } - public static function pagar() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - $tipo = get('tipo'); - switch($tipo) { - case 'subsidio': - $pago = $venta->subsidio()->subsidio(); - break; - case 'pago': - $pago = $venta->subsidio()->pago(); - break; - default: - $pago = null; - } - echo view('ventas.subsidios.pagar', compact('venta', 'pago')); - } - public static function do_pagar() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $tipo = post('tipo'); - switch($tipo) { - case 'subsidio': - $pago = $venta->subsidio()->subsidio(); - break; - case 'pago': - $pago = $venta->subsidio()->pago(); - break; - default: - $pago = null; - } - $pago->valor = post('valor'); - $tipo = model(TipoEstadoPago::class)->where('descripcion', 'depositado')->findOne(); - $data = [ - 'pago' => $pago->id, - 'fecha' => $f->format('Y-m-d'), - 'estado' => $tipo->id - ]; - $estado = model(EstadoPago::class)->create($data); - $pago->save(); - $estado->save(); - header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); - } - public static function abonar() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - $tipo = get('tipo'); - switch($tipo) { - case 'subsidio': - $pago = $venta->subsidio()->subsidio(); - break; - case 'pago': - $pago = $venta->subsidio()->pago(); - break; - default: - $pago = null; - } - echo view('ventas.subsidios.abonar', compact('venta', 'pago')); - } - public static function do_abonar() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $tipo = post('tipo'); - switch($tipo) { - case 'subsidio': - $pago = $venta->subsidio()->subsidio(); - break; - case 'pago': - $pago = $venta->subsidio()->pago(); - break; - default: - $pago = null; - } - $pago->valor = post('valor'); - $tipo = model(TipoEstadoPago::class)->where('descripcion', 'abonado')->findOne(); - $data = [ - 'pago' => $pago->id, - 'fecha' => $f->format('Y-m-d'), - 'estado' => $tipo->id - ]; - $estado = model(EstadoPago::class)->create($data); - $pago->save(); - $estado->save(); - header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); - } -} diff --git a/app/Controller/Temas.php b/app/Controller/Temas.php deleted file mode 100644 index 24b121a..0000000 --- a/app/Controller/Temas.php +++ /dev/null @@ -1,111 +0,0 @@ -orderByAsc('descripcion')->findMany(); - return view('temas.add', compact('proyectos')); - } - public static function agregar() - { - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $data = [ - "proyecto_id" => post('proyecto'), - "inicio" => $f->format('Y-m-d'), - "texto" => post('texto') - ]; - $tema = model(Tema::class)->create($data); - - $tema->save(); - header('Location: ' . url('', ['p' => 'temas', 'a' => 'list'])); - } - public static function list() - { - $temas = model(Tema::class)->findMany(); - $t = Carbon::today(config('app.timezone')); - foreach ($temas as $i => $tema) { - if ($tema->cierre()->year != -1 and $t->diff($tema->cierre())->days > 10) { - unset($temas[$i]); - } - } - $temas = array_values($temas); - usort($temas, function($a, $b) { - $p = strcmp($a->proyecto()->descripcion, $b->proyecto()->descripcion); - if ($p == 0) { - $f = $b->inicio()->diff($a->inicio())->format('%r%a'); - if ($f == 0) { - return $a->id - $b->id; - } - return $f; - } - return $p; - }); - - return view('temas.list', compact('temas')); - } - public static function edit() - { - $id = get('tema'); - $tema = model(Tema::class)->findOne($id); - $proyectos = model(Proyecto::class)->orderByAsc('descripcion')->findMany(); - return view('temas.edit', compact('tema', 'proyectos')); - } - public static function editar() - { - $id = get('tema'); - $tema = model(Tema::class)->findOne($id); - - $proyecto = post('proyecto'); - $changed = false; - if ($tema->proyecto_id != $proyecto) { - $tema->proyecto_id = $proyecto; - $changed = true; - } - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - if ($tema->inicio() != $f) { - $tema->inicio = $f->format('Y-m-d'); - $changed = true; - } - $texto = post('texto'); - if ($tema->texto != $texto) { - $tema->texto = $texto; - $changed = true; - } - - if ($changed) { - $tema->save(); - } - header('Location: ' . url('', ['p' => 'temas', 'a' => 'list'])); - } - public static function cerrar() - { - $id = get('tema'); - $tema = model(Tema::class)->findOne($id); - $f = Carbon::today(config('app.timezone')); - $tema->cierre = $f->format('Y-m-d'); - - $tema->save(); - header('Location: ' . url('', ['p' => 'temas', 'a' => 'list'])); - } - public static function abrir() - { - $id = get('tema'); - $tema = model(Tema::class)->findOne($id)->as_array(); - unset($tema['id'], $tema['cierre'], $tema['created_at'], $tema['updated_at']); - - $tema = model(Tema::class)->create($tema); - - $tema->save(); - header('Location: ' . url('', ['p' => 'temas', 'a' => 'list'])); - } -} -?> diff --git a/app/Controller/Unidades.php b/app/Controller/Unidades.php deleted file mode 100644 index 9f0da01..0000000 --- a/app/Controller/Unidades.php +++ /dev/null @@ -1,126 +0,0 @@ -findOne($id); - $len = strlen(post('total')); - - $unis = json_decode(post('unidades')); - $data = []; - foreach ($unis as $n_unidad) { - if ($tipo->tipo()->descripcion == 'departamento') { - $ini = post('piso_ini' . $n_unidad); - $end = post('piso_end' . $n_unidad); - $subtipo = post('linea' . $n_unidad); - $orientacion = post('orientacion' . $n_unidad); - for ($piso = $ini; $piso <= $end; $piso ++) { - $descripcion = $piso . str_pad(post('linea' . $n_unidad), $len, '0', \STR_PAD_LEFT); - - $data []= [ - 'proyecto' => $tipo->proyecto()->id, - 'tipo' => $tipo->tipo()->id, - 'subtipo' => $subtipo, - 'piso' => $piso, - 'descripcion' => $descripcion, - 'abreviacion' => $tipo->abreviacion, - 'm2' => $tipo->m2, - 'terraza' => $tipo->terraza, - 'logia' => $tipo->logia, - 'orientacion' => $orientacion, - 'pt' => $tipo->id - ]; - } - } else { - $descripcion = post('descripcion' . $n_unidad); - $piso = post('piso' . $n_unidad); - $data []= [ - 'proyecto' => $tipo->proyecto()->id, - 'tipo' => $tipo->tipo()->id, - 'piso' => $piso, - 'descripcion' => $descripcion, - 'abreviacion' => $tipo->abreviacion, - 'm2' => $tipo->m2, - 'terraza' => $tipo->terraza, - 'logia' => $tipo->logia, - 'pt' => $tipo->id - ]; - } - } - - foreach ($data as $uni) { - $unidad = model(Unidad::class) - ->where('descripcion', $uni['descripcion']) - ->where('proyecto', $uni['proyecto']) - ->where('tipo', $uni['tipo']) - ->findOne(); - if ($unidad) { - continue; - } - $unidad = model(Unidad::class)->create($uni); - $unidad->save(); - } - header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'list_unidades', 'proyecto' => $tipo->proyecto()->id])); - } - public static function edit() - { - $id = get('unidad'); - $unidad = model(Unidad::class)->findOne($id); - $tipos = model(ProyectoTipoUnidad::class)->where('proyecto', $unidad->proyecto()->id)->findMany(); - $abreviaciones = ['N', 'NE', 'E', 'SE', 'S', 'SO', 'O', 'NO']; - $descripciones = ['Norte', 'Noreste', 'Este', 'Sureste', 'Sur', 'Suroeste', 'Oeste', 'Noroeste']; - $orientaciones = []; - foreach ($abreviaciones as $i => $ab) { - $orientaciones []= (object) ['abreviacion' => $ab, 'descripcion' => $descripciones[$i]]; - } - - return view('proyectos.unidades.edit', compact('unidad', 'tipos', 'orientaciones')); - } - public static function editar() - { - $id = get('unidad'); - $unidad = model(Unidad::class)->findOne($id); - - $change = false; - $fields = ['descripcion', 'tipo', 'piso', 'linea', 'orientacion']; - foreach ($fields as $field) { - $f = $field; - if ($f == 'tipo') { - $f = 'pt'; - } - if ($f == 'linea') { - $f = 'subtipo'; - } - if ($unidad->{$f} != post($field)) { - $unidad->{$f} = post($field); - $change = true; - } - } - - if ($change) { - $unidad->save(); - } - header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $unidad->proyecto()->id])); - } - public static function remove() - { - $id = get('unidad'); - $unidad = model(Unidad::class)->findOne($id); - $unidad->delete(); - - $id = get('proyecto'); - header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $id])); - } -} -?> diff --git a/app/Controller/UnidadesBloqueadas.php b/app/Controller/UnidadesBloqueadas.php deleted file mode 100644 index 9bd4107..0000000 --- a/app/Controller/UnidadesBloqueadas.php +++ /dev/null @@ -1,83 +0,0 @@ -findMany(); - echo view('ventas.operadores.unidades.list', compact('proyectos')); - } - public static function add() - { - $proyectos = model(Proyecto::class)->findMany(); - echo view('ventas.operadores.unidades.add', compact('proyectos')); - } - public static function bloquear() - { - $operador = model(ProyectoAgente::class)->findOne(get('operador')); - echo view('ventas.operadores.unidades.bloquear', compact('operador')); - } - public static function do_bloquear() - { - $operador = model(ProyectoAgente::class)->findOne(get('operador')); - $fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $unidades = self::getUnidades([], 'departamentos', 1); - $unidades = self::getUnidades($unidades, 'estacionamientos', 2); - $unidades = self::getUnidades($unidades, 'bodegas', 3); - if (post('unidad') != null) { - foreach (post('unidad') as $u) { - $unidad = model(Unidad::class)->findOne($u); - if (array_search($unidad, $unidades) === false) { - $unidades []= $unidad; - } - } - } - - foreach ($unidades as $unidad) { - $data = [ - 'agente' => $operador->id, - 'unidad' => $unidad->id - ]; - $ub = model(UnidadBloqueada::class)->create($data); - $ub->new($fecha); - } - header('Location: ' . nUrl('unidades_bloqueadas', 'list')); - } - protected static function getUnidades(array $unidades, string $name, int $tipo): array - { - if (trim(post($name)) == '') { - return $unidades; - } - $unis = []; - $separators = [PHP_EOL, ';', ',', '-']; - foreach ($separators as $separator) { - if (strpos(post($name), $separator) !== false) { - $unis = explode($separator, post($name)); - break; - } - } - if (count($unis) == 0) { - return $unidades; - } - array_walk($unis, function(&$item) { - $item = trim($item); - $item = model(Unidad::class)->where('descripcion', $item)->where('tipo', 1)->findOne(); - }); - foreach ($unis as $uni) { - if (array_search($uni, $unidades) === false) { - $unidades []= $uni; - } - } - return $unidades; - } -} diff --git a/app/Controller/Ventas.php b/app/Controller/Ventas.php deleted file mode 100644 index 31f1e61..0000000 --- a/app/Controller/Ventas.php +++ /dev/null @@ -1,605 +0,0 @@ -findOne($proyecto); - $ventas = $proyecto->ventas(); - self::sort($ventas); - return view('ventas.list', compact('proyecto', 'ventas')); - } - protected static function sort(&$ventas) - { - $sort = get('sort'); - if ($sort == null) { - $sort = 'departamento'; - } - $direction = get('sort_dir'); - if ($direction == null) { - $direction = 1; - } - switch ($sort) { - case 'departamento': - usort($ventas, function($a, $b) use ($direction) { - return ($a->propiedad()->unidad()->descripcion - $b->propiedad()->unidad()->descripcion) * $direction; - }); - break; - case 'propietario': - usort($ventas, function($a, $b) use ($direction) { - $pa = trim($a->propietario()->nombreCompleto(true), ', '); - $pb = trim($b->propietario()->nombreCompleto(true), ', '); - return $direction * strcasecmp($pa, $pb); - }); - break; - case 'valor_uf': - usort($ventas, function($a, $b) use ($direction) { - return $direction * ($a->valor_uf - $b->valor_uf); - }); - break; - case 'uf_m2': - usort($ventas, function($a, $b) use ($direction) { - return $direction * ($a->uf_m2() - $b->uf_m2()); - }); - break; - case 'fecha_venta': - usort($ventas, function($a, $b) use ($direction) { - return ($a->fecha()->timestamp - $b->fecha()->timestamp) * $direction; - }); - break; - } - if ($direction == 'desc') { - $ventas = array_reverse($ventas); - } - } - public static function listProyectos() - { - $proyectos = model(Proyecto::class) - ->select('proyecto.*') - ->join('estado_proyecto', ['estado.proyecto', '=', 'proyecto.id'], 'estado') - ->join('tipo_estado_proyecto', ['tipo.id', '=', 'estado.estado'], 'tipo') - ->join('etapa_proyecto', ['etapa.id', '=', 'tipo.etapa'], 'etapa') - ->whereGte('etapa.orden', 4) - ->orderByAsc('proyecto.descripcion') - ->groupBy('proyecto.id') - ->findMany(); - echo view('ventas.proyectos', compact('proyectos')); - } - public static function show() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - return view('ventas.show', compact('venta')); - } - public static function new() - { - $proyectos = model(Proyecto::class) - ->select('proyecto.*') - ->join('estado_proyecto', ['estado.proyecto', '=', 'proyecto.id'], 'estado') - ->join('tipo_estado_proyecto', ['tipo.id', '=', 'estado.estado'], 'tipo') - ->join('etapa_proyecto', ['etapa.id', '=', 'tipo.etapa'], 'etapa') - ->whereGte('etapa.orden', 3) - ->orderByAsc('proyecto.descripcion') - ->groupBy('proyecto.id') - ->findMany(); - $regiones = model(Region::class)->order_by_asc('numeracion')->findMany(); - return view('ventas.add', compact('proyectos', 'regiones')); - } - public static function agregar() - { - error_log(var_export(post(), true)); - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $t = Carbon::today(config('app.timezone')); - $uf = uf($f); - error_log(var_export($uf, true)); - - $calle = trim(post('calle')); - $numero = post('numero'); - $extra = trim(post('extra')); - $comuna = post('comuna'); - $direccion = model(Direccion::class) - ->where('calle', $calle) - ->where('numero', $numero) - ->where('extra', $extra) - ->where('comuna', $comuna) - ->findOne(); - if (!$direccion) { - $direccion = model(Direccion::class)->create(); - $direccion->calle = $calle; - $direccion->numero = $numero; - $direccion->extra = $extra; - $direccion->comuna = $comuna; - $direccion->save(); - } - - list($rut, $dv) = explode('-', str_replace('.', '', post('rut'))); - $propietario = model(Propietario::class)->where('rut', $rut)->findOne(); - if (!$propietario) { - $propietario = model(Propietario::class)->create(); - $propietario->rut = $rut; - $propietario->dv = $dv; - $propietario->nombres = trim(post('nombres')); - $propietario->apellido_paterno = trim(post('paterno')); - $propietario->apellido_materno = trim(post('materno')); - $propietario->direccion = $direccion->id; - if (post('otro') != null) { - $propietario->otro = 1; - } - - $propietario->save(); - } - - $unis = json_decode(post('unidades')); - $id_principal = array_shift($unis); - $principal = model(Unidad::class)->findOne(post('unidad' . $id_principal)); - // Revisar si existe la propiedad y si está vigente. - $propiedad = model(Propiedad::class)->create(); - $propiedad->unidad_principal = $principal->id; - $propiedad->save(); - $data = [ - 'propiedad' => $propiedad->id, - 'unidad' => $principal->id, - 'principal' => 1 - ]; - $pu = model(PropiedadUnidad::class)->create($data); - $pu->save(); - foreach ($unis as $id_unidad) { - $data = [ - 'propiedad' => $propiedad->id, - 'unidad' => post('unidad' . $id_unidad), - 'principal' => 0 - ]; - $pu = model(PropiedadUnidad::class)->create($data); - $pu->save(); - } - - $venta = model(Venta::class)->create(); - $venta->propietario = $propietario->rut; - $venta->propiedad = $propiedad->id; - if (post('pie')) { - $pie = model(Pie::class)->create(); - $pie->valor = post('pie'); - $pie->fecha = $f->format('Y-m-d'); - $pie->cuotas = post('cuotas'); - if ($uf->total > 0) { - $pie->uf = $uf->uf->value; - } - $pie->save(); - - $venta->pie = $pie->id; - } - if (post('bono_pie')) { - $bono = model(BonoPie::class)->create(); - $bono->valor = post('bono_pie'); - - $pago = model(Pago::class)->create(); - $pago->fecha = $f->format('Y-m-d'); - if ($uf->total > 0) { - $pago->uf = $uf->uf->value; - } - $pago->valor = $bono->valor * $uf->uf->value; - $pago->tipo = 8; - $pago->new(); - - $bono->pago = $pago->id; - $bono->save(); - - $venta->bono_pie = $bono->id; - } - if (post('credito')) { - $pago = model(Pago::class)->create(); - $pago->fecha = $f->format('Y-m-d'); - if ($uf->total > 0) { - $pago->uf = $uf->uf->value; - } - $pago->valor = post('credito') * $uf->uf->value; - $pago->tipo = 2; - $pago->new(); - - $credito = model(Credito::class)->create(); - $credito->pago = $pago->id; - $credito->save(); - - $venta->credito = $credito->id; - } - - $venta->fecha = $f->format('Y-m-d'); - $venta->valor_uf = str_replace(',', '.', post('valor')); - $venta->fecha_ingreso = $t->format('Y-m-d'); - if (post('operador') != 0) { - $venta->agente = post('operador'); - } - if ($uf->total > 0) { - $venta->uf = $uf->uf->value; - } - $venta->new(); - - if (post('promociones') != 0) { - $promos = json_decode(post('promociones')); - foreach ($promos as $id_promo) { - $promocion = model(Promocion::class)->findOne(post('promocion' . $id_promo)); - $promo = model(PromocionVenta::class)->create(); - $promo->promocion = $promocion->id; - $promo->venta = $venta->id; - $promo->valor = post('promo' . $id_promo); - $promo->save(); - } - } - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function edit() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->findMany(); - $regiones = model(Region::class)->order_by_asc('numeracion')->findMany(); - return view('ventas.edit', compact('venta', 'proyectos', 'regiones')); - } - public static function editar() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $uf = uf($f); - - $valor = correctNumber(post('valor')); - $change = false; - if ($venta->fecha != $f->format('Y-m-d')) { - $venta->fecha = $f->format('Y-m-d'); - $venta->uf = $uf->uf->value; - $change = true; - } - if ($venta->valor_uf != $valor) { - $venta->valor_uf = $valor; - $change = true; - } - if ($change) { - $venta->save(); - } - - $direccion = $venta->propietario()->direccion(); - $calle = post('calle'); - $numero = post('numero'); - $extra = post('extra'); - $comuna = post('comuna'); - $change = false; - if ($direccion->calle != $calle) { - $direccion->calle = $calle; - $change = true; - } - if ($direccion->numero != $numero) { - $direccion->numero = $numero; - $change = true; - } - if ($direccion->extra != $extra) { - $direccion->extra = $extra; - $change = true; - } - if ($direccion->comuna != $comuna) { - $direccion->comuna = $comuna; - $change = true; - } - if ($change) { - $direccion->save(); - } - - $propietario = $venta->propietario(); - list($rut, $dv) = explode('-', str_replace('.', '', post('rut'))); - $nombres = post('nombres'); - $paterno = post('paterno'); - $materno = post('materno'); - $change = false; - if ($propietario->rut != $rut) { - $propietario->rut = $rut; - $propietario->dv = $dv; - $venta->propietario = $rut; - $venta->save(); - $change = true; - } - if ($propietario->nombres != $nombres) { - $propietario->nombres = $nombres; - $change = true; - } - if ($propietario->apellido_paterno != $paterno) { - $propietario->apellido_paterno = $paterno; - $change = true; - } - if ($propietario->apellido_materno != $materno) { - $propietario->apellido_materno = $materno; - $change = true; - } - if ($change) { - $propietario->save(); - } - - $unidades = json_decode(post('unidades')); - if (count($unidades) > 0) { - $propiedad = $venta->propiedad(); - $ests = explode(';', $propiedad->estacionamientos); - $bods = explode(';', $propiedad->bodegas); - $change = false; - foreach ($unidades as $n) { - $id = post('unidad' . $n); - $unidad = model(Unidad::class)->findOne($id); - if ($unidad->tipo == 1 and $propiedad->unidad_principal != $unidad->id) { - $propiedad->unidad_principal = $unidad->id; - $change = true; - } - if ($unidad->tipo == 2 and array_search($unidad->id, $ests) === false) { - $ests []= $unidad->id; - } - if ($unidad->tipo == 3 and array_search($unidad->id, $bods) === false) { - $bods []= $unidad->id; - } - } - $ests = implode(';', $ests); - $bods = implode(';', $bods); - if ($propiedad->estacionamientos != $ests) { - $propiedad->estacionamientos = $ests; - $change = true; - } - if ($propiedad->bodegas != $bods) { - $propiedad->bodegas = $bods; - $change = true; - } - if ($change) { - $propiedad->save(); - } - } - - if (post('pie')) { - $pie = $venta->pie(); - $valor = correctNumber(post('pie')); - $cuotas = post('cuotas'); - $change = false; - if ($pie->valor != $valor) { - $pie->valor = $valor; - $change = true; - } - if ($pie->cuotas != $cuotas) { - $pie->cuotas = $cuotas; - $change = true; - } - if ($change) { - $pie->save(); - } - } - - $credito = $venta->credito(); - $valor = post('credito'); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function desistir() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - return view('ventas.desist', compact('venta')); - } - public static function desistiendo() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $valor = correctNumber(post('pago')); - $uf = uf($f); - - $venta->estado = 0; - $tipo = model(TipoEstadoVenta::class)->where('descripcion', 'desistida')->findOne(); - $data = [ - 'venta' => $venta->id, - 'estado' => $tipo->id, - 'fecha' => $f->format('Y-m-d') - ]; - $estado = model(EstadoVenta::class)->create($data); - $propiedad = $venta->propiedad(); - $propiedad->estado = 0; - $pago = model(Pago::class)->create(); - $pago->fecha = $f->format('Y-m-d'); - $pago->valor = (double) $valor; - $pago->uf = $uf->uf->value; - $pago->tipo = 1; - - $pago->new(); - $propiedad->save(); - $estado->save(); - $venta->resciliacion = $pago->id; - $venta->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function ceder() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - return view('ventas.ceder', compact('venta')); - } - public static function cediendo() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - $nueva_venta = model(Venta::class)->create(); - - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - - list($rut, $dv) = explode('-', str_replace('.', '', post('rut'))); - $propietario = model(Propietario::class)->where('rut', $rut)->findOne(); - if (!$propietario) { - $propietario = model(Propietario::class)->create(); - $propietario->rut = $rut; - $propietario->dv = $dv; - $propietario->nombres = trim(post('nombres')); - $propietario->apellido_paterno = trim(post('paterno')); - $propietario->apellido_materno = trim(post('materno')); - $propietario->direccion = $direccion->id; - if (post('otro') != null) { - $propietario->otro = 1; - } - - $propietario->save(); - } - - $nueva_venta->fecha_ingreso = $f->format(); - $nueva_venta->estado = 1; - $cols = [ - 'propiedad', - 'pie', - 'bono_pie', - 'credito', - 'escritura', - 'subsidio', - 'fecha', - 'valor_uf', - 'agente', - 'uf' - ]; - foreach ($cols as $col) { - $nueva_venta->{$col} = $venta->{$col}; - } - $nueva_venta->new(); - - $venta->estado = -1; - $tipo = model(TipoEstadoVenta::class)->where('descripcion', 'cedida')->findOne(); - $data = [ - 'venta' => $venta->id, - 'estado' => $tipo->id, - 'fecha' => $f->format('Y-m-d') - ]; - $estado = model(EstadoVenta::class)->create($data); - $estado->save(); - - $venta->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function entregar() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - return view('ventas.entregar', compact('venta')); - } - public static function consolidacion() - { - if (get('proyecto')) { - $id_proyecto = get('proyecto'); - $proyecto = model(Proyecto::class)->findOne($id_proyecto); - - $ventas = $proyecto->ventas(); - set_time_limit(count($ventas)); - - $f = Carbon::today(config('app.timezone')); - setlocale(LC_TIME, 'es'); - - return view('ventas.consolidacion.show', compact('ventas', 'f')); - } else { - $proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many(); - return view('ventas.consolidacion.proyectos', compact('proyectos')); - } - } - public static function devolucion() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - $uf = uf(Carbon::now(config('app.config')))->uf->value; - $valor = round($venta->saldo() * $uf); - - return view('ventas.devolucion', compact('venta', 'valor', 'uf')); - } - public static function devolver() - { - $id = get('venta'); - $venta = model(Venta::class)->findOne($id); - - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $uf = uf($f); - $valor = correctNumber(post('valor')); - - $data = [ - 'fecha' => $f->format('Y-m-d'), - 'valor' => $valor, - 'tipo' => 1, - 'uf' => $uf->uf->value, - 'identificador' => post('identificador'), - 'banco' => 0 - ]; - - $banco = model(Banco::class)->where('nombre', post('banco'))->findOne(); - if ($banco) { - $data['banco'] = $banco->id; - } - - $pago = model(Pago::class)->create($data); - $pago->newPagado(); - - $venta->devolucion = $pago->id; - $venta->save(); - header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); - } - public static function resciliaciones() - { - $resciliaciones = model(Venta::class)->where('estado', 0)->findMany(); - - return view('ventas.resciliaciones', compact('resciliaciones')); - } - public static function firmar() - { - $venta = \model(Venta::class)->findOne(get('venta')); - return view('ventas.firmar', compact('venta')); - } - public static function firmando() - { - $venta = \model(Venta::class)->findOne(get('venta')); - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $venta->firmar($f); - header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); - - } - public static function archivar() - { - $venta = \model(Venta::class)->findOne(get('venta')); - return view('ventas.archivar', compact('venta')); - } - public static function archivando() - { - $venta = \model(Venta::class)->findOne(get('venta')); - $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $venta->archivar($f); - header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id])); - } -} -?> diff --git a/app/Definition/Controller.php b/app/Definition/Controller.php deleted file mode 100644 index c0e3dae..0000000 --- a/app/Definition/Controller.php +++ /dev/null @@ -1,31 +0,0 @@ -isPublic()) { - - return self::{$action}(); - } - } - if (self::$default == null and \method_exists(self::class, 'setDefault')) { - self::setDefault(); - } - if (self::$default == null) { - header('Location: .'); - return; - } - return self::$default; - } -} -?> \ No newline at end of file diff --git a/app/Definition/hasEstado.php b/app/Definition/hasEstado.php deleted file mode 100644 index 014fe8a..0000000 --- a/app/Definition/hasEstado.php +++ /dev/null @@ -1,38 +0,0 @@ -getTable(); - $self = Stringy::create(get_class($this)); - $ns = $self->substr(0, $self->indexOfLast('\\')); - $self = $self->substr($self->indexOfLast('\\') + 1); - $column = $self->underscored(); - $class = $ns . '\\Estado' . $self; - if (substr($table, -1, 1) == 's') { - $column .= '_id'; - } - - return $this->has_many($class, $column)->findMany(); - } - public function estado() - { - $table = $this->getTable(); - $self = Stringy::create(get_class($this)); - $ns = $self->substr(0, $self->indexOfLast('\\')); - $self = $self->substr($self->indexOfLast('\\') + 1); - $column = $self->underscored(); - $class = $ns . '\\Estado' . $self; - if (substr($table, -1, 1) == 's') { - $column .= '_id'; - } - - $id = $this->has_many($class, $column)->max('id'); - return $this->has_many($class, $column)->findOne($id); - } -} -?> \ No newline at end of file diff --git a/app/Definition/hasRUT.php b/app/Definition/hasRUT.php deleted file mode 100644 index 8ba3d80..0000000 --- a/app/Definition/hasRUT.php +++ /dev/null @@ -1,20 +0,0 @@ -rut) . '-' . $this->dv; - } -} -?> \ No newline at end of file diff --git a/app/Exception/PropertyNotFound.php b/app/Exception/PropertyNotFound.php deleted file mode 100644 index a35e537..0000000 --- a/app/Exception/PropertyNotFound.php +++ /dev/null @@ -1,16 +0,0 @@ -class = $class; - $this->property = $property; - $msg = "Property '" . $property . "' for class '" . $class . "' not found."; - parent::__construct($msg); - } -} \ No newline at end of file diff --git a/app/Helper/Color.php b/app/Helper/Color.php deleted file mode 100644 index 68c3199..0000000 --- a/app/Helper/Color.php +++ /dev/null @@ -1,169 +0,0 @@ -color = $args[0]; - break; - } - $this->color = $this->hex2dec($this->hex2array($args[0])); - break; - case 2: - if (is_array($args[0])) { - $this->color = $args[0]; - $this->color []= $args[1]; - break; - } - $color = $this->hex2array($args[0]); - $color []= $args[1]; - $this->color = $this->hex2dec($color); - break; - case 3: - case 4: - if (is_numeric($args[0])) { - $this->color = $args; - break; - } - $this->color = $this->hex2dec($args); - break; - } - } - protected function hex2dec(array $hex) - { - return array_map('hexdec', $hex); - } - protected function dec2hex(array $bin) - { - return array_map('dechex', $bin); - } - protected function hex2array(string $hex) - { - switch (strlen($hex)) { - case 3: - case 4: - case 6: - case 7: - return str_split($hex, 2); - default: - throw new OutOfBoundsException('The string ' . $hex . ' is not a correct color code.'); - } - } - protected function array2hex(array $arr) - { - return implode('', $arr); - } - - public function convertTo($type) - { - switch (strtolower($type)) { - case 'hex': - if (is_numeric($this->color[0])) { - $this->color = $this->dec2hex($this->color); - } - break; - case 'dec': - if (!is_numeric($this->color[0])) { - $this->color = $this->hex2dec($this->color); - } - break; - default: - throw new InvalidArgumentException($type . ' is not a valid argument.'); - } - } - public function add($base_color, $amount) - { - $changed = false; - if (!is_numeric($this->color)) { - $this->convertTo('dec'); - $changed = true; - } - switch (strtolower($base_color)) { - case 'r': - $base_color = 0; - break; - case 'g': - $base_color = 1; - break; - case 'b': - $base_color = 2; - break; - case 'a': - $base_color = 3; - break; - default: - throw new OutOfBoundsException("Base color '" . $base_color . "' does not exist."); - } - $this->color[$base_color] += $amount; - if ($changed) { - $this->convertTo('hex'); - } - } - public function print() - { - $this->convertTo('hex'); - return implode('', $this->color); - } - public function toRGB() - { - $changed = false; - $this->convertTo('dec'); - $str = 'rgb(' . implode(', ', array_map(function($a) { - return round($a, 2); - }, $this->color)) . ')'; - if ($changed) { - $this->convertTo('hex'); - } - return $str; - } - public function __toString() - { - return $this->print(); - } - public function toArray() - { - return $this->color; - } - public function toVector() - { - $changed = false; - $this->convertTo('dec'); - $arr = $this->toArray(); - if ($changed) { - $this->convertTo('hex'); - } - return $arr; - } - public function luminosity() - { - $changed = false; - $this->convertTo('dec'); - //sqrt( 0.299*R^2 + 0.587*G^2 + 0.114*B^2 ) - $str = sqrt(0.299 * pow($this->color[0], 2) + 0.587 * pow($this->color[1], 2) + 0.114 * pow($this->color[2], 2)) / 255 * 100; - if ($changed) { - $this->convertTo('hex'); - } - return $str; - } - public function isDark() - { - if ($this->luminosity() < 50) { - return true; - } - return false; - } - public function isBright() - { - if ($this->luminosity() > 75) { - return true; - } - return false; - } -} diff --git a/app/Helper/Line.php b/app/Helper/Line.php deleted file mode 100644 index 02cc0d9..0000000 --- a/app/Helper/Line.php +++ /dev/null @@ -1,61 +0,0 @@ -origin = $point_a; - $this->length = $this->distance($point_a, $point_b); - $this->direction = $this->gradient($point_a, $point_b); - } - public function origin() - { - return $this->origin; - } - public function length() - { - return $this->length; - } - public function direction() - { - return $this->direction; - } - /** - * Calculate the gradient to move from point a to point b - * @param array $point_a [Vector] - * @param array $point_b [Vector] - * @return array [Vector] - */ - public function gradient($point_a, $point_b) - { - $distance = $this->distance($point_a, $point_b); - return array_map(function($a, $b) use ($distance) { - return ($a - $b) / $distance; - }, $point_b, $point_a); - } - // sqrt((a0-b0)²+(a1-b1)²+(a2-b2)²) - public function distance($point_a, $point_b) - { - return sqrt(array_sum(array_map(function($a, $b) { - return pow($a - $b, 2); - }, $point_a, $point_b))); - } - /** - * Move from point in the direction of the gradient acording to step_size - * @param array $point [Vector] - * @param int $step_size [step size] - * @return array [Vector] - */ - public function move($point, $step_size) - { - $gradient = $this->direction; - return array_map(function($a, $b) use ($step_size) { - return $a + $b * $step_size; - }, $point, $gradient); - } -} diff --git a/app/Helper/functions.php b/app/Helper/functions.php deleted file mode 100644 index 7c55e14..0000000 --- a/app/Helper/functions.php +++ /dev/null @@ -1,128 +0,0 @@ - "http://{$remote->getIP()}:8080", - 'headers' => [ - 'Accept' => 'application/json' - ] - ])))->getUF($date); -} -function format($tipo, $valor, $format = null, $print = false) { - if ($valor === null) { - $valor = 0; - } - if (strtolower($tipo) == 'localdate') { - $d = \Carbon\Carbon::parse($valor); - $d->locale('es_ES'); - if ($format == null) { - $format = 'DD [de] MMMM [de] YYYY'; - } - return $d->isoFormat($format); - } - if (method_exists('\App\Helper\Format', $tipo)) { - if ($print) { - return \App\Helper\Format::$tipo($valor, $print); - } else { - return \App\Helper\Format::$tipo($valor); - } - } else { - switch ($tipo) { - case 'localDate': - if (isset($format)) { - $intl = new IntlDateFormatter('es_ES', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, 'America/Santiago'); - $intl->setPattern($format); - return ucwords($intl->format($valor)); - } - case 'percent': - return \App\Helper\Format::number($valor, 2); - case 'rut': - return \App\Helper\Format::number($valor, 0); - } - } -} -function model(string $class_name) { - return \Model::factory($class_name); -} -function correctNumber($number) { - if (strpos($number, ',') !== false) { - return str_replace(',', '.', str_replace('.', '', $number)); - } elseif (substr_count($number, '.') > 1) { - return str_replace('.', '', $number); - } - return $number; -} -function parseRanges($range, $numeric = true, $negatives = true) { - $rns = preg_split('/[,;]+/', $range); - $data = []; - foreach ($rns as $p) { - if (!$negatives) { - if (strpos($p, '-') !== false) { - list($ini, $end) = explode('-', $p); - $data = array_merge($data, range($ini, $end)); - continue; - } - } - if ($numeric) { - $data []= (float) $p; - continue; - } - $data []= $p; - } - return $data; -} -function nUrl($p, $a = null, $data = null) { - $query = ['p' => $p]; - if ($a != null) { - $query['a'] = $a; - if ($data != null) { - $query = array_merge($query, $data); - } - } - return url('', $query); -} -function api($p, $a, $data = null) { - $url = baseUrl() . '/' . 'api'; - $url .= '?' . 'p=' . $p . '&a=' . $a . '&API_KEY=1'; - if ($data != null) { - $url .= '&' . implode('&', array_map(function($val, $k) { - return $k . '=' . $val; - }, $data)); - } - return $url; -} -function doLog($user, $action, $variables) { - App\Service\Register::log($user, $action, $variables); -} -?> diff --git a/app/Service/Auth.php b/app/Service/Auth.php deleted file mode 100644 index 7af1f48..0000000 --- a/app/Service/Auth.php +++ /dev/null @@ -1,163 +0,0 @@ -getCookie(); - } - protected function getCookie() - { - if (isset($_COOKIE['rememberMe'])) { - list($s, $t) = \explode(':', $_COOKIE['rememberMe']); - $this->selector = $s; - $this->token = $t; - } - } - protected function saveCookie() - { - $now = \Carbon\Carbon::now(config('app.timezone')); - $exp = $now->addHours(config('app.login_hours')); - \setcookie('rememberMe', $this->selector . ':' . $this->token, $exp->timestamp); - } - protected function clearCookie() - { - \setcookie('rememberMe', '', \Carbon\Carbon::now(config('app.timezone'))->timestamp); - } - protected function generateToken() - { - $this->selector = bin2hex(\random_bytes(12)); - $this->token = bin2hex(\random_bytes(20)); - } - public function login($username, $password) - { - $user = \Model::factory(\Incoviba\common\User::class)->where('name', $username)->where('enabled', 1)->findOne(); - if ($user !== false) { - if (\password_verify($password, $user->password) === false) { - $this->clearCookie(); - return false; - } - - $this->generateToken(); - $now = \Carbon\Carbon::now(config('app.timezone')); - $exp = $now->addHours(-config('app.login_hours')); - $auth = \Model::factory(\Incoviba\common\Auth::class)->where('user_id', $user->id)->whereGt('time', $exp->timestamp)->where('status', 1)->findOne(); - if ($auth !== false) { - $auth->time('now'); - $auth->selector = $this->selector; - $auth->token($this->token); - $auth->save(); - $this->saveCookie(); - return true; - } - - $auth = \Model::factory(\Incoviba\common\Auth::class)->create(); - $auth->user_id = $user->id; - $auth->time('now'); - $auth->selector = $this->selector; - $auth->token($this->token); - - try { - $auth->save(); - $this->saveCookie(); - return true; - } catch (\Exception $e) { - $this->clearCookie(); - return false; - } - } - return false; - } - public function isIn() - { - if ($this->selector == null) { - return false; - } - $auths = \Model::factory(\Incoviba\common\Auth::class)->where('selector', $this->selector)->findMany(); - if ($auths === false) { - $this->clearCookie(); - return false; - } - foreach ($auths as $auth) { - if (\password_verify($this->token, $auth->token)) { - return $auth->isIn(); - } - } - return false; - } - public function User() - { - if ($this->selector == null) { - return false; - } - $auths = \Model::factory(\Incoviba\common\Auth::class)->where('selector', $this->selector)->findMany(); - if ($auths === false) { - return false; - } - foreach ($auths as $auth) { - if (\password_verify($this->token, $auth->token)) { - return $auth->user(); - } - } - return false; - } - public function hasAccess() - { - if ($this->selector == null) { - return false; - } - $auths = \Model::factory(\Incoviba\common\Auth::class)->where('selector', $this->selector)->findMany(); - if ($auths === false) { - return false; - } - foreach ($auths as $auth) { - if (\password_verify($this->token, $auth->token)) { - return $auth->user()->hasAccess(); - } - } - return false; - } - public function checkAccess($controller, $action = null) - { - if ($this->selector == null) { - return false; - } - $auths = \Model::factory(\Incoviba\common\Auth::class)->where('selector', $this->selector)->findMany(); - if ($auths === false) { - return false; - } - foreach ($auths as $auth) { - if (\password_verify($this->token, $auth->token)) { - return $auth->user()->checkAccess($controller, $action); - } - } - return false; - } - public function logout() - { - $this->clearCookie(); - if ($this->selector == null) { - return true; - } - $auths = \Model::factory(\Incoviba\common\Auth::class)->where('selector', $this->selector)->findMany(); - if ($auths === false) { - return true; - } - foreach ($auths as $auth) { - if (\password_verify($this->token, $auth->token)) { - $auth->status = 0; - try { - $auth->save(); - return true; - } catch (\Exception $e) { - return false; - } - } - } - return true; - } -} diff --git a/app/Service/Borrador.php b/app/Service/Borrador.php deleted file mode 100644 index 4f4b3af..0000000 --- a/app/Service/Borrador.php +++ /dev/null @@ -1,118 +0,0 @@ -cierre = $cierre; - $this->lineas = []; - } - protected function add(string $str, int $new_line = 0) - { - $this->lineas []= $str; - if ($new_line > 0) { - $this->newLine($new_line); - } - } - protected function newLine($n = 1) - { - for ($i = 0; $i < $n; $i ++) { - $this->lineas []= ''; - } - } - protected function load() - { - $this->word = IOFactory::load('borrador-' . $this->cierre->proyecto()->nombre . '.docx'); - } - protected function extract() - { - $this->load(); - $data = []; - foreach ($this->word->getSections() as $section) { - foreach ($section->getElements() as $element) { - $r = $this->elementGet($element); - $data []= $r; - } - } - if (count($data) > 0) { - $this->text = $data; - } - } - protected function elementGet($element) - { - if ($element instanceof TextBreak) { - return PHP_EOL; - } - if ($element instanceof TextRun) { - $data = []; - foreach ($element->getElements() as $e) { - $data []= $this->elementGet($e); - } - return implode('', $data); - } - if (!method_exists($element, 'getText')) { - d($element); - } - return $element->getText(); - } - protected function build() - { - if ($this->text == null) { - $this->extract(); - } - foreach ($this->text as $line) { - if ($line == PHP_EOL) { - $this->newLine(); - continue; - } - if (strpos($line, '[[') !== false) { - $replacer = new Replacer(); - $this->add($replacer->replace($line, $this->cierre)); - continue; - } - $this->add($line); - } - } - public function create() - { - $output = new PhpWord(); - - $output->getSettings()->setDecimalSymbol(','); - $output->getSettings()->setThemeFontLang(new Language(Language::ES_ES)); - - $section = $output->addSection(); - foreach ($this->lineas as $linea) { - if ($linea == '') { - $section->addTextBreak(); - continue; - } - $section->addText($linea); - } - - $output->getSettings()->setTrackRevisions(true); - - $writer = IOFactory::createWriter($output); - $filename = 'Borrador ' . $this->cierre->propietario()->nombreCompleto() . ' con ' . $this->cierre->proyecto()->inmobiliaria()->razon_social . '.docx'; - $writer->save($filename); - } - public function show() - { - $this->build(); - return implode(PHP_EOL, $this->lineas); - } -} -?> \ No newline at end of file diff --git a/app/Service/DBToModel.php b/app/Service/DBToModel.php deleted file mode 100644 index 158e85c..0000000 --- a/app/Service/DBToModel.php +++ /dev/null @@ -1,158 +0,0 @@ -name = $name; - $this->db = \ORM::get_db($name); - } - - public function run() - { - $this->getTables(); - foreach ($this->tables as $table) { - if ($this->createClass($table)) { - echo 'ok
    ', PHP_EOL; - } - } - } - protected function getType($type) - { - if (strpos($type, '(') !== false) { - $type = substr($type, 0, strpos($type, '(')); - } - if (strpos($type, ' ') !== false) { - $type = substr($type, 0, strpos($type, ' ')); - } - switch ($type) { - case 'int': - case 'float': - case 'double': - case 'char': - return trim($type); - case 'date': - case 'datetime': - return trim(strtolower($type)); - case 'varchar': - case 'text': - case 'blob': - return 'string'; - case 'bigint': - case 'tinyint': - case 'enum': - return 'int'; - default: - d($type); - } - } - protected function getTables() - { - $q = "SHOW TABLES"; - $st = $this->db->query($q); - $results = $st->fetchAll(\PDO::FETCH_COLUMN); - $this->tables = []; - foreach ($results as $result) { - $this->tables []= $result; - } - } - protected function getColumns($table) - { - $q = "SHOW COLUMNS FROM `" . $table . "`"; - $st = $this->db->query($q); - $results = $st->fetchAll(\PDO::FETCH_OBJ); - return $results; - } - protected function phpDoc($columns) - { - $str = ['/**']; - $str []= ' *'; - foreach ($columns as $column) { - $str []= ' * @property ' . $this->getType($column->Type) . ' ' . $column->Field; - } - $str []= ' *'; - $str []= ' */'; - - return implode(PHP_EOL, $str); - } - protected function className($table) - { - $name = Stringy::create($table)->upperCamelize(); - return $name; - } - protected function createClass($table) - { - $class = '' . $this->className($table); - $columns = $this->getColumns($table); - $docs = $this->phpDoc($columns); - - $output = ['name}';"; - $output []= '}'; - $output []= '?>'; - - //d(implode(PHP_EOL, $output)); - - $filename = realpath(root() . '/src') . DIRECTORY_SEPARATOR . $class . '.php'; - return file_put_contents($filename, implode(PHP_EOL, $output)); - } - public function create($namespace, $table) - { - $class = '' . $this->className($table); - $columns = $this->getColumns($table); - $docs = $this->phpDoc($columns); - - $namespace = trim($namespace, '\\'); - - $output = ['name}';"; - $output []= '}'; - $output []= '?>'; - $output = implode(PHP_EOL, $output); - - $namespace = explode('\\', $namespace); - array_shift($namespace); - $namespace = implode('/', $namespace); - - $filename = realpath(root() . '/src/' . $namespace) . DIRECTORY_SEPARATOR . $class . '.php'; - - $result = [ - 'result' => false, - 'filename' => $filename, - 'output' => $output - ]; - if (!file_exists($filename)) { - $result['result'] = file_put_contents($filename, $output); - } else { - $result['result'] = true; - } - return json_encode($result); - } - public function list() - { - $this->getTables(); - $output = []; - foreach ($this->tables as $table) { - $output []= ['table' => $table, 'model' => '' . $this->className($table)]; - } - - return json_encode(['models' => $output]); - } -} -?> \ No newline at end of file diff --git a/app/Service/Factory.php b/app/Service/Factory.php deleted file mode 100644 index ac7386a..0000000 --- a/app/Service/Factory.php +++ /dev/null @@ -1,204 +0,0 @@ -class = $class; - $this->is_aggregator = true; - if (is_subclass_of($class, 'Model')) { - $this->is_aggregator = false; - } - } - public function new() - { - $class = $this->class; - if ($this->is_aggregator) { - return new $class(); - } - return model($class)->create(); - } - public function create($data) - { - $class = $this->class; - if ($this->is_aggregator) { - $obj = new $class(); - $obj->create($data); - return $obj; - } - return model($class)->create($data); - } - /** - * [column => value, column => [value, operator]] - * @var array - */ - protected $conditions; - public function where(array $data) - { - if ($this->conditions == null) { - $this->conditions = $data; - return $this; - } - $this->conditions = array_merge($this->conditions, $data); - return $this; - } - /** - * [column, column => order] - * @var array - */ - protected $order; - public function order(array $data) - { - if ($this->order == null) { - $this->order = $data; - return $this; - } - $this->order = array_merge($this->order, $data); - return $this; - } - protected $limit; - public function limit(array $data) - { - if (!isset($data['limit'])) { - $data['limit'] = $data[0]; - } - if (!isset($data['offset'])) { - $data['offset'] = 0; - if (isset($data[1])) { - $data['offset'] = $data[1]; - } - } - $this->limit = (object) ['limit' => $data['limit'], 'offset' => $data['offset']]; - return $this; - } - protected $many; - public function find($many = false) - { - $this->many = $many; - if ($this->is_aggregator) { - return $this->findAggregator(); - } - return $this->findModel(); - } - - protected function findModel() - { - $objs = model($this->class); - $objs = $this->parseLimit($this->parseOrder($this->parseConditions($objs))); - - if ($this->many) { - return $objs->findMany(); - } - return $objs->findOne(); - } - protected function parseConditions($orm) - { - if ($this->conditions == null) { - return $orm; - } - foreach ($this->conditions as $column => $value) { - if (is_array($value)) { - list($value, $op) = $value; - switch ($op) { - case '>': - case 'gt': - $orm = $orm->whereGt($column, $value); - break; - } - } else { - $orm = $orm->where($column, $value); - } - } - return $orm; - } - protected function parseOrder($orm) - { - if ($this->order == null) { - return $orm; - } - foreach ($this->order as $column => $order) { - if (is_numeric($column)) { - $column = $order; - $order = 'asc'; - } - switch (strtolower($order)) { - case 'asc': - default: - $orm = $orm->orderByAsc($column); - break; - case 'desc': - $orm = $orm->orderByDesc($column); - break; - case 'expr': - $orm = $orm->orderByExpr($column); - break; - } - } - return $orm; - } - protected function parseLimit($orm) - { - if ($this->limit == null) { - return $orm; - } - $orm = $orm->limit($this->limit->limit); - if (isset($this->limit->offset)) { - $orm = $orm->offset($this->limit->offset); - } - return $orm; - } - protected function findAggregator() - { - $model = $this->modelName($this->class); - $ids = $this->getIds($model); - $class = $this->class; - if (count($ids) == 0) { - return false; - } - if ($this->many) { - $objs = []; - foreach ($ids as $id) { - $objs []= new $class($id); - } - } else { - $objs = new $class($ids[0]); - } - return $objs; - } - protected function getIds($model) - { - $id = $this->getModelId($model); - $table = $this->getTable($model); - $st = \ORM::forTable($table)->select($id); - $st = $this->parseConditions($st); - $results = $st->findArray(); - $output = array_map(function($a) use($id) { - return $a[$id]; - }, $results); - return $output; - } - protected function modelName($class) - { - $arr = explode("\\", $class); - \array_push($arr, end($arr)); - return implode("\\", $arr); - } - protected function getModelId($model) - { - $table = $this->getTable($model); - $query = "SHOW KEYS FROM {$table} WHERE Key_name = 'PRIMARY'"; - $st = \ORM::getDb()->query($query); - $results = $st->fetchAll(\PDO::FETCH_OBJ); - return $results[0]->Column_name; - } - protected function getTable($model) - { - $arr = explode("\\", $model); - return Stringy::create(end($arr))->toLowerCase() . ''; - } -} diff --git a/app/Service/Informador.php b/app/Service/Informador.php deleted file mode 100644 index c64db26..0000000 --- a/app/Service/Informador.php +++ /dev/null @@ -1,463 +0,0 @@ -title = $title; - } else { - $this->title = 'Informe'; - } - } - - public function addColumn(string $title, $col = '') - { - if ($col == '') { - if ($this->columns == null) { - $i = 0; - } else{ - $i = count($this->columns); - } - $col = $this->mapColumn($i); - } - - if (isset($this->columns[$col])) { - $columns = []; - foreach ($this->columns as $c => $data) { - if (ord($c) < ord($col)) { - $columns[$c] = $data; - } elseif (ord($c) == ord($col)) { - $columns[$col] = $title; - } else { - $columns[chr(ord($c) + 1)] = $data; - } - } - $this->columns = $columns; - } else { - $this->columns[$col] = $title; - } - } - public function mapColumn($n) - { - $letters = range('A', 'Z'); - $max = count($letters); - $r = $n / $max + 1; - $p = floor($r - 1) - 1; - $i = $n % $max; - if ($r >= 2) { - return $letters[$p] . $letters[$i]; - } - return $letters[$i]; - } - public function getColumn($col_title) - { - return array_search($col_title, $this->columns); - } - public function getColumnNumber($col) - { - $letters = range('A', 'Z'); - if (strlen($col) > 1) { - $ls = str_split($col); - $n = 0; - foreach ($ls as $i => $l) { - $n += array_search($l, $letters) + $i * count($letters) + 1; - } - return $n; - } - return array_search($col, $letters); - } - public function addColumns(array $columns) - { - foreach ($columns as $column) { - $this->addColumn($column); - } - } - public function addData(int $row, $data, $col = '') - { - if (!isset($this->data[$row])) { - $this->data[$row] = []; - } - if ($col == '') { - $i = count($this->data[$row]); - $col = $this->mapColumn($i); - } elseif (ctype_print($col)) { - $col = $this->getColumn($col); - } else { - $col = $this->mapColumn($col); - } - - if (isset($this->data[$row][$col])) { - $data_array = []; - foreach ($this->data[$row] as $c => $d) { - if (ord($c) < ord($col)) { - $data_array[$c] = $d; - } elseif (ord($c) == ord($col)) { - $data_array[$col] = $this->parseData($data); - } else { - $data_array[chr(ord($c) + 1)] = $d; - } - } - $this->data[$row] = $data_array; - } else { - $this->data[$row][$col] = $this->parseData($data); - } - } - protected function parseData($data) - { - if ($this->isDate($data)) { - // Date - return Date::PHPToExcel($data); - } - return $data; - } - protected function isDate($data) - { - try { - if (strpos($data, '-') === false) { - return false; - } - $fecha = explode('-', $data); - if (count($fecha) != 3) { - return false; - } - list($year, $month, $day) = $fecha; - if (strlen($year) == 4 and strlen($month) <= 2 and strlen($day) <= 2) { - return true; - } - if (ctype_digit($year) and ctype_digit($month) and ctype_digit($day)) { - $f = Carbon::parse($data, config('app.timezone')); - return true; - } - return false; - } catch(\Exception $e) { - return false; - } - return false; - } - public function addDataRow(int $row, array $data_array) - { - foreach ($data_array as $data) { - $this->addData($row, $data); - } - } - public function addDatas(array $data_matrix) - { - foreach ($data_matrix as $row => $data_array) { - $this->addDataRow($row, $data_array); - } - } - protected function findTitleColumn($title) - { - return array_search($title, $this->columns); - } - public function addFormat($format, $title = '') - { - $col = 'A'; - if ($title == '') { - $i = count($this->col_formats); - $col = $this->mapColumn($i); - } else { - $col = $this->findTitleColumn($title); - } - - if (isset($this->col_formats[$col])) { - $columns = []; - foreach ($this->col_formats as $c => $data) { - if (ord($c) < ord($col)) { - $columns[$c] = $data; - } elseif (ord($c) == ord($col)) { - $columns[$col] = $this->translateFormat($format); - } else { - $columns[chr(ord($c) + 1)] = $data; - } - } - $this->col_formats = $columns; - } else { - $this->col_formats[$col] = $this->translateFormat($format); - } - - uksort($this->col_formats, function($ak, $bk) { - return strcmp($ak, $bk); - }); - } - protected function translateFormat(array $format) - { - $translated = []; - foreach ($format as $category => $values) { - switch ($category) { - case 'numberFormat': - $data = $this->translateNumberFormat($values); - break; - case 'alignment': - $data = $this->translateAlignment($values); - break; - case 'font': - $data = $this->translateFont($values); - break; - case 'fill': - $data = $this->translateFill($values); - break; - case 'borders': - $data = $this->translateBorders($values); - break; - } - $translated[$category] = $data; - } - return $translated; - } - protected function translateNumberFormat(array $values) - { - $translated = []; - foreach ($values as $value) { - switch ($value) { - case 'short-date': - $translated['formatCode'] = 'dd-mm-yyyy'; - break; - case 'date': - $translated['formatCode'] = 'dd mmmm, yyyy'; - break; - case 'thousands': - $translated['formatCode'] = NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1; - break; - case 'pesos': - $translated['formatCode'] = '$ #.###'; - break; - default: - $translated['formatCode'] = $value; - } - } - return $translated; - } - protected function translateAlignment(array $values) - { - $translated = []; - foreach ($values as $type => $value) { - switch ($type) { - case 'horizontal': - switch ($value) { - case 'center': - $new = Alignment::HORIZONTAL_CENTER; - break; - } - break; - case 'vertical': - switch ($value) { - case 'middle': - case 'center': - $new = Alignment::VERTICAL_CENTER; - } - default: - $new = $value; - break; - } - $translated[$type] = $new; - } - return $translated; - } - protected function translateFont(array $values) - { - $translated = []; - foreach ($values as $type => $value) { - switch ($type) { - case 'color': - $new = $this->translateColor($value); - break; - default: - $new = $value; - break; - } - $translated[$type] = $new; - } - return $translated; - } - protected function translateFill(array $values) - { - $translated = []; - foreach ($values as $type => $value) { - switch ($type) { - case 'fillType': - switch ($value) { - case 'solid': - $new = Fill::FILL_SOLID; - break; - default: - $new = $value; - break; - } - break; - case 'color': - $new = $this->translateColor($value); - break; - default: - $new = $value; - break; - } - $translated[$type] = $new; - } - return $translated; - } - protected function translateBorders(array $values) - { - $translated = []; - foreach ($format as $category => $value) { - switch ($category) { - case 'allBorders': - case 'left': - case 'right': - case 'top': - case 'bottom': - case 'diagonal': - case 'vertical': - case 'horizontal': - $data = $this->translateBorder($value); - break; - default: - $data = $value; - } - $translated[$category] = $data; - } - return $translated; - } - protected function translateBorder(array $values) - { - $translated = []; - foreach ($values as $type => $value) { - switch ($type) { - case 'color': - $new = $this->translateColor($value); - break; - default: - $new = $value; - break; - } - $translated[$type] = $new; - } - return $translated; - } - protected function translateColor($color) - { - $color_definitions = [ - 'red' => 'ff0000', - 'light-red' => 'ffcccc', - 'dark-red' => 'a00000' - ]; - if (is_array($color)) { - $t = dechex(255 * $color['transparency'] / 100); - $c = $color_definitions[$color['color']]; - $hex = $t . $c; - return ['argb' => $hex]; - } - return ['rgb' => $color_definitions[$color]]; - } - public function addFormats(array $formats) - { - foreach ($formats as $title => $format) { - $this->addFormat($format, $title); - } - } - public function addTotal(string $col) - { - if (isset($this->columns[$col])) { - $sum = 0; - foreach ($this->data as $row => $data) { - $sum += $data[$col]; - } - $this->totals[$col] = $sum; - } - } - public function addAverage(string $col) - { - $this->addTotal($col); - $this->totals[$col] /= count($this->data); - } - - protected function fillData() - { - foreach ($this->data as $row => $data) { - $this->data[$row] = $this->fillAndSort($data); - } - if (count($this->totals) > 0) { - $this->totals = $this->fillAndSort($this->totals); - } - } - protected function fillAndSort(array $row) - { - foreach ($this->columns as $val) { - if (!isset($row[$val])) { - $row[$val] = ''; - } - } - function sortArrayByArray(Array $array, Array $orderArray) { - $ordered = array(); - foreach($orderArray as $key) { - if(array_key_exists($key, $array)) { - $ordered[$key] = $array[$key]; - unset($array[$key]); - } - } - return $ordered + $array; - } - $row = sortArrayByArray($row, $this->columns); - - return $row; - } - - public function informe() - { - $ea = new Spreadsheet(); - $ea->getProperties()->setCreator('Juan Pablo Vial B.'); - $ea->getProperties()->setTitle($this->title); - $ea->getProperties()->setCompany('Incoviba S.A.'); - - $ews = $ea->getActiveSheet(); - - $ews->fromArray(array($this->columns), '', 'A1'); - $ews->fromArray($this->data, '', 'A2'); - $end = 2; - if ($this->totals != null and count($this->totals) > 0) { - $ews->fromArray($this->totals, '', 'A' . count($data) + 2); - $end = 3; - } - - if ($this->col_formats != null and count($this->col_formats) > 0) { - foreach ($this->col_formats as $col => $format) { - $ews->getStyleByColumnAndRow($this->getColumnNumber($col), 2, $this->getColumnNumber($col), count($this->data) + $end)->applyFromArray($format); - } - } - - for ($col = 0; $col < count($this->columns); $col ++) { - $ews->getColumnDimensionByColumn($col)->setAutoSize(true); - } - - $ews->setAutoFilterByColumnAndRow(0, 1, count($this->columns) - 1, count($this->data)); - - $hoy = Carbon::now(config('app.timezone')); - $filename = str_replace('ñ', 'n', $this->title . ' - ' . $hoy->format('Y-m-d') . '.xlsx'); - - $writer = IOFactory::createWriter($ea, "Xlsx"); - - header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8"); - header('Content-Transfer-Encoding: binary'); - header('Content-Disposition: attachment; filename="' . $filename . '"'); - header('Cache-Control: max-age=0'); - - $writer->save('php://output'); - } -} -?> diff --git a/app/Service/Informe/Contabilidad/Resumen.php b/app/Service/Informe/Contabilidad/Resumen.php deleted file mode 100644 index e20266a..0000000 --- a/app/Service/Informe/Contabilidad/Resumen.php +++ /dev/null @@ -1,190 +0,0 @@ -separator = $separator; - } - - protected function getVentas($id_proyecto) - { - $proyecto = model(Proyecto::class)->findOne($id_proyecto); - $ventas = $proyecto->ventas(); - $output = []; - foreach ($ventas as $venta) { - $found = false; - foreach ($output as $v) { - if ($v->unidad()->descripcion == $venta->unidad()->descripcion) { - $found = true; - break; - } - } - if (!$found) { - $output []= $venta; - } - } - return $output; - } - protected function startOfYear(DateTimeInterface $up_to) - { - return new DateTimeImmutable((clone $up_to)->sub(new DateInterval('P1Y'))->format('31-12-Y')); - } - protected function defaultValueDate(DateTimeInterface $up_to, $glosa = '') - { - return (object) ['fecha' => $this->startOfYear($up_to), 'valor' => 0, 'glosa' => $glosa, 'estado' => '']; - } - protected function extractValueDate(Pago $pago, $glosa = '') - { - return (object) ['fecha' => $pago->fecha(), 'valor' => $pago->valor, 'glosa' => $glosa, 'estado' => $pago->estado()->tipo()->descripcion]; - } - protected function getAnticipos(Venta $venta, DateTimeInterface $up_to) - { - if ($venta->pie == 0) { - return [$this->defaultValueDate($up_to)]; - } - $cuotas = $venta->pie()->cuotas('fecha', $up_to); - $ly = $this->startOfYear($up_to); - $older = array_reduce($cuotas, function($sum, $item) use ($ly) { - if ($item->pago()->estado()->tipo()->active != 1 or strtolower($item->pago()->estado()->tipo()->descripcion) == 'no pagado') { - return $sum; - } - if ($item->pago()->fecha() >= $ly) { - return $sum; - } - return $sum + $item->pago()->valor; - }); - $current = array_filter($cuotas, function($item) use ($ly) { - return $item->pago()->fecha() >= $ly; - }); - foreach ($current as &$item) { - $item = $this->extractValueDate($item->pago(), "Cuota {$item->numero}"); - } - return array_merge([(object) ['fecha' => $ly, 'valor' => $older, 'glosa' => 'Anticipo acumulado', 'estado' => 'Pagado']], $current); - } - protected function getReajuste(Venta $venta, DateTimeInterface $up_to) - { - if ($venta->pie == 0 or $venta->pie()->reajuste == null) { - return $this->defaultValueDate($up_to, 'Reajuste'); - } - return $this->extractValueDate($venta->pie()->reajuste(), 'Reajuste'); - } - protected function getAbono(Venta $venta, DateTimeInterface $up_to) - { - if ($venta->escritura == 0) { - return $this->defaultValueDate($up_to, 'Abono'); - } - return $this->extractValueDate($venta->escritura()->pago(), 'Abono'); - } - protected function getBono(Venta $venta, DateTimeInterface $up_to) - { - if ($venta->bono_pie == 0) { - return $this->defaultValueDate($up_to, 'Bono Pie'); - } - return $this->extractValueDate($venta->bonoPie()->pago(), 'Bono Pie'); - } - protected function getCredito(Venta $venta, DateTimeInterface $up_to) - { - if ($venta->credito == 0) { - return $this->defaultValueDate($up_to, 'Credito'); - } - return $this->extractValueDate($venta->credito()->pago(), 'Credito'); - } - protected function getSubsidio(Venta $venta, DateTimeInterface $up_to) - { - if ($venta->subsidio == 0) { - return [$this->defaultValueDate($up_to, 'Ahorro'), $this->defaultValueDate($up_to, 'Subsidio')]; - } - return [$this->extractValueDate($venta->subsidio()->pago(), 'Ahorro'), $this->extractValueDate($venta->subsidio()->subsidio(), 'Subsidio')]; - } - protected function getResciliacion(Venta $venta, DateTimeInterface $up_to) - { - if ($venta->resciliacion == null) { - return $this->defaultValueDate($up_to, 'Resciliacion'); - } - return $this->extractValueDate($venta->resciliacion()->pago(), 'Resciliacion'); - } - protected function getPagos(Venta $venta, DateTimeInterface $up_to) - { - $pagos = []; - $pagos = array_merge($pagos, $this->getAnticipos($venta, $up_to)); - $pagos []= $this->getReajuste($venta, $up_to); - $pagos []= $this->getAbono($venta, $up_to); - $pagos []= $this->getBono($venta, $up_to); - $pagos []= $this->getCredito($venta, $up_to); - $pagos = array_merge($pagos, $this->getSubsidio($venta, $up_to)); - return array_filter($pagos, function($item) { - return $item->valor != 0; - }); - } - - protected function buildLine(Venta $venta, $pago) - { - if ($pago->valor > 0) { - return ['', $venta->unidad()->descripcion, $pago->fecha->format('d/m/Y'), $pago->glosa, '', $pago->valor, $pago->estado]; - } - return ['', $venta->unidad()->descripcion, $pago->fecha->format('d/m/Y'), $pago->glosa, -$pago->valor, '', $pago->estado]; - } - protected function buildLibro(Venta $venta, DateTimeInterface $up_to) - { - $pagos = $this->getPagos($venta, $up_to); - $output = [ - ['', "Cuenta: Anticipos Dpto {$venta->unidad()->descripcion}"], - ['', 'Fecha', 'Glosa', 'Haber', 'Debe', 'Estado'] - ]; - $debe = 0; - $haber = 0; - foreach ($pagos as $pago) { - $output []= $this->buildLine($venta, $pago); - if ($pago->valor > 0) { - $debe += $pago->valor; - } - else { - $haber -= $pago->valor; - } - } - $output []= ['', '', '', 'Total', $haber, $debe]; - return $output; - } - - public function build(int $id_proyecto, DateTimeInterface $up_to) - { - ini_set('max_execution_time', 60 * 60); - $ventas = $this->getVentas($id_proyecto); - - $output = ["Libro Mayor {$ventas[0]->proyecto()->descripcion}", '']; - foreach ($ventas as $venta) { - $output = array_merge($output, $this->buildLibro($venta, $up_to)); - } - - $filename = "Contabilidad - Resumen - {$ventas[0]->proyecto()->descripcion} - {$up_to->format('Y-m-d')}.xlsx"; - $informe = new Informe(); - $informe->createSpreadsheet() - ->addArray($output) - ->formatColumn('E') - ->formatColumn('F') - ->send($filename); - } -} diff --git a/app/Service/Informe/Informe.php b/app/Service/Informe/Informe.php deleted file mode 100644 index 8254a10..0000000 --- a/app/Service/Informe/Informe.php +++ /dev/null @@ -1,55 +0,0 @@ -spreadsheet = new Spreadsheet(); - return $this; - } - protected function formatArray(array $data) - { - $maxCols = 0; - foreach ($data as $row) { - if (!is_array($row)) { - continue; - } - if (count($row) > $maxCols) { - $maxCols = count($row); - } - } - foreach ($data as &$row) { - if (!is_array($row)) { - $row = [$row]; - } - if (count($row) < $maxCols) { - $row = array_merge($row, array_fill(0, $maxCols - count($row), '')); - } - } - return $data; - } - public function addArray(array $data, string $start = 'A1') - { - $this->spreadsheet->getActiveSheet()->fromArray($this->formatArray($data), null, $start); - return $this; - } - public function formatColumn(string $column) - { - $this->spreadsheet->getActiveSheet()->getStyle("{$column}:{$column}")->getNumberFormat()->setFormatCode('#,##0'); - return $this; - } - public function send(string $filename) - { - header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); - header("Content-Disposition: attachment;filename=\"{$filename}\""); - header('Cache-Control: max-age=0'); - - $writer = IOFactory::createWriter($this->spreadsheet, 'Xlsx'); - $writer->save('php://output'); - } -} diff --git a/app/Service/Money.php b/app/Service/Money.php deleted file mode 100644 index 2472e62..0000000 --- a/app/Service/Money.php +++ /dev/null @@ -1,55 +0,0 @@ -parseDate($date); - if (!$this->checkNextMonthValueCalculationByDate($date)) { - return $this->emptyResult(); - } - - $response = $this->client->get('api/uf/value/' . $date->format('Y-m-d')); - - if (!$this->isOk($response)) { - return $this->emptyResult(); - } - - $body = $response->getBody()->getContents(); - if (trim($response->getBody()) === '') { - return $this->emptyResult(); - } - return json_decode($body); - } - - protected function parseDate(string|DateTimeInterface $date): DateTimeInterface - { - if (is_string($date)) { - $date = Carbon::parse($date, config('app.timezone')); - } - return $date; - } - protected function checkNextMonthValueCalculationByDate(DateTimeInterface $date): bool - { - $next_m_9 = Carbon::today(config('app.timezone'))->copy()->endOfMonth()->addDays(9); - $date = Carbon::parse($date); - return $date->lessThan($next_m_9); - } - protected function isOk(ResponseInterface $response): bool - { - $statusCode = $response->getStatusCode(); - return $statusCode >= 200 and $statusCode < 300; - } - protected function emptyResult(): object - { - return (object) ['total' => 0]; - } -} diff --git a/app/Service/Register.php b/app/Service/Register.php deleted file mode 100644 index 03f96e0..0000000 --- a/app/Service/Register.php +++ /dev/null @@ -1,34 +0,0 @@ - $user, - 'action' => $action, - 'time' => Carbon::now(config('app.timezone'))->toDateTimeString()//->format('Y-m-d HH:mm:ss') - ]; - $registry = model(RModel::class) - ->where('user', $user) - ->where('action', $action) - ->where('time', $data['time']) - ->findOne(); - if (!$registry) { - $registry = model(RModel::class)->create($data); - $registry->save(); - } - foreach ($variables as $data) { - $data['registry'] = $registry->id; - $log = (new Factory(RegistryData::class))->where($data)->find(); - if (!$log) { - $log = model(RegistryData::class)->create($data); - $log->save(); - } - } - } -} diff --git a/app/Service/Remote.php b/app/Service/Remote.php deleted file mode 100644 index 2e6e69e..0000000 --- a/app/Service/Remote.php +++ /dev/null @@ -1,19 +0,0 @@ -connection->connect(); - $statement = $connection->query($query); - $result = $statement->fetch(PDO::FETCH_ASSOC); - return $result['ip']; - } -} diff --git a/app/Service/Replacer.php b/app/Service/Replacer.php deleted file mode 100644 index bf61513..0000000 --- a/app/Service/Replacer.php +++ /dev/null @@ -1,127 +0,0 @@ -parseLine($line); - - $output = $line; - foreach ($instructions as $instruction) { - $output = str_replace($instruction['original'], $this->buildLine($instruction['instruction'], $data), $output); - } - return $output; - } - protected function parseLine($line) - { - $ini_el = '[['; - $end_el = ']]'; - - $instructions = []; - $offset = 0; - while (strpos($line, $ini_el, $offset) !== false) { - $ini = strpos($line, $ini_el, $offset) + strlen($ini_el); - $end = strpos($line, $end_el, $offset); - $find = substr($line, $ini, $end - $ini); - $instructions []= ['original' => $ini_el . $find . $end_el, 'instruction' => $find]; - $offset = $end + 1; - } - return $instructions; - } - protected function buildLine($instructions, $data) - { - if (strpos($instructions, '|') !== false) { - $instructions = explode('|', $instructions); - } else { - $instructions = [$instructions]; - } - $output = ''; - foreach ($instructions as $instruction) { - $output = $this->buildReplace($instruction, $data, $output); - } - return $output; - } - protected function buildReplace($instruction, $data, $output = null) - { - if (strpos($instruction, '(') !== false) { - $ini = strpos($instruction, '(') + 1; - $end = strpos($instruction, ')'); - $mod = substr($instruction, $ini, $end - $ini); - $instruction = substr($instruction, 0, $ini - 1); - } - switch ($instruction) { - case 'UPPER': - return strtoupper($output); - case 'LOWER': - return strtolower($output); - case 'ISSET': - if ($output != '') { - return ', ' . $output; - } - return ''; - case 'UFS': - return format('ufs', $output); - case 'PESOS': - return format('pesos', $output); - } - - if (isset($mod)) { - $obj = $this->find($instruction . '(' . $mod .')', $data); - } else { - $obj = $this->find($instruction, $data); - } - if ($obj) { - return $obj; - } - if (is_object($output) and method_exists($output, $instruction)) { - if (isset($mod)) { - return $output->$instruction($mod); - } - return $output->$instruction(); - } - if (is_object($output) and isset($output->$instruction)) { - return $output->$instruction; - } - if ($instruction == 'strftime') { - setlocale(LC_TIME, 'es-CL', 'es'); - $f = Carbon::parse($output, config('app.timezone')); - $output = strftime($mod, $f->timestamp); - return $output; - } - - d($output, $instruction, function_exists($instruction), is_object($output), is_object($output) and isset($output->$instruction)); - } - protected function find($instruction, $data) - { - if (strpos($instruction, '(') !== false) { - $ini = strpos($instruction, '(') + 1; - $end = strpos($instruction, ')'); - $mod = substr($instruction, $ini, $end - $ini); - $instruction = substr($instruction, 0, $ini - 1); - } - if (method_exists($data, $instruction)) { - if (isset($mod)) { - return $data->$instruction($mod); - } - return $data->$instruction(); - } - if (isset($data->$instruction)) { - return $data->$instruction; - } - switch ($instruction) { - case 'Unidades': - $str = 'Departamento ' . $data->reserva()->unidad()->numeracion; - foreach ($data->reserva()->unidades() as $unidad) { - $str .= ', ' . ucwords($unidad->unidadProyecto()->tipo()->descripcion) . ' ' . $unidad->numeracion; - } - return $str; - case 'inmobiliaria': - return $data->proyecto()->inmobiliaria(); - } - return false; - } -} -?> \ No newline at end of file diff --git a/app/Service/Route.php b/app/Service/Route.php deleted file mode 100644 index f910f87..0000000 --- a/app/Service/Route.php +++ /dev/null @@ -1,131 +0,0 @@ -add($t, $query, $callback); - } - } else { - switch (strtoupper($type)) { - case 'GET': - $this->get($query, $callback); - break; - case 'POST': - $this->post($query, $callback); - break; - } - } - } - public function get($query, $callback) - { - if ($this->exists('get', $query)) { - return; - } - $this->routes['get'][$query] = (object) ['query' => $query, 'callback' => $this->parseCallback($callback)]; - } - public function post($query, $callback) - { - if ($this->exists('post', $query)) { - return; - } - $this->routes['post'][$query] = (object) ['query' => $query, 'callback' => $this->parseCallback($callback)]; - } - protected function exists($type, $query) - { - return isset($this->routes['post'][$query]); - } - protected function parseCallback($callback) - { - if (is_callable($callback)) { - return $callback; - } - elseif (is_object($callback)) { - return [$callback, 'index']; - } - elseif (is_string($callback) and strpos($callback, '@') !== false) { - list($class, $method) = explode('@', $callback); - $class = '\\App\\Controller\\' . $class; - if (method_exists($class, $method)) { - return [$class, $method]; - } - } - elseif (is_string($callback)) { - $class = '\\App\\Controller\\' . $callback; - return [$class, 'index']; - } - } - public function route() - { - $url = $_SERVER['SCRIPT_NAME']; - $query = $_SERVER['QUERY_STRING']; - $method = $_SERVER['REQUEST_METHOD']; - $route = null; - switch (strtoupper($method)) { - case 'GET': - $route = $this->getGet($url, $query); - break; - case 'POST': - $route = $this->getPost($url, $query); - break; - } - if ($route) { - return $this->run($route->callback); - } - return false; - } - protected function getGet($url, $query) - { - if (isset($this->routes['get'][$url])) { - return $this->routes['get'][$url]; - } - $p = get('p'); - if ($p == null) { - $p = get('page'); - if ($p == null) { - $p = get('m'); - if ($p == null) { - $p = get('module'); - } - } - } - if (isset($this->routes['get'][$p])) { - return $this->routes['get'][$p]; - } - return false; - } - protected function getPost($url, $query) - { - if (isset($this->routes['post'][$url])) { - return $this->routes['post'][$url]; - } - $p = get('p'); - if ($p == null) { - $p = get('page'); - if ($p == null) { - $p = get('m'); - if ($p == null) { - $p = get('module'); - } - } - } - if (isset($this->routes['post'][$p])) { - return $this->routes['post'][$p]; - } - return false; - } - protected function run($callback) - { - return call_user_func($callback); - } -} -?> \ No newline at end of file diff --git a/bin/Pipfile b/bin/Pipfile deleted file mode 100644 index 8108982..0000000 --- a/bin/Pipfile +++ /dev/null @@ -1,12 +0,0 @@ -[[source]] -name = "pypi" -url = "https://pypi.org/simple" -verify_ssl = true - -[dev-packages] - -[packages] -gunicorn = "*" - -[requires] -python_version = "3.8" diff --git a/bin/console b/bin/console deleted file mode 100644 index 11aaaef..0000000 --- a/bin/console +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -php /code/bin/index.php "$@" diff --git a/bin/index.php b/bin/index.php deleted file mode 100644 index f5683c7..0000000 --- a/bin/index.php +++ /dev/null @@ -1,8 +0,0 @@ -run(); diff --git a/bin/informes/Pipfile b/bin/informes/Pipfile deleted file mode 100644 index e8687af..0000000 --- a/bin/informes/Pipfile +++ /dev/null @@ -1,16 +0,0 @@ -[[source]] -name = "pypi" -url = "https://pypi.org/simple" -verify_ssl = true - -[dev-packages] - -[packages] -pandas = "*" -xlsxwriter = "*" -httpx = "*" -flask = "*" -numpy = "*" - -[requires] -python_version = "3.8" diff --git a/bin/informes/app.py b/bin/informes/app.py deleted file mode 100644 index ff2a8f0..0000000 --- a/bin/informes/app.py +++ /dev/null @@ -1,14 +0,0 @@ -import argparse -from flask import Flask -from controllers.ventas import ventas_blueprint - - -app = Flask(__name__) -app.register_blueprint(ventas_blueprint, url_prefix='/ventas') - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('-p', '--port', default=8011) - args = parser.parse_args() - app.run(port=args.port, debug=True) diff --git a/bin/informes/controllers/ventas.py b/bin/informes/controllers/ventas.py deleted file mode 100644 index ab3ffce..0000000 --- a/bin/informes/controllers/ventas.py +++ /dev/null @@ -1,141 +0,0 @@ -from flask import Blueprint, request, Response -import io -import json -import pandas as pd -import numpy as np -import datetime - - -ventas_blueprint = Blueprint('ventas', __name__,) - - -def format_data(data): - df = pd.DataFrame(data) - int_columns = ['Departamento', 'Estacionamientos', 'Bodegas'] - for col in int_columns: - df[col] = pd.to_numeric(df[col], errors='ignore') - float_columns = ['Valor Promesa', 'Pie', 'Pie Pagado', '% Pie Pagado', 'Bono Pie', 'Valor Operador', - 'Premios', 'Subsidio', 'Ahorro', 'Credito', 'Valor Ests & Bods', 'Valor Neto', - 'UF/m²*', 'Comision', 'Venta s/Comision', 'Precio'] - for col in float_columns: - if col in df.columns: - df[col] = pd.to_numeric(df[col], errors='coerce') - df = df.replace(np.nan, 0, regex=True) - - df['Fecha Venta'] = pd.to_datetime(df['Fecha Venta'], format='%Y-%m-%d') - df = df.sort_values(by=['Fecha Venta', 'Departamento']) - df['Fecha Venta'] = df['Fecha Venta'].dt.strftime('%d.%m.%Y') - - return df - - -def format_columns(workbook, columns): - column_settings = [{'header': column} for column in columns] - - center_format = workbook.add_format({'align': 'center'}) - amount_format = workbook.add_format({'num_format': '#,##0.00'}) - percent_format = workbook.add_format({'num_format': '0.00%'}) - - amount_columns = ['m² Ponderados', 'Valor Promesa', 'Pie', 'Pie Pagado', 'Bono Pie', 'Valor Operador', 'Premios', - 'Subsidio', 'Ahorro', 'Credito', 'Valor Ests & Bods', 'Valor Neto', 'UF/m²*', 'Comision', - 'Venta s/Comision', 'Precio'] - center_columns = ['Departamento', 'Estacionamientos', 'Bodegas'] - sum_columns = ['m² Ponderados', 'Valor Promesa', 'Pie', 'Pie Pagado', 'Bono Pie', 'Subsidio', 'Ahorro', 'Credito', - 'Valor Operador', 'Premios', 'Valor Ests & Bods', 'Valor Neto', 'Comision'] - count_columns = ['Departamento', 'Estacionamientos', 'Bodegas'] - - for (k, col) in enumerate(column_settings): - if col['header'] in amount_columns: - column_settings[k]['format'] = amount_format - if col['header'] in center_columns: - column_settings[k]['format'] = center_format - if col['header'] in sum_columns: - column_settings[k]['total_function'] = 'sum' - if col['header'] in count_columns: - column_settings[k]['total_function'] = 'count' - if col['header'] == '% Pie Pagado': - column_settings[k]['format'] = percent_format - if col['header'] == 'Propietario': - column_settings[k]['total_string'] = 'TOTAL' - - return column_settings - - -def format_excel(workbook, worksheet, data): - center_format = workbook.add_format({'align': 'center'}) - amount_format = workbook.add_format({'num_format': '#,##0.00'}) - percent_format = workbook.add_format({'num_format': '0.00%'}) - - amount_columns = ['m² Ponderados', 'Valor Promesa', 'Pie', 'Pie Pagado', 'Bono Pie', 'Valor Operador', 'Premios', - 'Subsidio', 'Ahorro', 'Credito', 'Valor Ests & Bods', 'Valor Neto', 'UF/m²*', 'Comision', - 'Venta s/Comision', 'Precio'] - center_columns = ['Departamento', 'Estacionamientos', 'Bodegas'] - - for col in amount_columns: - if col not in data.columns: - continue - k = data.columns.get_loc(col) + 1 - worksheet.set_column(k, k, cell_format=amount_format) - for col in center_columns: - if col not in data.columns: - continue - k = data.columns.get_loc(col) + 1 - worksheet.set_column(k, k, cell_format=center_format) - col = '% Pie Pagado' - k = data.columns.get_loc(col) + 1 - worksheet.set_column(k, k, cell_format=percent_format) - - return worksheet - - -@ventas_blueprint.route('', methods=['POST']) -def ventas(): - data = json.loads(request.data) - output = io.BytesIO() - writer = pd.ExcelWriter('tmp.xlsx', engine='xlsxwriter') - df = format_data(data['data']) - - start_row = 4 - if 'Compañía' in data: - start_row += 1 - df.to_excel(writer, startrow=start_row+1, startcol=1, header=False, index=False, sheet_name='Ventas') - wb = writer.book - wb.filename = output - - title_format = wb.add_format({'font_size': 16, 'bold': True}) - ws = writer.sheets['Ventas'] - (max_row, max_col) = df.shape - - if 'Compañía' in data: - ws.merge_range(1, 1, 1, max_col, data['Compañía']) - ws.merge_range(start_row-3, 1, start_row-3, max_col, data['Proyecto'], cell_format=title_format) - ws.write_string(start_row-2, 1, 'Ventas') - column_settings = format_columns(wb, df.columns) - ws.add_table(start_row, 1, max_row+start_row+1, max_col, {'name': 'Ventas', 'total_row': 1, - 'columns': column_settings, - 'style': 'Table Style Medium 1'}) - ws = format_excel(wb, ws, df) - - column_widths = { - 'B': 46, - 'C': 16, - 'D': 18, - 'E': 10, - 'F': 13, - 'G': 7, - 'H': 8, - 'I': 16, - 'J': 16, - 'K': 13, - 'L': 14 - } - for (col, wd) in column_widths.items(): - ws.set_column('{0}:{0}'.format(col), wd) - - writer.save() - output.seek(0) - date = datetime.date.today() - filename = "Informe de Ventas - {0} - {1}.xlsx".format(data['Proyecto'], date.strftime('%Y-%m-%d')) - return Response(output, mimetype="application/ms-excel", - headers={"Content-Disposition": "attachment;filename={0}".format(filename), - "Content-Type": 'application/octet-stream; charset=utf-8'}) diff --git a/bootstrap/autoload.php b/bootstrap/autoload.php deleted file mode 100644 index 318f80d..0000000 --- a/bootstrap/autoload.php +++ /dev/null @@ -1,8 +0,0 @@ - diff --git a/bootstrap/database.php b/bootstrap/database.php deleted file mode 100644 index 4372bf2..0000000 --- a/bootstrap/database.php +++ /dev/null @@ -1,29 +0,0 @@ - $data) { - load($data, $name); -} - -function load($data, $name = '') { - if (!isset($data['port'])) { - $port = 3306; - } else { - $port = $data['port']; - } - $dsn = 'mysql:host=' . $data['host'] . ';port=' . $port . ';dbname=' . $data['database'] . ';charset=utf8'; - - if ($name != '') { - ORM::configure($dsn, null, $name); - ORM::configure('username', $data['username'], $name); - ORM::configure('password', $data['password'], $name); - } else { - ORM::configure($dsn, null); - ORM::configure('username', $data['username']); - ORM::configure('password', $data['password']); - } -} - -Model::$short_table_names = true; diff --git a/bootstrap/dotenv.php b/bootstrap/dotenv.php deleted file mode 100644 index 799a5b1..0000000 --- a/bootstrap/dotenv.php +++ /dev/null @@ -1,12 +0,0 @@ -isDir() or $file->getExtension() != 'env') { - continue; - } - $env = Dotenv::createImmutable($file->getPath(), $file->getBasename()); - $env->load(); -} diff --git a/bootstrap/errors.php b/bootstrap/errors.php deleted file mode 100644 index 0e54dc4..0000000 --- a/bootstrap/errors.php +++ /dev/null @@ -1,7 +0,0 @@ -pushHandler(new \Whoops\Handler\PrettyPageHandler); - $whoops->register(); -}*/ -?> diff --git a/bootstrap/logs.php b/bootstrap/logs.php deleted file mode 100644 index 249be53..0000000 --- a/bootstrap/logs.php +++ /dev/null @@ -1,26 +0,0 @@ -underscored(); - Route::add(['GET', 'POST'], $route, $name); -} - -Route::add(['GET', 'POST'], 'buscar', 'Buscar'); -?> \ No newline at end of file diff --git a/composer.json b/composer.json deleted file mode 100644 index 55f9f15..0000000 --- a/composer.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "name" : "aldarien/incoviba", - "description" : "Intranet portal for Incoviba", - "type" : "project", - "require" : { - "aldarien/asset": "*", - "aldarien/config": "*", - "aldarien/format": "*", - "aldarien/response": "*", - "aldarien/session": "*", - "aldarien/url": "*", - "aldarien/view": "*", - "guzzlehttp/guzzle": "*", - "incoviba/modelos": "*", - "j4mie/paris": "^1.5", - "monolog/monolog": "^3", - "nesbot/carbon": "^2", - "nyholm/psr7": "*", - "nyholm/psr7-server": "*", - "php-di/php-di": "*", - "php-di/slim-bridge": "*", - "phpoffice/phpspreadsheet": "^1", - "phpoffice/phpword": "^0", - "rubellum/slim-blade-view": "*", - "slam/php-excel": "^4.4", - "slim/slim": "^4", - "symfony/console": "6.4.x-dev", - "vlucas/phpdotenv": "^5.3", - "voku/stringy": "^6" - }, - "require-dev" : { - "phpunit/phpunit" : "*", - "kint-php/kint" : "*", - "filp/whoops" : "*" - }, - "license" : "GNU AGPLv3", - "authors" : [{ - "name" : "Aldarien", - "email" : "jpvial@gmail.com" - } - ], - "autoload" : { - "psr-4" : { - "App\\" : "app/", - "ProVM\\Common\\": "provm/common/" - }, - "files" : [ - "app/Helper/functions.php" - ] - }, - "minimum-stability": "dev", - "repositories": [ - { - "type": "path", - "url": "./aldarien/**", - "options": { - "symlink": true - } - }, - { - "type": "path", - "url": "./incoviba/modelos" - } - ], - "config": { - "sort-packages": true - } -} diff --git a/config/app.php b/config/app.php deleted file mode 100644 index 4db5c28..0000000 --- a/config/app.php +++ /dev/null @@ -1,9 +0,0 @@ - 'America/Santiago', - 'locale' => 'es', - 'database' => 'mysql', - 'debug' => false, - 'benchmark' => false, - 'login_hours' => 5*24 -]; diff --git a/config/databases.php b/config/databases.php deleted file mode 100644 index 14e279f..0000000 --- a/config/databases.php +++ /dev/null @@ -1,24 +0,0 @@ - [ - 'host' => $_ENV['MYSQL_HOST'], - 'database' => $_ENV['MYSQL_DATABASE'], - 'username' => $_ENV['MYSQL_USER'], - 'password' => $_ENV['MYSQL_PASSWORD'] - ], - 'mysql_copy' => [ - 'host' => 'localhost', - 'database' => 'incoviba3', - 'username' => 'incoviba', - 'password' => $_ENV['MYSQL_PASSWORD'] - ] - ]; - if (isset($_ENV['MYSQL_PORT'])) { - $arr['mysql']['port'] = $_ENV['MYSQL_PORT']; - } - return $arr; -} -return buildDatabaseConfig(); diff --git a/config/incoviba.php b/config/incoviba.php deleted file mode 100644 index d21d9e8..0000000 --- a/config/incoviba.php +++ /dev/null @@ -1,6 +0,0 @@ - [ - 'caducidad' => 30 - ] -]; diff --git a/config/locations.php b/config/locations.php deleted file mode 100644 index 05442b6..0000000 --- a/config/locations.php +++ /dev/null @@ -1,16 +0,0 @@ - root(), - 'cache' => '{locations.base}/cache', - 'public' => '{locations.base}/public', - 'resources' => '{locations.base}/resources', - 'views' => '{locations.resources}/views', - 'src' => '{locations.base}/src', - //'languages' => '{locations.resources}/languages' - 'app' => '{locations.base}/app', - 'controllers' => '{locations.app}/Controller', - 'money' => 'provm.cl/optimus/money', - 'api' => '192.168.1.100/intranet/api', - 'api_url' => '/api' -]; -?> diff --git a/fontify.json b/fontify.json deleted file mode 100644 index 923703c..0000000 --- a/fontify.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "modules": [ - "bootstrap", - "font-awesome" - ], - "dest": "public" -} \ No newline at end of file From d9d5a15376816dc920289ef0860536b79851a58b Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Mon, 24 Jul 2023 20:54:30 -0400 Subject: [PATCH 004/163] Docker --- .env.sample | 3 +++ Dockerfile | 2 ++ docker-compose.yml | 25 ++++++++++++++----------- nginx.conf | 7 ++----- 4 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..ea98faf --- /dev/null +++ b/.env.sample @@ -0,0 +1,3 @@ +COMPOSE_PROFILES=app,db +APP_PATH=./app +APP_PORT=8080 diff --git a/Dockerfile b/Dockerfile index 509141c..2b3b2ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,8 @@ RUN docker-php-ext-install pdo pdo_mysql zip intl gd bcmath RUN pecl install xdebug-3.1.3 \ && docker-php-ext-enable xdebug +COPY ./php-errors.ini /usr/local/etc/php/conf.d/docker-php-errors.ini + COPY --from=composer /usr/bin/composer /usr/bin/composer WORKDIR /code diff --git a/docker-compose.yml b/docker-compose.yml index 4052376..58ae7bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,10 +11,11 @@ services: container_name: incoviba_web <<: *restart ports: - - "8080:80" + - "${APP_PORT}:80" volumes: - - .:/code + - ${APP_PATH:-.}/:/code - ./nginx.conf:/etc/nginx/conf.d/default.conf + - ./logs/proxy:/logs php: profiles: @@ -23,13 +24,12 @@ services: container_name: incoviba_php <<: *restart env_file: - - .env - - .db.env - - .remote.env + - ${APP_PATH:-.}/.env + - ${APP_PATH:-.}/.db.env + #- ${APP_PATH:-.}/.remote.env volumes: - - .:/code - - ./php-errors.ini:/usr/local/etc/php/conf.d/docker-php-errors.ini - - ./logs:/logs + - ${APP_PATH:-.}/:/code + - ./logs/php:/logs db: profiles: @@ -37,9 +37,10 @@ services: image: mariadb:latest container_name: incoviba_db <<: *restart - env_file: .db.env + env_file: ${APP_PATH:-.}/.db.env volumes: - dbdata:/var/lib/mysql + - ./incoviba.sql.gz:/docker-entrypoint-initdb.d/incoviba.sql.gz networks: - default - adminer_network @@ -50,9 +51,11 @@ services: image: adminer:latest container_name: incoviba_adminer <<: *restart + env_file: ${APP_PATH:-.}/.adminer.env + networks: + - adminer_network ports: - "8083:8080" - env_file: .adminer.env python: profiles: @@ -80,7 +83,7 @@ services: - "8084:80" volumes: - dbdata: + dbdata: {} networks: adminer_network: {} diff --git a/nginx.conf b/nginx.conf index 42bb089..dfbee25 100644 --- a/nginx.conf +++ b/nginx.conf @@ -2,13 +2,10 @@ server { listen 80; server_name web; index index.php; - error_log /code/logs/error.log; - access_log /code/logs/access.log; + error_log /logs/error.log; + access_log /logs/access.log; root /code/public; - location /api { - try_files $uri /api/index.php$is_args$args; - } location / { try_files $uri /index.php$is_args$args; } From 1a7b10ce3c999f7654004d5fc8c87e293b7c4168 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Mon, 24 Jul 2023 20:55:26 -0400 Subject: [PATCH 005/163] Auth, Login, Home, Venta->Listados->Precios --- app/common/Alias/View.php | 9 + app/common/Define/Connection.php | 14 + app/common/Define/Database.php | 8 + app/common/Define/Model.php | 8 + app/common/Define/Repository.php | 11 + app/common/Ideal/Model.php | 16 + app/common/Ideal/Repository.php | 126 ++++ app/common/Implement/Connection.php | 61 ++ app/common/Implement/Database/MySQL.php | 24 + .../Implement/Exception/EmptyResult.php | 15 + app/composer.json | 31 + app/public/assets/images/Isotipo 16.png | Bin 0 -> 3552 bytes app/public/assets/images/Isotipo 32.png | Bin 0 -> 4572 bytes app/public/assets/images/Isotipo 64.png | Bin 0 -> 6361 bytes app/public/assets/images/logo_cabezal.png | Bin 0 -> 23004 bytes app/public/index.php | 7 + app/public/robots.txt | 2 + app/resources/routes/01_api.php | 13 + app/resources/routes/03_proyectos.php | 6 + app/resources/routes/04_ventas.php | 10 + app/resources/routes/98_login.php | 8 + app/resources/routes/99_base.php | 4 + app/resources/routes/api/proyectos.php | 6 + app/resources/routes/api/ventas.php | 13 + app/resources/routes/api/ventas/precios.php | 6 + app/resources/routes/ventas/cuotas.php | 9 + app/resources/routes/ventas/precios.php | 6 + app/resources/views/guest.blade.php | 7 + app/resources/views/home.blade.php | 26 + .../views/home/cierres_vigentes.blade.php | 24 + .../views/home/cuotas_por_vencer.blade.php | 22 + app/resources/views/layout/base.blade.php | 5 + app/resources/views/layout/body.blade.php | 5 + .../views/layout/body/footer.blade.php | 4 + .../views/layout/body/header.blade.php | 7 + .../views/layout/body/header/menu.blade.php | 17 + .../body/header/menu/contabilidad.blade.php | 8 + .../layout/body/header/menu/guest.blade.php | 1 + .../body/header/menu/herramientas.blade.php | 7 + .../body/header/menu/inmobiliarias.blade.php | 1 + .../body/header/menu/operadores.blade.php | 9 + .../body/header/menu/proyectos.blade.php | 8 + .../layout/body/header/menu/search.blade.php | 1 + .../layout/body/header/menu/user.blade.php | 31 + .../layout/body/header/menu/ventas.blade.php | 41 ++ .../views/layout/body/scripts.blade.php | 4 + .../layout/body/scripts/datatables.blade.php | 4 + app/resources/views/layout/head.blade.php | 10 + .../views/layout/head/styles.blade.php | 3 + .../layout/head/styles/datatables.blade.php | 3 + app/resources/views/login/form.blade.php | 60 ++ .../views/ventas/cuotas/pendientes.blade.php | 108 +++ .../views/ventas/precios/list.blade.php | 676 ++++++++++++++++++ app/setup/app.php | 45 ++ app/setup/composer.php | 6 + app/setup/middlewares/01_auth.php | 2 + app/setup/middlewares/98_logs.php | 2 + app/setup/middlewares/99_routes.php | 12 + app/setup/settings/env.php | 2 + app/setup/settings/folders.php | 12 + app/setup/settings/urls.php | 21 + app/setup/setups/database.php | 18 + app/setup/setups/logs.php | 32 + app/setup/setups/middlewares.php | 15 + app/setup/setups/services.php | 14 + app/setup/setups/views.php | 23 + app/src/Controller/Base.php | 90 +++ app/src/Controller/Login.php | 55 ++ app/src/Controller/Proyectos.php | 21 + app/src/Controller/Users.php | 11 + app/src/Controller/Ventas/Cuotas.php | 60 ++ app/src/Controller/Ventas/Precios.php | 24 + app/src/Middleware/Authentication.php | 48 ++ app/src/Model/Banco.php | 16 + app/src/Model/Comuna.php | 18 + app/src/Model/Direccion.php | 22 + app/src/Model/Inmobiliaria.php | 38 + app/src/Model/Inmobiliaria/TipoSociedad.php | 16 + app/src/Model/Login.php | 25 + app/src/Model/Provincia.php | 18 + app/src/Model/Proyecto.php | 32 + app/src/Model/Proyecto/ProyectoTipoUnidad.php | 42 ++ app/src/Model/Proyecto/Superficie.php | 8 + app/src/Model/Proyecto/Terreno.php | 8 + app/src/Model/Region.php | 20 + app/src/Model/Role.php | 7 + app/src/Model/Tipo.php | 16 + app/src/Model/User.php | 28 + app/src/Model/Venta/Cierre.php | 26 + app/src/Model/Venta/Cuota.php | 38 + app/src/Model/Venta/Datos.php | 27 + app/src/Model/Venta/EstadoPago.php | 22 + app/src/Model/Venta/EstadoPrecio.php | 21 + app/src/Model/Venta/Pago.php | 32 + app/src/Model/Venta/Pie.php | 27 + app/src/Model/Venta/Precio.php | 23 + app/src/Model/Venta/Propietario.php | 46 ++ app/src/Model/Venta/TipoEstadoPago.php | 8 + app/src/Model/Venta/TipoEstadoPrecio.php | 7 + app/src/Model/Venta/TipoPago.php | 8 + app/src/Model/Venta/TipoUnidad.php | 16 + app/src/Model/Venta/Unidad.php | 25 + app/src/Repository/Banco.php | 35 + app/src/Repository/Comuna.php | 51 ++ app/src/Repository/Direccion.php | 48 ++ app/src/Repository/Inmobiliaria.php | 55 ++ .../Repository/Inmobiliaria/TipoSociedad.php | 36 + app/src/Repository/Login.php | 77 ++ app/src/Repository/Provincia.php | 51 ++ app/src/Repository/Proyecto.php | 88 +++ .../Proyecto/ProyectoTipoUnidad.php | 54 ++ app/src/Repository/Region.php | 53 ++ app/src/Repository/User.php | 46 ++ app/src/Repository/Venta/Cierre.php | 82 +++ app/src/Repository/Venta/Cuota.php | 161 +++++ app/src/Repository/Venta/EstadoPago.php | 67 ++ app/src/Repository/Venta/EstadoPrecio.php | 65 ++ app/src/Repository/Venta/Pago.php | 73 ++ app/src/Repository/Venta/Pie.php | 60 ++ app/src/Repository/Venta/Precio.php | 55 ++ app/src/Repository/Venta/Propietario.php | 82 +++ app/src/Repository/Venta/TipoEstadoPago.php | 40 ++ app/src/Repository/Venta/TipoEstadoPrecio.php | 35 + app/src/Repository/Venta/TipoPago.php | 35 + app/src/Repository/Venta/TipoUnidad.php | 39 + app/src/Repository/Venta/Unidad.php | 47 ++ app/src/Service/Format.php | 24 + app/src/Service/Login.php | 135 ++++ app/src/Service/Ventas/Pago.php | 31 + app/src/Service/Ventas/Precio.php | 19 + 130 files changed, 4302 insertions(+) create mode 100644 app/common/Alias/View.php create mode 100644 app/common/Define/Connection.php create mode 100644 app/common/Define/Database.php create mode 100644 app/common/Define/Model.php create mode 100644 app/common/Define/Repository.php create mode 100644 app/common/Ideal/Model.php create mode 100644 app/common/Ideal/Repository.php create mode 100644 app/common/Implement/Connection.php create mode 100644 app/common/Implement/Database/MySQL.php create mode 100644 app/common/Implement/Exception/EmptyResult.php create mode 100644 app/composer.json create mode 100644 app/public/assets/images/Isotipo 16.png create mode 100644 app/public/assets/images/Isotipo 32.png create mode 100644 app/public/assets/images/Isotipo 64.png create mode 100644 app/public/assets/images/logo_cabezal.png create mode 100644 app/public/index.php create mode 100644 app/public/robots.txt create mode 100644 app/resources/routes/01_api.php create mode 100644 app/resources/routes/03_proyectos.php create mode 100644 app/resources/routes/04_ventas.php create mode 100644 app/resources/routes/98_login.php create mode 100644 app/resources/routes/99_base.php create mode 100644 app/resources/routes/api/proyectos.php create mode 100644 app/resources/routes/api/ventas.php create mode 100644 app/resources/routes/api/ventas/precios.php create mode 100644 app/resources/routes/ventas/cuotas.php create mode 100644 app/resources/routes/ventas/precios.php create mode 100644 app/resources/views/guest.blade.php create mode 100644 app/resources/views/home.blade.php create mode 100644 app/resources/views/home/cierres_vigentes.blade.php create mode 100644 app/resources/views/home/cuotas_por_vencer.blade.php create mode 100644 app/resources/views/layout/base.blade.php create mode 100644 app/resources/views/layout/body.blade.php create mode 100644 app/resources/views/layout/body/footer.blade.php create mode 100644 app/resources/views/layout/body/header.blade.php create mode 100644 app/resources/views/layout/body/header/menu.blade.php create mode 100644 app/resources/views/layout/body/header/menu/contabilidad.blade.php create mode 100644 app/resources/views/layout/body/header/menu/guest.blade.php create mode 100644 app/resources/views/layout/body/header/menu/herramientas.blade.php create mode 100644 app/resources/views/layout/body/header/menu/inmobiliarias.blade.php create mode 100644 app/resources/views/layout/body/header/menu/operadores.blade.php create mode 100644 app/resources/views/layout/body/header/menu/proyectos.blade.php create mode 100644 app/resources/views/layout/body/header/menu/search.blade.php create mode 100644 app/resources/views/layout/body/header/menu/user.blade.php create mode 100644 app/resources/views/layout/body/header/menu/ventas.blade.php create mode 100644 app/resources/views/layout/body/scripts.blade.php create mode 100644 app/resources/views/layout/body/scripts/datatables.blade.php create mode 100644 app/resources/views/layout/head.blade.php create mode 100644 app/resources/views/layout/head/styles.blade.php create mode 100644 app/resources/views/layout/head/styles/datatables.blade.php create mode 100644 app/resources/views/login/form.blade.php create mode 100644 app/resources/views/ventas/cuotas/pendientes.blade.php create mode 100644 app/resources/views/ventas/precios/list.blade.php create mode 100644 app/setup/app.php create mode 100644 app/setup/composer.php create mode 100644 app/setup/middlewares/01_auth.php create mode 100644 app/setup/middlewares/98_logs.php create mode 100644 app/setup/middlewares/99_routes.php create mode 100644 app/setup/settings/env.php create mode 100644 app/setup/settings/folders.php create mode 100644 app/setup/settings/urls.php create mode 100644 app/setup/setups/database.php create mode 100644 app/setup/setups/logs.php create mode 100644 app/setup/setups/middlewares.php create mode 100644 app/setup/setups/services.php create mode 100644 app/setup/setups/views.php create mode 100644 app/src/Controller/Base.php create mode 100644 app/src/Controller/Login.php create mode 100644 app/src/Controller/Proyectos.php create mode 100644 app/src/Controller/Users.php create mode 100644 app/src/Controller/Ventas/Cuotas.php create mode 100644 app/src/Controller/Ventas/Precios.php create mode 100644 app/src/Middleware/Authentication.php create mode 100644 app/src/Model/Banco.php create mode 100644 app/src/Model/Comuna.php create mode 100644 app/src/Model/Direccion.php create mode 100644 app/src/Model/Inmobiliaria.php create mode 100644 app/src/Model/Inmobiliaria/TipoSociedad.php create mode 100644 app/src/Model/Login.php create mode 100644 app/src/Model/Provincia.php create mode 100644 app/src/Model/Proyecto.php create mode 100644 app/src/Model/Proyecto/ProyectoTipoUnidad.php create mode 100644 app/src/Model/Proyecto/Superficie.php create mode 100644 app/src/Model/Proyecto/Terreno.php create mode 100644 app/src/Model/Region.php create mode 100644 app/src/Model/Role.php create mode 100644 app/src/Model/Tipo.php create mode 100644 app/src/Model/User.php create mode 100644 app/src/Model/Venta/Cierre.php create mode 100644 app/src/Model/Venta/Cuota.php create mode 100644 app/src/Model/Venta/Datos.php create mode 100644 app/src/Model/Venta/EstadoPago.php create mode 100644 app/src/Model/Venta/EstadoPrecio.php create mode 100644 app/src/Model/Venta/Pago.php create mode 100644 app/src/Model/Venta/Pie.php create mode 100644 app/src/Model/Venta/Precio.php create mode 100644 app/src/Model/Venta/Propietario.php create mode 100644 app/src/Model/Venta/TipoEstadoPago.php create mode 100644 app/src/Model/Venta/TipoEstadoPrecio.php create mode 100644 app/src/Model/Venta/TipoPago.php create mode 100644 app/src/Model/Venta/TipoUnidad.php create mode 100644 app/src/Model/Venta/Unidad.php create mode 100644 app/src/Repository/Banco.php create mode 100644 app/src/Repository/Comuna.php create mode 100644 app/src/Repository/Direccion.php create mode 100644 app/src/Repository/Inmobiliaria.php create mode 100644 app/src/Repository/Inmobiliaria/TipoSociedad.php create mode 100644 app/src/Repository/Login.php create mode 100644 app/src/Repository/Provincia.php create mode 100644 app/src/Repository/Proyecto.php create mode 100644 app/src/Repository/Proyecto/ProyectoTipoUnidad.php create mode 100644 app/src/Repository/Region.php create mode 100644 app/src/Repository/User.php create mode 100644 app/src/Repository/Venta/Cierre.php create mode 100644 app/src/Repository/Venta/Cuota.php create mode 100644 app/src/Repository/Venta/EstadoPago.php create mode 100644 app/src/Repository/Venta/EstadoPrecio.php create mode 100644 app/src/Repository/Venta/Pago.php create mode 100644 app/src/Repository/Venta/Pie.php create mode 100644 app/src/Repository/Venta/Precio.php create mode 100644 app/src/Repository/Venta/Propietario.php create mode 100644 app/src/Repository/Venta/TipoEstadoPago.php create mode 100644 app/src/Repository/Venta/TipoEstadoPrecio.php create mode 100644 app/src/Repository/Venta/TipoPago.php create mode 100644 app/src/Repository/Venta/TipoUnidad.php create mode 100644 app/src/Repository/Venta/Unidad.php create mode 100644 app/src/Service/Format.php create mode 100644 app/src/Service/Login.php create mode 100644 app/src/Service/Ventas/Pago.php create mode 100644 app/src/Service/Ventas/Precio.php diff --git a/app/common/Alias/View.php b/app/common/Alias/View.php new file mode 100644 index 0000000..80df0a9 --- /dev/null +++ b/app/common/Alias/View.php @@ -0,0 +1,9 @@ + $this->id + ]; + } +} diff --git a/app/common/Ideal/Repository.php b/app/common/Ideal/Repository.php new file mode 100644 index 0000000..9b4acc7 --- /dev/null +++ b/app/common/Ideal/Repository.php @@ -0,0 +1,126 @@ +table; + } + public function setTable(string $table): Repository + { + $this->table = $table; + return $this; + } + + public function load(array $data_row): Model + { + $model = $this->create($data_row); + $model->{$this->getKey()} = $data_row[$this->getKey()]; + return $model; + } + + public function remove(Model $model): void + { + $query = "DELETE FROM `{$this->getTable()}` WHERE `{$this->getKey()}` = ?"; + $this->connection->execute($query, [$model->getId()]); + } + + public function fetchById(int $id): Define\Model + { + $query = "SELECT * FROM `{$this->getTable()}` WHERE `{$this->getKey()}` = ?"; + return $this->fetchOne($query, [$id]); + } + public function fetchAll(): array + { + $query = "SELECT * FROM `{$this->getTable()}`"; + return $this->fetchMany($query); + } + + protected function getKey(): string + { + return 'id'; + } + protected function parseData(Define\Model $model, ?array $data, array $data_map): Define\Model + { + if ($data === null) { + return $model; + } + foreach ($data_map as $column => $settings) { + if (isset($data[$column])) { + $property = $column; + if (isset($settings['property'])) { + $property = $settings['property']; + } + $value = $data[$column]; + if (isset($settings['function'])) { + $value = $settings['function']($data); + } + $model->{$property} = $value; + } + } + return $model; + } + protected function saveNew(array $columns, array $values): int + { + $columns_string = implode(', ', array_map(function($column) {return "`{$column}`";}, $columns)); + $columns_questions = implode(', ', array_fill(0, count($columns), '?')); + $query = "INSERT INTO `{$this->getTable()}` ({$columns_string}) VALUES ($columns_questions)"; + $this->connection->execute($query, $values); + return $this->connection->getPDO()->lastInsertId(); + } + protected function update(Model $model, array $columns, array $data): Define\Model + { + $changes = []; + $values = []; + foreach ($columns as $column) { + if (isset($data[$column])) { + $changes []= $column; + $values []= $data[$column]; + } + } + if (count($changes) === 0) { + return $model; + } + $columns_string = implode(', ', array_map(function($property) {return "`{$property}` = ?";}, $changes)); + $query = "UPDATE `{$this->getTable()}` SET {$columns_string} WHERE `{$this->getKey()}` = ?"; + $values []= $model->id; + $this->connection->execute($query, $values); + $id = $model->id; + $model = $this->create($data); + $model->id = $id; + return $model; + } + protected function fetchOne(string $query, ?array $data = null): Define\Model + { + $result = $this->connection->execute($query, $data)->fetch(PDO::FETCH_ASSOC); + if ($result === false) { + throw new EmptyResult($query); + } + return $this->load($result); + } + protected function fetchMany(string $query, ?array $data = null): array + { + $results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC); + if ($results === false) { + throw new EmptyResult($query); + } + return array_map([$this, 'load'], $results); + } + protected function fetchAsArray(string $query, ?array $data = null): array + { + $results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC); + if ($results === false) { + throw new EmptyResult($query); + } + return $results; + } +} diff --git a/app/common/Implement/Connection.php b/app/common/Implement/Connection.php new file mode 100644 index 0000000..bcb6eab --- /dev/null +++ b/app/common/Implement/Connection.php @@ -0,0 +1,61 @@ +connection)) { + if ($this->database->needsUser()) { + $this->connection = new PDO($this->database->getDSN(), $this->database->user, $this->database->password); + } else { + $this->connection = new PDO($this->database->getDSN()); + } + } + return $this; + } + public function getPDO(): PDO + { + $this->connect(); + return $this->connection; + } + + public function query(string $query): PDOStatement + { + $this->connect(); + $statement = $this->connection->query($query); + if ($statement === false) { + throw new PDOException("Query failed: '{$query}'"); + } + return $statement; + } + public function prepare(string $query): PDOStatement + { + $this->connect(); + $statement = $this->connection->prepare($query); + if ($statement === false) { + throw new PDOException("Query failed: '{$query}'"); + } + return $statement; + } + public function execute(string $query, ?array $data = null): PDOStatement + { + if ($data === null) { + return $this->query($query); + } + $statement = $this->prepare($query); + $status = $statement->execute($data); + if ($status === false) { + throw new PDOException("Query could not be executed: '{$query}'"); + } + return $statement; + } +} diff --git a/app/common/Implement/Database/MySQL.php b/app/common/Implement/Database/MySQL.php new file mode 100644 index 0000000..b2bca28 --- /dev/null +++ b/app/common/Implement/Database/MySQL.php @@ -0,0 +1,24 @@ +host};dbname={$this->name}"; + if ($this->port !== 3306) { + $dsn .= ";port={$this->port}"; + } + return $dsn; + } + public function needsUser(): bool + { + return true; + } +} diff --git a/app/common/Implement/Exception/EmptyResult.php b/app/common/Implement/Exception/EmptyResult.php new file mode 100644 index 0000000..2a8e3ef --- /dev/null +++ b/app/common/Implement/Exception/EmptyResult.php @@ -0,0 +1,15 @@ +KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq3?Wo(Y?l$ge?uXo;%ru`Vo>?<<(8I_>;8Eq#KMS9gFl*neeosSB zfoHYnBQIkwkyowPu(zdms`p{<7e4kra-ZWq<2*OsGTvEV%s0Td$hXT+!*8Bnh2KMe zBmZRodjHV?r+_5^X9J0WL4jKW`}lf%A-|44I@@LTvf1rHjG(ze6+w@Jt%Bvjts!X0 z?2xS?_ve_-kiKB_KiJlZ$9G`c^=E@oNG)mWWaNo-3TIW8)$Hg0Ub-~8?KhvJ>$ z3*&nim@mj(aCxE5!t{lw7O5^0EIO7zOo&c6l<+|iDySBWCGrz@C5{St!X3hAA}`T4 z(TLbXTq+(;@<=L8dXnssyft|w#WSTW<++3>sgS%(4NTpeI-VAqb|7ssJvzNHgOZVu zaYCvgO_R1~>SyL=cFU|~g|hy|Zi}}s9+d~lYqOB71z9Z$wnC=pR9Yz4DhIM>Wmjgu z&56o6maCpC&F##y%G;1PobR9i?GnNg;gYtchD%p19a!eQtZF&3JaKv33gZ<8D~47E ztUS1iwkmDaPpj=$m#%)jCVEY4fnLGNg2A-`YwHVD3gv};>)hAvT~AmqS>Lr``i7kw zJ{5_It`yrBmlc25DBO7E8;5VoznR>Ww5hAaxn$2~(q`%A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z0009ENkl#t4#a7ZeDA&=~8sYk6z!e%rZS)9(N8>BZJ2)${&& zz8{|FYe=Hpw+Xx8Km`XX8c+b0tI(gfK34(LmhU-VRi0CEKOc_Qu(Pf}{6^JV$=Ud8 z4*o3(T-8C{%zSI-m-gGarG0jG?mJx7VXrA{5&ALf`eC~0copEk0afl6+nT(p#cYS? z$VF<7UBX$+wPQ~Y+otQ8)Piexx?nyMaw-GhTyq-WbnUg1KYxOAqsMdNB94ap0r2)t z@Wr!_wY+mR|5c6OL+vt2WsSgL0+o~Y)L6fxvCZQ-@zbgq;B@!bJbyXBqTB>L6>R-; zah0HQp84Nia6Whh*PfnLW2sc;@Zsb1_P&ol^bp<}59LxBuy5~76wV@z9M}H|HVGnv zdO=jMLBY_YT3`RTC25(!3{}r1)mZn@=?^%#zn!gHn;00l%*@OJ_q5#2mdy>c?`k6w zjxabl$Y*_n1OnkT0u8vW)Ri{{es#TgQj!#jY*t4{r(&_anwpxBB*jNYBuQ_aIxDER zB(0PB=4ZEZ+pcJGb>C017`6@Ya< zo_=x%iOCd0!y|-(URqlp=H}88iA0jl&V7uHO;V{CbRK*e(-~e1umu!~#A4gY<%)E7 zf60CKHnG0m$6vVup(gRPtA_!_?VR=Sh;4Xb1k4usk7P6A0 zuCCW*7>$-B3`vyEhsutIr%b}zNv1PgPiNV+t(m2{JX;R*5sr9i+!)2@^D{PY{g4tn`r6kVN@H^F+l;MRns=-W?8r%MZyE^J!?gv=eK75y-B5ubXfr>NZWR^z2a6 a-va=T>#R+iEvaAt0000KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq3?Wo(Y?l$ge?uXo;%ru`Vo>?<<(8I_>;8Eq#KMS9gFl*neeosSB zfoHYnBQIkwkyowPu(zdms`p{<7e4kra-ZWq<2*OsGTvEV%s0Td$hXT+!*8Bnh2KMe zBmZRodjHV?r+_5^X9J0WL4jKW`}lf%A-|44I@@LTvf1rHjG(ze6+w@Jt%Bvjts!X0 z?2xS?_ve_-kiKB_KiJlZ$9G`c^=E@oNG)mWWaNo-3TIW8)$Hg0Ub-~8?KhvJ>$ z3*&nim@mj(aCxE5!t{lw7O5^0EIO7zOo&c6l<+|iDySBWCGrz@C5{St!X3hAA}`T4 z(TLbXTq+(;@<=L8dXnssyft|w#WSTW<++3>sgS%(4NTpeI-VAqb|7ssJvzNHgOZVu zaYCvgO_R1~>SyL=cFU|~g|hy|Zi}}s9+d~lYqOB71z9Z$wnC=pR9Yz4DhIM>Wmjgu z&56o6maCpC&F##y%G;1PobR9i?GnNg;gYtchD%p19a!eQtZF&3JaKv33gZ<8D~47E ztUS1iwkmDaPpj=$m#%)jCVEY4fnLGNg2A-`YwHVD3gv};>)hAvT~AmqS>Lr``i7kw zJ{5_It`yrBmlc25DBO7E8;5VoznR>Ww5hAaxn$2~(q`%A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z000LENkl3&26~}+~Z8Kxzu|4Ar%w`CT?P6gQJ9ceIffN$dv{FN)s%Zr@ zN@y#Qh7V1kfhweGL|ZA9Kuw}bO{A143y72^h7z2xv{<1-OEEUsf!Y|b9Wb`>KHGcm z_QTj_29K9=q|waWckccF-`VatLP`mMxqksNBEeRXCP-6&Es!Q)ML*IKV2bGP==yuo z6b2SgN)s@n`YEcU<&MhQ<7wo%EQ(SrPT$cfN;1h(C7<8Xf9-Fp-3g#@e=-9&iV)vN zi1ondfM+6Q2_!2L0qzgF9JOZ$j2)xT?uWnlUsDu;WK!@Zyxt3mpKl0@L?nvDWQ zhq@g8YayjF%W3u9FM)M{AKh6XyRL)bLKw-|x2}TjTnPAqCt^3GYLe!F`nbPO_YauD zm!(T=iFrQ+wu3l=rn~IcI?&v>w$|W!;WI>X23B(&Xqtvl4kCHkp-9}Cq-jvw@m`1P z6A8|AU1CK;PK+L^O%wbr6!mE=8@r_eC9f3c=8qAnGXY3`)z9#2Phk500l7ZN6uV|b ztmIpRn$;0ewx>F5oXQw@oQNs1V3suHK`<&9?8my+hF0}7jvu_0kY(_XTX5FDLx;>| zeRT%^>e5L|wh$w+5F0*)x6vHf?TrY_g>!Q?s_$Eq`stm0AF=7BQ{b3OPFfh#n%cLCEbu#o z@;0i9eWL*-bpg&TXQu?;w(Vs$ZPxxgag=Z*HL}zFrM5G z`iuz=7#J92GgplaEhOX;`!{O*rLI8qLsGp(1W(>z1yk0MnNNBPw z5a@Gea^!C(m^;6c1$o6h^UTlVG>)IBWx>J{e7;pQHGN6W%p7d1gC<(z z-8hfOQ;N^`0HI(Q2$7qcg~#K@<8j9wIeT^%ON$Fxv}hjd*8LDi(2cGulhlF!0Sfc; zC@C)kX42gqpsDf7*yD!!MgZ2VsUkDeOaH(ipfNNQ7}I&-#b2>%^>=vXmAzwrf9$bu zP+7U0zTOUmn1p}~MRT~MI3EaMMmo88@h*Xjms$a+ta=b&%;&Lk>{u-)PgJvO*Yg}Y z^vT%z;>Ec@kk~{SN5C8@VauyZN2<8Zg@zUYnwziD)N}*LX64E#0o%665f~l{kL>l5 zl|5^0{c39`U=W)OI{{4*wo`>U--*avs2zDhSELE6QT@Z4@C;lsUZq z`Ujjkb(X%qAwZxA0Ro1GdO3HliN?l@qlU(KLsE>5MOJnekUc&+7OQQy({Mi#gL0000u literal 0 HcmV?d00001 diff --git a/app/public/assets/images/Isotipo 64.png b/app/public/assets/images/Isotipo 64.png new file mode 100644 index 0000000000000000000000000000000000000000..8b503d19529984b3b75b81357d953ac44e0bbfd6 GIT binary patch literal 6361 zcmV;~7$)b5P)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq3?Wo(Y?l$ge?uXo;%ru`Vo>?<<(8I_>;8Eq#KMS9gFl*neeosSB zfoHYnBQIkwkyowPu(zdms`p{<7e4kra-ZWq<2*OsGTvEV%s0Td$hXT+!*8Bnh2KMe zBmZRodjHV?r+_5^X9J0WL4jKW`}lf%A-|44I@@LTvf1rHjG(ze6+w@Jt%Bvjts!X0 z?2xS?_ve_-kiKB_KiJlZ$9G`c^=E@oNG)mWWaNo-3TIW8)$Hg0Ub-~8?KhvJ>$ z3*&nim@mj(aCxE5!t{lw7O5^0EIO7zOo&c6l<+|iDySBWCGrz@C5{St!X3hAA}`T4 z(TLbXTq+(;@<=L8dXnssyft|w#WSTW<++3>sgS%(4NTpeI-VAqb|7ssJvzNHgOZVu zaYCvgO_R1~>SyL=cFU|~g|hy|Zi}}s9+d~lYqOB71z9Z$wnC=pR9Yz4DhIM>Wmjgu z&56o6maCpC&F##y%G;1PobR9i?GnNg;gYtchD%p19a!eQtZF&3JaKv33gZ<8D~47E ztUS1iwkmDaPpj=$m#%)jCVEY4fnLGNg2A-`YwHVD3gv};>)hAvT~AmqS>Lr``i7kw zJ{5_It`yrBmlc25DBO7E8;5VoznR>Ww5hAaxn$2~(q`%A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z000gINkl&`fqTaJTUTWVS3vwZLp1r$LSMR!(3ArMH&gTx4VNs{g){k-?L ze{`ow=ni?%jWe^SD%F+WJ@?*ozW1E-JLmjKkkMaEkfs0$ zM1N&;9Fxd+Y-|LdNn&1;=cOsqF}Xb=0PX^A13m=wWIlWtvuT=%0=#+7_UQqy z{>uybz6$_m1E+w$8ZmYq&<4y;mhu2Ox}+DZ#FQTQ@n> zr{DKtr)_^&LXK`C$GGQm0q_Fw%p~}K4eXkf@<668(S+p9PV1{XyRA=a0x~p-DaXD~ zOR?e>;A5a>)TjUy9kaI$3=@%A2-1j#`xvbOP6Ag0y%#fi3FKNNK?D0MXKaTW2DIud zi-{(8yz&ANnC-_<=PZ|M*=lLF9|O|_5hqS*^cjoBQeFY_ERwT+G549T z?TrnCT6MNHqP(1dkf{RT&S<2cIa+xY!U4?IlV}TX!~Vb?VgJYNLSK0gW@|mtKLCn) z;j`Sp=fJ(A{as)ckZm#e%A@|>Gi~-09RX30Yc)sB1m6V!{|3Ao|0WGN_$}s{7A))j z8QZ;EW0!23p2K?g6UeSMWPb;!2~&dq1fCuab}mhlu1ntQvOM<28QY6Oz%+{-*W^I zs^qn1`>uuobxpc%VpEy4^2xM-+-ShMKzRW|!8~&eEH3PuKTD{5>}yoritFFMM7XcO zY^jaJi)dUhW#nt=S>aWU9`%#oopc;*=-1Y`EhbiFYRV@IfR#XNG+>PmcGAH7<^*c- z_1J%Q40YDx@dYZFi|er?Xv^1Op010;3{-5I#E})|!$uo5yR)xu^J*({od$}SxWA_Y zfct^}25fP`E;xwU-iWsRE^PmB0O87>@I!^wiQ^~Ru-x`Aq2@+hW*^pR@Lz{rT)!)u zzJNkrT6oG|Jy`%e32cdfqK@>Q#q4g!vhG({fAIX2Uts&;<77Sl8fun*QnWxxa7un4zsHj z{l-VIY}^aBj7t{k*S~s}>#qMx0wGCWelg|+`9LyhA}+8qVU4cp$a5`7zYpu3FQd+1 zpA>=qcKyS=^6GQg9dk%ePs1=mDXrEn2Ea7n08kkh?1YBwtOI*Cw)O9$%vgTOg7o)# zxaF2jeENs?$#Ty}*HsL|NO_$e4}cH=%Ypsz^Sc5@7_*}hWmXNAJKjb(b1zwl!=E2# z^-UY-?K?|$?g9iRrfFW5Mn!xKkn+dCp*ZCg4T4@|PYc@Od$4Z&LsFD~>4jY^s=0;U zzJ7A^%Rm}j*r`q>iMY1->sNZDNm`_>9c@bs9lV{G{e9?v@g(ZP2a@vg0q+pg3zjl4 zFhpMdYz!luYJI)kT?f<0i2-u7VJI5Xdj>*&EO%@}nX@iw(u56z%&a_o{+`RB{M2Rv z=|6{X=A+;K8X~7UsV`R*fvT#P)#N9i2L$>M?((E7|Hne(10eXbChd<&7$F3PVc_=% z5JF6VUqRCpG)+q_079H!Yg3b`u#|F?fr-d^CWc{72!LQPh-vr%FCej4^T^E1L`rkQ zab-dP3?uyDLr<{xo&C(5nICCWnUZh5>EyRh{)}61T`}hUzklH^e({Sf6cx=t2th+b zD~~?<02?=ae>m|1psTZ!RjZcs;){a}Q)4mb8&QoMII!}f0PNZQ0d1}C(bhUAdS5eHnVVx) zFyfoyblI6PBY$!|xs{9fG4Rw=kFfUp_p)!_9&++ZBa1D`s0PibkT=}85-1|eolADk zbh2}%1BKK#v|YTeZ~O+BOLoq5Z1ybDGHO_{V%eB(G35@DRp-6;o@43K6?AvDpeSl` z02rp~1#`)A=P@+oA7PI!>g!MA_xlsx)6&vTQ&Sr@y9)rn&%?a3A~G}6F;i6RJoeaT zz>d%7Pwp%*v%t-~vLX&0`d`x08~`|-4q98!aOzYW^XHeu-E-nZGyQ!%WV!RBbLs%q z)nx$q{DFx#NIv?4ef$20tgLht0cB-HtX_RJs;VS#iN)Ofy_LMX_kFB6S0r~DT(r2H zLx&E;{YspQ?gZztCU0G8BL09wpf6-59cYHJ%3@*g=;AH&)2529P#EM8nb zX|r~vWdj9F%br7aPBG~j#e8(|Wwva2F|oDI$OFbtvnLI}f(3K2Sf}Cl2S^}`865D8 z{65s5Y>At<8ynkbYWfF%yj*i_a%u{pD1e`=tZ50aclY!H;i!cs5deS{D;EKt z*mrTdoHVzz)6j5w6yLF9r|^2ZvD>W}h6(5_T~ax<-od~i&`nQwFFoBobai}*s^zos zhku=r|Fh4IF_DdDQv%@HYpSDhz>EdLfd3pPPBf1O;P@%PhoUI>`~jS<+}I2-S<1`H zMkr;JlonE6QOYg1uIJ;AUZlm6w`gsJeO{4rdNNUjT>07B#aVUww6w zJMOsoJOH(gM0Ux5Z_vZynkq_43a13X=FNBU&_f$gRDrH*h%w4kpD)O!O^*-`d2zel zn5L0@3n(qUl6mv4VrXz=9B}Z-r(d1V9!-c(cX5(os*v}sY$ zQb#x4w2Y%iwsZge_tDqe5)Hg5YKSaeRDq(p2?Rn|tvb4{1O3$1HL-MQ6^9Oe34~Bp zg#oXZiuuJPNA(I@7jvTG!@E32eWBX2a zz4aC^zw~=HZMu`c`N8Id{0~2TH;4@UNs;aqoJ^iTx0HCI( z0yy8#S5y}r9X;&X^D*Ck+mFj>Cm0F?=~K%8$7`qA?KVKt((-k}u2E6ZOu&~q0G2G7 z52OVdi(#1Px`wB(pR#!+EUBqXdeD=x0PIY7-RZDJJDDj0pt7=r z88Zv;4h%&~B8!Etu5;|(a}cZ563zenxb~WAH2u;V&|$*>f&_yhLZL8&g8_QKJ;LnS zh1|G0aXT&|my$XFGBY!%s+x-#?u&gB!!QX34HQL*m7>Wof4|QU^yBIG(BIdKKj3FU z_07ET#?$Cpd}3r6Ce6+5fFm{2;4rPeaT)Ktz4JVxiV{=a?+>Es*-=-yGwMXkn&&WzG0FgkLK`m5vR)k9@fNwhg}`RK9VJjb@JZ<6IMyr}X? zv4He67jx%cLF?&#^mG?RYlGpxv(!w||0l8{bkVBur%&+sZ=S&6oQ|%m6c!^RD3rqb6MwKSHOpGR$N165UP zM_AFt1d~7z@B;!(%O*Rg6d~k_X(7D-M_`)B;jNm{lcA<5(G)e-goNnU z8X*9M;GiEfWJFAR#OYG2T_w;Hf}kH^b;WuJnx>JF>7KB=2q7+58!(y7;?lSP2;GJB z_h8gMbHUMBC34i&fZ(uV1|yETic!a3kzhuzBf+YN2zhK^E(F~Qgd?lPBGU1>Tr~ch z%rK}nMCMiJ6_O)=i90*Y7-xr-k-SzDMOPzkaGAEmrDPiXQ>Xv;03>n&FOU}f{d1y( bI{n`OS|NRY86>_D00000NkvXXu0mjfU{o%_ literal 0 HcmV?d00001 diff --git a/app/public/assets/images/logo_cabezal.png b/app/public/assets/images/logo_cabezal.png new file mode 100644 index 0000000000000000000000000000000000000000..29fd0595347b55901e215dc2a07ac5e75426a69e GIT binary patch literal 23004 zcmbTdbySqy_dYyyhae%{9U>(y0@B^xB`w_`N(j=@E#2KQgd&Y}4Bg!f&F@B^&+~o$ zd)Indi7lQ2L}slTXPV|V=i6QQcZOS zUkJK*{#G_LAYRr%1rM1*%jzk zf&sh4yp}}{cn*5w75O$F^yVE*Kzb6LDkuvcWHexEvIbIO1sT!%Z;pck(yx-eVL-a^ zlz1>%F(3+D^H6b+l>n%8MB|GDNb4o&xrJ;GA83XZ^io>WLJCyb00IwVqg8{D(Lpbj zLq9Wu;Jraczo@A_K%bI9&)=PD3Z5{RV{b75mP)P`Y@*?l2-HPpbwbkAWFuo3mL_0+ z&SMN~obraP%QN}Kt3WQS<+DK$C@TgJIPKZJ$1rC3@GwtgJ*FY+ZU^Ecm5IsP!^TL7 z;~NlY#l`RU0}Fc%QGftqfZan5?IFCC0a}(TG~A*Z>rEXfYiCaL%<;)K64}vBv$GrP z>oYPvZ*`6PHGLl}y9~ja_qNx5f_Ko1<@QyYz*qW#lJHl{U4!Rxc_bsTD4$Fqn^BT? z4QP*dq~laQ(k4w>OwZSpahxK>QzFh@3WO(7S$|(BqMW!9$g#Oh)Vz zZ%Dbo%2vT~j+ks+>W!E}j#xLw$Qhjst$`@;qQ8)FjVb3sVNAYgQAZ*ZB!9l5?39AX z38$gx3w^FkB^$#n#i8;=jY3_D^i=2rEMJJ;yXF{yU!YeX?}A$;IpPDWm4znI>%^K0 zd5J!~%Rw78bKyvd!p}+_{ZLCJ6v30dHCkeYH5Vl;*838?O^C$VWBZcrXZPEx*DNS; zrUO+}rRXI;i7GWp;ab8jOh>BR;c)^bz$iTM?r$lK$wZ~J zeNyhCr;00-t)**zcHKj0@`@uwONxbh3MUGe9osuptcRBdCrs=WeN!~7bXBg}7|z(c zF?$v29hRb0E-51FxV||vn`$J!coqugU!T|0*Sps_*NN9DPjyk#P2M==Ua77!sPw;= zd9i`L!L@;Cp7cso{d_~1WZo{3sqhkc)1@(qnGQ3D7L?X0&;Z9hQB$xkUJp4tk z+Dl%Jy`-&VtYimuEv9-VAH0};)NeB1=)Ms%v8xpo=NB&)qp6>%52!^I8L0Y}zf^y|7IF6u`+~!yjCO;73^|8_MbEaa8xmjkd$oJJ zn}Q2TbS=ahbQ;8Y^kG85AKXq3f~4%d^C!w;`rU8D@{GS3C$4;oY5Fbree&JccUTeD zKlRpV*6e=T{rpacNJmL0E59p$n4%)zl+TziASWQ#J2W_yGc=XVohrmJ{c0<9D|I?` zsliCcLx-ilu)fh;x_VtFU;D7W)&8>%pLU*>x{iL$yR!5$+NqYZmV##mO$u=eB^gte z-IXWxef32RFDf@?5a-M5?dpAvElmh48-A2`AI7!C`8NB0y%$2l2${t!A=M%EbFTgH zoL_@~F=aUIP{jAgdBP66rPc`c$PDLNJ?;Qwk9E3g>bRsOfn}3(&{=4BnC!;^wnSmJ zRN|itzuMMiTrQmSSG>k9(o<_vyABHHD-L-Mtq(&WnS)%Jj2YUT&ZFJG#Fmveev6=G zetT)NRO+WFrWj~hw?)lv${wRxHeK0}=UxmoJ|Yml6#kI8CcGxdyZCBR+i;K<-0-Vm zK(X5)!|?Nxm_PNS*`wFvZ%{!1EsP~xSfFU2F6`}^=|6{j)(jSjbPUxZ`puEZ z?fx4g=DZ|+Bc33>m}<$P$XCHC!_6dI%=TVzj<=bsS>z|1h4$d2R=Sq7tt<&28&f%t zy>0u_-N9MNYWgbLnm0ib`!9V*&+Or@^UnqNMQk`M{0VR5LKR-eAB$o$72-$Gp5nUG zMxuIlk#<>9vH#}z9XcbX$3&)ZD#ax46}unP%I!(>gENn1qv;cUQFN;uhTK9be+GVv z8-?8~A^tXwpxBsbr?c!1M|vl3gM7c8sEN~*QlR{EZ= zTF}XJ9(4^5fjL+Mu~e|}OFfg_q+-c|W@5Qt8=aTDO`t(%|HsZc7@Ivbb<~Z|zI%}A z1ARp;cI~A))AXBZ$J8^j?F{T<1W_}Ze9o+h&qi!qCx%|+G> zUCe~y#LYxZdyLt+T8t%)+JlQriFx+KA%^*upn9>U?;V1Tt>y)N!$SfhYPo9XYBy>; zhhqzM#?x2!zYmGMTQ9lxC+Brrq4&al?epp|>hhBoljgV5w>40a^04BatAtxS{W1kR zr-NR&F}QmqYRvlSrin??F(EaTs43<>Nz7jI_J{N%cUBA@4E3*RKUb+8#XZ+|peRdF zG7SDXw+Qdj6{K-;H&RPd_V;g7PE+2cs;1oPn&>tw4hsLC+FkUzlbk2VO5+mL_LMnO z>$9HQ`8XbDc{&o2{w>|tkL?;_G@n!Ny=6MQ^d8IMs2SU3WlZ8Rd`qBJU|8?8(dD#y zegjvtQ8T52-_UN?WmoVaZd|dqC9Nf;yh+cd>CmgK&f5aIL!7}oyl~#;d4m5qHJQOD zw9t0urQ`I)~eWQc>d-pqv1o-S290 zZ+iH5((mlV)5N$AJDiKgrtrJUBTF&NXfiI^7}eq(|SEuoTyQDEt{7 zt*)ysR7VSL<6gwYJ;K8!o!yyovd#l|lfqO=MIHq5q6L8hfSG{5P?Ii;g5G9kRp<_xTu=P-2Q@l65ix}?+Ns>i;98sQYIz`xfzYnwZ|Z)P=vc) z-1MlecTsjHb*H$M_d>Z03pe9U_OcRN4E7>74GH!&?`Ef|QNk zn}hDd=>ki9tXR^mO^NOY;+~ZJJ(gUG)t`TNaPUrsN;qTAyVrlz<)L zG&`qwAJ)_uFaOtJmFkY(9T{?PLF&?n`he@Pm^_LodAt zOAbR{x+2L77d+HfJKy<5$G*8zGE+4pQ~Q;zkC!k@1`;h2NLsXTW1o&1&p^u~+FWe2*jmzT0N09a_Nr&s$Y=%<-eQ+u z_>)U|F28t<-c>?XI7Jnr`}-gH5SpFcay&3I_!|t~EE*vVF83kVE0&*-U;NqeC?vf30)DutvCg6@hfJvE@*u|ju;+_==7r3qcCq7=8EZqm z;yzgumZg^>lN zihJop$5tOeH5SHv?>y<)2WZ0@G^XFWS&CX_z%+U9(b4 z=1We-)wcfoMR;vk>E8e_qnAd4&4f*r%$4y3Ux1x2w%nPg@lboY+nB?nAk|CT1Z}Z# z_&kh~cz?Y*0l(8+?s-;z;DvBZg#Ck3!yh(yDs#yWSD&?}d|$t5wz4^=k9?4+T#f4= z&+cCyU&F4a-Ca|b&5ah4)Z36fN*`M7=RsQy zZQm`z$}KD+kA6dkEb|jcvhHJ^R2fu`QW1>J#SMruO`>5vvR!Vwac(IqW1i!0P_v&t z1P{+EdUUJC()<(bC}SA#9->tze0C#Rt zzvhkRBQMsyaSN5Z#_wo?d_0E=t0%XbZ5gZQL{ltGa63H6>$4*)O1%N%k~)y`!qRo@LA| z(7HixwaRTIBmozIvz&Qh>9&N}*m%%pic`aP5T*(#$f6C)RKn&R6%e(MexWzJHt!LARx0aW?&eK_jvYF{qg@4bPBNNW| zDTZdDdBczE#P%lJP$zM8$-vzUY5`I;YBw-;-C%c(?r4L)DhM}2 z?m>;1eSj2EE>PyJt~b|(r>=g#lwu%gJ+Ys2@vp0vX^I9A!SrBdj>1FUH|jqy>W*NM zV0e47hKXV97m605BD^FBG$+Ca?J6AjIWI6SP|rpx&gLJXjmWXJ`3|qP3jQmGSNg^~ z@p~X87!gpR4*aODXDHzQ<59`UbSNAg30CBI9TgtPyQ{F%u3-i{-%z|7ZGYeH?mR7wm6zymnEL$q%550Ci$_crB>NIX zsO&BS9iA=!rS4nO?7vTNuOjrlu|@dBzpbDSZV{d>Le$kC*3H)0?qFc(dgV*%`+S%d z*r*@NkY>2d$@DSbC|mXAvEpJe!-u-{y`x>Ux~}ZMK_N~rts6Th?$$x5HjQvo+f;uk z!g`$t2*B5X=sCkW@>J5SZZ+~88!YrKjG*3vE$!#GrbIj9+h3P)7<$Kr0a6&0WgKH& zBoo`lq*bN~)u7LeqIjmK6ddee@OY;oaQkqBU#^<)LGIJ(ko(`waV-R?!ZUUAnw#V` zt{uBuevEC74>)DB6n{(Atn^qDxFg{5S;a2S@*vOjM8?GC+}!76d<`erA<5iL)~{im z=KN%YdhROF3v@c^y~s4}^D}|*FSmQD|1_8?e8_B`S!cR_2Iw$Ubl(EjyRIq!vYi60 ztTE3*uu|yQ4V`Tk6Kv^9@4CdZ{jp+Ovu;g5Ro0J$uf$61KYng58Mt}F?P!Z$d`mi7 zFf>{B$fNA>qm0`XOdhCff*md&XzWVwCc;t(%U)Q_zt@y08zPsasZ^}^e{kd*m_bE| zQ5lMV9KxeHt-$3O{YBR%K?9=WjNd>dSCpacP6Doj55@G!Pxxtxs`W+ZkuCe+0>ka|u}{k8#6iw)y; z8Lwd~0Bs_eZ~IiW(94>!#wk%PA2+aVbTh*bFdX~i9K1( zB5(qAO~sejwi-FB^(jSf{FjRedu(ltTo#-b-1Wz?45lh}!J71mevdRA!rw(6{DH_9fP~x6l;RfV057XHg6MU?kUGR}oir5l1)k zOyZ2|s`E)kjDORpIxcrXnssiJ8gbGWb|!D=Tb=56jjDS8iYB-jtR&nMLVQ@P3DW8N z?B+GU`LxS9Ql_)0ok?i7r9V@f?L(~K0TnY4bFpu{kndQf`QaMT7>s7k?(ygk3LgE( zcOSgRQM2{Mw7E9Q?v^x9TXr6`WpKCZnsP1=3wvvUzONt18&Lj;8}jW(9-~8@$hbIX zzm`6_=A*Zm)oOH0ZvyYvH0ARjp)Vv-X)bDv2-w<82IGyV_sX$-<>hs>0oV4#_dpp~ z8yjR#K6*C`!a~rVi?=q{1p2N<)4i zw&_p72_q_min`hawA-;&+`m-du=n;JvQ;^2dm!8J^5dup4GO87x6<Y>`z@`(o?eC-jg>;JDtE`2k~`{*}!7Zik6@p(me9 zJLc3bx3h)7b_d9tDlO;+h$I*q=n_C10eG^>s3IFGX#(?wR^IX6-LCPf1Qnlsa_G%d z?E1wOnnw{prfIPn5gVxxC+$EA43D}8S$fTgc1NWzwEgWHWK?d|F8VZtHd*@DB7WO& z3^I@D|JnN>Y2p=+51Gz`_28zH9;*NkHzm-pCbHbi6kG1h+LHMD_`)DzT366WKRqcn z9k67_z$Vyn8BD0=PNSsmr+rYU*G^}5RIELES)TGeKo;4_d9HK(3*U_0NYokX`3?ba zvY2%`88ou(YP6R`+b@E4g)#P3fQ|9FT;O{5X$UMje8fnnmzCZN`bfR-rtmu7q$l&! zyjIpZev_ygh!uzl)G3wau2Wf?M_{9!*cg%Ve2dK@W!=)42kr(hOW#`BZ@Z?8TOO9l zhqOOFm;ihbr2hq9aArev878O0=m&|>Z<*oYupjeU#}=sa3khSzy@M@5Wp=e>Up!d}80qUN+d4zidnFJJlyl_+&S zLENX)VPLt<22c3pJ^-6;cW8<+Vsn9NLMzRxkl=?%viy1S9@29Ii%AAC_?rPV0?O|_ z8V4-EO3TrJzqtT^pUgaa|DjAO;gFn@{55PN$yFvodx#wKW>)7xvR1`kXhYK(rqbP= zPP)vQo# zE!@DUKv!ym$vkl02EkXM;=7zGw26t2Ra5t-i}3Xhda=AaAC>KzR&4D4loqPa@F5dS zj3^hj+%SPaP7|dCujOB-Xua)aboi|T9n9=^Mjxuw1tf2&pW3L@N8G$%N&X7BR``AV zpxsC$#010FZV@S($82*|yCWltES_C9zotLY{2L8YTV(;ffsq`cTasYo4T8wjynMXY z@!N|ghtW^5yrtG5Y(_Ag1N;Zc6?Q#$?=ObmA8 z2wg}72LiHhrH2?iwhl(Oa<=H=A$koAihr3jO;ec4+FJU<8{7&QCqk18SVz6<>$S}i z6ojK5VPC@+TuV~U+{_z(Rx@uWRIjPMzQi0h^GGf@?^YNzbQKa?nB$k_?HLH_g=qm z{?F2Pmc1$|r(_6`Uqs~um!qp|dNGvGkQX;v)DG{4qiBy5i`f~}|L`)JD!|kt0`|zQ znCD@lg6*&mT5gw(i!b#r)=;kHZ@G~fD7%$F3}7y?H?xM zRUD%7pugBVyUVJ|^B?=Clx&L^ofJh%!bQQ-a)fqIg6qsJt#N0w^cy72e`xxx{L-Yy zhyG=TfCgh-1^oCRUfxawj@OT#U_(GEv^eGMaXF-{dcIeLAnMA^!dO5;?5W`6q%yDq zItVQD87&c}-9~}I)ttS)Wfs`2vNxKfH@lx=EenQ6*#Gib8hcpXeD9TU(gyfzm{Ci2<&52*sODS_4jJo1z?J z16Xp{neN!%+%lqMiWX}TuSNavcoU13Ts}=zDgWQd{5;~KNA7_!BaFCp#rm>xKf+05 z`vcNZ*MqvHut@!Sx%SuV>wlfB^V%w$DaC_yh5>O4is&pHmjp%-vBx-c(iN<3Uhu~kz}a@DIZ;Kt&3&8{|D&>7xX&_TN+S*8 zRxRjt{r-d#`|c^?QHl_Ai_e|&$u9?s=jCPp(b=vFUmhJ6v1i%G4;GU}z!j3%T-({= zGF=R3NTzu@7Vr5_rhd?UAd1aZ0EZ^gNQ(uw=gGuIyq+&=_EVDIDf!C}X;4r#(`oG5 z1&(pBLnt+(U<$rv6w8|hx!o^*yI!*-XnnMm?;}gur+w-gVG8m1LLJxI^70TE06;y+ z2As(#zHpCX%Zs7uBjU^3K2t1sZdd%Tq7v-326DJqpx)lB!Q)F z^SH8zQJH1`_KL9_0v1DzVW^8qrT`4fdN*56$nS?y`(%B4;6&9*S))ajWZ#4fY4^R5GRn8iN<9bYSXHx?^ zzGVm+M4iC2_+=h^={Q4^Z0D-aZTP3|D8>g6m?(`PfKT%1zxpdA4x;;uK1`B76#hj$ zX4*N=UE>1bWEDw7bP@;B=zgg_e{!|BN{+C$KfF@j-(>*%%@ah~SMgfCDr%N{G8z?5 zJ_BZ(E~=iASJx*2SIaJ0c3im5EF}j$jM=vx-6aBO^GF)<69? znJw^tpD2ULWgqyBzjU$x5v~0Ek|a+QJWSjBHyxj7%YdH2hy728pa0APfm8f_CWG=* zx;~9%pT=8H)7(ED02qh->D7Qzw12(_1pN8_|9gQ<{9gn7|9%38I^ky-t@;|LU#{Bw z-iPeUtrQ6d@o;-Yf<0N5Rk1B6s~gLq=tiiOQCv+->DJR8wsm+(e&wJ%z4*%K2Dd@_~4cc?}`+0ul9DVz@-DdCgP zV1J=L`heRU>_R-lM#9C^9@sESDB69=HyXO=9olv|Co1~anY9+}Tf+$LQeHXmww6~Z z=<0DJ<^2aLofC2cFmDI1^`JdJ4IidPkaovY>w;2Kk^1?)J z3w7+1LFA7|$AbUJWHN@jJ%M@^4c zr^kk-we&5rVzh*Z4X_EsEV%6zym`tF2IZUdO7D2oKs%}rhjiZY#gh}Jr-6ebTMxHv z-vOVY{xe{BzT`{~hbty*s}{V(sEh+*v9Wu2fTBJB=Q$m5jh-?I2QKg|Vn0S;+cj0A z5@BwSN-6(s!^H5cuU@Si%46nO|-wlU*VzkEMxlARb_ zJNQL?srhu<1ehOYWkj{Of3+z^Pws8^;RkR4jDV_+PR<`=eJXsJb8(X}Q9Wf7;?fGJ zYrW=u*h(TBUmQ1)ghl9qX!^6(mbje9uHULb17WXxJ`jVac4y37)yw5byu(k(dcIzs zX1Jub7QS~j5=-Px&7B4CQVb2f3}BNwTg%tjQ%T=_vUp#zpcUA>w?6g+Z_{vZHaQc# zv>b-u-w&tpIbUCBMsaY9+#N2Vp`I2M&!u!@E`*C=&W4|!j+JK2XLvt|{wYmTp{LY( z4V8&?n7$dY<^p+Op5QO!E8d4D+$U4o)n<&;l72(i1b6BE#Udx?;|}I^!t>DicLYx% z2-Ifmhr1NpLDk)_O$Kf6xsQyl9$1D29(f`~R+#Wv`xOpn>-IL))Z+I{{)UhVS0zQy znz`vli!kEA)VmrO@3W!KH1`L)+3T#$t(r-Vbk}E3f@3on@&)UL%D;8+dW#%)*NJz| zQ3%1%kDi@fQS{foupYV=n14rPz<`VmW;gH}Y`f%Kz^wC#+kyi&U~?O=0a?JdA2o5} zvBo@3PE6!dFevxWNEtm-dOmj2wXgh&Peht{i0JYPx58VMa7Gb7Eltr9DF+kH;d1wqox{M>;^#<_KP%^{d&Y^&>rs@bPG-d zv;;5xN++xu{Y@4Sf_z4+Z~#9kM; z254g7i3~y^9p*ba3&{J}Z_COGnSII&N%RH61c|o0=OofRMAO;fpWqi@!$4OI zGN!1BkAn9B^DOh%$c;!Iy-;&Cz11^Ew*ncs3^_rOm@O&>3n1Q@_f-}izBUipgfm=~D~h`^XiUugKFs@-Pj z5}X|!!XQ>iF1e(=jUf**3gL@j!J1*qHBHtzu}8-F!roDea^dk=0s+;ldL5>K0e#5t z*V06Fx_>m$rfby-jkWpod&OneWwZe|wBMJu1Di4KiPcr$#k_R6Azx_;OacrQ~Tn+wx>FsIZ$U=yjnyhhxa(f zT!1}4BvV|-uQ%E&)t6(GZea4-l>c|@e04f1+(xR;2@$l7@Ee1Kq$t0W7k*)#?bc}0 zLY%C0+v`{6A^>7K5pu^omJbaWKD^BP#!Z zQDpo{`2)joy1BsZJ1)0+a{&if#aNv-HW{oiOBh4#`Wi8?d8!;@bqoW-1v88o1MiaHg$8*^ofP8R&xPE}51CiATVK~+e`3+E zR)bN@AIJOnO?W#~{Jr@E*|TyBq-Fg9H?}aX{d%}}rfwc`*jS;H2?y}A553VTQkl$Q zDoR2!-)o^J>lhT1^K;a6uH1}RGm>E{mpFODJ3^7Gj?TKub%(SoOf2XQi=+Fq7pNYu z>@pAeVkX4=+RX)^Ags8QB^)GP?RsZ_uc8CnUIzyiu~D9{qL42Ew=DBboS`#$1hX%> zcXOD~PEdC9N-hl|LgWLo6AsQJj_>)R91Xyqrc}uj#ToZ~1DP;*sZ@E@zH(qHhhQFv z2`vsLJ3l{PSE;~x)UUs>ULGXWc;s4cXX$mIC_>mE z5mXpoG9kE@(pvec?AwQc_Yw|j!;BUXgI&@tKh?S_`9%=DOOk#=9%P=Hl6hWt)Z`V5 zsT@U?{#IxaOGHj%G_EAg$}T?%qv403w9Y2~fEy+%aB24Lea&P}Qtu%E;@Ac&BiLb7 zojtqL3Z75Y^jHnqMdoFI51y4y2Vh6x^$X^`rj;>{%;xs2;r#Z=dPe`3+f24*VK1@B z13iM!tU_29Nuq6~?H2qpgoHn@mvw$tFn6X7#(?qyk%s_cJF8HVNOmdYj`DI)X#ptd zsPEZ-zF*KW-7_0-y9^!m^$Lm>fy-vWB`XkT9Q2gY1ps#>4z2b#0I^)o_}(f-T^}^8 z;a!>Sq3&nY#woCyIT=Q#Yj`h*MdK`ahhFvvlzG~F^0dvqpU9wR61$Om9-D%O(_qQW zaeQ5GOV1?q1MaQxV*QInqz}x>r$X*H$Fe{k-32GMH`!Shw(HcdPO!w}F@ zxDmr{)t$P_w;7>-mt-uoL=h5LkL<9xzCtqFX*}R)mGdwjBzlXn97mLCJ4csrFav{S z%~{9Q=oSC=!$Doac$0G@@m$CKB|X4_DwYRc?ZF|zv9Ir<E@ObQF0*z@1CczU1`zIMQnlvloOQI`0t!O{TS)7?bNBo%ABh~4*I#ojN zSO{FCu$*>_EJKv^M9;hyzDONJS;LS@4-wzMSzHe4eY*z$F;L{3@DHaw!4KN43b#g; z?pzvSu}4in6K{N@<*lR!dxS6%JqOZ#QMd-bt0!`)*zf|PX5G8I=<88EM&a<1_0bRR z8=#l(YWQKENw<-RAigF$^G>Q$q_>>a`r#;`($+FtO>SgMeRN0219`a=0Do;!$ZHWC zqelJipmDAKZf^mJZ{^b?+Wkx>`ir6Mk&bbRXuOLCTgws>p@u;4R6cn?fI<6KMolvf z3c!)PmYk1hFA_YWvu|us_wkgp>7#d_ac-bx0Z4(jlucTu_fU4p84D5f2ZXKyWSOTa zWm|tvS7P{cdDd7$^sC(OnjldCiChS|1F)`ihuI~t` z#q972xF&el{nfDxntyNJMYyQhULbd2b=_~<#=fzx^ADFxuzN)Oat$ny8eY1_p(xHO z_TyZfJT+5YliA^yMn~9~4OQj>djNIj&IucfV)d;_96)@$txDrdtTOdqZ{8ytllV4i zjYcAGfAGz@xwEFrCaag{(Ck$?mMStHFm|YiN^NJd6_eW|lrt#B zC{v++_@z=W+^bMSn4(E+c|w3r$-;bdMJf8sCHFe#^RyG9kqJ(r`D|p^hBEg)+d~Gt z-zzmY0A{)U+KTI|UUopby0!_)=F^dhe=8OLavGx|RXtw-o+r2S_+4krn!mmMCPu_IGKivX~gP zB&jQh7-R$w-8xK9dtwDU$lTDT5F&sfxL)galnoO+>_k+=+ac;Tp`_0YG*AYrrSEjX zOV&SHAjdJC)v{uOQ9_)8i%K7TS1QD;rDFOCyXTKQUNK%hxb~ zhU5|_iYp{TU5`Sk-W#-%){g|HqkQE#?gi?HlvQh}W57UZKYi$->nfDJPvy;xC&YDnTk>@bwK;tm7YY(rzZrO)iFu=5U2Cv7?ch8(u6WZ(Pu=RS3Dwu=z^6#-3J3p@c1JRjrJndGC9n*x)5^#-JdTJ)e$?wyNGf~ zU5=z=D@+~4w#@fGryVt+1(1J_X1LA}h@9Bw33PPZY5t%JY|)Z=6vfdjyuTL zzGIQEEC)feDl6ZJ#+Z{)HD>D;{5-z9eZeA7s*EH`|9nCBSg1z0^T57?YMi+wl2gsz z1}9#TN+s&s4r*zhWk_08P|?WvDN3klGG+_$`$jt^<^HjdcJ8&H7846Ni82oY)iy8J zjg^pcv-MC*zSYqCUn3)$N;tz%h&4Q~=FZGHU4TryN?b}ek;U_KIR66tJ6pw|Exc** zB5r0-ibsYPz~vNR;&CU?Gy(s1F9!GDGv(e`rZ8Y|KzQKv=>(?~t$|VKGIWjPdjdmp zl92$~l@2u7W8P&PqjBp{mhkSVcgCsL4iCGDJ?q09oaE1ah&M44^fr32+=PPCrtj4# zDMrS0RPdU`dy&kqx>XdxMcH?vf=KWj`}QeEP2A0s7Ks3(2n+&72!fw(G(jyEO5)Tn zy=Wf|NFCMTbm;^M3@ouQc3zk5yyZQ~chL$pd@#`hh=Rv`T}#vb5y5D^9Weq;w$BJD z<{f?3szUg0F)@zHqU=@rPaaIFaBLN{4r20jGUMpIL+f8Yv3?zBNScM`WlEj0nbGG; z3rvoA2YN)!e(;9<@#5}5YRQ?Pd|lu;G2m!6kQFxrElkB#s@HmGXt?K&#x;E_tK-g` z;_=~1+3S2e*NA3X2ewC}gubRxaab(>n9mgQ(VCZolkf)i4E-)Cl=|OexdE zge(1ne>76o{dUXcSsm6gh7bb~r9-R!3~qC=n6(1+swi1xK76p5UekiC6JsO>nTeHk z1&FxZZvF$0{gdhE(eMD#4>T8uf+0Xuf*2aTFA)q_||5(4&&ym!2!EZ(>SuWo05`N#y3DythK4ks_>{O z+;zUs?)v%~;&avnl1Yf&f?0;8VDJ7Q6R;MjOXb&|O3Wg#Pjg~rbW;6^p^dS52dT0Z zom{W_TMr9ouhHyY-KzULIJAK3fIXGu4RPzxO9ONvzJ6KycfD}EAPGb)cU?j#vC*60 zjz@sEx|XyWdmlz69NZz>;v40}pD6X}NykH6#JI|6og?LFWG1CdARcS89uKyQKF*aN zW3bz|6sm2vSYMGNVLDcu3p7ahoFuwpBnVNj+d#GPR~sTbt1UyYYk=aD0_(wnEoBP? zk?riTqY*SlLbU!;6;xM*_MYRyzE4B>jGi@8x^Gc!kgp$7epRdIx>XF;&B zBv7Py20PK+uX6&=gf$0@W({EHWI|rk%UHYSZsLm5@{|XP7pbEOXxEPiNYr83MX{A_kAFNh!X_uUPwd*;*PPx`K^vwMQW2;0& zYV!g1_5-@0h%sNANd>{3_dlZ^o76jWHFV_W>zKAH6$E$|&3yUotDfoFO(v5G@hdAu zw{a`>_se+Ro$SrnL2!h5sC=NSr?AELt_|$S*?DKfXy%;Fo*OH_Gp!p;Uo9$FM89afJ*>g~Hh(dSAQgEF%Txe&Tu_*<=fzgQc!6R~-E>T9|6z9b6q{@} zrNj_Tgq$bY!P}(RU9O8eb)x>6di$1zY5QydsNbs3l4*P0APnb?SL}KvK!R=08r2sd zQ?yqYAj#W|lH|K*)nmfmi++|;g}p)m7gasR1+E>A0<)%qMOZ%;Xl0d<{DLY& zB%FSK&CccNMOSecaMKyvEP;K!Sup3#G35u(2Fn8#f?mpP&em!)4;^M2bBqHFYX0L< z`w4g*r1u--{w|&ec5&bH51i(tS zX9B!o2xcFb4^Ha+XChuHHp1kcAgqlo1Hm`Q!e9UKum4NA-)z5e=)sHjd72LNT2=|bdOyD+t z1jQ1^At`JOhf9QU%)sZw*J3byCfYC;^X2JLzWmuEn3sTF zFyP`MLk-x9U>~^^C8FAvp4jj~bU$+!>dYo}C?IXfYi(5vRE(5F**x%j(Rt{>Hd{a$d;(mVOnx_; z9kwuQ@0~#&vKwan_NLBUKoOWd2}i&IuPECY#vEr>KZ1MPw<6*45j^^>ea7qB-DV6HBUJ3VY_)!^;5n7Bxo_A1)~L*!o69A0Y=L}D_e`@8w# z75Anj26N|(*s#we!Mp9)zJ`DS3w!tGD+)elu!yqaEh5ZNQ*BKY4y07&Ar4^L9I?iY zP$siUJ#(p0;Tug8B8z9}+qFe+OgJDR3le9H8&LxCrv%^S*AH=P_?3MIvUfSP&ku@8 z(P}IvIXq9#M!4)(^jsNg=If+ zV~AE4AQJ*6l%_*%uq`01bOuS7pH_=(i(4}T9%}Vf9Hs^CEQf)b5@gNXGK#l-ao+`SyZr?d-fJ zdcEFfSrmvc4y8-sH^#x{EU@n^j!BipD$nAx@KQ%Mx2)DsOr;0y5)DTw+ZZ*?!M&rE zEriMZlUN5@y0%p@uo;5vAOq0Ga}d46dYatD0|9NWd{SB|xrSm?740xkaRJz+NY%J; zo%)R-CPmQjS&(H`F3p^C$~C<%TFE-xW34UycG!R@3)+JO2*umA9yhOx#10}B7>+^y z{o}-@(-OP8Gn!Y?)O#A9%^@s@!0gpks<{S-f&E#Xb0$Wg5j$XX_H4Nt^hMxzb^2b8 zqYfAmv0q*$YD}&h%gFd;U5}^IcaC6?B!X6jLBhfF{KN;tWQyS9y;({^$?J?;FIm4% z;Ks#BEQ@+HeByM`+sMr+{=>4wfLr~U5bs)3<_^K*EuvBdg_l_ftUu~YjTYT{RY+_i zL(|;%by#^y63goqcRCG<-)3^!wDVI5uTjpiJ4;>a$s8TUacFV-amL6j2w7TurM8ra zPU^WQz}Mx62mbkDSBbFQE+vCw7(>omHyHxJ=nm>L()I%i34DXJTyb}4vhaxvECH}9 zTUH8NJIOohcYd`z>J-^t@m<{0c z$YFFl1+z$6@LIGK985bZis@mt6`M=(!yV7_ZcLom)&@6~ z3f}5Je6a+$xknRhMkiauZCDt&BjM+WMg}<{z>P<;;2@Am?#Qr9>5#zOsXXh>14M&U zc%_j^L5Fhj?WmOZ@AtLi4D`Qh+S2nD6?ERU*l?6nN_`s_A72+wA*;T{k;OB4`*k5- zW+6c0z<>8LB?r1-e^?FPo;=pk#=_O#qCG&~C zK$uJHxX!T zQK;+6Ny6V0pf^kHauSJQSngK?Kbex}_o$9et1!qjZmLmJ&?-9*B8BqU?(k>#a)w%a zAx+}+lHm~eCgUh9tSLk0aeS9l1OX|r;et3=T4!0!OC@n>v2c-uiKsNIKazm`Qsk3R zF#X_(#6z^|_fKfZidakq<{J5Os^BsvTNE;%*OdECP{kj&Vu#`y;cDR`f4z9IA9n3RWi9r8u&Z*7<$^lDj0CN5BgqmdT?> zd%?6}KQFgbfFIV&WvwoA&VpuZgS`dFjcS16$a!m@`(ek|0e->f2wxzTB4sG#70#O97|d)Y&RG+x0iT zU3m-+udMKwo;Kj3#t%#F*%F%*EOc!4zj?`ISA@!9&kBvQy!<_weSXu>ajgZ;o$<9_ zqH^)VmZ(|hHG4Z+pL6^r`DD}GABn}9_0n~_STBy2*73Z&3~T8OKArdGOSu`QaQB^s zg!AoYe!gB7V`();c>t*&bnw$>Y2KquX*P@WeQ-p98^dK8PY;TZlKIh(D;HPiy2(lG zzA%2BQz|GY!#mD$Usk$%oI`1)Y_2n#HFfl~ywczSdDK{Z>ZE~XjHSg!Y4a}5!Rwih zPFBit;Q73_Dbb5n5etQw4ZLJA@m=^D{g~th`&yiL9erqx6P%d8)w_d>WGdxfMrfzw$+I%d2ZQq4W@Ms>!|>ztzd`}=EC z9u&i{4W4kneNLfvKT-gvtXs`Ozdfl0sN0n7ObCr==Y$D`>HnAz#rpHliL}01XD8`* z{3Bda4taJ?yy;woGNnw}xP9??XeCf0YDgIZwpZWe8nWkpX}1@ofM{P`>IuY>Fd}wA z31EG@wKm_(xAj}EX5EW|;+kQhlC-0*llYvw(qBWNS!}pm_;-w9K!8xA)#1vkAB<-F@nNkLMhUy)UbSqf32aU%ymjzxV0O#X_c+N%8@9 zW_0vt1ZzM^v;f}$uP{S(hWBkCB`6MfE)d0vYhT!X+(LaaV;6qiOMhYZw$y*kzZdMS z*#JpD@?vPa$!X3Io<8o&&Uu6-HC)IJ@(?|}%pUW7tUd@d>Vyu?f<|BattW1eKb5LW z0PJNxiRGc~01OWKFLT<*mNC{tTAk$q%BJ%&#ESaqjs*C~y$3B;MW`|)E8zW;A=ukR zJME&X$?236h0OoRU_`Y<-AlQ{cRNMaXnCJ@uismgBt=l9!(CQK?&b^-e78Aj=Cn>I zTjzdrGP7L%fUHW2=B4w2&iK{4Mh114Y5=V!3j{e%7n+}|E~ z@7nrZ*6KGWO~Sf0A!bo_^NbL!JG^c5u1-NTlCnV>R1*jOXav@3_k0A1MGqj|0yGVG z5iY;FjJV{~N9aLqv~w1l;$Tj0XQ=uKqb}v@4pjder8|KvcA>Z?x`nEkuDIyg>uicZ7v3p1aV%lRs97M9oh~W zF(EDPSXM4^-~^}#P;lg@pG*b0()hV-)c1)2p}?O8=99eF$3FXJI?N6m+O`>{mG`~9xjD`!dTVzpN7-Bi?`K0sKZitG{FoT8^7#R7i@*Vr`%Up zGycO-Vmi?@+s8YUWjexOuuv$ks?pupfqGrB$$_yR@N_mEci!YXd$mm!!+9{IVBj+} zM&V|)9uT^>K^CLhn>R}n35Y}TmYBv*)l^71CHNY!lODqF4ZX&10P_s*E|oA(7$>=| z5SpsGXuybmm_KRF7yMVu8 z7I5;>f48A;jcg_oZhbk!l`o#x+EtZ_&)?~Krgro+8EQ;$srZ(uZTtjv3-ZzHF5fLh zx*RBm5(9iNZ6uGAZcEL`+q-!)>YjIn?H&86;R@u%SterpR(qL;oW!@9n5KMm6zT3i z6Cyvhd`EjLNy~kRV%ffzqfqEm9lhd)pr|HbW33z<`=9aKOj{caJh%} z*}f}3#cGR3&}|@VG4}0_KWoA|B^W9yVQA>?Qhf%N_qEVg^Q2&V1IzM3Li9nw(`mDS~$@bxo#`t8_kaa5Nht)rWa-2s1sDL z;(N3&QH!B6k;%I6_D`~jWofoMz7o$j>bUr1G{n7Ddf6i8KL8Ju!pD($<+!Pj04%`Y z<{hdjuLDrkd3MGB6t-gYRCY^hbvUy;C^Cw4MG`qKA{P-CB!*baU7d)JJCne)GDo2) zfGx}JlSbe0=$G8c{EKVM3n9b|A>c#rR-q>lhXHC@$$6t+z+U)u#9Q={xZuCJ5oY=5 z<0t#T@%w=7)o=edau76vl~aT7Gx6FTiyQ!_m15`VbTvu?X%9}Rh+{v@RL#7Uk^2_a!sq*LSWN2=j#G&0{Poein59;3@|sodJVsl0QqZGD!=b%ad#7cvjmE;< z+yoKJ08I1F4>8=q&go{g3zOWHZF+i5aFf;ioqT<=-#ny=1-|@q#gHu0saS81Z0J+a zTSPc2GXS4ghP($3wP--mK(WdmM4(2Z1?Fx+Hd)5lzj^R!)N~-hY*Y7oHgLdmiV(N@ zy3>s6;+K5mIpGesq)z`TXN?N75ZBVn2T7Oqf>qm2ixoNxirEgn?7u-XlF{?8d7+ry zm=%{ME~PK2u-d&?-znuMY*bd+FQTl}8^)U7i^9{-2!!Z;{uF==d>B$`Ou+0k8%u$L zBtH=jKm`4zOK&7$qlD=Sh+jJ+bcaaF2v}aPjP0I7d?fcN@9K}$vAXKN`j6~jR98(r z>fHFF`T{+@RG%C54d-i|V{t#Q98 zXz?Dx4l%4K_?}Gb)rx`))a4y0g%2Mr!Wx)7hm_z2YD+}77f}rhgG4;5} zQ~>iPDZwB7V#R>aV54=q9`R}g|7hit%;g=8wuP$pEWT{2&s zvvs~I^KMXR5JbM7fTo)0^z+2^O2#}`cNuY|1N4gcVxTJXgX&i6!|O9q=S4okVr;US~~2XZn~BAs3_; zIsGT%a^%spO~D&8kzk{%9l(ACl=G}mmxkY=SqEXW1R$<%KgSdtX0Nb59T=mzu>O;8 zH+yH180m*bY%oZBu@tw)z>L^ERX~1WrdA7o@XA84xNoxBs8P{CcNssL!?V{LDU-Rk@C!9f_$zeafWxYY{+n0_sq(KD zBP+jOYTn2F6WJZTpi1%zvK!qw${Vdp#ZCtTa5sX=Z|uMR9nhsBb5*+ZpL7(oeT($J zb8#Rj^*7-0H$d}$49@+(-Qa(W=KXJrun(); diff --git a/app/public/robots.txt b/app/public/robots.txt new file mode 100644 index 0000000..1f53798 --- /dev/null +++ b/app/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / diff --git a/app/resources/routes/01_api.php b/app/resources/routes/01_api.php new file mode 100644 index 0000000..a8f19fa --- /dev/null +++ b/app/resources/routes/01_api.php @@ -0,0 +1,13 @@ +group('/api', function($app) { + $folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'api']); + if (file_exists($folder)) { + $files = new FilesystemIterator($folder); + foreach ($files as $file) { + if ($file->isDir()) { + continue; + } + include_once $file->getRealPath(); + } + } +}); diff --git a/app/resources/routes/03_proyectos.php b/app/resources/routes/03_proyectos.php new file mode 100644 index 0000000..02303aa --- /dev/null +++ b/app/resources/routes/03_proyectos.php @@ -0,0 +1,6 @@ +group('/proyectos', function($app) { + $app->get('[/]', Proyectos::class); +}); diff --git a/app/resources/routes/04_ventas.php b/app/resources/routes/04_ventas.php new file mode 100644 index 0000000..93a94c7 --- /dev/null +++ b/app/resources/routes/04_ventas.php @@ -0,0 +1,10 @@ +group('/ventas', function($app) { + $files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'ventas'])); + foreach ($files as $file) { + if ($file->isDir()) { + continue; + } + include_once $file->getRealPath(); + } +}); diff --git a/app/resources/routes/98_login.php b/app/resources/routes/98_login.php new file mode 100644 index 0000000..4521062 --- /dev/null +++ b/app/resources/routes/98_login.php @@ -0,0 +1,8 @@ +group('/login', function($app) { + $app->post('[/]', [Login::class, 'login']); + $app->get('[/]', [Login::class, 'form']); +}); +$app->get('/logout', [Login::class, 'logout']); diff --git a/app/resources/routes/99_base.php b/app/resources/routes/99_base.php new file mode 100644 index 0000000..c8c764e --- /dev/null +++ b/app/resources/routes/99_base.php @@ -0,0 +1,4 @@ +get('[/]', Base::class); diff --git a/app/resources/routes/api/proyectos.php b/app/resources/routes/api/proyectos.php new file mode 100644 index 0000000..a0bf995 --- /dev/null +++ b/app/resources/routes/api/proyectos.php @@ -0,0 +1,6 @@ +group('/proyectos', function($app) { + $app->get('[/]', [Proyectos::class, 'list']); +}); diff --git a/app/resources/routes/api/ventas.php b/app/resources/routes/api/ventas.php new file mode 100644 index 0000000..361f498 --- /dev/null +++ b/app/resources/routes/api/ventas.php @@ -0,0 +1,13 @@ +group('/ventas', function($app) { + $folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'ventas']); + if (file_exists($folder)) { + $files = new FilesystemIterator($folder); + foreach ($files as $file) { + if ($file->isDir()) { + continue; + } + include_once $file->getRealPath(); + } + } +}); diff --git a/app/resources/routes/api/ventas/precios.php b/app/resources/routes/api/ventas/precios.php new file mode 100644 index 0000000..0ad9ba4 --- /dev/null +++ b/app/resources/routes/api/ventas/precios.php @@ -0,0 +1,6 @@ +group('/precios', function($app) { + $app->post('[/]', [Precios::class, 'proyecto']); +}); diff --git a/app/resources/routes/ventas/cuotas.php b/app/resources/routes/ventas/cuotas.php new file mode 100644 index 0000000..981dccd --- /dev/null +++ b/app/resources/routes/ventas/cuotas.php @@ -0,0 +1,9 @@ +group('/cuotas', function($app) { + $app->get('/pendientes[/]', [Cuotas::class, 'pendientes']); +}); +$app->group('/cuota', function($app) { + $app->post('/depositar[/]', [Cuotas::class, 'depositar']); +}); diff --git a/app/resources/routes/ventas/precios.php b/app/resources/routes/ventas/precios.php new file mode 100644 index 0000000..c035216 --- /dev/null +++ b/app/resources/routes/ventas/precios.php @@ -0,0 +1,6 @@ +group('/precios', function($app) { + $app->get('[/]', Precios::class); +}); diff --git a/app/resources/views/guest.blade.php b/app/resources/views/guest.blade.php new file mode 100644 index 0000000..8acdfe6 --- /dev/null +++ b/app/resources/views/guest.blade.php @@ -0,0 +1,7 @@ +@extends('layout.base') + +@section('page_content') +
    + Bienvenid@ a Incoviba +
    +@endsection diff --git a/app/resources/views/home.blade.php b/app/resources/views/home.blade.php new file mode 100644 index 0000000..06597bf --- /dev/null +++ b/app/resources/views/home.blade.php @@ -0,0 +1,26 @@ +@extends('layout.base') + +@section('page_content') +
    +

    Bienvenid@ {{$user->name}}

    +
    + @if ($cuotas_hoy > 0) + Existe{{$cuotas_hoy > 1 ? 'n' : ''}} {{$cuotas_hoy}} deposito{{$cuotas_hoy > 1 ? 's' : ''}} para hoy. +
    + @endif + @if ($cuotas_pendientes > 0) + + Existe{{$cuotas_pendientes > 1 ? 'n' : ''}} {{$cuotas_pendientes}} cuota{{$cuotas_pendientes > 1 ? 's' : ''}} pendiente{{$cuotas_pendientes > 1 ? 's' : ''}}. + + @endif +
    +
    +
    + @include('home.cuotas_por_vencer') +
    +
    + @include('home.cierres_vigentes') +
    +
    +
    +@endsection diff --git a/app/resources/views/home/cierres_vigentes.blade.php b/app/resources/views/home/cierres_vigentes.blade.php new file mode 100644 index 0000000..fe974e0 --- /dev/null +++ b/app/resources/views/home/cierres_vigentes.blade.php @@ -0,0 +1,24 @@ +

    Cierres Vigentes

    +
    + @foreach($cierres_vigentes as $proyecto => $estados) +
    +
    +
    + {{$proyecto}} [{{$estados['total']}}] +
    +
    +
    Promesados
    +
    {{$estados['promesados']}}
    +
    +
    +
    Pendientes
    +
    {{$estados['pendientes']}}
    +
    +
    +
    Rechazados
    +
    {{$estados['rechazados']}}
    +
    +
    +
    + @endforeach +
    diff --git a/app/resources/views/home/cuotas_por_vencer.blade.php b/app/resources/views/home/cuotas_por_vencer.blade.php new file mode 100644 index 0000000..a0df444 --- /dev/null +++ b/app/resources/views/home/cuotas_por_vencer.blade.php @@ -0,0 +1,22 @@ +

    Cuotas Por Vencer

    +
    + @foreach ($cuotas_por_vencer as $date => $proyectos) +
    +
    +
    + {{$format->localDate($date, "EEE. dd 'de' MMMM 'de' yyyy", true)}} +
    + @foreach ($proyectos as $proyecto => $cuotas) +
    +
    + + {{$proyecto}} + +
    +
    {{$cuotas}}
    +
    + @endforeach +
    +
    + @endforeach +
    diff --git a/app/resources/views/layout/base.blade.php b/app/resources/views/layout/base.blade.php new file mode 100644 index 0000000..9deb8c1 --- /dev/null +++ b/app/resources/views/layout/base.blade.php @@ -0,0 +1,5 @@ + + +@include('layout.head') +@include('layout.body') + diff --git a/app/resources/views/layout/body.blade.php b/app/resources/views/layout/body.blade.php new file mode 100644 index 0000000..fb0cc48 --- /dev/null +++ b/app/resources/views/layout/body.blade.php @@ -0,0 +1,5 @@ + + @include('layout.body.header') + @yield('page_content') + @include('layout.body.footer') + diff --git a/app/resources/views/layout/body/footer.blade.php b/app/resources/views/layout/body/footer.blade.php new file mode 100644 index 0000000..c3b1007 --- /dev/null +++ b/app/resources/views/layout/body/footer.blade.php @@ -0,0 +1,4 @@ +
    + +
    +@include('layout.body.scripts') diff --git a/app/resources/views/layout/body/header.blade.php b/app/resources/views/layout/body/header.blade.php new file mode 100644 index 0000000..48d779d --- /dev/null +++ b/app/resources/views/layout/body/header.blade.php @@ -0,0 +1,7 @@ +
    + + logo + + @include('layout.body.header.menu') +
    +
    diff --git a/app/resources/views/layout/body/header/menu.blade.php b/app/resources/views/layout/body/header/menu.blade.php new file mode 100644 index 0000000..392dc36 --- /dev/null +++ b/app/resources/views/layout/body/header/menu.blade.php @@ -0,0 +1,17 @@ + diff --git a/app/resources/views/layout/body/header/menu/contabilidad.blade.php b/app/resources/views/layout/body/header/menu/contabilidad.blade.php new file mode 100644 index 0000000..7ed6b0c --- /dev/null +++ b/app/resources/views/layout/body/header/menu/contabilidad.blade.php @@ -0,0 +1,8 @@ + diff --git a/app/resources/views/layout/body/header/menu/guest.blade.php b/app/resources/views/layout/body/header/menu/guest.blade.php new file mode 100644 index 0000000..8c7399b --- /dev/null +++ b/app/resources/views/layout/body/header/menu/guest.blade.php @@ -0,0 +1 @@ +Ingresar diff --git a/app/resources/views/layout/body/header/menu/herramientas.blade.php b/app/resources/views/layout/body/header/menu/herramientas.blade.php new file mode 100644 index 0000000..45b0b52 --- /dev/null +++ b/app/resources/views/layout/body/header/menu/herramientas.blade.php @@ -0,0 +1,7 @@ + diff --git a/app/resources/views/layout/body/header/menu/inmobiliarias.blade.php b/app/resources/views/layout/body/header/menu/inmobiliarias.blade.php new file mode 100644 index 0000000..9aa161c --- /dev/null +++ b/app/resources/views/layout/body/header/menu/inmobiliarias.blade.php @@ -0,0 +1 @@ +Inmobiliarias diff --git a/app/resources/views/layout/body/header/menu/operadores.blade.php b/app/resources/views/layout/body/header/menu/operadores.blade.php new file mode 100644 index 0000000..c30b9c0 --- /dev/null +++ b/app/resources/views/layout/body/header/menu/operadores.blade.php @@ -0,0 +1,9 @@ + diff --git a/app/resources/views/layout/body/header/menu/proyectos.blade.php b/app/resources/views/layout/body/header/menu/proyectos.blade.php new file mode 100644 index 0000000..c72eb69 --- /dev/null +++ b/app/resources/views/layout/body/header/menu/proyectos.blade.php @@ -0,0 +1,8 @@ + diff --git a/app/resources/views/layout/body/header/menu/search.blade.php b/app/resources/views/layout/body/header/menu/search.blade.php new file mode 100644 index 0000000..cd4315e --- /dev/null +++ b/app/resources/views/layout/body/header/menu/search.blade.php @@ -0,0 +1 @@ + diff --git a/app/resources/views/layout/body/header/menu/user.blade.php b/app/resources/views/layout/body/header/menu/user.blade.php new file mode 100644 index 0000000..e2bd013 --- /dev/null +++ b/app/resources/views/layout/body/header/menu/user.blade.php @@ -0,0 +1,31 @@ + + +@push('page_scripts') + +@endpush diff --git a/app/resources/views/layout/body/header/menu/ventas.blade.php b/app/resources/views/layout/body/header/menu/ventas.blade.php new file mode 100644 index 0000000..7d669cc --- /dev/null +++ b/app/resources/views/layout/body/header/menu/ventas.blade.php @@ -0,0 +1,41 @@ + diff --git a/app/resources/views/layout/body/scripts.blade.php b/app/resources/views/layout/body/scripts.blade.php new file mode 100644 index 0000000..9b8faa6 --- /dev/null +++ b/app/resources/views/layout/body/scripts.blade.php @@ -0,0 +1,4 @@ + + + +@stack('page_scripts') diff --git a/app/resources/views/layout/body/scripts/datatables.blade.php b/app/resources/views/layout/body/scripts/datatables.blade.php new file mode 100644 index 0000000..980cdf7 --- /dev/null +++ b/app/resources/views/layout/body/scripts/datatables.blade.php @@ -0,0 +1,4 @@ +@push('page_scripts') + + +@endpush diff --git a/app/resources/views/layout/head.blade.php b/app/resources/views/layout/head.blade.php new file mode 100644 index 0000000..98233b9 --- /dev/null +++ b/app/resources/views/layout/head.blade.php @@ -0,0 +1,10 @@ + + + @hasSection('page_title') + Incoviba - @yield('page_title') + @else + Incoviba + @endif + + @include('layout.head.styles') + diff --git a/app/resources/views/layout/head/styles.blade.php b/app/resources/views/layout/head/styles.blade.php new file mode 100644 index 0000000..60ed4f9 --- /dev/null +++ b/app/resources/views/layout/head/styles.blade.php @@ -0,0 +1,3 @@ + + +@stack('page_styles') diff --git a/app/resources/views/layout/head/styles/datatables.blade.php b/app/resources/views/layout/head/styles/datatables.blade.php new file mode 100644 index 0000000..a5dcca3 --- /dev/null +++ b/app/resources/views/layout/head/styles/datatables.blade.php @@ -0,0 +1,3 @@ +@push('page_styles') + +@endpush diff --git a/app/resources/views/login/form.blade.php b/app/resources/views/login/form.blade.php new file mode 100644 index 0000000..31e38ff --- /dev/null +++ b/app/resources/views/login/form.blade.php @@ -0,0 +1,60 @@ +@extends('layout.base') + +@section('page_content') +
    +
    +
    + + +
    +
    + + +
    + +
    +
    +@endsection + +@push('page_scripts') + +@endpush diff --git a/app/resources/views/ventas/cuotas/pendientes.blade.php b/app/resources/views/ventas/cuotas/pendientes.blade.php new file mode 100644 index 0000000..00a4ba1 --- /dev/null +++ b/app/resources/views/ventas/cuotas/pendientes.blade.php @@ -0,0 +1,108 @@ +@extends('layout.base') + +@section('page_content') +
    +

    Cuotas Pendientes

    +
    +
    Total
    +
    {{count($cuotas_pendientes)}}
    +
    {{$format->pesos(array_reduce($cuotas_pendientes, function($sum, $cuota) {return $sum + $cuota['Valor'];}, 0))}}
    +
    +
    ' . ucwords(str_replace('_', ' ', $fuente->tipo)) . '' . $fuente->obj->pie()->venta()->proyecto()->descripcion - . '' . $fuente->obj->pie()->venta()->unidad()->descripcion . '' - . $fuente->obj->pie()->venta()->propietario()->nombreCompleto() - . '' . format('shortDate', $rebote->estado()->fecha) . '' . format('pesos', $rebote->valor('pesos'), true) . '
    + + + + + + + + + + + + + + + + + @foreach($cuotas_pendientes as $cuota) + + + + + + + + + + + + + + @endforeach + +
    ProyectoDepartamentoDepartamento SortValorDíaCuotaPropietarioBancoFecha Cheque (Días)Fecha ISODepositar
    {{$cuota['Proyecto']}} + + {{$cuota['Departamento']}} + + {{str_pad($cuota['Departamento'], 4, '0', STR_PAD_LEFT)}}{{$format->pesos($cuota['Valor'])}}{{$cuota['Dia']}}{{$cuota['Numero']}}{{$cuota['Propietario']}}{{$cuota['Banco']}}{{$cuota['Fecha Cheque']}} ({{$cuota['Vencida']}}){{$cuota['Fecha ISO']}} + +
    + +@endsection + +@include('layout.head.styles.datatables') +@include('layout.body.scripts.datatables') + +@push('page_scripts') + +@endpush diff --git a/app/resources/views/ventas/precios/list.blade.php b/app/resources/views/ventas/precios/list.blade.php new file mode 100644 index 0000000..101e4de --- /dev/null +++ b/app/resources/views/ventas/precios/list.blade.php @@ -0,0 +1,676 @@ +@extends('layout.base') + + +@section('page_title') + Precios - Listado +@endsection + +@section('page_content') +
    +

    Listado de Precios

    +
    +

    +
    +
    +
    +
    + + +
    + +
    +
    +

    + +
    +
    +
    + +@endsection + +@push('page_styles') + +@endpush + +@push('page_scripts') + +@endpush diff --git a/app/setup/app.php b/app/setup/app.php new file mode 100644 index 0000000..a17667e --- /dev/null +++ b/app/setup/app.php @@ -0,0 +1,45 @@ +isDir()) { + continue; + } + $builder->addDefinitions($file->getRealPath()); + } + } + $app = Bridge::create($builder->build()); + $folder = implode(DIRECTORY_SEPARATOR, [ + __DIR__, + 'middlewares' + ]); + if (file_exists($folder)) { + $files = new FilesystemIterator($folder); + foreach ($files as $file) { + if ($file->isDir()) { + continue; + } + require_once $file->getRealPath(); + } + } + return $app; +} +return buildApp(); diff --git a/app/setup/composer.php b/app/setup/composer.php new file mode 100644 index 0000000..b451f96 --- /dev/null +++ b/app/setup/composer.php @@ -0,0 +1,6 @@ +add($app->getContainer()->get(Incoviba\Middleware\Authentication::class)); diff --git a/app/setup/middlewares/98_logs.php b/app/setup/middlewares/98_logs.php new file mode 100644 index 0000000..b81e521 --- /dev/null +++ b/app/setup/middlewares/98_logs.php @@ -0,0 +1,2 @@ +getContainer()->get(Psr\Log\LoggerInterface::class)); diff --git a/app/setup/middlewares/99_routes.php b/app/setup/middlewares/99_routes.php new file mode 100644 index 0000000..a08c17c --- /dev/null +++ b/app/setup/middlewares/99_routes.php @@ -0,0 +1,12 @@ +getContainer()->get('folders')->get('routes'); + $files = new FilesystemIterator($folder); + foreach ($files as $file) { + if ($file->isDir()) { + continue; + } + include_once $file->getRealPath(); + } +} +loadRoutes($app); diff --git a/app/setup/settings/env.php b/app/setup/settings/env.php new file mode 100644 index 0000000..580b775 --- /dev/null +++ b/app/setup/settings/env.php @@ -0,0 +1,2 @@ + function() { + return new DI\Container([ + 'base' => dirname(__FILE__, 3), + 'resources' => DI\String('{base}/resources'), + 'routes' => DI\String('{resources}/routes'), + 'cache' => DI\String('{base}/cache'), + 'templates' => DI\String('{resources}/views') + ]); + } +]; diff --git a/app/setup/settings/urls.php b/app/setup/settings/urls.php new file mode 100644 index 0000000..d07f846 --- /dev/null +++ b/app/setup/settings/urls.php @@ -0,0 +1,21 @@ + function() { + $urls = [ + 'base' => $_ENV['APP_URL'] ?? '', + ]; + $urls['api'] = implode('/', [ + $urls['base'], + 'api' + ]); + $urls['assets'] = implode('/', [ + $urls['base'], + 'assets' + ]); + $urls['images'] = implode('/', [ + $urls['assets'], + 'images' + ]); + return (object) $urls; + } +]; diff --git a/app/setup/setups/database.php b/app/setup/setups/database.php new file mode 100644 index 0000000..3cfd071 --- /dev/null +++ b/app/setup/setups/database.php @@ -0,0 +1,18 @@ + function(ContainerInterface $container) { + return new Incoviba\Common\Implement\Database\MySQL( + $container->has('MYSQL_HOST') ? $container->get('MYSQL_HOST') : 'db', + $container->get('MYSQL_DATABASE'), + $container->get('MYSQL_USER'), + $container->get('MYSQL_PASSWORD') + ); + }, + Incoviba\Common\Define\Connection::class => function(ContainerInterface $container) { + return new Incoviba\Common\Implement\Connection( + $container->get(Incoviba\Common\Define\Database::class) + ); + } +]; diff --git a/app/setup/setups/logs.php b/app/setup/setups/logs.php new file mode 100644 index 0000000..0ccd933 --- /dev/null +++ b/app/setup/setups/logs.php @@ -0,0 +1,32 @@ + function(ContainerInterface $container) { + return new Monolog\Logger('incoviba', [ + new Monolog\Handler\FilterHandler( + (new Monolog\Handler\RotatingFileHandler('/logs/debug.log')) + ->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)), + Monolog\Level::Debug, + Monolog\Level::Notice + ), + new Monolog\Handler\FilterHandler( + (new Monolog\Handler\RotatingFileHandler('/logs/error.log')) + ->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)), + Monolog\Level::Warning, + Monolog\Level::Error + ), + new Monolog\Handler\FilterHandler( + (new Monolog\Handler\RotatingFileHandler('/logs/critical.log')) + ->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)), + Monolog\Level::Critical + ) + ], [ + $container->get(Monolog\Processor\PsrLogMessageProcessor::class), + $container->get(Monolog\Processor\WebProcessor::class), + $container->get(Monolog\Processor\IntrospectionProcessor::class), + $container->get(Monolog\Processor\MemoryUsageProcessor::class), + $container->get(Monolog\Processor\MemoryPeakUsageProcessor::class) + ]); + } +]; diff --git a/app/setup/setups/middlewares.php b/app/setup/setups/middlewares.php new file mode 100644 index 0000000..5c5f23f --- /dev/null +++ b/app/setup/setups/middlewares.php @@ -0,0 +1,15 @@ + function(ContainerInterface $container) { + return $container->get(Nyholm\Psr7\Factory\Psr17Factory::class); + }, + Incoviba\Middleware\Authentication::class => function(ContainerInterface $container) { + return new Incoviba\Middleware\Authentication( + $container->get(Psr\Http\Message\ResponseFactoryInterface::class), + $container->get(Incoviba\Service\Login::class), + implode('/', [$container->get('APP_URL'), 'login']) + ); + } +]; diff --git a/app/setup/setups/services.php b/app/setup/setups/services.php new file mode 100644 index 0000000..3f4906f --- /dev/null +++ b/app/setup/setups/services.php @@ -0,0 +1,14 @@ + function(ContainerInterface $container) { + return new Incoviba\Service\Login( + $container->get(Incoviba\Repository\Login::class), + $container->get('COOKIE_NAME'), + $container->get('MAX_LOGIN_HOURS'), + $container->has('COOKIE_DOMAIN') ? $container->get('COOKIE_DOMAIN') : '', + $container->has('COOKIE_PATH') ? $container->get('COOKIE_PATH') : '' + ); + } +]; diff --git a/app/setup/setups/views.php b/app/setup/setups/views.php new file mode 100644 index 0000000..41cf638 --- /dev/null +++ b/app/setup/setups/views.php @@ -0,0 +1,23 @@ + function(ContainerInterface $container) { + $folders = $container->get('folders'); + $global_variables = [ + 'urls' => $container->get('urls'), + 'money_url' => '', + 'login' => $container->get(Incoviba\Service\Login::class), + 'format' => $container->get(Incoviba\Service\Format::class), + ]; + if ($global_variables['login']->isIn()) { + $global_variables['user'] = $global_variables['login']->getUser(); + } + return new Incoviba\Common\Alias\View( + $folders->get('templates'), + $folders->get('cache'), + null, + $global_variables + ); + } +]; diff --git a/app/src/Controller/Base.php b/app/src/Controller/Base.php new file mode 100644 index 0000000..2cd225d --- /dev/null +++ b/app/src/Controller/Base.php @@ -0,0 +1,90 @@ +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; + } +} diff --git a/app/src/Controller/Login.php b/app/src/Controller/Login.php new file mode 100644 index 0000000..70467f5 --- /dev/null +++ b/app/src/Controller/Login.php @@ -0,0 +1,55 @@ +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'); + } +} diff --git a/app/src/Controller/Proyectos.php b/app/src/Controller/Proyectos.php new file mode 100644 index 0000000..9ef8c47 --- /dev/null +++ b/app/src/Controller/Proyectos.php @@ -0,0 +1,21 @@ +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'); + } +} diff --git a/app/src/Controller/Users.php b/app/src/Controller/Users.php new file mode 100644 index 0000000..cfa82ff --- /dev/null +++ b/app/src/Controller/Users.php @@ -0,0 +1,11 @@ +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'); + } +} diff --git a/app/src/Controller/Ventas/Precios.php b/app/src/Controller/Ventas/Precios.php new file mode 100644 index 0000000..c4ef615 --- /dev/null +++ b/app/src/Controller/Ventas/Precios.php @@ -0,0 +1,24 @@ +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'); + } +} diff --git a/app/src/Middleware/Authentication.php b/app/src/Middleware/Authentication.php new file mode 100644 index 0000000..32d3e9f --- /dev/null +++ b/app/src/Middleware/Authentication.php @@ -0,0 +1,48 @@ +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; + } +} diff --git a/app/src/Model/Banco.php b/app/src/Model/Banco.php new file mode 100644 index 0000000..1852ff2 --- /dev/null +++ b/app/src/Model/Banco.php @@ -0,0 +1,16 @@ + $this->nombre ?? '' + ]); + } +} diff --git a/app/src/Model/Comuna.php b/app/src/Model/Comuna.php new file mode 100644 index 0000000..3bf746d --- /dev/null +++ b/app/src/Model/Comuna.php @@ -0,0 +1,18 @@ + $this->descripcion, + 'provincia' => $this->provincia + ]); + } +} diff --git a/app/src/Model/Direccion.php b/app/src/Model/Direccion.php new file mode 100644 index 0000000..7795ad5 --- /dev/null +++ b/app/src/Model/Direccion.php @@ -0,0 +1,22 @@ + $this->calle, + 'numero' => $this->numero, + 'extra' => $this->extra, + 'comuna' => $this->comuna + ]); + } +} diff --git a/app/src/Model/Inmobiliaria.php b/app/src/Model/Inmobiliaria.php new file mode 100644 index 0000000..cc7778c --- /dev/null +++ b/app/src/Model/Inmobiliaria.php @@ -0,0 +1,38 @@ +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 ?? '' + ]; + } +} diff --git a/app/src/Model/Inmobiliaria/TipoSociedad.php b/app/src/Model/Inmobiliaria/TipoSociedad.php new file mode 100644 index 0000000..dc71047 --- /dev/null +++ b/app/src/Model/Inmobiliaria/TipoSociedad.php @@ -0,0 +1,16 @@ + $this->abreviacion + ]); + } +} diff --git a/app/src/Model/Login.php b/app/src/Model/Login.php new file mode 100644 index 0000000..fb66590 --- /dev/null +++ b/app/src/Model/Login.php @@ -0,0 +1,25 @@ + $this->user->id, + 'selector' => $this->selector, + 'token' => $this->token, + 'date_time' => $this->dateTime->format('Y-m-d H:i:s'), + 'status' => $this->status + ]); + } +} diff --git a/app/src/Model/Provincia.php b/app/src/Model/Provincia.php new file mode 100644 index 0000000..1f2f387 --- /dev/null +++ b/app/src/Model/Provincia.php @@ -0,0 +1,18 @@ + $this->descripcion, + 'region' => $this->region + ]); + } +} diff --git a/app/src/Model/Proyecto.php b/app/src/Model/Proyecto.php new file mode 100644 index 0000000..f9f21d2 --- /dev/null +++ b/app/src/Model/Proyecto.php @@ -0,0 +1,32 @@ + $this->inmobiliaria, + 'descripcion' => $this->descripcion, + 'direccion' => $this->direccion, + 'terreno' => $this->terreno, + 'superficie' => $this->superficie, + 'corredor' => $this->corredor, + 'pisos' => $this->pisos, + 'subterraneos' => $this->subterraneos + ]); + } +} diff --git a/app/src/Model/Proyecto/ProyectoTipoUnidad.php b/app/src/Model/Proyecto/ProyectoTipoUnidad.php new file mode 100644 index 0000000..a755bb7 --- /dev/null +++ b/app/src/Model/Proyecto/ProyectoTipoUnidad.php @@ -0,0 +1,42 @@ +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 + ]); + } +} diff --git a/app/src/Model/Proyecto/Superficie.php b/app/src/Model/Proyecto/Superficie.php new file mode 100644 index 0000000..72d6e5f --- /dev/null +++ b/app/src/Model/Proyecto/Superficie.php @@ -0,0 +1,8 @@ + $this->descripcion, + 'numeral' => $this->numeral, + 'numeracion' => $this->numeracion ?? 0 + ]); + } +} diff --git a/app/src/Model/Role.php b/app/src/Model/Role.php new file mode 100644 index 0000000..e27c6a9 --- /dev/null +++ b/app/src/Model/Role.php @@ -0,0 +1,7 @@ + $this->descripcion + ]); + } +} diff --git a/app/src/Model/User.php b/app/src/Model/User.php new file mode 100644 index 0000000..2647b88 --- /dev/null +++ b/app/src/Model/User.php @@ -0,0 +1,28 @@ +password); + } + public function isAdmin(): bool + { + return false; + } + + public function jsonSerialize(): mixed + { + return array_merge(parent::jsonSerialize(), [ + 'name' => $this->name + ]); + } +} diff --git a/app/src/Model/Venta/Cierre.php b/app/src/Model/Venta/Cierre.php new file mode 100644 index 0000000..25d3009 --- /dev/null +++ b/app/src/Model/Venta/Cierre.php @@ -0,0 +1,26 @@ + $this->proyecto->id, + 'precio' => $this->precio, + 'date_time' => $this->dateTime->format('Y-m-d H:i:s'), + 'relacionado' => $this->relacionado, + 'propietario' => $this->propietario->rut + ]); + } +} diff --git a/app/src/Model/Venta/Cuota.php b/app/src/Model/Venta/Cuota.php new file mode 100644 index 0000000..188f4c0 --- /dev/null +++ b/app/src/Model/Venta/Cuota.php @@ -0,0 +1,38 @@ + $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 ?? '' + ]); + } +} diff --git a/app/src/Model/Venta/Datos.php b/app/src/Model/Venta/Datos.php new file mode 100644 index 0000000..b9a7ebd --- /dev/null +++ b/app/src/Model/Venta/Datos.php @@ -0,0 +1,27 @@ + $this->sexo ?? '', + 'estado_civil' => $this->estado_civil ?? '', + 'profesion' => $this->profesion ?? '', + 'direccion' => $this->direccion ?? '', + 'telefono' => $this->telefono ?? '', + 'email' => $this->email ?? '' + ]; + } +} diff --git a/app/src/Model/Venta/EstadoPago.php b/app/src/Model/Venta/EstadoPago.php new file mode 100644 index 0000000..e94f8d8 --- /dev/null +++ b/app/src/Model/Venta/EstadoPago.php @@ -0,0 +1,22 @@ + $this->pago->id, + 'fecha' => $this->fecha->format('Y-m-d'), + 'tipo_estado_pago_id' => $this->tipoEstadoPago->id + ]); + } + +} diff --git a/app/src/Model/Venta/EstadoPrecio.php b/app/src/Model/Venta/EstadoPrecio.php new file mode 100644 index 0000000..815793f --- /dev/null +++ b/app/src/Model/Venta/EstadoPrecio.php @@ -0,0 +1,21 @@ + $this->precio->id, + 'tipo_estado_precio' => $this->tipoEstadoPrecio, + 'fecha' => $this->fecha->format('Y-m-d') + ]); + } +} diff --git a/app/src/Model/Venta/Pago.php b/app/src/Model/Venta/Pago.php new file mode 100644 index 0000000..08f5da9 --- /dev/null +++ b/app/src/Model/Venta/Pago.php @@ -0,0 +1,32 @@ + $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 ?? '' + ]); + } +} diff --git a/app/src/Model/Venta/Pie.php b/app/src/Model/Venta/Pie.php new file mode 100644 index 0000000..3a1f4ad --- /dev/null +++ b/app/src/Model/Venta/Pie.php @@ -0,0 +1,27 @@ + $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 ?? '' + ]); + } +} diff --git a/app/src/Model/Venta/Precio.php b/app/src/Model/Venta/Precio.php new file mode 100644 index 0000000..0b2094e --- /dev/null +++ b/app/src/Model/Venta/Precio.php @@ -0,0 +1,23 @@ + $this->unidad, + 'valor' => $this->valor, + 'estado_precio' => $this->current ?? [], + 'estados' => $this->estados ?? null + ]); + } +} diff --git a/app/src/Model/Venta/Propietario.php b/app/src/Model/Venta/Propietario.php new file mode 100644 index 0000000..77300eb --- /dev/null +++ b/app/src/Model/Venta/Propietario.php @@ -0,0 +1,46 @@ +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 ?? '' + ]); + } +} diff --git a/app/src/Model/Venta/TipoEstadoPago.php b/app/src/Model/Venta/TipoEstadoPago.php new file mode 100644 index 0000000..2d00621 --- /dev/null +++ b/app/src/Model/Venta/TipoEstadoPago.php @@ -0,0 +1,8 @@ + $this->orden + ]); + } +} diff --git a/app/src/Model/Venta/Unidad.php b/app/src/Model/Venta/Unidad.php new file mode 100644 index 0000000..3040504 --- /dev/null +++ b/app/src/Model/Venta/Unidad.php @@ -0,0 +1,25 @@ + $this->subtipo, + 'piso' => $this->piso, + 'descripcion' => $this->descripcion, + 'orientacion' => $this->orientacion, + 'proyecto_tipo_unidad' => $this->proyectoTipoUnidad + ]); + } +} diff --git a/app/src/Repository/Banco.php b/app/src/Repository/Banco.php new file mode 100644 index 0000000..7a35492 --- /dev/null +++ b/app/src/Repository/Banco.php @@ -0,0 +1,35 @@ +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); + } +} diff --git a/app/src/Repository/Comuna.php b/app/src/Repository/Comuna.php new file mode 100644 index 0000000..ddb54e1 --- /dev/null +++ b/app/src/Repository/Comuna.php @@ -0,0 +1,51 @@ +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]); + } +} diff --git a/app/src/Repository/Direccion.php b/app/src/Repository/Direccion.php new file mode 100644 index 0000000..87bd955 --- /dev/null +++ b/app/src/Repository/Direccion.php @@ -0,0 +1,48 @@ +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]); + } +} diff --git a/app/src/Repository/Inmobiliaria.php b/app/src/Repository/Inmobiliaria.php new file mode 100644 index 0000000..7ae90c6 --- /dev/null +++ b/app/src/Repository/Inmobiliaria.php @@ -0,0 +1,55 @@ +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); + } +} diff --git a/app/src/Repository/Inmobiliaria/TipoSociedad.php b/app/src/Repository/Inmobiliaria/TipoSociedad.php new file mode 100644 index 0000000..0d2a05f --- /dev/null +++ b/app/src/Repository/Inmobiliaria/TipoSociedad.php @@ -0,0 +1,36 @@ +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); + } +} diff --git a/app/src/Repository/Login.php b/app/src/Repository/Login.php new file mode 100644 index 0000000..0cfa3e4 --- /dev/null +++ b/app/src/Repository/Login.php @@ -0,0 +1,77 @@ +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]); + } +} diff --git a/app/src/Repository/Provincia.php b/app/src/Repository/Provincia.php new file mode 100644 index 0000000..3e8406e --- /dev/null +++ b/app/src/Repository/Provincia.php @@ -0,0 +1,51 @@ +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]); + } +} diff --git a/app/src/Repository/Proyecto.php b/app/src/Repository/Proyecto.php new file mode 100644 index 0000000..0c8d4e8 --- /dev/null +++ b/app/src/Repository/Proyecto.php @@ -0,0 +1,88 @@ +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); + } +} diff --git a/app/src/Repository/Proyecto/ProyectoTipoUnidad.php b/app/src/Repository/Proyecto/ProyectoTipoUnidad.php new file mode 100644 index 0000000..1500f26 --- /dev/null +++ b/app/src/Repository/Proyecto/ProyectoTipoUnidad.php @@ -0,0 +1,54 @@ +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); + } +} diff --git a/app/src/Repository/Region.php b/app/src/Repository/Region.php new file mode 100644 index 0000000..34287e6 --- /dev/null +++ b/app/src/Repository/Region.php @@ -0,0 +1,53 @@ +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]); + } +} diff --git a/app/src/Repository/User.php b/app/src/Repository/User.php new file mode 100644 index 0000000..97ae151 --- /dev/null +++ b/app/src/Repository/User.php @@ -0,0 +1,46 @@ +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]); + } +} diff --git a/app/src/Repository/Venta/Cierre.php b/app/src/Repository/Venta/Cierre.php new file mode 100644 index 0000000..6366347 --- /dev/null +++ b/app/src/Repository/Venta/Cierre.php @@ -0,0 +1,82 @@ +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; + } +} diff --git a/app/src/Repository/Venta/Cuota.php b/app/src/Repository/Venta/Cuota.php new file mode 100644 index 0000000..341d554 --- /dev/null +++ b/app/src/Repository/Venta/Cuota.php @@ -0,0 +1,161 @@ +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); + } +} diff --git a/app/src/Repository/Venta/EstadoPago.php b/app/src/Repository/Venta/EstadoPago.php new file mode 100644 index 0000000..406647f --- /dev/null +++ b/app/src/Repository/Venta/EstadoPago.php @@ -0,0 +1,67 @@ +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]); + } +} diff --git a/app/src/Repository/Venta/EstadoPrecio.php b/app/src/Repository/Venta/EstadoPrecio.php new file mode 100644 index 0000000..c223e30 --- /dev/null +++ b/app/src/Repository/Venta/EstadoPrecio.php @@ -0,0 +1,65 @@ +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]); + } +} diff --git a/app/src/Repository/Venta/Pago.php b/app/src/Repository/Venta/Pago.php new file mode 100644 index 0000000..ec9b6e6 --- /dev/null +++ b/app/src/Repository/Venta/Pago.php @@ -0,0 +1,73 @@ +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); + } +} diff --git a/app/src/Repository/Venta/Pie.php b/app/src/Repository/Venta/Pie.php new file mode 100644 index 0000000..37b8d2c --- /dev/null +++ b/app/src/Repository/Venta/Pie.php @@ -0,0 +1,60 @@ +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); + } +} diff --git a/app/src/Repository/Venta/Precio.php b/app/src/Repository/Venta/Precio.php new file mode 100644 index 0000000..f7bb16d --- /dev/null +++ b/app/src/Repository/Venta/Precio.php @@ -0,0 +1,55 @@ +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]); + } +} diff --git a/app/src/Repository/Venta/Propietario.php b/app/src/Repository/Venta/Propietario.php new file mode 100644 index 0000000..8e0dce6 --- /dev/null +++ b/app/src/Repository/Venta/Propietario.php @@ -0,0 +1,82 @@ +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); + } +} diff --git a/app/src/Repository/Venta/TipoEstadoPago.php b/app/src/Repository/Venta/TipoEstadoPago.php new file mode 100644 index 0000000..80f8a0b --- /dev/null +++ b/app/src/Repository/Venta/TipoEstadoPago.php @@ -0,0 +1,40 @@ +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]); + } +} diff --git a/app/src/Repository/Venta/TipoEstadoPrecio.php b/app/src/Repository/Venta/TipoEstadoPrecio.php new file mode 100644 index 0000000..1955b2e --- /dev/null +++ b/app/src/Repository/Venta/TipoEstadoPrecio.php @@ -0,0 +1,35 @@ +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); + } +} diff --git a/app/src/Repository/Venta/TipoPago.php b/app/src/Repository/Venta/TipoPago.php new file mode 100644 index 0000000..dda6865 --- /dev/null +++ b/app/src/Repository/Venta/TipoPago.php @@ -0,0 +1,35 @@ +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); + } +} diff --git a/app/src/Repository/Venta/TipoUnidad.php b/app/src/Repository/Venta/TipoUnidad.php new file mode 100644 index 0000000..13474bb --- /dev/null +++ b/app/src/Repository/Venta/TipoUnidad.php @@ -0,0 +1,39 @@ +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); + } +} + + diff --git a/app/src/Repository/Venta/Unidad.php b/app/src/Repository/Venta/Unidad.php new file mode 100644 index 0000000..4783c40 --- /dev/null +++ b/app/src/Repository/Venta/Unidad.php @@ -0,0 +1,47 @@ +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); + } +} diff --git a/app/src/Service/Format.php b/app/src/Service/Format.php new file mode 100644 index 0000000..ec9177b --- /dev/null +++ b/app/src/Service/Format.php @@ -0,0 +1,24 @@ +setPattern($format); + return $formatter->format($date); + + } + public function pesos(string $valor): string + { + return '$' . number_format($valor, 0, ',', '.'); + } +} diff --git a/app/src/Service/Login.php b/app/src/Service/Login.php new file mode 100644 index 0000000..175be0d --- /dev/null +++ b/app/src/Service/Login.php @@ -0,0 +1,135 @@ +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]; + } +} diff --git a/app/src/Service/Ventas/Pago.php b/app/src/Service/Ventas/Pago.php new file mode 100644 index 0000000..f931f38 --- /dev/null +++ b/app/src/Service/Ventas/Pago.php @@ -0,0 +1,31 @@ +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; + } + } +} diff --git a/app/src/Service/Ventas/Precio.php b/app/src/Service/Ventas/Precio.php new file mode 100644 index 0000000..b03174a --- /dev/null +++ b/app/src/Service/Ventas/Precio.php @@ -0,0 +1,19 @@ +precioRepository->fetchByProyecto($proyecto_id); + foreach ($precios as &$precio) { + $precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id); + $precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id); + } + return $precios; + } +} From 43cd955061293eb81e88e8b7dc76cb6b94410895 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Tue, 25 Jul 2023 17:03:57 -0400 Subject: [PATCH 006/163] Venta->Listado->Cierres --- app/resources/routes/api/ventas/cierres.php | 6 + app/resources/routes/ventas/cierres.php | 6 + .../views/ventas/cierres/list.blade.php | 360 ++++++++++++++++++ app/src/Controller/Ventas/Cierres.php | 24 ++ app/src/Model/Venta/Cierre.php | 12 +- app/src/Model/Venta/EstadoCierre.php | 21 + app/src/Model/Venta/TipoEstadoCierre.php | 16 + app/src/Repository/Venta/Cierre.php | 13 +- app/src/Repository/Venta/EstadoCierre.php | 66 ++++ app/src/Repository/Venta/TipoEstadoCierre.php | 40 ++ app/src/Repository/Venta/Unidad.php | 14 +- app/src/Service/Ventas/Cierre.php | 23 ++ 12 files changed, 596 insertions(+), 5 deletions(-) create mode 100644 app/resources/routes/api/ventas/cierres.php create mode 100644 app/resources/routes/ventas/cierres.php create mode 100644 app/resources/views/ventas/cierres/list.blade.php create mode 100644 app/src/Controller/Ventas/Cierres.php create mode 100644 app/src/Model/Venta/EstadoCierre.php create mode 100644 app/src/Model/Venta/TipoEstadoCierre.php create mode 100644 app/src/Repository/Venta/EstadoCierre.php create mode 100644 app/src/Repository/Venta/TipoEstadoCierre.php create mode 100644 app/src/Service/Ventas/Cierre.php diff --git a/app/resources/routes/api/ventas/cierres.php b/app/resources/routes/api/ventas/cierres.php new file mode 100644 index 0000000..c242b05 --- /dev/null +++ b/app/resources/routes/api/ventas/cierres.php @@ -0,0 +1,6 @@ +group('/cierres', function($app) { + $app->post('[/]', [Cierres::class, 'proyecto']); +}); diff --git a/app/resources/routes/ventas/cierres.php b/app/resources/routes/ventas/cierres.php new file mode 100644 index 0000000..52c0e2d --- /dev/null +++ b/app/resources/routes/ventas/cierres.php @@ -0,0 +1,6 @@ +group('/cierres', function($app) { + $app->get('[/]', Cierres::class); +}); diff --git a/app/resources/views/ventas/cierres/list.blade.php b/app/resources/views/ventas/cierres/list.blade.php new file mode 100644 index 0000000..334d2bf --- /dev/null +++ b/app/resources/views/ventas/cierres/list.blade.php @@ -0,0 +1,360 @@ +@extends('layout.base') + + +@section('page_title') + Cierres - Listado +@endsection + +@section('page_content') +
    +

    Listado de Cierres

    + + + + + + + +
    Proyecto
    +
    +@endsection + +@push('page_styles') + +@endpush + +@push('page_scripts') + +@endpush diff --git a/app/src/Controller/Ventas/Cierres.php b/app/src/Controller/Ventas/Cierres.php new file mode 100644 index 0000000..7c4d325 --- /dev/null +++ b/app/src/Controller/Ventas/Cierres.php @@ -0,0 +1,24 @@ +render($response, 'ventas.cierres.list'); + } + public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Ventas\Cierre $service): ResponseInterface + { + $body = $request->getBody(); + $json = json_decode($body->getContents()); + $proyecto_id = $json->proyecto_id; + $cierres = $service->getByProyecto($proyecto_id); + $response->getBody()->write(json_encode(['cierres' => $cierres, 'total' => count($cierres)])); + return $response->withHeader('Content-Type', 'application/json'); + } +} diff --git a/app/src/Model/Venta/Cierre.php b/app/src/Model/Venta/Cierre.php index 25d3009..8eb00f5 100644 --- a/app/src/Model/Venta/Cierre.php +++ b/app/src/Model/Venta/Cierre.php @@ -13,14 +13,22 @@ class Cierre extends Ideal\Model public bool $relacionado; public Propietario $propietario; + public array $estados = []; + public ?EstadoCierre $current = null; + + public array $unidades = []; + public function jsonSerialize(): mixed { return array_merge(parent::jsonSerialize(), [ - 'proyecto_id' => $this->proyecto->id, + 'proyecto' => $this->proyecto, 'precio' => $this->precio, 'date_time' => $this->dateTime->format('Y-m-d H:i:s'), 'relacionado' => $this->relacionado, - 'propietario' => $this->propietario->rut + 'propietario' => $this->propietario->rut, + 'estados' => $this->estados, + 'estado_cierre' => $this->current, + 'unidades' => $this->unidades ]); } } diff --git a/app/src/Model/Venta/EstadoCierre.php b/app/src/Model/Venta/EstadoCierre.php new file mode 100644 index 0000000..2a94606 --- /dev/null +++ b/app/src/Model/Venta/EstadoCierre.php @@ -0,0 +1,21 @@ + $this->cierre->id, + 'tipo_estado_cierre' => $this->tipoEstadoCierre, + 'fecha' => $this->fecha->format('Y-m-d') + ]); + } +} diff --git a/app/src/Model/Venta/TipoEstadoCierre.php b/app/src/Model/Venta/TipoEstadoCierre.php new file mode 100644 index 0000000..58a6d5b --- /dev/null +++ b/app/src/Model/Venta/TipoEstadoCierre.php @@ -0,0 +1,16 @@ + $this->vigente + ]); + } +} diff --git a/app/src/Repository/Venta/Cierre.php b/app/src/Repository/Venta/Cierre.php index 6366347..6de51f9 100644 --- a/app/src/Repository/Venta/Cierre.php +++ b/app/src/Repository/Venta/Cierre.php @@ -71,7 +71,7 @@ FROM `{$this->getTable()}` a 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` + JOIN `proyecto` ON `proyecto`.`id` = a.`proyecto` AND tec.`descripcion` NOT IN ('revisado') GROUP BY `proyecto`.`descripcion`, tec.`descripcion`"; $results = $this->connection->execute($query)->fetchAll(PDO::FETCH_ASSOC); if ($results === false) { @@ -79,4 +79,15 @@ GROUP BY `proyecto`.`descripcion`, tec.`descripcion`"; } return $results; } + public function fetchByProyecto(int $proyecto_id): array + { + $query = "SELECT a.* +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` +WHERE `proyecto` = ? AND tec.`descripcion` NOT IN ('revisado')"; + return $this->fetchMany($query, [$proyecto_id]); + } } diff --git a/app/src/Repository/Venta/EstadoCierre.php b/app/src/Repository/Venta/EstadoCierre.php new file mode 100644 index 0000000..ed82284 --- /dev/null +++ b/app/src/Repository/Venta/EstadoCierre.php @@ -0,0 +1,66 @@ +setTable('estado_cierre'); + } + + public function create(?array $data = null): Define\Model + { + $map = [ + 'cierre' => [ + 'function' => function($data) { + return $this->cierreRepository->fetchById($data['cierre']); + } + ], + 'tipo' => [ + 'property' => 'tipoEstadoCierre', + 'function' => function($data) { + return $this->tipoEstadoCierreRepository->fetchById($data['tipo']); + } + ], + 'fecha' => [ + 'function' => function($data) { + return new DateTimeImmutable($data['fecha']); + } + ] + ]; + return $this->parseData(new Model\Venta\EstadoCierre(), $data, $map); + } + public function save(Define\Model $model): Define\Model + { + $model->id = $this->saveNew( + ['cierre', 'tipo', 'fecha'], + [$model->cierre->id, $model->tipoEstadoCierre->id, $model->fecha->format('Y-m-d')] + ); + return $model; + } + public function edit(Define\Model $model, array $new_data): Define\Model + { + return $this->update($model, ['cierre', 'tipo', 'fecha'], $new_data); + } + + public function fetchByCierre(int $cierre_id): array + { + $query = "SELECT * FROM `{$this->getTable()}` WHERE `cierre` = ?"; + return $this->fetchMany($query, [$cierre_id]); + } + public function fetchCurrentByCierre(int $cierre_id): Define\Model + { + $query = "SELECT e1.* +FROM `{$this->getTable()}` e1 + JOIN (SELECT MAX(`id`) AS 'id', `cierre` FROM `{$this->getTable()}` GROUP BY `cierre`) e0 ON e0.`id` = e1.`id` +WHERE e1.`cierre` = ?"; + return $this->fetchOne($query, [$cierre_id]); + } +} diff --git a/app/src/Repository/Venta/TipoEstadoCierre.php b/app/src/Repository/Venta/TipoEstadoCierre.php new file mode 100644 index 0000000..7883c82 --- /dev/null +++ b/app/src/Repository/Venta/TipoEstadoCierre.php @@ -0,0 +1,40 @@ +setTable('tipo_estado_cierre'); + } + + public function create(?array $data = null): Define\Model + { + $map = [ + 'descripcion' => [], + 'vigente' => [ + 'function' => function($data) { + return $data['vigente'] != 0; + } + ] + ]; + return $this->parseData(new Model\Venta\TipoEstadoCierre(), $data, $map); + } + public function save(Define\Model $model): Define\Model + { + $model->id = $this->saveNew( + ['descripcion', 'vigente'], + [$model->descripcion, $model->vigente ? 1 : 0] + ); + return $model; + } + public function edit(Define\Model $model, array $new_data): Define\Model + { + return $this->update($model, ['descripcion', 'vigente'], $new_data); + } +} diff --git a/app/src/Repository/Venta/Unidad.php b/app/src/Repository/Venta/Unidad.php index 4783c40..271997f 100644 --- a/app/src/Repository/Venta/Unidad.php +++ b/app/src/Repository/Venta/Unidad.php @@ -30,7 +30,6 @@ class Unidad extends Ideal\Repository ]; return $this->parseData(new Model\Venta\Unidad(), $data, $map); } - public function save(Define\Model $model): Define\Model { $model->id = $this->saveNew( @@ -39,9 +38,20 @@ class Unidad extends Ideal\Repository ); return $model; } - public function edit(Define\Model $model, array $new_data): Define\Model { return $this->update($model, ['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'], $new_data); } + + public function fetchByCierre(int $cierre_id): array + { + $query = "SELECT a.* +FROM `{$this->getTable()}` a + JOIN `unidad_cierre` uc ON uc.`unidad` = a.`id` + JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt` + JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo` +WHERE uc.`cierre` = ? +ORDER BY tu.`orden`, LPAD(a.`descripcion`, 4, '0')"; + return $this->fetchMany($query, [$cierre_id]); + } } diff --git a/app/src/Service/Ventas/Cierre.php b/app/src/Service/Ventas/Cierre.php new file mode 100644 index 0000000..c066022 --- /dev/null +++ b/app/src/Service/Ventas/Cierre.php @@ -0,0 +1,23 @@ +cierreRepository->fetchByProyecto($proyecto_id); + foreach ($cierres as &$cierre) { + $cierre->estados = $this->estadoCierreRepository->fetchByCierre($cierre->id); + $cierre->current = $this->estadoCierreRepository->fetchCurrentByCierre($cierre->id); + $cierre->unidades = $this->unidadRepository->fetchByCierre($cierre->id); + } + return $cierres; + } +} From 38383f52958b50a75149991608f0c7c1f2b1b9b7 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Tue, 25 Jul 2023 20:25:28 -0400 Subject: [PATCH 007/163] Accordion --- .../views/ventas/cierres/list.blade.php | 185 ++++++------------ 1 file changed, 59 insertions(+), 126 deletions(-) diff --git a/app/resources/views/ventas/cierres/list.blade.php b/app/resources/views/ventas/cierres/list.blade.php index 334d2bf..859ca54 100644 --- a/app/resources/views/ventas/cierres/list.blade.php +++ b/app/resources/views/ventas/cierres/list.blade.php @@ -8,17 +8,14 @@ @section('page_content')

    Listado de Cierres

    - - - - - - - -
    Proyecto
    +

    Proyectos

    +
    @endsection +@include('layout.head.styles.datatables') +@include('layout.body.scripts.datatables') + @push('page_styles') +@endpush + +@push('page_scripts') + +@endpush diff --git a/app/resources/views/ventas/add.blade.php b/app/resources/views/ventas/add.blade.php index 75bb644..7359c0a 100644 --- a/app/resources/views/ventas/add.blade.php +++ b/app/resources/views/ventas/add.blade.php @@ -3,7 +3,7 @@ @section('page_content')

    Nueva Venta

    -
    +
    diff --git a/app/resources/views/ventas/precios/list.blade.php b/app/resources/views/ventas/precios/list.blade.php index 5820b22..5b4ae22 100644 --- a/app/resources/views/ventas/precios/list.blade.php +++ b/app/resources/views/ventas/precios/list.blade.php @@ -75,48 +75,46 @@ @push('page_scripts') @endpush diff --git a/app/src/Controller/API/Proyectos.php b/app/src/Controller/API/Proyectos.php index d547dae..5ed2152 100644 --- a/app/src/Controller/API/Proyectos.php +++ b/app/src/Controller/API/Proyectos.php @@ -21,6 +21,19 @@ class Proyectos } catch (EmptyResult) {} return $this->withJson($response, $output); } + public function escriturando(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface + { + $output = [ + 'total' => 0, + 'proyectos' => [] + ]; + try { + $proyectos = $proyectoRepository->fetchAllEscriturando(); + $output['proyectos'] = $proyectos; + $output['total'] = count($proyectos); + } catch (EmptyResult) {} + return $this->withJson($response, $output); + } public function unidades(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface { $output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0]; diff --git a/app/src/Controller/API/Ventas.php b/app/src/Controller/API/Ventas.php new file mode 100644 index 0000000..bdfc853 --- /dev/null +++ b/app/src/Controller/API/Ventas.php @@ -0,0 +1,138 @@ +getBody(); + $json = json_decode($body->getContents()); + $proyecto_id = $json->proyecto_id; + $output = [ + 'proyecto' => [ + 'id' => $proyecto_id + ], + 'total' => 0 + ]; + try { + $ventas = $service->fetchActivaByProyecto($proyecto_id); + $output['ventas'] = array_map(function(Model\Venta $venta) {return $venta->id;}, $ventas); + $output['proyecto']['descripcion'] = $ventas[0]->proyecto()->descripcion; + $output['total'] = count($ventas); + } catch (EmptyResult) {} + return $this->withJson($response, $output); + } + public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, int $venta_id): ResponseInterface + { + try { + $venta = $service->getById($venta_id); + $output = compact('venta'); + } catch (EmptyResult $exception) { + $output = [ + 'error' => [ + 'code' => $exception->getCode(), + 'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage()) + ] + ]; + } + return $this->withJson($response, $output); + } + public function porFirmar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface + { + $body = $request->getBody(); + $json = json_decode($body->getContents()); + $proyecto_id = $json->proyecto_id; + $output = [ + 'proyecto_id' => $proyecto_id, + 'promesas' => 0 + ]; + try { + $ventas = $ventaService->getByProyecto($proyecto_id); + $promesas = array_filter($ventas, function(Model\Venta $venta) { + return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'vigente'; + }); + $output['promesas'] = count($promesas); + } catch (EmptyResult) {} + return $this->withJson($response, $output); + } + public function escrituras(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, Service\Venta\Pago $pagoService): ResponseInterface + { + $body = $request->getBody(); + $json = json_decode($body->getContents()); + $proyecto_id = $json->proyecto_id; + $output = [ + 'proyecto_id' => $proyecto_id, + 'escrituras' => [ + 'firmar' => 0, + 'pagar' => 0, + 'abonar' => 0 + ] + ]; + try { + $ventas = $ventaService->getEscriturasByProyecto($proyecto_id); + $porFirmar = array_filter($ventas, function(Model\Venta $venta) { + return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'escriturando'; + }); + $output['escrituras']['firmar'] = count($porFirmar); + unset($porFirmar); + $escrituras = array_filter($ventas, function(Model\Venta $venta) { + return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'firmado por inmobiliaria'; + }); + unset($ventas); + $porPagar = array_filter($escrituras, function(Model\Venta $venta) use ($pagoService) { + $pagos = $pagoService->getByVenta($venta->id); + $porPagar = array_filter($pagos, function(Model\Venta\Pago $pago) { + return $pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado'; + }); + return count($porPagar) > 0; + }); + $output['escrituras']['pagar'] = count($porPagar); + unset($porPagar); + $porAbonar = array_filter($escrituras, function(Model\Venta $venta) use ($pagoService) { + $pagos = $pagoService->getByVenta($venta->id); + $porPagar = array_filter($pagos, function(Model\Venta\Pago $pago) { + return $pago->currentEstado->tipoEstadoPago->descripcion === 'depositado'; + }); + return count($porPagar) > 0; + }); + $output['escrituras']['abonar'] = count($porAbonar); + unset($porAbonar); + } catch (EmptyResult) {} + return $this->withJson($response, $output); + } + public function comentarios(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, Repository\Venta\Comentario $comentarioRepository, int $venta_id): ResponseInterface + { + $venta = $service->getById($venta_id); + $output = ['total' => 0]; + try { + $comentarios = $comentarioRepository->fetchByVenta($venta->id); + $output['total'] = count($comentarios); + $output['comentarios'] = $comentarios; + } catch (EmptyResult) {} + return $this->withJson($response, $output); + } + public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface + { + $data = $request->getParsedBody(); + $output = [ + 'status' => false, + 'errors' => [] + ]; + try { + $ventaService->add($data); + $output['status'] = true; + } catch (\Exception $exception) { + $output['errors'] = $exception; + } + return $this->withJson($response, $output); + } +} diff --git a/app/src/Controller/API/Ventas/Unidades.php b/app/src/Controller/API/Ventas/Unidades.php new file mode 100644 index 0000000..f04deeb --- /dev/null +++ b/app/src/Controller/API/Ventas/Unidades.php @@ -0,0 +1,56 @@ +getBody(); + $json = json_decode($body->getContents()); + $proyecto_id = $json->proyecto_id; + $output = [ + 'proyecto_id' => $proyecto_id, + 'unidades' => [ + 'total' => [ + 'departamentos' => 0, + 'estacionamientos' => 0, + 'bodegas' => 0, + ], + 'departamentos' => 0, + 'estacionamientos' => 0, + 'bodegas' => 0, + ] + ]; + try { + $totalUnidades = $unidadRepository->fetchByProyecto($proyecto_id); + $unidades = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id); + + $tiposUnidades = $tipoUnidadRepository->fetchAll(); + foreach ($tiposUnidades as $tipoUnidad) { + $tempUnidades = array_filter($totalUnidades, function(Model\Venta\Unidad $unidad) use ($tipoUnidad) { + return $unidad->proyectoTipoUnidad->tipoUnidad->id === $tipoUnidad->id; + }); + if (count($tempUnidades) > 0) { + $output['unidades']['total']["{$tipoUnidad->descripcion}s"] = count($tempUnidades); + } + $tempUnidades = array_filter($unidades, function(Model\Venta\Unidad $unidad) use ($tipoUnidad) { + return $unidad->proyectoTipoUnidad->tipoUnidad->id === $tipoUnidad->id; + }); + if (count($tempUnidades) === 0) { + continue; + } + $output['unidades']["{$tipoUnidad->descripcion}s"] = count($tempUnidades); + } + } catch (EmptyResult) {} + return $this->withJson($response, $output); + } +} diff --git a/app/src/Controller/Ventas.php b/app/src/Controller/Ventas.php index 3b54065..22583ba 100644 --- a/app/src/Controller/Ventas.php +++ b/app/src/Controller/Ventas.php @@ -28,39 +28,6 @@ class Ventas $venta = $service->getByProyectoAndUnidad($proyecto_nombre, $unidad_descripcion); return $view->render($response, 'ventas.show', compact('venta')); } - public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta $service): ResponseInterface - { - $body = $request->getBody(); - $json = json_decode($body->getContents()); - $proyecto_id = $json->proyecto_id; - $output = [ - 'proyecto' => [ - 'id' => $proyecto_id - ], - 'total' => 0 - ]; - try { - $ventas = $service->fetchActivaByProyecto($proyecto_id); - $output['ventas'] = array_map(function(Model\Venta $venta) {return $venta->id;}, $ventas); - $output['proyecto']['descripcion'] = $ventas[0]->proyecto()->descripcion; - $output['total'] = count($ventas); - } catch (EmptyResult) {} - $response->getBody()->write(json_encode($output)); - return $response->withHeader('Content-Type', 'application/json'); - } - public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, int $venta_id): ResponseInterface - { - try { - $venta = $service->getById($venta_id); - $response->getBody()->write(json_encode(compact('venta'))); - } catch (EmptyResult $exception) { - $response->getBody()->write(json_encode(['error' => [ - 'code' => $exception->getCode(), - 'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage()) - ]])); - } - return $response->withHeader('Content-Type', 'application/json'); - } public function edit(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, int $venta_id): ResponseInterface { $venta = $service->getById($venta_id); @@ -90,18 +57,6 @@ class Ventas } return $view->render($response, 'ventas.propiedades.edit', compact('propiedad', 'proyecto', 'tiposUnidades', 'unidades', 'venta_id')); } - public function comentarios(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, Repository\Venta\Comentario $comentarioRepository, int $venta_id): ResponseInterface - { - $venta = $service->getById($venta_id); - $output = ['total' => 0]; - try { - $comentarios = $comentarioRepository->fetchByVenta($venta->id); - $output['total'] = count($comentarios); - $output['comentarios'] = $comentarios; - } catch (EmptyResult) {} - $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(); @@ -111,22 +66,6 @@ class Ventas $proyectos = $proyectoRepository->fetchAllActive(); return $view->render($response, 'ventas.add', compact('regiones', 'proyectos')); } - public function doAdd(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface - { - $data = $request->getParsedBody(); - $output = [ - 'status' => false, - 'errors' => [] - ]; - try { - $ventaService->add($data); - $output['status'] = true; - } catch (\Exception $exception) { - $output['errors'] = $exception; - } - $response->getBody()->write(json_encode($output)); - return $response->withHeader('Content-Type', 'application/json'); - } public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, View $view, int $venta_id): ResponseInterface { $venta = $ventaService->getById($venta_id); diff --git a/app/src/Model/Proyecto/ProyectoTipoUnidad.php b/app/src/Model/Proyecto/ProyectoTipoUnidad.php index e05f9d9..8c7a6bf 100644 --- a/app/src/Model/Proyecto/ProyectoTipoUnidad.php +++ b/app/src/Model/Proyecto/ProyectoTipoUnidad.php @@ -7,7 +7,7 @@ use Incoviba\Model; class ProyectoTipoUnidad extends Ideal\Model { public Model\Proyecto $proyecto; - public Model\Venta\TipoUnidad $tipoUnidad; + public Model\Proyecto\TipoUnidad $tipoUnidad; public string $nombre; public string $abreviacion; public float $util; diff --git a/app/src/Model/Venta/TipoUnidad.php b/app/src/Model/Proyecto/TipoUnidad.php similarity index 87% rename from app/src/Model/Venta/TipoUnidad.php rename to app/src/Model/Proyecto/TipoUnidad.php index 4c1af89..7f7954a 100644 --- a/app/src/Model/Venta/TipoUnidad.php +++ b/app/src/Model/Proyecto/TipoUnidad.php @@ -1,5 +1,5 @@ etapaRepository->fetchByDescripcion('Proyecto'); + $etapaTerminado = $this->etapaRepository->fetchByDescripcion('Terminado'); $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 + {$this->joinEstado()} +WHERE et.`orden` BETWEEN {$etapaProyecto->orden} AND ({$etapaTerminado->orden} - 1) ORDER BY a.`descripcion`"; return $this->fetchMany($query); } + public function fetchAllEscriturando(): array + { + $etapaRecepcion = $this->etapaRepository->fetchByDescripcion('Recepción'); + $etapaTerminado = $this->etapaRepository->fetchByDescripcion('Terminado'); + $query = "SELECT a.* +FROM `{$this->getTable()}` a + {$this->joinEstado()} +WHERE et.`orden` BETWEEN {$etapaRecepcion->orden} AND ({$etapaTerminado->orden} - 1) +ORDER BY a.`descripcion`"; + return $this->fetchMany($query); + } + + protected function joinEstado(): string + { + return "JOIN ( + SELECT e2.* + FROM `estado_proyecto` e2 + JOIN ( + SELECT MAX(e1.`id`) AS 'id', e1.`proyecto` + FROM `estado_proyecto` e1 + JOIN ( + SELECT MAX(`id`) AS 'id', `proyecto`, `fecha` + FROM `estado_proyecto` + GROUP BY `proyecto`, `fecha` + ) e0 ON e1.`id` = e0.`id` + GROUP BY `proyecto` + ) e01 ON e01.`id` = e2.`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`"; + } } diff --git a/app/src/Repository/Proyecto/Etapa.php b/app/src/Repository/Proyecto/Etapa.php index e81a1a6..4ab3bbb 100644 --- a/app/src/Repository/Proyecto/Etapa.php +++ b/app/src/Repository/Proyecto/Etapa.php @@ -28,4 +28,10 @@ class Etapa extends Ideal\Repository { return $this->update($model, ['descripcion', 'orden'], $new_data); } + + public function fetchByDescripcion(string $descripcion): Model\Proyecto\Etapa + { + $query = "SELECT * FROM `{$this->getTable()}` WHERE `descripcion` = ?"; + return $this->fetchOne($query, [$descripcion]); + } } diff --git a/app/src/Repository/Proyecto/ProyectoTipoUnidad.php b/app/src/Repository/Proyecto/ProyectoTipoUnidad.php index 4beb4ac..737f767 100644 --- a/app/src/Repository/Proyecto/ProyectoTipoUnidad.php +++ b/app/src/Repository/Proyecto/ProyectoTipoUnidad.php @@ -9,7 +9,7 @@ use Incoviba\Repository; class ProyectoTipoUnidad extends Ideal\Repository { - public function __construct(Define\Connection $connection, protected Repository\Proyecto $proyectoRepository, protected Repository\Venta\TipoUnidad $tipoUnidadRepository) + public function __construct(Define\Connection $connection, protected Repository\Proyecto $proyectoRepository, protected Repository\Proyecto\TipoUnidad $tipoUnidadRepository) { parent::__construct($connection); $this->setTable('proyecto_tipo_unidad'); diff --git a/app/src/Repository/Venta/TipoUnidad.php b/app/src/Repository/Proyecto/TipoUnidad.php similarity index 87% rename from app/src/Repository/Venta/TipoUnidad.php rename to app/src/Repository/Proyecto/TipoUnidad.php index 035a9a2..1290c4f 100644 --- a/app/src/Repository/Venta/TipoUnidad.php +++ b/app/src/Repository/Proyecto/TipoUnidad.php @@ -1,8 +1,8 @@ parseData(new Model\Venta\TipoUnidad(), $data, $map); + return $this->parseData(new Model\Proyecto\TipoUnidad(), $data, $map); } public function save(Define\Model $model): Define\Model { diff --git a/app/src/Repository/Venta.php b/app/src/Repository/Venta.php index 3944586..c8f28ef 100644 --- a/app/src/Repository/Venta.php +++ b/app/src/Repository/Venta.php @@ -220,4 +220,17 @@ FROM `{$this->getTable()}` a WHERE CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE ?"; return $this->fetchMany($query, [$propietario]); } + public function fetchEscriturasByProyecto(int $proyecto_id): array + { + $query = "SELECT DISTINCT a.* +FROM `{$this->getTable()}` a + JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad` + JOIN `unidad` ON `unidad`.`id` = pu.`unidad` + JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`id` + JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id` + JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado` +WHERE ptu.`proyecto` = ? AND tev.`descripcion` IN ('firmado por inmobiliaria', 'escriturando') +GROUP BY a.`id`"; + return $this->fetchMany($query, [$proyecto_id]); + } } diff --git a/app/src/Repository/Venta/Pago.php b/app/src/Repository/Venta/Pago.php index 04e380b..451789e 100644 --- a/app/src/Repository/Venta/Pago.php +++ b/app/src/Repository/Venta/Pago.php @@ -60,4 +60,44 @@ class Pago extends Ideal\Repository { return $this->update($model, ['valor', 'banco', 'tipo', 'identificador', 'fecha', 'uf', 'pagador', 'asociado'], $new_data); } + + public function fetchByVenta(int $venta_id): array + { + $query = "SELECT a.* +FROM ( + SELECT a.*, venta.id AS venta_id, 'cuota' AS fuente + FROM pago a + JOIN cuota ON cuota.pago = a.id + JOIN venta ON venta.pie = cuota.pie + UNION ALL + SELECT a.*, venta.id AS venta_id, 'reajuste' AS fuente + FROM pago a + JOIN pie ON pie.reajuste = a.id + JOIN venta ON venta.pie = pie.id + UNION ALL + SELECT a.*, venta.id AS venta_id, 'credito' AS fuente + FROM pago a + JOIN credito ON credito.pago = a.id + JOIN venta ON venta.credito = credito.id + UNION ALL + SELECT a.*, venta.id AS venta_id, 'escritura' AS fuente + FROM pago a + JOIN escritura ON escritura.pago = a.id + JOIN venta ON venta.escritura = escritura.id + UNION ALL + SELECT a.*, venta.id AS venta_id, 'subsidio' AS fuente + FROM pago a + JOIN subsidio ON subsidio.subsidio = a.id + JOIN venta ON venta.subsidio = subsidio.id + UNION ALL + SELECT a.*, venta.id AS venta_id, 'ahorro' AS fuente + FROM pago a + JOIN subsidio ON subsidio.pago = a.id + JOIN venta ON venta.subsidio = subsidio.id + ) a + 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 = a.id + JOIN tipo_estado_pago tep ON tep.id = ep.estado +WHERE venta_id = ?"; + return $this->fetchMany($query, [$venta_id]); + } } diff --git a/app/src/Service/Search.php b/app/src/Service/Search.php index 82421e8..3a704bd 100644 --- a/app/src/Service/Search.php +++ b/app/src/Service/Search.php @@ -2,12 +2,12 @@ namespace Incoviba\Service; use Incoviba\Common\Implement\Exception\EmptyResult; -use Incoviba\Repository; use Incoviba\Model; +use Incoviba\Repository; class Search { - public function __construct(protected Venta $ventaService, protected Repository\Venta $ventaRepository, protected Repository\Venta\Unidad $unidadRepository, protected Repository\Venta\TipoUnidad $tipoUnidadRepository) {} + public function __construct(protected Venta $ventaService, protected Repository\Venta $ventaRepository, protected Repository\Venta\Unidad $unidadRepository, protected Repository\Proyecto\TipoUnidad $tipoUnidadRepository) {} public function query(string $query, string $tipo): array { @@ -127,7 +127,7 @@ class Search protected function getTiposUnidades(): array { if (!isset($this->tipos)) { - $this->tipos = array_map(function(Model\Venta\TipoUnidad $tipoUnidad) { + $this->tipos = array_map(function(Model\Proyecto\TipoUnidad $tipoUnidad) { return $tipoUnidad->descripcion; }, $this->tipoUnidadRepository->fetchAll()); } diff --git a/app/src/Service/Venta.php b/app/src/Service/Venta.php index 93fdd1d..01215b7 100644 --- a/app/src/Service/Venta.php +++ b/app/src/Service/Venta.php @@ -28,18 +28,12 @@ class Venta public function getByProyecto(int $proyecto_id): array { $ventas = $this->ventaRepository->fetchByProyecto($proyecto_id); - foreach ($ventas as &$venta) { - $venta = $this->process($venta); - } - return $ventas; + return array_map([$this, 'process'], $ventas); } public function getActivaByProyecto(int $proyecto_id): array { $ventas = $this->ventaRepository->fetchActivaByProyecto($proyecto_id); - foreach ($ventas as &$venta) { - $venta = $this->process($venta); - } - return $ventas; + return array_map([$this, 'process'], $ventas); } public function getByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Model\Venta { @@ -49,26 +43,22 @@ class Venta public function getByUnidad(string $unidad, string $tipo): array { $ventas = $this->ventaRepository->fetchByUnidad($unidad, $tipo); - foreach ($ventas as &$venta) { - $venta = $this->process($venta); - } - return $ventas; + return array_map([$this, 'process'], $ventas); } public function getByPropietario(string $propietario): array { $ventas = $this->ventaRepository->fetchByPropietario($propietario); - foreach ($ventas as &$venta) { - $venta = $this->process($venta); - } - return $ventas; + return array_map([$this, 'process'], $ventas); } public function getByPrecio(string $precio): array { $ventas = $this->ventaRepository->fetchByPrecio($precio); - foreach ($ventas as &$venta) { - $venta = $this->process($venta); - } - return $ventas; + return array_map([$this, 'process'], $ventas); + } + public function getEscriturasByProyecto(int $proyecto_id): array + { + $ventas = $this->ventaRepository->fetchEscriturasByProyecto($proyecto_id); + return array_map([$this, 'process'], $ventas); } protected function process(Model\Venta $venta): Model\Venta diff --git a/app/src/Service/Venta/Pago.php b/app/src/Service/Venta/Pago.php index cff2779..3f8d161 100644 --- a/app/src/Service/Venta/Pago.php +++ b/app/src/Service/Venta/Pago.php @@ -69,15 +69,12 @@ class Pago public function getById(int $pago_id): Model\Venta\Pago { $pago = $this->pagoRepository->fetchById($pago_id); - $pago->estados = $this->estadoPagoRepository->fetchByPago($pago_id); - $pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago_id); - if (($pago->uf === null or $pago->uf === 0.0) and $pago->fecha < new DateTimeImmutable()) { - $pago->uf = $this->moneyService->getUF($pago->fecha); - if ($pago->uf !== 0.0) { - $this->pagoRepository->edit($pago, ['uf' => $pago->uf]); - } - } - return $pago; + return $this->process($pago); + } + + public function getByVenta(int $venta_id): array + { + return array_map([$this, 'process'], $this->pagoRepository->fetchByVenta($venta_id)); } public function getPendientes(): array @@ -121,4 +118,17 @@ class Pago $pago->currentEstado = $estado; return $pago; } + + protected function process($pago): Model\Venta\Pago + { + $pago->estados = $this->estadoPagoRepository->fetchByPago($pago->id); + $pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago->id); + if (($pago->uf === null or $pago->uf === 0.0) and $pago->fecha < new DateTimeImmutable()) { + $pago->uf = $this->moneyService->getUF($pago->fecha); + if ($pago->uf !== 0.0) { + $this->pagoRepository->edit($pago, ['uf' => $pago->uf]); + } + } + return $pago; + } } diff --git a/docker-compose.yml b/docker-compose.yml index 88027bf..09ec208 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,6 +41,8 @@ services: volumes: - dbdata:/var/lib/mysql - ./incoviba.sql.gz:/docker-entrypoint-initdb.d/incoviba.sql.gz + ports: + - "33060:3306" networks: - default - adminer_network From 850a475ef6e989a60735244fbe29e7b7f1dd57b8 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Thu, 19 Oct 2023 18:58:48 -0300 Subject: [PATCH 019/163] Cuando no tiene resultados en cuotas, entregar vacio --- app/src/Controller/API/Ventas/Cuotas.php | 57 ++++++++++++++---------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/app/src/Controller/API/Ventas/Cuotas.php b/app/src/Controller/API/Ventas/Cuotas.php index 05df9df..f47b94e 100644 --- a/app/src/Controller/API/Ventas/Cuotas.php +++ b/app/src/Controller/API/Ventas/Cuotas.php @@ -3,6 +3,7 @@ namespace Incoviba\Controller\API\Ventas; use DateTimeImmutable; use DateInterval; +use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Controller\API\withJson; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -15,44 +16,52 @@ class Cuotas public function hoy(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository): ResponseInterface { $output = [ - 'cuotas' => count($cuotaRepository->fetchHoy()) ?? 0 + 'cuotas' => 0 ]; + try { + $output['cuotas'] = count($cuotaRepository->fetchHoy()); + } catch (EmptyResult) {} return $this->withJson($response, $output); } public function pendiente(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository): ResponseInterface { $output = [ - 'cuotas' => count($cuotaRepository->fetchPendientes()) ?? 0 + 'cuotas' => 0 ]; + try { + $output['cuotas'] = count($cuotaRepository->fetchPendientes()); + } catch (EmptyResult) {} return $this->withJson($response, $output); } public function porVencer(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Format $formatService): ResponseInterface { - $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'); + try { + $cuotas = $cuotaRepository->fetchDatosPorVencer(); + 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'); + } + $key = $formatService->localDate($fecha, "EEE. dd 'de' MMMM 'de' yyyy", true); + if (!isset($output[$key])) { + $output[$key] = []; + } + if (!isset($output[$key][$row['Proyecto']])) { + $output[$key][$row['Proyecto']] = 0; + } + $output[$key][$row['Proyecto']] += $row['Cantidad']; } - $key = $formatService->localDate($fecha, "EEE. dd 'de' MMMM 'de' yyyy", true); - if (!isset($output[$key])) { - $output[$key] = []; + foreach ($output as $key => $day) { + uksort($day, function($a, $b) { + return strcmp($a, $b); + }); + $output[$key] = $day; } - if (!isset($output[$key][$row['Proyecto']])) { - $output[$key][$row['Proyecto']] = 0; - } - $output[$key][$row['Proyecto']] += $row['Cantidad']; - } - foreach ($output as $key => $day) { - uksort($day, function($a, $b) { - return strcmp($a, $b); - }); - $output[$key] = $day; - } + } catch (EmptyResult) {} return $this->withJson($response, ['cuotas' => $output]); } } From ada0434caff6edc3ba104493c7274bcfd92af39c Mon Sep 17 00:00:00 2001 From: Aldarien Date: Thu, 19 Oct 2023 19:10:08 -0300 Subject: [PATCH 020/163] Error log cuotas --- app/src/Controller/API/Ventas/Cuotas.php | 6 ++++++ php-errors.ini | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/Controller/API/Ventas/Cuotas.php b/app/src/Controller/API/Ventas/Cuotas.php index f47b94e..25a8545 100644 --- a/app/src/Controller/API/Ventas/Cuotas.php +++ b/app/src/Controller/API/Ventas/Cuotas.php @@ -37,7 +37,11 @@ class Cuotas { $output = []; try { + $benchmark = [ + 'start' => microtime(true) + ]; $cuotas = $cuotaRepository->fetchDatosPorVencer(); + $benchmark['cuotas'] = microtime(true) - $benchmark['start']; foreach ($cuotas as $row) { $fecha = $row['Fecha']; $date = new DateTimeImmutable($fecha); @@ -61,6 +65,8 @@ class Cuotas }); $output[$key] = $day; } + $benchmark['run'] = microtime(true) - $benchmark['start']; + error_log(var_export($benchmark,true)); } catch (EmptyResult) {} return $this->withJson($response, ['cuotas' => $output]); } diff --git a/php-errors.ini b/php-errors.ini index c791df7..aed1ffb 100644 --- a/php-errors.ini +++ b/php-errors.ini @@ -1,3 +1,3 @@ display_errors=no log_errors=yes -error_log=/logs/php_errors.log +error_log=/logs/errors.log From 742c0327c28465c5ada2db7a11651a652c42367b Mon Sep 17 00:00:00 2001 From: Aldarien Date: Thu, 19 Oct 2023 19:39:27 -0300 Subject: [PATCH 021/163] Improving cuotas por vencer --- app/src/Repository/Venta/Cuota.php | 51 +++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/app/src/Repository/Venta/Cuota.php b/app/src/Repository/Venta/Cuota.php index b9d87ab..9e3de82 100644 --- a/app/src/Repository/Venta/Cuota.php +++ b/app/src/Repository/Venta/Cuota.php @@ -138,22 +138,43 @@ ORDER BY `pago`.`fecha` DESC"; } public function fetchDatosPorVencer(): array { - $query = "SELECT `pago`.`fecha` AS 'Fecha', `proyecto`.`descripcion` AS 'Proyecto', COUNT(a.`id`) AS 'Cantidad' + $query = "SELECT p1.`fecha` AS 'Fecha', v1.`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`"; + JOIN ( + SELECT `pago`.`id`, `pago`.`fecha` + FROM `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` AND tep.`descripcion` = 'no pagado' + ) p1 ON p1.id = a.`pago` + JOIN ( + SELECT `venta`.`pie`, `venta`.`propiedad`, `proyecto`.`descripcion` + FROM `venta` + 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` AND tev.`descripcion` IN ('vigente', 'escriturando', 'firmado por inmobiliaria') + 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` + ) v1 ON v1.`pie` = a.`pie` +WHERE p1.`fecha` BETWEEN DATE_ADD(CURDATE(), INTERVAL 1 DAY) AND DATE_ADD(CURDATE(), INTERVAL 1 MONTH) +GROUP BY p1.`fecha`, v1.`descripcion` +ORDER BY p1.`fecha`, v1.`descripcion`"; return $this->fetchAsArray($query); } public function fetchVigenteByPie(int $pie_id): array From dc217d876a91c51fdf687502781bb536bb9610e0 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Thu, 19 Oct 2023 20:46:52 -0300 Subject: [PATCH 022/163] Redis service --- app/common/Implement/Exception/EmptyRedis.php | 15 +++ app/composer.json | 1 + app/setup/setups/services.php | 7 ++ app/src/Controller/API/Ventas.php | 90 +++++++++------ app/src/Controller/API/Ventas/Cuotas.php | 103 +++++++++++------- app/src/Controller/API/Ventas/Unidades.php | 52 +++++---- app/src/Controller/API/withJson.php | 2 +- app/src/Controller/API/withRedis.php | 24 ++++ app/src/Service/Redis.php | 18 +++ docker-compose.yml | 13 +++ 10 files changed, 228 insertions(+), 97 deletions(-) create mode 100644 app/common/Implement/Exception/EmptyRedis.php create mode 100644 app/src/Controller/API/withRedis.php create mode 100644 app/src/Service/Redis.php diff --git a/app/common/Implement/Exception/EmptyRedis.php b/app/common/Implement/Exception/EmptyRedis.php new file mode 100644 index 0000000..cc6ac45 --- /dev/null +++ b/app/common/Implement/Exception/EmptyRedis.php @@ -0,0 +1,15 @@ +register('uf', $mindicador) ->register('ipc', $mindicador); }, + Predis\Client::class => function(ContainerInterface $container) { + return new Predis\Client([ + 'scheme' => 'tcp', + 'host' => $container->get('REDIS_HOST'), + 'port' => $container->get('REDIS_PORT') + ]); + } ]; diff --git a/app/src/Controller/API/Ventas.php b/app/src/Controller/API/Ventas.php index bdfc853..87deea0 100644 --- a/app/src/Controller/API/Ventas.php +++ b/app/src/Controller/API/Ventas.php @@ -1,6 +1,8 @@ withJson($response, $output); } - public function porFirmar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface + public function porFirmar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, Service\Redis $redisService): ResponseInterface { $body = $request->getBody(); $json = json_decode($body->getContents()); $proyecto_id = $json->proyecto_id; + $today = new DateTimeImmutable(); + $redisKey = "promesas_por_firmar-{$proyecto_id}-{$today->format('Y-m-d')}"; + $output = [ 'proyecto_id' => $proyecto_id, 'promesas' => 0 ]; try { - $ventas = $ventaService->getByProyecto($proyecto_id); - $promesas = array_filter($ventas, function(Model\Venta $venta) { - return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'vigente'; - }); - $output['promesas'] = count($promesas); - } catch (EmptyResult) {} + $output = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $ventas = $ventaService->getByProyecto($proyecto_id); + $promesas = array_filter($ventas, function(Model\Venta $venta) { + return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'vigente'; + }); + $output['promesas'] = count($promesas); + $this->saveRedis($redisService, $redisKey, $output); + } catch (EmptyResult) {} + } return $this->withJson($response, $output); } - public function escrituras(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, Service\Venta\Pago $pagoService): ResponseInterface + public function escrituras(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, Service\Venta\Pago $pagoService, Service\Redis $redisService): ResponseInterface { $body = $request->getBody(); $json = json_decode($body->getContents()); $proyecto_id = $json->proyecto_id; + $today = new DateTimeImmutable(); + $redisKey = "escrituras-{$proyecto_id}-{$today->format('Y-m-d')}"; + $output = [ 'proyecto_id' => $proyecto_id, 'escrituras' => [ @@ -78,35 +91,40 @@ class Ventas ] ]; try { - $ventas = $ventaService->getEscriturasByProyecto($proyecto_id); - $porFirmar = array_filter($ventas, function(Model\Venta $venta) { - return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'escriturando'; - }); - $output['escrituras']['firmar'] = count($porFirmar); - unset($porFirmar); - $escrituras = array_filter($ventas, function(Model\Venta $venta) { - return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'firmado por inmobiliaria'; - }); - unset($ventas); - $porPagar = array_filter($escrituras, function(Model\Venta $venta) use ($pagoService) { - $pagos = $pagoService->getByVenta($venta->id); - $porPagar = array_filter($pagos, function(Model\Venta\Pago $pago) { - return $pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado'; + $output = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $ventas = $ventaService->getEscriturasByProyecto($proyecto_id); + $porFirmar = array_filter($ventas, function(Model\Venta $venta) { + return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'escriturando'; }); - return count($porPagar) > 0; - }); - $output['escrituras']['pagar'] = count($porPagar); - unset($porPagar); - $porAbonar = array_filter($escrituras, function(Model\Venta $venta) use ($pagoService) { - $pagos = $pagoService->getByVenta($venta->id); - $porPagar = array_filter($pagos, function(Model\Venta\Pago $pago) { - return $pago->currentEstado->tipoEstadoPago->descripcion === 'depositado'; + $output['escrituras']['firmar'] = count($porFirmar); + unset($porFirmar); + $escrituras = array_filter($ventas, function(Model\Venta $venta) { + return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'firmado por inmobiliaria'; }); - return count($porPagar) > 0; - }); - $output['escrituras']['abonar'] = count($porAbonar); - unset($porAbonar); - } catch (EmptyResult) {} + unset($ventas); + $porPagar = array_filter($escrituras, function(Model\Venta $venta) use ($pagoService) { + $pagos = $pagoService->getByVenta($venta->id); + $porPagar = array_filter($pagos, function(Model\Venta\Pago $pago) { + return $pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado'; + }); + return count($porPagar) > 0; + }); + $output['escrituras']['pagar'] = count($porPagar); + unset($porPagar); + $porAbonar = array_filter($escrituras, function(Model\Venta $venta) use ($pagoService) { + $pagos = $pagoService->getByVenta($venta->id); + $porPagar = array_filter($pagos, function(Model\Venta\Pago $pago) { + return $pago->currentEstado->tipoEstadoPago->descripcion === 'depositado'; + }); + return count($porPagar) > 0; + }); + $output['escrituras']['abonar'] = count($porAbonar); + unset($porAbonar); + $this->saveRedis($redisService, $redisKey, $output); + } catch (EmptyResult) {} + } return $this->withJson($response, $output); } public function comentarios(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, Repository\Venta\Comentario $comentarioRepository, int $venta_id): ResponseInterface diff --git a/app/src/Controller/API/Ventas/Cuotas.php b/app/src/Controller/API/Ventas/Cuotas.php index 25a8545..32e8da5 100644 --- a/app/src/Controller/API/Ventas/Cuotas.php +++ b/app/src/Controller/API/Ventas/Cuotas.php @@ -3,71 +3,94 @@ namespace Incoviba\Controller\API\Ventas; use DateTimeImmutable; use DateInterval; -use Incoviba\Common\Implement\Exception\EmptyResult; -use Incoviba\Controller\API\withJson; +use Incoviba\Controller\API\withRedis; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Incoviba\Common\Implement\Exception\EmptyRedis; +use Incoviba\Common\Implement\Exception\EmptyResult; +use Incoviba\Controller\API\withJson; use Incoviba\Repository; use Incoviba\Service; class Cuotas { - use withJson; - public function hoy(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository): ResponseInterface + use withJson, withRedis; + public function hoy(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService): ResponseInterface { + $today = new DateTimeImmutable(); + $redisKey = "cuotas_hoy-{$today->format('Y-m-d')}"; $output = [ 'cuotas' => 0 ]; try { - $output['cuotas'] = count($cuotaRepository->fetchHoy()); - } catch (EmptyResult) {} + $output['cuotas'] = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $output['cuotas'] = count($cuotaRepository->fetchHoy()); + $this->saveRedis($redisService, $redisKey, $output['cuotas']); + } catch (EmptyResult) {} + } return $this->withJson($response, $output); } - public function pendiente(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository): ResponseInterface + public function pendiente(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService): ResponseInterface { + $today = new DateTimeImmutable(); + $redisKey = "cuotas_pendientes-{$today->format('Y-m-d')}"; $output = [ 'cuotas' => 0 ]; try { - $output['cuotas'] = count($cuotaRepository->fetchPendientes()); - } catch (EmptyResult) {} + $output['cuotas'] = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $output['cuotas'] = count($cuotaRepository->fetchPendientes()); + $this->saveRedis($redisService, $redisKey, $output['cuotas']); + } catch (EmptyResult) {} + } return $this->withJson($response, $output); } - public function porVencer(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Format $formatService): ResponseInterface + public function porVencer(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService, Service\Format $formatService): ResponseInterface { - $output = []; + $today = new DateTimeImmutable(); + $redisKey = "cuotas_por_vencer-{$today->format('Y-m-d')}"; try { - $benchmark = [ - 'start' => microtime(true) - ]; - $cuotas = $cuotaRepository->fetchDatosPorVencer(); - $benchmark['cuotas'] = microtime(true) - $benchmark['start']; - 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'); + $output = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + $output = []; + try { + $benchmark = [ + 'start' => microtime(true) + ]; + $cuotas = $cuotaRepository->fetchDatosPorVencer(); + $benchmark['cuotas'] = microtime(true) - $benchmark['start']; + 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'); + } + $key = $formatService->localDate($fecha, "EEE. dd 'de' MMMM 'de' yyyy", true); + if (!isset($output[$key])) { + $output[$key] = []; + } + if (!isset($output[$key][$row['Proyecto']])) { + $output[$key][$row['Proyecto']] = 0; + } + $output[$key][$row['Proyecto']] += $row['Cantidad']; } - $key = $formatService->localDate($fecha, "EEE. dd 'de' MMMM 'de' yyyy", true); - if (!isset($output[$key])) { - $output[$key] = []; + foreach ($output as $key => $day) { + uksort($day, function($a, $b) { + return strcmp($a, $b); + }); + $output[$key] = $day; } - if (!isset($output[$key][$row['Proyecto']])) { - $output[$key][$row['Proyecto']] = 0; - } - $output[$key][$row['Proyecto']] += $row['Cantidad']; - } - foreach ($output as $key => $day) { - uksort($day, function($a, $b) { - return strcmp($a, $b); - }); - $output[$key] = $day; - } - $benchmark['run'] = microtime(true) - $benchmark['start']; - error_log(var_export($benchmark,true)); - } catch (EmptyResult) {} + $benchmark['run'] = microtime(true) - $benchmark['start']; + error_log(var_export($benchmark,true)); + $this->saveRedis($redisService, $redisKey, $output); + } catch (EmptyResult) {} + } return $this->withJson($response, ['cuotas' => $output]); } } diff --git a/app/src/Controller/API/Ventas/Unidades.php b/app/src/Controller/API/Ventas/Unidades.php index f04deeb..398f3af 100644 --- a/app/src/Controller/API/Ventas/Unidades.php +++ b/app/src/Controller/API/Ventas/Unidades.php @@ -1,22 +1,29 @@ getBody(); $json = json_decode($body->getContents()); $proyecto_id = $json->proyecto_id; + $today = new DateTimeImmutable(); + $redisKey = "unidades_disponibles-{$proyecto_id}-{$today->format('Y-m-d')}"; + $output = [ 'proyecto_id' => $proyecto_id, 'unidades' => [ @@ -31,26 +38,31 @@ class Unidades ] ]; try { - $totalUnidades = $unidadRepository->fetchByProyecto($proyecto_id); - $unidades = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id); + $output = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $totalUnidades = $unidadRepository->fetchByProyecto($proyecto_id); + $unidades = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id); - $tiposUnidades = $tipoUnidadRepository->fetchAll(); - foreach ($tiposUnidades as $tipoUnidad) { - $tempUnidades = array_filter($totalUnidades, function(Model\Venta\Unidad $unidad) use ($tipoUnidad) { - return $unidad->proyectoTipoUnidad->tipoUnidad->id === $tipoUnidad->id; - }); - if (count($tempUnidades) > 0) { - $output['unidades']['total']["{$tipoUnidad->descripcion}s"] = count($tempUnidades); + $tiposUnidades = $tipoUnidadRepository->fetchAll(); + foreach ($tiposUnidades as $tipoUnidad) { + $tempUnidades = array_filter($totalUnidades, function(Model\Venta\Unidad $unidad) use ($tipoUnidad) { + return $unidad->proyectoTipoUnidad->tipoUnidad->id === $tipoUnidad->id; + }); + if (count($tempUnidades) > 0) { + $output['unidades']['total']["{$tipoUnidad->descripcion}s"] = count($tempUnidades); + } + $tempUnidades = array_filter($unidades, function(Model\Venta\Unidad $unidad) use ($tipoUnidad) { + return $unidad->proyectoTipoUnidad->tipoUnidad->id === $tipoUnidad->id; + }); + if (count($tempUnidades) === 0) { + continue; + } + $output['unidades']["{$tipoUnidad->descripcion}s"] = count($tempUnidades); } - $tempUnidades = array_filter($unidades, function(Model\Venta\Unidad $unidad) use ($tipoUnidad) { - return $unidad->proyectoTipoUnidad->tipoUnidad->id === $tipoUnidad->id; - }); - if (count($tempUnidades) === 0) { - continue; - } - $output['unidades']["{$tipoUnidad->descripcion}s"] = count($tempUnidades); - } - } catch (EmptyResult) {} + $this->saveRedis($redisService, $redisKey, $output); + } catch (EmptyResult) {} + } return $this->withJson($response, $output); } } diff --git a/app/src/Controller/API/withJson.php b/app/src/Controller/API/withJson.php index 78aa191..1a6e2f4 100644 --- a/app/src/Controller/API/withJson.php +++ b/app/src/Controller/API/withJson.php @@ -5,7 +5,7 @@ use Psr\Http\Message\ResponseInterface; trait withJson { - public function withJson(ResponseInterface $response, array $data = []): ResponseInterface + public function withJson(ResponseInterface $response, array|object $data = []): ResponseInterface { $response->getBody()->write(json_encode($data)); return $response->withHeader('Content-Type', 'application/json'); diff --git a/app/src/Controller/API/withRedis.php b/app/src/Controller/API/withRedis.php new file mode 100644 index 0000000..0913c11 --- /dev/null +++ b/app/src/Controller/API/withRedis.php @@ -0,0 +1,24 @@ +get($redisKey); + if ($jsonString === null) { + throw new EmptyRedis($redisKey); + } + return json_decode($jsonString); + } + public function saveRedis(Service\Redis $redisService, string $redisKey, mixed $value): void + { + if (is_array($value) or is_object($value)) { + $value = json_encode($value); + } + $redisService->set($redisKey, $value); + } +} diff --git a/app/src/Service/Redis.php b/app/src/Service/Redis.php new file mode 100644 index 0000000..5a9845a --- /dev/null +++ b/app/src/Service/Redis.php @@ -0,0 +1,18 @@ +client->get($name); + } + public function set(string $name, mixed $value): void + { + $this->client->set($name, $value); + } +} diff --git a/docker-compose.yml b/docker-compose.yml index 09ec208..3e628b8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -47,6 +47,18 @@ services: - default - adminer_network + redis: + profiles: + - cache + image: redis + container_name: incoviba_redis + <<: *restart + env_file: ${APP_PATH:-.}/.redis.env + volumes: + - incoviba_redis:/data + ports: + - "63790:6379" + python: profiles: - python @@ -74,6 +86,7 @@ services: volumes: dbdata: {} + incoviba_redis: {} networks: adminer_network: {} From e536f0f8f31808e6b46c23b56d8a3c67effdee6d Mon Sep 17 00:00:00 2001 From: Aldarien Date: Thu, 19 Oct 2023 21:49:57 -0300 Subject: [PATCH 023/163] Redis expiration 1 day --- app/src/Service/Redis.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/Service/Redis.php b/app/src/Service/Redis.php index 5a9845a..1d7f050 100644 --- a/app/src/Service/Redis.php +++ b/app/src/Service/Redis.php @@ -2,6 +2,7 @@ namespace Incoviba\Service; use Predis\Client; +use Incoviba\Common\Implement\Exception\EmptyRedis; class Redis { @@ -9,10 +10,13 @@ class Redis public function get(string $name): mixed { + if (!$this->client->exists($name)) { + throw new EmptyRedis($name); + } return $this->client->get($name); } public function set(string $name, mixed $value): void { - $this->client->set($name, $value); + $this->client->set($name, $value, 'EX', 60 * 60 * 24); } } From 54ac535a49bfc5b48de8fcff1ddb7227e51d134c Mon Sep 17 00:00:00 2001 From: Aldarien Date: Thu, 19 Oct 2023 22:01:00 -0300 Subject: [PATCH 024/163] Remove benchmark --- app/src/Controller/API/Ventas/Cuotas.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/src/Controller/API/Ventas/Cuotas.php b/app/src/Controller/API/Ventas/Cuotas.php index 32e8da5..9e4bd87 100644 --- a/app/src/Controller/API/Ventas/Cuotas.php +++ b/app/src/Controller/API/Ventas/Cuotas.php @@ -58,11 +58,7 @@ class Cuotas } catch (EmptyRedis) { $output = []; try { - $benchmark = [ - 'start' => microtime(true) - ]; $cuotas = $cuotaRepository->fetchDatosPorVencer(); - $benchmark['cuotas'] = microtime(true) - $benchmark['start']; foreach ($cuotas as $row) { $fecha = $row['Fecha']; $date = new DateTimeImmutable($fecha); @@ -86,8 +82,6 @@ class Cuotas }); $output[$key] = $day; } - $benchmark['run'] = microtime(true) - $benchmark['start']; - error_log(var_export($benchmark,true)); $this->saveRedis($redisService, $redisKey, $output); } catch (EmptyResult) {} } From 4734417fe297905957d55184a2e6e8ed288f0853 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Thu, 19 Oct 2023 22:43:21 -0300 Subject: [PATCH 025/163] Estado Recepcion Final en Proyecto --- app/resources/routes/api/proyectos.php | 1 + app/resources/views/proyectos/list.blade.php | 114 ++++++++---------- .../API/Proyectos/EstadosProyectos.php | 13 ++ app/src/Repository/Proyecto.php | 2 +- .../Repository/Proyecto/EstadoProyecto.php | 8 ++ 5 files changed, 75 insertions(+), 63 deletions(-) diff --git a/app/resources/routes/api/proyectos.php b/app/resources/routes/api/proyectos.php index 5216427..784b0d1 100644 --- a/app/resources/routes/api/proyectos.php +++ b/app/resources/routes/api/proyectos.php @@ -9,4 +9,5 @@ $app->group('/proyecto/{proyecto_id}', function($app) { $app->get('/estados[/]', [Proyectos\EstadosProyectos::class, 'byProyecto']); $app->get('/estado[/]', [Proyectos\EstadosProyectos::class, 'currentByProyecto']); $app->get('/inicio[/]', [Proyectos\EstadosProyectos::class, 'firstByProyecto']); + $app->get('/recepcion[/]', [Proyectos\EstadosProyectos::class, 'recepcionByProyecto']); }); diff --git a/app/resources/views/proyectos/list.blade.php b/app/resources/views/proyectos/list.blade.php index f0dc90d..3dbdb83 100644 --- a/app/resources/views/proyectos/list.blade.php +++ b/app/resources/views/proyectos/list.blade.php @@ -11,6 +11,7 @@ Etapa Estado Tiempo Total + Tiempo RF @@ -21,6 +22,7 @@ + @endforeach @@ -38,7 +40,8 @@ this.id = id this.estados = { start: null, - current: null + current: null, + recepcion: null } } get() { @@ -60,6 +63,21 @@ }).then(data => { this.estados.current = data.estado }) + }, + recepcion: () => { + return fetch('{{$urls->api}}/proyecto/' + this.id + '/recepcion').then(response => { + if (response.ok) { + if (response.status === 204) { + return null + } + return response.json() + } + }).then(data => { + if (data === null) { + return + } + this.estados.recepcion = data.estado + }) } } } @@ -87,10 +105,10 @@ if (diff >= 30) { diff /= 30 frame = 'meses' - } - if (diff >= 12) { - diff /= 12 - frame = 'años' + if (diff >= 12) { + diff /= 12 + frame = 'años' + } } if (diff > 0) { estado += ' (hace ' + Math.floor(diff) + ' ' + frame + ')' @@ -111,83 +129,55 @@ if (diff >= 30) { diff /= 30 frame = 'meses' - } - if (diff >= 12) { - diff /= 12 - frame = 'años' + if (diff >= 12) { + diff /= 12 + frame = 'años' + } } - row.find('.tiempo').html('Hace ' + Math.floor(diff) + ' ' + frame) + row.find('.tiempo').html(Math.floor(diff) + ' ' + frame) + }, + recepcion: () => { + if (this.estados.recepcion === null) { + return + } + let diff = (today - new Date(this.estados.recepcion.fecha.date)) / (1000 * 60 * 60 * 24) + if (isNaN(diff) || diff === 0) { + return + } + + let frame = 'dias' + if (diff >= 30) { + diff /= 30 + frame = 'meses' + if (diff >= 12) { + diff /= 12 + frame = 'años' + } + } + + row.find('.recepcion').html(Math.floor(diff) + ' ' + frame) } } } } - function showTiempo(proyecto_id, tiempo) { - if (tiempo.trim() === '') { - return - } - const row = $(".proyecto[data-id='" + proyecto_id + "']") - row.find('.tiempo').html(tiempo) - } - function getEstados(proyecto_id) { - return fetch('{{$urls->api}}/proyecto/' + proyecto_id + '/estados').then(response => { - if (response.ok) { - return response.json() - } - }).then(data => { - let tiempo = 0 - const current = new Date(data.estados.at(-1).fecha.date) - const start = new Date(data.estados[0].fecha.date) - tiempo = (current - start) / (1000 * 60 * 60 * 24) - if (isNaN(tiempo) || tiempo === 0) { - return - } - let frame = 'días' - if (tiempo > 30) { - tiempo /= 30 - frame = 'meses' - } - if (tiempo > 12) { - tiempo /= 12 - frame = 'años' - } - showTiempo(data.proyecto_id, 'Hace ' + Math.ceil(tiempo) + ' ' + frame) - }) - } - function showEtapa(proyecto_id, etapa) { - const row = $(".proyecto[data-id='" + proyecto_id + "']") - row.find('.etapa').html(etapa) - } - function showEstado(proyecto_id, estado) { - const row = $(".proyecto[data-id='" + proyecto_id + "']") - row.find('.estado').html(estado) - } - function getEstado(proyecto_id) { - return fetch('{{$urls->api}}/proyecto/' + proyecto_id + '/estado').then(response => { - if (response.ok) { - return response.json() - } - }).then(data => { - showEtapa(data.proyecto_id, data.estado.tipo_estado_proyecto.etapa.descripcion) - showEstado(data.proyecto_id, data.estado.tipo_estado_proyecto.descripcion) - }) - } + function loadEstados(proyecto_id) { const proyecto = new Proyecto(proyecto_id) const promises = [] promises.push(proyecto.get().start()) promises.push(proyecto.get().current()) + promises.push(proyecto.get().recepcion()) Promise.all(promises).then(() => { proyecto.show().etapa() proyecto.show().current() proyecto.show().tiempo() + proyecto.show().recepcion() }) } $(document).ready(() => { @foreach ($proyectos as $proyecto) loadEstados('{{$proyecto->id}}') - /*getEstado('{{$proyecto->id}}') - getEstados('{{$proyecto->id}}')*/ @endforeach }) diff --git a/app/src/Controller/API/Proyectos/EstadosProyectos.php b/app/src/Controller/API/Proyectos/EstadosProyectos.php index bc03d06..9fc451f 100644 --- a/app/src/Controller/API/Proyectos/EstadosProyectos.php +++ b/app/src/Controller/API/Proyectos/EstadosProyectos.php @@ -50,4 +50,17 @@ class EstadosProyectos } return $this->withJson($response, $output); } + public function recepcionByProyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface + { + $output = [ + 'proyecto_id' => $proyecto_id, + 'estado' => null + ]; + try { + $output['estado'] = $estadoProyectoRepository->fetchRecepcionByProyecto($proyecto_id); + } catch (EmptyResult) { + return $this->emptyBody($response); + } + return $this->withJson($response, $output); + } } diff --git a/app/src/Repository/Proyecto.php b/app/src/Repository/Proyecto.php index 924d62b..21b1c7e 100644 --- a/app/src/Repository/Proyecto.php +++ b/app/src/Repository/Proyecto.php @@ -102,7 +102,7 @@ ORDER BY a.`descripcion`"; SELECT MAX(e1.`id`) AS 'id', e1.`proyecto` FROM `estado_proyecto` e1 JOIN ( - SELECT MAX(`id`) AS 'id', `proyecto`, `fecha` + SELECT `id`, `proyecto`, MAX(`fecha`) as 'fecha' FROM `estado_proyecto` GROUP BY `proyecto`, `fecha` ) e0 ON e1.`id` = e0.`id` diff --git a/app/src/Repository/Proyecto/EstadoProyecto.php b/app/src/Repository/Proyecto/EstadoProyecto.php index b27a0ca..ff6ece5 100644 --- a/app/src/Repository/Proyecto/EstadoProyecto.php +++ b/app/src/Repository/Proyecto/EstadoProyecto.php @@ -70,4 +70,12 @@ FROM `{$this->getTable()}` a WHERE a.`proyecto` = ?"; return $this->fetchOne($query, [$proyecto_id]); } + public function fetchRecepcionByProyecto(int $proyecto_id): Model\Proyecto\EstadoProyecto + { + $query = "SELECT a.* +FROM `{$this->getTable()}` a + JOIN `tipo_estado_proyecto` tep ON tep.`id` = a.`estado` +WHERE a.`proyecto` = ? AND tep.`descripcion` = 'Recepción Final'"; + return $this->fetchOne($query, [$proyecto_id]); + } } From b4742a501e2fbf3d512af746748c91d5c1cbbe3b Mon Sep 17 00:00:00 2001 From: Aldarien Date: Fri, 20 Oct 2023 19:03:29 -0300 Subject: [PATCH 026/163] Show Proyecto --- app/resources/routes/03_proyectos.php | 3 + app/resources/routes/api/proyectos.php | 7 + app/resources/routes/api/ventas/precios.php | 2 +- app/resources/views/proyectos/list.blade.php | 6 +- app/resources/views/proyectos/show.blade.php | 470 +++++++++++++++++++ app/src/Controller/API/Proyectos.php | 96 +++- app/src/Controller/API/Ventas.php | 4 +- app/src/Controller/API/Ventas/Precios.php | 36 ++ app/src/Controller/API/Ventas/Unidades.php | 2 +- app/src/Controller/Proyectos.php | 8 +- app/src/Controller/Ventas/Precios.php | 21 - app/src/Model/Proyecto.php | 18 + app/src/Model/Proyecto/Superficie.php | 5 + app/src/Model/Venta/Propiedad.php | 6 +- app/src/Repository/Proyecto.php | 4 + app/src/Service/Redis.php | 4 +- 16 files changed, 644 insertions(+), 48 deletions(-) create mode 100644 app/resources/views/proyectos/show.blade.php create mode 100644 app/src/Controller/API/Ventas/Precios.php diff --git a/app/resources/routes/03_proyectos.php b/app/resources/routes/03_proyectos.php index 4f31a20..7c734ea 100644 --- a/app/resources/routes/03_proyectos.php +++ b/app/resources/routes/03_proyectos.php @@ -5,3 +5,6 @@ $app->group('/proyectos', function($app) { $app->get('/unidades[/]', [Proyectos::class, 'unidades']); $app->get('[/]', Proyectos::class); }); +$app->group('/proyecto/{proyecto_id}', function($app) { + $app->get('[/]', [Proyectos::class, 'show']); +}); diff --git a/app/resources/routes/api/proyectos.php b/app/resources/routes/api/proyectos.php index 784b0d1..3d8cca7 100644 --- a/app/resources/routes/api/proyectos.php +++ b/app/resources/routes/api/proyectos.php @@ -10,4 +10,11 @@ $app->group('/proyecto/{proyecto_id}', function($app) { $app->get('/estado[/]', [Proyectos\EstadosProyectos::class, 'currentByProyecto']); $app->get('/inicio[/]', [Proyectos\EstadosProyectos::class, 'firstByProyecto']); $app->get('/recepcion[/]', [Proyectos\EstadosProyectos::class, 'recepcionByProyecto']); + $app->group('/superficies', function($app) { + $app->get('/vendible[/]', [Proyectos::class, 'superficies']); + }); + $app->group('/unidades', function($app) { + $app->get('/disponibles[/]', [Proyectos::class, 'disponibles']); + $app->get('[/]', [Proyectos::class, 'unidades']); + }); }); diff --git a/app/resources/routes/api/ventas/precios.php b/app/resources/routes/api/ventas/precios.php index 2f04166..6546f48 100644 --- a/app/resources/routes/api/ventas/precios.php +++ b/app/resources/routes/api/ventas/precios.php @@ -1,5 +1,5 @@ group('/precios', function($app) { $app->post('[/]', [Precios::class, 'proyecto']); diff --git a/app/resources/views/proyectos/list.blade.php b/app/resources/views/proyectos/list.blade.php index 3dbdb83..98fd8c2 100644 --- a/app/resources/views/proyectos/list.blade.php +++ b/app/resources/views/proyectos/list.blade.php @@ -17,7 +17,11 @@ @foreach ($proyectos as $proyecto) - {{$proyecto->descripcion}} + + + {{$proyecto->descripcion}} + + {{$proyecto->inmobiliaria()->nombreCompleto()}} diff --git a/app/resources/views/proyectos/show.blade.php b/app/resources/views/proyectos/show.blade.php new file mode 100644 index 0000000..88986fd --- /dev/null +++ b/app/resources/views/proyectos/show.blade.php @@ -0,0 +1,470 @@ +@extends('layout.base') + +@section('page_title') + Proyecto {{$proyecto->descripcion}} +@endsection + +@section('page_content') +
    +

    + Proyecto {{$proyecto->descripcion}} - {{$proyecto->inmobiliaria()->razon}} +

    + @php + $today = new DateTimeImmutable(); + @endphp + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Dirección{{$proyecto->direccion()}}
    Inmobiliaria{{$proyecto->inmobiliaria()->nombreCompleto()}}
    Inicio + {{$proyecto->estados()[0]->tipoEstadoProyecto->descripcion}} + [{{$proyecto->estados()[0]->tipoEstadoProyecto->etapa->descripcion}}] + ({{$proyecto->estados()[0]->fecha->format('d-m-Y')}}) + ({{$today->diff($proyecto->estados()[0]->fecha)->format('%y años antes')}}) +
    Estado + {{$proyecto->currentEstado()->tipoEstadoProyecto->descripcion}} + [{{$proyecto->currentEstado()->tipoEstadoProyecto->etapa->descripcion}}] + ({{$proyecto->currentEstado()->fecha->format('d-m-Y')}}) + ({{$today->diff($proyecto->currentEstado()->fecha)->format('%y años antes')}}) + + + +
    Superficies + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + Total + + + + {{$format->number($proyecto->superficie->total(), 2)}}m² + +
    Bajo Nivel{{$format->number($proyecto->superficie->bajo_nivel, 2)}}m²
    Sobre Nivel{{$format->number($proyecto->superficie->sobre_nivel, 2)}}m²
    + + Vendible + + + +
    Vendido
    Por Vender
    +
    Unidades
    Ventas
    Stock
    Proyección
    +
    +@endsection + +@include('layout.body.scripts.chartjs') + +@push('page_scripts') + +@endpush diff --git a/app/src/Controller/API/Proyectos.php b/app/src/Controller/API/Proyectos.php index 5ed2152..2cf3608 100644 --- a/app/src/Controller/API/Proyectos.php +++ b/app/src/Controller/API/Proyectos.php @@ -3,13 +3,15 @@ namespace Incoviba\Controller\API; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Incoviba\Common\Implement\Exception\EmptyRedis; use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Repository; use Incoviba\Model; +use Incoviba\Service; class Proyectos { - use withJson; + use withJson, withRedis; public function list(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface { @@ -34,26 +36,88 @@ class Proyectos } catch (EmptyResult) {} return $this->withJson($response, $output); } - public function unidades(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface + public function unidades(ServerRequestInterface $request, ResponseInterface $response, + Repository\Venta\Unidad $unidadRepository, Service\Redis $redisService, + int $proyecto_id): ResponseInterface { $output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0]; + $redisKey = "unidades-proyecto-{$proyecto_id}"; try { - $unidades = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id); - $tipos = []; - foreach ($unidades as $unidad) { - if (!isset($tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion])) { - $tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] = []; + $output = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + 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; } - $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); + 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); + $this->saveRedis($redisService, $redisKey, $output); + } catch (EmptyResult) {} + } + return $this->withJson($response, $output); + } + public function disponibles(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface + { + $output = [ + 'proyecto_id' => $proyecto_id, + 'unidades' => [] + ]; + try { + $output['unidades'] = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id); } catch (EmptyResult) {} return $this->withJson($response, $output); } + public function superficies(ServerRequestInterface $request, ResponseInterface $response, + Repository\Proyecto $proyectoRepository, Repository\Venta $ventaRepository, + Repository\Venta\Unidad $unidadRepository, Service\Redis $redisService, + Service\Format $formatService, int $proyecto_id): ResponseInterface + { + $output = [ + 'proyecto_id' => $proyecto_id, + 'superficies' => [ + 'vendible' => 0, + 'vendido' => 0, + 'por_vender' => 0 + ], + 'formatted' => [ + 'vendible' => '0m²', + 'vendido' => '0m²', + 'por_vender' => '0m²' + ] + ]; + $redisKey = "superficices-proyecto-{$proyecto_id}"; + try { + $output = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $ventas = $ventaRepository->fetchActivaByProyecto($proyecto_id); + $unidades = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id); + + $output['superficies']['vendido'] = array_reduce($ventas, function($sum, Model\Venta $venta) { + return $sum + array_reduce($venta->propiedad()->unidades, function($sum, Model\Venta\Unidad $unidad) { + return $sum + $unidad->proyectoTipoUnidad->vendible(); + }); + }, 0); + $output['formatted']['vendido'] = "{$formatService->number($output['superficies']['vendido'], 2)}m²"; + $output['superficies']['por_vender'] = array_reduce($unidades, function($sum, Model\Venta\Unidad $unidad) { + return $sum + $unidad->proyectoTipoUnidad->vendible(); + }); + $output['formatted']['por_vender'] = "{$formatService->number($output['superficies']['por_vender'], 2)}m²"; + $output['superficies']['vendible'] = $output['superficies']['vendido'] + $output['superficies']['por_vender']; + $output['formatted']['vendible'] = "{$formatService->number($output['superficies']['vendible'], 2)}m²"; + $this->saveRedis($redisService, $redisKey, $output, 60 * 60); + } catch (EmptyResult) {} + } + return $this->withJson($response, $output); + } } diff --git a/app/src/Controller/API/Ventas.php b/app/src/Controller/API/Ventas.php index 87deea0..2604ae1 100644 --- a/app/src/Controller/API/Ventas.php +++ b/app/src/Controller/API/Ventas.php @@ -54,7 +54,7 @@ class Ventas $json = json_decode($body->getContents()); $proyecto_id = $json->proyecto_id; $today = new DateTimeImmutable(); - $redisKey = "promesas_por_firmar-{$proyecto_id}-{$today->format('Y-m-d')}"; + $redisKey = "promesas_por_firmar-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}"; $output = [ 'proyecto_id' => $proyecto_id, @@ -80,7 +80,7 @@ class Ventas $json = json_decode($body->getContents()); $proyecto_id = $json->proyecto_id; $today = new DateTimeImmutable(); - $redisKey = "escrituras-{$proyecto_id}-{$today->format('Y-m-d')}"; + $redisKey = "escrituras-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}"; $output = [ 'proyecto_id' => $proyecto_id, diff --git a/app/src/Controller/API/Ventas/Precios.php b/app/src/Controller/API/Ventas/Precios.php new file mode 100644 index 0000000..927e815 --- /dev/null +++ b/app/src/Controller/API/Ventas/Precios.php @@ -0,0 +1,36 @@ +getBody(); + $json = json_decode($body->getContents()); + $proyecto_id = $json->proyecto_id; + $output = ['total' => 0]; + try { + $precios = $precioService->getByProyecto($proyecto_id); + $output['precios'] = $precios; + $output['total'] = count($precios); + } catch (EmptyResult) {} + return $this->withJson($response, $output); + } + public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface + { + try { + $precio = $precioService->getVigenteByUnidad($unidad_id); + return $this->withJson($response, compact('precio')); + } catch (EmptyResult) { + return $this->emptyBody($response); + } + } +} diff --git a/app/src/Controller/API/Ventas/Unidades.php b/app/src/Controller/API/Ventas/Unidades.php index 398f3af..9f8538f 100644 --- a/app/src/Controller/API/Ventas/Unidades.php +++ b/app/src/Controller/API/Ventas/Unidades.php @@ -22,7 +22,7 @@ class Unidades $json = json_decode($body->getContents()); $proyecto_id = $json->proyecto_id; $today = new DateTimeImmutable(); - $redisKey = "unidades_disponibles-{$proyecto_id}-{$today->format('Y-m-d')}"; + $redisKey = "unidades_disponibles-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}"; $output = [ 'proyecto_id' => $proyecto_id, diff --git a/app/src/Controller/Proyectos.php b/app/src/Controller/Proyectos.php index 81c53b9..4f62910 100644 --- a/app/src/Controller/Proyectos.php +++ b/app/src/Controller/Proyectos.php @@ -4,8 +4,9 @@ namespace Incoviba\Controller; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Incoviba\Common\Alias\View; -use Incoviba\Repository; use Incoviba\Model; +use Incoviba\Repository; +use Incoviba\Service; class Proyectos { @@ -29,4 +30,9 @@ class Proyectos }); return $view->render($response, 'proyectos.unidades', compact('proyectos')); } + public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Proyecto $proyectoService, int $proyecto_id): ResponseInterface + { + $proyecto = $proyectoService->getById($proyecto_id); + return $view->render($response, 'proyectos.show', compact('proyecto')); + } } diff --git a/app/src/Controller/Ventas/Precios.php b/app/src/Controller/Ventas/Precios.php index 6a96459..890d749 100644 --- a/app/src/Controller/Ventas/Precios.php +++ b/app/src/Controller/Ventas/Precios.php @@ -1,7 +1,6 @@ $proyecto->id, 'descripcion' => $proyecto->descripcion];}, $proyectoService->getVendibles()); return $view->render($response, 'ventas.precios.list', compact('proyectos')); } - public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService): ResponseInterface - { - $body = $request->getBody(); - $json = json_decode($body->getContents()); - $proyecto_id = $json->proyecto_id; - $output = ['total' => 0]; - try { - $precios = $precioService->getByProyecto($proyecto_id); - $output['precios'] = $precios; - $output['total'] = count($precios); - } catch (EmptyResult) {} - $response->getBody()->write(json_encode($output)); - return $response->withHeader('Content-Type', 'application/json'); - } - public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface - { - $precio = $precioService->getVigenteByUnidad($unidad_id); - $response->getBody()->write(json_encode(['precio' => $precio])); - return $response->withHeader('Content-Type', 'application/json'); - } } diff --git a/app/src/Model/Proyecto.php b/app/src/Model/Proyecto.php index a0ab993..d4a2e69 100644 --- a/app/src/Model/Proyecto.php +++ b/app/src/Model/Proyecto.php @@ -1,6 +1,7 @@ inmobiliaria)) { @@ -29,6 +33,20 @@ class Proyecto extends Ideal\Model } return $this->direccion; } + public function estados(): array + { + if (!isset($this->estados)) { + $this->estados = $this->runFactory('estados'); + } + return $this->estados; + } + public function currentEstado(): Proyecto\EstadoProyecto + { + if (!isset($this->currentEstado)) { + $this->currentEstado = $this->runFactory('currentEstado'); + } + return $this->currentEstado; + } public function jsonSerialize(): mixed { diff --git a/app/src/Model/Proyecto/Superficie.php b/app/src/Model/Proyecto/Superficie.php index 72d6e5f..da7e1a9 100644 --- a/app/src/Model/Proyecto/Superficie.php +++ b/app/src/Model/Proyecto/Superficie.php @@ -5,4 +5,9 @@ class Superficie { public float $sobre_nivel; public float $bajo_nivel; + + public function total(): float + { + return $this->bajo_nivel + $this->sobre_nivel; + } } diff --git a/app/src/Model/Venta/Propiedad.php b/app/src/Model/Venta/Propiedad.php index 0e18cea..546a984 100644 --- a/app/src/Model/Venta/Propiedad.php +++ b/app/src/Model/Venta/Propiedad.php @@ -9,15 +9,15 @@ class Propiedad extends Ideal\Model public function departamentos(): array { - return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento';}); + return array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento';})); } public function estacionamientos(): array { - return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'estacionamiento';}); + return array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'estacionamiento';})); } public function bodegas(): array { - return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'bodega';}); + return array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'bodega';})); } protected float $vendible; diff --git a/app/src/Repository/Proyecto.php b/app/src/Repository/Proyecto.php index 21b1c7e..e03de3b 100644 --- a/app/src/Repository/Proyecto.php +++ b/app/src/Repository/Proyecto.php @@ -92,6 +92,10 @@ WHERE et.`orden` BETWEEN {$etapaRecepcion->orden} AND ({$etapaTerminado->orden} ORDER BY a.`descripcion`"; return $this->fetchMany($query); } + public function fetchSuperficieVendido(int $proyecto_id): float + { + + } protected function joinEstado(): string { diff --git a/app/src/Service/Redis.php b/app/src/Service/Redis.php index 1d7f050..d8d61ce 100644 --- a/app/src/Service/Redis.php +++ b/app/src/Service/Redis.php @@ -15,8 +15,8 @@ class Redis } return $this->client->get($name); } - public function set(string $name, mixed $value): void + public function set(string $name, mixed $value, int $expirationTTL = 60 * 60 * 24): void { - $this->client->set($name, $value, 'EX', 60 * 60 * 24); + $this->client->set($name, $value, 'EX', $expirationTTL); } } From 9ab051595459575ff2c9045a8e7d3a156fddb655 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Wed, 22 Nov 2023 19:08:19 -0300 Subject: [PATCH 027/163] Facturacion --- app/common/Define/Connection.php | 1 + app/common/Define/Model.php | 1 + app/common/Define/Query.php | 15 + app/common/Define/Query/Builder.php | 33 ++ app/common/Define/Query/Create.php | 31 ++ .../Define/Query/Create/CreateDefinition.php | 59 +++ app/common/Define/Query/Delete.php | 12 + app/common/Define/Query/Insert.php | 32 ++ app/common/Define/Query/Select.php | 62 +++ app/common/Define/Query/Update.php | 13 + app/common/Define/Repository/Mapper.php | 4 + app/common/Ideal/Query.php | 12 + app/common/Ideal/Repository.php | 28 +- app/common/Implement/Connection.php | 6 +- .../Implement/Database/Query/Builder.php | 29 ++ .../Implement/Database/Query/Create.php | 102 +++++ .../Database/Query/Create/Definition.php | 104 +++++ .../Implement/Database/Query/Delete.php | 89 ++++ .../Implement/Database/Query/Insert.php | 87 ++++ .../Implement/Database/Query/Select.php | 215 ++++++++++ .../Implement/Database/Query/Update.php | 113 ++++++ app/resources/routes/api/money.php | 7 + app/resources/routes/api/ventas.php | 1 + .../routes/api/ventas/facturacion.php | 6 + app/resources/routes/ventas/facturacion.php | 6 + .../views/proyectos/unidades.blade.php | 1 + .../views/ventas/facturacion.blade.php | 384 ++++++++++++++++++ .../views/ventas/facturacion/show.blade.php | 11 + app/setup/middlewares/97_not_found.php | 1 + app/setup/setups/database.php | 3 +- app/src/Controller/API/Money.php | 123 ++++++ app/src/Controller/API/Ventas.php | 19 +- app/src/Controller/API/Ventas/Facturacion.php | 36 ++ app/src/Controller/API/withRedis.php | 6 +- app/src/Controller/Ventas/Facturacion.php | 21 + app/src/Middleware/Errors.php | 31 ++ app/src/Model/Proyecto/Superficie.php | 13 +- app/src/Model/Proyecto/Terreno.php | 15 +- app/src/Model/Venta/Unidad.php | 4 +- app/src/Repository/Proyecto.php | 50 ++- app/src/Repository/Venta/Unidad.php | 86 ++-- app/src/Service/Money.php | 11 + app/src/Service/Money/MiIndicador.php | 7 + app/src/Service/Proyecto.php | 4 + app/src/Service/Venta/Unidad.php | 23 +- 45 files changed, 1846 insertions(+), 71 deletions(-) create mode 100644 app/common/Define/Query.php create mode 100644 app/common/Define/Query/Builder.php create mode 100644 app/common/Define/Query/Create.php create mode 100644 app/common/Define/Query/Create/CreateDefinition.php create mode 100644 app/common/Define/Query/Delete.php create mode 100644 app/common/Define/Query/Insert.php create mode 100644 app/common/Define/Query/Select.php create mode 100644 app/common/Define/Query/Update.php create mode 100644 app/common/Ideal/Query.php create mode 100644 app/common/Implement/Database/Query/Builder.php create mode 100644 app/common/Implement/Database/Query/Create.php create mode 100644 app/common/Implement/Database/Query/Create/Definition.php create mode 100644 app/common/Implement/Database/Query/Delete.php create mode 100644 app/common/Implement/Database/Query/Insert.php create mode 100644 app/common/Implement/Database/Query/Select.php create mode 100644 app/common/Implement/Database/Query/Update.php create mode 100644 app/resources/routes/api/money.php create mode 100644 app/resources/routes/api/ventas/facturacion.php create mode 100644 app/resources/routes/ventas/facturacion.php create mode 100644 app/resources/views/ventas/facturacion.blade.php create mode 100644 app/resources/views/ventas/facturacion/show.blade.php create mode 100644 app/src/Controller/API/Money.php create mode 100644 app/src/Controller/API/Ventas/Facturacion.php create mode 100644 app/src/Controller/Ventas/Facturacion.php create mode 100644 app/src/Middleware/Errors.php diff --git a/app/common/Define/Connection.php b/app/common/Define/Connection.php index 577c094..a35af54 100644 --- a/app/common/Define/Connection.php +++ b/app/common/Define/Connection.php @@ -11,4 +11,5 @@ interface Connection public function prepare(string $query): PDOStatement; public function execute(string $query, ?array $data = null): PDOStatement; public function getPDO(): PDO; + public function getQueryBuilder(): Query\Builder; } diff --git a/app/common/Define/Model.php b/app/common/Define/Model.php index d7910fd..2f42207 100644 --- a/app/common/Define/Model.php +++ b/app/common/Define/Model.php @@ -5,4 +5,5 @@ use JsonSerializable; interface Model extends JsonSerializable { + public function addFactory(string $property, Repository\Factory $factory): Model; } diff --git a/app/common/Define/Query.php b/app/common/Define/Query.php new file mode 100644 index 0000000..f22208a --- /dev/null +++ b/app/common/Define/Query.php @@ -0,0 +1,15 @@ +build(); + } +} diff --git a/app/common/Ideal/Repository.php b/app/common/Ideal/Repository.php index cb49210..993d62c 100644 --- a/app/common/Ideal/Repository.php +++ b/app/common/Ideal/Repository.php @@ -31,18 +31,25 @@ abstract class Repository implements Define\Repository public function remove(Define\Model $model): void { - $query = "DELETE FROM `{$this->getTable()}` WHERE `{$this->getKey()}` = ?"; - $this->connection->execute($query, [$model->getId()]); + $query = $this->connection->getQueryBuilder() + ->delete()->from($this->getTable()) + ->where("{$this->getKey()} = ?"); + $this->connection->execute($query, [$model->id]); } public function fetchById(int $id): Define\Model { - $query = "SELECT * FROM `{$this->getTable()}` WHERE `{$this->getKey()}` = ?"; + $query = $this->connection->getQueryBuilder() + ->select() + ->from($this->getTable()) + ->where("{$this->getKey()} = ?"); return $this->fetchOne($query, [$id]); } public function fetchAll(): array { - $query = "SELECT * FROM `{$this->getTable()}`"; + $query = $this->connection->getQueryBuilder() + ->select() + ->from($this->getTable()); return $this->fetchMany($query); } @@ -96,9 +103,11 @@ abstract class Repository implements Define\Repository } protected function saveNew(array $columns, array $values): int { - $columns_string = implode(', ', array_map(function($column) {return "`{$column}`";}, $columns)); - $columns_questions = implode(', ', array_fill(0, count($columns), '?')); - $query = "INSERT INTO `{$this->getTable()}` ({$columns_string}) VALUES ($columns_questions)"; + $query = $this->connection->getQueryBuilder() + ->insert() + ->into($this->getTable()) + ->columns($columns) + ->values(array_fill(0, count($columns), '?')); $this->connection->execute($query, $values); return $this->connection->getPDO()->lastInsertId(); } @@ -117,7 +126,10 @@ abstract class Repository implements Define\Repository return $model; } $columns_string = implode(', ', array_map(function($property) {return "`{$property}` = ?";}, $changes)); - $query = "UPDATE `{$this->getTable()}` SET {$columns_string} WHERE `{$this->getKey()}` = ?"; + $query = $this->connection->getQueryBuilder() + ->update($this->getTable()) + ->set($columns_string) + ->where("{$this->getKey()} = ?"); $values []= $model->{$this->getKey()}; $this->connection->execute($query, $values); return $this->fetchById($model->{$this->getKey()}); diff --git a/app/common/Implement/Connection.php b/app/common/Implement/Connection.php index bcb6eab..761151a 100644 --- a/app/common/Implement/Connection.php +++ b/app/common/Implement/Connection.php @@ -8,7 +8,7 @@ use Incoviba\Common\Define; class Connection implements Define\Connection { - public function __construct(protected Define\Database $database) {} + public function __construct(protected Define\Database $database, protected Database\Query\Builder $queryBuilder) {} protected PDO $connection; public function connect(): Define\Connection @@ -27,6 +27,10 @@ class Connection implements Define\Connection $this->connect(); return $this->connection; } + public function getQueryBuilder(): Database\Query\Builder + { + return $this->queryBuilder; + } public function query(string $query): PDOStatement { diff --git a/app/common/Implement/Database/Query/Builder.php b/app/common/Implement/Database/Query/Builder.php new file mode 100644 index 0000000..82a3c5f --- /dev/null +++ b/app/common/Implement/Database/Query/Builder.php @@ -0,0 +1,29 @@ +table($table_name); + } + + public function select(array|string $columns = '*'): Select + { + return (new Select())->columns($columns); + } + public function insert(): Insert + { + return new Insert(); + } + public function update(string $table): Update + { + return (new Update())->table($table); + } + public function delete(): Delete + { + return new Delete(); + } +} diff --git a/app/common/Implement/Database/Query/Create.php b/app/common/Implement/Database/Query/Create.php new file mode 100644 index 0000000..2c21bfe --- /dev/null +++ b/app/common/Implement/Database/Query/Create.php @@ -0,0 +1,102 @@ +name = $name; + return $this; + } + public function definitions(Define\Query\Create\CreateDefinition|array|string $create_definitions): Define\Query\Create + { + if (is_array($create_definitions)) { + foreach ($create_definitions as $definition) { + $this->addDefinition($definition); + } + return $this; + } + return $this->addDefinition($create_definitions); + } + public function options(array|string $table_options): Define\Query\Create + { + if (is_string($table_options)) { + return $this->addOption($table_options); + } + foreach ($table_options as $option) { + $this->addOption($option); + } + return $this; + } + public function partition(array|string $partition_options): Define\Query\Create + { + if (is_string($partition_options)) { + return $this->addPartition($partition_options); + } + foreach ($partition_options as $option) { + $this->addPartition($option); + } + return $this; + } + public function build(): string + { + $query = [ + "CREATE TABLE {$this->name}", + $this->getDefinitions(), + $this->getOptions(), + $this->getPartitions() + ]; + return implode('', $query); + } + + protected function addDefinition(string $definition): Create + { + if (!isset($this->definitions)) { + $this->definitions = []; + } + $this->definitions []= $definition; + return $this; + } + protected function addOption(string $option): Create + { + if (!isset($this->options)) { + $this->options = []; + } + $this->options []= $option; + return $this; + } + protected function addPartition(string $partition): Create + { + if (!isset($this->partitions)) { + $this->partitions = []; + } + $this->partitions []= $partition; + return $this; + } + protected function getDefinitions(): string + { + return ' (' . implode(', ', $this->definitions) . ')'; + } + protected function getOptions(): string + { + if (!isset($this->options) or count($this->options) <= 0) { + return ''; + } + return ' ' . implode(' ', $this->options); + } + protected function getPartitions(): string + { + if (!isset($this->partitions) or count($this->partitions) <= 0) { + return ''; + } + return ' PARTITION BY (' . implode(', ', $this->partitions) . ')'; + } +} diff --git a/app/common/Implement/Database/Query/Create/Definition.php b/app/common/Implement/Database/Query/Create/Definition.php new file mode 100644 index 0000000..a81680c --- /dev/null +++ b/app/common/Implement/Database/Query/Create/Definition.php @@ -0,0 +1,104 @@ +name = $name; + return $this; + } + public function type(string $type, ?int $size = null): CreateDefinition + { + $this->type = $type; + if ($size !== null) { + $this->size = $size; + } + return $this; + } + public function primary(): CreateDefinition + { + $this->primary = true; + return $this; + } + public function autoIncrement(): CreateDefinition + { + $this->auto_increment = true; + return $this; + } + public function unsigned(): CreateDefinition + { + $this->unsigned = true; + return $this; + } + public function default(mixed $value): CreateDefinition + { + $this->default = $value; + return $this; + } + public function foreign(string $reference_table, string $reference_column = 'id', int $on_delete = CreateDefinition::CASCADE, int $on_update = CreateDefinition::CASCADE): CreateDefinition + { + $this->foreign_table = $reference_table; + $this->foreign_key = $reference_column; + $this->foreign_delete = $on_delete; + $this->foreign_update = $on_update; + return $this; + } + + public function __toString(): string + { + $type = $this->type ?? 'int'; + if (isset($this->size)) { + $type = "{$type}({$this->size})"; + } elseif (in_array($type, ['varchar'])) { + $type = "{$type}(255)"; + } + $output = [ + "`{$this->name}`", + $type + ]; + if (isset($this->unsigned)) { + $output []= 'UNSIGNED'; + } + if (isset($this->default)) { + $default = $this->default; + if (in_array($this->type, ['varchar', 'text', 'char'])) { + $default = "'{$default}'"; + } + $output []= "DEFAULT {$default}"; + } + if (isset($this->auto_increment)) { + $output []= 'AUTO_INCREMENT'; + } + if (isset($this->primary)) { + $output []= 'PRIMARY KEY'; + } + if (isset($this->foreign_table)) { + $output []= "REFERENCES `{$this->foreign_table}` (`{$this->foreign_key}`)"; + $on = [ + 'RESTRICT', + 'CASCADE', + 'SET_NULL', + 'NO_ACTION', + 'SET_DEFAULT' + ]; + $output []= "ON DELETE {$on[$this->foreign_delete]}"; + $output []= "ON UPDATE {$on[$this->foreign_update]}"; + } + return implode(' ', $output); + } +} diff --git a/app/common/Implement/Database/Query/Delete.php b/app/common/Implement/Database/Query/Delete.php new file mode 100644 index 0000000..c193d98 --- /dev/null +++ b/app/common/Implement/Database/Query/Delete.php @@ -0,0 +1,89 @@ +table = $table; + return $this; + } + public function where(array|string $conditions): Delete + { + if (is_string($conditions)) { + return $this->addCondition($conditions); + } + foreach ($conditions as $condition) { + $this->addCondition($condition); + } + return $this; + } + public function order(array|string $sorting): Delete + { + if (is_string($sorting)) { + return $this->addOrder($sorting); + } + foreach ($sorting as $order) { + $this->addOrder($order); + } + return $this; + } + public function limit(int $limit): Delete + { + $this->limit = $limit; + return $this; + } + public function build(): string + { + $query = [ + "DELETE FROM {$this->table}", + $this->getConditions(), + $this->getSorting(), + $this->getLimit() + ]; + return implode('', $query); + } + + protected function addCondition(string $condition): Delete + { + if (!isset($this->conditions)) { + $this->conditions = []; + } + $this->conditions []= $condition; + return $this; + } + protected function getConditions(): string + { + return ' WHERE ' . implode(' AND ', $this->conditions); + } + protected function addOrder(string $order): Delete + { + if (!isset($this->sorts)) { + $this->sorts = []; + } + $this->sorts []= $order; + return $this; + } + protected function getSorting(): string + { + if (!isset($this->sorts) or count($this->sorts) === 0) { + return ''; + } + return ' ORDER BY ' . implode(', ', $this->sorts); + } + protected function getLimit(): string + { + if (!isset($this->limit) or $this->limit <= 0) { + return ''; + } + return " LIMIT {$this->limit}"; + } +} diff --git a/app/common/Implement/Database/Query/Insert.php b/app/common/Implement/Database/Query/Insert.php new file mode 100644 index 0000000..6c9b7cf --- /dev/null +++ b/app/common/Implement/Database/Query/Insert.php @@ -0,0 +1,87 @@ +table = $table; + if ($columns !== null) { + return $this->columns($columns); + } + return $this; + } + public function columns(array $columns): Insert + { + foreach ($columns as $column) { + $this->addColumn($column); + } + return $this; + } + public function values(array $values): Insert + { + foreach ($values as $value) { + $this->addValue($value); + } + return $this; + } + public function select(Define\Query\Select $select): Insert + { + $this->select = $select; + return $this; + } + public function build(): string + { + $query = [ + "INSERT INTO {$this->table}" + ]; + if (isset($this->select)) { + $query []= " {$this->select}"; + return implode('', $query); + } + $query []= $this->getColumns(); + $query []= $this->getValues(); + return implode('', $query); + } + + protected function addColumn(string $column): Insert + { + if (!isset($this->columns)) { + $this->columns = []; + } + $this->columns []= $column; + return $this; + } + protected function addValue(mixed $value): Insert + { + if (!isset($this->values)) { + $this->values = []; + } + $this->values []= $value; + return $this; + } + protected function getColumns(): string + { + return ' (' . implode(', ', array_map(function(string $column) {return "`{$column}`";}, $this->columns)) . ')'; + } + protected function getValues(): string + { + return ' VALUES (' . implode(', ', array_map(function($value) { + if ($value === '?') { + return $value; + } + if ($value === (int) $value) { + return $value; + } + return "'{$value}'"; + }, $this->values)) . ')'; + } +} diff --git a/app/common/Implement/Database/Query/Select.php b/app/common/Implement/Database/Query/Select.php new file mode 100644 index 0000000..0f7a88b --- /dev/null +++ b/app/common/Implement/Database/Query/Select.php @@ -0,0 +1,215 @@ +addColumn($expressions); + } + foreach ($expressions as $expression) { + $this->addColumn($expression); + } + return $this; + } + public function from(string $table): Select + { + $this->table = $table; + return $this; + } + public function joined(array|string $joins): Select + { + if (is_string($joins)) { + return $this->addJoin($joins); + } + foreach ($joins as $join) { + $this->addJoin($join); + } + return $this; + } + public function where(array|string $conditions): Select + { + if (is_string($conditions)) { + return $this->addCondition($conditions); + } + foreach ($conditions as $condition) { + $this->addCondition($condition); + } + return $this; + } + public function group(array|string $grouping): Select + { + if (is_string($grouping)) { + return $this->addGroup($grouping); + } + foreach ($grouping as $group) { + $this->addGroup($group); + } + return $this; + } + public function having(array|string $conditions): Select + { + if (is_string($conditions)) { + return $this->addCondition($conditions); + } + foreach ($conditions as $condition) { + $this->addCondition($condition); + } + return $this; + } + public function order(array|string $sorting): Select + { + if (is_string($sorting)) { + return $this->addOrder($sorting); + } + foreach ($sorting as $order) { + $this->addOrder($order); + } + return $this; + } + public function limit(int $limit, ?int $offset = null): Select + { + $this->limit = $limit; + if ($offset !== null) { + return $this->offset($offset); + } + return $this; + } + public function offset(int $offset): Select + { + $this->offset = $offset; + return $this; + } + public function build(): string + { + $query = [ + "SELECT {$this->getColumns()} FROM {$this->table}", + $this->getJoins(), + $this->getConditions(), + $this->getGroups(), + $this->getHaving(), + $this->getOrder(), + $this->getLimit() + ]; + return implode('', $query); + } + + protected function addColumn(string $expression): Select + { + if (!isset($this->columns)) { + $this->columns = []; + } + $this->columns []= $expression; + return $this; + } + protected function addJoin(string $join): Select + { + if (!isset($this->joins)) { + $this->joins = []; + } + $this->joins []= $join; + return $this; + } + protected function addCondition(string $condition): Select + { + if (!isset($this->coditions)) { + $this->conditions = []; + } + $this->conditions []= $condition; + return $this; + } + protected function addGroup(string $group): Select + { + if (!isset($this->groups)) { + $this->groups = []; + } + $this->groups []= $group; + return $this; + } + protected function addHaving(string $having): Select + { + if (!isset($this->haves)) { + $this->haves = []; + } + $this->haves []= $having; + return $this; + } + protected function addOrder(string $order): Select + { + if (!isset($this->orders)) { + $this->orders = []; + } + $this->orders []= $order; + return $this; + } + protected function getColumns(): string + { + if (!isset($this->columns) or count($this->columns) === 0) { + return '*'; + } + return implode(', ', $this->columns); + } + protected function getJoins(): string + { + if (!isset($this->joins) or count($this->joins) === 0) { + return ''; + } + return ' ' . implode(' ', $this->joins); + } + protected function getConditions(): string + { + if (!isset($this->conditions) or count($this->conditions) === 0) { + return ''; + } + return ' WHERE ' . implode(' AND ', $this->conditions); + } + protected function getGroups(): string + { + if (!isset($this->groups) or count($this->groups) === 0) { + return ''; + } + return ' GROUP BY ' . implode(', ', $this->groups); + } + protected function getHaving(): string + { + if (!isset($this->haves) or count($this->haves) === 0) { + return ''; + } + return ' HAVING ' . implode(' AND ', $this->haves); + } + protected function getOrder(): string + { + if (!isset($this->orders) or count($this->orders) === 0) { + return ''; + } + return ' ORDER BY ' . implode(', ', $this->orders); + } + protected function getLimit(): string + { + if (!isset($this->limit) or $this->limit <= 0) { + return ''; + } + return " LIMIT {$this->limit}{$this->getOffset()}"; + } + protected function getOffset(): string + { + if (!isset($this->offset) or $this->offset <= 0) { + return ''; + } + return " OFFSET {$this->offset}"; + } +} diff --git a/app/common/Implement/Database/Query/Update.php b/app/common/Implement/Database/Query/Update.php new file mode 100644 index 0000000..f671363 --- /dev/null +++ b/app/common/Implement/Database/Query/Update.php @@ -0,0 +1,113 @@ +table = $table; + return $this; + } + public function set(array|string $column_pairs): Define\Query\Update + { + if (is_string($column_pairs)) { + return $this->addSet($column_pairs); + } + foreach ($column_pairs as $pair) { + $this->addSet($pair); + } + return $this; + } + public function where(array|string $conditions): Define\Query\Update + { + if (is_string($conditions)) { + return $this->addCondition($conditions); + } + foreach ($conditions as $condition) { + $this->addCondition($condition); + } + return $this; + } + public function order(array|string $ordering): Define\Query\Update + { + if (is_string($ordering)) { + return $this->addOrder($ordering); + } + foreach ($ordering as $order) { + $this->addOrder($order); + } + return $this; + } + public function limit(int $limit): Define\Query\Update + { + $this->limit = $limit; + return $this; + } + public function build(): string + { + $query = [ + "UPDATE {$this->table}", + $this->getSet(), + $this->getConditions(), + $this->getOrder(), + $this->getLimit() + ]; + return implode('', $query); + } + + protected function addSet(string $pair): Update + { + if (!isset($this->setPairs)) { + $this->setPairs = []; + } + $this->setPairs []= $pair; + return $this; + } + protected function addCondition(string $condition): Update + { + if (!isset($this->conditions)) { + $this->conditions = []; + } + $this->conditions []= $condition; + return $this; + } + protected function addOrder(string $order): Update + { + if (!isset($this->orders)) { + $this->orders = []; + } + $this->orders []= $order; + return $this; + } + protected function getSet(): string + { + return ' SET ' . implode(', ', $this->setPairs); + } + protected function getConditions(): string + { + return ' WHERE ' . implode(' AND ', $this->conditions); + } + protected function getOrder(): string + { + if (!isset($this->orders) or count($this->orders) === 0) { + return ''; + } + return ' ORDER BY ' . implode(', ', $this->orders); + } + protected function getLimit(): string + { + if (!isset($this->limit) or $this->limit <= 0) { + return ''; + } + return " LIMIT {$this->limit}"; + } +} diff --git a/app/resources/routes/api/money.php b/app/resources/routes/api/money.php new file mode 100644 index 0000000..2f3fb4c --- /dev/null +++ b/app/resources/routes/api/money.php @@ -0,0 +1,7 @@ +group('/money', function($app) { + $app->post('/ipc[/]', [Money::class, 'ipc']); + $app->post('[/]', [Money::class, 'get']); +}); diff --git a/app/resources/routes/api/ventas.php b/app/resources/routes/api/ventas.php index a635e6b..894128d 100644 --- a/app/resources/routes/api/ventas.php +++ b/app/resources/routes/api/ventas.php @@ -22,6 +22,7 @@ $app->group('/ventas', function($app) { $app->post('[/]', [Ventas::class, 'proyecto']); }); $app->group('/venta/{venta_id}', function($app) { + $app->get('/unidades', [Ventas::class, 'unidades']); $app->get('/comentarios', [Ventas::class, 'comentarios']); $app->get('[/]', [Ventas::class, 'get']); }); diff --git a/app/resources/routes/api/ventas/facturacion.php b/app/resources/routes/api/ventas/facturacion.php new file mode 100644 index 0000000..cae92a8 --- /dev/null +++ b/app/resources/routes/api/ventas/facturacion.php @@ -0,0 +1,6 @@ +group('/facturacion', function($app) { + $app->get('/proyecto/{proyecto_id}[/]', [Facturacion::class, 'proyecto']); +}); diff --git a/app/resources/routes/ventas/facturacion.php b/app/resources/routes/ventas/facturacion.php new file mode 100644 index 0000000..b49f175 --- /dev/null +++ b/app/resources/routes/ventas/facturacion.php @@ -0,0 +1,6 @@ +group('/facturacion', function($app) { + $app->get('[/]', Facturacion::class); +}); diff --git a/app/resources/views/proyectos/unidades.blade.php b/app/resources/views/proyectos/unidades.blade.php index c61af0c..75cfd88 100644 --- a/app/resources/views/proyectos/unidades.blade.php +++ b/app/resources/views/proyectos/unidades.blade.php @@ -224,6 +224,7 @@ const proyecto_id = element.data('proyecto') this.get().tipos(proyecto_id) }) + $('#data').hide() } } $(document).ready(() => { diff --git a/app/resources/views/ventas/facturacion.blade.php b/app/resources/views/ventas/facturacion.blade.php new file mode 100644 index 0000000..7878c84 --- /dev/null +++ b/app/resources/views/ventas/facturacion.blade.php @@ -0,0 +1,384 @@ +@extends('layout.base') + +@section('page_content') +
    +

    Matriz Facturación

    +

    +
    +
    Proyectos
    +
    +
    + + +
    +
    +
    +

    + +
    +
    +@endsection + +@include('layout.head.styles.datatables') +@include('layout.body.scripts.datatables') + +@push('page_scripts') + +@endpush diff --git a/app/resources/views/ventas/facturacion/show.blade.php b/app/resources/views/ventas/facturacion/show.blade.php new file mode 100644 index 0000000..07e844e --- /dev/null +++ b/app/resources/views/ventas/facturacion/show.blade.php @@ -0,0 +1,11 @@ +@extends('layout.base') + +@section('page_content') +
    + +
    + +
    + +
    +@endsection diff --git a/app/setup/middlewares/97_not_found.php b/app/setup/middlewares/97_not_found.php index 9a61f5f..14d5c25 100644 --- a/app/setup/middlewares/97_not_found.php +++ b/app/setup/middlewares/97_not_found.php @@ -1,2 +1,3 @@ add($app->getContainer()->get(Incoviba\Middleware\NotFound::class)); +$app->add($app->getContainer()->get(Incoviba\Middleware\Errors::class)); diff --git a/app/setup/setups/database.php b/app/setup/setups/database.php index 3cfd071..5ef8d8f 100644 --- a/app/setup/setups/database.php +++ b/app/setup/setups/database.php @@ -12,7 +12,8 @@ return [ }, Incoviba\Common\Define\Connection::class => function(ContainerInterface $container) { return new Incoviba\Common\Implement\Connection( - $container->get(Incoviba\Common\Define\Database::class) + $container->get(Incoviba\Common\Define\Database::class), + $container->get(Incoviba\Common\Implement\Database\Query\Builder::class) ); } ]; diff --git a/app/src/Controller/API/Money.php b/app/src/Controller/API/Money.php new file mode 100644 index 0000000..74d0527 --- /dev/null +++ b/app/src/Controller/API/Money.php @@ -0,0 +1,123 @@ +getParsedBody(); + $output = [ + 'input' => $data + ]; + $output[$data['provider']] = 0; + $redisKey = $data['provider']; + $date = new DateTimeImmutable($data['fecha']); + if (isset($data['start'])) { + $start = new DateTimeImmutable($data['start']); + } + $value = $this->getValue($redisService, $redisKey, $moneyService, $date, $data['provider']); + if (isset($start)) { + $months = $date->diff($start)->m; + $current = clone $start; + $value = $this->getValue($redisService, $redisKey, $moneyService, $current, $data['provider']); + for ($i = 1; $i <= $months; $i ++) { + $current = $current->add(new DateInterval("P{$i}M")); + $value += $this->getValue($redisService, $redisKey, $moneyService, $current, $data['provider']); + } + } + $output[$data['provider']] = $value; + return $this->withJson($response, $output); + } + + protected array $data; + protected function getValue(Service\Redis $redisService, string $redisKey, Service\Money $moneyService, DateTimeInterface $date, string $provider): float + { + if (isset($this->data[$date->format('Y-m-d')])) { + return $this->data[$date->format('Y-m-d')]; + } + try { + $this->data = (array) $this->fetchRedis($redisService, $redisKey); + if (!isset($this->data[$date->format('Y-m-d')])) { + throw new EmptyRedis($redisKey); + } + } catch (EmptyRedis) { + $result = $moneyService->get($provider, $date); + $this->data[$date->format('Y-m-d')] = $result; + $this->saveRedis($redisService, $redisKey, $this->data, $this->time); + } + return $this->data[$date->format('Y-m-d')]; + } + /*public function uf(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, Service\Money $moneyService): ResponseInterface + { + $body = $request->getParsedBody(); + $output = [ + 'input' => $body, + 'uf' => 0 + ]; + $redisKey = 'uf'; + $date = new DateTimeImmutable($body['fecha']); + try { + $ufs = $this->fetchRedis($redisService, $redisKey); + if (!isset($ufs[$date->format('Y-m-d')])) { + throw new EmptyRedis($redisKey); + } + } catch (EmptyRedis) { + error_log(var_export($ufs,true)); + if (!isset($ufs)) { + $ufs = []; + } + $uf = $moneyService->getUF($date); + $ufs[$date->format('Y-m-d')] = $uf; + $this->saveRedis($redisService, $redisKey, $ufs, 60 * 60 * 24 * 30); + } + $output['uf'] = $ufs[$date->format('Y-m-d')]; + return $this->withJson($response, $output); + }*/ + public function ipc(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, Service\Money $moneyService): ResponseInterface + { + $data = $request->getParsedBody(); + $output = [ + 'input' => $data, + 'date_string' => '', + 'ipc' => 0 + ]; + $redisKey = 'ipc'; + $start = new DateTimeImmutable($data['start']); + $end = new DateTimeImmutable($data['end']); + $now = new DateTimeImmutable(); + if ($end > $now) { + return $this->withJson($response, $output); + } + $dateKey = "{$start->format('Y-m')}-{$end->format('Y-m')}"; + $months = $start->diff($end)->m; + $current = new DateTimeImmutable((($start <= $end) ? $start : $end)->format('Y-m-15')); + $value = 0; + $ipcs = []; + try { + $ipcs = (array) $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) {} + for ($i = 1; $i < $months; $i ++) { + $current = $current->add(new DateInterval("P1M")); + if (!isset($ipcs[$current->format('Y-m')])) { + $ipcs[$current->format('Y-m')] = $moneyService->getIPC($current); + $this->saveRedis($redisService, $redisKey, $ipcs, $this->time); + } + $value += $ipcs[$current->format('Y-m')]; + } + $output['date_string'] = $dateKey; + $output['ipc'] = $value; + return $this->withJson($response, $output); + } +} diff --git a/app/src/Controller/API/Ventas.php b/app/src/Controller/API/Ventas.php index 2604ae1..c069dd3 100644 --- a/app/src/Controller/API/Ventas.php +++ b/app/src/Controller/API/Ventas.php @@ -2,9 +2,9 @@ namespace Incoviba\Controller\API; use DateTimeImmutable; -use Incoviba\Common\Implement\Exception\EmptyRedis; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Incoviba\Common\Implement\Exception\EmptyRedis; use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Model; use Incoviba\Repository; @@ -153,4 +153,21 @@ class Ventas } return $this->withJson($response, $output); } + public function unidades(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Unidad $unidadService, int $venta_id): ResponseInterface + { + $output = [ + 'venta_id' => $venta_id, + 'unidades' => [] + ]; + try { + $unidades = $unidadService->getByVenta($venta_id); + $output['unidades'] = json_decode(json_encode($unidades)); + array_walk($output['unidades'], function($unidad, $index, $unidades) { + $unidad->prorrateo = $unidades[$index]->prorrateo; + $unidad->precios = $unidades[$index]->precios; + $unidad->current_precio = $unidades[$index]->currentPrecio; + }, $unidades); + } catch (EmptyResult) {} + return $this->withJson($response, $output); + } } diff --git a/app/src/Controller/API/Ventas/Facturacion.php b/app/src/Controller/API/Ventas/Facturacion.php new file mode 100644 index 0000000..2f94857 --- /dev/null +++ b/app/src/Controller/API/Ventas/Facturacion.php @@ -0,0 +1,36 @@ + $proyecto_id, + 'ventas' => [] + ]; + $today = new DateTimeImmutable(); + $redisKey = "ventas_facturacion-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}"; + try { + $output['ventas'] = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $output['ventas'] = $ventaService->getActivaByProyecto($proyecto_id); + $this->saveRedis($redisService, $redisKey, $output['ventas']); + } catch (EmptyResult) {} + } + return $this->withJson($response, $output); + } +} diff --git a/app/src/Controller/API/withRedis.php b/app/src/Controller/API/withRedis.php index 0913c11..364d129 100644 --- a/app/src/Controller/API/withRedis.php +++ b/app/src/Controller/API/withRedis.php @@ -14,11 +14,15 @@ trait withRedis } return json_decode($jsonString); } - public function saveRedis(Service\Redis $redisService, string $redisKey, mixed $value): void + public function saveRedis(Service\Redis $redisService, string $redisKey, mixed $value, ?int $expiration = null): void { if (is_array($value) or is_object($value)) { $value = json_encode($value); } + if ($expiration !== null) { + $redisService->set($redisKey, $value, $expiration); + return; + } $redisService->set($redisKey, $value); } } diff --git a/app/src/Controller/Ventas/Facturacion.php b/app/src/Controller/Ventas/Facturacion.php new file mode 100644 index 0000000..90581a9 --- /dev/null +++ b/app/src/Controller/Ventas/Facturacion.php @@ -0,0 +1,21 @@ +getEscriturando(); + return $view->render($response, 'ventas.facturacion', compact('proyectos')); + } + public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $ventaService, int $venta_id): ResponseInterface + { + $venta = $ventaService->getById($venta_id); + return $view->render($response, 'ventas.facturacion.show', compact('venta')); + } +} diff --git a/app/src/Middleware/Errors.php b/app/src/Middleware/Errors.php new file mode 100644 index 0000000..17cde71 --- /dev/null +++ b/app/src/Middleware/Errors.php @@ -0,0 +1,31 @@ +handle($request); + } catch (Exception $exception) { + $this->logger->notice($exception); + } catch (Error $error) { + $this->logger->error($error); + } + $response = $this->responseFactory->createResponse(404); + if (str_contains($request->getUri()->getPath(), '/api')) { + return $response; + } + return $this->view->render($response, 'construccion'); + } +} diff --git a/app/src/Model/Proyecto/Superficie.php b/app/src/Model/Proyecto/Superficie.php index da7e1a9..5127e3d 100644 --- a/app/src/Model/Proyecto/Superficie.php +++ b/app/src/Model/Proyecto/Superficie.php @@ -1,7 +1,9 @@ bajo_nivel + $this->sobre_nivel; } + + public function jsonSerialize(): mixed + { + return [ + 'sobre_nivel' => $this->sobre_nivel, + 'bajo_nivel' => $this->bajo_nivel, + 'total' => $this->total() + ]; + } } diff --git a/app/src/Model/Proyecto/Terreno.php b/app/src/Model/Proyecto/Terreno.php index ce9c2fe..adcdaad 100644 --- a/app/src/Model/Proyecto/Terreno.php +++ b/app/src/Model/Proyecto/Terreno.php @@ -1,8 +1,21 @@ $this->superficie, + 'valor' => $this->valor, + 'date' => $this->date?->format('Y-m-d') + ]; + } } diff --git a/app/src/Model/Venta/Unidad.php b/app/src/Model/Venta/Unidad.php index 6d66454..d5efdab 100644 --- a/app/src/Model/Venta/Unidad.php +++ b/app/src/Model/Venta/Unidad.php @@ -12,6 +12,7 @@ class Unidad extends Ideal\Model public string $descripcion; public ?string $orientacion = ''; public Model\Proyecto\ProyectoTipoUnidad $proyectoTipoUnidad; + public ?float $prorrateo; public array $precios = []; public ?Precio $currentPrecio = null; @@ -50,7 +51,8 @@ class Unidad extends Ideal\Model 'piso' => $this->piso, 'descripcion' => $this->descripcion, 'orientacion' => $this->orientacion, - 'proyecto_tipo_unidad' => $this->proyectoTipoUnidad + 'proyecto_tipo_unidad' => $this->proyectoTipoUnidad, + 'prorrateo' => $this->prorrateo ]); } } diff --git a/app/src/Repository/Proyecto.php b/app/src/Repository/Proyecto.php index e03de3b..eb7a26b 100644 --- a/app/src/Repository/Proyecto.php +++ b/app/src/Repository/Proyecto.php @@ -1,6 +1,7 @@ superficie = $data['superficie_terreno']; $terreno->valor = $data['valor_terreno']; + $terreno->date = null; + if (isset($data['fecha_terreno']) and $data['fecha_terreno'] !== '') { + $terreno->date = new DateTimeImmutable($data['fecha_terreno']); + } return $terreno; })) ->register('superficie_sobre_nivel', (new Implement\Repository\Mapper()) @@ -67,36 +72,55 @@ class Proyecto extends Ideal\Repository } public function fetchByName(string $name): Define\Model { - $query = "SELECT * FROM `{$this->getTable()}` WHERE `name` = ?"; + $query = $this->connection->getQueryBuilder() + ->select($this->columns()) + ->from("{$this->getTable()} a") + ->joined($this->joinTerreno()) + ->where("name = ?"); return $this->fetchOne($query, [$name]); } public function fetchAllActive(): array { $etapaProyecto = $this->etapaRepository->fetchByDescripcion('Proyecto'); $etapaTerminado = $this->etapaRepository->fetchByDescripcion('Terminado'); - $query = "SELECT a.* -FROM `{$this->getTable()}` a - {$this->joinEstado()} -WHERE et.`orden` BETWEEN {$etapaProyecto->orden} AND ({$etapaTerminado->orden} - 1) -ORDER BY a.`descripcion`"; + $query = $this->connection->getQueryBuilder() + ->select($this->columns()) + ->from("{$this->getTable()} a") + ->joined($this->joinTerreno()) + ->joined($this->joinEstado()) + ->where("et.orden BETWEEN {$etapaProyecto->orden} AND ({$etapaTerminado->orden} - 1)") + ->order('a.descripcion'); return $this->fetchMany($query); } public function fetchAllEscriturando(): array { $etapaRecepcion = $this->etapaRepository->fetchByDescripcion('Recepción'); $etapaTerminado = $this->etapaRepository->fetchByDescripcion('Terminado'); - $query = "SELECT a.* -FROM `{$this->getTable()}` a - {$this->joinEstado()} -WHERE et.`orden` BETWEEN {$etapaRecepcion->orden} AND ({$etapaTerminado->orden} - 1) -ORDER BY a.`descripcion`"; + $query = $this->connection->getQueryBuilder() + ->select($this->columns()) + ->from("{$this->getTable()} a") + ->joined($this->joinTerreno()) + ->joined($this->joinEstado()) + ->where("et.orden BETWEEN {$etapaRecepcion->orden} AND ({$etapaTerminado->orden} - 1)") + ->order('a.descripcion'); return $this->fetchMany($query); } - public function fetchSuperficieVendido(int $proyecto_id): float + /*public function fetchSuperficieVendido(int $proyecto_id): float { - } + }*/ + protected function columns(): string + { + return "a.id, a.inmobiliaria, a.descripcion, a.direccion, a.superficie_terreno, + COALESCE(pt.valor, a.valor_terreno) AS valor_terreno, COALESCE(pt.fecha, '') AS fecha_terreno, a.corredor, + a.superficie_sobre_nivel, a.superficie_bajo_nivel, a.pisos, a.subterraneos"; + } + protected function joinTerreno(): string + { + return "LEFT OUTER JOIN (SELECT pt1.* FROM proyecto_terreno pt1 JOIN ( + SELECT MAX(id) AS id, proyecto_id FROM proyecto_terreno) pt0 ON pt0.id = pt1.id) pt ON pt.proyecto_id = a.id"; + } protected function joinEstado(): string { return "JOIN ( diff --git a/app/src/Repository/Venta/Unidad.php b/app/src/Repository/Venta/Unidad.php index 341665e..252cfa9 100644 --- a/app/src/Repository/Venta/Unidad.php +++ b/app/src/Repository/Venta/Unidad.php @@ -17,7 +17,7 @@ class Unidad extends Ideal\Repository public function create(?array $data = null): Model\Venta\Unidad { - $map = (new Implement\Repository\MapperParser(['subtipo', 'piso', 'descripcion', 'orientacion'])) + $map = (new Implement\Repository\MapperParser(['subtipo', 'piso', 'descripcion', 'orientacion', 'prorrateo'])) ->register('pt', (new Implement\Repository\Mapper()) ->setProperty('proyectoTipoUnidad') ->setFunction(function($data) { @@ -38,62 +38,88 @@ class Unidad extends Ideal\Repository return $this->update($model, ['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'], $new_data); } + public function fetchByVenta(int $venta_id): array + { + $query = $this->connection->getQueryBuilder() + ->select('a.*, up.prorrateo') + ->from("{$this->getTable()} a") + ->joined($this->joinProrrateo()) + ->joined('JOIN propiedad_unidad pu ON pu.unidad = a.id + JOIN venta ON venta.propiedad = pu.propiedad') + ->where('venta.id = ?'); + return $this->fetchMany($query, [$venta_id]); + } public function fetchByPropiedad(int $propiedad_id): array { - $query = "SELECT a.* -FROM `{$this->getTable()}` a - JOIN `propiedad_unidad` pu ON pu.`unidad` = a.`id` -WHERE pu.`propiedad` = ? -GROUP BY a.`id`"; + $query = $this->connection->getQueryBuilder() + ->select('a.*, up.prorrateo') + ->from("{$this->getTable()} a") + ->joined($this->joinProrrateo()) + ->joined('JOIN `propiedad_unidad` pu ON pu.`unidad` = a.`id`') + ->where('pu.propiedad = ?') + ->group('a.id'); return $this->fetchMany($query, [$propiedad_id]); } public function fetchByCierre(int $cierre_id): array { - $query = "SELECT a.* -FROM `{$this->getTable()}` a - JOIN `unidad_cierre` uc ON uc.`unidad` = a.`id` + $query = $this->connection->getQueryBuilder() + ->select('a.*, up.prorrateo') + ->from("{$this->getTable()} a") + ->joined($this->joinProrrateo()) + ->joined("JOIN `unidad_cierre` uc ON uc.`unidad` = a.`id` JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt` - JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo` -WHERE uc.`cierre` = ? -GROUP BY a.`id` -ORDER BY tu.`orden`, LPAD(a.`descripcion`, 4, '0')"; + JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`") + ->where('uc.cierre = ?') + ->group('a.id') + ->order("tu.orden, LPAD(a.descripcion, 4, '0')"); return $this->fetchMany($query, [$cierre_id]); } public function fetchByProyecto(int $proyecto_id): array { - $query = "SELECT a.* -FROM `{$this->getTable()}` a - JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt` - JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo` -WHERE ptu.`proyecto` = ? -ORDER BY tu.`orden`"; + $query = $this->connection->getQueryBuilder() + ->select('a.*, up.prorrateo') + ->from("{$this->getTable()} a") + ->joined($this->joinProrrateo()) + ->joined("JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt` + JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`") + ->where('ptu.proyecto = ?') + ->order('tu.orden'); return $this->fetchMany($query, [$proyecto_id]); } public function fetchDisponiblesByProyecto(int $proyecto_id): array { - $query = "SELECT DISTINCT a.* -FROM `{$this->getTable()}` a - JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt` + $query = $this->connection->getQueryBuilder() + ->select('DISTINCT a.*, up.prorrateo') + ->from("{$this->getTable()} a") + ->joined($this->joinProrrateo()) + ->joined("JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt` JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo` LEFT OUTER JOIN `propiedad_unidad` pu ON pu.`unidad` = a.`id` LEFT OUTER JOIN `venta` ON `venta`.`propiedad` = `pu`.`propiedad` LEFT OUTER JOIN (SELECT ev1.* FROM `estado_venta` ev1 JOIN (SELECT MAX(`id`) as 'id', `venta` FROM `estado_venta`) ev0 ON ev0.`id` = ev1.`id`) ev ON ev.`venta` = `venta`.`id` - LEFT OUTER JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado` -WHERE ptu.`proyecto` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`activa` = 0) -ORDER BY tu.`orden`"; + LEFT OUTER JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`") + ->where("ptu.`proyecto` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`activa` = 0)") + ->order('tu.orden'); return $this->fetchMany($query, [$proyecto_id]); } public function fetchDisponiblesByDescripcionAndTipo(string $descripcion, string $tipo): array { - $query = "SELECT DISTINCT a.* -FROM `{$this->getTable()}` a - JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt` + $query = $this->connection->getQueryBuilder() + ->select('DISTINCT a.*, up.prorrateo') + ->from("{$this->getTable()} a") + ->joined($this->joinProrrateo()) + ->joined("JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt` JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo` LEFT OUTER JOIN `propiedad_unidad` pu ON pu.`unidad` = a.`id` LEFT OUTER JOIN `venta` ON `venta`.`propiedad` = pu.`propiedad` LEFT OUTER JOIN (SELECT ev1.* FROM `estado_venta` ev1 JOIN (SELECT MAX(`id`) as 'id', `venta` FROM `estado_venta`) ev0 ON ev0.`id` = ev1.`id`) ev ON ev.`venta` = `venta`.`id` - LEFT OUTER JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado` -WHERE a.`descripcion` LIKE ? AND tu.`descripcion` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`activa` = 0)"; + LEFT OUTER JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`") + ->where("a.`descripcion` LIKE ? AND tu.`descripcion` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`activa` = 0)"); return $this->fetchMany($query, [$descripcion, $tipo]); } + + protected function joinProrrateo(): string + { + return "LEFT OUTER JOIN unidad_prorrateo up ON up.unidad_id = a.id"; + } } diff --git a/app/src/Service/Money.php b/app/src/Service/Money.php index 3cb7df8..b4d581c 100644 --- a/app/src/Service/Money.php +++ b/app/src/Service/Money.php @@ -2,6 +2,8 @@ namespace Incoviba\Service; use DateTimeInterface; +use DateTimeImmutable; +use DateInterval; use Incoviba\Common\Define\Money\Provider; use Incoviba\Common\Implement\Exception\EmptyResponse; use Incoviba\Service\Money\MiIndicador; @@ -22,6 +24,15 @@ class Money return $this->providers[$name]; } + public function get(string $provider, DateTimeInterface $dateTime): float + { + try { + $upper = strtoupper($provider); + return $this->getProvider($provider)->get(MiIndicador::getSymbol($provider), $dateTime); + } catch (EmptyResponse) { + return 0; + } + } public function getUF(DateTimeInterface $dateTime): float { try { diff --git a/app/src/Service/Money/MiIndicador.php b/app/src/Service/Money/MiIndicador.php index 113bc30..a223250 100644 --- a/app/src/Service/Money/MiIndicador.php +++ b/app/src/Service/Money/MiIndicador.php @@ -36,4 +36,11 @@ class MiIndicador implements Provider } return $json->serie[0]->valor; } + public static function getSymbol(string $identifier): string + { + $upper = strtoupper($identifier); + $output = ''; + eval("\$output = self::{$upper};"); + return $output; + } } diff --git a/app/src/Service/Proyecto.php b/app/src/Service/Proyecto.php index c6de619..2facad9 100644 --- a/app/src/Service/Proyecto.php +++ b/app/src/Service/Proyecto.php @@ -15,6 +15,10 @@ class Proyecto { return $this->proyectoRepository->fetchAllActive(); } + public function getEscriturando(): array + { + return $this->proyectoRepository->fetchAllEscriturando(); + } public function getById(int $venta_id): Model\Proyecto { return $this->process($this->proyectoRepository->fetchById($venta_id)); diff --git a/app/src/Service/Venta/Unidad.php b/app/src/Service/Venta/Unidad.php index b690a2f..899580e 100644 --- a/app/src/Service/Venta/Unidad.php +++ b/app/src/Service/Venta/Unidad.php @@ -15,35 +15,32 @@ class Unidad public function getById(int $unidad_id): Model\Venta\Unidad { - $unidad = $this->unidadRepository->fetchById($unidad_id); - $this->fillPrecios($unidad); - return $unidad; + return $this->process($this->unidadRepository->fetchById($unidad_id)); + } + public function getByVenta(int $venta_id): array + { + return array_map([$this, 'process'], $this->unidadRepository->fetchByVenta($venta_id)); } public function getByPropiedad(int $propiedad_id): array { - $unidades = $this->unidadRepository->fetchByPropiedad($propiedad_id); - array_walk($unidades, [$this, 'fillPrecios']); - return $unidades; + return array_map([$this, 'process'], $this->unidadRepository->fetchByPropiedad($propiedad_id)); } public function getByCierre(int $cierre_id): array { - $unidades = $this->unidadRepository->fetchByCierre($cierre_id); - array_walk($unidades, [$this, 'fillPrecios']); - return $unidades; + return array_map([$this, 'process'], $this->unidadRepository->fetchByCierre($cierre_id)); } public function getDisponiblesByProyecto(int $proyecto_id): array { - $unidades = $this->unidadRepository->fetchDisponiblesByProyecto($proyecto_id); - //array_walk($unidades, [$this, 'fillPrecios']); - return $unidades; + return $this->unidadRepository->fetchDisponiblesByProyecto($proyecto_id); } - protected function fillPrecios(&$unidad): void + protected function process($unidad): Model\Venta\Unidad { try { $unidad->precios = $this->precioService->getByUnidad($unidad->id); $unidad->currentPrecio = $this->precioService->getVigenteByUnidad($unidad->id); } catch (EmptyResult) { } + return $unidad; } } From bf03e85975551d213ee6f7656d73608874ae8635 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Thu, 23 Nov 2023 00:53:49 -0300 Subject: [PATCH 028/163] Redis --- app/resources/routes/api/direcciones.php | 2 +- app/resources/routes/api/provincias.php | 2 +- app/resources/routes/api/regiones.php | 3 +- app/resources/views/login/form.blade.php | 10 +- app/resources/views/search.blade.php | 9 +- app/setup/setups/middlewares.php | 2 + app/src/Controller/API/Direcciones.php | 65 ++++++++++ app/src/Controller/API/Money.php | 18 +-- app/src/Controller/API/Provincias.php | 39 ++++++ app/src/Controller/API/Proyectos.php | 72 +++++++---- .../API/Proyectos/EstadosProyectos.php | 71 ++++++++--- app/src/Controller/API/Regiones.php | 39 ++++++ app/src/Controller/API/Ventas.php | 115 ++++++++++++------ app/src/Controller/API/Ventas/Cierres.php | 85 ++++++++----- app/src/Controller/API/Ventas/Cuotas.php | 24 ++-- app/src/Controller/API/Ventas/Facturacion.php | 17 +-- app/src/Controller/API/Ventas/Precios.php | 43 +++++-- app/src/Controller/API/Ventas/Unidades.php | 8 +- app/src/Controller/Direcciones.php | 39 ------ app/src/Controller/Inmobiliarias.php | 32 ++++- app/src/Controller/Login.php | 13 +- app/src/Controller/Provincias.php | 28 ----- app/src/Controller/Proyectos.php | 59 ++++++--- app/src/Controller/Regiones.php | 28 ----- app/src/Controller/Ventas.php | 28 +++-- app/src/Controller/{API => }/withRedis.php | 2 +- app/src/Middleware/Authentication.php | 15 ++- app/src/Repository/Proyecto.php | 2 +- app/src/Repository/Venta/Subsidio.php | 11 +- app/src/Service/Proyecto.php | 10 +- app/src/Service/Search.php | 18 ++- app/src/Service/Venta.php | 4 +- 32 files changed, 599 insertions(+), 314 deletions(-) create mode 100644 app/src/Controller/API/Direcciones.php create mode 100644 app/src/Controller/API/Provincias.php create mode 100644 app/src/Controller/API/Regiones.php delete mode 100644 app/src/Controller/Direcciones.php delete mode 100644 app/src/Controller/Provincias.php delete mode 100644 app/src/Controller/Regiones.php rename app/src/Controller/{API => }/withRedis.php (95%) diff --git a/app/resources/routes/api/direcciones.php b/app/resources/routes/api/direcciones.php index 5f2d740..61ea957 100644 --- a/app/resources/routes/api/direcciones.php +++ b/app/resources/routes/api/direcciones.php @@ -1,5 +1,5 @@ group('/direcciones', function($app) { $app->group('/region/{region_id:[0-9]+}', function($app) { diff --git a/app/resources/routes/api/provincias.php b/app/resources/routes/api/provincias.php index 188986c..f7bccb7 100644 --- a/app/resources/routes/api/provincias.php +++ b/app/resources/routes/api/provincias.php @@ -1,5 +1,5 @@ group('/provincia/{provincia_id}', function($app) { $app->get('/comunas', [Provincias::class, 'comunas']); diff --git a/app/resources/routes/api/regiones.php b/app/resources/routes/api/regiones.php index 14ccd9c..3f48645 100644 --- a/app/resources/routes/api/regiones.php +++ b/app/resources/routes/api/regiones.php @@ -1,5 +1,6 @@ group('/regiones', function($app) {}); $app->group('/region/{region_id}', function($app) { diff --git a/app/resources/views/login/form.blade.php b/app/resources/views/login/form.blade.php index 31e38ff..1352f74 100644 --- a/app/resources/views/login/form.blade.php +++ b/app/resources/views/login/form.blade.php @@ -34,11 +34,11 @@ } }).then(data => { if (data.login === true) { - @if(isset($redirect_uri)) - window.location = '{{$redirect_uri}}' - @else - window.location = '{{$urls->base}}' - @endif + @if(isset($redirect_uri)) + window.location = '{{$redirect_uri}}' + @else + window.location = '{{$urls->base}}' + @endif } }) } diff --git a/app/resources/views/search.blade.php b/app/resources/views/search.blade.php index 6bcd790..59dbc46 100644 --- a/app/resources/views/search.blade.php +++ b/app/resources/views/search.blade.php @@ -6,7 +6,7 @@
    -
    +
    @@ -65,6 +65,9 @@ unidad += '' } + const numberFormat = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2}) + const superficie = numberFormat.format(Math.round(this.unidad.proyecto_tipo_unidad.superficie * 100) / 100) + return $('').append( $('').append( $('').attr('href', '{{$urls->base}}/proyecto/' + this.proyecto.id).html(this.proyecto.descripcion) @@ -76,9 +79,9 @@ ).append( $('').append(propietario) ).append( - $('').addClass('right aligned').html(Math.round(this.unidad.proyecto_tipo_unidad.superficie * 100) / 100 + ' m²') + $('').addClass('right aligned').html(superficie + ' m²') ).append( - $('').addClass('right aligned').html(this.unidad.precio) + $('').addClass('right aligned').html(numberFormat.format(this.unidad.precio)) ).append( $('').html(fecha) ).append( diff --git a/app/setup/setups/middlewares.php b/app/setup/setups/middlewares.php index 5c5f23f..df7a7e2 100644 --- a/app/setup/setups/middlewares.php +++ b/app/setup/setups/middlewares.php @@ -9,6 +9,8 @@ return [ return new Incoviba\Middleware\Authentication( $container->get(Psr\Http\Message\ResponseFactoryInterface::class), $container->get(Incoviba\Service\Login::class), + $container->get(Psr\Log\LoggerInterface::class), + $container->get(Incoviba\Common\Alias\View::class), implode('/', [$container->get('APP_URL'), 'login']) ); } diff --git a/app/src/Controller/API/Direcciones.php b/app/src/Controller/API/Direcciones.php new file mode 100644 index 0000000..f7527c9 --- /dev/null +++ b/app/src/Controller/API/Direcciones.php @@ -0,0 +1,65 @@ + 0, 'comunas' => []]; + $redisKey = 'comunas'; + try { + $output['comunas'] = $this->fetchRedis($redisService, $redisKey); + $output['total'] = count($output['comunas']); + } catch (EmptyRedis) { + $provinciaKey = 'provincias'; + try { + $temp_provincias = $this->fetchRedis($redisService, $provinciaKey); + } catch (EmptyRedis) { + $temp_provincias = $provinciaRepository->fetchByRegion($region_id); + $this->saveRedis($redisService, $provinciaKey, $temp_provincias, 60 * 60 * 24 * 30); + } + $comunas = []; + foreach($temp_provincias as $provincia) { + $temp_comunas = $comunaRepository->fetchByProvincia($provincia->id); + $comunas = array_merge($comunas, $temp_comunas); + } + usort($comunas, function(Model\Comuna $a, Model\Comuna $b) { + return strcoll($a->descripcion, $b->descripcion); + }); + $output = ['comunas' => $comunas, 'total' => count($comunas)]; + $this->saveRedis($redisService, $redisKey, $comunas, 60 * 60 * 24 * 30); + } + return $this->withJson($response, $output); + } + public function findComunas(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, + Repository\Comuna $comunaRepository): ResponseInterface + { + $body = $request->getBody(); + $json = json_decode($body->getContents()); + $output = ['input' => $json, 'total' => 0, 'comunas' => []]; + $redisKey = "comunas:direccion:{$json->direccion}"; + try { + $output['comunas'] = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $comunas = $comunaRepository->fetchByDireccion($json->direccion); + $output['comunas'] = $comunas; + $output['total'] = count($comunas); + $this->saveRedis($redisService, $redisKey, $comunas); + } catch (EmptyResult) {} + } + return $this->withJson($response, $output); + } +} diff --git a/app/src/Controller/API/Money.php b/app/src/Controller/API/Money.php index 74d0527..252bfc8 100644 --- a/app/src/Controller/API/Money.php +++ b/app/src/Controller/API/Money.php @@ -1,13 +1,14 @@ getParsedBody(); $output = [ @@ -42,7 +44,8 @@ class Money } protected array $data; - protected function getValue(Service\Redis $redisService, string $redisKey, Service\Money $moneyService, DateTimeInterface $date, string $provider): float + protected function getValue(Service\Redis $redisService, string $redisKey, Service\Money $moneyService, + DateTimeInterface $date, string $provider): float { if (isset($this->data[$date->format('Y-m-d')])) { return $this->data[$date->format('Y-m-d')]; @@ -85,7 +88,8 @@ class Money $output['uf'] = $ufs[$date->format('Y-m-d')]; return $this->withJson($response, $output); }*/ - public function ipc(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, Service\Money $moneyService): ResponseInterface + public function ipc(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, + Service\Money $moneyService): ResponseInterface { $data = $request->getParsedBody(); $output = [ diff --git a/app/src/Controller/API/Provincias.php b/app/src/Controller/API/Provincias.php new file mode 100644 index 0000000..99c55b5 --- /dev/null +++ b/app/src/Controller/API/Provincias.php @@ -0,0 +1,39 @@ + $provincia_id, + 'comunas' => [] + ]; + $redisKey = "comunas:provincia:{$provincia_id}"; + try { + $output['comunas'] = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $comunas = $comunaRepository->fetchByProvincia($provincia_id); + usort($comunas, function(Model\Comuna $a, Model\Comuna $b) { + return strcmp($a->descripcion, $b->descripcion); + }); + $output['comunas'] = $comunas; + $this->saveRedis($redisService, $redisKey, $comunas, 60 * 60 * 24 * 30); + } catch (EmptyResult) {} + } + return $this->withJson($response, $output); + } +} diff --git a/app/src/Controller/API/Proyectos.php b/app/src/Controller/API/Proyectos.php index 2cf3608..cff4441 100644 --- a/app/src/Controller/API/Proyectos.php +++ b/app/src/Controller/API/Proyectos.php @@ -1,39 +1,51 @@ 0]; + $output = ['total' => 0, 'proyectos' => []]; + $redisKey = 'proyectos:activos'; try { - $proyectos = $proyectoRepository->fetchAllActive(); - $output['proyectos'] = $proyectos; - $output['total'] = count($proyectos); - } catch (EmptyResult) {} + $output['proyectos'] = $this->fetchRedis($redisService, $redisKey); + $output['total'] = count($output['proyectos']); + } catch (EmptyRedis) { + try { + $output['proyectos'] = $proyectoRepository->fetchAllActive(); + $output['total'] = count($output['proyectos']); + $this->saveRedis($redisService, $redisKey, $output['proyectos']); + } catch (EmptyResult) {} + } return $this->withJson($response, $output); } - public function escriturando(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface + public function escriturando(ServerRequestInterface $request, ResponseInterface $response, + Service\Redis $redisService, Repository\Proyecto $proyectoRepository): ResponseInterface { - $output = [ - 'total' => 0, - 'proyectos' => [] - ]; + $output = ['total' => 0, 'proyectos' => []]; + $redisKey = 'proyectos:escriturando'; try { - $proyectos = $proyectoRepository->fetchAllEscriturando(); - $output['proyectos'] = $proyectos; - $output['total'] = count($proyectos); - } catch (EmptyResult) {} + $output['proyectos'] = $this->fetchRedis($redisService, $redisKey); + $output['total'] = count($output['proyectos']); + } catch (EmptyRedis) { + try { + $output['proyectos'] = $proyectoRepository->fetchAllEscriturando(); + $output['total'] = count($output['proyectos']); + $this->saveRedis($redisService, $redisKey, $output['proyectos']); + } catch (EmptyResult) {} + } return $this->withJson($response, $output); } public function unidades(ServerRequestInterface $request, ResponseInterface $response, @@ -41,7 +53,7 @@ class Proyectos int $proyecto_id): ResponseInterface { $output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0]; - $redisKey = "unidades-proyecto-{$proyecto_id}"; + $redisKey = "unidades:proyecto:{$proyecto_id}"; try { $output = $this->fetchRedis($redisService, $redisKey); } catch (EmptyRedis) { @@ -66,21 +78,29 @@ class Proyectos } return $this->withJson($response, $output); } - public function disponibles(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface + public function disponibles(ServerRequestInterface $request, ResponseInterface $response, + Service\Redis $redisService, Repository\Venta\Unidad $unidadRepository, + int $proyecto_id): ResponseInterface { $output = [ 'proyecto_id' => $proyecto_id, 'unidades' => [] ]; + $redisKey = "unidades:disponibles:proyecto:{$proyecto_id}"; try { - $output['unidades'] = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id); - } catch (EmptyResult) {} + $output['unidades'] = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $output['unidades'] = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id); + $this->saveRedis($redisService, $redisKey, $output['unidades']); + } catch (EmptyResult) {} + } return $this->withJson($response, $output); } public function superficies(ServerRequestInterface $request, ResponseInterface $response, - Repository\Proyecto $proyectoRepository, Repository\Venta $ventaRepository, - Repository\Venta\Unidad $unidadRepository, Service\Redis $redisService, - Service\Format $formatService, int $proyecto_id): ResponseInterface + Repository\Venta $ventaRepository, Repository\Venta\Unidad $unidadRepository, + Service\Redis $redisService, Service\Format $formatService, + int $proyecto_id): ResponseInterface { $output = [ 'proyecto_id' => $proyecto_id, @@ -95,7 +115,7 @@ class Proyectos 'por_vender' => '0m²' ] ]; - $redisKey = "superficices-proyecto-{$proyecto_id}"; + $redisKey = "superficices:proyecto:{$proyecto_id}"; try { $output = $this->fetchRedis($redisService, $redisKey); } catch (EmptyRedis) { diff --git a/app/src/Controller/API/Proyectos/EstadosProyectos.php b/app/src/Controller/API/Proyectos/EstadosProyectos.php index 9fc451f..8634565 100644 --- a/app/src/Controller/API/Proyectos/EstadosProyectos.php +++ b/app/src/Controller/API/Proyectos/EstadosProyectos.php @@ -1,65 +1,98 @@ $proyecto_id, 'estados' => [] ]; + $redisKey = "estados:proyecto:{$proyecto_id}"; try { - $output['estados'] = $estadoProyectoRepository->fetchByProyecto($proyecto_id); - } catch (EmptyResult) { - return $this->emptyBody($response); + $output['estados'] = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $output['estados'] = $estadoProyectoRepository->fetchByProyecto($proyecto_id); + $this->saveRedis($redisService, $redisKey, $output['estados']); + } catch (EmptyResult) { + return $this->emptyBody($response); + } } return $this->withJson($response, $output); } - public function currentByProyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface + public function currentByProyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, + Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface { $output = [ 'proyecto_id' => $proyecto_id, 'estado' => null ]; + $redisKey = "estado:proyecto:{$proyecto_id}"; try { - $output['estado'] = $estadoProyectoRepository->fetchCurrentByProyecto($proyecto_id); - } catch (EmptyResult) { - return $this->emptyBody($response); + $output['estado'] = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $output['estado'] = $estadoProyectoRepository->fetchCurrentByProyecto($proyecto_id); + $this->saveRedis($redisService, $redisKey, $output['estado']); + } catch (EmptyResult) { + return $this->emptyBody($response); + } } return $this->withJson($response, $output); } - public function firstByProyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface + public function firstByProyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, + Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface { $output = [ 'proyecto_id' => $proyecto_id, 'estado' => null ]; + $redisKey = "estado:proyecto:{$proyecto_id}:first"; try { - $output['estado'] = $estadoProyectoRepository->fetchFirstByProyecto($proyecto_id); - } catch (EmptyResult) { - return $this->emptyBody($response); + $output['estado'] = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $output['estado'] = $estadoProyectoRepository->fetchFirstByProyecto($proyecto_id); + $this->saveRedis($redisService, $redisKey, $output['estado']); + } catch (EmptyResult) { + return $this->emptyBody($response); + } } return $this->withJson($response, $output); } - public function recepcionByProyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface + public function recepcionByProyecto(ServerRequestInterface $request, ResponseInterface $response, + Service\Redis $redisService, + Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, + int $proyecto_id): ResponseInterface { $output = [ 'proyecto_id' => $proyecto_id, 'estado' => null ]; + $redisKey = "recepcion:proyecto:{$proyecto_id}"; try { - $output['estado'] = $estadoProyectoRepository->fetchRecepcionByProyecto($proyecto_id); - } catch (EmptyResult) { - return $this->emptyBody($response); + $output['estado'] = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $output['estado'] = $estadoProyectoRepository->fetchRecepcionByProyecto($proyecto_id); + $this->saveRedis($redisService, $redisKey, $output['estado']); + } catch (EmptyResult) { + return $this->emptyBody($response); + } } return $this->withJson($response, $output); } diff --git a/app/src/Controller/API/Regiones.php b/app/src/Controller/API/Regiones.php new file mode 100644 index 0000000..75ac94f --- /dev/null +++ b/app/src/Controller/API/Regiones.php @@ -0,0 +1,39 @@ + $region_id, + 'provincias' => [] + ]; + $redisKey = "provincias:region:{$region_id}"; + try { + $output['provincias'] = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $provincias = $provinciaRepository->fetchByRegion($region_id); + usort($provincias, function(Model\Provincia $a, Model\Provincia $b) { + return strcmp($a->descripcion, $b->descripcion); + }); + $output['provincias'] = $provincias; + $this->saveRedis($redisService, $redisKey, $output['provincias'], 60 * 60 * 24 * 30); + } catch (EmptyResult) {} + } + return $this->withJson($response, $output); + } +} diff --git a/app/src/Controller/API/Ventas.php b/app/src/Controller/API/Ventas.php index c069dd3..770cc12 100644 --- a/app/src/Controller/API/Ventas.php +++ b/app/src/Controller/API/Ventas.php @@ -2,19 +2,21 @@ namespace Incoviba\Controller\API; use DateTimeImmutable; -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; use Incoviba\Common\Implement\Exception\EmptyRedis; use Incoviba\Common\Implement\Exception\EmptyResult; +use Incoviba\Controller\withRedis; use Incoviba\Model; use Incoviba\Repository; use Incoviba\Service; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; class Ventas { use withJson, withRedis; - public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta $service): ResponseInterface + public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, + Repository\Proyecto $proyectoRepository, Repository\Venta $ventaRepository): ResponseInterface { $body = $request->getBody(); $json = json_decode($body->getContents()); @@ -25,26 +27,50 @@ class Ventas ], 'total' => 0 ]; + $proyectosKey = "proyectos"; try { - $ventas = $service->fetchActivaByProyecto($proyecto_id); - $output['ventas'] = array_map(function(Model\Venta $venta) {return $venta->id;}, $ventas); - $output['proyecto']['descripcion'] = $ventas[0]->proyecto()->descripcion; - $output['total'] = count($ventas); - } catch (EmptyResult) {} + $proyectos = $this->fetchRedis($redisService, $proyectosKey); + } catch (EmptyRedis) { + $proyectos = $proyectoRepository->fetchAllActive(); + $this->saveRedis($redisService, $proyectosKey, $proyectos); + } + $proyecto = array_values(array_filter($proyectos, function($proyecto) use ($proyecto_id) {return $proyecto->id === $proyecto_id;}))[0]; + $output['proyecto']['descripcion'] = $proyecto->descripcion; + + $redisKey = "ventas:proyecto:{$proyecto_id}"; + try { + $output['ventas'] = $this->fetchRedis($redisService, $redisKey); + $output['total'] = count($output['ventas']); + } catch (EmptyRedis) { + try { + $ventas = $ventaRepository->fetchActivaByProyecto($proyecto_id); + $output['ventas'] = array_map(function(Model\Venta $venta) {return $venta->id;}, $ventas); + $output['total'] = count($ventas); + $this->saveRedis($redisService, $redisKey, $output['ventas']); + } catch (EmptyResult) {} + } return $this->withJson($response, $output); } - public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, int $venta_id): ResponseInterface + public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, + Service\Venta $service, int $venta_id): ResponseInterface { + $redisKey = "venta:{$venta_id}"; try { - $venta = $service->getById($venta_id); + $venta = $this->fetchRedis($redisService, $redisKey); $output = compact('venta'); - } catch (EmptyResult $exception) { - $output = [ - 'error' => [ - 'code' => $exception->getCode(), - 'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage()) - ] - ]; + } catch (EmptyRedis) { + try { + $venta = $service->getById($venta_id); + $output = compact('venta'); + $this->saveRedis($redisService, $redisKey, $venta); + } catch (EmptyResult $exception) { + $output = [ + 'error' => [ + 'code' => $exception->getCode(), + 'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage()) + ] + ]; + } } return $this->withJson($response, $output); } @@ -54,7 +80,7 @@ class Ventas $json = json_decode($body->getContents()); $proyecto_id = $json->proyecto_id; $today = new DateTimeImmutable(); - $redisKey = "promesas_por_firmar-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}"; + $redisKey = "promesas:por_firmar:proyecto:{$proyecto_id}:{$today->format('Y-m-d')}"; $output = [ 'proyecto_id' => $proyecto_id, @@ -80,7 +106,7 @@ class Ventas $json = json_decode($body->getContents()); $proyecto_id = $json->proyecto_id; $today = new DateTimeImmutable(); - $redisKey = "escrituras-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}"; + $redisKey = "escrituras:proyecto:{$proyecto_id}:{$today->format('Y-m-d')}"; $output = [ 'proyecto_id' => $proyecto_id, @@ -127,18 +153,27 @@ class Ventas } return $this->withJson($response, $output); } - public function comentarios(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, Repository\Venta\Comentario $comentarioRepository, int $venta_id): ResponseInterface + public function comentarios(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, + Service\Venta $service, Repository\Venta\Comentario $comentarioRepository, int $venta_id): ResponseInterface { $venta = $service->getById($venta_id); - $output = ['total' => 0]; + $output = ['total' => 0, 'comentarios' => []]; + $redisKey = "comentarios:venta:{$venta_id}"; try { - $comentarios = $comentarioRepository->fetchByVenta($venta->id); - $output['total'] = count($comentarios); - $output['comentarios'] = $comentarios; - } catch (EmptyResult) {} + $output['comentarios'] = $this->fetchRedis($redisService, $redisKey); + $output['total'] = count($output['comentarios']); + } catch (EmptyRedis) { + try { + $comentarios = $comentarioRepository->fetchByVenta($venta->id); + $output['total'] = count($comentarios); + $output['comentarios'] = $comentarios; + $this->saveRedis($redisService, $redisKey, $output['comentarios']); + } catch (EmptyResult) {} + } return $this->withJson($response, $output); } - public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface + public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, + Service\Venta $ventaService): ResponseInterface { $data = $request->getParsedBody(); $output = [ @@ -146,28 +181,36 @@ class Ventas 'errors' => [] ]; try { - $ventaService->add($data); + $venta = $ventaService->add($data); + $this->saveRedis($redisService, "venta:{$venta->id}", $venta); $output['status'] = true; } catch (\Exception $exception) { $output['errors'] = $exception; } return $this->withJson($response, $output); } - public function unidades(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Unidad $unidadService, int $venta_id): ResponseInterface + public function unidades(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, + Service\Venta\Unidad $unidadService, int $venta_id): ResponseInterface { $output = [ 'venta_id' => $venta_id, 'unidades' => [] ]; + $redisKey = "unidades:venta:{$venta_id}"; try { - $unidades = $unidadService->getByVenta($venta_id); - $output['unidades'] = json_decode(json_encode($unidades)); - array_walk($output['unidades'], function($unidad, $index, $unidades) { - $unidad->prorrateo = $unidades[$index]->prorrateo; - $unidad->precios = $unidades[$index]->precios; - $unidad->current_precio = $unidades[$index]->currentPrecio; - }, $unidades); - } catch (EmptyResult) {} + $output['unidades'] = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $unidades = $unidadService->getByVenta($venta_id); + $output['unidades'] = json_decode(json_encode($unidades)); + array_walk($output['unidades'], function($unidad, $index, $unidades) { + $unidad->prorrateo = $unidades[$index]->prorrateo; + $unidad->precios = $unidades[$index]->precios; + $unidad->current_precio = $unidades[$index]->currentPrecio; + }, $unidades); + $this->saveRedis($redisService, $redisKey, $output['unidades']); + } catch (EmptyResult) {} + } return $this->withJson($response, $output); } } diff --git a/app/src/Controller/API/Ventas/Cierres.php b/app/src/Controller/API/Ventas/Cierres.php index 5531e7e..7acf4d9 100644 --- a/app/src/Controller/API/Ventas/Cierres.php +++ b/app/src/Controller/API/Ventas/Cierres.php @@ -1,55 +1,74 @@ getBody(); $json = json_decode($body->getContents()); $proyecto_id = $json->proyecto_id; - $output = ['total' => 0]; + $output = ['total' => 0, 'cierres' => []]; + $redisKey = "cierres:proyecto:{$proyecto_id}"; try { - $cierres = $service->getByProyecto($proyecto_id); - $output['cierres'] = $cierres; - $output['total'] = count($cierres); - } catch (EmptyResult) {} + $output['cierres'] = $this->fetchRedis($redisService, $redisKey); + $output['total'] = count($output['cierres']); + } catch (EmptyRedis) { + try { + $cierres = $service->getByProyecto($proyecto_id); + $output['cierres'] = $cierres; + $this->saveRedis($redisService, $redisKey, $output['cierres']); + $output['total'] = count($cierres); + } catch (EmptyResult) {} + } return $this->withJson($response, $output); } - public function vigentes(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cierre $cierreRepository): ResponseInterface + public function vigentes(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, + Repository\Venta\Cierre $cierreRepository): ResponseInterface { - $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 + $output = ['cierres' => []]; + $redisKey = "cierres:vigentes"; + try { + $output['cierres'] = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $cierres = $cierreRepository->fetchDatosVigentes(); + $estados = [ + 'revisado' => 'pendientes', + 'rechazado' => 'rechazados', + 'aprobado' => 'pendientes', + 'vendido' => 'promesados', + 'abandonado' => 'rechazados', + 'promesado' => 'promesados', + 'resciliado' => 'rechazados' ]; - } - $estado = $estados[$row['Estado']]; - $output[$row['Proyecto']][$estado] += $row['Cantidad']; - $output[$row['Proyecto']]['total'] += $row['Cantidad']; + foreach ($cierres as $row) { + if (!isset($output['cierres'][$row['Proyecto']])) { + $output['cierres'][$row['Proyecto']] = [ + 'promesados' => 0, + 'pendientes' => 0, + 'rechazados' => 0, + 'total' => 0 + ]; + } + $estado = $estados[$row['Estado']]; + $output['cierres'][$row['Proyecto']][$estado] += $row['Cantidad']; + $output['cierres'][$row['Proyecto']]['total'] += $row['Cantidad']; + } + $this->saveRedis($redisService, $redisKey, $output['cierres']); + } catch (EmptyRedis) {} } - return $this->withJson($response, ['cierres' => $output]); + return $this->withJson($response, $output); } } diff --git a/app/src/Controller/API/Ventas/Cuotas.php b/app/src/Controller/API/Ventas/Cuotas.php index 9e4bd87..102c324 100644 --- a/app/src/Controller/API/Ventas/Cuotas.php +++ b/app/src/Controller/API/Ventas/Cuotas.php @@ -1,24 +1,25 @@ format('Y-m-d')}"; + $redisKey = "cuotas:hoy:{$today->format('Y-m-d')}"; $output = [ 'cuotas' => 0 ]; @@ -32,10 +33,11 @@ class Cuotas } return $this->withJson($response, $output); } - public function pendiente(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService): ResponseInterface + public function pendiente(ServerRequestInterface $request, ResponseInterface $response, + Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService): ResponseInterface { $today = new DateTimeImmutable(); - $redisKey = "cuotas_pendientes-{$today->format('Y-m-d')}"; + $redisKey = "cuotas:pendientes:{$today->format('Y-m-d')}"; $output = [ 'cuotas' => 0 ]; @@ -49,10 +51,12 @@ class Cuotas } return $this->withJson($response, $output); } - public function porVencer(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService, Service\Format $formatService): ResponseInterface + public function porVencer(ServerRequestInterface $request, ResponseInterface $response, + Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService, + Service\Format $formatService): ResponseInterface { $today = new DateTimeImmutable(); - $redisKey = "cuotas_por_vencer-{$today->format('Y-m-d')}"; + $redisKey = "cuotas:por_vencer:{$today->format('Y-m-d')}"; try { $output = $this->fetchRedis($redisService, $redisKey); } catch (EmptyRedis) { diff --git a/app/src/Controller/API/Ventas/Facturacion.php b/app/src/Controller/API/Ventas/Facturacion.php index 2f94857..14477da 100644 --- a/app/src/Controller/API/Ventas/Facturacion.php +++ b/app/src/Controller/API/Ventas/Facturacion.php @@ -2,27 +2,28 @@ namespace Incoviba\Controller\API\Ventas; use DateTimeImmutable; +use Incoviba\Common\Implement\Exception\EmptyRedis; +use Incoviba\Common\Implement\Exception\EmptyResult; +use Incoviba\Controller\API\emptyBody; +use Incoviba\Controller\API\withJson; +use Incoviba\Controller\withRedis; +use Incoviba\Service; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Incoviba\Service; -use Incoviba\Controller\API\withJson; -use Incoviba\Controller\API\withRedis; -use Incoviba\Controller\API\emptyBody; -use Incoviba\Common\Implement\Exception\EmptyResult; -use Incoviba\Common\Implement\Exception\EmptyRedis; class Facturacion { use withJson, withRedis, emptyBody; - public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, Service\Venta $ventaService, int $proyecto_id): ResponseInterface + public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, + Service\Venta $ventaService, int $proyecto_id): ResponseInterface { $output = [ 'proyecto_id' => $proyecto_id, 'ventas' => [] ]; $today = new DateTimeImmutable(); - $redisKey = "ventas_facturacion-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}"; + $redisKey = "ventas:facturacion:proyecto:{$proyecto_id}:{$today->format('Y-m-d')}"; try { $output['ventas'] = $this->fetchRedis($redisService, $redisKey); } catch (EmptyRedis) { diff --git a/app/src/Controller/API/Ventas/Precios.php b/app/src/Controller/API/Ventas/Precios.php index 927e815..63b3cf9 100644 --- a/app/src/Controller/API/Ventas/Precios.php +++ b/app/src/Controller/API/Ventas/Precios.php @@ -1,36 +1,53 @@ getBody(); $json = json_decode($body->getContents()); $proyecto_id = $json->proyecto_id; - $output = ['total' => 0]; + $output = ['total' => 0, 'precios' => []]; + $redisKey = "precios:proyecto:{$proyecto_id}"; try { - $precios = $precioService->getByProyecto($proyecto_id); - $output['precios'] = $precios; - $output['total'] = count($precios); - } catch (EmptyResult) {} + $output['precios'] = $this->fetchRedis($redisService, $redisKey); + $output['total'] = count($output['precios']); + } catch (EmptyRedis) { + try { + $precios = $precioService->getByProyecto($proyecto_id); + $output['precios'] = $precios; + $output['total'] = count($precios); + $this->saveRedis($redisService, $redisKey, $output['precios']); + } catch (EmptyResult) {} + } return $this->withJson($response, $output); } - public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface + public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, + Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface { + $redisKey = "precio:unidad:{$unidad_id}"; try { - $precio = $precioService->getVigenteByUnidad($unidad_id); + $precio = $this->fetchRedis($redisService, $redisKey); return $this->withJson($response, compact('precio')); - } catch (EmptyResult) { - return $this->emptyBody($response); + } catch (EmptyRedis) { + try { + $precio = $precioService->getVigenteByUnidad($unidad_id); + $this->saveRedis($redisService, $redisKey, $precio); + return $this->withJson($response, compact('precio')); + } catch (EmptyResult) { + return $this->emptyBody($response); + } } } } diff --git a/app/src/Controller/API/Ventas/Unidades.php b/app/src/Controller/API/Ventas/Unidades.php index 9f8538f..cc1843e 100644 --- a/app/src/Controller/API/Ventas/Unidades.php +++ b/app/src/Controller/API/Ventas/Unidades.php @@ -3,14 +3,14 @@ namespace Incoviba\Controller\API\Ventas; use DateTimeImmutable; use Incoviba\Common\Implement\Exception\EmptyRedis; -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Controller\API\withJson; -use Incoviba\Controller\API\withRedis; +use Incoviba\Controller\withRedis; use Incoviba\Model; use Incoviba\Repository; use Incoviba\Service; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; class Unidades { @@ -22,7 +22,7 @@ class Unidades $json = json_decode($body->getContents()); $proyecto_id = $json->proyecto_id; $today = new DateTimeImmutable(); - $redisKey = "unidades_disponibles-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}"; + $redisKey = "unidades:disponibles:proyecto:{$proyecto_id}:{$today->format('Y-m-d')}"; $output = [ 'proyecto_id' => $proyecto_id, diff --git a/app/src/Controller/Direcciones.php b/app/src/Controller/Direcciones.php deleted file mode 100644 index 18024bf..0000000 --- a/app/src/Controller/Direcciones.php +++ /dev/null @@ -1,39 +0,0 @@ -fetchByRegion($region_id); - $comunas = []; - foreach($temp_provincias as $provincia) { - $temp_comunas = $comunaRepository->fetchByProvincia($provincia->id); - $comunas = array_merge($comunas, $temp_comunas); - } - usort($comunas, function(Model\Comuna $a, Model\Comuna $b) { - return strcoll($a->descripcion, $b->descripcion); - }); - $response->getBody()->write(json_encode(['comunas' => $comunas, 'total' => count($comunas)])); - return $response->withHeader('Content-Type', 'application/json'); - } - public function findComunas(ServerRequestInterface $request, ResponseInterface $response, Repository\Comuna $comunaRepository): ResponseInterface - { - $body = $request->getBody(); - $json = json_decode($body->getContents()); - $output = ['total' => 0]; - try { - $comunas = $comunaRepository->fetchByDireccion($json->direccion); - $output['comunas'] = $comunas; - $output['total'] = count($comunas); - } catch (EmptyResult) {} - $response->getBody()->write(json_encode($output)); - return $response->withHeader('Content-Type', 'application/json'); - } -} diff --git a/app/src/Controller/Inmobiliarias.php b/app/src/Controller/Inmobiliarias.php index 8d1ad37..3387909 100644 --- a/app/src/Controller/Inmobiliarias.php +++ b/app/src/Controller/Inmobiliarias.php @@ -4,18 +4,42 @@ namespace Incoviba\Controller; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Incoviba\Common\Alias\View; +use Incoviba\Common\Implement\Exception\EmptyRedis; +use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Repository; +use Incoviba\Service; class Inmobiliarias { - public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Inmobiliaria $inmobiliariaRepository): ResponseInterface + use withRedis; + + public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, + Service\Redis $redisService, Repository\Inmobiliaria $inmobiliariaRepository): ResponseInterface { - $inmobiliarias = $inmobiliariaRepository->fetchAll(); + $redisKey = 'inmobiliarias'; + $inmobiliarias = []; + try { + $inmobiliarias = array_map(function($row) use ($inmobiliariaRepository) { + return $inmobiliariaRepository->load((array) $row); + }, $this->fetchRedis($redisService, $redisKey)); + } catch (EmptyRedis) { + try { + $inmobiliarias = $inmobiliariaRepository->fetchAll(); + $this->saveRedis($redisService, $redisKey, $inmobiliarias); + } catch (EmptyResult) {} + } return $view->render($response, 'inmobiliarias.list', compact('inmobiliarias')); } - public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Inmobiliaria $inmobiliariaRepository, int $inmobiliaria_rut): ResponseInterface + public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, + Service\Redis $redisService, Repository\Inmobiliaria $inmobiliariaRepository, int $inmobiliaria_rut): ResponseInterface { - $inmobiliaria = $inmobiliariaRepository->fetchById($inmobiliaria_rut); + $redisKey = "inmobiliaria:{$inmobiliaria_rut}"; + try { + $inmobiliaria = $inmobiliariaRepository->load((array) $this->fetchRedis($redisService, $redisKey)); + } catch (EmptyResult) { + $inmobiliaria = $inmobiliariaRepository->fetchById($inmobiliaria_rut); + $this->saveRedis($redisService, $redisKey, $inmobiliaria); + } return $view->render($response, 'inmobiliaria.show', compact('inmobiliaria')); } } diff --git a/app/src/Controller/Login.php b/app/src/Controller/Login.php index 44fb96c..ed22278 100644 --- a/app/src/Controller/Login.php +++ b/app/src/Controller/Login.php @@ -12,19 +12,10 @@ 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); + return $response->withStatus(301)->withHeader('Location', $view->get('urls')->base); } - if ($request->hasHeader('X-Redirect-URI')) { - $redirect_uri = $request->getHeaderLine('X-Redirect-URI'); - } - $query = $request->getQueryParams(); - if (isset($query['url'])) { - $redirect_uri = base64_decode(urldecode($query['url'])); - } - return $view->render($response, 'login.form', compact('redirect_uri')); + return $view->render($response, 'login.form'); } public function login(ServerRequestInterface $request, ResponseInterface $response, Repository\User $userRepository, Service\Login $service): ResponseInterface { diff --git a/app/src/Controller/Provincias.php b/app/src/Controller/Provincias.php deleted file mode 100644 index 36c3a11..0000000 --- a/app/src/Controller/Provincias.php +++ /dev/null @@ -1,28 +0,0 @@ - $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'); - } -} diff --git a/app/src/Controller/Proyectos.php b/app/src/Controller/Proyectos.php index 4f62910..106de6b 100644 --- a/app/src/Controller/Proyectos.php +++ b/app/src/Controller/Proyectos.php @@ -4,35 +4,62 @@ namespace Incoviba\Controller; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Incoviba\Common\Alias\View; +use Incoviba\Common\Implement\Exception\EmptyRedis; +use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Model; use Incoviba\Repository; use Incoviba\Service; class Proyectos { - public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Proyecto $proyectoRepository): ResponseInterface + use withRedis; + + public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, + Repository\Proyecto $proyectoRepository): ResponseInterface { - $proyectos = $proyectoRepository->fetchAll(); - usort($proyectos, function(Model\Proyecto $a, Model\Proyecto $b) { - return strcmp($a->descripcion, $b->descripcion); - }); + $proyectos = []; + try { + $proyectos = $proyectoRepository->fetchAll(); + usort($proyectos, function(Model\Proyecto $a, Model\Proyecto $b) { + return strcmp($a->descripcion, $b->descripcion); + }); + } catch (EmptyResult) {} return $view->render($response, 'proyectos.list', compact('proyectos')); } - public function unidades(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Proyecto $proyectoRepository, Repository\Venta\Unidad $unidadRepository): ResponseInterface + public function unidades(ServerRequestInterface $request, ResponseInterface $response, View $view, + Service\Redis $redisService, Repository\Proyecto $proyectoRepository, + Repository\Venta\Unidad $unidadRepository): ResponseInterface { - $proyectos = $proyectoRepository->fetchAll(); - $proyectos = array_filter($proyectos, function(Model\Proyecto $proyecto) use ($unidadRepository) { - $unidades = $unidadRepository->fetchByProyecto($proyecto->id); - return count($unidades) > 0; - }); - usort($proyectos, function(Model\Proyecto $a, Model\Proyecto $b) { - return strcmp($a->descripcion, $b->descripcion); - }); + $proyectos = []; + $redisKey = "proyectos:con_unidades"; + try { + $proyectos = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $proyectos = $proyectoRepository->fetchAll(); + $proyectos = array_filter($proyectos, function(Model\Proyecto $proyecto) use ($unidadRepository) { + $unidades = $unidadRepository->fetchByProyecto($proyecto->id); + return count($unidades) > 0; + }); + usort($proyectos, function(Model\Proyecto $a, Model\Proyecto $b) { + return strcmp($a->descripcion, $b->descripcion); + }); + $this->saveRedis($redisService, $redisKey, $proyectos); + } catch (EmptyResult) {} + } return $view->render($response, 'proyectos.unidades', compact('proyectos')); } - public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Proyecto $proyectoService, int $proyecto_id): ResponseInterface + public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, + Service\Redis $redisService, Service\Proyecto $proyectoService, + Repository\Proyecto $proyectoRepository, int $proyecto_id): ResponseInterface { - $proyecto = $proyectoService->getById($proyecto_id); + $redisKey = "proyecto:{$proyecto_id}"; + try { + $proyecto = $proyectoService->getById($proyectoRepository->load((array) $this->fetchRedis($redisService, $redisKey))); + } catch (EmptyRedis) { + $proyecto = $proyectoService->getById($proyecto_id); + $this->saveRedis($redisService, $redisKey, $proyecto); + } return $view->render($response, 'proyectos.show', compact('proyecto')); } } diff --git a/app/src/Controller/Regiones.php b/app/src/Controller/Regiones.php deleted file mode 100644 index 8d43598..0000000 --- a/app/src/Controller/Regiones.php +++ /dev/null @@ -1,28 +0,0 @@ - $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'); - } -} diff --git a/app/src/Controller/Ventas.php b/app/src/Controller/Ventas.php index 22583ba..c079d48 100644 --- a/app/src/Controller/Ventas.php +++ b/app/src/Controller/Ventas.php @@ -1,28 +1,42 @@ $proyecto->id, 'descripcion' => $proyecto->descripcion];}, $proyectoService->getVendibles()); + $redisKey = "proyectos:vendibles"; + try { + $proyectos = $proyectoService->process($proyectoRepository->load((array) $this->fetchRedis($redisService, $redisKey))); + } catch (EmptyRedis) { + $proyectos = array_map(function(Model\Proyecto $proyecto) { + return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion]; + }, $proyectoService->getVendibles()); + $this->saveRedis($redisService, $redisKey, $proyectos); + } return $view->render($response, 'ventas.list', compact('proyectos')); } - public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, int $venta_id): ResponseInterface + public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, + Service\Venta $service, int $venta_id): ResponseInterface { $venta = $service->getById($venta_id); return $view->render($response, 'ventas.show', compact('venta')); } - public function showUnidad(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, string $proyecto_nombre, int $unidad_descripcion): ResponseInterface + public function showUnidad(ServerRequestInterface $request, ResponseInterface $response, View $view, + Service\Venta $service, string $proyecto_nombre, int $unidad_descripcion): ResponseInterface { $proyecto_nombre = urldecode($proyecto_nombre); $venta = $service->getByProyectoAndUnidad($proyecto_nombre, $unidad_descripcion); diff --git a/app/src/Controller/API/withRedis.php b/app/src/Controller/withRedis.php similarity index 95% rename from app/src/Controller/API/withRedis.php rename to app/src/Controller/withRedis.php index 364d129..0cc5bab 100644 --- a/app/src/Controller/API/withRedis.php +++ b/app/src/Controller/withRedis.php @@ -1,5 +1,5 @@ service->isIn() or $this->isValid($request)) { return $handler->handle($request); } - $response = $this->responseFactory->createResponse(301, 'Not logged in'); - $uri = urlencode(base64_encode((string) $request->getUri())); - return $response->withHeader('Location', implode('?', [$this->login_url, "url={$uri}"])) + $this->logger->notice("Not logged in."); + $response = $this->responseFactory->createResponse(301, 'Not logged in') ->withHeader('Referer', (string) $request->getUri()) ->withHeader('X-Redirected-URI', (string) $request->getUri()); + return $this->view->render($response, 'login.form', ['redirect_uri' => (string) $request->getUri()]); } protected function isValid(ServerRequestInterface $request): bool diff --git a/app/src/Repository/Proyecto.php b/app/src/Repository/Proyecto.php index eb7a26b..be015ce 100644 --- a/app/src/Repository/Proyecto.php +++ b/app/src/Repository/Proyecto.php @@ -76,7 +76,7 @@ class Proyecto extends Ideal\Repository ->select($this->columns()) ->from("{$this->getTable()} a") ->joined($this->joinTerreno()) - ->where("name = ?"); + ->where("descripcion = ?"); return $this->fetchOne($query, [$name]); } public function fetchAllActive(): array diff --git a/app/src/Repository/Venta/Subsidio.php b/app/src/Repository/Venta/Subsidio.php index f79ae24..180b72f 100644 --- a/app/src/Repository/Venta/Subsidio.php +++ b/app/src/Repository/Venta/Subsidio.php @@ -16,7 +16,16 @@ class Subsidio extends Ideal\Repository public function create(?array $data = null): Model\Venta\Subsidio { - $map = new Implement\Repository\MapperParser(['pago', 'subsidio']); + $map = (new Implement\Repository\MapperParser()) + ->register('pago', (new Implement\Repository\Mapper()) + ->setProperty('ahorro') + ->setFunction(function($data) { + return $this->pagoRepository->fetchById($data['pago']); + })) + ->register('subsidio', (new Implement\Repository\Mapper()) + ->setFunction(function($data) { + return $this->pagoRepository->fetchById($data['subsidio']); + })); return $this->parseData(new Model\Venta\Subsidio(), $data, $map); } public function save(Define\Model $model): Model\Venta\Subsidio diff --git a/app/src/Service/Proyecto.php b/app/src/Service/Proyecto.php index 2facad9..70b6332 100644 --- a/app/src/Service/Proyecto.php +++ b/app/src/Service/Proyecto.php @@ -19,11 +19,15 @@ class Proyecto { return $this->proyectoRepository->fetchAllEscriturando(); } - public function getById(int $venta_id): Model\Proyecto + public function getById(int $proyecto_id): Model\Proyecto { - return $this->process($this->proyectoRepository->fetchById($venta_id)); + return $this->process($this->proyectoRepository->fetchById($proyecto_id)); } - protected function process(Model\Proyecto $proyecto): Model\Proyecto + public function getByName(string $name): Model\Proyecto + { + return $this->process($this->proyectoRepository->fetchByName($name)); + } + public function process(Model\Proyecto $proyecto): Model\Proyecto { $proyecto->addFactory('estados', (new Implement\Repository\Factory()) ->setCallable([$this->estadoProyecto, 'fetchByProyecto']) diff --git a/app/src/Service/Search.php b/app/src/Service/Search.php index 3a704bd..08f6633 100644 --- a/app/src/Service/Search.php +++ b/app/src/Service/Search.php @@ -2,12 +2,18 @@ namespace Incoviba\Service; use Incoviba\Common\Implement\Exception\EmptyResult; +use Incoviba\Common\Implement\Exception\EmptyResponse; use Incoviba\Model; use Incoviba\Repository; class Search { - public function __construct(protected Venta $ventaService, protected Repository\Venta $ventaRepository, protected Repository\Venta\Unidad $unidadRepository, protected Repository\Proyecto\TipoUnidad $tipoUnidadRepository) {} + public function __construct( + protected Proyecto $proyectoService, + protected Venta $ventaService, + protected Repository\Venta $ventaRepository, + protected Repository\Venta\Unidad $unidadRepository, + protected Repository\Proyecto\TipoUnidad $tipoUnidadRepository) {} public function query(string $query, string $tipo): array { @@ -39,7 +45,12 @@ class Search } protected function find(string $query, string $tipo): array { - $queries = explode(' ', $query); + preg_match_all('/["\']([\s\w]+)["\']|(\w+)/i', $query, $matches, PREG_SET_ORDER | PREG_UNMATCHED_AS_NULL); + $queries = array_map(function($match) { + array_shift($match); + $valid = array_filter($match, function($line) {return $line !== null;}); + return implode(' ', $valid); + }, $matches); $tiposUnidades = $this->getTiposUnidades(); $results = []; foreach ($queries as $q) { @@ -113,7 +124,8 @@ class Search protected function findProyecto(string $query): array { try { - return $this->ventaService->getByProyecto($query); + $proyecto = $this->proyectoService->getByName($query); + return $this->ventaService->getByProyecto($proyecto->id); } catch (EmptyResult) { return []; } diff --git a/app/src/Service/Venta.php b/app/src/Service/Venta.php index 01215b7..512bfac 100644 --- a/app/src/Service/Venta.php +++ b/app/src/Service/Venta.php @@ -72,7 +72,7 @@ class Venta return $venta; } - public function add(array $data): void + public function add(array $data): Model\Venta { $fecha = new DateTimeImmutable($data['fecha_venta']); $data['uf'] = $this->moneyService->getUF($fecha); @@ -103,6 +103,8 @@ class Venta 'fecha' => $venta->fecha->format('Y-m-d') ]); $this->estadoVentaRepository->save($estado); + + return $venta; } protected function addPropietario(array $data): Model\Venta\Propietario { From e1ef31dccd083d3a5f09d57d4f5662f3c0773c16 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Thu, 23 Nov 2023 23:35:19 -0300 Subject: [PATCH 029/163] Search update and optimization --- app/resources/views/search.blade.php | 115 ++++++++++++++++++--- app/src/Controller/API/Ventas/Unidades.php | 18 ++++ app/src/Controller/Ventas.php | 2 +- app/src/Model/Venta.php | 2 +- app/src/Model/Venta/Propiedad.php | 25 ++++- app/src/Model/Venta/Unidad.php | 7 +- app/src/Repository/Venta.php | 41 +++++++- app/src/Repository/Venta/Unidad.php | 15 +++ app/src/Service/Search.php | 30 +++--- cli/bin/index.php | 13 +++ 10 files changed, 232 insertions(+), 36 deletions(-) create mode 100644 cli/bin/index.php diff --git a/app/resources/views/search.blade.php b/app/resources/views/search.blade.php index 59dbc46..9f9af42 100644 --- a/app/resources/views/search.blade.php +++ b/app/resources/views/search.blade.php @@ -45,6 +45,7 @@ draw() { const tipo = this.unidad.proyecto_tipo_unidad.tipo_unidad.descripcion let unidad = tipo.charAt(0).toUpperCase() + tipo.slice(1) + ' ' + this.unidad.descripcion + let precio = 0 let propietario = '' let fecha = '' let fecha_entrega = '' @@ -61,8 +62,10 @@ if (typeof this.venta.entrega !== 'undefined') { fecha_entrega = dateFormatter.format(new Date(this.venta.entrega.fecha)) } + precio = this.venta.valor } else { unidad += '' + precio = this.unidad.current_precio.valor } const numberFormat = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2}) @@ -81,7 +84,7 @@ ).append( $('').addClass('right aligned').html(superficie + ' m²') ).append( - $('').addClass('right aligned').html(numberFormat.format(this.unidad.precio)) + $('').addClass('right aligned').html(numberFormat.format(precio)) ).append( $('').html(fecha) ).append( @@ -104,29 +107,84 @@ const uri = '{{$urls->api}}/search' this.data = [] return fetch(uri, {method: 'post', body: data}).then(response => { - this.draw().clear() if (response.ok) { return response.json() } + }).catch(error => { + this.draw().clear() + this.draw().error(error) }).then(data => { - if (typeof data.results !== 'undefined' && data.results.length > 0) { - data.results.forEach(row => { - if (typeof row.proyecto_tipo_unidad === 'undefined') { - const r = new Row({unidad: row.propiedad.departamentos[0], proyecto: row.proyecto}) - r.venta = row - this.data.push(r) - } else { - this.data.push(new Row({unidad: row, proyecto: row.proyecto_tipo_unidad.proyecto})) - } - }) - this.draw().table() + this.draw().clear() + if (typeof data.results === 'undefined' || data.results.length === 0) { + this.draw().empty() return } - this.draw().empty() + const progress = this.draw().progress(data.results.length) + const promises = [] + data.results.forEach(row => { + if (row.tipo === 'venta') { + promises.push(this.get().venta(row.id).then(json => { + const venta = json.venta + progress.progress('increment') + const r = new Row({unidad: venta.propiedad.unidades[0], proyecto: venta.proyecto}) + r.venta = venta + this.data.push(r) + }).catch(error => { + progress.progress('increment') + console.error(row) + console.error(error) + })) + return + } + promises.push(this.get().unidad(row.id).then(json => { + const unidad = json.unidad + progress.progress('increment') + this.data.push(new Row({unidad: unidad, proyecto: unidad.proyecto_tipo_unidad.proyecto})) + }).catch(error => { + progress.progress('increment') + console.error(row) + console.error(error) + })) + }) + Promise.all(promises).then(() => { + this.sort() + this.draw().clear() + this.draw().table() + }) + }) + }, + unidad: id => { + const url = '{{$urls->api}}/ventas/unidad/' + id + return fetch(url).then(response => { + if (response.ok) { + return response.json() + } + }) + }, + venta: id => { + const url = '{{$urls->api}}/venta/' + id + return fetch(url).then(response => { + if (response.ok) { + return response.json() + } }) } } }, + sort: function() { + this.data.sort((a, b) => { + const p = a.proyecto.descripcion.localeCompare(b.proyecto.descripcion) + if (p === 0) { + const t = a.unidad.proyecto_tipo_unidad.tipo_unidad.descripcion + .localeCompare(b.unidad.proyecto_tipo_unidad.tipo_unidad.descripcion) + if (t === 0) { + return a.unidad.descripcion.localeCompare(b.unidad.descripcion) + } + return t + } + return p + }) + }, draw: function() { return { clear: () => { @@ -213,6 +271,35 @@ $('
    ').addClass('content').html('No se han encontrado resultados.') ) ) + }, + error: error => { + this.draw().separator() + $(this.id).append( + $('
    ').addClass('ui icon error message').append( + $('').addClass('exclamation triangle icon') + ).append( + $('
    ').addClass('content').html(error) + ) + ) + }, + progress: cantidad => { + this.draw().separator() + const progress = $('
    ').addClass('ui active progress').append( + $('
    ').addClass('bar').append( + $('
    ').addClass('centered progress') + ) + ).append( + $('
    ').addClass('label').html('Cargando datos') + ) + progress.progress({ + total: cantidad, + label: 'ratio', + text: { + ratio: '{value} de {total} ({percent}%)' + } + }) + $(this.id).append(progress) + return progress } } }, diff --git a/app/src/Controller/API/Ventas/Unidades.php b/app/src/Controller/API/Ventas/Unidades.php index cc1843e..1d29f81 100644 --- a/app/src/Controller/API/Ventas/Unidades.php +++ b/app/src/Controller/API/Ventas/Unidades.php @@ -16,6 +16,24 @@ class Unidades { use withJson, withRedis; + public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, + Service\Venta\Unidad $unidadService, int $unidad_id): ResponseInterface + { + $output = [ + 'unidad_id' => $unidad_id, + 'unidad' => null + ]; + $redisKey = "unidad:{$unidad_id}"; + try { + $output['unidad'] = $this->fetchRedis($redisService, $redisKey); + } catch (EmptyRedis) { + try { + $output['unidad'] = $unidadService->getById($unidad_id); + $this->saveRedis($redisService, $redisKey, $output['unidad']); + } catch (EmptyResult) {} + } + return $this->withJson($response, $output); + } public function disponibles(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, Repository\Proyecto\TipoUnidad $tipoUnidadRepository, Service\Redis $redisService): ResponseInterface { $body = $request->getBody(); diff --git a/app/src/Controller/Ventas.php b/app/src/Controller/Ventas.php index c079d48..1be7461 100644 --- a/app/src/Controller/Ventas.php +++ b/app/src/Controller/Ventas.php @@ -20,7 +20,7 @@ class Ventas { $redisKey = "proyectos:vendibles"; try { - $proyectos = $proyectoService->process($proyectoRepository->load((array) $this->fetchRedis($redisService, $redisKey))); + $proyectos = $this->fetchRedis($redisService, $redisKey); } catch (EmptyRedis) { $proyectos = array_map(function(Model\Proyecto $proyecto) { return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion]; diff --git a/app/src/Model/Venta.php b/app/src/Model/Venta.php index 5e8a502..fa2610c 100644 --- a/app/src/Model/Venta.php +++ b/app/src/Model/Venta.php @@ -66,7 +66,7 @@ class Venta extends Ideal\Model public function proyecto(): Proyecto { - return $this->propiedad()->departamentos()[0]->proyectoTipoUnidad->proyecto; + return $this->propiedad()->proyecto(); } protected float $valor_util; diff --git a/app/src/Model/Venta/Propiedad.php b/app/src/Model/Venta/Propiedad.php index 546a984..47e8094 100644 --- a/app/src/Model/Venta/Propiedad.php +++ b/app/src/Model/Venta/Propiedad.php @@ -2,22 +2,40 @@ namespace Incoviba\Model\Venta; use Incoviba\Common\Ideal; +use Incoviba\Model; class Propiedad extends Ideal\Model { public array $unidades; + protected array $departamentos; public function departamentos(): array { - return array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento';})); + if (!isset($this->departamentos)) { + $this->departamentos = array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento';})); + } + return $this->departamentos; } + protected array $estacionamientos; public function estacionamientos(): array { - return array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'estacionamiento';})); + if (!isset($this->estacionamientos)) { + $this->estacionamientos = array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'estacionamiento';})); + } + return $this->estacionamientos; } + protected array $bodegas; public function bodegas(): array { - return array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'bodega';})); + if (!isset($this->bodegas)) { + $this->bodegas = array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'bodega';})); + } + return $this->bodegas; + } + + public function proyecto(): Model\Proyecto + { + return $this->unidades[0]->proyectoTipoUnidad->proyecto; } protected float $vendible; @@ -46,6 +64,7 @@ class Propiedad extends Ideal\Model public function jsonSerialize(): mixed { return [ + 'unidades' => $this->unidades, 'departamentos' => $this->departamentos(), 'estacionamientos' => $this->estacionamientos(), 'bodegas' => $this->bodegas(), diff --git a/app/src/Model/Venta/Unidad.php b/app/src/Model/Venta/Unidad.php index d5efdab..05a54fb 100644 --- a/app/src/Model/Venta/Unidad.php +++ b/app/src/Model/Venta/Unidad.php @@ -46,7 +46,7 @@ class Unidad extends Ideal\Model public function jsonSerialize(): mixed { - return array_merge(parent::jsonSerialize(), [ + $output = array_merge(parent::jsonSerialize(), [ 'subtipo' => $this->subtipo, 'piso' => $this->piso, 'descripcion' => $this->descripcion, @@ -54,5 +54,10 @@ class Unidad extends Ideal\Model 'proyecto_tipo_unidad' => $this->proyectoTipoUnidad, 'prorrateo' => $this->prorrateo ]); + if (isset($this->precios)) { + $output['precios'] = $this->precios; + $output['current_precio'] = $this->currentPrecio; + } + return $output; } } diff --git a/app/src/Repository/Venta.php b/app/src/Repository/Venta.php index c8f28ef..d550dfb 100644 --- a/app/src/Repository/Venta.php +++ b/app/src/Repository/Venta.php @@ -1,7 +1,7 @@ fetchMany($query, [$proyecto_id]); } + public function fetchIdsByProyecto(int $proyecto_id): array + { + $query = "SELECT a.`id` +FROM `{$this->getTable()}` a + JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad` + JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1 + JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt` + JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id` + JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado` +WHERE ptu.`proyecto` = ? AND tev.`activa` +GROUP BY a.`id`"; + return $this->connection->execute($query, [$proyecto_id])->fetchAll(PDO::FETCH_ASSOC); + } public function fetchActivaByProyecto(int $proyecto_id): array { $query = "SELECT a.* @@ -197,11 +210,27 @@ FROM `{$this->getTable()}` a WHERE `unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?"; return $this->fetchMany($query, [$unidad, $tipo]); } + public function fetchIdsByUnidad(string $unidad, string $tipo): array + { + $query = "SELECT a.id +FROM `{$this->getTable()}` a + JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad` + JOIN `unidad` ON `unidad`.`id` = pu.`unidad` + JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt` + JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo` +WHERE `unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?"; + return $this->connection->execute($query, [$unidad, $tipo])->fetchAll(PDO::FETCH_ASSOC); + } public function fetchByPrecio(string $precio): array { $query = "SELECT * FROM `{$this->getTable()}` WHERE `valor_uf` = ?"; return $this->fetchMany($query, [$precio]); } + public function fetchIdsByPrecio(string $precio): array + { + $query = "SELECT `id` FROM `{$this->getTable()}` WHERE `valor_uf` = ?"; + return $this->connection->execute($query, [$precio])->fetchAll(PDO::FETCH_ASSOC); + } public function fetchByPropietario(string $propietario): array { $query = "SELECT a.* @@ -212,6 +241,16 @@ WHERE CONCAT_WS('-', `propietario`.`rut`, `propietario`.`dv`) LIKE :propietario OR CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE :propietario"; return $this->fetchMany($query, [':propietario' => "%{$propietario}%"]); } + public function fetchIdsByPropietario(string $propietario): array + { + $query = "SELECT a.id +FROM `{$this->getTable()}` a + JOIN `propietario` ON `propietario`.`rut` = a.`propietario` +WHERE CONCAT_WS('-', `propietario`.`rut`, `propietario`.`dv`) LIKE :propietario OR `propietario`.`nombres` LIKE :propietario + OR `propietario`.`apellido_paterno` LIKE :propietario OR `propietario`.`apellido_materno` LIKE :propietario + OR CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE :propietario"; + return $this->connection->execute($query, [':propietario' => "%{$propietario}%"])->fetchAll(PDO::FETCH_ASSOC); + } public function fetchByPropietarioNombreCompleto(string $propietario): array { $query = "SELECT a.* diff --git a/app/src/Repository/Venta/Unidad.php b/app/src/Repository/Venta/Unidad.php index 252cfa9..8605d32 100644 --- a/app/src/Repository/Venta/Unidad.php +++ b/app/src/Repository/Venta/Unidad.php @@ -1,6 +1,7 @@ where("a.`descripcion` LIKE ? AND tu.`descripcion` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`activa` = 0)"); return $this->fetchMany($query, [$descripcion, $tipo]); } + public function fetchDisponiblesIdsByDescripcionAndTipo(string $descripcion, string $tipo): array + { + $query = $this->connection->getQueryBuilder() + ->select('a.id') + ->from("{$this->getTable()} a") + ->joined("JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt` + JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo` + LEFT OUTER JOIN `propiedad_unidad` pu ON pu.`unidad` = a.`id` + LEFT OUTER JOIN `venta` ON `venta`.`propiedad` = pu.`propiedad` + LEFT OUTER JOIN (SELECT ev1.* FROM `estado_venta` ev1 JOIN (SELECT MAX(`id`) as 'id', `venta` FROM `estado_venta`) ev0 ON ev0.`id` = ev1.`id`) ev ON ev.`venta` = `venta`.`id` + LEFT OUTER JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`") + ->where("a.`descripcion` LIKE ? AND tu.`descripcion` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`activa` = 0)"); + return $this->connection->execute($query, [$descripcion, $tipo])->fetchAll(PDO::FETCH_ASSOC); + } protected function joinProrrateo(): string { diff --git a/app/src/Service/Search.php b/app/src/Service/Search.php index 08f6633..5b66a4e 100644 --- a/app/src/Service/Search.php +++ b/app/src/Service/Search.php @@ -22,7 +22,8 @@ class Search } else { $results = $this->find($query, $tipo); } - return $this->sort($results); + return $results; + //return $this->sort($results); } protected function findCualquiera(string $query): array @@ -45,7 +46,7 @@ class Search } protected function find(string $query, string $tipo): array { - preg_match_all('/["\']([\s\w]+)["\']|(\w+)/i', $query, $matches, PREG_SET_ORDER | PREG_UNMATCHED_AS_NULL); + preg_match_all('/["\']([\s\w]+)["\']|(\w+)/iu', $query, $matches, PREG_SET_ORDER | PREG_UNMATCHED_AS_NULL); $queries = array_map(function($match) { array_shift($match); $valid = array_filter($match, function($line) {return $line !== null;}); @@ -56,7 +57,7 @@ class Search foreach ($queries as $q) { $this->add($results, $this->findVentas($q, $tipo)); if (in_array($tipo, $tiposUnidades)) { - $this->add($results, $this->findUnidadesDisponibles($q, $tipo)); + $this->add($results, $this->findUnidadesDisponibles($q, $tipo), false); } } return $results; @@ -91,7 +92,7 @@ class Search protected function findUnidadesDisponibles(string $query, string $tipo): array { try { - return $this->unidadRepository->fetchDisponiblesByDescripcionAndTipo($query, $tipo); + return $this->unidadRepository->fetchDisponiblesIdsByDescripcionAndTipo($query, $tipo); } catch (EmptyResponse) { return []; } @@ -99,7 +100,7 @@ class Search protected function findUnidad(string $query, string $tipo): array { try { - return $this->ventaService->getByUnidad($query, $tipo); + return $this->ventaRepository->fetchIdsByUnidad($query, $tipo); } catch (EmptyResult) { return []; } @@ -107,7 +108,7 @@ class Search protected function findPropietario(string $query): array { try { - return $this->ventaService->getByPropietario($query); + return $this->ventaRepository->fetchIdsByPropietario($query); } catch (EmptyResult) { return []; } @@ -116,7 +117,7 @@ class Search { try { $precio = str_replace(['$', '.', ','], ['', '', '.'], $query); - return $this->ventaService->getByPrecio($precio); + return $this->ventaRepository->fetchIdsByPrecio($precio); } catch (EmptyResult) { return []; } @@ -125,7 +126,7 @@ class Search { try { $proyecto = $this->proyectoService->getByName($query); - return $this->ventaService->getByProyecto($proyecto->id); + return $this->ventaRepository->fetchIdsByProyecto($proyecto->id); } catch (EmptyResult) { return []; } @@ -145,22 +146,21 @@ class Search } return $this->tipos; } - protected function add(array &$results, array $found): void + protected function add(array &$results, array $found, bool $is_venta = true): void { foreach ($found as $item) { if (!$this->inResults($item, $results)) { + $item['tipo'] = 'venta'; + if (!$is_venta) { + $item['tipo'] = 'unidad'; + } $results []= $item; } } } protected function inResults($item, array $results): bool { - foreach ($results as $result) { - if (get_class($item) === get_class($result) and $item->id === $result->id) { - return true; - } - } - return false; + return in_array($item, $results, true); } protected function sort(&$results): array { diff --git a/cli/bin/index.php b/cli/bin/index.php new file mode 100644 index 0000000..9e47d85 --- /dev/null +++ b/cli/bin/index.php @@ -0,0 +1,13 @@ +run(); +} catch (Error $error) { + $app->getContainer()->get(Psr\Log\LoggerInterface::class)->error($error); +} catch (Exception $exception) { + $app->getContainer()->get(Psr\Log\LoggerInterface::class)->notice($exception); +} From a82db6e1dab41f7bc71b26769f934f435fe8f9dc Mon Sep 17 00:00:00 2001 From: Aldarien Date: Fri, 24 Nov 2023 10:24:42 -0300 Subject: [PATCH 030/163] FIX: trailing slash in ventas url --- app/resources/views/layout/body/header/menu/ventas.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/resources/views/layout/body/header/menu/ventas.blade.php b/app/resources/views/layout/body/header/menu/ventas.blade.php index b2a914a..2cea6c4 100644 --- a/app/resources/views/layout/body/header/menu/ventas.blade.php +++ b/app/resources/views/layout/body/header/menu/ventas.blade.php @@ -8,7 +8,7 @@