/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { try { $data = $request->all(); $date = Carbon::now(); $pedido = new Pedido(); $pedido->fecha = $date->toDateString(); $pedido->idCliente = $data["idCliente"]; $pedido->valor = $data["total"]; $pedido->estado = "Espera"; $pedido->domicilio = $data["domicilio"]; $pedido->save(); $detalles = json_decode($data["detalles"]); foreach ($detalles as $d) { $detalle = new Detalle(); $detalle->idPedido = $pedido->id; $detalle->idProducto = $d->idProducto; $detalle->cantidad = $d->cantidad; $detalle->precioProducto = $d->precio; $detalle->subTotal = $d->subtotal; $detalle->save(); $producto = Producto::find($detalle->idProducto); $cantidad = $producto->visitas; $producto->visitas = $cantidad + 1; $producto->save(); } return JsonResponse::create(array('message' => "Pedido Enviado correctamente"), 200); } catch (Exception $exc) { return JsonResponse::create(array('message' => "No se pudo enviar el pedido", "exception" => $exc->getMessage(), "request" => json_encode($data)), 401); } }
public function post_catalogo(Request $request) { $user = Auth::user(); $producto = Producto::find($request->input('id_producto')); $consulta = Venta::where('id_cliente', $user->id)->where('estado', 'SIN PAGO')->first(); if ($consulta) { $detalleventa = null; $detalleventa = DetalleVenta::where('id_venta', $consulta->id)->where('id_producto', $producto->id)->first(); if ($detalleventa == null) { $detalleventa = new DetalleVenta(); $detalleventa->id_venta = $consulta->id; $detalleventa->id_producto = $request->input('id_producto'); $detalleventa->cantidad = 1; $detalleventa->save(); } else { $detalleventa->cantidad = $detalleventa->cantidad + 1; $detalleventa->save(); } } else { $venta = new Venta(); $venta->id_cliente = $user->id; $venta->estado = "SIN PAGO"; $venta->save(); $detalleventa = new DetalleVenta(); $detalleventa->id_venta = $venta->id; $detalleventa->id_producto = $request->input('id_producto'); $detalleventa->cantidad = "1"; $detalleventa->save(); } return redirect()->action('UserController@get_detalleventa'); }
public function run() { $faker = Faker::create('es_ES'); $ventas = Venta::all(); $cantidadProductos = Producto::all()->count(); foreach ($ventas as $venta) { for ($i = 0; $i < 7; $i++) { $idProducto = $faker->numberBetween($min = 1, $max = $cantidadProductos); $cantidad = $faker->numberBetween($min = 1, $max = 20); $productoObj = Producto::find($idProducto); $subtotal = $productoObj->subtotal($cantidad); $venta->productos()->attach($idProducto, ['cantidad' => $cantidad, 'subtotal' => $subtotal]); } } }
public function destroy($id) { $imagen = DB::table('imagen')->where('id_producto', $id)->delete(); //File::delete('/uploads/imagenes/' . $imagen->ruta_imagen); //$query = DB::table('imagen')->where('id_producto', '=', $id); //$imagen = $query->first(); //print_r($image); //return 'end'; //File::delete(public_p . '/uploads/imagenes/thumb-' . $image->path); //File::delete('/uploads/imagenes/' . $imagen->ruta_imagen); //var_dump($imagen->id_producto); //$query->delete(); $producto = Producto::find($id); $producto->delete(); return redirect('productos'); }
public function ventasPdf(Request $request) { $id = $request->id; $clienteId = $request->cliente_id; $productos = array(); $venta = Venta::find($id); foreach ($venta->productos as $producto) { $id = $producto->pivot->producto_id; $cantidad = $producto->pivot->cantidad; $subtotal = $producto->pivot->subtotal; $proAux = Producto::find($id); $nombre = $proAux->nombre; $precio = $proAux->precio; $productoObj = array(['id' => $id, 'nombre' => $nombre, 'cantidad' => $cantidad, 'precio' => $precio, 'subtotal' => $subtotal]); array_push($productos, $productoObj); } $view = \View::make('admi.ventaPdf')->with(['venta' => $venta, 'productos' => $productos])->render(); $pdf = \App::make('dompdf.wrapper'); $pdf->loadHTML($view)->setPaper('a4')->setOrientation('landscape'); return $pdf->stream('invoice'); }
public function find(Route $route) { $this->producto = Producto::find($route->getParameter('productos')); // productos es el atributo que figura junto al nombre de la ruta en el archivo de rutas. }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { if (Auth::user()->rol->permisos->contains(8)) { $validator = Validator::make($request->all(), ['nombre' => 'required|unique:productos,nombre,' . $id, 'precio' => 'required|numeric', 'stock' => 'required|integer']); if ($validator->fails()) { return back()->withErrors($validator); } $producto = Producto::find($id); $input = $request->except('stock'); $producto->fill($input); $stock = $producto->stock(); $stock->cantidad = (int) $request->stock; $stock->save(); if ($request->hasFile('imagen')) { $validator->after(function ($validator) use($request) { if ($this->VerificarDimensionImagen($request->file('imagen'))) { $validator->errors()->add('field', 'La imagen debe ser de 500px X 500px.'); } }); if ($validator->fails()) { return back()->withErrors($validator); } $producto->imagen = $this->GuardarImagen($request); } $producto->save(); Session::flash('mensaje', 'Producto Actualizado!!!'); return redirect()->route('admin.producto.show', [$id]); } else { return abort(401); } }
public function get_detalleventa() { $user = Auth::user(); $consulta = Venta::where('id_cliente', $user->id)->where('estado', 'SIN PAGO')->first(); $productos = array('0' => '0'); $detalles = null; $x = 1; if ($consulta) { $detalles = DetalleVenta::where('id_venta', $consulta->id)->get(); $productos = array('0' => '0'); foreach ($detalles as $detalle) { $producto = Producto::find($detalle->id_producto); $productos = array_add($productos, $x, $producto); $x++; } } return View::make('propio/detalle')->with('detalles', $detalles)->with('productos', $productos); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $producto = Producto::find($id); $producto->delete(); \Session::flash('message', 'Producto Borrado Correctamente'); return \Redirect::to('admi/productos'); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $producto = Producto::find($id); $producto->activo = 0; $producto->save(); return redirect('productos'); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(Request $request) { $producto = Producto::find($request->id); return response()->json(view('front.productos.modalProducto', compact('producto'))->render()); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { try { $producto = Producto::find($id); $producto->delete(); return JsonResponse::create(array('message' => "Producto Eliminada Correctamente", "request" => json_encode($id)), 200); } catch (Exception $ex) { return JsonResponse::create(array('message' => "No se pudo Eliminar la producto", "exception" => $ex->getMessage(), "request" => json_encode($id)), 401); } }
public function postDelete(Request $request) { $id = $request->input('_id'); $producto = Producto::find($id); $producto->delete(); return redirect("productos")->with('success', 'delete')->with("id_producto", $producto->id); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { Producto::find($id)->delete(); \Session::flash('flash_message', 'Se ha eliminado correctamente!!!'); return redirect(''); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $params = []; if ($request->hasFile('pro_imagen_default')) { $params = $request->all(); try { $params['pro_imagen_default'] = $this->uploadPhoto($request, 'pro_imagen_default', 'productos'); $galeria_id = Galeria::where('producto_id', $id)->pluck('id')->first(); $galeria = Galeria::find($galeria_id); $galeria->pro_imagen_default = $params['pro_imagen_default']; $galeria->save(); } catch (Exception $ex) { return redirect()->back()->with('error_message', 'Ups... no se puede procesar el archivo subido, intentelo de nuevo, si persiste contacte con el programador'); } } else { $params = $request->except('pro_imagen_default'); } $producto = Producto::find($id); $producto->fill($params); $producto->save(); return redirect()->back()->with('success_message', 'Datos del producto actualizados'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function newPedido(Request $request) { $ganancia = 0; $data = $request->all(); $date = Carbon::now(); $pedido = new PedidoVendedor(); $pedido->fecha = $date->toDateString(); $pedido->idVendedor = $data["idVendedor"]; $pedido->valor = $data["total"]; $pedido->estado = "Espera"; $pedido->domicilio = $data["domicilio"]; $pedido->estadoPago = "SIN LIQUIDAR"; $pedido->save(); $detalles = json_decode($data["detalles"]); foreach ($detalles as $d) { $detalle = new DetallePedidoVendedor(); $detalle->idPedidoVendedores = $pedido->id; $detalle->idProducto = $d->idProducto; $detalle->precio = $d->precio; $detalle->porcentajeVendedor = $d->porcentajeVendedor; $detalle->porcentajeDescuento = $d->porcentajeDescuento; $detalle->ganancia = $d->precio * $d->porcentajeVendedor / 100 * $d->cantidad; $detalle->cantidad = $d->cantidad; $detalle->subTotal = $d->subtotal; $detalle->save(); $ganancia = $ganancia + $detalle->ganancia; $producto = Producto::find($detalle->idProducto); $cantidad = $producto->visitas; $producto->visitas = $cantidad + 1; $producto->save(); } $pedido->ganancia = $ganancia; $pedido->save(); return JsonResponse::create(array('message' => "Guardado Correctamente"), 200); }