Exemplo n.º 1
0
 public function testAccessoryAdd()
 {
     $accessory = factory(Accessory::class, 'accessory')->make();
     $values = ['name' => $accessory->name, 'category_id' => $accessory->category_id, 'qty' => $accessory->qty];
     Accessory::create($values);
     $this->tester->seeRecord('accessories', $values);
 }
Exemplo n.º 2
0
 /**
  * Exports the accessories to CSV
  *
  * @deprecated Server-side exports have been replaced by datatables export since v2.
  * @author [A. Gianotto] [<*****@*****.**>]
  * @see ManufacturersController::getDatatable() method that generates the JSON response
  * @since [v1.0]
  * @return \Illuminate\Http\Response
  */
 public function exportAccessoryReport()
 {
     $accessories = Accessory::orderBy('created_at', 'DESC')->get();
     $rows = array();
     $header = array(trans('admin/accessories/table.title'), trans('admin/accessories/general.accessory_category'), trans('admin/accessories/general.total'), trans('admin/accessories/general.remaining'));
     $header = array_map('trim', $header);
     $rows[] = implode($header, ', ');
     // Row per accessory
     foreach ($accessories as $accessory) {
         $row = array();
         $row[] = e($accessory->accessory_name);
         $row[] = e($accessory->accessory_category);
         $row[] = e($accessory->total);
         $row[] = e($accessory->remaining);
         $rows[] = implode($row, ',');
     }
     $csv = implode($rows, "\n");
     $response = Response::make($csv, 200);
     $response->header('Content-Type', 'text/csv');
     $response->header('Content-disposition', 'attachment;filename=report.csv');
     return $response;
 }
Exemplo n.º 3
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     if ($this->confirm("\n****************************************************\nTHIS WILL DELETE ALL OF THE DATA IN YOUR DATABASE. \nThere is NO undo. This WILL destroy ALL of your data. \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]")) {
         if ($this->option('soft')) {
             Accessory::getQuery()->delete();
             Asset::getQuery()->delete();
             Category::getQuery()->delete();
             Company::getQuery()->delete();
             Component::getQuery()->delete();
             Consumable::getQuery()->delete();
             Depreciation::getQuery()->delete();
             License::getQuery()->delete();
             LicenseSeat::getQuery()->delete();
             Location::getQuery()->delete();
             Manufacturer::getQuery()->delete();
             AssetModel::getQuery()->delete();
             Statuslabel::getQuery()->delete();
             Supplier::getQuery()->delete();
             Group::getQuery()->delete();
             DB::statement('delete from accessories_users');
             DB::statement('delete from asset_logs');
             DB::statement('delete from asset_maintenances');
             DB::statement('delete from asset_uploads');
             DB::statement('delete from consumables_users');
             DB::statement('delete from custom_field_custom_fieldset');
             DB::statement('delete from custom_fields');
             DB::statement('delete from custom_fieldsets');
             DB::statement('delete from components_assets');
             DB::statement('delete from password_resets');
             DB::statement('delete from requested_assets');
             DB::statement('delete from requests');
             DB::statement('delete from throttle');
             DB::statement('delete from users_groups');
             DB::statement('delete from users WHERE id!=1');
         } else {
             \DB::statement('drop table IF EXISTS accessories_users');
             \DB::statement('drop table IF EXISTS accessories');
             \DB::statement('drop table IF EXISTS asset_logs');
             \DB::statement('drop table IF EXISTS asset_maintenances');
             \DB::statement('drop table IF EXISTS asset_uploads');
             \DB::statement('drop table IF EXISTS assets');
             \DB::statement('drop table IF EXISTS categories');
             \DB::statement('drop table IF EXISTS companies');
             \DB::statement('drop table IF EXISTS consumables_users');
             \DB::statement('drop table IF EXISTS consumables');
             \DB::statement('drop table IF EXISTS custom_field_custom_fieldset');
             \DB::statement('drop table IF EXISTS custom_fields');
             \DB::statement('drop table IF EXISTS custom_fieldsets');
             \DB::statement('drop table IF EXISTS depreciations');
             \DB::statement('drop table IF EXISTS groups');
             \DB::statement('drop table IF EXISTS history');
             \DB::statement('drop table IF EXISTS components');
             \DB::statement('drop table IF EXISTS components_assets');
             \DB::statement('drop table IF EXISTS license_seats');
             \DB::statement('drop table IF EXISTS licenses');
             \DB::statement('drop table IF EXISTS locations');
             \DB::statement('drop table IF EXISTS manufacturers');
             \DB::statement('drop table IF EXISTS models');
             \DB::statement('drop table IF EXISTS migrations');
             \DB::statement('drop table IF EXISTS password_resets');
             \DB::statement('drop table IF EXISTS requested_assets');
             \DB::statement('drop table IF EXISTS requests');
             \DB::statement('drop table IF EXISTS settings');
             \DB::statement('drop table IF EXISTS status_labels');
             \DB::statement('drop table IF EXISTS suppliers');
             \DB::statement('drop table IF EXISTS throttle');
             \DB::statement('drop table IF EXISTS users_groups');
             \DB::statement('drop table IF EXISTS users');
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Create an accessory if a duplicate does not exist
  *
  * @author Daniel Melzter
  * @since 3.0
  * @param $item array
  */
 public function createAccessoryIfNotExists(array $item)
 {
     $this->log("Creating Accessory");
     foreach ($this->accessories as $tempaccessory) {
         if (strcasecmp($tempaccessory->name, $item["item_name"]) == 0) {
             $this->log('A matching Accessory ' . $item["item_name"] . ' already exists.  ');
             // FUTURE: Adjust quantity on import maybe?
             return;
         }
     }
     $accessory = new Accessory();
     $accessory->name = $item["item_name"];
     if (!empty($item["purchase_date"])) {
         $accessory->purchase_date = $item["purchase_date"];
     } else {
         $accessory->purchase_date = null;
     }
     if (!empty($item["purchase_cost"])) {
         $accessory->purchase_cost = number_format(e($item["purchase_cost"]), 2);
     } else {
         $accessory->purchase_cost = 0.0;
     }
     if ($item["location"]) {
         $accessory->location_id = $item["location"]->id;
     }
     $accessory->user_id = $this->option('user_id');
     if ($item["company"]) {
         $accessory->company_id = $item["company"]->id;
     }
     $accessory->order_number = $item["order_number"];
     if ($item["category"]) {
         $accessory->category_id = $item["category"]->id;
     }
     //TODO: Implement
     //		$accessory->notes = e($item_notes);
     $accessory->requestable = filter_var($item["requestable"], FILTER_VALIDATE_BOOLEAN);
     //Must have at least zero of the item if we import it.
     if ($item["quantity"] > -1) {
         $accessory->qty = $item["quantity"];
     } else {
         $accessory->qty = 1;
     }
     if (!$this->option('testrun')) {
         if ($accessory->save()) {
             $this->log('Accessory ' . $item["item_name"] . ' was created');
             // $this->comment('Accessory ' . $item["item_name"] . ' was created');
         } else {
             $this->jsonError('Accessory', $accessory->getErrors());
         }
     } else {
         $this->log('TEST RUN - Accessory  ' . $item["item_name"] . ' not created');
     }
 }
Exemplo n.º 5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $force = $this->option('force');
     if ($this->confirm("\n****************************************************\nTHIS WILL PURGE ALL SOFT-DELETED ITEMS IN YOUR SYSTEM. \nThere is NO undo. This WILL permanently destroy \nALL of your deleted data. \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]") || $force == 'true') {
         /**
          * Delete assets
          */
         $assets = Asset::whereNotNull('deleted_at')->withTrashed()->get();
         $assetcount = $assets->count();
         $this->info($assets->count() . ' assets purged.');
         $asset_assoc = 0;
         $asset_maintenances = 0;
         foreach ($assets as $asset) {
             $this->info('- Asset "' . $asset->showAssetName() . '" deleted.');
             $asset_assoc += $asset->assetlog()->count();
             $asset->assetlog()->forceDelete();
             $asset_maintenances += $asset->assetmaintenances()->count();
             $asset->assetmaintenances()->forceDelete();
             $asset->forceDelete();
         }
         $this->info($asset_assoc . ' corresponding log records purged.');
         $this->info($asset_maintenances . ' corresponding maintenance records purged.');
         $locations = Location::whereNotNull('deleted_at')->withTrashed()->get();
         $this->info($locations->count() . ' locations purged.');
         foreach ($locations as $location) {
             $this->info('- Location "' . $location->name . '" deleted.');
             $location->forceDelete();
         }
         $accessories = Accessory::whereNotNull('deleted_at')->withTrashed()->get();
         $accessory_assoc = 0;
         $this->info($accessories->count() . ' accessories purged.');
         foreach ($accessories as $accessory) {
             $this->info('- Accessory "' . $accessory->name . '" deleted.');
             $accessory_assoc += $accessory->assetlog()->count();
             $accessory->assetlog()->forceDelete();
             $accessory->forceDelete();
         }
         $this->info($accessory_assoc . ' corresponding log records purged.');
         $consumables = Consumable::whereNotNull('deleted_at')->withTrashed()->get();
         $this->info($consumables->count() . ' consumables purged.');
         foreach ($consumables as $consumable) {
             $this->info('- Consumable "' . $consumable->name . '" deleted.');
             $consumable->assetlog()->forceDelete();
             $consumable->forceDelete();
         }
         $components = Component::whereNotNull('deleted_at')->withTrashed()->get();
         $this->info($components->count() . ' components purged.');
         foreach ($components as $component) {
             $this->info('- Component "' . $component->name . '" deleted.');
             $component->assetlog()->forceDelete();
             $component->forceDelete();
         }
         $licenses = License::whereNotNull('deleted_at')->withTrashed()->get();
         $this->info($licenses->count() . ' licenses purged.');
         foreach ($licenses as $license) {
             $this->info('- License "' . $license->name . '" deleted.');
             $license->assetlog()->forceDelete();
             $license->licenseseats()->forceDelete();
             $license->forceDelete();
         }
         $models = AssetModel::whereNotNull('deleted_at')->withTrashed()->get();
         $this->info($models->count() . ' asset models purged.');
         foreach ($models as $model) {
             $this->info('- Asset Model "' . $model->name . '" deleted.');
             $model->forceDelete();
         }
         $categories = Category::whereNotNull('deleted_at')->withTrashed()->get();
         $this->info($categories->count() . ' categories purged.');
         foreach ($categories as $category) {
             $this->info('- Category "' . $category->name . '" deleted.');
             $category->forceDelete();
         }
         $suppliers = Supplier::whereNotNull('deleted_at')->withTrashed()->get();
         $this->info($suppliers->count() . ' suppliers purged.');
         foreach ($suppliers as $supplier) {
             $this->info('- Supplier "' . $supplier->name . '" deleted.');
             $supplier->forceDelete();
         }
         $users = User::whereNotNull('deleted_at')->where('show_in_list', '!=', '0')->withTrashed()->get();
         $this->info($users->count() . ' users purged.');
         $user_assoc = 0;
         foreach ($users as $user) {
             $this->info('- User "' . $user->username . '" deleted.');
             $user_assoc += $user->userlog()->count();
             $user->userlog()->forceDelete();
             $user->forceDelete();
         }
         $this->info($user_assoc . ' corresponding user log records purged.');
         $manufacturers = Manufacturer::whereNotNull('deleted_at')->withTrashed()->get();
         $this->info($manufacturers->count() . ' manufacturers purged.');
         foreach ($manufacturers as $manufacturer) {
             $this->info('- Manufacturer "' . $manufacturer->name . '" deleted.');
             $manufacturer->forceDelete();
         }
         $status_labels = Statuslabel::whereNotNull('deleted_at')->withTrashed()->get();
         $this->info($status_labels->count() . ' status labels purged.');
         foreach ($status_labels as $status_label) {
             $this->info('- Status Label "' . $status_label->name . '" deleted.');
             $status_label->forceDelete();
         }
     } else {
         $this->info('Action canceled. Nothing was purged.');
     }
 }
Exemplo n.º 6
0
 /**
  * Generates the JSON response for accessory detail view.
  *
  * Example:
  * <code>
  * {
  * "rows": [
  * {
  * "actions": "(link to available actions)",
  * "name": "(link to user)"
  * }
  * ],
  * "total": 1
  * }
  * </code>
  *
  * The names of the fields in the returns JSON correspond directly to the the
  * names of the fields in the bootstrap-tables in the view.
  *
  * For debugging, see at /api/accessories/$accessoryID/view
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @param  int  $accessoryId
  * @return string JSON containing accessories and their associated atrributes.
  **/
 public function getDataView(Request $request, $accessoryID)
 {
     $accessory = Accessory::find($accessoryID);
     if (!Company::isCurrentUserHasAccess($accessory)) {
         return ['total' => 0, 'rows' => []];
     }
     $accessory_users = $accessory->users;
     $count = $accessory_users->count();
     $rows = array();
     foreach ($accessory_users as $user) {
         $actions = '<a href="' . route('checkin/accessory', $user->pivot->id) . '" class="btn btn-info btn-sm">Checkin</a>';
         $rows[] = array('name' => (string) link_to('/admin/users/' . $user->id . '/view', e($user->fullName())), 'actions' => $actions);
     }
     $data = array('total' => $count, 'rows' => $rows);
     return $data;
 }
Exemplo n.º 7
0
 /**
  * This nasty little method gets the low inventory info for the
  * alert dropdown
  **/
 public static function checkLowInventory()
 {
     $consumables = Consumable::with('users')->whereNotNull('min_amt')->get();
     $accessories = Accessory::with('users')->whereNotNull('min_amt')->get();
     $components = Component::with('assets')->whereNotNull('min_amt')->get();
     $avail_consumables = 0;
     $items_array = array();
     $all_count = 0;
     foreach ($consumables as $consumable) {
         $avail = $consumable->numRemaining();
         if ($avail < $consumable->min_amt + \App\Models\Setting::getSettings()->alert_threshold) {
             if ($consumable->total_qty > 0) {
                 $percent = number_format($consumable->numRemaining() / $consumable->total_qty * 100, 0);
             } else {
                 $percent = 100;
             }
             $items_array[$all_count]['id'] = $consumable->id;
             $items_array[$all_count]['name'] = $consumable->name;
             $items_array[$all_count]['type'] = 'consumables';
             $items_array[$all_count]['percent'] = $percent;
             $items_array[$all_count]['remaining'] = $consumable->numRemaining();
             $items_array[$all_count]['min_amt'] = $consumable->min_amt;
             $all_count++;
         }
     }
     foreach ($accessories as $accessory) {
         $avail = $accessory->numRemaining();
         if ($avail < $accessory->min_amt + \App\Models\Setting::getSettings()->alert_threshold) {
             if ($accessory->total_qty > 0) {
                 $percent = number_format($accessory->numRemaining() / $accessory->total_qty * 100, 0);
             } else {
                 $percent = 100;
             }
             $items_array[$all_count]['id'] = $accessory->id;
             $items_array[$all_count]['name'] = $accessory->name;
             $items_array[$all_count]['type'] = 'accessories';
             $items_array[$all_count]['percent'] = $percent;
             $items_array[$all_count]['remaining'] = $accessory->numRemaining();
             $items_array[$all_count]['min_amt'] = $accessory->min_amt;
             $all_count++;
         }
     }
     foreach ($components as $component) {
         $avail = $component->numRemaining();
         if ($avail < $component->min_amt + \App\Models\Setting::getSettings()->alert_threshold) {
             if ($component->total_qty > 0) {
                 $percent = number_format($component->numRemaining() / $component->total_qty * 100, 0);
             } else {
                 $percent = 100;
             }
             $items_array[$all_count]['id'] = $component->id;
             $items_array[$all_count]['name'] = $component->name;
             $items_array[$all_count]['type'] = 'components';
             $items_array[$all_count]['percent'] = $percent;
             $items_array[$all_count]['remaining'] = $component->numRemaining();
             $items_array[$all_count]['min_amt'] = $component->min_amt;
             $all_count++;
         }
     }
     return $items_array;
 }
Exemplo n.º 8
0
 public function getAcceptAsset($logID = null)
 {
     if (!($findlog = DB::table('asset_logs')->where('id', '=', $logID)->first())) {
         echo 'no record';
         //return redirect()->to('account')->with('error', trans('admin/hardware/message.does_not_exist'));
     }
     $user = Auth::user();
     if ($user->id != $findlog->checkedout_to) {
         return redirect()->to('account/view-assets')->with('error', trans('admin/users/message.error.incorrect_user_accepted'));
     }
     // Asset
     if ($findlog->asset_id != '' && $findlog->asset_type == 'hardware') {
         $item = Asset::find($findlog->asset_id);
         // software
     } elseif ($findlog->asset_id != '' && $findlog->asset_type == 'software') {
         $item = License::find($findlog->asset_id);
         // accessories
     } elseif ($findlog->accessory_id != '') {
         $item = Accessory::find($findlog->accessory_id);
         // consumable
     } elseif ($findlog->consumable_id != '') {
         $item = Consumable::find($findlog->consumable_id);
         // components
     } elseif ($findlog->component_id != '') {
         $item = Component::find($findlog->component_id);
     }
     // Check if the asset exists
     if (is_null($item)) {
         // Redirect to the asset management page
         return redirect()->to('account')->with('error', trans('admin/hardware/message.does_not_exist'));
     } elseif (!Company::isCurrentUserHasAccess($item)) {
         return redirect()->route('requestable-assets')->with('error', trans('general.insufficient_permissions'));
     } else {
         return View::make('account/accept-asset', compact('item'))->with('findlog', $findlog);
     }
 }
Exemplo n.º 9
0
 /**
  * Create an accessory if a duplicate does not exist
  *
  * @author Daniel Melzter
  * @since 3.0
  * @param $item array
  */
 public function createAccessoryIfNotExists(array $item)
 {
     $accessory = null;
     $editingAccessory = false;
     $this->log("Creating Accessory");
     foreach ($this->accessories as $tempaccessory) {
         if (strcasecmp($tempaccessory->name, $item["item_name"]) == 0) {
             $this->log('A matching Accessory ' . $item["item_name"] . ' already exists.  ');
             if (!$this->option('update')) {
                 $this->log("Skipping accessory.");
                 return;
             }
             $this->log('Updating matching accessory with new values');
             $editingAccessory = true;
             $accessory = $tempaccessory;
         }
     }
     if (is_null($accessory)) {
         $this->log("No Matching Accessory, Creating a new one");
         $accessory = new Accessory();
     }
     if (!$editingAccessory) {
         $accessory->name = $item["item_name"];
     }
     if (!empty($item["purchase_date"])) {
         $accessory->purchase_date = $item["purchase_date"];
     } else {
         $accessory->purchase_date = null;
     }
     if (!empty($item["purchase_cost"])) {
         $accessory->purchase_cost = Helper::ParseFloat($item["purchase_cost"]);
     }
     if ($item["location"]) {
         $accessory->location_id = $item["location"]->id;
     }
     $accessory->user_id = $this->option('user_id');
     if ($item["company"]) {
         $accessory->company_id = $item["company"]->id;
     }
     if (!empty($item["order_number"])) {
         $accessory->order_number = $item["order_number"];
     }
     if ($item["category"]) {
         $accessory->category_id = $item["category"]->id;
     }
     //TODO: Implement
     //		$accessory->notes = e($item_notes);
     if (!empty($item["requestable"])) {
         $accessory->requestable = filter_var($item["requestable"], FILTER_VALIDATE_BOOLEAN);
     }
     //Must have at least zero of the item if we import it.
     if (!empty($item["quantity"])) {
         if ($item["quantity"] > -1) {
             $accessory->qty = $item["quantity"];
         } else {
             $accessory->qty = 1;
         }
     }
     if (!$this->option('testrun')) {
         if ($accessory->save()) {
             $this->log('Accessory ' . $item["item_name"] . ' was created');
             // $this->comment('Accessory ' . $item["item_name"] . ' was created');
         } else {
             $this->jsonError('Accessory', $accessory->getErrors());
         }
     } else {
         $this->log('TEST RUN - Accessory  ' . $item["item_name"] . ' not created');
     }
 }
Exemplo n.º 10
0
 public function run()
 {
     Accessory::truncate();
     factory(Accessory::class, 'accessory', 15)->create();
 }