<?php $__env->startSection('section-title', 'Product'); ?>
<?php $__env->startSection('page-title', 'Add Product'); ?>

<?php if(check_permission('product.update')): ?>
    <?php $__env->startSection('action-button'); ?>
        <a href="<?php echo e(route('product.index')); ?>" class="btn add_list_btn">
            <i class="mr-2 feather icon-list"></i>
            All Product
        </a>
    <?php $__env->stopSection(); ?>
<?php endif; ?>

<?php $__env->startSection('content'); ?>
<div class="row justify-content-center">
    <div class="col-md-12">
        <div class="card m-b-30 card_style">
            <div class="card-body">
                <div class="">
                    <form class="row g-3 needs-validation" method="POST" action="<?php echo e(route('product.store')); ?>"
                        enctype="multipart/form-data" novalidate>
                        <?php echo csrf_field(); ?>
                        
                        <div class="mt-2 col-md-6">
                            <label for="name" class="form-label fw-bold">Name *</label>
                            <input type="text" onfocus="this.select()" autofocus class="form-control" name="name"
                                placeholder="Enter Name">
                            <div class="errors"><?php echo e(($errors->has('name'))?$errors->first('name'):''); ?></div>
                        </div>

                        
                        <div class="mt-2 col-md-6">
                            <label for="barcode" class="form-label fw-bold">Barcode</label>
                            <input type="text" class="form-control"
                                placeholder="Enter Barcode" name="barcode">
                            <div class="errors"><?php echo e(($errors->has('barcode'))?$errors->first('barcode'):''); ?></div>
                        </div>

                        
                        <div class="mt-2 col-md-6">
                            <div class="row">
                                <div class="col-md-11 col-10" style="margin-right: -6px">
                                    <label for="unit_id" class="form-label fw-bold">Category *</label>
                                    <select class="select2" name="category_id" id="categoryId">
                                        <option selected value="">Select Category</option>
                                        <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value=<?php echo e($category->id); ?>><?php echo e($category->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                    <div class="errors"><?php echo e(($errors->has('category_id'))?$errors->first('category_id'):''); ?></div>
                                </div>
                                <div class="col-md-1 col-2 m-0 p-0">
                                    <label class="form-label font-weight-bold"></label>
                                    <div class="" style="margin-top: 10px">
                                        
                                        <button data-toggle="modal" type="button" data-target="#addModal1"
                                            class="btn extra_btn">
                                            <i class="feather icon-plus"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>
                            
                        </div>

                        
                        <div class="mt-2 col-md-6">
                            <div class="row">
                                <div class="col-md-11 col-10" style="margin-right: -6px">
                                    <label for="brand_id" class="form-label fw-bold">Brand</label>
                                    <select class="select2" name="brand_id" id="brandId">
                                        <option selected value="">Select Brand</option>
                                        <?php $__currentLoopData = $brands; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $brand): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value=<?php echo e($brand->id); ?>><?php echo e($brand->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                                <div class="col-md-1 col-2 m-0 p-0">
                                    <label class="form-label font-weight-bold"></label>
                                    <div class="" style="margin-top: 10px">
                                        
                                        <button data-toggle="modal" type="button" data-target="#addModal"
                                            class="btn extra_btn">
                                            <i class="feather icon-plus"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>

                        
                        <div class="mt-2 col-md-3">
                            <label for="unit_id" class="form-label fw-bold">Main Unit</label>
                            <select class="select2 main_unit" name="unit_id">
                                <?php $__currentLoopData = $units; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $unit): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($unit->id); ?>"><?php echo e($unit->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>

                        
                        <div class="mt-2 col-md-3">
                            <label for="unit_id" class="form-label fw-bold">Sub Unit</label>
                            <select name="sub_unit_id" id="" class="form-control sub_unit">
                                <option value="">No Related Unit Found</option>
                            </select>
                        </div>

                        
                        <div class="mt-2 col-md-6">
                            <div class="form-group">
                                <label for="">Low Stock Quantity</label>
                                <div class="opening_stocks form-row" style="padding-left: 5px; padding-right:5px;">
                                    <input type="text" name="main_qty" value="" class="form-control col" placeholder="Pices">
                                </div>
                            </div>
                        </div>

                        
                        <div class="mt-2 col-md-6">
                            <label for="purchase_price" class="form-label fw-bold">Purchase Price *</label>
                            <input type="number" class="form-control" name="purchase_price"
                            >
                            <div class="errors"><?php echo e(($errors->has('purchase_price'))?$errors->first('purchase_price'):''); ?></div>
                        </div>
                        <div class="mt-2 col-md-6">
                            <label for="selling_price" class="form-label fw-bold">Sale Price *</label>
                            <input type="number" class="form-control" name="selling_price"
                            >
                            <div class="errors"><?php echo e(($errors->has('selling_price'))?$errors->first('selling_price'):''); ?></div>
                        </div>
                        

                        <div class="col-md-6 mt-2" style="margin-right: -6px">
                            <label for="status" class="form-label fw-bold">Status *</label>
                            <select class="select2" name="status">
                                <option value="1">Active</option>
                                <option value="0">Deactive</option>
                            </select>
                            <div class="errors"><?php echo e(($errors->has('status'))?$errors->first('status'):''); ?></div>
                        </div>
                        <div class="mt-2 col-md-6">
                            <label for="description" class="form-label fw-bold">Description</label>
                            <textarea class="form-control" name="description" rows="3"></textarea>
                        </div>

                        
                        <div class="mt-2 col-md-6">
                            <label for="image" class="form-label fw-bold">Product
                                Images</label>
                            <input class="form-control image-uploadify" type="file"
                                name="images" accept="image/*" onchange="readURL(this);">
                        </div>

                        <div class="mt-2 col-md-6">
                            <img id="image" style="border-radius: 25px" src="<?php echo e(url('backend/images/no_images.png')); ?>" width="120px" height="80px" />
                        </div>

                        <div class="mt-3 text-center col-12">
                            <button class="btn save_btn" type="submit"> Save </button>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<form action="#" id="categoryForm" method="POST">
    <?php echo csrf_field(); ?>
    <?php if (isset($component)) { $__componentOriginal8a45cb879a3822356ac357ed87f7dd9a = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal8a45cb879a3822356ac357ed87f7dd9a = $attributes; } ?>
<?php $component = App\View\Components\AnotherModal::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('another-modal'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(App\View\Components\AnotherModal::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => 'Add Category','sizeClass' => 'modal-md']); ?>
        <?php if (isset($component)) { $__componentOriginal786b6632e4e03cdf0a10e8880993f28a = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal786b6632e4e03cdf0a10e8880993f28a = $attributes; } ?>
<?php $component = App\View\Components\Input::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('input'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(App\View\Components\Input::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['label' => 'Category Name *','type' => 'text','name' => 'name','placeholder' => 'Enter Category Name','required' => true]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal786b6632e4e03cdf0a10e8880993f28a)): ?>
<?php $attributes = $__attributesOriginal786b6632e4e03cdf0a10e8880993f28a; ?>
<?php unset($__attributesOriginal786b6632e4e03cdf0a10e8880993f28a); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal786b6632e4e03cdf0a10e8880993f28a)): ?>
<?php $component = $__componentOriginal786b6632e4e03cdf0a10e8880993f28a; ?>
<?php unset($__componentOriginal786b6632e4e03cdf0a10e8880993f28a); ?>
<?php endif; ?>
     <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal8a45cb879a3822356ac357ed87f7dd9a)): ?>
<?php $attributes = $__attributesOriginal8a45cb879a3822356ac357ed87f7dd9a; ?>
<?php unset($__attributesOriginal8a45cb879a3822356ac357ed87f7dd9a); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal8a45cb879a3822356ac357ed87f7dd9a)): ?>
<?php $component = $__componentOriginal8a45cb879a3822356ac357ed87f7dd9a; ?>
<?php unset($__componentOriginal8a45cb879a3822356ac357ed87f7dd9a); ?>
<?php endif; ?>
</form>


<form action="#" id="brandForm" method="POST">
    <?php echo csrf_field(); ?>
    <?php if (isset($component)) { $__componentOriginalefc5d8f1512157b4f4b5cdc230110e8b = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalefc5d8f1512157b4f4b5cdc230110e8b = $attributes; } ?>
<?php $component = App\View\Components\AddModal::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('add-modal'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(App\View\Components\AddModal::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => 'Add Brand','sizeClass' => 'modal-md']); ?>
        <?php if (isset($component)) { $__componentOriginal786b6632e4e03cdf0a10e8880993f28a = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal786b6632e4e03cdf0a10e8880993f28a = $attributes; } ?>
<?php $component = App\View\Components\Input::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('input'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(App\View\Components\Input::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['label' => 'Brand Name:','type' => 'text','name' => 'name','placeholder' => 'Enter Brand Name','required' => true]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal786b6632e4e03cdf0a10e8880993f28a)): ?>
<?php $attributes = $__attributesOriginal786b6632e4e03cdf0a10e8880993f28a; ?>
<?php unset($__attributesOriginal786b6632e4e03cdf0a10e8880993f28a); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal786b6632e4e03cdf0a10e8880993f28a)): ?>
<?php $component = $__componentOriginal786b6632e4e03cdf0a10e8880993f28a; ?>
<?php unset($__componentOriginal786b6632e4e03cdf0a10e8880993f28a); ?>
<?php endif; ?>
     <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalefc5d8f1512157b4f4b5cdc230110e8b)): ?>
<?php $attributes = $__attributesOriginalefc5d8f1512157b4f4b5cdc230110e8b; ?>
<?php unset($__attributesOriginalefc5d8f1512157b4f4b5cdc230110e8b); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalefc5d8f1512157b4f4b5cdc230110e8b)): ?>
<?php $component = $__componentOriginalefc5d8f1512157b4f4b5cdc230110e8b; ?>
<?php unset($__componentOriginalefc5d8f1512157b4f4b5cdc230110e8b); ?>
<?php endif; ?>
</form>



<script type="text/javascript">
    function readURL(input) {
        if (input.files && input.files[0]) {
        var reader = new FileReader();
        reader.onload = function (e) {
            $('#image')
                .attr('src', e.target.result)
                .width(120)
                .height(80);
            };
            reader.readAsDataURL(input.files[0]);
        }
    }
</script>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('js'); ?>
    <script>
        //category modal ajax code
        $(document).ready(function () {
            $('#categoryForm').on('submit', function (e) {
                e.preventDefault(); // Prevent the default form submission

                $.ajax({
                    url: "<?php echo e(route('category.store')); ?>", // Define the route for submission
                    method: 'POST',
                    data: $(this).serialize(), // Serialize form data
                    success: function (response) {
                        // Reload the table data dynamically
                        $('#addModal1').modal('hide');
                        // Clear form
                        $('#categoryForm')[0].reset();

                        // Add the new customer to the dropdown without appending manually
                        // Reset and reload the dropdown
                        $('#categoryId').load(location.href + ' #categoryId>*');

                    },
                    error: function (xhr) {
                        // Handle validation errors or server errors here
                        console.error(xhr.responseText);
                    }
                });
            });
        });
    </script>
    <script>
        //Brand modal ajax code
        $(document).ready(function () {
            $('#brandForm').on('submit', function (e) {
                e.preventDefault(); // Prevent the default form submission

                $.ajax({
                    url: "<?php echo e(route('brand.store')); ?>", // Define the route for submission
                    method: 'POST',
                    data: $(this).serialize(), // Serialize form data
                    success: function (response) {
                        // Reload the table data dynamically
                        $('#addModal').modal('hide');
                        // Clear form
                        $('#brandForm')[0].reset();

                        // Add the new customer to the dropdown without appending manually
                        // Reset and reload the dropdown
                        $('#brandId').load(location.href + ' #brandId>*');

                    },
                    error: function (xhr) {
                        // Handle validation errors or server errors here
                        console.error(xhr.responseText);
                    }
                });
            });
        });
    </script>
    <script>
        $('.main_unit').change(function(){
            $('.sub_unit').html('<option value="">No Related Unit Found</option>');
            var main_unit_id=$(this).find(':selected').val();
            var main_unit_text=$(this).find(':selected').text();

            let url = "<?php echo e(route('product-unit', 'my_id')); ?>".replace('my_id', main_unit_id);

            $.ajax({
                url: url,
                method: 'GET',
                success: function (data) {
                    if(data){
                        var sub_value='<option value="">Select Unit</option><option value="'+data.related_unit_id+'">'+data.related_unit.name+'</option>';
                        $('.sub_unit').html(sub_value);

                        // Opening Stock
                        var opening_stock="";
                        opening_stock+=`<input type="text" name="main_qty" value="" class="form-control col" placeholder="${main_unit_text}">`;
                        $('.opening_stocks').html(opening_stock);
                    }else{
                        $('.sub_unit').html('<option value="" selected>No Related Unit Found</option>');
                        // opening Stock

                        var opening_stock=`<input type="text" name="main_qty" value="" class="form-control col" placeholder="${main_unit_text}">`;
                        $('.opening_stocks').html(opening_stock);
                    }
                }
            });
        });

        $('.sub_unit').change(function(){
            var sub_unit_id=$(this).find(':selected').val();
            var sub_unit_text=$(this).find(':selected').text();

            var main_unit_id=$('.main_unit').find(':selected').val();
            var main_unit_text=$('.main_unit').find(':selected').text();
            var opening_stock='';
            if(sub_unit_id==""){
                opening_stock=`<input type="text" name="main_qty" value="" class="form-control col" placeholder="${main_unit_text}">`;
            }else{
                opening_stock+=`<input type="text" name="main_qty" value="" class="form-control col" placeholder="${main_unit_text}" style="margin-right:5px;">`;
                opening_stock+=`<input type="text" name="sub_qty" value="" class="form-control col" placeholder="${sub_unit_text}">`;
            }

            $('.opening_stocks').html(opening_stock);

        });
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('backend.layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\laragon\www\new demo\resources\views/backend/pages/product/create.blade.php ENDPATH**/ ?>