/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { if (Auth::user()->rol->permisos->contains(6)) { $validator = Validator::make($request->all(), ['nombre' => 'required|unique:productos,nombre', 'precio' => 'required|numeric', 'stock' => 'required|integer', 'imagen' => 'required|image']); $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); } $input = $request->except('stock'); $nProducto = Producto::create($input); $nProducto->imagen = $this->GuardarImagen($request); $nStock = Stock::create(); $nStock->id_producto = $nProducto->id; $nStock->cantidad = (int) $request->stock; $nProducto->save(); $nStock->save(); Session::flash('mensaje', 'Nuevo Producto guardado!!!'); return redirect()->route('admin.producto.index'); } else { return abort(401); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $product = Product::create(Form_Request::all()); $stock = array('product_id' => $product->id, 'tanker_id' => 1, 'quantity' => 0); Stock::create($stock); $redirect = Redirect::back(); if ($product != null) { return $redirect->with('message', 'Successfully saved!'); } else { return $redirect->withInput()->withErrors(['error_message']); } }
/** * Function that creates a new product. * * @return Response */ public function createProduct() { // Validate Input. $validator = Validator::make(Input::all(), array('code' => 'required', 'description' => 'required', 'cost' => 'required', 'price' => 'required', 'minimum' => 'required', 'providerId' => 'required')); $response = array(); if ($validator->fails()) { $response['state'] = 'Error'; $response['error'] = 'Informacion incompleta!'; return response()->json($response); } // Check that user is part of authorized staff. if (Auth::user()->Type != 1) { // If they are unauthorized no point in returning anything. return response()->json(array()); } // Get the worker. $worker = Worker::find(Auth::user()->TypeId); // Verify that a product with code doesn't already exist. $product = Stock::where('Code', '=', Input::get('code'))->where('BranchId', '=', $worker->BranchId)->first(); if ($product) { $response['state'] = 'Error'; $response['error'] = 'Ya existe un producto con el codigo especificado!'; return response()->json($response); } // Create the product. Stock::create(array('Code' => Input::get('code'), 'Description' => Input::get('description'), 'Cost' => Input::get('cost'), 'Price' => Input::get('price'), 'Minimum' => Input::get('minimum'), 'ProviderId' => Input::get('providerId'), 'BranchId' => $worker->BranchId, 'AverageCost' => Input::get('cost'), 'Quantity' => 0)); // Prepare to notify admins. // Admins are UserLevel 1 $admins = User::where('UserLevel', '=', 1)->get(); // Now send notifications to admins. foreach ($admins as $admin) { $reason = "Se ha creado un nuevo producto: " . Input::get('description') . " El producto fue creado por {$worker->Name}."; Notification::create(array('UserId' => $admin->Id, 'Reason' => $reason, 'Url' => '/bills/product/' . Input::get('code') . '/branchId/' . $worker->BranchId, 'Seen' => false)); } $response['state'] = 'Success'; // Return result. return response()->json($response); }
/** * Function that creates products. * * @return Response */ public function createProduct() { // Validate Input. $validator = Validator::make(Input::all(), array('formData' => 'required')); if ($validator->fails()) { return response()->json(['error' => 'Informacion incompleta!']); } // Check that user is part of authorized staff. if (Auth::user()->Type != 1) { // If they are unauthorized no point in returning anything. return response()->json(array()); } $worker = Worker::find(Auth::user()->TypeId); $branchId = $worker->BranchId; // Create the product. $product = Stock::create(array('Code' => Input::get('formData')['ppcCode'], 'Description' => Input::get('formData')['ppcDescription'], 'Cost' => Input::get('formData')['ppcCost'], 'AverageCost' => Input::get('formData')['ppcCost'], 'Price' => Input::get('formData')['ppcPrice'], 'Bonus' => Input::get('formData')['ppcBonus'], 'Quantity' => Input::get('formData')['ppcQuantity'], 'BranchId' => $branchId, 'Minimum' => Input::get('formData')['ppcMinimum'], 'ProviderId' => Input::get('formData')['ppcProvider'], 'Category' => Input::get('formData')['ppcCategory'])); $response['state'] = 'Success'; $response['message'] = 'El producto ha sido creado exitosamente!'; $response['product'] = $product; return response()->json($response); }