This commit is contained in:
2021-08-10 15:48:33 -04:00
parent a1519752cd
commit 2d4f48f3a9
39 changed files with 864 additions and 0 deletions

3
api/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Composer
**/vendor/
**/composer.lock

5
api/PHP.Dockerfile Normal file
View File

@ -0,0 +1,5 @@
FROM php:7.4-fpm
RUN docker-php-ext-install pdo pdo_mysql
WORKDIR /app

View File

@ -0,0 +1,14 @@
<?php
namespace Incoviba\Common\Controller;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Incoviba\Common\Define\Controller\Json;
class Base {
use Json;
public function __invoke(Request $request, Response $response): Response {
return $this->withJson($response, []);
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace Incoviba\Common\Controller;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use \Model;
use Incoviba\Common\Define\Controller\Json;
use Incoviba\Operador;
use Incoviba\TipoAgente;
class Operadores {
use Json;
public function __invoke(Request $request, Response $response): Response {
$tipo = Model::factory(TipoAgente::class)->where('descripcion', 'operador')->find_one();
$ids = array_map(function($item) {
return $item->agente;
}, $tipo->agente_tipos());
$operadores = [];
foreach ($ids as $id) {
$operadores []= Model::factory(Operador::class)->find_one($id);
}
usort($operadores, function($a, $b) {
return strcmp($a->abreviacion, $b->abreviacion);
});
array_walk($operadores, function(&$item) {
$item = $item->as_array();
});
$output = compact('operadores');
return $this->withJson($response, $output);
}
public function show(Request $request, Response $response, $id_operador): Response {
$operador = Model::factory(Operador::class)->find_one($id_operador);
$output = ['operador' => $operador->as_array()];
return $this->withJson($response, $output);
}
public function add(Request $request, Response $response): Response {
$post = $request->getParsedBody();
$output = Operador::add($post);
return $this->withJson($response, $output);
}
public function ventas(Request $request, Response $response, $id_operador): Response {
$operador = Model::factory(Operador::class)->find_one($id_operador);
$output = [
'operador' => $operador->as_array(),
'ventas' => array_map(function($item) {
return $item->as_array();
}, $operador->ventas())
];
return $this->withJson($response, $output);
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace Incoviba\Common\Controller;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use \Model;
use Incoviba\Common\Define\Controller\Json;
use Incoviba\Proyecto;
class Proyectos {
use Json;
public function __invoke(Request $request, Response $response): Response {
$proyectos = Model::factory(Proyecto::class)->order_by_asc('descripcion')->find_many();
array_walk($proyectos, function(&$item) {
$item = $item->as_array();
});
$output = compact('proyectos');
return $this->withJson($response, $output);
}
public function show(Request $request, Response $response, $id_proyecto): Response {
$proyecto = Model::factory(Proyecto::class)->find_one($id_proyecto);
$output = ['proyecto' => $proyecto->as_array()];
return $this->withJson($response, $output);
}
public function ventas(Request $request, Response $response, $id_proyecto): Response {
$proyecto = Model::factory(Proyecto::class)->find_one($id_proyecto);
$output = [
'proyecto' => $proyecto->as_array(),
'ventas' => array_map(function($item) {
if ($item) {
return $item->as_array();
}
}, $proyecto->ventas())
];
return $this->withJson($response, $output);
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace Incoviba\Common\Controller;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use \Model;
use Incoviba\Common\Define\Controller\Json;
use Incoviba\Venta;
class Ventas {
use Json;
public function __invoke(Request $request, Response $response): Response {
$ventas = Model::factory(Venta::class)->find_array();
$output = compact('ventas');
return $this->withJson($response, $output);
}
public function show(Request $request, Response $response, $id_venta): Response {
$venta = Model::factory(Venta::class)->find_one($id_venta);
$output = ['venta' => $venta->as_array()];
return $this->withJson($response, $output);
}
public function operador(Request $request, Response $response, $id_venta): Response {
$venta = Model::factory(Venta::class)->find_one($id_venta);
$output = [
'venta' => $venta->as_array(),
'operador' => $venta->operador() ? $venta->operador()->as_array() : null
];
return $this->withJson($response, $output);
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace Incoviba\Common\Define\Controller;
use Psr\Http\Message\ResponseInterface as Response;
trait Json {
public function withJson(Response $response, $data, int $status = 200): Response {
$response->getBody()->write(json_encode($data));
return $response
->withHeader('Content-Type', 'application/json')
->withStatus($status);
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Incoviba\Common\Middleware;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as Handler;
use Psr\Http\Message\ResponseInterface as Response;
use Slim\Routing\RouteContext;
class Cors {
public function __invoke(Request $request, Handler $handler): Response {
$routeContext = RouteContext::fromRequest($request);
$routingResults = $routeContext->getRoutingResults();
$methods = $routingResults->getAllowedMethods();
$requestHeaders = $request->getHeaderLine('Access-Control-Request-Headers');
$response = $handler->handle($request);
$response = $response->withHeader('Access-Control-Allow-Origin', '*');
$response = $response->withHeader('Access-Control-Allow-Methods', implode(',', $methods));
$response = $response->withHeader('Access-Control-Allow-Headers', $requestHeaders);
return $response;
}
}

28
api/composer.json Normal file
View File

@ -0,0 +1,28 @@
{
"name": "incoviba/operadores",
"description": "Modulo de Operadores para Incoviba",
"type": "project",
"require": {
"php-di/slim-bridge": "^3.1",
"nyholm/psr7": "^1.4",
"nyholm/psr7-server": "^1.0",
"zeuxisoo/slim-whoops": "^0.7.3",
"j4mie/paris": "^1.5"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"kint-php/kint": "^3.3"
},
"autoload": {
"psr-4": {
"Incoviba\\Common\\": "common/",
"Incoviba\\": "src/"
}
},
"authors": [
{
"name": "Aldarien",
"email": "aldarien85@gmail.com"
}
]
}

27
api/nginx.conf Normal file
View File

@ -0,0 +1,27 @@
server {
listen 80;
index index.php index.html index.htm;
# server_name php-docker.local;
# error_log /var/log/nginx/error.log;
# access_log /var/log/nginx/access.log;
root /app/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass backend:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}

26
api/phpunit.xml Normal file
View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>

7
api/public/index.php Normal file
View File

@ -0,0 +1,7 @@
<?php
require_once implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__),
'setup',
'app.php'
]);
$app->run();

View File

@ -0,0 +1,13 @@
<?php
use Incoviba\Common\Controller\Operadores;
$app->group('/operadores', function($app) {
$app->post('/add[/]', [Operadores::class, 'add']);
$app->get('[/]', Operadores::class);
});
$app->group('/operador/{id_operador}', function($app) {
$app->group('/ventas', function($app) {
$app->get('[/]', [Operadores::class, 'ventas']);
});
$app->get('[/]', [Operadores::class, 'show']);
});

View File

@ -0,0 +1,12 @@
<?php
use Incoviba\Common\Controller\Proyectos;
$app->group('/proyectos', function($app) {
$app->get('[/]', Proyectos::class);
});
$app->group('/proyecto/{id_proyecto}', function($app) {
$app->group('/ventas', function($app) {
$app->get('[/]', [Proyectos::class, 'ventas']);
});
$app->get('[/]', [Proyectos::class, 'show']);
});

View File

@ -0,0 +1,12 @@
<?php
use Incoviba\Common\Controller\Ventas;
$app->group('/ventas', function($app) {
$app->get('[/]', Ventas::class);
});
$app->group('/venta/{id_venta}', function($app) {
$app->group('/operador', function($app) {
$app->get('[/]', [Ventas::class, 'operador']);
});
$app->get('[/]', [Ventas::class, 'show']);
});

View File

@ -0,0 +1,4 @@
<?php
use Incoviba\Common\Controller\Base;
$app->get('[/]', Base::class);

44
api/setup/app.php Normal file
View File

@ -0,0 +1,44 @@
<?php
use DI\ContainerBuilder as Builder;
use DI\Bridge\Slim\Bridge;
include_once 'composer.php';
$builder = new Builder();
$folders = [
'settings',
'setups'
];
foreach ($folders as $folder) {
$name = implode(DIRECTORY_SEPARATOR, [__DIR__, $folder]);
if (!file_exists($name)) {
continue;
}
$files = new DirectoryIterator($name);
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
$builder->addDefinitions($file->getRealPath());
}
}
$container = $builder->build();
#!d($container->getKnownEntryNames());
$app = Bridge::create($container);
$app->addBodyParsingMiddleware();
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'middlewares']);
if (file_exists($folder)) {
$files = new DirectoryIterator($folder);
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
include_once $file->getRealPath();
}
}
include_once 'databases.php';
include_once 'router.php';

6
api/setup/composer.php Normal file
View File

@ -0,0 +1,6 @@
<?php
require_once implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__),
'vendor',
'autoload.php'
]);

30
api/setup/databases.php Normal file
View File

@ -0,0 +1,30 @@
<?php
$databases = $app->getContainer()->get('databases');
foreach ($databases->databases as $name => $settings) {
switch ($settings->engine) {
case 'mysql': {
$dsn = ["mysql:host={$settings->host->name}"];
if (isset($settings->host->port)) {
$dsn []= "port={$settings->host->port}";
}
$dsn []= "dbname={$settings->name}";
$dsn = implode(';', $dsn);
$config = [
'connection_string' => $dsn,
'username' => $settings->user->name,
'password' => $settings->user->password
];
Model::configure($config, null, $name);
Model::set_db(new PDO($dsn, $settings->user->name, $settings->user->password), $name);
break;
}
case 'sqlite': {
$dsn = "sqlite:{$settings->database}";
Model::configure($dsn, null, $name);
break;
}
}
}
if (isset($databases->short_names) and $databases->short_names) {
Model::$short_table_names = true;
}

View File

@ -0,0 +1,3 @@
<?php
$app->add(new Incoviba\Common\Middleware\Cors());
$app->addRoutingMiddleware();

View File

@ -0,0 +1,2 @@
<?php
$app->add(new Zeuxisoo\Whoops\Slim\WhoopsMiddleware());

9
api/setup/router.php Normal file
View File

@ -0,0 +1,9 @@
<?php
$folder = $app->getContainer()->get('folders')->routes;
$files = new DirectoryIterator($folder);
foreach ($files as $file) {
if ($file->isDir() or $file->getExtension() !== 'php') {
continue;
}
include_once $file->getRealPath();
}

View File

@ -0,0 +1,34 @@
<?php
return [
'databases' => function() {
$arr = [
'databases' => [
ORM::DEFAULT_CONNECTION => (object) [
'engine' => 'mysql',
'name' => $_ENV['MYSQL_DATABASE'],
'host' => (object) [
'name' => 'db'
],
'user' => (object) [
'name' => $_ENV['MYSQL_USER'],
'password' => $_ENV['MYSQL_PASSWORD']
]
]
],
'short_names' => true
];
return (object) $arr;
},
'folders' => function() {
$arr = ['base' => dirname(__DIR__, 2)];
$arr['resources'] = implode(DIRECTORY_SEPARATOR, [
$arr['base'],
'resources'
]);
$arr['routes'] = implode(DIRECTORY_SEPARATOR, [
$arr['resources'],
'routes'
]);
return (object) $arr;
}
];

16
api/src/Agente.php Normal file
View File

@ -0,0 +1,16 @@
<?php
namespace Incoviba;
use \Model;
class Agente extends Model {
public static $_table = 'agente';
protected $agente_tipos;
public function agente_tipos() {
if ($this->agente_tipos === null) {
$this->agente_tipos = $this->has_many(AgenteTipo::class, 'agente')->find_many();
}
return $this->agente_tipos;
}
}

30
api/src/AgenteTipo.php Normal file
View File

@ -0,0 +1,30 @@
<?php
namespace Incoviba;
use \Model;
class AgenteTipo extends Model {
public static $_table = 'agente_tipo';
protected $proyecto_agentes;
public function proyecto_agentes() {
if ($this->proyecto_agentes === null) {
$this->proyecto_agentes = $this->has_many(ProyectoAgente::class, 'agente')->find_many();
}
return $this->proyecto_agentes;
}
protected $agente_obj;
public function agente() {
if ($this->agente_obj === null) {
$this->agente_obj = $this->belongs_to(Agente::class, 'agente')->find_one();
}
return $this->agente_obj;
}
protected $tipo_obj;
public function tipo() {
if ($this->tipo_obj === null) {
$this->tipo_obj = $this->belongs_to(TipoAgente::class, 'tipo')->find_one();
}
return $this->tipo_obj;
}
}

23
api/src/EstadoVenta.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace Incoviba;
use \Model;
class EstadoVenta extends Model {
public static $_table = 'estado_venta';
protected $tipo;
public function tipo() {
if ($this->tipo === null) {
$this->tipo = $this->belongs_to(TipoEstadoVenta::class, 'estado')->find_one();
}
return $this->tipo;
}
protected $venta_obj;
public function venta() {
if ($this->venta_obj === null) {
$this->venta_obj = $this->belongs_to(Venta::class, 'venta')->find_one();
}
return $this->venta_obj;
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Incoviba;
use \Model;
/**
* @property int $id
* @property Operador $operador_id
* @property int $factura
* @property int $valor_neto
* @property int $iva
* @property int $valor_total
*/
class FacturaOperador extends Model {
public static $_table = 'factura_operador';
protected $operador;
public function operador() {
if ($this->operador === null) {
$this->operador = $this->belongs_to(Operador::class, 'operador_id')->find_one();
}
return $this->operador;
}
}

29
api/src/FacturaUnidad.php Normal file
View File

@ -0,0 +1,29 @@
<?php
namespace Incoviba;
use \Model;
/**
* @property int $id
* @property FacturaOperador $factura_id
* @property Unidad $unidad_id
* @property double $valor
*/
class FacturaUnidad extends Model {
public static $_table = 'factura_unidad';
protected $factura;
public function factura() {
if ($this->factura === null) {
$this->factura = $this->belongs_to(FacturaOperador::class, 'factura_id')->find_one();
}
return $this->factura;
}
protected $unidad;
public function unidad() {
if ($this->unidad === null) {
$this->unidad = $this->belongs_to(Unidad::class, 'unidad_id')->find_one();
}
return $this->unidad;
}
}

8
api/src/Inmobiliaria.php Normal file
View File

@ -0,0 +1,8 @@
<?php
namespace Incoviba;
use \Model;
class Inmobiliaria extends Model {
public static $_table = 'inmobiliaria';
}

84
api/src/Operador.php Normal file
View File

@ -0,0 +1,84 @@
<?php
namespace Incoviba;
use \Model;
class Operador extends Agente {
protected $venta;
public function ventas() {
if ($this->ventas === null) {
$ventas = [];
foreach ($this->agente_tipos() as $at) {
foreach ($at->proyecto_agentes() as $pa) {
$ventas = array_merge($ventas, $pa->ventas());
}
}
$this->ventas = $ventas;
}
return $this->ventas;
}
protected $comisiones;
public function comisiones() {
if ($this->comisiones === null) {
$comisiones = [];
foreach ($this->agente_tipos() as $at) {
foreach ($at->proyecto_agentes() as $pa) {
$comisiones []= (object) ['proyecto' => (object) $pa->proyecto()->as_array(), 'comision' => $pa->comision];
}
}
$this->comisiones = $comisiones;
}
return $this->comisiones;
}
public static function add($data) {
$fields = [
'rut',
'descripcion',
'abreviacion',
'representante',
'telefono',
'correo'
];
$input = array_intersect_key($data, array_combine($fields, $fields));
$tipo = Model::factory(TipoAgente::class)->where('descripcion', 'operador')->find_one();
$input['tipo'] = $tipo->id;
$validate = [
'rut',
'descripcion',
'abreviacion'
];
$found = false;
foreach ($validate as $val) {
$operador = Model::factory(Operador::class)->where($val, $input[$val])->find_one();
if ($operador) {
$found = true;
break;
}
}
$created = false;
if (!$found) {
$operador = Operador::create($input);
$created = $operador->save();
$input = [
'agente' => $operador->id,
'tipo' => $tipo->id
];
$at = AgenteTipo::create($input);
$at->save();
}
$output = [
'input' => $data,
'operador' => $operador->as_array(),
'new' => $found,
'created' => $created
];
return $output;
}
public function as_array() {
$arr = parent::as_array();
$arr['comisiones'] = $this->comisiones();
return $arr;
}
}

16
api/src/Propiedad.php Normal file
View File

@ -0,0 +1,16 @@
<?php
namespace Incoviba;
use \Model;
class Propiedad extends Model {
public static $_table = 'propiedad';
protected $venta;
public function venta() {
if ($this->venta === null) {
$this->venta = $this->has_one(Venta::class, 'propiedad')->find_one();
}
return $this->venta;
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace Incoviba;
use \Model;
class PropiedadUnidad extends Model {
public static $_table = 'propiedad_unidad';
protected $propiedad_obj;
public function propiedad() {
if ($this->propiedad_obj === null) {
$this->propiedad_obj = $this->belongs_to(Propiedad::class, 'propiedad')->find_one();
}
return $this->propiedad_obj;
}
}

49
api/src/Proyecto.php Normal file
View File

@ -0,0 +1,49 @@
<?php
namespace Incoviba;
use \Model;
class Proyecto extends Model {
public static $_table = 'proyecto';
protected $inmobiliaria_obj;
public function inmobiliaria() {
if ($this->inmobiliaria_obj === null) {
$this->inmobiliaria_obj = $this->belongs_to(Inmobiliaria::class, 'inmobiliaria', 'rut')->find_one();
}
return $this->inmobiliaria_obj;
}
protected $ventas;
public function ventas() {
if ($this->ventas === null) {
$ventas = [];
foreach ($this->proyecto_tipo_unidades() as $pu) {
foreach ($pu->unidades() as $u) {
if (!$u->propiedad_unidad() or $u->propiedad_unidad()->principal != 1 or !$u->propiedad_unidad()->propiedad() or !$u->propiedad_unidad()->propiedad()->venta()) {
continue;
}
$ventas = array_merge($ventas, [$u->propiedad_unidad()->propiedad()->venta()]);
}
}
$ventas = array_filter($ventas, function($item) {
return ($item->activa());
});
$this->ventas = $ventas;
}
return $this->ventas;
}
protected $proyecto_tipo_unidades;
public function proyecto_tipo_unidades() {
if ($this->proyecto_tipo_unidades === null) {
$this->proyecto_tipo_unidades = $this->has_many(ProyectoTipoUnidad::class, 'proyecto')->find_many();
}
return $this->proyecto_tipo_unidades;
}
public function as_array() {
$arr = parent::as_array();
$arr['inmobiliaria'] = $this->inmobiliaria()->as_array();
return $arr;
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace Incoviba;
use \Model;
class ProyectoAgente extends Model {
public static $_table = 'proyecto_agente';
protected $ventas;
public function ventas() {
if ($this->ventas === null) {
$this->ventas = $this->has_many(Venta::class, 'agente')->find_many();
}
return $this->ventas;
}
protected $agente_tipo;
public function agente_tipo() {
if ($this->agente_tipo === null) {
$this->agente_tipo = $this->belongs_to(AgenteTipo::class, 'agente')->find_one();
}
return $this->agente_tipo;
}
protected $proyecto_obj;
public function proyecto() {
if ($this->proyecto_obj === null) {
$this->proyecto_obj = $this->belongs_to(Proyecto::class, 'proyecto')->find_one();
}
return $this->proyecto_obj;
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace Incoviba;
use \Model;
class ProyectoTipoUnidad extends Model {
public static $_table = 'proyecto_tipo_unidad';
protected $unidades;
public function unidades() {
if ($this->unidades === null) {
$this->unidades = $this->has_many(Unidad::class, 'pt')->find_many();
}
return $this->unidades;
}
}

16
api/src/TipoAgente.php Normal file
View File

@ -0,0 +1,16 @@
<?php
namespace Incoviba;
use \Model;
class TipoAgente extends Model {
public static $_table = 'tipo_agente';
protected $agente_tipos;
public function agente_tipos() {
if ($this->agente_tipos === null) {
$this->agente_tipos = $this->has_many(AgenteTipo::class, 'tipo')->find_many();
}
return $this->agente_tipos;
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace Incoviba;
use \Model;
class TipoEstadoVenta extends Model {
public static $_table = 'tipo_estado_venta';
}

16
api/src/Unidad.php Normal file
View File

@ -0,0 +1,16 @@
<?php
namespace Incoviba;
use \Model;
class Unidad extends Model {
public static $_table = 'unidad';
protected $propiedad_unidad;
public function propiedad_unidad() {
if ($this->propiedad_unidad === null) {
$this->propiedad_unidad = $this->has_one(PropiedadUnidad::class, 'unidad')->find_one();
}
return $this->propiedad_unidad;
}
}

46
api/src/Venta.php Normal file
View File

@ -0,0 +1,46 @@
<?php
namespace Incoviba;
use \Model;
class Venta extends Model {
public static $_table = 'venta';
protected $operador;
public function operador() {
if ($this->operador === null) {
$pa = $this->proyecto_agente();
if ($pa) {
$id = $this->proyecto_agente()->agente_tipo()->agente()->id;
$this->operador = Model::factory(Operador::class)->find_one($id);
}
}
return $this->operador;
}
protected $proyecto_agente;
public function proyecto_agente() {
if ($this->proyecto_agente === null) {
$this->proyecto_agente = $this->belongs_to(ProyectoAgente::class, 'agente')->find_one();
}
return $this->proyecto_agente;
}
protected $estados;
public function estados() {
if ($this->estados === null) {
$this->estados = $this->has_many(EstadoVenta::class, 'venta')->order_by_asc('fecha', 'id')->find_many();
}
return $this->estados;
}
protected $activa;
public function activa() {
if ($this->activa === null) {
$this->activa = false;
foreach ($this->estados() as $estado) {
if ($estado->tipo()->activa == 1) {
$this->activa = true;
}
}
}
return $this->activa;
}
}