Skip to content

Commit

Permalink
More license tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Nov 25, 2013
1 parent 1b01074 commit faae6a2
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 49 deletions.
7 changes: 4 additions & 3 deletions app/controllers/admin/LicensesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ public function postCheckout($assetId)
$logaction->asset_id = $license->id;
$logaction->checkedout_to = $license->assigned_to;
$logaction->location_id = $assigned_to->location_id;
$logaction->asset_type = 'software';
$logaction->user_id = Sentry::getUser()->id;
$log = $logaction->logaction('checkout');

Expand Down Expand Up @@ -320,8 +321,8 @@ public function postCheckin($assetId)
if($license->save())
{
$logaction->asset_id = $license->id;

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

Expand All @@ -341,13 +342,13 @@ public function postCheckin($assetId)
**/
public function getView($licenseId = null)
{
$license = Asset::find($licenseId);
$license = License::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' ));
$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
35 changes: 33 additions & 2 deletions app/models/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function assignedusers()
**/
public function assetloc()
{
return $this->assigneduser->hasOne('Location');
return $this->assignedusers->hasOne('Location');
}

/**
Expand All @@ -38,7 +38,7 @@ public function assetloc()
public function assetlog()
{
return $this->hasMany('Actionlog','asset_id')
->where('assigned_to', '=', '0')
->where('checkedout_to', '=', '0')
->orderBy('added_on', 'desc');
}

Expand Down Expand Up @@ -72,6 +72,37 @@ public static function availassetcount()

}

public function availcount()
{
return DB::table('license_seats')
->where('assigned_to', '=', '0')
->where('license_id', '=', $this->id)
->whereNull('deleted_at','and')
->count();
}


public function assignedcount()
{
return DB::table('license_seats')
->where('assigned_to', '>', '0')
->where('license_id', '=', $this->id)
->whereNull('deleted_at','and')
->count();
}

public function totalcount()
{
$avail = $this->availcount();
$taken = $this->assignedcount();
$diff = ($avail + $taken);
return $diff;
}

public function licenseseats()
{
return $this->hasMany('LicenseSeat');
}


}
12 changes: 8 additions & 4 deletions app/models/LicenseSeat.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
class LicenseSeat extends Elegant {
protected $table = 'license_seats';

public function assignedusers()
{
return $this->belongsToMany('LicenseSeat', 'assigned_to');
}
public function license()
{
return $this->belongsTo('License');
}

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

}
22 changes: 12 additions & 10 deletions app/views/backend/licenses/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,34 @@
{{ $errors->first('serial', '<span class="help-inline">:message</span>') }}
</div>
</div>

<div class="control-group {{ $errors->has('license_name') ? 'error' : '' }}">
<label class="control-label" for="license_name">Licensed to Name</label>
<div class="controls">
<input class="span6" type="text" name="license_name" id="license_name" value="{{ Input::old('license_name', $license->license_name) }}" />
{{ $errors->first('license_name', '<span class="help-inline">:message</span>') }}
</div>
</div>
<div class="control-group {{ $errors->has('license_email') ? 'error' : '' }}">
<label class="control-label" for="license_email">License Email</label>
<label class="control-label" for="license_email">Licensed to Email</label>
<div class="controls">
<input class="span6" type="text" name="license_email" id="license_email" value="{{ Input::old('license_email', $license->license_email) }}" />
{{ $errors->first('license_email', '<span class="help-inline">:message</span>') }}
</div>
</div>

<div class="control-group {{ $errors->has('license_name') ? 'error' : '' }}">
<label class="control-label" for="license_name">License Name</label>
<div class="control-group {{ $errors->has('seats') ? 'error' : '' }}">
<label class="control-label" for="seats">Seats</label>
<div class="controls">
<input class="span6" type="text" name="license_name" id="license_name" value="{{ Input::old('license_name', $license->license_name) }}" />
{{ $errors->first('license_name', '<span class="help-inline">:message</span>') }}
<input class="span1" type="text" name="seats" id="seats" value="{{ Input::old('seats', $license->seats) }}" />
{{ $errors->first('seats', '<span class="help-inline">:message</span>') }}
</div>
</div>

<div class="control-group {{ $errors->has('order_number') ? 'error' : '' }}">
<label class="control-label" for="order_number">Order Number</label>
<div class="controls">
<input class="span4" type="text" name="order_number" id="order_number" value="{{ Input::old('order_number', $license->order_number) }}" />
{{ $errors->first('order_number', '<span class="help-inline">:message</span>') }}
</div>
</div>


<div class="control-group {{ $errors->has('purchase_cost') ? 'error' : '' }}">
<label class="control-label" for="purchase_cost">Purchase Cost</label>
<div class="controls">
Expand Down
90 changes: 62 additions & 28 deletions app/views/backend/licenses/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
<table class="table table-hover">
<thead>
<tr>
<th class="span2">@lang('admin/licenses/table.title')</th>
<th class="span1">@lang('admin/licenses/table.seats')</th>
<th class="span2"><span class="line"></span>@lang('admin/licenses/table.title')</th>
<th class="span2"><span class="line"></span>@lang('admin/licenses/table.serial')</th>
<th class="span2"><span class="line"></span>@lang('admin/licenses/table.license_name')</th>
<th class="span2"><span class="line"></span>@lang('admin/licenses/table.license_email')</th>
Expand All @@ -33,35 +34,68 @@
</tr>
</thead>
<tbody>


@foreach ($licenses as $license)
<tr>
<td><a href="{{ route('view/license', $license->id) }}">{{ $license->name }}</a></td>
<td><a href="{{ route('view/license', $license->id) }}">{{ $license->serial }}</a></td>

<td>{{ $license->license_name }}</td>
<td>{{ $license->license_email }}</td>

<td>
@if ($license->assigned_to != 0)
<a href="{{ route('view/user', $license->assigned_to) }}">
{{ $license->assigneduser->fullName() }}
</a>
@endif
</td>
<td>
@if ($license->assigned_to != 0)
<a href="{{ route('checkin/license', $license->id) }}" class="btn-flat info">Checkin</a>
@else
<a href="{{ route('checkout/license', $license->id) }}" class="btn-flat success">Checkout</a>
@endif
</td>
<td>
<a href="{{ route('update/license', $license->id) }}" class="btn-flat white"> @lang('button.edit')</a>
<a class="btn-flat danger delete-asset" data-toggle="modal" href="{{ route('delete/license', $license->id) }}" data-content="Are you sure you wish to delete the {{ $license->name }} license?" data-title="Delete {{ $license->name }}?" onClick="return false;">@lang('button.delete')</a>

</td>
</tr>

<tr>
<td>{{ $license->seats }}</td>
<td><a href="{{ route('view/license', $license->id) }}">{{ $license->name }}</a></td>
<td><a href="{{ route('view/license', $license->id) }}">{{ $license->serial }}</a></td>
<td>{{ $license->license_name }}</td>
<td>{{ $license->license_email }} </td>
<td></td>
<td></td>
<td>

<a href="{{ route('update/license', $license->id) }}" class="btn-flat white"> @lang('button.edit')</a>
<a class="btn-flat danger delete-asset" data-toggle="modal" href="{{ route('delete/license', $license->id) }}" data-content="Are you sure you wish to delete the {{ $license->name }} license?" data-title="Delete {{ $license->name }}?" onClick="return false;">@lang('button.delete')</a>


</td>
</tr>
@if ($license->licenseseats)

@foreach ($license->licenseseats as $licensedto)

<tr>

<td></td>
<td></td>
<td><i class="icon-chevron-right"></i> {{ $license->serial }}</td>


<td>{{ $license->license_name }}</td>
<td>{{ $license->license_email }} </td>
<td>
@if ($licensedto->assigned_to)
<a href="{{ route('view/user', $licensedto->id) }}">
{{ $licensedto->user->fullName() }}
</a>
@endif
</td>
<td>
@if ($licensedto->assigned_to)
<a href="{{ route('checkin/license', $licensedto->id) }}" class="btn-flat info"> Checkin </a>
@else
<a href="{{ route('checkout/license', $licensedto->id) }}" class="btn-flat success">Checkout</a>
@endif
</td>
<td>
</td>
</tr>
@endforeach
@endif


@endforeach







</tbody>
</table>
</div>
Expand Down
23 changes: 21 additions & 2 deletions app/views/backend/licenses/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,28 @@
<li><a href="{{ route('update/license', $license->id) }}">Edit License</a></li>
</ul>
</div>


</h3>


<div class="span6 bio">
<div class="profile-box">
<br>
@if ($license->serial)
<p>Serial: {{ $license->serial }} <br>
@endif
@if ($license->license_name)
License Name: {{ $license->license_name }} <br>
@endif
@if ($license->license_email)
License Email: {{ $license->license_email }} <br>
@endif
@if ($license->purchase_date)
Purchase Date: {{ $license->purchase_date }} <br>
@endif
</p>
</div>
</div>




Expand Down Expand Up @@ -106,6 +123,8 @@
<!-- side address column -->
<div class="span3 address pull-right">



@if ((isset($license->assigned_to ) && ($license->assigned_to > 0)))
<h6><br>Checked Out To:</h6>
<ul>
Expand Down

0 comments on commit faae6a2

Please sign in to comment.