diff --git a/Dockerfile b/Dockerfile index bed32d7..cfbc93f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,6 @@ RUN docker-php-ext-install zip RUN pecl install xdebug-3.1.1 \ && docker-php-ext-enable xdebug -WORKDIR /code +WORKDIR /app/ui COPY --from=composer /usr/bin/composer /usr/bin/composer diff --git a/common/Controller/Precios.php b/common/Controller/Precios.php new file mode 100644 index 0000000..cc88776 --- /dev/null +++ b/common/Controller/Precios.php @@ -0,0 +1,14 @@ +render($response, 'ventas.precios.proyectos'); + } +} diff --git a/common/Controller/Proyectos.php b/common/Controller/Proyectos.php new file mode 100644 index 0000000..9d0c374 --- /dev/null +++ b/common/Controller/Proyectos.php @@ -0,0 +1,14 @@ +render($response, 'ventas.precios.list', compact('proyecto_id')); + } +} diff --git a/common/Controller/Ventas.php b/common/Controller/Ventas.php new file mode 100644 index 0000000..672c18d --- /dev/null +++ b/common/Controller/Ventas.php @@ -0,0 +1,18 @@ +render($response, 'ventas.proyectos'); + } + public function get(ServerRequestInterface $request, ResponseInterface $response, View $view, $proyecto_id): ResponseInterface + { + return $view->render($response, 'ventas.list', compact('proyecto_id')); + } +} diff --git a/common/Service/Auth.php b/common/Service/Auth.php index cfcc4a3..97748f1 100644 --- a/common/Service/Auth.php +++ b/common/Service/Auth.php @@ -85,9 +85,10 @@ class Auth { return false; } if ($response->getStatusCode() != 200) { + error_log(var_export($response, true)); return false; } - $data = json_decode($response->getBody()); + $data = json_decode($response->getBody()->getContents()); if (!$data->login) { return false; } diff --git a/composer.json b/composer.json index b524437..48bae8e 100644 --- a/composer.json +++ b/composer.json @@ -8,9 +8,9 @@ "zeuxisoo/slim-whoops": "^0.7.3", "nyholm/psr7": "^1.4", "nyholm/psr7-server": "^1.0", - "rubellum/slim-blade-view": "^0.1.1", "nesbot/carbon": "^2.54", - "guzzlehttp/guzzle": "^7.4" + "guzzlehttp/guzzle": "^7.4", + "berrnd/slim-blade-view": "^1.0" }, "require-dev": { "phpunit/phpunit": "^9.5", diff --git a/nginx.conf b/nginx.conf index 560e540..b8e45ec 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,10 +1,10 @@ server { listen 80; - server_name api; + server_name ui; index index.php; - error_log /code/logs/error.log; - access_log /code/logs/access.log; - root /code/public; + error_log /var/log/nginx/ui.error.log; + access_log /var/log/nginx/ui.access.log; + root /app/ui/public; location / { try_files $uri /index.php$is_args$args; diff --git a/public/js/ventas/list.js b/public/js/ventas/list.js new file mode 100644 index 0000000..e05a61b --- /dev/null +++ b/public/js/ventas/list.js @@ -0,0 +1,170 @@ +const ventas = { + url: '', + id_proyecto: '', + id_ventas: '', + setup: function() { + sendGet(this.url).then(response => { + const formatters = { + pesos: Intl.NumberFormat('es-CL', {style: 'decimal', useGrouping: true}), + uf: Intl.NumberFormat('es-CL', {style: 'decimal', useGrouping: true, minimumFractionDigits: 2, maximumFractionDigits: 2}) + } + const p = new Proyecto(response.proyecto) + p.set().formatters(formatters) + p.draw().title($(this.id_proyecto)) + p.draw().ventas($(this.id_ventas)) + }) + } +} +class Proyecto { + constructor({id, descripcion, ventas}) { + this.id = id + this.descripcion = descripcion + this.set().ventas(ventas) + this.formatters = { + uf: null + } + } + set() { + return { + ventas: ventas => { + this.ventas = ventas.map(el => { + return new Venta(el) + }) + }, + formatters: formatters => { + this.formatters = formatters + this.ventas.forEach(v => { + v.set().formatters(formatters) + }) + } + } + } + draw() { + return { + title: parent => { + parent.append( + $('').attr('href', _urls.base + '/proyecto/' + this.id).html(this.descripcion + ' [' + this.ventas.length + ']') + ) + }, + ventas: tbody => { + this.ventas.forEach(venta => { + venta.draw().row(tbody) + }) + } + } + } +} +class Venta { + constructor({id, propiedad, propietario, fecha, valor, estado}) { + this.id = id + this.unidades = '' + this.set().unidades(propiedad) + this.propiedad = propiedad + this.superficie = 0 + this.set().superficie(propiedad) + this.tipologia = '' + this.set().tipologia(propiedad) + this.propietario = '' + this.set().propietario(propietario) + this.fecha = fecha + this.valor = valor + this.estado = '' + this.set().estado(estado) + this.formatters = { + uf: null + } + } + set() { + return { + unidades: propiedad => { + const departamentos = propiedad.unidades.filter(u => { + return (u.tipo.descripcion === 'departamento') + }).map(u => { + return u.descripcion + }).join('-') + let bodegas = [] + let estacionamientos = propiedad.unidades.filter(u => { + return (u.tipo.descripcion === 'estacionamiento') + }).map(u => { + if (u.descripcion.includes('B')) { + const e = u.descripcion.split('B') + while (e.length > 1) { + bodegas.push(e.pop().replace(' ', '').replace('-', ',')) + } + return e[0].replace(' ', '').replace(',', '').replace('-', ',') + } + return u.descripcion.replace(' ', '').replace('-', ',').replace('y ', ',') + }).sort((a, b) => { + return parseInt(a) - parseInt(b) + }) + if (estacionamientos.length > 0) { + estacionamientos = ' - E' + estacionamientos.join(',').replace(/(,\s)*$/g, '') + } else { + estacionamientos = '' + } + bodegas = [...(bodegas.filter(el => el !== '')), ...(propiedad.unidades.filter(u => { + return (u.tipo.descripcion === 'bodega') + }).map(u => { + return u.descripcion.replace(' ', '').replace('-', ',') + }))].sort((a, b) => { + return parseInt(a) - parseInt(b) + }).filter(el => el !== '') + if (bodegas.length > 0) { + bodegas = ' - B' + bodegas.join(',').replace(/(,\s)*$/g, '') + } else { + bodegas = '' + } + this.unidades = departamentos + estacionamientos + bodegas + }, + superficie: propiedad => { + const unidad = propiedad.unidades[0] + this.superficie = unidad.proyectoTipoUnidad.superficie.vendible + }, + tipologia: propiedad => { + const unidad = propiedad.unidades[0] + this.tipologia = unidad.proyectoTipoUnidad.tipologia.abreviacion + }, + propietario: propietario => { + this.propietario = propietario.nombreCompleto + }, + estado: estado => { + this.estado = estado.estado.descripcion.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase(); }) + }, + formatters: formatters => { + this.formatters = formatters + } + } + } + draw() { + return { + row: parent => { + parent.append( + $('').append( + $('').append( + $('') + .attr('href', _urls.base + '/venta/' + this.id) + .html(this.unidades) + .append('') + ) + ).append( + $('').append( + $('') + .attr('href', _urls.base + '/search/' + encodeURIComponent(this.propietario)) + .html(this.propietario + ' ') + ) + ).append( + $('').html(this.formatters.uf.format(this.valor) + ' UF') + ).append( + $('').html(this.tipologia + ' (' + this.formatters.uf.format(this.superficie) + ' m²)') + ).append( + $('').html(this.formatters.uf.format(this.valor / this.superficie) + ' UF/m²') + ).append( + $('').html(new Date(this.fecha.date).toLocaleDateString('es-CL')) + ).append( + $('').html(this.estado) + ) + ) + } + } + } +} diff --git a/resources/routes/04_proyectos.php b/resources/routes/04_proyectos.php new file mode 100644 index 0000000..0030f5d --- /dev/null +++ b/resources/routes/04_proyectos.php @@ -0,0 +1,10 @@ +group('/proyectos', function($app) { + $app->get('[/]', \Incoviba\UI\Common\Controller\Proyectos::class); +}); +$app->group('/proyecto/{proyecto_id}', function($app) { + $app->group('/precios', function($app) { + $app->get('/add', [\Incoviba\UI\Common\Controller\Precios::class, 'add']); + $app->get('[/]', [\Incoviba\UI\Common\Controller\Proyectos::class, 'precios']); + }); +}); diff --git a/resources/routes/05_ventas.php b/resources/routes/05_ventas.php new file mode 100644 index 0000000..30da1e1 --- /dev/null +++ b/resources/routes/05_ventas.php @@ -0,0 +1,6 @@ +group('/ventas', function($app) { + $app->get('/{proyecto_id}', [\Incoviba\UI\Common\Controller\Ventas::class, 'get']); + $app->get('[/]', \Incoviba\UI\Common\Controller\Ventas::class); +}); +$app->get('/precios', [\Incoviba\UI\Common\Controller\Precios::class, 'proyectos']); diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 6b0f325..cf05708 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -20,7 +20,7 @@ diff --git a/resources/views/layout/base.blade.php b/resources/views/layout/base.blade.php index ef25f73..fb14965 100644 --- a/resources/views/layout/base.blade.php +++ b/resources/views/layout/base.blade.php @@ -14,8 +14,6 @@ - - @stack('styles') @@ -29,6 +27,8 @@ @include('layout.footer') + + + +@endpush diff --git a/resources/views/ventas/precios/list.blade.php b/resources/views/ventas/precios/list.blade.php index e2f27a1..cb091ba 100644 --- a/resources/views/ventas/precios/list.blade.php +++ b/resources/views/ventas/precios/list.blade.php @@ -5,9 +5,13 @@

- Precios - {{$proyecto->descripcion}} + Precios - +
+ -

@@ -25,110 +29,323 @@ UF/m² - - @foreach ($proyecto->ProyectoTipoUnidades() as $tipo) - - {{ucwords($tipo->tipo()->descripcion)}} - {{$tipo->nombre}} - - @if ($tipo->tipologia()) - {{$tipo->tipologia()->descripcion}} - @else - {{$tipo->abreviacion}} - @endif - - {{$tipo->lineas()}} - {{$tipo->m2()}} - {{count($tipo->unidades())}} - {{format('ufs', $tipo->precio(), true)}} - - @if ($tipo->m2() > 0) - {{format('ufs', $tipo->precio() / $tipo->m2(), true)}}/m² - @else - - - @endif - - - - - - - - - - - - - - - - - @foreach ($tipo->unidades() as $unidad) - @if ($subtipo != $unidad->subtipo) - subtipo; ?> - - - - - - - @endif - - - @if ($unidad->precio()) - - - - @else - - @endif - - @endforeach - -
UnidadDesdePrecioUF/m²
Línea {{$subtipo}}{{format('ufs', $tipo->precioSubtipo($subtipo), null, true)}}{{format('ufs', $tipo->precioSubtipo($subtipo) / $tipo->m2(), null, true)}}/m²
{{$unidad->descripcion}}{{format('shortDate', $unidad->precio()->estado()->fecha)}}{{format('ufs', $unidad->precio()->valor, null, true)}} - @if ($unidad->m2('vendible') > 0) - {{format('ufs', $unidad->precio()->valor / $unidad->m2('vendible'), null, true)}}/m² - @else - - - @endif - --
- - - @endforeach - + @endsection @push('scripts') @endpush diff --git a/resources/views/ventas/precios/proyectos.blade.php b/resources/views/ventas/precios/proyectos.blade.php index 095b5b6..23f4697 100644 --- a/resources/views/ventas/precios/proyectos.blade.php +++ b/resources/views/ventas/precios/proyectos.blade.php @@ -5,10 +5,24 @@

Precios

- @foreach ($proyectos as $proyecto) - - - @endforeach +
{{$proyecto->descripcion}} -
@endsection + +@push('scripts') + +@endpush diff --git a/resources/views/ventas/proyectos.blade.php b/resources/views/ventas/proyectos.blade.php index 043fc60..3a4a7f6 100644 --- a/resources/views/ventas/proyectos.blade.php +++ b/resources/views/ventas/proyectos.blade.php @@ -7,12 +7,29 @@
- @foreach ($proyectos as $proyecto) - - - - @endforeach +
{{$proyecto->descripcion}}
-@endsection \ No newline at end of file +@endsection + +@push('scripts') + +@endpush