Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Nov 19, 2013
2 parents edbf195 + 4e8c351 commit 57f5f57
Show file tree
Hide file tree
Showing 19 changed files with 832 additions and 89 deletions.
59 changes: 55 additions & 4 deletions app/controllers/admin/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use User;
use Redirect;
use DB;
use Actionlog;
use Model;
use Depreciation;
use Sentry;
Expand All @@ -29,6 +30,12 @@ public function getIndex()
return View::make('backend/assets/index', compact('assets'));
}

public function getReports()
{
// Grab all the assets
$assets = Asset::orderBy('created_at', 'DESC')->get();
return View::make('backend/reports/index', compact('assets'));
}

/**
* Asset create.
Expand Down Expand Up @@ -91,7 +98,6 @@ public function postCreate()
return Redirect::back()->withInput()->withErrors($errors);
}


// Redirect to the asset create page with an error
return Redirect::to('assets/create')->with('error', Lang::get('admin/assets/message.create.error'));

Expand Down Expand Up @@ -238,7 +244,6 @@ public function postCheckout($assetId)
$assigned_to = e(Input::get('assigned_to'));



// Declare the rules for the form validation
$rules = array(
'assigned_to' => 'required|min:1'
Expand All @@ -265,10 +270,18 @@ public function postCheckout($assetId)
// Update the asset data
$asset->assigned_to = e(Input::get('assigned_to'));


// Was the asset updated?
if($asset->save())
{
$logaction = new Actionlog();
$logaction->asset_id = $asset->id;
$logaction->checkedout_to = $asset->assigned_to;
$logaction->location_id = $assigned_to->location_id;
$logaction->user_id = Sentry::getUser()->id;
$log = $logaction->logaction('checkout');



// Redirect to the new asset page
return Redirect::to("admin")->with('success', Lang::get('admin/assets/message.checkout.success'));
}
Expand All @@ -279,6 +292,9 @@ public function postCheckout($assetId)

/**
* Check in the item so that it can be checked out again to someone else
*
* @param int $assetId
* @return View
**/
public function postCheckin($assetId)
{
Expand All @@ -289,12 +305,26 @@ public function postCheckin($assetId)
return Redirect::to('admin')->with('error', Lang::get('admin/assets/message.not_found'));
}

// Update the asset data
if (!is_null($asset->assigned_to)) {
$user = User::find($asset->assigned_to);
}

$logaction = new Actionlog();
$logaction->checkedout_to = $asset->assigned_to;

// Update the asset data to null, since it's being checked in
$asset->assigned_to = '';

// Was the asset updated?
if($asset->save())
{

$logaction->asset_id = $asset->id;

$logaction->location_id = NULL;
$logaction->user_id = Sentry::getUser()->id;
$log = $logaction->logaction('checkin from');

// Redirect to the new asset page
return Redirect::to("admin")->with('success', Lang::get('admin/assets/message.checkin.success'));
}
Expand All @@ -304,7 +334,28 @@ public function postCheckin($assetId)
}


/**
* Get the asset information to present to the asset view page
*
* @param int $assetId
* @return View
**/
public function getView($assetId = null)
{
$asset = Asset::find($assetId);

if (isset($asset->id)) {
return View::make('backend/assets/view', compact('asset'));
} else {
// Prepare the error message
$error = Lang::get('admin/assets/message.does_not_exist', compact('id' ));

// Redirect to the user management page
return Redirect::route('assets')->with('error', $error);
}


}



Expand Down
44 changes: 42 additions & 2 deletions app/controllers/admin/LicensesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use License;
use Asset;
use User;
use Actionlog;
use DB;
use Redirect;
use Sentry;
Expand Down Expand Up @@ -261,6 +262,13 @@ public function postCheckout($assetId)
// Was the asset updated?
if($license->save())
{
$logaction = new Actionlog();
$logaction->asset_id = $license->id;
$logaction->checkedout_to = $license->assigned_to;
$logaction->location_id = $assigned_to->location_id;
$logaction->user_id = Sentry::getUser()->id;
$log = $logaction->logaction('checkout');

// Redirect to the new asset page
return Redirect::to("admin/licenses")->with('success', Lang::get('admin/licenses/message.checkout.success'));
}
Expand All @@ -281,18 +289,50 @@ public function postCheckin($assetId)
return Redirect::to('admin/licenses')->with('error', Lang::get('admin/assets/message.not_found'));
}

$logaction = new Actionlog();
$logaction->checkedout_to = $license->assigned_to;

// Update the asset data
$license->assigned_to = '';

// Was the asset updated?
if($license->save())
{
$logaction->asset_id = $license->id;

$logaction->location_id = NULL;
$logaction->user_id = Sentry::getUser()->id;
$log = $logaction->logaction('checkin from');

// Redirect to the new asset page
return Redirect::to("admin/licenses")->with('success', Lang::get('admin/assets/message.checkout.success'));
return Redirect::to("admin/licenses")->with('success', Lang::get('admin/licenses/message.checkout.success'));
}

// Redirect to the asset management page with error
return Redirect::to("admin/licenses")->with('error', Lang::get('admin/assets/message.checkout.error'));
return Redirect::to("admin/licenses")->with('error', Lang::get('admin/licenses/message.checkout.error'));
}

/**
* Get the asset information to present to the asset view page
*
* @param int $assetId
* @return View
**/
public function getView($licenseId = null)
{
$license = Asset::find($licenseId);

if (isset($license->id)) {
return View::make('backend/licenses/view', compact('license'));
} else {
// Prepare the error message
$error = Lang::get('admin/licenses/message.does_not_exist', compact('id' ));

// Redirect to the user management page
return Redirect::route('licenses')->with('error', $error);
}


}


Expand Down
23 changes: 18 additions & 5 deletions app/controllers/admin/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use User;
use Asset;
use Lang;
use Actionlog;
use Location;
use Redirect;
use Sentry;
Expand Down Expand Up @@ -410,15 +411,27 @@ public function getRestore($id = null)
}



/**
* Get user info for user view
*
* @param int $userId
* @return View
*/
public function getView($userId = null)
{
$user = User::find($userId);
// Show the page
return View::make('backend/users/view', compact('user'));
}

$user = Sentry::getUserProvider()->createModel()->withTrashed()->find($userId);

if (isset($user->id)) {
return View::make('backend/users/view', compact('user'));
} else {
// Prepare the error message
$error = Lang::get('admin/users/message.user_not_found', compact('id' ));

// Redirect to the user management page
return Redirect::route('users')->with('error', $error);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;

class CreateAssetLogsTable extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('asset_logs', function($table)
{
$table->increments('id');
$table->integer('user_id');
$table->string('action_type');
$table->integer('asset_id');
$table->integer('checkedout_to')->nullable;
$table->integer('location_id')->nullable;
$table->timestamp('added_on');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('asset_logs');
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;

class EditAddedOnAssetLogsTable extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement('ALTER TABLE asset_logs MODIFY added_on timestamp null');

}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;

class EditLocationIdAssetLogsTable extends Migration {


/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement('ALTER TABLE asset_logs MODIFY location_id int(11) null');
DB::statement('ALTER TABLE asset_logs MODIFY added_on timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP');

}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}

}
40 changes: 40 additions & 0 deletions app/models/Actionlog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

class ActionLog extends Eloquent {

protected $table = 'asset_logs';
public $timestamps = false;


public function assetlog() {
return $this->belongsTo('Asset','asset_id');
}

public function adminlog() {
return $this->belongsTo('User','user_id');
}

public function userlog() {
return $this->belongsTo('User','checkedout_to');
}


/**
* Get the parent category name
*/
public function logaction($actiontype)
{
$this->action_type = $actiontype;

if($this->save())
{
return true;
} else {
return false;
}
}




}
Loading

0 comments on commit 57f5f57

Please sign in to comment.