

<?php $__env->startSection('title', 'Stock History - Finished Goods'); ?>

<?php $__env->startSection('content'); ?>
<div class="accordion mb-3" id="grnFilterAccordion">
	<div class="accordion-item">
		<h2 class="accordion-header" id="grnFilterHeading">
			<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#grnFilterCollapse" aria-expanded="false" aria-controls="grnFilterCollapse">
				Filters
			</button>
		</h2>
		<div id="grnFilterCollapse" class="accordion-collapse collapse" aria-labelledby="grnFilterHeading" data-bs-parent="#grnFilterAccordion">
			<div class="accordion-body">
                <div class="row mb-3">
                        <div class="col-md-3">
                            <label for="warehouse_filter">Warehouse</label>
                            <select id="warehouse_filter" class="form-select">
                                <option value="">All Warehouses</option>
                                <?php $__currentLoopData = $warehouses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $warehouse): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($warehouse->id); ?>" <?php echo e($warehouse->id == $warehouseID ? 'selected' : ''); ?>><?php echo e($warehouse->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="col-md-3">
                            <label for="item_filter">Item</label>
                            <?php echo $__env->make('common.item-select', [
                                'name' => 'item_filter',
                                'id' => 'item_filter',
                                'label' => 'Item',
                                'class' => 'form-select',
                                'placeholder' => 'All Items',
                                'allowClear' => true,
                                'selectedItem' => $selectedItem
                            ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                        </div>
                        <div class="col-md-3">
                            <label for="txn_type_filter">Type</label>
                            <select id="txn_type_filter" class="form-select">
                                <option value="">All Types</option>
                                <option value="inward">Inward</option>
                                <option value="outward">Outward</option>
                            </select>
                        </div>
                        <div class="col-md-3">
                            <label class="form-label">Date Range</label>
                            <input type="text" id="dateRange" class="form-control flatpickr" placeholder="Select date range">
                        </div>
                    </div>
                <div class="mt-3">
                    <button type="button" class="btn btn-primary" id="apply_Filters">
                        <i class="fas fa-search me-2"></i>
                        Apply
                    </button>
                    <button type="button" class="btn btn-outline-secondary" id="clear_Filters">
                        <i class="fas fa-times me-2"></i>
                        Clear
                    </button>
                </div>
            </div>
		</div>
	</div>
</div>
<?php if(session('success')): ?>
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            <i class="fas fa-check-circle me-2"></i>
            <?php echo e(session('success')); ?>

            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
    <?php endif; ?>

    <?php if($errors->any()): ?>
        <div class="alert alert-danger alert-dismissible fade show" role="alert">
            <i class="fas fa-exclamation-triangle me-2"></i>
            <?php echo e($errors->first()); ?>

            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
    <?php endif; ?>

    <div class="row">
        <div class="col-12">
            <div class="card">
                
                <div class="card-body">
                    <!-- Filters -->
<div class="d-flex justify-content-between align-items-center mb-3">
			<h6 class="card-title mb-0">Stock History - Finished Goods</h6>
</div>

                    <!-- DataTable -->
                    <div class="table-responsive">
                        <table id="stockHistoryTable" class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>Date</th>
                                    <th>Type</th>
                                    <th>Item Name</th>
                                    <th>Item Type</th>
                                    <th>Size</th>
                                    <th>M-Number</th>
                                    <th>Invoice Number</th>
                                    <th>Quantity</th>
                                    <!-- <th>Balance</th> -->
                                    <th>Warehouse</th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

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

<?php $__env->startPush('plugin-styles'); ?>
<link rel="stylesheet" href="<?php echo e(asset('theme/vendors/datatables/dataTables.bootstrap5.min.css')); ?>">
<link rel="stylesheet" href="<?php echo e(asset('theme/vendors/flatpickr/flatpickr.min.css')); ?>">
<?php $__env->stopPush(); ?>

<?php $__env->startPush('plugin-scripts'); ?>
<script src="<?php echo e(asset('theme/vendors/datatables/jquery.dataTables.min.js')); ?>"></script>
<script src="<?php echo e(asset('theme/vendors/datatables/dataTables.bootstrap5.min.js')); ?>"></script>
<script src="<?php echo e(asset('theme/vendors/flatpickr/flatpickr.min.js')); ?>"></script>
<?php $__env->stopPush(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
$(document).ready(function() {
    // Initialize Flatpickr
    flatpickr('#dateRange', {
        mode: 'range',
        dateFormat: 'Y-m-d',
        placeholder: 'Select date range'
    });

    // Initialize DataTable
    var table = $('#stockHistoryTable').DataTable({
        processing: true,
        serverSide: true,
        ajax: {
            url: '<?php echo e(route("warehouses.stock-history-finished-goods.data")); ?>',
            data: function(d) {
                d.warehouse_id = $('#warehouse_filter').val();
                d.item_id = $('#item_filter').val();
                d.txn_type = $('#txn_type_filter').val();

                const dateRange = $('#dateRange').val();
                if (dateRange) {
                    const [start, end] = dateRange.split(' to ');
                    d.date_from = start;
                    d.date_to = end;
                }
            }
        },
        columns: [
            {data: 'date', name: 'created_at'},
            {data: 'txn_marker', name: 'txn_marker'},
            {data: 'item_name', name: 'item_name'},
            {data: 'item_type', name: 'item_type'},
            {data: 'size', name: 'size'},
            {data: 'm_number', name: 'm_number'},
            {data: 'invoice_number', name: 'invoice_number'},
            {data: 'ac_qty', name: 'ac_qty', className: 'text-end'},
            // {data: 'ledger_qty', name: 'ledger_qty', className: 'text-end'},
            {data: 'warehouse_name', name: 'warehouse_name'},
        ],
        order: [[0, 'desc']],
        pageLength: 25,
        responsive: true
    });

    // Apply filters
    $('#apply_Filters').click(function() {
        table.draw();
    });

    // Clear filters
    $('#clear_Filters').click(function() {
        $('#warehouse_filter').val('').trigger('change');
        $('#item_filter').val('').trigger('change');
        $('#txn_type_filter').val('').trigger('change');
        $('#dateRange').val('');
        const fp = document.querySelector("#dateRange")._flatpickr;
        if (fp) {
            fp.clear();
        }
        table.draw();
    });
});
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\habibcables-ERP\resources\views\warehouses\stock-history-finished-goods.blade.php ENDPATH**/ ?>