Compare commits
349 Commits
feature/pr
...
5b6a1c42e3
Author | SHA1 | Date | |
---|---|---|---|
5b6a1c42e3 | |||
81bce6fe7f | |||
e1072ea252 | |||
21473fe52c | |||
7d589e0e87 | |||
c48a0d2381 | |||
abb1ce7299 | |||
f1ed9668fc | |||
f9ae809fc4 | |||
06e5292af1 | |||
47ba664142 | |||
d10ee33215 | |||
5134630525 | |||
13b246b998 | |||
d601d7d719 | |||
dc0ae2746b | |||
eb402b1b71 | |||
c5188a1feb | |||
1c3052219c | |||
9e8a388653 | |||
cbee830f7a | |||
d5b8c7f877 | |||
b668844fea | |||
f2169c9536 | |||
48bcb33bad | |||
92ae0b4ac2 | |||
44540d0dc3 | |||
d9a2f63691 | |||
b10accf602 | |||
981858f251 | |||
8c0bd450ef | |||
8996765cb4 | |||
ec2451cb69 | |||
37d30d2aec | |||
afb6e2526f | |||
a9b6f2a87b | |||
9aeb6906f6 | |||
879d365baf | |||
1d03b262ae | |||
2c175c8171 | |||
a750bdbfaa | |||
7f6d0232c0 | |||
37cff67a1c | |||
bc3d739af9 | |||
46efbb57c1 | |||
d71333b334 | |||
688b500f1e | |||
d4b1a66a9e | |||
e796d91d95 | |||
2a442417ce | |||
3c161ed4e9 | |||
3c8822e531 | |||
b3b91d3f8f | |||
6e34a76a3f | |||
ed29dfb984 | |||
7f37dc76e3 | |||
a62293e509 | |||
fbfc2cb8ae | |||
02665ac6bd | |||
300d966f3f | |||
27031035ed | |||
18fc9a76fd | |||
cb6fa73a21 | |||
8796762cfe | |||
99c9952c93 | |||
9895fd6a70 | |||
c1149d89be | |||
7d8e2249de | |||
a54586e870 | |||
734f258382 | |||
f728ed0b55 | |||
6144accb8e | |||
f399eb8d47 | |||
b4159d1417 | |||
2a792a947d | |||
25710d616a | |||
3197802264 | |||
6c53127c2f | |||
b7391a77d3 | |||
5b499aee75 | |||
4505531c5f | |||
3f8adc753c | |||
ace205798f | |||
6e0e1fc75e | |||
026474c63c | |||
f32204df97 | |||
2852816eae | |||
892cdf324f | |||
a9a10e012d | |||
b7089f7a1c | |||
aed26cfcd8 | |||
896dded6eb | |||
3b03c4b64b | |||
f34ed03b84 | |||
ce75ec1548 | |||
312baa34f6 | |||
b7c5e4ebc3 | |||
105179b4ed | |||
16cd29635d | |||
2bdb2a0ed0 | |||
8ce7d2570d | |||
8ba54fd3ad | |||
f47f86dd2b | |||
8ca68bf7e8 | |||
8965354528 | |||
8d32aecd09 | |||
c8f79e076e | |||
9e0d604d79 | |||
331d004040 | |||
03317b3aa5 | |||
e33edc4d7b | |||
bb459a2ff5 | |||
5e2d2e861f | |||
e9b2fe9963 | |||
2f481ef8a9 | |||
386fe452af | |||
91ad1e39f8 | |||
a3a5b58cfb | |||
1d77d65af2 | |||
0f0c81e283 | |||
ac278ca690 | |||
97d34f9ad6 | |||
134588c96d | |||
8b6516241d | |||
d6e60efcaf | |||
3e937ab748 | |||
fa6881d0a9 | |||
f07c1f1cbd | |||
148d08089d | |||
45b6ee710e | |||
c84277fdc4 | |||
c0024a4a63 | |||
308a84a448 | |||
91c74bf113 | |||
024a6eae54 | |||
d536342425 | |||
e7f3b33850 | |||
c47d94d475 | |||
ee74fc7588 | |||
5ac324de6a | |||
dfb0ff7aea | |||
6d1a1c914a | |||
b45d03aa7e | |||
4e0b611bcf | |||
20ea5d021d | |||
32dc24a783 | |||
95a6aa96e9 | |||
f14cdd2730 | |||
3006adb0f7 | |||
d22480dcb8 | |||
425b85e40d | |||
2c21e48562 | |||
8d3ce99be7 | |||
35386724b3 | |||
1597657f0e | |||
c6bbaf3404 | |||
9e2d7277b0 | |||
abe37227ce | |||
32130f0bc2 | |||
d78bdaa7f5 | |||
1266c3859d | |||
c5466b2c4d | |||
6d8e8a9068 | |||
4d5b657b92 | |||
4ca1616dfc | |||
fb7177fd65 | |||
1486d6cf38 | |||
8b2de31e02 | |||
61324f159b | |||
c95e74d574 | |||
59ecb6cc79 | |||
db84187461 | |||
c2f98c8b0d | |||
8d73987ac3 | |||
400b2754bf | |||
418becaeda | |||
679b401101 | |||
26b6862955 | |||
e239669839 | |||
adc0e52c1e | |||
d1905194bd | |||
a5c1d60819 | |||
5ad4fc4038 | |||
ca5354a3ee | |||
c1ebac6c0c | |||
f742c7ddd0 | |||
5d5f9866bb | |||
0866292d84 | |||
e02ed4684f | |||
8be5f94b7c | |||
878b02ee52 | |||
f3e15b34a8 | |||
3903551176 | |||
43eb8ec758 | |||
a405b15410 | |||
a2f2d94e64 | |||
0587b64d65 | |||
a6b81f1bff | |||
4239bafc26 | |||
6591e9f80e | |||
b57f32c86b | |||
0e903f99c4 | |||
186cd0f5b8 | |||
167d8e1ab7 | |||
46802507a7 | |||
aaf2ed7612 | |||
3ced9e40b1 | |||
594cb68b09 | |||
af68c4b8ec | |||
ea8f483dd5 | |||
5f53c77a1f | |||
b9adb9108b | |||
8be085222a | |||
d1e4314b35 | |||
7d04b406ab | |||
972e57b6f1 | |||
5f63bdbf4a | |||
a8325c3310 | |||
7e54b72587 | |||
ebe31a3d3d | |||
db6445bcf3 | |||
4e1901b7c8 | |||
c3316029c9 | |||
cbfc796685 | |||
da56192f97 | |||
b5d08620f9 | |||
c92b07ee6f | |||
ee6956d417 | |||
21d5e2d03b | |||
73a742c01e | |||
dd42c12d49 | |||
41ea5f5c15 | |||
eeb6f5bcd1 | |||
2680f51167 | |||
019d57a0b0 | |||
1a400d9a5c | |||
6276f87274 | |||
28c93a42bc | |||
4ff5d28522 | |||
a93642c55d | |||
87c0d8c8d9 | |||
dd1741a930 | |||
ad0fd82a9e | |||
bae5c1740d | |||
f5f1482b7a | |||
4bd5fe16df | |||
61845fbd05 | |||
f8ac0f14f0 | |||
acb7a1336d | |||
8af56137a8 | |||
c3247838b3 | |||
dd82ac6bb7 | |||
2acf0362fa | |||
e6892ee085 | |||
86b8d6b3c7 | |||
53115b085f | |||
c3b7427f60 | |||
5d939f970b | |||
4845801b27 | |||
d5bf9a7660 | |||
795dda868b | |||
53a3633dc7 | |||
0143fd11ac | |||
55745a8d0a | |||
2a1930c5f7 | |||
31f49dddb6 | |||
b4ca59fb6d | |||
d910f3eb69 | |||
555cdb7138 | |||
65088da2f5 | |||
966b341b65 | |||
90b05ca25c | |||
bb3a2fffa1 | |||
8a5e41a722 | |||
5736a346e7 | |||
4f4e69f0c3 | |||
00deebeaa8 | |||
aee0754b5a | |||
eabdab23c3 | |||
5147450ed6 | |||
ed96f25475 | |||
d5a3512852 | |||
d6730cd020 | |||
c7dddc818c | |||
33b4182bd3 | |||
fc776e6cec | |||
5d79ea83c3 | |||
c34048a53a | |||
f7af93b815 | |||
993e4ff3b8 | |||
bc49ba7629 | |||
3c2b486083 | |||
76f69f3bda | |||
8ba3c456b6 | |||
98b18fab3e | |||
12a4831887 | |||
da46914de4 | |||
596bc71cf8 | |||
7f8e4ea943 | |||
5456485f71 | |||
836503a71b | |||
4df0cca675 | |||
00a0adb4ac | |||
037fcd60f3 | |||
7a97fc9dfe | |||
7b2df74e4d | |||
b5d6d0acb9 | |||
8a1e6a7761 | |||
ced673e452 | |||
8a7a1d4e64 | |||
9be20ab1cd | |||
1c40f18624 | |||
db36549699 | |||
4ce83fb270 | |||
b191a01313 | |||
d3b0026ca4 | |||
2b3f476df7 | |||
39c148b7b3 | |||
bae0f1f555 | |||
2e49e2c947 | |||
68aebdb4fe | |||
346001db8e | |||
8b04eb262f | |||
7c7c8315e2 | |||
510e05e5ca | |||
5055d2703c | |||
2bc30ab9e8 | |||
c7ee440e03 | |||
18dd8c4ec0 | |||
8ea4995f6b | |||
aeeca65d94 | |||
5f69069aa0 | |||
095a65a643 | |||
928d2e57be | |||
2a0335f834 | |||
9ccf53fa4e | |||
ef54c36edc | |||
4aa88d5164 | |||
8ea13c3efd | |||
12e3d7ed3b | |||
a7fc89ac29 | |||
a71df4e70d | |||
f17b7a758a | |||
7fb28cd44c | |||
a44bd610ad | |||
28bba8a438 | |||
0ec6ebdafe | |||
3ebe256a66 | |||
9d135e2c26 |
@ -1,4 +1,4 @@
|
||||
FROM php:8.2-cli
|
||||
FROM php:8.4-cli
|
||||
|
||||
ENV TZ "${TZ}"
|
||||
ENV APP_NAME "${APP_NAME}"
|
||||
@ -6,11 +6,14 @@ ENV API_URL "${API_URL}"
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends cron rsyslog nano && rm -r /var/lib/apt/lists/*
|
||||
|
||||
RUN pecl install xdebug-3.2.2 \
|
||||
RUN pecl install xdebug-3.4.2 \
|
||||
&& docker-php-ext-enable xdebug \
|
||||
&& echo "#/bin/bash\nprintenv >> /etc/environment\ncron -f -L 11" > /root/entrypoint && chmod a+x /root/entrypoint
|
||||
&& echo $TZ > /etc/timezone
|
||||
|
||||
COPY --chmod=550 ./cli/entrypoint /root/entrypoint
|
||||
|
||||
COPY ./php-errors.ini /usr/local/etc/php/conf.d/docker-php-errors.ini
|
||||
COPY ./php-timezone.ini /usr/local/etc/php/conf.d/docker-php-timezone.ini
|
||||
|
||||
WORKDIR /code/bin
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
FROM php:8.2-fpm
|
||||
FROM php:8.4-fpm
|
||||
|
||||
ENV TZ=America/Santiago
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends 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 libxml2-dev \
|
||||
&& rm -r /var/lib/apt/lists/* \
|
||||
&& docker-php-ext-install pdo pdo_mysql zip intl gd bcmath \
|
||||
&& pecl install xdebug-3.3.2 \
|
||||
&& docker-php-ext-install pdo pdo_mysql zip intl gd bcmath dom \
|
||||
&& pecl install xdebug-3.4.2 \
|
||||
&& docker-php-ext-enable xdebug \
|
||||
&& echo $TZ > /etc/timezone
|
||||
|
||||
|
@ -2,17 +2,18 @@
|
||||
|
||||
APP_URL=
|
||||
|
||||
MYSQL_HOST=db
|
||||
|
||||
COOKIE_NAME=
|
||||
COOKIE_DOMAIN=
|
||||
COOKIE_PATH=/
|
||||
MAX_LOGIN_HOURS=120
|
||||
|
||||
REDIS_HOST=redis
|
||||
REDIS_PORT=6379
|
||||
#REDIS_HOST=redis
|
||||
#REDIS_PORT=6379
|
||||
|
||||
DB_HOST=db
|
||||
DB_DATABASE=incoviba
|
||||
DB_USER=incoviba
|
||||
DB_PASSWORD=
|
||||
|
||||
TOKU_URL=
|
||||
TOKU_TOKEN=
|
||||
|
1
app/.gitignore
vendored
1
app/.gitignore
vendored
@ -1 +1,2 @@
|
||||
**/bin
|
||||
**/public/tests
|
||||
|
@ -10,5 +10,5 @@ notifications:
|
||||
failingTests: false
|
||||
hideManual: true
|
||||
phpunit:
|
||||
arguments: '--log-events-text /logs/output.txt --stop-on-failure'
|
||||
arguments: '--testsuite unit --log-events-text /logs/output.txt --stop-on-failure'
|
||||
timeout: 180
|
||||
|
3
app/bin/console
Normal file
3
app/bin/console
Normal file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
php -d auto_prepend_file=test.bootstrap.php -a
|
3
app/bin/integration_tests
Normal file
3
app/bin/integration_tests
Normal file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
bin/phpunit --testsuite acceptance $@
|
3
app/bin/performance_tests
Normal file
3
app/bin/performance_tests
Normal file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
bin/phpunit --testsuite performance $@
|
3
app/bin/unit_tests
Normal file
3
app/bin/unit_tests
Normal file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
./bin/phpunit --testsuite unit $@
|
@ -1,9 +1,6 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Alias;
|
||||
|
||||
use Illuminate\Events\Dispatcher;
|
||||
use Slim\Views\Blade;
|
||||
|
||||
class View extends Blade
|
||||
{
|
||||
}
|
||||
class View extends Blade {}
|
||||
|
@ -8,9 +8,9 @@ interface Provider
|
||||
{
|
||||
/**
|
||||
* @param string $money_symbol
|
||||
* @param DateTimeInterface $dateTime
|
||||
* @param ?DateTimeInterface $dateTime = null
|
||||
* @return float
|
||||
* @throws EmptyResponse
|
||||
*/
|
||||
public function get(string $money_symbol, DateTimeInterface $dateTime): float;
|
||||
public function get(string $money_symbol, ?DateTimeInterface $dateTime = null): float;
|
||||
}
|
||||
|
18
app/common/Ideal/LoggerEnabled.php
Normal file
18
app/common/Ideal/LoggerEnabled.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Ideal;
|
||||
|
||||
use Psr\Log\LoggerAwareInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
abstract class LoggerEnabled implements LoggerAwareInterface
|
||||
{
|
||||
protected LoggerInterface $logger;
|
||||
public function setLogger(LoggerInterface $logger): void
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
public function getLogger(): LoggerInterface
|
||||
{
|
||||
return $this->logger;
|
||||
}
|
||||
}
|
@ -24,6 +24,11 @@ abstract class Repository implements Define\Repository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getConnection(): Define\Connection
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
public function load(array $data_row): Define\Model
|
||||
{
|
||||
$model = $this->create($data_row);
|
||||
@ -189,7 +194,7 @@ abstract class Repository implements Define\Repository
|
||||
try {
|
||||
$this->connection->execute($query, $values);
|
||||
} catch (PDOException $exception) {
|
||||
throw new EmptyResult($query, $exception);
|
||||
throw new EmptyResult($query, $exception, $data);
|
||||
}
|
||||
return $this->fetchById($this->getIndex($model));
|
||||
}
|
||||
@ -205,10 +210,10 @@ abstract class Repository implements Define\Repository
|
||||
try {
|
||||
$result = $this->connection->execute($query, $data)->fetch(PDO::FETCH_ASSOC);
|
||||
if ($result === false) {
|
||||
throw new EmptyResult($query);
|
||||
throw new EmptyResult($query, null, $data);
|
||||
}
|
||||
} catch (PDOException $exception) {
|
||||
throw new EmptyResult($query, $exception);
|
||||
throw new EmptyResult($query, $exception, $data);
|
||||
}
|
||||
return $this->load($result);
|
||||
}
|
||||
@ -224,7 +229,7 @@ abstract class Repository implements Define\Repository
|
||||
try {
|
||||
$results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $exception) {
|
||||
throw new EmptyResult($query, $exception);
|
||||
throw new EmptyResult($query, $exception, $data);
|
||||
}
|
||||
return array_map([$this, 'load'], $results);
|
||||
}
|
||||
@ -240,7 +245,7 @@ abstract class Repository implements Define\Repository
|
||||
try {
|
||||
$results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $exception) {
|
||||
throw new EmptyResult($query, $exception);
|
||||
throw new EmptyResult($query, $exception, $data);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
56
app/common/Ideal/Service/API.php
Normal file
56
app/common/Ideal/Service/API.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Ideal\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Exception\ServiceAction;
|
||||
|
||||
abstract class API extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array|null $order
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getAll(null|string|array $order = null): array;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Define\Model
|
||||
* @throws ServiceAction\Read
|
||||
*/
|
||||
abstract public function get(int $id): Define\Model;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return Define\Model
|
||||
* @throws ServiceAction\Create
|
||||
*/
|
||||
abstract public function add(array $data): Define\Model;
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Define\Model
|
||||
* @throws ServiceAction\Update
|
||||
*/
|
||||
abstract public function edit(Define\Model $model, array $new_data): Define\Model;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Define\Model
|
||||
* @throws ServiceAction\Delete
|
||||
*/
|
||||
abstract public function delete(int $id): Define\Model;
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @return Define\Model
|
||||
*/
|
||||
abstract protected function process(Define\Model $model): Define\Model;
|
||||
}
|
@ -81,6 +81,9 @@ class Insert extends Ideal\Query implements Define\Query\Insert
|
||||
if ($value === (int) $value) {
|
||||
return $value;
|
||||
}
|
||||
if (str_starts_with($value, ':')) {
|
||||
return $value;
|
||||
}
|
||||
return "'{$value}'";
|
||||
}, $this->values)) . ')';
|
||||
}
|
||||
|
@ -6,10 +6,15 @@ use Throwable;
|
||||
|
||||
class EmptyResult extends Exception
|
||||
{
|
||||
public function __construct(public string $query, ?Throwable $previous = null)
|
||||
public function __construct(public string $query, ?Throwable $previous = null, protected ?array $data = null)
|
||||
{
|
||||
$message = "Empty results for {$query}";
|
||||
$code = 700;
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
public function getData(): ?array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
|
48
app/common/Implement/Log/Formatter/PDO.php
Normal file
48
app/common/Implement/Log/Formatter/PDO.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Implement\Log\Formatter;
|
||||
|
||||
use Throwable;
|
||||
use Monolog\Formatter\JsonFormatter;
|
||||
use Monolog\LogRecord;
|
||||
|
||||
class PDO extends JsonFormatter
|
||||
{
|
||||
public function __construct(int $batchMode = self::BATCH_MODE_JSON, bool $appendNewline = false, bool $ignoreEmptyContextAndExtra = false, bool $includeStacktraces = true)
|
||||
{
|
||||
parent::__construct($batchMode, $appendNewline, $ignoreEmptyContextAndExtra, $includeStacktraces);
|
||||
}
|
||||
|
||||
public function format(LogRecord $record): string
|
||||
{
|
||||
if (is_a($record->message, Throwable::class)) {
|
||||
$exception = $record->message;
|
||||
$message = $this->normalizeException($exception);
|
||||
$context = $record->context;
|
||||
$context['exception'] = $exception;
|
||||
if ($exception->getPrevious()) {
|
||||
$context['previous'] = $this->walkException($exception);
|
||||
}
|
||||
$new_record = new LogRecord(
|
||||
$record->datetime,
|
||||
$record->channel,
|
||||
$record->level,
|
||||
json_encode($message),
|
||||
$context,
|
||||
$record->extra
|
||||
);
|
||||
$record = $new_record;
|
||||
}
|
||||
$normalized = $this->normalize($record, $this->maxNormalizeDepth);
|
||||
return $normalized['message'];
|
||||
}
|
||||
|
||||
protected function walkException(Throwable $exception, int $depth = 0): array
|
||||
{
|
||||
$output = [];
|
||||
$currentDepth = $depth;
|
||||
while ($previous = $exception->getPrevious() and $currentDepth < $this->maxNormalizeDepth) {
|
||||
$output []= $this->normalizeException($previous);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Implement\Log;
|
||||
namespace Incoviba\Common\Implement\Log\Handler;
|
||||
|
||||
use PDOStatement;
|
||||
use Monolog\Handler\AbstractProcessingHandler;
|
||||
use Monolog\LogRecord;
|
||||
use Monolog\Level;
|
||||
use Incoviba\Common\Define\Connection;
|
||||
use Monolog\Handler\AbstractProcessingHandler;
|
||||
use Monolog\Level;
|
||||
use Monolog\LogRecord;
|
||||
use PDOStatement;
|
||||
|
||||
class MySQLHandler extends AbstractProcessingHandler
|
||||
class MySQL extends AbstractProcessingHandler
|
||||
{
|
||||
private bool $initialized = false;
|
||||
private PDOStatement $statement;
|
||||
@ -19,9 +19,12 @@ class MySQLHandler extends AbstractProcessingHandler
|
||||
public function write(LogRecord $record): void
|
||||
{
|
||||
if (!$this->initialized) {
|
||||
if (!$this->checkTableExists()) {
|
||||
$this->createTable();
|
||||
}
|
||||
$this->cleanup();
|
||||
$this->initialized();
|
||||
}
|
||||
$this->cleanup();
|
||||
$this->statement->execute([
|
||||
'channel' => $record->channel,
|
||||
'level' => $record->level->getName(),
|
||||
@ -35,6 +38,21 @@ class MySQLHandler extends AbstractProcessingHandler
|
||||
private function initialized(): void
|
||||
{
|
||||
$query = <<<QUERY
|
||||
INSERT INTO monolog (channel, level, message, time, context, extra)
|
||||
VALUES (:channel, :level, :message, :time, :context, :extra)
|
||||
QUERY;
|
||||
$this->statement = $this->connection->getPDO()->prepare($query);
|
||||
$this->initialized = true;
|
||||
}
|
||||
private function checkTableExists(): bool
|
||||
{
|
||||
$query = "SHOW TABLES LIKE 'monolog'";
|
||||
$result = $this->connection->query($query);
|
||||
return $result->rowCount() > 0;
|
||||
}
|
||||
private function createTable(): void
|
||||
{
|
||||
$query = <<<QUERY
|
||||
CREATE TABLE IF NOT EXISTS monolog (
|
||||
channel VARCHAR(255),
|
||||
level VARCHAR(100),
|
||||
@ -45,12 +63,6 @@ CREATE TABLE IF NOT EXISTS monolog (
|
||||
)
|
||||
QUERY;
|
||||
$this->connection->getPDO()->exec($query);
|
||||
$query = <<<QUERY
|
||||
INSERT INTO monolog (channel, level, message, time, context, extra)
|
||||
VALUES (:channel, :level, :message, :time, :context, :extra)
|
||||
QUERY;
|
||||
$this->statement = $this->connection->getPDO()->prepare($query);
|
||||
$this->initialized = true;
|
||||
}
|
||||
private function cleanup(): void
|
||||
{
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Implement\Log;
|
||||
|
||||
use Monolog\Formatter\JsonFormatter;
|
||||
use Monolog\LogRecord;
|
||||
|
||||
class PDOFormatter extends JsonFormatter
|
||||
{
|
||||
public function __construct(int $batchMode = self::BATCH_MODE_JSON, bool $appendNewline = false, bool $ignoreEmptyContextAndExtra = false, bool $includeStacktraces = true)
|
||||
{
|
||||
parent::__construct($batchMode, $appendNewline, $ignoreEmptyContextAndExtra, $includeStacktraces);
|
||||
}
|
||||
|
||||
public function format(LogRecord $record): string
|
||||
{
|
||||
$normalized = $this->normalize($record);
|
||||
return $normalized['message'];
|
||||
}
|
||||
}
|
91
app/common/Implement/Log/Processor/ArrayBuilder.php
Normal file
91
app/common/Implement/Log/Processor/ArrayBuilder.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Implement\Log\Processor;
|
||||
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Monolog\Formatter;
|
||||
use Monolog\Handler;
|
||||
use Monolog\Level;
|
||||
use Predis;
|
||||
use Incoviba;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class ArrayBuilder extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected ContainerInterface $container)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function build(array $data): array
|
||||
{
|
||||
$handlers = [];
|
||||
foreach ($data as $handlerData) {
|
||||
if (in_array($handlerData['handler'], [Handler\StreamHandler::class, Handler\RotatingFileHandler::class,])) {
|
||||
$params = [
|
||||
"/logs/{$handlerData['filename']}",
|
||||
];
|
||||
if ($handlerData['handler'] === Handler\RotatingFileHandler::class) {
|
||||
$params []= 10;
|
||||
}
|
||||
try {
|
||||
$formatter = Formatter\LineFormatter::class;
|
||||
if (array_key_exists('formatter', $handlerData)) {
|
||||
$formatter = $handlerData['formatter'];
|
||||
}
|
||||
$handler = new $handlerData['handler'](...$params)
|
||||
->setFormatter($this->container->get($formatter));
|
||||
} catch (NotFoundExceptionInterface | ContainerExceptionInterface $exception) {
|
||||
$this->logger->error($exception->getMessage(), ['exception' => $exception, 'handlerData' => $handlerData]);
|
||||
continue;
|
||||
}
|
||||
} elseif ($handlerData['handler'] === Incoviba\Common\Implement\Log\Handler\MySQL::class) {
|
||||
try {
|
||||
$params = [
|
||||
$this->container->get(Incoviba\Common\Define\Connection::class)
|
||||
];
|
||||
$formatter = Incoviba\Common\Implement\Log\Formatter\PDO::class;
|
||||
if (array_key_exists('formatter', $handlerData)) {
|
||||
$formatter = $handlerData['formatter'];
|
||||
}
|
||||
$handler = new $handlerData['handler'](...$params)
|
||||
->setFormatter($this->container->get($formatter));
|
||||
} catch (NotFoundExceptionInterface | ContainerExceptionInterface $exception) {
|
||||
$this->logger->error($exception->getMessage(), ['exception' => $exception, 'handlerData' => $handlerData]);
|
||||
continue;
|
||||
}
|
||||
} elseif ($handlerData['handler'] === Handler\RedisHandler::class) {
|
||||
try {
|
||||
$params = [
|
||||
$this->container->get(Predis\ClientInterface::class),
|
||||
"logs:{$handlerData['name']}"
|
||||
];
|
||||
} catch (NotFoundExceptionInterface | ContainerExceptionInterface $exception) {
|
||||
$this->logger->error($exception->getMessage(), ['exception' => $exception, 'handlerData' => $handlerData]);
|
||||
continue;
|
||||
}
|
||||
$handler = new $handlerData['handler'](...$params);
|
||||
}
|
||||
if (!isset($handler)) {
|
||||
$this->logger->error("Invalid handler", ['handlerData' => $handlerData]);
|
||||
continue;
|
||||
}
|
||||
$params = [
|
||||
$handler,
|
||||
];
|
||||
if (is_array($handlerData['levels'])) {
|
||||
foreach ($handlerData['levels'] as $level) {
|
||||
$params []= $level;
|
||||
}
|
||||
} else {
|
||||
$params []= $handlerData['levels'];
|
||||
$params []= Level::Emergency;
|
||||
}
|
||||
$params []= false;
|
||||
$handlers []= new Handler\FilterHandler(...$params);
|
||||
}
|
||||
return $handlers;
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Implement\Log;
|
||||
namespace Incoviba\Common\Implement\Log\Processor;
|
||||
|
||||
use Incoviba\Service;
|
||||
use Monolog\LogRecord;
|
||||
use Monolog\Processor\ProcessorInterface;
|
||||
use Incoviba\Service;
|
||||
|
||||
class UserProcessor implements ProcessorInterface
|
||||
class User implements ProcessorInterface
|
||||
{
|
||||
public function __construct(protected Service\Login $loginService) {}
|
||||
public function __invoke(LogRecord $record): LogRecord
|
@ -4,6 +4,7 @@
|
||||
"type": "project",
|
||||
"require": {
|
||||
"ext-curl": "*",
|
||||
"ext-dom": "*",
|
||||
"ext-gd": "*",
|
||||
"ext-openssl": "*",
|
||||
"ext-pdo": "*",
|
||||
@ -18,7 +19,8 @@
|
||||
"predis/predis": "^2",
|
||||
"robmorgan/phinx": "^0.16",
|
||||
"slim/slim": "^4",
|
||||
"symfony/string": "^7.2"
|
||||
"symfony/string": "^7.2",
|
||||
"tedivm/jshrink": "^1.7"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "^1",
|
||||
|
@ -28,16 +28,15 @@
|
||||
<directory>common</directory>
|
||||
</include>
|
||||
</source>
|
||||
<coverage pathCoverage="false" ignoreDeprecatedCodeUnits="true" disableCodeCoverageIgnore="true">
|
||||
<!--<coverage pathCoverage="false" ignoreDeprecatedCodeUnits="true" disableCodeCoverageIgnore="true">
|
||||
<report>
|
||||
<html outputDirectory="/code/public/coverage/html"/>
|
||||
<php outputFile="/code/public/coverage/coverage.php"/>
|
||||
</report>
|
||||
</coverage>
|
||||
</coverage>-->
|
||||
<logging>
|
||||
<junit outputFile="/code/cache/tests/junit.xml"/>
|
||||
<teamcity outputFile="/code/cache/tests/teamcity.txt"/>
|
||||
<testdoxHtml outputFile="/code/cache/tests/testdox.html"/>
|
||||
<!--<testdoxHtml outputFile="/code/public/tests/testdox.html"/>-->
|
||||
<testdoxText outputFile="/code/cache/tests/testdox.txt"/>
|
||||
</logging>
|
||||
</phpunit>
|
||||
|
@ -13,3 +13,12 @@ try {
|
||||
$app->getContainer()->get(Psr\Log\LoggerInterface::class)->notice($exception);
|
||||
header('Location: /construccion');
|
||||
}
|
||||
register_shutdown_function(function() {
|
||||
$error = error_get_last();
|
||||
|
||||
$fatal_errors = [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR];
|
||||
if ($error !== null and in_array($error['type'], $fatal_errors, true)) {
|
||||
error_log(json_encode($error).PHP_EOL,3, '/logs/fatal.log');
|
||||
}
|
||||
error_clear_last();
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ class CreateAgente extends Phinx\Migration\AbstractMigration
|
||||
->addColumn('telefono', 'integer', ['length' => 11, 'default' => null, 'null' => true])
|
||||
->addColumn('correo', 'string', ['length' => 50, 'default' => null, 'null' => true])
|
||||
->addColumn('direccion', 'integer', ['length' => 11, 'default' => null, 'null' => true])
|
||||
->addColumn('giro', 'mediumtext', ['default' => null, 'null' => true])
|
||||
->addColumn('giro', 'text', ['default' => null, 'null' => true])
|
||||
->addColumn('abreviacion', 'string', ['length' => 20, 'default' => null, 'null' => true])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
|
@ -13,9 +13,9 @@ class CreateCartolas extends Phinx\Migration\AbstractMigration
|
||||
$this->table('cartolas')
|
||||
->addColumn('cuenta_id', 'integer', ['length' => 10, 'null' => false, 'signed' => false])
|
||||
->addColumn('fecha', 'date', ['null' => false])
|
||||
->addColumn('cargos', 'bigint', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('abonos', 'bigint', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('saldo', 'bigint', ['length' => 20, 'default' => 0, 'null' => false])
|
||||
->addColumn('cargos', 'biginteger', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('abonos', 'biginteger', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('saldo', 'biginteger', ['length' => 20, 'default' => 0, 'null' => false])
|
||||
->addForeignKey('cuenta_id', 'cuenta', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
|
@ -15,7 +15,7 @@ class CreateCentrosCostos extends Phinx\Migration\AbstractMigration
|
||||
->addColumn('categoria_id', 'integer', ['length' => 10, 'null' => false, 'signed' => false])
|
||||
->addColumn('tipo_cuenta_id', 'integer', ['length' => 10, 'default' => null, 'null' => true, 'signed' => false])
|
||||
->addColumn('cuenta_contable', 'string', ['length' => 100, 'null' => false])
|
||||
->addColumn('descripcion', 'mediumtext', ['null' => false])
|
||||
->addColumn('descripcion', 'text', ['null' => false, 'limit' => MysqlAdapter::TEXT_MEDIUM])
|
||||
->addForeignKey('tipo_centro_id', 'tipos_centros_costos', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->addForeignKey('categoria_id', 'categorias_centros_costos', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
|
@ -19,7 +19,7 @@ class CreateCobro extends Phinx\Migration\AbstractMigration
|
||||
->addColumn('iva', 'float', ['default' => 0])
|
||||
->addColumn('uf', 'float', ['default' => null, 'null' => true])
|
||||
->addColumn('identificador', 'string', ['length' => 50, 'default' => null, 'null' => true])
|
||||
->addColumn('glosa', 'mediumtext', ['default' => null, 'null' => true])
|
||||
->addColumn('glosa', 'text', ['default' => null, 'null' => true, 'limit' => MysqlAdapter::TEXT_MEDIUM])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class CreateEscritura extends Phinx\Migration\AbstractMigration
|
||||
$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");
|
||||
|
||||
$this->table('escritura')
|
||||
->addColumn('valor', 'bigint', ['length' => 20, 'null' => false])
|
||||
->addColumn('valor', 'biginteger', ['length' => 20, 'null' => false])
|
||||
->addColumn('fecha', 'date', ['null' => false])
|
||||
->addColumn('uf', 'float', ['default' => null, 'null' => true])
|
||||
->addColumn('abonado', 'integer', ['length' => 11, 'default' => 0])
|
||||
|
@ -13,7 +13,7 @@ class CreateEstadoProblema extends Phinx\Migration\AbstractMigration
|
||||
$this->table('estado_problema')
|
||||
->addColumn('problema', 'integer', ['length' => 11, 'default' => null, 'null' => true])
|
||||
->addColumn('fecha', 'date', ['default' => null, 'null' => true])
|
||||
->addColumn('estado', 'enum', ['length' => 'ingreso','revision','correccion','ok', 'default' => null, 'null' => true])
|
||||
->addColumn('estado', 'enum', ['values' => ['ingreso','revision','correccion','ok'], 'default' => null, 'null' => true])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class CreateInmobiliariasNubox extends Phinx\Migration\AbstractMigration
|
||||
->addColumn('alias', 'string', ['length' => 100, 'null' => false])
|
||||
->addColumn('usuario', 'string', ['length' => 100, 'null' => false])
|
||||
->addColumn('contraseña', 'string', ['length' => 100, 'null' => false])
|
||||
->addForeignKey('inmobiliaria_rut', 'inmobiliaria', 'rut', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
#->addForeignKey('inmobiliaria_rut', 'inmobiliaria', 'rut', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
|
@ -15,9 +15,9 @@ class CreateMovimientos extends Phinx\Migration\AbstractMigration
|
||||
->addColumn('fecha', 'date', ['null' => false])
|
||||
->addColumn('glosa', 'text', ['null' => false])
|
||||
->addColumn('documento', 'string', ['length' => 50, 'null' => false])
|
||||
->addColumn('cargo', 'bigint', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('abono', 'bigint', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('saldo', 'bigint', ['length' => 20, 'default' => 0, 'null' => false])
|
||||
->addColumn('cargo', 'biginteger', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('abono', 'biginteger', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('saldo', 'biginteger', ['length' => 20, 'default' => 0, 'null' => false])
|
||||
->addForeignKey('cuenta_id', 'cuenta', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
|
@ -12,7 +12,7 @@ class CreateProblema extends Phinx\Migration\AbstractMigration
|
||||
|
||||
$this->table('problema')
|
||||
->addColumn('venta', 'integer', ['length' => 11, 'default' => null, 'null' => true])
|
||||
->addColumn('descripcion', 'mediumtext', ['default' => null, 'null' => true])
|
||||
->addColumn('descripcion', 'text', ['default' => null, 'null' => true, 'limit' => MysqlAdapter::TEXT_MEDIUM])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ class CreateProyecto extends Phinx\Migration\AbstractMigration
|
||||
|
||||
$this->table('proyecto')
|
||||
->addColumn('inmobiliaria', 'integer', ['length' => 10, 'default' => null, 'null' => true, 'signed' => false])
|
||||
->addColumn('descripcion', 'mediumtext', ['null' => false])
|
||||
->addColumn('descripcion', 'text', ['null' => false, 'limit' => MysqlAdapter::TEXT_MEDIUM])
|
||||
->addColumn('direccion', 'integer', ['length' => 10, 'null' => false, 'signed' => false])
|
||||
->addColumn('superficie_terreno', 'float', ['default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('valor_terreno', 'float', ['default' => 0, 'null' => false, 'signed' => false])
|
||||
|
@ -18,7 +18,7 @@ class CreateProyectoTipoUnidad extends Phinx\Migration\AbstractMigration
|
||||
->addColumn('m2', 'float', ['default' => null, 'null' => true])
|
||||
->addColumn('logia', 'float', ['default' => 0])
|
||||
->addColumn('terraza', 'float', ['default' => 0])
|
||||
->addColumn('descripcion', 'mediumtext', ['default' => null, 'null' => true])
|
||||
->addColumn('descripcion', 'text', ['default' => null, 'null' => true, 'limit' => MysqlAdapter::TEXT_MEDIUM])
|
||||
->addForeignKey('proyecto', 'proyecto', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
|
@ -33,7 +33,7 @@ class CreateVenta extends Phinx\Migration\AbstractMigration
|
||||
->addColumn('resciliacion', 'integer', ['length' => 10, 'default' => null, 'null' => true, 'signed' => false])
|
||||
->addColumn('devolucion', 'integer', ['length' => 10, 'default' => null, 'null' => true, 'signed' => false])
|
||||
->addForeignKey('propiedad', 'propiedad', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->addForeignKey('propietario', 'propietario', 'rut', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
#->addForeignKey('propietario', 'propietario', 'rut', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class CreateVentaAbonoCuotas extends Phinx\Migration\AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
|
||||
$this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';");
|
||||
$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");
|
||||
|
||||
$this->table('venta_abono_cuotas')
|
||||
->addColumn('venta_id', 'integer', ['length' => 11, 'null' => false, 'signed' => false])
|
||||
->addColumn('pago_id', 'integer', ['length' => 11, 'null' => false, 'signed' => false])
|
||||
->addColumn('numero', 'integer', ['length' => 11, 'default' => 1, 'null' => false, 'signed' => false])
|
||||
->addForeignKey('venta_id', 'venta', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->addForeignKey('pago_id', 'pago', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateBroker extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('brokers', ['id' => false, 'primary_key' => ['rut']])
|
||||
->addColumn('rut', 'integer', ['identity' => true, 'signed' => false, 'null' => false])
|
||||
->addColumn('digit', 'string', ['length' => 1, 'null' => false])
|
||||
->addColumn('name', 'string', ['length' => 255, 'null' => false])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateBrokerContract extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
|
||||
$this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';");
|
||||
$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");
|
||||
|
||||
$this->table('broker_contracts')
|
||||
->addColumn('broker_rut', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('project_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('commission', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => false])
|
||||
->addForeignKey('broker_rut', 'brokers', 'rut', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->addForeignKey('project_id', 'proyecto', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateBrokerData extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
|
||||
$this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';");
|
||||
$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");
|
||||
|
||||
$this->table('broker_data')
|
||||
->addColumn('broker_rut', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('representative_id', 'integer', ['signed' => false, 'null' => true, 'default' => null])
|
||||
->addColumn('legal_name', 'string', ['length' => 255, 'default' => null, 'null' => true])
|
||||
->addForeignKey('broker_rut', 'brokers', ['rut'], ['delete' => 'CASCADE', 'update' => 'CASCADE'])
|
||||
->addForeignKey('representative_id', 'broker_contacts', ['id'], ['delete' => 'CASCADE', 'update' => 'CASCADE'])
|
||||
->create();
|
||||
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreatePromotion extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
|
||||
$this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';");
|
||||
$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");
|
||||
|
||||
$this->table('promotions')
|
||||
->addColumn('price_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('amount', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => false])
|
||||
->addColumn('start_date', 'date', ['null' => false])
|
||||
->addColumn('end_date', 'date', ['null' => false])
|
||||
->addColumn('valid_until', 'date', ['null' => false])
|
||||
->addColumn('state', 'integer', ['length' => 1, 'null' => false, 'default' => 1])
|
||||
->addForeignKey('price_id', 'prices', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateReservation extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
|
||||
$this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';");
|
||||
$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");
|
||||
|
||||
$this->table('reservation')
|
||||
->addColumn('buyer_rut', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('date', 'date', ['null' => false])
|
||||
->addForeignKey('buyer_rut', 'personas', 'rut', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateBrokerContractState extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
|
||||
$this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';");
|
||||
$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");
|
||||
|
||||
$this->table('broker_contract_states')
|
||||
->addColumn('contract_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('date', 'date', ['null' => false])
|
||||
->addColumn('type', 'integer', ['length' => 1, 'null' => false, 'default' => 0])
|
||||
->addForeignKey('contract_id', 'broker_contracts', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateReservationDatas extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
|
||||
$this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';");
|
||||
$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");
|
||||
|
||||
$this->table('reservation_data')
|
||||
->addColumn('reservation_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('type', 'integer', ['length' => 1, 'signed' => false, 'null' => false])
|
||||
->addColumn('reference_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('value', 'decimal', ['precision' => 10, 'scale' => 2, 'signed' => false, 'default' => 0.00, 'null' => true])
|
||||
->create();
|
||||
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateReservationStates extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
|
||||
$this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';");
|
||||
$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");
|
||||
|
||||
$this->table('reservation_states')
|
||||
->addColumn('reservation_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('date', 'date', ['null' => false])
|
||||
->addColumn('type', 'integer', ['length' => 3, 'null' => false, 'default' => 0])
|
||||
->addForeignKey('reservation_id', 'reservation', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateBrokerContacts extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
|
||||
$this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';");
|
||||
$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");
|
||||
|
||||
$this->table('broker_contacts')
|
||||
->addColumn('rut', 'integer', ['signed' => false, 'null' => true])
|
||||
->addColumn('digit', 'string', ['length' => 1, 'null' => true])
|
||||
->addColumn('name', 'string', ['length' => 255, 'null' => true])
|
||||
->addColumn('email', 'string', ['length' => 255, 'null' => true])
|
||||
->addColumn('phone', 'string', ['length' => 255, 'null' => true])
|
||||
->addColumn('address_id', 'integer', ['signed' => false, 'null' => true])
|
||||
->addForeignKey('address_id', 'direccion', ['id'], ['delete' => 'CASCADE', 'update' => 'CASCADE'])
|
||||
->create();
|
||||
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AlterPromotionsRemovePrice extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
if ($this->table('promotions')->hasColumn('price_id')) {
|
||||
$this->table('promotions')
|
||||
->dropForeignKey('price_id')
|
||||
->removeColumn('price_id')
|
||||
->update();
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void {}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreatePromotionUnit extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('promotion_units')
|
||||
->addColumn('promotion_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('unit_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('created_at', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])
|
||||
->addForeignKey('promotion_id', 'promotions', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
|
||||
->addForeignKey('unit_id', 'unidad', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AlterPromotionsNullDates extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$this->table('promotions')
|
||||
->changeColumn('end_date', 'date', ['null' => true])
|
||||
->changeColumn('valid_until', 'date', ['null' => true])
|
||||
->update();
|
||||
}
|
||||
public function down(): void {}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AlterPromotionsAddDescriptionAndType extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('promotions')
|
||||
->addColumn('description', 'string', ['limit' => 255, 'null' => false, 'after' => 'id'])
|
||||
->addColumn('type', 'integer', ['limit' => 1, 'null' => false, 'default' => 0, 'after' => 'description'])
|
||||
->update();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreatePromotionProjects extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('promotion_projects')
|
||||
->addColumn('promotion_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('project_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addForeignKey('promotion_id', 'promotions', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->addForeignKey('project_id', 'proyecto', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreatePromotionBrokers extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('promotion_brokers')
|
||||
->addColumn('promotion_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('broker_rut', 'integer', ['signed' => false, 'null' => false])
|
||||
->addForeignKey('promotion_id', 'promotions', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
|
||||
->addForeignKey('broker_rut', 'brokers', 'rut', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreatePromotionUnitLines extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('promotion_unit_lines')
|
||||
->addColumn('promotion_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('unit_line_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addForeignKey('promotion_id', 'promotions', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
|
||||
->addForeignKey('unit_line_id', 'proyecto_tipo_unidad', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreatePromotionUnitTypes extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('promotion_unit_types')
|
||||
->addColumn('promotion_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('project_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addColumn('unit_type_id', 'integer', ['signed' => false, 'null' => false])
|
||||
->addForeignKey('promotion_id', 'promotions', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
|
||||
->addForeignKey('project_id', 'proyecto', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
|
||||
->addForeignKey('unit_type_id', 'tipo_unidad', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateTokuCustomers extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('toku_customers')
|
||||
->addColumn('rut', 'string', ['length' => 9])
|
||||
->addColumn('toku_id', 'string', ['length' => 255])
|
||||
->addTimestamps()
|
||||
->addIndex(['rut'], ['unique' => true])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateTokuSubscriptions extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('toku_subscriptions')
|
||||
->addColumn('venta_id', 'integer', ['signed' => false])
|
||||
->addColumn('toku_id', 'string', ['length' => 255])
|
||||
->addTimestamps()
|
||||
->addIndex(['venta_id'], ['unique' => true])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateTokuInvoices extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('toku_invoices')
|
||||
->addColumn('cuota_id', 'integer', ['signed' => false])
|
||||
->addColumn('toku_id', 'string', ['length' => 255])
|
||||
->addTimestamps()
|
||||
->addIndex(['cuota_id'], ['unique' => true])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateJobs extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('jobs')
|
||||
->addColumn('configuration', 'json')
|
||||
->addColumn('executed', 'boolean', ['default' => false])
|
||||
->addTimestamps()
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateTokuWebhooks extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('toku_webhooks')
|
||||
->addColumn('secret', 'string', ['length' => 255])
|
||||
->addColumn('events', 'json')
|
||||
->addColumn('enabled', 'boolean', ['default' => true])
|
||||
->addTimestamps()
|
||||
->create();
|
||||
}
|
||||
}
|
@ -2,6 +2,16 @@
|
||||
use Incoviba\Controller\Proyectos;
|
||||
|
||||
$app->group('/proyectos', function($app) {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'proyectos']);
|
||||
if (file_exists($folder)) {
|
||||
$files = new FilesystemIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
}
|
||||
$app->get('/unidades[/]', [Proyectos::class, 'unidades']);
|
||||
$app->get('[/]', Proyectos::class);
|
||||
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));
|
||||
|
@ -23,6 +23,7 @@ $app->group('/venta/{venta_id:[0-9]+}', function($app) {
|
||||
$app->get('[/]', [Ventas::class, 'propiedad']);
|
||||
});
|
||||
$app->group('/pie', function($app) {
|
||||
$app->get('/add[/]', [Ventas\Pies::class, 'add']);
|
||||
$app->group('/cuotas', function($app) {
|
||||
$app->get('[/]', [Ventas::class, 'cuotas']);
|
||||
});
|
||||
|
@ -7,4 +7,4 @@ $app->group('/contabilidad', function($app) {
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
});
|
||||
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));
|
||||
|
@ -7,4 +7,4 @@ $app->group('/admin', function($app) {
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
});
|
||||
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));
|
||||
|
@ -2,5 +2,9 @@
|
||||
use Incoviba\Controller\API\Admin\Users;
|
||||
|
||||
$app->group('/users', function($app) {
|
||||
$app->post('/add[/]', Users::class . ':add');
|
||||
$app->post('/add[/]', [Users::class, 'add']);
|
||||
});
|
||||
$app->group('/user/{user_id}', function($app) {
|
||||
$app->post('/edit[/]', [Users::class, 'edit']);
|
||||
$app->delete('[/]', [Users::class, 'delete']);
|
||||
});
|
||||
|
16
app/resources/routes/api/external.php
Normal file
16
app/resources/routes/api/external.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\External;
|
||||
|
||||
$app->group('/external', function($app) {
|
||||
$files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'external']));
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
$app->group('/services', function($app) {
|
||||
$app->get('/check[/]', [External::class, 'check']);
|
||||
$app->get('/update[/]', [External::class, 'update']);
|
||||
});
|
||||
});
|
10
app/resources/routes/api/external/toku.php
vendored
Normal file
10
app/resources/routes/api/external/toku.php
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\Ventas\MediosPago\Toku;
|
||||
|
||||
$app->group('/toku', function($app) {
|
||||
$app->post('/cuotas/{venta_id}[/]', [Toku::class, 'cuotas']);
|
||||
$app->post('/success[/]', [Toku::class, 'success']);
|
||||
$app->get('/test[/]', [Toku::class, 'test']);
|
||||
$app->delete('/reset[/]', [Toku::class, 'reset']);
|
||||
$app->post('/enqueue[/]', [Toku::class, 'enqueue']);
|
||||
});
|
@ -3,6 +3,13 @@ use Incoviba\Controller\API\Proyectos;
|
||||
|
||||
$app->group('/proyectos', function($app) {
|
||||
$app->get('/escriturando[/]', [Proyectos::class, 'escriturando']);
|
||||
$files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'proyectos']));
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
$app->get('[/]', [Proyectos::class, 'list']);
|
||||
});
|
||||
$app->group('/proyecto/{proyecto_id}', function($app) {
|
||||
@ -14,10 +21,13 @@ $app->group('/proyecto/{proyecto_id}', function($app) {
|
||||
$app->get('/vendible[/]', [Proyectos::class, 'superficies']);
|
||||
});
|
||||
$app->group('/unidades', function($app) {
|
||||
$app->post('/precios[/]', [Proyectos\Unidades::class, 'precios']);
|
||||
$app->post('/estados[/]', [Proyectos\Unidades::class, 'estados']);
|
||||
$app->get('/disponibles[/]', [Proyectos::class, 'disponibles']);
|
||||
$app->get('[/]', [Proyectos::class, 'unidades']);
|
||||
});
|
||||
$app->group('/terreno', function($app) {
|
||||
$app->post('/edit[/]', [Proyectos::class, 'terreno']);
|
||||
});
|
||||
$app->get('/brokers', [Proyectos::class, 'brokers']);
|
||||
});
|
||||
|
30
app/resources/routes/api/proyectos/brokers.php
Normal file
30
app/resources/routes/api/proyectos/brokers.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\Proyectos\Brokers;
|
||||
use Incoviba\Controller\API\Proyectos\Brokers\Contracts;
|
||||
|
||||
$app->group('/brokers', function($app) {
|
||||
$app->group('/contracts', function($app) {
|
||||
$app->post('/add[/]', [Contracts::class, 'add']);
|
||||
$app->get('[/]', Contracts::class);
|
||||
});
|
||||
$app->group('/contract/{contract_id}', function($app) {
|
||||
$app->post('/edit[/]', [Contracts::class, 'edit']);
|
||||
$app->post('/inactive[/]', [Contracts::class, 'inactive']);
|
||||
$app->delete('[/]', [Contracts::class, 'delete']);
|
||||
$app->get('[/]', [Contracts::class, 'get']);
|
||||
});
|
||||
$app->post('/add[/]', [Brokers::class, 'add']);
|
||||
$app->post('/edit[/]', [Brokers::class, 'edit']);
|
||||
$app->get('[/]', Brokers::class);
|
||||
});
|
||||
$app->group('/broker/{broker_rut}', function($app) {
|
||||
$app->group('/contracts', function($app) {
|
||||
$app->post('/add[/]', [Contracts::class, 'add']);
|
||||
$app->get('[/]', [Contracts::class, 'getByBroker']);
|
||||
});
|
||||
$app->group('/contract/{contract_id}', function($app) {
|
||||
$app->post('/promotions[/]', [Contracts::class, 'promotions']);
|
||||
});
|
||||
$app->delete('[/]', [Brokers::class, 'delete']);
|
||||
$app->get('[/]', [Brokers::class, 'get']);
|
||||
});
|
10
app/resources/routes/api/queue.php
Normal file
10
app/resources/routes/api/queue.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\Queues;
|
||||
|
||||
$app->group('/queue', function($app) {
|
||||
$app->get('/jobs[/]', [Queues::class, 'jobs']);
|
||||
$app->group('/run', function($app) {
|
||||
$app->get('/{job_id:[0-9]+}[/]', [Queues::class, 'run']);
|
||||
$app->get('[/]', Queues::class);
|
||||
});
|
||||
});
|
@ -21,6 +21,7 @@ $app->group('/ventas', function($app) {
|
||||
});
|
||||
$app->group('/by', function($app) {
|
||||
$app->get('/unidad/{unidad_id}', [Ventas::class, 'unidad']);
|
||||
$app->post('/unidades[/]', [Ventas::class, 'byUnidades']);
|
||||
});
|
||||
$app->post('/get[/]', [Ventas::class, 'getMany']);
|
||||
$app->post('[/]', [Ventas::class, 'proyecto']);
|
||||
@ -55,6 +56,9 @@ $app->group('/venta/{venta_id}', function($app) {
|
||||
$app->group('/propietario', function($app) {
|
||||
$app->put('/edit[/]', [Ventas::class, 'propietario']);
|
||||
});
|
||||
$app->group('/pie', function($app) {
|
||||
$app->post('/add[/]', [Ventas\Pies::class, 'add']);
|
||||
});
|
||||
$app->post('[/]', [Ventas::class, 'edit']);
|
||||
$app->get('[/]', [Ventas::class, 'get']);
|
||||
});
|
||||
|
28
app/resources/routes/api/ventas/promotions.php
Normal file
28
app/resources/routes/api/ventas/promotions.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\Ventas\Promotions;
|
||||
|
||||
$app->group('/promotions', function($app) {
|
||||
$app->post('/add[/]', [Promotions::class, 'add']);
|
||||
$app->post('/edit[/]', [Promotions::class, 'edit']);
|
||||
});
|
||||
$app->group('/promotion/{promotion_id}', function($app) {
|
||||
$app->delete('/remove[/]', [Promotions::class, 'remove']);
|
||||
$app->group('/connections', function($app) {
|
||||
$app->post('/add[/]', [Promotions::class, 'addConnections']);
|
||||
$app->group('/project/{project_id}', function($app) {
|
||||
$app->delete('[/]', [Promotions::class, 'removeProject']);
|
||||
$app->group('/unit-type/{unit_type_id}', function($app) {
|
||||
$app->delete('[/]', [Promotions::class, 'removeUnitType']);
|
||||
});
|
||||
});
|
||||
$app->group('/broker/{broker_rut}', function($app) {
|
||||
$app->delete('[/]', [Promotions::class, 'removeBroker']);
|
||||
});
|
||||
$app->group('/unit-line/{unit_line_id}', function($app) {
|
||||
$app->delete('[/]', [Promotions::class, 'removeUnitLine']);
|
||||
});
|
||||
$app->group('/unit/{unit_id}', function($app) {
|
||||
$app->delete('[/]', [Promotions::class, 'removeUnit']);
|
||||
});
|
||||
});
|
||||
});
|
12
app/resources/routes/api/ventas/reservations.php
Normal file
12
app/resources/routes/api/ventas/reservations.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\Ventas\Reservations;
|
||||
|
||||
$app->group('/reservations', function($app) {
|
||||
$app->post('/add[/]', [Reservations::class, 'add']);
|
||||
$app->get('[/]', Reservations::class);
|
||||
});
|
||||
$app->group('/reservation/{reservation_id}', function($app) {
|
||||
$app->post('/edit[/]', [Reservations::class, 'edit']);
|
||||
$app->delete('[/]', [Reservations::class, 'delete']);
|
||||
$app->get('[/]', [Reservations::class, 'get']);
|
||||
});
|
12
app/resources/routes/proyectos/brokers.php
Normal file
12
app/resources/routes/proyectos/brokers.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Proyectos\Brokers;
|
||||
|
||||
$app->group('/brokers', function($app) {
|
||||
$app->get('[/]', Brokers::class);
|
||||
});
|
||||
$app->group('/broker/{broker_rut}', function($app) {
|
||||
$app->group('/contract/{contract_id}', function($app) {
|
||||
$app->get('[/]', [Brokers\Contracts::class, 'show']);
|
||||
});
|
||||
$app->get('[/]', [Brokers::class, 'show']);
|
||||
});
|
9
app/resources/routes/ventas/promotions.php
Normal file
9
app/resources/routes/ventas/promotions.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Ventas\Promotions;
|
||||
|
||||
$app->group('/promotions', function($app) {
|
||||
$app->get('[/]', Promotions::class);
|
||||
});
|
||||
$app->group('/promotion/{promotion_id}', function($app) {
|
||||
$app->get('[/]', [Promotions::class, 'show']);
|
||||
});
|
@ -14,15 +14,15 @@
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody id="users">
|
||||
@foreach($users as $user)
|
||||
<tr>
|
||||
<tr data-user="{{ $user->id }}">
|
||||
<td>{{ $user->name }}</td>
|
||||
<td class="right aligned">
|
||||
<button class="ui mini blue icon button">
|
||||
<button class="ui mini blue icon button edit" data-user="{{ $user->id }}">
|
||||
<i class="edit icon"></i>
|
||||
</button>
|
||||
<button class="ui mini red icon button">
|
||||
<button class="ui mini red icon button remove" data-user="{{ $user->id }}">
|
||||
<i class="trash icon"></i>
|
||||
</button>
|
||||
</td>
|
||||
@ -50,6 +50,10 @@
|
||||
<label>Contraseña</label>
|
||||
<input type="password" name="password" placeholder="Contraseña">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Confirmar contraseña</label>
|
||||
<input type="password" name="password_confirmation" placeholder="Confirmar contraseña">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
@ -62,6 +66,45 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui modal" id="edit-user-modal">
|
||||
<i class="close icon"></i>
|
||||
<div class="header">
|
||||
Editar usuario
|
||||
</div>
|
||||
<div class="content">
|
||||
<form class="ui form">
|
||||
<input type="hidden" name="id" />
|
||||
<div class="field">
|
||||
<label>Contraseña Antigua</label>
|
||||
<input type="password" name="old_password" placeholder="Contraseña Antigua">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Force Change?</label>
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="force" >
|
||||
<label>Yes</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Contraseña</label>
|
||||
<input type="password" name="password" placeholder="Contraseña">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Confirmar contraseña</label>
|
||||
<input type="password" name="password_confirmation" placeholder="Confirmar contraseña">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui black deny button">
|
||||
Cancelar
|
||||
</div>
|
||||
<div class="ui positive right labeled icon button">
|
||||
Guardar
|
||||
<i class="checkmark icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.cryptojs')
|
||||
@ -74,12 +117,20 @@
|
||||
return [passphrase, encrypted.toString()].join('')
|
||||
}
|
||||
$(document).ready(function () {
|
||||
$('#create-user-modal').modal({
|
||||
const $createUserModal = $('#create-user-modal')
|
||||
$createUserModal.modal({
|
||||
onApprove: function() {
|
||||
const form = document.querySelector('#create-user-modal form')
|
||||
const password = form.querySelector('[name="password"]').value
|
||||
const password_confirmation = form.querySelector('[name="password_confirmation"]').value
|
||||
if (password !== password_confirmation) {
|
||||
alert('Las contraseñas no coinciden')
|
||||
return
|
||||
}
|
||||
const url = '{{$urls->api}}/admin/users/add'
|
||||
const method = 'post'
|
||||
const body = new FormData(document.querySelector('#create-user-modal form'))
|
||||
body.set('password', encryptPassword(body.get('password')))
|
||||
const body = new FormData(form)
|
||||
body.set('password', encryptPassword(password))
|
||||
fetchAPI(url, {method, body}).then(response => {
|
||||
if (!response) {
|
||||
return;
|
||||
@ -92,8 +143,64 @@
|
||||
})
|
||||
}
|
||||
})
|
||||
$('#create-user-button').on('click', function () {
|
||||
$('#create-user-modal').modal('show')
|
||||
const $editUserModal = $('#edit-user-modal')
|
||||
$editUserModal.modal({
|
||||
onApprove: function() {
|
||||
const form = document.querySelector('#edit-user-modal form')
|
||||
const user_id = form.querySelector('[name="id"]').value
|
||||
const old_password = form.querySelector('[name="old_password"]').value
|
||||
const password = form.querySelector('[name="password"]').value
|
||||
const password_confirmation = form.querySelector('[name="password_confirmation"]').value
|
||||
if (password !== password_confirmation) {
|
||||
alert('Las nuevas contraseñas no coinciden')
|
||||
return
|
||||
}
|
||||
const url = `{{$urls->api}}/admin/user/${user_id}/edit`
|
||||
const method = 'post'
|
||||
const body = new FormData(form)
|
||||
body.set('old_password', encryptPassword(old_password))
|
||||
body.set('password', encryptPassword(password))
|
||||
if (form.querySelector('[name="force"]').checked) {
|
||||
body.set('force', 'true')
|
||||
}
|
||||
fetchAPI(url, {method, body}).then(response => {
|
||||
if (!response) {
|
||||
return;
|
||||
}
|
||||
response.json().then(result => {
|
||||
if (result.success) {
|
||||
location.reload()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
document.getElementById('create-user-modal').addEventListener('submit', event => {
|
||||
$createUserModal.modal('show')
|
||||
})
|
||||
document.querySelectorAll('.button.edit').forEach(button => {
|
||||
button.addEventListener('click', clickEvent => {
|
||||
const user_id = clickEvent.currentTarget.dataset.user
|
||||
$editUserModal.find('input[name="id"]').val(user_id)
|
||||
$editUserModal.modal('show')
|
||||
})
|
||||
})
|
||||
document.querySelectorAll('.button.remove').forEach(button => {
|
||||
button.addEventListener('click', clickEvent => {
|
||||
const user_id = clickEvent.currentTarget.dataset.user
|
||||
const url = `{{$urls->api}}/admin/user/${user_id}`
|
||||
const method = 'delete'
|
||||
fetchAPI(url, {method}).then(response => {
|
||||
if (!response) {
|
||||
return;
|
||||
}
|
||||
response.json().then(result => {
|
||||
if (result.success) {
|
||||
location.reload()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
</script>
|
||||
|
@ -96,26 +96,7 @@
|
||||
columnDefs,
|
||||
order,
|
||||
language: Object.assign(dtD.language, {
|
||||
searchBuilder: {
|
||||
add: 'Filtrar',
|
||||
condition: 'Comparador',
|
||||
clearAll: 'Resetear',
|
||||
delete: 'Eliminar',
|
||||
deleteTitle: 'Eliminar Titulo',
|
||||
data: 'Columna',
|
||||
left: 'Izquierda',
|
||||
leftTitle: 'Titulo Izquierdo',
|
||||
logicAnd: 'Y',
|
||||
logicOr: 'O',
|
||||
right: 'Derecha',
|
||||
rightTitle: 'Titulo Derecho',
|
||||
title: {
|
||||
0: 'Filtros',
|
||||
_: 'Filtros (%d)'
|
||||
},
|
||||
value: 'Opciones',
|
||||
valueJoiner: 'y'
|
||||
}
|
||||
searchBuilder
|
||||
}),
|
||||
layout: {
|
||||
top1: {
|
||||
|
@ -20,7 +20,7 @@
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
const cuotas = {
|
||||
get: function() {
|
||||
return {
|
||||
|
@ -2,7 +2,7 @@
|
||||
<div class="ui divided list" id="alertas_escrituras"></div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
const alertas_escrituras = {
|
||||
id: '#alertas_escrituras',
|
||||
data: {
|
||||
|
@ -2,7 +2,7 @@
|
||||
<div class="ui divided list" id="cierres_vigentes"></div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
const cierres_vigentes = {
|
||||
get: function() {
|
||||
const list = $('#cierres_vigentes')
|
||||
|
@ -2,7 +2,7 @@
|
||||
<div class="ui divided list" id="cuotas_por_vencer"></div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
const cuotas_por_vencer = {
|
||||
get: function() {
|
||||
const list = $('#cuotas_por_vencer')
|
||||
|
@ -3,5 +3,6 @@
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<a class="item" href="{{$urls->base}}/proyectos/unidades">Unidades</a>
|
||||
<a class="item" href="{{ $urls->base }}/proyectos/brokers">Operadores</a>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -11,7 +11,7 @@
|
||||
</div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
function logout() {
|
||||
return fetch('{{$urls->base}}/logout').then(response => {
|
||||
if (response.ok) {
|
||||
|
@ -3,6 +3,7 @@
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<a class="item" href="{{$urls->base}}/ventas/precios">Precios</a>
|
||||
<a class="item" href="{{ $urls->base }}/ventas/promotions">Promociones</a>
|
||||
<a class="item" href="{{$urls->base}}/ventas/cierres">Cierres</a>
|
||||
<div class="item">
|
||||
Cuotas
|
||||
@ -33,6 +34,7 @@
|
||||
{{--<a class="item" href="{{$urls->base}}/ventas/precios/importar">Importar Precios</a>--}}
|
||||
{{--<a class="item" href="{{$urls->base}}/ventas/cierres/evaluar">Evaluar Cierre</a>--}}
|
||||
<a class="item" href="{{$urls->base}}/ventas/facturacion">Facturación</a>
|
||||
<div class="divider"></div>
|
||||
<a class="item" href="{{$urls->base}}/ventas/add">
|
||||
Nueva Venta
|
||||
<i class="plus icon"></i>
|
||||
|
@ -1,33 +1,9 @@
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js" integrity="sha512-3gJwYpMe3QewGELv8k/BX9vcqhryRdzRMxVfq6ngyWXwo03GFEzjsUm8Q7RZcHPHksttq7/GFoxjCVUjkjvPdw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.3/semantic.min.js" integrity="sha512-gnoBksrDbaMnlE0rhhkcx3iwzvgBGz6mOEj4/Y5ZY09n55dYddx6+WYc72A55qEesV8VX2iMomteIwobeGK1BQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
class APIClient {
|
||||
static fetch(url, options=null, showErrors=false) {
|
||||
return fetchAPI(url, options, showErrors)
|
||||
}
|
||||
}
|
||||
function fetchAPI(url, options=null, showErrors=false) {
|
||||
if (options === null) {
|
||||
options = {}
|
||||
}
|
||||
if (!Object.hasOwn(options, 'headers')) {
|
||||
options['headers'] = {}
|
||||
}
|
||||
if (!Object.hasOwn(options['headers'], 'Authorization')) {
|
||||
options['headers']['Authorization'] = 'Bearer {{md5($API_KEY)}}{{($login->isIn()) ? $login->getSeparator() . $login->getToken() : ''}}'
|
||||
}
|
||||
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 => {
|
||||
if (showErrors) {
|
||||
console.error(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
@include('layout.body.scripts.api')
|
||||
|
||||
<script>
|
||||
const datatables_defaults = {
|
||||
language: {
|
||||
emptyTable: 'No hay datos disponibles',
|
||||
|
32
app/resources/views/layout/body/scripts/api.blade.php
Normal file
32
app/resources/views/layout/body/scripts/api.blade.php
Normal file
@ -0,0 +1,32 @@
|
||||
<script>
|
||||
class APIClient {
|
||||
static getApiKey() {
|
||||
return '{{md5($API_KEY)}}{{($login->isIn()) ? $login->getSeparator() . $login->getToken() : ''}}'
|
||||
}
|
||||
|
||||
static fetch(url, options=null, showErrors=false) {
|
||||
if (options === null) {
|
||||
options = {}
|
||||
}
|
||||
if (!Object.hasOwn(options, 'headers')) {
|
||||
options['headers'] = {}
|
||||
}
|
||||
if (!Object.hasOwn(options['headers'], 'Authorization')) {
|
||||
options['headers']['Authorization'] = `Bearer ${APIClient.getApiKey()}`
|
||||
}
|
||||
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 => {
|
||||
if (showErrors) {
|
||||
console.error(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
function fetchAPI(url, options=null, showErrors=false) {
|
||||
return APIClient.fetch(url, options, showErrors)
|
||||
}
|
||||
</script>
|
@ -1,4 +1,4 @@
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript" src="https://cdn.datatables.net/2.0.3/js/dataTables.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/2.0.3/js/dataTables.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/2.0.3/js/dataTables.semanticui.min.js"></script>
|
||||
@endpush
|
||||
|
@ -2,4 +2,26 @@
|
||||
<script src="https://cdn.datatables.net/datetime/1.5.2/js/dataTables.dateTime.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/searchbuilder/1.7.0/js/dataTables.searchBuilder.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/searchbuilder/1.7.0/js/searchBuilder.semanticui.js"></script>
|
||||
<script>
|
||||
const searchBuilder = {
|
||||
add: 'Filtrar',
|
||||
condition: 'Comparador',
|
||||
clearAll: 'Resetear',
|
||||
delete: 'Eliminar',
|
||||
deleteTitle: 'Eliminar Titulo',
|
||||
data: 'Columna',
|
||||
left: 'Izquierda',
|
||||
leftTitle: 'Titulo Izquierdo',
|
||||
logicAnd: 'Y',
|
||||
logicOr: 'O',
|
||||
right: 'Derecha',
|
||||
rightTitle: 'Titulo Derecho',
|
||||
title: {
|
||||
0: 'Filtros',
|
||||
_: 'Filtros (%d)'
|
||||
},
|
||||
value: 'Opciones',
|
||||
valueJoiner: 'y'
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -0,0 +1,45 @@
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
Intl.NumberFormat.prototype.parse = function(valueString) {
|
||||
const format = new Intl.NumberFormat(this.resolvedOptions().locale);
|
||||
const parts = format.formatToParts(-12345.6);
|
||||
const numerals = Array.from({ length: 10 }).map((_, i) => format.format(i));
|
||||
const index = new Map(numerals.map((d, i) => [d, i]));
|
||||
_minusSign = new RegExp(`[${parts.find(d => d.type === 'minusSign').value}]`);
|
||||
_group = new RegExp(`[${parts.find(d => d.type === 'group').value}]`, 'g');
|
||||
_decimal = new RegExp(`[${parts.find(d => d.type === 'decimal').value}]`);
|
||||
_numeral = new RegExp(`[${numerals.join('')}]`, 'g');
|
||||
_index = d => index.get(d);
|
||||
|
||||
const DIRECTION_MARK = /\u061c|\u200e/g
|
||||
return +(
|
||||
valueString.trim()
|
||||
.replace(DIRECTION_MARK, '')
|
||||
.replace(_group, '')
|
||||
.replace(_decimal, '.')
|
||||
.replace(_numeral, _index)
|
||||
.replace(_minusSign, '-')
|
||||
)
|
||||
}
|
||||
Intl.NumberFormat.prototype.isLocale = function(stringValue) {
|
||||
const format = new Intl.NumberFormat(this.resolvedOptions().locale);
|
||||
const parts = format.formatToParts(-12345.6);
|
||||
const group = parts.find(d => d.type === 'group').value;
|
||||
const decimal = parts.find(d => d.type === 'decimal').value;
|
||||
|
||||
if (stringValue.includes(group)) {
|
||||
if (stringValue.includes(decimal)) {
|
||||
return stringValue.indexOf(group) < stringValue.indexOf(decimal)
|
||||
}
|
||||
if (stringValue.split(group).map(d => d.length).filter(d => d > 3).length > 0) {
|
||||
return false
|
||||
}
|
||||
return stringValue.split(group).length > 2;
|
||||
}
|
||||
if (stringValue.includes(decimal)) {
|
||||
return stringValue.split(decimal).length <= 2;
|
||||
}
|
||||
return false
|
||||
}
|
||||
</script>
|
||||
@endpush
|
@ -0,0 +1,76 @@
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
if (typeof Intl.NumberFormat.isLocale === 'undefined' || typeof Intl.NumberFormat.isLocale !== 'function') {
|
||||
// Load Intl.NumberFormat custom methods
|
||||
@include('layout.body.scripts.number_format')
|
||||
}
|
||||
class NumberInput {
|
||||
input
|
||||
isRational
|
||||
outputLocale
|
||||
currentValue
|
||||
formatters
|
||||
|
||||
constructor({input, isRational, outputLocale}) {
|
||||
this.input = input
|
||||
this.isRational = isRational
|
||||
this.outputLocale = outputLocale || 'es-CL'
|
||||
|
||||
this.formatters = {}
|
||||
const locales = ['es-CL', 'en-US']
|
||||
locales.forEach(locale => {
|
||||
this.formatters[locale] = {
|
||||
rational: new Intl.NumberFormat(locale, {minimumFractionDigits: 2, maximumFractionDigits: 2}),
|
||||
integer: new Intl.NumberFormat(locale)
|
||||
}
|
||||
})
|
||||
|
||||
if (this.input.value !== '') {
|
||||
this.currentValue = this.process(this.input.value)
|
||||
this.input.value = this.format(this.currentValue)
|
||||
}
|
||||
}
|
||||
watch() {
|
||||
this.input.addEventListener('change', event => {
|
||||
this.currentValue = this.process(event.currentTarget.value)
|
||||
this.input.value = this.format(this.currentValue)
|
||||
})
|
||||
}
|
||||
process(stringValue) {
|
||||
if (stringValue === '') {
|
||||
return ''
|
||||
}
|
||||
if (typeof stringValue !== 'string') {
|
||||
return stringValue
|
||||
}
|
||||
return this.formatters[this.detectLocale(stringValue)][this.isRational ? 'rational' : 'integer'].parse(stringValue)
|
||||
}
|
||||
detectLocale(stringValue) {
|
||||
if (stringValue === '') {
|
||||
return ''
|
||||
}
|
||||
if (typeof stringValue !== 'string') {
|
||||
return stringValue
|
||||
}
|
||||
const outputFormat = this.formatters[this.outputLocale][this.isRational ? 'rational' : 'integer'].isLocale(stringValue)
|
||||
const otherFormats = Object.entries(this.formatters).filter(formatter => formatter[0] !== this.outputLocale).map(formatter => {
|
||||
return {
|
||||
locale: formatter[0],
|
||||
value: formatter[1][this.isRational ? 'rational' : 'integer'].isLocale(stringValue)
|
||||
}
|
||||
}).filter(formatter => formatter.value)
|
||||
|
||||
if (outputFormat) {
|
||||
return this.outputLocale
|
||||
}
|
||||
if (otherFormats.length > 0) {
|
||||
return otherFormats[0].locale
|
||||
}
|
||||
return 'en-US'
|
||||
}
|
||||
format(value) {
|
||||
return this.formatters[this.outputLocale][this.isRational ? 'rational' : 'integer'].format(value)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
@ -28,7 +28,7 @@
|
||||
if (!(typeof digito === 'string' || digito instanceof String)) {
|
||||
digito = digito.toString()
|
||||
}
|
||||
return Rut.digitoVerificador(rut) === digito
|
||||
return Rut.digitoVerificador(rut).toString().toUpperCase() === digito.toUpperCase()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
6
app/resources/views/layout/body/scripts/stats.blade.php
Normal file
6
app/resources/views/layout/body/scripts/stats.blade.php
Normal file
@ -0,0 +1,6 @@
|
||||
@prepend('page_scripts')
|
||||
<script src='https://unpkg.com/simple-statistics@7.8.8/dist/simple-statistics.min.js'></script>
|
||||
<script>
|
||||
const Stat = ss
|
||||
</script>
|
||||
@endprepend
|
@ -1,9 +1,9 @@
|
||||
<head>
|
||||
<meta charset="utf8" />
|
||||
@hasSection('page_title')
|
||||
<title>Incoviba - @yield('page_title')</title>
|
||||
<title>Incoviba - @yield('page_title')</title>
|
||||
@else
|
||||
<title>Incoviba</title>
|
||||
<title>Incoviba</title>
|
||||
@endif
|
||||
<link rel="icon" href="{{$urls->images}}/Isotipo 16.png" />
|
||||
@include('layout.head.styles')
|
||||
|
@ -19,7 +19,7 @@
|
||||
@include('layout.body.scripts.cryptojs')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
function encryptPassword(password) {
|
||||
const passphrase = Math.floor(Math.random() * Date.now()).toString()
|
||||
const encrypted = CryptoJS.AES.encrypt(password, passphrase)
|
||||
|
14
app/resources/views/not_allowed.blade.php
Normal file
14
app/resources/views/not_allowed.blade.php
Normal file
@ -0,0 +1,14 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_title')
|
||||
405 - Método No Permitido
|
||||
@endsection
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<div class="ui message">
|
||||
<i class="exclamation triangle icon"></i>
|
||||
No se ha encontrado la página solicitada para el método solicitado.
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
219
app/resources/views/proyectos/brokers.blade.php
Normal file
219
app/resources/views/proyectos/brokers.blade.php
Normal file
@ -0,0 +1,219 @@
|
||||
@extends('proyectos.brokers.base')
|
||||
|
||||
@section('brokers_content')
|
||||
<table id="brokers" class="ui table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>RUT</th>
|
||||
<th>Nombre</th>
|
||||
<th>Contacto</th>
|
||||
<th>Contratos</th>
|
||||
<th class="right aligned">
|
||||
<button class="ui small tertiary green icon button" id="add_button">
|
||||
<i class="plus icon"></i>
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@foreach($brokers as $broker)
|
||||
<tr>
|
||||
<td class="top aligned">
|
||||
<span
|
||||
@if ($broker->data()?->legalName !== '')
|
||||
data-tooltip="{{ $broker->data()?->legalName }}" data-position="right center"
|
||||
@endif
|
||||
>
|
||||
{{$broker->rutFull()}}
|
||||
</span>
|
||||
</td>
|
||||
<td class="top aligned">
|
||||
<a href="{{ $urls->base }}/proyectos/broker/{{ $broker->rut }}">
|
||||
{{$broker->name}}
|
||||
<i class="angle right icon"></i>
|
||||
</a>
|
||||
</td>
|
||||
<td class="top aligned">
|
||||
<span
|
||||
@if ($broker->data()?->representative?->email !== '' || $broker->data()?->representative?->phone !== '')
|
||||
data-tooltip="{{ ($broker->data()?->representative?->email !== '') ? "Email: " . $broker->data()?->representative?->email : '' }}{{ ($broker->data()?->representative?->phone !== '') ? ' Teléfono: ' . $broker->data()?->representative?->phone : '' }}" data-position="right center"
|
||||
@endif
|
||||
>
|
||||
{{ $broker->data()?->representative?->name }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="top aligned">
|
||||
<div class="ui list">
|
||||
@foreach($broker->contracts() as $contract)
|
||||
<div class="item">
|
||||
<a href="{{$urls->base}}/proyectos/broker/{{$broker->rut}}/contract/{{$contract->id}}" data-tooltip="{{$contract->current()->date->format('d-m-Y')}}" data-position="right center">
|
||||
{{$contract->project->descripcion}} ({{$format->percent($contract->commission, 2, true)}})
|
||||
</a>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</td>
|
||||
<td class="top aligned right aligned">
|
||||
<button class="ui small tertiary icon button edit_button" data-index="{{$broker->rut}}">
|
||||
<i class="edit icon"></i>
|
||||
</button>
|
||||
<button class="ui small tertiary red icon button remove_button" data-index="{{$broker->rut}}">
|
||||
<i class="remove icon"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</table>
|
||||
@include('proyectos.brokers.add_modal')
|
||||
@include('proyectos.brokers.edit_modal')
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
function storeBrokers() {
|
||||
localStorage.setItem('brokers', '{!! json_encode(array_map(function($broker) {
|
||||
$arr = json_decode(json_encode($broker), true);
|
||||
array_walk_recursive($arr, function(&$val, $key) {
|
||||
if ($val === null) {
|
||||
$val = '';
|
||||
}
|
||||
});
|
||||
$arr['contracts'] = $broker->contracts();
|
||||
return $arr;
|
||||
}, $brokers)) !!}')
|
||||
}
|
||||
const brokersHandler = {
|
||||
ids: {
|
||||
buttons: {
|
||||
add: 'add_button',
|
||||
edit: 'edit_button',
|
||||
remove: 'remove_button'
|
||||
},
|
||||
modals: {
|
||||
add: '',
|
||||
edit: ''
|
||||
},
|
||||
forms: {
|
||||
add: '',
|
||||
edit: ''
|
||||
}
|
||||
},
|
||||
modals: {
|
||||
add: null,
|
||||
edit: null
|
||||
},
|
||||
events() {
|
||||
return {
|
||||
add: clickEvent => {
|
||||
clickEvent.preventDefault()
|
||||
brokersHandler.actions().add()
|
||||
},
|
||||
edit: clickEvent => {
|
||||
clickEvent.preventDefault()
|
||||
const broker_rut = parseInt(clickEvent.currentTarget.dataset.index)
|
||||
brokersHandler.actions().edit(broker_rut)
|
||||
},
|
||||
delete: clickEvent => {
|
||||
clickEvent.preventDefault()
|
||||
const broker_rut = clickEvent.currentTarget.dataset.index
|
||||
brokersHandler.actions().delete(broker_rut)
|
||||
}
|
||||
}
|
||||
},
|
||||
buttonWatch() {
|
||||
document.getElementById(brokersHandler.ids.buttons.add).addEventListener('click', brokersHandler.events().add)
|
||||
Array.from(document.getElementsByClassName(brokersHandler.ids.buttons.edit)).forEach(button => {
|
||||
button.addEventListener('click', brokersHandler.events().edit)
|
||||
})
|
||||
Array.from(document.getElementsByClassName(brokersHandler.ids.buttons.remove)).forEach(button => {
|
||||
button.addEventListener('click', brokersHandler.events().delete)
|
||||
})
|
||||
},
|
||||
actions() {
|
||||
return {
|
||||
add: () => {
|
||||
this.modals.add.show()
|
||||
},
|
||||
edit: broker_rut => {
|
||||
const localData = JSON.parse(localStorage.getItem('brokers'))
|
||||
const broker = localData.find(broker => broker.rut === broker_rut)
|
||||
const data = {
|
||||
rut: broker_rut,
|
||||
name: broker.name,
|
||||
legal_name: broker.data?.legal_name || '',
|
||||
contact: broker.data?.representative?.name || '',
|
||||
email: broker.data?.representative?.email || '',
|
||||
phone: broker.data?.representative?.phone || '',
|
||||
address: broker.data?.representative?.address || '',
|
||||
contracts: broker.contracts
|
||||
}
|
||||
this.modals.edit.load(data)
|
||||
},
|
||||
delete: broker_rut => {
|
||||
brokersHandler.execute().delete(broker_rut)
|
||||
}
|
||||
}
|
||||
},
|
||||
execute() {
|
||||
return {
|
||||
add: data => {
|
||||
const url = '{{$urls->api}}/proyectos/brokers/add'
|
||||
const method = 'post'
|
||||
const body = new FormData()
|
||||
body.append('brokers[]', JSON.stringify(data))
|
||||
return APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||
if (!json.success) {
|
||||
console.error(json.errors)
|
||||
alert('No se pudo agregar operador.')
|
||||
return
|
||||
}
|
||||
window.location.reload()
|
||||
})
|
||||
},
|
||||
edit: data => {
|
||||
const url = '{{$urls->api}}/proyectos/brokers/edit'
|
||||
const method = 'post'
|
||||
const body = new FormData()
|
||||
body.append('brokers[]', JSON.stringify(data))
|
||||
return APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||
if (!json.success) {
|
||||
console.error(json.errors)
|
||||
alert('No se pudo editar operador.')
|
||||
return
|
||||
}
|
||||
window.location.reload()
|
||||
})
|
||||
},
|
||||
delete: broker_rut => {
|
||||
const url = '{{$urls->api}}/proyectos/broker/' + broker_rut
|
||||
const method = 'delete'
|
||||
return APIClient.fetch(url, {method}).then(response => response.json()).then(json => {
|
||||
if (!json.success) {
|
||||
console.error(json.errors)
|
||||
alert('No se pudo eliminar operador.')
|
||||
return
|
||||
}
|
||||
window.location.reload()
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
setup(ids) {
|
||||
brokersHandler.ids = ids
|
||||
brokersHandler.buttonWatch()
|
||||
|
||||
this.modals.add = new AddModal(brokersHandler)
|
||||
this.modals.edit = new EditModal(brokersHandler)
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
storeBrokers()
|
||||
brokersHandler.setup({
|
||||
buttons: {
|
||||
add: 'add_button',
|
||||
edit: 'edit_button',
|
||||
remove: 'remove_button',
|
||||
},
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
115
app/resources/views/proyectos/brokers/add_modal.blade.php
Normal file
115
app/resources/views/proyectos/brokers/add_modal.blade.php
Normal file
@ -0,0 +1,115 @@
|
||||
<div class="ui modal" id="add_broker_modal">
|
||||
<div class="header">
|
||||
Agregar Operador
|
||||
</div>
|
||||
<div class="content">
|
||||
<form class="ui form" id="add_broker_form">
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label>RUT</label>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="rut" placeholder="RUT" maxlength="10" required />
|
||||
<div class="ui basic label">-<span id="digit"></span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label>Nombre</label>
|
||||
<input type="text" name="name" placeholder="Nombre" required />
|
||||
</div>
|
||||
<div class="six wide field">
|
||||
<label>Razón Social</label>
|
||||
<input type="text" name="legal_name" placeholder="Razón Social" required />
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label>Contacto</label>
|
||||
<input type="text" name="contact" placeholder="Contacto" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label>Correo</label>
|
||||
<input type="email" name="email" placeholder="Correo" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Teléfono</label>
|
||||
<input type="text" name="phone" placeholder="Teléfono" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui deny button">
|
||||
Cancelar
|
||||
</div>
|
||||
<div class="ui positive right labeled icon button">
|
||||
Agregar
|
||||
<i class="checkmark icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@include('layout.body.scripts.rut')
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class AddModal {
|
||||
ids
|
||||
modal
|
||||
handler
|
||||
constructor(handler) {
|
||||
this.handler = handler
|
||||
this.ids = {
|
||||
modal: 'add_broker_modal',
|
||||
form: 'add_broker_form',
|
||||
digit: 'digit'
|
||||
}
|
||||
this.modal = $(`#${this.ids.modal}`)
|
||||
this.modal.modal({
|
||||
onApprove: () => {
|
||||
const form = document.getElementById(this.ids.form)
|
||||
const data = {
|
||||
rut: form.querySelector('[name="rut"]').value.replace(/\D/g, ''),
|
||||
digit: Rut.digitoVerificador(form.querySelector('[name="rut"]').value),
|
||||
name: form.querySelector('[name="name"]').value,
|
||||
legal_name: form.querySelector('[name="legal_name"]').value,
|
||||
contact: form.querySelector('[name="contact"]').value || '',
|
||||
email: form.querySelector('[name="email"]').value || '',
|
||||
phone: form.querySelector('[name="phone"]').value || ''
|
||||
}
|
||||
this.handler.execute().add(data)
|
||||
}
|
||||
})
|
||||
this.modal.modal('hide')
|
||||
const value = document.querySelector(`#${this.ids.form} input[name="rut"]`).value
|
||||
this.update().digit(value)
|
||||
this.watch().rut()
|
||||
}
|
||||
update() {
|
||||
return {
|
||||
digit: value => {
|
||||
if (value.length > 3) {
|
||||
document.getElementById(this.ids.digit).textContent = Rut.digitoVerificador(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
watch() {
|
||||
return {
|
||||
rut: () => {
|
||||
document.querySelector(`#${this.ids.form} input[name="rut"]`).addEventListener('input', event => {
|
||||
const value = event.currentTarget.value
|
||||
this.update().digit(value)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
show() {
|
||||
this.modal.modal('show')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
22
app/resources/views/proyectos/brokers/base.blade.php
Normal file
22
app/resources/views/proyectos/brokers/base.blade.php
Normal file
@ -0,0 +1,22 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_title')
|
||||
@hasSection('brokers_title')
|
||||
Operadores - @yield('brokers_title')
|
||||
@else
|
||||
Operadores
|
||||
@endif
|
||||
@endsection
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2 class="ui header">
|
||||
@hasSection('brokers_header')
|
||||
Operador - @yield('brokers_header')
|
||||
@else
|
||||
Operadores
|
||||
@endif
|
||||
</h2>
|
||||
@yield('brokers_content')
|
||||
</div>
|
||||
@endsection
|
489
app/resources/views/proyectos/brokers/contracts/show.blade.php
Normal file
489
app/resources/views/proyectos/brokers/contracts/show.blade.php
Normal file
@ -0,0 +1,489 @@
|
||||
@extends('proyectos.brokers.base')
|
||||
|
||||
@section('brokers_title')
|
||||
{{ $contract->broker->name }} - {{ $contract->project->descripcion }}
|
||||
@endsection
|
||||
|
||||
@section('brokers_header')
|
||||
{{ $contract->broker->name }} - {{ $contract->project->descripcion }}
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.stats')
|
||||
|
||||
@prepend('page_scripts')
|
||||
<script>
|
||||
class TableHandler {
|
||||
commission
|
||||
constructor(commission) {
|
||||
this.commission = commission
|
||||
}
|
||||
draw() {}
|
||||
prices(units) {
|
||||
return units.map(unit => {
|
||||
let price = unit.valor ?? (unit.precio?.valor ?? 0)
|
||||
const broker = price / (1 - this.commission)
|
||||
const promotions = unit.promotions?.map(promotion => {
|
||||
if (promotion.type === 1) {
|
||||
return {
|
||||
name: promotion.description,
|
||||
type: promotion.type,
|
||||
amount: promotion.amount,
|
||||
final: broker + promotion.amount
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: promotion.description,
|
||||
type: promotion.type,
|
||||
amount: promotion.amount,
|
||||
final: broker / (1 - promotion.amount)
|
||||
}
|
||||
}) ?? []
|
||||
return {
|
||||
id: unit.id,
|
||||
base: price,
|
||||
commission: this.commission,
|
||||
broker,
|
||||
promotions
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
class GroupedTableHandler extends TableHandler {
|
||||
promotions = {
|
||||
names: new Set(),
|
||||
values: []
|
||||
}
|
||||
process() {
|
||||
return {
|
||||
prices: prices => {
|
||||
let promotions = {}
|
||||
prices.map(price => price.promotions).forEach(promotionArray => {
|
||||
promotionArray.forEach(p => {
|
||||
if (!Object.hasOwn(promotions, p.name)) {
|
||||
promotions[p.name] = {
|
||||
name: p.name,
|
||||
type: p.type,
|
||||
amount: [],
|
||||
final: []
|
||||
}
|
||||
}
|
||||
promotions[p.name].amount.push(p.amount)
|
||||
promotions[p.name].final.push(p.final)
|
||||
})
|
||||
})
|
||||
return promotions
|
||||
},
|
||||
promotions: () => {
|
||||
return {
|
||||
names: promotions => {
|
||||
Object.keys(promotions).forEach(name => {
|
||||
this.add().promotion().name(name)
|
||||
})
|
||||
},
|
||||
values: ({promotions, formatters}) => {
|
||||
const temp = Object.values(promotions)
|
||||
if (temp.length > 0) {
|
||||
const data = temp.map(p => {
|
||||
return {
|
||||
name: p.name,
|
||||
type: p.type,
|
||||
amount: {
|
||||
min: Math.min(...p.amount),
|
||||
max: Math.max(...p.amount),
|
||||
desv: Stat.standardDeviation(p.amount),
|
||||
mean: Stat.mean(p.amount)
|
||||
},
|
||||
final: {
|
||||
min: Math.min(...p.final),
|
||||
max: Math.max(...p.final),
|
||||
desv: Stat.standardDeviation(p.final),
|
||||
mean: Stat.mean(p.final)
|
||||
}
|
||||
}
|
||||
})
|
||||
this.add().promotion().values({promotions: data, formatters})
|
||||
return
|
||||
}
|
||||
this.promotions.values.push([])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
add() {
|
||||
return {
|
||||
promotion: () => {
|
||||
return {
|
||||
name: name => {
|
||||
this.promotions.names.add(name)
|
||||
},
|
||||
values: ({promotions, formatters}) => {
|
||||
this.promotions.values.push(promotions.map(promotion => {
|
||||
const amount_tooltip = [
|
||||
`Min: ${promotion.type === 1 ? 'UF ' + formatters.ufs.format(promotion.amount.min) : formatters.percent.format(promotion.amount.min)}`,
|
||||
`Max: ${promotion.type === 1 ? 'UF ' + formatters.ufs.format(promotion.amount.max) : formatters.percent.format(promotion.amount.max)}`,
|
||||
`Desv: ${promotion.type === 1 ? 'UF ' + formatters.ufs.format(promotion.amount.desv) : formatters.percent.format(promotion.amount.desv)}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
const final_tooltip = [
|
||||
`Min: UF ${formatters.ufs.format(promotion.final.min)}`,
|
||||
`Max: UF ${formatters.ufs.format(promotion.final.max)}`,
|
||||
`Desv: UF ${formatters.ufs.format(promotion.final.desv)}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
return {
|
||||
name: promotion.name,
|
||||
value: [
|
||||
`<td class="right aligned"><span data-tooltip="${amount_tooltip}" data-position="right center" data-variation="wide multiline">${promotion.type === 1 ? formatters.ufs.format(promotion.amount.mean) : formatters.percent.format(promotion.amount.mean)}</td>`,
|
||||
`<td class="right aligned"><span data-tooltip="${final_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(promotion.final.mean)}</td></td>`,
|
||||
].join("\n")
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
build() {
|
||||
return {
|
||||
promotions: (table, tbody) => {
|
||||
if (this.promotions.names.size > 0) {
|
||||
const title = document.getElementById(this.ids.promotions)
|
||||
title.innerHTML = this.promotions.names.size > 0 ? Array.from(this.promotions.names)[0] : ''
|
||||
title.setAttribute('colspan', '2')
|
||||
if (this.promotions.names.size > 1) {
|
||||
const thead = table.querySelector('thead')
|
||||
Array.from(this.promotions.names).slice(1).forEach(name => {
|
||||
thead.insertAdjacentHTML('beforeend', `<th class="right aligned" style="text-decoration: overline" colspan="2">${name}</th>`)
|
||||
})
|
||||
}
|
||||
const trs = tbody.querySelectorAll('tr')
|
||||
this.promotions.values.forEach((row, i) => {
|
||||
const tr = trs[i]
|
||||
const td = tr.querySelector('td.promotions')
|
||||
if (row.length === 0) {
|
||||
td.setAttribute('colspan', 2 * this.promotions.names.size)
|
||||
return
|
||||
}
|
||||
td.remove()
|
||||
this.promotions.names.forEach(name => {
|
||||
const index = row.findIndex(r => r.name === name)
|
||||
if (index === -1) {
|
||||
tr.insertAdjacentHTML('beforeend', '<td colspan="2"></td>')
|
||||
return
|
||||
}
|
||||
tr.insertAdjacentHTML('beforeend', row[index].value)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endprepend
|
||||
|
||||
@section('brokers_content')
|
||||
<div class="ui statistic">
|
||||
<div class="value">{{ $format->percent($contract->commission ?? 0, 2, true) }}</div>
|
||||
<div class="label">
|
||||
Comisión desde {{ $contract->current()?->date?->format('d/m/Y') }}
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<div class="ui card">
|
||||
<div class="content">
|
||||
<div class="header">
|
||||
Promociones Aplicadas
|
||||
</div>
|
||||
<div class="description">
|
||||
@if (count($contract->promotions()) === 0)
|
||||
- Ninguna
|
||||
@else
|
||||
<div class="ui list">
|
||||
@foreach ($contract->promotions() as $promotion)
|
||||
<div class="item">
|
||||
{{ $promotion->description }} {{ $format->percent($promotion->amount, 2, true) }} {{ ucwords($promotion->type->name()) }}
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui very basic segment">
|
||||
<div class="ui active inline loader" id="loader"></div>
|
||||
<div class="ui indicating progress" id="load_progress">
|
||||
<div class="bar">
|
||||
<div class="progress"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="results">
|
||||
<div class="ui top attached tabular menu">
|
||||
<a class="item active" data-tab="tipos">Tipos</a>
|
||||
<a class="item" data-tab="lineas">Líneas</a>
|
||||
<a class="item" data-tab="unidades">Unidades</a>
|
||||
</div>
|
||||
<div class="ui top attached indicating progress" id="values_progress">
|
||||
<div class="bar"></div>
|
||||
</div>
|
||||
<div class="ui bottom attached tab basic fitted segment active" data-tab="tipos">
|
||||
@include('proyectos.brokers.contracts.show.tipo')
|
||||
</div>
|
||||
<div class="ui bottom attached tab basic fitted segment" data-tab="lineas">
|
||||
@include('proyectos.brokers.contracts.show.linea')
|
||||
</div>
|
||||
<div class="ui bottom attached tab basic fitted segment" data-tab="unidades">
|
||||
@include('proyectos.brokers.contracts.show.unidades')
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.datatables')
|
||||
@include('layout.body.scripts.datatables.searchbuilder')
|
||||
@include('layout.body.scripts.datatables.buttons')
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
const units = {
|
||||
ids: {
|
||||
units: '',
|
||||
loader: '',
|
||||
progress: '',
|
||||
load_progress: ''
|
||||
},
|
||||
data: {
|
||||
project_id: {{ $contract->project->id }},
|
||||
commission: {{ $contract->commission }},
|
||||
units: []
|
||||
},
|
||||
formatters: {
|
||||
ufs: new Intl.NumberFormat('es-CL', { style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 }),
|
||||
percent: new Intl.NumberFormat('es-CL', { style: 'percent', minimumFractionDigits: 2 })
|
||||
},
|
||||
handlers: {
|
||||
tipo: null,
|
||||
linea: null,
|
||||
unit: null
|
||||
},
|
||||
get() {
|
||||
return {
|
||||
units: () => {
|
||||
const url = `{{ $urls->api }}/proyecto/${units.data.project_id}/unidades`
|
||||
return APIClient.fetch(url).then(response => response.json()).then(json => {
|
||||
if (json.unidades.length === 0) {
|
||||
console.error(json.errors)
|
||||
return
|
||||
}
|
||||
units.data.units = []
|
||||
Object.entries(json.unidades).forEach(([tipo, unidades]) => {
|
||||
units.data.units = [...units.data.units, ...unidades]
|
||||
})
|
||||
})
|
||||
},
|
||||
promotions: progress_bar => {
|
||||
const chunkSize = 100
|
||||
const chunks = []
|
||||
for (let i = 0; i < units.data.units.length; i += chunkSize) {
|
||||
chunks.push(units.data.units.slice(i, i + chunkSize).map(u => u.id))
|
||||
}
|
||||
const promises = []
|
||||
const url = `{{ $urls->api }}/proyectos/broker/{{ $contract->broker->rut }}/contract/{{ $contract->id }}/promotions`
|
||||
const method = 'post'
|
||||
chunks.forEach(chunk => {
|
||||
const body = new FormData()
|
||||
chunk.forEach(id => body.append('unidad_ids[]', id))
|
||||
promises.push(APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||
progress_bar.progress('increment', json.input.unidad_ids.length)
|
||||
if (json.unidades.length === 0) {
|
||||
return
|
||||
}
|
||||
json.unidades.forEach(unidad => {
|
||||
const idx = units.data.units.findIndex(u => u.id === parseInt(unidad.id))
|
||||
units.data.units[idx].promotions = unidad.promotions
|
||||
})
|
||||
}))
|
||||
})
|
||||
return Promise.all(promises)
|
||||
},
|
||||
prices: progress_bar => {
|
||||
/*const unsold = [...units.data.units.filter(unit => !unit.sold), ...units.data.units.filter(unit => unit.sold && unit.proyecto_tipo_unidad.tipo_unidad.descripcion !== 'departamento')]
|
||||
const current_total = progress_bar.progress('get total')
|
||||
progress_bar.progress('set total', current_total + unsold.length)*/
|
||||
|
||||
const chunkSize = 100
|
||||
const chunks = []
|
||||
for (let i = 0; i < units.data.units.length; i += chunkSize) {
|
||||
chunks.push(units.data.units.slice(i, i + chunkSize).map(u => u.id))
|
||||
}
|
||||
const promises = []
|
||||
const url = `{{ $urls->api }}/proyecto/{{ $contract->project->id }}/unidades/precios`
|
||||
const method = 'post'
|
||||
chunks.forEach(chunk => {
|
||||
const body = new FormData()
|
||||
chunk.forEach(id => body.append('unidad_ids[]', id))
|
||||
promises.push(APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||
progress_bar.progress('increment', json.input.unidad_ids.length)
|
||||
if (json.precios.length === 0) {
|
||||
return
|
||||
}
|
||||
json.precios.forEach(unidad => {
|
||||
const idx = units.data.units.findIndex(u => u.id === parseInt(unidad.id))
|
||||
units.data.units[idx].precio = unidad.precio
|
||||
})
|
||||
}))
|
||||
})
|
||||
return Promise.all(promises)
|
||||
},
|
||||
values: progress_bar => {
|
||||
const sold = units.data.units.filter(unit => unit.sold && unit.proyecto_tipo_unidad.tipo_unidad.descripcion === 'departamento')
|
||||
progress_bar.progress('set total', sold.length)
|
||||
|
||||
const chunkSize = 10
|
||||
const chunks = []
|
||||
for (let i = 0; i < sold.length; i += chunkSize) {
|
||||
chunks.push(sold.slice(i, i + chunkSize).map(u => u.id))
|
||||
}
|
||||
const promises = []
|
||||
const url = `{{ $urls->api }}/ventas/by/unidades`
|
||||
const method = 'post'
|
||||
chunks.forEach(chunk => {
|
||||
const body = new FormData()
|
||||
chunk.forEach(id => body.append('unidad_ids[]', id))
|
||||
promises.push(APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||
progress_bar.progress('increment', json.input.unidad_ids.length)
|
||||
if (json.ventas.length === 0) {
|
||||
return
|
||||
}
|
||||
json.ventas.forEach(({unidad_id, venta}) => {
|
||||
const unidades = venta.propiedad.unidades
|
||||
const otras_unidades = unidades.filter(unit => unit.id !== parseInt(unidad_id) && unit.proyecto_tipo_unidad.tipo_unidad.descripcion !== 'departamento')
|
||||
const departamentos = unidades.filter(unit => unit.proyecto_tipo_unidad.tipo_unidad.descripcion === 'departamento' && unit.id !== parseInt(unidad_id))
|
||||
const precios = otras_unidades.map(unit => {
|
||||
const idx = units.data.units.findIndex(u => u.id === unit.id)
|
||||
return units.data.units[idx].precio?.valor ?? 0
|
||||
}).reduce((sum, precio) => sum + precio, 0)
|
||||
if (departamentos.length === 0) {
|
||||
const idx = units.data.units.findIndex(unit => unit.id === parseInt(unidad_id))
|
||||
units.data.units[idx].valor = venta.valor - precios
|
||||
units.data.units[idx].venta = venta
|
||||
return
|
||||
}
|
||||
const sum_precios = departamentos.map(departamento => {
|
||||
const idx = units.data.units.findIndex(unit => unit.id === departamento.id)
|
||||
return units.data.units[idx].precio
|
||||
}).reduce((sum, precio) => sum + precio, 0)
|
||||
departamentos.forEach(departamento => {
|
||||
const idx = units.data.units.findIndex(unit => unit.id === departamento.id)
|
||||
const saldo = venta.valor - precios
|
||||
units.data.units[idx].valor = saldo / sum_precios * departamento.precio
|
||||
units.data.units[idx].venta = venta
|
||||
})
|
||||
})
|
||||
}))
|
||||
})
|
||||
return Promise.all(promises)
|
||||
},
|
||||
sold: progress_bar => {
|
||||
const chunkSize = 100
|
||||
const chunks = []
|
||||
for (let i = 0; i < units.data.units.length; i += chunkSize) {
|
||||
chunks.push(units.data.units.slice(i, i + chunkSize).map(u => u.id))
|
||||
}
|
||||
const promises = []
|
||||
const url = `{{ $urls->api }}/proyecto/{{ $contract->project->id }}/unidades/estados`
|
||||
const method = 'post'
|
||||
chunks.forEach(chunk => {
|
||||
const body = new FormData()
|
||||
chunk.forEach(id => body.append('unidad_ids[]', id))
|
||||
promises.push(APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||
progress_bar.progress('increment', json.input.unidad_ids.length)
|
||||
if (json.estados.length === 0) {
|
||||
return
|
||||
}
|
||||
json.estados.forEach(unidad => {
|
||||
const idx = units.data.units.findIndex(u => u.id === parseInt(unidad.id))
|
||||
units.data.units[idx].sold = unidad.sold
|
||||
})
|
||||
}))
|
||||
})
|
||||
return Promise.all(promises)
|
||||
},
|
||||
}
|
||||
},
|
||||
draw() {
|
||||
return {
|
||||
units: () => {
|
||||
units.handlers.units.draw({units: units.data.units, formatters: units.formatters})
|
||||
},
|
||||
tipos: () => {
|
||||
units.handlers.tipo.draw({units: units.data.units, formatters: units.formatters})
|
||||
},
|
||||
lineas: () => {
|
||||
units.handlers.lineas.draw({units: units.data.units, formatters: units.formatters})
|
||||
}
|
||||
}
|
||||
},
|
||||
setup(ids) {
|
||||
units.ids = ids
|
||||
|
||||
units.handlers.tipo = new TipoTable(units.data.commission)
|
||||
units.handlers.lineas = new LineasTable(units.data.commission)
|
||||
units.handlers.units = new UnitsTable(units.data.commission)
|
||||
|
||||
$(`#${units.ids.results}`).find('.tabular.menu .item').tab({
|
||||
onVisible: function(tabPath) {
|
||||
if (tabPath !== 'unidades') {
|
||||
return
|
||||
}
|
||||
$(this.querySelector('table')).DataTable().columns.adjust().draw()
|
||||
this.querySelector('table').style.width = ''
|
||||
}
|
||||
})
|
||||
document.getElementById(units.ids.results).style.visibility = 'hidden'
|
||||
document.getElementById(units.ids.progress).style.visibility = 'hidden'
|
||||
document.getElementById(units.ids.load_progress).style.visibility = 'hidden'
|
||||
|
||||
const loader = $(`#${units.ids.loader}`)
|
||||
|
||||
units.get().units().then(() => {
|
||||
document.getElementById(units.ids.load_progress).style.visibility = 'visible'
|
||||
|
||||
const units_length = units.data.units.length
|
||||
const progress_bar = $(`#${units.ids.load_progress}`)
|
||||
progress_bar.progress({ total: units_length * 3 })
|
||||
|
||||
loader.hide()
|
||||
|
||||
units.get().promotions(progress_bar).then(() => {
|
||||
units.get().sold(progress_bar).then(() => {
|
||||
units.get().prices(progress_bar).then(() => {
|
||||
document.getElementById(units.ids.results).style.visibility = 'visible'
|
||||
|
||||
loader.parent().remove()
|
||||
|
||||
units.draw().units()
|
||||
units.draw().tipos()
|
||||
units.draw().lineas()
|
||||
|
||||
document.getElementById(units.ids.progress).style.visibility = 'visible'
|
||||
const progress_bar = $(`#${units.ids.progress}`)
|
||||
progress_bar.progress()
|
||||
|
||||
units.get().values(progress_bar).then(() => {
|
||||
document.getElementById(units.ids.progress).remove()
|
||||
|
||||
units.draw().units()
|
||||
units.draw().tipos()
|
||||
units.draw().lineas()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
$(document).ready(function () {
|
||||
units.setup({results: 'results', loader: 'loader', progress: 'values_progress', load_progress: 'load_progress'})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -0,0 +1,91 @@
|
||||
<table class="ui table" id="lineas">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tipo</th>
|
||||
<th class="center aligned">Línea</th>
|
||||
<th class="center aligned">Orientación</th>
|
||||
<th class="center aligned">Cantidad</th>
|
||||
<th class="right aligned" style="text-decoration: overline">Precio Base</th>
|
||||
<th class="right aligned" style="text-decoration: overline">Comisión</th>
|
||||
<th class="right aligned" style="text-decoration: overline">Precio Operador</th>
|
||||
<th class="center aligned" style="text-decoration: overline" id="linea_promociones">Promociones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class LineasTable extends GroupedTableHandler {
|
||||
ids = {
|
||||
lineas: 'lineas',
|
||||
promotions: 'linea_promociones'
|
||||
}
|
||||
constructor(commission) {
|
||||
super(commission)
|
||||
}
|
||||
draw({units, formatters}) {
|
||||
const table = document.getElementById(this.ids.lineas)
|
||||
const tbody = table.querySelector('tbody')
|
||||
tbody.innerHTML = ''
|
||||
const lineas = Object.groupBy(units, unit => {
|
||||
return [unit.proyecto_tipo_unidad.tipo_unidad.descripcion, unit.proyecto_tipo_unidad.nombre, unit.orientacion]
|
||||
})
|
||||
this.promotions.names = new Set()
|
||||
this.promotions.values = []
|
||||
Object.entries(lineas).sort(([linea1, unidades1], [linea2, unidades2]) => {
|
||||
const split1 = linea1.split(',')
|
||||
const split2 = linea2.split(',')
|
||||
const ct = unidades1[0].proyecto_tipo_unidad.tipo_unidad.orden - unidades2[0].proyecto_tipo_unidad.tipo_unidad.orden
|
||||
if (ct === 0) {
|
||||
const cl = split1[1].localeCompare(split2[1])
|
||||
if (cl === 0) {
|
||||
return split1[2].localeCompare(split2[2])
|
||||
}
|
||||
return cl
|
||||
}
|
||||
return ct
|
||||
}).forEach(([linea, unidades]) => {
|
||||
const parts = linea.split(',')
|
||||
const tipo = parts[0]
|
||||
const orientacion = parts[2]
|
||||
const prices = this.prices(unidades)
|
||||
|
||||
const base_tooltip = [
|
||||
`Min: UF ${formatters.ufs.format(Math.min(...prices.map(p => p.base)))}`,
|
||||
`Max: UF ${formatters.ufs.format(Math.max(...prices.map(p => p.base)))}`,
|
||||
`Desv: UF ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.base)))}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
const commission_tooltip = [
|
||||
`Min: ${formatters.percent.format(Math.min(...prices.map(p => p.commission)))}`,
|
||||
`Max: ${formatters.percent.format(Math.max(...prices.map(p => p.commission)))}`,
|
||||
`Desv: ${formatters.percent.format(Stat.standardDeviation(prices.map(p => p.commission)))}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
const broker_tooltip = [
|
||||
`Min: ${formatters.ufs.format(Math.min(...prices.map(p => p.broker)))}`,
|
||||
`Max: ${formatters.ufs.format(Math.max(...prices.map(p => p.broker)))}`,
|
||||
`Desv: ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.broker)))}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
|
||||
const promotions = this.process().prices(prices)
|
||||
this.process().promotions().names(promotions)
|
||||
this.process().promotions().values({promotions, formatters})
|
||||
|
||||
tbody.innerHTML += [
|
||||
`<tr>`,
|
||||
`<td>${tipo.charAt(0).toUpperCase() + tipo.slice(1)}</td>`,
|
||||
`<td class="center aligned"><span data-tooltip="${unidades[0].proyecto_tipo_unidad.tipologia}" data-position="right center">${parts[1]}</span></td>`,
|
||||
`<td class="center aligned">${orientacion}</td>`,
|
||||
`<td class="center aligned">${unidades.length}</td>`,
|
||||
`<td class="right aligned"><span data-tooltip="${base_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.base)))}</span></td>`,
|
||||
`<td class="right aligned"><span data-tooltip="${commission_tooltip}" data-position="right center" data-variation="wide multiline">${formatters.percent.format(Stat.mean(prices.map(p => p.commission)))}</span></td>`,
|
||||
`<td class="right aligned"><span data-tooltip="${broker_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.broker)))}</span></td>`,
|
||||
`<td class="right aligned promotions"></td>`,
|
||||
`</tr>`
|
||||
].join("\n")
|
||||
})
|
||||
this.build().promotions(table, tbody)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
@ -0,0 +1,71 @@
|
||||
<table class="ui table" id="tipos">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tipo</th>
|
||||
<th class="center aligned">Cantidad</th>
|
||||
<th class="right aligned" style="text-decoration: overline">Precio Base</th>
|
||||
<th class="right aligned" style="text-decoration: overline">Comisión</th>
|
||||
<th class="right aligned" style="text-decoration: overline">Precio Operador</th>
|
||||
<th class="center aligned" style="text-decoration: overline" id="tipo_promociones">Promociones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class TipoTable extends GroupedTableHandler {
|
||||
ids = {
|
||||
tipos: 'tipos',
|
||||
promotions: 'tipo_promociones'
|
||||
}
|
||||
constructor(commission) {
|
||||
super(commission)
|
||||
}
|
||||
draw({units, formatters}) {
|
||||
const table = document.getElementById(this.ids.tipos)
|
||||
const tbody = table.querySelector('tbody')
|
||||
tbody.innerHTML = ''
|
||||
const groups = Object.groupBy(units, unit => {
|
||||
return unit.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
})
|
||||
this.promotions.names = new Set()
|
||||
this.promotions.values = []
|
||||
Object.entries(groups).forEach(([tipo, unidades]) => {
|
||||
const prices = this.prices(unidades)
|
||||
const base_tooltip = [
|
||||
`Min: UF ${formatters.ufs.format(Math.min(...prices.map(p => p.base)))}`,
|
||||
`Max: UF ${formatters.ufs.format(Math.max(...prices.map(p => p.base)))}`,
|
||||
`Desv: UF ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.base)))}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
const commission_tooltip = [
|
||||
`Min: ${formatters.percent.format(Math.min(...prices.map(p => p.commission)))}`,
|
||||
`Max: ${formatters.percent.format(Math.max(...prices.map(p => p.commission)))}`,
|
||||
`Desv: ${formatters.percent.format(Stat.standardDeviation(prices.map(p => p.commission)))}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
const broker_tooltip = [
|
||||
`Min: ${formatters.ufs.format(Math.min(...prices.map(p => p.broker)))}`,
|
||||
`Max: ${formatters.ufs.format(Math.max(...prices.map(p => p.broker)))}`,
|
||||
`Desv: ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.broker)))}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
|
||||
const promotions = this.process().prices(prices)
|
||||
this.process().promotions().names(promotions)
|
||||
this.process().promotions().values({promotions, formatters})
|
||||
|
||||
tbody.innerHTML += [
|
||||
`<tr>`,
|
||||
`<td>${tipo.charAt(0).toUpperCase() + tipo.slice(1)}</td>`,
|
||||
`<td class="center aligned">${unidades.length}</td>`,
|
||||
`<td class="right aligned"><span data-tooltip="${base_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.base)))}</span></td>`,
|
||||
`<td class="right aligned"><span data-tooltip="${commission_tooltip}" data-position="right center" data-variation="wide multiline">${formatters.percent.format(Stat.mean(prices.map(p => p.commission)))}</span></td>`,
|
||||
`<td class="right aligned"><span data-tooltip="${broker_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.broker)))}</span></td>`,
|
||||
`<td class="right aligned promotions"></td>`,
|
||||
`</tr>`
|
||||
].join("\n")
|
||||
})
|
||||
this.build().promotions(table, tbody)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user