version 1.0

This commit is contained in:
Guillermo Gutierrez
2023-08-11 11:08:47 -07:00
commit 994709a3e5
223 changed files with 23438 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
<?php
namespace App\Http\Livewire;
use App\Models\Venta;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
class CancelacionController extends Component
{
const CODIGO_CANCELACION = 3;
public $buscador = '' , $modal = false;
public $cancelacion;
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.user_id',
];
public function updatingBuscador()
{
$this->resetPage();
}
public function render()
{
$cancelaciones = Venta::where([['codigo','like','%'.$this->buscador.'%'],['estado_venta_id','=',CancelacionController::CODIGO_CANCELACION]])->paginate(10);
return view('venta.cancelacion',[
'cancelaciones' => $cancelaciones
]);
}
public function create()
{
$this->clearInputs();
$this->cancelacion = new Venta([
'codigo' => 0,
'pago_efectivo' => 0,
'pago_tarjeta_debito' => 0,
'pago_tarjeta_credito' => 0,
'pago_vales' => 0,
'precio_venta' => 0,
'estado_venta_id' => 3,
]);
$this->showModal();
}
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',
]);
$this->cancelacion->user_id = Auth::user()->id;
$this->cancelacion->save();
session()->flash('message',"La cancelacion se ha registrado correctamente!");
$this->clearInputs();
$this->closeModal();
}
public function showModal()
{
$this->modal = true;
}
public function closeModal()
{
$this->modal = false;
}
public function clearInputs()
{
$this->reset();
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Http\Livewire;
use App\Models\Venta;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Livewire\Component;
class DashboardController extends Component
{
const ESTADO_VENTA =1, ESTADO_ABONO = 2, ESTADO_CANCELACION = 3;
public function render()
{
$venta = $this->totalDiaTipoVenta(DashboardController::ESTADO_VENTA);
$abono = $this->totalDiaTipoVenta(DashboardController::ESTADO_ABONO);
$cancelacion = $this->totalDiaTipoVenta(DashboardController::ESTADO_CANCELACION);
return view('dashboard',[
'venta' => $venta,
'abono' => $abono,
'cancelacion' => $cancelacion
]);
}
public function totalDiaTipoVenta($tipo_venta)
{
return
Venta::where([
['estado_venta_id','=', $tipo_venta],
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')],
])->sum('pago_efectivo') +
Venta::where([
['estado_venta_id','=', $tipo_venta],
[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],
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')],
])->sum('pago_vales');
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Livewire;
use App\Exports\VentasExport;
use App\Models\Venta;
use Carbon\Carbon;
use Livewire\Component;
use Maatwebsite\Excel\Facades\Excel;
class ReporteController extends Component
{
public $fecha_inicio, $fecha_final;
public function render()
{
return view('venta.reporte',[
'ventas' => Venta::whereBetween('created_at',[$this->fecha_inicio,$this->fecha_final])->get()
]);
}
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');
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace App\Http\Livewire;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Livewire\Component;
use Spatie\Permission\Models\Role;
class UserController extends Component
{
public $buscador = '', $modal = false;
public $user, $role_id, $password;
protected $rules = [
'user.name' => 'required|min:3',
'user.email' => 'required|email',
'user.password' => 'required|min:6',
];
public function updatingBuscador()
{
$this->resetPage();
}
public function render()
{
$users = User::where('email','like','%'.$this->buscador.'%')->paginate(10);
return view('user',[
'users' => $users,
'roles' => Role::all(),
]);
}
public function create()
{
$this->clearInputs();
$this->user = new User();
$this->showModal();
}
public function edit(User $user)
{
$this->user = $user;
$this->role_id = $this->user->roles->first()->id;
$this->showModal();
}
public function save()
{
$this->validate([
'user.name' => 'required|min:3',
'user.email' => 'required|min:3|unique:users,email',
'password' => 'required|min:6'
]);
$this->user->password = Hash::make($this->password);
$this->user->save();
$this->user->roles()->sync($this->role_id);
session()->flash('message',$this->user->id?"El usuario se ha actualizado correctamente!":"El usuario se ha registrado correctamente!");
$this->clearInputs();
$this->closeModal();
}
public function showModal()
{
$this->modal = true;
}
public function closeModal()
{
$this->modal = false;
}
public function clearInputs()
{
$this->reset();
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace App\Http\Livewire;
use App\Models\EstadoVenta;
use App\Models\Venta;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use Livewire\WithPagination;
class VentaController extends Component
{
use WithPagination;
const CODIGO_VENTA = 1;
public $buscador = '', $modal = false;
public $venta;
protected $rules = [
'venta.codigo' => 'min:0',
'venta.pago_efectivo' => 'numeric',
'venta.pago_tarjeta_debito' => 'numeric',
'venta.pago_tarjeta_credito' => 'numeric',
'venta.pago_vales' => 'numeric',
'venta.precio_venta' => 'numeric',
'venta.estado_venta_id' => 'numeric',
'venta.user_id',
];
public function updatingBuscador()
{
$this->resetPage();
}
public function render()
{
$ventas = Venta::where([['codigo','like','%'.$this->buscador.'%'],['estado_venta_id','=',VentaController::CODIGO_VENTA]])->paginate(10);
return view('venta.venta',[
'ventas' => $ventas,
'estadoVentas' => EstadoVenta::all(),
]);
}
public function create()
{
$this->clearInputs();
$this->venta = new Venta([
'codigo' => 0,
'pago_efectivo' => 0,
'pago_tarjeta_debito' => 0,
'pago_tarjeta_credito' => 0,
'pago_vales' => 0,
'precio_venta' => 0,
'estado_venta_id' => 1,
]);
$this->showModal();
}
public function save()
{
$this->validate([
'venta.pago_efectivo' => 'numeric',
'venta.pago_tarjeta_debito' => 'numeric',
'venta.pago_tarjeta_credito' => 'numeric',
'venta.pago_vales' => 'numeric',
'venta.precio_venta' => 'numeric',
'venta.estado_venta_id' => 'numeric',
]);
$this->venta->user_id = Auth::user()->id;
$this->venta->save();
session()->flash('message',"La venta se ha registrado correctamente!");
$this->clearInputs();
$this->closeModal();
}
public function showModal()
{
$this->modal = true;
}
public function closeModal()
{
$this->modal = false;
}
public function clearInputs()
{
$this->reset();
}
}

View File

@@ -0,0 +1,158 @@
<?php
namespace App\Http\Livewire;
use App\Models\Venta;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use Livewire\WithPagination;
class VentaEspecialController extends Component
{
use WithPagination;
const CODIGO_VENTA_ESPECIAL = 2;
public $buscador = '', $modal = false, $modalLiquidar;
public $ventaEspecial, $total_pagar, $abonado, $ventaAnterior;
protected $rules = [
'ventaEspecial.codigo' => 'min:0',
'ventaEspecial.pago_efectivo' => 'numeric',
'ventaEspecial.pago_tarjeta_debito' => 'numeric',
'ventaEspecial.pago_tarjeta_credito' => 'numeric',
'ventaEspecial.pago_vales' => 'numeric',
'ventaEspecial.precio_venta' => 'numeric',
'ventaEspecial.estado_venta_id' => 'numeric',
];
public function render()
{
$ventas = Venta::where([['codigo','like','%'.$this->buscador.'%'],['estado_venta_id','=',VentaEspecialController::CODIGO_VENTA_ESPECIAL]])->paginate(10);
return view('venta.venta-especial',[
'ventas' => $ventas,
]);
}
public function updatingBuscador()
{
$this->resetPage();
}
public function create()
{
$this->clearInputs();
$this->ventaEspecial = new Venta([
'codigo' => 0,
'pago_efectivo' => 0,
'pago_tarjeta_debito' => 0,
'pago_tarjeta_credito' => 0,
'pago_vales' => 0,
'precio_venta' => 0,
'estado_venta_id' => VentaEspecialController::CODIGO_VENTA_ESPECIAL,
]);
$this->showModal();
}
public function liquidar(Venta $venta)
{
$this->ventaAnterior = $venta;
$this->ventaEspecial = new Venta([
'codigo' => $venta->codigo,
'pago_efectivo' => 0,
'pago_tarjeta_debito' => 0,
'pago_tarjeta_credito' => 0,
'pago_vales' => 0,
'precio_venta' => $venta->precio_venta,
'estado_venta_id' => VentaEspecialController::CODIGO_VENTA_ESPECIAL,
]);
$this->total_pagar = $this->calcularTotalPagar($venta);
$this->abonado = $venta->precio_venta - $this->total_pagar;
$this->showModalLiquidar();
}
public function calcularTotalPagar($venta)
{
return ($venta->precio_venta - $venta->pago_efectivo - $venta->pago_tarjeta_credito - $venta->pago_tarjeta_debito - $venta->pago_vales);
}
public function save()
{
$this->validate([
'ventaEspecial.pago_efectivo' => 'numeric',
'ventaEspecial.pago_tarjeta_debito' => 'numeric',
'ventaEspecial.pago_tarjeta_credito' => 'numeric',
'ventaEspecial.pago_vales' => 'numeric',
'ventaEspecial.precio_venta' => 'numeric|gte:2',
'ventaEspecial.estado_venta_id' => 'numeric',
]);
$this->ventaEspecial->user_id = Auth::user()->id;
$this->ventaEspecial->save();
session()->flash('message',"La venta se ha registrado correctamente!");
$this->clearInputs();
$this->closeModal();
}
public function saveLiquidar()
{
$this->validate([
'ventaEspecial.pago_efectivo' => 'numeric',
'ventaEspecial.pago_tarjeta_debito' => 'numeric',
'ventaEspecial.pago_tarjeta_credito' => 'numeric',
'ventaEspecial.pago_vales' => 'numeric',
'ventaEspecial.precio_venta' => 'numeric|gte:2',
'ventaEspecial.estado_venta_id' => 'numeric',
]);
if(($this->calcularTotalPagar($this->ventaEspecial) - $this->ventaAnterior->totalAbono()) >0){
// session()->flash("message_abono",($this->calcularTotalPagar($this->ventaEspecial) - $this->ventaAnterior->totalAbono()));
session()->flash("message_abono","Debes liquidar la deuda para cerrarla.");
return;
}
$this->ventaAnterior->is_liquidado = true;
$this->ventaAnterior->save();
$this->ventaEspecial->user_id = Auth::user()->id;
$this->ventaEspecial->is_liquidado = true;
$this->ventaEspecial->save();
session()->flash('message',"La venta se ha registrado correctamente!");
$this->clearInputs();
$this->closeModalLiquidar();
}
public function showModal()
{
$this->modal = true;
}
public function closeModal()
{
$this->modal = false;
}
public function showModalLiquidar()
{
$this->modalLiquidar = true;
}
public function closeModalLiquidar()
{
$this->modalLiquidar = false;
}
public function clearInputs()
{
$this->reset();
}
}