Implementacion de modulo de pedidos
This commit is contained in:
17
app/Models/Impresora.php
Normal file
17
app/Models/Impresora.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Impresora extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'estacion',
|
||||
'nombre_impresora',
|
||||
'is_compartida',
|
||||
];
|
||||
}
|
||||
@@ -16,6 +16,7 @@ class Movimiento extends Model
|
||||
'pago_vales',
|
||||
'pago_transferencia',
|
||||
'precio_venta',
|
||||
'nota_credito',
|
||||
'estado_movimiento_id',
|
||||
'user_id',
|
||||
'is_liquidado',
|
||||
@@ -38,7 +39,8 @@ class Movimiento extends Model
|
||||
return ((float)$this->pago_efectivo +
|
||||
(float)$this->pago_tarjeta +
|
||||
(float)$this->pago_vales +
|
||||
(float)$this->pago_transferencia);
|
||||
(float)$this->pago_transferencia +
|
||||
(float)$this->nota_credito);
|
||||
}
|
||||
|
||||
public function cambio()
|
||||
@@ -47,6 +49,7 @@ class Movimiento extends Model
|
||||
((float)$this->pago_efectivo +
|
||||
(float)$this->pago_tarjeta +
|
||||
(float)$this->pago_vales +
|
||||
(float)$this->nota_credito +
|
||||
(float)$this->pago_transferencia) -
|
||||
(float)$this->precio_venta
|
||||
);
|
||||
@@ -59,7 +62,8 @@ class Movimiento extends Model
|
||||
((float)$this->pago_efectivo +
|
||||
(float)$this->pago_tarjeta +
|
||||
(float)$this->pago_vales +
|
||||
(float)$this->pago_transferencia)
|
||||
(float)$this->pago_transferencia +
|
||||
(float)$this->nota_credito)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -79,6 +83,30 @@ class Movimiento extends Model
|
||||
public function isTotalMayorCambio() : bool
|
||||
{
|
||||
|
||||
return ($this->pago_tarjeta + $this->pago_vales + $this->pago_transferencia)>$this->precio_venta;
|
||||
return ($this->pago_tarjeta + $this->pago_vales + $this->pago_transferencia + $this->nota_credito)>$this->precio_venta;
|
||||
}
|
||||
|
||||
public function getAbonos()
|
||||
{
|
||||
$collecion = collect($this->getFillable());
|
||||
$elements = [];
|
||||
foreach ($collecion as $value) {
|
||||
if(str_contains($value,"pago_"))
|
||||
{
|
||||
if($this->{$value} > 0)
|
||||
{
|
||||
$elements[] = [$this->{$value},str_replace("pago_","",$value)];
|
||||
}
|
||||
}
|
||||
else if(str_contains($value,"nota_credito"))
|
||||
{
|
||||
if($this->{$value} > 0)
|
||||
{
|
||||
$elements[] = [$this->{$value},str_replace("nota_","Nota de ",$value)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $elements;
|
||||
}
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
30
app/Models/Producto.php
Normal file
30
app/Models/Producto.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Producto extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'linea',
|
||||
'codigo',
|
||||
'descripcion',
|
||||
// 'prefijo',
|
||||
'ruta_id',
|
||||
'cantidad',
|
||||
'precio_unitario',
|
||||
];
|
||||
|
||||
public function ruta()
|
||||
{
|
||||
return $this->belongsTo(Ruta::class);
|
||||
}
|
||||
// public function total()
|
||||
// {
|
||||
// return (is_int($this->cantidad) && is_int($this->precio_unitario))?$this->cantidad * $this->precio_unitario:'';
|
||||
// }
|
||||
}
|
||||
16
app/Models/Ruta.php
Normal file
16
app/Models/Ruta.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Ruta extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'ruta',
|
||||
'prefijo',
|
||||
];
|
||||
}
|
||||
@@ -28,7 +28,7 @@ class User extends Authenticatable
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password',
|
||||
'name', 'email', 'password','impresora_id',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -60,4 +60,9 @@ class User extends Authenticatable
|
||||
protected $appends = [
|
||||
'profile_photo_url',
|
||||
];
|
||||
|
||||
public function impresora()
|
||||
{
|
||||
return $this->belongsTo(Impresora::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user