Finalizacion de la primera version del proyecto

This commit is contained in:
Guillermo Gutierrez
2023-08-16 16:13:34 -07:00
parent 994709a3e5
commit 0946d9e951
31 changed files with 640 additions and 271 deletions

View File

@@ -67,5 +67,6 @@ class Kernel extends HttpKernel
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
'role_or_permission' => \Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::class,
'cajaValidate' => \App\Http\Middleware\CajaValidate::class,
];
}

View File

@@ -2,7 +2,7 @@
namespace App\Http\Livewire;
use App\Models\Venta;
use App\Models\Movimiento;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
@@ -16,11 +16,8 @@ class CancelacionController extends Component
protected $rules = [
'cancelacion.codigo' => 'min:0',
'cancelacion.pago_efectivo' => 'numeric',
'cancelacion.pago_tarjeta_debito' => 'numeric',
'cancelacion.pago_tarjeta_credito' => 'numeric',
'cancelacion.pago_vales' => 'numeric',
'cancelacion.precio_venta' => 'numeric',
'cancelacion.estado_venta_id' => 'numeric',
'cancelacion.estado_movimiento_id' => 'numeric',
'cancelacion.motivo' => 'required',
'cancelacion.user_id',
];
@@ -31,7 +28,7 @@ class CancelacionController extends Component
public function render()
{
$cancelaciones = Venta::where([['codigo','like','%'.$this->buscador.'%'],['estado_venta_id','=',CancelacionController::CODIGO_CANCELACION]])->paginate(10);
$cancelaciones = Movimiento::where([['codigo','like','%'.$this->buscador.'%'],['estado_movimiento_id','=',CancelacionController::CODIGO_CANCELACION]])->paginate(10);
return view('venta.cancelacion',[
'cancelaciones' => $cancelaciones
]);
@@ -41,14 +38,14 @@ class CancelacionController extends Component
public function create()
{
$this->clearInputs();
$this->cancelacion = new Venta([
$this->cancelacion = new Movimiento([
'codigo' => 0,
'pago_efectivo' => 0,
'pago_tarjeta_debito' => 0,
'pago_tarjeta_credito' => 0,
'pago_vales' => 0,
'precio_venta' => 0,
'estado_venta_id' => 3,
'estado_movimiento_id' => 3,
]);
$this->showModal();
@@ -57,12 +54,9 @@ class CancelacionController extends Component
public function save()
{
$this->validate([
'cancelacion.pago_efectivo' => 'numeric',
'cancelacion.pago_tarjeta_debito' => 'numeric',
'cancelacion.pago_tarjeta_credito' => 'numeric',
'cancelacion.pago_vales' => 'numeric',
'cancelacion.precio_venta' => 'numeric',
'cancelacion.estado_venta_id' => 'numeric',
'cancelacion.pago_efectivo' => 'numeric|required|gte:1',
'cancelacion.estado_movimiento_id' => 'numeric',
'cancelacion.motivo' => 'required',
]);
$this->cancelacion->user_id = Auth::user()->id;

View File

@@ -2,7 +2,8 @@
namespace App\Http\Livewire;
use App\Models\Venta;
use App\Models\CajaMovimiento;
use App\Models\Movimiento;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Livewire\Component;
@@ -10,36 +11,74 @@ use Livewire\Component;
class DashboardController extends Component
{
const ESTADO_VENTA =1, ESTADO_ABONO = 2, ESTADO_CANCELACION = 3;
public $cajaModal = false, $cajaInicial;
public function render()
{
$venta = $this->totalDiaTipoVenta(DashboardController::ESTADO_VENTA);
$abono = $this->totalDiaTipoVenta(DashboardController::ESTADO_ABONO);
$cancelacion = $this->totalDiaTipoVenta(DashboardController::ESTADO_CANCELACION);
// dd(Movimiento::where([
// ['estado_movimiento_id','=', DashboardController::ESTADO_VENTA],
// [DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')]
// ])->count());
$movimiento = $this->totalDiaTipoMovimiento(DashboardController::ESTADO_VENTA);
$abono = $this->totalDiaTipoMovimiento(DashboardController::ESTADO_ABONO);
$cancelacion = $this->totalDiaTipoMovimiento(DashboardController::ESTADO_CANCELACION);
$this->validarCaja();
return view('dashboard',[
'venta' => $venta,
'movimiento' => $movimiento,
'abono' => $abono,
'cancelacion' => $cancelacion
'cancelacion' => $cancelacion,
'num_movimiento' => Movimiento::where([
['estado_movimiento_id','=', DashboardController::ESTADO_VENTA],
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')]
])->count(),
'num_abono' => Movimiento::where([
['estado_movimiento_id','=', DashboardController::ESTADO_ABONO],
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')]
])->count(),
'num_cancelacion' => Movimiento::where([
['estado_movimiento_id','=', DashboardController::ESTADO_CANCELACION],
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')]
])->count(),
'caja' => CajaMovimiento::cajaInicial(),
]);
}
public function totalDiaTipoVenta($tipo_venta)
public function totalDiaTipoMovimiento($tipo_movimiento)
{
return
Venta::where([
['estado_venta_id','=', $tipo_venta],
Movimiento::where([
['estado_movimiento_id','=', $tipo_movimiento],
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')],
])->sum('pago_efectivo') +
Venta::where([
['estado_venta_id','=', $tipo_venta],
Movimiento::where([
['estado_movimiento_id','=', $tipo_movimiento],
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')],
])->sum('pago_tarjeta_debito') +
Venta::where([
['estado_venta_id','=', $tipo_venta],
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')],
])->sum('pago_tarjeta_credito') +
Venta::where([
['estado_venta_id','=', $tipo_venta],
])->sum('pago_tarjeta') +
Movimiento::where([
['estado_movimiento_id','=', $tipo_movimiento],
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')],
])->sum('pago_vales');
}
public function validarCaja()
{
if(!CajaMovimiento::cajaInicial()->count())
{
$this->cajaModal = true;
}
}
public function save()
{
$this->validate([
'cajaInicial' => 'required|numeric',
]);
CajaMovimiento::create([
'cantidad' => $this->cajaInicial,
'estado_caja_movimiento_id' => CajaMovimiento::CODIGO_CAJA,
'user_id' => auth()->user()->id,
]);
$this->cajaModal = false;
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Http\Livewire;
use App\Exports\VentasExport;
use App\Models\Movimiento;
use App\Models\Venta;
use Carbon\Carbon;
use Livewire\Component;
@@ -11,20 +12,31 @@ use Maatwebsite\Excel\Facades\Excel;
class ReporteController extends Component
{
public $fecha_inicio, $fecha_final;
public $fn_inicio, $fn_final;
public function render()
{
return view('venta.reporte',[
'ventas' => Venta::whereBetween('created_at',[$this->fecha_inicio,$this->fecha_final])->get()
'movimientos' => Movimiento::whereBetween('created_at',[$this->fn_inicio,$this->fn_final])->get(),
]);
}
public function updatedFechaInicio()
{
$this->fn_inicio= Carbon::parse($this->fecha_inicio)->startOfDay();
}
public function updatedFechaFinal()
{
$this->fn_final= Carbon::parse($this->fecha_final)->endOfDay();
}
public function export()
{
$this->validate([
'fecha_inicio' => 'required|date',
'fecha_final' => 'required|date',
]);
return Excel::download(new VentasExport($this->fecha_inicio, $this->fecha_final),'venta-'.Carbon::now()->format('Y-m-d').'.xlsx');
return Excel::download(new VentasExport($this->fn_inicio, $this->fn_final),'venta-'.Carbon::now()->format('Y-m-d').'.xlsx');
}
}

View File

@@ -50,9 +50,14 @@ class UserController extends Component
public function save()
{
if(!isset($this->user->id))
{
$this->validate([
'user.email' => 'required|min:3|unique:users,email',
]);
}
$this->validate([
'user.name' => 'required|min:3',
'user.email' => 'required|min:3|unique:users,email',
'password' => 'required|min:6'
]);

View File

@@ -2,8 +2,8 @@
namespace App\Http\Livewire;
use App\Models\EstadoVenta;
use App\Models\Venta;
use App\Models\EstadoMovimiento;
use App\Models\Movimiento;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use Livewire\WithPagination;
@@ -15,16 +15,16 @@ class VentaController extends Component
const CODIGO_VENTA = 1;
public $buscador = '', $modal = false;
public $venta;
public $venta, $cambio, $faltante;
protected $rules = [
'venta.codigo' => 'min:0',
'venta.pago_efectivo' => 'numeric',
'venta.pago_tarjeta_debito' => 'numeric',
'venta.pago_tarjeta_credito' => 'numeric',
'venta.pago_tarjeta' => 'numeric',
'venta.pago_vales' => 'numeric',
'venta.precio_venta' => 'numeric',
'venta.estado_venta_id' => 'numeric',
'venta.precio_venta' => 'required|numeric|gte:1',
'venta.pago_transferencia' => 'numeric',
'venta.estado_movimiento_id' => 'numeric',
'venta.user_id',
];
@@ -35,39 +35,55 @@ class VentaController extends Component
public function render()
{
$ventas = Venta::where([['codigo','like','%'.$this->buscador.'%'],['estado_venta_id','=',VentaController::CODIGO_VENTA]])->paginate(10);
$ventas = Movimiento::where([['codigo','like','%'.$this->buscador.'%'],['estado_movimiento_id','=',VentaController::CODIGO_VENTA]])->paginate(10);
return view('venta.venta',[
'ventas' => $ventas,
'estadoVentas' => EstadoVenta::all(),
'estadoVentas' => EstadoMovimiento::all(),
]);
}
public function create()
{
$this->clearInputs();
$this->venta = new Venta([
$this->venta = new Movimiento([
'codigo' => 0,
'pago_efectivo' => 0,
'pago_tarjeta_debito' => 0,
'pago_tarjeta_credito' => 0,
'pago_vales' => 0,
'precio_venta' => 0,
'estado_venta_id' => 1,
'pago_efectivo' => 0,
'pago_tarjeta' => 0,
'pago_vales' => 0,
'pago_transferencia' => 0,
'estado_movimiento_id' => 1,
]);
$this->cambio;
$this->showModal();
}
public function updated()
{
if($this->venta->cambio()>0)
{
$this->cambio = $this->venta->cambio();
$this->faltante = 0;
}
else
{
$this->faltante = $this->venta->faltante();
$this->cambio = 0;
}
}
public function save()
{
$this->validate([
'venta.pago_efectivo' => 'numeric',
'venta.pago_tarjeta_debito' => 'numeric',
'venta.pago_tarjeta_credito' => 'numeric',
'venta.precio_venta' => 'required|numeric|gte:1',
'venta.pago_tarjeta' => 'required|numeric',
'venta.pago_vales' => 'numeric',
'venta.precio_venta' => 'numeric',
'venta.estado_venta_id' => 'numeric',
'venta.pago_transferencia' => 'numeric',
'venta.estado_movimiento_id' => 'numeric',
]);
$this->venta->ajusteCambio();
$this->venta->user_id = Auth::user()->id;
$this->venta->save();

View File

@@ -2,7 +2,7 @@
namespace App\Http\Livewire;
use App\Models\Venta;
use App\Models\Movimiento;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use Livewire\WithPagination;
@@ -13,21 +13,21 @@ class VentaEspecialController extends Component
const CODIGO_VENTA_ESPECIAL = 2;
public $buscador = '', $modal = false, $modalLiquidar;
public $ventaEspecial, $total_pagar, $abonado, $ventaAnterior;
public $ventaEspecial, $total_pagar, $ventaAnterior, $abonado, $cambio, $faltante;
protected $rules = [
'ventaEspecial.codigo' => 'min:0',
'ventaEspecial.pago_efectivo' => 'numeric',
'ventaEspecial.pago_tarjeta_debito' => 'numeric',
'ventaEspecial.pago_tarjeta_credito' => 'numeric',
'ventaEspecial.pago_tarjeta' => 'numeric',
'ventaEspecial.pago_vales' => 'numeric',
'ventaEspecial.precio_venta' => 'numeric',
'ventaEspecial.estado_venta_id' => 'numeric',
'ventaEspecial.pago_transferencia' => 'numeric',
'ventaEspecial.estado_movimiento_id' => 'numeric',
];
public function render()
{
$ventas = Venta::where([['codigo','like','%'.$this->buscador.'%'],['estado_venta_id','=',VentaEspecialController::CODIGO_VENTA_ESPECIAL]])->paginate(10);
$ventas = Movimiento::where([['codigo','like','%'.$this->buscador.'%'],['estado_movimiento_id','=',VentaEspecialController::CODIGO_VENTA_ESPECIAL]])->paginate(10);
return view('venta.venta-especial',[
'ventas' => $ventas,
]);
@@ -41,41 +41,59 @@ class VentaEspecialController extends Component
public function create()
{
$this->clearInputs();
$this->ventaEspecial = new Venta([
$this->ventaEspecial = new Movimiento([
'codigo' => 0,
'pago_efectivo' => 0,
'pago_tarjeta_debito' => 0,
'pago_tarjeta_credito' => 0,
'pago_tarjeta' => 0,
'pago_vales' => 0,
'pago_transferencia' => 0,
'precio_venta' => 0,
'estado_venta_id' => VentaEspecialController::CODIGO_VENTA_ESPECIAL,
'estado_movimiento_id' => VentaEspecialController::CODIGO_VENTA_ESPECIAL,
]);
$this->showModal();
}
public function liquidar(Venta $venta)
public function liquidar(Movimiento $venta)
{
$this->ventaAnterior = $venta;
$this->ventaEspecial = new Venta([
$this->ventaEspecial = new Movimiento([
'codigo' => $venta->codigo,
'pago_efectivo' => 0,
'pago_tarjeta_debito' => 0,
'pago_tarjeta_credito' => 0,
'pago_tarjeta' => 0,
'pago_vales' => 0,
'precio_venta' => $venta->precio_venta,
'estado_venta_id' => VentaEspecialController::CODIGO_VENTA_ESPECIAL,
'pago_transferencia' => 0,
'precio_venta' => $this->ventaAnterior->faltante(),
'estado_movimiento_id' => VentaEspecialController::CODIGO_VENTA_ESPECIAL,
]);
$this->total_pagar = $this->calcularTotalPagar($venta);
$this->abonado = $venta->precio_venta - $this->total_pagar;
$this->updated();
$this->showModalLiquidar();
}
public function updated()
{
if(!isset($this->ventaAnterior) || !isset($this->ventaEspecial)) return;
if($this->ventaEspecial->cambio()>0)
{
$this->cambio = $this->ventaEspecial->cambio();
$this->faltante = 0;
}
else
{
$this->faltante = $this->ventaEspecial->faltante();
$this->cambio = 0;
}
}
public function calcularTotalPagar($venta)
{
return ($venta->precio_venta - $venta->pago_efectivo - $venta->pago_tarjeta_credito - $venta->pago_tarjeta_debito - $venta->pago_vales);
return ($venta->precio_venta - $venta->pago_efectivo - $venta->pago_tarjeta - $venta->pago_vales - $venta->pago_transferencia);
}
@@ -83,11 +101,11 @@ class VentaEspecialController extends Component
{
$this->validate([
'ventaEspecial.pago_efectivo' => 'numeric',
'ventaEspecial.pago_tarjeta_debito' => 'numeric',
'ventaEspecial.pago_tarjeta_credito' => 'numeric',
'ventaEspecial.pago_tarjeta' => 'numeric',
'ventaEspecial.pago_vales' => 'numeric',
'ventaEspecial.pago_transferencia' => 'numeric',
'ventaEspecial.precio_venta' => 'numeric|gte:2',
'ventaEspecial.estado_venta_id' => 'numeric',
'ventaEspecial.estado_movimiento_id' => 'numeric',
]);
$this->ventaEspecial->user_id = Auth::user()->id;
@@ -103,11 +121,11 @@ class VentaEspecialController extends Component
{
$this->validate([
'ventaEspecial.pago_efectivo' => 'numeric',
'ventaEspecial.pago_tarjeta_debito' => 'numeric',
'ventaEspecial.pago_tarjeta_credito' => 'numeric',
'ventaEspecial.pago_tarjeta' => 'numeric',
'ventaEspecial.pago_vales' => 'numeric',
'ventaEspecial.pago_transferencia' => 'numeric',
'ventaEspecial.precio_venta' => 'numeric|gte:2',
'ventaEspecial.estado_venta_id' => 'numeric',
'ventaEspecial.estado_movimiento_id' => 'numeric',
]);
if(($this->calcularTotalPagar($this->ventaEspecial) - $this->ventaAnterior->totalAbono()) >0){
@@ -121,6 +139,11 @@ class VentaEspecialController extends Component
$this->ventaEspecial->user_id = Auth::user()->id;
$this->ventaEspecial->is_liquidado = true;
$this->ventaEspecial->ajusteCambio();
$this->ventaEspecial->precio_venta = $this->ventaAnterior->precio_venta;
$this->ventaEspecial->save();
session()->flash('message',"La venta se ha registrado correctamente!");

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Middleware;
use App\Models\CajaMovimiento;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Symfony\Component\HttpFoundation\Response;
class CajaValidate
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if(CajaMovimiento::cajaInicial()->count())
{
return $next($request);
}
else
{
return redirect(route('dashboard'));
}
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class CajaMovimiento extends Model
{
use HasFactory;
const CODIGO_CAJA = 1, CODIGO_RETIRO = 2;
protected $fillable = [
'cantidad',
'estado_caja_movimiento_id',
'user_id',
];
public static function cajaInicial()
{
return CajaMovimiento::where([
['user_id','=',auth()->user()->id],
['created_at', '>=', Carbon::now()->startOfDay()],
['created_at', '<=', Carbon::now()->endOfDay()],
])->get();
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class EstadoCajaMovimiento extends Model
{
use HasFactory;
protected $fillable = ['nombre'];
}

View File

@@ -5,7 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class EstadoVenta extends Model
class EstadoMovimiento extends Model
{
use HasFactory;

73
app/Models/Movimiento.php Normal file
View File

@@ -0,0 +1,73 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Movimiento extends Model
{
use HasFactory;
protected $fillable = [
'codigo',
'pago_efectivo',
'pago_tarjeta',
'pago_vales',
'pago_transferencia',
'precio_venta',
'estado_movimiento_id',
'user_id',
'is_liquidado',
'motivo',
];
public function estadoMovimiento()
{
return $this->belongsTo(EstadoMovimiento::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
public function totalAbono()
{
return ((float)$this->pago_efectivo +
(float)$this->pago_tarjeta +
(float)$this->pago_vales +
(float)$this->pago_transferencia);
}
public function cambio()
{
return (
((float)$this->pago_efectivo +
(float)$this->pago_tarjeta +
(float)$this->pago_vales +
(float)$this->pago_transferencia) -
(float)$this->precio_venta
);
}
public function faltante()
{
return (
(float)$this->precio_venta -
((float)$this->pago_efectivo +
(float)$this->pago_tarjeta +
(float)$this->pago_vales +
(float)$this->pago_transferencia)
);
}
public function ajusteCambio()
{
if(((float)$this->pago_efectivo) - $this->cambio()>0)
{
$this->pago_efectivo-= $this->cambio();
}
}
}

View File

@@ -1,42 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Venta extends Model
{
use HasFactory;
protected $fillable = [
'codigo',
'precio_venta',
'pago_efectivo',
'pago_tarjeta_debito',
'pago_tarjeta_credito',
'pago_vales',
'estado_venta_id',
'user_id',
'is_liquidado',
];
public function estadoVenta()
{
return $this->belongsTo(EstadoVenta::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
public function totalAbono()
{
return ($this->pago_efectivo +
$this->pago_tarjeta_debito +
$this->pago_tarjeta_credito +
$this->pago_vales);
}
}

View File

@@ -2,7 +2,7 @@
namespace App\Exports;
use App\Invoice;
use App\Models\Venta;
use App\Models\Movimiento;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\FromView;
@@ -19,14 +19,14 @@ class VentasExport implements FromView{
public function collection()
{
return Venta::select(
return Movimiento::select(
'codigo',
'pago_efectivo',
'pago_tarjeta_debito',
'pago_tarjeta_credito',
'pago_vales',
'precio_venta',
'estado_venta_id as tipo_venta',
'estado_venta_id as tipo_movimiento',
'user_id as usuario',
)->get();
}
@@ -34,7 +34,7 @@ class VentasExport implements FromView{
public function view(): View
{
return view('export.reporteExport',[
'ventas' => Venta::whereBetween('created_at',[$this->fecha_inicio,$this->fecha_final])->get(),
'movimientos' => Movimiento::whereBetween('created_at',[$this->fecha_inicio,$this->fecha_final])->get(),
]);
}
}