d6769443a9
commit399c7590cdMerge:d0c5ba70feb67d1b06Author: snipe <snipe@snipe.net> Date: Thu Dec 15 14:19:41 2022 -0800 Merge pull request #12209 from snipe/fixes/error_downloading_unaccepted_assets Fixed 500 when downloading the Unaccepted Assets report [sc-19555] commitd0c5ba70f6Merge:29c2ff56ed9a21cce0Author: snipe <snipe@snipe.net> Date: Thu Dec 15 12:42:29 2022 -0800 Merge pull request #12242 from inietov/features/add_purchase_cost_column Added `purchase_cost` to user's default view [sc-19680] commitd9a21cce00Author: Ivan Nieto Vivanco <inietov@gmail.com> Date: Thu Dec 15 14:12:05 2022 -0600 Add other items' purchase_cost columns to the same permission commit29c2ff56ecMerge:3e7975b2c1fe0bfe17Author: snipe <snipe@snipe.net> Date: Thu Dec 15 11:26:49 2022 -0800 Merge pull request #12188 from snipe/fixes/decrease_logging_for_saml_when_not_enabled Removed extra logging case that was very noisy commit3e7975b2c3Merge:227fef76ed870bc3b0Author: snipe <snipe@snipe.net> Date: Thu Dec 15 11:25:53 2022 -0800 Merge pull request #12250 from akemidx/grey_out_pw_reset_button Fixed: Grey out pw reset button for consistency commitd870bc3b02Author: akemidx <kojotek.dx@gmail.com> Date: Thu Dec 15 14:19:51 2022 -0500 nested if loop commit227fef76eeMerge:418ddcfac9d44720ffAuthor: snipe <snipe@snipe.net> Date: Thu Dec 15 11:06:53 2022 -0800 Merge pull request #11736 from Godmartinz/gh6508_ldap_default_group Adds a permission group selection for directory sync commit9d44720ffdAuthor: Godfrey M <godmartinz@gmail.com> Date: Thu Dec 15 11:02:34 2022 -0800 reverted changes to composer.lock commit9f3f0a25edAuthor: Godfrey M <godmartinz@gmail.com> Date: Thu Dec 15 10:53:45 2022 -0800 reverted changes to composer.lock commit2e228ccb0bAuthor: Godfrey M <godmartinz@gmail.com> Date: Thu Dec 15 10:45:42 2022 -0800 redid a few things. should be good now :) commit3ee413f379Author: Godfrey M <godmartinz@gmail.com> Date: Thu Dec 15 09:20:30 2022 -0800 removes livewire stuff commitb142f8e012Author: Ivan Nieto Vivanco <inietov@gmail.com> Date: Wed Dec 14 23:00:35 2022 -0600 Add the permission to show purchase cost column to non-admin sessions commit418ddcfac3Merge:c342668f01a908e361Author: snipe <snipe@snipe.net> Date: Wed Dec 14 17:46:53 2022 -0800 Merge pull request #9876 from Toreg87/fixes/locations-deletable Fixed #9875: Make locations deletable for non Superuser-Accounts with FullMultipleCompanySupport commitc342668f0fAuthor: snipe <snipe@snipe.net> Date: Wed Dec 14 17:25:39 2022 -0800 Update @scoo73r as a contributor commit2f6a26ec7dAuthor: snipe <snipe@snipe.net> Date: Wed Dec 14 17:25:25 2022 -0800 Add @scoo73r as a contributor commitf635278010Merge:d13a237008043b8678Author: snipe <snipe@snipe.net> Date: Wed Dec 14 16:42:41 2022 -0800 Merge pull request #12251 from snipe/security/upgrade_font_awesome Upgraded font awesome to 6.2.1 commit8043b86786Author: snipe <snipe@snipe.net> Date: Wed Dec 14 16:41:56 2022 -0800 Upgraded font awesome to 6.2.1 Signed-off-by: snipe <snipe@snipe.net> commitd13a237000Merge:fabefa61bd0d0058e7Author: snipe <snipe@snipe.net> Date: Wed Dec 14 12:13:18 2022 -0800 Merge pull request #12205 from Godmartinz/sc19675_add_remote_to_importer Adds remote field to the user importer commitb114ffd2c3Author: akemidx <kojotek.dx@gmail.com> Date: Wed Dec 14 14:48:59 2022 -0500 Grey out button pw reset button for consistency When user has no email in their profile, the box is greyed out for consistency accross all buttons on the user profile commitfabefa61b0Merge:389ec3a3cf3e57d7dcAuthor: snipe <snipe@snipe.net> Date: Tue Dec 13 14:00:48 2022 -0800 Merge pull request #12243 from akemidx/new_grey_out_when_no_assets Created method in users.php for adding up all assigned to user and pr… commitf3e57d7dc0Author: akemidx <kojotek.dx@gmail.com> Date: Tue Dec 13 16:00:59 2022 -0500 fixing PR commit389ec3a3cbMerge:c432fb9d76a72c344bAuthor: snipe <snipe@snipe.net> Date: Tue Dec 13 12:57:50 2022 -0800 Merge pull request #12247 from Godmartinz/gh12225_serial_added_to_components adds serial to components tab of assets commit6a72c344b7Author: Godfrey M <godmartinz@gmail.com> Date: Tue Dec 13 12:32:30 2022 -0800 removed the cuddlers commit4442b446b9Author: Godfrey M <godmartinz@gmail.com> Date: Tue Dec 13 10:30:37 2022 -0800 adds serial to components tab of assets commitc432fb9d70Merge:9e8fff6e5fa872b09aAuthor: snipe <snipe@snipe.net> Date: Tue Dec 13 10:28:17 2022 -0800 Merge pull request #12181 from Godmartinz/gh12163_asset_age Adds asset age to asset index and asset view pages commit07ae91b00fAuthor: akemi <akemi@ShibaPro.local> Date: Wed Dec 7 17:46:18 2022 -0500 Created method in users.php for adding up all assigned to user and providing an integer value. this then used to grey out buttons on user view if user has nothing assigned. commit450ad3dcecAuthor: Ivan Nieto Vivanco <inietov@gmail.com> Date: Mon Dec 12 14:17:08 2022 -0600 Added the column purchase_cost to user's default view commitfa872b09a9Author: Godfrey M <godmartinz@gmail.com> Date: Mon Dec 12 10:38:31 2022 -0800 fixes a typo, the world is great again commiteb67d1b064Author: Ivan Nieto Vivanco <inietov@gmail.com> Date: Tue Dec 6 18:00:16 2022 -0600 Filter items from the report if null returned commitd0d0058e79Author: Godfrey M <godmartinz@gmail.com> Date: Tue Dec 6 11:19:28 2022 -0800 removed unwanted changes commitbbd04f8876Author: Godfrey M <godmartinz@gmail.com> Date: Tue Dec 6 11:13:24 2022 -0800 adds the rest of the fields for Remote commit36901d271bAuthor: Godfrey M <godmartinz@gmail.com> Date: Mon Dec 5 16:28:19 2022 -0800 adds csvmatch for remote. Im a bit lost though lol commit3206929ee4Author: Godfrey M <godmartinz@gmail.com> Date: Tue Nov 29 09:51:42 2022 -0800 adds AgeFormatter, not working yet commit1fe0bfe17eAuthor: snipe <snipe@snipe.net> Date: Mon Nov 28 19:27:42 2022 -0800 Removed extra logging case that was very noisy Signed-off-by: snipe <snipe@snipe.net> commit8d861cfd82Author: Godfrey M <godmartinz@gmail.com> Date: Mon Nov 28 10:59:18 2022 -0800 adds age to the asset table commit078e7281cdAuthor: Godfrey M <godmartinz@gmail.com> Date: Mon Nov 28 10:45:58 2022 -0800 adds asset age to asset view commitf2d4a61e3cAuthor: Godfrey M <godmartinz@gmail.com> Date: Tue Oct 18 15:31:37 2022 -0700 removes dead space commit3f25a1bf61Author: Godfrey M <godmartinz@gmail.com> Date: Tue Oct 18 15:25:38 2022 -0700 removes dead code commitf9ac447dd1Merge:9b448227fb7bcfacccAuthor: Godfrey M <godmartinz@gmail.com> Date: Tue Oct 18 15:18:09 2022 -0700 adds default group to LDAP commit9b448227f7Author: Godfrey M <godmartinz@gmail.com> Date: Tue Sep 13 11:40:10 2022 -0700 tinkering to no avail commit28bc97f29fAuthor: Godfrey M <godmartinz@gmail.com> Date: Mon Sep 12 11:40:16 2022 -0700 one line away from this being over with commit193b31e427Author: Godfrey M <godmartinz@gmail.com> Date: Wed Aug 31 12:58:33 2022 -0700 select options working, testing sync then done commit70ac8af9c4Author: Godfrey M <godmartinz@gmail.com> Date: Wed Aug 31 09:53:20 2022 -0700 . commit0c362e8b57Author: Godfrey M <godmartinz@gmail.com> Date: Mon Aug 29 12:09:56 2022 -0700 gets the groups selector to appear but options are blank commitfc6fefdb4eAuthor: Godfrey M <godmartinz@gmail.com> Date: Thu Aug 25 15:19:38 2022 -0700 adds migration, variables, checkbox,working on groups commit1a908e361eAuthor: Tobias Regnery <tobias.regnery@gmail.com> Date: Thu Jul 29 10:33:34 2021 +0200 Make locations deletable for non Superuser-Accounts with FullMultipleCompanySupport locations->isDeletable() checks via gate::allows if a locations is deletable. This calls SnipePermissionsPolicy->before() and checks for !Company::isCurrentUserHasAccess($item). This returns false because locations don't have a company_id. Check for this and return true if the item don't have a company_id. Signed-off-by: snipe <snipe@snipe.net>
241 lines
11 KiB
PHP
241 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
use App\Helpers\Helper;
|
|
use App\Models\Asset;
|
|
use App\Models\Setting;
|
|
use Gate;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
|
class AssetsTransformer
|
|
{
|
|
public function transformAssets(Collection $assets, $total)
|
|
{
|
|
$array = [];
|
|
foreach ($assets as $asset) {
|
|
$array[] = self::transformAsset($asset);
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
}
|
|
|
|
public function transformAsset(Asset $asset)
|
|
{
|
|
// This uses the getSettings() method so we're pulling from the cache versus querying the settings on single asset
|
|
$setting = Setting::getSettings();
|
|
|
|
$array = [
|
|
'id' => (int) $asset->id,
|
|
'name' => e($asset->name),
|
|
'asset_tag' => e($asset->asset_tag),
|
|
'serial' => e($asset->serial),
|
|
'model' => ($asset->model) ? [
|
|
'id' => (int) $asset->model->id,
|
|
'name'=> e($asset->model->name),
|
|
] : null,
|
|
'model_number' => (($asset->model) && ($asset->model->model_number)) ? e($asset->model->model_number) : null,
|
|
'eol' => ($asset->purchase_date != '') ? Helper::getFormattedDateObject($asset->present()->eol_date(), 'date') : null,
|
|
'status_label' => ($asset->assetstatus) ? [
|
|
'id' => (int) $asset->assetstatus->id,
|
|
'name'=> e($asset->assetstatus->name),
|
|
'status_type'=> e($asset->assetstatus->getStatuslabelType()),
|
|
'status_meta' => e($asset->present()->statusMeta),
|
|
] : null,
|
|
'category' => (($asset->model) && ($asset->model->category)) ? [
|
|
'id' => (int) $asset->model->category->id,
|
|
'name'=> e($asset->model->category->name),
|
|
] : null,
|
|
'manufacturer' => (($asset->model) && ($asset->model->manufacturer)) ? [
|
|
'id' => (int) $asset->model->manufacturer->id,
|
|
'name'=> e($asset->model->manufacturer->name),
|
|
] : null,
|
|
'supplier' => ($asset->supplier) ? [
|
|
'id' => (int) $asset->supplier->id,
|
|
'name'=> e($asset->supplier->name),
|
|
] : null,
|
|
'notes' => ($asset->notes) ? e($asset->notes) : null,
|
|
'order_number' => ($asset->order_number) ? e($asset->order_number) : null,
|
|
'company' => ($asset->company) ? [
|
|
'id' => (int) $asset->company->id,
|
|
'name'=> e($asset->company->name),
|
|
] : null,
|
|
'location' => ($asset->location) ? [
|
|
'id' => (int) $asset->location->id,
|
|
'name'=> e($asset->location->name),
|
|
] : null,
|
|
'rtd_location' => ($asset->defaultLoc) ? [
|
|
'id' => (int) $asset->defaultLoc->id,
|
|
'name'=> e($asset->defaultLoc->name),
|
|
] : null,
|
|
'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null,
|
|
'qr' => ($setting->qr_code=='1') ? config('app.url').'/uploads/barcodes/qr-'.str_slug($asset->asset_tag).'-'.str_slug($asset->id).'.png' : null,
|
|
'alt_barcode' => ($setting->alt_barcode_enabled=='1') ? config('app.url').'/uploads/barcodes/'.str_slug($setting->alt_barcode).'-'.str_slug($asset->asset_tag).'.png' : null,
|
|
'assigned_to' => $this->transformAssignedTo($asset),
|
|
'warranty_months' => ($asset->warranty_months > 0) ? e($asset->warranty_months.' '.trans('admin/hardware/form.months')) : null,
|
|
'warranty_expires' => ($asset->warranty_months > 0) ? Helper::getFormattedDateObject($asset->warranty_expires, 'date') : null,
|
|
'created_at' => Helper::getFormattedDateObject($asset->created_at, 'datetime'),
|
|
'updated_at' => Helper::getFormattedDateObject($asset->updated_at, 'datetime'),
|
|
'last_audit_date' => Helper::getFormattedDateObject($asset->last_audit_date, 'datetime'),
|
|
'next_audit_date' => Helper::getFormattedDateObject($asset->next_audit_date, 'date'),
|
|
'deleted_at' => Helper::getFormattedDateObject($asset->deleted_at, 'datetime'),
|
|
'purchase_date' => Helper::getFormattedDateObject($asset->purchase_date, 'date'),
|
|
'age' => $asset->purchase_date ? Helper::AgeFormat($asset->purchase_date) : '',
|
|
'last_checkout' => Helper::getFormattedDateObject($asset->last_checkout, 'datetime'),
|
|
'expected_checkin' => Helper::getFormattedDateObject($asset->expected_checkin, 'date'),
|
|
'purchase_cost' => Helper::formatCurrencyOutput($asset->purchase_cost),
|
|
'checkin_counter' => (int) $asset->checkin_counter,
|
|
'checkout_counter' => (int) $asset->checkout_counter,
|
|
'requests_counter' => (int) $asset->requests_counter,
|
|
'user_can_checkout' => (bool) $asset->availableForCheckout(),
|
|
];
|
|
|
|
|
|
if (($asset->model) && ($asset->model->fieldset) && ($asset->model->fieldset->fields->count() > 0)) {
|
|
$fields_array = [];
|
|
|
|
foreach ($asset->model->fieldset->fields as $field) {
|
|
if ($field->isFieldDecryptable($asset->{$field->db_column})) {
|
|
$decrypted = Helper::gracefulDecrypt($field, $asset->{$field->db_column});
|
|
$value = (Gate::allows('superadmin')) ? $decrypted : strtoupper(trans('admin/custom_fields/general.encrypted'));
|
|
|
|
if ($field->format == 'DATE'){
|
|
if (Gate::allows('superadmin')){
|
|
$value = Helper::getFormattedDateObject($value, 'date', false);
|
|
} else {
|
|
$value = strtoupper(trans('admin/custom_fields/general.encrypted'));
|
|
}
|
|
}
|
|
|
|
$fields_array[$field->name] = [
|
|
'field' => e($field->db_column),
|
|
'value' => e($value),
|
|
'field_format' => $field->format,
|
|
'element' => $field->element,
|
|
];
|
|
|
|
} else {
|
|
$value = $asset->{$field->db_column};
|
|
|
|
if (($field->format == 'DATE') && (!is_null($value)) && ($value!='')){
|
|
$value = Helper::getFormattedDateObject($value, 'date', false);
|
|
}
|
|
|
|
$fields_array[$field->name] = [
|
|
'field' => e($field->db_column),
|
|
'value' => e($value),
|
|
'field_format' => $field->format,
|
|
'element' => $field->element,
|
|
];
|
|
}
|
|
|
|
$array['custom_fields'] = $fields_array;
|
|
}
|
|
} else {
|
|
$array['custom_fields'] = new \stdClass; // HACK to force generation of empty object instead of empty list
|
|
}
|
|
|
|
$permissions_array['available_actions'] = [
|
|
'checkout' => ($asset->deleted_at=='' && Gate::allows('checkout', Asset::class)) ? true : false,
|
|
'checkin' => ($asset->deleted_at=='' && Gate::allows('checkin', Asset::class)) ? true : false,
|
|
'clone' => Gate::allows('create', Asset::class) ? true : false,
|
|
'restore' => ($asset->deleted_at!='' && Gate::allows('create', Asset::class)) ? true : false,
|
|
'update' => ($asset->deleted_at=='' && Gate::allows('update', Asset::class)) ? true : false,
|
|
'delete' => ($asset->deleted_at=='' && $asset->assigned_to =='' && Gate::allows('delete', Asset::class)) ? true : false,
|
|
];
|
|
|
|
|
|
if (request('components')=='true') {
|
|
|
|
if ($asset->components) {
|
|
$array['components'] = [];
|
|
|
|
foreach ($asset->components as $component) {
|
|
$array['components'][] = [
|
|
|
|
'id' => $component->id,
|
|
'pivot_id' => $component->pivot->id,
|
|
'name' => e($component->name),
|
|
'qty' => $component->pivot->assigned_qty,
|
|
'price_cost' => $component->purchase_cost,
|
|
'purchase_total' => $component->purchase_cost * $component->pivot->assigned_qty,
|
|
'checkout_date' => Helper::getFormattedDateObject($component->pivot->created_at, 'datetime') ,
|
|
|
|
];
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$array += $permissions_array;
|
|
|
|
return $array;
|
|
}
|
|
|
|
public function transformAssetsDatatable($assets)
|
|
{
|
|
return (new DatatablesTransformer)->transformDatatables($assets);
|
|
}
|
|
|
|
public function transformAssignedTo($asset)
|
|
{
|
|
if ($asset->checkedOutToUser()) {
|
|
return $asset->assigned ? [
|
|
'id' => (int) $asset->assigned->id,
|
|
'username' => e($asset->assigned->username),
|
|
'name' => e($asset->assigned->getFullNameAttribute()),
|
|
'first_name'=> e($asset->assigned->first_name),
|
|
'last_name'=> ($asset->assigned->last_name) ? e($asset->assigned->last_name) : null,
|
|
'email'=> ($asset->assigned->email) ? e($asset->assigned->email) : null,
|
|
'employee_number' => ($asset->assigned->employee_num) ? e($asset->assigned->employee_num) : null,
|
|
'type' => 'user',
|
|
] : null;
|
|
}
|
|
|
|
return $asset->assigned ? [
|
|
'id' => $asset->assigned->id,
|
|
'name' => e($asset->assigned->display_name),
|
|
'type' => $asset->assignedType()
|
|
] : null;
|
|
}
|
|
|
|
|
|
public function transformRequestedAssets(Collection $assets, $total)
|
|
{
|
|
$array = [];
|
|
foreach ($assets as $asset) {
|
|
$array[] = self::transformRequestedAsset($asset);
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
}
|
|
|
|
public function transformRequestedAsset(Asset $asset)
|
|
{
|
|
$array = [
|
|
'id' => (int) $asset->id,
|
|
'name' => e($asset->name),
|
|
'asset_tag' => e($asset->asset_tag),
|
|
'serial' => e($asset->serial),
|
|
'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null,
|
|
'model' => ($asset->model) ? e($asset->model->name) : null,
|
|
'model_number' => (($asset->model) && ($asset->model->model_number)) ? e($asset->model->model_number) : null,
|
|
'expected_checkin' => Helper::getFormattedDateObject($asset->expected_checkin, 'date'),
|
|
'location' => ($asset->location) ? e($asset->location->name) : null,
|
|
'status'=> ($asset->assetstatus) ? $asset->present()->statusMeta : null,
|
|
'assigned_to_self' => ($asset->assigned_to == \Auth::user()->id),
|
|
];
|
|
|
|
$permissions_array['available_actions'] = [
|
|
'cancel' => ($asset->isRequestedBy(\Auth::user())) ? true : false,
|
|
'request' => ($asset->isRequestedBy(\Auth::user())) ? false : true,
|
|
];
|
|
|
|
$array += $permissions_array;
|
|
return $array;
|
|
|
|
|
|
}
|
|
}
|