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

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;
}
}