diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index e8f37d8574..584e4693d2 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -905,6 +905,7 @@ class AssetsController extends Controller $asset->expected_checkin = null; $asset->last_checkout = null; + $asset->last_checkin = now(); $asset->assigned_to = null; $asset->assignedTo()->disassociate($asset); $asset->accepted = null; diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.php index fd5cee30ea..5f79e7b19c 100644 --- a/app/Http/Controllers/Assets/AssetCheckinController.php +++ b/app/Http/Controllers/Assets/AssetCheckinController.php @@ -68,6 +68,7 @@ class AssetCheckinController extends Controller $asset->expected_checkin = null; $asset->last_checkout = null; + $asset->last_checkin = now(); $asset->assigned_to = null; $asset->assignedTo()->disassociate($asset); $asset->assigned_type = null; diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index c9a88ea0f1..68ca88a2eb 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -545,6 +545,10 @@ class ReportsController extends Controller $header[] = trans('admin/hardware/table.checkout_date'); } + if ($request->filled('checkin_date')) { + $header[] = trans('admin/hardware/table.last_checkin_date'); + } + if ($request->filled('expected_checkin')) { $header[] = trans('admin/hardware/form.expected_checkin'); } @@ -651,6 +655,14 @@ class ReportsController extends Controller $assets->whereBetween('assets.last_checkout', [$checkout_start, $checkout_end]); } + if (($request->filled('checkin_date_start'))) { + $assets->whereBetween('last_checkin', [ + Carbon::parse($request->input('checkin_date_start'))->startOfDay(), + // use today's date is `checkin_date_end` is not provided + Carbon::parse($request->input('checkin_date_end', now()))->endOfDay(), + ]); + } + if (($request->filled('expected_checkin_start')) && ($request->filled('expected_checkin_end'))) { $assets->whereBetween('assets.expected_checkin', [$request->input('expected_checkin_start'), $request->input('expected_checkin_end')]); } @@ -835,6 +847,12 @@ class ReportsController extends Controller $row[] = ($asset->last_checkout) ? $asset->last_checkout : ''; } + if ($request->filled('checkin_date')) { + $row[] = ($asset->last_checkin) + ? Carbon::parse($asset->last_checkin)->format('Y-m-d') + : ''; + } + if ($request->filled('expected_checkin')) { $row[] = ($asset->expected_checkin) ? $asset->expected_checkin : ''; } diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index 7f76d3baac..926116fe1e 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -161,6 +161,7 @@ class ActionlogsTransformer { $location = Location::withTrashed()->get(); $supplier = Supplier::withTrashed()->get(); $model = AssetModel::withTrashed()->get(); + $company = Company::withTrashed()->get(); if(array_key_exists('rtd_location_id',$clean_meta)) { @@ -177,17 +178,24 @@ class ActionlogsTransformer } if(array_key_exists('model_id', $clean_meta)) { - $clean_meta['model_id']['old'] = "[id: ".$clean_meta['model_id']['old']."] ".$model->find($clean_meta['model_id']['old'])->name; - $clean_meta['model_id']['new'] = "[id: ".$clean_meta['model_id']['new']."] ".$model->find($clean_meta['model_id']['new'])->name; /* model is required at asset creation */ + $oldModel = $model->find($clean_meta['model_id']['old']); + $oldModelName = $oldModel->name ?? trans('admin/models/message.deleted'); + + $newModel = $model->find($clean_meta['model_id']['new']); + $newModelName = $newModel->name ?? trans('admin/models/message.deleted'); + + $clean_meta['model_id']['old'] = "[id: ".$clean_meta['model_id']['old']."] ".$oldModelName; + $clean_meta['model_id']['new'] = "[id: ".$clean_meta['model_id']['new']."] ".$newModelName; /** model is required at asset creation */ $clean_meta['Model'] = $clean_meta['model_id']; unset($clean_meta['model_id']); } if(array_key_exists('company_id', $clean_meta)) { - $oldCompany = Company::find($clean_meta['company_id']['old']); + + $oldCompany = $company->find($clean_meta['company_id']['old']); $oldCompanyName = $oldCompany->name ?? trans('admin/companies/message.deleted'); - $newCompany = Company::find($clean_meta['company_id']['new']); + $newCompany = $company->find($clean_meta['company_id']['new']); $newCompanyName = $newCompany->name ?? trans('admin/companies/message.deleted'); $clean_meta['company_id']['old'] = $clean_meta['company_id']['old'] ? "[id: ".$clean_meta['company_id']['old']."] ". $oldCompanyName : trans('general.unassigned'); @@ -196,8 +204,15 @@ class ActionlogsTransformer unset($clean_meta['company_id']); } if(array_key_exists('supplier_id', $clean_meta)) { - $clean_meta['supplier_id']['old'] = $clean_meta['supplier_id']['old'] ? "[id: ".$clean_meta['supplier_id']['old']."] ".$supplier->find($clean_meta['supplier_id']['old'])->name : trans('general.unassigned'); - $clean_meta['supplier_id']['new'] = $clean_meta['supplier_id']['new'] ? "[id: ".$clean_meta['supplier_id']['new']."] ".$supplier->find($clean_meta['supplier_id']['new'])->name : trans('general.unassigned'); + + $oldSupplier = $supplier->find($clean_meta['supplier_id']['old']); + $oldSupplierName = $oldSupplier->name ?? trans('admin/suppliers/message.deleted'); + + $newSupplier = $supplier->find($clean_meta['supplier_id']['new']); + $newSupplierName = $newSupplier->name ?? trans('admin/suppliers/message.deleted'); + + $clean_meta['supplier_id']['old'] = $clean_meta['supplier_id']['old'] ? "[id: ".$clean_meta['supplier_id']['old']."] ". $oldSupplierName : trans('general.unassigned'); + $clean_meta['supplier_id']['new'] = $clean_meta['supplier_id']['new'] ? "[id: ".$clean_meta['supplier_id']['new']."] ". $newSupplierName : trans('general.unassigned'); $clean_meta['Supplier'] = $clean_meta['supplier_id']; unset($clean_meta['supplier_id']); } diff --git a/app/Models/Asset.php b/app/Models/Asset.php index d95aec51ce..1c17856234 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -73,6 +73,7 @@ class Asset extends Depreciable protected $casts = [ 'purchase_date' => 'date', 'last_checkout' => 'datetime', + 'last_checkin' => 'datetime', 'expected_checkin' => 'date', 'last_audit_date' => 'datetime', 'next_audit_date' => 'date', diff --git a/app/Models/User.php b/app/Models/User.php index f54d99188e..70c9fc44ae 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -750,4 +750,26 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo { return $this->locale; } + public function getUserTotalCost(){ + $asset_cost= 0; + $license_cost= 0; + $accessory_cost= 0; + foreach ($this->assets as $asset){ + $asset_cost += $asset->purchase_cost; + $this->asset_cost = $asset_cost; + } + foreach ($this->licenses as $license){ + $license_cost += $license->purchase_cost; + $this->license_cost = $license_cost; + } + foreach ($this->accessories as $accessory){ + $accessory_cost += $accessory->purchase_cost; + $this->accessory_cost = $accessory_cost; + } + + $this->total_user_cost = ($asset_cost + $accessory_cost + $license_cost); + + + return $this; + } } diff --git a/database/migrations/2023_08_17_202638_add_last_checkin_to_assets.php b/database/migrations/2023_08_17_202638_add_last_checkin_to_assets.php new file mode 100644 index 0000000000..74048ce941 --- /dev/null +++ b/database/migrations/2023_08_17_202638_add_last_checkin_to_assets.php @@ -0,0 +1,36 @@ +dateTime('last_checkin')->after('last_checkout')->nullable(); + }); + + DB::statement( + "UPDATE " . DB::getTablePrefix() . "assets SET last_checkin=(SELECT MAX(" . DB::getTablePrefix() . "action_logs.action_date) FROM " . DB::getTablePrefix() . "action_logs WHERE item_type='App\\\Models\\\Asset' AND " . DB::getTablePrefix() . "action_logs.item_id=" . DB::getTablePrefix() . "assets.id AND " . DB::getTablePrefix() . "action_logs.action_type='checkin from')" + ); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('assets', function (Blueprint $table) { + $table->dropColumn('last_checkin'); + }); + } +} diff --git a/resources/lang/en/admin/hardware/table.php b/resources/lang/en/admin/hardware/table.php index 10629fd22c..06b60bfd83 100644 --- a/resources/lang/en/admin/hardware/table.php +++ b/resources/lang/en/admin/hardware/table.php @@ -14,6 +14,7 @@ return [ 'dl_csv' => 'Download CSV', 'eol' => 'EOL', 'id' => 'ID', + 'last_checkin_date' => 'Last Checkin Date', 'location' => 'Location', 'purchase_cost' => 'Cost', 'purchase_date' => 'Purchased', diff --git a/resources/lang/en/admin/models/message.php b/resources/lang/en/admin/models/message.php index 77c2d88b5f..4dbcd4e75e 100644 --- a/resources/lang/en/admin/models/message.php +++ b/resources/lang/en/admin/models/message.php @@ -2,6 +2,7 @@ return array( + 'deleted' => 'Deleted asset model', 'does_not_exist' => 'Model does not exist.', 'no_association' => 'WARNING! The asset model for this item is invalid or missing!', 'no_association_fix' => 'This will break things in weird and horrible ways. Edit this asset now to assign it a model.', diff --git a/resources/lang/en/admin/suppliers/message.php b/resources/lang/en/admin/suppliers/message.php index cea332748f..a693669c7e 100644 --- a/resources/lang/en/admin/suppliers/message.php +++ b/resources/lang/en/admin/suppliers/message.php @@ -2,6 +2,7 @@ return array( + 'deleted' => 'Deleted supplier', 'does_not_exist' => 'Supplier does not exist.', diff --git a/resources/lang/en/admin/users/table.php b/resources/lang/en/admin/users/table.php index e318d51545..21e2154280 100644 --- a/resources/lang/en/admin/users/table.php +++ b/resources/lang/en/admin/users/table.php @@ -29,6 +29,7 @@ return array( 'show_deleted' => 'Show Deleted Users', 'title' => 'Title', 'to_restore_them' => 'to restore them.', + 'total_assets_cost' => "Total Assets Cost", 'updateuser' => 'Update User', 'username' => 'Username', 'user_deleted_text' => 'This user has been marked as deleted.', diff --git a/resources/views/reports/custom.blade.php b/resources/views/reports/custom.blade.php index ff78f21686..5b0bd384ee 100644 --- a/resources/views/reports/custom.blade.php +++ b/resources/views/reports/custom.blade.php @@ -141,6 +141,11 @@ {{ trans('admin/hardware/table.checkout_date') }} + +