<?php $__env->startSection('title'); ?><?php echo app('translator')->get('quickadmin.inventory.inventory_report'); ?><?php $__env->stopSection(); ?>
<?php $__env->startSection('customCss'); ?>
<?php $__env->startSection('hide-loader'); ?>
<meta name="csrf-token" content="<?php echo e(csrf_token()); ?>" >
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.css" />
<link rel="stylesheet" href="<?php echo e(asset('admintheme/assets/css/printView-datatable.css')); ?>">
<?php $__env->stopSection(); ?>
<?php $__env->startSection('main-content'); ?>

<div class="card MainBox">
    <div class="mainHeading">
        <h4><?php echo app('translator')->get('quickadmin.inventory.inventory_report'); ?></h4>
        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('estimate_date_filter_access')): ?>
        <!-- <div class="">
            <form id="invoice-filter-form">
                <div class="cart_filter_box">                                
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('estimate_date_filter_access')): ?>
                    <div class="mx-0 datapikergroup custom-select2 floatingLabel">
                        <div class="form-control-inner form-group">
                            <label for="reportrange">Select Date</label>
                            <div id="reportrange" class="pull-right">
                                <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>&nbsp;
                                <span></span> <b class="caret"></b>
                            </div>
                        </div>
                    </div>
                    <?php endif; ?>
                    <div class="form-group mb-0">
                        <button type="submit" class="btn addRecordBtn addBtn" id="apply-filter"><?php echo app('translator')->get('quickadmin.qa_submit'); ?></button>
                        <button type="reset" class="btn addRecordBtn addBtn" id="reset-filter"><?php echo app('translator')->get('quickadmin.qa_reset'); ?></button>
                    </div>                             
                </div>
            </form>
        </div> -->
        <?php endif; ?>

        <div class="">
            <form id="invoice-filter-form">
                <div class="cart_filter_box">
                    <div class="mx-0 custom-select2 floatingLabel floatingFlex">
                        <div class="form-control-inner form-group">
                            <label for="brand_id"><?php echo app('translator')->get('quickadmin.inventory.fields.brand_name'); ?></label>
                            <div class="input-group">
                                <select name="brand_id" class="form-control select2" id="brand_id">
                                    <option value="" selected><?php echo app('translator')->get('quickadmin.inventory.select_brand_name'); ?></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(isset($product) && $product->brand_id == $brand->id ? 'selected' : ''); ?>>
                                            <?php echo e($brand->name ?? ''); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                        </div>

                        <div class="form-control-inner form-group">
                            <label for="storage_type"><?php echo app('translator')->get('quickadmin.inventory.fields.storage_type'); ?></label>
                            <div class="input-group">
                                <select name="storage_type" class="form-control select2" id="storage_type">
                                    <option value="" selected><?php echo app('translator')->get('quickadmin.inventory.select_storage_type'); ?></option>
                                    <?php $__currentLoopData = $storageTypes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $place): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($key); ?>"><?php echo e($place); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <button type="submit" class="btn addRecordBtn addBtn" id="apply-filter" title="<?php echo app('translator')->get('quickadmin.qa_submit'); ?>"><i class="fa fa-paper-plane" aria-hidden="true"></i>
                            <?php echo app('translator')->get('quickadmin.qa_submit'); ?></button>
                        <button type="button" class="btn addRecordBtn addBtn" id="reset-filter" title="<?php echo app('translator')->get('quickadmin.qa_reset'); ?>"><i class="fa fa-refresh" aria-hidden="true"></i>
                            <?php echo app('translator')->get('quickadmin.qa_reset'); ?></button>
                    </div>
                    <div class="top_both_btn">
                        <a href="<?php echo e(route('inventory-view.allprint')); ?>" class="btn addRecordBtn addBtn" id="inventory-print" title="Print"> <?php if (isset($component)) { $__componentOriginal4fc2bce81e6643975498c1caac0c8935 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal4fc2bce81e6643975498c1caac0c8935 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.svg-icon','data' => ['icon' => 'print']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('svg-icon'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['icon' => 'print']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal4fc2bce81e6643975498c1caac0c8935)): ?>
<?php $attributes = $__attributesOriginal4fc2bce81e6643975498c1caac0c8935; ?>
<?php unset($__attributesOriginal4fc2bce81e6643975498c1caac0c8935); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal4fc2bce81e6643975498c1caac0c8935)): ?>
<?php $component = $__componentOriginal4fc2bce81e6643975498c1caac0c8935; ?>
<?php unset($__componentOriginal4fc2bce81e6643975498c1caac0c8935); ?>
<?php endif; ?><?php echo app('translator')->get('quickadmin.print'); ?></a>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="card-body p-0">
        <div class="table-responsive fixed_Search inventory-table inventory-table-view">
            <?php echo e($dataTable->table(['class' => 'table dt-responsive invoicdatatable order_table_custom', 'style' => 'width:100%;','id'=>'dataaTable'])); ?>

        </div>
    </div>
</div>
<div class="popup_render_div"></div>

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


<?php $__env->startSection('customJS'); ?>
<?php echo $dataTable->scripts(); ?>

    <script src="<?php echo e(asset('admintheme/assets/bundles/datatables/datatables.min.js')); ?>"></script>
    <script src="<?php echo e(asset('admintheme/assets/bundles/datatables/DataTables-1.10.16/js/dataTables.bootstrap4.min.js')); ?>"></script>
    <script src="<?php echo e(asset('admintheme/assets/bundles/jquery-ui/jquery-ui.min.js')); ?>"></script>
    <!-- Page Specific JS File -->
    <script src="<?php echo e(asset('admintheme/assets/js/page/datatables.js')); ?>"></script>
    <script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
    <script type="text/javascript" src="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>
   
    <script type="text/javascript">
        $(function() {
            var date = '<?php echo e(config("app.start_date")); ?>';
            var start = moment(date, 'YYYY-MM-DD'); /*.moment().startOf('month')*/
            var end = moment();
            function cb(start, end) {
                $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
            }
            $('#reportrange').daterangepicker({
                startDate: start,
                endDate: end,
                ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
                }
            }, cb);
            cb(start, end);
        });
        var defaultStartDate = moment('<?php echo e(config("app.start_date")); ?>', 'YYYY-MM-DD');
        var defaultEndDate = moment();
    </script>

<script>
    var inventory_selectedIds = [];
    $(document).ready(function () {
        var dataTable = $('#dataaTable').DataTable();
        // $('#invoice-print').printPage();

        $('#inventory-print').printPage();
        // Page show from top when page changes
        $(document).on('draw.dt','#orders-table', function (e) {
            e.preventDefault();
            $('html, body').animate({
                scrollTop: 0
            }, 'fast');
        });
        
        $('#reset-filter').on('click', function(e) {
            e.preventDefault();
            $('#invoice-filter-form')[0].reset();       
            //Reset the Daterangepicker
            if ($('#reportrange').data('daterangepicker')) {
                var start = defaultStartDate ?? null;
                var end = defaultEndDate ?? null;
                $('#reportrange').data('daterangepicker').setStartDate(start);
                $('#reportrange').data('daterangepicker').setEndDate(end);
                $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
            }
            dataTable.ajax.url("<?php echo e(route('inventory_list.view')); ?>").load();
            originalPrintUrl = "<?php echo e(route('orders.allprint')); ?>";
            $('#inventory-print').attr('href', "<?php echo e(route('inventory-view.allprint')); ?>");
            $('#invoice-print').attr('href', originalPrintUrl);
        });

        $(document).on('change', '#dt_cb_all', function(e)
        {
            e.preventDefault();
            var isChecked = $(this).prop('checked');
            $('.dt_checkbox').prop('checked', isChecked).trigger('change');
        });
        $(document).on('change', '.dt_checkbox', function (e) {
            e.preventDefault();

            inventory_selectedIds = [];
            $('.dt_checkbox:checked').each(function () {
                inventory_selectedIds.push($(this).val());
            });
            inventory_selectedIds = Array.from(new Set(inventory_selectedIds));

            var printUrl = "<?php echo e(route('inventory-view.allprint')); ?>";
            if (inventory_selectedIds.length > 0) {
                printUrl += "?inventory_id=" + encodeURIComponent(inventory_selectedIds.join(','));
            }
            $('#inventory-print').attr('href', printUrl);

            let baseText = "Print";
            if (inventory_selectedIds.length > 0) {
                $('#inventory-print').html(`<?php if (isset($component)) { $__componentOriginal4fc2bce81e6643975498c1caac0c8935 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal4fc2bce81e6643975498c1caac0c8935 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.svg-icon','data' => ['icon' => 'print']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('svg-icon'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['icon' => 'print']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal4fc2bce81e6643975498c1caac0c8935)): ?>
<?php $attributes = $__attributesOriginal4fc2bce81e6643975498c1caac0c8935; ?>
<?php unset($__attributesOriginal4fc2bce81e6643975498c1caac0c8935); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal4fc2bce81e6643975498c1caac0c8935)): ?>
<?php $component = $__componentOriginal4fc2bce81e6643975498c1caac0c8935; ?>
<?php unset($__componentOriginal4fc2bce81e6643975498c1caac0c8935); ?>
<?php endif; ?> ${baseText} (${inventory_selectedIds.length})`);
            } else {
                $('#inventory-print').html(`<?php if (isset($component)) { $__componentOriginal4fc2bce81e6643975498c1caac0c8935 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal4fc2bce81e6643975498c1caac0c8935 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.svg-icon','data' => ['icon' => 'print']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('svg-icon'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['icon' => 'print']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal4fc2bce81e6643975498c1caac0c8935)): ?>
<?php $attributes = $__attributesOriginal4fc2bce81e6643975498c1caac0c8935; ?>
<?php unset($__attributesOriginal4fc2bce81e6643975498c1caac0c8935); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal4fc2bce81e6643975498c1caac0c8935)): ?>
<?php $component = $__componentOriginal4fc2bce81e6643975498c1caac0c8935; ?>
<?php unset($__componentOriginal4fc2bce81e6643975498c1caac0c8935); ?>
<?php endif; ?> ${baseText}`);
            }

            if (!this.checked) {
                $('#dt_cb_all').prop('checked', false);
            } else {
                if ($('.dt_checkbox:checked').length === $('.dt_checkbox').length) {
                    $('#dt_cb_all').prop('checked', true);
                }
            }
        });

        $('#invoice-filter-form').on('submit', function(e) {
            e.preventDefault();
           
            var picker = $('#reportrange').data('daterangepicker');           
            if (picker && picker.startDate && picker.endDate) {
                var from_date = picker.startDate.format('YYYY-MM-DD');
                var to_date = picker.endDate.format('YYYY-MM-DD');
            } else {               
                var from_date = null;
                var to_date = null;
            }         
            if(from_date == undefined || from_date == 'Invalid date'){
                from_date = '';
            }
            if(to_date == undefined || to_date == 'Invalid date'){
                to_date = '';
            }        
           var printUrl = "<?php echo e(route('inventory_list.view')); ?>"            
            + '?from_date=' + encodeURIComponent(from_date)
            + '&to_date=' + encodeURIComponent(to_date);
            var params = {
                    from_date        : from_date,
                    to_date          : to_date,
            };
            dataTable.ajax.url("<?php echo e(route('inventory_list.view')); ?>?"+$.param(params)).load();
            $('#invoice-print').attr('href', printUrl);
        });
        
    });
    $(document).ready(function() {
        var table = $('#dataaTable').DataTable();

        $('#apply-filter').on('click', function(e) {
            e.preventDefault();

            table.ajax.reload();

            var printUrl = "<?php echo e(route('inventory-view.allprint')); ?>";
            var params = [];

            var brand_id = $('#brand_id').val();
            if (brand_id) params.push("brand_id=" + encodeURIComponent(brand_id));

            var storage_type = $('#storage_type').val();
            if (storage_type) params.push("storage_type=" + encodeURIComponent(storage_type));

            if (params.length > 0) printUrl += "?" + params.join("&");

            $('#inventory-print').attr('href', printUrl);
            // inventory_selectedIds = [];
            // $('.dt_checkbox').prop('checked', false);
        });

        $('#reset-filter').on('click', function() {
            $('#brand_id, #storage_type').val('').trigger('change');
            table.ajax.reload();
            $('#inventory-print').attr('href', "<?php echo e(route('inventory-view.allprint')); ?>");
            inventory_selectedIds = [];
            $('.dt_checkbox').prop('checked', false);
            $('#dt_cb_all').prop('checked', false); 
        });

        table.on('preXhr.dt', function(e, settings, data) {
            data.brand_id = $('#brand_id').val();
            data.storage_type = $('#storage_type').val();
        });

        $.fn.dataTable.ext.errMode = 'throw';

        table.on('draw.dt', function () {
            $('.dt_checkbox').each(function () {
                if (inventory_selectedIds.includes($(this).val())) {
                    $(this).prop('checked', true);
                }
            });
        });
    });



</script>

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

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/hipldemo2/public_html/billing-software.hipl-staging2.com/resources/views/admin/inventory/inventory_view.blade.php ENDPATH**/ ?>