Esempio n. 1
0
 public function redirector($assetClassId, $intent, $id = null)
 {
     if (Session::has('username') && (Session::get('user_type') == "Root" || Session::get('user_type') == "Admin")) {
         //This method works like magic.
         $assetClassification = AssetClassification::where("id", "=", $assetClassId)->where("type", "=", "Network")->first();
         if (!$assetClassification) {
             return Redirect::to("assets/network");
         }
         if ($intent == "add") {
             return Redirect::to("assets/network/add/" . $assetClassification->url_key);
         }
         return Redirect::to("assets/network/update/" . $assetClassification->url_key . "/" . $id);
     } else {
         return Redirect::to("/");
     }
 }
 public function updateAssetModel($id)
 {
     if (Session::has('username') && (Session::get('user_type') == "Root" || Session::get('user_type') == "Admin")) {
         $view = View::make("Settings.Assets.settings_update_asset_model");
         $assetModel = Model::find($id);
         if (!$assetModel) {
             return Redirect::to("settings/assets/assetmodels");
         }
         $getAssetClassifications = AssetClassification::orderBy("name")->get();
         $assetClassifications = array("--Select One--");
         foreach ($getAssetClassifications as $gac) {
             $assetClassifications[$gac->id] = $gac->name;
         }
         $view->assetClassifications = $assetClassifications;
         $view->assetModel = $assetModel;
         $view->nav = "system";
         return $view;
     } else {
         return Redirect::to("/");
     }
 }
Esempio n. 3
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("/");
     }
 }