/home/awneajlw/.trash/storage.2/framework/views/ec2f9a6c0dc7702712bd6a64675deeaa.php
<?php echo $__env->make('admin.component.header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

<?php echo $__env->make('admin.component.topnav', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php echo $__env->make('admin.component.navbar', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

<div class="content-body">
    <div class="container-fluid mt-3">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="row justify-content-center">
                        <div class="col-md-8 p-5">
                            <h4><?php echo e(__('SE.sale_form')); ?></h4>

                            <!-- Search Form -->
                            <form id="searchForm" class="mb-4">
                                <div class="input-group">
                                    <input type="text" id="searchInput" class="form-control"
                                        placeholder="Search for products...">
                                    <div class="input-group-append">
                                        <button type="button" id="searchButton" class="btn btn-primary"><?php echo e(__('SE.search')); ?></button>
                                    </div>
                                </div>
                            </form>

                            <!-- Inventory Form -->
                            <form action="<?php echo e(route('sales.store')); ?>" method="POST">
                                <?php echo csrf_field(); ?>


                                <div class="form-group">
                                    <label for="direction"><?php echo e(__('SE.direction')); ?></label>
                                    <select name="direction" class="form-select" id="" required>
                                        <option selected disabled>Select Direction</option>
                                        <option value="vertical"><?php echo e(__('SE.vertical')); ?></option>
                                        <option value="horizontal"><?php echo e(__('SE.horizontal')); ?></option>
                                    </select>

                                </div>
                                <div class="form-group">
                                    <label for="language"><?php echo e(__('SE.language_select')); ?></label>
                                    <select name="language" class="form-select" id="" required>
                                        <option selected disabled>Select Language</option>

                                        <option value="arabic"><?php echo e(__('SE.arabic')); ?></option>
                                        <option value="english"><?php echo e(__('SE.english')); ?></option>
                                    </select>

                                </div>
                                <div class="form-group">
                                    <label for="buyer_name"><?php echo e(__('SE.buyer_name')); ?></label>
                                    <input type="text" name="buyer_name" class="form-control" required>
                                </div>
                                <div class="form-group">
                                    <label for="buyer_name"><?php echo e(__('SE.vat_number')); ?></label>
                                    <input type="text" name="vat_no" id="vat_no" placeholder="VAT Number (Optional)"
                                        class="form-control">
                                </div>

                                <?php $__currentLoopData = $inventories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $inventory): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <div class="form-group row" id="product-<?php echo e($inventory->id); ?>">
                                    <div class="col-6">
                                        <input type="checkbox" name="inventory_ids[]" id="check_<?php echo e($inventory->id); ?>"
                                            value="<?php echo e($inventory->id); ?>">
                                        <label><?php echo e($inventory->name); ?>, Price: <?php echo e($inventory->price); ?> USD , Quantity: <?php echo e($inventory->quantity); ?> </label>
                                        <input type="number" id="quantity_<?php echo e($inventory->id); ?>" disabled
                                            onchange="calculateFinalPrice(<?php echo e($inventory->id); ?>)" name="quantities[]"
                                            placeholder="<?php echo e(__('SE.quantity')); ?>" min="1"
                                            max="<?php echo e($inventory->quantity); ?>" class="form-control">
                                    </div>
                                    <div class="col-3">
                                        <label for="price">Price:</label>
                                        <input type="number" id="price_<?php echo e($inventory->id); ?>"
                                            onchange="calculateFinalPrice(<?php echo e($inventory->id); ?>)" disabled
                                            name="prices[]" value="<?php echo e($inventory->price); ?>" class="form-control">
                                    </div>
                                    <div class="col-3">
                                        <label for="price">Calculated Price:</label>
                                        <span class="form-control" id="final_price_<?php echo e($inventory->id); ?>"></span>
                                    </div>

                                </div>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                <div class="row">
                                    <div class="col-5"></div>
                                    <div class="col-4">
                                        <button type="submit" class="btn btn-primary mt-4"><?php echo e(__('SE.create_bill')); ?></button>
                                    </div>
                                    <div class="col-3">
                                        <label for="price">Total Price:</label>
                                        <span class="form-control" id="total_price"></span>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>


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

        <div class="row">
            <div class="col-12">
                <div class="card">

                    <div class="row mt-4">
                        <div class="col">
                            <div class="card" style="overflow:auto; width:100% !important;">
                                <h3 class="text-center m-2"><?php echo e(__('SE.sold_items')); ?></h3>
                                <div class="card-header">
                                    <div class="col-md-12"
                                        style="background:white;  display: flex;  flex-wrap: wrap; flex-direction: row; justify-content: space-between;">

                                        <p style="margin-top: 14px;"><i class="fa fa-cart"></i> </p>


                                        <form id="filter-form"
                                            style="display:flex; align-items:center;  flex-wrap: nowrap; justify-content: space-between; margin-bottom: 0px;">

                                            <label for="from_date" class="me-2 h4"></label>
                                            <input type="date" id="from_date" class="me-2 form-control" name="from_date"
                                                style="width:40%;">

                                            <label for="to_date" class="me-2 h4">-</label>
                                            <input type="date" id="to_date" class="me-2 form-control" name="to_date"
                                                style="width:40%;">

                                            <button type="submit" class=" me-2 btn btn-primary" style="padding: 9px;"><i
                                                    class="fas fa-check"></i></button>

                                        </form>

                                    </div>

                                </div>


                                <div class="card-body" v-cloak>



                                    <div class="table-responsive">
                                        <table class="table table-hover sale-listing table-listing table-hover "
                                            style=" width:100%;">
                                            <thead>
                                                <tr>

                                                    <th><?php echo e(__('SE.id')); ?></th>

                                                    <th><?php echo e(__('SE.category')); ?></th>
                                                    <th><?php echo e(__('SE.name')); ?></th>
                                                    <th><?php echo e(__('SE.description')); ?></th>
                                                    <th><?php echo e(__('SE.quantity')); ?></th>

                                                    <th><?php echo e(__('SE.created_at')); ?></th>

                                                </tr>
                                            </thead>
                                            <tbody>

                                            </tbody>
                                        </table>
                                    </div>



                                </div>


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

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

<?php echo $__env->make('admin.component.footer', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

<script>
    document.getElementById('searchButton').addEventListener('click', function() {
        const searchValue = document.getElementById('searchInput').value.toLowerCase();
        const productElements = document.querySelectorAll('[id^="product-"]');

        for (let productElement of productElements) {
            const label = productElement.querySelector('label').innerText.toLowerCase();
            if (label.includes(searchValue)) {
                productElement.scrollIntoView({ behavior: 'smooth' });
                break;
            }
        }
    });
</script>




<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>

<script src="https://code.jquery.com/jquery-3.7.0.js"></script>

<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js" defer></script>

<script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap4.min.js" defer></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap4.min.css">





<script type="text/javascript">
    $(function() {
        setTimeout(function() {
            var table = $('.sale-listing').DataTable({
                processing: true,
                serverSide: true,
                ajax: {
                    url: "<?php echo e(url('/branch-sale-list')); ?>",
                    data: function(d) {
                        d.from_date = $('#from_date').val();
                        d.to_date = $('#to_date').val();
                        d.id = <?php echo e($user->branch_id); ?>;

                    }
                },

                columns: [
                    {
                        data: 'inventory_id',
                        name: 'inventory_id'
                    },
                    {
                        data: 'category_id',
                        name: 'category_id'
                    },
                    {
                        data: 'inventory_name',
                        name: 'inventory_name'
                    },
                    {
                        data: 'inventory_description',
                        name: 'inventory_description'
                    },
                    {
                        data: 'total_quantity_sold',
                        name: 'total_quantity_sold'
                    },


                    {
                        data: 'created_by',
                        name: 'created_by'
                    },

                ],
                order: [
                    [0, 'desc']
                ],
            });

            $('#filter-form').on('submit', function(e) {
                e.preventDefault();
                $('.sale-listing').DataTable().ajax.reload();
            });

        }, 2000);
    });

    function calculateFinalPrice(id) {
        const quantity = document.getElementById(`quantity_${id}`).value;
        const price = document.getElementById(`price_${id}`).value;
        let finalPrice = quantity * price;

        document.getElementById(`final_price_${id}`).innerText = finalPrice.toFixed(2);

        let total = 0;
        document.querySelectorAll('[id^="final_price_"]').forEach(element => {
            let value = parseFloat(element.innerText) || 0;
            total += value;
        });

        document.getElementById('total_price').innerText = total.toFixed(2);
    }


    function toggleInputs(id) {
        const checkbox = document.getElementById(`check_${id}`);
        const quantityInput = document.getElementById(`quantity_${id}`);
        const priceInput = document.getElementById(`price_${id}`);

        if (checkbox.checked) {
            quantityInput.removeAttribute('disabled');
            priceInput.removeAttribute('disabled');
        } else {
            quantityInput.setAttribute('disabled', 'true');
            priceInput.setAttribute('disabled', 'true');
            quantityInput.value = '';
            calculateFinalPrice(id);
        }
    }

    document.querySelectorAll('[id^="check_"]').forEach(checkbox => {
        checkbox.addEventListener('change', function () {
            toggleInputs(this.value);
        });
    });


</script>
<?php /**PATH C:\xampp\htdocs\safeEye\resources\views/admin/subAdmin/index.blade.php ENDPATH**/ ?>