Пример #1
0
 public function run()
 {
     // create default user asset
     $asset = Asset::where('filename', '=', 'default.png')->first();
     if ($asset == NULL) {
         $asset = new Asset();
         $asset->filename = 'default.png';
         $asset->path = 'assets/content/users';
         $asset->save();
     }
     $admin = Role::where('name', '=', 'Admin')->first();
     // create default roles
     if ($admin == NULL) {
         $admin = new Role();
         $admin->name = 'Admin';
         $admin->save();
     }
     $adminUser = User::where('username', '=', 'admin')->first();
     if ($adminUser != NULL) {
         echo "Admin User Already Exsit";
     } else {
         $adminUser = new User();
         $adminUser->username = '******';
         $adminUser->email = '*****@*****.**';
         $adminUser->password = '******';
         $adminUser->password_confirmation = 'admin';
         $adminUser->confirmation_code = md5(uniqid(mt_rand(), true));
         if ($adminUser->save()) {
             $adminUser->attachRole($admin);
             echo "Admin User Created";
         }
     }
 }
Пример #2
0
 public static function getExpiringWarrantee($days = 30)
 {
     return Asset::where('archived', '=', '0')->whereNotNull('warranty_months')->whereNotNull('purchase_date')->whereNull('deleted_at')->whereRaw(DB::raw('DATE_ADD(`purchase_date`,INTERVAL `warranty_months` MONTH) <= DATE(NOW() + INTERVAL ' . $days . ' DAY) AND DATE_ADD(`purchase_date`,INTERVAL `warranty_months` MONTH) > NOW()'))->orderBy('purchase_date', 'ASC')->get();
 }
Пример #3
0
 public function officeAssetsReports()
 {
     if (Session::has('username') && (Session::get('user_type') == "Root" || Session::get('user_type') == "Admin" || Session::get("user_type") == "User")) {
         $view = View::make("Reports.office_assets_reports");
         $view->nav = "system";
         $view->tab = "office";
         $totalOfficeAssets = Asset::whereHas("classification", function ($q) {
             $q->where("type", "=", "Office");
         })->get()->count();
         //Summary
         $printers = Asset::whereHas("classification", function ($q) {
             $q->where("name", "=", "Printers");
         })->get()->count();
         $projectors = Asset::whereHas("classification", function ($q) {
             $q->where("name", "=", "Projectors");
         })->get()->count();
         $otherAssets = Asset::whereHas("classification", function ($q) {
             $q->where("name", "=", "Other Assets");
         })->get()->count();
         if ($totalOfficeAssets > 0) {
             $printersPercentage = $printers > 0 ? $printers / $totalOfficeAssets * 100 : "0.00";
             $projectorsPercentage = $projectors > 0 ? $projectors / $totalOfficeAssets * 100 : "0.00";
             $otherAssetsPercentage = $otherAssets > 0 ? $otherAssets / $totalOfficeAssets * 100 : "0.00";
         } else {
             $printersPercentage = "0.00";
             $projectorsPercentage = "0.00";
             $otherAssetsPercentage = "0.00";
         }
         $view->totalOfficeAssets = $totalOfficeAssets;
         $view->printers = $printers;
         $view->projectors = $projectors;
         $view->otherAssets = $otherAssets;
         $view->printersPercentage = $printersPercentage;
         $view->projectorsPercentage = $projectorsPercentage;
         $view->otherAssetsPercentage = $otherAssetsPercentage;
         //Status
         //Printer Status
         $p_available = Asset::where("status", "=", "Available")->whereHas("classification", function ($q) {
             $q->where("name", "=", "Printers");
         })->count();
         $p_for_repair = Asset::where("status", "=", "For Repair")->whereHas("classification", function ($q) {
             $q->where("name", "=", "Printers");
         })->count();
         $p_installed = Asset::where("status", "=", "Installed")->whereHas("classification", function ($q) {
             $q->where("name", "=", "Printers");
         })->count();
         $p_lost = Asset::where("status", "=", "Lost")->whereHas("classification", function ($q) {
             $q->where("name", "=", "Printers");
         })->count();
         $p_retired = Asset::where("status", "=", "Retired")->whereHas("classification", function ($q) {
             $q->where("name", "=", "Printers");
         })->count();
         $view->p_available = $p_available;
         $view->p_for_repair = $p_for_repair;
         $view->p_installed = $p_installed;
         $view->p_lost = $p_lost;
         $view->p_retired = $p_retired;
         //Projector Status
         $pro_available = Asset::where("status", "=", "Available")->whereHas("classification", function ($q) {
             $q->where("name", "=", "Projectors");
         })->count();
         $pro_for_repair = Asset::where("status", "=", "For Repair")->whereHas("classification", function ($q) {
             $q->where("name", "=", "Projectors");
         })->count();
         $pro_installed = Asset::where("status", "=", "Installed")->whereHas("classification", function ($q) {
             $q->where("name", "=", "Projectors");
         })->count();
         $pro_lost = Asset::where("status", "=", "Lost")->whereHas("classification", function ($q) {
             $q->where("name", "=", "Projectors");
         })->count();
         $pro_retired = Asset::where("status", "=", "Retired")->whereHas("classification", function ($q) {
             $q->where("name", "=", "Projectors");
         })->count();
         $view->pro_available = $pro_available;
         $view->pro_for_repair = $pro_for_repair;
         $view->pro_installed = $pro_installed;
         $view->pro_lost = $pro_lost;
         $view->pro_retired = $pro_retired;
         //Other Assets Status
         $o_available = Asset::where("status", "=", "Available")->whereHas("classification", function ($q) {
             $q->where("name", "=", "Other Assets");
         })->count();
         $o_for_repair = Asset::where("status", "=", "For Repair")->whereHas("classification", function ($q) {
             $q->where("name", "=", "Other Assets");
         })->count();
         $o_installed = Asset::where("status", "=", "Installed")->whereHas("classification", function ($q) {
             $q->where("name", "=", "Other Assets");
         })->count();
         $o_lost = Asset::where("status", "=", "Lost")->whereHas("classification", function ($q) {
             $q->where("name", "=", "Other Assets");
         })->count();
         $o_retired = Asset::where("status", "=", "Retired")->whereHas("classification", function ($q) {
             $q->where("name", "=", "Other Assets");
         })->count();
         $view->o_available = $o_available;
         $view->o_for_repair = $o_for_repair;
         $view->o_installed = $o_installed;
         $view->o_lost = $o_lost;
         $view->o_retired = $o_retired;
         return $view;
     } else {
         return Redirect::to("/");
     }
 }
Пример #4
0
    // 	$em = Employee::has("manager")->get();
    // 	echo $em->manager->first()->id;
    // 	echo $em->count();
    // 	foreach($em as $e){
    // 		echo $e->manager->first_name;
    // 	}
    // 	$employees = Employee::paginate(10);
    // 	foreach($employees as $e){
    // 		//KEEP IN MIND TO CHECK IF NULL. BECAUSE IF IT IS, IT WILL RETURN A F*****G ERROR YOU SANOVA BITCH
    // 		if(!empty($e->manager->first_name))
    // 		echo $e->manager->first_name."<br/>";
    // 		else
    // 			echo "null biiiitch<br/>";
    // 	}
    $key = "4";
    $asset = Asset::where("serial_number", "LIKE", "{$key}")->orWhere("id", "=", $key)->orWhereHas("employee", function ($q) use($key) {
        $q->where("last_name", "LIKE", "%{$key}%");
    })->get();
    foreach ($asset as $a) {
        echo $a->employee->last_name . "<br/>";
    }
});
Route::get("dummy4", function () {
    // 	$logs = UserLog::whereBetween("datetime",array("2014-12-01","2014-12-02"." 23:59:59.000000"))->get();
    // 	foreach($logs as $l){
    // 		echo $l->datetime."<br/>";
    // 	}
    // 	$g1 = Asset::whereHas("classification",function($query){
    // 			$query->where("name","=","Laptops");
    // 		  })
    // 		  ->whereHas("model",function($query){
Пример #5
0
 private function processImport($file)
 {
     if (Session::has('username') && (Session::get('user_type') == "Root" || Session::get('user_type') == "Admin")) {
         if (!in_array($file->getClientOriginalExtension(), array("xls", "xlsx", "csv"))) {
             Input::flash();
             return Redirect::to('assets/software/import')->with('message', "Invalid file selected.");
         } else {
             $filename = "upload-" . str_random(9) . "." . $file->getClientOriginalExtension();
             $file->move("uploads", $filename);
             $readFile = "uploads/" . $filename;
             $reader = Excel::selectSheetsByIndex(0)->load($readFile, function ($reader) {
             })->get();
             /*
              * 				Before validating each rows of the file uploaded, the file itself is checked if it has the valid attributes (columns)
              * 				using the algorithm found below.
              *
              * 				1. File is read.
              * 				2. Boolean variable $excelIsValid to check if the file is valid. Set to false by default.
              *
              */
             $excelChecker = Excel::selectSheetsByIndex(0)->load($readFile, function ($reader) {
             })->get()->toArray();
             $excelIsValid = false;
             /*
              * 				3. Loop through the excel file and check if at least once all the columns have been present.
              * 				4. If it does, $excelIsValid is set to true.
              * 				5. If $excelIsValid is still false by end of the loop, it is automatically assumed that the file is:
              * 					A.) Empty
              * 					B.) Does not have the right attributes.
              * 					C.) Has valid columns, but does not have any valid entry.
              *
              */
             foreach ($excelChecker as $ex) {
                 if (isset($ex["productkey"]) && isset($ex["softwaretype"]) && isset($ex["status"])) {
                     $excelIsValid = true;
                 }
             }
             /*				6. If file is invalid, redirect to import form and return an error. */
             if (!$excelIsValid) {
                 Input::flash();
                 File::delete($readFile);
                 return Redirect::to('assets/software/import')->with('message', "Excel file has invalid attributes. Please download the form.");
             }
             /*
              * 				CHECKING EXCEL FILE FOR ERRORS WHILE READING THE ROWS
              *
              * 				1. $hasError is a Boolean variable that is simply used to tell if any error has been found.
              * 					This variable is, by default, set to false. If any error has been detected, it is set to true,
              * 					regardless of how many errors has been detected.
              *
              * 				2. $rowIndex indexes which row the reader is currently reading. Default value set to 1 because
              * 					the first row of excel files is automatically set as the attribute row. When the reader reads each row,
              * 					$rowIndex is incremented. For example, reader is currently reading row 2, $rowIndex will then be incremented,
              * 					setting its value to 2, thus the row number.
              *
              * 				3. $rowsWithErrors is the array of the rows with errors. To explain further, let's say excel file has 10 readable (non-attrib)
              * 					rows. No errors were found from rows number 2-8, but errors were found in rows 9, 10, and 11. These 9, 10, and 11
              * 					will then be in the $rowsWithError.
              *
              * 				4. $error array is the variable that will be used to collect all errors found from the excel file.
              * 					This is a two-dimensional array.
              *
              *
              */
             $hasError = false;
             //Detects if there are any errors.
             $hasCorrectRows = false;
             $rowIndex = 1;
             //Indexes which row the reader is reading.
             $rowsWithErrors = array();
             //This is used to contain in an array the row numbers of the rows with error.
             $error = array();
             //Error details collector.
             foreach ($reader as $r) {
                 /*
                  * 				5. Here, we immediately increment the value of $rowIndex, since the variable will be used in the core logic of this method.
                  *
                  * 				6. $errorCount variable is a variable used in every loop. Set to 0 when the loop begins, so it always comes back to 0 for every loop.
                  * 					$errorCount is used to track the number of errors for the current row. This variable goes hand in hand with the
                  * 					$rowsWithError array when publishing the rows with errors, and the error details for each row with error.
                  *
                  * 					This is how $rowsWithError and $rowCount will be used:
                  *
                  * 					for each $rowWithErrors:
                  * 						Row $rowWithErrors Index:
                  * 							Errors Found :
                  * 							$rowCount 1. Foo bar
                  * 							$rowCount 2. Jane Doe etc..
                  *
                  *
                  */
                 $rowIndex += 1;
                 $errorCount = 0;
                 //Counts the number of errors for the currect row.
                 $rowHasError = false;
                 //Check if this row has error. I will use this before the reading of the row ends.
                 //					If $rowHasError is still false by end of the reading, then I will write it in the database.
                 $warranty_start = !empty(trim($r->warrantystart)) ? trim($r->warrantystart) : "1994-04-16";
                 $validator = Validator::make(array("software asset tag" => trim($r->assettag), "product key" => trim($r->productkey), "employee number" => trim($r->employeenumber), "laptop serial number" => trim($r->laptopsn), "software type" => trim($r->softwaretype), "warranty start date" => trim($r->warrantystart), "warranty end date" => trim($r->warrantyend), "status" => trim($r->status)), array("software asset tag" => "required|unique:tbl_software_assets,asset_tag|unique:tbl_assets,asset_tag", "product key" => "required", "employee number" => "exists:tbl_employees,employee_number", "laptop serial number" => "exists:tbl_assets,serial_number", "software type" => "required|exists:tbl_software_types,software_type", "warranty start date" => "required_with:warranty end date|date:Y-m-d", "warranty end date" => "date:Y-m-d|after:" . $warranty_start, "status" => "required|in:Available,PWU,Retired,Test Case,Lost"), array("after" => "The :attribute must be after the warranty start date."));
                 if ($validator->fails()) {
                     /* 					7. When error has been found, $rowsWithError is immediately updated. Also, $hasError and $rowHasError are set to true.*/
                     $hasError = true;
                     $rowHasError = true;
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     /* 					8. Then I will check which fields have errors.
                      *
                      *					9. If an error has been found in a certain field,
                      *					   I will loop through the errors found on that field, increment the $errorCount (which, again, tracks
                      *					   how many errors has been found on a certain row.), update the two-dimensional $error array.
                      *					   Please note that the first array of $error contains the row number which the errors found belong to.
                      *
                      */
                     if ($validator->messages()->get("software asset tag")) {
                         foreach ($validator->messages()->get("software asset tag") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("product key")) {
                         foreach ($validator->messages()->get("product key") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("employee number")) {
                         foreach ($validator->messages()->get("employee number") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("laptop serial number")) {
                         foreach ($validator->messages()->get("laptop serial number") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("software type")) {
                         foreach ($validator->messages()->get("software type") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("warranty start date")) {
                         foreach ($validator->messages()->get("warranty start date") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("warranty end date")) {
                         foreach ($validator->messages()->get("warranty end date") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("status")) {
                         foreach ($validator->messages()->get("status") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                 }
                 if ($r->status != "Lost" && Employee::where("employee_number", "=", $r->employeenumber)->whereIn("status", array("OJT Graduate", "Graduate", "Resigned", "Obsolete"))->first()) {
                     $hasError = true;
                     //This will only matter if no errors has been found above.
                     $rowHasError = true;
                     //This will only matter if no errors has been found above.
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     //This will only matter if no errors has been found above.
                     $errorCount += 1;
                     $error[$rowIndex][$errorCount] = $errorCount . ". " . "Cannot assign an asset to employees no longer working in the company." . "<br/>";
                 }
                 if (trim($r->laptopsn) != null && !Asset::where("serial_number", "=", $r->laptopsn)->whereHas("classification", function ($q) {
                     $q->where("name", "=", "Laptops");
                 })->first()) {
                     $hasError = true;
                     //This will only matter if no errors has been found above.
                     $rowHasError = true;
                     //This will only matter if no errors has been found above.
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     //This will only matter if no errors has been found above.
                     $errorCount += 1;
                     $error[$rowIndex][$errorCount] = $errorCount . ". " . "Cannot assign software asset to non-laptop assets. Please check the serial number and try again." . "<br/>";
                 }
                 if (!$rowHasError) {
                     $hasCorrectRows = true;
                     $software_type_id = SoftwareType::where("software_type", "=", $r->softwaretype)->get(array("id"))->first();
                     //Create the asset
                     $software = new Software();
                     $software->asset_tag = trim($r->assettag) != null ? trim($r->assettag) : null;
                     $software->product_key = trim($r->productkey);
                     $software->employee_number = trim($r->employeenumber) != null ? trim($r->employeenumber) : null;
                     $software->assigned_to_serial_number = trim($r->laptopsn) != null ? trim($r->laptopsn) : null;
                     $software->location = trim($r->location) != null ? trim($r->location) : null;
                     $software->software_type_id = $software_type_id->id;
                     $software->warranty_start = trim($r->warrantystart);
                     $software->warranty_end = trim($r->warrantyend);
                     $software->status = trim($r->status);
                     $software->notes = trim($r->notes) != null ? trim($r->notes) : null;
                     $software->date_added = date("Y-m-d H:i:s");
                     $software->save();
                     //Log the new asset to asset logs
                     if (!empty(trim($r->employeenumber))) {
                         $employee = Employee::where("employee_number", "=", trim($r->employeenumber))->first();
                         $desc = "Software Asset <strong>" . $software->asset_tag . "</strong> added to the database and assigned to employee <strong>" . $employee->first_name . " " . $employee->last_name . "</strong> with asset status <strong>" . $software->status . "</strong>.";
                     } else {
                         $desc = "Software Asset <strong>" . $software->asset_tag . "</strong> added to the database with status <strong>" . $software->status . "</strong>.";
                     }
                     $softwareLog = new SoftwareLog();
                     $softwareLog->user_id = Session::get("user_id");
                     $softwareLog->software_id = $software->id;
                     $softwareLog->employee_id = !empty($software->employee->id) ? $software->employee->id : null;
                     $softwareLog->description = $desc;
                     $softwareLog->transaction = "History";
                     $softwareLog->save();
                     //Parallel logging to system logs
                     $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> added software asset <strong>" . $software->asset_tag . "</strong>.";
                     $newLog = new UserLog();
                     $newLog->description = $desc;
                     $newLog->user_id = Session::get('user_id');
                     $newLog->type = "System";
                     $newLog->save();
                 }
             }
             File::delete($readFile);
             if ($hasCorrectRows) {
                 //Log the changes made
                 $desc = "(" . Session::get("user_type") . ") <b>" . Session::get("username") . "</b> has imported data to software assets database. ";
                 $newLog = new UserLog();
                 $newLog->description = $desc;
                 $newLog->user_id = Session::get('user_id');
                 $newLog->type = "System";
                 $newLog->save();
             }
             return $this->importResult($hasError, $hasCorrectRows, $rowsWithErrors, $error);
         }
     } else {
         return Redirect::to('/');
     }
 }
Пример #6
0
 public function deleteAssets()
 {
     if (Session::has('username') && Session::get('user_type') == "Root") {
         $assets = Input::get("asset_id");
         $hasDeletedAny = false;
         $noOfDeletedAssets = 0;
         foreach ($assets as $a) {
             $asset = Asset::where("id", "=", $a)->whereHas("classification", function ($query) {
                 $query->where("type", "=", "Network");
             })->first();
             if (!$asset) {
                 continue;
             }
             $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has deleted network asset ( type: " . $asset->classification->name . ")  <strong>" . $asset->asset_tag . "</strong>, SN: <strong>" . $asset->serial_number . "</strong>.";
             //Log the changes made
             $newLog = new UserLog();
             $newLog->description = $desc;
             $newLog->user_id = Session::get('user_id');
             $newLog->type = "System";
             $newLog->save();
             $hasDeletedAny = true;
             $noOfDeletedAssets += 1;
             $asset->delete();
         }
         if ($hasDeletedAny) {
             $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has deleted <strong>" . $noOfDeletedAssets . "</strong> network asset(s).";
             //Log the changes made
             $newLog = new UserLog();
             $newLog->description = $desc;
             $newLog->user_id = Session::get('user_id');
             $newLog->type = "System";
             $newLog->save();
         }
         return Redirect::to(Session::get("page"));
     } else {
         return Redirect::to("/");
     }
 }
Пример #7
0
 function update()
 {
     $this->filter_access('Assets', 'roled_edit', 'assets/index');
     $asset = new Asset();
     $asset->where('asset_id', $this->input->post('id'))->update(array('asset_name' => $this->input->post('asset_name'), 'asset_status' => $this->input->post('asset_status'), 'staff_id' => $this->input->post('staff_id'), 'date' => $this->input->post('date')));
     $this->session->set_flashdata('message', 'Asset Update successfuly.');
     redirect('assets/');
 }
Пример #8
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 = '';
             // 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::get('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 {
                 // Create the user
                 $user = Sentry::createUser(array('first_name' => $first_name, 'last_name' => $last_name, 'email' => $user_email, 'username' => $user_username, 'password' => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 12), 'activated' => true, 'permissions' => array('admin' => 0, 'user' => 1), 'notes' => 'User imported through asset importer'));
                 // Find the group using the group id
                 $userGroup = Sentry::findGroupById(3);
                 // Assign the group to the user
                 $user->addGroup($userGroup);
                 $this->comment('User ' . $first_name . ' created');
             }
         } 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->comment('Something went wrong! Location ' . $user_asset_location . ' was NOT created');
                     }
                 } 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->comment('Something went wrong! Category ' . $user_asset_category . ' was NOT created');
             }
         }
         // 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->comment('Something went wrong! Manufacturer ' . $user_asset_mfgr . ' was NOT created');
             }
         }
         // Check for the asset model match and create it if it doesn't exist
         if ($asset_model = Model::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 Model();
             $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->comment('Something went wrong! Asset Model ' . $user_asset_name . ' was NOT created');
             }
         }
         // 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->comment('Something went wrong! Company ' . $user_asset_company_name . ' was NOT created');
                 }
             }
         } 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->comment('Something went wrong! Asset ' . $user_asset_name . ' was NOT created');
             }
         }
         $this->comment('=====================================');
         return true;
     });
 }
Пример #9
0
 public function exportOfficeBegin()
 {
     if (Session::has('username') && (Session::get('user_type') == "Root" || Session::get('user_type') == "Admin")) {
         if (isset($_GET["search"])) {
             $view = View::make("Export.export_office");
             $view->nav = "system";
             $view->tab = "office";
             $input = Input::all();
             $asset_tag = trim($input["asset_tag"]) != null ? str_replace(' ', '%', trim($input["asset_tag"])) : "";
             $serial_number = trim($input["serial_number"]) != null ? str_replace(' ', '%', trim($input["serial_number"])) : "";
             $employee = trim($input["employee"]) != null ? trim($input["employee"]) : "";
             $classification_id = trim($input["classification_id"]) != null ? str_replace(' ', '%', trim($input["classification_id"])) : "";
             $asset_status = !empty($input["asset_status"]) ? $input["asset_status"] : "";
             $model = !empty($input["model"]) ? $input["model"] : "";
             $warranty_start = trim($input["warranty_start"]) != null ? str_replace(' ', '%', trim($input["warranty_start"])) : "";
             $warranty_end = trim($input["warranty_end"]) != null ? str_replace(' ', '%', trim($input["warranty_end"])) : "";
             $assets = Asset::where("asset_tag", "LIKE", "%{$asset_tag}%")->whereHas("classification", function ($query) {
                 $query->where("type", "=", "Office");
             })->where(function ($query) use($serial_number) {
                 if (!empty($serial_number)) {
                     $query->where("serial_number", "LIKE", $serial_number);
                 }
             })->where(function ($query) use($employee) {
                 $emp = "%" . str_replace(' ', '%', $employee) . "%";
                 $emp = DB::connection()->getPdo()->quote($emp);
                 if (!empty($employee)) {
                     $query->where("employee_number", "LIKE", $employee)->orWhereHas("employee", function ($q) use($employee, $emp) {
                         $q->whereRaw("concat(first_name,' ',last_name) LIKE {$emp}");
                     })->orWhereHas("employee", function ($q) use($employee, $emp) {
                         $q->whereRaw("concat(last_name,' ',first_name) LIKE {$emp}");
                     });
                 }
             })->where(function ($query) use($classification_id) {
                 if (!empty($classification_id)) {
                     $query->where("classification_id", "LIKE", "{$classification_id}");
                 }
             })->where(function ($query) use($asset_status) {
                 if (!empty($asset_status)) {
                     $query->where("status", "=", "{$asset_status}");
                 }
             })->where(function ($query) use($model) {
                 if (!empty($model)) {
                     $query->where("model_id", "=", $model);
                 }
             })->where(function ($query) use($warranty_start) {
                 if (!empty($warranty_start)) {
                     $query->where("warranty_start", "LIKE", "{$warranty_start}%");
                 }
             })->where(function ($query) use($warranty_end) {
                 if (!empty($warranty_end)) {
                     $query->where("warranty_end", "LIKE", "{$warranty_end}%");
                 }
             })->orderBy("asset_tag", "asc")->paginate(25);
             $results = Asset::where("asset_tag", "LIKE", "%{$asset_tag}%")->whereHas("classification", function ($query) {
                 $query->where("type", "=", "Office");
             })->where(function ($query) use($serial_number) {
                 if (!empty($serial_number)) {
                     $query->where("serial_number", "LIKE", $serial_number);
                 }
             })->where(function ($query) use($employee) {
                 $emp = "%" . str_replace(' ', '%', $employee) . "%";
                 $emp = DB::connection()->getPdo()->quote($emp);
                 if (!empty($employee)) {
                     $query->where("employee_number", "LIKE", $employee)->orWhereHas("employee", function ($q) use($employee, $emp) {
                         $q->whereRaw("concat(first_name,' ',last_name) LIKE {$emp}");
                     })->orWhereHas("employee", function ($q) use($employee, $emp) {
                         $q->whereRaw("concat(last_name,' ',first_name) LIKE {$emp}");
                     });
                 }
             })->where(function ($query) use($classification_id) {
                 if (!empty($classification_id)) {
                     $query->where("classification_id", "LIKE", "{$classification_id}");
                 }
             })->where(function ($query) use($asset_status) {
                 if (!empty($asset_status)) {
                     $query->where("status", "=", "{$asset_status}");
                 }
             })->where(function ($query) use($model) {
                 if (!empty($model)) {
                     $query->where("model_id", "=", $model);
                 }
             })->where(function ($query) use($warranty_start) {
                 if (!empty($warranty_start)) {
                     $query->where("warranty_start", "LIKE", "{$warranty_start}%");
                 }
             })->where(function ($query) use($warranty_end) {
                 if (!empty($warranty_end)) {
                     $query->where("warranty_end", "LIKE", "{$warranty_end}%");
                 }
             })->count();
             $getAssetClassifications = AssetClassification::where("type", "=", "Office")->get();
             $assetClassifications = array("" => "All");
             foreach ($getAssetClassifications as $gac) {
                 $assetClassifications[$gac->id] = $gac->name;
             }
             $getAssetModels = Model::whereHas('classification', function ($query) {
                 $query->where("type", "=", "Office");
             })->orderBy("name", "asc")->get();
             $assetModels = array("" => "--Select One--");
             foreach ($getAssetModels as $gam) {
                 $assetModels[$gam->id] = $gam->name;
             }
             $view->assetModels = $assetModels;
             $view->assets = $assets;
             $view->results = $results;
             $view->assetClassifications = $assetClassifications;
             Input::flash();
             return $view;
         } else {
             if (isset($_GET["export"])) {
                 $input = Input::all();
                 $asset_tag = trim($input["asset_tag"]) != null ? str_replace(' ', '%', trim($input["asset_tag"])) : "";
                 $serial_number = trim($input["serial_number"]) != null ? str_replace(' ', '%', trim($input["serial_number"])) : "";
                 $employee = trim($input["employee"]) != null ? trim($input["employee"]) : "";
                 $classification_id = trim($input["classification_id"]) != null ? str_replace(' ', '%', trim($input["classification_id"])) : "";
                 $asset_status = !empty($input["asset_status"]) ? $input["asset_status"] : "";
                 $model = !empty($input["model"]) ? $input["model"] : "";
                 $warranty_start = trim($input["warranty_start"]) != null ? str_replace(' ', '%', trim($input["warranty_start"])) : "";
                 $warranty_end = trim($input["warranty_end"]) != null ? str_replace(' ', '%', trim($input["warranty_end"])) : "";
                 $assets = Asset::where("asset_tag", "LIKE", "%{$asset_tag}%")->whereHas("classification", function ($query) {
                     $query->where("type", "=", "Office");
                 })->where(function ($query) use($serial_number) {
                     if (!empty($serial_number)) {
                         $query->where("serial_number", "LIKE", $serial_number);
                     }
                 })->where(function ($query) use($employee) {
                     $emp = "%" . str_replace(' ', '%', $employee) . "%";
                     $emp = DB::connection()->getPdo()->quote($emp);
                     if (!empty($employee)) {
                         $query->where("employee_number", "LIKE", $employee)->orWhereHas("employee", function ($q) use($employee, $emp) {
                             $q->whereRaw("concat(first_name,' ',last_name) LIKE {$emp}");
                         })->orWhereHas("employee", function ($q) use($employee, $emp) {
                             $q->whereRaw("concat(last_name,' ',first_name) LIKE {$emp}");
                         });
                     }
                 })->where(function ($query) use($classification_id) {
                     if (!empty($classification_id)) {
                         $query->where("classification_id", "LIKE", "{$classification_id}");
                     }
                 })->where(function ($query) use($asset_status) {
                     if (!empty($asset_status)) {
                         $query->where("status", "=", "{$asset_status}");
                     }
                 })->where(function ($query) use($model) {
                     if (!empty($model)) {
                         $query->where("model_id", "=", $model);
                     }
                 })->where(function ($query) use($warranty_start) {
                     if (!empty($warranty_start)) {
                         $query->where("warranty_start", "LIKE", "{$warranty_start}%");
                     }
                 })->where(function ($query) use($warranty_end) {
                     if (!empty($warranty_end)) {
                         $query->where("warranty_end", "LIKE", "{$warranty_end}%");
                     }
                 })->orderBy("asset_tag")->get(array("id", "asset_tag", "serial_number", "model_id", "employee_number", "warranty_start", "warranty_end", "notes", "location", "classification_id", "date_added", "status"));
                 if ($assets->count() > 0) {
                     if (isset($_GET["format"])) {
                         $assetsArray = array();
                         foreach ($assets as $a) {
                             $assetsArray[$a->id] = array("Asset Tag" => $a->asset_tag, "Serial Number" => $a->serial_number, "Employee" => !empty($a->employee->first_name) ? $a->employee->first_name . " " . $a->employee->last_name : "Unassigned.", "Employee Number" => !empty($a->employee->employee_number) ? $a->employee->employee_number : null, "Model" => !empty($a->model->name) ? $a->model->name : "No Information.", "Notes" => !empty($a->notes) ? $a->notes : null, "Location" => !empty($a->location) ? $a->location : "No Information.", "Warranty Start Date" => !empty($a->warranty_start) ? DateTime::createFromFormat("Y-m-d", $a->warranty_start)->format("F d, Y") : "No Information", "Warranty End Date" => !empty($a->warranty_end) ? DateTime::createFromFormat("Y-m-d", $a->warranty_end)->format("F d, Y") : "No Information", "Date Added to System" => DateTime::createFromFormat("Y-m-d H:i:s", $a->date_added)->format("F d, Y g:iA"), "Asset Type" => $a->classification->name, "Status" => $a->status);
                         }
                     } else {
                         $assetsArray = $assets->toArray();
                     }
                     Excel::create('office_assets_export_' . str_random(6), function ($excel) use($assetsArray) {
                         // Set the title
                         $excel->setTitle('Office Assets Export');
                         // Chain the setters
                         $excel->setCreator('Vault')->setCompany('Vault');
                         // Call them separately
                         $excel->setDescription('Office Assets Data Export from IT Vault.');
                         // Our first sheet
                         $excel->sheet('Office Assets', function ($sheet) use($assetsArray) {
                             $sheet->fromArray($assetsArray);
                         });
                     })->download('xlsx');
                 } else {
                     Input::flash();
                     return Redirect::to('export/network')->withInput()->with('info', "No records have been retrieved. Data export cancelled.");
                 }
             }
         }
     } else {
         return Redirect::to("/");
     }
 }
Пример #10
0
 public function validateData($items)
 {
     $assetnames = array();
     foreach ($items as $item) {
         $assetnames[] = strval($item['SKU']);
     }
     $namecount = array_count_values($assetnames);
     $dbval = array();
     foreach ($items as $item) {
         $dbval[$item['SKU']] = Asset::where('SKU', $item['SKU'])->count();
     }
     return array('in' => $namecount, 'db' => $dbval);
 }
Пример #11
0
 public static function ExtractAdAsset($merchant_id, $selection = true)
 {
     $category = Asset::where('merchantId', $merchant_id)->get()->toArray();
     if ($selection) {
         $cats = array('' => 'All');
     } else {
         $cats = array();
     }
     if (count($category) > 0) {
         foreach ($category as $cat) {
             $cats[$cat['_id']] = $cat['itemDescription'];
         }
     }
     return $cats;
 }
 public function findAsset()
 {
     //input from Backbone
     $queryParams = Input::get('queryParams');
     $foundAsset = Asset::where('serial_number', '=', $queryParams['serial_number'])->where('asset_type', '=', $queryParams['asset_type'])->get();
     //if found, returns the object, else it returns false
     return Response::json($foundAsset);
 }