153 Commits

Author SHA1 Message Date
6ddc48ec60 Merge branch 'develop' 2024-03-13 16:31:34 -03:00
8caa80459e Accelerar listado ventas 2024-03-13 16:17:14 -03:00
98953cce42 FormaPago Service 2024-03-13 14:38:44 -03:00
c7dd309185 Movimiento + Detalles 2024-03-04 19:55:49 -03:00
48bfe5d8ab Mejora en velocidad de busqueda 2024-02-28 21:44:37 -03:00
d9b5bc6507 Procesar otras cartolas Santander 2024-02-28 17:02:04 -03:00
21d1ef653f FIX: Saldo actual informe tesoreria 2024-02-28 13:53:53 -03:00
e8d43e43ff FIX: fecha saldo consolidado 2024-02-28 13:45:20 -03:00
fc9788a1cd FIX: Mostrar pie con cuotas vigentes 2024-02-28 10:37:51 -03:00
02dcc950f4 FIX: Editar credito, valor mandaba fecha 2024-02-28 10:33:34 -03:00
370b6714bc Excel button in datatables 2024-02-27 16:49:39 -03:00
dc7a9f9e7a Buscar por rut 2024-02-27 16:11:48 -03:00
cfe18c1909 Informe tesoreria en excel 2024-02-23 22:37:09 -03:00
5156858205 Update Fomantic-UI 2024-02-23 10:20:58 -03:00
415ba31270 Cartola Diaria Manual 2024-02-23 10:20:44 -03:00
c784d1bee9 Fix informes 2024-02-21 21:22:04 +00:00
a1ade5c2c7 Merge branch 'develop' of http://git.provm.cl/Incoviba/oficial into develop 2024-02-20 01:54:05 +00:00
879b612493 Cartola Diaria 2024-02-19 22:39:22 -03:00
b4cdd2d5f7 Merge branch 'develop' of http://git.provm.cl/Incoviba/oficial into develop 2024-02-15 21:59:47 +00:00
51cabee824 Editar credito 2024-02-15 18:57:56 -03:00
d2e51e76f8 Merge branch 'develop' of http://git.provm.cl/Incoviba/oficial into develop 2024-02-14 16:54:10 +00:00
1621d6fe30 Implementacion agregar abono a escritura 2024-02-14 13:54:01 -03:00
0e32512adc Merge branch 'develop' of http://git.provm.cl/Incoviba/oficial into develop 2024-02-13 21:18:11 +00:00
338f290539 FIX: logged en debug 2024-02-13 18:13:53 -03:00
2aad7e1152 Merge branch 'develop' of http://git.provm.cl/Incoviba/oficial into develop 2024-02-13 21:00:02 +00:00
e542615128 FIX: Venta nueva no se ingresaba 2024-02-13 17:59:46 -03:00
1c7797b1b1 Merge branch 'develop' of http://git.provm.cl/Incoviba/oficial into develop 2024-02-13 15:13:06 +00:00
ba0d4073d7 FIX: All sociedades 2024-02-13 12:12:54 -03:00
faac3874a8 Merge branch 'develop' of http://git.provm.cl/Incoviba/oficial into develop 2024-02-13 15:11:33 +00:00
ade107ab3c Stackable grid 2024-02-13 12:11:26 -03:00
c192cf1883 Merge branch 'develop' of http://git.provm.cl/Incoviba/oficial into develop 2024-02-13 15:08:31 +00:00
4fb75b11c4 Mejora en look de depositos y vencidos 2024-02-13 12:08:25 -03:00
ccbb71d875 Merge branch 'develop' of http://git.provm.cl/Incoviba/oficial into develop 2024-02-13 14:26:36 +00:00
7f25b4b5e1 FIX: all sociedades & allActive depositos 2024-02-13 11:26:28 -03:00
f0b26a251b Merge branch 'develop' of http://git.provm.cl/Incoviba/oficial into develop 2024-02-13 14:17:08 +00:00
ea068d95d0 FIX: DAPs -> Depositos routes 2024-02-13 11:17:01 -03:00
1ccc9ab3d4 Cambio a proyectos:activos 2024-02-13 14:12:19 +00:00
5cd19bcdce Merge branch 'develop' of http://git.provm.cl/Incoviba/oficial into develop 2024-02-13 14:11:45 +00:00
712c70b34d FIX: DAPs -> Depositos 2024-02-13 11:11:30 -03:00
35ab7e7e8b Depositos vencidos no suman ni restan 2024-02-13 11:10:26 -03:00
4b39f93f30 Update permissions for cli 2024-02-13 04:30:54 +00:00
d3f188684a Increase update of proyectos 2024-02-13 04:30:29 +00:00
82647a171d Merge branch 'feature/DAPs' into develop 2024-02-13 01:16:58 -03:00
e44ab30665 Informe Tesoreria 2024-02-13 01:16:17 -03:00
19333bc338 Merge branch 'feature/dap' into develop 2024-02-12 10:00:42 -03:00
4738dae7c8 DAPs API 2024-02-12 10:00:17 -03:00
a370ffff43 Cleanup 2024-02-12 09:59:47 -03:00
88f9e539f7 Merge branch 'develop' of http://git.provm.cl/Incoviba/oficial into develop 2024-02-12 09:53:52 -03:00
671b26f038 Merge branch 'feature/Movimientos' into develop 2024-02-12 09:53:18 -03:00
e133bd36cf Cartola diaria 2024-02-12 09:52:48 -03:00
251dbbe0f0 FIX: cron ENV vars 2024-02-10 10:37:45 -03:00
e1eb2c4c56 Cleanup 2024-02-08 13:04:05 -03:00
1078f4c188 Simplificacion de Cartola diaria 2024-02-08 00:06:29 -03:00
38962cb9cf API Movimientos y cartola diaria 2024-02-07 23:48:31 -03:00
3cd699d2e2 Merge branch 'develop' of http://git.provm.cl/Incoviba/oficial into develop 2024-02-07 18:37:13 -03:00
d8b8787be9 FIX: Find Pago 2024-02-07 18:35:28 -03:00
ad3285efd9 FIX: find ventas por proyecto y unidad 2024-01-30 12:07:43 -03:00
62edca5335 Simplify set post or query 2024-01-23 20:41:52 -03:00
ac6c5b7d3d FIX: activar busqueda cuando tiene query definido 2024-01-23 20:18:02 -03:00
5b5a0ed1f5 FIX: Link a buscar propietario 2024-01-23 20:07:34 -03:00
9d7857621e FIX: findPago sin numero 2024-01-22 12:10:16 -03:00
029cd095cb Base Log cli 2024-01-19 23:27:06 -03:00
c1792907c0 Basic Controller and Service 2024-01-19 23:12:13 -03:00
fa11f5b240 Cleanup logs, fixed add Venta, fixed search 2024-01-19 23:10:20 -03:00
f55e4dbd5f ventas.base 2024-01-18 17:15:32 -03:00
ca83472012 Informe escritura 2024-01-18 16:41:16 -03:00
01af47fba1 FIX: escriturar 2024-01-18 15:18:07 -03:00
e1462657fc Clave -> Contraseña 2024-01-18 13:20:02 -03:00
72f63c5e6c Cleanup 2024-01-18 13:17:23 -03:00
1f076bc2f1 FIX: IPC y factura 2024-01-18 13:15:26 -03:00
ad003c7dcf Cleanup 2024-01-18 13:05:36 -03:00
aef1ccd4a0 Santander 2024-01-17 18:27:29 -03:00
3684bc2e21 FIX: glosa 2024-01-17 16:21:40 -03:00
d1d3705a7b Cambio base Cartola/Banco e implementacion de Itau 2024-01-17 16:19:38 -03:00
ecdb67a9ab FIX: Security en htm 2024-01-17 14:31:49 -03:00
4c86ce2a8a TipoUnidad por Proyecto 2024-01-17 11:22:10 -03:00
5c6bd91425 Missing updates 2024-01-17 11:15:13 -03:00
18d7e449f7 Missing updates 2024-01-17 11:13:27 -03:00
bfdaf0e7f2 Missing updates 2024-01-17 11:10:56 -03:00
ce0510687a Menu Centros de Costos 2024-01-17 11:05:25 -03:00
3eb4ce4d21 Max log files 2024-01-17 10:49:14 -03:00
674aba801e Cartolas 2024-01-17 10:33:11 -03:00
c4f486d3fa Disable edit of Centros Costos 2024-01-10 20:47:39 -03:00
dc840a7bff Sort Centros Costos 2024-01-10 20:36:18 -03:00
316cc51387 FIX: Tipo Cuenta 2024-01-10 20:32:55 -03:00
68e59770fd Menu contabilidad 2024-01-10 19:34:41 -03:00
a66b549a8c Centros de Costos 2024-01-09 23:35:35 -03:00
74b3bb42ea Add sorting to fetchAll 2024-01-09 23:35:11 -03:00
72a2ffe924 Error code change 2024-01-08 21:25:02 -03:00
6393a1fced Implement movimientos cuotas 2024-01-08 21:24:34 -03:00
d225011ae9 Implement search pago 2024-01-08 17:33:42 -03:00
bc2333bc95 FIX: Pie cuotas valores uf 2024-01-08 13:16:12 -03:00
675b3843ea FIX: Pie cuotas vigentes 2023-12-22 14:15:09 -03:00
0829d338a9 FIX: null date 2023-12-22 14:14:02 -03:00
20b2bdc6c6 FIX: Cuotas vigentes 2023-12-22 13:17:03 -03:00
8492d1df2b Eliminar desistimiento y loading en editar desistimiento 2023-12-22 12:52:04 -03:00
afbadd520b FIX: when new value is null 2023-12-22 12:50:09 -03:00
ac52305002 Editar desistimiento venta 2023-12-21 21:06:38 -03:00
d7d17a3051 Mostrar correctamente venta desistida 2023-12-21 19:15:11 -03:00
80a6bf1535 Desistir venta 2023-12-21 18:45:47 -03:00
93431e41b3 Porcentajes en cuotas 2023-12-20 20:59:43 -03:00
d99f2a6214 pageLength for cuotas 2023-12-20 15:39:13 -03:00
30277e6355 FIX: cuotas en pie 2023-12-20 15:37:47 -03:00
06d5327934 Search listado por defecto muestra 25 y cleanup 2023-12-20 12:04:06 -03:00
6f772a56b8 FIX: Buscar por nombre con wildcards 2023-12-20 12:02:52 -03:00
abe82e4689 FIX: Default valor unitario terreno 2023-12-20 10:50:49 -03:00
379a33a4da Escriturar 2023-12-20 08:44:49 -03:00
1ba53c9e12 FIX: Precio Unidad no existe en venta y facturacion 2023-12-13 13:28:19 -03:00
94906eea8c FIX: Precio Unidad no existe 2023-12-13 13:03:43 -03:00
8b9b02825a FIX: Precio Unidad no existe 2023-12-13 12:44:32 -03:00
8f2f90aca2 FIX: .env 2023-12-12 20:19:15 -03:00
d699f9bf62 Install executeable 2023-12-12 15:56:00 +00:00
e38fdd20ee FIX: install 2023-12-12 12:53:32 -03:00
f362054ea7 Install 2023-12-12 12:47:58 -03:00
f597d552be Edit fecha escritura 2023-12-04 21:43:57 -03:00
43977d1bd9 FIX: IPC no disponible 2023-12-04 19:51:44 -03:00
9aa4e0ae1d FIX: UF/m2 con valor venta 2023-12-04 19:08:26 -03:00
377cf51b44 Editar valor venta 2023-12-04 19:00:21 -03:00
57579a52f1 Editar propiedad en venta 2023-12-01 15:00:25 -03:00
af9c6c51d4 FIX: active -> activo en tipo_estado_pago 2023-12-01 12:39:26 -03:00
0eaa09bea0 FIX: Fetch terreno 2023-11-30 19:06:59 -03:00
04478afa2f Mejoras en Facturacion 2023-11-30 18:40:15 -03:00
f2efb41977 IPC rango y sort 2023-11-30 00:24:08 -03:00
d0a85b2149 IPC acumulado desde cli 2023-11-30 00:06:21 -03:00
68821fb0d3 Changed start location in cli 2023-11-29 23:07:50 -03:00
f957d29779 Full command 2023-11-29 23:02:12 -03:00
dc7a39e193 Output cron execution 2023-11-29 22:31:53 -03:00
17f93dcd34 Edit Pie 2023-11-29 22:21:46 -03:00
9991b7c6a3 FIX: % descuento 2023-11-29 21:23:11 -03:00
91bdef5cc5 FIX: % descuento 2023-11-29 21:21:51 -03:00
244d304e04 FIX: % descuento 2023-11-29 21:18:30 -03:00
2600bd409e FIX: fecha estado venta 2023-11-29 21:17:06 -03:00
0761be6613 Precio = valor propiedad o precio 2023-11-29 21:14:55 -03:00
e347aaabe9 Valor PU -> ultimo precio 2023-11-29 21:13:03 -03:00
fe3055708f FIX: precio->valor 2023-11-29 20:56:00 -03:00
62153dd1ef Editar propiedad en venta 2023-11-29 20:44:13 -03:00
39048e12b3 Facturacion, se agrega PropiedadUnidad 2023-11-29 20:09:08 -03:00
094209823a columna faltante del modelo 2023-11-28 22:12:15 -03:00
bcdca32075 Reajuste 2023-11-28 21:38:24 -03:00
fada4f80a2 FIX: link venta desde pie 2023-11-27 18:07:48 -03:00
a28c51d94c Total pesos en forma pago y detalle cuotas 2023-11-27 17:23:10 -03:00
df679b2a1a Log commands 2023-11-25 21:38:00 -03:00
ec4b16b2af Timezone 2023-11-25 01:14:28 -03:00
3c983fc6c9 FIX: missing slash 2023-11-25 01:05:56 -03:00
7945579e80 CLI 2023-11-25 00:56:18 -03:00
ab1647eed3 lighter install 2023-11-25 00:56:11 -03:00
ec7d8e69ab FIX: Remove login for API 2023-11-25 00:55:31 -03:00
3cadaca746 Focus and Dev Kint 2023-11-24 20:42:05 -03:00
2726bc5074 Cleanup old version 2023-11-24 20:41:41 -03:00
331ee1e584 Merge branch 'develop' 2023-06-22 23:18:13 -04:00
24c17debf3 Merge branch 'develop' 2023-02-15 18:30:09 -03:00
552fd0aa06 Merge branch 'develop' 2023-02-14 20:50:42 -03:00
60faf293d4 Merge branch 'develop' 2023-02-13 17:18:41 -03:00
879 changed files with 11308 additions and 43986 deletions

View File

@ -1,3 +1,6 @@
COMPOSE_PROFILES=app,db
COMPOSE_PATH_SEPARATOR=:
COMPOSE_FILE=./docker-compose.yml:./adminer-compose.yml
COMPOSE_PROFILES=app,db,cli,cache
APP_PATH=./app
CLI_PATH=./cli
APP_PORT=8080

2
.gitignore vendored
View File

@ -8,3 +8,5 @@
**/cache/
**/modules/
**/.idea/
**/upload?/
**/informe?/

1
.key.env.sample Normal file
View File

@ -0,0 +1 @@
API_KEY=

19
CLI.Dockerfile Normal file
View File

@ -0,0 +1,19 @@
FROM php:8.2-cli
ENV TZ "${TZ}"
ENV APP_NAME "${APP_NAME}"
ENV API_URL "${API_URL}"
RUN apt-get update && apt-get install -y --no-install-recommends cron rsyslog nano && rm -r /var/lib/apt/lists/*
RUN pecl install xdebug-3.2.2 \
&& docker-php-ext-enable xdebug \
&& echo "#/bin/bash\nprintenv >> /etc/environment\ncron -f -L 11" > /root/entrypoint && chmod a+x /root/entrypoint
COPY ./php-errors.ini /usr/local/etc/php/conf.d/docker-php-errors.ini
WORKDIR /code/bin
COPY --chmod=644 ./cli/crontab /var/spool/cron/crontabs/root
CMD [ "/root/entrypoint" ]

View File

@ -1,6 +1,6 @@
FROM php:8.1-fpm
RUN apt-get update && apt-get install -y libzip-dev libicu-dev git libpng-dev unzip tzdata \
RUN apt-get update && apt-get install -y --no-install-recommends libzip-dev libicu-dev git libpng-dev unzip tzdata \
&& rm -r /var/lib/apt/lists/*
RUN docker-php-ext-install pdo pdo_mysql zip intl gd bcmath

1
app/.adminer.env.sample Normal file
View File

@ -0,0 +1 @@
ADMINER_DESIGN=dracula

View File

@ -1,4 +1,4 @@
MYSQL_DATABASE=
MYSQL_PASSWORD=
MYSQL_ROOT_PASSWORD=
MYSQL_DATABASE=
MYSQL_USER=
MYSQL_PASSWORD=

11
app/.env.sample Normal file
View File

@ -0,0 +1,11 @@
APP_URL=
MYSQL_HOST=db
COOKIE_NAME=
COOKIE_DOMAIN=
COOKIE_PATH=/
MAX_LOGIN_HOURS=120
REDIS_HOST=redis
REDIS_PORT=6379

View File

@ -0,0 +1,10 @@
<?php
namespace Incoviba\Common\Define\Cartola;
use Psr\Http\Message\UploadedFileInterface;
interface Banco
{
public function process(UploadedFileInterface $file): array;
}

View File

@ -0,0 +1,10 @@
<?php
namespace Incoviba\Common\Define\Contabilidad;
use DateTimeInterface;
use Incoviba\Model;
interface Exporter
{
public function export(Model\Inmobiliaria $inmobiliaria, Model\Banco $banco, DateTimeInterface $mes, array $movimientos): string;
}

View File

@ -0,0 +1,10 @@
<?php
namespace Incoviba\Common\Define;
interface Informe
{
public function setTitle(string $title): Informe;
public function setFilename(string $filename): Informe;
public function addData(array $rows): Informe;
public function build(): void;
}

View File

@ -0,0 +1,34 @@
<?php
namespace Incoviba\Common\Ideal\Cartola;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal\Service;
use Psr\Http\Message\UploadedFileInterface;
abstract class Banco extends Service implements Define\Cartola\Banco
{
public function process(UploadedFileInterface $file): array
{
$data = $this->parseFile($file);
$temp = [];
$columns = $this->columnMap();
foreach ($data as $row) {
$r = [];
foreach ($columns as $old => $new) {
if (!isset($row[$old])) {
continue;
}
$r[$new] = $row[$old];
}
$temp []= $r;
}
return $temp;
}
public function processMovimientosDiarios(array $movimientos): array
{
return $movimientos;
}
abstract protected function columnMap(): array;
abstract protected function parseFile(UploadedFileInterface $uploadedFile): array;
}

View File

@ -0,0 +1,9 @@
<?php
namespace Incoviba\Common\Ideal;
use Psr\Log\LoggerInterface;
abstract class Controller
{
public function __construct(protected LoggerInterface $logger) {}
}

View File

@ -45,11 +45,14 @@ abstract class Repository implements Define\Repository
->where("{$this->getKey()} = ?");
return $this->fetchOne($query, [$id]);
}
public function fetchAll(): array
public function fetchAll(null|string|array $ordering = null): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable());
if ($ordering !== null) {
$query->order($ordering);
}
return $this->fetchMany($query);
}
@ -116,7 +119,7 @@ abstract class Repository implements Define\Repository
$changes = [];
$values = [];
foreach ($columns as $column) {
if (isset($data[$column])) {
if (in_array($column, array_keys($data))) {
$changes []= $column;
$values []= $data[$column];
}

View File

@ -0,0 +1,9 @@
<?php
namespace Incoviba\Common\Ideal;
use Psr\Log\LoggerInterface;
abstract class Service
{
public function __construct(protected LoggerInterface $logger) {}
}

View File

@ -55,14 +55,18 @@ class Mapper implements Define\Repository\Mapper
if ($this->hasProperty()) {
$property = $this->property;
}
if (isset($data[$column])) {
if (in_array($column, array_keys($data))) {
if ($this->hasFactory()) {
$model->addFactory($property, $this->factory);
return true;
}
$value = $data[$column];
if ($this->hasFunction()) {
$value = ($this->function)($data);
if ($value !== null) {
$value = ($this->function)($data);
} elseif ($this->hasDefault()) {
$value = $this->default;
}
}
$model->{$property} = $value;
return true;

View File

@ -9,7 +9,7 @@ class DateTime extends Mapper
public function __construct(string $column, ?string $property = null)
{
$this->setFunction(function($data) use ($column) {
return new DateTimeImmutable($data[$column]);
return new DateTimeImmutable($data[$column] ?? '');
});
if ($property !== null) {
$this->setProperty($property);

View File

@ -9,10 +9,12 @@
"nyholm/psr7-server": "^1.0",
"php-di/php-di": "^7.0",
"php-di/slim-bridge": "^3.4",
"phpoffice/phpspreadsheet": "^1.29",
"predis/predis": "^2.2",
"slim/slim": "^4.11"
},
"require-dev": {
"kint-php/kint": "^5.1",
"phpunit/phpunit": "^10.2"
},
"authors": [

View File

View File

@ -10,4 +10,4 @@ $app->group('/api', function($app) {
include_once $file->getRealPath();
}
}
});
})->add($app->getContainer()->get(Incoviba\Middleware\API::class));

View File

@ -3,4 +3,4 @@ use Incoviba\Controller\Inmobiliarias;
$app->group('/inmobiliarias', function($app) {
$app->get('[/]', Inmobiliarias::class);
});
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));

View File

@ -4,7 +4,7 @@ use Incoviba\Controller\Proyectos;
$app->group('/proyectos', function($app) {
$app->get('/unidades[/]', [Proyectos::class, 'unidades']);
$app->get('[/]', Proyectos::class);
});
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));
$app->group('/proyecto/{proyecto_id}', function($app) {
$app->get('[/]', [Proyectos::class, 'show']);
});
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));

View File

@ -11,10 +11,10 @@ $app->group('/ventas', function($app) {
}
$app->get('/add[/]', [Ventas::class, 'add']);
$app->get('[/]', Ventas::class);
});
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));
$app->group('/venta/{proyecto_nombre:[A-za-zÑñ\+\ %0-9]+}/{unidad_descripcion:[0-9]+}', function($app) {
$app->get('[/]', [Ventas::class, 'showUnidad']);
});
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));
$app->group('/venta/{venta_id:[0-9]+}', function($app) {
$app->group('/propietario', function($app) {
$app->get('[/]', [Ventas::class, 'propietario']);
@ -26,7 +26,17 @@ $app->group('/venta/{venta_id:[0-9]+}', function($app) {
$app->group('/cuotas', function($app) {
$app->get('[/]', [Ventas::class, 'cuotas']);
});
$app->get('[/]', [Ventas::class, 'pie']);
});
$app->group('/escritura', function($app) {
$app->get('/add[/]', [Ventas\Escrituras::class, 'add']);
});
$app->group('/credito', function($app) {
$app->get('[/]', [Ventas\Creditos::class, 'show']);
});
$app->get('/escriturar[/]', [Ventas::class, 'escriturar']);
$app->get('/desistir[/]', [Ventas::class, 'desistir']);
$app->get('/desistida[/]', [Ventas::class, 'desistida']);
$app->get('/edit[/]', [Ventas::class, 'edit']);
$app->get('[/]', [Ventas::class, 'show']);
});
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));

View File

@ -0,0 +1,10 @@
<?php
$app->group('/contabilidad', function($app) {
$files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'contabilidad']));
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
include_once $file->getRealPath();
}
});

View File

@ -4,4 +4,4 @@ use Incoviba\Controller\Search;
$app->group('/search', function($app) {
$app->get('[/{query}[/{tipo}[/]]]', Search::class);
$app->post('[/]', Search::class);
});
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));

View File

@ -4,5 +4,5 @@ use Incoviba\Controller\Login;
$app->group('/login', function($app) {
$app->post('[/]', [Login::class, 'login']);
$app->get('[/]', [Login::class, 'form']);
});
$app->get('/logout', [Login::class, 'logout']);
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));
$app->get('/logout', [Login::class, 'logout'])->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));

View File

@ -2,4 +2,4 @@
use Incoviba\Controller\Base;
$app->get('/construccion', [Base::class, 'construccion'])->setName('construccion');
$app->get('[/]', Base::class);
$app->get('[/]', Base::class)->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));

View File

@ -0,0 +1,10 @@
<?php
$app->group('/contabilidad', function($app) {
$files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'contabilidad']));
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
include_once $file->getRealPath();
}
});

View File

@ -0,0 +1,13 @@
<?php
use Incoviba\Controller\API\Contabilidad\Cartolas;
$app->group('/cartolas', function($app) {
$app->post('/procesar[/]', [Cartolas::class, 'procesar']);
});
$app->group('/cartola', function($app) {
$app->group('/diaria', function($app) {
$app->post('/ayer[/]', [Cartolas::class, 'ayer']);
$app->post('/procesar[/]', [Cartolas::class, 'diaria']);
});
$app->post('/exportar[/]', [Cartolas::class, 'exportar']);
});

View File

@ -0,0 +1,10 @@
<?php
use Incoviba\Controller\API\CentrosCostos;
$app->group('/centros_costos', function($app) {
$app->post('/add[/]', [CentrosCostos::class, 'add']);
});
$app->group('/centro_costo/{centro_costo_id}', function($app) {
$app->post('/edit[/]', [CentrosCostos::class, 'edit']);
$app->delete('[/]', [CentrosCostos::class, 'remove']);
});

View File

@ -0,0 +1,7 @@
<?php
use Incoviba\Controller\API\Contabilidad\Depositos;
$app->group('/depositos', function($app) {
$app->post('/add[/]', [Depositos::class, 'add']);
$app->get('/inmobiliaria/{inmobiliaria_rut}[/]', [Depositos::class, 'inmobiliaria']);
});

View File

@ -0,0 +1,6 @@
<?php
use Incoviba\Controller\API\Contabilidad\Movimientos;
$app->group('/movimiento/{movimiento_id}', function($app) {
$app->post('/detalles', [Movimientos::class, 'detalles']);
});

View File

@ -0,0 +1,11 @@
<?php
use Incoviba\Controller\API\Nubox;
$app->group('/nubox/{inmobiliaria_rut}', function($app) {
$app->get('/token[/]', [Nubox::class, 'token']);
$app->get('/sistemas[/]', [Nubox::class, 'sistemas']);
$app->group('/libro', function($app) {
$app->post('/mayor[/]', [Nubox::class, 'libroMayor']);
$app->post('/diario[/]', [Nubox::class, 'libroDiario']);
});
});

View File

@ -0,0 +1,10 @@
<?php
use Incoviba\Controller\API\Inmobiliarias;
$app->group('/inmobiliarias', function($app) {
$app->get('[/]', Inmobiliarias::class);
});
$app->group('/inmobiliaria/{inmobiliaria_rut}', function($app) {
$app->get('/cuentas[/]', [Inmobiliarias::class, 'cuentas']);
$app->get('/proyectos[/]', [Inmobiliarias::class, 'proyectos']);
});

View File

@ -3,5 +3,6 @@ use Incoviba\Controller\API\Money;
$app->group('/money', function($app) {
$app->post('/ipc[/]', [Money::class, 'ipc']);
$app->post('/uf[/]', [Money::class, 'uf']);
$app->post('[/]', [Money::class, 'get']);
});

View File

@ -17,4 +17,7 @@ $app->group('/proyecto/{proyecto_id}', function($app) {
$app->get('/disponibles[/]', [Proyectos::class, 'disponibles']);
$app->get('[/]', [Proyectos::class, 'unidades']);
});
$app->group('/terreno', function($app) {
$app->post('/edit[/]', [Proyectos::class, 'terreno']);
});
});

View File

@ -1,4 +1,12 @@
<?php
use Incoviba\Controller\Search;
use Incoviba\Controller\API\Search;
$app->post('/search', [Search::class, 'query']);
$app->group('/search', function($app) {
$app->group('/ventas', function($app) {
$app->post('/unidades', [Search::class, 'unidades']);
$app->get('/unidad/{unidad_id}', [Search::class, 'unidad']);
$app->post('[/]', [Search::class, 'ventas']);
});
$app->get('/venta/{venta_id}', [Search::class, 'venta']);
$app->post('[/]', [Search::class, 'query']);
});

View File

@ -19,10 +19,26 @@ $app->group('/ventas', function($app) {
$app->group('/escrituras', function($app) {
$app->post('/estados[/]', [Ventas::class, 'escrituras']);
});
$app->group('/by', function($app) {
$app->get('/unidad/{unidad_id}', [Ventas::class, 'unidad']);
});
$app->post('/get[/]', [Ventas::class, 'getMany']);
$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('/unidades[/]', [Ventas::class, 'unidades']);
$app->get('/comentarios[/]', [Ventas::class, 'comentarios']);
$app->group('/escritura', function($app) {
$app->post('/add[/]', [Ventas\Escrituras::class, 'add']);
});
$app->group('/credito', function($app) {
$app->post('[/]', [Ventas\Creditos::class, 'edit']);
});
$app->post('/escriturar[/]', [Ventas::class, 'escriturar']);
$app->group('/desistir', function($app) {
$app->get('/eliminar[/]', [Ventas::class, 'insistir']);
$app->post('[/]', [Ventas::class, 'desistir']);
});
$app->post('[/]', [Ventas::class, 'edit']);
$app->get('[/]', [Ventas::class, 'get']);
});

View File

@ -0,0 +1,6 @@
<?php
use Incoviba\Controller\API\Ventas\Escrituras;
$app->group('/escritura/{venta_id}', function($app) {
$app->post('/edit[/]', [Escrituras::class, 'edit']);
});

View File

@ -1,5 +1,5 @@
<?php
use Incoviba\Controller\Ventas\Pagos;
use Incoviba\Controller\API\Ventas\Pagos;
$app->group('/pagos', function($app) {
$app->get('/pendientes', [Pagos::class, 'para_pendientes']);
@ -7,6 +7,9 @@ $app->group('/pagos', function($app) {
$app->get('/rebotes', [Pagos::class, 'rebotes']);
});
$app->group('/pago/{pago_id:[0-9]+}', function($app) {
$app->put('/depositar[/]', [Pagos::class, 'depositar']);
$app->put('/abonar[/]', [Pagos::class, 'abonar']);
$app->post('/depositar[/]', [Pagos::class, 'depositar']);
$app->post('/abonar[/]', [Pagos::class, 'abonar']);
$app->post('/devolver[/]', [Pagos::class, 'devolver']);
$app->get('/anular[/]', [Pagos::class, 'anular']);
$app->post('[/]', [Pagos::class, 'edit']);
});

View File

@ -0,0 +1,6 @@
<?php
use Incoviba\Controller\API\Ventas\Pies;
$app->group('/pie/{pie_id}', function($app) {
$app->post('/edit[/]', [Pies::class, 'edit']);
});

View File

@ -0,0 +1,10 @@
<?php
$app->group('/propiedades', function($app) {
$files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'propiedades']));
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
include_once $file->getRealPath();
}
});

View File

@ -0,0 +1,10 @@
<?php
use Incoviba\Controller\API\Ventas\PropiedadesUnidades;
$app->group('/unidades', function($app) {
$app->post('/add[/]', [PropiedadesUnidades::class, 'add']);
});
$app->group('/unidad/{pu_id}', function($app) {
$app->post('/edit[/]', [PropiedadesUnidades::class, 'edit']);
$app->delete('[/]', [PropiedadesUnidades::class, 'remove']);
});

View File

@ -4,3 +4,9 @@ use Incoviba\Controller\API\Ventas\Unidades;
$app->group('/unidades', function($app) {
$app->post('/disponibles', [Unidades::class, 'disponibles']);
});
$app->group('/unidad/{unidad_id}', function($app) {
$app->group('/prorrateo', function($app) {
$app->post('[/]', [Unidades::class, 'prorrateo']);
});
$app->get('[/]', [Unidades::class, 'get']);
});

View File

@ -0,0 +1,6 @@
<?php
use Incoviba\Controller\Contabilidad;
$app->group('/cartolas', function($app) {
$app->get('/diaria[/]', [Contabilidad::class, 'diaria']);
});

View File

@ -0,0 +1,7 @@
<?php
use Incoviba\Controller\CentrosCostos;
$app->group('/centros_costos', function($app) {
$app->get('/asignar[/]', [CentrosCostos::class, 'asignar']);
$app->get('[/]', CentrosCostos::class);
});

View File

@ -0,0 +1,6 @@
<?php
use Incoviba\Controller\Contabilidad;
$app->group('/depositos', function($app) {
$app->get('[/]', [Contabilidad::class, 'depositos']);
});

View File

@ -0,0 +1,10 @@
<?php
$app->group('/informes', function($app) {
$files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'informes']));
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
include_once $file->getRealPath();
}
});

View File

@ -0,0 +1,6 @@
<?php
use Incoviba\Controller\Contabilidad;
$app->group('/tesoreria', function($app) {
$app->get('[/[{fecha}[/]]]', [Contabilidad::class, 'tesoreria']);
});

View File

@ -0,0 +1,6 @@
<?php
use Incoviba\Controller\Contabilidad\Informes;
$app->group('/xlsx', function($app) {
$app->get('/tesoreria/{fecha}[/]', [Informes::class, 'tesoreria']);
});

View File

@ -0,0 +1,7 @@
<?php
use Incoviba\Controller\Ventas\Escrituras;
$app->group('/escritura/{venta_id}', function($app) {
$app->get('/informe[/]', [Escrituras::class, 'informe']);
$app->get('[/]', [Escrituras::class, 'show']);
});

View File

@ -4,3 +4,6 @@ use Incoviba\Controller\Ventas\Facturacion;
$app->group('/facturacion', function($app) {
$app->get('[/]', Facturacion::class);
});
$app->group('/factura/{venta_id}', function($app) {
$app->get('[/]', [Facturacion::class, 'show']);
});

View File

@ -0,0 +1,823 @@
@extends('layout.base')
@section('page_content')
<div class="ui container">
<h1 class="ui header">
Cartola Diaria
</h1>
<div class="ui grid">
<div class="right aligned sixteen wide column">
<button class="ui green icon button" id="add_button">
Agregar
<i class="plus icon"></i>
</button>
</div>
</div>
<form class="ui form" id="cartola_form">
<input type="hidden" id="fields" name="fields" value="0" />
</form>
<div class="ui two columns grid">
<div class="column">
<button class="ui icon button" id="process_button">
<i class="file excel icon"></i>
Procesar
</button>
</div>
<div class="right aligned column">
<div class="ui inline active loader" id="loader"></div>
</div>
</div>
<table class="ui table" id="diferencia">
<thead>
<tr>
<th>Sociedad</th>
<th>Banco - Cuenta</th>
<th>Hoy</th>
<th>Último Saldo</th>
<th>Saldo Actual</th>
<th>Diferencia</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<div class="ui fluid container">
<table class="ui table" id="tabla_movimientos">
<thead>
<tr>
<th>Sociedad</th>
<th>Banco - Cuenta</th>
<th>Fecha</th>
<th>Glosa</th>
<th class="right aligned">Cargo</th>
<th class="right aligned">Abono</th>
<th class="right aligned">Saldo</th>
<th>Centro de Costo</th>
<th>Detalle</th>
<th>Orden</th>
</tr>
</thead>
<tbody id="movimientos"></tbody>
</table>
</div>
<div class="ui modal" id="manual_modal">
<div class="content">
<div class="header">
Movimientos |
<span id="modal_inmobiliaria"></span> |
<span id="modal_cuenta"></span> |
<span id="modal_fecha"></span>
</div>
<div class="ui one column grid">
<div class="right aligned column">
<button class="ui green icon button" id="add_manual">
<i class="plus icon"></i>
</button>
</div>
</div>
<form class="ui form" id="modal_form">
<input type="hidden" name="movimientos" value="[1]" />
<div id="modal_movimientos">
<div class="fields" data-movimiento="1">
<div class="field">
<label>Glosa</label>
<input type="text" name="glosa1" />
</div>
<div class="field">
<label>Cargo</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="cargo1" />
</div>
</div>
<div class="field">
<label>Abono</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="abono1" />
</div>
</div>
<div class="field">
<label>Saldo</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="saldo1" />
</div>
</div>
<div class="field"></div>
</div>
</div>
</form>
<div class="actions">
<button class="ui approve button">
Procesar
</button>
</div>
</div>
</div>
@endsection
@include('layout.head.styles.datatables')
@include('layout.body.scripts.datatables')
@push('page_scripts')
<script>
class Cartola {
idx
inmobiliaria = {
rut: 0,
razon: ''
}
cuenta = {
id: 0,
descripcion: ''
}
fecha = ''
bancos = []
movimientos = []
saldo = 0
ayer = 0
constructor(idx) {
this.idx = idx
}
get() {
return {
bancos: () => {
const url = '{{$urls->api}}/inmobiliaria/' + this.inmobiliaria.rut + '/cuentas'
diaria.loader().show()
return fetchAPI(url).then(response => {
diaria.loader().hide()
if (!response) {
this.bancos = []
return
}
return response.json().then(json => {
if (json.cuentas.length === 0) {
this.bancos = []
return
}
this.bancos = json.cuentas.map(cuenta => {
return {
value: cuenta.id,
text: cuenta.banco.nombre + ' - ' + cuenta.cuenta,
name: cuenta.banco.nombre + ' - ' + cuenta.cuenta
}
})
})
})
},
ayer: (fecha) => {
const url = '{{$urls->api}}/contabilidad/cartola/diaria/ayer'
const body = new FormData()
body.set('cuenta_id', this.cuenta.id)
body.set('fecha', fecha.toISOString())
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (json.cartola.length === 0) {
return
}
this.ayer = json.cartola.saldo
})
})
}
}
}
update() {
return {
centro: (idx, centro_id) => {
const id = this.movimientos[idx].id
const url = '{{$urls->api}}/contabilidad/movimiento/' + id + '/detalles'
const body = new FormData()
body.set('centro_id', centro_id)
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
response.json().then(json => {
if (!json.status) {
return
}
const dropdown = $(".dropdown[data-idx='" + idx + "']")
dropdown.dropdown('set selected', json.centro.id, true)
})
})
},
detalle: (idx, detalle) => {
const id = this.movimientos[idx].id
const url = '{{$urls->api}}/contabilidad/movimiento/' + id + '/detalles'
const body = new FormData()
body.set('detalle', detalle)
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
response.json().then(json => {
if (!json.status) {
return
}
const input = $("input[data-idx='" + idx + "']")
input.val(json.detalle)
})
})
}
}
}
draw() {
return {
form: ($form, inmobiliarias, first = false) => {
const $fields = $('<div></div>').addClass('fields cartola').attr('data-cartola', this.idx)
const $inmobiliarias_menu = $('<div></div>').addClass('menu')
inmobiliarias.forEach(inmobiliaria => {
$inmobiliarias_menu.append(
$('<div></div>').addClass('item').attr('data-value', inmobiliaria.rut).html(inmobiliaria.razon)
)
})
const $inmobiliarias_dropdown = $('<div></div>').addClass('ui search selection dropdown').attr('id', 'inmobiliaria' + this.idx).append(
$('<input />').attr('type', 'hidden')//.attr('name', 'inmobiliaria_rut' + this.idx)
).append(
$('<i></i>').addClass('dropdown icon')
).append(
$('<div></div>').addClass('default text').html('Inmobiliaria')
).append($inmobiliarias_menu)
$fields.append(
$('<div></div>').addClass('six wide field').append(
$('<label></label>').attr('for', 'inmobiliaria' + this.idx).html('Sociedad')
).append($inmobiliarias_dropdown)
)
const $cuentas_dropdown = $('<div></div>').addClass('ui search selection dropdown').attr('id', 'cuenta' + this.idx).append(
$('<input />').attr('type', 'hidden').attr('name', 'cuenta_id' + this.idx)
).append(
$('<i></i>').addClass('dropdown icon')
).append(
$('<div></div>').addClass('default text').html('Banco - Cuenta')
).append(
$('<div></div>').addClass('menu')
)
$fields.append(
$('<div></div>').addClass('four wide field').append(
$('<label></label>').html('Banco - Cuenta')
).append($cuentas_dropdown)
)
const $fecha_calendar = $('<div></div>').addClass('ui calendar').attr('id', 'fecha' + this.idx).append(
$('<div></div>').addClass('ui left icon input').append(
$('<i></i>').addClass('calendar icon')
).append(
$('<input />').attr('type', 'text')
)
)
$fields.append(
$('<div></div>').addClass('three wide field').append(
$('<label></label>').attr('for', 'fecha' + this.idx).html('Fecha')
).append($fecha_calendar)
)
$fields.append(
$('<div></div>').addClass('field').append(
$('<label></label>').html('Cartola')
).append(
$('<input />').addClass('ui invisible file input').attr('type', 'file').attr('name', 'file' + this.idx).attr('id', 'file' + this.idx)
).append(
$('<label></label>').addClass('ui icon button').attr('for', 'file' + this.idx).append(
$('<i></i>').addClass('file icon')
).append('Cargar')
)
)
const $manual_checkbox = $('<div></div>').addClass('ui invisible checkbox').append(
$('<input />').attr('type', 'checkbox').attr('name', 'manual' + this.idx).attr('id', 'manual' + this.idx)
).append(
$('<label></label>').addClass('image').attr('for', 'manual' + this.idx).append(
$('<i></i>').addClass('large orange keyboard icon')
)
)
$fields.append($('<div></div>').addClass('field').append(
$('<label></label>').html('Manual')
).append($manual_checkbox))
if (!first) {
$fields.append(
$('<div></div>').addClass('field').append(
$('<label></label>').html('Eliminar')
).append(
$('<button></button>').addClass('ui red icon button').attr('data-cartola', this.idx).append(
$('<i></i>').addClass('remove icon')
).click(event => {
const idx = $(event.currentTarget).data('cartola')
diaria.cartolas().remove(idx)
})
)
)
}
$form.append($fields)
const cdo = JSON.parse(JSON.stringify(calendar_date_options))
cdo['initialDate'] = new Date()
cdo['maxDate'] = cdo['initialDate']
cdo['onChange'] = (date, text, mode) => {
this.fecha = date
}
this.fecha = cdo['initialDate']
$inmobiliarias_dropdown.dropdown({
fireOnInit: true,
onChange: (value, text, $choice) => {
this.inmobiliaria.rut = value
this.inmobiliaria.razon = text
this.get().bancos(value).then(() => {
$cuentas_dropdown.dropdown('change values', this.bancos)
})
},
})
$cuentas_dropdown.dropdown({
fireOnInit: true,
onChange: (value, text, $choice) => {
this.cuenta.id = value
this.cuenta.descripcion = text
}
})
$fecha_calendar.calendar(cdo)
$manual_checkbox.change(event => {
const $element = $(event.currentTarget)
const status = $element.checkbox('is checked')
const $field = $element.parent().parent()
const $file = $field.find('#file' + this.idx).parent()
if (status) {
$file.find('input').attr('type', 'hidden')
$file.hide()
manual.data.inmobiliaria = $inmobiliarias_dropdown.dropdown('get text')
manual.data.cuenta = $cuentas_dropdown.dropdown('get text')
const fecha = $fecha_calendar.calendar('get date')
manual.data.fecha = [fecha.getDate(), (fecha.getMonth()+1).toString().padStart(2, '0'), fecha.getFullYear()].join('-')
manual.data.field = this.idx
manual.$modal.modal('show')
return
}
$file.find('input').attr('type', 'file')
$file.show()
})
},
diferencia: ($tbody, dateFormatter, numberFormatter) => {
$tbody.append(
$('<tr></tr>').append(
$('<td></td>').html(this.inmobiliaria.razon)
).append(
$('<td></td>').html(this.cuenta.descripcion)
).append(
$('<td></td>').html(dateFormatter.format(this.fecha))
).append(
$('<td></td>').html(numberFormatter.format(this.ayer))
).append(
$('<td></td>').html(numberFormatter.format(this.saldo))
).append(
$('<td></td>').html(numberFormatter.format(this.saldo - this.ayer))
)
)
},
cartola: ($tbody, dateFormatter, numberFormatter) => {
this.movimientos.forEach((row, idx) => {
$tbody.append(
$('<tr></tr>').append(
'<td>' + this.inmobiliaria.razon + '</td>' + "\n"
+ '<td>' + this.cuenta.descripcion + '</td>' + "\n"
+ '<td>' + dateFormatter.format(row.fecha) + '</td>' + "\n"
+ '<td>' + row.glosa + '</td>' + "\n"
+ '<td class="right aligned">' + (row.cargo === 0 ? '' : numberFormatter.format(row.cargo)) + '</td>' + "\n"
+ '<td class="right aligned">' + (row.abono === 0 ? '' : numberFormatter.format(row.abono)) + '</td>' + "\n"
+ '<td class="right aligned">' + (row.saldo === 0 ? '' : numberFormatter.format(row.saldo)) + '</td>' + "\n"
).append(
$('<td></td>').append(
this.draw().centroCosto(idx)
)
).append(
$('<td></td>').append(
this.draw().detalle(idx)
)
).append(
$('<td></td>').html(idx + 1)
)
)
})
},
centroCosto: idx => {
const centros = JSON.parse('{!! json_encode($centrosCostos) !!}')
const menu = $('<div></div>').addClass('menu')
centros.forEach(centro => {
menu.append(
'<div class="item" data-value="' + centro.id + '">'
+ centro.id + ' - ' + centro.descripcion
+ '</div>'
)
})
const dropdown = $('<div></div>').addClass('ui search selection dropdown').attr('data-idx', idx).html(
'<input type="hidden" name="centro" />' + "\n" +
'<i class="dropdown icon"></i>' + "\n" +
'<div class="default text">Centro de Costo</div>' + "\n"
).append(menu)
dropdown.dropdown({
onChange: (value, text, $element) => {
const idx = $element.parent().parent().data('idx')
this.update().centro(idx, value)
}
})
if (this.movimientos[idx].centro !== '') {
const cid = centros.findIndex(centro => centro.descripcion === this.movimientos[idx].centro)
dropdown.dropdown('set selected', centros[cid].id, true)
}
return dropdown
},
detalle: idx => {
const detalle = document.createElement('input')
detalle.type = 'text'
detalle.name = 'detalle' + idx
detalle.placeholder = 'Detalle'
detalle.setAttribute('data-idx', idx)
const input = document.createElement('div')
input.className = 'ui input'
input.appendChild(detalle)
if (this.movimientos[idx].detalle !== '') {
detalle.value = this.movimientos[idx].detalle
}
detalle.addEventListener('blur', event => {
const idx = event.currentTarget.dataset['idx']
this.update().detalle(idx, event.currentTarget.value)
})
return $(input)
}
}
}
}
@php
$columns = [
'sociedad',
'cuenta',
'fecha',
'glosa',
'cargo',
'abono',
'saldo',
'centro',
'detalle',
'orden'
];
@endphp
const diaria = {
ids: {},
data: {
inmobiliarias: JSON.parse('{!! json_encode($inmobiliarias) !!}'),
cartolasIdx: [],
cartolas: [],
},
dataTableConfig: {
order: [[{{array_search('orden', $columns)}}, 'asc']],
columnDefs: [
{
targets: [{{implode(',', array_keys(array_filter($columns, function($column) {return in_array($column, ['fecha', 'cargo', 'abono', 'saldo']);})))}}],
width: '{{round((1/(count($columns) + 3 - 1)) * 100,2)}}%'
},
{
targets: [{{implode(',', array_keys(array_filter($columns, function($column) {return in_array($column, ['sociedad', 'cuenta', 'glosa', 'centro', 'detalle']);})))}}],
width: '{{round((1/(count($columns) + 3 - 1)) * 2 * 100, 2)}}%'
},
{
targets: [{{array_search('orden', $columns)}}],
visible: false
}
],
},
loaderStatus: true,
loader() {
return {
show: () => {
if (!this.loaderStatus) {
$(this.ids.loader).show()
this.loaderStatus = true
}
},
hide: () => {
if (this.loaderStatus) {
$(this.ids.loader).hide()
this.loaderStatus = false
}
}
}
},
cartolas() {
return {
add: () => {
let first = false
if (this.data.cartolas.length === 0) {
first = true
}
const idx = this.data.cartolas.reduce((prev, cartola) => Math.max(prev, cartola.idx), 0) + 1
const cartola = new Cartola(idx)
this.data.cartolas.push(cartola)
this.data.cartolasIdx.push(idx)
const form = $(this.ids.form)
cartola.draw().form(form, this.data.inmobiliarias, first)
$(this.ids.fields).attr('value', JSON.stringify(this.data.cartolasIdx))
},
remove: idx => {
if (this.data.cartolas.length === 1) {
return
}
const i = this.data.cartolasIdx.findIndex(value => value === idx)
const cartolaIdx = this.data.cartolas.findIndex(cartola => cartola.idx === idx)
$("div.cartola[data-cartola='" + idx + "']").remove()
this.data.cartolasIdx.splice(i,1)
this.data.cartolas.splice(cartolaIdx,1)
$(this.ids.fields).attr('value', JSON.stringify(this.data.cartolasIdx))
}
}
},
draw() {
return {
empty: () => {
Object.values(this.ids.table).forEach(id => $(id).find('tbody').html(''))
},
diferencia: () => {
const $table = $(this.ids.table.diferencia)
const $tbody = $table.find('tbody')
$tbody.html('')
const dateFormatter = new Intl.DateTimeFormat('es-CL', {
year: 'numeric',
month: 'numeric',
day: 'numeric'
})
const numberFormatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 0, maximumFractionDigits: 0})
this.data.cartolas.forEach(cartola => {
cartola.draw().diferencia($tbody, dateFormatter, numberFormatter)
})
},
cartola: () => {
const $table = $(this.ids.table.base)
$table.DataTable().clear()
$table.DataTable().destroy()
const $tbody = $(this.ids.table.body)
$tbody.html('')
const dateFormatter = new Intl.DateTimeFormat('es-CL', {
year: 'numeric',
month: 'numeric',
day: 'numeric'
})
const numberFormatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 0, maximumFractionDigits: 0})
this.data.cartolas.forEach(cartola => {
cartola.draw().cartola($tbody, dateFormatter, numberFormatter)
})
$table.DataTable(this.dataTableConfig)
},
}
},
parse() {
return {
cartola: event => {
const body = new FormData($(this.ids.form)[0])
this.data.cartolas.forEach(cartola => {
body.set('fecha' + cartola.idx, [cartola.fecha.getFullYear(), cartola.fecha.getMonth()+1, cartola.fecha.getDate()].join('-'))
})
const url = '{{$urls->api}}/contabilidad/cartola/diaria/procesar'
diaria.loader().show()
fetchAPI(url, {method: 'post', body}).then(response => {
diaria.loader().hide()
this.draw().empty()
if (!response) {
return
}
return response.json().then(json => {
if (json.cartolas.length === 0) {
return
}
Object.entries(json.cartolas).forEach(entry => {
const cartolaIdx = this.data.cartolas.findIndex(cartola => cartola.idx === parseInt(entry[0]))
this.data.cartolas[cartolaIdx].movimientos = []
entry[1].movimientos.forEach((row, idx) => {
const fecha = new Date(row.fecha)
fecha.setDate(fecha.getDate() + 1)
this.data.cartolas[cartolaIdx].movimientos[idx] = {
id: row.id,
fecha: fecha,
glosa: row.glosa,
documento: row.documento,
cargo: row.cargo,
abono: row.abono,
saldo: row.saldo,
centro: row.detalles?.centro_costo.descripcion ?? '',
detalle: row.detalles?.detalle ?? ''
}
})
const ayer = new Date(this.data.cartolas[cartolaIdx].fecha.getTime())
ayer.setDate(this.data.cartolas[cartolaIdx].fecha.getDate() - 1)
this.data.cartolas[cartolaIdx].saldo = entry[1].cartola.saldo
this.data.cartolas[cartolaIdx].get().ayer(ayer)
})
this.draw().diferencia()
this.draw().cartola()
})
})
return false
}
}
},
setup(ids) {
this.ids = ids
this.loader().hide()
$(this.ids.form).submit(event => {
event.preventDefault()
return false
})
$(this.ids.buttons.add).click(event => {
this.cartolas().add()
})
$(this.ids.buttons.process).click(this.parse().cartola)
$(this.ids.table.base).DataTable(this.dataTableConfig)
this.cartolas().add()
}
}
const manual = {
ids: {},
$modal: null,
data: {
inmobiliaria: '',
cuenta: '',
fecha: '',
field: 0,
movimientos: [
{idx: 1}
]
},
get movimientosIdx() {
const $movimientosIdx = $(this.ids.form).find("[name='movimientos']")
return JSON.parse($movimientosIdx.val())
},
set movimientosIdx(list) {
const $movimientosIdx = $(this.ids.form).find("[name='movimientos']")
$movimientosIdx.val(JSON.stringify(list))
},
update() {
return {
file: movimientos => {
const $file = $("[name='file" + this.data.field + "']")
$file.val(JSON.stringify(movimientos))
}
}
},
parse() {
return {
movimientos: () => {
const $fields = $(this.ids.movimientos).find('.fields')
const movimientos = []
$fields.each((i, fields) => {
const idx = $(fields).data('movimiento')
const inputs = [
'glosa',
'cargo',
'abono',
'saldo'
]
const data = {}
inputs.forEach(name => {
data[name] = $(fields).find("[name='"+name+idx+"']").val()
if (name !== 'glosa') {
data[name] = parseInt(data[name]) || 0
}
})
movimientos.push(data)
})
this.update().file(movimientos)
}
}
},
movimiento() {
return {
add: () => {
const idx = this.data.movimientos.reduce((prev, movimiento) => Math.max(prev, movimiento.idx), 0) + 1
const movimiento = {
idx
}
this.data.movimientos.push(movimiento)
const movimientosidx = this.movimientosIdx
movimientosidx.push(idx)
this.movimientosIdx = movimientosidx
this.draw().movimiento(idx)
},
remove: idx => {
const movimientosIdx = this.movimientosIdx
const i = movimientosIdx.findIndex(n => n === idx)
movimientosIdx.splice(i, 1)
const movimientoIdx = this.data.movimientos.findIndex(movimiento => movimiento.idx === idx)
this.data.movimientos.splice(movimientoIdx, 1)
$(this.ids.movimientos).find("[data-idx='"+idx+"']").parent().parent().remove()
this.movimientosIdx = movimientosIdx
}
}
},
draw() {
return {
movimiento: idx => {
$(this.ids.movimientos).append(
$('<div></div>').addClass('fields').attr('data-movimiento', idx).append(
'<div class="field">' + "\n"
+ '<label>Glosa</label>' + "\n"
+ '<input type="text" name="glosa' + idx + '" />' + "\n"
+ '</div>' + "\n" +
'<div class="field">' + "\n"
+ '<label>Cargo</label>' + "\n"
+ '<div class="ui left labeled input">' + "\n"
+ '<div class="ui basic label">$</div>' + "\n"
+ '<input type="text" name="cargo' + idx + '" />' + "\n"
+ '</div>' + "\n"
+ '</div>' + "\n" +
'<div class="field">' + "\n"
+ '<label>Abono</label>' + "\n"
+ '<div class="ui left labeled input">' + "\n"
+ '<div class="ui basic label">$</div>' + "\n"
+ '<input type="text" name="abono' + idx + '" />' + "\n"
+ '</div>' + "\n"
+ '</div>' + "\n" +
'<div class="field">' + "\n"
+ '<label>Saldo</label>' + "\n"
+ '<div class="ui left labeled input">' + "\n"
+ '<div class="ui basic label">$</div>' + "\n"
+ '<input type="text" name="saldo' + idx + '" />' + "\n"
+ '</div>' + "\n"
+ '</div>'
).append(
$('<div></div>').addClass('field').append(
$('<label></label>').html('Eliminar')
).append(
$('<button></button>').addClass('ui red icon button').attr('type', 'button').attr('data-idx', idx).append(
$('<i></i>').addClass('remove icon')
).click(event => {
const idx = $(event.currentTarget).data('idx')
manual.movimiento().remove(idx)
})
)
)
)
}
}
},
setup(ids) {
this.ids = ids
$(this.ids.modal).modal({
onShow: () => {
$(this.ids.inmobiliaria).html(this.data.inmobiliaria)
$(this.ids.cuenta).html(this.data.cuenta)
$(this.ids.fecha).html(this.data.fecha)
this.movimientos = []
$(this.ids.form).trigger('reset')
},
onApprove: $element => {
this.parse().movimientos()
},
onHide: $element => {
this.parse().movimientos()
}
})
this.$modal = $(this.ids.modal)
$(this.ids.button).click(event => {
this.movimiento().add()
})
$(this.ids.form).submit(event => {
event.preventDefault()
this.$modal.modal('hide')
return false
})
}
}
$(document).ready(() => {
diaria.setup({
table: {
base: '#tabla_movimientos',
body: '#movimientos',
diferencia: '#diferencia'
},
form: '#cartola_form',
fields: '#fields',
buttons: {
add: '#add_button',
process: '#process_button'
},
loader: '#loader'
})
manual.setup({
modal: '#manual_modal',
button: '#add_manual',
inmobiliaria: '#modal_inmobiliaria',
cuenta: '#modal_cuenta',
fecha: '#modal_fecha',
form: '#modal_form',
movimientos: '#modal_movimientos'
})
})
</script>
@endpush

View File

@ -0,0 +1,330 @@
@extends('layout.base')
@section('page_content')
<div class="ui container">
<h1 class="ui header">
Centros de Costos
</h1>
{{--<div class="ui top attached right aligned basic segment">
<button class="ui tiny green icon button" id="add_button">
Agregar
<i class="plus icon"></i>
</button>
</div>--}}
<table class="ui table" id="centros_costos">
<thead>
<tr>
<th>Tipo de Centro</th>
<th>Categoría</th>
<th>Tipo de Cuenta</th>
<th>Cuenta Contable</th>
<th>Centro de Costo</th>
<th>Descripción</th>
{{--<th>
</th>--}}
</tr>
</thead>
<tbody>
@foreach ($centrosCostos as $centroCosto)
<tr data-id="{{$centroCosto->id}}">
<td data-id="{{$centroCosto->tipoCentro->id}}">{{$centroCosto->tipoCentro->descripcion}}</td>
<td data-id="{{$centroCosto->categoria->id}}">{{$centroCosto->categoria->descripcion}}</td>
<td data-id="{{$centroCosto->tipoCuenta?->id}}">{{$centroCosto->tipoCuenta?->descripcion}}</td>
<td>{{$centroCosto->cuentaContable}}</td>
<td>{{$centroCosto->id}}</td>
<td>{{$centroCosto->descripcion}}</td>
{{--<td>
<div class="ui mini buttons">
<button class="ui icon button edit_button" data-id="{{$centroCosto->id}}">
<i class="edit icon"></i>
</button>
<button class="ui red icon button remove_button" data-id="{{$centroCosto->id}}">
<i class="remove icon"></i>
</button>
</div>
</td>--}}
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="ui modal" id="modal_add">
<div class="content">
<form class="ui form" id="add_form">
<div class="fields">
<div class="three wide field">
<label for="tipo_centro">Tipo de Centro</label>
<div class="ui selection search dropdown" id="tipo_centro">
<input type="hidden" name="tipo_centro_id" />
<i class="dropdown icon"></i>
<div class="default text">Tipo</div>
<div class="menu">
@foreach ($tiposCentros as $tipoCentro)
<div class="item" data-value="{{$tipoCentro->id}}">{{$tipoCentro->descripcion}}</div>
@endforeach
</div>
</div>
</div>
<div class="three wide field">
<label for="tipo_cuenta">Tipo de Cuenta</label>
<div class="ui selection search dropdown" id="tipo_cuenta">
<input type="hidden" name="tipo_cuenta_id" />
<i class="dropdown icon"></i>
<div class="default text">Tipo de Cuenta</div>
<div class="menu">
<div class="item" data-value="">---</div>
@foreach ($tiposCuentas as $tipoCuenta)
<div class="item" data-value="{{$tipoCuenta->id}}">{{$tipoCuenta->descripcion}}</div>
@endforeach
</div>
</div>
</div>
</div>
<div class="five wide field">
<label for="categoria">Categoría</label>
<div class="ui selection search dropdown" id="categoria">
<input type="hidden" name="categoria_id" />
<i class="dropdown icon"></i>
<div class="default text">Categoría</div>
<div class="menu">
@foreach ($categorias as $categoria)
<div class="item" data-value="{{$categoria->id}}">{{$categoria->descripcion}}</div>
@endforeach
</div>
</div>
</div>
<div class="three wide field">
<label for="cuenta_contable">Cuenta Contable</label>
<input type="text" name="cuenta_contable" id="cuenta_contable" />
</div>
<div class="two wide field">
<label for="identificador">Centro de Costo</label>
<input type="number" name="id" id="identificador" maxlength="3" />
</div>
<div class="field">
<label for="descripcion">Descripción</label>
<textarea id="descripcion" name="descripcion" class="ui textarea" rows="1" cols="10"></textarea>
</div>
</form>
</div>
<div class="actions">
<button class="ui positive icon button">
<i class="plus icon"></i>
Agregar
</button>
</div>
</div>
<div class="ui modal" id="modal_edit">
<div class="header">
Centro de Costo <span id="id"></span>
</div>
<div class="content">
<form class="ui form" id="edit_form">
<input type="hidden" name="id" id="identificador" />
<div class="fields">
<div class="three wide field">
<label for="tipo_centro">Tipo de Centro</label>
<div class="ui selection search dropdown" id="tipo_centro">
<input type="hidden" name="tipo_centro_id" />
<i class="dropdown icon"></i>
<div class="default text">Tipo</div>
<div class="menu">
@foreach ($tiposCentros as $tipoCentro)
<div class="item" data-value="{{$tipoCentro->id}}">{{$tipoCentro->descripcion}}</div>
@endforeach
</div>
</div>
</div>
<div class="three wide field">
<label for="tipo_cuenta">Tipo de Cuenta</label>
<div class="ui selection search dropdown" id="tipo_cuenta">
<input type="hidden" name="tipo_cuenta_id" />
<i class="dropdown icon"></i>
<div class="default text">Tipo de Cuenta</div>
<div class="menu">
<div class="item" data-value="">---</div>
@foreach ($tiposCuentas as $tipoCuenta)
<div class="item" data-value="{{$tipoCuenta->id}}">{{$tipoCuenta->descripcion}}</div>
@endforeach
</div>
</div>
</div>
</div>
<div class="five wide field">
<label for="categoria">Categoría</label>
<div class="ui selection search dropdown" id="categoria">
<input type="hidden" name="categoria_id" />
<i class="dropdown icon"></i>
<div class="default text">Categoría</div>
<div class="menu">
@foreach ($categorias as $categoria)
<div class="item" data-value="{{$categoria->id}}">{{$categoria->descripcion}}</div>
@endforeach
</div>
</div>
</div>
<div class="three wide field">
<label for="cuenta_contable">Cuenta Contable</label>
<input type="text" name="cuenta_contable" id="cuenta_contable" />
</div>
<div class="field">
<label for="descripcion">Descripción</label>
<textarea id="descripcion" name="descripcion" class="ui textarea" rows="1" cols="10"></textarea>
</div>
</form>
</div>
<div class="actions">
<button class="ui positive icon button">
<i class="plus icon"></i>
Editar
</button>
</div>
</div>
@endsection
@include('layout.head.styles.datatables')
@include('layout.body.scripts.datatables')
@push('page_scripts')
<script>
const centros = {
ids: {
table: '',
modals: {
add: '',
edit: ''
},
buttons: {
add: '',
edit: '',
remove: ''
},
forms: {
add: '',
edit: ''
}
},
setup: function({ids}) {
this.ids = ids
Object.keys(this.ids.modals).forEach(name => {
$(this.ids.modals[name]).modal({
onApprove: ($element) => {
this.actions()[name]()
},
onHidden: (modal) => {
document.getElementById(this.ids.forms[name]).reset()
}
})
$(this.ids.modals[name]).find('.dropdown').each((idx, item) => {
$(item).dropdown()
})
})
Object.keys(this.ids.buttons).forEach(name => {
if (name === 'remove') {
return
}
$(this.ids.buttons[name]).click(event => {
if (name === 'edit') {
const id = $(event.currentTarget).data('id')
const row = $("tr[data-id='" + id + "']")
const data = {
id,
tipo_centro_id: row.find(':nth-child(1)').data('id'),
categoria_id: row.find(':nth-child(2)').data('id'),
tipo_cuenta_id: row.find(':nth-child(3)').data('id'),
cuenta_contable: row.find(':nth-child(4)').html(),
descripcion: row.find(':nth-child(6)').html()
}
$(this.ids.modals[name]).find('#id').html(id)
const form = $('#' + this.ids.forms[name])
form.find("[name='id']").val(data.id)
form.find('#tipo_centro').dropdown('set selected', data.tipo_centro_id)
form.find('#categoria').dropdown('set selected', data.categoria_id)
form.find('#tipo_cuenta').dropdown('set selected', data.tipo_cuenta_id)
form.find('#cuenta_contable').val(data.cuenta_contable)
form.find('#descripcion').val(data.descripcion)
}
$(this.ids.modals[name]).modal('show')
})
})
$(this.ids.buttons.remove).click(event => {
const id = $(event.currentTarget).data('id')
this.actions().remove(id)
})
$(this.ids.table).dataTable({
order: [
[0, 'desc'],
[2, 'asc'],
[1, 'asc'],
[4, 'asc']
]
})
},
actions: function() {
return {
add: () => {
const body = new FormData(document.getElementById(this.ids.forms.add))
const url = '{{$urls->api}}/contabilidad/centros_costos/add'
fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
response.json().then(json => {
if (json.added) {
window.location.reload()
}
})
})
},
edit: () => {
const body = new FormData(document.getElementById(this.ids.forms.edit))
const url = '{{$urls->api}}/contabilidad/centro_costo/' + body.get('id') + '/edit'
fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
response.json().then(json => {
if (json.edited) {
window.location.reload()
}
})
})
},
remove: id => {
const url = '{{$urls->api}}/contabilidad/centro_costo/' + id
fetchAPI(url, {method: 'delete'}).then(response => {
if (!response) {
return
}
response.json().then(json => {
if (json.removed) {
window.location.reload()
}
})
})
}
}
}
}
$(document).ready(() => {
centros.setup({ids: {
table: '#centros_costos',
modals: {
add: '#modal_add',
edit: '#modal_edit'
},
buttons: {
add: '#add_button',
edit: '.edit_button',
remove: '.remove_button'
},
forms: {
add: 'add_form',
edit: 'edit_form'
}
}
})
})
</script>
@endpush

View File

@ -0,0 +1,399 @@
@extends('layout.base')
@section('page_content')
<div class="ui container">
<h1 class="ui header">Asignar Centros de Costos</h1>
<form class="ui form" id="asignar_form">
<div class="ui grid">
<div class="fourteen wide column">
<div class="fields">
<div class="five wide field">
<label>Inmobiliaria</label>
<div class="ui selection search dropdown" id="inmobiliaria">
<input type="hidden" name="inmobiliaria"/>
<i class="dropdown icon"></i>
<div class="default text">Inmobiliaria</div>
<div class="menu">
@foreach ($inmobiliarias as $inmobiliaria)
<div class="item" data-value="{{$inmobiliaria->rut}}">{{$inmobiliaria->razon}}</div>
@endforeach
</div>
</div>
</div>
<div class="two wide field">
<label>Banco</label>
<div class="ui selection search dropdown" id="banco">
<input type="hidden" name="banco"/>
<i class="dropdown icon"></i>
<div class="default text">Banco</div>
<div class="menu"></div>
</div>
</div>
<div class="field">
<label>Mes</label>
<div class="ui calendar" id="mes">
<div class="ui icon input">
<i class="calendar icon"></i>
<input type="text" name="mes"/>
</div>
</div>
</div>
<div class="field">
<label for="file">Cartola</label>
<input type="file" name="file" id="file" class="ui invisible file input" />
<label for="file" class="ui icon button">
<i class="file icon"></i>
Cargar
</label>
</div>
</div>
</div>
<div class="two wide middle aligned column">
<button class="ui icon button">
Procesar
<i class="sync icon"></i>
</button>
</div>
</div>
</form>
<div class="ui two columns grid">
<div class="column">
<button class="ui icon button" id="export_button">
<i class="file excel icon"></i>
Exportar
</button>
</div>
<div class="right aligned column">
<div class="ui inline active loader" id="loader"></div>
</div>
</div>
</div>
<div class="ui fluid container">
<table class="ui table" id="tabla_movimientos">
<thead>
<tr>
<th>Fecha</th>
<th>Glosa</th>
<th>Documento</th>
<th class="right aligned">Cargo</th>
<th class="right aligned">Abono</th>
<th>Centro de Costo</th>
<th>Detalle</th>
<th>Orden</th>
</tr>
</thead>
<tbody id="movimientos"></tbody>
</table>
</div>
@endsection
@include('layout.head.styles.datatables')
@include('layout.body.scripts.datatables')
@push('page_scripts')
<script>
const cartola = {
ids: {
table: {
base: '',
body: ''
},
form: {
base: '',
inmobiliaria: '',
banco: '',
mes: '',
},
button: '',
loader: '',
},
data: {
inmobiliaria: {
rut: 0,
razon: ''
},
banco: {
id: 0,
nombre: ''
},
mes: '',
movimientos: [],
centrosCostos: {
ingresos: JSON.parse('{!! json_encode(array_values(array_map(function(\Incoviba\Model\CentroCosto $centroCosto) {
return [
'id' => $centroCosto->id,
'descripcion' => $centroCosto->descripcion
];
}, array_filter($centrosCostos, function(\Incoviba\Model\CentroCosto $centroCosto) {
return $centroCosto->tipoCentro->descripcion === 'Ingreso';
})))) !!}'),
egresos: JSON.parse('{!! json_encode(array_values(array_map(function(\Incoviba\Model\CentroCosto $centroCosto) {
return [
'id' => $centroCosto->id,
'descripcion' => $centroCosto->descripcion
];
}, array_filter($centrosCostos, function(\Incoviba\Model\CentroCosto $centroCosto) {
return $centroCosto->tipoCentro->descripcion === 'Egreso';
})))) !!}'),
}
},
dataTableConfig: {
pageLength: 100,
order: [[7, 'asc']],
columnDefs: [
{
targets: [0, 2, 3, 4],
width: '10%'
},
{
targets: [1],
width: '20%'
},
{
targets: [7],
visible: false
}
],
},
get() {
return {
bancos: inmobiliaria_rut => {
const url = '{{$urls->api}}/inmobiliaria/' + inmobiliaria_rut + '/cuentas'
$(this.ids.loader).show()
return fetchAPI(url).then(response => {
$(this.ids.loader).hide()
if (!response) {
return
}
return response.json().then(json => {
if (json.cuentas.length === 0) {
return
}
$(this.ids.form.banco).dropdown('change values', json.cuentas.map(cuenta => {
return {value: cuenta.banco.id, text: cuenta.banco.nombre, name: cuenta.banco.nombre}
})).dropdown('refresh')
})
})
},
firstDate: inmobiliaria_rut => {
const url = '{{$urls->api}}/inmobiliaria/' + inmobiliaria_rut + '/proyectos'
$(this.ids.loader).show()
return fetchAPI(url).then(response => {
$(this.ids.loader).hide()
if (!response) {
return
}
return response.json().then(json => {
if (json.proyectos.length === 0) {
return
}
const min = json.proyectos.reduce((min, proyecto) => {
const date = new Date(proyecto.current_estado.fecha.date)
if (min > date.getTime()) {
return date.getTime()
}
return min
}, (new Date()).getTime())
$(this.ids.form.mes).calendar('set minDate', new Date(min))
})
})
}
}
},
parse() {
return {
cartola: event => {
event.preventDefault()
const body = new FormData(document.getElementById('asignar_form'))
body.set('mes', $('#mes').calendar('get date').toISOString())
const url = '{{$urls->api}}/contabilidad/cartolas/procesar'
$(this.ids.loader).show()
fetchAPI(url, {method: 'post', body}).then(response => {
$(this.ids.loader).hide()
if (!response) {
return
}
return response.json().then(json => {
if (json.movimientos.length === 0) {
return
}
this.data.movimientos = []
json.movimientos.forEach((row, idx) => {
const fecha = new Date(row.fecha)
fecha.setDate(fecha.getDate() + 1)
this.data.movimientos[idx] = {
fecha: fecha,
glosa: row.glosa,
documento: row.documento,
cargo: row.cargo,
abono: row.abono,
}
})
this.draw().cartola()
})
})
return false
}
}
},
export() {
return {
cartola: event => {
const url = '{{$urls->api}}/contabilidad/cartola/exportar'
const body = new FormData()
body.set('inmobiliaria', $(this.ids.form.inmobiliaria).dropdown('get value'))
body.set('banco', $(this.ids.form.banco).dropdown('get value'))
body.set('mes', $(this.ids.form.mes).calendar('get date').toISOString())
const movimientos = this.data.movimientos.map((movimiento, idx) => {
const temp = structuredClone(movimiento)
temp.fecha = movimiento.fecha.toISOString()
let centro = $(".centro[data-index='" + (idx+1) + "']").dropdown('get value')
if (centro.length === 0) {
centro = ''
}
temp.centro_costo = centro
let detalle = $("[name='detalle" + (idx+1) + "']").val()
if (typeof detalle === 'undefined') {
detalle = ''
}
temp.detalle = detalle
return temp
})
body.set('movimientos', JSON.stringify(movimientos))
$(this.ids.loader).show()
fetchAPI(url, {method: 'post', body}).then(response => {
$(this.ids.loader).hide()
if (!response) {
return
}
response.json().then(json => {
if (json.filename === '') {
return
}
const anchor = document.createElement('a')
anchor.href = ['/uploads/', json.filename].join('/')
anchor.download = 'Cartola ' + this.data.banco.nombre + ' - ' + this.data.inmobiliaria.razon + ' - ' + this.data.mes + '.xlsx'
document.body.appendChild(anchor)
anchor.click()
anchor.remove()
})
})
}
}
},
draw() {
return {
cartola: () => {
const table = $(this.ids.table.base)
table.DataTable().clear()
table.DataTable().destroy()
const tbody = $(this.ids.table.body)
tbody.html('')
const dateFormatter = new Intl.DateTimeFormat('es-CL', {
year: 'numeric',
month: 'numeric',
day: 'numeric'
})
const numberFormatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 0, maximumFractionDigits: 0})
this.data.movimientos.forEach((row, idx) => {
tbody.append(
$('<tr></tr>').append(
$('<td></td>').html(dateFormatter.format(row.fecha))
).append(
$('<td></td>').html(row.glosa)
).append(
$('<td></td>').html(row.documento)
).append(
$('<td></td>').addClass('right aligned').html(row.cargo === 0 ? '' : numberFormatter.format(row.cargo))
).append(
$('<td></td>').addClass('right aligned').html(row.abono === 0 ? '' : numberFormatter.format(row.abono))
).append(
$('<td></td>').append(this.draw().centrosDropdown(idx + 1, row.cargo === 0))
).append(
$('<td></td>').append(
$('<div></div>').addClass('ui fluid input').append(
$('<input />').attr('type', 'text').attr('name', 'detalle' + (idx + 1))
)
)
).append(
$('<td></td>').html(idx + 1)
)
)
})
table.DataTable(this.dataTableConfig)
},
centrosDropdown: (idx, ingreso=true) => {
const menu = $('<div></div>').addClass('menu')
let centros = this.data.centrosCostos.ingresos
if (!ingreso) {
centros = this.data.centrosCostos.egresos
}
centros.forEach(centro => {
menu.append(
$('<div></div>').addClass('item').attr('data-value', centro.id).html(centro.id + ' - ' + centro.descripcion)
)
})
return $('<div></div>').addClass('ui selection search dropdown centro').attr('data-index', idx).css('width', '80%').append(
$('<input />').attr('type', 'hidden').attr('name', 'centro' + idx)
).append(
$('<i></i>').addClass('dropdown icon')
).append(
$('<div></div>').addClass('default text').html('Centro de Costos')
).append(menu).dropdown()
}
}
},
setup({ids}) {
this.ids = ids
$(this.ids.form.inmobiliaria).dropdown({
fireOnInit: true,
onChange: (value, text, $choice) => {
this.data.inmobiliaria.rut = value
this.data.inmobiliaria.razon = text
this.get().bancos(value)
this.get().firstDate(value)
},
})
$(this.ids.form.banco).dropdown({
fireOnInit: true,
onChange: (value, text, $choice) => {
this.data.banco.id = value
this.data.banco.nombre = text
}
})
$(this.ids.loader).hide()
calendar_date_options['type'] = 'month'
const lastMonth = new Date()
lastMonth.setDate(0)
calendar_date_options['maxDate'] = lastMonth
calendar_date_options['onChange'] = (date, text, mode) => {
this.data.mes = text
}
$(this.ids.form.mes).calendar(calendar_date_options)
$(this.ids.form.base).submit(this.parse().cartola)
$(this.ids.table.base).DataTable(this.dataTableConfig)
$(this.ids.button).click(this.export().cartola)
}
}
$(document).ready(() => {
cartola.setup({
ids: {
table: {
base: '#tabla_movimientos',
body: '#movimientos'
},
form: {
base: '#asignar_form',
inmobiliaria: '#inmobiliaria',
banco: '#banco',
mes: '#mes',
},
button: '#export_button',
loader: '#loader'
}
})
})
</script>
@endpush

View File

@ -0,0 +1,263 @@
@extends('layout.base')
@section('page_content')
<div class="ui container">
<h1 class="ui header">Depósitos a Plazo</h1>
</div>
<div class="ui stackable grid">
<div class="two wide column"></div>
<div class="twelve wide column">
<table class="ui table" id="depositos">
<thead>
<tr>
<th>Inmobiliaria</th>
<th>Banco</th>
<th> Depósito</th>
<th>Capital</th>
<th>Inicio</th>
<th>Plazo</th>
<th>Vencimiento</th>
<th>Vencimiento ISO</th>
<th>Monto al Vencimiento</th>
<th>Tasa</th>
<th>
<button class="ui green icon button" id="add_button">
<i class="plus icon"></i>
</button>
</th>
</tr>
</thead>
<tbody>
@foreach ($activos as $deposito)
<tr>
<td>{{$deposito->cuenta->inmobiliaria->razon}}</td>
<td>{{$deposito->cuenta->banco->nombre}}</td>
<td>{{$deposito->id}}</td>
<td>{{$format->pesos($deposito->capital)}}</td>
<td>{{$deposito->inicio->format('d-m-Y')}}</td>
<td>{{$deposito->plazo()}}</td>
<td>{{$deposito->termino->format('d-m-Y')}}</td>
<td>{{$deposito->termino->format('Y-m-d')}}</td>
<td>{{$format->pesos($deposito->futuro)}}</td>
<td>{{$format->percent($deposito->tasa() * 100, 4)}}</td>
<td>
<button class="ui red icon button remove_button" data-deposito="{{$deposito->id}}">
<i class="remove icon"></i>
</button>
</td>
</tr>
@endforeach
@foreach ($vencidos as $deposito)
<tr class="yellow">
<td>{{$deposito->cuenta->inmobiliaria->razon}}</td>
<td>{{$deposito->cuenta->banco->nombre}}</td>
<td>{{$deposito->id}}</td>
<td>{{$format->pesos($deposito->capital)}}</td>
<td>{{$deposito->inicio->format('d-m-Y')}}</td>
<td>{{$deposito->plazo()}}</td>
<td>{{$deposito->termino->format('d-m-Y')}}</td>
<td>{{$deposito->termino->format('Y-m-d')}}</td>
<td>{{$format->pesos($deposito->futuro)}}</td>
<td>{{$format->percent($deposito->tasa() * 100, 4)}}</td>
<td>
<button class="ui red icon button remove_button" data-deposito="{{$deposito->id}}">
<i class="remove icon"></i>
</button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
<div class="ui modal" id="add_modal">
<div class="content">
<form class="ui form" id="add_form">
<div class="two fields">
<div class="field">
<label for="inmobiliaria">Inmobiliaria</label>
<div class="ui search selection dropdown" id="inmobiliaria">
<input type="hidden" name="inmobiliaria_rut" />
<i class="dropdown icon"></i>
<div class="default text">Inmobiliaria</div>
<div class="menu">
@foreach ($inmobiliarias as $inmobiliaria)
<div class="item" data-value="{{$inmobiliaria->rut}}">{{$inmobiliaria->razon}}</div>
@endforeach
</div>
</div>
</div>
<div class="field">
<label for="banco">Banco</label>
<div class="ui search selection dropdown" id="banco">
<input type="hidden" name="banco_id" />
<i class="dropdown icon"></i>
<div class="default text">Banco</div>
<div class="menu"></div>
</div>
</div>
</div>
<div class="three wide field">
<label for="identificador"> Depósito</label>
<input type="text" id="identificador" name="id" />
</div>
<div class="three fields">
<div class="field">
<label for="capital">Capital</label>
<input type="number" id="capital" name="capital" />
</div>
<div class="field">
<label for="futuro">Monto al Vencimiento</label>
<input type="number" id="futuro" name="futuro" />
</div>
</div>
<div class="two fields">
<div class="field">
<label for="inicio">Inicio</label>
<div class="ui calendar" id="inicio">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="inicio" />
</div>
</div>
</div>
<div class="field">
<label for="termino">Vencimiento</label>
<div class="ui calendar" id="termino">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="termino" />
</div>
</div>
</div>
</div>
</form>
</div>
<div class="actions">
<button class="ui approve button">Agregar</button>
</div>
</div>
@endsection
@include('layout.head.styles.datatables')
@include('layout.body.scripts.datatables')
@push('page_scripts')
<script>
const depositos = {
ids: {},
data: {
inmobiliaria: {
rut: 0,
razon: ''
},
banco: {
id: 0,
nombre: ''
}
},
get() {
return {
bancos: inmobiliaria_rut => {
const url = '{{$urls->api}}/inmobiliaria/' + inmobiliaria_rut + '/cuentas'
return fetchAPI(url).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (json.cuentas.length === 0) {
return
}
$(this.ids.forms.add.bancos).dropdown('change values', json.cuentas.map(cuenta => {
return {value: cuenta.banco.id, text: cuenta.banco.nombre, name: cuenta.banco.nombre}
})).dropdown('refresh')
})
})
},
}
},
add() {
return {
deposito: form => {
const url = '{{$urls->api}}/contabilidad/depositos/add'
const body = new FormData(form)
const inicio = $(this.ids.forms.add.inicio).calendar('get date')
const termino = $(this.ids.forms.add.termino).calendar('get date')
body.set('inicio', [inicio.getFullYear(), inicio.getMonth()+1, inicio.getDate()].join('-'))
body.set('termino', [termino.getFullYear(), termino.getMonth()+1, termino.getDate()].join('-'))
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (json.status) {
window.location.reload()
}
})
})
}
}
},
setup(ids) {
this.ids = ids
$(this.ids.buttons.add).click(event => {
$(this.ids.modals.add).modal('show')
})
$(this.ids.modals.add).modal({
onApprove: $element => {
$(this.ids.forms.add.base).submit()
}
})
$(this.ids.forms.add.base).submit(event => {
event.preventDefault()
this.add().deposito(event.currentTarget)
return false
})
$(this.ids.forms.add.inmobiliarias).dropdown({
fireOnInit: true,
onChange: (value, text, $choice) => {
this.data.inmobiliaria.rut = value
this.data.inmobiliaria.razon = text
this.get().bancos(value)
}
})
$(this.ids.forms.add.banco).dropdown({
fireOnInit: true,
onChange: (value, text, $choice) => {
this.data.banco.id = value
this.data.banco.nombre = text
}
})
$(this.ids.forms.add.inicio).calendar(calendar_date_options)
$(this.ids.forms.add.termino).calendar(calendar_date_options)
$(this.ids.table).dataTable({
columnDefs: [{target: 7, visible: false, searchable: false}],
order: [[7, 'desc'], [0, 'asc']]
})
}
}
$(document).ready(() => {
depositos.setup({
table: '#depositos',
buttons: {
add: '#add_button'
},
modals: {
add: '#add_modal'
},
forms: {
add: {
base: '#add_form',
inmobiliarias: '#inmobiliaria',
bancos: '#banco',
inicio: '#inicio',
termino: '#termino'
}
}
})
})
</script>
@endpush

View File

@ -0,0 +1,156 @@
@extends('layout.base')
@section('page_content')
<div class="ui container">
<h1 class="ui centered header">Informe de Tesorería</h1>
<h4 class="ui centered sub header">{{$fecha->format('d M Y')}}</h4>
<div class="ui grid">
<div class="three wide column">
<a href="/contabilidad/informes/xlsx/tesoreria/{{$fecha->format('Y-m-d')}}" target="_blank" style="color: inherit;">
<div class="ui inverted green center aligned segment">
Descargar en Excel <i class="file excel icon"></i>
</div>
</a>
</div>
</div>
</div>
<div class="ui grid">
<div class="four wide column">
<table class="ui collapsing simple table">
<tr>
<td>Informe anterior</td>
<td>{{$anterior->format('d/m/Y')}}</td>
</tr>
<tr>
<td>Informe actual</td>
<td>{{$fecha->format('d/m/Y')}}</td>
</tr>
</table>
</div>
<div class="column"></div>
<div class="four wide column">
<table class="ui collapsing simple table">
<tr>
<td>Valor UF</td>
<td class="right aligned">{{$format->pesos($UF->get($fecha), 2)}}</td>
</tr>
<tr>
<td>Valor Dólar</td>
<td class="right aligned">{{$format->pesos($USD->get($fecha), 2)}}</td>
</tr>
</table>
</div>
</div>
<table class="ui striped table">
<thead>
<tr>
<th>EMPRESA</th>
<th>Banco</th>
<th>Cuenta</th>
<th class="right aligned">Saldo Anterior</th>
<th class="right aligned">Saldo Actual</th>
<th class="right aligned">Diferencia</th>
<th class="right aligned">FFMM</th>
<th class="right aligned">DAP</th>
<th class="right aligned">Saldo Empresa</th>
<th class="right aligned">Total Cuentas</th>
<th class="right aligned">Total FFMM</th>
<th class="right aligned">Total DAP</th>
<th class="right aligned">Caja Total</th>
</tr>
</thead>
<tbody>
@foreach ($informes['inmobiliarias'] as $inmobiliaria_rut => $informe)
@foreach ($informe->cuentas as $i => $cuenta)
<tr>
@if ($i === 0)
<td rowspan="{{count($informe->cuentas)}}">{{$informe->inmobiliaria->razon}}</td>
@endif
<td>{{$cuenta->banco}}</td>
<td>{{$cuenta->numero}}</td>
<td class="right aligned">{{$format->pesos($cuenta->anterior)}}</td>
<td class="right aligned">{{$format->pesos($cuenta->actual)}}</td>
<td class="right aligned">{{$format->pesos($cuenta->diferencia())}}</td>
<td class="right aligned">{{$format->pesos($cuenta->ffmm)}}</td>
<td class="right aligned">{{$format->pesos($cuenta->deposito)}}</td>
<td class="right aligned">{{$format->pesos($cuenta->saldo())}}</td>
@if ($i === 0)
<td class="right aligned" rowspan="{{count($informe->cuentas)}}">{{$format->pesos($informe->total())}}</td>
<td class="right aligned" rowspan="{{count($informe->cuentas)}}">{{$format->pesos($informe->ffmm())}}</td>
<td class="right aligned" rowspan="{{count($informe->cuentas)}}">{{$format->pesos($informe->deposito())}}</td>
<td class="right aligned" rowspan="{{count($informe->cuentas)}}">{{$format->pesos($informe->caja())}}</td>
@endif
</tr>
@endforeach
@endforeach
</tbody>
<tfoot>
<tr class="bold">
<th colspan="3">TOTAL</th>
<th class="right aligned">{{$format->pesos($informes['totales']->anterior)}}</th>
<th class="right aligned">{{$format->pesos($informes['totales']->actual)}}</th>
<th class="right aligned">{{$format->pesos($informes['totales']->diferencia())}}</th>
<th class="right aligned">{{$format->pesos($informes['totales']->ffmm)}}</th>
<th class="right aligned">{{$format->pesos($informes['totales']->deposito)}}</th>
<th class="right aligned">{{$format->pesos($informes['totales']->saldo())}}</th>
<th class="right aligned">{{$format->pesos($informes['totales']->cuentas())}}</th>
<th class="right aligned">{{$format->pesos($informes['totales']->ffmms())}}</th>
<th class="right aligned">{{$format->pesos($informes['totales']->depositos())}}</th>
<th class="right aligned">{{$format->pesos($informes['totales']->caja())}}</th>
</tr>
</tfoot>
</table>
<table class="ui table">
<thead>
<tr>
<th>EMPRESA</th>
<th class="right aligned">INGRESOS</th>
<th class="right aligned">EGRESOS</th>
<th>FECHA</th>
<th>BANCO</th>
<th>DESCRIPCIÓN</th>
</tr>
</thead>
<tbody>
@foreach ($informes['movimientos'] as $tipo => $movimientos)
@if ($tipo === 'capital dap')
@if (count($movimientos['ingresos']) === 0 and count($movimientos['egresos']) === 0)
@continue
@endif
<tr class="grey">
<td colspan="6">{{strtoupper($tipo)}}</td>
</tr>
@foreach ($movimientos as $ms)
@foreach ($ms as $movimiento)
<tr>
<td >{{$movimiento->cuenta->inmobiliaria->razon}}</td>
<td class="right aligned">{{$format->pesos($movimiento->abono)}}</td>
<td class="right aligned">{{$format->pesos($movimiento->cargo)}}</td>
<td>{{$movimiento->fecha->format('d/m/Y')}}</td>
<td>{{$movimiento->cuenta->banco->nombre}}</td>
<td>{{$movimiento->glosa}}</td>
</tr>
@endforeach
@endforeach
@continue
@endif
@if (count($movimientos) === 0)
@continue
@endif
<tr class="grey">
<td colspan="6">{{strtoupper($tipo)}}</td>
</tr>
@foreach ($movimientos as $movimiento)
<tr>
<td >{{$movimiento->cuenta->inmobiliaria->razon}}</td>
<td class="right aligned">{{$format->pesos($movimiento->abono)}}</td>
<td class="red right aligned">{{$format->pesos($movimiento->cargo)}}</td>
<td>{{$movimiento->fecha->format('d/m/Y')}}</td>
<td>{{$movimiento->cuenta->banco->nombre}}</td>
<td>{{$movimiento->glosa}}</td>
</tr>
@endforeach
@endforeach
</tbody>
</table>
@endsection

View File

@ -28,7 +28,7 @@
return {
hoy: () => {
const span = $('#cuotas_hoy')
return fetch('{{$urls->api}}/ventas/cuotas/hoy').then(response => {
return fetchAPI('{{$urls->api}}/ventas/cuotas/hoy').then(response => {
span.html('')
if (response.ok) {
return response.json()
@ -48,7 +48,7 @@
},
pendiente: () => {
const span = $('#cuotas_pendientes')
return fetch('{{$urls->api}}/ventas/cuotas/pendiente').then(response => {
return fetchAPI('{{$urls->api}}/ventas/cuotas/pendiente').then(response => {
span.html('')
if (response.ok) {
return response.json()

View File

@ -13,7 +13,7 @@
proyectos: () => {
this.draw().loading()
const url = '{{$urls->api}}/proyectos/escriturando'
return fetch(url).then(response => {
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
}
@ -38,7 +38,7 @@
},
unidades: proyecto_id => {
const url = '{{$urls->api}}/ventas/unidades/disponibles'
return fetch(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => {
return fetchAPI(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => {
if (response.ok) {
return response.json()
}
@ -49,7 +49,7 @@
},
promesas: proyecto_id => {
const url = '{{$urls->api}}/ventas/estados/firmar'
return fetch(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => {
return fetchAPI(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => {
if (response.ok) {
return response.json()
}
@ -60,7 +60,7 @@
},
escrituras: proyecto_id => {
const url = '{{$urls->api}}/ventas/escrituras/estados';
return fetch(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => {
return fetchAPI(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => {
if (response.ok) {
return response.json()
}

View File

@ -10,7 +10,7 @@
list.append(
$('<div><div>').addClass('ui inline active loader')
)
fetch('{{$urls->api}}/ventas/cierres/vigentes').then(response => {
fetchAPI('{{$urls->api}}/ventas/cierres/vigentes').then(response => {
list.html('')
if (response.ok) {
return response.json()

View File

@ -10,7 +10,7 @@
list.append(
$('<div><div>').addClass('ui inline active loader')
)
return fetch('{{$urls->api}}/ventas/cuotas/vencer').then(response => {
return fetchAPI('{{$urls->api}}/ventas/cuotas/vencer').then(response => {
list.html('')
if (response.ok) {
return response.json()

View File

@ -4,7 +4,7 @@
@include('layout.body.header.menu.ventas')
@include('layout.body.header.menu.proyectos')
@include('layout.body.header.menu.inmobiliarias')
{{--@include('layout.body.header.menu.contabilidad')--}}
@include('layout.body.header.menu.contabilidad')
{{--@include('layout.body.header.menu.operadores')--}}
{{--@include('layout.body.header.menu.herramientas')--}}
<div class="right aligned menu">

View File

@ -2,7 +2,21 @@
Contabilidad
<i class="dropdown icon"></i>
<div class="menu">
<a class="item" href="{{$urls->base}}/contabilidad/pagos/mes">Pagos Mes</a>
<a class="item" href="{{$urls->base}}/contabilidad/resumen">Resumen</a>
<div class="item">
<i class="dropdown icon"></i>
Informes
<div class="menu">
<a class="item" href="{{$urls->base}}/contabilidad/informes/tesoreria/{{$hoy->sub(new DateInterval('P1D'))->format('Y-m-d')}}">Tesorería</a>
</div>
</div>
<div class="item">
<i class="dropdown icon"></i>
<a class="text" href="{{$urls->base}}/contabilidad/centros_costos">Centros de Costos</a>
<div class="menu">
<a class="item" href="{{$urls->base}}/contabilidad/centros_costos/asignar">Asignar en Cartola</a>
</div>
</div>
<a class="item" href="{{$urls->base}}/contabilidad/cartolas/diaria">Cartola Diaria</a>
<a class="item" href="{{$urls->base}}/contabilidad/depositos">Depósitos a Plazo</a>
</div>
</div>

View File

@ -1,7 +1,26 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js" integrity="sha512-3gJwYpMe3QewGELv8k/BX9vcqhryRdzRMxVfq6ngyWXwo03GFEzjsUm8Q7RZcHPHksttq7/GFoxjCVUjkjvPdw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.2/semantic.min.js" integrity="sha512-5cguXwRllb+6bcc2pogwIeQmQPXEzn2ddsqAexIBhh7FO1z5Hkek1J9mrK2+rmZCTU6b6pERxI7acnp1MpAg4Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.3/semantic.min.js" integrity="sha512-gnoBksrDbaMnlE0rhhkcx3iwzvgBGz6mOEj4/Y5ZY09n55dYddx6+WYc72A55qEesV8VX2iMomteIwobeGK1BQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="text/javascript">
function fetchAPI(url, options=null) {
if (options === null) {
options = {}
}
if (!Object.hasOwn(options, 'headers')) {
options['headers'] = {}
}
if (!Object.hasOwn(options['headers'], 'Authorization')) {
options['headers']['Authorization'] = 'Bearer {{md5($API_KEY)}}'
}
return fetch(url, options).then(response => {
if (response.ok) {
return response
}
throw new Error(JSON.stringify({code: response.status, message: response.statusText, url}))
}).catch(error => {
console.error(error)
})
}
const calendar_date_options = {
type: 'date',
firstDayOfWeek: 1,

View File

@ -1,4 +1,5 @@
@push('page_scripts')
<script type="text/javascript" src="https://cdn.datatables.net/1.13.5/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.13.5/js/dataTables.semanticui.min.js"></script>
{{--<script type="text/javascript" src="https://cdn.datatables.net/2.0.1/js/jquery.dataTables.min.js"></script>--}}
<script type="text/javascript" src="https://cdn.datatables.net/2.0.1/js/dataTables.min.js"></script>
<script src="https://cdn.datatables.net/2.0.1/js/dataTables.semanticui.min.js"></script>
@endpush

View File

@ -0,0 +1,9 @@
@push('page_scripts')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.9/pdfmake.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.datatables.net/buttons/3.0.0/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/3.0.0/js/buttons.semanticui.min.js"></script>
<script src="https://cdn.datatables.net/buttons/3.0.0/js/buttons.colVis.min.js"></script>
<script src="https://cdn.datatables.net/buttons/3.0.0/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/3.0.0/js/buttons.print.min.js"></script>
@endpush

View File

@ -1,3 +1,3 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.2/semantic.min.css" integrity="sha512-n//BDM4vMPvyca4bJjZPDh7hlqsQ7hqbP9RH18GF2hTXBY5amBwM2501M0GPiwCU/v9Tor2m13GOTFjk00tkQA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.3/semantic.min.css" integrity="sha512-3quBdRGJyLy79hzhDDcBzANW+mVqPctrGCfIPosHQtMKb3rKsCxfyslzwlz2wj1dT8A7UX+sEvDjaUv+WExQrA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
@stack('page_styles')

View File

@ -1,3 +1,3 @@
@push('page_styles')
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.5/css/dataTables.semanticui.min.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/2.0.1/css/dataTables.semanticui.min.css" />
@endpush

View File

@ -0,0 +1,3 @@
@push('page_styles')
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/3.0.0/css/buttons.semanticui.min.css" />
@endpush

View File

@ -8,7 +8,7 @@
<input type="text" id="name" name="name" />
</div>
<div class="six wide field">
<label for="password">Clave</label>
<label for="password">Contraseña</label>
<input type="password" id="password" name="password" />
</div>
<button class="ui button" id="enter">Ingresar</button>

View File

@ -51,7 +51,7 @@
get() {
return {
start: () => {
return fetch('{{$urls->api}}/proyecto/' + this.id + '/inicio').then(response => {
return fetchAPI('{{$urls->api}}/proyecto/' + this.id + '/inicio').then(response => {
if (response.ok) {
return response.json()
}
@ -60,7 +60,7 @@
})
},
current: () => {
return fetch('{{$urls->api}}/proyecto/' + this.id + '/estado').then(response => {
return fetchAPI('{{$urls->api}}/proyecto/' + this.id + '/estado').then(response => {
if (response.ok) {
return response.json()
}
@ -69,7 +69,7 @@
})
},
recepcion: () => {
return fetch('{{$urls->api}}/proyecto/' + this.id + '/recepcion').then(response => {
return fetchAPI('{{$urls->api}}/proyecto/' + this.id + '/recepcion').then(response => {
if (response.ok) {
if (response.status === 204) {
return null

View File

@ -42,6 +42,26 @@
</span>
</td>
</tr>
<tr>
<td>Terreno</td>
<td>
<table class="ui very basic striped table">
<tr>
<td>
{{$format->number($proyecto->terreno->superficie, 2)}}m&#0178;
</td>
<td>
{{$format->pesos($proyecto->terreno->valor)}} ({{$proyecto->terreno->fecha?->format('d-m-Y')}})
</td>
<td>
<a href="{{$urls->base}}/proyecto/{{$proyecto->id}}/terreno">
<i class="edit icon"></i>
</a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>Superficies</td>
<td>
@ -134,7 +154,7 @@
return {
superficies: () => {
const url = '{{$urls->api}}/proyecto/{{$proyecto->id}}/superficies/vendible'
return fetch(url).then(response => {
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
}
@ -197,7 +217,7 @@
data: {},
get: function() {
const url = '{{$urls->api}}/proyecto/{{$proyecto->id}}/unidades'
return fetch(url).then(response => {
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
}
@ -273,7 +293,7 @@
return {
ventas: () => {
const url = '{{$urls->api}}/ventas'
return fetch(url, {method: 'post', headers: {'Content-Type': 'application/json'},
return fetchAPI(url, {method: 'post', headers: {'Content-Type': 'application/json'},
body: JSON.stringify({proyecto_id: '{{$proyecto->id}}'})}).then(response => {
if (response.ok) {
return response.json()
@ -294,7 +314,7 @@
},
stock: () => {
const url = '{{$urls->api}}/proyecto/{{$proyecto->id}}/unidades/disponibles'
return fetch(url).then(response => {
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
}
@ -315,7 +335,7 @@
},
venta: venta_id => {
const url = '{{$urls->api}}/venta/' + venta_id
return fetch(url).then(response => {
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
}
@ -325,7 +345,7 @@
},
precio: unidad_id => {
const url = '{{$urls->api}}/ventas/precio/unidad/' + unidad_id
return fetch(url).then(response => {
return fetchAPI(url).then(response => {
if (response.ok) {
if (response.status === 204) {
return null

View File

@ -0,0 +1,5 @@
@extends('layout.base')
@push('page_content')
@endpush

View File

@ -203,7 +203,7 @@
return {
tipos: proyecto_id => {
const url = '{{$urls->api}}/proyecto/' + proyecto_id + '/unidades/tipos'
return fetch(url).then(response => {
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
}

View File

@ -6,7 +6,7 @@
<form id="search_form" class="ui form" action="{{$urls->base}}/search" method="post">
<div class="field">
<div class="ui fluid input" data-tooltip="Para buscar frases se deben encerrar entre comillas. ej, 'portal la viña' o &quot;portal la viña&quot;" data-position="bottom left">
<div class="ui fluid input" data-tooltip="Para buscar frases se deben encerrar entre comillas. ej, 'portal la viña' o &quot;portal la viña&quot;" data-position="top right">
<input type="text" name="query" />
</div>
</div>
@ -56,7 +56,7 @@
unidad.html(unidad.html() + ' (I)')
}
propietario = $('<a></a>')
.attr('href','{{$urls->base}}/search/' + encodeURIComponent(this.venta.propietario.nombre_completo) + '/propietario')
.attr('href','{{$urls->base}}/search/"' + encodeURIComponent(this.venta.propietario.nombre_completo) + '"/propietario')
.html(this.venta.propietario.nombre_completo)
fecha = dateFormatter.format(new Date(this.venta.fecha))
if (typeof this.venta.entrega !== 'undefined') {
@ -96,6 +96,10 @@
id: '',
data: [],
table: null,
queues: {
unidades: [],
ventas: []
},
get: function() {
return {
results: () => {
@ -106,10 +110,11 @@
const data = new FormData(document.getElementById('search_form'))
const uri = '{{$urls->api}}/search'
this.data = []
return fetch(uri, {method: 'post', body: data}).then(response => {
if (response.ok) {
return response.json()
return fetchAPI(uri, {method: 'post', body: data}).then(response => {
if (!response) {
return
}
return response.json()
}).catch(error => {
this.draw().clear()
this.draw().error(error)
@ -121,31 +126,33 @@
}
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
this.queues.ventas = data.results.filter(row => row.tipo === 'venta').map(row => row.id)
this.queues.unidades = data.results.filter(row => row.tipo !== 'venta').map(row => row.id)
promises.push(this.get().ventas().then(arrays => {
arrays.forEach(json => {
if (json.ventas.length === 0) {
console.debug(json)
return
}
json.ventas.forEach(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 => {
})
})
}))
promises.push(this.get().unidades().then(arrays => {
arrays.forEach(json => {
if (json.unidades.length === 0) {
return
}
json.unidades.forEach(unidad => {
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)
}))
})
this.data.push(new Row({unidad: unidad, proyecto: unidad.proyecto_tipo_unidad.proyecto}))
})
})
}))
Promise.all(promises).then(() => {
this.sort()
this.draw().clear()
@ -153,21 +160,43 @@
})
})
},
unidad: id => {
const url = '{{$urls->api}}/ventas/unidad/' + id
return fetch(url).then(response => {
if (response.ok) {
unidades: () => {
const url = '{{$urls->api}}/search/ventas/unidades'
const chunks = []
for (let i = 0; i < this.queues.unidades.length; i += 100) {
chunks.push(this.queues.unidades.slice(i, i + 100))
}
const promises = []
chunks.forEach(ids => {
const body = new FormData()
body.set('unidades', ids)
promises.push(fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json()
}
}))
})
return Promise.all(promises)
},
venta: id => {
const url = '{{$urls->api}}/venta/' + id
return fetch(url).then(response => {
if (response.ok) {
ventas: () => {
const url = '{{$urls->api}}/search/ventas'
const chunks = []
for (let i = 0; i < this.queues.ventas.length; i += 100) {
chunks.push(this.queues.ventas.slice(i, i + 100))
}
const promises = []
chunks.forEach(ids => {
const body = new FormData()
body.set('ventas', ids)
promises.push(fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json()
}
}))
})
return Promise.all(promises)
}
}
},
@ -224,6 +253,7 @@
parent.append(table)
this.table = new DataTable(table, {
pageLength: 25,
order: [
[0, 'asc'],
[2, 'asc']
@ -303,27 +333,37 @@
}
}
},
set: function() {
return {
query: value => {
$("[name='query']").val(value)
this.get().results()
}
}
},
setup: function(id) {
this.id = id
this.get().results()
$('#tipo').dropdown().dropdown('set selected', '*')
@if (trim($post) !== '')
this.set().query('{!! $post !!}')
@elseif (trim($query) !== '')
this.set().query('{!! $query !!}')
@endif
@if (trim($tipo) !== '')
$('#tipo').dropdown('set selected', '{{$tipo}}')
@endif
$('#search_form').submit(event => {
event.preventDefault()
this.get().results()
return false
})
$("[name='query']").focus()
}
}
$(document).ready(() => {
$('#tipo').dropdown().dropdown('set selected', '*')
@if (trim($post) !== '')
$("[name='query']").val('{{$post}}')
@elseif (trim($query) !== '')
$("[name='query']").val('{{$query}}')
@endif
@if (trim($tipo) !== '')
$('#tipo').dropdown('set selected', '{{$tipo}}')
@endif
results.setup('#results')
})
</script>

View File

@ -3,7 +3,7 @@
@section('page_content')
<div class="ui container">
<h2 class="ui header">Nueva Venta</h2>
<form class="ui form" id="add_form" action="{{$urls->api}}/ventas/add" method="post">
<form class="ui form" id="add_form" method="post">
<label for="fecha_venta">Fecha de Venta</label>
<div class="inline field">
<div class="ui calendar" id="fecha_venta_calendar">
@ -269,7 +269,7 @@
return {
provincias: () => {
const uri = '{{$urls->api}}/region/' + this.data.region + '/provincias'
return fetch(uri).then(response => {
return fetchAPI(uri).then(response => {
if (response.ok) {
return response.json()
}
@ -286,7 +286,7 @@
},
comunas: provincia_id => {
const uri = '{{$urls->api}}/provincia/' + provincia_id + '/comunas'
return fetch(uri).then(response => {
return fetchAPI(uri).then(response => {
if (response.ok) {
return response.json()
}
@ -349,7 +349,7 @@
const lines = [
'<label for="rut">RUT</label>',
'<div class="inline field">',
'<input type="text" id="rut" name="rut" />',
'<input type="text" id="rut" name="rut" placeholder="00000000-0" />',
'<span class="ui error message" id="alert_rut">',
'<i class="exclamation triangle icon"></i>',
'RUT Inválido',
@ -358,25 +358,25 @@
'<label for="nombres">Nombre</label>',
'<div class="inline fields">',
'<div class="field">',
'<input type="text" name="nombres" id="nombres" />',
'<input type="text" name="nombres" id="nombres" placeholder="Nombre(s)" />',
'</div>',
'<div class="field">',
'<input type="text" name="apellido_paterno" />',
'<input type="text" name="apellido_paterno" placeholder="Apellido Paterno" />',
'</div>',
'<div class="field">',
'<input type="text" name="apellido_materno" />',
'<input type="text" name="apellido_materno" placeholder="Apellido Materno" />',
'</div>',
'</div>',
'<label for="calle">Dirección</label>',
'<div class="inline fields">',
'<div class="eight wide field">',
'<input type="text" name="calle" id="calle" size="16" />',
'<input type="text" name="calle" id="calle" size="16" placeholder="Calle" />',
'</div>',
'<div class="field">',
'<input type="text" name="numero" size="5" />',
'<input type="text" name="numero" size="5" placeholder="Número" />',
'</div>',
'<div class="field">',
'<input type="text" name="extra" />',
'<input type="text" name="extra" placeholder="Otros Detalles" />',
'</div>',
'</div>',
'<div class="inline fields">',
@ -581,7 +581,7 @@
return {
propietario: rut => {
const uri = '{{$urls->api}}/ventas/propietario/' + rut.split('-')[0]
return fetch(uri).then(response => {
return fetchAPI(uri).then(response => {
if (response.ok) {
return response.json()
}
@ -664,7 +664,7 @@
return {
unidades: () => {
const uri = '{{$urls->api}}/proyecto/' + this.data.id + '/unidades'
return fetch(uri).then(response => {
return fetchAPI(uri).then(response => {
if (response.ok) {
return response.json()
}
@ -686,7 +686,7 @@
$('<div></div>').addClass('content').append(tipo.charAt(0).toUpperCase() + tipo.slice(1) + ' ').append(
unidad.draw(this.unidades[tipo])
).append(
$('<button></button>').addClass('ui icon button').attr('type', 'button').attr('data-number', number).append(
$('<button></button>').addClass('ui basic red icon button').attr('type', 'button').attr('data-number', number).append(
$('<i></i>').addClass('remove icon')
).click(event => {
const number = $(event.currentTarget).attr('data-number')
@ -766,7 +766,7 @@
}
function showErrors(errors) {
console.debug(errors)
console.error(errors)
}
$(document).ready(() => {
@ -789,20 +789,21 @@
$('#add_form').submit(event => {
event.preventDefault()
const data = new FormData(event.currentTarget)
const uri = $(event.currentTarget).attr('action')
fetch(uri, {method: 'post', body: data}).then(response => {
if (response.ok) {
return response.json()
const body = new FormData(event.currentTarget)
const uri = '{{$urls->api}}/ventas/add'
return fetchAPI(uri, {method: 'post', body}).then(response => {
if (!response) {
return false
}
}).then(data => {
if (data.status) {
window.location = '{{$urls->base}}'
return true
}
showErrors(data.errors)
return response.json().then(data => {
if (data.status) {
window.location = '{{$urls->base}}/venta/' + data.venta_id
return true
}
showErrors(data.errors)
return false
})
})
return false
})
})
</script>

View File

@ -0,0 +1,36 @@
@extends('layout.base')
@section('page_title')
Venta {{$venta->proyecto()->descripcion}} {{$venta->propiedad()->summary()}}
@endsection
@section('page_content')
<div class="ui container">
<div class="ui two column grid">
<div class="row">
<h1 class="four wide column header">
<div class="content">
<div class="ui dividing sub header">{{$venta->proyecto()->descripcion}}</div>
<a href="{{$urls->base}}/venta/{{$venta->id}}">
{{$venta->propiedad()->summary()}}
</a>
</div>
</h1>
@if (isset($showPropietario) and $showPropietario)
<div class="right floated column">
@include('ventas.show.propietario')
</div>
@endif
</div>
@hasSection('venta_subtitle')
<div class="row">
<h2 class="ui sub header column">
@yield('venta_subtitle')
</h2>
</div>
@endif
</div>
<br />
@yield('venta_content')
</div>
@endsection

View File

@ -201,7 +201,7 @@
this.draw().loading()
return fetch('{{$urls->api}}/proyectos').then(response => {
return fetchAPI('{{$urls->api}}/proyectos').then(response => {
if (response.ok) {
return response.json()
}
@ -223,7 +223,7 @@
})
},
cierres: proyecto_id => {
return fetch('{{$urls->api}}/ventas/cierres',
return fetchAPI('{{$urls->api}}/ventas/cierres',
{method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => {
if (response.ok) {
return response.json()

View File

@ -0,0 +1,294 @@
@extends('ventas.base')
@section('venta_subtitle')
Crédito
@endsection
@section('venta_content')
@php($credito = $venta->formaPago()->credito)
<div class="ui grid">
<div class="row">
<div class="two wide column">Fecha</div>
<div class="six wide column" id="fecha" data-status="static">
<span id="fecha_data">
{{$credito->pago->fecha->format('d-m-Y')}}
</span>
<a href="#" id="fecha_edit">
<i class="edit icon"></i>
</a>
<div class="ui calendar hidden" id="fecha_input">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha" />
</div>
</div>
</div>
</div>
<div class="row">
<div class="two wide column">Banco</div>
<div class="six wide column" id="banco" data-status="static">
<span id="banco_data">
@if (isset($credito->pago->banco))
{{$credito->pago->banco->nombre}}
@else
No definido
@endif
</span>
<a href="#" id="banco_edit">
<i class="edit icon"></i>
</a>
<div class="ui search selection dropdown hidden" id="banco_input">
<input type="hidden" name="banco" />
<i class="dropdown icon"></i>
<div class="default text">Banco</div>
<div class="menu">
@foreach ($bancos as $banco)
<div class="item" data-value="{{$banco->id}}">{{$banco->nombre}}</div>
@endforeach
</div>
</div>
</div>
</div>
<div class="row">
<div class="two wide column">Valor</div>
<div class="six wide column" id="valor" data-status="static">
<span id="valor_data">
{{$format->ufs($credito->pago->valor())}}
</span>
<a href="#" id="valor_edit">
<i class="edit icon"></i>
</a>
<div class="ui right labeled input hidden" id="valor_input">
<input type="text" name="valor" />
<div class="ui basic label">UF</div>
</div>
</div>
</div>
</div>
@endsection
@push('page_styles')
<style>
.hidden {
display: none !important;
}
</style>
@endpush
@push('page_scripts')
<script>
const credito = {
ids: {},
data: {
venta: {{$venta->id}},
credito: {{$credito->id}},
fecha: new Date({{$credito->pago->fecha->format('Y')}},
{{$credito->pago->fecha->format('m')}}+1,
{{$credito->pago->fecha->format('d')}}),
banco: {
@if (isset($credito->pago->banco))
id: {{$credito->pago->banco->id}},
nombre: '{{$credito->pago->banco->nombre}}'
@else
id: 0,
nombre: ''
@endif
},
valor: {{$credito->pago->valor()}},
bancos: JSON.parse('{!! json_encode($bancos) !!}')
},
elements: {},
change() {
return {
status: (id, status) => {
this.elements[id].dataset.status = status
}
}
},
hide() {
return {
data: id => {
this.elements[id + '.data'].innerHTML = ''
this.elements[id + '.data'].classList.add('hidden')
this.elements[id + '.data'].hidden = true
},
input: id => {
this.elements[id + '.input'].classList.add('hidden')
this.elements[id + '.input'].hidden = true
}
}
},
show() {
return {
data: id => {
this.elements[id + '.data'].classList.remove('hidden')
this.elements[id + '.data'].hidden = false
},
input: id => {
this.elements[id + '.input'].classList.remove('hidden')
this.elements[id + '.input'].hidden = false
}
}
},
draw() {
return {
edit: (id) => {
this.change().status(id, 'edit')
this.show().input(id)
this.update()[id]()
},
static: (id, text) => {
this.change().status(id, 'static')
this.hide().input(id)
this.elements[this.ids.fields[id] + '.data'].innerHTML = this.format()[id](text)
}
}
},
send(id, value) {
const url = '{{$urls->api}}/venta/{{$venta->id}}/credito'
const body = new FormData()
body.set(id, value)
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (!json.status) {
return
}
this.data.fecha = new Date(json.credito.pago.fecha)
this.data.banco.id = json.credito.pago.banco.id
this.data.banco.nombre = json.credito.pago.banco.nombre
this.data.valor = json.credito.pago.valor / json.credito.pago.uf
})
})
},
edit() {
return {
fecha: fecha => {
this.send('fecha', fecha).then(() => {
this.draw().static('fecha', this.data.fecha)
})
},
banco: banco_id => {
this.send('banco', banco_id).then(() => {
this.draw().static('banco', this.data.banco.nombre)
})
},
valor: valor => {
this.send('valor', valor).then(() => {
this.draw().static('valor', this.data.valor)
})
}
}
},
format() {
return {
fecha: value => {
const dateFormatter = new Intl.DateTimeFormat('es-CL', {year: 'numeric', month: 'numeric', day: 'numeric'})
return dateFormatter.format(value)
},
banco: value => {
if (value === '') {
value = 'No definido'
}
return value
},
valor: value => {
const numberFormatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
return numberFormatter.format(value) + ' UF'
}
}
},
update() {
return {
fecha: () => {
const $fecha = $(this.elements.fecha.querySelector('div.ui.calendar'))
$fecha.calendar('set date', this.data.fecha)
$fecha.calendar('focus')
},
banco: () => {
const $dropdown = $(this.elements.banco.querySelector('div.ui.dropdown'))
$dropdown.dropdown('clear')
if (this.data.banco.id !== 0) {
$dropdown.dropdown('set selected', this.data.banco.id)
}
$dropdown.dropdown('toggle')
},
valor: () => {
const input = this.elements.valor.querySelector('input')
input.value = this.data.valor ?? ''
input.focus()
}
}
},
watch(id) {
this.elements[id + '.edit'].addEventListener('click', event => {
const elem = event.currentTarget.parentNode
const id = elem.id
const status = elem.dataset.status
if (status !== 'static') {
return
}
this.draw().edit(id)
})
},
register(name, elem_id) {
this.elements[name] = document.getElementById(elem_id)
},
setup(ids) {
this.ids = ids
Object.entries(this.ids.fields).forEach(entry => {
const name = entry[0]
const field = entry[1]
this.register(name, field)
this.register(name + '.data', field + '_data')
this.register(name + '.input', field + '_input')
this.register(name + '.edit', field + '_edit')
this.watch(field)
})
calendar_date_options['onChange'] = (date, text, mode) => {
if (date === this.data.fecha) {
return
}
this.edit().fecha([date.getFullYear(), date.getMonth()+1, date.getDate()].join('-'))
}
calendar_date_options['onHide'] = () => {
this.draw().static('fecha', this.data.fecha)
}
$(this.elements.fecha).find('div.ui.calendar').calendar(calendar_date_options)
$(this.elements.banco).find('div.ui.dropdown').dropdown({
onChange: (value, text, $element) => {
if (value === '' || value === this.data.banco.id) {
return
}
this.edit().banco(value)
},
onHide: () => {
this.draw().static('banco', this.data.banco.nombre)
}
})
this.elements.valor.querySelector('input').addEventListener('blur', event => {
let valor = event.currentTarget.value
if (valor.includes(',')) {
valor = valor.replaceAll('.', '').replace(',', '.')
}
if (parseFloat(valor) === this.data.valor) {
this.draw().static('valor', this.data.valor)
return
}
this.edit().valor(valor)
})
}
}
$(document).ready(() => {
credito.setup({
fields: {
fecha: 'fecha',
banco: 'banco',
valor: 'valor'
}
})
})
</script>
@endpush

View File

@ -105,7 +105,7 @@
const cuota_id = button.data('cuota')
const calendar = $(".ui.calendar[data-cuota='" + cuota_id + "']").calendar('get date')
const fecha = [calendar.getFullYear(), calendar.getMonth()+1, calendar.getDate()].join('-')
fetch('{{$urls->api}}/ventas/cuota/abonar', {
return fetchAPI('{{$urls->api}}/ventas/cuota/abonar', {
method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({cuota_id, fecha})
}).then(response => {
if (response.ok) {
@ -125,7 +125,7 @@
const cuota_id = button.data('cuota')
const calendar = $(".ui.calendar[data-cuota='" + cuota_id + "']").calendar('get date')
const fecha = [calendar.getFullYear(), calendar.getMonth()+1, calendar.getDate()].join('-')
fetch('{{$urls->api}}/ventas/cuota/devolver', {
return fetchAPI('{{$urls->api}}/ventas/cuota/devolver', {
method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({cuota_id, fecha})
}).then(response => {
if (response.ok) {

View File

@ -105,7 +105,7 @@
const cuota_id = button.data('cuota')
const calendar = $(".ui.calendar[data-cuota='" + cuota_id + "']").calendar('get date')
const fecha = [calendar.getFullYear(), calendar.getMonth()+1, calendar.getDate()].join('-')
fetch('{{$urls->api}}/ventas/cuota/depositar', {
return fetchAPI('{{$urls->api}}/ventas/cuota/depositar', {
method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({cuota_id, fecha})
}).then(response => {
if (response.ok) {

View File

@ -0,0 +1,110 @@
@extends('ventas.base')
@section('venta_subtitle')
Desistida
@endsection
@section('venta_content')
<form class="ui form" id="desistida_form">
<div class="fields">
<div class="three wide field">
<label for="fecha">Fecha</label>
<div class="ui calendar" id="fecha">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" />
</div>
</div>
</div>
<div class="one wide field">
<div id="loading-spinner-fecha" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
</div>
</div>
<div class="fields">
<div class="three wide field">
<label for="devolucion">Devolución</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" id="devolucion" value="{{$venta->resciliacion()->valor}}" />
</div>
</div>
<div class="one wide field">
<div id="loading-spinner-devolucion" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
</div>
</div>
<button class="ui red icon button" type="button" id="eliminar_desistimiento">
<i class="ban icon"></i>
Elmininar desistimiento
</button>
<div id="loading-spinner-eliminar" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
</form>
@endsection
@push('page_scripts')
<script>
function alertResponse(message, {color = 'green', icon = 'check circle'}={}) {
$.toast({
message,
showProgress: 'bottom',
progressUp: true,
class: color,
showIcon: icon,
classProgress: 'blue'
})
}
$(document).ready(() => {
const url = '{{$urls->api}}/ventas/pago/{{$venta->resciliacion()->id}}'
let old = new Date({{$venta->resciliacion()->fecha->format('Y')}},
{{$venta->resciliacion()->fecha->format('n')}}-1, {{$venta->resciliacion()->fecha->format('j')}})
calendar_date_options['initialDate'] = old
calendar_date_options['onChange'] = function(date, text, mode) {
if (date.getTime() === old.getTime()) {
return
}
const body = new FormData()
body.set('fecha', date.toISOString())
$('#loading-spinner-fecha').show()
fetchAPI(url, {method: 'post', body}).then(response => {
$('#loading-spinner-fecha').hide()
if (!response) {
return
}
old = date
alertResponse('Fecha cambiada correctamente.')
})
}
$('#fecha').calendar(calendar_date_options)
$('#devolucion').change(event => {
const val = $(event.currentTarget).val()
const body = new FormData()
body.set('valor', val)
$('#loading-spinner-devolucion').show()
fetchAPI(url, {method: 'post', body}).then(response => {
$('#loading-spinner-devolucion').hide()
if (!response) {
return
}
alertResponse('Devolución cambiada correctamente.')
})
})
$('#eliminar_desistimiento').click(event => {
const url = '{{$urls->api}}/venta/{{$venta->id}}/desistir/eliminar'
$('#loading-spinner-eliminar').show()
fetchAPI(url).then(response => {
$('#loading-spinner-eliminar').hide()
if (!response) {
alertResponse('No se pudo eliminar el desistimiento', {color: 'red', icon: 'triangle exclamation'})
return
}
response.json().then(json => {
if (!json.eliminado) {
alertResponse('No se pudo eliminar el disistimiento', {color: 'red', icon: 'triangle exclamation'})
return
}
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
})
})
})
})
</script>
@endpush

View File

@ -0,0 +1,73 @@
@extends('ventas.base')
@section('venta_subtitle')
Desistir
@endsection
@section('venta_content')
<div class="ui list">
<div class="item">
<div class="header">Valor Pagado</div>
<div class="content">
{{$format->pesos($venta->formaPago()->pie->pagado('pesos'))}}
<div class="ui left pointing small label">
{{$format->number($venta->formaPago()->pie->pagado() / $venta->valor * 100)}}% de la venta
</div>
</div>
</div>
<div class="item">
<div class="header">
Multa Estandar
<div class="ui left pointing small label">5%</div>
</div>
<div class="content">
{{$format->pesos($venta->valor * 0.05 * $UF->get())}}
</div>
</div>
</div>
<form class="ui form" id="desistir_form">
<div class="three wide field">
<label for="fecha">Fecha</label>
<div class="ui calendar" id="fecha">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" />
</div>
</div>
</div>
<div class="three wide field">
<label for="devolucion">Devolución [$]</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="devolucion" />
</div>
</div>
<button class="ui button">Desistir</button>
</form>
@endsection
@push('page_scripts')
<script>
$(document).ready(() => {
$('#fecha').calendar(calendar_date_options)
$('#desistir_form').submit(event => {
event.preventDefault()
const body = new FormData(event.currentTarget)
const fecha = $('#fecha').calendar('get date')
body.set('fecha', fecha.toISOString())
const url = '{{$urls->api}}/venta/{{$venta->id}}/desistir'
fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
response.json().then(json => {
if (json.desistida) {
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
}
})
})
return false
})
})
</script>
@endpush

View File

@ -1,94 +1,82 @@
@extends('layout.base')
@extends('ventas.base')
@section('page_content')
<div class="ui container">
<h2 class="ui header">Editar Venta</h2>
<form class="ui form" id="edit_form">
<div class="inline field">
<label for="valor">Valor</label>
<div class="ui right labeled input">
<input type="text" id="valor" name="valor" value="{{$venta->valor}}" />
<div class="ui label">UF</div>
@section('venta_subtitle')
Editar Venta
@endsection
@section('venta_content')
<form class="ui form" id="edit_form">
<div class="inline field">
<label for="valor">Valor</label>
<div class="ui right labeled input">
<input type="text" id="valor" name="valor" value="{{$venta->valor}}" />
<div class="ui label">UF</div>
</div>
</div>
<div class="inline field">
<label for="fecha">Fecha Promesa</label>
<div class="ui calendar" id="fecha_calendar">
<div class="ui icon input">
<input type="text" name="fecha" id="fecha" />
<i class="calendar icon"></i>
</div>
</div>
<div class="inline field">
<label for="fecha">Fecha Promesa</label>
<div class="ui calendar" id="fecha_calendar">
<div class="ui icon input">
<input type="text" name="fecha" id="fecha" />
<i class="calendar icon"></i>
</div>
</div>
</div>
<button class="ui button">
Guardar
</button>
</form>
</div>
</div>
<button class="ui button">
Guardar
</button>
</form>
@endsection
@push('page_scripts')
<script type="text/javascript">
function getMonthsList() {
const formatter = new Intl.DateTimeFormat('es-CL', {month: 'long'})
const months = []
let m = ''
for (let i = 0; i < 12; i ++) {
m = formatter.format((new Date()).setMonth(i))
months.push(m.charAt(0).toUpperCase() + m.slice(1))
}
return months
}
function redirect() {
const uri = '{{$urls->base}}/venta/{{$venta->id}}'
window.location = uri
}
function editVenta() {
const original = {
valor: {{$venta->valor}},
fecha: new Date('{{$venta->fecha->format('Y-m-d')}}T00:00:00')
}
const collator = new Intl.Collator('es-CL')
const data = {}
Object.keys(original).forEach(name => {
let val = $("[name='" + name + "']").val()
if (name === 'fecha') {
val = $('#fecha_calendar').calendar('get date')
if (val.getTime() !== original[name].getTime()) {
data[name] = [val.getFullYear(), (''+(val.getMonth()+1)).padStart(2, '0'), (''+val.getDate()).padStart(2, '0')].join('-')
const editVenta = {
getMonthsList() {
const formatter = new Intl.DateTimeFormat('es-CL', {month: 'long'})
const months = []
let m = ''
for (let i = 0; i < 12; i ++) {
m = formatter.format((new Date()).setMonth(i))
months.push(m.charAt(0).toUpperCase() + m.slice(1))
}
return months
},
redirect() {
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
},
edit() {
const uri = '{{$urls->api}}/venta/{{$venta->id}}'
const data = new FormData()
data.set('valor', $('#valor').val())
data.set('fecha', $('#fecha_calendar').calendar('get date').toISOString())
return fetchAPI(uri, {method: 'post', body: data}).then(response => {
if (response.ok) {
return response.json()
}
return
}
if (collator.compare(val, original[name]) !== 0) {
data[name] = val
}
})
if (Object.keys(data).length === 0) {
redirect()
return
}).then(json => {
if (!json.edited) {
return
}
this.redirect()
})
},
setup() {
$('#fecha_calendar').calendar({
type: 'date',
initialDate: '{{$venta->fecha->format('Y-m-d')}}',
text: {
months: this.getMonthsList()
}
})
$('#edit_form').submit(event => {
event.preventDefault()
this.edit()
return false
})
}
const uri = '{{$urls->api}}/venta/{{$venta->id}}'
return fetch(uri,
{method: 'put', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)}
).then(response => {
if (response.ok) {
redirect()
}
})
}
$(document).ready(() => {
$('#fecha_calendar').calendar({
type: 'date',
initialDate: '{{$venta->fecha->format('Y-m-d')}}',
text: {
months: getMonthsList()
}
})
$('#edit_form').submit(event => {
event.preventDefault()
editVenta()
return false
})
editVenta.setup()
})
</script>
@endpush

View File

@ -0,0 +1,276 @@
@extends('ventas.base')
@section('venta_subtitle')
Escriturar
@endsection
@section('venta_content')
<div class="ui basic segment">
<div class="ui four columns grid">
<div class="column">Faltante</div>
<div class="column">{{$format->pesos($venta->saldo('pesos'))}}</div>
<div class="column">{{$format->ufs($venta->saldo())}}</div>
</div>
</div>
<div class="ui divider"></div>
<form class="ui form" id="escriturar_form">
<div class="three wide field">
<label for="fecha">Fecha</label>
<div class="ui calendar" id="fecha">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha" />
</div>
</div>
</div>
@if ($venta->formaPago()->pie->reajuste === null)
<h4 class="ui header optional" data-name="reajuste">Reajuste <i class="small plus icon"></i></h4>
<div class="fields optional" id="reajuste">
<div class="field">
<label for="valor_reajuste">Valor [$]</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="valor_reajuste" id="valor_reajuste" />
</div>
</div>
<div class="field">
<label for="fecha_reajuste">Fecha</label>
<div class="ui calendar" id="fecha_reajuste">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha_reajuste" />
</div>
</div>
</div>
</div>
@else
<h4 class="ui header" data-name="reajuste">Reajuste</h4>
<div class="fields" id="reajuste">
<div class="field">
<label for="valor_reajuste">Valor [$]</label>
<div class="ui left labeled disabled input">
<div class="ui basic label">$</div>
<input type="text" value="{{$format->number($venta->formaPago()->pie->reajuste->valor)}}" />
</div>
</div>
<div class="field">
<label for="fecha_reajuste">Fecha</label>
<div class="ui disabled input">
<input type="text" value="{{$venta->formaPago()->pie->reajuste->fecha->format('d-m-Y')}}" />
</div>
</div>
</div>
@endif
@if (!isset($venta->formaPago()->escritura))
<h4 class="ui header optional" data-name="pago">Pago en Escritura <i class="small plus icon"></i></h4>
<div class="fields optional" id="pago">
<div class="field">
<label for="valor_pago_pesos">Valor [$]</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="valor_pago_pesos" id="valor_pago_pesos" />
</div>
</div>
<div class="field">
<label for="valor_pago_ufs">(Valor [UF])</label>
<div class="ui right labeled input">
<input type="text" name="valor_pago_ufs" id="valor_pago_ufs" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="fecha_pago">Fecha</label>
<div class="ui calendar" id="fecha_pago">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha_pago" />
</div>
</div>
</div>
</div>
@else
<h4 class="ui header" data-name="pago">Pago en Escritura</h4>
<div class="fields" id="pago">
<div class="field">
<label for="valor_pago_pesos">Valor [$]</label>
<div class="ui left labeled disabled input">
<div class="ui basic label">$</div>
<input type="text" value="{{$format->number($venta->formaPago()->escritura->pago->valor)}}" />
</div>
</div>
<div class="field">
<label for="valor_pago_ufs">(Valor [UF])</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$format->number($venta->formaPago()->escritura->pago->valor(),2)}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="fecha_pago">Fecha</label>
<div class="ui disabled input">
<input type="text" value="{{$venta->formaPago()->escritura->pago->fecha->format('d-m-Y')}}">
</div>
</div>
</div>
@endif
@if (!isset($venta->formaPago()->subsidio))
<h4 class="ui header optional" data-name="subsidio">Subsidio <i class="small plus icon"></i></h4>
<div class="fields optional" id="subsidio">
<div class="field">
<label for="valor_ahorro">Valor Ahorrado [UF]</label>
<div class="ui right labeled input">
<input type="text" name="valor_ahorro" id="valor_ahorro" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="valor_subsidio">Valor Subsidio [UF]</label>
<div class="ui right labeled input">
<input type="text" name="valor_subsidio" id="valor_subsidio" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="total_subsidio">Total</label>
<div class="ui right labeled disabled input">
<input type="text" id="total_subsidio" value="0,00" />
<div class="ui basic label">UF</div>
</div>
</div>
</div>
@else
<h4 class="ui header" data-name="subsidio">Subsidio</h4>
<div class="fields">
<div class="field">
<label for="valor_ahorro">Valor Ahorrado</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$venta->formaPago()->subsidio->ahorro->valor()}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="valor_subsidio">Valor Subsidio</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$venta->formaPago()->subidio->pago->valor()}}" />
<div class="ui basic label">UF</div>
</div>
</div>
</div>
@endif
@if (!isset($venta->formaPago()->credito) or $venta->formaPago()->credito->pago->banco === null)
<h4 class="ui header">Crédito</h4>
<div class="fields">
<div class="field">
<label for="valor_credito">Valor [UF]</label>
<div class="ui right labeled input">
<input type="text" id="valor_credito" name="valor_credito" value="{{$venta->formaPago()->credito?->pago->valor() ?? ''}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="four wide field">
<label for="banco_credito">Banco</label>
<div class="ui selection dropdown" id="banco_credito">
<input type="hidden" name="banco_credito" />
<div class="default text">Banco</div>
<i class="dropdown icon"></i>
<div class="menu">
@foreach ($bancos as $banco)
<div class="item" data-value="{{$banco->id}}">{{$banco->nombre}}</div>
@endforeach
</div>
</div>
</div>
</div>
@else
<h4 class="ui header">Crédito</h4>
<div class="fields">
<div class="field">
<label for="valor_credito">Valor [UF]</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$format->number($venta->formaPago()->credito->pago->valor(), 2)}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="four wide field">
<label for="banco_credito">Banco</label>
<div class="ui disabled input">
<input type="text" value="{{$venta->formaPago()->credito->pago->banco->nombre}}" />
</div>
</div>
</div>
@endif
<button class="ui button">Escriturar</button>
</form>
@endsection
@push('page_scripts')
<script>
const subsidio = {
watchIds: [
'#valor_ahorro',
'#valor_subsidio'
],
values: [0, 0],
watch() {
this.watchIds.forEach((id, idx) => {
$(id).change(event => {
let val = parseFloat($(event.currentTarget).val())
if (isNaN(val)) {
val = 0
}
this.values[idx] = val
this.update()
})
})
},
update() {
const total = this.values.reduce((sum, val) => sum + val, 0)
$('#total_subsidio').val(total.toLocaleString('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2}))
}
}
$(document).ready(() => {
$('#fecha').calendar(calendar_date_options)
$('#banco_credito').dropdown()
$('.header.optional').click(event => {
const elem = $(event.currentTarget)
const name = elem.data('name')
const icon = elem.find('.icon')
const status = Array.from(icon[0].classList).includes('plus')
const fields = $('#' + name)
if (status) {
icon.removeClass('plus').addClass('minus')
fields.show()
return
}
icon.removeClass('minus').addClass('plus')
fields.hide()
})
$('.fields.optional').hide()
subsidio.watch()
$('#escriturar_form').submit(event => {
event.preventDefault()
const url = '{{$urls->api}}/venta/{{$venta->id}}/escriturar'
const body = new FormData(event.currentTarget)
body.set('fecha', $('#fecha').calendar('get date').toISOString())
if (body.get('fecha_pago') !== '') {
body.set('fecha_pago', $('#fecha_pago').calendar('get date').toISOString())
}
if (body.get('fecha_reajuste') !== '') {
body.set('fecha_reajuste', $('#fecha_reajuste').calendar('get date').toISOString())
}
fetchAPI(url, {method: 'post', body}).then(response => {
if (response.ok) {
return response.json()
}
}).then(json => {
if (json.status) {
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
}
})
return false
})
$('#fecha_pago').calendar(calendar_date_options)
$('#fecha_reajuste').calendar(calendar_date_options)
})
</script>
@endpush

View File

@ -0,0 +1,153 @@
@extends('ventas.base')
@section('venta_subtitle')
Agregar Abono en Escritura
@endsection
@section('venta_content')
<div class="ui basic segment">
<p>Valor Promesa {{$format->ufs($venta->valor)}}</p>
@if (isset($venta->formaPago()->pie))
<p>Valor Anticipo {{$format->ufs($venta->formaPago()->pie->valor)}}</p>
@endif
@if (isset($venta->formaPago()->credito))
<p>Crédito {{$format->ufs($venta->formaPago()->credito->pago->valor())}}</p>
@endif
</div>
<form class="ui form" id="add_form">
<div class="three wide field">
<label for="fecha">Fecha</label>
<div class="ui calendar" id="fecha">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha" />
</div>
</div>
</div>
<div class="fields">
<div class="field">
<label for="valor">Valor</label>
<div class="ui labeled input" id="valor">
<div class="ui basic label">$</div>
<input type="text" name="valor" />
</div>
</div>
<div class="field">
<div class="ui checkbox" id="uf">
<input type="checkbox" name="uf" />
<label>Valor en UFs</label>
</div>
</div>
</div>
<div class="fields">
<div class="three wide field">
<label for="bancos">Banco</label>
<div class="ui search selection dropdown" id="bancos">
<input type="hidden" name="banco" />
<i class="dropdown icon"></i>
<div class="default text">Banco</div>
<div class="menu">
@foreach ($bancos as $banco)
<div class="item" data-value="{{$banco->id}}">{{$banco->nombre}}</div>
@endforeach
</div>
</div>
</div>
<div class="fields">
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="tipo" value="1" checked="checked" />
<label>Cheque</label>
</div>
</div>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="tipo" value="3" />
<label>Vale Vista</label>
</div>
</div>
</div>
</div>
<button class="ui button">Agregar</button>
</form>
@endsection
@push('page_scripts')
<script>
const escritura = {
ids: {},
add() {
return {
escritura: event => {
event.preventDefault()
const body = new FormData(event.currentTarget)
const fecha = $(this.ids.fecha).calendar('get date')
body.set('fecha', [fecha.getFullYear(), fecha.getMonth()+1, fecha.getDate()].join('-'))
const status = $(this.ids.checkbox).checkbox('is checked')
body.set('uf', status)
const url = '{{$urls->api}}/venta/{{$venta->id}}/escritura/add'
fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (json.status) {
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
}
})
})
return false
}
}
},
toggle() {
return {
checkbox: () => {
const status = $(this.ids.checkbox).checkbox('is checked')
if (status) {
return this.toggle().uf()
}
return this.toggle().pesos()
},
uf: () => {
const valor = $(this.ids.valor)
valor.attr('class', 'ui right labeled input')
valor.find('.label').remove()
valor.append(
$('<div></div>').addClass('ui basic label').html('UF')
)
},
pesos: () => {
const valor = $(this.ids.valor)
valor.attr('class', 'ui labeled input')
valor.find('.label').remove()
valor.prepend(
$('<div></div>').addClass('ui basic label').html('$')
)
}
}
},
setup(ids) {
this.ids = ids
$(this.ids.fecha).calendar(calendar_date_options)
$(this.ids.checkbox).checkbox({
fireOnInit: true,
onChange: this.toggle().checkbox
})
$(this.ids.bancos).dropdown()
$(this.ids.form).submit(this.add().escritura)
}
}
$(document).ready(() => {
escritura.setup({
form: '#add_form',
fecha: '#fecha',
checkbox: '#uf',
valor: '#valor',
bancos: '#bancos'
})
})
</script>
@endpush

View File

@ -0,0 +1,88 @@
@extends('ventas.base')
@section('venta_subtitle')
Resumen Escritura
@endsection
@section('venta_content')
<div class="ui segment">
El departamento {{$venta->propiedad()->departamentos()[0]->descripcion}}:<br />
@php
$estacionamientos = $venta->propiedad()->estacionamientos();
@endphp
@if (count($estacionamientos) === 0)
no tiene estacionamientos
@else
tiene
{{count($estacionamientos) === 1 ? 'el' : 'los'}}
estacionamiento{{count($estacionamientos) === 1 ? '': 's'}}
{{implode(', ', array_map(function(Incoviba\Model\Venta\Unidad $unidad) {
return $unidad->descripcion;
}, $estacionamientos))}}
@endif
y
@php
$bodegas = $venta->propiedad()->bodegas();
@endphp
@if (count($bodegas) === 0)
no tiene bodegas
@else
tiene
{{count($bodegas) === 1 ? 'la' : 'las'}}
bodega{{count($bodegas) === 1 ? '' : 's'}}
{{implode(', ', array_map(function(Incoviba\Model\Venta\Unidad $unidad) {
return $unidad->descripcion;
}, $bodegas))}}
@endif
<br />
<br />
<strong>PRECIO</strong>
{{$format->ufs($venta->valor)}}
<div class="ui fitted divider"></div>
<br />
@if (isset($venta->formaPago()->pie))
@php($pie = $venta->formaPago()->pie)
<strong>PIE</strong>
{{$pie->cuotas}} cuotas que suman
{{$format->pesos($pie->pagado('pesos'))}}
equivalente a
{{$format->ufs($pie->pagado())}}.
<br />
@endif
@if (isset($venta->formaPago()->escritura))
@php($escritura = $venta->formaPago()->escritura)
<strong>ESCRITURA</strong>
{{$format->pesos($escritura->pago->valor)}}
el
{{$escritura->fecha->format('d-m-Y')}}
equivalente a
{{$format->ufs($escritura->pago->valor())}}
<br />
@endif
<div class="ui fitted divider"></div>
<strong>TOTAL ANTICIPO</strong>
{{$format->ufs($venta->formaPago()->anticipo())}}
<br />
@if (isset($venta->formaPago()->bonoPie))
@php($bono = $venta->formaPago()->bonoPie)
<strong>BONO PIE</strong>
{{$format->ufs($bono->pago->valor())}}
<br />
@endif
@if (isset($venta->formaPago()->credito))
@php($credito = $venta->formaPago()->credito)
<strong>CRÉDITO</strong>
{{$format->ufs($credito->pago->valor())}}
en Banco {{$credito->pago->banco->nombre}}
<br />
@endif
<div class="ui fitted divider"></div>
<strong>TOTAL</strong>
{{$format->ufs($venta->formaPago()->total())}}
@if (($venta->formaPago()->total() - $venta->valor) !== 0)
<br />
<br />
Diferencia {{$format->ufs($venta->formaPago()->total() - $venta->valor)}}. ({{$format->percent(($venta->formaPago()->total() - $venta->valor) / $venta->valor * 100)}})
@endif
</div>
@endsection

View File

@ -0,0 +1,51 @@
@extends('ventas.base')
@section('venta_subtitle')
Escritura
@endsection
@section('venta_content')
<form class="ui form" id="edit_form">
<div class="three wide field">
<label for="fecha">Fecha</label>
<div class="ui calendar" id="fecha">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" placeholder="Fecha" />
</div>
</div>
</div>
<button class="ui button">Guardar</button>
</form>
@endsection
@push('page_scripts')
<script>
function editEscritura() {
const url = '{{$urls->api}}/ventas/escritura/{{$venta->id}}/edit'
const data = new FormData()
data.set('venta', {{$venta->id}})
const fecha = $('#fecha').calendar('get date')
data.set('fecha', fecha.toISOString())
return fetchAPI(url, {method: 'post', body: data}).then(response => {
if (response.ok) {
return response.json()
}
}).then(json => {
if (!json.edited) {
return
}
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
})
}
$(document).ready(() => {
calendar_date_options.initialDate = new Date({{$venta->currentEstado()->fecha->format('Y, m-1, j')}})
$('#fecha').calendar(calendar_date_options)
$('#edit_form').submit(event => {
event.preventDefault()
editEscritura()
return false
})
})
</script>
@endpush

View File

@ -0,0 +1,16 @@
@extends('layout.base')
@section('page_content')
<div class="ui container">
<h2 class="ui header">
Estado Venta -
{{$venta->proyecto()->descripcion}} -
<a href="{{$urls->base}}/venta/{{$venta->id}}">
{{$venta->propiedad()->summary()}}
</a>
</h2>
<h3 class="ui sub header">
{{$venta->currentEstado()->tipoEstadoVenta->descripcion}}
</h3>
</div>
@endsection

View File

@ -45,15 +45,14 @@
if (typeof this.sent.uf[date.toISOString()] !== 'undefined') {
return this.sent.uf[date.toISOString()]
}
const url = '{{$urls->api}}/money'
const url = '{{$urls->api}}/money/uf'
const data = new FormData()
data.set('provider', 'uf')
data.set('fecha', date.toISOString())
const options = {
method: 'post',
body: data
}
return this.sent.uf[date.toISOString()] = fetch(url, options).then(response => {
return this.sent.uf[date.toISOString()] = fetchAPI(url, options).then(response => {
if (response.ok) {
return response.json()
}
@ -68,14 +67,13 @@
}
const url = '{{$urls->api}}/money/ipc'
const data = new FormData()
data.set('provider', 'ipc')
data.set('start', start.toISOString())
data.set('end', end.toISOString())
const options = {
method: 'post',
body: data
}
return this.sent.ipc[dateKey] = fetch(url, options).then(response => {
return this.sent.ipc[dateKey] = fetchAPI(url, options).then(response => {
if (response.ok) {
return response.json()
}
@ -127,7 +125,7 @@
return {
unidades: () => {
const url = '{{$urls->api}}/venta/' + this.id + '/unidades'
return fetch(url).then(response => {
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
}
@ -233,7 +231,7 @@
return {
ventas: () => {
const url = '{{$urls->api}}/ventas/facturacion/proyecto/' + this.selected
return fetch(url).then(response => {
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
}

View File

@ -2,10 +2,450 @@
@section('page_content')
<div class="ui container">
<form id="venta_form">
<div class="field">
<label for=""></label>
<h2 class="ui header">
Facturación -
<a href="{{$urls->base}}/proyecto/{{$venta->proyecto()->id}}">
{{$venta->proyecto()->descripcion}}<span class="ui tiny text"><sub><i
class="search icon"></i></sub></span>
</a>
-
<a href="{{$urls->base}}/venta/{{$venta->id}}">
{{$venta->propiedad()->summary()}}
</a>
</h2>
<div class="ui very basic segment">
Valor Venta: {{$format->ufs($venta->valor)}}
</div>
<form id="venta_form" class="ui form">
<div class="two wide field">
<label for="proporcion">Proporción Factura</label>
<div class="ui right labeled input">
<input type="number" name="proporcion" id="proporcion" value="100" max="100" min="0"/>
<div class="ui basic icon label">
<i class="percent icon"></i>
</div>
</div>
</div>
<div class="fields">
@foreach ($venta->propiedad()->unidades as $unidad)
<div class="three wide field">
<label for="precio{{$unidad->pu_id}}">Precio {{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}} {{$unidad->descripcion}}</label>
<div class="ui right labeled input" id="input{{$unidad->pu_id}}">
<input class="price" type="text" name="precio{{$unidad->pu_id}}" id="precio{{$unidad->pu_id}}" data-id="{{$unidad->pu_id}}" value="{{($unidad->valor > 0) ? $unidad->valor : $unidad->precio($venta->currentEstado()->fecha)->valor}}" />
<div class="ui basic label">UF</div>
</div>
</div>
@endforeach
</div>
<div class="fields">
@foreach($venta->propiedad()->unidades as $unidad)
<div class="three wide field">
@if ($unidad->prorrateo === 0.0)
<label for="prorrateo{{$unidad->id}}">Prorrateo {{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}} {{$unidad->descripcion}}</label>
<div class="ui right labeled input" id="prorrateo{{$unidad->id}}">
<input class="prorrateo" type="text" data-id="{{$unidad->id}}" value="{{$unidad->prorrateo}}" />
<div class="ui basic label">%</div>
</div>
@endif
</div>
@endforeach
</div>
<div class="ui very basic segment" id="total_unidades"></div>
@php $lastDic = new DateTimeImmutable((new DateTimeImmutable())->sub(new DateInterval('P1Y'))->format('31-12-Y')); @endphp
@if (!isset($venta->proyecto()->terreno->fecha) or $venta->proyecto()->terreno->fecha < $lastDic)
<div class="four wide field">
<label for="terreno">Valor Terreno al {{$lastDic->format('d-m-Y')}}</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="number" id="terreno" />
</div>
</div>
@endif
</form>
@if ($venta->currentEstado()->fecha->sub(new DateInterval('P1M')) > $venta->proyecto()->terreno->fecha
and $IPC->get($venta->proyecto()->terreno->fecha, $venta->currentEstado()->fecha->sub(new DateInterval('P1M'))) === 0.0)
<div class="ui compact icon error message">
<i class="exclamation triangle icon"></i>
<div class="content">
IPC no disponible para este mes.
</div>
</div>
@endif
<div class="ui divider"></div>
<div id="factura">
<div class="ui compact grid">
<div class="two columns row">
<div class="twelve wide column">
<strong>
{{mb_strtoupper($venta->proyecto()->inmobiliaria()->nombreCompleto())}}
</strong><br/>
GIRO: <br/>
Dirección: {{$venta->proyecto()->direccion()->simple()}}
</div>
<div class="four wide column">
<div class="ui center aligned red segment">
<strong>
RUT: {{$venta->proyecto()->inmobiliaria()->rut()}}<br/>
FACTURA ELECTRÓNICA<br/>
#
</strong>
</div>
</div>
</div>
<div class="row">
<table class="ui table">
<tr>
<td class="grey"><strong>Señor(es)</strong></td>
<td>{{$venta->propietario()->nombreCompleto()}}</td>
<td class="grey"><strong>RUT</strong></td>
<td>{{$venta->propietario()->rut()}}</td>
</tr>
<tr>
<td class="grey"><strong>Giro</strong></td>
<td>Otras Actividades Profesionales</td>
<td class="grey"><strong>Fecha Emisión</strong></td>
<td>{{(new IntlDateFormatter('es-CL', IntlDateFormatter::LONG, IntlDateFormatter::NONE))->format($venta->currentEstado()->fecha)}}</td>
</tr>
<tr>
<td class="grey"><strong>Dirección</strong></td>
<td>{{$venta->propietario()->datos->direccion->simple()}}</td>
<td class="grey"><strong>Comuna</strong></td>
<td>{{mb_strtoupper($venta->propietario()->datos->direccion->comuna->descripcion)}}</td>
</tr>
</table>
</div>
<div class="row">
<table class="ui celled table">
<thead>
<tr class="grey">
<th class="center aligned" colspan="6">DETALLES</th>
</tr>
<tr class="grey">
<th></th>
<th class="center aligned">Descripción</th>
<th class="center aligned">Cant/Unidad</th>
<th class="center aligned">Prec. Unit.</th>
<th class="center aligned">Ind</th>
<th class="center aligned">Total</th>
</tr>
</thead>
<tbody id="unidades"></tbody>
<tfoot>
<tr>
<td colspan="6">
<br />
<br />
<br />
<br />
</td>
</tr>
</tfoot>
</table>
</div>
<div class="row">
<div class="ten wide column"></div>
<div class="six wide column">
<table class="ui celled very compact table">
<thead>
<tr>
<th class="center aligned grey" colspan="2">TOTALES</th>
</tr>
</thead>
<tbody>
<tr>
<td class="grey">Monto Neto</td>
<td class="right aligned" id="neto"></td>
</tr>
<tr>
<td class="grey">Monto Exento</td>
<td class="right aligned" id="exento"></td>
</tr>
<tr>
<td class="grey">19% IVA</td>
<td class="right aligned" id="iva"></td>
</tr>
<tr>
<td class="grey">Monto Total</td>
<td class="right aligned"><strong id="total"></strong></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
@endsection
@push('page_scripts')
<script>
const factura = {
id: '#unidades',
totales: {},
proporcion: 1,
precio: {{$UF->transform($venta->currentEstado()->fecha, $venta->valor)}},
terreno: {{(isset($venta->proyecto()->terreno->fecha) and $venta->proyecto()->terreno->fecha >= $lastDic) ?
$IPC->readjust($venta->proyecto()->terreno->valor, $venta->proyecto()->terreno->fecha, $venta->currentEstado()->fecha) : 0}},
uf: {{$UF->get($venta->currentEstado()->fecha)}},
unidades: JSON.parse('{!! json_encode(array_map(function(Incoviba\Model\Venta\PropiedadUnidad $unidad) use ($venta, $UF, $format) {
$precio = ($unidad->valor > 0) ? $unidad->valor : ($unidad->precio($venta->currentEstado()->fecha) ? $unidad->precio($venta->currentEstado()->fecha)->valor : 0);
return [
'id' => $unidad->id,
'pid' => $unidad->pu_id,
'descripcion' => ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion) . ' ' . $unidad->descripcion,
'precio' => $precio,
'base' => $UF->transform($venta->currentEstado()->fecha, $precio),
'prorrateo' => $unidad->prorrateo,
];
}, $venta->propiedad()->unidades)) !!}'),
build: function() {
const tbody = $(this.id)
tbody.html('')
const pesoFormatter = new Intl.NumberFormat('es-CL', {maximumFractionDigits: 0, minimumFractionDigits: 0})
const ufFormatter = new Intl.NumberFormat('es-CL', {maximumFractionDigits: 2, minimumFractionDigits: 2})
const percentFormatter = new Intl.NumberFormat('es-CL', {maximumFractionDigits: 5, minimumFractionDigits: 5})
let terreno = 0
let prorrateo = 0
let totalUnidades = 0
let precioUnidades = 0
let c = 1
const classes = [
'',
'',
'center aligned',
'right aligned',
'center aligned',
'right aligned'
]
this.unidades.forEach(unidad => {
totalUnidades += unidad.base
precioUnidades += unidad.precio
const descuento = this.terreno * unidad.prorrateo
terreno += descuento
prorrateo += unidad.prorrateo
const bruto = unidad.base - descuento
const neto = bruto / 1.19
const data = [
c ++,
unidad.descripcion + ' (UF ' + ufFormatter.format(unidad.precio * this.proporcion) + ')',
'1 UNID',
pesoFormatter.format(neto * this.proporcion),
'AF',
pesoFormatter.format(neto * this.proporcion)
]
const row = $('<tr></tr')
data.forEach((value, i) => {
const cell = $('<td></td>')
if (classes[i] !== '') {
cell.addClass(classes[i])
}
cell.html(value)
row.append(cell)
})
tbody.append(row)
})
$('#total_unidades')
.attr('class', 'ui compact segment ' + ((totalUnidades.toFixed(2) !== this.precio.toFixed(2)) ? 'inverted red' : 'inverted green'))
.html('Total Unidades: ' + ufFormatter.format(precioUnidades) + ' UF' +
((totalUnidades.toFixed(2) !== this.precio.toFixed(2)) ? '; Diferencia: ' + ufFormatter.format({{$venta->valor}} - precioUnidades) + ' UF' : ''))
if (totalUnidades.toFixed(2) !== this.precio.toFixed(2)) {
this.highlight()
}
const bruto = this.precio - terreno
const base = bruto / 1.19
const iva = base * .19
const subtotal = base + iva
const total = subtotal + terreno
const totalUF = total / this.uf
const emptyTerreno = '<div class="ui tiny red horizontal circular label">0</div>'
const data = [
c,
'Valor con Terreno ' + pesoFormatter.format((base + terreno) * this.proporcion) + ' - Menos valor terreno ' + ((terreno > 0) ? pesoFormatter.format(-terreno * this.proporcion) : emptyTerreno) + '<br />' +
'Base imponible ' + pesoFormatter.format(base * this.proporcion) + '<br />' +
'IVA ' + pesoFormatter.format(iva * this.proporcion) + '<br />' +
'SUBTOTAL ' + pesoFormatter.format(subtotal * this.proporcion) + '<br />' +
'Mas valor terreno ' + ((terreno > 0) ? pesoFormatter.format(terreno * this.proporcion) : emptyTerreno) + '<br />' +
'TOTAL ' + pesoFormatter.format(total * this.proporcion) + ';' + ufFormatter.format(totalUF * this.proporcion) + ' UF<br /><br />' +
'Descuento Terreno: ' + ((terreno > 0) ? percentFormatter.format(prorrateo * 100) : emptyTerreno) + '%<br /><br />' +
'UF: ' + ufFormatter.format(this.uf),
'1 UNID',
pesoFormatter.format(terreno * this.proporcion),
'EX',
pesoFormatter.format(terreno * this.proporcion)
]
const row = $('<tr></tr>').addClass('top aligned')
data.forEach((value, i) => {
const cell = $('<td></td>')
if (classes[i] !== '') {
cell.addClass(classes[i])
}
cell.html(value)
row.append(cell)
})
tbody.append(row)
$(this.totales.afecto).html(pesoFormatter.format(base * this.proporcion))
$(this.totales.exento).html(pesoFormatter.format(terreno * this.proporcion))
$(this.totales.iva).html(pesoFormatter.format(iva * this.proporcion))
$(this.totales.total).html(pesoFormatter.format(total * this.proporcion))
},
update: function() {
return {
price: (id, value) => {
this.unhighlight()
const idx = this.unidades.findIndex(unidad => unidad.pid === id)
if (idx === -1) {
return
}
const old_value = this.unidades[idx].precio
if (old_value === parseFloat(value)) {
return
}
const url = '{{$urls->api}}/ventas/propiedades/unidad/' + id + '/edit'
const data = new FormData()
data.set('valor', value)
return fetchAPI(url, {method: 'post', body: data}).then(response => {
if (response.ok) {
return response.json()
}
}).then(json => {
if (!json.edited) {
return
}
const idx = this.unidades.findIndex(unidad => unidad.pid === json.propiedad_unidad_id)
this.unidades[idx].precio = parseFloat(json.input.valor)
this.unidades[idx].base = parseFloat(json.input.valor * this.unidades[idx].base / old_value)
this.build()
})
},
terreno: value => {
const url = '{{$urls->api}}/proyecto/{{$venta->proyecto()->id}}/terreno/edit'
const data = new FormData()
data.set('valor', value)
data.set('fecha', '{{$lastDic->format('Y-m-d')}}')
return fetchAPI(url, {method: 'post', body: data}).then(response => {
if (response.ok) {
return response.json()
}
}).then(json => {
if (!json.edited) {
return
}
this.terreno = parseInt(json.input.valor)
const data = new FormData()
data.set('start', '{{$lastDic->format('Y-m-d')}}')
data.set('end', '{{$venta->currentEstado()->fecha->sub(new DateInterval('P1M'))->format('Y-m-d')}}')
const url = '{{$urls->api}}/money/ipc'
return fetchAPI(url, {method: 'post', body: data}).then(response => {
if (response.ok) {
return response.json()
}
}).then(json => {
this.terreno *= (1 + parseFloat(json.ipc))
this.build()
})
})
},
prorrateo: (id, value) => {
if (parseFloat(value) === 0) {
return
}
const url = '{{$urls->api}}/ventas/unidad/' + id + '/prorrateo'
const data = new FormData()
data.set('prorrateo', value)
return fetchAPI(url, {method: 'post', body: data}).then(response => {
if (response.ok) {
return response.json()
}
}).then(json => {
if (!json.edited) {
return
}
const idx = this.unidades.findIndex(unidad => unidad.id === json.unidad_id)
this.unidades[idx].prorrateo = parseFloat(json.input.prorrateo)
this.build()
})
}
}
},
watch: function() {
return {
proporcion: id => {
$(id).change(event => {
const val = $(event.currentTarget).val()
if (val / 100 === this.proporcion) {
return
}
this.proporcion = val / 100
this.build()
})
},
prices: class_name => {
$(class_name).change(event => {
const val = $(event.currentTarget).val()
const id = $(event.currentTarget).data('id')
this.update().price(id, val)
})
},
prorrateo: class_name => {
$(class_name).change(event => {
const val = $(event.currentTarget).val()
const id = $(event.currentTarget).data('id')
this.update().prorrateo(id, val)
})
},
terreno: id => {
$(id).change(event => {
const val = $(event.currentTarget).val()
this.update().terreno(val).then(() => {
$(id).parent().parent().hide()
})
})
}
}
},
highlight: function() {
const pid = this.unidades[0].pid
const input = $('#input' + pid)
input.addClass('error')
input.find('.label').addClass('red')
input.attr('data-content', 'Valor total no es igual a valor de venta')
input.popup()
},
unhighlight: function() {
const pid = this.unidades[0].pid
const input = $('#input' + pid)
input.removeClass('error')
input.find('.label').removeClass('red')
input.removeAttr('data-content')
},
setup: function({form_id, tbody_id, input_id, prices_class, prorrateo_class, terreno_id, totales_ids}) {
$(form_id).submit(event => {
event.preventDefault()
return false
})
this.id = tbody_id
this.totales = totales_ids
this.proporcion = $(input_id).val() / 100
this.watch().proporcion(input_id)
this.watch().prices(prices_class)
this.watch().prorrateo(prorrateo_class)
@if (!isset($venta->proyecto()->terreno->fecha) or $venta->proyecto()->terreno->fecha <= $lastDic)
this.watch().terreno(terreno_id)
@endif
this.build()
}
}
$(document).ready(() => {
factura.setup({form_id: '#venta_form', tbody_id: '#unidades', input_id: '#proporcion',
prices_class: '.price', prorrateo_class: '.prorrateo', terreno_id: '#terreno', totales_ids: {
afecto: '#neto',
exento: '#exento',
iva: '#iva',
total: '#total'
}})
})
</script>
@endpush

View File

@ -103,7 +103,7 @@
ventas: proyecto_id => {
this.data.venta_ids = []
this.data.ventas = []
return fetch('{{$urls->api}}/ventas',
return fetchAPI('{{$urls->api}}/ventas',
{method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}
).then(response => {
this.loading.precios = false
@ -112,15 +112,20 @@
}
}).then(data => {
if (data.total > 0) {
const progress = this.draw().progress(data.ventas.length)
this.data.id = data.proyecto.id
this.data.proyecto = data.proyecto.descripcion
this.data.venta_ids = data.ventas
const chunkSize = 50
const chunks = []
for (let i = 0; i < data.ventas.length; i += chunkSize) {
chunks.push(data.ventas.splice(i, i + chunkSize))
}
const promises = []
data.ventas.forEach(venta_id => {
const promise = this.get().venta(venta_id)
/*promise.then(() => {
this.draw().ventas(true)
})*/
chunks.forEach(chunk => {
const promise = this.get().venta(chunk).then(count => {
progress.progress('increment', count)
})
promises.push(promise)
})
Promise.all(promises).then(() => {
@ -129,17 +134,22 @@
}
})
},
venta: venta_id => {
return fetch('{{$urls->api}}/venta/' + venta_id).then(response => {
venta: chunk => {
const body = new FormData()
body.set('ventas', chunk.join(','))
return fetchAPI('{{$urls->api}}/ventas/get', {method: 'post', body}).then(response => {
if (response.ok) {
return response.json()
}
}).then(data => {
if (typeof data.venta === 'undefined') {
console.error(venta_id, data.error)
if (data.ventas.length === 0) {
console.error(chunk, data.error)
return
}
this.add().venta(data.venta)
data.ventas.forEach(venta_id => {
this.add().venta(venta_id)
})
return data.ventas.length
})
}
}
@ -185,6 +195,26 @@
parent.show()
parent.find('.item.proyecto').click(this.actions().get)
},
progress: cantidad => {
const parent = $(this.ids.proyectos)
parent.html('')
const progress = $('<div></div>').addClass('ui active progress').append(
$('<div></div>').addClass('bar').append(
$('<div></div>').addClass('centered progress')
)
).append(
$('<div></div>').addClass('label').html('Cargando datos')
)
progress.progress({
total: cantidad,
label: 'ratio',
text: {
ratio: '{value} de {total} ({percent}%)'
}
})
parent.append(progress)
return progress
},
ventas: (loading = false) => {
const title = $(this.ids.title)
const parent = $(this.ids.proyectos)
@ -214,6 +244,7 @@
this.table = new DataTable(table, {
order: [[0, 'asc']],
pageLength: 50
})
},
table: () => {

View File

@ -34,7 +34,7 @@
return {
pagos: () => {
const uri = '{{$urls->api}}/ventas/pagos/pendientes'
fetch(uri).then(response => {
return fetchAPI(uri).then(response => {
if (response.ok) {
return response.json()
}
@ -138,7 +138,7 @@
return {
pendientes: () => {
const uri = '{{$urls->api}}/ventas/pagos/abonar'
fetch(uri).then(response => {
return fetchAPI(uri).then(response => {
if (response.ok) {
return response.json()
}
@ -218,7 +218,7 @@
return {
devueltos: () => {
const uri = '{{$urls->api}}/ventas/pagos/rebotes'
fetch(uri).then(response => {
return fetchAPI(uri).then(response => {
if (response.ok) {
return response.json()
}

View File

@ -1,58 +1,266 @@
@extends('layout.base')
@extends('ventas.base')
@section('page_content')
<div class="ui container">
<div class="ui two column grid">
<h1 class="four wide column header">
<div class="content">
<div class="ui dividing sub header">{{$venta->proyecto()->descripcion}}</div>
{{$venta->propiedad()->summary()}}
</div>
</h1>
</div>
<h2>Cuotas - Pie</h2>
<table class="ui table" id="cuotas">
<thead>
<tr>
<th>#</th>
<th>Fecha</th>
<th>Fecha ISO</th>
<th>Banco</th>
<th>Identificador</th>
<th>Valor</th>
</tr>
</thead>
<tbody>
@foreach ($venta->formaPago()->pie->cuotas() as $cuota)
<tr>
<td>{{$cuota->numero}}</td>
<td>
{{$cuota->pago->fecha->format('d-m-Y')}}
</td>
<td>
{{$cuota->pago->fecha->format('Y-m-d')}}
</td>
<td>
{{$cuota->pago->banco->nombre}}
</td>
<td>
{{$cuota->pago->identificador}}
</td>
<td>
{{$format->pesos($cuota->pago->valor)}}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@section('venta_subtitle')
Cuotas - Pie
@endsection
@section('venta_content')
<table class="ui table" id="cuotas">
<thead>
<tr>
<th>#</th>
<th>Fecha</th>
<th>Fecha ISO</th>
<th>Banco</th>
<th>Identificador</th>
<th class="right aligned">Valor</th>
<th class="right aligned">Valor UF</th>
<th>Estado</th>
<th>Fecha Estado</th>
<th>Fecha Estado ISO</th>
<th></th>
</tr>
</thead>
<tbody>@php
$now = new DateTimeImmutable();
$uf_venta = $venta->uf === 0.0 ? $UF->get($venta->currentEstado()->fecha) : $venta->uf;
@endphp
@foreach ($venta->formaPago()->pie->cuotas() as $cuota)
<tr data-pago="{{$cuota->pago->id}}"
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['anulado', 'reemplazado']))
class="disabled"
@endif >
<td>{{$cuota->numero}}</td>
<td>{{$cuota->pago->fecha->format('d-m-Y')}}</td>
<td>{{$cuota->pago->fecha->format('Y-m-d')}}</td>
<td>{{$cuota->pago->banco->nombre}}</td>
<td>{{$cuota->pago->identificador}}</td>
<td class="right aligned">{{$format->pesos($cuota->pago->valor)}}</td>
<td class="right aligned">
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado' and $cuota->pago->currentEstado->fecha <= $now)
{{$format->ufs($cuota->pago->valor())}}
@endif
</td>
<td
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado')
class="green"
@elseif ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
class="yellow"
@elseif ($cuota->pago->currentEstado->tipoEstadoPago->activo !== 1)
class="red"
@endif
>{{ucwords($cuota->pago->currentEstado->tipoEstadoPago->descripcion)}}</td>
<td>
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['abonado', 'anulado', 'reemplazado']))
{{$cuota->pago->currentEstado->fecha->format('d-m-Y')}}
@elseif (!in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['anulado', 'reemplazado']))
<div class="ui calendar fecha_estado" data-date="{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}">
<div class="ui action left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha_estado" />
<button class="ui green basic icon button accept_estado" data-pago="{{$cuota->pago->id}}" data-estado="{{$cuota->pago->currentEstado->tipoEstadoPago->descripcion}}">
<i class="check icon"></i>
</button>
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
<button class="ui red basic icon button reject_estado" data-pago="{{$cuota->pago->id}}">
<i class="remove icon"></i>
</button>
@endif
</div>
</div>
@endif
</td>
<td>{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}</td>
<td>
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion !== 'anulado')
<button class="ui mini red icon basic button anular" data-pago="{{$cuota->pago->id}}">
<i class="remove icon"></i>
</button>
@endif
</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<th colspan="5">TOTAL</th>
<th class="right aligned">
{{$format->pesos($total_pesos = array_reduce($venta->formaPago()->pie->cuotas(),
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) {
return $sum + $cuota->pago->valor;
}, 0))}}
</th>
<th class="right aligned">
{{$format->ufs($total = array_reduce($venta->formaPago()->pie->cuotas(),
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) use ($now, $uf_venta) {
return $sum + (($cuota->pago->fecha > $now or $cuota->pago->uf === null) ?
$cuota->pago->valor / $uf_venta :
$cuota->pago->valor());
}, 0.0))}}
</th>
<th colspan="4"></th>
</tr>
<tr>
<th colspan="5">TOTAL PAGADO</th>
<th class="right aligned">
{{$format->pesos($pagado_pesos = array_reduce($venta->formaPago()->pie->cuotas(true),
function(int $sum, Incoviba\Model\Venta\Cuota $cuota) {
return $sum + $cuota->pago->valor;
}, 0))}}
</th>
<th class="right aligned">
{{$format->ufs($pagado = array_reduce($venta->formaPago()->pie->cuotas(true),
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) {
return $sum + $cuota->pago->valor();
}, 0.0))}}
</th>
<th class="right aligned">
{{$format->number($pagado / $total * 100, 2)}}%
</th>
<th colspan="3"></th>
</tr>
<tr>
<th colspan="5">POR PAGAR</th>
<th class="right aligned">
{{$format->pesos($total_pesos - $pagado_pesos)}}
</th>
<th class="right aligned">
{{$format->ufs($total - $pagado)}}
</th>
<th class="right aligned">
{{$format->number(($total - $pagado) / $total * 100, 2)}}%
</th>
<th colspan="3"></th>
</tr>
</tfoot>
</table>
@endsection
@include('layout.head.styles.datatables')
@include('layout.head.styles.datatables.buttons')
@include('layout.body.scripts.datatables')
@include('layout.body.scripts.datatables.buttons')
@push('page_scripts')
<script type="text/javascript">
$(document).ready(() => {
function updateRow({pago_id, fecha, color, estado, remove_fecha=false, add_reject=false, disable=false}) {
const tr = $("tr[data-pago='" + pago_id + "']")
tr.find(':nth-child(7)').attr('class', color).html(estado)
if (remove_fecha) {
tr.find(':nth-child(8)').html(fecha)
}
if (add_reject) {
tr.find(':nth-child(8)>.calendar>.input').append(
$('<button></button>').addClass('ui red basic icon button reject_estado').attr('data-pago', pago_id).append(
$('<i></i>').addClass('remove icon')
).click(event => {
const target = $(event.currentTarget)
const pago_id = target.data('pago')
const fecha = target.parent().parent().calendar('get date')
devolver(target, pago_id, fecha)
})
)
}
if (disable) {
tr.addClass('disabled')
tr.find(':nth-child(9)').html('')
}
return tr
}
function depositar(button, pago_id, fecha) {
const url = '{{$urls->api}}/ventas/pago/' + pago_id + '/depositar'
const body = new FormData()
body.set('fecha', fecha.toISOString())
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (!json.depositado) {
return
}
updateRow({pago_id: json.pago_id, fecha: json.input.fecha, estado: 'Depositado', color: 'yellow', add_reject: true})
button.attr('data-estado', 'depositado')
})
})
}
function abonar(pago_id, fecha) {
const url = '{{$urls->api}}/ventas/pago/' + pago_id + '/abonar'
const body = new FormData()
body.set('fecha', fecha.toISOString())
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (!json.abonado) {
return
}
updateRow({pago_id: json.pago_id, fecha: json.input.fecha, estado: 'Abonado', color: 'green', remove_fecha: true})
})
})
}
function anular(pago_id) {
const url = '{{$urls->api}}/ventas/pago/' + pago_id + '/anular'
return fetchAPI(url).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (!json.anulado) {
return
}
updateRow({pago_id: json.pago_id, fecha: json.fecha, estado: 'Anulado', color: 'red', remove_fecha: true, disable: true})
})
})
}
function devolver(button, pago_id, fecha) {
const url = '{{$urls->api}}/ventas/pago/' + pago_id + '/devolver'
const body = new FormData()
body.set('fecha', fecha.toISOString())
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (!json.devuelto) {
return
}
updateRow({pago_id: json.pago_id, fecha: json.input.fecha, estado: 'Devuelto', color: 'red'})
button.parent().find('.accept_estado').attr('data-estado', 'devuelto')
button.remove()
})
})
}
$('.fecha_estado').calendar({
type: 'date',
formatter: {
date: 'DD-MM-YYYY'
}
})
$('.accept_estado').click(event => {
const target = $(event.currentTarget)
const pago_id = target.data('pago')
const fecha = target.parent().parent().calendar('get date')
if (target.attr('data-estado') === 'depositado') {
return abonar(pago_id, fecha)
}
return depositar(target, pago_id, fecha)
})
$('.reject_estado').click(event => {
const target = $(event.currentTarget)
const pago_id = target.data('pago')
const fecha = target.parent().parent().calendar('get date')
devolver(target, pago_id, fecha)
})
$('.anular').click(event => {
const pago_id = $(event.currentTarget).data('pago')
anular(pago_id)
})
new DataTable('#cuotas', {
language: {
info: 'Mostrando página _PAGE_ de _PAGES_',
@ -62,17 +270,47 @@
zeroRecords: 'No se encotró cuotas con ese criterio',
search: 'Buscar: '
},
pageLength: "25",
columnDefs: [
{
target: 1,
orderData: [2]
},
{
target: 2,
visible: false,
searchable: false
},
{
target: 8,
orderData: [9]
},
{
target: 9,
visible: false,
searchable: false
}
],
order: [
[0, 'asc'],
[2, 'asc']
]
],
layout: {
top2End: {
buttons: [
{
extend: 'excel',
className: 'green',
text: 'Exportar a Excel <i class="file excel icon"></i>',
title: 'Cuotas - {{$venta->proyecto()->descripcion}} - {{$venta->propiedad()->summary()}}',
download: 'open',
exportOptions: {
columns: ':visible'
}
}
]
}
}
})
})
</script>

View File

@ -1,93 +1,86 @@
@extends('layout.base')
@extends('ventas.base')
@section('page_content')
<div class="ui container">
<div class="ui two column grid">
<h1 class="four wide column header">
<div class="content">
<div class="ui dividing sub header">{{$venta->proyecto()->descripcion}}</div>
{{$venta->propiedad()->summary()}}
</div>
</h1>
</div>
<h2>Agregar Cuotas - Pie</h2>
<form class="ui form" id="add_form" action="{{$urls->base}}/ventas/pie/{{$pie->id}}/cuotas/add" method="post">
<table class="ui table">
<thead>
<tr>
<th>#</th>
<th>Fecha</th>
<th>Banco</th>
<th>Identificador</th>
<th>Valor</th>
</tr>
</thead>
<tbody id="cuotas">
@for ($i = count($pie->cuotas()); $i < $pie->cuotas - count($pie->cuotas()); $i ++)
<tr>
<td>{{$i + 1}}</td>
<td>
<div class="inline field">
<div class="ui calendar fecha" data-index="{{$i}}">
<div class="ui icon input">
<input type="text" name="fecha{{$i}}" />
<i class="calendar icon"></i>
</div>
</div>
<button class="ui mini compact basic icon button copy fecha" type="button" data-index="{{$i}}">
<i class="down arrow icon"></i>
</button>
</div>
</td>
<td>
<div class="ui search selection dropdown banco" data-index="{{$i}}">
<input type="hidden" name="banco{{$i}}" />
<i class="dropdown icon"></i>
<div class="default text">Banco</div>
<div class="menu">
@foreach ($bancos as $banco)
@if ($banco->nombre === '')
@continue
@endif
<div class="item" data-value="{{$banco->id}}">{{$banco->nombre}}</div>
@endforeach
@section('venta_subtitle')
Agregar Cuotas - Pie
@endsection
@section('venta_content')
<form class="ui form" id="add_form" action="{{$urls->base}}/ventas/pie/{{$pie->id}}/cuotas/add" method="post">
<table class="ui table">
<thead>
<tr>
<th>#</th>
<th>Fecha</th>
<th>Banco</th>
<th>Identificador</th>
<th>Valor</th>
</tr>
</thead>
<tbody id="cuotas">
@for ($i = count($pie->cuotas(vigentes: true)); $i < $pie->cuotas; $i ++)
<tr>
<td>{{$i + 1}}</td>
<td>
<div class="inline field">
<div class="ui calendar fecha" data-index="{{$i}}">
<div class="ui icon input">
<input type="text" name="fecha{{$i}}" />
<i class="calendar icon"></i>
</div>
</div>
<button class="ui mini compact basic icon button copy banco" type="button" data-index="{{$i}}">
<button class="ui mini compact basic icon button copy fecha" type="button" data-index="{{$i}}">
<i class="down arrow icon"></i>
</button>
</td>
<td>
<div class="ui input">
<input type="text" name="identificador{{$i}}" />
</div>
</td>
<td>
<div class="ui search selection dropdown banco" data-index="{{$i}}">
<input type="hidden" name="banco{{$i}}" />
<i class="dropdown icon"></i>
<div class="default text">Banco</div>
<div class="menu">
@foreach ($bancos as $banco)
@if ($banco->nombre === '')
@continue
@endif
<div class="item" data-value="{{$banco->id}}">{{$banco->nombre}}</div>
@endforeach
</div>
</td>
<td>
<div class="inline field">
<div class="ui left labeled input">
<div class="ui label">$</div>
<input type="text" name="valor{{$i}}" />
</div>
<button class="ui mini compact basic icon button copy valor" type="button" data-index="{{$i}}">
<i class="down arrow icon"></i>
</button>
</div>
<button class="ui mini compact basic icon button copy banco" type="button" data-index="{{$i}}">
<i class="down arrow icon"></i>
</button>
</td>
<td>
<div class="ui input">
<input type="text" name="identificador{{$i}}" />
</div>
</td>
<td>
<div class="inline field">
<div class="ui left labeled input">
<div class="ui label">$</div>
<input type="text" name="valor{{$i}}" />
</div>
</td>
</tr>
@endfor
</tbody>
<tfoot>
<tr>
<td colspan="5">
<button class="ui button" type="submit">
Agregar
<button class="ui mini compact basic icon button copy valor" type="button" data-index="{{$i}}">
<i class="down arrow icon"></i>
</button>
</td>
</tr>
</tfoot>
</table>
</form>
</div>
</div>
</td>
</tr>
@endfor
</tbody>
<tfoot>
<tr>
<td colspan="5">
<button class="ui button" type="submit">
Agregar
</button>
</td>
</tr>
</tfoot>
</table>
</form>
@endsection
@include('layout.body.scripts.dayjs')
@ -112,7 +105,7 @@
const index = $(event.currentTarget).data('index')
const calendar = $(".fecha.calendar[data-index='" + index + "']")
const fecha = calendar.calendar('get date')
for (let i = index + 1; i < {{$pie->cuotas - count($pie->cuotas())}}; i ++) {
for (let i = index + 1; i < {{$pie->cuotas}}; i ++) {
setDate(i - index, $(".fecha.calendar[data-index='" + i + "']"), fecha)
}
})
@ -120,7 +113,7 @@
$('.copy.banco').click(event => {
const index = $(event.currentTarget).data('index')
const banco = $(".banco.dropdown[data-index='" + index + "']").dropdown('get value')
for (let i = index + 1; i < {{$pie->cuotas - count($pie->cuotas())}}; i ++) {
for (let i = index + 1; i < {{$pie->cuotas}}; i ++) {
$(".banco.dropdown[data-index='" + i + "']").dropdown('set selected', banco)
}
})
@ -133,7 +126,7 @@
$('.copy.valor').click(event => {
const index = $(event.currentTarget).data('index')
const valor = $("[name='valor" + index + "']").val()
for (let i = index + 1; i < {{$pie->cuotas - count($pie->cuotas())}}; i ++) {
for (let i = index + 1; i < {{$pie->cuotas}}; i ++) {
$("[name='valor" + i + "']").val(valor)
}
})

View File

@ -0,0 +1,43 @@
@extends('ventas.base')
@section('venta_subtitle')
Pie
@endsection
@section('venta_content')
<form class="ui form" id="edit_pie">
<div class="three wide field">
<label for="valor">Valor</label>
<div class="ui right labeled input">
<input type="text" name="valor" id="valor" value="{{$venta->formaPago()->pie->valor}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="three wide field">
<label for="cuotas"># Cuotas</label>
<input type="number" name="cuotas" id="cuotas" value="{{$venta->formaPago()->pie->cuotas}}" />
</div>
<button class="ui button">Editar</button>
</form>
@endsection
@push('page_scripts')
<script>
$(document).ready(() => {
$('#edit_pie').submit(event => {
event.preventDefault()
const data = new FormData(event.currentTarget)
fetchAPI('{{$urls->api}}/ventas/pie/{{$venta->formaPago()->pie->id}}/edit', {method: 'post', body: data}).then(response => {
if (response.ok) {
return response.json()
}
}).then(json => {
if (json.edited) {
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
}
})
return false
})
})
</script>
@endpush

View File

@ -339,7 +339,7 @@
$(this.ids.buttons.add).hide()
return fetch('{{$urls->api}}/proyectos').then(response => {
return fetchAPI('{{$urls->api}}/proyectos').then(response => {
if (response.ok) {
return response.json()
}
@ -357,7 +357,7 @@
},
precios: proyecto_id => {
this.data.precios = []
return fetch('{{$urls->api}}/ventas/precios',
return fetchAPI('{{$urls->api}}/ventas/precios',
{method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}
).then(response => {
$('.item.proyecto').css('cursor', 'default')
@ -639,7 +639,7 @@
fecha: $(this.ids.fields.calendar).calendar('get date'),
valor: $(this.ids.fields.valor).val()
}
return fetch('{{$urls->api}}/precios/update',
return fetchAPI('{{$urls->api}}/precios/update',
{method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)}
).then(response => {
if (response.ok) {

View File

@ -2,12 +2,18 @@
@section('page_content')
<div class="ui container">
<h2>Editar Propiedad - {{$proyecto->descripcion}} {{$propiedad->summary()}}</h2>
<h2 class="ui header">
Editar Propiedad - {{$proyecto->descripcion}}
<a href="{{$urls->base}}/venta/{{$venta->id}}">
{{$propiedad->summary()}}
</a>
</h2>
<table class="ui table">
<thead>
<tr>
<th>Tipo</th>
<th>Unidad</th>
<th>Valor</th>
<th class="right aligned">
<button class="ui small green circular icon button" id="add_unidad">
<i class="plus icon"></i>
@ -15,13 +21,19 @@
</th>
</tr>
</thead>
<tbody>
<tbody id="unidades">
@foreach($propiedad->unidades as $unidad)
<tr>
<td>{{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}</td>
<td>{{$unidad->descripcion}}</td>
<td>
<div class="ui right labeled input">
<input type="text" name="precio{{$unidad->pu_id}}" class="precio" data-pid="{{$unidad->pu_id}}" value="{{($unidad->valor > 0) ? $unidad->valor : $unidad->precio($venta->fecha)->valor}}" />
<div class="ui basic label">UF</div>
</div>
</td>
<td class="right aligned">
<button class="ui small red circular icon button remove_unidad" data-id="{{$unidad->id}}">
<button class="ui small red circular icon button remove_unidad" data-pid="{{$unidad->pu_id}}">
<i class="remove icon"></i>
</button>
</td>
@ -33,7 +45,7 @@
<div class="ui modal" id="add_modal">
<div class="content">
<h3 class="header">Agregar</h3>
<div class="ui form" id="add_form">
<form class="ui form" id="add_form">
<div class="field">
<label for="tipo">Tipo</label>
<select id="tipo" name="tipo" class="ui search selection dropdown">
@ -46,59 +58,195 @@
<label for="unidad">Unidad</label>
<select id="unidad" name="unidad" class="ui search selection dropdown" size="4"></select>
</div>
<button class="ui button">Agregar</button>
</div>
<div class="field">
<label for="valor">Valor Venta</label>
<input id="valor" type="text" name="valor" />
</div>
</form>
</div>
<div class="actions">
<button class="ui approve button">Agregar</button>
</div>
</div>
@endsection
@push('page_scripts')
<script type="text/javascript">
const unidades = {
@foreach($tiposUnidades as $tipoUnidad)
{{$tipoUnidad->id}}: [
@foreach($unidades as $unidad)
@if ($unidad->proyectoTipoUnidad->tipoUnidad->id === $tipoUnidad->id)
{
value: {{$unidad->id}},
text: '{{$unidad->descripcion}}',
name: '{{$unidad->descripcion}}'
},
@endif
const propiedad = {
unidades: [
@foreach($propiedad->unidades as $unidad)
{
id: {{$unidad->id}},
tipo: '{{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}',
tipo_id: {{$unidad->proyectoTipoUnidad->tipoUnidad->id}},
descripcion: '{{$unidad->descripcion}}',
pid: {{$unidad->pu_id}},
valor: {{($unidad->valor > 0) ? $unidad->valor : $unidad->precio($venta->fecha)->valor}}
},
@endforeach
],
@endforeach
}
function changeTipoUnidad(tipo_unidad_id) {
$('#unidad').dropdown('change values', unidades[tipo_unidad_id].sort((a, b) => a.text.padStart(4, '0').localeCompare(b.text.padStart(4, '0'))))
}
function addUnidad() {
$('#add_modal').modal('show')
}
function removeUnidad(unidad_id) {
console.debug(unidad_id)
tipos: {
@foreach($tiposUnidades as $tipoUnidad)
{{$tipoUnidad->id}}: [
@foreach($unidades as $unidad)
@if ($unidad->proyectoTipoUnidad->tipoUnidad->id === $tipoUnidad->id)
{
value: {{$unidad->id}},
text: '{{$unidad->descripcion}}',
name: '{{$unidad->descripcion}}'
},
@endif
@endforeach
],
@endforeach
},
changeTipoUnidad: function(tipo_unidad_id) {
$('#unidad').dropdown('change values', this.tipos[tipo_unidad_id].sort((a, b) => a.text.padStart(4, '0').localeCompare(b.text.padStart(4, '0'))))
},
addUnidad: function() {
$('#add_modal').modal('show')
},
doAddUnidad: function() {
const url = '{{$urls->api}}/ventas/propiedades/unidades/add'
const data = new FormData(document.getElementById('add_form'))
data.set('propiedad', {{$propiedad->id}})
return fetchAPI(url, {method: 'post', body: data}).then(response => {
if (response.ok) {
return response.json()
}
}).then(json => {
if (!json.added) {
return
}
const tipo = json.propiedad_unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
this.unidades.push({
id: json.propiedad_unidad.id,
tipo: tipo.charAt(0).toUpperCase() + tipo.slice(1),
tipo_id: json.propiedad_unidad.proyecto_tipo_unidad.tipo_unidad.id,
descripcion: json.propiedad_unidad.descripcion,
pid: json.propiedad_unidad.pu_id,
valor: parseFloat(json.propiedad_unidad.valor)
})
this.draw()
const idx = this.tipos[json.propiedad_unidad.proyecto_tipo_unidad.tipo_unidad.id].findIndex(unidad => unidad.value === json.propiedad_unidad.id)
this.tipos[json.propiedad_unidad.proyecto_tipo_unidad.tipo_unidad.id].splice(idx,1)
})
},
removeUnidad: function(unidad_id) {
const url = '{{$urls->api}}/ventas/propiedades/unidad/' + unidad_id
return fetchAPI(url, {method: 'delete'}).then(response => {
if (response.ok) {
return response.json()
}
}).then(json => {
if (!json.removed) {
return
}
const idx = this.unidades.findIndex(unidad => unidad.pid === json.propiedad_unidad_id)
const unidad = this.unidades.splice(idx,1)[0]
this.draw()
this.tipos[unidad.tipo_id].push({
value: unidad.id,
text: unidad.descripcion,
name: unidad.descripcion
})
})
},
updatePrecio: function(pid, valor) {
const idx = this.unidades.findIndex(unidad => unidad.pid === pid)
if (idx === -1) {
return
}
const old_value = this.unidades[idx].valor
if (old_value === parseFloat(valor)) {
return
}
const url = '{{$urls->api}}/ventas/propiedades/unidad/' + pid + '/edit'
const data = new FormData()
data.set('valor', valor)
return fetchAPI(url, {method: 'post', body: data}).then(response => {
if (response.ok) {
return response.json()
}
}).then(json => {
if (!json.edited) {
return
}
const idx = this.unidades.findIndex(unidad => unidad.pid === json.propiedad_unidad_id)
this.unidades[idx].valor = parseFloat(json.input.valor)
this.draw()
})
},
draw: function() {
const tbody = $('#unidades')
tbody.html('')
this.unidades.forEach(unidad => {
const row = $('<tr></tr>').append(
$('<td></td>').html(unidad.tipo)
).append(
$('<td></td>').html(unidad.descripcion)
).append(
$('<td></td>').append(
$('<div></div>').addClass('ui right labeled input').append(
$('<input />').addClass('precio').attr('type', 'text').attr('data-pid', unidad.pid).attr('value', unidad.valor)
).append(
$('<div></div>').addClass('ui basic label').html('UF')
)
)
).append(
$('<td></td>').addClass('right aligned').append(
$('<button></button>').addClass('ui small red circular icon button remove_unidad').attr('data-pid', unidad.pid).append(
$('<i></i>').addClass('remove icon')
)
)
)
tbody.append(row)
})
$('.price').change(event => {
const pid = $(event.currentTarget).data('pid')
const val = $(event.currentTarget).val()
this.updatePrecio(pid, val)
})
$('.remove_unidad').click(event => {
const unidad_id = $(event.currentTarget).data('pid')
this.removeUnidad(unidad_id)
})
},
setup: function() {
$('#add_unidad').click(event => {
this.addUnidad()
})
$('.remove_unidad').click(event => {
const unidad_id = $(event.currentTarget).data('pid')
this.removeUnidad(unidad_id)
})
$('#add_modal').modal({
onApprove: ($element) => {
this.doAddUnidad()
}
})
const tipo = $('#tipo')
tipo.dropdown()
tipo.change(event => {
this.changeTipoUnidad(tipo.val())
})
$('#unidad').dropdown()
this.changeTipoUnidad(tipo.val())
$('#add_form').submit(event => {
event.preventDefault()
this.doAddUnidad()
tipo.modal('hide')
return false
})
$('.precio').change(event => {
const pid = $(event.currentTarget).data('pid')
const val = $(event.currentTarget).val()
this.updatePrecio(pid, val)
})
}
}
$(document).ready(() => {
$('#add_unidad').click(event => {
addUnidad()
})
$('.remove_unidad').click(event => {
const unidad_id = $(event.currentTarget).data('id')
removeUnidad(unidad_id)
})
$('#add_modal').modal()
const tipo = $('#tipo')
tipo.dropdown()
tipo.change(event => {
changeTipoUnidad(tipo.val())
})
$('#unidad').dropdown()
changeTipoUnidad(tipo.val())
$('#add_form').submit(event => {
event.preventDefault()
tipo.model('hide')
return false
})
propiedad.setup()
})
</script>
@endpush

View File

@ -79,7 +79,7 @@ Editar Propietario
const original_id = $("[name='comuna']").val()
const uri = '{{$urls->api}}/direcciones/comunas/find'
const data = {direccion}
return fetch(uri,
return fetchAPI(uri,
{method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)}
).then(response => {
if (response.ok) {
@ -101,7 +101,7 @@ Editar Propietario
const parent = $('#comunas')
parent.hide()
const uri = '{{$urls->api}}/direcciones/region/' + region_id + '/comunas'
return fetch(uri).then(response => {
return fetchAPI(uri).then(response => {
if (response.ok) {
return response.json()
}
@ -195,7 +195,7 @@ Editar Propietario
redirect()
return
}
return fetch(uri,
return fetchAPI(uri,
{method: 'put', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)}
).then(response => {
if (response.ok) {

Some files were not shown because too many files have changed in this diff Show More