Inheritance: extends BaseModel
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('license', function (Blueprint $table) {
         $table->engine = 'InnoDB';
         $table->increments('id');
         $table->string('key', 128)->unique();
         $table->string('slug')->unique();
         $table->string('name')->index();
         $table->text('description')->nullable();
         $table->integer('duration')->nullable()->unsigned()->index();
         $table->text('permissions')->nullable();
         $table->boolean('is_enabled')->default(true)->index();
         $table->boolean('needs_validation')->default(false)->index();
         $table->timestamps();
     });
     // FIXTURES Licenses
     $data = [];
     $file = file_get_contents(base_path() . '/database/fixtures/licenses.csv');
     $lines = str_getcsv($file, "\n");
     foreach ($lines as $line) {
         $keys = ['slug', 'name', 'description', 'duration', 'permissions', 'is_enabled', 'needs_validation'];
         $row = array_combine($keys, str_getcsv($line, ';'));
         License::create($row);
     }
 }
Ejemplo n.º 2
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param array $data
  *
  * @return User
  */
 protected function create(array $data)
 {
     $license = License::where('license', $data['code'])->where('used', 0)->first();
     if ($license == null) {
         return redirect()->to('/register')->with('Error', 'Je licentie code is incorrect');
     }
     $user = User::create(['name' => $data['name'], 'code' => $data['code'], 'province_id' => $data['province'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
     $user->addLicense($license);
     return $user;
 }
Ejemplo n.º 3
0
 public function run()
 {
     License::truncate();
     factory(License::class, 'license', 10)->create();
     LicenseSeat::truncate();
     factory(LicenseSeat::class, 'license-seat', 10)->create();
     // factory(App\Models\Asset::class, 50)->create()->each(function($u) {
     //   $u->assetmodel()->save(factory(App\AssetModel::class)->make());
     // });
 }
Ejemplo n.º 4
0
 public function store(Requests\CreateBinRequest $request)
 {
     $license = License::whereLicense($request->get('license'))->first();
     if ($license->used == 1) {
         return redirect()->route('user.bins.index')->with('Error', 'Licentie is al in gebruik');
     }
     $license->used = 1;
     $license->save();
     auth()->user()->addLicense($license);
     return redirect()->route('user.bins.index')->with('Success', 'Licentie is toegevoegd');
 }
Ejemplo n.º 5
0
 public function addScore($license, $points)
 {
     $lic = License::whereLicense($license)->first();
     if ($lic == null) {
         return new JsonResponse(['Licentie bestaat niet, heeft u zich aangemeld?'], 200);
     }
     $score = new Score();
     $score->license = $license;
     $score->score = $points;
     $score->save();
     return new JsonResponse(['Gelukt'], 200);
 }
Ejemplo n.º 6
0
 private function _users()
 {
     $provinces = Province::all();
     foreach ($provinces as $p) {
         $faker = \Faker\Factory::create();
         $user = new User();
         $user->name = $faker->name;
         $user->province_id = $p->id;
         $user->email = $faker->email;
         $user->password = Hash::make('123456');
         $user->save();
         $license = License::where('used', 0)->first();
         $license->used = 1;
         $license->save();
         $license->user()->attach($user);
         $score = new Score();
         $score->score = rand(100, 3500);
         $score->license = $license->license;
         $score->save();
     }
 }
Ejemplo n.º 7
0
 /**
  * Exports the licenses to CSV
  *
  * @deprecated Server-side exports have been replaced by datatables export since v2.
  * @author [A. Gianotto] [<*****@*****.**>]
  * @since [v1.0]
  * @return \Illuminate\Http\Response
  */
 public function exportLicenseReport()
 {
     $licenses = License::orderBy('created_at', 'DESC')->get();
     $rows = [];
     $header = [trans('admin/licenses/table.title'), trans('admin/licenses/table.serial'), trans('admin/licenses/form.seats'), trans('admin/licenses/form.remaining_seats'), trans('admin/licenses/form.expiration'), trans('admin/licenses/form.date'), trans('admin/licenses/form.cost')];
     $header = array_map('trim', $header);
     $rows[] = implode($header, ', ');
     // Row per license
     foreach ($licenses as $license) {
         $row = [];
         $row[] = e($license->name);
         $row[] = e($license->serial);
         $row[] = e($license->seats);
         $row[] = $license->remaincount();
         $row[] = $license->expiration_date;
         $row[] = $license->purchase_date;
         $row[] = '"' . Helper::formatCurrencyOutput($license->purchase_cost) . '"';
         $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;
 }
Ejemplo n.º 8
0
 public function doRegister()
 {
     $affiliate = Affiliate::where('affiliate_key', '=', SELF_HOST_AFFILIATE_KEY)->first();
     $license = new License();
     $license->first_name = Input::get('first_name');
     $license->last_name = Input::get('last_name');
     $license->email = Input::get('email');
     $license->transaction_reference = Request::getClientIp();
     $license->license_key = Utils::generateLicense();
     $license->affiliate_id = $affiliate->id;
     $license->product_id = PRODUCT_SELF_HOST;
     $license->is_claimed = 1;
     $license->save();
     return '';
 }
Ejemplo n.º 9
0
 /**
  * Generates the next free seat ID for checkout.
  *
  * @todo This is a dumb way to solve this problem.
  * Author should refactor. And go hide in a hole and
  * think about what she's done. And perhaps find a new
  * line of work. And get in the sea.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @since [v1.0]
  * @param int $licenseId
  * @return View
  */
 public function getFreeLicense($licenseId)
 {
     // Check if the asset exists
     if (is_null($license = License::find($licenseId))) {
         // Redirect to the asset management page with error
         return redirect()->to('admin/licenses')->with('error', trans('admin/licenses/message.not_found'));
     }
     $seatId = $license->freeSeat($licenseId);
     return redirect()->to('admin/licenses/' . $seatId . '/checkout');
 }
Ejemplo n.º 10
0
 /**
  * Remove the specified resource from storage.
  *
  * @param License $license
  *
  * @return \Illuminate\Http\Response
  */
 public function destroy(License $license)
 {
     $license->delete();
     return redirect()->route('admin.licenses')->with('Success', 'Licentie is verwijderd');
 }
Ejemplo n.º 11
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');
         }
     }
 }
 public function claim_license()
 {
     $licenseKey = Input::get('license_key');
     $productId = Input::get('product_id', PRODUCT_ONE_CLICK_INSTALL);
     $license = License::where('license_key', '=', $licenseKey)->where('is_claimed', '<', 5)->where('product_id', '=', $productId)->first();
     if ($license) {
         if ($license->transaction_reference != 'TEST_MODE') {
             $license->is_claimed = $license->is_claimed + 1;
             $license->save();
         }
         return $productId == PRODUCT_INVOICE_DESIGNS ? file_get_contents(storage_path() . '/invoice_designs.txt') : 'valid';
     } else {
         return 'invalid';
     }
 }
Ejemplo n.º 13
0
 /**
  * Auto set the users license
  *
  * @param string $licenseID
  */
 public static function getAutoLicense($licenseID)
 {
     $license = null;
     if ($licenseID) {
         $license = License::where(['slug' => $licenseID])->first();
     }
     return $license;
 }
Ejemplo n.º 14
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);
     }
 }
Ejemplo n.º 15
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $filename = $this->argument('filename');
     if (!$this->option('testrun') == 'true') {
         $this->comment('======= Importing Licenses from ' . $filename . ' =========');
     } else {
         $this->comment('====== TEST ONLY License 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
         if (array_key_exists('0', $row)) {
             $user_name = trim($row[0]);
         } else {
             $user_name = '';
         }
         if (array_key_exists('1', $row)) {
             $user_email = trim($row[1]);
         } else {
             $user_email = '';
         }
         if (array_key_exists('2', $row)) {
             $user_username = trim($row[2]);
         } else {
             $user_username = '';
         }
         if (array_key_exists('3', $row)) {
             $user_license_name = trim($row[3]);
         } else {
             $user_license_name = '';
         }
         if (array_key_exists('4', $row)) {
             $user_license_serial = trim($row[4]);
         } else {
             $user_license_serial = '';
         }
         if (array_key_exists('5', $row)) {
             $user_licensed_to_name = trim($row[5]);
         } else {
             $user_licensed_to_name = '';
         }
         if (array_key_exists('6', $row)) {
             $user_licensed_to_email = trim($row[6]);
         } else {
             $user_licensed_to_email = '';
         }
         if (array_key_exists('7', $row)) {
             $user_license_seats = trim($row[7]);
         } else {
             $user_license_seats = '';
         }
         if (array_key_exists('8', $row)) {
             $user_license_reassignable = trim($row[8]);
             if ($user_license_reassignable != '') {
                 if (strtolower($user_license_reassignable) == 'yes' || strtolower($user_license_reassignable) == 'true' || $user_license_reassignable == '1') {
                     $user_license_reassignable = 1;
                 }
             } else {
                 $user_license_reassignable = 0;
             }
         } else {
             $user_license_reassignable = 0;
         }
         if (array_key_exists('9', $row)) {
             $user_license_supplier = trim($row[9]);
         } else {
             $user_license_supplier = '';
         }
         if (array_key_exists('10', $row)) {
             $user_license_maintained = trim($row[10]);
             if ($user_license_maintained != '') {
                 if (strtolower($user_license_maintained) == 'yes' || strtolower($user_license_maintained) == 'true' || $user_license_maintained == '1') {
                     $user_license_maintained = 1;
                 }
             } else {
                 $user_license_maintained = 0;
             }
         } else {
             $user_license_maintained = '';
         }
         if (array_key_exists('11', $row)) {
             $user_license_notes = trim($row[11]);
         } else {
             $user_license_notes = '';
         }
         if (array_key_exists('12', $row)) {
             if ($row[12] != '') {
                 $user_license_purchase_date = date("Y-m-d 00:00:01", strtotime($row[12]));
             } else {
                 $user_license_purchase_date = '';
             }
         } else {
             $user_license_purchase_date = 0;
         }
         // 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 = '';
             // No name was given
         } elseif ($user_name == '') {
             $this->comment('No user data provided - skipping user creation, just adding license');
             $first_name = '';
             $last_name = '';
             $user_username = '';
         } else {
             $name = explode(" ", $user_name);
             $first_name = $name[0];
             $email_last_name = '';
             $email_prefix = $first_name;
             if (!array_key_exists(1, $name)) {
                 $last_name = '';
                 $email_last_name = $last_name;
                 $email_prefix = $first_name;
             } else {
                 $last_name = str_replace($first_name, '', $user_name);
                 if ($this->option('email_format') == 'filastname') {
                     $email_last_name .= str_replace(' ', '', $last_name);
                     $email_prefix = $first_name[0] . $email_last_name;
                 } elseif ($this->option('email_format') == 'firstname.lastname') {
                     $email_last_name .= str_replace(' ', '', $last_name);
                     $email_prefix = $first_name . '.' . $email_last_name;
                 } elseif ($this->option('email_format') == 'firstname') {
                     $email_last_name .= str_replace(' ', '', $last_name);
                     $email_prefix = $first_name;
                 }
             }
             $user_username = $email_prefix;
             // Generate an email based on their name if no email address is given
             if ($user_email == '') {
                 if ($first_name == 'Unknown') {
                     $status_id = 7;
                 }
                 $email = strtolower($email_prefix) . '@' . $this->option('domain');
                 $user_email = str_replace("'", '', $email);
             }
         }
         $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('License Name: ' . $user_license_name);
         $this->comment('Serial No: ' . $user_license_serial);
         $this->comment('Licensed To Name: ' . $user_licensed_to_name);
         $this->comment('Licensed To Email: ' . $user_licensed_to_email);
         $this->comment('Seats: ' . $user_license_seats);
         $this->comment('Reassignable: ' . $user_license_reassignable);
         $this->comment('Supplier: ' . $user_license_supplier);
         $this->comment('Maintained: ' . $user_license_maintained);
         $this->comment('Notes: ' . $user_license_notes);
         $this->comment('Purchase Date: ' . $user_license_purchase_date);
         $this->comment('------------- Action Summary ----------------');
         if ($user_username != '') {
             if ($user = User::where('username', $user_username)->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());
                 }
                 $this->comment('User ' . $first_name . ' created');
             }
         } else {
             $user = new User();
             $user->user_id = null;
         }
         // Check for the supplier match and create it if it doesn't exist
         if ($supplier = Supplier::where('name', $user_license_supplier)->first()) {
             $this->comment('Supplier ' . $user_license_supplier . ' already exists');
         } else {
             $supplier = new Supplier();
             $supplier->name = e($user_license_supplier);
             $supplier->user_id = 1;
             if ($supplier->save()) {
                 $this->comment('Supplier ' . $user_license_supplier . ' was created');
             } else {
                 $this->comment('Something went wrong! Supplier ' . $user_license_supplier . ' was NOT created');
             }
         }
         // Add the license
         $license = new License();
         $license->name = e($user_license_name);
         if ($user_license_purchase_date != '') {
             $license->purchase_date = $user_license_purchase_date;
         } else {
             $license->purchase_date = null;
         }
         $license->serial = e($user_license_serial);
         $license->seats = e($user_license_seats);
         $license->supplier_id = $supplier->id;
         $license->user_id = 1;
         if ($user_license_purchase_date != '') {
             $license->purchase_date = $user_license_purchase_date;
         } else {
             $license->purchase_date = null;
         }
         $license->license_name = $user_licensed_to_name;
         $license->license_email = $user_licensed_to_email;
         $license->notes = e($user_license_notes);
         if ($license->save()) {
             $this->comment('License ' . $user_license_name . ' with serial number ' . $user_license_serial . ' was created');
             $license_seat_created = 0;
             for ($x = 0; $x < $user_license_seats; $x++) {
                 // Create the license seat entries
                 $license_seat = new LicenseSeat();
                 $license_seat->license_id = $license->id;
                 // Only assign the first seat to the user
                 if ($x == 0) {
                     $license_seat->assigned_to = $user->id;
                 } else {
                     $license_seat->assigned_to = null;
                 }
                 if ($license_seat->save()) {
                     $license_seat_created++;
                 }
             }
             if ($license_seat_created > 0) {
                 $this->comment($license_seat_created . ' seats were created');
             } else {
                 $this->comment('Something went wrong! NO seats for ' . $user_license_name . ' were created');
             }
         } else {
             $this->comment('Something went wrong! License ' . $user_license_name . ' was NOT created');
         }
         $this->comment('=====================================');
         return true;
     });
 }
Ejemplo n.º 16
0
 public static function getExpiringLicenses($days = 60)
 {
     return License::whereNotNull('expiration_date')->whereNull('deleted_at')->whereRaw(DB::raw('DATE_SUB(`expiration_date`,INTERVAL ' . $days . ' DAY) <= DATE(NOW()) '))->where('expiration_date', '>', date("Y-m-d"))->orderBy('expiration_date', 'ASC')->get();
 }
Ejemplo n.º 17
0
 public function claim_license()
 {
     $licenseKey = Input::get('license_key');
     $productId = Input::get('product_id', PRODUCT_ONE_CLICK_INSTALL);
     $license = License::where('license_key', '=', $licenseKey)->where('is_claimed', '<', 5)->where('product_id', '=', $productId)->first();
     if ($license) {
         if ($license->transaction_reference != 'TEST_MODE') {
             $license->is_claimed = $license->is_claimed + 1;
             $license->save();
         }
         if ($productId == PRODUCT_INVOICE_DESIGNS) {
             return file_get_contents(storage_path() . '/invoice_designs.txt');
         } else {
             // temporary fix to enable previous version to work
             if (Input::get('get_date')) {
                 return $license->created_at->format('Y-m-d');
             } else {
                 return 'valid';
             }
         }
     } else {
         return RESULT_FAILURE;
     }
 }
Ejemplo n.º 18
0
 public function claim_license()
 {
     $licenseKey = Input::get('license_key');
     $productId = Input::get('product_id', PRODUCT_ONE_CLICK_INSTALL);
     $license = License::where('license_key', '=', $licenseKey)->where('is_claimed', '<', 3)->where('product_id', '=', $productId)->first();
     if ($license) {
         if ($license->transaction_reference != 'TEST_MODE') {
             $license->is_claimed = $license->is_claimed + 1;
             $license->save();
         }
         return $productId == PRODUCT_INVOICE_DESIGNS ? $_ENV['INVOICE_DESIGNS'] : 'valid';
     } else {
         return 'invalid';
     }
 }
Ejemplo n.º 19
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.');
     }
 }
 /**
  * @return mixed
  */
 public function doRegister()
 {
     $affiliate = Affiliate::where('affiliate_key', '=', SELF_HOST_AFFILIATE_KEY)->first();
     $email = trim(Input::get('email'));
     if (!$email || $email == TEST_USERNAME) {
         return RESULT_FAILURE;
     }
     $license = new License();
     $license->first_name = Input::get('first_name');
     $license->last_name = Input::get('last_name');
     $license->email = $email;
     $license->transaction_reference = Request::getClientIp();
     $license->license_key = Utils::generateLicense();
     $license->affiliate_id = $affiliate->id;
     $license->product_id = PRODUCT_SELF_HOST;
     $license->is_claimed = 1;
     $license->save();
     return RESULT_SUCCESS;
 }
Ejemplo n.º 21
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     // Expiring Assets
     $expiring_assets = Asset::getExpiringWarrantee(Setting::getSettings()->alert_interval);
     $this->info(count($expiring_assets) . ' expiring assets');
     $asset_data['count'] = count($expiring_assets);
     $asset_data['email_content'] = '';
     $now = date("Y-m-d");
     foreach ($expiring_assets as $asset) {
         $expires = $asset->warrantee_expires();
         $difference = round(abs(strtotime($expires) - strtotime($now)) / 86400);
         if ($difference > 30) {
             $asset_data['email_content'] .= '<tr style="background-color: #fcffa3;">';
         } else {
             $asset_data['email_content'] .= '<tr style="background-color:#d9534f;">';
         }
         $asset_data['email_content'] .= '<td><a href="' . config('app.url') . '/hardware/' . e($asset->id) . '/view">';
         $asset_data['email_content'] .= $asset->showAssetName() . '</a></td><td>' . e($asset->asset_tag) . '</td>';
         $asset_data['email_content'] .= '<td>' . e($asset->warrantee_expires()) . '</td>';
         $asset_data['email_content'] .= '<td>' . $difference . ' days</td>';
         $asset_data['email_content'] .= '<td>' . ($asset->supplier ? e($asset->supplier->name) : '') . '</td>';
         $asset_data['email_content'] .= '<td>' . ($asset->assigneduser ? e($asset->assigneduser->fullName()) : '') . '</td>';
         $asset_data['email_content'] .= '</tr>';
     }
     // Expiring licenses
     $expiring_licenses = License::getExpiringLicenses(Setting::getSettings()->alert_interval);
     $this->info(count($expiring_licenses) . ' expiring licenses');
     $license_data['count'] = count($expiring_licenses);
     $license_data['email_content'] = '';
     foreach ($expiring_licenses as $license) {
         $expires = $license->expiration_date;
         $difference = round(abs(strtotime($expires) - strtotime($now)) / 86400);
         if ($difference > 30) {
             $license_data['email_content'] .= '<tr style="background-color: #fcffa3;">';
         } else {
             $license_data['email_content'] .= '<tr style="background-color:#d9534f;">';
         }
         $license_data['email_content'] .= '<td><a href="' . config('app.url') . '/admin/licenses/' . $license->id . '/view">';
         $license_data['email_content'] .= $license->name . '</a></td>';
         $license_data['email_content'] .= '<td>' . $license->expiration_date . '</td>';
         $license_data['email_content'] .= '<td>' . $difference . ' days</td>';
         $license_data['email_content'] .= '</tr>';
     }
     if (Setting::getSettings()->alert_email != '' && Setting::getSettings()->alerts_enabled == 1) {
         if (count($expiring_assets) > 0) {
             \Mail::send('emails.expiring-assets-report', $asset_data, function ($m) {
                 $m->to(explode(',', Setting::getSettings()->alert_email), Setting::getSettings()->site_name);
                 $m->subject('Expiring Assets Report');
             });
         }
         if (count($expiring_licenses) > 0) {
             \Mail::send('emails.expiring-licenses-report', $license_data, function ($m) {
                 $m->to(explode(',', Setting::getSettings()->alert_email), Setting::getSettings()->site_name);
                 $m->subject('Expiring Licenses Report');
             });
         }
     } else {
         if (Setting::getSettings()->alert_email == '') {
             echo "Could not send email. No alert email configured in settings. \n";
         } elseif (Setting::getSettings()->alerts_enabled != 1) {
             echo "Alerts are disabled in the settings. No mail will be sent. \n";
         }
     }
 }