Log checkouts (#2772)

* Ensure the log has a target before trying to fetch the associated company

* Log creation of items, both in importer and manually
This commit is contained in:
Daniel Meltzer 2016-10-12 20:45:32 -05:00 committed by snipe
parent 219ef23126
commit e85241af6a
9 changed files with 37 additions and 3 deletions

View file

@ -856,6 +856,7 @@ class ObjectImportCommand extends Command
if (!$this->option('testrun')) { if (!$this->option('testrun')) {
if ($asset->save()) { if ($asset->save()) {
$asset->logCreate('Imported using csv importer');
$this->log('Asset ' . $item["item_name"] . ' with serial number ' . $asset_serial . ' was created'); $this->log('Asset ' . $item["item_name"] . ' with serial number ' . $asset_serial . ' was created');
} else { } else {
$this->jsonError('Asset', $asset->getErrors()); $this->jsonError('Asset', $asset->getErrors());
@ -941,6 +942,7 @@ class ObjectImportCommand extends Command
if (!$this->option('testrun')) { if (!$this->option('testrun')) {
if ($accessory->save()) { if ($accessory->save()) {
$accessory->logCreate('Imported using CSV Importer');
$this->log('Accessory ' . $item["item_name"] . ' was created'); $this->log('Accessory ' . $item["item_name"] . ' was created');
// $this->comment('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")) { if (!$this->option("testrun")) {
// dd($consumable); // dd($consumable);
if ($consumable->save()) { if ($consumable->save()) {
$consumable->logCreate('Imported using CSV Importer');
$this->log("Consumable " . $item["item_name"] . ' was created'); $this->log("Consumable " . $item["item_name"] . ' was created');
// $this->comment("Consumable " . $item["item_name"] . ' was created'); // $this->comment("Consumable " . $item["item_name"] . ' was created');

View file

@ -100,6 +100,7 @@ class AccessoriesController extends Controller
// Was the accessory created? // Was the accessory created?
if ($accessory->save()) { if ($accessory->save()) {
$accessory->logCreate();
// Redirect to the new accessory page // Redirect to the new accessory page
return redirect()->to("admin/accessories")->with('success', trans('admin/accessories/message.create.success')); return redirect()->to("admin/accessories")->with('success', trans('admin/accessories/message.create.success'));
} }

View file

@ -264,7 +264,7 @@ class AssetsController extends Controller
// Was the asset created? // Was the asset created?
if ($asset->save()) { if ($asset->save()) {
$asset->logCreate();
if (Input::get('assigned_to')!='') { if (Input::get('assigned_to')!='') {
$user = User::find(e(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'))); $asset->checkOutToUser($user, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset creation', e(Input::get('name')));

View file

@ -107,6 +107,7 @@ class ComponentsController extends Controller
// Was the component created? // Was the component created?
if ($component->save()) { if ($component->save()) {
$component->logCreate();
// Redirect to the new component page // Redirect to the new component page
return redirect()->to("admin/components")->with('success', trans('admin/components/message.create.success')); return redirect()->to("admin/components")->with('success', trans('admin/components/message.create.success'));
} }

View file

@ -105,6 +105,7 @@ class ConsumablesController extends Controller
// Was the consumable created? // Was the consumable created?
if ($consumable->save()) { if ($consumable->save()) {
$consumable->logCreate();
// Redirect to the new consumable page // Redirect to the new consumable page
return redirect()->to("admin/consumables")->with('success', trans('admin/consumables/message.create.success')); return redirect()->to("admin/consumables")->with('success', trans('admin/consumables/message.create.success'));
} }

View file

@ -155,7 +155,7 @@ class LicensesController extends Controller
// Was the license created? // Was the license created?
if ($license->save()) { if ($license->save()) {
$license->logCreate();
$insertedId = $license->id; $insertedId = $license->id;
// Save the license seat data // Save the license seat data
DB::transaction(function () use (&$insertedId, &$license) { DB::transaction(function () use (&$insertedId, &$license) {

View file

@ -30,7 +30,11 @@ class Actionlog extends Model
static::creating( function (Actionlog $actionlog) { static::creating( function (Actionlog $actionlog) {
// If the admin is a superadmin, let's see if the target instead has a company. // If the admin is a superadmin, let's see if the target instead has a company.
if (Auth::user() && Auth::user()->isSuperUser()) { 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) { } else if (Auth::user() && Auth::user()->company) {
$actionlog->company_id = Auth::user()->company_id; $actionlog->company_id = Auth::user()->company_id;
} }

View file

@ -81,6 +81,29 @@ trait Loggable
return $log; return $log;
} }
/**
* @author Daniel Meltzer <parallelgrapefruit@gmail.com
* @since [v3.4]
* @return \App\Models\Actionlog
*/
public function logCreate($note = null)
{
$log = new Actionlog;
if (static::class == LicenseSeat::class) {
$log->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 <parallelgrapefruit@gmail.com * @author Daniel Meltzer <parallelgrapefruit@gmail.com
* @since [v3.4] * @since [v3.4]

View file

@ -41,6 +41,7 @@
'consumables' => 'Consumables', 'consumables' => 'Consumables',
'country' => 'Country', 'country' => 'Country',
'create' => 'Create New', 'create' => 'Create New',
'created' => 'Item Created',
'created_asset' => 'created asset', 'created_asset' => 'created asset',
'created_at' => 'Created at', 'created_at' => 'Created at',
'currency' => '$', // this is deprecated 'currency' => '$', // this is deprecated