Пример #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('units')->delete();
     //weight unit
     $unit = new Units();
     $unit->fill(array('title' => 'g', 'factor' => 1, 'default' => 1, 'group_id' => 1, 'disable_delete' => 1));
     $unit->save();
     //capacity unit
     $unit = new Units();
     $unit->fill(array('title' => 'ml', 'factor' => 1, 'default' => 1, 'group_id' => 2, 'disable_delete' => 1));
     $unit->save();
     //units unit
     $unit = new Units();
     $unit->fill(array('title' => 'unit', 'factor' => 1, 'default' => 1, 'group_id' => 3, 'disable_delete' => 1));
     $unit->save();
 }
Пример #2
0
 public function edit($id)
 {
     $last_tree_categories = ItemCategories::select('item_categories.*')->leftJoin('item_categories AS c2', 'item_categories.id', '=', 'c2.parent_id')->whereNull('c2.id')->lists('title', 'id');
     foreach ($last_tree_categories as $key => $category) {
         $last_tree_categories[$key] = $last_tree_categories[$key] . " (id:{$key})";
     }
     return view('Items.edit')->with(array('title' => $this->title, 'categories' => $last_tree_categories, 'Items' => Items::findOrFail($id), 'units' => Units::lists('title', 'id')));
 }
Пример #3
0
 public function destroy($id)
 {
     $Units = Units::findOrFail($id);
     if ($Units->disable_delete) {
         Session::flash('flash_message', 'This ' . $this->title . ' is not deletable!');
     } else {
         Helper::add($id, 'deleted unit ' . $Units->title . ' (ID ' . $Units->id . ')');
         if ($Units->default) {
             $first = Units::where('id', '!=', $id)->where(['group_id' => $Units->group_id])->first();
             if ($first) {
                 $first->update(['default' => 1]);
                 $group = UnitGroups::findOrFail($first->group_id);
                 Units::where(['group_id' => $Units->group_id])->update(['factor' => DB::raw('factor/' . $first->factor)]);
                 Helper::add($id, 'changed default unit to ' . $Units->title . ' (ID ' . $Units->id . ') in group ' . $group->title . ' (ID ' . $group->id . ')');
             }
         }
         $Units->delete();
         Session::flash('flash_message', $this->title . ' successfully deleted!');
     }
     return Redirect::action('UnitsController@index');
 }
Пример #4
0
 public function update($id, Request $request)
 {
     $Units = Units::findOrFail($id);
     $item = Items::findOrFail($Units->item_id);
     $this->validate($request, ['title' => 'required|unique:units|max:100']);
     $input = $request->all();
     Helper::add($id, 'updated unit ' . $Units->title . ' for item ID ' . $input['item_id']);
     if (array_key_exists('default', $input)) {
         ItemUnits::where(['default' => 1, 'item_id' => $input['item_id']])->where('id', '!=', $id)->update(['default' => 0]);
         ItemUnits::where(['item_id' => $input['item_id']])->update(['factor' => DB::raw('factor/' . $input['factor'])]);
         Helper::add($id, 'changed item ' . $item->title . '(ID ' . $input['item_id'] . ') default unit to ' . $Units->title);
         StockItem::where(['item_id' => $input['item_id']])->update(['stock' => DB::raw('stock/' . $input['factor'])]);
         RecipeItems::where(['item_id' => $input['item_id']])->update(['value' => DB::raw('value/' . $input['factor'])]);
         Menu::where(['item_id' => $input['item_id']])->update(['value' => DB::raw('value/' . $input['factor'])]);
         ItemPurchases::where(['item_id' => $input['item_id']])->update(['value' => DB::raw('value/' . $input['factor'])]);
         StockCheck::where(['item_id' => $input['item_id']])->update(['before' => DB::raw('`before` / ' . $input['factor']), 'after' => DB::raw('`after` / ' . $input['factor'])]);
         $input['default'] = 1;
     }
     $Units->fill($input)->save();
     Session::flash('flash_message', $this->title . ' successfully added!');
     return Redirect::action('UnitsController@index');
 }
Пример #5
0
 public function update($id, Request $request)
 {
     $Units = Units::findOrFail($id);
     $this->validate($request, ['title' => 'required|unique:units|max:100']);
     $input = $request->all();
     if (array_key_exists('default', $input)) {
         ItemUnits::where(['default' => 1, 'item_id' => $input['item_id']])->where('id', '!=', $id)->update(['default' => 0]);
         ItemUnits::where(['item_id' => $input['item_id']])->update(['factor' => DB::raw('factor/' . $input['factor'])]);
         $input['default'] = 1;
     }
     $Units->fill($input)->save();
     Session::flash('flash_message', $this->title . ' successfully added!');
     return Redirect::action('UnitsController@index');
 }