@extends('layouts.app') @section('title', __('product.edit_product')) @section('content') @php $is_image_required = !empty($common_settings['is_product_image_required']) && empty($product->image); @endphp

@lang('product.edit_product')

{!! Form::open(['url' => action([\App\Http\Controllers\ProductController::class, 'update'] , [$product->id] ), 'method' => 'PUT', 'id' => 'product_add_form', 'class' => 'product_form', 'files' => true ]) !!} @component('components.widget', ['class' => 'box-primary'])
{!! Form::label('name', __('product.product_name') . ':*') !!} {!! Form::text('name', $product->name, ['class' => 'form-control', 'required', 'placeholder' => __('product.product_name')]); !!}
{!! Form::label('sku', __('product.sku') . ':*') !!} @show_tooltip(__('tooltip.sku')) {!! Form::text('sku', $product->sku, ['class' => 'form-control', 'placeholder' => __('product.sku'), 'required']); !!}
{!! Form::label('barcode_type', __('product.barcode_type') . ':*') !!} {!! Form::select('barcode_type', $barcode_types, $product->barcode_type, ['placeholder' => __('messages.please_select'), 'class' => 'form-control select2', 'required']); !!}
{!! Form::label('unit_id', __('product.unit') . ':*') !!} @show_tooltip(__('product.base_unit_tooltip'))
{!! Form::select('unit_id', $units, $product->unit_id, ['placeholder' => __('messages.please_select'), 'class' => 'form-control select2', 'required']); !!}
{!! Form::label('sub_unit_ids', __('lang_v1.related_sub_units') . ':') !!} @show_tooltip(__('lang_v1.sub_units_tooltip'))
{!! Form::label('default_sell_sub_unit_id', __('lang_v1.default_sell_sub_unit') . ':') !!} @show_tooltip(__('lang_v1.default_sell_sub_unit_help')) @php // Hand-built @foreach($sub_units as $id => $sub_unit_value) @endforeach @if($saved_sell_unit && !isset($sub_units[$saved_sell_id])) @endif
{!! Form::label('default_purchase_sub_unit_id', __('lang_v1.default_purchase_sub_unit') . ':') !!} @show_tooltip(__('lang_v1.default_purchase_sub_unit_help'))
{!! Form::label('sell_sub_unit_ids', __('lang_v1.sell_sub_units') . ':') !!} @show_tooltip(__('lang_v1.sell_sub_units_help')) {!! Form::select('sell_sub_unit_ids[]', [], null, ['class' => 'form-control select2', 'multiple', 'id' => 'sell_sub_unit_ids', 'data-initial' => !empty($product->sell_sub_unit_ids) ? json_encode($product->sell_sub_unit_ids) : null]); !!}
{!! Form::label('purchase_sub_unit_ids', __('lang_v1.purchase_sub_units') . ':') !!} @show_tooltip(__('lang_v1.purchase_sub_units_help')) {!! Form::select('purchase_sub_unit_ids[]', [], null, ['class' => 'form-control select2', 'multiple', 'id' => 'purchase_sub_unit_ids', 'data-initial' => !empty($product->purchase_sub_unit_ids) ? json_encode($product->purchase_sub_unit_ids) : null]); !!}
@if(!empty($common_settings['enable_secondary_unit']))
{!! Form::label('secondary_unit_id', __('lang_v1.secondary_unit') . ':') !!} @show_tooltip(__('lang_v1.secondary_unit_help')) {!! Form::select('secondary_unit_id', $units, $product->secondary_unit_id, ['class' => 'form-control select2']); !!}
@endif
{!! Form::label('brand_id', __('product.brand') . ':') !!}
{!! Form::select('brand_id', $brands, $product->brand_id, ['placeholder' => __('messages.please_select'), 'class' => 'form-control select2']); !!}
{!! Form::label('category_id', __('product.category') . ':') !!} {!! Form::select('category_id', $categories, $product->category_id, ['placeholder' => __('messages.please_select'), 'class' => 'form-control select2']); !!}
{!! Form::label('sub_category_id', __('product.sub_category') . ':') !!} {!! Form::select('sub_category_id', $sub_categories, $product->sub_category_id, ['placeholder' => __('messages.please_select'), 'class' => 'form-control select2']); !!}
{!! Form::label('composition_id', __('composition.composition') . ':') !!} {!! Form::select('composition_id', $compositions, $product->composition_id, ['placeholder' => __('messages.please_select'), 'class' => 'form-control select2']); !!}

@lang('composition.product_form_help')

{!! Form::label('hsn_code', __('lang_v1.hsn_code') . ':') !!} {!! Form::text('hsn_code', $product->hsn_code, ['class' => 'form-control', 'placeholder' => __('lang_v1.hsn_code')]); !!}
{!! Form::label('drug_schedule', __('lang_v1.drug_schedule') . ':') !!} {!! Form::select('drug_schedule', $drug_schedules, $product->drug_schedule, ['placeholder' => __('messages.please_select'), 'class' => 'form-control select2']); !!}
{!! Form::label('dosage_form', __('lang_v1.dosage_form') . ':') !!} {!! Form::select('dosage_form', $dosage_forms, $product->dosage_form, ['placeholder' => __('messages.please_select'), 'class' => 'form-control select2']); !!}
{!! Form::label('storage_condition', __('lang_v1.storage_condition') . ':') !!} {!! Form::select('storage_condition', $storage_conditions, $product->storage_condition, ['placeholder' => __('messages.please_select'), 'class' => 'form-control select2']); !!}
{!! Form::label('mfg_lead_time_days', __('lang_v1.mfg_lead_time_days') . ':') !!} {!! Form::number('mfg_lead_time_days', $product->mfg_lead_time_days, ['class' => 'form-control', 'min' => 0, 'max' => 3650, 'placeholder' => __('lang_v1.days')]); !!} @lang('lang_v1.mfg_lead_time_help')
{!! Form::label('manufacturer_ids', __('lang_v1.manufacturer') . ':') !!} @php // Full mapped set; falls back to the legacy single column for // products created before the pivot existed. $selected_manufacturers = $product->manufacturers->pluck('id')->all(); if (empty($selected_manufacturers) && !empty($product->manufacturer_id)) { $selected_manufacturers = [$product->manufacturer_id]; } @endphp
{!! Form::select('manufacturer_ids[]', $manufacturers, $selected_manufacturers, ['placeholder' => __('messages.please_select'), 'class' => 'form-control select2', 'multiple', 'id' => 'manufacturer_ids']); !!}
@lang('lang_v1.manufacturer_multi_help')
{!! Form::label('primary_manufacturer_id', __('lang_v1.primary_manufacturer') . ':') !!} {!! Form::select('primary_manufacturer_id', $manufacturers, $product->manufacturer_id, ['placeholder' => __('messages.please_select'), 'class' => 'form-control select2', 'id' => 'primary_manufacturer_id']); !!} @lang('lang_v1.primary_manufacturer_help')
{!! Form::label('division_id', __('lang_v1.division') . ':') !!}
{!! Form::select('division_id', $divisions, $product->division_id, ['placeholder' => __('messages.please_select'), 'class' => 'form-control select2']); !!}
{{-- 'Tags' field removed — movement tags are per-store & auto-computed. --}}
{!! Form::label('product_locations', __('business.business_locations') . ':') !!} @show_tooltip(__('lang_v1.product_location_help')) {!! Form::select('product_locations[]', $business_locations, $product->product_locations->pluck('id'), ['class' => 'form-control select2', 'multiple', 'id' => 'product_locations']); !!}

@show_tooltip(__('tooltip.enable_stock'))

@lang('product.enable_stock_help')

{{-- 'Prescription required' removed — derived from Drug Schedule (H/H1/X) on save. --}}



{{-- Alert quantity is no longer entered separately — the low-stock / reorder threshold comes from the per-store Min stock (variation_location_details.min_quantity). Kept as a hidden field to preserve the value and the toggle JS targets. --}} @if(!empty($common_settings['enable_product_warranty']))
{!! Form::label('warranty_id', __('lang_v1.warranty') . ':') !!} {!! Form::select('warranty_id', $warranties, $product->warranty_id, ['class' => 'form-control select2', 'placeholder' => __('messages.please_select')]); !!}
@endif @if(!empty($pos_module_data)) @foreach($pos_module_data as $key => $value) @if(!empty($value['view_path'])) @includeIf($value['view_path'], ['view_data' => $value['view_data']]) @endif @endforeach @endif
{!! Form::label('product_description', __('lang_v1.product_description') . ':') !!} {!! Form::textarea('product_description', $product->product_description, ['class' => 'form-control']); !!}
{!! Form::label('image', __('lang_v1.product_image') . ':') !!} {!! Form::file('image', ['id' => 'upload_image', 'accept' => 'image/*', 'required' => $is_image_required]); !!}

@lang('purchase.max_file_size', ['size' => (config('constants.document_size_limit') / 1000000)]). @lang('lang_v1.aspect_ratio_should_be_1_1') @if(!empty($product->image))
@lang('lang_v1.previous_image_will_be_replaced') @endif

{!! Form::label('product_brochure', __('lang_v1.product_brochure') . ':') !!} {!! Form::file('product_brochure', ['id' => 'product_brochure', 'accept' => implode(',', array_keys(config('constants.document_upload_mimes_types')))]); !!}

@lang('lang_v1.previous_file_will_be_replaced')
@lang('purchase.max_file_size', ['size' => (config('constants.document_size_limit') / 1000000)]) @includeIf('components.document_help_text')

@endcomponent @component('components.widget', ['class' => 'box-primary'])
@if(session('business.enable_product_expiry')) @if(session('business.expiry_type') == 'add_expiry') @php $expiry_period = 12; $hide = true; @endphp @else @php $expiry_period = null; $hide = false; @endphp @endif
@php $disabled = false; $disabled_period = false; if( empty($product->expiry_period_type) || empty($product->enable_stock) ){ $disabled = true; } if( empty($product->enable_stock) ){ $disabled_period = true; } @endphp {!! Form::label('expiry_period', __('product.expires_in') . ':') !!}
{!! Form::text('expiry_period', @num_format($product->expiry_period), ['class' => 'form-control pull-left input_number', 'placeholder' => __('product.expiry_period'), 'style' => 'width:60%;', 'disabled' => $disabled]); !!} {!! Form::select('expiry_period_type', ['months'=>__('product.months'), 'days'=>__('product.days'), '' =>__('product.not_applicable') ], $product->expiry_period_type, ['class' => 'form-control select2 pull-left', 'style' => 'width:40%;', 'id' => 'expiry_period_type', 'disabled' => $disabled_period]); !!}
@endif
@show_tooltip(__('lang_v1.tooltip_sr_no'))
{{-- 'Not for selling' removed — inverse of 'Can be sold'; derived on save. --}}
@if(session('business.enable_racks') || session('business.enable_row') || session('business.enable_position'))

@lang('lang_v1.rack_details'): @show_tooltip(__('lang_v1.tooltip_rack_details'))

@foreach($business_locations as $id => $location)
{!! Form::label('rack_' . $id, $location . ':') !!} @if(!empty($rack_details[$id])) @if(session('business.enable_racks')) {!! Form::text('product_racks_update[' . $id . '][rack]', $rack_details[$id]['rack'], ['class' => 'form-control', 'id' => 'rack_' . $id]); !!} @endif @if(session('business.enable_row')) {!! Form::text('product_racks_update[' . $id . '][row]', $rack_details[$id]['row'], ['class' => 'form-control']); !!} @endif @if(session('business.enable_position')) {!! Form::text('product_racks_update[' . $id . '][position]', $rack_details[$id]['position'], ['class' => 'form-control']); !!} @endif @else {!! Form::text('product_racks[' . $id . '][rack]', null, ['class' => 'form-control', 'id' => 'rack_' . $id, 'placeholder' => __('lang_v1.rack')]); !!} {!! Form::text('product_racks[' . $id . '][row]', null, ['class' => 'form-control', 'placeholder' => __('lang_v1.row')]); !!} {!! Form::text('product_racks[' . $id . '][position]', null, ['class' => 'form-control', 'placeholder' => __('lang_v1.position')]); !!} @endif
@endforeach @endif
@php $custom_labels = json_decode(session('business.custom_labels'), true); $product_custom_fields = !empty($custom_labels['product']) ? $custom_labels['product'] : []; $product_cf_details = !empty($custom_labels['product_cf_details']) ? $custom_labels['product_cf_details'] : []; @endphp @foreach($product_custom_fields as $index => $cf) @if(!empty($cf)) @php $db_field_name = 'product_custom_field' . $loop->iteration; $cf_type = !empty($product_cf_details[$loop->iteration]['type']) ? $product_cf_details[$loop->iteration]['type'] : 'text'; $dropdown = !empty($product_cf_details[$loop->iteration]['dropdown_options']) ? explode(PHP_EOL, $product_cf_details[$loop->iteration]['dropdown_options']) : []; @endphp
{!! Form::label($db_field_name, $cf . ':') !!} @if(in_array($cf_type, ['text', 'date'])) @elseif($cf_type == 'dropdown') @endif
@endif @endforeach @include('layouts.partials.module_form_part')
@endcomponent @component('components.widget', ['class' => 'box-primary'])
{!! Form::label('tax', __('product.applicable_tax') . ':') !!} {!! Form::select('tax', $taxes, $product->tax, ['placeholder' => __('messages.please_select'), 'class' => 'form-control select2'], $tax_attributes); !!}
{!! Form::label('tax_type', __('product.selling_price_tax_type') . ':*') !!} {!! Form::select('tax_type',['inclusive' => __('product.inclusive'), 'exclusive' => __('product.exclusive')], $product->tax_type, ['class' => 'form-control select2', 'required']); !!}
{!! Form::label('type', __('product.product_type') . ':*') !!} @show_tooltip(__('tooltip.product_type')) {!! Form::select('type', $product_types, $product->type, ['class' => 'form-control select2', 'required','disabled', 'data-action' => 'edit', 'data-product_id' => $product->id ]); !!}
@endcomponent
@if($selling_price_group_count) @endif @can('product.opening_stock') @endif
{!! Form::close() !!}
@endsection @section('javascript') @endsection