@php // Restore the saved intermediate state. The user-typed ratio // (1 Baby Box = 10 Strips) is not stored; we reverse-compute // it from the persisted base_unit_multiplier (100) divided by // the intermediate unit's own base_unit_multiplier (10) = 10. $saved_intermediate_unit = $unit->intermediate_unit_id ? $sub_units->get($unit->intermediate_unit_id) : null; $saved_intermediate_multiplier = null; if ($saved_intermediate_unit && $saved_intermediate_unit->base_unit_multiplier) { $saved_intermediate_multiplier = (float) $unit->base_unit_multiplier / (float) $saved_intermediate_unit->base_unit_multiplier; } @endphp {!! Form::open(['url' => action([\App\Http\Controllers\UnitController::class, 'update'], [$unit->id]), 'method' => 'PUT', 'id' => 'unit_edit_form' ]) !!}

@lang( 'unit.edit_unit' )

{!! Form::label('actual_name', __( 'unit.name' ) . ':*') !!} {!! Form::text('actual_name', $unit->actual_name, ['class' => 'form-control', 'required', 'placeholder' => __( 'unit.name' )]); !!}
{!! Form::label('short_name', __( 'unit.short_name' ) . ':*') !!} {!! Form::text('short_name', $unit->short_name, ['class' => 'form-control', 'placeholder' => __( 'unit.short_name' ), 'required']); !!}
{!! Form::label('allow_decimal', __( 'unit.allow_decimal' ) . ':*') !!} {!! Form::select('allow_decimal', ['1' => __('messages.yes'), '0' => __('messages.no')], $unit->allow_decimal, ['placeholder' => __( 'messages.please_select' ), 'required', 'class' => 'form-control']); !!}
@show_tooltip(__('lang_v1.multi_unit_help'))
1 {{$unit->actual_name}} = {!! Form::text('base_unit_multiplier', !empty($unit->base_unit_multiplier) ? @number_format($unit->base_unit_multiplier) : null, ['class' => 'form-control input_number', 'id' => 'base_unit_multiplier', 'placeholder' => __( 'lang_v1.times_base_unit' )]); !!} {!! Form::select('base_unit_id', $units, $unit->base_unit_id, ['placeholder' => __( 'lang_v1.select_base_unit' ), 'class' => 'form-control', 'id' => 'base_unit_id_select']); !!}

*@lang('lang_v1.edit_multi_unit_help_text')

{{-- Intermediate unit helper --}} @if($sub_units->count() > 0)
@show_tooltip(__('unit.intermediate_unit_help'))
1 {{$unit->actual_name}} = {!! Form::text('intermediate_multiplier', $saved_intermediate_multiplier !== null ? @number_format($saved_intermediate_multiplier, 4, '.', '') : null, ['class' => 'form-control input_number', 'id' => 'intermediate_multiplier', 'placeholder' => __('unit.quantity')]); !!}

@endif
{!! Form::close() !!} {{-- On edit-modal-open, if the unit was saved with an intermediate, fire the auto-fill so the preview line and the base_unit_multiplier field stay in sync. --}} @if(!empty($saved_intermediate_unit)) @endif