public function uploadMenu(Request $request) { $data = $this->postUpload($request); if (is_array($data)) { $before = Menu::count(); foreach ($data as $item) { Menu::updateOrCreate(['number' => $item['number']], ['number' => $item['number'], 'title' => $item['title'], 'price' => $item['price']]); } $difference = Menu::count() - $before; Helper::add('', 'uploaded menu items import file'); if ($difference > 0) { Session::flash('flash_message', $difference . ' ' . $this->title . ' items successfully imported!'); } else { Session::flash('flash_message', 'No new ' . $this->title . ' items imported!'); } return Redirect::action('MenusController@index'); } else { return $data; } }
public function uploadMenu(Request $request) { $data = $this->postUpload($request); if (is_array($data)) { $before = Menu::count(); $sale = Sales::create(['stock_period_id' => $request->get('stock_period_id')]); foreach ($data as $item) { $menu = Menu::updateOrCreate(['number' => $item['number']], ['number' => $item['number'], 'title' => $item['title'], 'price' => $item['price']]); $data = ['quantity' => $item['quantity'], 'menu_id' => $menu->id, 'sale_id' => $sale->id, 'price' => $item['price'], 'total_price' => round($item['price'] * $item['quantity'], 2)]; SaleItems::create($data); } $difference = Menu::count() - $before; Helper::add('', 'uploaded ' . $difference . ' menu items import file on import sales action'); Session::flash('flash_message', 'Sale uploaded successfully with ' . $difference . ' new items added to menu.'); return Redirect::action('SalesController@index', ['stock_period' => $request->get('stock_period_id')]); } else { return $data; } }
/** * Update/Store admin menu settings * POST /admin/settings * * @return Response */ public function storeSettings() { $data = Input::all(); Log::info($data); $allMenus = Menu::lists('name', 'id'); $allItems = MenuItem::lists('title', 'id'); //existing menus foreach ($data['menus'] as $i => $menu) { $m = Menu::updateOrCreate(['id' => $i], array('name' => $menu, 'link' => $data['mlinks'][$i], 'sort_id' => $data['msorts'][$i])); if (isset($data['imenus'][$i])) { foreach ($data['imenus'][$i] as $k => $im) { $sm = MenuItem::updateOrCreate(['id' => $k], array('title' => $im, 'link' => $data['ilinks'][$i][$k], 'sort_id' => $data['isorts'][$i][$k])); unset($allItems[$k]); } } if (isset($data['submenus'][$i])) { foreach ($data['submenus'][$i] as $k => $sb) { MenuItem::create(array('menu_id' => $i, 'title' => $sb, 'link' => $data['sublinks'][$i][$k], 'sort_id' => $data['subsorts'][$i][$k])); } } unset($allMenus[$i]); } //new menus if (isset($data['newmenus'])) { foreach ($data['newmenus'] as $i => $nmenu) { $m = Menu::create(array('name' => $nmenu, 'link' => $data['newlinks'][$i], 'sort_id' => $data['newsorts'][$i])); if (isset($data['submenus'][$i])) { foreach ($data['submenus'][$i] as $k => $im) { $sm = MenuItem::create(array('menu_id' => $m->id, 'title' => $im, 'link' => $data['sublinks'][$i][$k], 'sort_id' => $data['subsorts'][$i][$k])); } unset($data['submenus'][$i]); unset($allItems[$i]); } } //new submenus of exising menus foreach ($data['submenus'] as $k => $im) { foreach ($data['submenus'][$k] as $i => $sb) { MenuItem::create(array('menu_id' => $k, 'title' => $sb, 'link' => $data['sublinks'][$k][$i], 'sort_id' => $data['subsorts'][$k][$i])); } } } foreach ($allItems as $i => $title) { MenuItem::where('id', '=', $i)->delete(); } foreach ($allMenus as $m => $name) { Menu::where('id', '=', $m)->delete(); } if (Request::ajax()) { return Response::json('success'); } return View::make('admin.settings'); }