config
This commit is contained in:
104
app_old/incoviba/modelos/src/nuevo/Venta/Venta.php
Normal file
104
app_old/incoviba/modelos/src/nuevo/Venta/Venta.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\nuevo\Inmobiliaria\Agente;
|
||||
use Incoviba\Common\Definition\hasEstado;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Propietario propietario_rut
|
||||
* @property Propiedad propiedad_id
|
||||
* @property FormaPago forma_pago_id
|
||||
* @property Date fecha_promesa
|
||||
* @property double valor_promesa
|
||||
* @property double uf
|
||||
* @property boolean relacionado
|
||||
* @property Agente agente_id
|
||||
* @property DateTime created_at
|
||||
* @property DateTime updated_at
|
||||
*
|
||||
*/
|
||||
class Venta extends NewModel
|
||||
{
|
||||
use hasEstado;
|
||||
|
||||
protected static $_table = 'ventas';
|
||||
|
||||
public function propietario()
|
||||
{
|
||||
return $this->belongs_to(Propietario::class, 'propietario_rut', 'rut')->findOne();
|
||||
}
|
||||
public function propiedad()
|
||||
{
|
||||
return $this->belongs_to(Propiedad::class, 'propiedad_id')->findOne();
|
||||
}
|
||||
public function formaPago()
|
||||
{
|
||||
return $this->belongs_to(FormaPago::class, 'forma_pago_id')->findOne();
|
||||
}
|
||||
public function agente()
|
||||
{
|
||||
$agente = $this->belongs_to(Agente::class, 'agente_id');
|
||||
if ($agente) {
|
||||
return $agente->findOne();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function valor()
|
||||
{
|
||||
return $this->valor_promesa * $this->uf;
|
||||
}
|
||||
public function proyecto()
|
||||
{
|
||||
return $this->propiedad->unidadPrincipal->unidadProyecto->proyecto();
|
||||
}
|
||||
public function comision()
|
||||
{
|
||||
return $this->agente->comision($this->proyecto->inmobiliaria->rut);
|
||||
}
|
||||
public function ufM2()
|
||||
{
|
||||
if (!$this->agente) {
|
||||
return 0;
|
||||
}
|
||||
return ($this->valor_promesa - $this->premios->sum('valor') - $this->comision() - $this->propiedad->unidades->sum('valor')) / $this->propiedad->unidadPrincipal->unidadProyecto->m2->vendibles();
|
||||
}
|
||||
public function fechaPromesa()
|
||||
{
|
||||
return Carbon::parse($this->fecha_promesa, config('app.timezone'));
|
||||
}
|
||||
|
||||
public function premios()
|
||||
{
|
||||
$premios = $this->has_many(Premio::class, 'venta_id');
|
||||
if ($premios) {
|
||||
return $premios->findMany();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
public function comentarios()
|
||||
{
|
||||
$comentarios = $this->has_many(Comentario::class, 'venta_id');
|
||||
if ($comentarios) {
|
||||
return $comentarios->findMany();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
public function fondos()
|
||||
{
|
||||
return $this->has_many(FondoVenta::class, 'venta_id')->findMany();
|
||||
}
|
||||
public function postventas()
|
||||
{
|
||||
$postventas = $this->has_many(Postventa::class, 'venta_id');
|
||||
if ($postventas) {
|
||||
return $postventas->findMany();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user