diff --git a/app/Console/Commands/ObjectImportCommand.php b/app/Console/Commands/ObjectImportCommand.php index bc0a023b25..b8d24ea50c 100644 --- a/app/Console/Commands/ObjectImportCommand.php +++ b/app/Console/Commands/ObjectImportCommand.php @@ -856,6 +856,7 @@ class ObjectImportCommand extends Command if (!$this->option('testrun')) { if ($asset->save()) { + $asset->logCreate('Imported using csv importer'); $this->log('Asset ' . $item["item_name"] . ' with serial number ' . $asset_serial . ' was created'); } else { $this->jsonError('Asset', $asset->getErrors()); @@ -941,6 +942,7 @@ class ObjectImportCommand extends Command if (!$this->option('testrun')) { if ($accessory->save()) { + $accessory->logCreate('Imported using CSV Importer'); $this->log('Accessory ' . $item["item_name"] . ' was created'); // $this->comment('Accessory ' . $item["item_name"] . ' was created'); @@ -1025,6 +1027,7 @@ class ObjectImportCommand extends Command if (!$this->option("testrun")) { // dd($consumable); if ($consumable->save()) { + $consumable->logCreate('Imported using CSV Importer'); $this->log("Consumable " . $item["item_name"] . ' was created'); // $this->comment("Consumable " . $item["item_name"] . ' was created'); diff --git a/app/Http/Controllers/AccessoriesController.php b/app/Http/Controllers/AccessoriesController.php index 6b0d305eab..6769346361 100755 --- a/app/Http/Controllers/AccessoriesController.php +++ b/app/Http/Controllers/AccessoriesController.php @@ -100,6 +100,7 @@ class AccessoriesController extends Controller // Was the accessory created? if ($accessory->save()) { + $accessory->logCreate(); // Redirect to the new accessory page return redirect()->to("admin/accessories")->with('success', trans('admin/accessories/message.create.success')); } diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index d5e3e40f56..f3cc630f99 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -264,7 +264,7 @@ class AssetsController extends Controller // Was the asset created? if ($asset->save()) { - + $asset->logCreate(); if (Input::get('assigned_to')!='') { $user = User::find(e(Input::get('assigned_to'))); $asset->checkOutToUser($user, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset creation', e(Input::get('name'))); diff --git a/app/Http/Controllers/ComponentsController.php b/app/Http/Controllers/ComponentsController.php index c514bb7042..406ca1673c 100644 --- a/app/Http/Controllers/ComponentsController.php +++ b/app/Http/Controllers/ComponentsController.php @@ -107,6 +107,7 @@ class ComponentsController extends Controller // Was the component created? if ($component->save()) { + $component->logCreate(); // Redirect to the new component page return redirect()->to("admin/components")->with('success', trans('admin/components/message.create.success')); } diff --git a/app/Http/Controllers/ConsumablesController.php b/app/Http/Controllers/ConsumablesController.php index 20dd4367f6..07e2ade5dd 100644 --- a/app/Http/Controllers/ConsumablesController.php +++ b/app/Http/Controllers/ConsumablesController.php @@ -105,6 +105,7 @@ class ConsumablesController extends Controller // Was the consumable created? if ($consumable->save()) { + $consumable->logCreate(); // Redirect to the new consumable page return redirect()->to("admin/consumables")->with('success', trans('admin/consumables/message.create.success')); } diff --git a/app/Http/Controllers/LicensesController.php b/app/Http/Controllers/LicensesController.php index ad5f7959ce..221f7a6048 100755 --- a/app/Http/Controllers/LicensesController.php +++ b/app/Http/Controllers/LicensesController.php @@ -155,7 +155,7 @@ class LicensesController extends Controller // Was the license created? if ($license->save()) { - + $license->logCreate(); $insertedId = $license->id; // Save the license seat data DB::transaction(function () use (&$insertedId, &$license) { diff --git a/app/Models/Actionlog.php b/app/Models/Actionlog.php index 316d2ff783..613df7585e 100755 --- a/app/Models/Actionlog.php +++ b/app/Models/Actionlog.php @@ -30,7 +30,11 @@ class Actionlog extends Model static::creating( function (Actionlog $actionlog) { // If the admin is a superadmin, let's see if the target instead has a company. if (Auth::user() && Auth::user()->isSuperUser()) { - $actionlog->company_id = $actionlog->target->company_id; + if ($actionlog->target) { + $actionlog->company_id = $actionlog->target->company_id; + } else if ($actionlog->item) { + $actionlog->company_id = $actionlog->item->company_id; + } } else if (Auth::user() && Auth::user()->company) { $actionlog->company_id = Auth::user()->company_id; } diff --git a/app/Models/Loggable.php b/app/Models/Loggable.php index a0799f96c4..08ac74574e 100644 --- a/app/Models/Loggable.php +++ b/app/Models/Loggable.php @@ -81,6 +81,29 @@ trait Loggable return $log; } + /** + * @author Daniel Meltzer item_type = License::class; + $log->item_id = $this->license_id; + } else { + $log->item_type = static::class; + $log->item_id = $this->id; + } + $log->location_id = null; + $log->note = $note; + $log->user_id = Auth::user()->id; + $log->logaction('created'); + + return $log; + } + /** * @author Daniel Meltzer 'Consumables', 'country' => 'Country', 'create' => 'Create New', + 'created' => 'Item Created', 'created_asset' => 'created asset', 'created_at' => 'Created at', 'currency' => '$', // this is deprecated