-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unaccepted Assets Report Actions (send reminder, delete) added
Unaccepted Assets Export fixed
- Loading branch information
Showing
5 changed files
with
111 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -929,6 +931,7 @@ public function exportAssetMaintenancesReport() | |
* getAssetAcceptanceReport | ||
* | ||
* @return mixed | ||
* @throws \Illuminate\Auth\Access\AuthorizationException | ||
* @author Vincent Sposato <[email protected]> | ||
* @version v1.0 | ||
*/ | ||
|
@@ -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 | ||
* | ||
|
@@ -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 = [ ]; | ||
|
||
|
@@ -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, ','); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters