Implementacion de modulo de pedidos
This commit is contained in:
78
app/Models/Pedido.php
Normal file
78
app/Models/Pedido.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Pedido extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'cuenta',
|
||||
'pedido',
|
||||
'telefono',
|
||||
'year',
|
||||
'marca',
|
||||
'modelo',
|
||||
'motor',
|
||||
'folio_proveedor',
|
||||
'user_id',
|
||||
'comentarios',
|
||||
'numero_remision',
|
||||
|
||||
'is_venta_cerrada',
|
||||
'venta_cerrada_user_id',
|
||||
'is_venta_entregada',
|
||||
'venta_entregada_user_id',
|
||||
'venta_cerrada_at',
|
||||
'venta_entregada_at'
|
||||
];
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::created(function ($model){
|
||||
$model->pedido = 'PE-'.$model->id;
|
||||
$model->save();
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function productos()
|
||||
{
|
||||
return $this->belongsToMany(Producto::class,'producto_pedidos','pedido_id','producto_id')->withPivot(['unidades','is_arrivo','precio_unitario']);
|
||||
}
|
||||
|
||||
public function ultimaVenta()
|
||||
{
|
||||
return $this->hasOne(Movimiento::class,'codigo','pedido')->latest();
|
||||
}
|
||||
|
||||
public function primeraVenta()
|
||||
{
|
||||
return $this->hasOne(Movimiento::class,'codigo','pedido')->first();
|
||||
}
|
||||
|
||||
public function ultimaVentaBy()
|
||||
{
|
||||
return $this->ultimaVenta()->where('is_liquidado', '=', '1')->first();
|
||||
}
|
||||
|
||||
public function ventaEntregadaUser()
|
||||
{
|
||||
return $this->belongsTo(User::class,'venta_entregada_user_id','id');
|
||||
}
|
||||
|
||||
public function ventaCerradaUser()
|
||||
{
|
||||
return $this->belongsTo(User::class,'venta_cerrada_user_id','id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user