old models
This commit is contained in:
81
src/old/Venta/Precio.php
Normal file
81
src/old/Venta/Precio.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property Unidad $unidad
|
||||
* @property double $valor
|
||||
*/
|
||||
class Precio extends Model
|
||||
{
|
||||
public function unidad()
|
||||
{
|
||||
return $this->belongsTo(Unidad::class, 'unidad')->findOne();
|
||||
}
|
||||
public function estados()
|
||||
{
|
||||
return $this->hasMany(EstadoPrecio::class, 'precio')->findMany();
|
||||
}
|
||||
public function estado()
|
||||
{
|
||||
return \model(EstadoPrecio::class)
|
||||
->select('estado_precio.*')
|
||||
->rawJoin('JOIN (SELECT precio, MAX(id) AS id FROM estado_precio GROUP BY precio)', ['e0.id', '=', 'estado_precio.id'], 'e0')
|
||||
->where('estado_precio.precio', $this->id)
|
||||
->findOne();
|
||||
}
|
||||
public function inicio()
|
||||
{
|
||||
return \model(EstadoPrecio::class)
|
||||
->where('estado_precio.precio', $this->id)
|
||||
->orderByAsc('id')
|
||||
->findOne();
|
||||
}
|
||||
public function vigente()
|
||||
{
|
||||
if ($this->estado()->estado()->descripcion == 'vigente') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function reemplazar($fecha)
|
||||
{
|
||||
if ($this->estado()->estado()->descripcion == 'reemplazado') {
|
||||
return;
|
||||
}
|
||||
$tipo = model(TipoEstadoPrecio::class)->where('descripcion', 'reemplazado')->findOne();
|
||||
$data = [
|
||||
'precio' => $this->id,
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
'estado' => $tipo->id
|
||||
];
|
||||
$estado = model(EstadoPrecio::class)->create($data);
|
||||
$estado->save();
|
||||
}
|
||||
public function actualizar($fecha)
|
||||
{
|
||||
$tipo = model(TipoEstadoPrecio::class)->where('descripcion', 'vigente')->findOne();
|
||||
$data = [
|
||||
'precio' => $this->id,
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
'estado' => $tipo->id
|
||||
];
|
||||
$estado = model(EstadoPrecio::class)->create($data);
|
||||
$estado->save();
|
||||
}
|
||||
public function new($fecha)
|
||||
{
|
||||
$this->save();
|
||||
|
||||
$tipo = model(TipoEstadoPrecio::class)->where('descripcion', 'vigente')->findOne();
|
||||
$data = [
|
||||
'precio' => $this->id,
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
'estado' => $tipo->id
|
||||
];
|
||||
$estado = model(EstadoPrecio::class)->create($data);
|
||||
$estado->save();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user