Ejemplo n.º 1
0
 /**
  * Get data formatted for JSON output
  *
  * @param Array $attach Optional: sub-resources to attach to the base data, if available. Possible values: options, images, custom_fields
  * @return Array $output The formatted data
  */
 public function getOutput($attach = [])
 {
     $output = array('id' => $this->id, 'name' => $this->name, 'sku' => $this->sku, 'description' => $this->description, 'price' => $this->price, 'cost_price' => $this->cost_price, 'retail_price' => $this->retail_price, 'sale_price' => $this->sale_price, 'calculated_price' => $this->calculated_price, 'warranty' => $this->warranty, 'custom_url' => $this->custom_url);
     if (in_array('options', $attach) && isset($this->_options)) {
         $output['options'] = unserialize($this->_options);
     }
     if (in_array('images', $attach)) {
         $images = Image::where('product_id', $this->id)->get();
         $output['images'] = [];
         if (count($images)) {
             foreach ($images as $image) {
                 $output['images'][] = $image->mapData();
             }
         }
     }
     if (in_array('custom_fields', $attach)) {
         $custom_fields = CustomField::where('product_id', $this->id)->get();
         $output['custom_fields'] = [];
         if (count($custom_fields)) {
             foreach ($custom_fields as $custom_field) {
                 $output['custom_fields'][] = $custom_field->mapData();
             }
         }
     }
     return $output;
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     foreach (\App\Models\CustomField::all() as $custom_field) {
         if ($custom_field->format == 'regex:/^MAC$/') {
             $custom_field->format = 'regex:/^[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}$/';
         }
         $custom_field->save();
     }
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     foreach (\App\Models\CustomField::all() as $custom_field) {
         switch ($custom_field->format) {
             case '[a-zA-Z]*':
                 $custom_field->format = 'ALPHA';
                 break;
             case '[0-9]*':
                 $custom_field->format = 'NUMERIC';
                 break;
             case '([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])':
                 $custom_field->format = 'IP';
                 break;
                 //ANYTHING ELSE.
             //ANYTHING ELSE.
             default:
                 $custom_field->format = 'regex:/^' . $custom_field->format . "\$/";
         }
         $custom_field->save();
     }
 }
 /**
  * Run the migrations.
  * "ANY" => "",
  * "ALPHA" => "alpha",
  * "EMAIL" => "email",
  * "DATE" => "date",
  *  "URL" => "url",
  * "NUMERIC" => "numeric",
  * "MAC" => "regex:/^[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}$/",
  * "IP" => "ip"
  *
  * @return void
  */
 public function up()
 {
     foreach (\App\Models\CustomField::all() as $custom_field) {
         // Handle alphanumeric
         if (stripos($custom_field->format, 'ALPHA') !== false) {
             $custom_field->format = 'alpha';
             // Numeric
         } elseif (stripos($custom_field->format, 'NUMERIC') !== false) {
             $custom_field->format = 'numeric';
             // IP
         } elseif (stripos($custom_field->format, 'IP') !== false) {
             $custom_field->format = 'ip';
             // Email
         } elseif (stripos($custom_field->format, 'EMAIL') !== false) {
             $custom_field->format = 'email';
             // MAC
         } elseif (stripos($custom_field->format, 'regex:/^[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}$/') !== false) {
             $custom_field->format = 'regex:/^[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}$/';
             // Date
         } elseif (stripos($custom_field->format, 'DATE') !== false) {
             $custom_field->format = 'date';
             // URL
         } elseif (stripos($custom_field->format, 'URL') !== false) {
             $custom_field->format = 'url';
             // ANY
         } elseif (stripos($custom_field->format, 'ANY') !== false) {
             $custom_field->format = '';
             // Fix any custom regexes
         } else {
             $tmp_custom = str_replace('regex:/^', '', $custom_field->format);
             $tmp_custom = str_replace('$/', '', $tmp_custom);
             $custom_field->format = 'regex:/^' . $tmp_custom . '$/';
         }
         $custom_field->save();
     }
 }
Ejemplo n.º 5
0
 /**
  * Query builder scope to search on text for complex Bootstrap Tables API
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $search      Search term
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeTextSearch($query, $search)
 {
     $search = explode(' OR ', $search);
     return $query->where(function ($query) use($search) {
         foreach ($search as $search) {
             $query->whereHas('model', function ($query) use($search) {
                 $query->whereHas('category', function ($query) use($search) {
                     $query->where(function ($query) use($search) {
                         $query->where('categories.name', 'LIKE', '%' . $search . '%')->orWhere('models.name', 'LIKE', '%' . $search . '%')->orWhere('models.modelno', 'LIKE', '%' . $search . '%');
                     });
                 });
             })->orWhereHas('model', function ($query) use($search) {
                 $query->whereHas('manufacturer', function ($query) use($search) {
                     $query->where(function ($query) use($search) {
                         $query->where('manufacturers.name', 'LIKE', '%' . $search . '%');
                     });
                 });
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('assetstatus', function ($query) use($search) {
                     $query->where('status_labels.name', 'LIKE', '%' . $search . '%');
                 });
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('company', function ($query) use($search) {
                     $query->where('companies.name', 'LIKE', '%' . $search . '%');
                 });
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('defaultLoc', function ($query) use($search) {
                     $query->where('locations.name', 'LIKE', '%' . $search . '%');
                 });
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('assigneduser', function ($query) use($search) {
                     $query->where(function ($query) use($search) {
                         $query->where('users.first_name', 'LIKE', '%' . $search . '%')->orWhere('users.last_name', 'LIKE', '%' . $search . '%')->orWhere(function ($query) use($search) {
                             $query->whereHas('userloc', function ($query) use($search) {
                                 $query->where('locations.name', 'LIKE', '%' . $search . '%');
                             });
                         });
                     });
                 });
             })->orWhere('assets.name', 'LIKE', '%' . $search . '%')->orWhere('assets.asset_tag', 'LIKE', '%' . $search . '%')->orWhere('assets.serial', 'LIKE', '%' . $search . '%')->orWhere('assets.order_number', 'LIKE', '%' . $search . '%')->orWhere('assets.notes', 'LIKE', '%' . $search . '%');
         }
         foreach (CustomField::all() as $field) {
             $query->orWhere($field->db_column_name(), 'LIKE', "%{$search}%");
         }
     });
 }
Ejemplo n.º 6
0
 /**
  * Generates the JSON used to display the asset listing.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @param  string  $status
  * @since [v2.0]
  * @return String JSON
  */
 public function getDatatable(Request $request, $status = null)
 {
     $assets = Company::scopeCompanyables(Asset::select('assets.*'))->with('model', 'assigneduser', 'assigneduser.userloc', 'assetstatus', 'defaultLoc', 'assetlog', 'model', 'model.category', 'model.manufacturer', 'model.fieldset', 'assetstatus', 'assetloc', 'company')->Hardware();
     if ($request->has('search')) {
         $assets = $assets->TextSearch(e($request->get('search')));
     }
     if ($request->has('offset')) {
         $offset = e($request->get('offset'));
     } else {
         $offset = 0;
     }
     if ($request->has('limit')) {
         $limit = e($request->get('limit'));
     } else {
         $limit = 50;
     }
     if ($request->has('order_number')) {
         $assets->where('order_number', '=', e($request->get('order_number')));
     }
     switch ($status) {
         case 'Deleted':
             $assets->withTrashed()->Deleted();
             break;
         case 'Pending':
             $assets->Pending();
             break;
         case 'RTD':
             $assets->RTD();
             break;
         case 'Undeployable':
             $assets->Undeployable();
             break;
         case 'Archived':
             $assets->Archived();
             break;
         case 'Requestable':
             $assets->RequestableAssets();
             break;
         case 'Deployed':
             $assets->Deployed();
             break;
         default:
             $assets->NotArchived();
             break;
     }
     if ($request->has('status_id')) {
         $assets->where('status_id', '=', e($request->get('status_id')));
     }
     $allowed_columns = ['id', 'name', 'asset_tag', 'serial', 'model', 'model_number', 'last_checkout', 'category', 'manufacturer', 'notes', 'expected_checkin', 'order_number', 'companyName', 'location', 'image', 'status_label', 'assigned_to', 'created_at', 'purchase_date', 'purchase_cost'];
     $all_custom_fields = CustomField::all();
     //used as a 'cache' of custom fields throughout this page load
     foreach ($all_custom_fields as $field) {
         $allowed_columns[] = $field->db_column_name();
     }
     $order = $request->get('order') === 'asc' ? 'asc' : 'desc';
     $sort = in_array($request->get('sort'), $allowed_columns) ? $request->get('sort') : 'asset_tag';
     switch ($sort) {
         case 'model':
             $assets = $assets->OrderModels($order);
             break;
         case 'model_number':
             $assets = $assets->OrderModelNumber($order);
             break;
         case 'category':
             $assets = $assets->OrderCategory($order);
             break;
         case 'manufacturer':
             $assets = $assets->OrderManufacturer($order);
             break;
         case 'companyName':
             $assets = $assets->OrderCompany($order);
             break;
         case 'location':
             $assets = $assets->OrderLocation($order);
             break;
         case 'status_label':
             $assets = $assets->OrderStatus($order);
             break;
         case 'assigned_to':
             $assets = $assets->OrderAssigned($order);
             break;
         default:
             $assets = $assets->orderBy($sort, $order);
             break;
     }
     $assetCount = $assets->count();
     $assets = $assets->skip($offset)->take($limit)->get();
     $rows = array();
     foreach ($assets as $asset) {
         $inout = '';
         $actions = '<div style="white-space: nowrap;">';
         if ($asset->deleted_at == '') {
             if (Gate::allows('assets.create')) {
                 $actions .= '<a href="' . route('clone/hardware', $asset->id) . '" class="btn btn-info btn-sm" title="Clone asset" data-toggle="tooltip"><i class="fa fa-clone"></i></a> ';
             }
             if (Gate::allows('assets.edit')) {
                 $actions .= '<a href="' . route('update/hardware', $asset->id) . '" class="btn btn-warning btn-sm" title="Edit asset" data-toggle="tooltip"><i class="fa fa-pencil icon-white"></i></a> ';
             }
             if (Gate::allows('assets.delete')) {
                 $actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('delete/hardware', $asset->id) . '" data-content="' . trans('admin/hardware/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($asset->asset_tag) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
             }
         } elseif ($asset->model->deleted_at == '') {
             $actions .= '<a href="' . route('restore/hardware', $asset->id) . '" title="Restore asset" data-toggle="tooltip" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>';
         }
         $actions .= '</div>';
         if ($asset->availableForCheckout()) {
             if (Gate::allows('assets.checkout')) {
                 $inout = '<a href="' . route('checkout/hardware', $asset->id) . '" class="btn btn-info btn-sm" title="Checkout this asset to a user" data-toggle="tooltip">' . trans('general.checkout') . '</a>';
             }
         } else {
             if (Gate::allows('assets.checkin')) {
                 $inout = '<a href="' . route('checkin/hardware', $asset->id) . '" class="btn btn-primary btn-sm" title="Checkin this asset" data-toggle="tooltip">' . trans('general.checkin') . '</a>';
             }
         }
         $purchase_cost = Helper::formatCurrencyOutput($asset->purchase_cost);
         $row = array('checkbox' => '<div class="text-center"><input type="checkbox" name="edit_asset[' . $asset->id . ']" class="one_required"></div>', 'id' => $asset->id, 'image' => $asset->image && $asset->image != '' ? '<img src="' . config('app.url') . '/uploads/assets/' . $asset->image . '" height=50 width=50>' : ($asset->model && $asset->model->image != '' ? '<img src="' . config('app.url') . '/uploads/models/' . $asset->model->image . '" height=40 width=50>' : ''), 'name' => '<a title="' . e($asset->name) . '" href="hardware/' . $asset->id . '/view">' . e($asset->name) . '</a>', 'asset_tag' => '<a title="' . e($asset->asset_tag) . '" href="hardware/' . $asset->id . '/view">' . e($asset->asset_tag) . '</a>', 'serial' => e($asset->serial), 'model' => $asset->model ? (string) link_to('/hardware/models/' . $asset->model->id . '/view', e($asset->model->name)) : 'No model', 'model_number' => $asset->model && $asset->model->modelno ? (string) $asset->model->modelno : '', 'status_label' => $asset->assigneduser ? 'Deployed' : (e($asset->assetstatus) ? e($asset->assetstatus->name) : ''), 'assigned_to' => $asset->assigneduser ? (string) link_to(config('app.url') . '/admin/users/' . $asset->assigned_to . '/view', e($asset->assigneduser->fullName())) : '', 'location' => $asset->assigneduser && $asset->assigneduser->userloc != '' ? (string) link_to('admin/settings/locations/' . $asset->assigneduser->userloc->id . '/view', e($asset->assigneduser->userloc->name)) : ($asset->defaultLoc != '' ? (string) link_to('admin/settings/locations/' . $asset->defaultLoc->id . '/edit', e($asset->defaultLoc->name)) : ''), 'category' => $asset->model && $asset->model->category ? (string) link_to('/admin/settings/categories/' . $asset->model->category->id . '/view', e($asset->model->category->name)) : '', 'manufacturer' => $asset->model && $asset->model->manufacturer ? (string) link_to('/admin/settings/manufacturers/' . $asset->model->manufacturer->id . '/view', e($asset->model->manufacturer->name)) : '', 'eol' => $asset->eol_date() ? $asset->eol_date() : '', 'purchase_cost' => $purchase_cost, 'purchase_date' => $asset->purchase_date ? $asset->purchase_date : '', 'notes' => e($asset->notes), 'order_number' => $asset->order_number != '' ? '<a href="' . config('app.url') . '/hardware?order_number=' . e($asset->order_number) . '">' . e($asset->order_number) . '</a>' : '', 'last_checkout' => $asset->last_checkout != '' ? e($asset->last_checkout) : '', 'expected_checkin' => $asset->expected_checkin != '' ? e($asset->expected_checkin) : '', 'created_at' => $asset->created_at != '' ? e($asset->created_at->format('F j, Y h:iA')) : '', 'change' => $inout ? $inout : '', 'actions' => $actions ? $actions : '', 'companyName' => is_null($asset->company) ? '' : e($asset->company->name));
         foreach ($all_custom_fields as $field) {
             $column_name = $field->db_column_name();
             if ($field->isFieldDecryptable($asset->{$column_name})) {
                 if (Gate::allows('admin')) {
                     if ($field->format == 'URL' && $asset->{$column_name} != '') {
                         $row[$column_name] = '<a href="' . Helper::gracefulDecrypt($field, $asset->{$column_name}) . '" target="_blank">' . Helper::gracefulDecrypt($field, $asset->{$column_name}) . '</a>';
                     } else {
                         $row[$column_name] = Helper::gracefulDecrypt($field, $asset->{$column_name});
                     }
                 } else {
                     $row[$field->db_column_name()] = strtoupper(trans('admin/custom_fields/general.encrypted'));
                 }
             } else {
                 if ($field->format == 'URL' && $asset->{$field->db_column_name()} != '') {
                     $row[$field->db_column_name()] = '<a href="' . $asset->{$field->db_column_name()} . '" target="_blank">' . $asset->{$field->db_column_name()} . '</a>';
                 } else {
                     $row[$field->db_column_name()] = e($asset->{$field->db_column_name()});
                 }
             }
         }
         $rows[] = $row;
     }
     $data = array('total' => $assetCount, 'rows' => $rows);
     return $data;
 }
Ejemplo n.º 7
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $filename = $this->argument('filename');
     if (!$this->option('web-importer')) {
         $logFile = $this->option('logfile');
         \Log::useFiles($logFile);
         if ($this->option('testrun')) {
             $this->comment('====== TEST ONLY Asset Import for ' . $filename . ' ====');
             $this->comment('============== NO DATA WILL BE WRITTEN ==============');
         } else {
             $this->comment('======= Importing Assets from ' . $filename . ' =========');
         }
     }
     if (!ini_get("auto_detect_line_endings")) {
         ini_set("auto_detect_line_endings", '1');
     }
     $csv = Reader::createFromPath($this->argument('filename'));
     $csv->setNewline("\r\n");
     $results = $csv->fetchAssoc();
     $newarray = null;
     foreach ($results as $index => $arraytoNormalize) {
         $internalnewarray = array_change_key_case($arraytoNormalize);
         $newarray[$index] = $internalnewarray;
     }
     $this->locations = Location::All(['name', 'id']);
     $this->categories = Category::All(['name', 'category_type', 'id']);
     $this->manufacturers = Manufacturer::All(['name', 'id']);
     $this->asset_models = AssetModel::All(['name', 'modelno', 'category_id', 'manufacturer_id', 'id']);
     $this->companies = Company::All(['name', 'id']);
     $this->status_labels = Statuslabel::All(['name', 'id']);
     $this->suppliers = Supplier::All(['name', 'id']);
     $this->assets = Asset::all(['asset_tag']);
     $this->accessories = Accessory::All(['name']);
     $this->consumables = Consumable::All(['name']);
     $this->customfields = CustomField::All(['name']);
     $bar = null;
     if (!$this->option('web-importer')) {
         $bar = $this->output->createProgressBar(count($newarray));
     }
     // Loop through the records
     DB::transaction(function () use(&$newarray, $bar) {
         Model::unguard();
         $item_type = strtolower($this->option('item-type'));
         foreach ($newarray as $row) {
             // Let's just map some of these entries to more user friendly words
             // Fetch general items here, fetch item type specific items in respective methods
             /** @var Asset, License, Accessory, or Consumable $item_type */
             $item_category = $this->array_smart_fetch($row, "category");
             $item_company_name = $this->array_smart_fetch($row, "company");
             $item_location = $this->array_smart_fetch($row, "location");
             $item_status_name = $this->array_smart_fetch($row, "status");
             $item["item_name"] = $this->array_smart_fetch($row, "item name");
             if ($this->array_smart_fetch($row, "purchase date") != '') {
                 $item["purchase_date"] = date("Y-m-d 00:00:01", strtotime($this->array_smart_fetch($row, "purchase date")));
             } else {
                 $item["purchase_date"] = null;
             }
             $item["purchase_cost"] = $this->array_smart_fetch($row, "purchase cost");
             $item["order_number"] = $this->array_smart_fetch($row, "order number");
             $item["notes"] = $this->array_smart_fetch($row, "notes");
             $item["quantity"] = $this->array_smart_fetch($row, "quantity");
             $item["requestable"] = $this->array_smart_fetch($row, "requestable");
             $item["asset_tag"] = $this->array_smart_fetch($row, "asset tag");
             $this->current_assetId = $item["item_name"];
             if ($item["asset_tag"] != '') {
                 $this->current_assetId = $item["asset_tag"];
             }
             $this->log('Category: ' . $item_category);
             $this->log('Location: ' . $item_location);
             $this->log('Purchase Date: ' . $item["purchase_date"]);
             $this->log('Purchase Cost: ' . $item["purchase_cost"]);
             $this->log('Company Name: ' . $item_company_name);
             $this->log('Status: ' . $item_status_name);
             $item["user"] = $this->createOrFetchUser($row);
             $item["location"] = $this->createOrFetchLocation($item_location);
             $item["category"] = $this->createOrFetchCategory($item_category, $item_type);
             $item["manufacturer"] = $this->createOrFetchManufacturer($row);
             $item["company"] = $this->createOrFetchCompany($item_company_name);
             $item["status_label"] = $this->createOrFetchStatusLabel($item_status_name);
             switch ($item_type) {
                 case "asset":
                     // -----------------------------
                     // CUSTOM FIELDS
                     // -----------------------------
                     // Loop through custom fields in the database and see if we have any matches in the CSV
                     foreach ($this->customfields as $customfield) {
                         if ($item['custom_fields'][$customfield->db_column_name()] = $this->array_smart_custom_field_fetch($row, $customfield)) {
                             $this->log('Custom Field ' . $customfield->name . ': ' . $this->array_smart_custom_field_fetch($row, $customfield));
                         }
                     }
                     $this->createAssetIfNotExists($row, $item);
                     break;
                 case "accessory":
                     $this->createAccessoryIfNotExists($item);
                     break;
                 case 'consumable':
                     $this->createConsumableIfNotExists($item);
                     break;
             }
             if (!$this->option('web-importer')) {
                 $bar->advance();
             }
             $this->log('------------- Action Summary ----------------');
         }
     });
     if (!$this->option('web-importer')) {
         $bar->finish();
     }
     $this->log('=====================================');
     if (!$this->option('web-importer')) {
         if (!empty($this->errors)) {
             $this->comment("The following Errors were encountered.");
             foreach ($this->errors as $asset => $error) {
                 $this->comment('Error: Item: ' . $asset . 'failed validation: ' . json_encode($error));
             }
         } else {
             $this->comment("All Items imported successfully!");
         }
     } else {
         if (empty($this->errors)) {
             return 0;
         } else {
             $this->comment(json_encode($this->errors));
             //Send a big string to the
             return 1;
         }
     }
     $this->comment("");
     return 2;
 }
Ejemplo n.º 8
0
 /**
  * Exports the custom report to CSV
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @see ReportsController::getCustomReport() method that generates form view
  * @since [v1.0]
  * @return \Illuminate\Http\Response
  */
 public function postCustom()
 {
     $assets = Asset::orderBy('created_at', 'DESC')->get();
     $customfields = CustomField::get();
     $rows = [];
     $header = [];
     if (e(Input::get('company_name')) == '1') {
         $header[] = 'Company Name';
     }
     if (e(Input::get('asset_name')) == '1') {
         $header[] = 'Asset Name';
     }
     if (e(Input::get('asset_tag')) == '1') {
         $header[] = 'Asset Tag';
     }
     if (e(Input::get('manufacturer')) == '1') {
         $header[] = 'Manufacturer';
     }
     if (e(Input::get('model')) == '1') {
         $header[] = 'Model';
         $header[] = 'Model Number';
     }
     if (e(Input::get('category')) == '1') {
         $header[] = 'Category';
     }
     if (e(Input::get('serial')) == '1') {
         $header[] = 'Serial';
     }
     if (e(Input::get('purchase_date')) == '1') {
         $header[] = 'Purchase Date';
     }
     if (e(Input::get('purchase_cost')) == '1' && e(Input::get('depreciation')) != '1') {
         $header[] = 'Purchase Cost';
     }
     if (e(Input::get('order')) == '1') {
         $header[] = 'Order Number';
     }
     if (e(Input::get('supplier')) == '1') {
         $header[] = 'Supplier';
     }
     if (e(Input::get('location')) == '1') {
         $header[] = 'Location';
     }
     if (e(Input::get('assigned_to')) == '1') {
         $header[] = 'Assigned To';
     }
     if (e(Input::get('username')) == '1') {
         $header[] = 'Username';
     }
     if (e(Input::get('status')) == '1') {
         $header[] = 'Status';
     }
     if (e(Input::get('warranty')) == '1') {
         $header[] = 'Warranty';
         $header[] = 'Warranty Expires';
     }
     if (e(Input::get('depreciation')) == '1') {
         $header[] = 'Purchase Cost';
         $header[] = 'Value';
         $header[] = 'Diff';
     }
     foreach ($customfields as $customfield) {
         if (e(Input::get($customfield->db_column_name())) == '1') {
             $header[] = $customfield->name;
         }
     }
     $header = array_map('trim', $header);
     $rows[] = implode($header, ',');
     foreach ($assets as $asset) {
         $row = [];
         if (e(Input::get('company_name')) == '1') {
             $row[] = is_null($asset->company) ? '' : e($asset->company->name);
         }
         if (e(Input::get('asset_name')) == '1') {
             $row[] = '"' . e($asset->name) . '"';
         }
         if (e(Input::get('asset_tag')) == '1') {
             $row[] = e($asset->asset_tag);
         }
         if (e(Input::get('manufacturer')) == '1') {
             if ($asset->model->manufacturer) {
                 $row[] = '"' . e($asset->model->manufacturer->name) . '"';
             } else {
                 $row[] = '';
             }
         }
         if (e(Input::get('model')) == '1') {
             $row[] = '"' . e($asset->model->name) . '"';
             $row[] = '"' . e($asset->model->modelno) . '"';
         }
         if (e(Input::get('category')) == '1') {
             $row[] = '"' . e($asset->model->category->name) . '"';
         }
         if (e(Input::get('serial')) == '1') {
             $row[] = e($asset->serial);
         }
         if (e(Input::get('purchase_date')) == '1') {
             $row[] = e($asset->purchase_date);
         }
         if (e(Input::get('purchase_cost')) == '1' && e(Input::get('depreciation')) != '1') {
             $row[] = '"' . Helper::formatCurrencyOutput($asset->purchase_cost) . '"';
         }
         if (e(Input::get('order')) == '1') {
             if ($asset->order_number) {
                 $row[] = e($asset->order_number);
             } else {
                 $row[] = '';
             }
         }
         if (e(Input::get('supplier')) == '1') {
             if ($asset->supplier_id) {
                 $row[] = '"' . e($asset->supplier->name) . '"';
             } else {
                 $row[] = '';
             }
         }
         if (e(Input::get('location')) == '1') {
             $show_loc = '';
             if ($asset->assigned_to > 0 && $asset->assigneduser->location_id != '') {
                 $location = Location::find($asset->assigneduser->location_id);
                 if ($location) {
                     $show_loc .= '"' . e($location->name) . '"';
                 } else {
                     $show_loc .= 'User location ' . $asset->assigneduser->location_id . ' is invalid';
                 }
             } elseif ($asset->rtd_location_id != '') {
                 $location = Location::find($asset->rtd_location_id);
                 if ($location) {
                     $show_loc .= '"' . e($location->name) . '"';
                 } else {
                     $show_loc .= 'Default location ' . $asset->rtd_location_id . ' is invalid';
                 }
             }
             $row[] = $show_loc;
         }
         if (e(Input::get('assigned_to')) == '1') {
             if ($asset->assigned_to > 0) {
                 $user = User::find($asset->assigned_to);
                 $row[] = '"' . e($user->fullName()) . '"';
             } else {
                 $row[] = '';
                 // Empty string if unassigned
             }
         }
         if (e(Input::get('username')) == '1') {
             if ($asset->assigned_to > 0) {
                 $user = User::find($asset->assigned_to);
                 $row[] = '"' . e($user->username) . '"';
             } else {
                 $row[] = '';
                 // Empty string if unassigned
             }
         }
         if (e(Input::get('status')) == '1') {
             if ($asset->status_id == '0' && $asset->assigned_to == '0') {
                 $row[] = trans('general.ready_to_deploy');
             } elseif ($asset->status_id == '' && $asset->assigned_to == '0') {
                 $row[] = trans('general.pending');
             } elseif ($asset->assetstatus) {
                 $row[] = '"' . e($asset->assetstatus->name) . '"';
             } else {
                 $row[] = '';
             }
         }
         if (e(Input::get('warranty')) == '1') {
             if ($asset->warranty_months) {
                 $row[] = $asset->warranty_months;
                 $row[] = $asset->warrantee_expires();
             } else {
                 $row[] = '';
                 $row[] = '';
             }
         }
         if (e(Input::get('depreciation')) == '1') {
             $depreciation = $asset->getDepreciatedValue();
             $row[] = '"' . Helper::formatCurrencyOutput($asset->purchase_cost) . '"';
             $row[] = '"' . Helper::formatCurrencyOutput($depreciation) . '"';
             $row[] = '"' . Helper::formatCurrencyOutput($asset->purchase_cost) . '"';
         }
         foreach ($customfields as $customfield) {
             $column_name = $customfield->db_column_name();
             if (e(Input::get($customfield->db_column_name())) == '1') {
                 $row[] = $asset->{$column_name};
             }
         }
         $rows[] = implode($row, ',');
     }
     // spit out a csv
     if (array_filter($rows)) {
         $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;
     } else {
         return redirect()->to("reports/custom")->with('error', trans('admin/reports/message.error'));
     }
 }
Ejemplo n.º 9
0
 /**
  * Updates an existing Tour model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelsCustomField = $model->customFields;
     if ($model->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelsCustomField, 'id', 'id');
         $modelsCustomField = Model::createMultiple(CustomField::classname(), $modelsCustomField);
         Model::loadMultiple($modelsCustomField, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsCustomField, 'id', 'id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsCustomField), ActiveForm::validate($model));
         }
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsCustomField) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         CustomField::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsCustomField as $modelCustomField) {
                         $modelCustomField->tour_id = $model->id;
                         if (!($flag = $modelCustomField->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('update', ['model' => $model, 'modelsCustomField' => empty($modelsCustomField) ? [new CustomField()] : $modelsCustomField]);
 }
Ejemplo n.º 10
0
 /**
  * Validates and stores a new custom field.
  *
  * @author [Brady Wetherington] [<*****@*****.**>]
  * @param int $id
  * @since [v1.8]
  * @return View
  */
 public function show($id)
 {
     //$id=$parameters[0];
     $cfset = CustomFieldset::find($id);
     //print_r($parameters);
     //
     $custom_fields_list = ["" => "Add New Field to Fieldset"] + CustomField::lists("name", "id")->toArray();
     // print_r($custom_fields_list);
     $maxid = 0;
     foreach ($cfset->fields as $field) {
         // print "Looking for: ".$field->id;
         if ($field->pivot->order > $maxid) {
             $maxid = $field->pivot->order;
         }
         if (isset($custom_fields_list[$field->id])) {
             // print "Found ".$field->id.", so removing it.<br>";
             unset($custom_fields_list[$field->id]);
         }
     }
     return View::make("custom_fields.show")->with("custom_fieldset", $cfset)->with("maxid", $maxid + 1)->with("custom_fields_list", $custom_fields_list);
 }
Ejemplo n.º 11
0
 public static function gracefulDecrypt(CustomField $field, $string)
 {
     if ($field->isFieldDecryptable($string)) {
         try {
             Crypt::decrypt($string);
             return Crypt::decrypt($string);
         } catch (DecryptException $e) {
             return 'Error Decrypting: ' . $e->getMessage();
         }
     }
     return $string;
 }
Ejemplo n.º 12
0
 public function run()
 {
     CustomField::truncate();
 }
Ejemplo n.º 13
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCustomFields()
 {
     return $this->hasMany(CustomField::className(), ['tour_id' => 'id'])->orderBy(['sort' => SORT_ASC]);
 }
Ejemplo n.º 14
0
 public function testDbName()
 {
     $customfield = new CustomField();
     $customfield->name = "An Example Name";
     $this->assertEquals($customfield->db_column_name(), "_snipeit_an_example_name");
 }