Пример #1
0
 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');
     }
 }
 public function destroy($id)
 {
     $ItemCategories = ItemCategories::findOrFail($id);
     $items = Items::where(['category_id' => $id])->get();
     Helper::add($id, 'deleted items category ' . $ItemCategories->title);
     if (count($items) > 0) {
         $category = ItemCategories::where(['title' => 'Uncategorized'])->first();
         if (!$category) {
             $category = ItemCategories::create(['title' => 'Uncategorized']);
         }
         Items::where(['category_id' => $id])->update(['category_id' => $category->id]);
     }
     if ($ItemCategories->title == 'Uncategorized' && count($items) > 0) {
     } else {
         $ItemCategories->delete();
     }
     Session::flash('flash_message', $this->title . ' successfully deleted!');
     return Redirect::action('ItemCategoriesController@index');
 }
Пример #3
0
 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]);
 }
Пример #4
0
 function getItemsByCategory($id)
 {
     $items = Items::where('category_id', $id)->get();
     return $items;
 }