Viewing File: /home/ubuntu/misabloom-backend-base/resources/views/admin/products/_form.blade.php

<div class="card card-flush py- overflow-x-hidden">
	<div class="card-body">
		<div class="d-flex flex-column gap-5 gap-md-7">
			<form class="form" method="POST" action="{{ route('admin.products.save') }}" enctype="multipart/form-data">
				<input type="hidden" name="product_id" value="{{ $product->id }}">
				<input type="hidden" name="price" value="{{ $product->price ? : 0 }}" id="price">
				<input type="hidden" name="thc_drug_content" value="{{ $product->thc_drug_content ? YES : NO }}" id="thc_drug_content">
				<input type="hidden" name="cbd_drug_content" value="{{ $product->cbd_drug_content ? YES : NO }}" id="cbd_drug_content">
				@csrf
				<div class="border rounded p-5">
					<h4 class="text-dark py-3"> {{ tr('basic_info') }}</h4>
					<div class="d-flex flex-column flex-md-row gap-5">
						<div class="fv-row flex-row-fluid">
							<label class="required form-label">{{ tr('name') }}</label>
							<label class="form-label text-muted">({{ tr('max_characters', 255) }})</label>
							<input class="form-control" type="text" name="name" placeholder="{{ tr('name') }}" value="{{ old('name', $product->name) }}" required title="{{ tr('name') }}" maxlength="255" />
						</div>
					</div>

					<div class="d-flex flex-column flex-md-row gap-5 pt-10">
						<div class="fv-row flex-row-fluid">
							<label class="required form-label">{{ tr('category') }}</label>
			                <select class="form-select form-select-solid category_id" data-control="select2" name="category_id" required>
			                    <option value="" selected disabled> {{ tr('select_category') }} </option>
			                    @foreach($categories as $category)
			                    	<option value="{{ $category->id }}" @if(old('category_id') == $category->id || $product->category_id == $category->id) selected @endif> {{ $category->name }} </option>
			                    @endforeach
			                </select>
						</div>

						@if(request()->product_id)
							<div class="fv-row flex-row-fluid">
								<label class="required form-label">{{ tr('sub_category') }}</label>
								<select class="form-select form-select-solid sub_category_id" data-control="select2" name="sub_category_id" required>
				                    <option value="" selected disabled> {{ tr('select_sub_category') }} </option>
				                    	<option value="{{ $product->sub_category_id }}" selected> {{ $product->subCategory->name ?? tr('na') }} </option>
				                </select>
							</div>
						@else

						<div class="fv-row flex-row-fluid">
							<label class="required form-label">{{ tr('sub_category') }}</label>
			                <select class="form-select form-select-solid sub_category_id" data-control="select2" name="sub_category_id" required>
			                    <option value="" selected disabled> {{ tr('select_sub_category') }} </option>
			                    @foreach($sub_categories as $sub_category)
			                    	<option value="{{ $sub_category->id }}" @if(old('sub_category_id') == $sub_category->id || $product->sub_category_id == $sub_category->id) selected @endif> {{ $sub_category->name }} </option>
			                    @endforeach
			                </select>
						</div>
						@endif
					</div>
				</div>

				<div class="border rounded p-5 mt-10">
					<div class="d-flex justify-content-between pb-5">
						<h4 class="text-dark py-3"> {{ tr('thc_drug_content') }}</h4>
						<div class="form-check form-switch form-check-custom form-check-solid float-right">
						    <input class="form-check-input" type="checkbox" value="{{ $product->thc_drug_content ? YES : NO }}" id="thcDrugContent" onchange="enableDrugFields('thc')" {{ $product->thc_drug_content ? 'checked' : '' }} />
						    <label class="form-check-label" for="thcDrugContent"> Drug Content </label>
						</div>
					</div>
					<div class="d-flex flex-column flex-md-row gap-5">
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('thc') }} {{ tr('from') }} (%)</label>
							<input type="number" min="0" max="200000" step="any" name="thc_from" class="form-control form-control-lg form-control-solid mb-3 w-280px" placeholder="{{ tr('thc') }} {{ tr('from') }}" value="{{ old('thc_from', $product->thc_from) }}" title="{{ tr('thc') }} {{ tr('from') }}" id="thc_from" {{ $product->thc_drug_content ? '' : 'readOnly' }} />
						</div>
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('thc') }} {{ tr('to') }} (%)</label>
							<input type="number" min="0" max="200000" step="any" name="thc_to" class="form-control form-control-lg form-control-solid mb-3 w-280px" placeholder="{{ tr('thc') }} {{ tr('to') }}" value="{{ old('thc_to', $product->thc_to) }}" title="{{ tr('thc') }} {{ tr('to') }}" id="thc_to" {{ $product->thc_drug_content ? '' : 'readOnly' }} />
						</div>
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('thc') }} {{ tr('unit') }} (%)</label>
							<select class="form-select form-select-solid w-280px" data-control="select2" name="thc_unit" id="thc_unit" {{ $product->thc_drug_content ? '' : 'readOnly' }}>
								<option value="" selected> {{ tr('select_unit') }} </option>
								@foreach(get_cannabidiol_units() as $thc_unit)
									<option class="" value="{{ $thc_unit }}" @if($product->thc_unit == $thc_unit || old('thc_unit') == $thc_unit) selected @endif> {{ $thc_unit }} </option>
								@endforeach
							</select>
						</div>
					</div>
					<div class="d-flex flex-column flex-md-row gap-5 mt-5">
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('thc') }} {{ tr('per') }} {{ tr('from') }} (%)</label>
							<input type="number" min="0" max="200000" step="any" name="thc_per_from" class="form-control form-control-lg form-control-solid mb-3 w-280px" placeholder="{{ tr('thc') }} {{ tr('per') }} {{ tr('from') }}" value="{{ old('thc_per_from', $product->thc_per_from) }}" title="{{ tr('thc') }} {{ tr('from') }}" id="thc_per_from" {{ $product->thc_drug_content ? '' : 'readOnly' }}/>
						</div>
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('thc') }} {{ tr('per') }} {{ tr('to') }} (%)</label>
							<input type="number" min="0" max="200000" step="any" name="thc_per_to" class="form-control form-control-lg form-control-solid mb-3 w-280px" placeholder="{{ tr('thc') }} {{ tr('per') }} {{ tr('to') }}" value="{{ old('thc_per_to', $product->thc_per_to) }}" title="{{ tr('thc') }} {{ tr('to') }}" id="thc_per_to" {{ $product->thc_drug_content ? '' : 'readOnly' }}/>
						</div>
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('thc') }} {{ tr('per') }} {{ tr('unit') }} (%)</label>
							<select class="form-select form-select-solid w-280px" data-control="select2" name="thc_per_unit" id="thc_per_unit" {{ $product->thc_drug_content ? '' : 'readOnly' }}>
								<option value="" selected> {{ tr('select_unit') }} </option>
								@foreach(get_cannabidiol_units() as $thc_per_unit)
									<option class="" value="{{ $thc_per_unit }}" @if($product->thc_per_unit == $thc_per_unit || old('thc_per_unit') == $thc_per_unit) selected @endif> {{ $thc_per_unit }} </option>
								@endforeach
							</select>
						</div>
					</div>
					<hr />
					<div class="d-flex justify-content-between pb-5">
						<h4 class="text-dark py-3"> {{ tr('cbd_drug_content') }}</h4>
						<div class="form-check form-switch form-check-custom form-check-solid float-right">
						    <input class="form-check-input" type="checkbox" value="{{ $product->cbd_drug_content ? YES : NO }}" id="cbdDrugContent" onchange="enableDrugFields('cbd')" {{ $product->cbd_drug_content ? 'checked' : '' }}/>
						    <label class="form-check-label" for="cbdDrugContent"> Drug Content </label>
						</div>
					</div>
					<div class="d-flex flex-column flex-md-row gap-5 mt-5">
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('cbd') }} {{ tr('from') }} (%)</label>
			               <input type="number" min="0" max="200000" name="cbd_from" step="any" class="form-control form-control-lg form-control-solid mb-3 w-280px" placeholder="{{ tr('cbd') }} {{ tr('from') }}" value="{{ old('cbd_from', $product->cbd_from) }}" title="{{ tr('cbd') }} {{ tr('from') }}" id="cbd_from" {{ $product->cbd_drug_content ? '' : 'readOnly' }} />
						</div>
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('cbd') }} {{ tr('to') }} (%)</label>
			               <input type="number" min="0" max="200000" name="cbd_to" step="any" class="form-control form-control-lg form-control-solid mb-3 w-280px" placeholder="{{ tr('cbd') }} {{ tr('to') }}" value="{{ old('cbd_to', $product->cbd_to) }}" title="{{ tr('cbd') }} {{ tr('to') }}" id="cbd_to" {{ $product->cbd_drug_content ? '' : 'readOnly' }}/>
						</div>
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('cbd') }} {{ tr('unit') }} (%)</label>
							<select class="form-select form-select-solid w-280px" data-control="select2" name="cbd_unit" id="cbd_unit" {{ $product->cbd_drug_content ? '' : 'readOnly' }}>
								<option value="" selected> {{ tr('select_unit') }} </option>
								@foreach(get_cannabidiol_units() as $cbd_unit)
									<option class="" value="{{ $cbd_unit }}" @if($product->cbd_unit == $cbd_unit || old('cbd_unit') == $cbd_unit) selected @endif> {{ $cbd_unit }} </option>
								@endforeach
							</select>
						</div>
					</div>
					<div class="d-flex flex-column flex-md-row gap-5 mt-5">
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('cbd') }} {{ tr('per') }} {{ tr('from') }} (%)</label>
			               <input type="number" min="0" max="200000" name="cbd_per_from" step="any" class="form-control form-control-lg form-control-solid mb-3 w-280px" placeholder="{{ tr('cbd') }} {{ tr('per') }} {{ tr('from') }}" value="{{ old('cbd_per_from', $product->cbd_per_from) }}" title="{{ tr('cbd') }} {{ tr('per') }} {{ tr('from') }}" id="cbd_per_from" {{ $product->cbd_drug_content ? '' : 'readOnly' }}/>
						</div>
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('cbd') }} {{ tr('per') }} {{ tr('to') }} (%)</label>
			               <input type="number" min="0" max="200000" name="cbd_per_to" step="any" class="form-control form-control-lg form-control-solid mb-3 w-280px" placeholder="{{ tr('cbd') }} {{ tr('per') }} {{ tr('to') }}" value="{{ old('cbd_per_to', $product->cbd_per_to) }}" title="{{ tr('cbd') }} {{ tr('per') }} {{ tr('to') }}" id="cbd_per_to" {{ $product->cbd_drug_content ? '' : 'readOnly' }}/>
						</div>
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('cbd') }} {{ tr('per') }} {{ tr('unit') }} (%)</label>
							<select class="form-select form-select-solid w-280px" data-control="select2" name="cbd_per_unit" id="cbd_per_unit" {{ $product->cbd_drug_content ? '' : 'readOnly' }}>
								<option value="" selected> {{ tr('select_unit') }} </option>
								@foreach(get_cannabidiol_units() as $cbd_per_unit)
									<option class="" value="{{ $cbd_per_unit }}" @if($product->cbd_per_unit == $cbd_per_unit || old('cbd_per_unit') == $cbd_per_unit) selected @endif> {{ $cbd_per_unit }} </option>
								@endforeach
							</select>
						</div>
					</div>
					<div class="d-flex flex-column flex-md-row gap-5 mt-5">
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('plant_type') }}</label>
							<label class="form-label text-muted">({{ tr('max_characters', 255) }})</label>
							<input class="form-control" type="text" name="plant_type" placeholder="{{ tr('plant_type') }}" value="{{ old('plant_type', $product->plant_type) }}" title="{{ tr('plant_type') }}" maxlength="255" />
						</div>
					</div>
				</div>

				<div class="border rounded p-5 mt-10">
					<h4 class="text-dark py-3"> {{ tr('pricing') }}</h4>
					<!-- <div class="d-flex flex-column flex-md-row gap-5">
						<input type="number" min="0" step="any" name="usd_price" class="form-control form-control-lg form-control-solid mb-3 mb-lg-0 usd_price" placeholder="{{ tr('usd_price') }}" title="{{ tr('usd_price') }}" id="usd_price" />
						<button class="btn btn-sm btn-primary" type="button" id="convert_to_pscn" onclick="convertToPSCN()"> {{ tr('convert') }} </button>
					</div> -->
					<div class="d-flex flex-column flex-md-row gap-5 pt-10">
						<div class="fv-row flex-row-fluid">
							<label class="required form-label">{{ tr('original_price') }} ({{ Setting::get('token_symbol') }}) </label>
							<input type="number" min="1" step="any" name="original_price" class="form-control form-control-lg form-control-solid mb-3 mb-lg-0 original_price" placeholder="{{ tr('original_price') }}" value="{{ old('original_price', $product->original_price) }}" required title="{{ tr('original_price') }}" id="original_price" />
						</div>
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('discount_type') }}</label>
							<div class="">
								<div class="form-check py-1">
							  		<input class="form-check-input discount_type" type="radio" name="discount_type" id="{{DISCOUNT_TYPE_PERCENTAGE}}" value="{{DISCOUNT_TYPE_PERCENTAGE}}" @if($product->discount->discount_type == DISCOUNT_TYPE_PERCENTAGE || old('discount_type') == DISCOUNT_TYPE_PERCENTAGE) checked @endif>
							  		<label class="form-check-label" for="{{DISCOUNT_TYPE_PERCENTAGE}}">{{ tr('percentage') }}</label>
							  	</div>
							  	<div class="form-check py-1">
							  		<input class="form-check-input discount_type" type="radio" name="discount_type" id="{{DISCOUNT_TYPE_FLAT_PRICE}}" value="{{DISCOUNT_TYPE_FLAT_PRICE}}" @if($product->discount->discount_type == DISCOUNT_TYPE_FLAT_PRICE || old('discount_type') == DISCOUNT_TYPE_FLAT_PRICE) checked @endif>
							  		<label class="form-check-label" for="{{DISCOUNT_TYPE_FLAT_PRICE}}">{{ tr('flat_price') }}</label>
								</div>
							</div>
						</div>
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('discount') }}</label>
			               <input type="number" min="1" name="discount" class="form-control form-control-lg form-control-solid mb-3 mb-lg-0 discount" placeholder="{{ tr('discount') }}" value="{{ old('discount', $product->discount->discount ?? '') }}" title="{{ tr('discount') }}" id="discount" />
						</div>
					</div>

					<div class="d-flex flex-column flex-md-row gap-5 pt-10">
						<div class="fv-row flex-row-fluid">
							<label class="form-label">{{ tr('price_tag_preview') }} : </label>
			               	<label class="text-danger fw-bolder" id="selling_price"> {{ formatted_amount($product->price ? : 0) }} </label> &nbsp; 
			               	
	                           	<label class="text-muted">
	                           		<s id="strike_price" class="{{ $product->discount_price ? '' : 'd-none' }}"> {{ formatted_amount($product->original_price ? : 0) }} </s>
	                           	</label>
                           	
						</div>
					</div>
					<div class="d-flex justify-content-end gap-3">
						<button class="btn btn-sm btn-danger" type="button" id="clear_discount" onclick="priceTagClear()"> {{ tr('clear_price') }} </button>
						<button class="btn btn-sm btn-success" type="button" id="apply_discount" onclick="priceTagApply()"> {{ tr('preview_price') }} </button>
					</div>
				</div>

				<div class="border rounded p-5 mt-10">
					<h4 class="text-dark py-3"> {{ tr('inventory') }}</h4>
					<div class="d-flex flex-column flex-md-row gap-5">
						<div class="fv-row flex-row-fluid">
							<label class="required form-label">{{ tr('operation') }}</label>
							<div class="">
								<div class="form-check py-1">
							  		<input class="form-check-input" type="radio" name="operation" value="{{ADD}}" id="operation_add" checked onchange="resetQuantity()">
							  		<label class="form-check-label" for="operation_add">{{ tr('add') }}</label>
							  	</div>
							  	<div class="form-check py-1">
							  		<input class="form-check-input" type="radio" name="operation" value="{{MINUS}}" id="operation_minus" onchange="resetQuantity()" @if(!request()->product_id) disabled @endif>
							  		<label class="form-check-label" for="operation_minus">{{ tr('minus') }}</label>
								</div>
							</div>
						</div>
						<div class="fv-row flex-row-fluid">
							<label class="required form-label">{{ tr('quantity') }} </label>
							<input type="number" id="quantity" min="1" class="form-control form-control-lg form-control-solid mb-3 mb-lg-0" placeholder="{{ tr('quantity') }}" value="{{ old('quantity') }}" title="{{ tr('quantity') }}" {{ request()->product_id ? '' : 'required' }}/>
						</div>

						<div class="fv-row flex-row-fluid">
							<label class="required form-label fs-9">{{ tr('quantity_shown_as') }} </label>
							<input type="number" name="quantity" class="form-control form-control-lg form-control-solid mb-3 mb-lg-0" value="{{ old('quantity', $product->quantity) }}" title="{{ tr('quantity') }}" id="quantity_preview" readOnly />
						</div>
					</div>
					<div class="d-flex flex-column flex-md-row gap-5 pt-10">
						<div class="fv-row flex-row-fluid w-150px">
							<label class="required form-label">{{ tr('gross_weight') }} </label>
							<input type="number" min="0" name="gross_weight" step="any" class="form-control form-control-lg form-control-solid mb-3 mb-lg-0" placeholder="{{ tr('gross_weight') }}" value="{{ old('gross_weight', $product->gross_weight) }}" required title="{{ tr('gross_weight') }}" id="gross_weight" />
						</div>
						<div class="fv-row flex-row-fluid w-150px">
							<label class="required form-label">{{ tr('unit') }} </label>
							<select class="form-select" name="unit" id="unit" required>
								<option value="" disabled selected> {{ tr('select_unit') }} </option>
								@foreach(get_units() as $unit)
									<option class="" value="{{ $unit }}" @if($product->unit == $unit || old('unit') == $unit) selected @endif> {{ $unit }} </option>
								@endforeach
							</select>
						</div>
					</div>
				</div>

				<div class="border rounded p-5 mt-10">
					<h4 class="text-dark py-3"> {{ tr('gallery') }}</h4>
					<div class="col-md-12">
						<div class="w-930px">
							<label class="form-label required">{{ tr('files') }}</label>
							<label class="text-muted">{{ tr('product_file_note') }} {{ tr('multiple_file_supported') }}</label>
							<input class="form-control mt-3" id="file" type="file" name="pictures[]" accept=".png, .jpg, .jpeg" onchange="imgPreview()" {{ !request()->product_id ? 'required' : ''}} multiple />
						</div>
					</div>
				</div>

				<div class="col-md-12">
                    @if(request()->product_id)

                        @foreach($product->productFiles as $product_file)
                            <div class="column-preview">
                                <img class="info-prev-img" src="{{ $product_file->file }}">
                            </div>
                        @endforeach

                        <div id="image_preview_edit"></div></div>

                    @else

                        <div id="image_preview_add"></div></div>

                    @endif
                </div>

				<div class="col-md-12 {{ request()->product_id ? '' : 'pt-10' }}" id="description">
					<div class="flex-row-fluid">
						<label class="form-label required">{{ tr('description') }}</label>
						<textarea id="ckeditor_classic" rows="10" class="form-control" name="description" placeholder="{{ tr('description') }}" title="{{ tr('description') }}" />{{ old('description', $product->description) }}</textarea>
					</div>
				</div>
				
				<div class="float-right info-btn">
					<a href="{{ route('admin.products.index') }}" class="btn btn-warning btn-active-light-primary me-2 fs-4"><i class="las la-times-circle fs-2x"></i>{{ tr('cancel') }}</a>
					<button type="submit" class="btn btn-primary fs-4" {{ Setting::get( 'is_demo_control_enabled') ? 'disabled' : ''}}><i class="las la-check-circle fs-2x"></i>{{ tr('submit') }}</button>
				</div>
			</form>
		</div>
	</div>
</div>
</div>
</div>
</div>

@section('scripts')
    
<script type="text/javascript">
 
    $(document).ready(function() {

	@if(!request()->product_id && !$errors->any())
       	$('.sub_category_id').find('option').not(':first').remove();
    @endif

    @if($errors->any())
    	$('.sub_category_id option[value!={{old('sub_category_id')}}]').remove();
    	@if(old('discount') && old('discount_type'))
    		priceTagApply();
    	@endif
    @endif

    $('.category_id').on('change' , function (e) {

            var category_id = $(this).val();

            if(category_id == null || category_id == undefined) {
                return false;
            }

            var get_sub_categories_url = "{{route('admin.get_sub_categories')}}";

            var data = {'category_id' : category_id};

            var request = $.ajax({
                            url: get_sub_categories_url,
                            type: "GET",
                            data: data,
                        }); 

            request.done(function(result) { 

                if(result.success == true) {

                $(".sub_category_id").html(result.view);
                $(".sub_category_id").select2();
            }

            });

            request.fail(function(jqXHR, textStatus) {
                console.log( "Request failed: " + textStatus );
            });

        });
    });

    $('#quantity').on('keyup change', function() {

    	const quantity = {{ $product->quantity ? : 0 }};

    	const operation_quantity = this.value ? this.value : 0;

    	if(operation_quantity < 0) {

    		alert("Sorry, you can't add quantity in negative. Please update correct values.");

    		this.value = 0; quantity_preview.value = quantity;

    		return;
    	}

    	if($('#operation_add').is(':checked')) {

    		var operation = document.getElementById('operation_add');

    	} else if($('#operation_minus').is(':checked')) {

    		var operation = document.getElementById('operation_minus');
    	}

    	const quantity_preview = document.getElementById('quantity_preview');

    	if(operation.value == "ADD") {

    		quantity_preview.value = parseInt(quantity) + parseInt(operation_quantity);

    	} else {

    		preview_quantity = parseInt(quantity) - parseInt(operation_quantity);

    		if(preview_quantity < 0) {

    			alert("Sorry, current operation & operation value will show quantity in negative. Please update correct values.");

    			this.value = 0; quantity_preview.value = quantity;

    			return;
    		}

    		quantity_preview.value = preview_quantity;
    	}
    });

    function resetQuantity() {

    	const quantity = {{ $product->quantity ? : 0 }};

    	const operation_quantity = document.getElementById('quantity');

    	operation_quantity.value = 0; quantity_preview.value = quantity;
    }

    // $('#original_price').on('keyup change', function() {

    // 	const original_price = this.value ? this.value : 0;

    // 	const price = document.getElementById('price');

    // 	const currency = "{{ Setting::get('token_symbol') }}";

    // 	const symbol_position = "{{ Setting::get('symbol_position') }}";

    // 	if(symbol_position == 'prefix') {

    // 		document.getElementById('selling_price').innerHTML = currency + ' ' +Number(original_price).toFixed(2);

    // 	} else {

    // 		document.getElementById('selling_price').innerHTML = Number(original_price).toFixed(2) + ' ' + currency;
    		
    // 	}

    // 	price.value = original_price;

    // });

    function priceTagApply() {

    	const original_price = document.getElementById('original_price').value;

    	if($('#percentage').is(':checked')) {

    		var discount_type = document.getElementById('percentage').value;

    	} else if($('#flat-price').is(':checked')) {

    		var discount_type = document.getElementById('flat-price').value;
    	}

    	var discount = document.getElementById('discount').value;

    	if(!original_price) {

    		alert('Please, enter the original price field.');

    		return;

    	} else if(original_price == 0) {

    		alert('Original price minimum should be 1.');

    		return;

    	} else if(!discount) {

    		alert('Please, enter the discount field.');

    		return;

    	} else if(!discount_type) {

    		alert('Please, select the discount type field.');

    		return;
    	}

    	if(original_price != 0 && discount_type && discount) {

    		strike_price = document.getElementById('strike_price');

    		const currency = "{{ Setting::get('token_symbol') }}";

    		const symbol_position = "{{ Setting::get('symbol_position') }}";

    		if(discount_type == 'flat-price') {

    			if(discount == 0) {

					alert("Minimum amount is 1.");

					document.getElementById('discount').value = {{ $product->discount->discount ? : 0 }};

					strike_price.classList.add('d-none');

					if(symbol_position == 'prefix') {

			    		document.getElementById('selling_price').innerHTML = currency + ' ' +Number(original_price).toFixed(2);

			    	} else {

			    		document.getElementById('selling_price').innerHTML = Number(original_price).toFixed(2) + ' ' + currency;
			    		
			    	}

					return;
				}

				var selling_price = original_price - discount;

    			if(Number(selling_price).toFixed(2) == Number(original_price).toFixed(2)) {

    				alert("Sorry, for current discount original and selling price will be same.");

					document.getElementById('discount').value = {{ $product->discount->discount ? : 0 }};

					@if(!request()->product_id) strike_price.classList.add('d-none'); @endif

					if(symbol_position == 'prefix') {

			    		document.getElementById('selling_price').innerHTML = currency + ' ' +Number(original_price).toFixed(2);

			    	} else {

			    		document.getElementById('selling_price').innerHTML = Number(original_price).toFixed(2) + ' ' + currency;
			    		
			    	}

						return;
	    			}

	    		} else if(discount_type == 'percentage') {

	    			if(discount > 100) {

	    				strike_price.classList.add('d-none');

	    				document.getElementById('discount').value = 0;

	    				alert("Sorry, you can't add discount percentage more than 100.");

				    	if(symbol_position == 'prefix') {

				    		document.getElementById('selling_price').innerHTML = currency + ' ' +Number(original_price).toFixed(2);

				    	} else {

				    		document.getElementById('selling_price').innerHTML = Number(original_price).toFixed(2) + ' ' + currency;
				    	}

	    				return;
	    			}

	    			var selling_price = original_price - (original_price * (discount / 100));

	    			if(Number(selling_price).toFixed(2) == Number(original_price).toFixed(2)) {

	    				alert("Sorry, for current discount original and selling price will be same.");

						document.getElementById('discount').value = {{ $product->discount->discount ? : 0 }};

						@if(!request()->product_id) strike_price.classList.add('d-none'); @endif

						if(symbol_position == 'prefix') {

			    		document.getElementById('selling_price').innerHTML = currency + ' ' +Number(original_price).toFixed(2);

			    	} else {

			    		document.getElementById('selling_price').innerHTML = Number(original_price).toFixed(2) + ' ' + currency;
			    		
			    	}

					return;
    			}
    		}

    		if(selling_price < 0) {

    			var originalPrice = {{ $product->original_price ? : 0}};

    			var productPrice = {{ $product->price ? : 0}};

    			document.getElementById('original_price').value = originalPrice ? originalPrice : original_price;

    			document.getElementById('discount').value = {{ $product->discount->discount ? : 0}};

    			if(symbol_position == 'prefix') {

		    		document.getElementById('selling_price').innerHTML = currency + ' ' +Number(original_price).toFixed(2);

		    	} else {

		    		document.getElementById('selling_price').innerHTML = Number(original_price).toFixed(2) + ' ' + currency;
		    		
		    	}

    			@if(!request()->product_id) strike_price.classList.add('d-none'); @endif

    			alert("Sorry, You can't add amount in negative. Invalid Amount.");

    			return;
    		}

    		strike_price.classList.remove('d-none');

    		if(symbol_position == 'prefix') {

    			strike_price.innerHTML = currency + ' ' + Number(original_price).toFixed(2);

	    		document.getElementById('selling_price').innerHTML = currency + ' ' +Number(selling_price).toFixed(2);

	    	} else {

	    		strike_price.innerHTML = Number(original_price).toFixed(2) + ' ' + currency;

	    		document.getElementById('selling_price').innerHTML = Number(selling_price).toFixed(2) + ' ' + currency;
	    		
	    	}
    	}

    }

    function priceTagClear() {

    	const currency = "{{ Setting::get('token_symbol') }}";

    	const symbol_position = "{{ Setting::get('symbol_position') }}";

    	strike_price = document.getElementById('strike_price');

    	@if(!request()->product_id)

	    	if($('#percentage').is(':checked')) {

	    		document.getElementById('percentage').checked = false;

	    	} else if($('#flat-price').is(':checked')) {

	    		document.getElementById('flat-price').checked = false;
	    	}
	    	
	    @else
	    	
	    	var discount_type_id = "{{ $product->discount->discount_type }}";

	    	if(discount_type_id) {

	    		document.getElementById(discount_type_id).checked = true;

	    	} else {

	    		strike_price.classList.add('d-none');
	    	}

    	@endif

    	document.getElementById('original_price').value = {{ $product->original_price ? : 0 }};

		document.getElementById('discount').value = {{ $product->discount->discount ? : 0 }};

		if(symbol_position == 'prefix') {

			document.getElementById('selling_price').innerHTML = currency + ' ' + Number({{ $product->price ? : 0 }}).toFixed(2);

    	} else {

			document.getElementById('selling_price').innerHTML = Number({{ $product->price ? : 0 }}).toFixed(2) + ' ' + currency;
    		
    	}

		@if(!request()->product_id) strike_price.classList.add('d-none'); @endif

		return;

    }

    function imgPreview() {

	 	@if(request()->product_id)
	 		var gallery_id = 'image_preview_edit';
	 	@else
	 		var gallery_id = 'image_preview_add';
	 	@endif

	 	$("#"+gallery_id).html('');

	 	document.getElementById("description").classList.remove("pt-10");

	 	var total_file = document.getElementById("file").files.length;

	 	for(var i = 0; i < total_file; i++) {

	  		$('#'+gallery_id).append("<div class='column-preview'><img class='info-prev-img' src='"+URL.createObjectURL(event.target.files[i])+"' /></div>");
		}
	}

	function convertToPSCN() {

		const usd_price = document.getElementById('usd_price').value;

		if(!usd_price) {

			alert('Please enter usd price.');

			return false;
		}

		const original_price = document.getElementById('original_price');

		let pscn = usd_price / 0.01131;

		original_price.value = parseFloat(pscn).toFixed(2);
	 
	}

	function enableDrugFields(type) {

		let drugContent = document.getElementById(type + 'DrugContent');

		let hiddenKey = document.getElementById(type + '_drug_content');

		let from = document.getElementById(type + '_from');

		let to = document.getElementById(type + '_to');

		let unit = document.getElementById(type + '_unit');

		let per_from = document.getElementById(type + '_per_from');

		let per_to = document.getElementById(type + '_per_to');

		let per_unit = document.getElementById(type + '_per_unit');

		let isDisabled = drugContent.checked ? false : true;

		console.log(isDisabled);

		from.readOnly = to.readOnly = unit.readOnly = per_from.readOnly = per_to.readOnly = per_unit.readOnly = isDisabled;

		if(!drugContent.checked) from.value = to.value = per_from.value = per_to.value = '';

		$(`#${type}_unit`).val('').change();
		$(`#${type}_per_unit`).val('').change();

		hiddenKey.value = drugContent.checked ? 1 : 0;
	}

</script>
   
@endsection
Back to Directory File Manager