145 lines
4.3 KiB
PHP
145 lines
4.3 KiB
PHP
<?php
|
|
namespace Incoviba\Venta;
|
|
|
|
use DateTime;
|
|
use Incoviba\API\Common\Alias\Model;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property Propietario $propietario
|
|
* @property Propiedad $propiedad
|
|
* @property ?Pie $pie
|
|
* @property ?BonoPie $bono_pie
|
|
* @property ?Credito $credito
|
|
* @property ?Escritura $escritura
|
|
* @property ?Subsidio $subsidio
|
|
* @property ?DateTime $escriturado
|
|
* @property ?Entrega $entrega
|
|
* @property ?DateTime $entregado
|
|
* @property DateTime $fecha
|
|
* @property double $valor_uf
|
|
* @property int $estado
|
|
* @property ?DateTime $fecha_entrega
|
|
* @property int $avalchile
|
|
* @property Agente $agente
|
|
* @property double $uf
|
|
* @property int $relacionado
|
|
* @property ?Promocion $promocion
|
|
* @property ?Resciliacion $resciliacion
|
|
* @property ?Pago $devolucion
|
|
*/
|
|
class Venta extends Model {
|
|
public static $_table = 'venta';
|
|
protected static $field = ['propietario', 'propiedad', 'pie', 'bono_pie', 'credito', 'escritura', 'subsidio',
|
|
'escriturado', 'entrega', 'entregado', 'fecha', 'valor_uf', 'estado', 'fecha_entrega', 'avalchile', 'agente', 'uf',
|
|
'relacionado', 'promocion', 'resciliacion', 'devolucion'];
|
|
|
|
protected $propietario_o;
|
|
public function propietario() {
|
|
if ($this->propietario_o === null) {
|
|
$this->propietario_o = $this->childOf(Propietario::class, [Model::SELF_KEY => 'propietario', Model::PARENT_KEY => 'rut']);
|
|
}
|
|
return $this->propietario_o;
|
|
}
|
|
protected $propiedad_o;
|
|
public function propiedad() {
|
|
if ($this->propiedad_o === null) {
|
|
$this->propiedad_o = $this->childOf(Propiedad::class, [Model::SELF_KEY => 'propiedad']);
|
|
}
|
|
return $this->propiedad_o;
|
|
}
|
|
protected $pie_o;
|
|
public function pie() {
|
|
if($this->pie_o === null) {
|
|
$this->pie_o = $this->childOf(Pie::class, [Model::SELF_KEY => 'pie']);
|
|
}
|
|
return $this->pie_o;
|
|
}
|
|
protected $bono;
|
|
public function bono() {
|
|
if ($this->bono === null) {
|
|
$this->bono = $this->childOf(BonoPie::class, [Model::SELF_KEY => 'bono_pie']);
|
|
}
|
|
return $this->bono;
|
|
}
|
|
protected $credito_o;
|
|
public function credito() {
|
|
if ($this->credito_o === null) {
|
|
$this->credito_o = $this->childOf(Credito::class, [Model::SELF_KEY => 'credito']);
|
|
}
|
|
return $this->credito_o;
|
|
}
|
|
protected $escritura_o;
|
|
public function escritura() {
|
|
if ($this->escritura_o === null) {
|
|
$this->escritura_o = $this->childOf(Escritura::class, [Model::SELF_KEY => 'escritura']);
|
|
}
|
|
return $this->escritura_o;
|
|
}
|
|
protected $subsidio_o;
|
|
public function subsidio() {
|
|
if ($this->subsidio_o === null) {
|
|
$this->subsidio_o = $this->childOf(Subsidio::class, [Model::SELF_KEY => 'subsidio']);
|
|
}
|
|
return $this->subsidio_o;
|
|
}
|
|
protected $entrega_o;
|
|
public function entrega() {
|
|
if ($this->entrega_o === null) {
|
|
$this->entrega_o = $this->childOf(Entrega::class, [Model::SELF_KEY => 'entrega']);
|
|
}
|
|
return $this->entrega_o;
|
|
}
|
|
protected $pa;
|
|
public function proyectoAgente() {
|
|
if ($this->pa === null) {
|
|
$this->pa = $this->childOf(ProyectoAgente::class, [Model::SELF_KEY => 'agente']);
|
|
}
|
|
return $this->pa;
|
|
}
|
|
protected $promocion_o;
|
|
public function promocion() {
|
|
if ($this->promocion_o === null) {
|
|
$this->promocion_o = $this->childOf(Promocion::class, [Model::SELF_KEY => 'promocion']);
|
|
}
|
|
return $this->promocion_o;
|
|
}
|
|
protected $resciliacion_o;
|
|
public function resciliacion() {
|
|
if ($this->resciliacion_o === null) {
|
|
$this->resciliacion_o = $this->childOf(Resciliacion::class, [Model::SELF_KEY => 'resciliacion']);
|
|
}
|
|
return $this->resciliacion_o;
|
|
}
|
|
protected $devolucion_o;
|
|
public function devolucion() {
|
|
if ($this->devolucion_o === null) {
|
|
$this->devolucion_o = $this->childOf(Pago::class, [Model::SELF_KEY => 'devolucion']);
|
|
}
|
|
return $this->devolucion_o;
|
|
}
|
|
|
|
protected $estados;
|
|
public function estados() {
|
|
if ($this->estados === null) {
|
|
$this->estados = $this->parentOf(EstadoVenta::class, [Model::CHILD_KEY => 'venta']);
|
|
}
|
|
return $this->estados;
|
|
}
|
|
protected $estado;
|
|
public function estado() {
|
|
if ($this->estado === null) {
|
|
$estados = $this->estados();
|
|
usort($estados, function ($a, $b) {
|
|
$f = $b->fecha - $a->fecha;
|
|
if ($f == 0) {
|
|
return $b->id - $a->id;
|
|
}
|
|
return $f;
|
|
});
|
|
$this->estado = $estados[0];
|
|
}
|
|
return $this->estado;
|
|
}
|
|
}
|