API
This commit is contained in:
46
api/src/Venta.php
Normal file
46
api/src/Venta.php
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user