Auth, Login, Home, Venta->Listados->Precios
This commit is contained in:
9
app/common/Alias/View.php
Normal file
9
app/common/Alias/View.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Alias;
|
||||
|
||||
use Illuminate\Events\Dispatcher;
|
||||
use Slim\Views\Blade;
|
||||
|
||||
class View extends Blade
|
||||
{
|
||||
}
|
14
app/common/Define/Connection.php
Normal file
14
app/common/Define/Connection.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Define;
|
||||
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
|
||||
interface Connection
|
||||
{
|
||||
public function connect(): Connection;
|
||||
public function query(string $query): PDOStatement;
|
||||
public function prepare(string $query): PDOStatement;
|
||||
public function execute(string $query, ?array $data = null): PDOStatement;
|
||||
public function getPDO(): PDO;
|
||||
}
|
8
app/common/Define/Database.php
Normal file
8
app/common/Define/Database.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Define;
|
||||
|
||||
interface Database
|
||||
{
|
||||
public function getDSN(): string;
|
||||
public function needsUser(): bool;
|
||||
}
|
8
app/common/Define/Model.php
Normal file
8
app/common/Define/Model.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Define;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
interface Model extends JsonSerializable
|
||||
{
|
||||
}
|
11
app/common/Define/Repository.php
Normal file
11
app/common/Define/Repository.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Define;
|
||||
|
||||
interface Repository
|
||||
{
|
||||
public function create(?array $data = null): Model;
|
||||
public function save(Model $model): Model;
|
||||
public function load(array $data_row): Model;
|
||||
public function edit(Model $model, array $new_data): Model;
|
||||
public function remove(Model $model): void;
|
||||
}
|
16
app/common/Ideal/Model.php
Normal file
16
app/common/Ideal/Model.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Ideal;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
|
||||
abstract class Model implements Define\Model
|
||||
{
|
||||
public int $id;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'id' => $this->id
|
||||
];
|
||||
}
|
||||
}
|
126
app/common/Ideal/Repository.php
Normal file
126
app/common/Ideal/Repository.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Ideal;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use PDO;
|
||||
use Incoviba\Common\Define\Model;
|
||||
use Incoviba\Common\Define;
|
||||
|
||||
abstract class Repository implements Define\Repository
|
||||
{
|
||||
public function __construct(protected Define\Connection $connection) {}
|
||||
|
||||
protected string $table;
|
||||
public function getTable(): string
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
public function setTable(string $table): Repository
|
||||
{
|
||||
$this->table = $table;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function load(array $data_row): Model
|
||||
{
|
||||
$model = $this->create($data_row);
|
||||
$model->{$this->getKey()} = $data_row[$this->getKey()];
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function remove(Model $model): void
|
||||
{
|
||||
$query = "DELETE FROM `{$this->getTable()}` WHERE `{$this->getKey()}` = ?";
|
||||
$this->connection->execute($query, [$model->getId()]);
|
||||
}
|
||||
|
||||
public function fetchById(int $id): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `{$this->getKey()}` = ?";
|
||||
return $this->fetchOne($query, [$id]);
|
||||
}
|
||||
public function fetchAll(): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}`";
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
|
||||
protected function getKey(): string
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
protected function parseData(Define\Model $model, ?array $data, array $data_map): Define\Model
|
||||
{
|
||||
if ($data === null) {
|
||||
return $model;
|
||||
}
|
||||
foreach ($data_map as $column => $settings) {
|
||||
if (isset($data[$column])) {
|
||||
$property = $column;
|
||||
if (isset($settings['property'])) {
|
||||
$property = $settings['property'];
|
||||
}
|
||||
$value = $data[$column];
|
||||
if (isset($settings['function'])) {
|
||||
$value = $settings['function']($data);
|
||||
}
|
||||
$model->{$property} = $value;
|
||||
}
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
protected function saveNew(array $columns, array $values): int
|
||||
{
|
||||
$columns_string = implode(', ', array_map(function($column) {return "`{$column}`";}, $columns));
|
||||
$columns_questions = implode(', ', array_fill(0, count($columns), '?'));
|
||||
$query = "INSERT INTO `{$this->getTable()}` ({$columns_string}) VALUES ($columns_questions)";
|
||||
$this->connection->execute($query, $values);
|
||||
return $this->connection->getPDO()->lastInsertId();
|
||||
}
|
||||
protected function update(Model $model, array $columns, array $data): Define\Model
|
||||
{
|
||||
$changes = [];
|
||||
$values = [];
|
||||
foreach ($columns as $column) {
|
||||
if (isset($data[$column])) {
|
||||
$changes []= $column;
|
||||
$values []= $data[$column];
|
||||
}
|
||||
}
|
||||
if (count($changes) === 0) {
|
||||
return $model;
|
||||
}
|
||||
$columns_string = implode(', ', array_map(function($property) {return "`{$property}` = ?";}, $changes));
|
||||
$query = "UPDATE `{$this->getTable()}` SET {$columns_string} WHERE `{$this->getKey()}` = ?";
|
||||
$values []= $model->id;
|
||||
$this->connection->execute($query, $values);
|
||||
$id = $model->id;
|
||||
$model = $this->create($data);
|
||||
$model->id = $id;
|
||||
return $model;
|
||||
}
|
||||
protected function fetchOne(string $query, ?array $data = null): Define\Model
|
||||
{
|
||||
$result = $this->connection->execute($query, $data)->fetch(PDO::FETCH_ASSOC);
|
||||
if ($result === false) {
|
||||
throw new EmptyResult($query);
|
||||
}
|
||||
return $this->load($result);
|
||||
}
|
||||
protected function fetchMany(string $query, ?array $data = null): array
|
||||
{
|
||||
$results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
|
||||
if ($results === false) {
|
||||
throw new EmptyResult($query);
|
||||
}
|
||||
return array_map([$this, 'load'], $results);
|
||||
}
|
||||
protected function fetchAsArray(string $query, ?array $data = null): array
|
||||
{
|
||||
$results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
|
||||
if ($results === false) {
|
||||
throw new EmptyResult($query);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
61
app/common/Implement/Connection.php
Normal file
61
app/common/Implement/Connection.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Implement;
|
||||
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
use PDOException;
|
||||
use Incoviba\Common\Define;
|
||||
|
||||
class Connection implements Define\Connection
|
||||
{
|
||||
public function __construct(protected Define\Database $database) {}
|
||||
|
||||
protected PDO $connection;
|
||||
public function connect(): Define\Connection
|
||||
{
|
||||
if (!isset($this->connection)) {
|
||||
if ($this->database->needsUser()) {
|
||||
$this->connection = new PDO($this->database->getDSN(), $this->database->user, $this->database->password);
|
||||
} else {
|
||||
$this->connection = new PDO($this->database->getDSN());
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function getPDO(): PDO
|
||||
{
|
||||
$this->connect();
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
public function query(string $query): PDOStatement
|
||||
{
|
||||
$this->connect();
|
||||
$statement = $this->connection->query($query);
|
||||
if ($statement === false) {
|
||||
throw new PDOException("Query failed: '{$query}'");
|
||||
}
|
||||
return $statement;
|
||||
}
|
||||
public function prepare(string $query): PDOStatement
|
||||
{
|
||||
$this->connect();
|
||||
$statement = $this->connection->prepare($query);
|
||||
if ($statement === false) {
|
||||
throw new PDOException("Query failed: '{$query}'");
|
||||
}
|
||||
return $statement;
|
||||
}
|
||||
public function execute(string $query, ?array $data = null): PDOStatement
|
||||
{
|
||||
if ($data === null) {
|
||||
return $this->query($query);
|
||||
}
|
||||
$statement = $this->prepare($query);
|
||||
$status = $statement->execute($data);
|
||||
if ($status === false) {
|
||||
throw new PDOException("Query could not be executed: '{$query}'");
|
||||
}
|
||||
return $statement;
|
||||
}
|
||||
}
|
24
app/common/Implement/Database/MySQL.php
Normal file
24
app/common/Implement/Database/MySQL.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Implement\Database;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
|
||||
class MySQL implements Define\Database
|
||||
{
|
||||
public function __construct(public string $host, public string $name, public string $user, public string $password) {}
|
||||
|
||||
public int $port = 3306;
|
||||
|
||||
public function getDSN(): string
|
||||
{
|
||||
$dsn = "mysql:host={$this->host};dbname={$this->name}";
|
||||
if ($this->port !== 3306) {
|
||||
$dsn .= ";port={$this->port}";
|
||||
}
|
||||
return $dsn;
|
||||
}
|
||||
public function needsUser(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
15
app/common/Implement/Exception/EmptyResult.php
Normal file
15
app/common/Implement/Exception/EmptyResult.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Implement\Exception;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
class EmptyResult extends Exception
|
||||
{
|
||||
public function __construct(string $query, ?Throwable $previous = null)
|
||||
{
|
||||
$message = "Empty results for {$query}";
|
||||
$code = 700;
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
31
app/composer.json
Normal file
31
app/composer.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "incoviba/web",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"slim/slim": "^4.11",
|
||||
"php-di/php-di": "^7.0",
|
||||
"php-di/slim-bridge": "^3.4",
|
||||
"berrnd/slim-blade-view": "^1.0",
|
||||
"monolog/monolog": "^3.4",
|
||||
"nyholm/psr7": "^1.8",
|
||||
"nyholm/psr7-server": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^10.2"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Aldarien",
|
||||
"email": "aldarien85@gmail.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Incoviba\\Common\\": "common/",
|
||||
"Incoviba\\": "src/"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
}
|
||||
}
|
BIN
app/public/assets/images/Isotipo 16.png
Normal file
BIN
app/public/assets/images/Isotipo 16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
BIN
app/public/assets/images/Isotipo 32.png
Normal file
BIN
app/public/assets/images/Isotipo 32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
BIN
app/public/assets/images/Isotipo 64.png
Normal file
BIN
app/public/assets/images/Isotipo 64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.2 KiB |
BIN
app/public/assets/images/logo_cabezal.png
Normal file
BIN
app/public/assets/images/logo_cabezal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
7
app/public/index.php
Normal file
7
app/public/index.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
$app = require_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__FILE__, 2),
|
||||
'setup',
|
||||
'app.php'
|
||||
]);
|
||||
$app->run();
|
2
app/public/robots.txt
Normal file
2
app/public/robots.txt
Normal file
@ -0,0 +1,2 @@
|
||||
User-agent: *
|
||||
Disallow: /
|
13
app/resources/routes/01_api.php
Normal file
13
app/resources/routes/01_api.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
$app->group('/api', function($app) {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'api']);
|
||||
if (file_exists($folder)) {
|
||||
$files = new FilesystemIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
}
|
||||
});
|
6
app/resources/routes/03_proyectos.php
Normal file
6
app/resources/routes/03_proyectos.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Proyectos;
|
||||
|
||||
$app->group('/proyectos', function($app) {
|
||||
$app->get('[/]', Proyectos::class);
|
||||
});
|
10
app/resources/routes/04_ventas.php
Normal file
10
app/resources/routes/04_ventas.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
$app->group('/ventas', function($app) {
|
||||
$files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'ventas']));
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
});
|
8
app/resources/routes/98_login.php
Normal file
8
app/resources/routes/98_login.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Login;
|
||||
|
||||
$app->group('/login', function($app) {
|
||||
$app->post('[/]', [Login::class, 'login']);
|
||||
$app->get('[/]', [Login::class, 'form']);
|
||||
});
|
||||
$app->get('/logout', [Login::class, 'logout']);
|
4
app/resources/routes/99_base.php
Normal file
4
app/resources/routes/99_base.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Base;
|
||||
|
||||
$app->get('[/]', Base::class);
|
6
app/resources/routes/api/proyectos.php
Normal file
6
app/resources/routes/api/proyectos.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Proyectos;
|
||||
|
||||
$app->group('/proyectos', function($app) {
|
||||
$app->get('[/]', [Proyectos::class, 'list']);
|
||||
});
|
13
app/resources/routes/api/ventas.php
Normal file
13
app/resources/routes/api/ventas.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
$app->group('/ventas', function($app) {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'ventas']);
|
||||
if (file_exists($folder)) {
|
||||
$files = new FilesystemIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
}
|
||||
});
|
6
app/resources/routes/api/ventas/precios.php
Normal file
6
app/resources/routes/api/ventas/precios.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Ventas\Precios;
|
||||
|
||||
$app->group('/precios', function($app) {
|
||||
$app->post('[/]', [Precios::class, 'proyecto']);
|
||||
});
|
9
app/resources/routes/ventas/cuotas.php
Normal file
9
app/resources/routes/ventas/cuotas.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Ventas\Cuotas;
|
||||
|
||||
$app->group('/cuotas', function($app) {
|
||||
$app->get('/pendientes[/]', [Cuotas::class, 'pendientes']);
|
||||
});
|
||||
$app->group('/cuota', function($app) {
|
||||
$app->post('/depositar[/]', [Cuotas::class, 'depositar']);
|
||||
});
|
6
app/resources/routes/ventas/precios.php
Normal file
6
app/resources/routes/ventas/precios.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Ventas\Precios;
|
||||
|
||||
$app->group('/precios', function($app) {
|
||||
$app->get('[/]', Precios::class);
|
||||
});
|
7
app/resources/views/guest.blade.php
Normal file
7
app/resources/views/guest.blade.php
Normal file
@ -0,0 +1,7 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
Bienvenid@ a Incoviba
|
||||
</div>
|
||||
@endsection
|
26
app/resources/views/home.blade.php
Normal file
26
app/resources/views/home.blade.php
Normal file
@ -0,0 +1,26 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h4 class="ui header">Bienvenid@ {{$user->name}}</h4>
|
||||
<div class="ui basic fitted segment">
|
||||
@if ($cuotas_hoy > 0)
|
||||
Existe{{$cuotas_hoy > 1 ? 'n' : ''}} {{$cuotas_hoy}} deposito{{$cuotas_hoy > 1 ? 's' : ''}} para hoy.
|
||||
<br />
|
||||
@endif
|
||||
@if ($cuotas_pendientes > 0)
|
||||
<a href="{{$urls->base}}/ventas/cuotas/pendientes">
|
||||
Existe{{$cuotas_pendientes > 1 ? 'n' : ''}} {{$cuotas_pendientes}} cuota{{$cuotas_pendientes > 1 ? 's' : ''}} pendiente{{$cuotas_pendientes > 1 ? 's' : ''}}. <i class="right arrow icon"></i>
|
||||
</a>
|
||||
@endif
|
||||
</div>
|
||||
<div class="ui two column grid">
|
||||
<div class="column">
|
||||
@include('home.cuotas_por_vencer')
|
||||
</div>
|
||||
<div class="column">
|
||||
@include('home.cierres_vigentes')
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
24
app/resources/views/home/cierres_vigentes.blade.php
Normal file
24
app/resources/views/home/cierres_vigentes.blade.php
Normal file
@ -0,0 +1,24 @@
|
||||
<h4 class="ui dividing header">Cierres Vigentes</h4>
|
||||
<div class="ui divided list">
|
||||
@foreach($cierres_vigentes as $proyecto => $estados)
|
||||
<div class="item">
|
||||
<div class="ui feed">
|
||||
<div class="date">
|
||||
<strong>{{$proyecto}}</strong> [{{$estados['total']}}]
|
||||
</div>
|
||||
<div class="event">
|
||||
<div class="content">Promesados</div>
|
||||
<div class="meta">{{$estados['promesados']}}</div>
|
||||
</div>
|
||||
<div class="event">
|
||||
<div class="content">Pendientes</div>
|
||||
<div class="meta">{{$estados['pendientes']}}</div>
|
||||
</div>
|
||||
<div class="event">
|
||||
<div class="content">Rechazados</div>
|
||||
<div class="meta">{{$estados['rechazados']}}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
22
app/resources/views/home/cuotas_por_vencer.blade.php
Normal file
22
app/resources/views/home/cuotas_por_vencer.blade.php
Normal file
@ -0,0 +1,22 @@
|
||||
<h4 class="ui dividing header">Cuotas Por Vencer</h4>
|
||||
<div class="ui divided list">
|
||||
@foreach ($cuotas_por_vencer as $date => $proyectos)
|
||||
<div class="item">
|
||||
<div class="ui feed">
|
||||
<div class="date">
|
||||
<strong>{{$format->localDate($date, "EEE. dd 'de' MMMM 'de' yyyy", true)}}</strong>
|
||||
</div>
|
||||
@foreach ($proyectos as $proyecto => $cuotas)
|
||||
<div class="event">
|
||||
<div class="content">
|
||||
<span class="ui small text">
|
||||
{{$proyecto}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="meta">{{$cuotas}}</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
5
app/resources/views/layout/base.blade.php
Normal file
5
app/resources/views/layout/base.blade.php
Normal file
@ -0,0 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
@include('layout.head')
|
||||
@include('layout.body')
|
||||
</html>
|
5
app/resources/views/layout/body.blade.php
Normal file
5
app/resources/views/layout/body.blade.php
Normal file
@ -0,0 +1,5 @@
|
||||
<body>
|
||||
@include('layout.body.header')
|
||||
@yield('page_content')
|
||||
@include('layout.body.footer')
|
||||
</body>
|
4
app/resources/views/layout/body/footer.blade.php
Normal file
4
app/resources/views/layout/body/footer.blade.php
Normal file
@ -0,0 +1,4 @@
|
||||
<footer>
|
||||
|
||||
</footer>
|
||||
@include('layout.body.scripts')
|
7
app/resources/views/layout/body/header.blade.php
Normal file
7
app/resources/views/layout/body/header.blade.php
Normal file
@ -0,0 +1,7 @@
|
||||
<header class="ui container">
|
||||
<a class="ui medium image" href="{{$urls->base}}">
|
||||
<img src="{{$urls->images}}/logo_cabezal.png" alt="logo" />
|
||||
</a>
|
||||
@include('layout.body.header.menu')
|
||||
</header>
|
||||
<br />
|
17
app/resources/views/layout/body/header/menu.blade.php
Normal file
17
app/resources/views/layout/body/header/menu.blade.php
Normal file
@ -0,0 +1,17 @@
|
||||
<nav class="ui borderless menu">
|
||||
<a class="item" href="{{$urls->base}}"><img src="{{$urls->images}}/Isotipo 64.png" alt="brand" /></a>
|
||||
@if ($login->isIn())
|
||||
@include('layout.body.header.menu.ventas')
|
||||
@include('layout.body.header.menu.proyectos')
|
||||
@include('layout.body.header.menu.inmobiliarias')
|
||||
@include('layout.body.header.menu.contabilidad')
|
||||
@include('layout.body.header.menu.operadores')
|
||||
@include('layout.body.header.menu.herramientas')
|
||||
<div class="right aligned menu">
|
||||
@include('layout.body.header.menu.user')
|
||||
@include('layout.body.header.menu.search')
|
||||
</div>
|
||||
@else
|
||||
@include('layout.body.header.menu.guest')
|
||||
@endif
|
||||
</nav>
|
@ -0,0 +1,8 @@
|
||||
<div class="ui simple dropdown item">
|
||||
Contabilidad
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<a class="item" href="{{$urls->base}}/contabilidad/pagos/mes">Pagos Mes</a>
|
||||
<a class="item" href="{{$urls->base}}/contabilidad/resumen">Resumen</a>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1 @@
|
||||
<a class="item" href="{{$urls->base}}/login">Ingresar</a>
|
@ -0,0 +1,7 @@
|
||||
<div class="ui simple dropdown item">
|
||||
Herramientas
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<a class="item" href="{{$money_url}}">Valores Monetarios</a>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1 @@
|
||||
<a class="item" href="{{$urls->base}}/inmobiliarias">Inmobiliarias</a>
|
@ -0,0 +1,9 @@
|
||||
<div class="ui simple dropdown item">
|
||||
Operadores
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<a class="item" href="{{$urls->base}}/operadores/listado">Listado</a>
|
||||
<a class="item" href="{{$urls->base}}/operadores/ventas">Ventas</a>
|
||||
<a class="item" href="{{$urls->base}}/operadores/informe">Informe</a>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,8 @@
|
||||
<div class="ui simple dropdown item">
|
||||
Proyectos
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<a class="item" href="{{$urls->base}}">Listado</a>
|
||||
<a class="item" href="{{$urls->base}}/unidades">Unidades</a>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1 @@
|
||||
<a class="item" href="{{$urls->base}}/search"><i class="large search icon"></i></a>
|
31
app/resources/views/layout/body/header/menu/user.blade.php
Normal file
31
app/resources/views/layout/body/header/menu/user.blade.php
Normal file
@ -0,0 +1,31 @@
|
||||
<div class="ui simple dropdown item">
|
||||
{{$user->name}}
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<a class="item" href="{{$urls->base}}/user/password/change">Cambiar Clave</a>
|
||||
@if ($user->isAdmin())
|
||||
<a class="item" href="{{$urls->base}}/admin">Administración</a>
|
||||
@endif
|
||||
<div class="item" onclick="logout()">Salir</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
function logout() {
|
||||
return fetch('{{$urls->base}}/logout').then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (data.logout === true) {
|
||||
@if(isset($redirect_uri))
|
||||
window.location = '{{$redirect_uri}}'
|
||||
@else
|
||||
window.location = '{{$urls->base}}'
|
||||
@endif
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@endpush
|
41
app/resources/views/layout/body/header/menu/ventas.blade.php
Normal file
41
app/resources/views/layout/body/header/menu/ventas.blade.php
Normal file
@ -0,0 +1,41 @@
|
||||
<div class="ui simple dropdown item">
|
||||
Ventas
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<div class="item">
|
||||
Listados
|
||||
<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/cierres">Cierres</a>
|
||||
<a class="item" href="{{$urls->base}}/ventas">Ventas</a>
|
||||
<div class="item">
|
||||
Cuotas
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<a class="item" href="{{$urls->base}}/ventas/cuotas/pendientes">Pendientes</a>
|
||||
<a class="item" href="{{$urls->base}}/ventas/cuotas/abonar">Abonar</a>
|
||||
</div>
|
||||
</div>
|
||||
<a class="item" href="{{$urls->base}}/ventas/pagos/pendientes">Pagos Pendientes</a>
|
||||
<a class="item" href="{{$urls->base}}/ventas/consolidado">Consolidado Ventas</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="item">
|
||||
Informes
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<a class="item" href="{{$urls->base}}/informes/ventas">Ventas</a>
|
||||
<a class="item" href="{{$urls->base}}/informes/escrituras">Escrituras</a>
|
||||
<a class="item" href="{{$urls->base}}/informes/entregas/gantt">Gantt de Entregas</a>
|
||||
<a class="item" href="{{$urls->base}}/informes/resciliaciones">Resciliaciones</a>
|
||||
</div>
|
||||
</div>
|
||||
<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/add">
|
||||
Nueva Venta
|
||||
<i class="plus icon"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
4
app/resources/views/layout/body/scripts.blade.php
Normal file
4
app/resources/views/layout/body/scripts.blade.php
Normal file
@ -0,0 +1,4 @@
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js" integrity="sha512-3gJwYpMe3QewGELv8k/BX9vcqhryRdzRMxVfq6ngyWXwo03GFEzjsUm8Q7RZcHPHksttq7/GFoxjCVUjkjvPdw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.2/semantic.min.js" integrity="sha512-5cguXwRllb+6bcc2pogwIeQmQPXEzn2ddsqAexIBhh7FO1z5Hkek1J9mrK2+rmZCTU6b6pERxI7acnp1MpAg4Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
|
||||
@stack('page_scripts')
|
@ -0,0 +1,4 @@
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript" src="https://cdn.datatables.net/1.13.5/js/jquery.dataTables.min.js"></script>
|
||||
<script type="text/javascript" src="https://cdn.datatables.net/1.13.5/js/dataTables.semanticui.min.js"></script>
|
||||
@endpush
|
10
app/resources/views/layout/head.blade.php
Normal file
10
app/resources/views/layout/head.blade.php
Normal file
@ -0,0 +1,10 @@
|
||||
<head>
|
||||
<meta charset="utf8" />
|
||||
@hasSection('page_title')
|
||||
<title>Incoviba - @yield('page_title')</title>
|
||||
@else
|
||||
<title>Incoviba</title>
|
||||
@endif
|
||||
<link rel="icon" href="{{$urls->images}}/Isotipo 16.png" />
|
||||
@include('layout.head.styles')
|
||||
</head>
|
3
app/resources/views/layout/head/styles.blade.php
Normal file
3
app/resources/views/layout/head/styles.blade.php
Normal file
@ -0,0 +1,3 @@
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.2/semantic.min.css" integrity="sha512-n//BDM4vMPvyca4bJjZPDh7hlqsQ7hqbP9RH18GF2hTXBY5amBwM2501M0GPiwCU/v9Tor2m13GOTFjk00tkQA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||
|
||||
@stack('page_styles')
|
@ -0,0 +1,3 @@
|
||||
@push('page_styles')
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.5/css/dataTables.semanticui.min.css" />
|
||||
@endpush
|
60
app/resources/views/login/form.blade.php
Normal file
60
app/resources/views/login/form.blade.php
Normal file
@ -0,0 +1,60 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<div class="ui form" id="login_form">
|
||||
<div class="six wide field">
|
||||
<label for="name">Nombre</label>
|
||||
<input type="text" id="name" name="name" />
|
||||
</div>
|
||||
<div class="six wide field">
|
||||
<label for="password">Clave</label>
|
||||
<input type="password" id="password" name="password" />
|
||||
</div>
|
||||
<button class="ui button" id="enter">Ingresar</button>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
function sendLogin(name, password) {
|
||||
const data = new FormData()
|
||||
data.append('name', name)
|
||||
data.append('password', password)
|
||||
return fetch('{{$urls->base}}/login', {
|
||||
method: 'post',
|
||||
headers: {
|
||||
Accept: 'json'
|
||||
},
|
||||
body: data
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (data.login === true) {
|
||||
@if(isset($redirect_uri))
|
||||
window.location = '{{$redirect_uri}}'
|
||||
@else
|
||||
window.location = '{{$urls->base}}'
|
||||
@endif
|
||||
}
|
||||
})
|
||||
}
|
||||
$(document).ready(() => {
|
||||
$('#login_form').find('input').keypress(event => {
|
||||
if (event.which !== 13) {
|
||||
return
|
||||
}
|
||||
$('#enter').click()
|
||||
})
|
||||
$('#enter').click(event => {
|
||||
const form = $('#login_form')
|
||||
const name = form.find('#name').val()
|
||||
const password = form.find('#password').val()
|
||||
sendLogin(name, password)
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
108
app/resources/views/ventas/cuotas/pendientes.blade.php
Normal file
108
app/resources/views/ventas/cuotas/pendientes.blade.php
Normal file
@ -0,0 +1,108 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h3 class="ui header">Cuotas Pendientes</h3>
|
||||
<div class="ui grid">
|
||||
<div class="two wide column">Total</div>
|
||||
<div class="column">{{count($cuotas_pendientes)}}</div>
|
||||
<div class="column">{{$format->pesos(array_reduce($cuotas_pendientes, function($sum, $cuota) {return $sum + $cuota['Valor'];}, 0))}}</div>
|
||||
</div>
|
||||
<table class="ui striped table" id="cuotas">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="two wide column">Proyecto</th>
|
||||
<th class="column">Departamento</th>
|
||||
<th>Departamento Sort</th>
|
||||
<th class="column">Valor</th>
|
||||
<th class="column">Día</th>
|
||||
<th class="column">Cuota</th>
|
||||
<th class="two wide column">Propietario</th>
|
||||
<th class="column">Banco</th>
|
||||
<th class="two wide column">Fecha Cheque (Días)</th>
|
||||
<th>Fecha ISO</th>
|
||||
<th class="column">Depositar</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($cuotas_pendientes as $cuota)
|
||||
<tr>
|
||||
<td>{{$cuota['Proyecto']}}</td>
|
||||
<td>
|
||||
<a href="{{$urls->base}}/venta/{{$cuota['venta_id']}}">
|
||||
{{$cuota['Departamento']}}
|
||||
</a>
|
||||
</td>
|
||||
<td>{{str_pad($cuota['Departamento'], 4, '0', STR_PAD_LEFT)}}</td>
|
||||
<td>{{$format->pesos($cuota['Valor'])}}</td>
|
||||
<td>{{$cuota['Dia']}}</td>
|
||||
<td>{{$cuota['Numero']}}</td>
|
||||
<td>{{$cuota['Propietario']}}</td>
|
||||
<td>{{$cuota['Banco']}}</td>
|
||||
<td>{{$cuota['Fecha Cheque']}} ({{$cuota['Vencida']}})</td>
|
||||
<td>{{$cuota['Fecha ISO']}}</td>
|
||||
<td>
|
||||
<button class="ui icon button depositar" data-cuota="{{$cuota['id']}}">
|
||||
<i class="currency icon"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.head.styles.datatables')
|
||||
@include('layout.body.scripts.datatables')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
$(document).ready(() => {
|
||||
const cuotas_tables = new DataTable('#cuotas', {
|
||||
language: {
|
||||
info: 'Mostrando página _PAGE_ de _PAGES_',
|
||||
infoEmpty: 'No hay cuotas pendientes',
|
||||
infoFiltered: '(filtrado de _MAX_ cuotas)',
|
||||
lengthMenu: 'Mostrando de a _MENU_ cuotas',
|
||||
zeroRecords: 'No se encotró cuotas con ese criterio',
|
||||
search: 'Buscar: '
|
||||
},
|
||||
columnDefs: [
|
||||
{
|
||||
target: 9,
|
||||
visible: false
|
||||
},
|
||||
{
|
||||
target: 2,
|
||||
visible: false,
|
||||
searchable: false
|
||||
}
|
||||
],
|
||||
order: [
|
||||
[9, 'desc'],
|
||||
[0, 'asc'],
|
||||
[2, 'asc']
|
||||
]
|
||||
})
|
||||
$('.depositar.button').click(event => {
|
||||
const button = $(event.currentTarget)
|
||||
const cuota_id = button.data('cuota')
|
||||
fetch('{{$urls->base}}/ventas/cuota/depositar', {
|
||||
method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({cuota_id})
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (data.depositada) {
|
||||
const button = $(".depositar.button[data-cuota='" + data.cuota_id + "']")
|
||||
const cell = button.parent()
|
||||
const row = cell.parent()
|
||||
cuotas_tables.row(row).remove().draw()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
676
app/resources/views/ventas/precios/list.blade.php
Normal file
676
app/resources/views/ventas/precios/list.blade.php
Normal file
@ -0,0 +1,676 @@
|
||||
@extends('layout.base')
|
||||
|
||||
|
||||
@section('page_title')
|
||||
Precios - Listado
|
||||
@endsection
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2 class="ui header">Listado de Precios</h2>
|
||||
<div id="list">
|
||||
<h4 class="ui dividing header">
|
||||
<div class="ui two column grid">
|
||||
<div id="list_title" class="column"></div>
|
||||
<div class="right aligned column">
|
||||
<div class="ui tiny icon buttons">
|
||||
<button class="ui button" id="up_button">
|
||||
<i class="up arrow icon"></i>
|
||||
</button>
|
||||
<button class="ui button" id="refresh_button">
|
||||
<i class="refresh icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
<button class="ui tiny green icon button" id="add_button">
|
||||
<i class="plus icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</h4>
|
||||
<div class="ui link selection list" id="proyectos"></div>
|
||||
<table class="ui table" id="list_data"></table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui modal" id="list_modal">
|
||||
<div class="header">
|
||||
Actualizar <span id="modal_title"></span>
|
||||
<button class="ui right floated icon button"><i class="close icon"></i></button>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="ui form">
|
||||
<input type="hidden" name="type" value="" />
|
||||
<input type="hidden" name="id" value="" />
|
||||
<div class="inline field">
|
||||
<label for="fecha">Fecha</label>
|
||||
<div class="ui calendar" id="fecha">
|
||||
<div class="ui input left icon">
|
||||
<i class="calendar icon"></i>
|
||||
<input type="text" placeholder="Fecha" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="inline field">
|
||||
<label for="valor">Valor</label>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" id="valor" name="valor" />
|
||||
<div class="ui basic label">UF</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui button" id="send">
|
||||
Actualizar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_styles')
|
||||
<style>
|
||||
.show-unidades, .linea {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
@endpush
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
class Unidad {
|
||||
data = {
|
||||
id: 0,
|
||||
nombre: '',
|
||||
fecha: '',
|
||||
precio: 0,
|
||||
superficie: 0,
|
||||
tipo: '',
|
||||
linea: 0
|
||||
}
|
||||
|
||||
constructor({id, nombre, fecha, precio, superficie, tipo, linea}) {
|
||||
this.data.id = id
|
||||
this.data.nombre = nombre
|
||||
this.data.fecha = fecha
|
||||
this.data.precio = precio
|
||||
this.data.superficie = superficie
|
||||
this.data.tipo = tipo
|
||||
this.data.linea = linea
|
||||
}
|
||||
|
||||
unitario() {
|
||||
return this.data.precio / this.data.superficie
|
||||
}
|
||||
draw(formatter) {
|
||||
const date = new Date(this.data.fecha)
|
||||
const dateFormatter = new Intl.DateTimeFormat('es-CL')
|
||||
return $('<tr></tr>').addClass('unidad').attr('data-linea', this.data.linea).append(
|
||||
$('<td></td>').html(this.data.nombre)
|
||||
).append(
|
||||
$('<td></td>')
|
||||
).append(
|
||||
$('<td></td>').html(dateFormatter.format(date))
|
||||
).append(
|
||||
$('<td></td>').html(formatter.format(this.data.precio) + ' UF')
|
||||
).append(
|
||||
$('<td></td>').html(formatter.format(this.unitario()) + ' UF/m²')
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
$('<button></button>').addClass('ui tiny green icon button add_unidad')
|
||||
.attr('data-id', this.data.id)
|
||||
.attr('data-tipo', this.data.tipo)
|
||||
.attr('data-unidad', this.data.nombre).append(
|
||||
$('<i></i>').addClass('plus icon')
|
||||
).click(precios.actions().add().unidad)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
class Linea {
|
||||
data = {
|
||||
id: 0,
|
||||
nombre: '',
|
||||
orientacion: '',
|
||||
superficie: 0,
|
||||
unidades: [],
|
||||
}
|
||||
|
||||
constructor({id, nombre, orientacion, superficie}) {
|
||||
this.data.id = id
|
||||
this.data.nombre = nombre
|
||||
this.data.orientacion = orientacion
|
||||
this.data.superficie = superficie
|
||||
}
|
||||
|
||||
precio() {
|
||||
let sum = 0
|
||||
this.data.unidades.forEach(unidad => {
|
||||
sum += unidad.data.precio
|
||||
})
|
||||
return sum / this.data.unidades.length
|
||||
}
|
||||
unitario() {
|
||||
return this.precio() / this.data.superficie
|
||||
}
|
||||
add(data) {
|
||||
if (this.data.id !== data.unidad.subtipo) {
|
||||
return
|
||||
}
|
||||
let unidad = this.data.unidades.find(unidad => unidad.data.id === data.unidad.id)
|
||||
if (typeof unidad !== 'undefined') {
|
||||
return
|
||||
}
|
||||
const tipo = data.unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
unidad = new Unidad({
|
||||
id: data.unidad.id,
|
||||
nombre: data.unidad.descripcion,
|
||||
fecha: data.estado_precio.fecha,
|
||||
precio: data.valor,
|
||||
superficie: this.data.superficie,
|
||||
tipo: tipo.charAt(0).toUpperCase() + tipo.slice(1),
|
||||
linea: this.data.id
|
||||
})
|
||||
this.data.unidades.push(unidad)
|
||||
}
|
||||
draw(formatter) {
|
||||
const row1 = $('<tr></tr>').attr('data-id', this.data.id).attr('data-status', 'closed').append(
|
||||
$('<td></td>').addClass('linea').append($('<strong></strong>').html(this.data.nombre)).append(
|
||||
$('<i></i>').addClass('right caret icon')
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').addClass('linea').append($('<strong></strong>').html(this.data.orientacion))
|
||||
).append(
|
||||
$('<td></td>').addClass('linea')
|
||||
).append(
|
||||
$('<td></td>').addClass('linea').append($('<strong></strong>').html(formatter.format(this.precio()) + ' UF'))
|
||||
).append(
|
||||
$('<td></td>').addClass('linea').append($('<strong></strong>').html(formatter.format(this.unitario()) + ' UF/m²'))
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
$('<button></button>').addClass('ui tiny green icon button add_linea').attr('data-id', this.data.id).append(
|
||||
$('<i></i>').addClass('plus icon')
|
||||
).click(precios.actions().add().linea)
|
||||
)
|
||||
)
|
||||
const output = [
|
||||
row1
|
||||
]
|
||||
this.data.unidades.forEach(unidad => {
|
||||
output.push(unidad.draw(formatter))
|
||||
})
|
||||
return output
|
||||
}
|
||||
}
|
||||
class Tipologia {
|
||||
data = {
|
||||
id: 0,
|
||||
tipo: '',
|
||||
nombre: '',
|
||||
descripcion: '',
|
||||
lineas: [],
|
||||
superficie: 0,
|
||||
}
|
||||
constructor({id, tipo, nombre, descripcion, superficie}) {
|
||||
this.data.id = id
|
||||
this.data.tipo = tipo
|
||||
this.data.nombre = nombre
|
||||
this.data.descripcion = descripcion
|
||||
this.data.superficie = superficie
|
||||
}
|
||||
count() {
|
||||
return this.data.lineas.reduce((sum, linea) => {
|
||||
return sum + linea.data.unidades.length
|
||||
}, 0)
|
||||
}
|
||||
precio() {
|
||||
let sum = 0
|
||||
this.data.lineas.forEach(linea => {
|
||||
sum += linea.precio()
|
||||
})
|
||||
return sum / this.data.lineas.length
|
||||
}
|
||||
unitario() {
|
||||
return this.precio() / this.data.superficie
|
||||
}
|
||||
add(data) {
|
||||
if (this.data.id !== data.unidad.proyecto_tipo_unidad.id) {
|
||||
return
|
||||
}
|
||||
let linea = this.data.lineas.find(linea => linea.data.id === data.unidad.subtipo)
|
||||
if (this.data.lineas.length === 0 || typeof linea === 'undefined') {
|
||||
linea = new Linea({
|
||||
id: data.unidad.subtipo,
|
||||
nombre: 'Linea ' + data.unidad.subtipo,
|
||||
orientacion: data.unidad.orientacion,
|
||||
superficie: data.unidad.proyecto_tipo_unidad.vendible
|
||||
})
|
||||
this.data.lineas.push(linea)
|
||||
}
|
||||
linea.add(data)
|
||||
}
|
||||
draw(formatter) {
|
||||
const output = []
|
||||
const row1 = $('<tr></tr>').attr('data-status', 'closed').attr('data-id', this.data.id)
|
||||
row1.append(
|
||||
$('<td></td>').addClass('show-unidades').html(this.data.tipo).append(
|
||||
$('<i></i>').addClass('right caret icon')
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').addClass('show-unidades').html(this.data.nombre)
|
||||
).append(
|
||||
$('<td></td>').addClass('show-unidades').html(this.data.descripcion)
|
||||
).append(
|
||||
$('<td></td>').addClass('show-unidades').html(this.data.lineas.map(linea => linea.data.id).sort((a, b) => parseInt(a) - parseInt(b)).join(' - '))
|
||||
).append(
|
||||
$('<td></td>').addClass('show-unidades').html(formatter.format(this.data.superficie) + ' m²')
|
||||
).append(
|
||||
$('<td></td>').addClass('show-unidades').html(this.count())
|
||||
).append(
|
||||
$('<td></td>').addClass('show-unidades').html(formatter.format(this.precio()) + ' UF')
|
||||
).append(
|
||||
$('<td></td>').addClass('show-unidades').html(formatter.format(this.unitario()) + ' UF/m²')
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
$('<button></button>').addClass('ui tiny green icon button add_tipologia').attr('data-id', this.data.id).attr('data-tipologia', this.data.nombre).append(
|
||||
$('<i></i>').addClass('plus icon')
|
||||
).click(precios.actions().add().tipologia)
|
||||
)
|
||||
)
|
||||
const row2 = $('<tr></tr>').addClass('unidades').attr('data-tipo', this.data.id)
|
||||
const tbody = $('<tbody></tbody>')
|
||||
this.data.lineas.forEach(linea => {
|
||||
linea.draw(formatter).forEach(row => {
|
||||
tbody.append(row)
|
||||
})
|
||||
})
|
||||
const table = $('<table></table>').addClass('ui striped table')
|
||||
table.append(
|
||||
$('<thead></thead>').append(
|
||||
$('<tr></tr>').append(
|
||||
$('<th></th>').html('Unidad')
|
||||
).append(
|
||||
$('<th></th>').html('Orientación')
|
||||
).append(
|
||||
$('<th></th>').html('Desde')
|
||||
).append(
|
||||
$('<th></th>').html('Precio')
|
||||
).append(
|
||||
$('<th></th>').html('UF/m²')
|
||||
).append(
|
||||
$('<th></th>')
|
||||
)
|
||||
)
|
||||
).append(tbody)
|
||||
row2.append(
|
||||
$('<td></td>')
|
||||
).append(
|
||||
$('<td></td>').attr('colspan', 8).append(table)
|
||||
)
|
||||
output.push(row1)
|
||||
output.push(row2)
|
||||
return output
|
||||
}
|
||||
}
|
||||
const precios = {
|
||||
ids: {
|
||||
list: '',
|
||||
proyectos: '',
|
||||
buttons: {
|
||||
add: '',
|
||||
up: '',
|
||||
refresh: ''
|
||||
}
|
||||
},
|
||||
data: {
|
||||
id: 0,
|
||||
proyecto: '',
|
||||
proyectos: [],
|
||||
precios: []
|
||||
},
|
||||
table: null,
|
||||
loading: {
|
||||
precios: false
|
||||
},
|
||||
get: function() {
|
||||
return {
|
||||
proyectos: () => {
|
||||
this.data.proyectos = []
|
||||
this.data.id = 0
|
||||
this.data.proyecto = ''
|
||||
|
||||
$(this.ids.buttons.add).hide()
|
||||
|
||||
return fetch('{{$urls->api}}/proyectos').then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (data.total > 0) {
|
||||
data.proyectos.forEach(proyecto => {
|
||||
this.data.proyectos.push({
|
||||
id: proyecto.id,
|
||||
descripcion: proyecto.descripcion
|
||||
})
|
||||
})
|
||||
this.draw().proyectos()
|
||||
}
|
||||
})
|
||||
},
|
||||
precios: proyecto_id => {
|
||||
this.data.precios = []
|
||||
return fetch('{{$urls->api}}/ventas/precios',
|
||||
{method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}
|
||||
).then(response => {
|
||||
$('.item.proyecto').css('cursor', 'default')
|
||||
this.loading.precios = false
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (data.total > 0) {
|
||||
this.data.id = data.precios[0].unidad.proyecto_tipo_unidad.proyecto.id
|
||||
this.data.proyecto = data.precios[0].unidad.proyecto_tipo_unidad.proyecto.descripcion
|
||||
data.precios.forEach(precio => {
|
||||
this.add().precio(precio)
|
||||
})
|
||||
this.draw().precios()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
add: function() {
|
||||
return {
|
||||
precio: data => {
|
||||
let tipologia = this.data.precios.find(tipologia => tipologia.data.id === data.unidad.proyecto_tipo_unidad.id)
|
||||
if (this.data.precios.length === 0 || typeof tipologia === 'undefined') {
|
||||
const tipo = data.unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
tipologia = new Tipologia({
|
||||
id: data.unidad.proyecto_tipo_unidad.id,
|
||||
tipo: tipo.charAt(0).toUpperCase() + tipo.slice(1),
|
||||
nombre: data.unidad.proyecto_tipo_unidad.nombre,
|
||||
descripcion: data.unidad.proyecto_tipo_unidad.abreviacion,
|
||||
superficie: data.unidad.proyecto_tipo_unidad.vendible
|
||||
})
|
||||
this.data.precios.push(tipologia)
|
||||
}
|
||||
tipologia.add(data)
|
||||
}
|
||||
}
|
||||
},
|
||||
draw: function() {
|
||||
return {
|
||||
proyectos: () => {
|
||||
const parent = $(this.ids.list)
|
||||
const header = parent.find('#list_title')
|
||||
const list = parent.find('.list')
|
||||
const table = parent.find('table.table')
|
||||
|
||||
$(this.ids.buttons.add).hide()
|
||||
$(this.ids.buttons.add).attr('data-id', '')
|
||||
$(this.ids.buttons.add).attr('data-proyecto', '')
|
||||
|
||||
header.html('Proyectos')
|
||||
table.hide()
|
||||
list.html('')
|
||||
|
||||
this.data.proyectos.forEach(proyecto => {
|
||||
list.append(
|
||||
$('<div></div>').addClass('item proyecto').attr('data-proyecto', proyecto.id).html(proyecto.descripcion).css('cursor', 'pointer')
|
||||
)
|
||||
})
|
||||
list.show()
|
||||
$('.item.proyecto').click(event => {
|
||||
if (this.loading.precios) {
|
||||
return false
|
||||
}
|
||||
const element = $(event.currentTarget)
|
||||
$('.item.proyecto').css('cursor', 'wait')
|
||||
this.loading.precios = true
|
||||
const proyecto_id = element.data('proyecto')
|
||||
this.get().precios(proyecto_id)
|
||||
})
|
||||
},
|
||||
precios: () => {
|
||||
const parent = $(this.ids.list)
|
||||
const header = parent.find('#list_title')
|
||||
const list = parent.find('.list')
|
||||
const table = parent.find('table.table')
|
||||
|
||||
$(this.ids.buttons.add).attr('data-id', this.data.id)
|
||||
$(this.ids.buttons.add).attr('data-proyecto', this.data.proyecto)
|
||||
$(this.ids.buttons.add).show()
|
||||
|
||||
header.html('Precios de ' + this.data.proyecto)
|
||||
list.hide()
|
||||
table.html('')
|
||||
|
||||
table.append(this.draw().header())
|
||||
const tbody = $('<tbody></tbody>')
|
||||
const formatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
|
||||
this.data.precios.forEach(tipologia => {
|
||||
tipologia.draw(formatter).forEach(row => {
|
||||
tbody.append(row)
|
||||
})
|
||||
})
|
||||
table.append(tbody)
|
||||
table.show()
|
||||
|
||||
$('.show-unidades').click(this.actions().toggle().tipologia)
|
||||
$('.unidades').hide()
|
||||
$('.linea').click(this.actions().toggle().linea)
|
||||
$('.unidad').hide()
|
||||
},
|
||||
header: () => {
|
||||
return $('<thead></thead>').append(
|
||||
$('<tr></tr>').append(
|
||||
$('<th></th>').html('Tipo')
|
||||
).append(
|
||||
$('<th></th>').html('Nombre')
|
||||
).append(
|
||||
$('<th></th>').html('Tipología')
|
||||
).append(
|
||||
$('<th></th>').html('Líneas')
|
||||
).append(
|
||||
$('<th></th>').html('m² Vendibles')
|
||||
).append(
|
||||
$('<th></th>').html('#')
|
||||
).append(
|
||||
$('<th></th>').html('Precio Promedio')
|
||||
).append(
|
||||
$('<th></th>').html('UF/m²')
|
||||
).append(
|
||||
$('<th></th>')
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
actions: function() {
|
||||
return {
|
||||
toggle: () => {
|
||||
return {
|
||||
tipologia: event => {
|
||||
const th = $(event.currentTarget)
|
||||
const row = th.parent()
|
||||
const id = row.data('id')
|
||||
const status = row.attr('data-status')
|
||||
const unidades = $(".unidades[data-tipo='" + id + "']")
|
||||
if (status === 'closed') {
|
||||
unidades.show()
|
||||
row.attr('data-status', 'open')
|
||||
row.find('.caret.icon').removeClass('right').addClass('down')
|
||||
return
|
||||
}
|
||||
unidades.find('.linea').data('status', 'closed')
|
||||
unidades.find('.unidad').hide()
|
||||
unidades.hide()
|
||||
row.attr('data-status', 'closed')
|
||||
row.find('.caret.icon').removeClass('down').addClass('right')
|
||||
},
|
||||
linea: event => {
|
||||
const th = $(event.currentTarget)
|
||||
const row = th.parent()
|
||||
const id = row.data('id')
|
||||
const status = row.attr('data-status')
|
||||
const unidades = $(".unidad[data-linea='" + id + "']")
|
||||
if (status === 'closed') {
|
||||
unidades.show()
|
||||
row.attr('data-status', 'open')
|
||||
row.find('.caret.icon').removeClass('right').addClass('down')
|
||||
return
|
||||
}
|
||||
unidades.hide()
|
||||
row.attr('data-status', 'closed')
|
||||
row.find('.caret.icon').removeClass('down').addClass('right')
|
||||
}
|
||||
}
|
||||
},
|
||||
up: event => {
|
||||
this.get().proyectos()
|
||||
},
|
||||
refresh: event => {
|
||||
const list = $(this.ids.proyectos)
|
||||
if (list.is(':hidden')) {
|
||||
this.get().precios(this.data.id)
|
||||
} else {
|
||||
this.get().proyectos()
|
||||
}
|
||||
},
|
||||
add: () => {
|
||||
return {
|
||||
list: event => {
|
||||
const button = $(event.currentTarget)
|
||||
const id = button.data('id')
|
||||
const proyecto = button.data('proyecto')
|
||||
list_modal.data.title = 'Precios del Proyecto ' + proyecto
|
||||
list_modal.data.type = 'proyecto'
|
||||
list_modal.data.id = id
|
||||
list_modal.actions().open()
|
||||
},
|
||||
tipologia: event => {
|
||||
const button = $(event.currentTarget)
|
||||
const id = button.data('id')
|
||||
const tipologia = button.data('tipologia')
|
||||
list_modal.data.title = 'Precios de Tipología ' + tipologia
|
||||
list_modal.data.type = 'tipologia'
|
||||
list_modal.data.id = id
|
||||
list_modal.actions().open()
|
||||
},
|
||||
linea: event => {
|
||||
const button = $(event.currentTarget)
|
||||
const id = button.data('id')
|
||||
list_modal.data.title = 'Precios de la Línea ' + id
|
||||
list_modal.data.type = 'linea'
|
||||
list_modal.data.id = id
|
||||
list_modal.actions().open()
|
||||
},
|
||||
unidad: event => {
|
||||
const button = $(event.currentTarget)
|
||||
const id = button.data('id')
|
||||
const tipo = button.data('tipo')
|
||||
const unidad = button.data('unidad')
|
||||
list_modal.data.title = 'Precio de ' + tipo + ' ' + unidad
|
||||
list_modal.data.type = 'unidad'
|
||||
list_modal.data.id = id
|
||||
list_modal.actions().open()
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
setup: function() {
|
||||
$(this.ids.buttons.up).click(this.actions().up)
|
||||
$(this.ids.buttons.refresh).click(this.actions().refresh)
|
||||
$(this.ids.buttons.add).click(this.actions().add().list)
|
||||
|
||||
this.get().proyectos()
|
||||
}
|
||||
}
|
||||
|
||||
const list_modal = {
|
||||
ids: {
|
||||
modal: '',
|
||||
title: '',
|
||||
fields: {
|
||||
type: '',
|
||||
id: '',
|
||||
calendar: '',
|
||||
valor: ''
|
||||
},
|
||||
button: ''
|
||||
},
|
||||
data: {
|
||||
title: '',
|
||||
type: '',
|
||||
id: 0
|
||||
},
|
||||
actions: function() {
|
||||
return {
|
||||
reset: () => {
|
||||
this.data.title = ''
|
||||
this.data.type = ''
|
||||
this.data.id = 0
|
||||
|
||||
$(this.ids.fields.calendar).calendar('refresh')
|
||||
$(this.ids.fields.valor).val('')
|
||||
},
|
||||
open: event => {
|
||||
this.draw()
|
||||
$(this.ids.modal).modal('show')
|
||||
},
|
||||
close: event => {
|
||||
$(this.ids.modal).modal('hide')
|
||||
this.actions().reset()
|
||||
},
|
||||
send: event => {
|
||||
const data = {
|
||||
type: $(this.ids.fields.type).val(),
|
||||
id: $(this.ids.fields.id).val(),
|
||||
fecha: $(this.ids.fields.calendar).calendar('get date'),
|
||||
valor: $(this.ids.fields.valor).val()
|
||||
}
|
||||
return fetch('{{$urls->api}}/precios/update',
|
||||
{method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)}
|
||||
).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
precios.get().precios(precios.data.proyecto)
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
draw: function() {
|
||||
$(this.ids.title).html(this.data.title)
|
||||
$(this.ids.modal).find("input[name='type']").val(this.data.type)
|
||||
$(this.ids.modal).find("input[name='id']").val(this.data.id)
|
||||
},
|
||||
setup: function() {
|
||||
$(this.ids.modal).modal('hide')
|
||||
$(this.ids.modal).find('.icon.button').find('.close.icon').parent().click(this.actions().close)
|
||||
|
||||
$(this.ids.fields.calendar).calendar({
|
||||
type: 'date'
|
||||
})
|
||||
$(this.ids.button).click(this.actions().send)
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(() => {
|
||||
precios.ids.list = '#list'
|
||||
precios.ids.proyectos = '#proyectos'
|
||||
precios.ids.buttons.up = '#up_button'
|
||||
precios.ids.buttons.refresh = '#refresh_button'
|
||||
precios.ids.buttons.add = '#add_button'
|
||||
precios.setup()
|
||||
|
||||
list_modal.ids.modal = '#list_modal'
|
||||
list_modal.ids.title = '#modal_title'
|
||||
list_modal.ids.fields.type = "input[name='type']"
|
||||
list_modal.ids.fields.id = "input[name='id']"
|
||||
list_modal.ids.fields.calendar = '#fecha'
|
||||
list_modal.ids.fields.valor = '#valor'
|
||||
list_modal.ids.button = '#send'
|
||||
list_modal.setup()
|
||||
})
|
||||
</script>
|
||||
@endpush
|
45
app/setup/app.php
Normal file
45
app/setup/app.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
use DI\ContainerBuilder;
|
||||
use DI\Bridge\Slim\Bridge;
|
||||
|
||||
require_once 'composer.php';
|
||||
|
||||
function buildApp() {
|
||||
$builder = new ContainerBuilder();
|
||||
$folders = [
|
||||
'settings',
|
||||
'setups'
|
||||
];
|
||||
foreach ($folders as $folder_name) {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
$folder_name
|
||||
]);
|
||||
if (!file_exists($folder)) {
|
||||
continue;
|
||||
}
|
||||
$files = new FilesystemIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
$builder->addDefinitions($file->getRealPath());
|
||||
}
|
||||
}
|
||||
$app = Bridge::create($builder->build());
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
'middlewares'
|
||||
]);
|
||||
if (file_exists($folder)) {
|
||||
$files = new FilesystemIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
require_once $file->getRealPath();
|
||||
}
|
||||
}
|
||||
return $app;
|
||||
}
|
||||
return buildApp();
|
6
app/setup/composer.php
Normal file
6
app/setup/composer.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
require_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__FILE__, 2),
|
||||
'vendor',
|
||||
'autoload.php'
|
||||
]);
|
2
app/setup/middlewares/01_auth.php
Normal file
2
app/setup/middlewares/01_auth.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
$app->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));
|
2
app/setup/middlewares/98_logs.php
Normal file
2
app/setup/middlewares/98_logs.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
Monolog\ErrorHandler::register($app->getContainer()->get(Psr\Log\LoggerInterface::class));
|
12
app/setup/middlewares/99_routes.php
Normal file
12
app/setup/middlewares/99_routes.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
function loadRoutes(&$app): void {
|
||||
$folder = $app->getContainer()->get('folders')->get('routes');
|
||||
$files = new FilesystemIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
}
|
||||
loadRoutes($app);
|
2
app/setup/settings/env.php
Normal file
2
app/setup/settings/env.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
return $_ENV;
|
12
app/setup/settings/folders.php
Normal file
12
app/setup/settings/folders.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
return [
|
||||
'folders' => function() {
|
||||
return new DI\Container([
|
||||
'base' => dirname(__FILE__, 3),
|
||||
'resources' => DI\String('{base}/resources'),
|
||||
'routes' => DI\String('{resources}/routes'),
|
||||
'cache' => DI\String('{base}/cache'),
|
||||
'templates' => DI\String('{resources}/views')
|
||||
]);
|
||||
}
|
||||
];
|
21
app/setup/settings/urls.php
Normal file
21
app/setup/settings/urls.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
return [
|
||||
'urls' => function() {
|
||||
$urls = [
|
||||
'base' => $_ENV['APP_URL'] ?? '',
|
||||
];
|
||||
$urls['api'] = implode('/', [
|
||||
$urls['base'],
|
||||
'api'
|
||||
]);
|
||||
$urls['assets'] = implode('/', [
|
||||
$urls['base'],
|
||||
'assets'
|
||||
]);
|
||||
$urls['images'] = implode('/', [
|
||||
$urls['assets'],
|
||||
'images'
|
||||
]);
|
||||
return (object) $urls;
|
||||
}
|
||||
];
|
18
app/setup/setups/database.php
Normal file
18
app/setup/setups/database.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
Incoviba\Common\Define\Database::class => function(ContainerInterface $container) {
|
||||
return new Incoviba\Common\Implement\Database\MySQL(
|
||||
$container->has('MYSQL_HOST') ? $container->get('MYSQL_HOST') : 'db',
|
||||
$container->get('MYSQL_DATABASE'),
|
||||
$container->get('MYSQL_USER'),
|
||||
$container->get('MYSQL_PASSWORD')
|
||||
);
|
||||
},
|
||||
Incoviba\Common\Define\Connection::class => function(ContainerInterface $container) {
|
||||
return new Incoviba\Common\Implement\Connection(
|
||||
$container->get(Incoviba\Common\Define\Database::class)
|
||||
);
|
||||
}
|
||||
];
|
32
app/setup/setups/logs.php
Normal file
32
app/setup/setups/logs.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
|
||||
return new Monolog\Logger('incoviba', [
|
||||
new Monolog\Handler\FilterHandler(
|
||||
(new Monolog\Handler\RotatingFileHandler('/logs/debug.log'))
|
||||
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
|
||||
Monolog\Level::Debug,
|
||||
Monolog\Level::Notice
|
||||
),
|
||||
new Monolog\Handler\FilterHandler(
|
||||
(new Monolog\Handler\RotatingFileHandler('/logs/error.log'))
|
||||
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
|
||||
Monolog\Level::Warning,
|
||||
Monolog\Level::Error
|
||||
),
|
||||
new Monolog\Handler\FilterHandler(
|
||||
(new Monolog\Handler\RotatingFileHandler('/logs/critical.log'))
|
||||
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
|
||||
Monolog\Level::Critical
|
||||
)
|
||||
], [
|
||||
$container->get(Monolog\Processor\PsrLogMessageProcessor::class),
|
||||
$container->get(Monolog\Processor\WebProcessor::class),
|
||||
$container->get(Monolog\Processor\IntrospectionProcessor::class),
|
||||
$container->get(Monolog\Processor\MemoryUsageProcessor::class),
|
||||
$container->get(Monolog\Processor\MemoryPeakUsageProcessor::class)
|
||||
]);
|
||||
}
|
||||
];
|
15
app/setup/setups/middlewares.php
Normal file
15
app/setup/setups/middlewares.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
Psr\Http\Message\ResponseFactoryInterface::class => function(ContainerInterface $container) {
|
||||
return $container->get(Nyholm\Psr7\Factory\Psr17Factory::class);
|
||||
},
|
||||
Incoviba\Middleware\Authentication::class => function(ContainerInterface $container) {
|
||||
return new Incoviba\Middleware\Authentication(
|
||||
$container->get(Psr\Http\Message\ResponseFactoryInterface::class),
|
||||
$container->get(Incoviba\Service\Login::class),
|
||||
implode('/', [$container->get('APP_URL'), 'login'])
|
||||
);
|
||||
}
|
||||
];
|
14
app/setup/setups/services.php
Normal file
14
app/setup/setups/services.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
Incoviba\Service\Login::class => function(ContainerInterface $container) {
|
||||
return new Incoviba\Service\Login(
|
||||
$container->get(Incoviba\Repository\Login::class),
|
||||
$container->get('COOKIE_NAME'),
|
||||
$container->get('MAX_LOGIN_HOURS'),
|
||||
$container->has('COOKIE_DOMAIN') ? $container->get('COOKIE_DOMAIN') : '',
|
||||
$container->has('COOKIE_PATH') ? $container->get('COOKIE_PATH') : ''
|
||||
);
|
||||
}
|
||||
];
|
23
app/setup/setups/views.php
Normal file
23
app/setup/setups/views.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
Incoviba\Common\Alias\View::class => function(ContainerInterface $container) {
|
||||
$folders = $container->get('folders');
|
||||
$global_variables = [
|
||||
'urls' => $container->get('urls'),
|
||||
'money_url' => '',
|
||||
'login' => $container->get(Incoviba\Service\Login::class),
|
||||
'format' => $container->get(Incoviba\Service\Format::class),
|
||||
];
|
||||
if ($global_variables['login']->isIn()) {
|
||||
$global_variables['user'] = $global_variables['login']->getUser();
|
||||
}
|
||||
return new Incoviba\Common\Alias\View(
|
||||
$folders->get('templates'),
|
||||
$folders->get('cache'),
|
||||
null,
|
||||
$global_variables
|
||||
);
|
||||
}
|
||||
];
|
90
app/src/Controller/Base.php
Normal file
90
app/src/Controller/Base.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Base
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Login $service, Repository\Venta\Cuota $cuotaRepository, Repository\Venta\Cierre $cierreRepository): ResponseInterface
|
||||
{
|
||||
if ($service->isIn()) {
|
||||
return $this->home($response, $view, $cuotaRepository, $cierreRepository);
|
||||
}
|
||||
return $this->login($response, $view);
|
||||
}
|
||||
|
||||
protected function home(ResponseInterface $response, View $view, Repository\Venta\Cuota $cuotaRepository, Repository\Venta\Cierre $cierreRepository): ResponseInterface
|
||||
{
|
||||
$cuotas_hoy = count($cuotaRepository->fetchHoy()) ?? 0;
|
||||
$cuotas_pendientes = count($cuotaRepository->fetchPendientes()) ?? 0;
|
||||
$cuotas_por_vencer = $this->getCuotasPorVencer($cuotaRepository);
|
||||
$cierres_vigentes = $this->getCierresVigentes($cierreRepository);
|
||||
return $view->render($response, 'home', compact('cuotas_hoy', 'cuotas_pendientes', 'cuotas_por_vencer', 'cierres_vigentes'));
|
||||
}
|
||||
protected function login(ResponseInterface $response, View $view): ResponseInterface
|
||||
{
|
||||
return $view->render($response, 'guest');
|
||||
}
|
||||
protected function getCuotasPorVencer(Repository\Venta\Cuota $cuotaRepository): array
|
||||
{
|
||||
$cuotas = $cuotaRepository->fetchDatosPorVencer();
|
||||
$output = [];
|
||||
foreach ($cuotas as $row) {
|
||||
$fecha = $row['Fecha'];
|
||||
$date = new DateTimeImmutable($fecha);
|
||||
if (($weekday = $date->format('N')) > 5) {
|
||||
$day_diff = 7 - $weekday + 1;
|
||||
$date = $date->add(new DateInterval("P{$day_diff}D"));
|
||||
$fecha = $date->format('Y-m-d');
|
||||
}
|
||||
if (!isset($output[$fecha])) {
|
||||
$output[$fecha] = [];
|
||||
}
|
||||
if (!isset($output[$fecha][$row['Proyecto']])) {
|
||||
$output[$fecha][$row['Proyecto']] = 0;
|
||||
}
|
||||
$output[$fecha][$row['Proyecto']] += $row['Cantidad'];
|
||||
}
|
||||
foreach ($output as $fecha => $day) {
|
||||
uksort($day, function($a, $b) {
|
||||
return strcmp($a, $b);
|
||||
});
|
||||
$output[$fecha] = $day;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
protected function getCierresVigentes(Repository\Venta\Cierre $cierreRepository): array
|
||||
{
|
||||
$cierres = $cierreRepository->fetchDatosVigentes();
|
||||
$output = [];
|
||||
$estados = [
|
||||
'revisado' => 'pendientes',
|
||||
'rechazado' => 'rechazados',
|
||||
'aprobado' => 'pendientes',
|
||||
'vendido' => 'promesados',
|
||||
'abandonado' => 'rechazados',
|
||||
'promesado' => 'promesados',
|
||||
'resciliado' => 'rechazados'
|
||||
];
|
||||
foreach ($cierres as $row) {
|
||||
if (!isset($output[$row['Proyecto']])) {
|
||||
$output[$row['Proyecto']] = [
|
||||
'promesados' => 0,
|
||||
'pendientes' => 0,
|
||||
'rechazados' => 0,
|
||||
'total' => 0
|
||||
];
|
||||
}
|
||||
$estado = $estados[$row['Estado']];
|
||||
$output[$row['Proyecto']][$estado] += $row['Cantidad'];
|
||||
$output[$row['Proyecto']]['total'] += $row['Cantidad'];
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
55
app/src/Controller/Login.php
Normal file
55
app/src/Controller/Login.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use PDOException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Login
|
||||
{
|
||||
public function form(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Login $service): ResponseInterface
|
||||
{
|
||||
$redirect_uri = $request->hasHeader('Referer') ? $request->getHeaderLine('Referer') : $view->get('urls')->base;
|
||||
if ($service->isIn()) {
|
||||
$redirect_uri = str_replace('/login', '', $redirect_uri);
|
||||
return $response->withStatus(301)->withHeader('Location', $redirect_uri);
|
||||
}
|
||||
if ($request->hasHeader('X-Redirect-URI')) {
|
||||
$redirect_uri = $request->getHeaderLine('X-Redirect-URI');
|
||||
}
|
||||
return $view->render($response, 'login.form', compact('redirect_uri'));
|
||||
}
|
||||
public function login(ServerRequestInterface $request, ResponseInterface $response, Repository\User $userRepository, Service\Login $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$user = $userRepository->fetchByName($body['name']);
|
||||
$output = [
|
||||
'name' => $user->name,
|
||||
'login' => false
|
||||
];
|
||||
if ($user->validate($body['password'])) {
|
||||
$output['login'] = $service->login($user);
|
||||
}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function logout(ServerRequestInterface $request, ResponseInterface $response, Repository\Login $loginRepository, Service\Login $service): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'name' => '',
|
||||
'logout' => false
|
||||
];
|
||||
try {
|
||||
$user = $service->getUser();
|
||||
$output = [
|
||||
'name' => $user->name,
|
||||
'logout' => $service->logout($user)
|
||||
];
|
||||
} catch (PDOException) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
21
app/src/Controller/Proyectos.php
Normal file
21
app/src/Controller/Proyectos.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Proyectos
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view): ResponseInterface
|
||||
{
|
||||
return $view->render($response, 'proyectos.list');
|
||||
}
|
||||
public function list(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$proyectos = $proyectoRepository->fetchAllActive();
|
||||
$response->getBody()->write(json_encode(['proyectos' => $proyectos, 'total' => count($proyectos)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
11
app/src/Controller/Users.php
Normal file
11
app/src/Controller/Users.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Users
|
||||
{
|
||||
}
|
60
app/src/Controller/Ventas/Cuotas.php
Normal file
60
app/src/Controller/Ventas/Cuotas.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use IntlDateFormatter;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Cuotas
|
||||
{
|
||||
public function pendientes(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Venta\Cuota $cuotaRepository): ResponseInterface
|
||||
{
|
||||
$cuotas = $cuotaRepository->fetchPendientes();
|
||||
$cuotas_pendientes = [];
|
||||
$today = new DateTimeImmutable();
|
||||
$formatter = new IntlDateFormatter('es_ES');
|
||||
$formatter->setPattern('EEEE dd');
|
||||
foreach ($cuotas as $cuota) {
|
||||
$date = new DateTimeImmutable($cuota['fecha']);
|
||||
$day = clone $date;
|
||||
$weekday = $date->format('N');
|
||||
if ($weekday > 5) {
|
||||
$diff = 7 - $weekday + 1;
|
||||
$day = $day->add(new DateInterval("P{$diff}D"));
|
||||
}
|
||||
$cuotas_pendientes []= [
|
||||
'id' => $cuota['cuota_id'],
|
||||
'venta_id' => $cuota['venta_id'],
|
||||
'Proyecto' => $cuota['Proyecto'],
|
||||
'Departamento' => $cuota['Departamento'],
|
||||
'Valor' => $cuota['Valor'],
|
||||
'Dia' => $formatter->format($day),
|
||||
'Numero' => $cuota['Numero'],
|
||||
'Propietario' => $cuota['Propietario'],
|
||||
'Banco' => $cuota['Banco'],
|
||||
'Fecha Cheque' => $date->format('d-m-Y'),
|
||||
'Vencida' => $today->diff($date)->days,
|
||||
'Fecha ISO' => $date->format('Y-m-d')
|
||||
];
|
||||
}
|
||||
return $view->render($response, 'ventas.cuotas.pendientes', compact('cuotas_pendientes'));
|
||||
}
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Ventas\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$cuota_id = $json->cuota_id;
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output = [
|
||||
'cuota_id' => $cuota_id,
|
||||
'depositada' => $pagoService->depositar($cuota->pago)
|
||||
];
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
24
app/src/Controller/Ventas/Precios.php
Normal file
24
app/src/Controller/Ventas/Precios.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Precios
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view): ResponseInterface
|
||||
{
|
||||
return $view->render($response, 'ventas.precios.list');
|
||||
}
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Ventas\Precio $precioService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$precios = $precioService->getByProyecto($proyecto_id);
|
||||
$response->getBody()->write(json_encode(['precios' => $precios, 'total' => count($precios)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
48
app/src/Middleware/Authentication.php
Normal file
48
app/src/Middleware/Authentication.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace Incoviba\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseFactoryInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Authentication
|
||||
{
|
||||
public function __construct(protected ResponseFactoryInterface $responseFactory, protected Service\Login $service, protected string $login_url) {}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
if ($this->service->isIn() or $this->isValid($request)) {
|
||||
return $handler->handle($request);
|
||||
}
|
||||
$response = $this->responseFactory->createResponse(301, 'Not logged in');
|
||||
return $response->withHeader('Location', $this->login_url)
|
||||
->withHeader('X-Redirected-URI', (string) $request->getUri());
|
||||
}
|
||||
|
||||
protected function isValid(ServerRequestInterface $request): bool
|
||||
{
|
||||
$uri = $request->getUri();
|
||||
$current_path = $uri->getPath();
|
||||
$current_url = implode('', [
|
||||
"{$uri->getScheme()}://",
|
||||
$uri->getHost() . ($uri->getPort() !== null ? ":{$uri->getPort()}" : ''),
|
||||
$uri->getPath()
|
||||
]);
|
||||
|
||||
$valid_paths = [
|
||||
'/',
|
||||
];
|
||||
if (in_array($current_path, $valid_paths, true)) {
|
||||
return true;
|
||||
}
|
||||
$valid_uris = [
|
||||
$this->login_url,
|
||||
];
|
||||
if (in_array($current_url, $valid_uris, true)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
16
app/src/Model/Banco.php
Normal file
16
app/src/Model/Banco.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class Banco extends Model
|
||||
{
|
||||
public ?string $nombre;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'nombre' => $this->nombre ?? ''
|
||||
]);
|
||||
}
|
||||
}
|
18
app/src/Model/Comuna.php
Normal file
18
app/src/Model/Comuna.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class Comuna extends Model
|
||||
{
|
||||
public string $descripcion;
|
||||
public Provincia $provincia;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'descripcion' => $this->descripcion,
|
||||
'provincia' => $this->provincia
|
||||
]);
|
||||
}
|
||||
}
|
22
app/src/Model/Direccion.php
Normal file
22
app/src/Model/Direccion.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class Direccion extends Model
|
||||
{
|
||||
public string $calle;
|
||||
public int $numero;
|
||||
public string $extra;
|
||||
public Comuna $comuna;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'calle' => $this->calle,
|
||||
'numero' => $this->numero,
|
||||
'extra' => $this->extra,
|
||||
'comuna' => $this->comuna
|
||||
]);
|
||||
}
|
||||
}
|
38
app/src/Model/Inmobiliaria.php
Normal file
38
app/src/Model/Inmobiliaria.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
use Incoviba\Model\Inmobiliaria\TipoSociedad;
|
||||
|
||||
class Inmobiliaria extends Model
|
||||
{
|
||||
public int $rut;
|
||||
public ?string $dv;
|
||||
public ?string $razon;
|
||||
public ?string $abreviacion;
|
||||
public ?string $cuenta;
|
||||
public ?Banco $banco;
|
||||
public ?TipoSociedad $tipoSociedad;
|
||||
|
||||
public function rut(): string
|
||||
{
|
||||
return implode('-', [
|
||||
number_format($this->rut, 0, ',', '.'),
|
||||
$this->dv
|
||||
]);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'rut' => $this->rut,
|
||||
'dv' => $this->dv ?? '',
|
||||
'rut_formateado' => $this->rut(),
|
||||
'razon' => $this->razon ?? '',
|
||||
'abreviacion' => $this->abreviacion ?? '',
|
||||
'cuenta' => $this->cuenta ?? '',
|
||||
'banco' => $this->banco ?? '',
|
||||
'tipo_sociedad' => $this->tipoSociedad ?? ''
|
||||
];
|
||||
}
|
||||
}
|
16
app/src/Model/Inmobiliaria/TipoSociedad.php
Normal file
16
app/src/Model/Inmobiliaria/TipoSociedad.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Inmobiliaria;
|
||||
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoSociedad extends Model\Tipo
|
||||
{
|
||||
public string $abreviacion;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'abreviacion' => $this->abreviacion
|
||||
]);
|
||||
}
|
||||
}
|
25
app/src/Model/Login.php
Normal file
25
app/src/Model/Login.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Login extends Ideal\Model
|
||||
{
|
||||
public User $user;
|
||||
public string $selector;
|
||||
public string $token;
|
||||
public DateTimeInterface $dateTime;
|
||||
public bool $status;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'user_id' => $this->user->id,
|
||||
'selector' => $this->selector,
|
||||
'token' => $this->token,
|
||||
'date_time' => $this->dateTime->format('Y-m-d H:i:s'),
|
||||
'status' => $this->status
|
||||
]);
|
||||
}
|
||||
}
|
18
app/src/Model/Provincia.php
Normal file
18
app/src/Model/Provincia.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class Provincia extends Model
|
||||
{
|
||||
public string $descripcion;
|
||||
public Region $region;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'descripcion' => $this->descripcion,
|
||||
'region' => $this->region
|
||||
]);
|
||||
}
|
||||
}
|
32
app/src/Model/Proyecto.php
Normal file
32
app/src/Model/Proyecto.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
use Incoviba\Model\Proyecto\Superficie;
|
||||
use Incoviba\Model\Proyecto\Terreno;
|
||||
|
||||
class Proyecto extends Model
|
||||
{
|
||||
public Inmobiliaria $inmobiliaria;
|
||||
public string $descripcion;
|
||||
public Direccion $direccion;
|
||||
public Terreno $terreno;
|
||||
public Superficie $superficie;
|
||||
public float $corredor;
|
||||
public int $pisos;
|
||||
public int $subterraneos;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'inmobiliaria' => $this->inmobiliaria,
|
||||
'descripcion' => $this->descripcion,
|
||||
'direccion' => $this->direccion,
|
||||
'terreno' => $this->terreno,
|
||||
'superficie' => $this->superficie,
|
||||
'corredor' => $this->corredor,
|
||||
'pisos' => $this->pisos,
|
||||
'subterraneos' => $this->subterraneos
|
||||
]);
|
||||
}
|
||||
}
|
42
app/src/Model/Proyecto/ProyectoTipoUnidad.php
Normal file
42
app/src/Model/Proyecto/ProyectoTipoUnidad.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class ProyectoTipoUnidad extends Ideal\Model
|
||||
{
|
||||
public Model\Proyecto $proyecto;
|
||||
public Model\Venta\TipoUnidad $tipoUnidad;
|
||||
public string $nombre;
|
||||
public string $abreviacion;
|
||||
public float $util;
|
||||
public float $logia;
|
||||
public float $terraza;
|
||||
public string $descripcion;
|
||||
|
||||
public function superficie(): float
|
||||
{
|
||||
return array_reduce([$this->util, $this->logia, $this->terraza], function($sum, $item) {return $sum + $item;}, 0);
|
||||
}
|
||||
public function vendible(): float
|
||||
{
|
||||
return array_reduce([$this->util, $this->logia, $this->terraza / 2], function($sum, $item) {return $sum + $item;}, 0);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'proyecto' => $this->proyecto,
|
||||
'tipo_unidad' => $this->tipoUnidad,
|
||||
'nombre' => $this->nombre,
|
||||
'abreviacion' => $this->abreviacion,
|
||||
'util' => $this->util,
|
||||
'logia' => $this->logia,
|
||||
'terraza' => $this->terraza,
|
||||
'superficie' => $this->superficie(),
|
||||
'vendible' => $this->vendible(),
|
||||
'descripcion' => $this->descripcion
|
||||
]);
|
||||
}
|
||||
}
|
8
app/src/Model/Proyecto/Superficie.php
Normal file
8
app/src/Model/Proyecto/Superficie.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
class Superficie
|
||||
{
|
||||
public float $sobre_nivel;
|
||||
public float $bajo_nivel;
|
||||
}
|
8
app/src/Model/Proyecto/Terreno.php
Normal file
8
app/src/Model/Proyecto/Terreno.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
class Terreno
|
||||
{
|
||||
public float $superficie;
|
||||
public float $valor;
|
||||
}
|
20
app/src/Model/Region.php
Normal file
20
app/src/Model/Region.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class Region extends Model
|
||||
{
|
||||
public string $descripcion;
|
||||
public string $numeral;
|
||||
public ?int $numeracion;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'descripcion' => $this->descripcion,
|
||||
'numeral' => $this->numeral,
|
||||
'numeracion' => $this->numeracion ?? 0
|
||||
]);
|
||||
}
|
||||
}
|
7
app/src/Model/Role.php
Normal file
7
app/src/Model/Role.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class Role extends Model
|
||||
{}
|
16
app/src/Model/Tipo.php
Normal file
16
app/src/Model/Tipo.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
abstract class Tipo extends Ideal\Model
|
||||
{
|
||||
public string $descripcion;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'descripcion' => $this->descripcion
|
||||
]);
|
||||
}
|
||||
}
|
28
app/src/Model/User.php
Normal file
28
app/src/Model/User.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use function password_verify;
|
||||
|
||||
class User extends Ideal\Model
|
||||
{
|
||||
public string $name;
|
||||
public string $password;
|
||||
public bool $enabled;
|
||||
|
||||
public function validate(string $provided_password): bool
|
||||
{
|
||||
return password_verify($provided_password, $this->password);
|
||||
}
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'name' => $this->name
|
||||
]);
|
||||
}
|
||||
}
|
26
app/src/Model/Venta/Cierre.php
Normal file
26
app/src/Model/Venta/Cierre.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Cierre extends Ideal\Model
|
||||
{
|
||||
public Model\Proyecto $proyecto;
|
||||
public float $precio;
|
||||
public DateTimeInterface $dateTime;
|
||||
public bool $relacionado;
|
||||
public Propietario $propietario;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'proyecto_id' => $this->proyecto->id,
|
||||
'precio' => $this->precio,
|
||||
'date_time' => $this->dateTime->format('Y-m-d H:i:s'),
|
||||
'relacionado' => $this->relacionado,
|
||||
'propietario' => $this->propietario->rut
|
||||
]);
|
||||
}
|
||||
}
|
38
app/src/Model/Venta/Cuota.php
Normal file
38
app/src/Model/Venta/Cuota.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
use Incoviba\Model\Banco;
|
||||
|
||||
class Cuota extends Model
|
||||
{
|
||||
public Pie $pie;
|
||||
public DateTimeInterface $fecha;
|
||||
public float $valor;
|
||||
public ?bool $estado;
|
||||
public ?Banco $banco;
|
||||
public ?DateTimeInterface $fechaPago;
|
||||
public ?bool $abonado;
|
||||
public ?DateTimeInterface $fechaAbonado;
|
||||
public ?float $uf;
|
||||
public ?Pago $pago;
|
||||
public ?int $numero;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'pie_id' => $this->pie->id,
|
||||
'fecha' => $this->fecha->format('Y-m-d H:i:s'),
|
||||
'valor' => $this->valor,
|
||||
'estado' => $this->estado ?? false,
|
||||
'banco' => $this->banco,
|
||||
'fecha_pago' => $this->fechaPago->format('Y-m-d H:i:s') ?? '',
|
||||
'abonado' => $this->abonado ?? false,
|
||||
'fecha_abonado' => $this->fechaAbonado->format('Y-m-d H:i:s') ?? '',
|
||||
'uf' => $this->uf ?? 1,
|
||||
'pago' => $this->pago ?? '',
|
||||
'numero' => $this->numero ?? ''
|
||||
]);
|
||||
}
|
||||
}
|
27
app/src/Model/Venta/Datos.php
Normal file
27
app/src/Model/Venta/Datos.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use JsonSerializable;
|
||||
use Incoviba\Model\Direccion;
|
||||
|
||||
class Datos
|
||||
{
|
||||
public ?string $sexo;
|
||||
public ?string $estado_civil;
|
||||
public ?string $profesion;
|
||||
public ?Direccion $direccion;
|
||||
public ?int $telefono;
|
||||
public ?string $email;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'sexo' => $this->sexo ?? '',
|
||||
'estado_civil' => $this->estado_civil ?? '',
|
||||
'profesion' => $this->profesion ?? '',
|
||||
'direccion' => $this->direccion ?? '',
|
||||
'telefono' => $this->telefono ?? '',
|
||||
'email' => $this->email ?? ''
|
||||
];
|
||||
}
|
||||
}
|
22
app/src/Model/Venta/EstadoPago.php
Normal file
22
app/src/Model/Venta/EstadoPago.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class EstadoPago extends Model
|
||||
{
|
||||
public Pago $pago;
|
||||
public DateTimeInterface $fecha;
|
||||
public TipoEstadoPago $tipoEstadoPago;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'pago_id' => $this->pago->id,
|
||||
'fecha' => $this->fecha->format('Y-m-d'),
|
||||
'tipo_estado_pago_id' => $this->tipoEstadoPago->id
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
21
app/src/Model/Venta/EstadoPrecio.php
Normal file
21
app/src/Model/Venta/EstadoPrecio.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class EstadoPrecio extends Ideal\Model
|
||||
{
|
||||
public Precio $precio;
|
||||
public TipoEstadoPrecio $tipoEstadoPrecio;
|
||||
public DateTimeInterface $fecha;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'precio_id' => $this->precio->id,
|
||||
'tipo_estado_precio' => $this->tipoEstadoPrecio,
|
||||
'fecha' => $this->fecha->format('Y-m-d')
|
||||
]);
|
||||
}
|
||||
}
|
32
app/src/Model/Venta/Pago.php
Normal file
32
app/src/Model/Venta/Pago.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
use Incoviba\Model\Banco;
|
||||
|
||||
class Pago extends Model
|
||||
{
|
||||
public float $valor;
|
||||
public ?Banco $banco;
|
||||
public ?TipoPago $tipoPago;
|
||||
public ?string $identificador;
|
||||
public ?DateTimeInterface $fecha;
|
||||
public ?float $uf;
|
||||
public ?string $pagador;
|
||||
public ?Pago $asociado;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'valor' => $this->valor,
|
||||
'banco' => $this->banco ?? '',
|
||||
'tipo_pago' => $this->tipoPago ?? '',
|
||||
'identificador' => $this->identificador ?? '',
|
||||
'fecha' => $this->fecha->format('Y-m-d H:i:S') ?? '',
|
||||
'uf' => $this->uf ?? 1,
|
||||
'pagador' => $this->pagador ?? '',
|
||||
'asociado' => $this->asociado ?? ''
|
||||
]);
|
||||
}
|
||||
}
|
27
app/src/Model/Venta/Pie.php
Normal file
27
app/src/Model/Venta/Pie.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
|
||||
class Pie extends Model
|
||||
{
|
||||
public DateTimeInterface $fecha;
|
||||
public float $valor;
|
||||
public ?float $uf;
|
||||
public int $cuotas;
|
||||
public ?Pie $asociado;
|
||||
public ?Pago $reajuste;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'fecha' => $this->fecha->format('Y-m-d H:i:s'),
|
||||
'valor' => $this->valor,
|
||||
'uf' => $this->uf ?? 1,
|
||||
'cuotas' => $this->cuotas,
|
||||
'asociado' => $this->asociado ?? '',
|
||||
'reajuste' => $this->reajuste ?? ''
|
||||
]);
|
||||
}
|
||||
}
|
23
app/src/Model/Venta/Precio.php
Normal file
23
app/src/Model/Venta/Precio.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Precio extends Ideal\Model
|
||||
{
|
||||
public Unidad $unidad;
|
||||
public float $valor;
|
||||
|
||||
public array $estados;
|
||||
public EstadoPrecio $current;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'unidad' => $this->unidad,
|
||||
'valor' => $this->valor,
|
||||
'estado_precio' => $this->current ?? [],
|
||||
'estados' => $this->estados ?? null
|
||||
]);
|
||||
}
|
||||
}
|
46
app/src/Model/Venta/Propietario.php
Normal file
46
app/src/Model/Venta/Propietario.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
use Incoviba\Model\Direccion;
|
||||
|
||||
class Propietario extends Model
|
||||
{
|
||||
public int $rut;
|
||||
public string $dv;
|
||||
public string $nombres;
|
||||
public array $apellidos;
|
||||
public Datos $datos;
|
||||
public ?Propietario $representante;
|
||||
public ?bool $otro;
|
||||
|
||||
public function rut(): string
|
||||
{
|
||||
return implode('-', [
|
||||
number_format($this->rut, 0, ',', '.'),
|
||||
$this->dv
|
||||
]);
|
||||
}
|
||||
public function nombreCompleto(): string
|
||||
{
|
||||
return implode(' ', [
|
||||
$this->nombres,
|
||||
implode(' ', $this->apellidos)
|
||||
]);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge([
|
||||
'rut' => $this->rut,
|
||||
'dv' => $this->dv,
|
||||
'rut_formateado' => $this->rut(),
|
||||
'nombres' => $this->nombres,
|
||||
'apellidos' => $this->apellidos,
|
||||
'nombre_completo' => $this->nombreCompleto(),
|
||||
], $this->datos->jsonSerialize(), [
|
||||
'representante' => $this->representante ?? '',
|
||||
'otro' => $this->otro ?? ''
|
||||
]);
|
||||
}
|
||||
}
|
8
app/src/Model/Venta/TipoEstadoPago.php
Normal file
8
app/src/Model/Venta/TipoEstadoPago.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoEstadoPago extends Model\Tipo
|
||||
{
|
||||
}
|
7
app/src/Model/Venta/TipoEstadoPrecio.php
Normal file
7
app/src/Model/Venta/TipoEstadoPrecio.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Model\Tipo;
|
||||
|
||||
class TipoEstadoPrecio extends Tipo
|
||||
{}
|
8
app/src/Model/Venta/TipoPago.php
Normal file
8
app/src/Model/Venta/TipoPago.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoPago extends Model\Tipo
|
||||
{
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user