Example #1
0
    protected function btnSearch_Click()
    {
        $this->dtrAssetLog_Bind();
    }
    protected function dtrAssetLog_Bind()
    {
        $result = $this->GetAssetLog();
        $this->dtrAssetLog->TotalItemCount = sizeof($result);
        $this->dtrAssetLog->DataSource = $result;
    }
    protected function GetAssetLog()
    {
        $objClauses = array();
        array_push($objClauses, QQ::OrderBy(QQN::Assetsauditlog()->RealReturnDate));
        if ($this->txtSearchTerm->Text == "") {
            $condition = QQ::Equal(QQN::Assetsauditlog()->Owner, $_SESSION['User']);
            $myassets = Assetsauditlog::QueryArray($condition, $objClauses);
        } else {
            $objCondition = QQ::AndCondition(QQ::OrCondition(QQ::Like(QQN::Assetsauditlog()->Asin, '%' . $this->txtSearchTerm->Text . '%'), QQ::Like(QQN::Assetsauditlog()->Email, '%' . $this->txtSearchTerm->Text . '%'), QQ::Like(QQN::Assetsauditlog()->Title, '%' . $this->txtSearchTerm->Text . '%'), QQ::Like(QQN::Assetsauditlog()->FullName, '%' . $this->txtSearchTerm->Text . '%')), QQ::Equal(QQN::Assetsauditlog()->Owner, $_SESSION['User']));
            $objDbResult = Assetsauditlog::QueryArray($objCondition, $objClauses);
            $myassets = $objDbResult;
        }
        return $myassets;
    }
    protected function pnlHeader_Create()
    {
        $this->pnlHeader = new pnlHeader($this, 'CloseEditPane');
    }
}
AssetLog::Run('AssetLog');
Example #2
0
<?php

$logs = UserLog::orderBy("id", "desc")->take(10)->get();
?>
<b>System Logs</b>
<table border="1">
	@foreach($logs as $log)
	<tr>
		<td>{{ $log->description }}</td>	
	</tr>
	@endforeach
</table>
<br/>

<?php 
$assetLogs = AssetLog::orderBy("id", "desc")->take(10)->get();
?>

<b>Asset Logs</b>
	<table border="1">
	@foreach($assetLogs as $log)
	<tr>
		<td>{{ $log->description }}</td>	
	</tr>
	@endforeach
	</table>
<br/>

<?php 
$softwareLogs = SoftwareLog::orderBy("id", "desc")->take(10)->get();
?>
 private function processImport($file, $assetClass)
 {
     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/network/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["assettag"]) && isset($ex["serialnumber"]) && 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/network/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.
                 /*"CP"=>"CP",
                 			"Dual Boot"=>"Dual Boot",
                 		"Nokia"=>"Nokia",
                 		"NWL"=>"NWL",
                 		"OAM"=>"OAM",
                 		"Recruitment"=>"Recruitment",
                 		"Ubuntu"=>"Ubuntu"
                 		*
                 		*/
                 $warranty_start = !empty(trim($r->warrantystart)) ? trim($r->warrantystart) : "1994-04-16";
                 $validator = Validator::make(array("asset tag" => trim($r->assettag), "serial number" => trim($r->serialnumber), "model" => trim($r->modelid), "employee number" => trim($r->employeenumber), "status" => trim($r->status), "warranty start date" => trim($r->warrantystart), "warranty end date" => trim($r->warrantyend)), array("asset tag" => "required|unique:tbl_assets,asset_tag", "serial number" => "required|unique:tbl_assets,serial_number", "model" => "exists:tbl_asset_models,id", "employee number" => "numeric|exists:tbl_employees,employee_number", "status" => "required|in:Available,For Repair,Installed,Lost,Retired", "warranty start date" => "required_with:warranty end date|date:Y-m-d", "warranty end date" => "date:Y-m-d|after:" . $warranty_start), 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("asset tag")) {
                         foreach ($validator->messages()->get("asset tag") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("serial number")) {
                         foreach ($validator->messages()->get("serial number") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("model")) {
                         foreach ($validator->messages()->get("model") 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("status")) {
                         foreach ($validator->messages()->get("status") 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 ($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 ($r->modelid != null && !Model::where("classification_id", "=", $assetClass)->where("id", "=", $r->modelid)->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 . ". " . "The asset model does not belong to the selected asset type." . "<br/>";
                 }
                 if (!$rowHasError) {
                     $hasCorrectRows = true;
                     //To set image as null if asset class is not laptop.
                     $image = !AssetClassification::where("id", "=", $assetClass)->where("name", "=", "Laptops")->first() ? null : $r->image;
                     //Add the new asset
                     $asset = new Asset();
                     $asset->asset_tag = trim($r->assettag);
                     $asset->serial_number = trim($r->serialnumber) != null ? trim($r->serialnumber) : null;
                     $asset->model_id = $r->modelid != null ? $r->modelid : null;
                     $asset->location = $r->location != null ? $r->location : null;
                     $asset->employee_number = $r->employeenumber != null ? trim($r->employeenumber) : null;
                     $asset->warranty_start = trim($r->warrantystart) != null ? trim($r->warrantystart) : null;
                     $asset->warranty_end = trim($r->warrantyend) != null ? $r->warrantyend : null;
                     $asset->classification_id = $assetClass;
                     $asset->status = trim($r->status);
                     $asset->notes = trim($r->notes) != null ? trim($r->notes) : null;
                     $asset->date_added = date("Y-m-d H:i:s");
                     $asset->save();
                     //Log the new asset to asset logs
                     if (!empty(trim($r->employeenumber))) {
                         $employee = Employee::where("employee_number", "=", $r->employeenumber)->first();
                         $desc = "Network Asset <strong>" . $asset->asset_tag . ",</strong> SN: <strong>" . $asset->serial_number . "</strong> added to the database and assigned to employee <strong>" . $employee->first_name . " " . $employee->last_name . "</strong> with asset status <strong>" . $asset->status . "</strong>.";
                     } else {
                         $desc = "Network Asset <strong>" . $asset->asset_tag . "</strong>, SN: <strong>" . $asset->serial_number . "</strong> added to the database with status <strong>" . $asset->status . "</strong>.";
                     }
                     $assetLog = new AssetLog();
                     $assetLog->user_id = Session::get("user_id");
                     $assetLog->asset_id = $asset->id;
                     $assetLog->employee_id = !empty($asset->employee->id) ? $asset->employee->id : null;
                     $assetLog->description = $desc;
                     $assetLog->transaction = "History";
                     $assetLog->save();
                     //Parallel logging to system logs
                     $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> added network asset <strong>" . $asset->asset_tag . "</strong>, SN: <strong>" . $asset->serial_number . "</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 network assets database. ";
                 $newLog = new UserLog();
                 $newLog->description = $desc;
                 $newLog->user_id = Session::get('user_id');
                 $newLog->save();
             }
             return $this->importResult($hasError, $hasCorrectRows, $rowsWithErrors, $error);
         }
     } else {
         return Redirect::to('/');
     }
 }
 public function osImage()
 {
     $user = Input::get('userid');
     $status = Input::get('function_params');
     $assettag = Input::get('assettag');
     DB::table('tbl_assets')->where('id', $user)->update(array('image' => $status));
     $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has updated client asset <strong>" . $assettag . "'s</strong> information. These are the fields that have been modified:<br/>" . "1.) image to " . $status;
     //Log the changes made
     $newLog = new UserLog();
     $newLog->description = $desc;
     $newLog->user_id = Session::get('user_id');
     $newLog->type = "System";
     $newLog->save();
     //Parallel logging to asset logs
     $assetLog = new AssetLog();
     $assetLog->asset_id = $user;
     $assetLog->user_id = Session::get("user_id");
     $assetLog->description = $desc;
     $assetLog->transaction = "Updates";
     $assetLog->save();
     return Redirect::to("assets/client/view/laptops");
 }