mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Merge pull request #13498 from marcusmoore/feature/add-checkin-date-range-filter-to-custom-asset-report
Added last check in column and filter to custom asset report
This commit is contained in:
commit
a62e2f092b
|
@ -905,6 +905,7 @@ class AssetsController extends Controller
|
|||
|
||||
$asset->expected_checkin = null;
|
||||
$asset->last_checkout = null;
|
||||
$asset->last_checkin = now();
|
||||
$asset->assigned_to = null;
|
||||
$asset->assignedTo()->disassociate($asset);
|
||||
$asset->accepted = null;
|
||||
|
|
|
@ -68,6 +68,7 @@ class AssetCheckinController extends Controller
|
|||
|
||||
$asset->expected_checkin = null;
|
||||
$asset->last_checkout = null;
|
||||
$asset->last_checkin = now();
|
||||
$asset->assigned_to = null;
|
||||
$asset->assignedTo()->disassociate($asset);
|
||||
$asset->assigned_type = null;
|
||||
|
|
|
@ -545,6 +545,10 @@ class ReportsController extends Controller
|
|||
$header[] = trans('admin/hardware/table.checkout_date');
|
||||
}
|
||||
|
||||
if ($request->filled('checkin_date')) {
|
||||
$header[] = trans('admin/hardware/table.last_checkin_date');
|
||||
}
|
||||
|
||||
if ($request->filled('expected_checkin')) {
|
||||
$header[] = trans('admin/hardware/form.expected_checkin');
|
||||
}
|
||||
|
@ -651,6 +655,14 @@ class ReportsController extends Controller
|
|||
$assets->whereBetween('assets.last_checkout', [$checkout_start, $checkout_end]);
|
||||
}
|
||||
|
||||
if (($request->filled('checkin_date_start'))) {
|
||||
$assets->whereBetween('last_checkin', [
|
||||
Carbon::parse($request->input('checkin_date_start'))->startOfDay(),
|
||||
// use today's date is `checkin_date_end` is not provided
|
||||
Carbon::parse($request->input('checkin_date_end', now()))->endOfDay(),
|
||||
]);
|
||||
}
|
||||
|
||||
if (($request->filled('expected_checkin_start')) && ($request->filled('expected_checkin_end'))) {
|
||||
$assets->whereBetween('assets.expected_checkin', [$request->input('expected_checkin_start'), $request->input('expected_checkin_end')]);
|
||||
}
|
||||
|
@ -835,6 +847,12 @@ class ReportsController extends Controller
|
|||
$row[] = ($asset->last_checkout) ? $asset->last_checkout : '';
|
||||
}
|
||||
|
||||
if ($request->filled('checkin_date')) {
|
||||
$row[] = ($asset->last_checkin)
|
||||
? Carbon::parse($asset->last_checkin)->format('Y-m-d')
|
||||
: '';
|
||||
}
|
||||
|
||||
if ($request->filled('expected_checkin')) {
|
||||
$row[] = ($asset->expected_checkin) ? $asset->expected_checkin : '';
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ class Asset extends Depreciable
|
|||
protected $casts = [
|
||||
'purchase_date' => 'date',
|
||||
'last_checkout' => 'datetime',
|
||||
'last_checkin' => 'datetime',
|
||||
'expected_checkin' => 'date',
|
||||
'last_audit_date' => 'datetime',
|
||||
'next_audit_date' => 'date',
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddLastCheckinToAssets extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('assets', function (Blueprint $table) {
|
||||
$table->dateTime('last_checkin')->after('last_checkout')->nullable();
|
||||
});
|
||||
|
||||
DB::statement(
|
||||
"UPDATE " . DB::getTablePrefix() . "assets SET last_checkin=(SELECT MAX(" . DB::getTablePrefix() . "action_logs.action_date) FROM " . DB::getTablePrefix() . "action_logs WHERE item_type='App\\\Models\\\Asset' AND " . DB::getTablePrefix() . "action_logs.item_id=" . DB::getTablePrefix() . "assets.id AND " . DB::getTablePrefix() . "action_logs.action_type='checkin from')"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('assets', function (Blueprint $table) {
|
||||
$table->dropColumn('last_checkin');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ return [
|
|||
'dl_csv' => 'Download CSV',
|
||||
'eol' => 'EOL',
|
||||
'id' => 'ID',
|
||||
'last_checkin_date' => 'Last Checkin Date',
|
||||
'location' => 'Location',
|
||||
'purchase_cost' => 'Cost',
|
||||
'purchase_date' => 'Purchased',
|
||||
|
|
|
@ -141,6 +141,11 @@
|
|||
{{ trans('admin/hardware/table.checkout_date') }}
|
||||
</label>
|
||||
|
||||
<label class="form-control">
|
||||
{{ Form::checkbox('checkin_date', '1', '1') }}
|
||||
{{ trans('admin/hardware/table.last_checkin_date') }}
|
||||
</label>
|
||||
|
||||
<label class="form-control">
|
||||
{{ Form::checkbox('expected_checkin', '1', '1') }}
|
||||
{{ trans('admin/hardware/form.expected_checkin') }}
|
||||
|
@ -289,6 +294,16 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Last Checkin Date -->
|
||||
<div class="form-group checkin-range">
|
||||
<label for="checkin_date" class="col-md-3 control-label">{{ trans('admin/hardware/table.last_checkin_date') }}</label>
|
||||
<div class="input-daterange input-group col-md-6" id="datepicker">
|
||||
<input type="text" class="form-control" name="checkin_date_start" aria-label="checkin_date_start">
|
||||
<span class="input-group-addon">{{ strtolower(trans('general.to')) }}</span>
|
||||
<input type="text" class="form-control" name="checkin_date_end" aria-label="checkin_date_end">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Expected Checkin Date -->
|
||||
<div class="form-group expected_checkin-range">
|
||||
<label for="expected_checkin_start" class="col-md-3 control-label">{{ trans('admin/hardware/form.expected_checkin') }}</label>
|
||||
|
@ -381,6 +396,13 @@
|
|||
format: 'yyyy-mm-dd'
|
||||
});
|
||||
|
||||
$('.checkin-range .input-daterange').datepicker({
|
||||
clearBtn: true,
|
||||
todayHighlight: true,
|
||||
endDate: '0d',
|
||||
format: 'yyyy-mm-dd'
|
||||
});
|
||||
|
||||
$('.expected_checkin-range .input-daterange').datepicker({
|
||||
clearBtn: true,
|
||||
todayHighlight: true,
|
||||
|
|
30
tests/Feature/Api/Assets/AssetCheckinTest.php
Normal file
30
tests/Feature/Api/Assets/AssetCheckinTest.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\Assets;
|
||||
|
||||
use App\Models\Asset;
|
||||
use App\Models\User;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AssetCheckinTest extends TestCase
|
||||
{
|
||||
use InteractsWithSettings;
|
||||
|
||||
public function testLastCheckInFieldIsSetOnCheckin()
|
||||
{
|
||||
$admin = User::factory()->superuser()->create();
|
||||
$asset = Asset::factory()->create(['last_checkin' => null]);
|
||||
|
||||
$asset->checkOut(User::factory()->create(), $admin, now());
|
||||
|
||||
$this->actingAsForApi($admin)
|
||||
->postJson(route('api.asset.checkin', $asset))
|
||||
->assertOk();
|
||||
|
||||
$this->assertNotNull(
|
||||
$asset->fresh()->last_checkin,
|
||||
'last_checkin field should be set on checkin'
|
||||
);
|
||||
}
|
||||
}
|
32
tests/Feature/Assets/AssetCheckinTest.php
Normal file
32
tests/Feature/Assets/AssetCheckinTest.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Assets;
|
||||
|
||||
use App\Models\Asset;
|
||||
use App\Models\User;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AssetCheckinTest extends TestCase
|
||||
{
|
||||
use InteractsWithSettings;
|
||||
|
||||
public function testLastCheckInFieldIsSetOnCheckin()
|
||||
{
|
||||
$admin = User::factory()->superuser()->create();
|
||||
$asset = Asset::factory()->create(['last_checkin' => null]);
|
||||
|
||||
$asset->checkOut(User::factory()->create(), $admin, now());
|
||||
|
||||
$this->actingAs($admin)
|
||||
->post(route('hardware.checkin.store', [
|
||||
'assetId' => $asset->id,
|
||||
]))
|
||||
->assertRedirect();
|
||||
|
||||
$this->assertNotNull(
|
||||
$asset->fresh()->last_checkin,
|
||||
'last_checkin field should be set on checkin'
|
||||
);
|
||||
}
|
||||
}
|
|
@ -107,4 +107,29 @@ class CustomReportTest extends TestCase
|
|||
->assertDontSeeTextInStreamedResponse('Asset A')
|
||||
->assertSeeTextInStreamedResponse('Asset B');
|
||||
}
|
||||
|
||||
public function testCanLimitAssetsByLastCheckIn()
|
||||
{
|
||||
Asset::factory()->create(['name' => 'Asset A', 'last_checkin' => '2023-08-01']);
|
||||
Asset::factory()->create(['name' => 'Asset B', 'last_checkin' => '2023-08-02']);
|
||||
Asset::factory()->create(['name' => 'Asset C', 'last_checkin' => '2023-08-03']);
|
||||
Asset::factory()->create(['name' => 'Asset D', 'last_checkin' => '2023-08-04']);
|
||||
Asset::factory()->create(['name' => 'Asset E', 'last_checkin' => '2023-08-05']);
|
||||
|
||||
$this->actingAs(User::factory()->canViewReports()->create())
|
||||
->post('reports/custom', [
|
||||
'asset_name' => '1',
|
||||
'asset_tag' => '1',
|
||||
'serial' => '1',
|
||||
'checkin_date' => '1',
|
||||
'checkin_date_start' => '2023-08-02',
|
||||
'checkin_date_end' => '2023-08-04',
|
||||
])->assertOk()
|
||||
->assertHeader('content-type', 'text/csv; charset=UTF-8')
|
||||
->assertDontSeeTextInStreamedResponse('Asset A')
|
||||
->assertSeeTextInStreamedResponse('Asset B')
|
||||
->assertSeeTextInStreamedResponse('Asset C')
|
||||
->assertSeeTextInStreamedResponse('Asset D')
|
||||
->assertDontSeeTextInStreamedResponse('Asset E');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue