Skip to content

Commit

Permalink
Unaccepted Assets Report Actions (send reminder, delete) added
Browse files Browse the repository at this point in the history
Unaccepted Assets Export fixed
  • Loading branch information
dampfklon committed Jul 16, 2021
1 parent 5f842d0 commit e1c4eb7
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 21 deletions.
95 changes: 83 additions & 12 deletions app/Http/Controllers/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
use App\Models\Depreciation;
use App\Models\License;
use App\Models\Setting;
use App\Notifications\CheckoutAssetNotification;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\View;
use Input;
Expand Down Expand Up @@ -929,6 +931,7 @@ public function exportAssetMaintenancesReport()
* getAssetAcceptanceReport
*
* @return mixed
* @throws \Illuminate\Auth\Access\AuthorizationException
* @author Vincent Sposato <[email protected]>
* @version v1.0
*/
Expand All @@ -939,20 +942,78 @@ public function getAssetAcceptanceReport()
/**
* Get all assets with pending checkout acceptances
*/

$acceptances = CheckoutAcceptance::pending()->get();
$acceptances = CheckoutAcceptance::pending()->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model'])->get();

$assetsForReport = $acceptances
->filter(function($acceptance) {
return $acceptance->checkoutable_type == 'App\Models\Asset';
})
->map(function($acceptance) {
return $acceptance->checkoutable;
return ['assetItem' => $acceptance->checkoutable, 'acceptance' => $acceptance];
});

return view('reports/unaccepted_assets', compact('assetsForReport'));
}

/**
* sentAssetAcceptanceReminder
*
* @param integer|null $acceptanceId
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
* @version v1.0
*/
public function sentAssetAcceptanceReminder($acceptanceId = null)
{
$this->authorize('reports.view');

if (!$acceptance = CheckoutAcceptance::pending()->find($acceptanceId)) {
// Redirect to the unaccepted assets report page with error
return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data'));
}
$assetItem = $acceptance->checkoutable;

$logItem = $assetItem->checkouts()->where('created_at', '=', $acceptance->created_at)->get()[0];

if(!$assetItem->assignedTo->locale){
Notification::locale(Setting::getSettings()->locale)->send(
$assetItem->assignedTo,
new CheckoutAssetNotification($assetItem, $assetItem->assignedTo, $logItem->user, $acceptance, $logItem->note)
);
} else {
Notification::send(
$assetItem->assignedTo,
new CheckoutAssetNotification($assetItem, $assetItem->assignedTo, $logItem->user, $acceptance, $logItem->note)
);
}

return redirect()->route('reports/unaccepted_assets')->with('success', trans('admin/reports/general.reminder_sent'));
}

/**
* sentAssetAcceptanceReminder
*
* @param integer|null $acceptanceId
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
* @version v1.0
*/
public function deleteAssetAcceptance($acceptanceId = null)
{
$this->authorize('reports.view');

if (!$acceptance = CheckoutAcceptance::pending()->find($acceptanceId)) {
// Redirect to the unaccepted assets report page with error
return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data'));
}

if($acceptance->delete()) {
return redirect()->route('reports/unaccepted_assets')->with('success', trans('admin/reports/general.acceptance_deleted'));
} else {
return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.deletion_failed'));
}
}

/**
* exportAssetAcceptanceReport
*
Expand All @@ -963,9 +1024,19 @@ public function getAssetAcceptanceReport()
public function exportAssetAcceptanceReport()
{
$this->authorize('reports.view');
// Grab all the improvements
$assetsForReport = Actionlog::whereIn('id', $this->getAssetsNotAcceptedYet())
->get();

/**
* Get all assets with pending checkout acceptances
*/
$acceptances = CheckoutAcceptance::pending()->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model'])->get();

$assetsForReport = $acceptances
->filter(function($acceptance) {
return $acceptance->checkoutable_type == 'App\Models\Asset';
})
->map(function($acceptance) {
return ['assetItem' => $acceptance->checkoutable, 'acceptance' => $acceptance];
});

$rows = [ ];

Expand All @@ -980,13 +1051,13 @@ public function exportAssetAcceptanceReport()
$header = array_map('trim', $header);
$rows[] = implode($header, ',');

foreach ($assetsForReport as $assetItem) {
foreach ($assetsForReport as $item) {
$row = [ ];
$row[] = str_replace(',', '', e($assetItem->assetlog->model->category->name));
$row[] = str_replace(',', '', e($assetItem->assetlog->model->name));
$row[] = str_replace(',', '', e($assetItem->assetlog->present()->name()));
$row[] = str_replace(',', '', e($assetItem->assetlog->asset_tag));
$row[] = str_replace(',', '', e($assetItem->assetlog->assignedTo->present()->name()));
$row[] = str_replace(',', '', e($item['assetItem']->model->category->name));
$row[] = str_replace(',', '', e($item['assetItem']->model->name));
$row[] = str_replace(',', '', e($item['assetItem']->name));
$row[] = str_replace(',', '', e($item['assetItem']->asset_tag));
$row[] = str_replace(',', '', e(($item['acceptance']->assignedTo) ? $item['acceptance']->assignedTo->present()->name() : trans('admin/reports/general.deleted_user')));
$rows[] = implode($row, ',');
}

Expand Down
7 changes: 6 additions & 1 deletion resources/lang/en/admin/reports/general.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

return array(
'info' => 'Select the options you want for your asset report.'
'info' => 'Select the options you want for your asset report.',
'deleted_user' => 'Deleted user',
'send_reminder' => 'Send reminder',
'reminder_sent' => 'Reminder sent',
'acceptance_deleted' => 'Acceptance request deleted',
'acceptance_request' => 'Acceptance request'
);
1 change: 1 addition & 0 deletions resources/lang/en/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
'delete_confirm' => 'Are you sure you wish to delete :item?',
'deleted' => 'Deleted',
'delete_seats' => 'Deleted Seats',
'deletion_failed' => 'Deletion failed',
'departments' => 'Departments',
'department' => 'Department',
'deployed' => 'Deployed',
Expand Down
21 changes: 13 additions & 8 deletions resources/views/reports/unaccepted_assets.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,24 @@ class="table table-striped snipe-table"
<th class="col-sm-1">{{ trans('admin/hardware/form.name') }}</th>
<th class="col-sm-1">{{ trans('admin/hardware/table.asset_tag') }}</th>
<th class="col-sm-1">{{ trans('admin/hardware/table.checkoutto') }}</th>
<th class="col-md-1"><span class="line"></span>{{ trans('table.actions') }}</th>
</tr>
</thead>
<tbody>
@if ($assetsForReport)
@foreach ($assetsForReport as $assetItem)
@if ($assetItem)
@foreach ($assetsForReport as $item)
@if ($item['assetItem'])
<tr>
<td>{{ ($assetItem->company) ? $assetItem->company->name : '' }}</td>
<td>{{ $assetItem->model->category->name }}</td>
<td>{{ $assetItem->model->name }}</td>
<td>{!! $assetItem->present()->nameUrl() !!}</td>
<td>{{ $assetItem->asset_tag }}</td>
<td>{!! ($assetItem->assignedTo) ? $assetItem->assignedTo->present()->nameUrl() : 'Deleted user' !!}</td>
<td>{{ ($item['assetItem']->company) ? $assetItem->company->name : '' }}</td>
<td>{!! $item['assetItem']->model->category->present()->nameUrl() !!}</td>
<td>{!! $item['assetItem']->present()->modelUrl() !!}</td>
<td>{!! $item['assetItem']->present()->nameUrl() !!}</td>
<td>{{ $item['assetItem']->asset_tag }}</td>
<td>{!! ($item['acceptance']->assignedTo) ? $item['acceptance']->assignedTo->present()->nameUrl() : trans('admin/reports/general.deleted_user') !!}</td>
<td>
@if ($item['acceptance']->assignedTo)<a href="{{ route('reports/unaccepted_assets_sent_reminder', ['acceptanceId' => $item['acceptance']->id]) }}" class="btn btn-sm bg-purple" data-tooltip="true">{{ trans('admin/reports/general.send_reminder') }}</a>@endif
<a href="{{ route('reports/unaccepted_assets_delete', ['acceptanceId' => $item['acceptance']->id]) }}" class="btn btn-sm btn-danger delete-asset" data-tooltip="true" data-toggle="modal" data-content="{{ trans('general.delete_confirm', ['item' =>trans('admin/reports/general.acceptance_request')]) }}" data-title="{{ trans('general.delete') }}" onClick="return false;"><i class="fa fa-trash"></i></a>
</td>
</tr>
@endif
@endforeach
Expand Down
8 changes: 8 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,14 @@
'reports/unaccepted_assets',
[ 'as' => 'reports/unaccepted_assets', 'uses' => 'ReportsController@getAssetAcceptanceReport' ]
);
Route::get(
'reports/unaccepted_assets/{acceptanceId}/sent_reminder',
[ 'as' => 'reports/unaccepted_assets_sent_reminder', 'uses' => 'ReportsController@sentAssetAcceptanceReminder' ]
);
Route::delete(
'reports/unaccepted_assets/{acceptanceId}/delete',
[ 'as' => 'reports/unaccepted_assets_delete', 'uses' => 'ReportsController@deleteAssetAcceptance' ]
);
Route::get(
'reports/export/unaccepted_assets',
[ 'as' => 'reports/export/unaccepted_assets', 'uses' => 'ReportsController@exportAssetAcceptanceReport' ]
Expand Down

0 comments on commit e1c4eb7

Please sign in to comment.