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

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

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

            <?php
            if ($_SESSION["user_profile"] == "Waiter" || $_SESSION["user_profile"] == "Cashier") { ?>

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

            <?php } else { ?>

                <div class="row border-bottom pb-2">
                    <div class="col-xl-9 col-lg-9">
                        <h4 class="page-title fw-bold col-md-6 mb-0"><?= $translate["products_list"]; ?></h4>
                    </div>

                    <div class="col-xl-3 col-lg-3 col-md-6 btn-group">
                        <button class="btn btn-indigo text-uppercase btnAddProduct" type="button"> <i class="ph-plus me-1"></i> <?= $translate["new_product"]; ?></button>
                    </div>
                </div>

            <?php } ?>

            <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["type"]; ?></label>
                    <div class="input-group">
                        <span class="input-group-text"><i class="ph ph-stack"></i></span>
                        <select class="form-control form-control-lg select2 searchType" data-width="1%" onchange="listDataToDatatable();">
                            <option value="All"><?= $translate["all"]; ?></option>
                            <option value="Product"><?= $translate["products"]; ?></option>
                            <option value="Service"><?= $translate["services"]; ?></option>
                        </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["status"]; ?></label>
                    <div class="input-group">
                        <span class="input-group-text"><i class="ph ph-list-checks"></i></span>
                        <select class="form-control form-control-lg select2 searchStatus" data-width="1%" onchange="listDataToDatatable();">
                            <option value="Enabled" selected><?= $translate["enabled"]; ?></option>
                            <option value="Disabled"><?= $translate["disabled"]; ?></option>
                        </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 -->

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

            <table class="table table-sm table-hover table-hover products-table">
                <thead>
                    <tr class="table-dark text-uppercase">
                        <th>#</th>
                        <th><?= $translate["code"]; ?></th>
                        <th><?= $translate["picture"]; ?></th>
                        <th><?= $translate["category"]; ?></th>
                        <th><?= $translate["product"]; ?></th>
                        <th><?= $translate["price"]; ?></th>
                        <th><?= $translate["festive_price"]; ?></th>
                        <th><?= $translate["stock"]; ?></th>
                        <th><?= $translate["status"]; ?></th>
                        <th><?= $translate["options"]; ?></th>
                    </tr>
                </thead>
            </table>

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

        <!-- /content area -->

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

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


<!-- PRODUCT MODAL -->
<div id="product-modal" class="modal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title span-modal-title"></h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <form action="" id="frmAddEditProduct" autocomplete="off" method="POST">

                <input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">

                <div class="modal-body">

                    <div class="row">

                        <input type="hidden" name="pro_id" id="pro_id">
                        <input type="hidden" name="pro_ent_id" id="pro_ent_id">
                        <input type="hidden" name="pro_pos_id" id="pro_pos_id">

                        <div class="mb-4 text-uppercase fw-medium notAllowed">
                            <div class="col-lg-12">
                                <div class="input-group">
                                    <span class="input-group-text form-control form-control-lg content-left"><?= $translate["branch"]; ?></span>
                                    <span class="input-group-text form-control form-control-lg pos_description content-right"></span>
                                </div>
                            </div>
                        </div>

                        <div class="row mb-3">
                            <label class="col-lg-3 col-form-label"><?= $translate["barcode"]; ?></label>
                            <div class="col-lg-9">
                                <div class="input-group">
                                    <span class="input-group-text"><i class="ph-barcode"></i></span>
                                    <input type="text" class="form-control form-control-lg" name="pro_code" id="pro_code" required autocomplete="off" placeholder="<?= $translate["barcode"]; ?>">
                                </div>
                            </div>
                        </div>

                        <div class="row mb-3">
                            <label class="col-lg-3 col-form-label"><?= $translate["category"]; ?> <span class="text-danger fs-15px">*</span></label>
                            <div class="col-lg-9">
                                <select class="form-control form-control-lg select2" data-minimum-results-for-search="Infinity" name="pro_cat_id" id="pro_cat_id">
                                </select>
                            </div>
                        </div>

                        <div class="row mb-3">
                            <label class="col-lg-3 col-form-label"><?= $translate["description"]; ?> <span class="text-danger fs-15px">*</span></label>
                            <div class="col-lg-9">
                                <input type="text" class="form-control form-control-lg" name="pro_description" id="pro_description" required autocomplete="off" placeholder="<?= $translate["description"]; ?>">
                            </div>
                        </div>

                        <div class="row mb-3">
                            <label class="col-lg-3 col-form-label"><?= $translate["type"]; ?> <span class="text-danger fs-15px">*</span></label>
                            <div class="col-lg-9">
                                <select class="form-control form-control-lg select2" data-minimum-results-for-search="Infinity" name="pro_type" id="pro_type">
                                    <option value="Product" selected><?= $translate['product'] ?></option>
                                    <option value="Service"><?= $translate['service'] ?></option>
                                </select>
                            </div>
                        </div>

                        <?php
                        if ($posInfo["pos_business_category"] == "Others") { ?>
                            <div class="row mb-3">
                                <label class="col-lg-3 col-form-label"><?= $translate["sale_measure"]; ?> <span class="text-danger fs-15px">*</span></label>
                                <div class="col-lg-9">
                                    <select class="form-control form-control-lg select2" data-minimum-results-for-search="Infinity" name="pro_sale_measure" id="pro_sale_measure">
                                        <option value="Unit" selected><?= $translate['unit'] ?></option>
                                        <option value="Pound"><?= $translate['pound'] ?></option>
                                    </select>
                                </div>
                            </div>
                        <?php } else { ?>
                            <input type="hidden" name="pro_sale_measure" id="pro_sale_measure" value="Unit">
                        <?php } ?>

                        <div class="row mb-3">
                            <label class="col-lg-3 col-form-label"><?= $translate["price"]; ?> <span class="text-danger fs-15px">*</span></label>
                            <div class="col-lg-9">
                                <div class="input-group">
                                    <span class="input-group-text"><i class="ph-currency-dollar"></i></span>
                                    <input type="number" step="0.01" min="0" class="form-control form-control-lg" name="pro_price" id="pro_price" required autocomplete="off" placeholder="0.00">
                                </div>
                            </div>
                        </div>

                        <?php
                        if ($posInfo["pos_business_category"] == "Restaurant" || $posInfo["pos_business_category"] == "Nightclub") { ?>
                            <div class="row mb-3 divFestivePrice">
                                <label class="col-lg-3 col-form-label"><?= $translate["festive_price"]; ?> (<?= $translate["high"]; ?>)</label>
                                <div class="col-lg-9">
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="ph-currency-dollar"></i></span>
                                        <input type="number" step="0.01" min="0" class="form-control form-control-lg" name="pro_price_party" id="pro_price_party" required autocomplete="off" placeholder="0.00">
                                    </div>
                                </div>
                            </div>
                        <?php } else { ?>
                            <input type="hidden" name="pro_price_party" id="pro_price_party" value="0">
                        <?php } ?>

                        <div class="row mb-3">
                            <label class="col-lg-3 col-form-label"><?= $translate["image"]; ?></label>
                            <div class="col-lg-6 col-md-6">
                                <input type="file" class="form-control form-control-lg new_picture" name="pro_image" id="pro_image">
                                <div class="form-text fw-medium text-muted"><?= $translate["accepted_formats_png_jpg_2_mb"]; ?></div>
                            </div>
                            <div class="col-lg-3 col-md-3 text-end">
                                <img src="assets/images/no-image.png" class="w-100px h-100px rounded-pill picturePreview">
                            </div>
                        </div>

                    </div>

                </div>

            </form>

            <div class="modal-footer">
                <button type="button" class="btn btn-indigo text-uppercase btnSave"><i class="ph-floppy-disk-back me-1"></i> <?= $translate["save"]; ?></button>
                <button type="button" class="btn btn-indigo text-uppercase btnEdit"><i class="ph-floppy-disk-back me-1"></i> <?= $translate["save"]; ?></button>
                <button type="button" class="btn btn-light text-uppercase" data-bs-dismiss="modal"><i class="mi-close me-1"></i> <?= $translate["close"]; ?></button>
            </div>
        </div>
    </div>
</div>
<!-- PRODUCT MODAL -->


<!-- STOCK ADJUST MODAL -->
<div id="stock-adjust-modal" class="modal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><?= $translate["stock_adjustment"]; ?></h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <form action="" id="frmStockAdjust" autocomplete="off" method="POST" enctype="multipart/form-data">

                <input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">

                <div class="modal-body">

                    <div class="row">

                        <input type="hidden" name="adjust_ent_id" id="adjust_ent_id">
                        <input type="hidden" name="adjust_pos_id" id="adjust_pos_id">
                        <input type="hidden" name="adjust_product_id" id="adjust_product_id">
                        <input type="hidden" name="adjust_current_stock" id="adjust_current_stock">

                        <div class="mb-2 text-uppercase fw-medium notAllowed" style="display: none">
                            <div class="col-lg-12">
                                <div class="input-group">
                                    <span class="input-group-text form-control form-control-lg content-left"><?= $translate["branch"]; ?></span>
                                    <span class="input-group-text form-control form-control-lg pos_description content-right"></span>
                                </div>
                            </div>
                        </div>

                        <div class="col-lg-12 col-md-12 mb-2">
                            <label class="col-form-label"><?= $translate["product"]; ?></label>
                            <div class="input-group">
                                <span class="input-group-text form-control form-control-lg" id="span_pro_description"></span>
                            </div>
                        </div>

                        <div class="col-lg-6 col-md-6 mb-2">
                            <label class="col-form-label"><?= $translate["adjust"]; ?> <span class="text-danger fs-15px">*</span></label>
                            <select class="form-control form-control-lg select2" data-minimum-results-for-search="Infinity" name="adjust_type" id="adjust_type">
                                <option value="Increase" selected><?= $translate['increase'] ?></option>
                                <option value="Decrease"><?= $translate['decrease'] ?></option>
                            </select>
                        </div>

                        <div class="col-lg-6 col-md-6 mb-2">
                            <label class="col-form-label"><?= $translate["current_stock"]; ?></label>
                            <div class="input-group">
                                <span class="input-group-text form-control form-control-lg" id="span_current_stock"></span>
                            </div>
                        </div>

                        <div class="col-lg-6 col-md-6 mb-2">
                            <label class="col-form-label"><?= $translate["quantity"]; ?> <span class="text-danger fs-15px">*</span></label>
                            <input type="number" min="0" class="form-control form-control-lg" name="adjust_quantity" id="adjust_quantity" value="0">
                            <!-- <div class="input-group">
                                <button type="button" class="btn btn-light btn-icon" onclick="this.parentNode.querySelector('input[type=number]').stepDown()">
                                    <i class="ph-minus ph-sm"></i>
                                </button>
                                <input class="form-control form-control-lg form-control-number text-center" type="number" name="adjust_quantity" id="adjust_quantity" value="0">
                                <button type="button" class="btn btn-light btn-icon" onclick="this.parentNode.querySelector('input[type=number]').stepUp()">
                                    <i class="ph-plus ph-sm"></i>
                                </button>
                            </div> -->
                        </div>

                        <div class="col-lg-6 col-md-6 mb-2">
                            <label class="col-form-label"><?= $translate["final_stock"]; ?></label>
                            <div class="input-group">
                                <span class="input-group-text form-control form-control-lg" id="span_final_stock"></span>
                            </div>
                        </div>

                        <div class="col-lg-12">
                            <label class="col-form-label"><?= $translate["adjustment_reason"]; ?> <span class="text-danger fs-15px">*</span></label>
                            <textarea rows="3" class="form-control" name="adjust_reason" id="adjust_reason" placeholder="<?= $translate["note"]; ?>"></textarea>
                        </div>

                    </div>

                </div>

            </form>

            <div class="modal-footer">
                <button type="button" class="btn btn-indigo text-uppercase btnSaveAdjustStock"><i class="ph-floppy-disk-back me-1"></i> <?= $translate["save"]; ?></button>
                <button type="button" class="btn btn-light text-uppercase" data-bs-dismiss="modal"><i class="mi-close me-1"></i> <?= $translate["close"]; ?></button>
            </div>
        </div>
    </div>
</div>
<!-- STOCK ADJUST MODAL -->

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