2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2016-08-15 19:57:34 -07:00
|
|
|
use App\Helpers\Helper;
|
2016-03-25 01:18:05 -07:00
|
|
|
use App\Models\Accessory;
|
|
|
|
use App\Models\Actionlog;
|
|
|
|
use App\Models\Asset;
|
|
|
|
use App\Models\AssetMaintenance;
|
2018-07-28 04:21:11 -07:00
|
|
|
use App\Models\CheckoutAcceptance;
|
2016-08-15 19:57:34 -07:00
|
|
|
use App\Models\CustomField;
|
2018-01-25 11:16:49 -08:00
|
|
|
use App\Models\Depreciation;
|
2016-08-15 19:57:34 -07:00
|
|
|
use App\Models\License;
|
|
|
|
use App\Models\Setting;
|
2021-05-03 12:06:12 -07:00
|
|
|
use App\Notifications\CheckoutAssetNotification;
|
2016-08-15 19:57:34 -07:00
|
|
|
use Carbon\Carbon;
|
2021-05-20 21:19:04 -07:00
|
|
|
use Illuminate\Auth\Access\AuthorizationException;
|
2019-03-13 20:12:03 -07:00
|
|
|
use Illuminate\Http\Request;
|
2021-05-03 12:06:12 -07:00
|
|
|
use Illuminate\Support\Facades\Notification;
|
2016-03-25 01:18:05 -07:00
|
|
|
use Illuminate\Support\Facades\Response;
|
|
|
|
use Illuminate\Support\Facades\View;
|
|
|
|
use Input;
|
|
|
|
use League\Csv\Reader;
|
2016-09-12 14:06:55 -07:00
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
2022-09-30 09:29:17 -07:00
|
|
|
use League\Csv\EscapeFormula;
|
2023-10-18 06:13:25 -07:00
|
|
|
use App\Http\Requests\CustomAssetReportRequest;
|
2022-09-30 11:47:27 -07:00
|
|
|
|
|
|
|
|
2016-04-07 13:21:09 -07:00
|
|
|
/**
|
|
|
|
* This controller handles all actions related to Reports for
|
|
|
|
* the Snipe-IT Asset Management application.
|
|
|
|
*
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
class ReportsController extends Controller
|
|
|
|
{
|
2018-07-12 18:28:02 -07:00
|
|
|
/**
|
|
|
|
* Checks for correct permissions
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function __construct()
|
|
|
|
{
|
2018-07-12 18:28:02 -07:00
|
|
|
parent::__construct();
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
/**
|
2016-09-28 22:57:19 -07:00
|
|
|
* Returns a view that displays the accessories report.
|
2016-04-07 13:39:35 -07:00
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return View
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getAccessoryReport()
|
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2023-01-24 17:35:44 -08:00
|
|
|
return view('reports/accessories');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-04-07 13:39:35 -07:00
|
|
|
* Exports the accessories to CSV
|
|
|
|
*
|
|
|
|
* @deprecated Server-side exports have been replaced by datatables export since v2.
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see ManufacturersController::getDatatable() method that generates the JSON response
|
|
|
|
* @since [v1.0]
|
2016-04-07 17:08:38 -07:00
|
|
|
* @return \Illuminate\Http\Response
|
2016-04-07 13:39:35 -07:00
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function exportAccessoryReport()
|
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2016-03-25 01:18:05 -07:00
|
|
|
$accessories = Accessory::orderBy('created_at', 'DESC')->get();
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$rows = [];
|
|
|
|
$header = [
|
2016-04-07 13:39:35 -07:00
|
|
|
trans('admin/accessories/table.title'),
|
|
|
|
trans('admin/accessories/general.accessory_category'),
|
|
|
|
trans('admin/accessories/general.total'),
|
2021-06-10 13:15:52 -07:00
|
|
|
trans('admin/accessories/general.remaining'),
|
|
|
|
];
|
2016-03-25 01:18:05 -07:00
|
|
|
$header = array_map('trim', $header);
|
2021-07-16 15:07:51 -07:00
|
|
|
$rows[] = implode(', ', $header);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
// Row per accessory
|
|
|
|
foreach ($accessories as $accessory) {
|
2021-06-10 13:15:52 -07:00
|
|
|
$row = [];
|
2016-03-25 15:24:12 -07:00
|
|
|
$row[] = e($accessory->accessory_name);
|
|
|
|
$row[] = e($accessory->accessory_category);
|
|
|
|
$row[] = e($accessory->total);
|
|
|
|
$row[] = e($accessory->remaining);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2021-07-16 15:07:51 -07:00
|
|
|
$rows[] = implode(',', $row);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2021-07-16 15:07:51 -07:00
|
|
|
$csv = implode("\n", $rows);
|
2016-03-25 01:18:05 -07:00
|
|
|
$response = Response::make($csv, 200);
|
|
|
|
$response->header('Content-Type', 'text/csv');
|
|
|
|
$response->header('Content-disposition', 'attachment;filename=report.csv');
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
2018-05-02 14:13:06 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
/**
|
2016-04-07 17:08:38 -07:00
|
|
|
* Show depreciation report for assets.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return View
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getDeprecationReport()
|
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2018-01-25 11:16:49 -08:00
|
|
|
$depreciations = Depreciation::get();
|
2021-09-15 13:49:53 -07:00
|
|
|
return view('reports/depreciation')->with('depreciations',$depreciations);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-04-07 17:08:38 -07:00
|
|
|
* Exports the depreciations to CSV
|
|
|
|
*
|
|
|
|
* @deprecated Server-side exports have been replaced by datatables export since v2.
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function exportDeprecationReport()
|
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2016-03-25 01:18:05 -07:00
|
|
|
// Grab all the assets
|
2016-12-29 06:31:16 -08:00
|
|
|
$assets = Asset::with('model', 'assignedTo', 'assetstatus', 'defaultLoc', 'assetlog')
|
2016-03-25 01:18:05 -07:00
|
|
|
->orderBy('created_at', 'DESC')->get();
|
|
|
|
|
|
|
|
$csv = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject());
|
|
|
|
$csv->setOutputBOM(Reader::BOM_UTF16_BE);
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$rows = [];
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
// Create the header row
|
|
|
|
$header = [
|
2016-04-07 13:39:35 -07:00
|
|
|
trans('admin/hardware/table.asset_tag'),
|
|
|
|
trans('admin/hardware/table.title'),
|
|
|
|
trans('admin/hardware/table.serial'),
|
|
|
|
trans('admin/hardware/table.checkoutto'),
|
|
|
|
trans('admin/hardware/table.location'),
|
|
|
|
trans('admin/hardware/table.purchase_date'),
|
|
|
|
trans('admin/hardware/table.purchase_cost'),
|
|
|
|
trans('admin/hardware/table.book_value'),
|
2021-06-10 13:15:52 -07:00
|
|
|
trans('admin/hardware/table.diff'),
|
2016-03-25 01:18:05 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
//we insert the CSV header
|
|
|
|
$csv->insertOne($header);
|
|
|
|
|
|
|
|
// Create a row per asset
|
|
|
|
foreach ($assets as $asset) {
|
2021-06-10 13:15:52 -07:00
|
|
|
$row = [];
|
2016-03-25 15:24:12 -07:00
|
|
|
$row[] = e($asset->asset_tag);
|
|
|
|
$row[] = e($asset->name);
|
|
|
|
$row[] = e($asset->serial);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-12-27 16:24:41 -08:00
|
|
|
if ($target = $asset->assignedTo) {
|
|
|
|
$row[] = e($target->present()->name());
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
|
|
|
$row[] = ''; // Empty string if unassigned
|
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
if (($asset->assigned_to > 0) && ($location = $asset->location)) {
|
2016-03-25 01:18:05 -07:00
|
|
|
if ($location->city) {
|
2021-06-10 13:15:52 -07:00
|
|
|
$row[] = e($location->city).', '.e($location->state);
|
2016-03-25 01:18:05 -07:00
|
|
|
} elseif ($location->name) {
|
2016-03-25 15:24:12 -07:00
|
|
|
$row[] = e($location->name);
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
|
|
|
$row[] = '';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$row[] = ''; // Empty string if location is not set
|
|
|
|
}
|
|
|
|
|
2017-10-28 02:58:38 -07:00
|
|
|
if ($asset->location) {
|
|
|
|
$currency = e($asset->location->currency);
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
2018-11-01 19:59:50 -07:00
|
|
|
$currency = e(Setting::getSettings()->default_currency);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$row[] = $asset->purchase_date;
|
2021-06-10 13:15:52 -07:00
|
|
|
$row[] = $currency.Helper::formatCurrencyOutput($asset->purchase_cost);
|
|
|
|
$row[] = $currency.Helper::formatCurrencyOutput($asset->getDepreciatedValue());
|
|
|
|
$row[] = $currency.Helper::formatCurrencyOutput(($asset->purchase_cost - $asset->getDepreciatedValue()));
|
2016-03-25 01:18:05 -07:00
|
|
|
$csv->insertOne($row);
|
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$csv->output('depreciation-report-'.date('Y-m-d').'.csv');
|
2016-03-25 01:18:05 -07:00
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
2017-08-25 10:04:19 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays audit report.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v4.0]
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
public function audit()
|
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-08-25 10:04:19 -07:00
|
|
|
return view('reports/audit');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
/**
|
2016-04-07 17:08:38 -07:00
|
|
|
* Displays activity report.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return View
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getActivityReport()
|
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-06-09 16:44:03 -07:00
|
|
|
return view('reports/activity');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2020-11-13 16:25:05 -08:00
|
|
|
/**
|
|
|
|
* Exports the activity report to CSV
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v5.0.7]
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function postActivityReport(Request $request)
|
|
|
|
{
|
|
|
|
ini_set('max_execution_time', 12000);
|
|
|
|
$this->authorize('reports.view');
|
|
|
|
|
|
|
|
\Debugbar::disable();
|
|
|
|
$response = new StreamedResponse(function () {
|
|
|
|
\Log::debug('Starting streamed response');
|
|
|
|
|
|
|
|
// Open output stream
|
|
|
|
$handle = fopen('php://output', 'w');
|
|
|
|
stream_set_timeout($handle, 2000);
|
|
|
|
|
|
|
|
$header = [
|
|
|
|
trans('general.date'),
|
|
|
|
trans('general.admin'),
|
|
|
|
trans('general.action'),
|
|
|
|
trans('general.type'),
|
|
|
|
trans('general.item'),
|
2023-10-31 02:43:47 -07:00
|
|
|
trans('general.license_serial'),
|
|
|
|
trans('general.model_name'),
|
|
|
|
trans('general.model_no'),
|
2020-11-13 16:25:05 -08:00
|
|
|
'To',
|
|
|
|
trans('general.notes'),
|
2023-12-15 02:45:22 -08:00
|
|
|
trans('admin/settings/general.login_ip'),
|
|
|
|
trans('admin/settings/general.login_user_agent'),
|
|
|
|
trans('general.action_source'),
|
2020-11-13 16:25:05 -08:00
|
|
|
'Changed',
|
|
|
|
|
|
|
|
];
|
2021-06-10 13:15:52 -07:00
|
|
|
$executionTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'];
|
2020-11-13 16:25:05 -08:00
|
|
|
\Log::debug('Starting headers: '.$executionTime);
|
|
|
|
fputcsv($handle, $header);
|
2021-06-10 13:15:52 -07:00
|
|
|
$executionTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'];
|
2020-11-13 16:25:05 -08:00
|
|
|
\Log::debug('Added headers: '.$executionTime);
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$actionlogs = Actionlog::with('item', 'user', 'target', 'location')
|
2020-11-13 16:25:05 -08:00
|
|
|
->orderBy('created_at', 'DESC')
|
2021-06-10 13:15:52 -07:00
|
|
|
->chunk(20, function ($actionlogs) use ($handle) {
|
|
|
|
$executionTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'];
|
2020-11-13 16:25:05 -08:00
|
|
|
\Log::debug('Walking results: '.$executionTime);
|
|
|
|
$count = 0;
|
|
|
|
|
|
|
|
foreach ($actionlogs as $actionlog) {
|
|
|
|
$count++;
|
|
|
|
$target_name = '';
|
|
|
|
|
|
|
|
if ($actionlog->target) {
|
2021-06-10 13:15:52 -07:00
|
|
|
if ($actionlog->targetType() == 'user') {
|
|
|
|
$target_name = $actionlog->target->getFullNameAttribute();
|
2020-11-13 16:25:05 -08:00
|
|
|
} else {
|
|
|
|
$target_name = $actionlog->target->getDisplayNameAttribute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-01 11:25:55 -07:00
|
|
|
if($actionlog->item){
|
|
|
|
$item_name = e($actionlog->item->getDisplayNameAttribute());
|
|
|
|
} else {
|
|
|
|
$item_name = '';
|
|
|
|
}
|
2020-11-13 16:25:05 -08:00
|
|
|
|
|
|
|
$row = [
|
|
|
|
$actionlog->created_at,
|
2023-03-01 12:23:13 -08:00
|
|
|
($actionlog->admin) ? e($actionlog->admin->getFullNameAttribute()) : '',
|
2020-11-13 16:25:05 -08:00
|
|
|
$actionlog->present()->actionType(),
|
|
|
|
e($actionlog->itemType()),
|
2022-05-01 11:25:55 -07:00
|
|
|
($actionlog->itemType() == 'user') ? $actionlog->filename : $item_name,
|
2024-02-09 12:53:33 -08:00
|
|
|
($actionlog->item) ? $actionlog->item->serial : null,
|
2024-02-19 07:34:57 -08:00
|
|
|
(($actionlog->item) && ($actionlog->item->model)) ? htmlspecialchars($actionlog->item->model->name, ENT_NOQUOTES) : null,
|
|
|
|
(($actionlog->item) && ($actionlog->item->model)) ? $actionlog->item->model->model_number : null,
|
2020-11-13 16:25:05 -08:00
|
|
|
$target_name,
|
2021-06-10 13:15:52 -07:00
|
|
|
($actionlog->note) ? e($actionlog->note) : '',
|
2020-11-13 16:25:05 -08:00
|
|
|
$actionlog->log_meta,
|
2023-12-15 02:45:22 -08:00
|
|
|
$actionlog->remote_ip,
|
|
|
|
$actionlog->user_agent,
|
|
|
|
$actionlog->action_source,
|
2020-11-13 16:25:05 -08:00
|
|
|
];
|
|
|
|
fputcsv($handle, $row);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Close the output stream
|
|
|
|
fclose($handle);
|
2021-06-10 13:15:52 -07:00
|
|
|
$executionTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'];
|
|
|
|
\Log::debug('-- SCRIPT COMPLETED IN '.$executionTime);
|
2020-11-13 16:25:05 -08:00
|
|
|
}, 200, [
|
|
|
|
'Content-Type' => 'text/csv',
|
2021-06-10 13:15:52 -07:00
|
|
|
'Content-Disposition' => 'attachment; filename="activity-report-'.date('Y-m-d-his').'.csv"',
|
2020-11-13 16:25:05 -08:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-28 22:57:19 -07:00
|
|
|
/**
|
|
|
|
* Displays license report
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return View
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getLicenseReport()
|
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2016-09-28 22:57:19 -07:00
|
|
|
$licenses = License::with('depreciation')->orderBy('created_at', 'DESC')
|
2016-03-25 01:18:05 -07:00
|
|
|
->with('company')
|
|
|
|
->get();
|
|
|
|
|
2017-06-09 16:44:03 -07:00
|
|
|
return view('reports/licenses', compact('licenses'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-04-07 17:08:38 -07:00
|
|
|
* Exports the licenses to CSV
|
|
|
|
*
|
|
|
|
* @deprecated Server-side exports have been replaced by datatables export since v2.
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function exportLicenseReport()
|
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2016-03-25 01:18:05 -07:00
|
|
|
$licenses = License::orderBy('created_at', 'DESC')->get();
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$rows = [];
|
|
|
|
$header = [
|
2016-04-07 13:39:35 -07:00
|
|
|
trans('admin/licenses/table.title'),
|
|
|
|
trans('admin/licenses/table.serial'),
|
|
|
|
trans('admin/licenses/form.seats'),
|
|
|
|
trans('admin/licenses/form.remaining_seats'),
|
|
|
|
trans('admin/licenses/form.expiration'),
|
2016-11-29 08:46:33 -08:00
|
|
|
trans('general.purchase_date'),
|
|
|
|
trans('general.depreciation'),
|
2021-06-10 13:15:52 -07:00
|
|
|
trans('general.purchase_cost'),
|
2016-03-25 01:18:05 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
$header = array_map('trim', $header);
|
2021-07-16 15:07:51 -07:00
|
|
|
$rows[] = implode(', ', $header);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
// Row per license
|
|
|
|
foreach ($licenses as $license) {
|
2021-06-10 13:15:52 -07:00
|
|
|
$row = [];
|
2016-03-25 15:24:12 -07:00
|
|
|
$row[] = e($license->name);
|
|
|
|
$row[] = e($license->serial);
|
|
|
|
$row[] = e($license->seats);
|
2016-03-25 01:18:05 -07:00
|
|
|
$row[] = $license->remaincount();
|
|
|
|
$row[] = $license->expiration_date;
|
|
|
|
$row[] = $license->purchase_date;
|
2021-06-10 13:15:52 -07:00
|
|
|
$row[] = ($license->depreciation != '') ? '' : e($license->depreciation->name);
|
|
|
|
$row[] = '"'.Helper::formatCurrencyOutput($license->purchase_cost).'"';
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2021-07-16 15:07:51 -07:00
|
|
|
$rows[] = implode(',', $row);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2021-07-16 15:07:51 -07:00
|
|
|
|
|
|
|
$csv = implode("\n", $rows);
|
2016-03-25 01:18:05 -07:00
|
|
|
$response = Response::make($csv, 200);
|
|
|
|
$response->header('Content-Type', 'text/csv');
|
|
|
|
$response->header('Content-disposition', 'attachment;filename=report.csv');
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
2016-04-07 17:08:38 -07:00
|
|
|
/**
|
|
|
|
* Returns a form that allows the user to generate a custom CSV report.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see ReportsController::postCustomReport() method that generates the CSV
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getCustomReport()
|
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2016-08-02 15:04:10 -07:00
|
|
|
$customfields = CustomField::get();
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-06-09 16:44:03 -07:00
|
|
|
return view('reports/custom')->with('customfields', $customfields);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-04-07 17:08:38 -07:00
|
|
|
/**
|
2016-09-27 07:19:52 -07:00
|
|
|
* Exports the custom report to CSV
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see ReportsController::getCustomReport() method that generates form view
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2023-10-18 06:13:25 -07:00
|
|
|
public function postCustom(CustomAssetReportRequest $request)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2021-04-05 21:47:57 -07:00
|
|
|
ini_set('max_execution_time', env('REPORT_TIME_LIMIT', 12000)); //12000 seconds = 200 minutes
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2019-08-15 06:14:25 -07:00
|
|
|
|
2023-10-18 06:13:25 -07:00
|
|
|
|
2017-12-01 14:37:11 -08:00
|
|
|
\Debugbar::disable();
|
|
|
|
$customfields = CustomField::get();
|
|
|
|
$response = new StreamedResponse(function () use ($customfields, $request) {
|
2019-08-15 06:14:25 -07:00
|
|
|
\Log::debug('Starting streamed response');
|
2022-09-30 09:48:43 -07:00
|
|
|
\Log::debug('CSV escaping is set to: '.config('app.escape_formulas'));
|
2019-08-15 06:14:25 -07:00
|
|
|
|
2017-12-01 14:37:11 -08:00
|
|
|
// Open output stream
|
|
|
|
$handle = fopen('php://output', 'w');
|
2019-08-15 06:14:25 -07:00
|
|
|
stream_set_timeout($handle, 2000);
|
2017-12-01 14:37:11 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('use_bom')) {
|
2021-06-10 13:15:52 -07:00
|
|
|
fprintf($handle, chr(0xEF).chr(0xBB).chr(0xBF));
|
2016-08-02 15:04:10 -07:00
|
|
|
}
|
|
|
|
|
2017-12-01 14:37:11 -08:00
|
|
|
$header = [];
|
2016-08-02 15:04:10 -07:00
|
|
|
|
2022-08-10 13:51:47 -07:00
|
|
|
if ($request->filled('id')) {
|
|
|
|
$header[] = trans('general.id');
|
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('company')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('general.company');
|
2016-09-20 00:49:08 -07:00
|
|
|
}
|
2016-09-27 07:19:52 -07:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('asset_name')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('admin/hardware/form.name');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('asset_tag')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('admin/hardware/table.asset_tag');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('model')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('admin/hardware/form.model');
|
|
|
|
$header[] = trans('general.model_no');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('category')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('general.category');
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('manufacturer')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('admin/hardware/form.manufacturer');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('serial')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('admin/hardware/table.serial');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('purchase_date')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('admin/hardware/table.purchase_date');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
if (($request->filled('purchase_cost')) || ($request->filled('depreciation'))) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('admin/hardware/table.purchase_cost');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('eol')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('admin/hardware/table.eol');
|
2016-10-27 14:20:55 -07:00
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('order')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('admin/hardware/form.order');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('supplier')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('general.supplier');
|
2017-12-01 14:37:11 -08:00
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('location')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('admin/hardware/table.location');
|
2017-12-01 14:37:11 -08:00
|
|
|
}
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('location_address')) {
|
2018-03-26 15:59:09 -07:00
|
|
|
$header[] = trans('general.address');
|
|
|
|
$header[] = trans('general.address');
|
|
|
|
$header[] = trans('general.city');
|
|
|
|
$header[] = trans('general.state');
|
|
|
|
$header[] = trans('general.country');
|
|
|
|
$header[] = trans('general.zip');
|
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('rtd_location')) {
|
2018-04-05 17:33:25 -07:00
|
|
|
$header[] = trans('admin/hardware/form.default_location');
|
|
|
|
}
|
2018-05-08 07:34:14 -07:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('rtd_location_address')) {
|
2018-04-05 17:33:25 -07:00
|
|
|
$header[] = trans('general.address');
|
|
|
|
$header[] = trans('general.address');
|
|
|
|
$header[] = trans('general.city');
|
|
|
|
$header[] = trans('general.state');
|
|
|
|
$header[] = trans('general.country');
|
|
|
|
$header[] = trans('general.zip');
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('assigned_to')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('admin/hardware/table.checkoutto');
|
|
|
|
$header[] = trans('general.type');
|
2017-12-01 14:37:11 -08:00
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('username')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$header[] = 'Username';
|
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('employee_num')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$header[] = 'Employee No.';
|
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('manager')) {
|
2018-06-27 00:45:09 -07:00
|
|
|
$header[] = trans('admin/users/table.manager');
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('department')) {
|
2018-04-16 20:10:38 -07:00
|
|
|
$header[] = trans('general.department');
|
|
|
|
}
|
|
|
|
|
2021-12-13 18:27:23 -08:00
|
|
|
if ($request->filled('title')) {
|
|
|
|
$header[] = trans('admin/users/table.title');
|
|
|
|
}
|
|
|
|
|
2023-10-26 17:10:53 -07:00
|
|
|
if ($request->filled('phone')) {
|
|
|
|
$header[] = trans('admin/users/table.phone');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->filled('user_address')) {
|
2023-10-31 19:38:52 -07:00
|
|
|
$header[] = trans('admin/reports/general.custom_export.user_address');
|
2023-10-26 17:10:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->filled('user_city')) {
|
2023-10-31 19:38:52 -07:00
|
|
|
$header[] = trans('admin/reports/general.custom_export.user_city');
|
2023-10-26 17:10:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->filled('user_state')) {
|
2023-10-31 19:38:52 -07:00
|
|
|
$header[] = trans('admin/reports/general.custom_export.user_state');
|
2023-10-26 17:10:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->filled('user_country')) {
|
2023-10-31 19:38:52 -07:00
|
|
|
$header[] = trans('admin/reports/general.custom_export.user_country');
|
2023-10-26 17:10:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->filled('user_zip')) {
|
2023-10-31 19:38:52 -07:00
|
|
|
$header[] = trans('admin/reports/general.custom_export.user_zip');
|
2023-10-26 17:10:53 -07:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('status')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('general.status');
|
2017-12-01 14:37:11 -08:00
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('warranty')) {
|
2023-06-22 14:12:40 -07:00
|
|
|
$header[] = trans('admin/hardware/form.warranty');
|
|
|
|
$header[] = trans('admin/hardware/form.warranty_expires');
|
2017-12-01 14:37:11 -08:00
|
|
|
}
|
2023-06-22 14:00:42 -07:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('depreciation')) {
|
2023-06-22 14:00:42 -07:00
|
|
|
$header[] = trans('admin/hardware/table.book_value');
|
|
|
|
$header[] = trans('admin/hardware/table.diff');
|
|
|
|
$header[] = trans('admin/hardware/form.fully_depreciated');
|
2017-12-01 14:37:11 -08:00
|
|
|
}
|
2017-12-01 16:51:38 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('checkout_date')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('admin/hardware/table.checkout_date');
|
|
|
|
}
|
|
|
|
|
2023-08-21 13:44:49 -07:00
|
|
|
if ($request->filled('checkin_date')) {
|
|
|
|
$header[] = trans('admin/hardware/table.last_checkin_date');
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('expected_checkin')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$header[] = trans('admin/hardware/form.expected_checkin');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-09-29 11:37:38 -07:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('created_at')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('general.created_at');
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('updated_at')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$header[] = trans('general.updated_at');
|
|
|
|
}
|
|
|
|
|
2022-08-02 19:58:17 -07:00
|
|
|
if ($request->filled('deleted_at')) {
|
|
|
|
$header[] = trans('general.deleted');
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('last_audit_date')) {
|
2017-12-12 03:03:43 -08:00
|
|
|
$header[] = trans('general.last_audit');
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('next_audit_date')) {
|
2017-12-12 03:03:43 -08:00
|
|
|
$header[] = trans('general.next_audit_date');
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('notes')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$header[] = trans('general.notes');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-09-29 11:37:38 -07:00
|
|
|
|
2022-08-10 13:57:42 -07:00
|
|
|
if ($request->filled('url')) {
|
2024-02-05 11:09:16 -08:00
|
|
|
$header[] = trans('general.url');
|
2022-08-10 13:51:47 -07:00
|
|
|
}
|
|
|
|
|
2016-09-29 11:37:38 -07:00
|
|
|
|
2017-12-01 14:37:11 -08:00
|
|
|
foreach ($customfields as $customfield) {
|
2021-09-28 16:45:47 -07:00
|
|
|
if ($request->input($customfield->db_column_name()) == '1') {
|
2017-12-01 14:37:11 -08:00
|
|
|
$header[] = $customfield->name;
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
}
|
2016-08-02 15:04:10 -07:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$executionTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'];
|
2019-08-15 06:14:25 -07:00
|
|
|
\Log::debug('Starting headers: '.$executionTime);
|
2017-12-01 14:37:11 -08:00
|
|
|
fputcsv($handle, $header);
|
2021-06-10 13:15:52 -07:00
|
|
|
$executionTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'];
|
2019-08-15 06:14:25 -07:00
|
|
|
\Log::debug('Added headers: '.$executionTime);
|
|
|
|
|
2023-08-08 17:22:15 -07:00
|
|
|
$assets = Asset::select('assets.*')->with(
|
2022-09-14 18:17:52 -07:00
|
|
|
'location', 'assetstatus', 'company', 'defaultLoc', 'assignedTo',
|
2021-06-10 13:15:52 -07:00
|
|
|
'model.category', 'model.manufacturer', 'supplier');
|
2017-12-01 14:37:11 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('by_location_id')) {
|
2023-05-10 14:45:31 -07:00
|
|
|
$assets->whereIn('assets.location_id', $request->input('by_location_id'));
|
2017-12-01 14:37:11 -08:00
|
|
|
}
|
2017-11-06 10:44:18 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('by_rtd_location_id')) {
|
2023-05-16 13:58:21 -07:00
|
|
|
$assets->whereIn('assets.rtd_location_id', $request->input('by_rtd_location_id'));
|
2018-05-08 07:34:14 -07:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('by_supplier_id')) {
|
2023-05-16 13:58:21 -07:00
|
|
|
$assets->whereIn('assets.supplier_id', $request->input('by_supplier_id'));
|
2016-11-23 05:17:54 -08:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('by_company_id')) {
|
2023-04-13 12:02:11 -07:00
|
|
|
$assets->whereIn('assets.company_id', $request->input('by_company_id'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-12-01 14:37:11 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('by_model_id')) {
|
2023-05-16 13:58:21 -07:00
|
|
|
$assets->whereIn('assets.model_id', $request->input('by_model_id'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-12-01 14:37:11 -08:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('by_category_id')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$assets->InCategory($request->input('by_category_id'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-12-01 14:37:11 -08:00
|
|
|
|
2018-10-31 15:19:13 -07:00
|
|
|
if ($request->filled('by_dept_id')) {
|
|
|
|
$assets->CheckedOutToTargetInDepartment($request->input('by_dept_id'));
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('by_manufacturer_id')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$assets->ByManufacturer($request->input('by_manufacturer_id'));
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('by_order_number')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$assets->where('assets.order_number', $request->input('by_order_number'));
|
2016-11-15 01:55:27 -08:00
|
|
|
}
|
2016-08-02 15:04:10 -07:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('by_status_id')) {
|
2023-05-16 13:58:21 -07:00
|
|
|
$assets->whereIn('assets.status_id', $request->input('by_status_id'));
|
2017-12-01 16:51:38 -08:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if (($request->filled('purchase_start')) && ($request->filled('purchase_end'))) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$assets->whereBetween('assets.purchase_date', [$request->input('purchase_start'), $request->input('purchase_end')]);
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if (($request->filled('created_start')) && ($request->filled('created_end'))) {
|
2023-07-20 15:17:06 -07:00
|
|
|
$created_start = \Carbon::parse($request->input('created_start'))->startOfDay();
|
|
|
|
$created_end = \Carbon::parse($request->input('created_end'))->endOfDay();
|
2023-10-18 06:13:25 -07:00
|
|
|
|
2023-07-20 15:17:06 -07:00
|
|
|
$assets->whereBetween('assets.created_at', [$created_start, $created_end]);
|
2017-02-03 02:20:56 -08:00
|
|
|
}
|
2024-02-14 17:00:23 -08:00
|
|
|
|
2023-04-19 09:11:44 -07:00
|
|
|
if (($request->filled('checkout_date_start')) && ($request->filled('checkout_date_end'))) {
|
2023-07-20 15:17:06 -07:00
|
|
|
$checkout_start = \Carbon::parse($request->input('checkout_date_start'))->startOfDay();
|
2024-02-15 16:56:08 -08:00
|
|
|
$checkout_end = \Carbon::parse($request->input('checkout_date_end',now()))->endOfDay();
|
2023-07-20 15:17:06 -07:00
|
|
|
|
2024-02-15 16:56:08 -08:00
|
|
|
$actionlogassets = Actionlog::where('action_type','=', 'checkout')
|
|
|
|
->where('item_type', 'LIKE', '%Asset%',)
|
|
|
|
->whereBetween('action_date',[$checkout_start, $checkout_end])
|
2024-02-15 16:15:27 -08:00
|
|
|
->pluck('item_id');
|
2023-07-20 15:17:06 -07:00
|
|
|
|
2024-04-04 06:23:58 -07:00
|
|
|
$assets->whereIn('assets.id',$actionlogassets);
|
2023-04-19 09:11:44 -07:00
|
|
|
}
|
2018-05-08 07:34:14 -07:00
|
|
|
|
2023-08-21 14:35:15 -07:00
|
|
|
if (($request->filled('checkin_date_start'))) {
|
2024-02-13 14:09:51 -08:00
|
|
|
$checkin_start = \Carbon::parse($request->input('checkin_date_start'))->startOfDay();
|
2023-10-18 06:13:25 -07:00
|
|
|
// use today's date is `checkin_date_end` is not provided
|
2024-02-13 14:09:51 -08:00
|
|
|
$checkin_end = \Carbon::parse($request->input('checkin_date_end', now()))->endOfDay();
|
|
|
|
|
|
|
|
$assets->whereBetween('assets.last_checkin', [$checkin_start, $checkin_end ]);
|
2023-08-21 13:44:49 -07:00
|
|
|
}
|
2024-02-13 14:09:51 -08:00
|
|
|
//last checkin is exporting, but currently is a date and not a datetime in the custom report ONLY.
|
2023-08-21 13:44:49 -07:00
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if (($request->filled('expected_checkin_start')) && ($request->filled('expected_checkin_end'))) {
|
2023-10-18 06:13:25 -07:00
|
|
|
$assets->whereBetween('assets.expected_checkin', [$request->input('expected_checkin_start'), $request->input('expected_checkin_end')]);
|
2018-05-08 07:34:14 -07:00
|
|
|
}
|
2021-01-26 12:05:31 -08:00
|
|
|
|
|
|
|
if (($request->filled('last_audit_start')) && ($request->filled('last_audit_end'))) {
|
2023-10-18 06:13:25 -07:00
|
|
|
$last_audit_start = \Carbon::parse($request->input('last_audit_start'))->startOfDay();
|
|
|
|
$last_audit_end = \Carbon::parse($request->input('last_audit_end'))->endOfDay();
|
2023-07-20 15:17:06 -07:00
|
|
|
|
2023-10-18 06:13:25 -07:00
|
|
|
$assets->whereBetween('assets.last_audit_date', [$last_audit_start, $last_audit_end]);
|
2021-01-26 12:05:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (($request->filled('next_audit_start')) && ($request->filled('next_audit_end'))) {
|
|
|
|
$assets->whereBetween('assets.next_audit_date', [$request->input('next_audit_start'), $request->input('next_audit_end')]);
|
|
|
|
}
|
2022-08-02 19:58:37 -07:00
|
|
|
if ($request->filled('exclude_archived')) {
|
2022-07-12 12:20:11 -07:00
|
|
|
$assets->notArchived();
|
2022-07-11 09:56:58 -07:00
|
|
|
}
|
2024-01-16 12:33:16 -08:00
|
|
|
if ($request->input('deleted_assets') == 'include_deleted') {
|
2022-08-01 14:52:12 -07:00
|
|
|
$assets->withTrashed();
|
|
|
|
}
|
2024-01-16 12:33:16 -08:00
|
|
|
if ($request->input('deleted_assets') == 'only_deleted') {
|
2022-08-01 14:52:12 -07:00
|
|
|
$assets->onlyTrashed();
|
|
|
|
}
|
2022-07-12 09:46:44 -07:00
|
|
|
|
2023-05-16 13:58:21 -07:00
|
|
|
\Log::debug($assets->toSql());
|
2021-06-10 13:15:52 -07:00
|
|
|
$assets->orderBy('assets.id', 'ASC')->chunk(20, function ($assets) use ($handle, $customfields, $request) {
|
2017-12-01 14:37:11 -08:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$executionTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'];
|
2019-08-15 06:14:25 -07:00
|
|
|
\Log::debug('Walking results: '.$executionTime);
|
|
|
|
$count = 0;
|
2022-09-30 09:29:17 -07:00
|
|
|
|
|
|
|
$formatter = new EscapeFormula("`");
|
|
|
|
|
2017-12-01 14:37:11 -08:00
|
|
|
foreach ($assets as $asset) {
|
2019-08-15 06:14:25 -07:00
|
|
|
$count++;
|
2017-12-01 14:37:11 -08:00
|
|
|
$row = [];
|
2022-08-10 13:51:47 -07:00
|
|
|
|
|
|
|
if ($request->filled('id')) {
|
|
|
|
$row[] = ($asset->id) ? $asset->id : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('company')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$row[] = ($asset->company) ? $asset->company->name : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('asset_name')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$row[] = ($asset->name) ? $asset->name : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('asset_tag')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$row[] = ($asset->asset_tag) ? $asset->asset_tag : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('model')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$row[] = ($asset->model) ? $asset->model->name : '';
|
|
|
|
$row[] = ($asset->model) ? $asset->model->model_number : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('category')) {
|
2018-01-25 00:25:43 -08:00
|
|
|
$row[] = (($asset->model) && ($asset->model->category)) ? $asset->model->category->name : '';
|
2017-12-01 14:37:11 -08:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('manufacturer')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$row[] = ($asset->model && $asset->model->manufacturer) ? $asset->model->manufacturer->name : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('serial')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$row[] = ($asset->serial) ? $asset->serial : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('purchase_date')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$row[] = ($asset->purchase_date) ? $asset->purchase_date : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('purchase_cost')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$row[] = ($asset->purchase_cost) ? Helper::formatCurrencyOutput($asset->purchase_cost) : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('eol')) {
|
2023-10-26 12:39:02 -07:00
|
|
|
$row[] = ($asset->asset_eol_date) ? $asset->asset_eol_date : '';
|
2017-12-01 14:37:11 -08:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('order')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$row[] = ($asset->order_number) ? $asset->order_number : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('supplier')) {
|
2017-12-04 20:45:20 -08:00
|
|
|
$row[] = ($asset->supplier) ? $asset->supplier->name : '';
|
2017-12-01 14:37:11 -08:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('location')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$row[] = ($asset->location) ? $asset->location->present()->name() : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('location_address')) {
|
2018-05-08 09:21:43 -07:00
|
|
|
$row[] = ($asset->location) ? $asset->location->address : '';
|
|
|
|
$row[] = ($asset->location) ? $asset->location->address2 : '';
|
|
|
|
$row[] = ($asset->location) ? $asset->location->city : '';
|
|
|
|
$row[] = ($asset->location) ? $asset->location->state : '';
|
|
|
|
$row[] = ($asset->location) ? $asset->location->country : '';
|
|
|
|
$row[] = ($asset->location) ? $asset->location->zip : '';
|
2018-04-05 17:33:25 -07:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('rtd_location')) {
|
2018-05-08 09:21:43 -07:00
|
|
|
$row[] = ($asset->defaultLoc) ? $asset->defaultLoc->present()->name() : '';
|
2018-04-05 17:33:25 -07:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('rtd_location_address')) {
|
2018-04-05 17:33:25 -07:00
|
|
|
$row[] = ($asset->defaultLoc) ? $asset->defaultLoc->address : '';
|
|
|
|
$row[] = ($asset->defaultLoc) ? $asset->defaultLoc->address2 : '';
|
|
|
|
$row[] = ($asset->defaultLoc) ? $asset->defaultLoc->city : '';
|
|
|
|
$row[] = ($asset->defaultLoc) ? $asset->defaultLoc->state : '';
|
|
|
|
$row[] = ($asset->defaultLoc) ? $asset->defaultLoc->country : '';
|
|
|
|
$row[] = ($asset->defaultLoc) ? $asset->defaultLoc->zip : '';
|
2018-03-26 15:59:09 -07:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('assigned_to')) {
|
2018-12-12 19:38:24 -08:00
|
|
|
$row[] = ($asset->checkedOutToUser() && $asset->assigned) ? $asset->assigned->getFullNameAttribute() : ($asset->assigned ? $asset->assigned->display_name : '');
|
|
|
|
$row[] = ($asset->checkedOutToUser() && $asset->assigned) ? 'user' : $asset->assignedType();
|
2017-12-01 14:37:11 -08:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('username')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
// Only works if we're checked out to a user, not anything else.
|
|
|
|
if ($asset->checkedOutToUser()) {
|
2022-11-16 16:34:57 -08:00
|
|
|
$row[] = ($asset->assignedto) ? $asset->assignedto->username : '';
|
2017-12-01 14:37:11 -08:00
|
|
|
} else {
|
|
|
|
$row[] = ''; // Empty string if unassigned
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('employee_num')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
// Only works if we're checked out to a user, not anything else.
|
|
|
|
if ($asset->checkedOutToUser()) {
|
2022-11-16 16:34:57 -08:00
|
|
|
$row[] = ($asset->assignedto) ? $asset->assignedto->employee_num : '';
|
2017-12-01 14:37:11 -08:00
|
|
|
} else {
|
|
|
|
$row[] = ''; // Empty string if unassigned
|
2018-04-16 20:10:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('manager')) {
|
2018-06-27 00:45:09 -07:00
|
|
|
if ($asset->checkedOutToUser()) {
|
2022-11-16 16:34:57 -08:00
|
|
|
$row[] = (($asset->assignedto) && ($asset->assignedto->manager)) ? $asset->assignedto->manager->present()->fullName : '';
|
2018-06-27 00:45:09 -07:00
|
|
|
} else {
|
|
|
|
$row[] = ''; // Empty string if unassigned
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('department')) {
|
2018-04-16 20:10:38 -07:00
|
|
|
if ($asset->checkedOutToUser()) {
|
2022-11-16 16:34:57 -08:00
|
|
|
$row[] = (($asset->assignedto) && ($asset->assignedto->department)) ? $asset->assignedto->department->name : '';
|
2018-04-16 20:10:38 -07:00
|
|
|
} else {
|
|
|
|
$row[] = ''; // Empty string if unassigned
|
2017-12-01 14:37:11 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-13 18:27:23 -08:00
|
|
|
if ($request->filled('title')) {
|
|
|
|
if ($asset->checkedOutToUser()) {
|
2022-11-16 16:34:57 -08:00
|
|
|
$row[] = ($asset->assignedto) ? $asset->assignedto->jobtitle : '';
|
2021-12-13 18:27:23 -08:00
|
|
|
} else {
|
|
|
|
$row[] = ''; // Empty string if unassigned
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-26 17:10:53 -07:00
|
|
|
if ($request->filled('phone')) {
|
|
|
|
if ($asset->checkedOutToUser()) {
|
|
|
|
$row[] = ($asset->assignedto) ? $asset->assignedto->phone : '';
|
|
|
|
} else {
|
|
|
|
$row[] = ''; // Empty string if unassigned
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->filled('user_address')) {
|
|
|
|
if ($asset->checkedOutToUser()) {
|
|
|
|
$row[] = ($asset->assignedto) ? $asset->assignedto->address : '';
|
|
|
|
} else {
|
|
|
|
$row[] = ''; // Empty string if unassigned
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->filled('user_city')) {
|
|
|
|
if ($asset->checkedOutToUser()) {
|
|
|
|
$row[] = ($asset->assignedto) ? $asset->assignedto->city : '';
|
|
|
|
} else {
|
|
|
|
$row[] = ''; // Empty string if unassigned
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->filled('user_state')) {
|
|
|
|
if ($asset->checkedOutToUser()) {
|
|
|
|
$row[] = ($asset->assignedto) ? $asset->assignedto->state : '';
|
|
|
|
} else {
|
|
|
|
$row[] = ''; // Empty string if unassigned
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->filled('user_country')) {
|
|
|
|
if ($asset->checkedOutToUser()) {
|
|
|
|
$row[] = ($asset->assignedto) ? $asset->assignedto->country : '';
|
|
|
|
} else {
|
|
|
|
$row[] = ''; // Empty string if unassigned
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->filled('user_zip')) {
|
|
|
|
if ($asset->checkedOutToUser()) {
|
|
|
|
$row[] = ($asset->assignedto) ? $asset->assignedto->zip : '';
|
|
|
|
} else {
|
|
|
|
$row[] = ''; // Empty string if unassigned
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('status')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$row[] = ($asset->assetstatus) ? $asset->assetstatus->name.' ('.$asset->present()->statusMeta.')' : '';
|
2017-12-01 14:37:11 -08:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('warranty')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$row[] = ($asset->warranty_months) ? $asset->warranty_months : '';
|
2022-08-02 19:12:18 -07:00
|
|
|
$row[] = $asset->present()->warranty_expires();
|
2017-12-01 14:37:11 -08:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('depreciation')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$depreciation = $asset->getDepreciatedValue();
|
|
|
|
$diff = ($asset->purchase_cost - $depreciation);
|
2021-06-10 13:15:52 -07:00
|
|
|
$row[] = Helper::formatCurrencyOutput($depreciation);
|
|
|
|
$row[] = Helper::formatCurrencyOutput($diff);
|
|
|
|
$row[] = ($asset->depreciation) ? $asset->depreciated_date()->format('Y-m-d') : '';
|
2017-12-01 16:51:38 -08:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('checkout_date')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$row[] = ($asset->last_checkout) ? $asset->last_checkout : '';
|
2017-12-01 14:37:11 -08:00
|
|
|
}
|
|
|
|
|
2023-08-21 13:44:49 -07:00
|
|
|
if ($request->filled('checkin_date')) {
|
|
|
|
$row[] = ($asset->last_checkin)
|
|
|
|
? Carbon::parse($asset->last_checkin)->format('Y-m-d')
|
|
|
|
: '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('expected_checkin')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$row[] = ($asset->expected_checkin) ? $asset->expected_checkin : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('created_at')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$row[] = ($asset->created_at) ? $asset->created_at : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('updated_at')) {
|
2017-12-01 16:51:38 -08:00
|
|
|
$row[] = ($asset->updated_at) ? $asset->updated_at : '';
|
|
|
|
}
|
|
|
|
|
2022-08-02 19:58:37 -07:00
|
|
|
if ($request->filled('deleted_at')) {
|
|
|
|
$row[] = ($asset->deleted_at) ? $asset->deleted_at : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('last_audit_date')) {
|
2017-12-12 03:03:43 -08:00
|
|
|
$row[] = ($asset->last_audit_date) ? $asset->last_audit_date : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('next_audit_date')) {
|
2017-12-12 03:03:43 -08:00
|
|
|
$row[] = ($asset->next_audit_date) ? $asset->next_audit_date : '';
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled('notes')) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$row[] = ($asset->notes) ? $asset->notes : '';
|
|
|
|
}
|
|
|
|
|
2022-08-10 13:51:47 -07:00
|
|
|
if ($request->filled('url')) {
|
|
|
|
$row[] = config('app.url').'/hardware/'.$asset->id ;
|
|
|
|
}
|
|
|
|
|
2017-12-01 14:37:11 -08:00
|
|
|
foreach ($customfields as $customfield) {
|
|
|
|
$column_name = $customfield->db_column_name();
|
2019-05-23 17:17:46 -07:00
|
|
|
if ($request->filled($customfield->db_column_name())) {
|
2017-12-01 14:37:11 -08:00
|
|
|
$row[] = $asset->$column_name;
|
|
|
|
}
|
|
|
|
}
|
2022-09-30 09:48:43 -07:00
|
|
|
|
|
|
|
|
|
|
|
// CSV_ESCAPE_FORMULAS is set to false in the .env
|
|
|
|
if (config('app.escape_formulas') === false) {
|
|
|
|
fputcsv($handle, $row);
|
|
|
|
|
|
|
|
// CSV_ESCAPE_FORMULAS is set to true or is not set in the .env
|
|
|
|
} else {
|
|
|
|
fputcsv($handle, $formatter->escapeRecord($row));
|
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$executionTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'];
|
|
|
|
\Log::debug('-- Record '.$count.' Asset ID:'.$asset->id.' in '.$executionTime);
|
2016-08-02 15:04:10 -07:00
|
|
|
}
|
2017-12-01 14:37:11 -08:00
|
|
|
});
|
2016-08-02 15:04:10 -07:00
|
|
|
|
2017-12-01 14:37:11 -08:00
|
|
|
// Close the output stream
|
|
|
|
fclose($handle);
|
2021-06-10 13:15:52 -07:00
|
|
|
$executionTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'];
|
|
|
|
\Log::debug('-- SCRIPT COMPLETED IN '.$executionTime);
|
2017-12-01 14:37:11 -08:00
|
|
|
}, 200, [
|
|
|
|
'Content-Type' => 'text/csv',
|
2021-06-10 13:15:52 -07:00
|
|
|
'Content-Disposition' => 'attachment; filename="custom-assets-report-'.date('Y-m-d-his').'.csv"',
|
2017-12-01 14:37:11 -08:00
|
|
|
]);
|
|
|
|
|
|
|
|
return $response;
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-15 19:59:42 -08:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
/**
|
|
|
|
* getImprovementsReport
|
|
|
|
*
|
2016-04-07 17:08:38 -07:00
|
|
|
* @return View
|
2016-03-25 01:18:05 -07:00
|
|
|
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
|
|
|
public function getAssetMaintenancesReport()
|
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2023-04-27 17:12:53 -07:00
|
|
|
return view('reports.asset_maintenances');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* exportImprovementsReport
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
|
|
|
public function exportAssetMaintenancesReport()
|
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2016-03-25 01:18:05 -07:00
|
|
|
// Grab all the improvements
|
|
|
|
$assetMaintenances = AssetMaintenance::with('asset', 'supplier')
|
|
|
|
->orderBy('created_at', 'DESC')
|
|
|
|
->get();
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$rows = [];
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
$header = [
|
2016-10-12 14:18:51 -07:00
|
|
|
trans('admin/hardware/table.asset_tag'),
|
2016-04-07 13:39:35 -07:00
|
|
|
trans('admin/asset_maintenances/table.asset_name'),
|
2016-11-29 12:48:00 -08:00
|
|
|
trans('general.supplier'),
|
2016-04-07 13:39:35 -07:00
|
|
|
trans('admin/asset_maintenances/form.asset_maintenance_type'),
|
|
|
|
trans('admin/asset_maintenances/form.title'),
|
|
|
|
trans('admin/asset_maintenances/form.start_date'),
|
|
|
|
trans('admin/asset_maintenances/form.completion_date'),
|
|
|
|
trans('admin/asset_maintenances/form.asset_maintenance_time'),
|
2021-06-10 13:15:52 -07:00
|
|
|
trans('admin/asset_maintenances/form.cost'),
|
2016-03-25 01:18:05 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
$header = array_map('trim', $header);
|
2021-07-16 15:07:51 -07:00
|
|
|
$rows[] = implode(',', $header);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
foreach ($assetMaintenances as $assetMaintenance) {
|
2021-06-10 13:15:52 -07:00
|
|
|
$row = [];
|
2016-10-12 14:18:51 -07:00
|
|
|
$row[] = str_replace(',', '', e($assetMaintenance->asset->asset_tag));
|
2016-03-25 15:24:12 -07:00
|
|
|
$row[] = str_replace(',', '', e($assetMaintenance->asset->name));
|
|
|
|
$row[] = str_replace(',', '', e($assetMaintenance->supplier->name));
|
|
|
|
$row[] = e($assetMaintenance->improvement_type);
|
|
|
|
$row[] = e($assetMaintenance->title);
|
|
|
|
$row[] = e($assetMaintenance->start_date);
|
2016-03-25 18:51:44 -07:00
|
|
|
$row[] = e($assetMaintenance->completion_date);
|
2016-03-25 01:18:05 -07:00
|
|
|
if (is_null($assetMaintenance->asset_maintenance_time)) {
|
|
|
|
$improvementTime = intval(Carbon::now()
|
|
|
|
->diffInDays(Carbon::parse($assetMaintenance->start_date)));
|
|
|
|
} else {
|
|
|
|
$improvementTime = intval($assetMaintenance->asset_maintenance_time);
|
|
|
|
}
|
|
|
|
$row[] = $improvementTime;
|
2016-08-16 18:47:53 -07:00
|
|
|
$row[] = trans('general.currency') . Helper::formatCurrencyOutput($assetMaintenance->cost);
|
2021-07-16 15:07:51 -07:00
|
|
|
$rows[] = implode(',', $row);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// spit out a csv
|
2021-07-16 15:07:51 -07:00
|
|
|
$csv = implode("\n", $rows);
|
2016-03-25 01:18:05 -07:00
|
|
|
$response = Response::make($csv, 200);
|
|
|
|
$response->header('Content-Type', 'text/csv');
|
|
|
|
$response->header('Content-disposition', 'attachment;filename=report.csv');
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getAssetAcceptanceReport
|
|
|
|
*
|
|
|
|
* @return mixed
|
2021-05-03 12:06:12 -07:00
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
2021-10-28 18:11:03 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
2021-07-16 16:37:11 -07:00
|
|
|
public function getAssetAcceptanceReport($deleted = false)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2021-07-16 16:37:11 -07:00
|
|
|
$showDeleted = $deleted == 'deleted';
|
2018-07-28 04:21:11 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all assets with pending checkout acceptances
|
|
|
|
*/
|
2022-03-16 12:20:46 -07:00
|
|
|
if($showDeleted) {
|
2022-05-18 12:46:48 -07:00
|
|
|
$acceptances = CheckoutAcceptance::pending()->where('checkoutable_type', 'App\Models\Asset')->withTrashed()->with(['assignedTo' , 'checkoutable.assignedTo', 'checkoutable.model'])->get();
|
2022-03-16 12:20:46 -07:00
|
|
|
} else {
|
2022-05-18 12:46:48 -07:00
|
|
|
$acceptances = CheckoutAcceptance::pending()->where('checkoutable_type', 'App\Models\Asset')->with(['assignedTo' => function ($query) {
|
2022-03-16 12:20:46 -07:00
|
|
|
$query->withTrashed();
|
|
|
|
}, 'checkoutable.assignedTo', 'checkoutable.model'])->get();
|
|
|
|
}
|
2018-07-28 04:21:11 -07:00
|
|
|
|
|
|
|
$assetsForReport = $acceptances
|
2022-03-16 12:20:46 -07:00
|
|
|
->filter(function ($acceptance) {
|
2023-09-11 16:40:59 -07:00
|
|
|
$acceptance_checkoutable_flag = false;
|
|
|
|
if ($acceptance->checkoutable){
|
|
|
|
$acceptance_checkoutable_flag = $acceptance->checkoutable->checkedOutToUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $acceptance->checkoutable_type == 'App\Models\Asset' && $acceptance_checkoutable_flag;
|
2018-07-28 04:21:11 -07:00
|
|
|
})
|
|
|
|
->map(function($acceptance) {
|
2021-05-03 12:06:12 -07:00
|
|
|
return ['assetItem' => $acceptance->checkoutable, 'acceptance' => $acceptance];
|
2018-07-28 04:21:11 -07:00
|
|
|
});
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2021-07-16 16:37:11 -07:00
|
|
|
return view('reports/unaccepted_assets', compact('assetsForReport','showDeleted' ));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-05-03 12:06:12 -07:00
|
|
|
* sentAssetAcceptanceReminder
|
|
|
|
*
|
|
|
|
* @param integer|null $acceptanceId
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
2023-10-09 08:13:41 -07:00
|
|
|
public function sentAssetAcceptanceReminder(Request $request)
|
2021-05-03 12:06:12 -07:00
|
|
|
{
|
|
|
|
$this->authorize('reports.view');
|
|
|
|
|
2023-10-09 08:13:41 -07:00
|
|
|
if (!$acceptance = CheckoutAcceptance::pending()->find($request->input('acceptance_id'))) {
|
|
|
|
\Log::debug('No pending acceptances');
|
2021-05-03 12:06:12 -07:00
|
|
|
// Redirect to the unaccepted assets report page with error
|
|
|
|
return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data'));
|
|
|
|
}
|
2023-10-09 08:13:41 -07:00
|
|
|
|
2021-05-03 12:06:12 -07:00
|
|
|
$assetItem = $acceptance->checkoutable;
|
|
|
|
|
2023-10-09 08:13:41 -07:00
|
|
|
\Log::debug(print_r($assetItem, true));
|
|
|
|
|
2022-08-17 20:02:13 -07:00
|
|
|
if (is_null($acceptance->created_at)){
|
2023-10-09 08:13:41 -07:00
|
|
|
\Log::debug('No acceptance created_at');
|
2022-08-17 20:02:13 -07:00
|
|
|
return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data'));
|
|
|
|
} else {
|
2023-03-13 20:44:06 -07:00
|
|
|
$logItem_res = $assetItem->checkouts()->where('created_at', '=', $acceptance->created_at)->get();
|
2023-10-09 08:13:41 -07:00
|
|
|
|
2023-03-13 20:44:06 -07:00
|
|
|
if ($logItem_res->isEmpty()){
|
2023-10-09 08:13:41 -07:00
|
|
|
\Log::debug('Acceptance date mismatch');
|
2023-03-13 20:44:06 -07:00
|
|
|
return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data'));
|
|
|
|
}
|
|
|
|
$logItem = $logItem_res[0];
|
2022-08-17 20:02:13 -07:00
|
|
|
}
|
2021-05-03 12:06:12 -07:00
|
|
|
|
2024-02-22 04:03:07 -08:00
|
|
|
// Only send notification if assigned
|
|
|
|
if ($assetItem->assignedTo) {
|
|
|
|
|
|
|
|
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)
|
|
|
|
);
|
|
|
|
}
|
2021-05-03 12:06:12 -07:00
|
|
|
}
|
|
|
|
|
2024-03-05 10:30:24 -08:00
|
|
|
if ($assetItem->assignedTo->email == ''){
|
|
|
|
return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.no_email'));
|
|
|
|
}
|
|
|
|
|
2021-05-03 12:06:12 -07:00
|
|
|
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'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
/**
|
2021-07-16 15:15:33 -07:00
|
|
|
* Exports the AssetAcceptance report to CSV
|
2016-03-25 01:18:05 -07:00
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
2021-07-16 16:37:11 -07:00
|
|
|
public function postAssetAcceptanceReport($deleted = false)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2021-07-16 16:37:11 -07:00
|
|
|
$showDeleted = $deleted == 'deleted';
|
2021-05-03 12:06:12 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all assets with pending checkout acceptances
|
|
|
|
*/
|
2021-07-16 16:37:11 -07:00
|
|
|
if($showDeleted) {
|
2022-10-03 16:12:30 -07:00
|
|
|
$acceptances = CheckoutAcceptance::pending()->where('checkoutable_type', 'App\Models\Asset')->withTrashed()->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model'])->get();
|
2021-07-16 16:37:11 -07:00
|
|
|
} else {
|
2022-10-03 16:12:30 -07:00
|
|
|
$acceptances = CheckoutAcceptance::pending()->where('checkoutable_type', 'App\Models\Asset')->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model'])->get();
|
2021-07-16 16:37:11 -07:00
|
|
|
}
|
2021-05-03 12:06:12 -07:00
|
|
|
|
|
|
|
$assetsForReport = $acceptances
|
|
|
|
->filter(function($acceptance) {
|
|
|
|
return $acceptance->checkoutable_type == 'App\Models\Asset';
|
|
|
|
})
|
|
|
|
->map(function($acceptance) {
|
|
|
|
return ['assetItem' => $acceptance->checkoutable, 'acceptance' => $acceptance];
|
|
|
|
});
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$rows = [];
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
$header = [
|
2016-04-07 13:39:35 -07:00
|
|
|
trans('general.category'),
|
|
|
|
trans('admin/hardware/form.model'),
|
|
|
|
trans('admin/hardware/form.name'),
|
|
|
|
trans('admin/hardware/table.asset_tag'),
|
|
|
|
trans('admin/hardware/table.checkoutto'),
|
2016-03-25 01:18:05 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
$header = array_map('trim', $header);
|
2021-07-16 15:07:51 -07:00
|
|
|
$rows[] = implode(',', $header);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2021-05-03 12:06:12 -07:00
|
|
|
foreach ($assetsForReport as $item) {
|
2022-12-06 16:00:16 -08:00
|
|
|
|
|
|
|
if ($item['assetItem'] != null){
|
|
|
|
|
|
|
|
$row = [ ];
|
|
|
|
$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);
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// spit out a csv
|
2021-07-16 15:07:51 -07:00
|
|
|
$csv = implode("\n", $rows);
|
2016-03-25 01:18:05 -07:00
|
|
|
$response = Response::make($csv, 200);
|
|
|
|
$response->header('Content-Type', 'text/csv');
|
|
|
|
$response->header('Content-disposition', 'attachment;filename=report.csv');
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getCheckedOutAssetsRequiringAcceptance
|
|
|
|
*
|
|
|
|
* @param $modelsInCategoriesThatRequireAcceptance
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
|
|
|
protected function getCheckedOutAssetsRequiringAcceptance($modelsInCategoriesThatRequireAcceptance)
|
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2016-03-25 01:18:05 -07:00
|
|
|
$assets = Asset::deployed()
|
|
|
|
->inModelList($modelsInCategoriesThatRequireAcceptance)
|
|
|
|
->select('id')
|
|
|
|
->get()
|
|
|
|
->toArray();
|
|
|
|
|
|
|
|
return array_pluck($assets, 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getModelsInCategoriesThatRequireAcceptance
|
|
|
|
*
|
|
|
|
* @param $assetCategoriesRequiringAcceptance
|
|
|
|
* @return array
|
|
|
|
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
|
|
|
protected function getModelsInCategoriesThatRequireAcceptance($assetCategoriesRequiringAcceptance)
|
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
return array_pluck(Model::inCategory($assetCategoriesRequiringAcceptance)
|
|
|
|
->select('id')
|
|
|
|
->get()
|
|
|
|
->toArray(), 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getCategoriesThatRequireAcceptance
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
|
|
|
protected function getCategoriesThatRequireAcceptance()
|
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
return array_pluck(Category::requiresAcceptance()
|
|
|
|
->select('id')
|
|
|
|
->get()
|
|
|
|
->toArray(), 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getAssetsCheckedOutRequiringAcceptance
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
|
|
|
protected function getAssetsCheckedOutRequiringAcceptance()
|
|
|
|
{
|
2018-07-25 10:45:32 -07:00
|
|
|
$this->authorize('reports.view');
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
return $this->getCheckedOutAssetsRequiringAcceptance(
|
|
|
|
$this->getModelsInCategoriesThatRequireAcceptance($this->getCategoriesThatRequireAcceptance())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|