Updated more form fields

This commit is contained in:
snipe
2025-11-01 02:45:59 +00:00
parent 7161d56ae2
commit 80e4e4a40e
10 changed files with 277 additions and 132 deletions

View File

@@ -20,6 +20,13 @@ class SnipeModel extends Model
$this->attributes['purchase_date'] = $value;
}
protected function purchaseDateForDatepicker(): Attribute
{
return Attribute:: make(
get: fn(mixed $value, array $attributes) => $attributes['purchase_date'] ? Carbon::parse($attributes['purchase_date'])->format('Y-m-d') : null,
);
}
protected function purchaseDateFormatted(): Attribute
{

View File

@@ -0,0 +1,7 @@
<!-- Help Text -->
<div {{ $attributes->merge(['class' => 'col-md-8 col-md-offset-3']) }}>
<p class="help-block">
{{ $slot }}
</p>
</div>

View File

@@ -0,0 +1,7 @@
<!-- Info Tooltip -->
<div class="col-md-1 text-left" style="padding-left:0; margin-top: 5px;">
<x-form-tooltip>
{{ $slot }}
</x-form-tooltip>
</div>

View File

@@ -4,7 +4,36 @@
'class' => 'col-md-8',
])
<?php
// Let's set some sane defaults here for smaller fields
// This uses the form name to determine the appropriate class
switch ($name) {
case 'qty':
case 'min_amt':
case 'seats':
$class = 'col-md-3';
break;
case 'purchase_cost':
case 'purchase_date':
case 'termination_date':
case 'expiration_date':
case 'start_date':
case 'end_date':
$class = 'col-md-5';
break;
case 'model_number':
case 'item_no':
case 'order_number':
case 'purchase_order':
$class = 'col-md-6';
break;
default:
$class = 'col-md-8';
break;
}
?>
<!-- form-input blade component -->
<div {{ $attributes->merge(['class' => $class]) }}>
{{ $slot }}
@@ -18,4 +47,6 @@
{{ $message }}
</span>
</div>
@enderror

View File

@@ -7,6 +7,7 @@
'selected' => null,
'includeEmpty' => false,
'forLivewire' => false,
'name' => null
])
<select

View File

@@ -2,6 +2,7 @@
@props([
'value' => null,
'rows' => 5,
'name' => null,
])
<textarea

View File

@@ -4,6 +4,7 @@
'helpPosition' => 'right',
'helpText' => trans('help.components'),
'formAction' => (isset($item->id)) ? route('components.update', ['component' => $item->id]) : route('components.store'),
'container_classes' => 'col-lg-6 col-lg-offset-3 col-md-10 col-md-offset-1 col-sm-12 col-sm-offset-0',
'index_route' => 'components.index',
'options' => [
'back' => trans('admin/hardware/form.redirect_to_type',['type' => trans('general.previous_page')]),
@@ -18,8 +19,35 @@
@include ('partials.forms.edit.name', ['translated_name' => trans('admin/components/table.title')])
@include ('partials.forms.edit.category-select', ['translated_name' => trans('general.category'), 'fieldname' => 'category_id','category_type' => 'component'])
@include ('partials.forms.edit.quantity')
@include ('partials.forms.edit.minimum_quantity')
<!-- QTY -->
<x-form-row name="qty">
<x-form-label>{{ trans('general.quantity') }}</x-form-label>
<x-form-input class="col-md-5">
<x-input.text
type="number"
:value="old('qty', $item->qty)"
input_min="1"
required="true"
/>
</x-form-input>
</x-form-row>
<!-- Minimum QTY -->
<x-form-row name="min_amt">
<x-form-label>{{ trans('general.min_amt') }}</x-form-label>
<x-form-input class="col-md-5">
<x-input.text
type="number"
:value="old('min_amt', $item->min_amt)"
input_min="0"
/>
</x-form-input>
<x-form-inline-tooltip>
{{ trans('general.min_amt_help') }}
</x-form-inline-tooltip>
</x-form-row>
@include ('partials.forms.edit.serial', ['fieldname' => 'serial'])
@include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'manufacturer_id'])
@include ('partials.forms.edit.model_number')

View File

@@ -18,11 +18,15 @@
@include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id'])
<!-- Name -->
<x-form-row
:label="trans('general.name')"
:$item
name="name"
/>
<x-form-row name="name">
<x-form-label>{{ trans('general.name') }}</x-form-label>
<x-form-input>
<x-input.text
required="true"
:value="old('name', $item->name)"
/>
</x-form-input>
</x-form-row>
@include ('partials.forms.edit.category-select', ['translated_name' => trans('general.category'), 'fieldname' => 'category_id', 'required' => 'true', 'category_type' => 'consumable'])
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id'])
@@ -30,80 +34,96 @@
@include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id'])
<!-- Model Number -->
<x-form-row
:label="trans('general.model_no')"
:$item
name="model_number"
/>
<x-form-row name="model_number">
<x-form-label>{{ trans('general.model_no') }}</x-form-label>
<x-form-input>
<x-input.text :value="old('model_number', $item->model_number)"
/>
</x-form-input>
</x-form-row>
<!-- Item Number -->
<x-form-row name="item_no">
<x-form-label>{{ trans('admin/consumables/general.item_no') }}</x-form-label>
<x-form-input>
<x-input.text :value="old('item_no', $item->item_no)" />
</x-form-input>
</x-form-row>
@include ('partials.forms.edit.item_number')
<!-- Order Number -->
<x-form-row
:label="trans('general.order_number')"
:$item
name="order_number"
/>
<x-form-row name="order_number">
<x-form-label>{{ trans('general.order_number') }}</x-form-label>
<x-form-input>
<x-input.text :value="old('order_number', $item->order_number)" />
</x-form-input>
</x-form-row>
<!--- Purchase Date -->
<x-form-row
:label="trans('general.purchase_date')"
:$item
name="purchase_date"
type="datepicker"
input_div_class="col-md-5"
input_icon="email"
input_group_addon="left"
/>
<x-form-row name="purchase_date">
<x-form-label>{{ trans('general.purchase_date') }}</x-form-label>
<x-form-input>
<x-input.datepicker :value="old('purchase_date', $item->purchase_date_for_datepicker)" />
</x-form-input>
</x-form-row>
<!-- Purchase Cost -->
<x-form-row
:label="trans('general.unit_cost')"
:$item
name="purchase_cost"
type="number"
input_div_class="col-md-5"
input_min="0"
input_group_text="{{ $snipeSettings->default_currency }}"
input_group_addon="left"
maxlength="25"
input_max="99999999999999999.000"
input_min="0.00"
input_step="0.001"
/>
<x-form-row name="purchase_cost">
<x-form-label>{{ trans('general.unit_cost') }}</x-form-label>
<x-form-input>
<x-input.text
type="number"
:input_group_text="$snipeSettings->default_currency"
:value="old('purchase_cost', $item->purchase_cost)"
input_group_addon="left"
input_max="99999999999999999.000"
input_min="0"
input_min="0.00"
input_step="0.001"
maxlength="25"
/>
</x-form-input>
</x-form-row>
<!-- QTY -->
<x-form-row
:label="trans('general.quantity')"
:$item
name="qty"
type="number"
input_div_class="col-md-4"
input_min="1"
/>
<x-form-row name="qty">
<x-form-label>{{ trans('general.quantity') }}</x-form-label>
<x-form-input>
<x-input.text
type="number"
:value="old('qty', $item->qty)"
input_min="1"
required="true"
/>
</x-form-input>
</x-form-row>
<!-- Minimum QTY -->
<x-form-row
:label="trans('general.min_amt')"
:$item
name="min_amt"
type="number"
input_div_class="col-md-4 col-xs-9"
info_tooltip_text="{{ trans('general.min_amt_help') }}"
input_min="0"
<x-form-row name="min_amt">
<x-form-label>{{ trans('general.min_amt') }}</x-form-label>
<x-form-input>
<x-input.text
type="number"
:value="old('min_amt', $item->min_amt)"
input_min="0"
/>
</x-form-input>
<x-form-inline-tooltip>
{{ trans('general.min_amt_help') }}
</x-form-inline-tooltip>
</x-form-row>
/>
<!-- Notes -->
<x-form-row
:label="trans('general.notes')"
:$item
name="notes"
type="textarea"
placeholder="{{ trans('general.placeholders.notes') }}"
/>
<x-form-row name="notes">
<x-form-label>{{ trans('general.notes') }}</x-form-label>
<x-form-input>
<x-input.textarea
:value="old('notes', $item->notes)"
placeholder="{{ trans('general.placeholders.notes') }}"
/>
</x-form-input>
</x-form-row>
@include ('partials.forms.edit.image-upload', ['image_path' => app('consumables_upload_path')])

View File

@@ -4,6 +4,7 @@
'topSubmit' => true,
'formAction' => ($item->id) ? route('licenses.update', ['license' => $item->id]) : route('licenses.store'),
'index_route' => 'licenses.index',
'container_classes' => 'col-lg-6 col-lg-offset-3 col-md-10 col-md-offset-1 col-sm-12 col-sm-offset-0',
'options' => [
'back' => trans('admin/hardware/form.redirect_to_type',['type' => trans('general.previous_page')]),
'index' => trans('admin/hardware/form.redirect_to_all', ['type' => 'licenses']),
@@ -15,29 +16,50 @@
@section('inputFields')
<!-- Name -->
<x-form-row
:label="trans('general.name')"
:$item
name="name"
/>
<x-form-row name="name">
<x-form-label>{{ trans('general.name') }}</x-form-label>
<x-form-input>
<x-input.text
required="true"
:value="old('name', $item->name)"
/>
</x-form-input>
</x-form-row>
@include ('partials.forms.edit.category-select', ['translated_name' => trans('admin/categories/general.category_name'), 'fieldname' => 'category_id', 'required' => 'true', 'category_type' => 'license'])
<!-- Seats -->
<div class="form-group {{ $errors->has('seats') ? ' has-error' : '' }}">
<label for="seats" class="col-md-3 control-label">{{ trans('admin/licenses/form.seats') }}</label>
<div class="col-md-7 col-sm-12">
<div class="col-md-12" style="padding-left:0px">
<input class="form-control" type="text" name="seats" id="seats" value="{{ old('seats', $item->seats) }}" minlength="1" required style="width: 97px;">
</div>
</div>
{!! $errors->first('seats', '<div class="col-md-8 col-md-offset-3"><span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span></div>') !!}
</div>
@include ('partials.forms.edit.minimum_quantity')
<!-- Seats -->
<x-form-row name="seats">
<x-form-label>{{ trans('admin/licenses/form.seats') }}</x-form-label>
<x-form-input>
<x-input.text
type="number"
:value="old('seats', $item->seats)"
input_min="1"
required="true"
/>
</x-form-input>
</x-form-row>
<!-- Serial-->
<!-- Minimum QTY -->
<x-form-row name="min_amt">
<x-form-label>{{ trans('general.min_amt') }}</x-form-label>
<x-form-input>
<x-input.text
type="number"
:value="old('min_amt', $item->min_amt)"
input_min="0"
/>
</x-form-input>
<x-form-inline-tooltip>
{{ trans('general.min_amt_help') }}
</x-form-inline-tooltip>
</x-form-row>
<!-- Serial-->
@can('viewKeys', $item)
<div class="form-group {{ $errors->has('serial') ? ' has-error' : '' }}">
<label for="serial" class="col-md-3 control-label">{{ trans('admin/licenses/form.license_key') }}</label>
@@ -84,46 +106,71 @@
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id'])
@include ('partials.forms.edit.order_number')
@include ('partials.forms.edit.purchase_cost')
@include ('partials.forms.edit.datepicker', ['translated_name' => trans('general.purchase_date'),'fieldname' => 'purchase_date'])
<!-- Order Number -->
<x-form-row name="order_number">
<x-form-label>{{ trans('general.order_number') }}</x-form-label>
<x-form-input>
<x-input.text :value="old('order_number', $item->order_number)" />
</x-form-input>
</x-form-row>
{{-- @TODO How does this differ from Order #? --}}
<!-- Purchase Order -->
<x-form-row name="purchase_order">
<x-form-label>{{ trans('admin/licenses/form.purchase_order') }}</x-form-label>
<x-form-input>
<x-input.text :value="old('purchase_order', $item->purchase_order)" />
</x-form-input>
</x-form-row>
<!-- Purchase Cost -->
<x-form-row name="purchase_cost">
<x-form-label>{{ trans('general.unit_cost') }}</x-form-label>
<x-form-input>
<x-input.text
type="number"
:input_group_text="$snipeSettings->default_currency"
:value="old('purchase_cost', $item->purchase_cost)"
input_group_addon="left"
input_max="99999999999999999.000"
input_min="0"
input_min="0.00"
input_step="0.001"
maxlength="25"
/>
</x-form-input>
</x-form-row>
<!--- Purchase Date -->
<x-form-row name="purchase_date">
<x-form-label>{{ trans('general.purchase_date') }}</x-form-label>
<x-form-input>
<x-input.datepicker
:value="old('purchase_date', $item->purchase_date_for_datepicker)"
input_group_addon="left"/>
</x-form-input>
</x-form-row>
<!-- Expiration Date -->
<div class="form-group {{ $errors->has('expiration_date') ? ' has-error' : '' }}">
<label for="expiration_date" class="col-md-3 control-label">{{ trans('admin/licenses/form.expiration') }}</label>
<div class="input-group col-md-4">
<div class="input-group date" data-provide="datepicker" data-date-format="yyyy-mm-dd" data-autoclose="true" data-date-clear-btn="true">
<input type="text" class="form-control" placeholder="{{ trans('general.select_date') }}" name="expiration_date" id="expiration_date" value="{{ old('expiration_date', ($item->expiration_date) ? $item->expiration_date->format('Y-m-d') : '') }}" maxlength="10">
<span class="input-group-addon"><x-icon type="calendar" /></span>
</div>
{!! $errors->first('expiration_date', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>
<x-form-row name="expiration_date">
<x-form-label>{{ trans('admin/licenses/form.expiration') }}</x-form-label>
<x-form-input>
<x-input.datepicker :value="old('expiration_date', $item->expiration_date)" />
</x-form-input>
</x-form-row>
<!-- Termination Date -->
<div class="form-group {{ $errors->has('termination_date') ? ' has-error' : '' }}">
<label for="termination_date" class="col-md-3 control-label">{{ trans('admin/licenses/form.termination_date') }}</label>
<x-form-row name="termination_date">
<x-form-label>{{ trans('admin/licenses/form.termination_date') }}</x-form-label>
<x-form-input>
<x-input.datepicker :value="old('termination_date', $item->termination_date)" />
</x-form-input>
</x-form-row>
<div class="input-group col-md-4">
<div class="input-group date" data-provide="datepicker" data-date-format="yyyy-mm-dd" data-autoclose="true" data-date-clear-btn="true">
<input type="text" class="form-control" placeholder="{{ trans('general.select_date') }}" name="termination_date" id="termination_date" value="{{ old('termination_date', ($item->termination_date) ? $item->termination_date->format('Y-m-d') : '') }}" maxlength="10">
<span class="input-group-addon"><x-icon type="calendar" /></span>
</div>
{!! $errors->first('termination_date', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>
{{-- @TODO How does this differ from Order #? --}}
<!-- Purchase Order -->
<div class="form-group {{ $errors->has('purchase_order') ? ' has-error' : '' }}">
<label for="purchase_order" class="col-md-3 control-label">{{ trans('admin/licenses/form.purchase_order') }}</label>
<div class="col-md-3 text-right">
<input class="form-control" type="text" name="purchase_order" id="purchase_order" value="{{ old('purchase_order', $item->purchase_order) }}" maxlength="191" />
{!! $errors->first('purchase_order', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>
@include ('partials.forms.edit.depreciation')
@@ -139,12 +186,14 @@
</div>
<!-- Notes -->
<x-form-row
:label="trans('general.notes')"
:$item
name="notes"
type="textarea"
placeholder="{{ trans('general.placeholders.notes') }}"
/>
<x-form-row name="notes">
<x-form-label>{{ trans('general.notes') }}</x-form-label>
<x-form-input>
<x-input.textarea
:value="old('notes', $item->notes)"
placeholder="{{ trans('general.placeholders.notes') }}"
/>
</x-form-input>
</x-form-row>
@stop

View File

@@ -11,19 +11,13 @@
@stop
@section('header_right')
<a href="{{ URL::previous() }}" class="btn btn-primary pull-right">
{{ trans('general.back') }}</a>
@stop
{{-- Page content --}}
@section('content')
<div class="row">
<!-- Inititate form component -->
<!-- Initiate form component -->
<x-form :$item update_route="maintenances.update" create_route="maintenances.store">
<!-- Start box component -->