
<?php $__env->startSection('title'); ?> Purchase | Beauty Parlour <?php $__env->stopSection(); ?>
<?php $__env->startSection('purchase'); ?> active <?php $__env->stopSection(); ?>
<?php $__env->startSection('styles'); ?>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('main_content_section'); ?>
<div class="row py-3 ps-2">
    <div class="heading d-flex justify-content-start align-items-center">
        <h3 class="mb-0 pb-0"><span> Update Purchase Invoice</span></h3>
    </div>
</div>

<div class="row min-vh-100">
    <!-- all content will be here. start -->
    <div>
        <input type="hidden" name="purchase_id" id="purchaseId" value="<?php echo e($prchaseUniqueId); ?>">
        <div class="row invoice p-0 m-0">
            <div class="col-md-6">
                <div class="card h-100 py-2 px-2">

                    <div class="row">
                        <div class="col-md-12 d-flex gap-2">
                            <div class="custom-w-80">
                                <div class="form-group custom-select2-form">
                                    <label for="supplier_id">Supplier <span class=" text-danger">*</span> </label>
                                    <select name="supplier_id" id="supplier_id" class="form-select select2" required>
                                        <option value="" selected disabled>Select Supplier</option>
                                        <?php $__currentLoopData = $supplierData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $singleSD): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php if(isset($singleSD) && $singleSD != null): ?>
                                        <option value="<?php echo e($singleSD->id); ?>"
                                            <?php echo e($singleSD->id == $singlePurchaseData->supplier_id ? 'selected' : ''); ?>

                                            >
                                            <?php echo e($singleSD->supplier_name); ?></span>
                                        </option>
                                        <?php endif; ?>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                    
                                <?php $__errorArgs = ['supplier_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                <span class=text-danger><?php echo e($message); ?></span>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                            <div class="custom-w-20 custom-add-new-supplier-btn">
                                <div class="form-group">
                                    <button type="button" class="btn btn-outline-primary" data-bs-toggle="modal"
                                        data-bs-target="#addNewSupplier">
                                        <span class="material-symbols-outlined">
                                            person_add
                                        </span>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row mt-3 mb-5">
                        <div class="col-md-12">
                            <div class="table-container table-responsive" id="updatePurchaseList">
                                <table class="table table-bordered">
                                    <thead class="text-uppercase">
                                        <tr class="me-3">
                                            <th class="text-center" scope="col"><span>Product</span></th>
                                            <th class="text-center" scope="col"><span>MRP/Sell</span></th>
                                            <th class="text-center" scope="col"><span>Qty/Price</span></th>
                                        </tr>
                                    </thead>
                                    <tbody class="text-center">
                                        <?php $__currentLoopData = $purchaseProductData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $singlePPD): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php if(isset($singlePPD) && $singlePPD != null): ?>
                                        <tr class="text-start">
                                            <td class="text-start">
                                                <div class="row_title">
                                                    <span class="text-info fw-bolder"><?php echo e($singlePPD->productData->product_name); ?></span>
                                                </div>
                                                <div class="row-actions mt-2">
                                
                                                    <?php if(Auth::user()->can('purchase-edit')): ?>
                                                    <span><a class="fw-bolder text-success" href="#"
                                                            onclick="duplicateItem(<?php echo e($singlePPD->id); ?>)">Duplicate</a>
                                                    </span> |
                                
                                                    <span><a href="#" class="fw-bolder text-primary edit_class_modal border-0 bg-transparent"
                                                            data-bs-toggle="modal" data-bs-target="#updatePurProData<?php echo e($singlePPD->id); ?>"> Edit
                                                        </a></span>
                                                    <?php endif; ?>
                                
                                                    <?php if(Auth::user()->can('purchase-delete')): ?>
                                                    <span> | <a class="fw-bolder text-danger" href="#"
                                                            onclick="deletePurchaseProduct(<?php echo e($singlePPD->id); ?>)">Delete</a>
                                                    </span>
                                                    <?php endif; ?>
                                                </div>
                                            </td>
                                            <td class="text-start">
                                                <b>MRP: </b><?php echo e($singlePPD->mrp_price); ?> <br>
                                                <b>Selling: </b><?php echo e($singlePPD->selling_price); ?>

                                            </td>
                                            <td class="text-start">
                                                <b>Product(qty): </b><?php echo e($singlePPD->total_product); ?><br>
                                                <b>Total Price: </b><?php echo e($singlePPD->total_product_price); ?>

                                            </td>
                                        </tr>
                                
                                        
                                        <input type="hidden" value="<?php echo e($singlePPD->id); ?>" id="purchaseProductId<?php echo e($singlePPD->id); ?>"
                                            name="purchaseProductId">
                                        <input type="hidden" value="<?php echo e($singlePPD->mrp_price); ?>" id="unit_price<?php echo e($singlePPD->id); ?>"
                                            name="unit_price<?php echo e($singlePPD->id); ?>">
                                        <div class="modal fade" id="updatePurProData<?php echo e($singlePPD->id); ?>" tabindex="-1"
                                            aria-labelledby="oneInputModalLabel" aria-hidden="true" data-bs-backdrop='static'>
                                            <div class="modal-dialog modal-dialog-centered max-width-900px">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <h1 class="modal-title fs-5" id="oneInputModalLabel">Update Purchase</h1>
                                                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                                    </div>
                                
                                                    <div class="modal-body px-3 py-3">
                                                        <form action="#" method="post" enctype="multipart/form-data">
                                                            <div class="row">
                                
                                                                <div class="col-md-6 mb-2">
                                                                    <div>
                                                                        <div class="form-group">
                                                                            <label for="mrp_price_fmp">MRP Price<span class="text-danger">*</span>
                                                                            </label>
                                                                            <input type="number" name="mrp_price_fmp"
                                                                                id="mrp_price_fmp<?php echo e($singlePPD->id); ?>"
                                                                                class="form-control form-control-solid custom-readonly-color"
                                                                                value="<?php echo e($singlePPD->mrp_price); ?>" placeholder="MRP Price" readonly
                                                                                required>
                                                                        </div>
                                
                                                                        <?php $__errorArgs = ['mrp_price_fmp'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                                        <span class=text-danger><?php echo e($message); ?></span>
                                                                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                                    </div>
                                                                </div>
                                
                                                                <div class="col-md-6 mb-2">
                                                                    <div>
                                                                        <div class="form-group">
                                                                            <label for="product_qty_fmp">Qty<span class="text-danger">*</span>
                                                                            </label>
                                                                            <input type="number" name="product_qty_fmp"
                                                                                id="product_qty_fmp<?php echo e($singlePPD->id); ?>"
                                                                                class="form-control form-control-solid"
                                                                                value="<?php echo e($singlePPD->product_qty); ?>" placeholder="Product Qty"
                                                                                onblur="productQuantityFMP(<?php echo e($singlePPD->id); ?>)" required>
                                                                        </div>
                                
                                                                        <?php $__errorArgs = ['product_qty_fmp'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                                        <span class=text-danger><?php echo e($message); ?></span>
                                                                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                                    </div>
                                                                </div>
                                
                                                                <div class="col-md-6 mb-2">
                                                                    <div>
                                                                        <div class="form-group">
                                                                            <label for="selling_price_fmp">Selling
                                                                                Price<span class="text-danger">*</span>
                                                                            </label>
                                                                            <input type="number" name="selling_price_fmp"
                                                                                id="selling_price_fmp<?php echo e($singlePPD->id); ?>"
                                                                                class="form-control form-control-solid"
                                                                                value="<?php echo e($singlePPD->selling_price); ?>" placeholder="Selling Price"
                                                                                required>
                                                                        </div>
                                
                                                                        <?php $__errorArgs = ['selling_price_fmp'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                                        <span class=text-danger><?php echo e($message); ?></span>
                                                                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                                    </div>
                                                                </div>
                                
                                                                <div class="col-md-6 mb-2">
                                                                    <div>
                                                                        <div class="form-group">
                                                                            <label for="total_product_price_fmp">Total
                                                                                Price<span class="text-danger">*</span>
                                                                            </label>
                                                                            <input type="number" name="total_product_price_fmp"
                                                                                id="total_product_price_fmp<?php echo e($singlePPD->id); ?>"
                                                                                class="form-control form-control-solid custom-readonly-color"
                                                                                value="<?php echo e($singlePPD->total_product_price); ?>" placeholder="Total Price"
                                                                                readonly required>
                                                                        </div>
                                
                                                                        <?php $__errorArgs = ['total_product_price_fmp'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                                        <span class=text-danger><?php echo e($message); ?></span>
                                                                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                                    </div>
                                                                </div>
                                
                                                            </div>
                                
                                                            <div class="modal-footer">
                                                                <button type="submit" class="btn btn-success"
                                                                    onclick="updateProductDetails(<?php echo e($singlePPD->id); ?>)">Update</button>
                                                                <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Cancel</button>
                                                            </div>
                                                        </form>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                
                                        <?php endif; ?>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </tbody>
                                
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class="row mt-3 custom-bill-pay-button-row">
                        <div class="col-12">
                            <a onclick="getPurchaseProductData()" href="#"
                                class="btn btn-success custom-bill-pay-button px-2">
                                <span class="material-symbols-outlined">
                                    payments
                                </span>
                                <span class="button-text">Bill Pay</span>
                            </a>

                            <a id="purchasePayLink" href="#">
                                <span class="button-text"></span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="card h-100 py-2 px-2">
                    <div class="row">
                        <div class="col-md-12">
                            <div>
                                <div class="form-group custom-select2-form">
                                    <label for="category_id">Category <span class=" text-danger">*</span> </label>
                                    <select class="form-select select2" name="category_id" id="category_id" required>
                                        <option value="" selected disabled>Select Category</option>
                                        <?php $__currentLoopData = $categoryData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $singleBD): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php if(isset($singleBD) && $singleBD != null): ?>
                                        <option value="<?php echo e($singleBD->id); ?>">
                                            <?php echo e($singleBD->category_name); ?></span>
                                        </option>
                                        <?php endif; ?>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                    </select>
                                </div>

                                <?php $__errorArgs = ['category_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                <span class=text-danger><?php echo e($message); ?></span>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                        </div>
                    </div>
                    <div class="row mt-2 px-2">
                        <div class="col-md-12 p-1 d-flex gap-2">
                            <div class="custom-w-70">
                                <input type="text" name="search" id="search"
                                    class="form-control form-control-solid border" value="" placeholder="Product Search"
                                    required>
                            </div>
                            <div class="custom-w-70">
                                <div class="custom-product-filter-btn gap-2 d-flex">
                                    <button type="button" class="btn btn-primary"
                                        onclick="searchProduct()">Search</button>
                                    <button type="button" class="btn btn-danger" onclick="resetSearch()">Reset</button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <span id="filterProductList">

                        <div class="row mt-2 px-2">
                            <?php $__currentLoopData = $productData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$singlePD): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php if(isset($singlePD) && $singlePD != null): ?>
                            <?php
                            $lastProductId = $singlePD->id;
                            if($key == 0){
                            $firstProductId = $singlePD->id;
                            }
                            ?>

                            <div class="col-md-3 col-sm-2 p-1">
                                <div class="card p-1 custom-pos-lay-product-card h-100">
                                    <a href="#" onclick="purchaseProductCreate(<?php echo e($singlePD->id); ?>)">
                                        <div class="img-block">
                                            <?php if(isset($singlePD->product_image)): ?>
                                            <img src="<?php echo e(asset('uploads/product/thumbnail/'.$singlePD->product_image)); ?>"
                                                class="w-100 h-100" />
                                            <?php else: ?>
                                            <img src="<?php echo e(asset('backend/template-assets/')); ?>/images/img_preview.png"
                                                class="w-100 h-100" />
                                            <?php endif; ?>
                                        </div>
                                        <p class="mb-1 mt-2 text-center">
                                            <b class="text-primary"><?php echo e($singlePD->product_name); ?> </b><br>
                                            <b class="text-primary">Price: <span
                                                    class="text-success"><?php echo e($singlePD->product_price); ?></span> </b>
                                        </p>
                                    </a>
                                </div>
                            </div>


                            
                            <input type="hidden" value="<?php echo e($singlePD->id); ?>" id="productId<?php echo e($singlePD->id); ?>"
                                name="productId<?php echo e($singlePD->id); ?>">
                            <input type="hidden" value="<?php echo e($singlePD->product_price); ?>" id="unit_price<?php echo e($singlePD->id); ?>"
                                name="unit_price<?php echo e($singlePD->id); ?>">
                            <div class="modal fade" id="purchaseProductCreate<?php echo e($singlePD->id); ?>" tabindex="-1"
                                aria-labelledby="oneInputModalLabel" aria-hidden="true" data-bs-backdrop='static'>
                                <div class="modal-dialog modal-dialog-centered max-width-900px">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <h1 class="modal-title fs-5" id="oneInputModalLabel">New Purchase Create</h1>
                                            <button type="button" class="btn-close" data-bs-dismiss="modal"
                                                aria-label="Close"></button>
                                        </div>

                                        <div class="modal-body px-3 py-3">
                                            <form action="#" method="post" enctype="multipart/form-data"
                                                onsubmit="return addProductDetailsFMP(<?php echo e($singlePD->id); ?>)">
                                                <div class="row">

                                                    <div class="col-md-6 mb-2">
                                                        <div>
                                                            <div class="form-group">
                                                                <label for="mrp_price_fmp">MRP Price<span
                                                                        class="text-danger">*</span>
                                                                </label>
                                                                <input type="number" name="mrp_price_fmp"
                                                                    id="mrp_price_fmp<?php echo e($singlePD->id); ?>"
                                                                    class="form-control form-control-solid custom-readonly-color"
                                                                    value="<?php echo e($singlePD->product_price); ?>"
                                                                    placeholder="MRP Price" readonly required>
                                                            </div>

                                                            <?php $__errorArgs = ['mrp_price_fmp'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                            <span class=text-danger><?php echo e($message); ?></span>
                                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                        </div>
                                                    </div>

                                                    <div class="col-md-6 mb-2">
                                                        <div>
                                                            <div class="form-group">
                                                                <label for="product_qty_fmp">Qty<span
                                                                        class="text-danger">*</span>
                                                                </label>
                                                                <input type="number" name="product_qty_fmp"
                                                                    id="product_qty_fmp<?php echo e($singlePD->id); ?>"
                                                                    class="form-control form-control-solid" value="1"
                                                                    placeholder="Product Qty"
                                                                    onblur="productQuantityFMP(<?php echo e($singlePD->id); ?>)"
                                                                    required>
                                                            </div>

                                                            <?php $__errorArgs = ['product_qty_fmp'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                            <span class=text-danger><?php echo e($message); ?></span>
                                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                        </div>
                                                    </div>

                                                    <div class="col-md-6 mb-2">
                                                        <div>
                                                            <div class="form-group">
                                                                <label for="selling_price_fmp">Selling
                                                                    Price<span class="text-danger">*</span>
                                                                </label>
                                                                <input type="number" name="selling_price_fmp"
                                                                    id="selling_price_fmp<?php echo e($singlePD->id); ?>"
                                                                    class="form-control form-control-solid" value="0"
                                                                    placeholder="Selling Price" required>
                                                            </div>

                                                            <?php $__errorArgs = ['selling_price_fmp'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                            <span class=text-danger><?php echo e($message); ?></span>
                                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                        </div>
                                                    </div>

                                                    <div class="col-md-6 mb-2">
                                                        <div>
                                                            <div class="form-group">
                                                                <label for="total_product_price_fmp">Total
                                                                    Price<span class="text-danger">*</span>
                                                                </label>
                                                                <input type="number" name="total_product_price_fmp"
                                                                    id="total_product_price_fmp<?php echo e($singlePD->id); ?>"
                                                                    class="form-control form-control-solid custom-readonly-color"
                                                                    value="<?php echo e($singlePD->product_price); ?>"
                                                                    placeholder="Total Price" readonly required>
                                                            </div>

                                                            <?php $__errorArgs = ['total_product_price_fmp'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                            <span class=text-danger><?php echo e($message); ?></span>
                                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                        </div>
                                                    </div>

                                                </div>

                                                <div class="modal-footer">
                                                    <button type="submit" class="btn btn-success">Save</button>
                                                    <button type="button" class="btn btn-danger"
                                                        data-bs-dismiss="modal">Cancel</button>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <?php endif; ?>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                            <?php if(isset($lastProductId) && isset($firstProductId)): ?>
                            <input type="hidden" id="firstProductId" value="<?php echo e($firstProductId); ?>">
                            <input type="hidden" id="lastProductId" value="<?php echo e($lastProductId); ?>">
                            <?php endif; ?>

                        </div>
                        <div class="row">
                            <div class="col-12 mb-1 mt-3">
                                <div class="pagination w-100 justify-content-center">
                                    <button class="btn btn-sm" id="previous" onclick="previousProductData()"
                                        style="background-color: #eff2f5">Previous</button>
                                    <button class="btn btn-sm" id="next" onclick="nextProductData()"
                                        style="margin-left: 10px; background-color: #eff2f5; ">Next</button>
                                </div>
                            </div>
                        </div>

                    </span>

                </div>
            </div>
        </div>
    </div>
    <!-- all content will be here. end -->
</div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<?php echo $__env->make('admin.productManage.purchaseProduct.partial.script', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<script>
    $("#date_issue").flatpickr({
        allowInput: true,
        dateFormat: "d-m-Y",
    });

    $("#due_issue").flatpickr({
        allowInput: true,
        dateFormat: "d-m-Y",
    });

    $(document).ready(function(){
        $("#supplier_id").select2();
        $("#category_id").select2();
        $("#brand_id").select2();
    });

    function checkValidate() {
        var mobileNumber = $("#supplier_phone").val();

        if (mobileNumber != '' && mobileNumber.length != 11) { 
            event.preventDefault();
            toastr.error("Mobile number must be 11 digit."); 
        }

        return true;
    }

    //To get purchase prodct data...
    function getPurchaseProductData() {
        let supplierId = $("#supplier_id").val();
        let purchaseId = $("#purchaseId").val();
        if (purchaseId !== '' && purchaseId !== null) {
            var url = "<?php echo e(route('check-purchase')); ?>";
            if (purchaseId != '') {
                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    }
                });
                $.ajax({
                    type: 'post',
                    url: url,
                    data: {
                        supplierId: supplierId,
                        purchaseId: purchaseId,
                    },
                    success: function (data) {
                        if (data.error) {
                            toastr.error(data.error);
                        } else {
                            // If a supplier is selected, update the href attribute with the purchaseId
                            var billPayUrl = "<?php echo e(route('get-purchase-product', ['id' => ':purchaseId'])); ?>";
                            billPayUrl = billPayUrl.replace(':purchaseId', purchaseId);
                            $("#purchasePayLink").attr("href", billPayUrl);
                            
                            // Now, trigger a click event on the anchor tag to navigate to the new URL
                            $("#purchasePayLink")[0].click();
                        }
                    }
                });
            }
        }
    }

    //To fetch next page product...
    function nextProductData() {
        event.preventDefault();
        var lastProductId = $("#lastProductId").val();
        var url = "<?php echo e(route('purchase.next-page-product-data')); ?>";
        if (lastProductId != null) {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $.ajax({
                type: 'post',
                url: url,
                data: {
                    lastProductId: lastProductId,
                },
                success: function (data) {
                    if (data.error) {
                        toastr.error(data.error);
                    } else {
                        $("#filterProductList").html(data);
                    }
                }
            });
        }
    }

    //To fetch previous page product...
    function previousProductData() {
        event.preventDefault();
        var lastProductId = $("#firstProductId").val();
        var url = "<?php echo e(route('purchase.previous-page-product-data')); ?>";
        if (lastProductId != null) {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $.ajax({
                type: 'post',
                url: url,
                data: {
                    lastProductId: lastProductId,
                },
                success: function (data) {
                    if (data.error) {
                        toastr.error(data.error);
                    } else {
                        $("#filterProductList").html(data);
                    }
                }
            });
        }
    }

    //To duplicate purchase product data...
    function duplicateItem(id) {
        var purchaseProductId = id;

        var url = "<?php echo e(route('duplicate-purchase-data')); ?>";
        if (purchaseProductId != '') {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $.ajax({
                type: 'post',
                url: url,
                data: {
                    purchaseProductId: purchaseProductId,
                },
                success: function (data) {
                    if(data.error){
                        toastr.error(data.error);
                    }else{
                        $("#updatePurchaseList").html(data);
                        toastr.success('Successfully product duplicate to list.');
                    }
                }
            });
        }
    }

    //productQuantity calculation singleProductPrice and totalProduct
    function productQuantityFMP(id) {
        let singleProductPrice = parseFloat($("#mrp_price_fmp" + id).val());
        let productQty = parseFloat($("#product_qty_fmp" + id).val());
    
        if (productQty >= 0) {
            let totalProductPrice = singleProductPrice * productQty;
            $("#total_product_price_fmp" + id).text(totalProductPrice);
            $("#total_product_price_fmp" + id).val(totalProductPrice);

        }else {
            $("#total_product_price_fmp" + id).text(0);
            $("#total_product_price_fmp" + id).val(0);
        }

    }

    //To update product details ----
    function updateProductDetails(id) {
        event.preventDefault();
        var purchaseProductId = $("#purchaseProductId" + id).val();
        var productQty = $("#product_qty_fmp" + id).val();
        var mrpPrice = $("#mrp_price_fmp" + id).val();
        var sellingPrice = $("#selling_price_fmp" + id).val();
        var totalProductPrice = $("#total_product_price_fmp" + id).val();

        var url = "<?php echo e(route('update.product-deatils')); ?>";
        if(purchaseProductId != ''){
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $.ajax({
                type: 'post',
                url: url,
                data: {
                    purchaseProductId: purchaseProductId,
                    productQty: productQty,
                    totalProductPrice: totalProductPrice,
                    mrpPrice: mrpPrice,
                    sellingPrice: sellingPrice,
                },

                success: function (data) {
                    if(data.error){
                        toastr.error(data.error);
                    }else{
                        toastr.success('Success product updated to purchase list.');

                        //To purchase modal to hide...
                        $("#updatePurProData" + purchaseProductId).modal('hide');
                        $("#updatePurchaseList").html(data);
                    }
                },
                error: function (jqXHR) {
                    if (jqXHR.status === 422) {
                        event.preventDefault();
                        toastr.error('Validation error occurred. Please check the required fields.');
                    } else {
                        toastr.error('An unexpected error occurred.');
                    }
                }
            });
        }

    }

    //To remove the purchase product data from product list....
    function deletePurchaseProduct(id) {
        event.preventDefault();
        var purchaseProductId = id;
        var url = "<?php echo e(route('purchase-list-remove-product')); ?>";
        if (purchaseProductId != '') {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $.ajax({
                type: 'post',
                url: url,
                data: {
                    purchaseProductId: purchaseProductId,
                },
                success: function (data) {
                    $("#updatePurchaseList").html(data);
                    toastr.success('Successfully product deleted from list.');
                }
            });
        }
    }

</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH E:\Project\Personal-Project\Office-Project\update\skin-care\resources\views/admin/productManage/purchaseProduct/edit.blade.php ENDPATH**/ ?>