@@ -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 }
0 commit comments