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

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

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

            <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["sales_list"]; ?></h4>
                </div>
                <div class="col-xl-3 col-lg-3 col-md-6 btn-group">
                    <button class="btn btn-indigo text-uppercase btnAddSale" type="button"> <i class="ph-plus me-2"></i> <?= $translate["new_sale"]; ?></button>
                </div>
            </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-xl-3 col-lg-4 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" data-width="1%">
                        </select>
                    </div>
                </div>

                <div class="col-xl-3 col-lg-4 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>

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

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

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

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

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

                            <button type="button" class="btn btn-indigo btnCashBox btn-icon"><i class="icon-cash3 me-2"></i> <?= $translate["cash_box"]; ?></button>

                        <?php } ?>
                    </div>
                </div>

            </div>

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

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

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

            <ul class="nav nav-tabs nav-tabs-highlight nav-justified mb-3">
                <li class="nav-item">
                    <a href="#js-pending-list" class="nav-link text-uppercase active" data-bs-toggle="tab">
                        <?= $translate['pending_sales']; ?>
                    </a>
                </li>

                <li class="nav-item">
                    <a href="#js-completed-list" class="nav-link text-uppercase" data-bs-toggle="tab">
                        <?= $translate['completed_sales']; ?>
                    </a>
                </li>

                <li class="nav-item">
                    <a href="#js-canceled-list" class="nav-link text-uppercase" data-bs-toggle="tab">
                        <?= $translate['canceled_sales']; ?>
                    </a>
                </li>
            </ul>

            <div class="tab-content">
                <div class="tab-pane fade show active" id="js-pending-list">

                    <table class="table table-sm table-hover pending-sales-table">
                        <thead>
                            <tr class="table-dark text-uppercase">
                                <th>#</th>
                                <th><?= $translate["branch"]; ?></th>
                                <th><?= $translate["date"]; ?> </th>
                                <th><?= $translate["attended_by"]; ?> </th>
                                <th><?= $translate["customer"]; ?></th>
                                <th><?= $translate["type"]; ?></th>
                                <th><?= $translate["total"]; ?></th>
                                <th><?= $translate["debt"]; ?></th>
                                <th><?= $translate["status"]; ?></th>
                                <th><?= $translate["options"]; ?></th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr class="table-dark text-uppercase fw-bold">
                                <td>__</td>
                                <td>__</td>
                                <td>__</td>
                                <td>__</td>
                                <td>__</td>
                                <td>__</td>
                                <td><span id="finalPendingTotal">0.00</span></td>
                                <td><span id="finalPendingDebt">0.00</span></td>
                                <td>__</td>
                                <td>__</td>
                        </tfoot>
                    </table>

                </div>

                <div class="tab-pane fade" id="js-completed-list">

                    <table class="table table-sm table-hover completed-sales-table">
                        <thead>
                            <tr class="table-dark text-uppercase">
                                <th>#</th>
                                <th><?= $translate["branch"]; ?></th>
                                <th><?= $translate["date"]; ?> </th>
                                <th><?= $translate["attended_by"]; ?> </th>
                                <th><?= $translate["customer"]; ?></th>
                                <th><?= $translate["type"]; ?></th>
                                <th><?= $translate["total"]; ?></th>
                                <!-- <th><?= $translate["debt"]; ?></th> -->
                                <th><?= $translate["status"]; ?></th>
                                <th><?= $translate["options"]; ?></th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr class="table-dark text-uppercase fw-bold">
                                <td>__</td>
                                <td>__</td>
                                <td>__</td>
                                <td>__</td>
                                <td>__</td>
                                <td>__</td>
                                <td><span id="finalCompletedTotal">0.00</span></td>
                                <!-- <td><span id="finalCompletedDebt">0.00</span></td> -->
                                <td>__</td>
                                <td>__</td>
                        </tfoot>
                    </table>

                </div>

                <div class="tab-pane fade" id="js-canceled-list">

                    <table class="table table-sm table-hover canceled-sales-table">
                        <thead>
                            <tr class="table-dark text-uppercase">
                                <th>#</th>
                                <th><?= $translate["branch"]; ?></th>
                                <th><?= $translate["date"]; ?> </th>
                                <th><?= $translate["attended_by"]; ?> </th>
                                <th><?= $translate["customer"]; ?></th>
                                <th><?= $translate["type"]; ?></th>
                                <th><?= $translate["total"]; ?></th>
                                <th><?= $translate["debt"]; ?></th>
                                <th><?= $translate["status"]; ?></th>
                                <th><?= $translate["options"]; ?></th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr class="table-dark text-uppercase fw-bold">
                                <td>__</td>
                                <td>__</td>
                                <td>__</td>
                                <td>__</td>
                                <td>__</td>
                                <td>__</td>
                                <td><span id="finalCanceledTotal">0.00</span></td>
                                <td><span id="finalCanceledDebt">0.00</span></td>
                                <td>__</td>
                                <td>__</td>
                        </tfoot>
                    </table>

                </div>
            </div>

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


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

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

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


<!-- PRINT CASH SUMMARY MODAL -->
<div id="showCashSummaryModal" class="modal" data-bs-keyboard="false" data-bs-backdrop="static" tabindex="-1">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">

            <div id="printDivCashSummaryHidden" style="display: none;"></div>
            <div id="printDivCashSummary" style="margin-left: 20px; margin-right: 20px; margin-top: 20px;"></div>

            <div class="modal-footer d-flex justify-content-center mt-3">
                <div class="col-sm-12 btn-group d-flex gap-1">
                    <button type="button" class="btn btn-indigo" onclick="printTicketCashSummary()"><i class="ph-printer me-1"></i> <?= $translate["print"]; ?></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>
</div>
<!-- PRINT CASH SUMMARY MODAL -->

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