API
This commit is contained in:
@ -43,4 +43,46 @@ class Venta extends Model {
|
||||
}
|
||||
return $this->activa;
|
||||
}
|
||||
protected $propietario_obj;
|
||||
public function propietario() {
|
||||
if ($this->propietario_obj === null) {
|
||||
$this->propietario_obj = $this->belongs_to(Propietario::class, 'propietario', 'rut')->find_one();
|
||||
}
|
||||
return $this->propietario_obj;
|
||||
}
|
||||
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;
|
||||
}
|
||||
protected $comision;
|
||||
public function comision() {
|
||||
if ($this->comision === null) {
|
||||
$proyecto_id = $this->propiedad()->unidades()[0]->proyecto_tipo_unidad()->proyecto()->id;
|
||||
$comision = array_values(array_filter($this->operador()->comisiones(), function($item) use ($proyecto_id) {
|
||||
return ($item->proyecto->id == $proyecto_id);
|
||||
}));
|
||||
$comision = $comision[0]->comision;
|
||||
$this->comision = (object) [
|
||||
'valor' => $comision / 100,
|
||||
'total' => $comision / 100 * $this->valor_uf
|
||||
];
|
||||
}
|
||||
return $this->comision;
|
||||
}
|
||||
|
||||
public function as_array() {
|
||||
$arr = parent::as_array();
|
||||
$arr['propietario'] = $this->propietario()->as_array();
|
||||
$arr['propiedad'] = $this->propiedad()->as_array();
|
||||
$arr['valor'] = '$ ' . number_format($this->valor_uf, 2, ',', '.');
|
||||
if ($this->operador()) {
|
||||
$arr['operador'] = $this->operador()->as_array();
|
||||
$arr['comision'] = (array) $this->comision();
|
||||
$arr['comision']['formateada'] = '$ ' . number_format($this->comision()->total, 2, ',', '.');
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user