Small tweaks to history

This commit is contained in:
snipe 2016-08-12 19:03:32 -07:00
parent 5e9740e0b4
commit 7edf1db101
2 changed files with 19 additions and 17 deletions

View file

@ -1044,7 +1044,7 @@ class AssetsController extends Controller
$results = $csv->fetchAssoc(); $results = $csv->fetchAssoc();
$item = array(); $item = array();
$errors = array(); $status = array();
foreach($results as $row) { foreach($results as $row) {
@ -1058,7 +1058,8 @@ class AssetsController extends Controller
} }
$batch_counter = count($item[$asset_tag]); $batch_counter = count($item[$asset_tag]);
$item[$asset_tag][$batch_counter]['date'] = date('Y-m-d H:i:s', strtotime(Helper::array_smart_fetch($row, "date"))); $item[$asset_tag][$batch_counter]['checkout_date'] = Carbon::parse(Helper::array_smart_fetch($row, "date"))->format('Y-m-d H:i:s');
$item[$asset_tag][$batch_counter]['asset_tag'] = Helper::array_smart_fetch($row, "asset tag"); $item[$asset_tag][$batch_counter]['asset_tag'] = Helper::array_smart_fetch($row, "asset tag");
$item[$asset_tag][$batch_counter]['name'] = Helper::array_smart_fetch($row, "name"); $item[$asset_tag][$batch_counter]['name'] = Helper::array_smart_fetch($row, "name");
$item[$asset_tag][$batch_counter]['email'] = Helper::array_smart_fetch($row, "email"); $item[$asset_tag][$batch_counter]['email'] = Helper::array_smart_fetch($row, "email");
@ -1113,7 +1114,7 @@ class AssetsController extends Controller
'user_id' => Auth::user()->id, 'user_id' => Auth::user()->id,
'note' => 'Checkout imported by '.Auth::user()->fullName().' from history importer', 'note' => 'Checkout imported by '.Auth::user()->fullName().' from history importer',
'checkedout_to' => $item[$asset_tag][$batch_counter]['user_id'], 'checkedout_to' => $item[$asset_tag][$batch_counter]['user_id'],
'created_at' => $item[$asset_tag][$batch_counter]['date'], 'created_at' => $item[$asset_tag][$batch_counter]['checkout_date'],
'action_type' => 'checkout' 'action_type' => 'checkout'
) )
); );
@ -1136,22 +1137,22 @@ class AssetsController extends Controller
// Loop through and backfill the checkins // Loop through and backfill the checkins
foreach ($item as $key => $asset_batch) { foreach ($item as $key => $asset_batch) {
$batch_counter = 0; $total_in_batch = count($asset_batch);
for($x = 0; $x < $total_in_batch; $x++) {
for($x = 0; $x < count($asset_batch); $x++) { $next = $x + 1;
// Only do this if a matching user was found // Only do this if a matching user was found
if ($asset_batch[$x]['checkedout_to']!='') { if ($asset_batch[$x]['checkedout_to']!='') {
$batch_counter++;
if ((count($asset_batch) != 1) && ($batch_counter < count($asset_batch))) { if (($total_in_batch > 1) && ($x < $total_in_batch) && (array_key_exists($next,$asset_batch))) {
$checkin_date = Carbon::parse($asset_batch[$next]['checkout_date'])->subDay(1)->format('Y-m-d H:i:s');
$asset_batch[$x]['real_checkin'] = $checkin_date;
$checkin_date = date('Y-m-d H:i:s',(strtotime($asset_batch[$x]['date']) + 10));
Actionlog::firstOrCreate(array( Actionlog::firstOrCreate(array(
'asset_id' => $asset_batch[$x]['asset_id'], 'asset_id' => $asset_batch[$x]['asset_id'],
'asset_type' => 'hardware', 'asset_type' => 'hardware',
'user_id' => Auth::user()->id, 'user_id' => Auth::user()->id,
'note' => 'Checkin imported by '.Auth::user()->fullName().' from history importer', 'note' => 'Checkin imported by ' . Auth::user()->fullName() . ' from history importer',
'checkedout_to' => null, 'checkedout_to' => null,
'created_at' => $checkin_date, 'created_at' => $checkin_date,
'action_type' => 'checkin' 'action_type' => 'checkin'
@ -1160,11 +1161,10 @@ class AssetsController extends Controller
} }
} }
}
} }
}
return View::make('hardware/history')->with('status',$status); return View::make('hardware/history')->with('status',$status);
} }

View file

@ -38,6 +38,8 @@
<p><strong>Date</strong> should be the checkout date. <strong>Tag</strong> should be the asset tag. <strong>Name</strong> should be the user's name (firstname lastname).</p> <p><strong>Date</strong> should be the checkout date. <strong>Tag</strong> should be the asset tag. <strong>Name</strong> should be the user's name (firstname lastname).</p>
<p><strong>History should be ordered by date in ascending order.</strong></p>
<div class="form-group"> <div class="form-group">
<label for="first_name" class="col-sm-3 control-label">{{ trans('admin/users/general.usercsv') }}</label> <label for="first_name" class="col-sm-3 control-label">{{ trans('admin/users/general.usercsv') }}</label>
<div class="col-sm-9"> <div class="col-sm-9">