version 1.0
This commit is contained in:
96
app/Http/Livewire/VentaController.php
Normal file
96
app/Http/Livewire/VentaController.php
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user