コード例 #1
0
 public function testManufacturerAdd()
 {
     $manufacturers = factory(Manufacturer::class, 'manufacturer')->make();
     $values = ['name' => $manufacturers->name];
     Manufacturer::create($values);
     $this->tester->seeRecord('manufacturers', $values);
 }
コード例 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Manufacturer::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['manufacturer_id' => $this->manufacturer_id, 'flag_active' => $this->flag_active, 'date_added' => $this->date_added, 'date_update' => $this->date_update]);
     $query->andFilterWhere(['like', 'manufacturer_name', $this->manufacturer_name])->andFilterWhere(['like', 'manufacturer_desc', $this->manufacturer_desc]);
     return $dataProvider;
 }
コード例 #3
0
ファイル: PaveIt.php プロジェクト: dmeltzer/snipe-it
 /**
  * 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');
         }
     }
 }
コード例 #4
0
 /**
  * Finds a manufacturer with matching name, otherwise create it.
  *
  * @author Daniel Melzter
  * @since 3.0
  * @param $row array
  * @return Manufacturer
  * @internal param $asset_mfgr string
  */
 public function createOrFetchManufacturer(array $row)
 {
     $asset_mfgr = $this->array_smart_fetch($row, "manufacturer");
     if (empty($asset_mfgr)) {
         $asset_mfgr = 'Unknown';
     }
     $this->log('Manufacturer ID: ' . $asset_mfgr);
     foreach ($this->manufacturers as $tempmanufacturer) {
         if (strcasecmp($tempmanufacturer->name, $asset_mfgr) == 0) {
             $this->log('Manufacturer ' . $asset_mfgr . ' already exists');
             return $tempmanufacturer;
         }
     }
     //Otherwise create a manufacturer.
     $manufacturer = new Manufacturer();
     $manufacturer->name = $asset_mfgr;
     $manufacturer->user_id = $this->option('user_id');
     if (!$this->option('testrun')) {
         if ($manufacturer->save()) {
             $this->manufacturers->add($manufacturer);
             $this->log('Manufacturer ' . $manufacturer->name . ' was created');
             return $manufacturer;
         } else {
             $this->jsonError('Manufacturer "' . $manufacturer->name . '"', $manufacturer->getErrors());
             return $manufacturer;
         }
     } else {
         $this->manufacturers->add($manufacturer);
         return $manufacturer;
     }
 }
コード例 #5
0
ファイル: _form.php プロジェクト: vab777/marts.id_be
    </div><!--/form-group-->
 
    <div class="form-group">
      <label class="col-sm-3 control-label">Category</label>
      <div class="col-sm-6">
          <?php 
echo $form->field($model, 'category_id')->label(false)->dropDownList(ArrayHelper::map(Category::find()->all(), 'category_id', 'category_name'), ['prompt' => 'Select Category Name', 'class' => 'form-control']);
?>
      </div>
    </div><!--/form-group--> 

    <div class="form-group">
      <label class="col-sm-3 control-label">Manufacturer</label>
      <div class="col-sm-6">
        <?php 
echo $form->field($model, 'manufacturer_id')->label(false)->dropDownList(ArrayHelper::map(Manufacturer::find()->all(), 'manufacturer_id', 'manufacturer_name'), ['prompt' => 'Select Manufacturer Name', 'class' => 'form-control']);
?>
      </div>
    </div><!--/form-group--> 

    <div class="form-group">
      <label class="col-sm-3 control-label">UPC Barcode</label>
      <div class="col-sm-6">
        <?php 
echo $form->field($model, 'upc_barcode')->label(false)->textInput(['maxlength' => 12, 'placeholder' => 'Input UPC Barcode.']);
?>
      </div>
    </div><!--/form-group--> 
    
    <div class="form-group">
      <label class="col-sm-3 control-label">ean13 Barcode</label>
コード例 #6
0
 /**
  * Updates an existing Part model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     if (Yii::$app->user->identity && Yii::$app->user->identity->isStaff()) {
         $model = $this->findModel($id);
         $manufacturers = ArrayHelper::map(Manufacturer::find()->all(), 'manufacturer_id', 'manufacturer_name');
         $parametersData = $model->getParametersData($model->role_fk);
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->part_id]);
         } else {
             return $this->render('update', ['model' => $model, 'manufacturers' => $manufacturers, 'role' => $model->role_fk, 'parametersData' => $parametersData]);
         }
     } else {
         throw new \yii\web\HttpException(403, 'STAFF ONLY');
     }
 }
コード例 #7
0
 /**
  * Finds the Manufacturer model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Manufacturer the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Manufacturer::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #8
0
ファイル: Purge.php プロジェクト: stijni/snipe-it
 /**
  * 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.');
     }
 }
コード例 #9
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $filename = $this->argument('filename');
     if (!$this->option('testrun') == 'true') {
         $this->comment('======= Importing Assets from ' . $filename . ' =========');
     } else {
         $this->comment('====== TEST ONLY Asset Import for ' . $filename . ' ====');
         $this->comment('============== NO DATA WILL BE WRITTEN ==============');
     }
     if (!ini_get("auto_detect_line_endings")) {
         ini_set("auto_detect_line_endings", '1');
     }
     $csv = Reader::createFromPath($this->argument('filename'));
     $csv->setNewline("\r\n");
     $csv->setOffset(1);
     $duplicates = '';
     // Loop through the records
     $nbInsert = $csv->each(function ($row) use($duplicates) {
         $status_id = 1;
         // Let's just map some of these entries to more user friendly words
         // User's name
         if (array_key_exists('0', $row)) {
             $user_name = trim($row[0]);
         } else {
             $user_name = '';
         }
         // User's email
         if (array_key_exists('1', $row)) {
             $user_email = trim($row[1]);
         } else {
             $user_email = '';
         }
         // User's email
         if (array_key_exists('2', $row)) {
             $user_username = trim($row[2]);
         } else {
             $user_username = '';
         }
         // Asset Name
         if (array_key_exists('3', $row)) {
             $user_asset_asset_name = trim($row[3]);
         } else {
             $user_asset_asset_name = '';
         }
         // Asset Category
         if (array_key_exists('4', $row)) {
             $user_asset_category = trim($row[4]);
         } else {
             $user_asset_category = '';
         }
         // Asset Name
         if (array_key_exists('5', $row)) {
             $user_asset_name = trim($row[5]);
         } else {
             $user_asset_name = '';
         }
         // Asset Manufacturer
         if (array_key_exists('6', $row)) {
             $user_asset_mfgr = trim($row[6]);
         } else {
             $user_asset_mfgr = '';
         }
         // Asset model number
         if (array_key_exists('7', $row)) {
             $user_asset_modelno = trim($row[7]);
         } else {
             $user_asset_modelno = '';
         }
         // Asset serial number
         if (array_key_exists('8', $row)) {
             $user_asset_serial = trim($row[8]);
         } else {
             $user_asset_serial = '';
         }
         // Asset tag
         if (array_key_exists('9', $row)) {
             $user_asset_tag = trim($row[9]);
         } else {
             $user_asset_tag = '';
         }
         // Asset location
         if (array_key_exists('10', $row)) {
             $user_asset_location = trim($row[10]);
         } else {
             $user_asset_location = '';
         }
         // Asset notes
         if (array_key_exists('11', $row)) {
             $user_asset_notes = trim($row[11]);
         } else {
             $user_asset_notes = '';
         }
         // Asset purchase date
         if (array_key_exists('12', $row)) {
             if ($row[12] != '') {
                 $user_asset_purchase_date = date("Y-m-d 00:00:01", strtotime($row[12]));
             } else {
                 $user_asset_purchase_date = '';
             }
         } else {
             $user_asset_purchase_date = '';
         }
         // Asset purchase cost
         if (array_key_exists('13', $row)) {
             if ($row[13] != '') {
                 $user_asset_purchase_cost = trim($row[13]);
             } else {
                 $user_asset_purchase_cost = '';
             }
         } else {
             $user_asset_purchase_cost = '';
         }
         // Asset Company Name
         if (array_key_exists('14', $row)) {
             if ($row[14] != '') {
                 $user_asset_company_name = trim($row[14]);
             } else {
                 $user_asset_company_name = '';
             }
         } else {
             $user_asset_company_name = '';
         }
         // A number was given instead of a name
         if (is_numeric($user_name)) {
             $this->comment('User ' . $user_name . ' is not a name - assume this user already exists');
             $user_username = '';
             $first_name = '';
             $last_name = '';
             // No name was given
         } elseif ($user_name == '') {
             $this->comment('No user data provided - skipping user creation, just adding asset');
             $first_name = '';
             $last_name = '';
             //$user_username = '';
         } else {
             $user_email_array = User::generateFormattedNameFromFullName($this->option('email_format'), $user_name);
             $first_name = $user_email_array['first_name'];
             $last_name = $user_email_array['last_name'];
             if ($user_email == '') {
                 $user_email = $user_email_array['username'] . '@' . config('app.domain');
             }
             if ($user_username == '') {
                 if ($this->option('username_format') == 'email') {
                     $user_username = $user_email;
                 } else {
                     $user_name_array = User::generateFormattedNameFromFullName($this->option('username_format'), $user_name);
                     $user_username = $user_name_array['username'];
                 }
             }
         }
         $this->comment('Full Name: ' . $user_name);
         $this->comment('First Name: ' . $first_name);
         $this->comment('Last Name: ' . $last_name);
         $this->comment('Username: '******'Email: ' . $user_email);
         $this->comment('Category Name: ' . $user_asset_category);
         $this->comment('Item: ' . $user_asset_name);
         $this->comment('Manufacturer ID: ' . $user_asset_mfgr);
         $this->comment('Model No: ' . $user_asset_modelno);
         $this->comment('Serial No: ' . $user_asset_serial);
         $this->comment('Asset Tag: ' . $user_asset_tag);
         $this->comment('Location: ' . $user_asset_location);
         $this->comment('Purchase Date: ' . $user_asset_purchase_date);
         $this->comment('Purchase Cost: ' . $user_asset_purchase_cost);
         $this->comment('Notes: ' . $user_asset_notes);
         $this->comment('Company Name: ' . $user_asset_company_name);
         $this->comment('------------- Action Summary ----------------');
         if ($user_username != '') {
             if ($user = User::MatchEmailOrUsername($user_username, $user_email)->whereNotNull('username')->first()) {
                 $this->comment('User ' . $user_username . ' already exists');
             } else {
                 $user = new \App\Models\User();
                 $password = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20);
                 $user->first_name = $first_name;
                 $user->last_name = $last_name;
                 $user->username = $user_username;
                 $user->email = $user_email;
                 $user->permissions = '{user":1}';
                 $user->password = bcrypt($password);
                 $user->activated = 1;
                 if ($user->save()) {
                     $this->comment('User ' . $first_name . ' created');
                 } else {
                     $this->error('ERROR CREATING User ' . $first_name . ' ' . $last_name);
                     $this->error($user->getErrors());
                 }
             }
         } else {
             $user = new User();
         }
         // Check for the location match and create it if it doesn't exist
         if ($location = Location::where('name', e($user_asset_location))->first()) {
             $this->comment('Location ' . $user_asset_location . ' already exists');
         } else {
             $location = new Location();
             if ($user_asset_location != '') {
                 $location->name = e($user_asset_location);
                 $location->address = '';
                 $location->city = '';
                 $location->state = '';
                 $location->country = '';
                 $location->user_id = 1;
                 if (!$this->option('testrun') == 'true') {
                     if ($location->save()) {
                         $this->comment('Location ' . $user_asset_location . ' was created');
                     } else {
                         $this->error('Something went wrong! Location ' . $user_asset_location . ' was NOT created');
                         $this->error($location->getErrors());
                     }
                 } else {
                     $this->comment('Location ' . $user_asset_location . ' was (not) created - test run only');
                 }
             } else {
                 $this->comment('No location given, so none created.');
             }
         }
         if (e($user_asset_category) == '') {
             $category_name = 'Unnamed Category';
         } else {
             $category_name = e($user_asset_category);
         }
         // Check for the category match and create it if it doesn't exist
         if ($category = Category::where('name', e($category_name))->where('category_type', 'asset')->first()) {
             $this->comment('Category ' . $category_name . ' already exists');
         } else {
             $category = new Category();
             $category->name = e($category_name);
             $category->category_type = 'asset';
             $category->user_id = 1;
             if ($category->save()) {
                 $this->comment('Category ' . $user_asset_category . ' was created');
             } else {
                 $this->error('Something went wrong! Category ' . $user_asset_category . ' was NOT created');
                 $this->error($category->getErrors());
             }
         }
         // Check for the manufacturer match and create it if it doesn't exist
         if ($manufacturer = Manufacturer::where('name', e($user_asset_mfgr))->first()) {
             $this->comment('Manufacturer ' . $user_asset_mfgr . ' already exists');
         } else {
             $manufacturer = new Manufacturer();
             $manufacturer->name = e($user_asset_mfgr);
             $manufacturer->user_id = 1;
             if ($manufacturer->save()) {
                 $this->comment('Manufacturer ' . $user_asset_mfgr . ' was created');
             } else {
                 $this->error('Something went wrong! Manufacturer ' . $user_asset_mfgr . ' was NOT created: ' . $manufacturer->getErrors()->first());
             }
         }
         // Check for the asset model match and create it if it doesn't exist
         if ($asset_model = AssetModel::where('name', e($user_asset_name))->where('modelno', e($user_asset_modelno))->where('category_id', $category->id)->where('manufacturer_id', $manufacturer->id)->first()) {
             $this->comment('The Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' already exists');
         } else {
             $asset_model = new AssetModel();
             $asset_model->name = e($user_asset_name);
             $asset_model->manufacturer_id = $manufacturer->id;
             $asset_model->modelno = e($user_asset_modelno);
             $asset_model->category_id = $category->id;
             $asset_model->user_id = 1;
             if ($asset_model->save()) {
                 $this->comment('Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' was created');
             } else {
                 $this->error('Something went wrong! Asset Model ' . $user_asset_name . ' was NOT created: ' . $asset_model->getErrors()->first());
             }
         }
         // Check for the asset company match and create it if it doesn't exist
         if ($user_asset_company_name != '') {
             if ($company = Company::where('name', e($user_asset_company_name))->first()) {
                 $this->comment('Company ' . $user_asset_company_name . ' already exists');
             } else {
                 $company = new Company();
                 $company->name = e($user_asset_company_name);
                 if ($company->save()) {
                     $this->comment('Company ' . $user_asset_company_name . ' was created');
                 } else {
                     $this->error('Something went wrong! Company ' . $user_asset_company_name . ' was NOT created: ' . $company->getErrors()->first());
                 }
             }
         } else {
             $company = new Company();
         }
         // Check for the asset match and create it if it doesn't exist
         if ($asset = Asset::where('asset_tag', e($user_asset_tag))->first()) {
             $this->comment('The Asset with asset tag ' . $user_asset_tag . ' already exists');
         } else {
             $asset = new Asset();
             $asset->name = e($user_asset_asset_name);
             if ($user_asset_purchase_date != '') {
                 $asset->purchase_date = $user_asset_purchase_date;
             } else {
                 $asset->purchase_date = null;
             }
             if ($user_asset_purchase_cost != '') {
                 $asset->purchase_cost = ParseFloat(e($user_asset_purchase_cost));
             } else {
                 $asset->purchase_cost = 0.0;
             }
             $asset->serial = e($user_asset_serial);
             $asset->asset_tag = e($user_asset_tag);
             $asset->model_id = $asset_model->id;
             $asset->assigned_to = $user->id;
             $asset->rtd_location_id = $location->id;
             $asset->user_id = 1;
             $asset->status_id = $status_id;
             $asset->company_id = $company->id;
             if ($user_asset_purchase_date != '') {
                 $asset->purchase_date = $user_asset_purchase_date;
             } else {
                 $asset->purchase_date = null;
             }
             $asset->notes = e($user_asset_notes);
             if ($asset->save()) {
                 $this->comment('Asset ' . $user_asset_name . ' with serial number ' . $user_asset_serial . ' was created');
             } else {
                 $this->error('Something went wrong! Asset ' . $user_asset_name . ' was NOT created: ' . $asset->getErrors()->first());
             }
         }
         $this->comment('=====================================');
         return true;
     });
 }
コード例 #10
0
ファイル: Products.php プロジェクト: vab777/marts.id_be
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getManufacturer()
 {
     return $this->hasOne(Manufacturer::className(), ['manufacturer_id' => 'manufacturer_id']);
 }
コード例 #11
0
ファイル: Helper.php プロジェクト: stijni/snipe-it
 public static function manufacturerList()
 {
     $manufacturer_list = array('' => trans('general.select_manufacturer')) + Manufacturer::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
     return $manufacturer_list;
 }
コード例 #12
0
 /**
  * Generates the JSON used to display the manufacturer detail.
  * This JSON returns data on all of the assets with the specified
  * manufacturer ID number.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @see ManufacturersController::getView()
  * @param int $manufacturerId
  * @since [v1.0]
  * @return String JSON
  */
 public function getDataView($manufacturerId)
 {
     $manufacturer = Manufacturer::with('assets.company')->find($manufacturerId);
     $manufacturer_assets = $manufacturer->assets;
     if (Input::has('search')) {
         $manufacturer_assets = $manufacturer_assets->TextSearch(e(Input::get('search')));
     }
     if (Input::has('offset')) {
         $offset = e(Input::get('offset'));
     } else {
         $offset = 0;
     }
     if (Input::has('limit')) {
         $limit = e(Input::get('limit'));
     } else {
         $limit = 50;
     }
     $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
     $allowed_columns = ['id', 'name', 'serial', 'asset_tag'];
     $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
     $count = $manufacturer_assets->count();
     $rows = array();
     foreach ($manufacturer_assets as $asset) {
         $actions = '';
         if ($asset->deleted_at == '') {
             $actions = '<div style=" white-space: nowrap;"><a href="' . route('clone/hardware', $asset->id) . '" class="btn btn-info btn-sm" title="Clone asset"><i class="fa fa-files-o"></i></a> <a href="' . route('update/hardware', $asset->id) . '" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('delete/hardware', $asset->id) . '" data-content="' . trans('admin/hardware/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($asset->asset_tag) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';
         } elseif ($asset->deleted_at != '') {
             $actions = '<a href="' . route('restore/hardware', $asset->id) . '" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>';
         }
         if ($asset->assetstatus) {
             if ($asset->assetstatus->deployable != 0) {
                 if ($asset->assigned_to != '' && $asset->assigned_to > 0) {
                     $inout = '<a href="' . route('checkin/hardware', $asset->id) . '" class="btn btn-primary btn-sm">' . trans('general.checkin') . '</a>';
                 } else {
                     $inout = '<a href="' . route('checkout/hardware', $asset->id) . '" class="btn btn-info btn-sm">' . trans('general.checkout') . '</a>';
                 }
             }
         }
         $row = array('id' => $asset->id, 'name' => (string) link_to('/hardware/' . $asset->id . '/view', e($asset->showAssetName())), 'model' => e($asset->model->name), 'asset_tag' => e($asset->asset_tag), 'serial' => e($asset->serial), 'assigned_to' => $asset->assigneduser ? (string) link_to('/admin/users/' . $asset->assigneduser->id . '/view', e($asset->assigneduser->fullName())) : '', 'actions' => $actions, 'companyName' => e(Company::getName($asset)));
         if (isset($inout)) {
             $row['change'] = $inout;
         }
         $rows[] = $row;
     }
     $data = array('total' => $count, 'rows' => $rows);
     return $data;
 }
コード例 #13
0
 public function run()
 {
     Manufacturer::truncate();
     factory(Manufacturer::class, 'manufacturer', 10)->create();
 }
コード例 #14
0
 /**
  * Generates the JSON used to display the manufacturer detail.
  * This JSON returns data on all of the assets with the specified
  * manufacturer ID number.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @see ManufacturersController::getView()
  * @param int $manufacturerId
  * @since [v1.0]
  * @return String JSON
  */
 public function getDataView($manufacturerId, $itemtype = null)
 {
     $manufacturer = Manufacturer::with('assets.company')->find($manufacturerId);
     switch ($itemtype) {
         case "assets":
             return $this->getDataAssetsView($manufacturer);
         case "licenses":
             return $this->getDataLicensesView($manufacturer);
         case "accessories":
             return $this->getDataAccessoriesView($manufacturer);
         case "consumables":
             return $this->getDataConsumablesView($manufacturer);
     }
     throw new Exception("We shouldn't be here");
 }