Skip to content

Commit 45f353e

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 185ffd3 + bef5170 commit 45f353e

File tree

3 files changed

+96
-6
lines changed

3 files changed

+96
-6
lines changed

app/controllers/admin/LicensesController.php

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,20 @@ public function postEdit($licenseId = null)
188188
$license->license_name = e(Input::get('license_name'));
189189
$license->notes = e(Input::get('notes'));
190190
$license->order_number = e(Input::get('order_number'));
191-
$license->purchase_date = e(Input::get('purchase_date'));
192-
$license->purchase_cost = e(Input::get('purchase_cost'));
191+
192+
// Update the asset data
193+
if ( e(Input::get('purchase_date')) == '') {
194+
$license->purchase_date = NULL;
195+
} else {
196+
$license->purchase_date = e(Input::get('purchase_date'));
197+
}
198+
199+
if ( e(Input::get('purchase_cost')) == '') {
200+
$license->purchase_cost = NULL;
201+
} else {
202+
$license->purchase_cost = e(Input::get('purchase_cost'));
203+
}
204+
193205

194206
//Are we changing the total number of seats?
195207
if( $license->seats != e(Input::get('seats')))
@@ -205,12 +217,13 @@ public function postEdit($licenseId = null)
205217
return is_null($seat->user);
206218
});
207219

220+
208221
//If the remaining collection is as large or larger than the number of seats we want to delete
209222
if($seats->count() >= abs($difference))
210223
{
211224
for ($i=1; $i <= abs($difference); $i++) {
212225
//Delete the appropriate number of seats
213-
$seats->first()->delete();
226+
$seats->pop()->delete();
214227
}
215228

216229
//Log the deletion of seats to the log
@@ -219,7 +232,9 @@ public function postEdit($licenseId = null)
219232
$logaction->asset_type = 'software';
220233
$logaction->user_id = Sentry::getUser()->id;
221234
$logaction->note = abs($difference)." seats";
235+
$logaction->checkedout_to = NULL;
222236
$log = $logaction->logaction('delete seats');
237+
223238
} else {
224239
// Redirect to the license edit page
225240
return Redirect::to("admin/licenses/$licenseId/edit")->with('error', Lang::get('admin/licenses/message.assoc_users'));
@@ -364,21 +379,34 @@ public function postCheckout($seatId)
364379

365380

366381
// Update the asset data
367-
$licenseseat->assigned_to = e(Input::get('assigned_to'));
368-
382+
if ( e(Input::get('assigned_to')) == '') {
383+
$licenseseat->assigned_to = NULL;
384+
} else {
385+
$licenseseat->assigned_to = e(Input::get('assigned_to'));
386+
}
369387

370388
// Was the asset updated?
371389
if($licenseseat->save())
372390
{
391+
373392
$logaction = new Actionlog();
374393
$logaction->asset_id = $licenseseat->license_id;
375-
$logaction->checkedout_to = $licenseseat->assigned_to;
376394
$logaction->location_id = $assigned_to->location_id;
377395
$logaction->asset_type = 'software';
378396
$logaction->user_id = Sentry::getUser()->id;
379397
$logaction->note = e(Input::get('note'));
398+
399+
400+
// Update the asset data
401+
if ( e(Input::get('assigned_to')) == '') {
402+
$logaction->checkedout_to = NULL;
403+
} else {
404+
$logaction->checkedout_to = e(Input::get('assigned_to'));
405+
}
406+
380407
$log = $logaction->logaction('checkout');
381408

409+
382410
// Redirect to the new asset page
383411
return Redirect::to("admin/licenses")->with('success', Lang::get('admin/licenses/message.checkout.success'));
384412
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class MakeAssetLogCheckedoutToNullable extends Migration {
7+
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
//
16+
DB::statement('ALTER TABLE asset_logs MODIFY column checkedout_to int(11) NULL');
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*
22+
* @return void
23+
*/
24+
public function down()
25+
{
26+
//
27+
}
28+
29+
}
30+
31+
32+
33+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class MakeAssetLogPurchasedateToNullable extends Migration {
7+
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
//
16+
DB::statement('ALTER TABLE licenses MODIFY column purchase_date date NULL');
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*
22+
* @return void
23+
*/
24+
public function down()
25+
{
26+
//
27+
}
28+
29+
}

0 commit comments

Comments
 (0)