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();
$item = array();
$errors = array();
$status = array();
foreach($results as $row) {
@ -1058,7 +1058,8 @@ class AssetsController extends Controller
}
$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]['name'] = Helper::array_smart_fetch($row, "name");
$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,
'note' => 'Checkout imported by '.Auth::user()->fullName().' from history importer',
'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'
)
);
@ -1136,36 +1137,35 @@ class AssetsController extends Controller
// Loop through and backfill the checkins
foreach ($item as $key => $asset_batch) {
$batch_counter = 0;
for($x = 0; $x < count($asset_batch); $x++) {
$total_in_batch = count($asset_batch);
for($x = 0; $x < $total_in_batch; $x++) {
$next = $x + 1;
// Only do this if a matching user was found
if ($asset_batch[$x]['checkedout_to']!='') {
$batch_counter++;
if ((count($asset_batch) != 1) && ($batch_counter < count($asset_batch))) {
$checkin_date = date('Y-m-d H:i:s',(strtotime($asset_batch[$x]['date']) + 10));
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;
Actionlog::firstOrCreate(array(
'asset_id' => $asset_batch[$x]['asset_id'],
'asset_type' => 'hardware',
'user_id' => Auth::user()->id,
'note' => 'Checkin imported by '.Auth::user()->fullName().' from history importer',
'user_id' => Auth::user()->id,
'note' => 'Checkin imported by ' . Auth::user()->fullName() . ' from history importer',
'checkedout_to' => null,
'created_at' => $checkin_date,
'action_type' => 'checkin'
'created_at' => $checkin_date,
'action_type' => 'checkin'
)
);
}
}
}
}
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>History should be ordered by date in ascending order.</strong></p>
<div class="form-group">
<label for="first_name" class="col-sm-3 control-label">{{ trans('admin/users/general.usercsv') }}</label>
<div class="col-sm-9">