2021-12-30 13:12:14 -03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2022-01-05 18:14:21 -03:00
|
|
|
use Illuminate\Http\Request;
|
2022-01-07 18:02:48 -03:00
|
|
|
use App\Filtros\FiltroDeProducto;
|
2024-09-05 13:34:33 -03:00
|
|
|
use Illuminate\Support\Str;
|
2021-12-30 13:12:14 -03:00
|
|
|
|
|
|
|
class Producto extends Model
|
|
|
|
{
|
|
|
|
public $timestamps = false;
|
|
|
|
protected $fillable = [ "nombre", "precio", "presentacion", "stock", "categoria" ];
|
2022-01-05 18:14:21 -03:00
|
|
|
static $paginarPorDefecto = 10;
|
2021-12-30 13:12:14 -03:00
|
|
|
|
|
|
|
public function subpedidos()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany('App\Subpedido','productos_subpedidos')->withPivot(["cantidad"]);
|
|
|
|
}
|
2024-08-27 20:56:27 -03:00
|
|
|
|
2021-12-30 13:12:14 -03:00
|
|
|
public function proveedor()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('App\Proveedor');
|
|
|
|
}
|
2022-01-05 18:14:21 -03:00
|
|
|
|
2024-09-05 13:34:33 -03:00
|
|
|
public function pagaTransporte() {
|
|
|
|
return !($this->bono || Str::contains($this->categoria, 'SUBSIDIADO'));
|
|
|
|
}
|
|
|
|
|
2022-01-07 18:02:48 -03:00
|
|
|
//Este método permite que se apliquen los filtros al hacer una request (por ejemplo, de búsqueda)
|
|
|
|
public function scopeFiltrar($query, FiltroDeProducto $filtros)
|
2022-01-05 18:14:21 -03:00
|
|
|
{
|
|
|
|
return $filtros->aplicar($query);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getPaginar(Request $request)
|
|
|
|
{
|
|
|
|
return $request->has('paginar') && intval($request->input('paginar')) ? intval($request->input('paginar')) : self::$paginarPorDefecto;
|
|
|
|
}
|
2022-10-01 15:29:31 -03:00
|
|
|
|
|
|
|
public static function productosFilaID() {
|
|
|
|
return Producto::pluck('id', 'fila',)->all();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function productosIDNombre() {
|
|
|
|
return Producto::pluck('nombre', 'id',)->all();
|
|
|
|
}
|
2024-08-27 20:56:27 -03:00
|
|
|
|
2021-12-30 13:12:14 -03:00
|
|
|
}
|