'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(); } }