public function guardarFacturaVenta($Venta, $Detalle) { $IdUltimaVenta; $Credito = new Credito(); try { $Venta->save(); $IdUltimaVenta = $this->obtenerUltimoIdVenta(); if (strcmp($Venta->TipoVenta, "cr") == 0) { $Credito->IdVenta = $IdUltimaVenta; $Credito->MontoTotal = $Venta->TotalVenta; $Credito->Saldo = $Venta->TotalVenta; $Credito->IdCliente = $Venta->IdCliente; $Credito->FechaRegistro = $Venta->Fecha; $Credito->Estado = "A"; $Credito->save(); } foreach ($Detalle as $Linea) { $DetalleVenta = new DetalleVenta(); $Producto = Producto::findOrFail($Linea->IdProducto); $Producto->Stock = $Producto->Stock - $Linea->Cantidad; $DetalleVenta->IdVenta = $IdUltimaVenta; $DetalleVenta->IdProducto = $Linea->IdProducto; $DetalleVenta->PrecioVentaUnitario = $Linea->PrecioVentaUnitario; $DetalleVenta->Cantidad = $Linea->Cantidad; $DetalleVenta->PrecioCostoUnitario = $Linea->PrecioCosto; $DetalleVenta->EsExcento = $Linea->EsExcento; $DetalleVenta->PorcentajeIV = $Linea->PorcentajeIV; $DetalleVenta->PorcentajeDescuento = $Linea->PorcentajeDescuento; $DetalleVenta->PorcentajeUtilidad = $Linea->PorcentajeUtilidad; $DetalleVenta->DescuentoUnitario = $Linea->DescuentoUnitario; $DetalleVenta->UtilidadUnitario = $Linea->UtilidadUnitario; $DetalleVenta->TotalIV = $Linea->TotalIV; $DetalleVenta->TotalDescuento = $Linea->TotalDescuento; $DetalleVenta->TotalUtilidad = $Linea->TotalUtilidad; $DetalleVenta->TotalLinea = $Linea->TotalLinea; $DetalleVenta->save(); $Producto->save(); } return true; } catch (Exception $e) { return false; } }
public function abonoCredito($IdCredito, $Monto, $Fecha, $tipo) { $Credito = Credito::findOrFail($IdCredito); $Detalle = new CreditoDetalle(); $Detalle->IdCredito = $IdCredito; $Detalle->MontoAbonado = $Monto; $Detalle->FechaAbono = $Fecha; $Detalle->TipoAbono = $tipo; $Credito->Saldo = $Credito->Saldo - $Monto; $Credito->save(); $Detalle->save(); }
public function creditosexcel() { Excel::create('Credito', function ($excel) { $excel->sheet('Creditos', function ($sheet) { $credito = Credito::all(); $array = array(); $creditos = DB::select("call obtenerTodosCreditos()"); foreach ($creditos as $obj) { $array[] = (array) $obj; } $sheet->fromArray($array); }); })->export('xls'); }