Skip to content

Commit

Permalink
Changed license structure to use join table to handle multiple seats
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Nov 25, 2013
1 parent 5489422 commit 1b01074
Show file tree
Hide file tree
Showing 15 changed files with 398 additions and 51 deletions.
21 changes: 17 additions & 4 deletions app/controllers/admin/LicensesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Actionlog;
use DB;
use Redirect;
use LicenseSeat;
use Setting;
use Sentry;
use Str;
Expand All @@ -26,7 +27,7 @@ class LicensesController extends AdminController {
public function getIndex()
{
// Grab all the licenses
$licenses = License::orderBy('created_at', 'DESC')->where('physical', '=', 0)->paginate(Setting::getSettings()->per_page);
$licenses = License::orderBy('created_at', 'DESC')->paginate(Setting::getSettings()->per_page);

// Show the page
return View::make('backend/licenses/index', compact('licenses'));
Expand Down Expand Up @@ -72,15 +73,28 @@ public function postCreate()
$license->license_name = e(Input::get('license_name'));
$license->notes = e(Input::get('notes'));
$license->order_number = e(Input::get('order_number'));
$license->seats = e(Input::get('seats'));
$license->purchase_date = e(Input::get('purchase_date'));
$license->purchase_cost = e(Input::get('purchase_cost'));
$license->user_id = Sentry::getId();
$license->physical = '0';


// Was the asset created?



// Was the license created?
if($license->save())
{
$insertedId = $license->id;
// Save the license seat data
for ($x=0; $x<$license->seats; $x++) {
$license_seat = new LicenseSeat();
$license_seat->license_id = $insertedId;
$license_seat->user_id = Sentry::getId();
$license_seat->save();
}


// Redirect to the new license page
return Redirect::to("admin/licenses")->with('success', Lang::get('admin/licenses/message.create.success'));
}
Expand Down Expand Up @@ -151,7 +165,6 @@ public function postEdit($licenseId = null)
$license->order_number = e(Input::get('order_number'));
$license->purchase_date = e(Input::get('purchase_date'));
$license->purchase_cost = e(Input::get('purchase_cost'));
$license->physical = '0';


// Was the asset created?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

use Illuminate\Database\Migrations\Migration;

class ReCreateLicensesTable extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::create('licenses', function($table)
{
$table->increments('id');
$table->string('name');
$table->string('serial');
$table->date('purchase_date')->nullable();
$table->decimal('purchase_cost', 8, 2)->nullable();
$table->string('order_number');
$table->integer('seats');
$table->text('notes');
$table->integer('user_id');
$table->integer('depreciation_id');
$table->timestamps();
$table->softDeletes();
});
}

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

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

use Illuminate\Database\Migrations\Migration;

class CreateLicenseSeatsTable extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::create('license_seats', function($table)
{
$table->increments('id');
$table->integer('license_id');
$table->integer('assigned_to');
$table->text('notes');
$table->integer('user_id');
$table->timestamps();
$table->softDeletes();
});
}

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

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

use Illuminate\Database\Migrations\Migration;

class AddTypeToActionlogTable extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::table('asset_logs', function($table)
{
$table->enum('asset_type', array('software', 'hardware'));
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::table('asset_logs', function($table)
{
$table->dropColumn('asset_type');
});
}

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

use Illuminate\Database\Migrations\Migration;

class DeleteBadLicensesTable extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::drop('licenses');
}

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

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

use Illuminate\Database\Migrations\Migration;

class CreateNewLicensesTable extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::create('licenses', function($table)
{
$table->increments('id');
$table->string('name');
$table->string('serial');
$table->date('purchase_date')->nullable();
$table->decimal('purchase_cost', 8, 2)->nullable();
$table->string('order_number');
$table->integer('seats')->default(1);
$table->text('notes');
$table->integer('user_id');
$table->integer('depreciation_id');
$table->timestamps();
$table->softDeletes();
});
}

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

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

use Illuminate\Database\Migrations\Migration;

class AddLicensedToLicensesTable extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::table('licenses', function($table)
{
$table->string('license_name');
$table->string('license_email');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::table('licenses', function($table)
{
$table->dropColumn('license_name');
$table->dropColumn('license_email');
});
}

}
39 changes: 0 additions & 39 deletions app/database/seeds/AssetsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,45 +112,6 @@ public function run()
'status_id' => 0,
);

// Deployed (status_id =0, assigned_to > 0)
$asset[] = array(
'name' => 'Photoshop CS6',
'asset_tag' => 'NNY65756756775',
'model_id' => 8,
'serial' => 'OMG-WTF-SRSLY-BBQ',
'purchase_date' => '2012-01-02',
'purchase_cost' => '1999.99',
'order_number' => '657756',
'created_at' => $date->modify('-10 day'),
'updated_at' => $date->modify('-3 day'),
'user_id' => 2,
'assigned_to' => 2,
'physical' => 0,
'archived' => 0,
'license_name' => 'Alison Giasnotto',
'license_email' => '[email protected]',
'status_id' => 0,
);

// Deployed (status_id =0, assigned_to > 0)
$asset[] = array(
'name' => 'Git Tower',
'asset_tag' => 'NNY65756756775',
'model_id' => 7,
'serial' => 'OMG-WTF-SRSLY-BBQ',
'purchase_date' => '2012-01-02',
'purchase_cost' => '1999.99',
'order_number' => '657756',
'created_at' => $date->modify('-10 day'),
'updated_at' => $date->modify('-3 day'),
'user_id' => 2,
'assigned_to' => 2,
'physical' => 0,
'archived' => 0,
'license_name' => 'Alison Giasnotto',
'license_email' => '[email protected]',
'status_id' => 0,
);

// Deployed (status_id =0, assigned_to > 0)
$asset[] = array(
Expand Down
2 changes: 2 additions & 0 deletions app/database/seeds/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function run()
$this->call('DepreciationsSeeder');
$this->call('StatuslabelsSeeder');
$this->call('SettingsSeeder');
$this->call('LicensesSeeder');
$this->call('LicenseSeatsSeeder');
}

}
Loading

0 comments on commit 1b01074

Please sign in to comment.