Rename SavedReport to ReportTemplate

This commit is contained in:
Marcus Moore 2023-12-18 12:55:48 -08:00
parent 27bb938d9e
commit 9fcb1a2d0e
No known key found for this signature in database
10 changed files with 131 additions and 138 deletions

View file

@ -3,18 +3,18 @@
namespace App\Http\Controllers;
use App\Models\CustomField;
use App\Models\SavedReport;
use App\Models\ReportTemplate;
use Illuminate\Http\Request;
class SavedReportsController extends Controller
class ReportTemplatesController extends Controller
{
public function store(Request $request)
{
$this->authorize('reports.view');
$request->validate((new SavedReport)->getRules());
$request->validate((new ReportTemplate)->getRules());
$report = $request->user()->savedReports()->create([
$report = $request->user()->reportTemplates()->create([
'name' => $request->get('name'),
'options' => $request->except(['_token', 'name']),
]);
@ -24,19 +24,19 @@ class SavedReportsController extends Controller
public function edit(Request $request, $reportId)
{
$report = SavedReport::findOrFail($reportId);
$report = ReportTemplate::findOrFail($reportId);
return view('reports/custom', [
'customfields' => CustomField::get(),
'savedReport' => $report,
'reportTemplate' => $report,
]);
}
public function update(Request $request)
{
$this->authorize('update',SavedReport::class);
$this->authorize('update',ReportTemplate::class);
if(is_null($reportid = SavedReport::find($request)))
if(is_null($reportid = ReportTemplate::find($request)))
{
return redirect()->route('reports/custom');
}
@ -44,7 +44,7 @@ class SavedReportsController extends Controller
$request->validate()->report->id->getRules();
$report = $request->user()->savedReports()->edit([
$report = $request->user()->reportTemplates()->edit([
'name' => $request->get('name'),
'options' => $request->except(['token','name']),
]);

View file

@ -11,7 +11,7 @@ use App\Models\CheckoutAcceptance;
use App\Models\CustomField;
use App\Models\Depreciation;
use App\Models\License;
use App\Models\SavedReport;
use App\Models\ReportTemplate;
use App\Models\Setting;
use App\Notifications\CheckoutAssetNotification;
use Carbon\Carbon;
@ -392,12 +392,12 @@ class ReportsController extends Controller
{
$this->authorize('reports.view');
$customfields = CustomField::get();
$saved_reports = SavedReport::orderBy('name')->get();
$report_templates = ReportTemplate::orderBy('name')->get();
return view('reports/custom', [
'customfields' => $customfields,
'saved_reports' => $saved_reports,
'savedReport' => $saved_reports->find($request->input('report')) ?? new SavedReport,
'report_templates' => $report_templates,
'reportTemplate' => $report_templates->find($request->input('report')) ?? new ReportTemplate,
]);
}

View file

@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Watson\Validating\ValidatingTrait;
class SavedReport extends Model
class ReportTemplate extends Model
{
use HasFactory;
use ValidatingTrait;
@ -28,7 +28,7 @@ class SavedReport extends Model
// @todo: add $rules
protected $rules = [
'name' => 'required|unique:saved_reports,name',
'name' => 'required|unique:report_templates,name',
'options' => 'array',
];

View file

@ -330,9 +330,9 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
return $this->belongsToMany(\App\Models\License::class, 'license_seats', 'assigned_to', 'license_id')->withPivot('id');
}
public function savedReports(): HasMany
public function reportTemplates(): HasMany
{
return $this->hasMany(SavedReport::class);
return $this->hasMany(ReportTemplate::class);
}
/**

View file

@ -4,7 +4,7 @@ namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class SavedReportFactory extends Factory
class ReportTemplateFactory extends Factory
{
/**
* Define the model's default state.

View file

@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateSavedReportsTable extends Migration
class CreateReportTemplatesTable extends Migration
{
/**
* Run the migrations.
@ -13,7 +13,7 @@ class CreateSavedReportsTable extends Migration
*/
public function up()
{
Schema::create('saved_reports', function (Blueprint $table) {
Schema::create('report_templates', function (Blueprint $table) {
$table->id();
$table->integer('user_id')->nullable();
$table->string('name');
@ -30,6 +30,6 @@ class CreateSavedReportsTable extends Migration
*/
public function down()
{
Schema::dropIfExists('saved_reports');
Schema::dropIfExists('report_templates');
}
}

View file

@ -28,31 +28,31 @@
<div class="box box-default">
<div class="box-header with-border">
<h2 class="box-title">
@if ($savedReport->exists && request()->routeIs('saved-templates.edit'))
Updating: {{ $savedReport->name }}
@elseif($savedReport->exists)
Saved Template: {{ $savedReport->name }}
@if ($reportTemplate->exists && request()->routeIs('report-templates.edit'))
Updating: {{ $reportTemplate->name }}
@elseif($reportTemplate->exists)
Saved Template: {{ $reportTemplate->name }}
@else
{{ trans('general.customize_report') }}
@endif
</h2>
@if ($savedReport->exists && request()->routeIs('saved-templates.edit'))
@if ($reportTemplate->exists && request()->routeIs('report-templates.edit'))
<div class="box-tools pull-right">
{{-- todo --}}
<form id="savetemplateform" action="{{ route("savedreports/update") }}">
<form id="savetemplateform" action="{{ route("report-templates.update", $reportTemplate->id) }}">
@csrf
@method('PUT')
<input type="hidden" id="savetemplateform" name="options">
<input type="hidden" id="name" name="name" value="{{ $savedReport->name }},1git ">
<input type="hidden" id="name" name="name" value="{{ $reportTemplate->name }},1git ">
<button class="btn btn-primary" style="width: 32%">
{{ "update" }}
</button>
</form>
</div>
@elseif ($savedReport->exists)
@elseif ($reportTemplate->exists)
<div class="box-tools pull-right">
<a
href="{{ route('saved-templates.edit', $savedReport) }}"
href="{{ route('report-templates.edit', $reportTemplate) }}"
class="btn btn-sm btn-warning"
data-tooltip="true"
title="Update"
@ -86,147 +86,147 @@
</label>
<label class="form-control">
{{ Form::checkbox('id', '1', $savedReport->checkmarkValue('id')) }}
{{ Form::checkbox('id', '1', $reportTemplate->checkmarkValue('id')) }}
{{ trans('general.id') }}
</label>
<label class="form-control">
{{ Form::checkbox('company', '1', $savedReport->checkmarkValue('company')) }}
{{ Form::checkbox('company', '1', $reportTemplate->checkmarkValue('company')) }}
{{ trans('general.company') }}
</label>
<label class="form-control">
{{ Form::checkbox('asset_tag', '1', $savedReport->checkmarkValue('asset_tag')) }}
{{ Form::checkbox('asset_tag', '1', $reportTemplate->checkmarkValue('asset_tag')) }}
{{ trans('general.asset_tag') }}
</label>
<label class="form-control">
{{ Form::checkbox('asset_name', '1', $savedReport->checkmarkValue('asset_name')) }}
{{ Form::checkbox('asset_name', '1', $reportTemplate->checkmarkValue('asset_name')) }}
{{ trans('admin/hardware/form.name') }}
</label>
<label class="form-control">
{{ Form::checkbox('manufacturer', '1', $savedReport->checkmarkValue('manufacturer')) }}
{{ Form::checkbox('manufacturer', '1', $reportTemplate->checkmarkValue('manufacturer')) }}
{{ trans('general.manufacturer') }}
</label>
<label class="form-control">
{{ Form::checkbox('model', '1', $savedReport->checkmarkValue('model')) }}
{{ Form::checkbox('model', '1', $reportTemplate->checkmarkValue('model')) }}
{{ trans('general.asset_models') }}
</label>
<label class="form-control">
{{ Form::checkbox('category', '1', $savedReport->checkmarkValue('category')) }}
{{ Form::checkbox('category', '1', $reportTemplate->checkmarkValue('category')) }}
{{ trans('general.category') }}
</label>
<label class="form-control">
{{ Form::checkbox('serial', '1', $savedReport->checkmarkValue('serial')) }}
{{ Form::checkbox('serial', '1', $reportTemplate->checkmarkValue('serial')) }}
{{ trans('admin/hardware/table.serial') }}
</label>
<label class="form-control">
{{ Form::checkbox('purchase_date', '1', $savedReport->checkmarkValue('purchase_date')) }}
{{ Form::checkbox('purchase_date', '1', $reportTemplate->checkmarkValue('purchase_date')) }}
{{ trans('admin/licenses/table.purchase_date') }}
</label>
<label class="form-control">
{{ Form::checkbox('purchase_cost', '1', $savedReport->checkmarkValue('purchase_cost')) }}
{{ Form::checkbox('purchase_cost', '1', $reportTemplate->checkmarkValue('purchase_cost')) }}
{{ trans('admin/hardware/form.cost') }}
</label>
<label class="form-control">
{{ Form::checkbox('eol', '1', $savedReport->checkmarkValue('eol')) }}
{{ Form::checkbox('eol', '1', $reportTemplate->checkmarkValue('eol')) }}
{{ trans('admin/hardware/table.eol') }}
</label>
<label class="form-control">
{{ Form::checkbox('order', '1', $savedReport->checkmarkValue('order')) }}
{{ Form::checkbox('order', '1', $reportTemplate->checkmarkValue('order')) }}
{{ trans('admin/hardware/form.order') }}
</label>
<label class="form-control">
{{ Form::checkbox('supplier', '1', $savedReport->checkmarkValue('supplier')) }}
{{ Form::checkbox('supplier', '1', $reportTemplate->checkmarkValue('supplier')) }}
{{ trans('general.suppliers') }}
</label>
<label class="form-control">
{{ Form::checkbox('location', '1', $savedReport->checkmarkValue('location')) }}
{{ Form::checkbox('location', '1', $reportTemplate->checkmarkValue('location')) }}
{{ trans('general.location') }}
</label>
<label class="form-control">
{{ Form::checkbox('location_address', '1', $savedReport->checkmarkValue('location_address')) }}
{{ Form::checkbox('location_address', '1', $reportTemplate->checkmarkValue('location_address')) }}
- {{ trans('general.address') }}
</label>
<label class="form-control">
{{ Form::checkbox('rtd_location', '1', $savedReport->checkmarkValue('rtd_location')) }}
{{ Form::checkbox('rtd_location', '1', $reportTemplate->checkmarkValue('rtd_location')) }}
{{ trans('admin/hardware/form.default_location') }}
</label>
<label class="form-control">
{{ Form::checkbox('rtd_location_address', '1', $savedReport->checkmarkValue('rtd_location_address')) }}
{{ Form::checkbox('rtd_location_address', '1', $reportTemplate->checkmarkValue('rtd_location_address')) }}
- {{ trans('general.address') }}
</label>
<label class="form-control">
{{ Form::checkbox('status', '1', $savedReport->checkmarkValue('status')) }}
{{ Form::checkbox('status', '1', $reportTemplate->checkmarkValue('status')) }}
{{ trans('general.status') }}
</label>
<label class="form-control">
{{ Form::checkbox('warranty', '1', $savedReport->checkmarkValue('warranty')) }}
{{ Form::checkbox('warranty', '1', $reportTemplate->checkmarkValue('warranty')) }}
{{ trans('admin/hardware/form.warranty') }}
</label>
<label class="form-control">
{{ Form::checkbox('depreciation', '1', $savedReport->checkmarkValue('depreciation')) }}
{{ Form::checkbox('depreciation', '1', $reportTemplate->checkmarkValue('depreciation')) }}
{{ trans('general.depreciation') }}
</label>
<label class="form-control">
{{ Form::checkbox('checkout_date', '1', $savedReport->checkmarkValue('checkout_date')) }}
{{ Form::checkbox('checkout_date', '1', $reportTemplate->checkmarkValue('checkout_date')) }}
{{ trans('admin/hardware/table.checkout_date') }}
</label>
<label class="form-control">
{{ Form::checkbox('expected_checkin', '1', $savedReport->checkmarkValue('expected_checkin')) }}
{{ Form::checkbox('expected_checkin', '1', $reportTemplate->checkmarkValue('expected_checkin')) }}
{{ trans('admin/hardware/form.expected_checkin') }}
</label>
<label class="form-control">
{{ Form::checkbox('created_at', '1', $savedReport->checkmarkValue('created_at')) }}
{{ Form::checkbox('created_at', '1', $reportTemplate->checkmarkValue('created_at')) }}
{{ trans('general.created_at') }}
</label>
<label class="form-control">
{{ Form::checkbox('updated_at', '1', $savedReport->checkmarkValue('updated_at')) }}
{{ Form::checkbox('updated_at', '1', $reportTemplate->checkmarkValue('updated_at')) }}
{{ trans('general.updated_at') }}
</label>
<label class="form-control">
{{ Form::checkbox('deleted_at', '1', $savedReport->checkmarkValue('deleted_at')) }}
{{ Form::checkbox('deleted_at', '1', $reportTemplate->checkmarkValue('deleted_at')) }}
{{ trans('general.deleted') }}
</label>
<label class="form-control">
{{ Form::checkbox('last_audit_date', '1', $savedReport->checkmarkValue('last_audit_date')) }}
{{ Form::checkbox('last_audit_date', '1', $reportTemplate->checkmarkValue('last_audit_date')) }}
{{ trans('general.last_audit') }}
</label>
<label class="form-control">
{{ Form::checkbox('next_audit_date', '1', $savedReport->checkmarkValue('next_audit_date')) }}
{{ Form::checkbox('next_audit_date', '1', $reportTemplate->checkmarkValue('next_audit_date')) }}
{{ trans('general.next_audit_date') }}
</label>
<label class="form-control">
{{ Form::checkbox('notes', '1', $savedReport->checkmarkValue('notes')) }}
{{ Form::checkbox('notes', '1', $reportTemplate->checkmarkValue('notes')) }}
{{ trans('general.notes') }}
</label>
<label class="form-control">
{{ Form::checkbox('url', '1', $savedReport->checkmarkValue('url')) }}
{{ Form::checkbox('url', '1', $reportTemplate->checkmarkValue('url')) }}
- {{ trans('admin/manufacturers/table.url') }}
</label>
@ -236,32 +236,32 @@
<h2>{{ trans('general.checked_out_to') }} {{ trans('general.fields') }}:</h2>
<label class="form-control">
{{ Form::checkbox('assigned_to', '1', $savedReport->checkmarkValue('assigned_to')) }}
{{ Form::checkbox('assigned_to', '1', $reportTemplate->checkmarkValue('assigned_to')) }}
{{ trans('admin/licenses/table.assigned_to') }}
</label>
<label class="form-control">
{{ Form::checkbox('username', '1', $savedReport->checkmarkValue('username')) }}
{{ Form::checkbox('username', '1', $reportTemplate->checkmarkValue('username')) }}
{{ trans('admin/users/table.username') }}
</label>
<label class="form-control">
{{ Form::checkbox('employee_num', '1', $savedReport->checkmarkValue('employee_num')) }}
{{ Form::checkbox('employee_num', '1', $reportTemplate->checkmarkValue('employee_num')) }}
{{ trans('general.employee_number') }}
</label>
<label class="form-control">
{{ Form::checkbox('manager', '1', $savedReport->checkmarkValue('manager')) }}
{{ Form::checkbox('manager', '1', $reportTemplate->checkmarkValue('manager')) }}
{{ trans('admin/users/table.manager') }}
</label>
<label class="form-control">
{{ Form::checkbox('department', '1', $savedReport->checkmarkValue('department')) }}
{{ Form::checkbox('department', '1', $reportTemplate->checkmarkValue('department')) }}
{{ trans('general.department') }}
</label>
<label class="form-control">
{{ Form::checkbox('title', '1', $savedReport->checkmarkValue('title')) }}
{{ Form::checkbox('title', '1', $reportTemplate->checkmarkValue('title')) }}
{{ trans('admin/users/table.title') }}
</label>
@ -274,7 +274,7 @@
@foreach ($customfields as $customfield)
<label class="form-control">
{{ Form::checkbox($customfield->db_column_name(), '1', $savedReport->checkmarkValue($customfield->db_column_name())) }}
{{ Form::checkbox($customfield->db_column_name(), '1', $reportTemplate->checkmarkValue($customfield->db_column_name())) }}
{{ $customfield->name }}
</label>
@ -290,21 +290,21 @@
<br>
@include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'),'multiple' => 'true', 'fieldname' => 'by_company_id[]', 'hide_new' => 'true', 'selected' => $savedReport->selectValues('by_company_id')])
@include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'multiple' => 'true', 'fieldname' => 'by_location_id[]', 'hide_new' => 'true', 'selected' => $savedReport->selectValues('by_location_id')])
@include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.default_location'), 'multiple' => 'true', 'fieldname' => 'by_rtd_location_id[]', 'hide_new' => 'true', 'selected' => $savedReport->selectValues('by_rtd_location_id')])
@include ('partials.forms.edit.department-select', ['translated_name' => trans('general.department'), 'fieldname' => 'by_dept_id', 'hide_new' => 'true', 'selected' => $savedReport->selectValue('by_dept_id')])
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'by_supplier_id[]', 'multiple' => 'true', 'hide_new' => 'true', 'selected' => $savedReport->selectValues('by_supplier_id')])
@include ('partials.forms.edit.model-select', ['translated_name' => trans('general.asset_model'), 'fieldname' => 'by_model_id[]', 'multiple' => 'true', 'hide_new' => 'true', 'selected' => $savedReport->selectValues('by_model_id')])
@include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'by_manufacturer_id', 'hide_new' => 'true', 'selected' => $savedReport->selectValue('by_manufacturer_id')])
@include ('partials.forms.edit.category-select', ['translated_name' => trans('general.category'), 'fieldname' => 'by_category_id', 'hide_new' => 'true', 'category_type' => 'asset', 'selected' => $savedReport->selectValue('by_category_id')])
@include ('partials.forms.edit.status-select', ['translated_name' => trans('admin/hardware/form.status'), 'fieldname' => 'by_status_id[]', 'multiple' => 'true', 'hide_new' => 'true', 'selected' => $savedReport->selectValues('by_status_id')])
@include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'),'multiple' => 'true', 'fieldname' => 'by_company_id[]', 'hide_new' => 'true', 'selected' => $reportTemplate->selectValues('by_company_id')])
@include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'multiple' => 'true', 'fieldname' => 'by_location_id[]', 'hide_new' => 'true', 'selected' => $reportTemplate->selectValues('by_location_id')])
@include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.default_location'), 'multiple' => 'true', 'fieldname' => 'by_rtd_location_id[]', 'hide_new' => 'true', 'selected' => $reportTemplate->selectValues('by_rtd_location_id')])
@include ('partials.forms.edit.department-select', ['translated_name' => trans('general.department'), 'fieldname' => 'by_dept_id', 'hide_new' => 'true', 'selected' => $reportTemplate->selectValue('by_dept_id')])
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'by_supplier_id[]', 'multiple' => 'true', 'hide_new' => 'true', 'selected' => $reportTemplate->selectValues('by_supplier_id')])
@include ('partials.forms.edit.model-select', ['translated_name' => trans('general.asset_model'), 'fieldname' => 'by_model_id[]', 'multiple' => 'true', 'hide_new' => 'true', 'selected' => $reportTemplate->selectValues('by_model_id')])
@include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'by_manufacturer_id', 'hide_new' => 'true', 'selected' => $reportTemplate->selectValue('by_manufacturer_id')])
@include ('partials.forms.edit.category-select', ['translated_name' => trans('general.category'), 'fieldname' => 'by_category_id', 'hide_new' => 'true', 'category_type' => 'asset', 'selected' => $reportTemplate->selectValue('by_category_id')])
@include ('partials.forms.edit.status-select', ['translated_name' => trans('admin/hardware/form.status'), 'fieldname' => 'by_status_id[]', 'multiple' => 'true', 'hide_new' => 'true', 'selected' => $reportTemplate->selectValues('by_status_id')])
<!-- Order Number -->
<div class="form-group">
<label for="by_order_number" class="col-md-3 control-label">{{ trans('general.order_number') }}</label>
<div class="col-md-5 col-sm-8">
<input class="form-control" type="text" name="by_order_number" value="{{ $savedReport->textValue('by_order_number') }}" aria-label="by_order_number">
<input class="form-control" type="text" name="by_order_number" value="{{ $reportTemplate->textValue('by_order_number') }}" aria-label="by_order_number">
</div>
</div>
@ -312,9 +312,9 @@
<div class="form-group purchase-range">
<label for="purchase_start" class="col-md-3 control-label">{{ trans('general.purchase_date') }} {{ trans('general.range') }}</label>
<div class="input-daterange input-group col-md-6" id="datepicker">
<input type="text" class="form-control" name="purchase_start" aria-label="purchase_start" value="{{ $savedReport->textValue('purchase_start') }}">
<input type="text" class="form-control" name="purchase_start" aria-label="purchase_start" value="{{ $reportTemplate->textValue('purchase_start') }}">
<span class="input-group-addon">to</span>
<input type="text" class="form-control" name="purchase_end" aria-label="purchase_end" value="{{ $savedReport->textValue('purchase_end') }}">
<input type="text" class="form-control" name="purchase_end" aria-label="purchase_end" value="{{ $reportTemplate->textValue('purchase_end') }}">
</div>
</div>
@ -322,9 +322,9 @@
<div class="form-group purchase-range">
<label for="created_start" class="col-md-3 control-label">{{ trans('general.created_at') }} {{ trans('general.range') }}</label>
<div class="input-daterange input-group col-md-6" id="datepicker">
<input type="text" class="form-control" name="created_start" aria-label="created_start" value="{{ $savedReport->textValue('created_start') }}">
<input type="text" class="form-control" name="created_start" aria-label="created_start" value="{{ $reportTemplate->textValue('created_start') }}">
<span class="input-group-addon">to</span>
<input type="text" class="form-control" name="created_end" aria-label="created_end" value="{{ $savedReport->textValue('created_end') }}">
<input type="text" class="form-control" name="created_end" aria-label="created_end" value="{{ $reportTemplate->textValue('created_end') }}">
</div>
</div>
@ -332,9 +332,9 @@
<div class="form-group checkout-range">
<label for="checkout_date" class="col-md-3 control-label">{{ trans('general.checkout') }} {{ trans('general.range') }}</label>
<div class="input-daterange input-group col-md-6" id="datepicker">
<input type="text" class="form-control" name="checkout_date_start" aria-label="checkout_date_start" value="{{ $savedReport->textValue('checkout_date_start') }}">
<input type="text" class="form-control" name="checkout_date_start" aria-label="checkout_date_start" value="{{ $reportTemplate->textValue('checkout_date_start') }}">
<span class="input-group-addon">to</span>
<input type="text" class="form-control" name="checkout_date_end" aria-label="checkout_date_end" value="{{ $savedReport->textValue('checkout_date_end') }}">
<input type="text" class="form-control" name="checkout_date_end" aria-label="checkout_date_end" value="{{ $reportTemplate->textValue('checkout_date_end') }}">
</div>
</div>
@ -342,9 +342,9 @@
<div class="form-group expected_checkin-range">
<label for="expected_checkin_start" class="col-md-3 control-label">{{ trans('admin/hardware/form.expected_checkin') }}</label>
<div class="input-daterange input-group col-md-6" id="datepicker">
<input type="text" class="form-control" name="expected_checkin_start" aria-label="expected_checkin_start" value="{{ $savedReport->textValue('expected_checkin_start') }}">
<input type="text" class="form-control" name="expected_checkin_start" aria-label="expected_checkin_start" value="{{ $reportTemplate->textValue('expected_checkin_start') }}">
<span class="input-group-addon">to</span>
<input type="text" class="form-control" name="expected_checkin_end" aria-label="expected_checkin_end" value="{{ $savedReport->textValue('expected_checkin_end') }}">
<input type="text" class="form-control" name="expected_checkin_end" aria-label="expected_checkin_end" value="{{ $reportTemplate->textValue('expected_checkin_end') }}">
</div>
</div>
@ -352,9 +352,9 @@
<div class="form-group last_audit-range">
<label for="last_audit_start" class="col-md-3 control-label">{{ trans('general.last_audit') }}</label>
<div class="input-daterange input-group col-md-6" id="datepicker">
<input type="text" class="form-control" name="last_audit_start" aria-label="last_audit_start" value="{{ $savedReport->textValue('last_audit_start') }}">
<input type="text" class="form-control" name="last_audit_start" aria-label="last_audit_start" value="{{ $reportTemplate->textValue('last_audit_start') }}">
<span class="input-group-addon">to</span>
<input type="text" class="form-control" name="last_audit_end" aria-label="last_audit_end" value="{{ $savedReport->textValue('last_audit_end') }}">
<input type="text" class="form-control" name="last_audit_end" aria-label="last_audit_end" value="{{ $reportTemplate->textValue('last_audit_end') }}">
</div>
</div>
@ -362,36 +362,36 @@
<div class="form-group next_audit-range">
<label for="next_audit_start" class="col-md-3 control-label">{{ trans('general.next_audit_date') }}</label>
<div class="input-daterange input-group col-md-6" id="datepicker">
<input type="text" class="form-control" name="next_audit_start" aria-label="nex_audit_start" value="{{ $savedReport->textValue('next_audit_start') }}">
<input type="text" class="form-control" name="next_audit_start" aria-label="nex_audit_start" value="{{ $reportTemplate->textValue('next_audit_start') }}">
<span class="input-group-addon">to</span>
<input type="text" class="form-control" name="next_audit_end" aria-label="next_audit_end" value="{{ $savedReport->textValue('next_audit_end') }}">
<input type="text" class="form-control" name="next_audit_end" aria-label="next_audit_end" value="{{ $reportTemplate->textValue('next_audit_end') }}">
</div>
</div>
<div class="col-md-9 col-md-offset-3">
<label class="form-control">
{{ Form::checkbox('exclude_archived', '1', $savedReport->checkmarkValue('exclude_archived')) }}
{{ Form::checkbox('exclude_archived', '1', $reportTemplate->checkmarkValue('exclude_archived')) }}
{{ trans('general.exclude_archived') }}
</label>
</div>
<div class="col-md-9 col-md-offset-3">
<label class="form-control">
{{ Form::checkbox('use_bom', '1', $savedReport->checkmarkValue('use_bom')) }}
{{ Form::checkbox('use_bom', '1', $reportTemplate->checkmarkValue('use_bom')) }}
{{ trans('general.bom_remark') }}
</label>
</div>
<div class="col-md-9 col-md-offset-3">
<label class="form-control">
{{ Form::radio('deleted_assets', '', $savedReport->radioValue('deleted_assets', null, true), ['aria-label'=>'deleted_assets', 'id'=>'deleted_assets_exclude_deleted'])}}
{{ Form::radio('deleted_assets', '', $reportTemplate->radioValue('deleted_assets', null, true), ['aria-label'=>'deleted_assets', 'id'=>'deleted_assets_exclude_deleted'])}}
{{ trans('general.exclude_deleted') }}
</label>
<label class="form-control">
{{ Form::radio('deleted_assets', '1', $savedReport->radioValue('deleted_assets', '1', '1'), ['aria-label'=>'deleted_assets', 'id'=>'deleted_assets_include_deleted']) }}
{{ Form::radio('deleted_assets', '1', $reportTemplate->radioValue('deleted_assets', '1', '1'), ['aria-label'=>'deleted_assets', 'id'=>'deleted_assets_include_deleted']) }}
{{ trans('general.include_deleted') }}
</label>
<label class="form-control">
{{ Form::radio('deleted_assets', '0', $savedReport->radioValue('deleted_assets', '0', '1'), ['aria-label'=>'deleted_assets','id'=>'deleted_assets_only_deleted']) }}
{{ Form::radio('deleted_assets', '0', $reportTemplate->radioValue('deleted_assets', '0', '1'), ['aria-label'=>'deleted_assets','id'=>'deleted_assets_only_deleted']) }}
{{ trans('general.only_deleted') }}
</label>
</div>
@ -411,12 +411,12 @@
</div>
<div class="col-md-2">
@if (! request()->routeIs('saved-templates.edit'))
@if (! request()->routeIs('report-templates.edit'))
<div style=padding-bottom:5px>
<form method="post" id="savetemplateform" action="{{ route("savedreports/store") }}">
<form method="post" id="savetemplateform" action="{{ route("report-templates.store") }}">
@csrf
<input type="hidden" id="savetemplateform" name="options">
<input type="text" id="name" name="name" value="{{ $savedReport->name }}"> {{--this means that the name of a loaded report is in the input box. could lead to confusion with update--}}
<input type="text" id="name" name="name" value="{{ $reportTemplate->name }}"> {{--this means that the name of a loaded report is in the input box. could lead to confusion with update--}}
<button class="btn btn-primary" style="width: 100%">
{{ trans('admin/reports/general.save_template') }}
</button>
@ -424,11 +424,6 @@
</div>
<div style=padding-bottom:5px>
{{-- <a href="#" class="js-data-ajax" data-toggle="dropdown" tabindex="-1" data-placeholder="{{ trans('admin/reports/general.saved_reports')}}" style="width:100%">--}}
{{-- {{ trans('admin/reports/general.select_template') }}--}}
{{-- <strong class="caret"></strong>--}}
{{-- </a>--}}
{{-- {!! Form::select('brand', array('1'=>'Text','2'=>'Logo','3'=>'Logo + Text'), old('brand', $setting->brand), array('class' => 'form-control select2', 'style'=>'width: 150px ;')) !!}--}}
<select
id="saved_report_select"
class="form-control select2"
@ -436,9 +431,9 @@
data-allow-clear="true"
>
<option></option>
@foreach($saved_reports as $report)
<option value="{{ $report->id }}" @if (request()->input('report') == $report->id) selected @endif>
{{ $report->name }}
@foreach($report_templates as $template)
<option value="{{ $template->id }}" @if (request()->input('report') == $template->id) selected @endif>
{{ $template->name }}
</option>
@endforeach
</select>
@ -447,10 +442,10 @@
{{-- <button type="submit" class="btn btn-success" style="width: 32%">--}}
{{-- <i class="fas fa-download icon-white" aria-hidden="true"></i>--}}
{{-- </button>--}}
{{-- <form method="post" id="savetemplateform" action="{{ route("savedreports/update") }}">--}}
{{-- <form method="post" id="savetemplateform" action="{{ route("report-templates.update") }}">--}}
{{-- @csrf--}}
{{-- <input type="hidden" id="savetemplateform" name="options">--}}
{{-- <input type="hidden" id="name" name="name" value="{{ $savedReport->name }},1git ">--}}
{{-- <input type="hidden" id="name" name="name" value="{{ $reportTemplate->name }},1git ">--}}
{{-- <button class="btn btn-primary" style="width: 32%">--}}
{{-- {{ "update" }}--}}
{{-- </button>--}}
@ -529,7 +524,7 @@
value: $('#name').val(),
}).appendTo(form);
form.attr('action', '/reports/savedtemplate').submit();
form.attr('action', '{{ route('report-templates.store') }}').submit();
});
</script>

View file

@ -16,7 +16,7 @@ use App\Http\Controllers\ManufacturersController;
use App\Http\Controllers\ModalController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\ReportsController;
use App\Http\Controllers\SavedReportsController;
use App\Http\Controllers\ReportTemplatesController;
use App\Http\Controllers\SettingsController;
use App\Http\Controllers\StatuslabelsController;
use App\Http\Controllers\SuppliersController;
@ -357,11 +357,9 @@ Route::group(['middleware' => ['auth']], function () {
)->name('reports/export/accessories');
Route::get('reports/custom', [ReportsController::class, 'getCustomReport'])->name('reports/custom');
Route::post('reports/custom', [ReportsController::class, 'postCustom']);
// @todo: change to saved-template?
Route::post('reports/savedtemplate', [SavedReportsController::class, 'store'])->name('savedreports/store');
// @todo: starting the process of adding "-" to saved-template...
Route::get('reports/saved-templates/{reportId}/edit', [SavedReportsController::class, 'edit'])->name('saved-templates.edit');
Route::put('report/savedtemplate', [SavedReportsController::class, 'update'])->name('savedreports/update');
Route::post('reports/saved-templates', [ReportTemplatesController::class, 'store'])->name('report-templates.store');
Route::get('reports/saved-templates/{reportId}/edit', [ReportTemplatesController::class, 'edit'])->name('report-templates.edit');
Route::post('report/saved-templates/{reportId}', [ReportTemplatesController::class, 'update'])->name('report-templates.update');
Route::get(
'reports/activity',

View file

@ -1,13 +1,13 @@
<?php
namespace Tests\Feature\SavedReports;
namespace Tests\Feature\ReportTemplates;
use App\Models\SavedReport;
use App\Models\ReportTemplate;
use App\Models\User;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class SavedReportsTest extends TestCase
class ReportTemplateTest extends TestCase
{
use InteractsWithSettings;
@ -16,7 +16,7 @@ class SavedReportsTest extends TestCase
$this->actingAs(User::factory()->canViewReports()->create())
->get(route('reports/custom'))
->assertOk()
->assertViewHas(['savedReport' => function (SavedReport $report) {
->assertViewHas(['reportTemplate' => function (ReportTemplate $report) {
// the view should have an empty report by default
return $report->exists() === false;
}]);
@ -25,14 +25,14 @@ class SavedReportsTest extends TestCase
public function testCanLoadASavedCustomReport()
{
$user = User::factory()->canViewReports()->create();
$savedReport = SavedReport::factory()->make(['name' => 'My Awesome Report']);
$user->savedReports()->save($savedReport);
$reportTemplate = ReportTemplate::factory()->make(['name' => 'My Awesome Report']);
$user->reportTemplates()->save($reportTemplate);
$this->actingAs($user)
->get(route('reports/custom', ['report' => $savedReport->id]))
->get(route('reports/custom', ['report' => $reportTemplate->id]))
->assertOk()
->assertViewHas(['savedReport' => function (SavedReport $viewReport) use ($savedReport) {
return $viewReport->is($savedReport);
->assertViewHas(['reportTemplate' => function (ReportTemplate $viewReport) use ($reportTemplate) {
return $viewReport->is($reportTemplate);
}]);
}
@ -41,26 +41,26 @@ class SavedReportsTest extends TestCase
$user = User::factory()->canViewReports()->create();
$this->actingAs($user)
->post(route('savedreports/store'), [
->post(route('report-templates.store'), [
'name' => 'My Awesome Report',
'company' => '1',
'by_company_id' => ['1', '2'],
])
->assertRedirect();
$report = $user->savedReports->first(function ($report) {
$template = $user->reportTemplates->first(function ($report) {
return $report->name === 'My Awesome Report';
});
$this->assertNotNull($report);
$this->assertEquals('1', $report->options['company']);
$this->assertEquals(['1', '2'], $report->options['by_company_id']);
$this->assertNotNull($template);
$this->assertEquals('1', $template->options['company']);
$this->assertEquals(['1', '2'], $template->options['by_company_id']);
}
public function testSavingReportRequiresValidFields()
{
$this->actingAs(User::factory()->canViewReports()->create())
->post(route('savedreports/store'), [
->post(route('report-templates.store'), [
//
])
->assertSessionHasErrors('name');
@ -69,7 +69,7 @@ class SavedReportsTest extends TestCase
public function testSavingReportRequiresCorrectPermission()
{
$this->actingAs(User::factory()->create())
->post(route('savedreports/store'))
->post(route('report-templates.store'))
->assertForbidden();
}
}

View file

@ -2,14 +2,14 @@
namespace Tests\Unit;
use App\Models\SavedReport;
use App\Models\ReportTemplate;
use Tests\TestCase;
class SavedReportTest extends TestCase
class ReportTemplateTest extends TestCase
{
public function testParsingCheckmarkValue()
{
$savedReport = SavedReport::factory()->create([
$savedReport = ReportTemplate::factory()->create([
'options' => [
'is_a_checkbox_field' => '1',
],
@ -18,12 +18,12 @@ class SavedReportTest extends TestCase
$this->assertEquals('1', $savedReport->checkmarkValue('is_a_checkbox_field'));
$this->assertEquals('0', $savedReport->checkmarkValue('non_existent_key'));
$this->assertEquals('1', (new SavedReport)->checkmarkValue('is_a_checkbox_field'));
$this->assertEquals('1', (new ReportTemplate)->checkmarkValue('is_a_checkbox_field'));
}
public function testParsingTextValue()
{
$savedReport = SavedReport::factory()->create([
$savedReport = ReportTemplate::factory()->create([
'options' => [
'is_a_text_field' => 'some text',
],
@ -32,12 +32,12 @@ class SavedReportTest extends TestCase
$this->assertEquals('some text', $savedReport->textValue('is_a_text_field'));
$this->assertEquals('', $savedReport->textValue('non_existent_key'));
$this->assertEquals('', (new SavedReport)->textValue('is_a_text_field'));
$this->assertEquals('', (new ReportTemplate)->textValue('is_a_text_field'));
}
public function testParsingRadioValue()
{
$savedReport = SavedReport::factory()->create([
$savedReport = ReportTemplate::factory()->create([
'options' => [
'is_a_radio_field' => null,
],
@ -50,7 +50,7 @@ class SavedReportTest extends TestCase
public function testParsingSelectValue()
{
$savedReport = SavedReport::factory()->create([
$savedReport = ReportTemplate::factory()->create([
'options' => [
'is_a_text_field_as_well' => '4',
'contains_a_null_value' => null,
@ -64,7 +64,7 @@ class SavedReportTest extends TestCase
public function testParsingSelectValues()
{
$savedReport = SavedReport::factory()->create([
$savedReport = ReportTemplate::factory()->create([
'options' => [
'is_an_array' => ['2', '3', '4'],
'is_an_array_containing_null' => [null],