47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
namespace Incoviba\nuevo\Venta;
|
|
|
|
use App\Alias\NewModel;
|
|
use App\Definition\hasEstado;
|
|
|
|
/**
|
|
*
|
|
* @author Aldarien
|
|
* @property int id
|
|
* @property Venta venta_id
|
|
*
|
|
*/
|
|
class Entrega extends NewModel
|
|
{
|
|
use hasEstado;
|
|
|
|
protected static $_table = 'entregas';
|
|
|
|
public function venta()
|
|
{
|
|
return $this->belongs_to(Venta::class, 'venta_id')->findOne();
|
|
}
|
|
|
|
public function fondos()
|
|
{
|
|
return $this->has_many_through(Pago::class, FondoEntrega::class, 'entrega_id', 'pago_id')->findMany();
|
|
}
|
|
public function mediciones()
|
|
{
|
|
return $this->has_many_through(Medicion::class, MedicionEntrega::class, 'entrega_id', 'medicion_id')->findMany();
|
|
}
|
|
public function observaciones()
|
|
{
|
|
return $this->has_many_through(Observacion::class, EntregaObservacion::class, 'entrega_id', 'observacion_id')->findMany();
|
|
}
|
|
public function observacionesPendientes()
|
|
{
|
|
return $this->has_many_through(Observacion::class, EntregaObservacion::class, 'entrega_id', 'observacion_id')
|
|
->select('observaciones.*')
|
|
->rawJoin('JOIN (SELECT e1.* FROM (SELECT MAX(id) AS id, observacion_id FROM estado_observaciones GROUP BY observacion_id) e0 JOIN estado_observaciones e1 ON e1.id = e0.id)', ['ep.observacion_id', '=', 'observaciones.id'], 'ep')
|
|
->leftOuterJoin('tipo_estado_observaciones', ['tipo_estado_observaciones.id', '=', 'ep.tipo_estado_observacion_id'])
|
|
->where('tipo_estado_observaciones.descripcion', 'ingresada')
|
|
->findMany();
|
|
}
|
|
}
|
|
?>
|