public function action_edit($id = null)
 {
     if ($inventory = Model_Inventory::find($id)) {
         $val = Model_Inventory::validate('edit');
         if ($val->run()) {
             $inventory->description = Input::post('description');
             $inventory->barcode = Input::post('barcode');
             $inventory->short_code = Input::post('short_code');
             $inventory->inventory_units_id = Input::post('inventory_units_id');
             $inventory->warning_level = Input::post('warning_level');
             if ($inventory->save()) {
                 Session::set_flash('success', e('Updated inventory #' . $id));
                 Response::redirect('admin/inventory/view/' . $inventory->id);
             } else {
                 Session::set_flash('error', e('Could not update inventory #' . $id));
             }
         } else {
             if (Input::method() == 'POST') {
                 $inventory->description = $val->validated('description');
                 $inventory->barcode = $val->validated('barcode');
                 $inventory->short_code = $val->validated('short_code');
                 $inventory->inventory_units_id = $val->validated('inventory_units_id');
                 $inventory->warning_level = $val->validated('warning_level');
                 Session::set_flash('error', $val->error());
             }
             $this->template->set_global('inventory', $inventory, false);
         }
         $this->template->set_global('inventory_units', Model_Inventory_Unit::find('all', array('order_by' => array(array('name', 'asc')))));
         $this->template->title = "Inventory » " . $inventory->description . " » Edit";
         $this->template->content = View::forge('admin/inventory/edit');
     } else {
         Fuel\Core\Session::set_flash('error', 'Cannot find the selected item');
         \Fuel\Core\Response::redirect_back('admin/inventory');
     }
 }
 public function action_delete($id = null)
 {
     if ($inventory_unit = Model_Inventory_Unit::find($id)) {
         $inventory_unit->delete();
         Session::set_flash('success', e('Deleted inventory_unit #' . $id));
     } else {
         Session::set_flash('error', e('Could not delete inventory_unit #' . $id));
     }
     Response::redirect('admin/inventory/units');
 }
 public function get_inventory_unit()
 {
     return !is_null($this->inventory_unit) ? $this->inventory_unit : Model_Inventory_Unit::forge(array('id' => 0));
 }