Finalizacion de la primera version del proyecto
This commit is contained in:
@@ -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!");
|
||||
|
||||
Reference in New Issue
Block a user