Example #1
0
 /**
  *
  * Создает новый трансфер с указанным списком товаров, но не проводит его
  * Если указанно, то создает резерв товара
  *
  * @param ProductQtyCollection $collection
  * @param Warehouse $source
  * @param Warehouse $target
  * @param boolean $reserve //зарезервировать товары?
  * @return StockTransfer
  */
 public function createTransfer(ProductQtyCollection $collection, Warehouse $source, Warehouse $target, $reserve = false)
 {
     if ($source->organization()->id != $target->organization()->id) {
         throw new StockException('Для перемещения между организациями, используйте метод StockRepository::createOrganisationsTransfer');
     }
     $transfer = new StockTransfer();
     $organization = $source->organization();
     $transfer->sourceOrganization()->associate($organization);
     $transfer->targetOrganization()->associate($organization);
     $transfer->sourceWarehouse()->associate($source);
     $transfer->targetWarehouse()->associate($target);
     $transfer->save();
     foreach ($collection as $row) {
         $productId = $row['id'];
         $qty = $row['qty'];
         $product = Product::findOrFail($productId);
         $stock = $this->stockRepository->findStockByProductAndWarehouse($product, $source);
         if (empty($stock)) {
             throw new StockNotFound();
         }
         $item = new StockTransferItem();
         $item->product()->associate($product);
         $item->stock()->associate($stock);
         $item->setQty($qty);
         $item->save();
     }
     if ($reserve === true) {
         $transfer->is_reserved = true;
         $rep = new ReserveRepository();
         $rep->createByDocument($transfer);
     }
     return $transfer;
 }
Example #2
0
 /**
  * Media uploads for a product.
  */
 public function getProductMedia($id)
 {
     // Get the product.
     $product = Product::findOrFail($id);
     // Render the view.
     return View::make('admin.products.media', ['product' => $product]);
 }
 /**
  * Update the specified product in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $product = Product::findOrFail($id);
     $validator = Validator::make($data = Input::all(), Product::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $product->update($data);
     return Redirect::route('products.index');
 }
 public function delete($id)
 {
     try {
         $product = Product::findOrFail($id);
         $product->delete(['id']);
         return Redirect::back()->with('error', false)->with('msg', 'Producto removido exitosamente.')->with('class', 'warning');
     } catch (Exception $exc) {
         echo $exc->getMessage() . " " . $exc->getLine();
         return Redirect::back()->with('error', true)->with('msg', '¡Algo salió mal! Contacte con administrador')->with('class', 'danger');
     }
 }
 /**
  * Store a newly created resource in storage.
  * POST /carts
  *
  * @return Response
  */
 public function store()
 {
     if ($id = Input::get('id')) {
         $product = Product::findOrFail((int) $id);
         $item = array('id' => $product->id, 'name' => $product->title, 'price' => $product->price, 'quantity' => 1);
         Cart::insert($item);
         return Cart::totalItems(true);
     } else {
         return false;
     }
 }
Example #6
0
 public function postAdd()
 {
     if (Request::ajax()) {
         $productId = Input::get('productId');
         $product = Product::findOrFail($productId);
         $name = Input::get('name');
         $price = Input::get('price');
         $link = 'product/' . $product->link;
         Cart::add(['id' => $productId, 'name' => $name, 'qty' => 1, 'price' => $price, 'options' => ['link' => $link]]);
         return Response::json(array('productId' => $productId, 'name' => $name, 'price' => $price, 'link' => $product->link));
     }
 }
 public function getDelete($id)
 {
     $delete = Product::findOrFail($id);
     if (!$delete) {
         return Redirect::to('product');
     }
     $delete->delete();
     if (!$delete->delete()) {
         return Redirect::to('product')->with(['message' => 'true', 'title' => 'Tebrikler!', 'text' => 'Ürün kaydı başarıyla silindi.', 'type' => 'success']);
     } else {
         return Redirect::to('product')->with(['message' => 'true', 'title' => 'Hata!', 'text' => 'Ürün kaydı silinemedi! Lütfen daha sonra tekrar deneyiniz.', 'type' => 'error']);
     }
 }
Example #8
0
 /**
  * Update the specified product in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $product = Product::findOrFail($id);
     $validator = Validator::make($data = Input::all(), Product::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $vendor = Vendor::find(Input::get('vendor_id'));
     $product->vendor()->associate($vendor);
     $product->name = Input::get('name');
     $product->description = Input::get('description');
     $product->price = Input::get('price');
     $product->status = 'active';
     $product->update();
     return Redirect::route('products.index');
 }
Example #9
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $product = $this->product->findOrFail($id);
     return View::make('products.show', compact('product'));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return Response
  */
 public function deleteDestroyproduct($id)
 {
     $product = Product::findOrFail($id);
     $product->delete();
     $bank = $product->bank;
     flash()->success('Producto eliminado con éxito.');
     return view('admin.showproduct', compact('bank'));
 }
 /**
  * Update the specified product in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $product = Product::findOrFail($id);
     $validator = Validator::make(Input::all(), Product::$rules);
     if ($validator->passes()) {
         $product->update(array('id' => $id, 'unit_id' => Input::get('unit_id'), 'name' => Input::get('name'), 'price' => Input::get('price'), 'cost' => Input::get('cost'), 'description' => Input::get('description'), 'created_at' => Carbon\Carbon::today(), 'producer' => Input::get('producer'), 'country' => Input::get('country')));
         return Response::json(array('success' => true, 'message' => array('type' => 'success', 'msg' => 'Cập nhật hàng hóa thành công!')));
     } else {
         return Response::json(array('success' => false, 'errors' => $validator->errors()));
     }
 }
Example #12
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $product = Product::findOrFail($id);
     $product->delete();
     return Redirect::route('product.index');
     // redirect to index after delete it
 }