Exemplo n.º 1
0
 public function testConsumableAdd()
 {
     $consumable = factory(Consumable::class, 'consumable')->make();
     $values = ['name' => $consumable->name, 'qty' => $consumable->qty, 'category_id' => $consumable->category_id, 'company_id' => $consumable->company_id];
     Consumable::create($values);
     $this->tester->seeRecord('consumables', $values);
 }
Exemplo n.º 2
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.º 3
0
 /**
  * Returns a JSON response containing details on the users associated with this consumable.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @see ConsumablesController::getView() method that returns the form.
  * @since [v1.0]
  * @param int $consumableId
  * @return View
  */
 public function getDataView($consumableId)
 {
     //$consumable = Consumable::find($consumableID);
     $consumable = Consumable::with(array('consumableAssigments' => function ($query) {
         $query->orderBy('created_at', 'DESC');
     }, 'consumableAssigments.admin' => function ($query) {
     }, 'consumableAssigments.user' => function ($query) {
     }))->find($consumableId);
     //  $consumable->load('consumableAssigments.admin','consumableAssigments.user');
     if (!Company::isCurrentUserHasAccess($consumable)) {
         return ['total' => 0, 'rows' => []];
     }
     $rows = array();
     foreach ($consumable->consumableAssigments as $consumable_assignment) {
         $rows[] = array('name' => (string) link_to('/admin/users/' . $consumable_assignment->user->id . '/view', e($consumable_assignment->user->fullName())), 'created_at' => $consumable_assignment->created_at->format('Y-m-d H:i:s') == '-0001-11-30 00:00:00' ? '' : $consumable_assignment->created_at->format('Y-m-d H:i:s'), 'admin' => $consumable_assignment->admin ? e($consumable_assignment->admin->fullName()) : '');
     }
     $consumableCount = $consumable->users->count();
     $data = array('total' => $consumableCount, 'rows' => $rows);
     return $data;
 }
Exemplo n.º 4
0
 /**
  * Create a consumable if a duplicate does not exist
  *
  * @author Daniel Melzter
  * @since 3.0
  * @param $item array
  */
 public function createConsumableIfNotExists(array $item)
 {
     $this->log("Creating Consumable");
     foreach ($this->consumables as $tempconsumable) {
         if (strcasecmp($tempconsumable->name, $item["item_name"]) == 0) {
             $this->log("A matching consumable " . $item["item_name"] . " already exists");
             //TODO: Adjust quantity if different maybe?
             return;
         }
     }
     $consumable = new Consumable();
     $consumable->name = $item["item_name"];
     if (!empty($item["purchase_date"])) {
         $consumable->purchase_date = $item["purchase_date"];
     } else {
         $consumable->purchase_date = null;
     }
     if (!empty($item["purchase_cost"])) {
         $consumable->purchase_cost = number_format(e($item["purchase_cost"]), 2);
     } else {
         $consumable->purchase_cost = 0.0;
     }
     $consumable->location_id = $item["location"]->id;
     $consumable->user_id = $this->option('user_id');
     $consumable->company_id = $item["company"]->id;
     $consumable->order_number = $item["order_number"];
     $consumable->category_id = $item["category"]->id;
     // TODO:Implement
     //$consumable->notes= e($item_notes);
     $consumable->requestable = filter_var($item["requestable"], FILTER_VALIDATE_BOOLEAN);
     if ($item["quantity"] > -1) {
         $consumable->qty = $item["quantity"];
     } else {
         $consumable->qty = 1;
     }
     if (!$this->option("testrun")) {
         if ($consumable->save()) {
             $this->log("Consumable " . $item["item_name"] . ' was created');
             // $this->comment("Consumable " . $item["item_name"] . ' was created');
         } else {
             $this->jsonError('Consumable', $consumable->getErrors());
         }
     } else {
         $this->log('TEST RUN - Consumable ' . $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
 /**
  * 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.º 7
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.º 8
0
 /**
  * Create a consumable if a duplicate does not exist
  *
  * @author Daniel Melzter
  * @since 3.0
  * @param $item array
  */
 public function createConsumableIfNotExists(array $item)
 {
     $consumable = null;
     $editingConsumable = false;
     $this->log("Creating Consumable");
     foreach ($this->consumables as $tempconsumable) {
         if (strcasecmp($tempconsumable->name, $item["item_name"]) == 0) {
             $this->log("A matching consumable " . $item["item_name"] . " already exists");
             if (!$this->option('update')) {
                 $this->log("Skipping consumable.");
                 return;
             }
             $this->log('Updating matching consumable with new values');
             $editingConsumable = true;
             $consumable = $tempconsumable;
         }
     }
     if (is_null($consumable)) {
         $this->log("No matching consumable, creating one");
         $consumable = new Consumable();
     }
     if (!$editingConsumable) {
         $consumable->name = $item["item_name"];
     }
     if (!empty($item["purchase_date"])) {
         $consumable->purchase_date = $item["purchase_date"];
     } else {
         $consumable->purchase_date = null;
     }
     if (!empty($item["purchase_cost"])) {
         $consumable->purchase_cost = Helper::ParseFloat($item["purchase_cost"]);
     }
     if ($item["location"]) {
         $consumable->location_id = $item["location"]->id;
     }
     $consumable->user_id = $this->option('user_id');
     if ($item["company"]) {
         $consumable->company_id = $item["company"]->id;
     }
     if (!empty($item["order_number"])) {
         $consumable->order_number = $item["order_number"];
     }
     if ($item["category"]) {
         $consumable->category_id = $item["category"]->id;
     }
     // TODO:Implement
     //$consumable->notes= e($item_notes);
     if (!empty($item["requestable"])) {
         $consumable->requestable = filter_var($item["requestable"], FILTER_VALIDATE_BOOLEAN);
     }
     if (!empty($item["quantity"])) {
         if ($item["quantity"] > -1) {
             $consumable->qty = $item["quantity"];
         } else {
             $consumable->qty = 1;
         }
     }
     if (!$this->option("testrun")) {
         // dd($consumable);
         if ($consumable->save()) {
             $this->log("Consumable " . $item["item_name"] . ' was created');
             // $this->comment("Consumable " . $item["item_name"] . ' was created');
         } else {
             $this->jsonError('Consumable', $consumable->getErrors());
         }
     } else {
         $this->log('TEST RUN - Consumable ' . $item['item_name'] . ' not created');
     }
 }
Exemplo n.º 9
0
 public function run()
 {
     Consumable::truncate();
     factory(Consumable::class, 'consumable', 25)->create();
 }