<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>

<script>
    //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) {
        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 /**PATH E:\Project\Personal-Project\Office-Project\update\skin-care\resources\views/admin/productManage/purchaseProduct/productPurchaseList.blade.php ENDPATH**/ ?>