public function index() { $currentPeriodId = Helper::currentPeriodId(); if ($currentPeriodId) { $search = Input::get('q'); $filter = Input::get('filter'); $not_updated = Items::select('count(*)')->whereRaw('not exists (select 1 from stock_items where stock_items.stock_period_id = ' . $currentPeriodId . ' and stock_items.item_id = items.id)')->count(); $items = $search ? Items::where('title', 'LIKE', '%' . $search . '%')->get() : ($filter == 'without_stock' ? Items::select('items.*')->whereRaw('not exists (select 1 from stock_items where stock_items.stock_period_id = ' . $currentPeriodId . ' and stock_items.item_id = items.id)')->get() : Items::all()); if (count($items) == 1 && $search) { return redirect()->action('StockCheckController@edit', ['item_id' => $items->first()->id]); } $last_period = StockPeriods::where(['number' => StockPeriods::findOrFail($currentPeriodId)->number - 1])->get(); return view('StockCheck.index')->with(array('title' => $this->title, 'items' => $search ? Items::where('title', 'LIKE', '%' . $search . '%')->take(10)->get() : ($filter == 'without_stock' ? Items::select('items.*')->whereRaw('not exists (select 1 from stock_items where stock_items.stock_period_id = ' . $currentPeriodId . ' and stock_items.item_id = items.id)')->orderBy("updated_at", 'DESC')->get() : Items::orderBy("updated_at", 'DESC')->take(10)->get()), 'item_list' => Items::lists('title'), 'search' => $search, 'period' => $currentPeriodId, 'previous' => count($last_period) > 0 ? $last_period->first()->id : 0, 'filter' => $filter, 'not_updated' => $not_updated)); } else { Session::flash('flash_message', 'You need to start a period first!'); return Redirect::action('StockPeriodsController@index'); } }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $item_purchase = ItemPurchases::findOrFail($id); $purchase = $item_purchase->purchase()->first(); $type = $item_purchase->type; if ($type == 'item') { $items = ItemUnits::orderBy('default', 'DESC')->get(); $items_units = []; foreach ($items as $item) { $items_units['list'][$item->item()->first()->id][] = ['id' => $item->id, 'title' => $item->unit()->first()->title]; $items_units['php_list'][$item->item()->first()->id][$item->id] = $item->unit()->first()->title; $items_units['factors'][$item->id] = $item->factor; $items_units['item_to_unit'][$item->id] = $item->unit()->first()->id; } $select_items = Items::orderBy('title', 'ASC')->lists('title', 'id'); if ($select_items) { return view('ItemPurchases.edit_item')->with(array('title' => $this->title, 'purchase' => $purchase, 'items' => $select_items, 'items_units' => $items_units, 'type' => $type, 'item' => $item_purchase)); } else { Session::flash('flash_message', 'It looks like you have used all possible products in your invoice.'); return Redirect::action('ItemPurchasesController@index', $purchase->id); } } else { return view('ItemPurchases.edit_custom')->with(array('title' => $this->title, 'purchase' => $purchase, 'type' => $type, 'item' => $item_purchase)); } }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $waste = Wastes::findOrFail($id); $currentPeriodId = Helper::defaultPeriodId(); $periods = StockPeriods::all(); $period_list = array(); foreach ($periods as $period) { $period_list[$period->id] = 'Stock #' . $period->number . ' (' . $period->date_from . ' - ' . ($period->id == $currentPeriodId ? 'NOW' : $period->date_to) . ')'; } if (Input::has('stock_period')) { $currentPeriodId = Input::get('stock_period'); } $select_recipes = Recipes::orderBy('title', 'ASC')->lists('title', 'id'); $items = ItemUnits::orderBy('default', 'DESC')->get(); $items_units = []; foreach ($items as $item) { $items_units['list'][$item->item()->first()->id][] = ['id' => $item->id, 'title' => $item->unit()->first()->title]; $items_units['php_list'][$item->item()->first()->id][$item->id] = $item->unit()->first()->title; $items_units['factors'][$item->id] = $item->factor; } $select_items = Items::orderBy('title', 'ASC')->lists('title', 'id'); $select_menus = Menu::orderBy('title', 'ASC')->lists('title', 'id'); $select_reasons = WasteReasons::orderBy('reason', 'ASC')->lists('reason', 'id'); return view('Wastes.edit')->with(array('title' => $this->title, 'recipes' => $select_recipes, 'items' => $select_items, 'items_units' => $items_units, 'menus' => $select_menus, 'period' => $currentPeriodId, 'stocks_list' => $period_list, 'reasons' => $select_reasons, 'waste' => $waste)); }
public function index() { $search = Input::get('q'); $items = $search ? Items::where('title', 'LIKE', '%' . $search . '%')->orderBy('category_id')->get() : Items::orderBy('category_id')->get(); return view('Items.index')->with(['title' => $this->title, 'items' => $items, 'search' => $search]); }
public function assign($id) { $menu = Menu::findOrFail($id); $select_recipes = Recipes::orderBy('title', 'ASC')->lists('title', 'id'); $items = ItemUnits::orderBy('default', 'DESC')->get(); $items_units = []; foreach ($items as $item) { $items_units['list'][$item->item()->first()->id][] = ['id' => $item->id, 'title' => $item->unit()->first()->title]; $items_units['php_list'][$item->item()->first()->id][$item->id] = $item->unit()->first()->title; $items_units['factors'][$item->id] = $item->factor; } $select_items = Items::orderBy('title', 'ASC')->lists('title', 'id'); return view('Menus.assign')->with(array('title' => $this->title, 'item' => $menu, 'recipes' => $select_recipes, 'items' => $select_items, 'items_units' => $items_units)); }