From 0946d9e9517ad79caef778b358dada232d96e8fd Mon Sep 17 00:00:00 2001 From: Guillermo Gutierrez Date: Wed, 16 Aug 2023 16:13:34 -0700 Subject: [PATCH] Finalizacion de la primera version del proyecto --- app/Http/Kernel.php | 1 + app/Http/Livewire/CancelacionController.php | 24 ++--- app/Http/Livewire/DashboardController.php | 75 ++++++++++++---- app/Http/Livewire/ReporteController.php | 16 +++- app/Http/Livewire/UserController.php | 7 +- app/Http/Livewire/VentaController.php | 54 ++++++++---- app/Http/Livewire/VentaEspecialController.php | 69 ++++++++++----- app/Http/Middleware/CajaValidate.php | 30 +++++++ app/Models/CajaMovimiento.php | 30 +++++++ app/Models/EstadoCajaMovimiento.php | 13 +++ .../{EstadoVenta.php => EstadoMovimiento.php} | 2 +- app/Models/Movimiento.php | 73 ++++++++++++++++ app/Models/Venta.php | 42 --------- app/exports/VentasExport.php | 8 +- ...13240_create_estado_movimientos_table.php} | 4 +- ..._08_02_014049_create_movimientos_table.php | 36 ++++++++ .../2023_08_02_014049_create_ventas_table.php | 38 -------- ...d_user_id_column_to_movimientos_table.php} | 7 +- ...7_create_estado_caja_movimientos_table.php | 28 ++++++ ...5_020113_create_caja_movimientos_table.php | 35 ++++++++ database/seeders/DatabaseSeeder.php | 3 +- .../seeders/EstadoCajaMovimientoSeeder.php | 30 +++++++ ...aSeeder.php => EstadoMovimientoSeeder.php} | 4 +- resources/views/dashboard.blade.php | 87 ++++++++++++++++--- .../views/export/reporteExport.blade.php | 30 ++++--- resources/views/navigation-menu.blade.php | 2 +- resources/views/venta/cancelacion.blade.php | 33 ++----- resources/views/venta/reporte.blade.php | 26 +++--- .../views/venta/venta-especial.blade.php | 55 ++++++------ resources/views/venta/venta.blade.php | 34 +++++--- routes/web.php | 15 ++-- 31 files changed, 640 insertions(+), 271 deletions(-) create mode 100644 app/Http/Middleware/CajaValidate.php create mode 100644 app/Models/CajaMovimiento.php create mode 100644 app/Models/EstadoCajaMovimiento.php rename app/Models/{EstadoVenta.php => EstadoMovimiento.php} (83%) create mode 100644 app/Models/Movimiento.php delete mode 100644 app/Models/Venta.php rename database/migrations/{2023_08_02_013240_create_estado_ventas_table.php => 2023_08_02_013240_create_estado_movimientos_table.php} (78%) create mode 100644 database/migrations/2023_08_02_014049_create_movimientos_table.php delete mode 100644 database/migrations/2023_08_02_014049_create_ventas_table.php rename database/migrations/{2023_08_09_011840_add_user_id_column_to_ventas_table.php => 2023_08_09_011840_add_user_id_column_to_movimientos_table.php} (66%) create mode 100644 database/migrations/2023_08_15_015707_create_estado_caja_movimientos_table.php create mode 100644 database/migrations/2023_08_15_020113_create_caja_movimientos_table.php create mode 100644 database/seeders/EstadoCajaMovimientoSeeder.php rename database/seeders/{EstadoVentaSeeder.php => EstadoMovimientoSeeder.php} (89%) diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index d359e9b..786c8ca 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -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, ]; } diff --git a/app/Http/Livewire/CancelacionController.php b/app/Http/Livewire/CancelacionController.php index 36162b2..a433a1b 100644 --- a/app/Http/Livewire/CancelacionController.php +++ b/app/Http/Livewire/CancelacionController.php @@ -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; diff --git a/app/Http/Livewire/DashboardController.php b/app/Http/Livewire/DashboardController.php index eaa8a20..32801b8 100644 --- a/app/Http/Livewire/DashboardController.php +++ b/app/Http/Livewire/DashboardController.php @@ -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; + } } diff --git a/app/Http/Livewire/ReporteController.php b/app/Http/Livewire/ReporteController.php index 9c39c25..c0a5720 100644 --- a/app/Http/Livewire/ReporteController.php +++ b/app/Http/Livewire/ReporteController.php @@ -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'); } } diff --git a/app/Http/Livewire/UserController.php b/app/Http/Livewire/UserController.php index ffddeba..8c86bc9 100644 --- a/app/Http/Livewire/UserController.php +++ b/app/Http/Livewire/UserController.php @@ -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' ]); diff --git a/app/Http/Livewire/VentaController.php b/app/Http/Livewire/VentaController.php index b676784..784b00c 100644 --- a/app/Http/Livewire/VentaController.php +++ b/app/Http/Livewire/VentaController.php @@ -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(); diff --git a/app/Http/Livewire/VentaEspecialController.php b/app/Http/Livewire/VentaEspecialController.php index f55647b..f7b120b 100644 --- a/app/Http/Livewire/VentaEspecialController.php +++ b/app/Http/Livewire/VentaEspecialController.php @@ -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!"); diff --git a/app/Http/Middleware/CajaValidate.php b/app/Http/Middleware/CajaValidate.php new file mode 100644 index 0000000..666858e --- /dev/null +++ b/app/Http/Middleware/CajaValidate.php @@ -0,0 +1,30 @@ +count()) + { + return $next($request); + } + else + { + return redirect(route('dashboard')); + } + } +} diff --git a/app/Models/CajaMovimiento.php b/app/Models/CajaMovimiento.php new file mode 100644 index 0000000..953b8b5 --- /dev/null +++ b/app/Models/CajaMovimiento.php @@ -0,0 +1,30 @@ +user()->id], + ['created_at', '>=', Carbon::now()->startOfDay()], + ['created_at', '<=', Carbon::now()->endOfDay()], + ])->get(); + } +} diff --git a/app/Models/EstadoCajaMovimiento.php b/app/Models/EstadoCajaMovimiento.php new file mode 100644 index 0000000..1368f0c --- /dev/null +++ b/app/Models/EstadoCajaMovimiento.php @@ -0,0 +1,13 @@ +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(); + } + } +} diff --git a/app/Models/Venta.php b/app/Models/Venta.php deleted file mode 100644 index 132e27f..0000000 --- a/app/Models/Venta.php +++ /dev/null @@ -1,42 +0,0 @@ -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); - } -} diff --git a/app/exports/VentasExport.php b/app/exports/VentasExport.php index 27b9898..a53f9f2 100644 --- a/app/exports/VentasExport.php +++ b/app/exports/VentasExport.php @@ -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(), ]); } } \ No newline at end of file diff --git a/database/migrations/2023_08_02_013240_create_estado_ventas_table.php b/database/migrations/2023_08_02_013240_create_estado_movimientos_table.php similarity index 78% rename from database/migrations/2023_08_02_013240_create_estado_ventas_table.php rename to database/migrations/2023_08_02_013240_create_estado_movimientos_table.php index ab92dbc..6a4e533 100644 --- a/database/migrations/2023_08_02_013240_create_estado_ventas_table.php +++ b/database/migrations/2023_08_02_013240_create_estado_movimientos_table.php @@ -11,7 +11,7 @@ return new class extends Migration */ public function up(): void { - Schema::create('estado_ventas', function (Blueprint $table) { + Schema::create('estado_movimientos', function (Blueprint $table) { $table->id(); $table->string('nombre'); $table->timestamps(); @@ -23,6 +23,6 @@ return new class extends Migration */ public function down(): void { - Schema::dropIfExists('estado_ventas'); + Schema::dropIfExists('estado_movimientos'); } }; diff --git a/database/migrations/2023_08_02_014049_create_movimientos_table.php b/database/migrations/2023_08_02_014049_create_movimientos_table.php new file mode 100644 index 0000000..5801f6f --- /dev/null +++ b/database/migrations/2023_08_02_014049_create_movimientos_table.php @@ -0,0 +1,36 @@ +id(); + $table->string('codigo',20); + $table->float('precio_venta',30)->nullable(); + $table->float('pago_efectivo',30)->nullable(); + $table->float('pago_tarjeta',30)->nullable(); + $table->float('pago_vales',30)->nullable(); + $table->float('pago_transferencia',30)->nullable(); + $table->unsignedBigInteger('estado_movimiento_id'); + $table->foreign('estado_movimiento_id')->on('estado_movimientos')->references('id'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('movimientos'); + } +}; diff --git a/database/migrations/2023_08_02_014049_create_ventas_table.php b/database/migrations/2023_08_02_014049_create_ventas_table.php deleted file mode 100644 index 4b2f13d..0000000 --- a/database/migrations/2023_08_02_014049_create_ventas_table.php +++ /dev/null @@ -1,38 +0,0 @@ -id(); - $table->string('codigo',20); - $table->string('pago_efectivo',30)->nullable(); - $table->string('pago_tarjeta_debito',30)->nullable(); - $table->string('pago_tarjeta_credito',30)->nullable(); - $table->string('pago_vales',30)->nullable(); - - $table->string('precio_venta')->nullable(); - - $table->unsignedBigInteger('estado_venta_id'); - $table->foreign('estado_venta_id')->on('estado_ventas')->references('id'); - - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('ventas'); - } -}; diff --git a/database/migrations/2023_08_09_011840_add_user_id_column_to_ventas_table.php b/database/migrations/2023_08_09_011840_add_user_id_column_to_movimientos_table.php similarity index 66% rename from database/migrations/2023_08_09_011840_add_user_id_column_to_ventas_table.php rename to database/migrations/2023_08_09_011840_add_user_id_column_to_movimientos_table.php index 4c66327..cca97ab 100644 --- a/database/migrations/2023_08_09_011840_add_user_id_column_to_ventas_table.php +++ b/database/migrations/2023_08_09_011840_add_user_id_column_to_movimientos_table.php @@ -11,11 +11,12 @@ return new class extends Migration */ public function up(): void { - Schema::table('ventas', function (Blueprint $table) { + Schema::table('movimientos', function (Blueprint $table) { // - $table->unsignedBigInteger('user_id')->after('precio_venta'); + $table->unsignedBigInteger('user_id')->after('estado_movimiento_id'); $table->foreign('user_id')->references('id')->on('users'); $table->boolean('is_liquidado')->nullable(); + $table->string('motivo')->nullable(); }); } @@ -24,7 +25,7 @@ return new class extends Migration */ public function down(): void { - Schema::table('ventas', function (Blueprint $table) { + Schema::table('movimientos', function (Blueprint $table) { // }); } diff --git a/database/migrations/2023_08_15_015707_create_estado_caja_movimientos_table.php b/database/migrations/2023_08_15_015707_create_estado_caja_movimientos_table.php new file mode 100644 index 0000000..930882c --- /dev/null +++ b/database/migrations/2023_08_15_015707_create_estado_caja_movimientos_table.php @@ -0,0 +1,28 @@ +id(); + $table->string('nombre'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('estado_caja_movimientos'); + } +}; diff --git a/database/migrations/2023_08_15_020113_create_caja_movimientos_table.php b/database/migrations/2023_08_15_020113_create_caja_movimientos_table.php new file mode 100644 index 0000000..c5cd3f0 --- /dev/null +++ b/database/migrations/2023_08_15_020113_create_caja_movimientos_table.php @@ -0,0 +1,35 @@ +id(); + $table->float('cantidad'); + + $table->unsignedBigInteger('estado_caja_movimiento_id'); + $table->foreign('estado_caja_movimiento_id')->references('id')->on('estado_caja_movimientos'); + + $table->unsignedBigInteger('user_id'); + $table->foreign('user_id')->references('id')->on('users'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('caja_movimientos'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 19629b5..47b2b7b 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -14,7 +14,8 @@ class DatabaseSeeder extends Seeder public function run(): void { $this->call([ - EstadoVentaSeeder::class, + EstadoMovimientoSeeder::class, + EstadoCajaMovimientoSeeder::class, RoleSeeder::class, UserSeeder::class, ]); diff --git a/database/seeders/EstadoCajaMovimientoSeeder.php b/database/seeders/EstadoCajaMovimientoSeeder.php new file mode 100644 index 0000000..3600348 --- /dev/null +++ b/database/seeders/EstadoCajaMovimientoSeeder.php @@ -0,0 +1,30 @@ +insert([ + [ + 'nombre' => 'Caja Inicial', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now() + ], + [ + 'nombre' => 'Retiro', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now() + ], + ]); + } +} diff --git a/database/seeders/EstadoVentaSeeder.php b/database/seeders/EstadoMovimientoSeeder.php similarity index 89% rename from database/seeders/EstadoVentaSeeder.php rename to database/seeders/EstadoMovimientoSeeder.php index f725bd4..8a4b44c 100644 --- a/database/seeders/EstadoVentaSeeder.php +++ b/database/seeders/EstadoMovimientoSeeder.php @@ -7,7 +7,7 @@ use Illuminate\Database\Seeder; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; -class EstadoVentaSeeder extends Seeder +class EstadoMovimientoSeeder extends Seeder { /** * Run the database seeds. @@ -16,7 +16,7 @@ class EstadoVentaSeeder extends Seeder { // - DB::table('estado_ventas')->insert([ + DB::table('estado_movimientos')->insert([ [ 'nombre' => 'Venta', 'created_at' => Carbon::now(), diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 2470621..f2389d7 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -7,15 +7,15 @@

Fecha: {{ now()}}

- + @role('admin')
- -
+ +

Ventas del dia

-

$ {{ $venta }}

+

$ {{ $movimiento }}

@@ -25,11 +25,54 @@
-
+

Abonos del dia

-

$ {{ $abono }}

+

$ {{ $abono }}

+
+
+ + + + +
+
+
+ +
+
+
+

Cancelaciones del dia

+

$ {{ $cancelacion }}

+
+
+ + + +
+
+
+ +
+
+
+

Numero de Ventas

+

{{ $num_movimiento }}

+
+
+ + + +
+
+
+ +
+
+
+

Numero de Abonos

+

{{ $num_abono }}

@@ -43,17 +86,41 @@
-

Cancelaciones del dia

-

$ {{ $cancelacion }}

+

Numero de Cancelaciones

+

{{ $num_cancelacion }}

- - + + +
+ @endrole + + + +
diff --git a/resources/views/export/reporteExport.blade.php b/resources/views/export/reporteExport.blade.php index 1578760..cee9d14 100644 --- a/resources/views/export/reporteExport.blade.php +++ b/resources/views/export/reporteExport.blade.php @@ -3,25 +3,31 @@ Codigo Pago Efectivo - Pago Tarjeta Debito - Pago Tarjeta Credito + Pago Tarjeta Pago Tarjeta Vales + Pago Transferencia + Suma Pagos + Total a pagar Registrado por - Tipo Venta + Tipo de Movimiento + Motivo Fecha - @foreach ($ventas as $venta) + @foreach ($movimientos as $movimiento) - {{ $venta->codigo }} - {{ $venta->pago_efectivo }} - {{ $venta->pago_tarjeta_debito }} - {{ $venta->pago_tarjeta_credito }} - {{ $venta->pago_vales }} - {{ $venta->user->name }} - {{ $venta->estadoVenta->nombre }} - {{ $venta->created_at }} + {{ $movimiento->codigo }} + {{ $movimiento->pago_efectivo }} + {{ $movimiento->pago_tarjeta }} + {{ $movimiento->pago_vales }} + {{ $movimiento->pago_transferencia }} + {{ $movimiento->totalAbono() }} + {{ $movimiento->precio_venta }} + {{ $movimiento->user->name }} + {{ $movimiento->estadoMovimiento->nombre }} + {{ $movimiento->motivo }} + {{ $movimiento->created_at }} @endforeach diff --git a/resources/views/navigation-menu.blade.php b/resources/views/navigation-menu.blade.php index 311b45a..0e7eda2 100644 --- a/resources/views/navigation-menu.blade.php +++ b/resources/views/navigation-menu.blade.php @@ -25,10 +25,10 @@ {{ __('Cancelacion') }} + @role('admin') {{ __('Reporte') }} - @role('admin') {{ __('Usuarios') }} diff --git a/resources/views/venta/cancelacion.blade.php b/resources/views/venta/cancelacion.blade.php index 4b33ff6..ce9a47f 100644 --- a/resources/views/venta/cancelacion.blade.php +++ b/resources/views/venta/cancelacion.blade.php @@ -29,10 +29,8 @@ Codigo - Pago Efectivo - Pago Tarjeta Debito - Pago Tarjeta Credito - Pago Tarjeta Vales + Retorno de efectivo + Motivo Registrado por Fecha @@ -42,9 +40,7 @@ {{$cancelacion->codigo}} {{$cancelacion->pago_efectivo}} - {{$cancelacion->pago_tarjeta_debito}} - {{$cancelacion->pago_tarjeta_credito}} - {{$cancelacion->pago_vales}} + {{$cancelacion->motivo}} {{$cancelacion->user->name}} {{$cancelacion->created_at}} @@ -90,27 +86,12 @@
- - + + {{-- --}} +
- @error('cancelacion.pago_tarjeta_debito'){{ $message }}@enderror - -
-
- - -
-
- @error('cancelacion.pago_tarjeta_credito'){{ $message }}@enderror - -
-
- - -
-
- @error('cancelacion.pago_vales'){{ $message }}@enderror + @error('cancelacion.motivo'){{ $message }}@enderror
diff --git a/resources/views/venta/reporte.blade.php b/resources/views/venta/reporte.blade.php index 04c1d08..cc0d9a8 100644 --- a/resources/views/venta/reporte.blade.php +++ b/resources/views/venta/reporte.blade.php @@ -34,25 +34,29 @@ Codigo Pago Efectivo - Pago Tarjeta Debito - Pago Tarjeta Credito + Pago Tarjeta Pago Tarjeta Vales + Pago Transferencia + Suma Pagos + Total a pagar Registrado por Tipo Venta Fecha - @foreach ($ventas as $venta) + @foreach ($movimientos as $movimiento) - {{ $venta->codigo }} - {{ $venta->pago_efectivo }} - {{ $venta->pago_tarjeta_debito }} - {{ $venta->pago_tarjeta_credito }} - {{ $venta->pago_vales }} - {{ $venta->user->name }} - {{ $venta->estadoVenta->nombre }} - {{ $venta->created_at }} + {{ $movimiento->codigo }} + {{ $movimiento->pago_efectivo }} + {{ $movimiento->pago_tarjeta }} + {{ $movimiento->pago_vales }} + {{ $movimiento->pago_transferencia }} + {{ $movimiento->totalAbono() }} + {{ $movimiento->precio_venta }} + {{ $movimiento->user->name }} + {{ $movimiento->estadoMovimiento->nombre }} + {{ $movimiento->created_at }} @endforeach diff --git a/resources/views/venta/venta-especial.blade.php b/resources/views/venta/venta-especial.blade.php index 047347f..bd97ceb 100644 --- a/resources/views/venta/venta-especial.blade.php +++ b/resources/views/venta/venta-especial.blade.php @@ -31,9 +31,9 @@ Codigo Pago Efectivo - Pago Tarjeta Debito - Pago Tarjeta Credito + Pago Tarjeta Pago Tarjeta Vales + Pago Transferencia Total a pagar Registrado por Fecha @@ -44,9 +44,9 @@ @foreach ($ventas as $venta) {{ $venta->codigo }} {{ $venta->pago_efectivo }} - {{ $venta->pago_tarjeta_debito }} - {{ $venta->pago_tarjeta_credito }} + {{ $venta->pago_tarjeta }} {{ $venta->pago_vales }} + {{ $venta->pago_transferencia }} {{ $venta->precio_venta }} {{ $venta->user->name }} {{ $venta->created_at }} @@ -84,6 +84,14 @@
@error('ventaEspecial.codigo'){{ $message }}@enderror +
+
+ + +
+
+ @error('ventaEspecial.precio_venta'){{ $message }}@enderror +
@@ -94,19 +102,19 @@
- - + +
- @error('ventaEspecial.pago_tarjeta_debito'){{ $message }}@enderror + @error('ventaEspecial.pago_tarjeta'){{ $message }}@enderror
- - + +
- @error('ventaEspecial.pago_tarjeta_credito'){{ $message }}@enderror + @error('ventaEspecial.pago_transferencia'){{ $message }}@enderror
@@ -115,14 +123,6 @@
@error('ventaEspecial.pago_vales'){{ $message }}@enderror - -
-
- - -
-
- @error('ventaEspecial.precio_venta'){{ $message }}@enderror
@@ -139,7 +139,12 @@

Liquidar Venta Especial

Saldo abonado: {{ $abonado }}

-

Saldo a pagar: {{ $total_pagar }}

+

+
+ +
+

Cambio: {{ $cambio }}

+

Saldo a pagar: {{ $faltante }}

@@ -160,19 +165,19 @@
- - + +
- @error('ventaEspecial.pago_tarjeta_debito'){{ $message }}@enderror + @error('ventaEspecial.pago_tarjeta'){{ $message }}@enderror
- - + +
- @error('ventaEspecial.pago_tarjeta_credito'){{ $message }}@enderror + @error('ventaEspecial.pago_transferencia'){{ $message }}@enderror
diff --git a/resources/views/venta/venta.blade.php b/resources/views/venta/venta.blade.php index ade72cc..5a873a7 100644 --- a/resources/views/venta/venta.blade.php +++ b/resources/views/venta/venta.blade.php @@ -30,9 +30,10 @@ Codigo Pago Efectivo - Pago Tarjeta Debito - Pago Tarjeta Credito + Pago Tarjeta Pago Tarjeta Vales + Pago Transferencia + Total Venta Registrado por Fecha @@ -41,9 +42,10 @@ @forelse ($ventas as $venta) {{ $venta->codigo }} {{ $venta->pago_efectivo }} - {{ $venta->pago_tarjeta_debito }} - {{ $venta->pago_tarjeta_credito }} + {{ $venta->pago_tarjeta }} {{ $venta->pago_vales }} + {{ $venta->pago_transferencia }} + {{ $venta->precio_venta }} {{ $venta->user->name }} {{ $venta->created_at }} @@ -68,6 +70,10 @@

Registrar Venta

+
+

Cambio: {{ $cambio }}

+

Saldo a pagar: {{ $faltante }}

+
@@ -77,6 +83,14 @@
@error('venta.codigo'){{ $message }}@enderror +
+
+ + +
+
+ @error('venta.precio_venta'){{ $message }}@enderror +
@@ -87,19 +101,19 @@
- - + +
- @error('venta.pago_tarjeta_debito'){{ $message }}@enderror + @error('venta.pago_tarjeta'){{ $message }}@enderror
- - + +
- @error('venta.pago_tarjeta_credito'){{ $message }}@enderror + @error('venta.pago_transferencia'){{ $message }}@enderror
diff --git a/routes/web.php b/routes/web.php index a02fd0d..ee767d2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -29,22 +29,27 @@ Route::get('/', function () { Route::middleware([ 'auth:sanctum', config('jetstream.auth_session'), - 'verified' + 'verified', + 'cajaValidate' ])->group(function () { - Route::get('/dashboard',DashboardController::class)->name('dashboard'); - Route::get('/venta',VentaController::class)->name('venta'); Route::get('/venta-especial',VentaEspecialController::class)->name('venta-especial'); Route::get('/cancelacion',CancelacionController::class)->name('cancelacion'); - Route::get('/reporte',ReporteController::class)->name('reporte'); }); +Route::middleware([ + 'auth:sanctum', + config('jetstream.auth_session'), + 'verified', +])->get('/dashboard',DashboardController::class)->name('dashboard'); + Route::middleware([ 'auth:sanctum', config('jetstream.auth_session'), 'verified', 'role:admin' ])->group(function(){ - + + Route::get('/reporte',ReporteController::class)->name('reporte'); Route::get('/usuarios',UserController::class)->name('usuarios'); });