Skip to content

Commit 13d3b10

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 4bdfd0e + 7062962 commit 13d3b10

File tree

12 files changed

+146
-30
lines changed

12 files changed

+146
-30
lines changed

app/Http/Controllers/Api/LicensesController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public function index(Request $request) : JsonResponse | array
2626

2727
$licenses = License::with('company', 'manufacturer', 'supplier','category', 'adminuser')->withCount('freeSeats as free_seats_count');
2828

29+
if ($request->input('status')=='inactive') {
30+
$licenses->ExpiredLicenses();
31+
} else {
32+
$licenses->ActiveLicenses();
33+
}
34+
2935
if ($request->filled('company_id')) {
3036
$licenses->where('licenses.company_id', '=', $request->input('company_id'));
3137
}
@@ -94,6 +100,8 @@ public function index(Request $request) : JsonResponse | array
94100
$licenses->onlyTrashed();
95101
}
96102

103+
104+
97105
// Make sure the offset and limit are actually integers and do not exceed system limits
98106
$offset = ($request->input('offset') > $licenses->count()) ? $licenses->count() : app('api_offset_value');
99107
$limit = app('api_limit_value');

app/Http/Controllers/Licenses/LicenseCheckoutController.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class LicenseCheckoutController extends Controller
2525
* @author [A. Gianotto] [<[email protected]>]
2626
* @since [v1.0]
2727
* @param $id
28-
* @return \Illuminate\Contracts\View\View
28+
* @return \Illuminate\Contracts\View\View |\Illuminate\Http\RedirectResponse
2929
* @throws \Illuminate\Auth\Access\AuthorizationException
3030
*/
3131
public function create(License $license)
@@ -39,6 +39,11 @@ public function create(License $license)
3939
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.checkout.not_enough_seats'));
4040
}
4141

42+
// Make sure the license is expired or terminated
43+
if ($license->isInactive()) {
44+
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.checkout.license_is_inactive'));
45+
}
46+
4247
// We don't currently allow checking out licenses to locations, so we'll reset that to user if needed
4348
if (session()->get('checkout_to_type') == 'location') {
4449
session()->put(['checkout_to_type' => 'user']);
@@ -70,8 +75,19 @@ public function store(LicenseCheckoutRequest $request, $licenseId, $seatId = nul
7075
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
7176
}
7277

78+
7379
$this->authorize('checkout', $license);
7480

81+
// Make sure there is at least one available to checkout
82+
if ($license->availCount()->count() < 1) {
83+
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.checkout.not_enough_seats'));
84+
}
85+
86+
// Make sure the license is expired or terminated
87+
if ($license->isInactive()) {
88+
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.checkout.license_is_inactive'));
89+
}
90+
7591
$licenseSeat = $this->findLicenseSeatToCheckout($license, $seatId);
7692
$licenseSeat->created_by = auth()->id();
7793
$licenseSeat->notes = $request->input('notes');
@@ -114,6 +130,7 @@ protected function findLicenseSeatToCheckout($license, $seatId)
114130
throw new \Illuminate\Http\Exceptions\HttpResponseException(redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.checkout.not_enough_seats')));
115131
}
116132

133+
117134
if (! $licenseSeat->license->is($license)) {
118135
throw new \Illuminate\Http\Exceptions\HttpResponseException(redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.checkout.mismatch')));
119136
}

app/Http/Transformers/LicensesTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public function transformLicense(License $license)
3131
'purchase_order' => ($license->purchase_order) ? e($license->purchase_order) : null,
3232
'purchase_date' => Helper::getFormattedDateObject($license->purchase_date, 'date'),
3333
'termination_date' => Helper::getFormattedDateObject($license->termination_date, 'date'),
34+
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),
3435
'depreciation' => ($license->depreciation) ? ['id' => (int) $license->depreciation->id,'name'=> e($license->depreciation->name)] : null,
3536
'purchase_cost' => Helper::formatCurrencyOutput($license->purchase_cost),
3637
'purchase_cost_numeric' => $license->purchase_cost,
3738
'notes' => Helper::parseEscapedMarkedownInline($license->notes),
38-
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),
3939
'seats' => (int) $license->seats,
4040
'free_seats_count' => (int) $license->free_seats_count - License::unReassignableCount($license),
4141
'remaining' => (int) $license->free_seats_count,

app/Models/License.php

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,36 @@ public function setTerminationDateAttribute($value)
299299
}
300300

301301
public function isInactive(): bool
302-
{
303-
$day = now()->startOfDay();
302+
{
303+
$day = now()->startOfDay();
304304

305-
$expired = $this->expiration_date && $this->asDateTime($this->expiration_date)->startofDay()->lessThanOrEqualTo($day);
305+
$expired = $this->expiration_date && $this->asDateTime($this->expiration_date)->startofDay()->lessThanOrEqualTo($day);
306306

307-
$terminated = $this->termination_date && $this->asDateTime($this->termination_date)->startofDay()->lessThanOrEqualTo($day);
307+
$terminated = $this->termination_date && $this->asDateTime($this->termination_date)->startofDay()->lessThanOrEqualTo($day);
308308

309309

310-
return $expired || $terminated;
311-
}
310+
return $this->isExpired() || $this->isTerminated();
311+
}
312+
313+
public function isExpired(): bool
314+
{
315+
$day = now()->startOfDay();
316+
317+
$expired = $this->expiration_date && $this->asDateTime($this->expiration_date)->startofDay()->lessThanOrEqualTo($day);
318+
319+
return $expired;
320+
}
321+
322+
public function isTerminated(): bool
323+
{
324+
$day = now()->startOfDay();
325+
326+
$terminated = $this->termination_date && $this->asDateTime($this->termination_date)->startofDay()->lessThanOrEqualTo($day);
327+
328+
329+
return $terminated;
330+
}
331+
312332
/**
313333
* Sets free_seat_count attribute
314334
*
@@ -750,6 +770,38 @@ public static function getExpiringLicenses($days = 60)
750770
->get();
751771
}
752772

773+
public function scopeActiveLicenses($query)
774+
{
775+
776+
return $query->whereNull('deleted_at')
777+
778+
// The termination date is null or within range
779+
->where(function ($query) {
780+
$query->whereNull('termination_date')
781+
->orWhereDate('termination_date', '>', [Carbon::now()]);
782+
})
783+
->where(function ($query) {
784+
$query->whereNull('expiration_date')
785+
->orWhereDate('expiration_date', '>', [Carbon::now()]);
786+
});
787+
}
788+
789+
public function scopeExpiredLicenses($query)
790+
{
791+
792+
return $query->whereNull('deleted_at')
793+
794+
// The termination date is null or within range
795+
->where(function ($query) {
796+
$query->whereNull('termination_date')
797+
->orWhereDate('termination_date', '<=', [Carbon::now()]);
798+
})
799+
->orWhere(function ($query) {
800+
$query->whereNull('expiration_date')
801+
->orWhereDate('expiration_date', '<=', [Carbon::now()]);
802+
});
803+
}
804+
753805
/**
754806
* Query builder scope to order on manufacturer
755807
*

app/Providers/BreadcrumbsServiceProvider.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,19 @@ public function boot()
349349
/**
350350
* Licenses Breadcrumbs
351351
*/
352-
Breadcrumbs::for('licenses.index', fn (Trail $trail) =>
353-
$trail->parent('home', route('home'))
354-
->push(trans('general.licenses'), route('licenses.index'))
355-
);
352+
if ((request()->is('licenses*')) && (request()->status=='inactive')) {
353+
Breadcrumbs::for('licenses.index', fn (Trail $trail) =>
354+
$trail->parent('home', route('home'))
355+
->push(trans('general.licenses'), route('licenses.index'))
356+
->push(trans('general.show_inactive'), route('licenses.index'))
357+
);
358+
} else {
359+
Breadcrumbs::for('licenses.index', fn (Trail $trail) =>
360+
$trail->parent('home', route('home'))
361+
->push(trans('general.licenses'), route('licenses.index'))
362+
);
363+
}
364+
356365

357366
Breadcrumbs::for('licenses.create', fn (Trail $trail) =>
358367
$trail->parent('licenses.index', route('licenses.index'))

database/factories/LicenseFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public function definition()
3333
'seats' => $this->faker->numberBetween(1, 10),
3434
'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'),
3535
'order_number' => $this->faker->numberBetween(1000000, 50000000),
36-
'expiration_date' => $this->faker->dateTimeBetween('now', '+3 years', date_default_timezone_get())->format('Y-m-d H:i:s'),
36+
'expiration_date' => null,
3737
'reassignable' => $this->faker->boolean(),
38-
'termination_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d H:i:s'),
38+
'termination_date' => null,
3939
'supplier_id' => Supplier::factory(),
4040
'category_id' => Category::factory(),
4141
];

resources/lang/en-US/general.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@
589589
'components' => ':count Component|:count Components',
590590
],
591591

592+
'show_inactive' => 'Expired or Terminated',
592593
'more_info' => 'More Info',
593594
'quickscan_bulk_help' => 'Checking this box will edit the asset record to reflect this new location. Leaving it unchecked will simply note the location in the audit log. Note that if this asset is checked out, it will not change the location of the person, asset or location it is checked out to.',
594595
'whoops' => 'Whoops!',

resources/views/licenses/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
id="licensesTable"
2828
data-buttons="licenseButtons"
2929
class="table table-striped snipe-table"
30-
data-url="{{ route('api.licenses.index') }}"
30+
data-url="{{ route('api.licenses.index', ['status' => e(request('status'))]) }}"
3131
data-export-options='{
3232
"fileName": "export-licenses-{{ date('Y-m-d') }}",
3333
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]

resources/views/licenses/view.blade.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@
249249
</strong>
250250
</div>
251251
<div class="col-md-9">
252+
@if ($license->isExpired())
253+
<span class="text-danger">
254+
<x-icon type="warning" class="text-warning" />
255+
</span>
256+
@endif
252257
{{ Helper::getFormattedDateObject($license->expiration_date, 'date', false) }}
253258
</div>
254259
</div>
@@ -262,6 +267,12 @@
262267
</strong>
263268
</div>
264269
<div class="col-md-9">
270+
@if ($license->isTerminated())
271+
<span class="text-danger">
272+
<x-icon type="warning" class="text-warning" />
273+
</span>
274+
@endif
275+
265276
{{ Helper::getFormattedDateObject($license->termination_date, 'date', false) }}
266277
</div>
267278
</div>
@@ -545,7 +556,7 @@ class="table table-striped snipe-table"
545556

546557
@can('checkout', $license)
547558

548-
@if ($license->availCount()->count() > 0)
559+
@if (($license->availCount()->count() > 0) && (!$license->isInactive()))
549560

550561
<a href="{{ route('licenses.checkout', $license->id) }}" class="btn bg-maroon btn-sm btn-social btn-block hidden-print" style="margin-bottom: 5px;">
551562
<x-icon type="checkout" />
@@ -558,17 +569,13 @@ class="table table-striped snipe-table"
558569
</a>
559570

560571
@else
561-
<span data-tooltip="true" title=" {{ trans('admin/licenses/general.bulk.checkout_all.disabled_tooltip') }}">
562-
<a href="#" class="btn bg-maroon btn-sm btn-social btn-block hidden-print disabled" style="margin-bottom: 5px;" data-tooltip="true" title="{{ trans('general.checkout') }}">
572+
<span data-tooltip="true" title="{{ ($license->availCount()->count() == 0) ? trans('admin/licenses/general.bulk.checkout_all.disabled_tooltip') : trans('admin/licenses/message.checkout.license_is_inactive') }}" class="btn bg-maroon btn-sm btn-social btn-block hidden-print disabled" style="margin-bottom: 5px;" data-tooltip="true" title="{{ trans('general.checkout') }}">
563573
<x-icon type="checkout" />
564574
{{ trans('general.checkout') }}
565-
</a>
566575
</span>
567-
<span data-tooltip="true" title=" {{ trans('admin/licenses/general.bulk.checkout_all.disabled_tooltip') }}">
568-
<a href="#" class="btn bg-maroon btn-sm btn-social btn-block hidden-print disabled" style="margin-bottom: 5px;" data-tooltip="true" title="{{ trans('general.checkout') }}">
576+
<span data-tooltip="true" title="{{ ($license->availCount()->count() == 0) ? trans('admin/licenses/general.bulk.checkout_all.disabled_tooltip') : trans('admin/licenses/message.checkout.license_is_inactive') }}" class="btn bg-maroon btn-sm btn-social btn-block hidden-print disabled" style="margin-bottom: 5px;" data-tooltip="true" title="{{ trans('general.checkout') }}">
569577
<x-icon type="checkout" />
570578
{{ trans('admin/licenses/general.bulk.checkout_all.button') }}
571-
</a>
572579
</span>
573580
@endif
574581
@endcan

resources/views/models/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
id="asssetModelsTable"
3737
data-buttons="modelButtons"
3838
class="table table-striped snipe-table"
39-
data-url="{{ route('api.models.index', ['status' => request('status')]) }}"
39+
data-url="{{ route('api.models.index', ['status' => e(request('status'))]) }}"
4040
data-export-options='{
4141
"fileName": "export-models-{{ date('Y-m-d') }}",
4242
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]

0 commit comments

Comments
 (0)