67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
<?php
|
|
namespace Incoviba\old\Venta;
|
|
|
|
use Incoviba\Common\Alias\OldModel as Model;
|
|
use Incoviba\old\Common\Direccion;
|
|
use Incoviba\nuevo\Venta\Propietario as P;
|
|
|
|
/**
|
|
*
|
|
* @property int $rut
|
|
* @property char $dv
|
|
* @property string $nombres
|
|
* @property string $apellido_paterno
|
|
* @property string $apellido_materno
|
|
* @property string $sexo
|
|
* @property string $estado_civil
|
|
* @property string $profesion
|
|
* @property Direccion $direccion
|
|
* @property int $telefono
|
|
* @property string $email
|
|
* @property int $representante
|
|
* @property int $otro
|
|
*
|
|
*/
|
|
class Propietario extends Model
|
|
{
|
|
public static $_id_column = 'rut';
|
|
|
|
public function direccion()
|
|
{
|
|
return $this->belongs_to(Direccion::class, 'direccion')->findOne();
|
|
}
|
|
public function nombreCompleto($ap = false)
|
|
{
|
|
$str = '';
|
|
if ($ap) {
|
|
$str = $this->apellido_paterno . ' ' . $this->apellido_materno . ', ' . $this->nombres;
|
|
} else {
|
|
$str = $this->nombres . ' ' . $this->apellido_paterno . ' ' . $this->apellido_materno;
|
|
}
|
|
return $str;
|
|
}
|
|
public function representante()
|
|
{
|
|
$r = $this->belongsTo(Propietario::class, 'representante', 'rut');
|
|
if ($r) {
|
|
return $r->findOne();
|
|
}
|
|
return null;
|
|
}
|
|
public function ventas() {
|
|
return $this->hasMany(Venta::class, 'propietario', 'rut')
|
|
->select('venta.*')
|
|
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
|
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
|
->join('proyecto', ['proyecto.id', '=', 'unidad.proyecto'])
|
|
->orderByAsc('proyecto.descripcion')
|
|
->orderByExpr("LPAD(unidad.descripcion, 4, '0')")
|
|
->findMany();
|
|
}
|
|
public function rut()
|
|
{
|
|
return format('rut', $this->rut) . '-' . $this->dv;
|
|
}
|
|
}
|
|
?>
|