Nuevo models

This commit is contained in:
2019-12-23 18:01:36 -03:00
parent f67ab72e2a
commit eeb725200a
67 changed files with 2171 additions and 0 deletions

View 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';
}
}