110 Commits

Author SHA1 Message Date
ad3285efd9 FIX: find ventas por proyecto y unidad 2024-01-30 12:07:43 -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
b66ef435c6 FIX: Escritura y saldo 2023-11-24 20:28:08 -03:00
a82db6e1da FIX: trailing slash in ventas url 2023-11-24 10:24:42 -03:00
e1ef31dccd Search update and optimization 2023-11-23 23:35:19 -03:00
bf03e85975 Redis 2023-11-23 00:53:49 -03:00
9ab0515954 Facturacion 2023-11-22 19:08:19 -03:00
b4742a501e Show Proyecto 2023-10-20 19:03:29 -03:00
4734417fe2 Estado Recepcion Final en Proyecto 2023-10-19 22:43:21 -03:00
54ac535a49 Remove benchmark 2023-10-19 22:01:00 -03:00
e536f0f8f3 Redis expiration 1 day 2023-10-19 21:49:57 -03:00
dc217d876a Redis service 2023-10-19 20:46:52 -03:00
742c0327c2 Improving cuotas por vencer 2023-10-19 19:39:27 -03:00
ada0434caf Error log cuotas 2023-10-19 19:10:08 -03:00
850a475ef6 Cuando no tiene resultados en cuotas, entregar vacio 2023-10-19 18:58:48 -03:00
02e1f3e091 Mostrar alertas en inicio 2023-10-19 18:20:37 -03:00
c2a3192b32 Listado proyectos 2023-10-13 10:45:21 -03:00
0d558b7980 Separar datos inicio 2023-10-11 09:03:44 -03:00
e4328d8604 Reorder docker 2023-10-11 09:00:00 -03:00
d8a81db78b Inmobiliarias 2023-09-28 22:28:30 -03:00
3141f1e7c4 Search 2023-09-28 21:05:16 -03:00
2e2d0f07b4 Limpieza de logo 2023-09-15 00:16:02 -03:00
900 changed files with 12163 additions and 44227 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

1
.gitignore vendored
View File

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

1
.key.env.sample Normal file
View File

@ -0,0 +1 @@
API_KEY=

16
CLI.Dockerfile Normal file
View File

@ -0,0 +1,16 @@
FROM php:8.2-fpm
ENV TZ "America/Santiago"
RUN apt-get update && apt-get install -y --no-install-recommends cron && rm -r /var/lib/apt/lists/*
RUN pecl install xdebug-3.2.2 \
&& docker-php-ext-enable xdebug
COPY ./php-errors.ini /usr/local/etc/php/conf.d/docker-php-errors.ini
WORKDIR /code/bin
COPY ./cli/crontab /var/spool/cron/crontabs/root
CMD ["cron", "-f"]

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

15
adminer-compose.yml Normal file
View File

@ -0,0 +1,15 @@
services:
adminer:
profiles:
- db
container_name: incoviba_adminer
image: adminer
restart: unless-stopped
env_file: ${APP_PATH:-.}/.adminer.env
networks:
- adminer_network
ports:
- "8083:8080"
networks:
adminer_network: {}

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

@ -11,4 +11,5 @@ interface Connection
public function prepare(string $query): PDOStatement;
public function execute(string $query, ?array $data = null): PDOStatement;
public function getPDO(): PDO;
public function getQueryBuilder(): Query\Builder;
}

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

@ -5,4 +5,5 @@ use JsonSerializable;
interface Model extends JsonSerializable
{
public function addFactory(string $property, Repository\Factory $factory): Model;
}

View File

@ -0,0 +1,15 @@
<?php
namespace Incoviba\Common\Define;
interface Query
{
/**
* @return string
*/
public function build(): string;
/**
* @return string
*/
public function __toString(): string;
}

View File

@ -0,0 +1,33 @@
<?php
namespace Incoviba\Common\Define\Query;
interface Builder
{
/**
* @param string $table_name
* @return Create
*/
public function create(string $table_name): Create;
/**
* @param string|array $columns
* @return Select
*/
public function select(string|array $columns = '*'): Select;
/**
* @return Insert
*/
public function insert(): Insert;
/**
* @param string $table
* @return Update
*/
public function update(string $table): Update;
/**
* @return Delete
*/
public function delete(): Delete;
}

View File

@ -0,0 +1,31 @@
<?php
namespace Incoviba\Common\Define\Query;
use Incoviba\Common\Define;
interface Create extends Define\Query
{
/**
* @param string $name
* @return Create
*/
public function table(string $name): Create;
/**
* @param string|Create\CreateDefinition|array $create_definitions
* @return Create
*/
public function definitions(string|Create\CreateDefinition|array $create_definitions): Create;
/**
* @param string|array $table_options
* @return Create
*/
public function options(string|array $table_options): Create;
/**
* @param string|array $partition_options
* @return Create
*/
public function partition(string|array $partition_options): Create;
}

View File

@ -0,0 +1,59 @@
<?php
namespace Incoviba\Common\Define\Query\Create;
interface CreateDefinition
{
const RESTRICT = 0;
const CASCADE = 1;
const SET_NULL = 2;
const NO_ACTION = 3;
const SET_DEFAULT = 4;
/**
* @param string $name
* @return CreateDefinition
*/
public function name(string $name): CreateDefinition;
/**
* @param string $type
* @param int|null $size
* @return CreateDefinition
*/
public function type(string $type, ?int $size = null): CreateDefinition;
/**
* @return CreateDefinition
*/
public function primary(): CreateDefinition;
/**
* @return CreateDefinition
*/
public function autoIncrement(): CreateDefinition;
/**
* @return CreateDefinition
*/
public function unsigned(): CreateDefinition;
/**
* @param mixed $value
* @return CreateDefinition
*/
public function default(mixed $value): CreateDefinition;
/**
* @param string $reference_table
* @param string $reference_column
* @param int $on_delete
* @param int $on_update
* @return CreateDefinition
*/
public function foreign(string $reference_table, string $reference_column = 'id', int $on_delete = CreateDefinition::CASCADE, int $on_update = CreateDefinition::CASCADE): CreateDefinition;
/**
* @return string
*/
public function __toString(): string;
}

View File

@ -0,0 +1,12 @@
<?php
namespace Incoviba\Common\Define\Query;
use Incoviba\Common\Define;
interface Delete extends Define\Query
{
public function from(string $table): Delete;
public function where(string|array $conditions): Delete;
public function order(string|array $sorting): Delete;
public function limit(int $limit): Delete;
}

View File

@ -0,0 +1,32 @@
<?php
namespace Incoviba\Common\Define\Query;
use Incoviba\Common\Define;
interface Insert extends Define\Query
{
/**
* @param string $table
* @param array|null $columns
* @return Insert
*/
public function into(string $table, ?array $columns = null): Insert;
/**
* @param array $columns
* @return Insert
*/
public function columns(array $columns): Insert;
/**
* @param array $values
* @return Insert
*/
public function values(array $values): Insert;
/**
* @param Select $select
* @return Insert
*/
public function select(Select $select): Insert;
}

View File

@ -0,0 +1,62 @@
<?php
namespace Incoviba\Common\Define\Query;
use Incoviba\Common\Define;
interface Select extends Define\Query
{
/**
* @param string|array $expressions
* @return Select
*/
public function columns(string|array $expressions): Select;
/**
* @param string $table
* @return Select
*/
public function from(string $table): Select;
/**
* @param string|array $joins
* @return Select
*/
public function joined(string|array $joins): Select;
/**
* @param string|array $conditions
* @return Select
*/
public function where(string|array $conditions): Select;
/**
* @param string|array $grouping
* @return Select
*/
public function group(string|array $grouping): Select;
/**
* @param string|array $conditions
* @return Select
*/
public function having(string|array $conditions): Select;
/**
* @param string|array $sorting
* @return Select
*/
public function order(string|array $sorting): Select;
/**
* @param int $limit
* @param int|null $offset
* @return Select
*/
public function limit(int $limit, ?int $offset = null): Select;
/**
* @param int $offset
* @return Select
*/
public function offset(int $offset): Select;
}

View File

@ -0,0 +1,13 @@
<?php
namespace Incoviba\Common\Define\Query;
use Incoviba\Common\Define;
interface Update extends Define\Query
{
public function table(string $table): Update;
public function set(string|array $column_pairs): Update;
public function where(string|array $conditions): Update;
public function order(string|array $ordering): Update;
public function limit(int $limit): Update;
}

View File

@ -1,6 +1,8 @@
<?php
namespace Incoviba\Common\Define\Repository;
use Incoviba\Common\Define\Model;
interface Mapper
{
public function setProperty(string $property): Mapper;
@ -12,4 +14,6 @@ interface Mapper
public function hasFunction(): bool;
public function hasFactory(): bool;
public function hasDefault(): bool;
public function parse(Model &$model, string $column, ?array $data): bool;
}

View File

@ -0,0 +1,26 @@
<?php
namespace Incoviba\Common\Ideal\Cartola;
use Incoviba\Common\Define;
use Psr\Http\Message\UploadedFileInterface;
abstract class Banco 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) {
$r[$new] = $row[$old];
}
$temp []= $r;
}
return $temp;
}
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

@ -0,0 +1,12 @@
<?php
namespace Incoviba\Common\Ideal;
use Incoviba\Common\Define;
abstract class Query implements Define\Query
{
public function __toString(): string
{
return $this->build();
}
}

View File

@ -31,18 +31,28 @@ abstract class Repository implements Define\Repository
public function remove(Define\Model $model): void
{
$query = "DELETE FROM `{$this->getTable()}` WHERE `{$this->getKey()}` = ?";
$this->connection->execute($query, [$model->getId()]);
$query = $this->connection->getQueryBuilder()
->delete()->from($this->getTable())
->where("{$this->getKey()} = ?");
$this->connection->execute($query, [$model->id]);
}
public function fetchById(int $id): Define\Model
{
$query = "SELECT * FROM `{$this->getTable()}` WHERE `{$this->getKey()}` = ?";
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where("{$this->getKey()} = ?");
return $this->fetchOne($query, [$id]);
}
public function fetchAll(): array
public function fetchAll(null|string|array $ordering = null): array
{
$query = "SELECT * FROM `{$this->getTable()}`";
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable());
if ($ordering !== null) {
$query->order($ordering);
}
return $this->fetchMany($query);
}
@ -96,9 +106,11 @@ abstract class Repository implements Define\Repository
}
protected function saveNew(array $columns, array $values): int
{
$columns_string = implode(', ', array_map(function($column) {return "`{$column}`";}, $columns));
$columns_questions = implode(', ', array_fill(0, count($columns), '?'));
$query = "INSERT INTO `{$this->getTable()}` ({$columns_string}) VALUES ($columns_questions)";
$query = $this->connection->getQueryBuilder()
->insert()
->into($this->getTable())
->columns($columns)
->values(array_fill(0, count($columns), '?'));
$this->connection->execute($query, $values);
return $this->connection->getPDO()->lastInsertId();
}
@ -107,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];
}
@ -117,7 +129,10 @@ abstract class Repository implements Define\Repository
return $model;
}
$columns_string = implode(', ', array_map(function($property) {return "`{$property}` = ?";}, $changes));
$query = "UPDATE `{$this->getTable()}` SET {$columns_string} WHERE `{$this->getKey()}` = ?";
$query = $this->connection->getQueryBuilder()
->update($this->getTable())
->set($columns_string)
->where("{$this->getKey()} = ?");
$values []= $model->{$this->getKey()};
$this->connection->execute($query, $values);
return $this->fetchById($model->{$this->getKey()});

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

@ -8,7 +8,7 @@ use Incoviba\Common\Define;
class Connection implements Define\Connection
{
public function __construct(protected Define\Database $database) {}
public function __construct(protected Define\Database $database, protected Database\Query\Builder $queryBuilder) {}
protected PDO $connection;
public function connect(): Define\Connection
@ -27,6 +27,10 @@ class Connection implements Define\Connection
$this->connect();
return $this->connection;
}
public function getQueryBuilder(): Database\Query\Builder
{
return $this->queryBuilder;
}
public function query(string $query): PDOStatement
{

View File

@ -0,0 +1,29 @@
<?php
namespace Incoviba\Common\Implement\Database\Query;
use Incoviba\Common\Define;
class Builder implements Define\Query\Builder
{
public function create(string $table_name): Create
{
return (new Create())->table($table_name);
}
public function select(array|string $columns = '*'): Select
{
return (new Select())->columns($columns);
}
public function insert(): Insert
{
return new Insert();
}
public function update(string $table): Update
{
return (new Update())->table($table);
}
public function delete(): Delete
{
return new Delete();
}
}

View File

@ -0,0 +1,102 @@
<?php
namespace Incoviba\Common\Implement\Database\Query;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
class Create extends Ideal\Query implements Define\Query\Create
{
protected string $name;
protected array $definitions;
protected array $options;
protected array $partitions;
public function table(string $name): Define\Query\Create
{
$this->name = $name;
return $this;
}
public function definitions(Define\Query\Create\CreateDefinition|array|string $create_definitions): Define\Query\Create
{
if (is_array($create_definitions)) {
foreach ($create_definitions as $definition) {
$this->addDefinition($definition);
}
return $this;
}
return $this->addDefinition($create_definitions);
}
public function options(array|string $table_options): Define\Query\Create
{
if (is_string($table_options)) {
return $this->addOption($table_options);
}
foreach ($table_options as $option) {
$this->addOption($option);
}
return $this;
}
public function partition(array|string $partition_options): Define\Query\Create
{
if (is_string($partition_options)) {
return $this->addPartition($partition_options);
}
foreach ($partition_options as $option) {
$this->addPartition($option);
}
return $this;
}
public function build(): string
{
$query = [
"CREATE TABLE {$this->name}",
$this->getDefinitions(),
$this->getOptions(),
$this->getPartitions()
];
return implode('', $query);
}
protected function addDefinition(string $definition): Create
{
if (!isset($this->definitions)) {
$this->definitions = [];
}
$this->definitions []= $definition;
return $this;
}
protected function addOption(string $option): Create
{
if (!isset($this->options)) {
$this->options = [];
}
$this->options []= $option;
return $this;
}
protected function addPartition(string $partition): Create
{
if (!isset($this->partitions)) {
$this->partitions = [];
}
$this->partitions []= $partition;
return $this;
}
protected function getDefinitions(): string
{
return ' (' . implode(', ', $this->definitions) . ')';
}
protected function getOptions(): string
{
if (!isset($this->options) or count($this->options) <= 0) {
return '';
}
return ' ' . implode(' ', $this->options);
}
protected function getPartitions(): string
{
if (!isset($this->partitions) or count($this->partitions) <= 0) {
return '';
}
return ' PARTITION BY (' . implode(', ', $this->partitions) . ')';
}
}

View File

@ -0,0 +1,104 @@
<?php
namespace ProVM\Implement\Data\Query\Create;
use ProVM\Define\Query\Create\CreateDefinition;
class Definition implements CreateDefinition
{
protected string $name;
protected string $type;
protected int $size;
protected bool $primary;
protected bool $auto_increment;
protected bool $unsigned;
protected mixed $default;
protected string $foreign_table;
protected string $foreign_key;
protected int $foreign_delete;
protected int $foreign_update;
public function name(string $name): CreateDefinition
{
$this->name = $name;
return $this;
}
public function type(string $type, ?int $size = null): CreateDefinition
{
$this->type = $type;
if ($size !== null) {
$this->size = $size;
}
return $this;
}
public function primary(): CreateDefinition
{
$this->primary = true;
return $this;
}
public function autoIncrement(): CreateDefinition
{
$this->auto_increment = true;
return $this;
}
public function unsigned(): CreateDefinition
{
$this->unsigned = true;
return $this;
}
public function default(mixed $value): CreateDefinition
{
$this->default = $value;
return $this;
}
public function foreign(string $reference_table, string $reference_column = 'id', int $on_delete = CreateDefinition::CASCADE, int $on_update = CreateDefinition::CASCADE): CreateDefinition
{
$this->foreign_table = $reference_table;
$this->foreign_key = $reference_column;
$this->foreign_delete = $on_delete;
$this->foreign_update = $on_update;
return $this;
}
public function __toString(): string
{
$type = $this->type ?? 'int';
if (isset($this->size)) {
$type = "{$type}({$this->size})";
} elseif (in_array($type, ['varchar'])) {
$type = "{$type}(255)";
}
$output = [
"`{$this->name}`",
$type
];
if (isset($this->unsigned)) {
$output []= 'UNSIGNED';
}
if (isset($this->default)) {
$default = $this->default;
if (in_array($this->type, ['varchar', 'text', 'char'])) {
$default = "'{$default}'";
}
$output []= "DEFAULT {$default}";
}
if (isset($this->auto_increment)) {
$output []= 'AUTO_INCREMENT';
}
if (isset($this->primary)) {
$output []= 'PRIMARY KEY';
}
if (isset($this->foreign_table)) {
$output []= "REFERENCES `{$this->foreign_table}` (`{$this->foreign_key}`)";
$on = [
'RESTRICT',
'CASCADE',
'SET_NULL',
'NO_ACTION',
'SET_DEFAULT'
];
$output []= "ON DELETE {$on[$this->foreign_delete]}";
$output []= "ON UPDATE {$on[$this->foreign_update]}";
}
return implode(' ', $output);
}
}

View File

@ -0,0 +1,89 @@
<?php
namespace Incoviba\Common\Implement\Database\Query;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
class Delete extends Ideal\Query implements Define\Query\Delete
{
protected string $table;
protected array $conditions;
protected array $sorts;
protected int $limit;
public function from(string $table): Delete
{
$this->table = $table;
return $this;
}
public function where(array|string $conditions): Delete
{
if (is_string($conditions)) {
return $this->addCondition($conditions);
}
foreach ($conditions as $condition) {
$this->addCondition($condition);
}
return $this;
}
public function order(array|string $sorting): Delete
{
if (is_string($sorting)) {
return $this->addOrder($sorting);
}
foreach ($sorting as $order) {
$this->addOrder($order);
}
return $this;
}
public function limit(int $limit): Delete
{
$this->limit = $limit;
return $this;
}
public function build(): string
{
$query = [
"DELETE FROM {$this->table}",
$this->getConditions(),
$this->getSorting(),
$this->getLimit()
];
return implode('', $query);
}
protected function addCondition(string $condition): Delete
{
if (!isset($this->conditions)) {
$this->conditions = [];
}
$this->conditions []= $condition;
return $this;
}
protected function getConditions(): string
{
return ' WHERE ' . implode(' AND ', $this->conditions);
}
protected function addOrder(string $order): Delete
{
if (!isset($this->sorts)) {
$this->sorts = [];
}
$this->sorts []= $order;
return $this;
}
protected function getSorting(): string
{
if (!isset($this->sorts) or count($this->sorts) === 0) {
return '';
}
return ' ORDER BY ' . implode(', ', $this->sorts);
}
protected function getLimit(): string
{
if (!isset($this->limit) or $this->limit <= 0) {
return '';
}
return " LIMIT {$this->limit}";
}
}

View File

@ -0,0 +1,87 @@
<?php
namespace Incoviba\Common\Implement\Database\Query;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
class Insert extends Ideal\Query implements Define\Query\Insert
{
protected string $table;
protected array $columns;
protected array $values;
protected Define\Query\Select $select;
public function into(string $table, ?array $columns = null): Insert
{
$this->table = $table;
if ($columns !== null) {
return $this->columns($columns);
}
return $this;
}
public function columns(array $columns): Insert
{
foreach ($columns as $column) {
$this->addColumn($column);
}
return $this;
}
public function values(array $values): Insert
{
foreach ($values as $value) {
$this->addValue($value);
}
return $this;
}
public function select(Define\Query\Select $select): Insert
{
$this->select = $select;
return $this;
}
public function build(): string
{
$query = [
"INSERT INTO {$this->table}"
];
if (isset($this->select)) {
$query []= " {$this->select}";
return implode('', $query);
}
$query []= $this->getColumns();
$query []= $this->getValues();
return implode('', $query);
}
protected function addColumn(string $column): Insert
{
if (!isset($this->columns)) {
$this->columns = [];
}
$this->columns []= $column;
return $this;
}
protected function addValue(mixed $value): Insert
{
if (!isset($this->values)) {
$this->values = [];
}
$this->values []= $value;
return $this;
}
protected function getColumns(): string
{
return ' (' . implode(', ', array_map(function(string $column) {return "`{$column}`";}, $this->columns)) . ')';
}
protected function getValues(): string
{
return ' VALUES (' . implode(', ', array_map(function($value) {
if ($value === '?') {
return $value;
}
if ($value === (int) $value) {
return $value;
}
return "'{$value}'";
}, $this->values)) . ')';
}
}

View File

@ -0,0 +1,215 @@
<?php
namespace Incoviba\Common\Implement\Database\Query;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
class Select extends Ideal\Query implements Define\Query\Select
{
protected array $columns;
protected string $table;
protected array $joins;
protected array $conditions;
protected array $groups;
protected array $haves;
protected array $orders;
protected int $limit;
protected int $offset;
public function columns(array|string $expressions): Select
{
if (is_string($expressions)) {
return $this->addColumn($expressions);
}
foreach ($expressions as $expression) {
$this->addColumn($expression);
}
return $this;
}
public function from(string $table): Select
{
$this->table = $table;
return $this;
}
public function joined(array|string $joins): Select
{
if (is_string($joins)) {
return $this->addJoin($joins);
}
foreach ($joins as $join) {
$this->addJoin($join);
}
return $this;
}
public function where(array|string $conditions): Select
{
if (is_string($conditions)) {
return $this->addCondition($conditions);
}
foreach ($conditions as $condition) {
$this->addCondition($condition);
}
return $this;
}
public function group(array|string $grouping): Select
{
if (is_string($grouping)) {
return $this->addGroup($grouping);
}
foreach ($grouping as $group) {
$this->addGroup($group);
}
return $this;
}
public function having(array|string $conditions): Select
{
if (is_string($conditions)) {
return $this->addCondition($conditions);
}
foreach ($conditions as $condition) {
$this->addCondition($condition);
}
return $this;
}
public function order(array|string $sorting): Select
{
if (is_string($sorting)) {
return $this->addOrder($sorting);
}
foreach ($sorting as $order) {
$this->addOrder($order);
}
return $this;
}
public function limit(int $limit, ?int $offset = null): Select
{
$this->limit = $limit;
if ($offset !== null) {
return $this->offset($offset);
}
return $this;
}
public function offset(int $offset): Select
{
$this->offset = $offset;
return $this;
}
public function build(): string
{
$query = [
"SELECT {$this->getColumns()} FROM {$this->table}",
$this->getJoins(),
$this->getConditions(),
$this->getGroups(),
$this->getHaving(),
$this->getOrder(),
$this->getLimit()
];
return implode('', $query);
}
protected function addColumn(string $expression): Select
{
if (!isset($this->columns)) {
$this->columns = [];
}
$this->columns []= $expression;
return $this;
}
protected function addJoin(string $join): Select
{
if (!isset($this->joins)) {
$this->joins = [];
}
$this->joins []= $join;
return $this;
}
protected function addCondition(string $condition): Select
{
if (!isset($this->coditions)) {
$this->conditions = [];
}
$this->conditions []= $condition;
return $this;
}
protected function addGroup(string $group): Select
{
if (!isset($this->groups)) {
$this->groups = [];
}
$this->groups []= $group;
return $this;
}
protected function addHaving(string $having): Select
{
if (!isset($this->haves)) {
$this->haves = [];
}
$this->haves []= $having;
return $this;
}
protected function addOrder(string $order): Select
{
if (!isset($this->orders)) {
$this->orders = [];
}
$this->orders []= $order;
return $this;
}
protected function getColumns(): string
{
if (!isset($this->columns) or count($this->columns) === 0) {
return '*';
}
return implode(', ', $this->columns);
}
protected function getJoins(): string
{
if (!isset($this->joins) or count($this->joins) === 0) {
return '';
}
return ' ' . implode(' ', $this->joins);
}
protected function getConditions(): string
{
if (!isset($this->conditions) or count($this->conditions) === 0) {
return '';
}
return ' WHERE ' . implode(' AND ', $this->conditions);
}
protected function getGroups(): string
{
if (!isset($this->groups) or count($this->groups) === 0) {
return '';
}
return ' GROUP BY ' . implode(', ', $this->groups);
}
protected function getHaving(): string
{
if (!isset($this->haves) or count($this->haves) === 0) {
return '';
}
return ' HAVING ' . implode(' AND ', $this->haves);
}
protected function getOrder(): string
{
if (!isset($this->orders) or count($this->orders) === 0) {
return '';
}
return ' ORDER BY ' . implode(', ', $this->orders);
}
protected function getLimit(): string
{
if (!isset($this->limit) or $this->limit <= 0) {
return '';
}
return " LIMIT {$this->limit}{$this->getOffset()}";
}
protected function getOffset(): string
{
if (!isset($this->offset) or $this->offset <= 0) {
return '';
}
return " OFFSET {$this->offset}";
}
}

View File

@ -0,0 +1,113 @@
<?php
namespace Incoviba\Common\Implement\Database\Query;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
class Update extends Ideal\Query implements Define\Query\Update
{
protected string $table;
protected array $setPairs;
protected array $conditions;
protected array $orders;
protected int $limit;
public function table(string $table): Define\Query\Update
{
$this->table = $table;
return $this;
}
public function set(array|string $column_pairs): Define\Query\Update
{
if (is_string($column_pairs)) {
return $this->addSet($column_pairs);
}
foreach ($column_pairs as $pair) {
$this->addSet($pair);
}
return $this;
}
public function where(array|string $conditions): Define\Query\Update
{
if (is_string($conditions)) {
return $this->addCondition($conditions);
}
foreach ($conditions as $condition) {
$this->addCondition($condition);
}
return $this;
}
public function order(array|string $ordering): Define\Query\Update
{
if (is_string($ordering)) {
return $this->addOrder($ordering);
}
foreach ($ordering as $order) {
$this->addOrder($order);
}
return $this;
}
public function limit(int $limit): Define\Query\Update
{
$this->limit = $limit;
return $this;
}
public function build(): string
{
$query = [
"UPDATE {$this->table}",
$this->getSet(),
$this->getConditions(),
$this->getOrder(),
$this->getLimit()
];
return implode('', $query);
}
protected function addSet(string $pair): Update
{
if (!isset($this->setPairs)) {
$this->setPairs = [];
}
$this->setPairs []= $pair;
return $this;
}
protected function addCondition(string $condition): Update
{
if (!isset($this->conditions)) {
$this->conditions = [];
}
$this->conditions []= $condition;
return $this;
}
protected function addOrder(string $order): Update
{
if (!isset($this->orders)) {
$this->orders = [];
}
$this->orders []= $order;
return $this;
}
protected function getSet(): string
{
return ' SET ' . implode(', ', $this->setPairs);
}
protected function getConditions(): string
{
return ' WHERE ' . implode(' AND ', $this->conditions);
}
protected function getOrder(): string
{
if (!isset($this->orders) or count($this->orders) === 0) {
return '';
}
return ' ORDER BY ' . implode(', ', $this->orders);
}
protected function getLimit(): string
{
if (!isset($this->limit) or $this->limit <= 0) {
return '';
}
return " LIMIT {$this->limit}";
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace Incoviba\Common\Implement\Exception;
use Throwable;
use Exception;
class EmptyRedis extends Exception
{
public function __construct(string $key, ?Throwable $previous = null)
{
$message = "Redis key {$key} not found in database.";
$code = 750;
parent::__construct($message, $code, $previous);
}
}

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,9 +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

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

View File

@ -0,0 +1,6 @@
<?php
use Incoviba\Controller\Inmobiliarias;
$app->group('/inmobiliarias', function($app) {
$app->get('[/]', Inmobiliarias::class);
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));

View File

@ -2,5 +2,9 @@
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

@ -9,15 +9,12 @@ $app->group('/ventas', function($app) {
}
include_once $file->getRealPath();
}
$app->group('/add', function($app) {
$app->post('[/]', [Ventas::class, 'doAdd']);
$app->get('[/]', [Ventas::class, 'add']);
});
$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']);
@ -29,7 +26,11 @@ $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->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

@ -0,0 +1,7 @@
<?php
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,9 @@
<?php
use Incoviba\Controller\API\Contabilidad;
$app->group('/cartolas', function($app) {
$app->post('/procesar[/]', [Contabilidad::class, 'procesarCartola']);
});
$app->group('/cartola', function($app) {
$app->post('/exportar[/]', [Contabilidad::class, 'exportarCartola']);
});

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,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

@ -1,5 +1,5 @@
<?php
use Incoviba\Controller\Direcciones;
use Incoviba\Controller\API\Direcciones;
$app->group('/direcciones', function($app) {
$app->group('/region/{region_id:[0-9]+}', function($app) {

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

@ -0,0 +1,8 @@
<?php
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

@ -1,5 +1,5 @@
<?php
use Incoviba\Controller\Provincias;
use Incoviba\Controller\API\Provincias;
$app->group('/provincia/{provincia_id}', function($app) {
$app->get('/comunas', [Provincias::class, 'comunas']);

View File

@ -1,9 +1,23 @@
<?php
use Incoviba\Controller\Proyectos;
use Incoviba\Controller\API\Proyectos;
$app->group('/proyectos', function($app) {
$app->get('/escriturando[/]', [Proyectos::class, 'escriturando']);
$app->get('[/]', [Proyectos::class, 'list']);
});
$app->group('/proyecto/{proyecto_id}', function($app) {
$app->get('/unidades[/]', [Proyectos::class, 'unidades']);
$app->get('/estados[/]', [Proyectos\EstadosProyectos::class, 'byProyecto']);
$app->get('/estado[/]', [Proyectos\EstadosProyectos::class, 'currentByProyecto']);
$app->get('/inicio[/]', [Proyectos\EstadosProyectos::class, 'firstByProyecto']);
$app->get('/recepcion[/]', [Proyectos\EstadosProyectos::class, 'recepcionByProyecto']);
$app->group('/superficies', function($app) {
$app->get('/vendible[/]', [Proyectos::class, 'superficies']);
});
$app->group('/unidades', function($app) {
$app->get('/disponibles[/]', [Proyectos::class, 'disponibles']);
$app->get('[/]', [Proyectos::class, 'unidades']);
});
$app->group('/terreno', function($app) {
$app->post('/edit[/]', [Proyectos::class, 'terreno']);
});
});

View File

@ -0,0 +1,4 @@
<?php
use Incoviba\Controller\API\Proyectos\EstadosProyectos;
//$app->group('/estados');

View File

@ -1,5 +1,6 @@
<?php
use Incoviba\Controller\Regiones;
use Incoviba\Controller\API\Regiones;
//$app->group('/regiones', function($app) {});
$app->group('/region/{region_id}', function($app) {

View File

@ -0,0 +1,4 @@
<?php
use Incoviba\Controller\API\Search;
$app->post('/search', [Search::class, 'query']);

View File

@ -1,5 +1,5 @@
<?php
use Incoviba\Controller\Ventas;
use Incoviba\Controller\API\Ventas;
$app->group('/ventas', function($app) {
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'ventas']);
@ -12,9 +12,23 @@ $app->group('/ventas', function($app) {
include_once $file->getRealPath();
}
}
$app->post('/add[/]', [Ventas::class, 'add']);
$app->group('/estados', function($app) {
$app->post('/firmar[/]', [Ventas::class, 'porFirmar']);
});
$app->group('/escrituras', function($app) {
$app->post('/estados[/]', [Ventas::class, 'escrituras']);
});
$app->post('[/]', [Ventas::class, 'proyecto']);
});
$app->group('/venta/{venta_id}', function($app) {
$app->get('/comentarios', [Ventas::class, 'comentarios']);
$app->get('/unidades[/]', [Ventas::class, 'unidades']);
$app->get('/comentarios[/]', [Ventas::class, 'comentarios']);
$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

@ -1,6 +1,7 @@
<?php
use Incoviba\Controller\Ventas\Cierres;
use Incoviba\Controller\API\Ventas\Cierres;
$app->group('/cierres', function($app) {
$app->get('/vigentes[/]', [Cierres::class, 'vigentes']);
$app->post('[/]', [Cierres::class, 'proyecto']);
});

View File

@ -0,0 +1,8 @@
<?php
use Incoviba\Controller\API\Ventas\Cuotas;
$app->group('/cuotas', function($app) {
$app->get('/hoy[/]', [Cuotas::class, 'hoy']);
$app->get('/pendiente[/]', [Cuotas::class, 'pendiente']);
$app->get('/vencer[/]', [Cuotas::class, 'porVencer']);
});

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

@ -0,0 +1,6 @@
<?php
use Incoviba\Controller\API\Ventas\Facturacion;
$app->group('/facturacion', function($app) {
$app->get('/proyecto/{proyecto_id}[/]', [Facturacion::class, 'proyecto']);
});

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

@ -1,5 +1,5 @@
<?php
use Incoviba\Controller\Ventas\Precios;
use Incoviba\Controller\API\Ventas\Precios;
$app->group('/precios', function($app) {
$app->post('[/]', [Precios::class, 'proyecto']);

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

@ -0,0 +1,12 @@
<?php
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,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,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

@ -0,0 +1,9 @@
<?php
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,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

@ -4,23 +4,83 @@
<div class="ui container">
<h4 class="ui header">Bienvenid@ {{$user->name}}</h4>
<div class="ui basic fitted segment">
@if ($cuotas_hoy > 0)
Existe{{$cuotas_hoy > 1 ? 'n' : ''}} {{$cuotas_hoy}} deposito{{$cuotas_hoy > 1 ? 's' : ''}} para hoy.
<br />
@endif
@if ($cuotas_pendientes > 0)
<a href="{{$urls->base}}/ventas/cuotas/pendientes">
Existe{{$cuotas_pendientes > 1 ? 'n' : ''}} {{$cuotas_pendientes}} cuota{{$cuotas_pendientes > 1 ? 's' : ''}} pendiente{{$cuotas_pendientes > 1 ? 's' : ''}}. <i class="right arrow icon"></i>
</a>
@endif
<span id="cuotas_hoy"></span>
<span id="cuotas_pendientes"></span>
</div>
<div class="ui two column grid">
<div class="column">
@include('home.cuotas_por_vencer')
</div>
<div class="column">
@include('home.alertas')
</div>
<div class="column">
@include('home.cierres_vigentes')
</div>
</div>
</div>
@endsection
@push('page_scripts')
<script type="text/javascript">
const cuotas = {
get: function() {
return {
hoy: () => {
const span = $('#cuotas_hoy')
return fetchAPI('{{$urls->api}}/ventas/cuotas/hoy').then(response => {
span.html('')
if (response.ok) {
return response.json()
}
}).then(data => {
let output = 'Existe'
if (data.cuotas > 1) {
output += 'n'
}
output += ' ' + data.cuotas + ' deposito'
if (data.cuotas > 1) {
output += 's'
}
output += ' para hoy.<br />'
span.html(output)
})
},
pendiente: () => {
const span = $('#cuotas_pendientes')
return fetchAPI('{{$urls->api}}/ventas/cuotas/pendiente').then(response => {
span.html('')
if (response.ok) {
return response.json()
}
}).then(data => {
const link = $('<a></a>').attr('href', '{{$urls->base}}/ventas/cuotas/pendientes')
let output = 'Existe'
if (data.cuotas > 1) {
output += 'n'
}
output += ' ' + data.cuotas + ' cuota'
if (data.cuotas > 1) {
output += 's'
}
output += ' pendiente'
if (data.cuotas > 1) {
output += 's'
}
output += ' por cobrar. <i class="right arrow icon"></i>'
link.html(output)
span.html(link)
})
}
}
},
run: function() {
this.get().hoy()
this.get().pendiente()
}
}
$(document).ready(() => {
cuotas.run()
})
</script>
@endpush

View File

@ -0,0 +1,191 @@
<h4 class="ui dividing header">Alertas Escrituras</h4>
<div class="ui divided list" id="alertas_escrituras"></div>
@push('page_scripts')
<script type="text/javascript">
const alertas_escrituras = {
id: '#alertas_escrituras',
data: {
proyectos: []
},
get: function() {
return {
proyectos: () => {
this.draw().loading()
const url = '{{$urls->api}}/proyectos/escriturando'
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
}
}).then(data => {
const promises = []
data.proyectos.forEach(proyecto => {
this.add().proyecto(proyecto)
promises.push(
this.get().unidades(proyecto.id)
)
promises.push(
this.get().promesas(proyecto.id)
)
promises.push(
this.get().escrituras(proyecto.id)
)
})
Promise.all(promises).then(() => {
this.draw().list()
})
})
},
unidades: proyecto_id => {
const url = '{{$urls->api}}/ventas/unidades/disponibles'
return fetchAPI(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => {
if (response.ok) {
return response.json()
}
}).then(data => {
const index = this.data.proyectos.findIndex(proyecto => proyecto.id === data.proyecto_id)
this.data.proyectos[index].unidades = data.unidades
})
},
promesas: proyecto_id => {
const url = '{{$urls->api}}/ventas/estados/firmar'
return fetchAPI(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => {
if (response.ok) {
return response.json()
}
}).then(data => {
const index = this.data.proyectos.findIndex(proyecto => proyecto.id === data.proyecto_id)
this.data.proyectos[index].promesas = data.promesas
})
},
escrituras: proyecto_id => {
const url = '{{$urls->api}}/ventas/escrituras/estados';
return fetchAPI(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => {
if (response.ok) {
return response.json()
}
}).then(data => {
const index = this.data.proyectos.findIndex(proyecto => proyecto.id === data.proyecto_id)
this.data.proyectos[index].escrituras = data.escrituras
})
/*const index = this.data.proyectos.findIndex(proyecto => proyecto.id === proyecto_id)
if (proyecto_id === 3) {
this.data.proyectos[index].escrituras = {
firmar: 20,
pagar: 70,
abonar: 3
}
}
if (proyecto_id === 4) {
this.data.proyectos[index].escrituras = {
firmar: 0,
pagar: 0,
abonar: 2
}
}*/
}
}
},
draw: function() {
return {
reset: () => {
const list = $(this.id)
list.html('')
},
loading: () => {
this.draw().reset()
const list = $(this.id)
list.append(
$('<div><div>').addClass('ui inline active loader')
)
},
list: () => {
this.draw().reset()
const list = $(this.id)
this.data.proyectos.forEach(proyecto => {
const feed = $('<div></div>').addClass('ui feed').append(
$('<div></div>').addClass('date').append(
$('<strong></strong>').html(proyecto.descripcion)
)
)
function add(control, title, value = null) {
if (control > 0) {
return $('<div></div>').addClass('event').append(
$('<div></div>').addClass('content').html(title)
).append(
$('<div></div>').addClass('meta').html(value ?? control)
)
}
}
const total_unidades = Object.entries(proyecto.unidades)
.filter(([tipo, total]) => tipo !== 'total')
.map(([tipo, total]) => total)
.reduce((sum, total_tipo) => sum + total_tipo, 0)
const unidades = $('<div></div>').addClass('ui feed')
const formatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 0, maximumFractionDigits: 0})
Object.entries(proyecto.unidades).filter(([tipo, total]) => tipo !== 'total').forEach(([tipo, total]) => {
const full = proyecto.unidades.total[tipo]
tipo = tipo.charAt(0).toUpperCase() + tipo.slice(1)
unidades.append(
$('<div></div>').addClass('event').append(
$('<div></div>').addClass('content').html(tipo)
).append(
$('<div></div>').addClass('meta').html(total + '/' + full + ' ' + formatter.format(Math.round(total / full * 10000) / 100).padStart(2, ' ') + '%')
)
)
})
if (total_unidades > 0) {
feed.append(
$('<div></div>').addClass('event').append(
$('<div></div>').addClass('content').html('Unidades por Vender')
).append(
$('<div></div>').addClass('content').append(unidades)
)
)
}
feed.append(add(proyecto.promesas, 'Promesas por Escriturar'))
feed.append(add(proyecto.escrituras.firmar, 'Escrituras por Firmar'))
feed.append(add(proyecto.escrituras.pagar, 'Escrituras con Pagos Pendientes'))
feed.append(add(proyecto.escrituras.abonar, 'Escrituras con Pagos no Abonados'))
list.append(
$('<div></div>').addClass('item').append(feed)
)
})
}
}
},
add: function() {
return {
proyecto: proyecto => {
proyecto.unidades = {
total: 0,
departamentos: 0,
estacionamientos: 0,
bodegas: 0
}
proyecto.promesas = 0
proyecto.escrituras = {
firmar: 0,
pagar: 0,
abonar: 0
}
this.data.proyectos.push(proyecto)
}
}
}
}
$(document).ready(() => {
alertas_escrituras.get().proyectos()
})
/**
* Listar proyectos construidos no terminados con unidades no vendidas, promesas o escrituras pendientes
* Listar # unidades no vendidas
* Listar # promesas por escriturar
* Listar # escrituras por firmar
* Listar # escrituras con pagos pendientes
* Listar # escrituras con abonos pendientes
*/
</script>
@endpush

View File

@ -1,24 +1,59 @@
<h4 class="ui dividing header">Cierres Vigentes</h4>
<div class="ui divided list">
@foreach($cierres_vigentes as $proyecto => $estados)
<div class="item">
<div class="ui feed">
<div class="date">
<strong>{{$proyecto}}</strong> [{{$estados['total']}}]
</div>
<div class="event">
<div class="content">Promesados</div>
<div class="meta">{{$estados['promesados']}}</div>
</div>
<div class="event">
<div class="content">Pendientes</div>
<div class="meta">{{$estados['pendientes']}}</div>
</div>
<div class="event">
<div class="content">Rechazados</div>
<div class="meta">{{$estados['rechazados']}}</div>
</div>
</div>
</div>
@endforeach
</div>
<div class="ui divided list" id="cierres_vigentes"></div>
@push('page_scripts')
<script type="text/javascript">
const cierres_vigentes = {
get: function() {
const list = $('#cierres_vigentes')
list.html('')
list.append(
$('<div><div>').addClass('ui inline active loader')
)
fetchAPI('{{$urls->api}}/ventas/cierres/vigentes').then(response => {
list.html('')
if (response.ok) {
return response.json()
}
}).then(data => {
this.draw(data.cierres)
})
},
draw: function(cierres) {
const list = $('#cierres_vigentes')
Object.entries(cierres).forEach(([proyecto, estados]) => {
const item = $('<div></div>').addClass('item')
const feed = $('<div></div>').addClass('ui feed')
feed.append(
$('<div></div>').addClass('date').append(
$('<strong></strong>').html(proyecto).append('[' + estados['total'] + ']')
)
).append(
$('<div></div>').addClass('event').append(
$('<div></div>').addClass('content').html('Promesados')
).append(
$('<div></div>').addClass('meta').html(estados['promesados'])
)
).append(
$('<div></div>').addClass('event').append(
$('<div></div>').addClass('content').html('Pendientes')
).append(
$('<div></div>').addClass('meta').html(estados['pendientes'])
)
).append(
$('<div></div>').addClass('event').append(
$('<div></div>').addClass('content').html('Rechazados')
).append(
$('<div></div>').addClass('meta').html(estados['rechazados'])
)
)
item.append(feed)
list.append(item)
})
}
}
$(document).ready(() => {
cierres_vigentes.get()
})
</script>
@endpush

View File

@ -1,22 +1,52 @@
<h4 class="ui dividing header">Cuotas Por Vencer</h4>
<div class="ui divided list">
@foreach ($cuotas_por_vencer as $date => $proyectos)
<div class="item">
<div class="ui feed">
<div class="date">
<strong>{{$format->localDate($date, "EEE. dd 'de' MMMM 'de' yyyy", true)}}</strong>
</div>
@foreach ($proyectos as $proyecto => $cuotas)
<div class="event">
<div class="content">
<span class="ui small text">
{{$proyecto}}
</span>
</div>
<div class="meta">{{$cuotas}}</div>
</div>
@endforeach
</div>
</div>
@endforeach
</div>
<div class="ui divided list" id="cuotas_por_vencer"></div>
@push('page_scripts')
<script type="text/javascript">
const cuotas_por_vencer = {
get: function() {
const list = $('#cuotas_por_vencer')
list.html('')
list.append(
$('<div><div>').addClass('ui inline active loader')
)
return fetchAPI('{{$urls->api}}/ventas/cuotas/vencer').then(response => {
list.html('')
if (response.ok) {
return response.json()
}
}).then(data => {
this.draw(data.cuotas)
})
},
draw: function(cuotas) {
const list = $('#cuotas_por_vencer')
Object.entries(cuotas).forEach(([fecha, proyectos]) => {
const item = $('<div></div>').addClass('item')
const feed = $('<div></div>').addClass('ui feed')
feed.append(
$('<div></div>').addClass('date').append(
$('<strong></strong>').html(fecha)
)
)
Object.entries(proyectos).forEach(([proyecto, cuotas]) => {
const event = $('<div></div>').addClass('event')
event.append(
$('<div></div>').addClass('content').append(
$('<span></span>').addClass('ui small text').html(proyecto)
)
).append(
$('<div></div>').addClass('meta').html(cuotas)
)
feed.append(event)
})
item.append(feed)
list.append(item)
})
}
}
$(document).ready(() => {
cuotas_por_vencer.get()
})
</script>
@endpush

View File

@ -0,0 +1,36 @@
@extends('layout.base')
@section('page_title')
Inmobiliarias
@endsection
@section('page_content')
<div class="ui container">
<h2 class="ui header two columns grid">
<div class="column">
Inmobiliarias
</div>
{{--<div class="right aligned column">
<button class="ui icon button" type="button">
<i class="plus icon"></i>
</button>
</div>--}}
</h2>
<div class="ui divider"></div>
<div class="ui cards">
@foreach($inmobiliarias as $inmobiliaria)
<div class="ui card">
<div class="content">
<div class="header">
{{$inmobiliaria->abreviacion}}
{{--<a href="{{$urls->base}}/inmobiliaria/{{$inmobiliaria->rut}}">
</a>--}}
</div>
<div class="description">{{$inmobiliaria->razon}} {{$inmobiliaria->tipoSociedad->descripcion}}</div>
<div class="meta">{{$inmobiliaria->rut()}}</div>
</div>
</div>
@endforeach
</div>
</div>
@endsection

View File

@ -1,5 +1,6 @@
<header class="ui container">
<a class="ui medium image" href="{{$urls->base}}">
<br />
<a class="ui small image" href="{{$urls->base}}">
<img src="{{$urls->images}}/logo_cabezal.png" alt="logo" />
</a>
@include('layout.body.header.menu')

View File

@ -1,10 +1,10 @@
<nav class="ui borderless menu">
<a class="item" href="{{$urls->base}}"><img src="{{$urls->images}}/Isotipo 64.png" alt="brand" /></a>
{{--<a class="item" href="{{$urls->base}}"><img src="{{$urls->images}}/Isotipo 64.png" alt="brand" /></a>--}}
@if ($login->isIn())
@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,12 @@
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>
<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>
</div>
</div>

View File

@ -8,7 +8,7 @@
<div class="menu">
<a class="item" href="{{$urls->base}}/ventas/precios">Precios</a>
<a class="item" href="{{$urls->base}}/ventas/cierres">Cierres</a>
<a class="item" href="{{$urls->base}}/ventas">Ventas</a>
<a class="item" href="{{$urls->base}}/ventas/">Ventas</a>
<div class="item">
Cuotas
<i class="dropdown icon"></i>

View File

@ -2,6 +2,25 @@
<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 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

@ -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>
@ -34,11 +34,11 @@
}
}).then(data => {
if (data.login === true) {
@if(isset($redirect_uri))
window.location = '{{$redirect_uri}}'
@else
window.location = '{{$urls->base}}'
@endif
@if(isset($redirect_uri))
window.location = '{{$redirect_uri}}'
@else
window.location = '{{$urls->base}}'
@endif
}
})
}

View File

@ -0,0 +1,188 @@
@extends('layout.base')
@section('page_content')
<div class="ui container">
<h2 class="ui header">Proyectos</h2>
<table class="ui table">
<thead>
<tr>
<th>Proyecto</th>
<th>Inmobiliaria</th>
<th>Etapa</th>
<th>Estado</th>
<th>Tiempo Total</th>
<th>Tiempo RF</th>
</tr>
</thead>
<tbody>
@foreach ($proyectos as $proyecto)
<tr class="proyecto" data-id="{{$proyecto->id}}">
<td>
<a href="{{$urls->base}}/proyecto/{{$proyecto->id}}">
{{$proyecto->descripcion}}
</a>
</td>
<td>{{$proyecto->inmobiliaria()->nombreCompleto()}}</td>
<td class="etapa"></td>
<td class="estado"></td>
<td class="tiempo"></td>
<td class="recepcion"></td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection
@push('page_scripts')
<script type="text/javascript">
class Proyecto {
id
estados
constructor(id) {
this.id = id
this.estados = {
start: null,
current: null,
recepcion: null
}
}
get() {
return {
start: () => {
return fetchAPI('{{$urls->api}}/proyecto/' + this.id + '/inicio').then(response => {
if (response.ok) {
return response.json()
}
}).then(data => {
this.estados.start = data.estado
})
},
current: () => {
return fetchAPI('{{$urls->api}}/proyecto/' + this.id + '/estado').then(response => {
if (response.ok) {
return response.json()
}
}).then(data => {
this.estados.current = data.estado
})
},
recepcion: () => {
return fetchAPI('{{$urls->api}}/proyecto/' + this.id + '/recepcion').then(response => {
if (response.ok) {
if (response.status === 204) {
return null
}
return response.json()
}
}).then(data => {
if (data === null) {
return
}
this.estados.recepcion = data.estado
})
}
}
}
show() {
const row = $(".proyecto[data-id='" + this.id + "']")
const today = new Date()
return {
etapa: () => {
row.find('.etapa').html(this.estados.current.tipo_estado_proyecto.etapa.descripcion)
},
current: () => {
let estado = this.estados.current.tipo_estado_proyecto.descripcion
if (this.estados.current.tipo_estado_proyecto.etapa.descripcion === 'Terminado') {
row.find('.estado').html(estado)
return
}
let diff = (today - new Date(this.estados.current.fecha.date)) / (1000 * 60 * 60 * 24)
if (isNaN(diff) || diff === 0) {
row.find('.estado').html(estado)
return
}
let frame = 'días'
if (diff >= 30) {
diff /= 30
frame = 'meses'
if (diff >= 12) {
diff /= 12
frame = 'años'
}
}
if (diff > 0) {
estado += ' (hace ' + Math.floor(diff) + ' ' + frame + ')'
}
row.find('.estado').html(estado)
},
tiempo: () => {
if (this.estados.current.tipo_estado_proyecto.etapa.descripcion === 'Terminado') {
return
}
let diff = (today - new Date(this.estados.start.fecha.date)) / (1000 * 60 * 60 * 24)
if (isNaN(diff) || diff === 0) {
return
}
let frame = 'días'
if (diff >= 30) {
diff /= 30
frame = 'meses'
if (diff >= 12) {
diff /= 12
frame = 'años'
}
}
row.find('.tiempo').html(Math.floor(diff) + ' ' + frame)
},
recepcion: () => {
if (this.estados.recepcion === null) {
return
}
let diff = (today - new Date(this.estados.recepcion.fecha.date)) / (1000 * 60 * 60 * 24)
if (isNaN(diff) || diff === 0) {
return
}
let frame = 'dias'
if (diff >= 30) {
diff /= 30
frame = 'meses'
if (diff >= 12) {
diff /= 12
frame = 'años'
}
}
row.find('.recepcion').html(Math.floor(diff) + ' ' + frame)
}
}
}
}
function loadEstados(proyecto_id) {
const proyecto = new Proyecto(proyecto_id)
const promises = []
promises.push(proyecto.get().start())
promises.push(proyecto.get().current())
promises.push(proyecto.get().recepcion())
Promise.all(promises).then(() => {
proyecto.show().etapa()
proyecto.show().current()
proyecto.show().tiempo()
proyecto.show().recepcion()
})
}
$(document).ready(() => {
@foreach ($proyectos as $proyecto)
loadEstados('{{$proyecto->id}}')
@endforeach
})
</script>
@endpush

View File

@ -0,0 +1,490 @@
@extends('layout.base')
@section('page_title')
Proyecto {{$proyecto->descripcion}}
@endsection
@section('page_content')
<div class="ui container">
<h2 class="ui header">
Proyecto {{$proyecto->descripcion}} - {{$proyecto->inmobiliaria()->razon}}
</h2>
@php
$today = new DateTimeImmutable();
@endphp
<table class="ui striped table">
<tr>
<td>Dirección</td>
<td>{{$proyecto->direccion()}}</td>
</tr>
<tr>
<td>Inmobiliaria</td>
<td>{{$proyecto->inmobiliaria()->nombreCompleto()}}</td>
</tr>
<tr>
<td>Inicio</td>
<td>
{{$proyecto->estados()[0]->tipoEstadoProyecto->descripcion}}
[{{$proyecto->estados()[0]->tipoEstadoProyecto->etapa->descripcion}}]
({{$proyecto->estados()[0]->fecha->format('d-m-Y')}})
({{$today->diff($proyecto->estados()[0]->fecha)->format('%y años antes')}})
</td>
</tr>
<tr>
<td>Estado</td>
<td>
{{$proyecto->currentEstado()->tipoEstadoProyecto->descripcion}}
[{{$proyecto->currentEstado()->tipoEstadoProyecto->etapa->descripcion}}]
({{$proyecto->currentEstado()->fecha->format('d-m-Y')}})
({{$today->diff($proyecto->currentEstado()->fecha)->format('%y años antes')}})
<span class="ui blue text" id="estados_avanzar" style="cursor: pointer;">
<i class="right chevron icon"></i>
</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>
<table class="ui very basic striped table">
<tr>
<td>
<strong>
Total
</strong>
</td>
<td>
<strong>
{{$format->number($proyecto->superficie->total(), 2)}}m&#0178;
</strong>
</td>
<td rowspan="6" id="chart_superficies" class="six wide"></td>
</tr>
<tr>
<td>Bajo Nivel</td>
<td>{{$format->number($proyecto->superficie->bajo_nivel, 2)}}m&#0178;</td>
</tr>
<tr>
<td>Sobre Nivel</td>
<td>{{$format->number($proyecto->superficie->sobre_nivel, 2)}}m&#0178;</td>
</tr>
<tr>
<td>
<strong>
Vendible
</strong>
</td>
<td>
<strong id="superficie_vendible"></strong>
</td>
</tr>
<tr>
<td>Vendido</td>
<td id="superficie_vendido"></td>
</tr>
<tr>
<td>Por Vender</td>
<td id="superficie_por_vender"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>Unidades</td>
<td id="unidades"></td>
</tr>
<tr>
<td>Ventas</td>
<td id="ventas"></td>
</tr>
<tr>
<td>Stock</td>
<td id="stock"></td>
</tr>
<tr>
<td>Proyección</td>
<td id="proyeccion"></td>
</tr>
<tr>
<td colspan="2" id="chart_venta_general"></td>
</tr>
<tr>
<td colspan="2" id="chart_venta_tipologias"></td>
</tr>
<tr>
<td colspan="2" id="chart_venta_velocidad"></td>
</tr>
</table>
</div>
@endsection
@include('layout.body.scripts.chartjs')
@push('page_scripts')
<script type="text/javascript">
const superficies = {
ids: {
vendible: '',
vendido: '',
por_vender: '',
chart: ''
},
data: {},
chart_obj: null,
get: function() {
return {
superficies: () => {
const url = '{{$urls->api}}/proyecto/{{$proyecto->id}}/superficies/vendible'
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
}
}).then(data => {
this.data = data
this.fill()
this.chart()
})
}
}
},
fill: function() {
$(this.ids.vendible).html(this.data.formatted.vendible)
$(this.ids.vendido).html(this.data.formatted.vendido)
$(this.ids.por_vender).html(this.data.formatted.por_vender)
},
chart: function() {
const container = $(this.ids.chart)
container.html('')
this.chart_obj = null
const ctx = $('<canvas></canvas>').attr('width', '100')
container.append(ctx)
const data = {
labels: [
'Vendida',
'Por Vender'
],
datasets: [
{
label: 'Superficies',
data: [
this.data.superficies.vendido,
this.data.superficies.por_vender
],
backgroundColor: [
'green',
'red'
]
}
]
}
const options = {
type: 'pie',
data
}
this.chart_obj = new Chart(ctx, options)
},
setup: function({id_vendible, id_vendido, id_por_vender, id_chart}) {
this.ids.vendible = id_vendible
this.ids.vendido = id_vendido
this.ids.por_vender = id_por_vender
this.ids.chart = id_chart
this.get().superficies()
}
}
const unidades = {
id: '',
data: {},
get: function() {
const url = '{{$urls->api}}/proyecto/{{$proyecto->id}}/unidades'
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
}
}).then(data => {
this.data = data
this.draw()
})
},
draw: function() {
const parent = $(this.id)
const table = $('<table></table>').addClass('ui very basic striped table')
Object.entries(this.data.unidades).forEach(([tipo, unidades]) => {
tipo = tipo.charAt(0).toUpperCase() + tipo.slice(1) + 's'
table.append(
$('<tr></tr>').append(
$('<td></td>').html(tipo)
).append(
$('<td></td>').html(unidades.length)
)
)
})
parent.append(table)
},
setup: function(id) {
this.id = id
this.get()
}
}
const ventas = {
ids: {
ventas: '',
stock: '',
proyeccion: '',
charts: {
general: '',
tipologias: '',
velocidad: ''
}
},
data: {
ventas: {
unidades: {},
valores: {
total: 0,
promedio: 0,
bonos: 0,
promociones: 0,
operadores: 0,
metro: 0,
},
superficies: {
total: 0,
promedio: 0
}
},
stock: {
unidades: {},
valores: {
total: 0,
promedio: 0,
bonos: 0,
promociones: 0,
operadores: 0,
metro: 0,
},
superficies: {
total: 0,
promedio: 0
}
}
},
get: function() {
return {
ventas: () => {
const url = '{{$urls->api}}/ventas'
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()
}
}).then(data => {
const promises = []
data.ventas.forEach(venta_id => {
promises.push(this.get().venta(venta_id))
})
return Promise.all(promises).then(() => {
const cantidad_total = Object.values(this.data.ventas.unidades).reduce((sum, cantidad) => sum + cantidad, 0)
this.data.ventas.valores.promedio = this.data.ventas.valores.total / cantidad_total
this.data.ventas.superficies.promedio = this.data.ventas.superficies.total / cantidad_total
this.data.ventas.valores.metro = this.data.ventas.valores.total / this.data.ventas.superficies.total
this.draw().ventas()
})
})
},
stock: () => {
const url = '{{$urls->api}}/proyecto/{{$proyecto->id}}/unidades/disponibles'
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
}
}).then(data => {
const promises = []
data.unidades.forEach(unidad => {
this.add().unidad(unidad)
promises.push(this.get().precio(unidad.id))
})
return Promise.all(promises).then(() => {
const cantidad_total = Object.values(this.data.stock.unidades).reduce((sum, cantidad) => sum + cantidad, 0)
this.data.stock.valores.promedio = this.data.stock.valores.total / cantidad_total
this.data.stock.superficies.promedio = this.data.stock.superficies.total / cantidad_total
this.data.stock.valores.metro = this.data.stock.valores.total / this.data.stock.superficies.total
this.draw().stock()
})
})
},
venta: venta_id => {
const url = '{{$urls->api}}/venta/' + venta_id
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
}
}).then(data => {
this.add().venta(data.venta)
})
},
precio: unidad_id => {
const url = '{{$urls->api}}/ventas/precio/unidad/' + unidad_id
return fetchAPI(url).then(response => {
if (response.ok) {
if (response.status === 204) {
return null
}
return response.json()
}
}).then(data => {
if (data === null) {
return
}
this.add().precio(data.precio)
})
}
}
},
add: function() {
return {
venta: venta => {
Object.entries(venta.propiedad).forEach(([tipo, unidades]) => {
if (tipo === 'summary') {
return
}
tipo = tipo.charAt(0).toUpperCase() + tipo.slice(1)
if (typeof this.data.ventas.unidades[tipo] === 'undefined') {
this.data.ventas.unidades[tipo] = 0
}
this.data.ventas.unidades[tipo] ++
this.data.ventas.superficies.total += unidades.reduce((sum, unidad) => sum + unidad.proyecto_tipo_unidad.vendible, 0)
this.data.ventas.valores.total += venta.valor
if (venta.forma_pago.bono_pie !== null) {
this.data.ventas.valores.bonos += venta.forma_pago.bono_pie
}
})
},
unidad: unidad => {
let tipo = unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
tipo = tipo.charAt(0).toUpperCase() + tipo.slice(1) + 's'
if (typeof this.data.stock.unidades[tipo] === 'undefined') {
this.data.stock.unidades[tipo] = 0
}
this.data.stock.unidades[tipo] ++
this.data.ventas.superficies.total += unidad.proyecto_tipo_unidad.vendible
},
precio: precio => {
this.data.stock.valores.total += precio.valor
}
}
},
draw: function() {
return {
loading: parent => {
parent.html('')
parent.append(
$('<div></div>').addClass('ui active inline loader')
)
},
ventas: () => {
const parent = $(this.ids.ventas)
parent.html('')
this.draw().table(parent, this.data.ventas)
},
stock: () => {
const parent = $(this.ids.stock)
parent.html('')
this.draw().table(parent, this.data.stock)
},
proyeccion: () => {
},
table: (parent, data) => {
const formatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
const table = $('<table></table>').addClass('ui very basic striped table')
let row = $('<tr></tr>')
let row2 = $('<tr></tr>')
Object.entries(data.unidades).forEach(([tipo, cantidad]) => {
row.append(
$('<td></td>').html(tipo)
)
row2.append(
$('<td></td>').html(cantidad)
)
})
table.append(row).append(row2)
row = $('<tr></tr>').append(
$('<td></td>').html('Valor Total [UF]')
).append(
$('<td></td>').html('Valor Promedio [UF]')
).append(
$('<td></td>').html('Valor Metro [UF/m²]')
)
table.append(row)
row = $('<tr></tr>').append(
$('<td></td>').html(formatter.format(data.valores.total))
).append(
$('<td></td>').html(formatter.format(data.valores.promedio))
).append(
$('<td></td>').html(formatter.format(data.valores.metro))
)
table.append(row)
parent.append(table)
}
}
},
chart: function() {
return {
general: () => {},
tipologias: () => {},
velocidad: () => {}
}
},
setup: function({id_ventas, id_stock, id_proyeccion, id_chart_general, id_chart_tipologias, id_chart_velocidad}) {
this.ids.ventas = id_ventas
this.ids.stock = id_stock
this.ids.proyeccion = id_proyeccion
this.ids.charts.general = id_chart_general
this.ids.charts.tipologias = id_chart_tipologias
this.ids.charts.velocidad = id_chart_velocidad
const promises = []
promises.push(this.get().ventas())
promises.push(this.get().stock())
Promise.all(promises).then(() => {
this.draw().proyeccion()
this.chart().general()
this.chart().tipologias()
this.chart().velocidad()
})
}
}
$(document).ready(() => {
$('#estados_avanzar').click(event => {
alert('Avanzar')
})
superficies.setup({id_vendible: '#superficie_vendible', id_vendido: '#superficie_vendido',
id_por_vender: '#superficie_por_vender', id_chart: '#chart_superficies'})
unidades.setup('#unidades')
ventas.setup({id_ventas: '#ventas', id_stock: '#stock', id_proyeccion: '#proyeccion',
id_chart_general: '#chart_venta_general', id_chart_tipologias: '#chart_venta_tipologia',
id_chart_velocidad: '#chart_venta_velocidad'})
})
</script>
@endpush

View File

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

View File

@ -0,0 +1,234 @@
@extends('layout.base')
@section('page_content')
<div class="ui container">
<h2 class="ui header">Unidades por Proyecto</h2>
<h4 class="ui dividing header">
<div class="ui two column grid">
<div id="list_title" class="column">Proyectos</div>
<div class="right aligned column">
<div class="ui tiny icon buttons">
<button id="up_button" class="ui button">
<i class="up arrow icon"></i>
</button>
<button id="refresh_button" class="ui button">
<i class="refresh icon"></i>
</button>
</div>
<button class="ui tiny green icon button" id="add_button">
<i class="plus icon"></i>
</button>
</div>
</div>
</h4>
<div id="proyectos" class="ui link selection list">
@foreach ($proyectos as $proyecto)
<div class="item" data-proyecto="{{$proyecto->id}}">{{$proyecto->descripcion}}</div>
@endforeach
</div>
<table class="ui table" id="data"></table>
</div>
@endsection
@push('page_styles')
<style>
.show-unidades, .linea {
cursor: pointer;
}
</style>
@endpush
@push('page_scripts')
<script type="text/javascript">
class Unidad
{
id
descripcion
piso
linea
constructor({id, descripcion, piso, linea})
{
this.id = id
this.descripcion = descripcion
this.piso = piso
this.linea = linea
}
draw(parent)
{
const row = $('<tr></tr>').addClass('unidad').attr('data-linea', linea).append(
$('<td></td>').html(this.descripcion)
).append(
$('<td></td>').html(this.piso)
).append(
$('<td></td>').addClass('right aligned').append(
$('<button></button>').addClass('ui yellow icon button').attr('type', 'button').append(
$('<i></i>').addClass('edit icon')
)
).append(
$('<button></button>').addClass('ui red icon button').attr('type', 'button').append(
$('<i></i>').addClass('remove icon')
)
)
)
parent.append(row)
}
}
class Linea
{
numero
orientacion
unidades
constructor({numero, orientacion})
{
this.numero = numero
this.orientacion = orientacion
this.unidades = []
}
get cantidad()
{
return this.unidades.length
}
get pisos()
{
if (this.cantidad === 0) {
return ''
}
const pisos = this.unidades.map(unidad => unidad.piso)
return Math.min(pisos) + ' - ' + Math.max(pisos)
}
get descripcion()
{
return 'Linea ' + this.numero
}
draw(parent)
{
const row = $('<tr></tr>').addClass('linea').attr('data-id', this.numero).attr('data-status', 'closed').append(
$('<td></td>').append(
$('<strong></strong>').html(this.descripcion)
).append(
$('<i></i>').addClass('caret right icon')
)
).append(
$('<td></td>').append(
$('<stong></stong>').html(this.orientacion)
)
).append($('<td></td>'))
parent.append(row)
this.unidades.forEach(unidad => {
unidad.draw(parent)
})
}
}
class ProyectoTipoUnidad
{
id
descripcion
tipo
tipologia
superficies
lineas
constructor({id, descripcion, tipo, tipologia, superficies})
{
this.id = id
this.descripcion = descripcion
this.tipo = tipo
this.tipologia = tipologia
this.superficies = superficies
this.lineas = []
}
get cantidad()
{
return this.lineas.reduce((sum, linea) => sum + linea.cantidad)
}
draw(parent)
{
const row = $('<tr></tr>').addClass('proyecto_tipo_unidad').attr('data-id', this.id).attr('data-status', 'closed').append(
$('<td></td>').append(this.tipo.descripcion).append(
$('<i></i>').addClass('caret icon right')
)
).append(
$('<td></td>').html(this.descripcion)
).append(
$('<td></td>').html(this.tipologia.abreviacion)
).append(
$('<td></td>').html(this.cantidad)
).append(
$('<td></td>').html(this.lineas.map(linea => linea.numero).join(' - '))
).append(
$('<td></td>').html(this.superficies.interior)
).append(
$('<td></td>').html(this.superficies.terraza)
).append(
$('<td></td>').html(this.superficies.vendible)
).append(
$('<td></td>').html(this.superficies.total)
).append(
$('<td></td>').html(this.tipologia.descripcion)
)
parent.append(row)
const tbody = $('<tbody></tbody>')
this.lineas.forEach(linea => {
linea.draw(tbody)
})
const table = $('<table></table>').addClass('ui table').append(
$('<thead></thead>').append(
$('<th></th>').html('Unidad')
).append(
$('<th></th>').html('Orientacion')
).append(
$('<th></th>').html('Cantidad<br />Piso')
)
).append(tbody)
const line_row = $('<tr></tr>').addClass('unidades').attr('data-tipo', this.id).append(
$('<td></td>')
).append(
$('<td></td>').attr('colspan', 9).append(table)
)
parent.append(line_row)
}
}
const proyectos = {
ids: {},
tipos: [],
get: function() {
return {
tipos: proyecto_id => {
const url = '{{$urls->api}}/proyecto/' + proyecto_id + '/unidades/tipos'
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
}
}).then(data => {
console.debug(tipos)
})
}
}
},
setup: function() {
$('.item.proyecto').click(event => {
if (this.loading.precios) {
return false
}
const element = $(event.currentTarget)
$('.item.proyecto').css('cursor', 'wait')
this.loading.precios = true
const proyecto_id = element.data('proyecto')
this.get().tipos(proyecto_id)
})
$('#data').hide()
}
}
$(document).ready(() => {
proyectos.setup()
})
</script>
@endpush

View File

@ -0,0 +1,338 @@
@extends('layout.base')
@section('page_content')
<div class="ui container">
<h1>Búsqueda</h1>
<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">
<input type="text" name="query" />
</div>
</div>
<div class="ui search selection dropdown" id="tipo">
<input type="hidden" name="tipo" />
<i class="dropdown icon"></i>
<div class="default text">Tipo</div>
<div class="menu">
<div class="item" data-value="*" data-selected="true">Cualquiera</div>
@foreach (['departamento', 'estacionamiento', 'bodega', 'propietario', 'precio_venta', 'proyecto', 'pago', 'unidad'] as $value)
<div class="item" data-value="{{$value}}">{{ucwords(str_replace('_', ' ', $value))}}</div>
@endforeach
</div>
</div>
<button class="ui button" type="submit">Buscar</button>
</form>
<div id="results"></div>
</div>
@endsection
@include('layout.head.styles.datatables')
@include('layout.body.scripts.datatables')
@push('page_scripts')
<script type="text/javascript">
class Row
{
proyecto
unidad
venta
constructor({proyecto, unidad}) {
this.proyecto = proyecto
this.unidad = unidad
}
draw() {
const tipo = this.unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
let unidad = tipo.charAt(0).toUpperCase() + tipo.slice(1) + ' ' + this.unidad.descripcion
let precio = 0
let propietario = ''
let fecha = ''
let fecha_entrega = ''
if (typeof this.venta !== 'undefined') {
const dateFormatter = new Intl.DateTimeFormat('es-CL', {dateStyle: 'medium'})
unidad = $('<a></a>').attr('href', '{{$urls->base}}/venta/' + this.venta.id).html(unidad)
if (!this.venta.current_estado.tipo_estado_venta.activa) {
unidad.html(unidad.html() + ' (I)')
}
propietario = $('<a></a>')
.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') {
fecha_entrega = dateFormatter.format(new Date(this.venta.entrega.fecha))
}
precio = this.venta.valor
} else {
unidad += '<i class="ban icon"></i>'
precio = this.unidad.current_precio.valor
}
const numberFormat = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
const superficie = numberFormat.format(Math.round(this.unidad.proyecto_tipo_unidad.superficie * 100) / 100)
return $('<tr></tr>').append(
$('<td></td>').append(
$('<a></a>').attr('href', '{{$urls->base}}/proyecto/' + this.proyecto.id).html(this.proyecto.descripcion)
)
).append(
$('<td></td>').append(unidad)
).append(
$('<td></td>').append(this.unidad.descripcion.padStart(4, '0'))
).append(
$('<td></td>').append(propietario)
).append(
$('<td></td>').addClass('right aligned').html(superficie + ' m&#0178;')
).append(
$('<td></td>').addClass('right aligned').html(numberFormat.format(precio))
).append(
$('<td></td>').html(fecha)
).append(
$('<td></td>').html(fecha_entrega)
)
}
}
const results = {
id: '',
data: [],
table: null,
get: function() {
return {
results: () => {
if ($("[name='query']").val().length < 1) {
return
}
this.draw().loading()
const data = new FormData(document.getElementById('search_form'))
const uri = '{{$urls->api}}/search'
this.data = []
return fetchAPI(uri, {method: 'post', body: data}).then(response => {
if (!response) {
return
}
return response.json()
}).catch(error => {
this.draw().clear()
this.draw().error(error)
}).then(data => {
this.draw().clear()
if (typeof data.results === 'undefined' || data.results.length === 0) {
this.draw().empty()
return
}
const progress = this.draw().progress(data.results.length)
const promises = []
data.results.forEach(row => {
if (row.tipo === 'venta') {
return promises.push(this.get().venta(row.id).then(json => {
if (json.venta === null) {
console.debug(json)
return
}
const venta = json.venta
progress.progress('increment')
const r = new Row({unidad: venta.propiedad.unidades[0], proyecto: venta.proyecto})
r.venta = venta
this.data.push(r)
}).catch(error => {
progress.progress('increment')
console.error(row)
console.error(error)
}))
}
promises.push(this.get().unidad(row.id).then(json => {
const unidad = json.unidad
progress.progress('increment')
this.data.push(new Row({unidad: unidad, proyecto: unidad.proyecto_tipo_unidad.proyecto}))
}).catch(error => {
progress.progress('increment')
console.error(row)
console.error(error)
}))
})
Promise.all(promises).then(() => {
this.sort()
this.draw().clear()
this.draw().table()
})
})
},
unidad: id => {
const url = '{{$urls->api}}/ventas/unidad/' + id
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
}
})
},
venta: id => {
const url = '{{$urls->api}}/venta/' + id
return fetchAPI(url).then(response => {
if (!response) {
return
}
return response.json()
})
}
}
},
sort: function() {
this.data.sort((a, b) => {
const p = a.proyecto.descripcion.localeCompare(b.proyecto.descripcion)
if (p === 0) {
const t = a.unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
.localeCompare(b.unidad.proyecto_tipo_unidad.tipo_unidad.descripcion)
if (t === 0) {
return a.unidad.descripcion.localeCompare(b.unidad.descripcion)
}
return t
}
return p
})
},
draw: function() {
return {
clear: () => {
$(this.id).html('')
},
separator: () => {
this.draw().clear()
$(this.id).append(
$('<div></div>').addClass('ui horizontal divider').html('Resultados')
)
},
loading: () => {
this.draw().separator()
$(this.id).append(
$('<div></div>').addClass('ui active centered inline loader')
)
},
table: () => {
const parent = $(this.id)
this.draw().separator()
if (this.table !== null) {
this.table.clear()
.draw()
.destroy()
this.table = null
}
const table = $('<table></table>').addClass('ui table')
const thead = this.draw().head()
const tbody = $('<tbody></tbody>')
this.data.forEach(row => {
tbody.append(row.draw())
})
table.append(thead).append(tbody)
parent.append(table)
this.table = new DataTable(table, {
pageLength: 25,
order: [
[0, 'asc'],
[2, 'asc']
],
columnDefs: [
{
target: 2,
visible: false,
searchable: false
},
{
target: 1,
orderData: [2]
}
]
})
},
head: () => {
return $('<thead></thead>').append(
$('<tr></tr>').append(
$('<th></th>').html('Proyecto')
).append(
$('<th></th>').html('Unidad')
).append(
$('<th></th>').html('Unidad [Sort]')
).append(
$('<th></th>').html('Propietario')
).append(
$('<th></th>').html('Superficie')
).append(
$('<th></th>').html('Valor')
).append(
$('<th></th>').html('Fecha Venta')
).append(
$('<th></th>').html('Fecha Entrega')
)
)
},
empty: () => {
this.draw().separator()
$(this.id).append(
$('<div></div>').addClass('ui icon info message').append(
$('<i></i>').addClass('meh outline icon')
).append(
$('<div></div>').addClass('content').html('No se han encontrado resultados.')
)
)
},
error: error => {
this.draw().separator()
$(this.id).append(
$('<div></div>').addClass('ui icon error message').append(
$('<i></i>').addClass('exclamation triangle icon')
).append(
$('<div></div>').addClass('content').html(error)
)
)
},
progress: cantidad => {
this.draw().separator()
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}%)'
}
})
$(this.id).append(progress)
return progress
}
}
},
setup: function(id) {
this.id = id
this.get().results()
$('#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
$('#search_form').submit(event => {
event.preventDefault()
this.get().results()
return false
})
$("[name='query']").focus()
}
}
$(document).ready(() => {
results.setup('#results')
})
</script>
@endpush

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->base}}/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()
}
@ -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

@ -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

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