<!-- Main content -->
<div class="content-wrapper">

    <!-- Inner content -->
    <div class="content-inner">

        <!-- card card-header -->
        <div class="card card-header mb-2">

            <div class="text-center border-bottom">
                <h4 class="page-title fw-bold"><?= $translate["adjustment_history"]; ?></h4>
            </div>

            <div class="row mt-3">

                <?php
                if ($_SESSION["user_profile"] == "ROOT") { ?>

                    <div class="col-lg-12 col-md-12 col-sm-12 mb-3">
                        <label class="form-label fw-medium text-uppercase"><?= $translate["enterprise"]; ?></label>
                        <div class="input-group">
                            <span class="input-group-text"><i class="ph ph-building-office"></i></span>
                            <select class="form-control form-control-lg select2" id="ent_id_value" onchange="selectBranchByUserPermission(this.value);" data-width="1%">
                                <?php

                                $sql = "SELECT ent_id,ent_name FROM tb_enterprises WHERE ent_contract_status = 'Enabled' ORDER BY ent_name ASC;";
                                $answer = executePDOFetchAll($sql, "");

                                foreach ($answer as $key => $value) {
                                    echo "<option value='{$value['ent_id']}' > {$value['ent_name']}</option>";
                                }

                                ?>
                            </select>
                        </div>
                    </div>

                <?php } else { ?>
                    <input type="hidden" id="ent_id_value" value="<?= $_SESSION["user_ent_id"]; ?>">
                <?php }
                ?>

                <div class="col-lg-3 col-md-6 col-sm-12 mb-2">
                    <label class="form-label fw-medium text-uppercase"><?= $translate["branch"]; ?></label>
                    <div class="input-group">
                        <span class="input-group-text"><i class="ph ph-storefront"></i></span>
                        <select class="form-control form-control-lg select2" id="pos_id_value" onchange="listDataToDatatable();" data-width="1%">
                        </select>
                    </div>
                </div>

                <div class="col-lg-3 col-md-6 col-sm-12 mb-2">
                    <label class="form-label fw-medium text-uppercase"><?= $translate["date_range"]; ?></label>
                    <div class="input-group">
                        <span class="input-group-text"><i class="ph-calendar"></i></span>
                        <input type="text" class="form-control form-control-lg daterange-predefined dateSelected" value="<?= date('Y-m-d', strtotime('-6 days')); ?> / <?= date('Y-m-d'); ?>" />
                    </div>
                </div>

                <div class="col-lg-3 col-md-6 col-sm-12 mb-2">
                    <label class="form-label fw-medium text-uppercase"><?= $translate["product"]; ?></label>
                    <div class="input-group">
                        <span class="input-group-text"><i class="ph ph-circles-four"></i></span>
                        <select class="form-control form-control-lg select2" id="prod_id_value" onchange="listDataToDatatable();" data-width="1%">
                        </select>
                    </div>
                </div>

                <div class="col-lg-2 col-md-6 col-sm-12 mb-2">
                    <label class="form-label fw-medium text-uppercase">&nbsp;</label>
                    <div class="btn-group d-flex">
                        <button type="button" class="btn btn-warning text-uppercase btnSearch"><i class="ph-magnifying-glass me-1"></i> <?= $translate["search"]; ?></button>
                    </div>
                </div>

            </div>

        </div>
        <!-- /card card-header -->


        <!-- Content area -->
        <!-- <div class="content"> -->

        <!-- Card layout -->
        <div class="card card-header mt-1">

            <table class="table table-sm table-hover stocks-adjustment-table">
                <thead>
                    <tr class="table-dark text-uppercase">
                        <th>#</th>
                        <th><?= $translate["branch"]; ?></th>
                        <th><?= $translate["date"]; ?></th>
                        <th><?= $translate["added_by"]; ?></th>
                        <th><?= $translate["product"]; ?></th>
                        <th><?= $translate["type"]; ?></th>
                        <th><?= $translate["quantity"]; ?></th>
                        <th><?= $translate["final"]; ?></th>
                        <th><?= $translate["actions"]; ?></th>
                    </tr>
                </thead>
            </table>

        </div>
        <!-- /Card layout -->


        <!-- </div> -->
        <!-- /content area -->

    </div>
    <!-- /inner content -->

</div>
<!-- /main content -->


<!-- View Product modal -->
<div id="stock-adjustment-view-modal" class="modal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><?= $translate["stock_adjustment_details"]; ?></h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">

                <table class="table table-hover table-bordered">
                    <tbody class="bg-light">
                        <tr>
                            <td width="30%"><?= $translate["product"]; ?></td>
                            <td><span id="stock_adjustment_product"></span></td>
                        </tr>
                        <tr>
                            <td width="30%"><?= $translate["adjustment_type"]; ?></td>
                            <td><span id="stock_adjustment_type"></span></td>
                        </tr>
                        <tr>
                            <td width="30%"><?= $translate["initial"]; ?></td>
                            <td><span id="stock_adjustment_initial"></span></td>
                        </tr>
                        <tr>
                            <td width="30%"><?= $translate["quantity"]; ?></td>
                            <td><span id="stock_adjustment_qty"></span></td>
                        </tr>
                        <tr>
                            <td width="30%"><?= $translate["final"]; ?></td>
                            <td><span id="stock_adjustment_final"></span></td>
                        </tr>
                        <tr>
                            <td width="30%"><?= $translate["reason"]; ?></td>
                            <td><span id="stock_adjustment_reason"></span></td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="mi-close me-1"></i> Close</button>
            </div>
        </div>
    </div>
</div>
<!-- /View Product modal -->

<script src="scripts/stock-adjustment.js?v=<?= md5(time()) ?>"></script>