Nuevo models
This commit is contained in:
71
src/nuevo/Venta/Propietario.php
Normal file
71
src/nuevo/Venta/Propietario.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\nuevo\Common\Direccion;
|
||||
use Incoviba\Common\Definition\hasRUT;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property string nombres
|
||||
* @property string apellido_paterno
|
||||
* @property string apellido_materno
|
||||
* @property int direccion_id
|
||||
* @property int telefono
|
||||
* @property Propietario representante_rut
|
||||
* @property Propietario otro_rut
|
||||
*
|
||||
*/
|
||||
class Propietario extends NewModel
|
||||
{
|
||||
use hasRUT;
|
||||
|
||||
protected static $_table = 'propietarios';
|
||||
|
||||
public function direccion()
|
||||
{
|
||||
return $this->belongsTo(Direccion::class, 'direccion_id')->findOne();
|
||||
}
|
||||
public function representante()
|
||||
{
|
||||
$prop = $this->belongsTo(Propietario::class, 'representante_rut', 'rut');
|
||||
if ($prop) {
|
||||
return $prop->findOne();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function otro()
|
||||
{
|
||||
$prop = $this->belongsTo(Propietario::class, 'otro_rut', 'rut');
|
||||
if ($prop) {
|
||||
return $prop->findOne();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function nombreCompleto()
|
||||
{
|
||||
return implode(' ', [$this->nombres, $this->apellido_paterno, $this->apellido_materno]);
|
||||
}
|
||||
|
||||
public function represntado()
|
||||
{
|
||||
$prop = $this->has_many(Propietario::class, 'representante_rut', 'rut');
|
||||
if ($prop) {
|
||||
return $prop->findOne();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function ventas()
|
||||
{
|
||||
return $this->hasMany(Venta::class, 'propietario_rut', 'rut')->findMany();
|
||||
}
|
||||
public function articulo()
|
||||
{
|
||||
if ($this->sexo == 'f') {
|
||||
return 'la';
|
||||
}
|
||||
return 'el';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user