<!-- 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["sales_report"]; ?></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-3">
                    <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-lg-3 col-md-6 col-sm-12 mb-3">
                    <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-3">
                    <label class="form-label fw-medium text-uppercase"><?= $translate["sale_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" id="pay_det_sale_type" onchange="listDataToDatatable();" data-width="1%">
                        </select>
                    </div>
                </div>

                <div class="col-lg-3 col-md-6 col-sm-12 mb-3">
                    <label class="form-label fw-medium text-uppercase"><?= $translate["payment_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" id="pay_det_payment_type" onchange="listDataToDatatable();" data-width="1%">
                        </select>
                    </div>
                </div>

                <div class="col-lg-3 col-md-6 col-sm-12 mb-3">
                    <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="pay_det_created_by" onchange="listDataToDatatable();" data-width="1%">
                        </select>
                    </div>
                </div>

                <div class="col-lg-3 col-md-6 col-sm-12 mb-3">
                    <label class="form-label fw-medium text-uppercase"><?= $translate["group_by"]; ?></label>
                    <div class="input-group">
                        <span class="input-group-text"><i class="ph ph-grid-four"></i></span>
                        <select class="form-control form-control-lg select2" id="group_by_period" onchange="listDataToDatatable();" data-width="1%">
                            <option value="day" selected><?= $translate["day"]; ?></option>
                            <option value="month"><?= $translate["month"]; ?></option>
                            <option value="year"><?= $translate["year"]; ?></option>
                        </select>
                    </div>
                </div>

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

            </div>

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

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

            <table class="table table-sm table-hover sales-report-table">
                <thead>
                    <tr class="table-dark text-uppercase">
                        <th><?= $translate["date"]; ?></th>
                        <th><?= $translate["branch"]; ?></th>
                        <th><?= $translate["payment_type"]; ?></th>
                        <th><?= $translate["sale"]; ?></th>
                        <th><?= $translate["debt_collected"]; ?></th>
                        <th><?= $translate["total_income"]; ?></th>
                    </tr>
                </thead>
                <tfoot>
                    <tr class="table-dark text-uppercase fw-bold">
                        <td>__</td>
                        <td>__</td>
                        <td>__</td>
                        <td><span id="finalTotalIncomes">0.00</span></td>
                        <td><span id="finalTotalDebtCollected">0.00</span></td>
                        <td><span id="finalTotalGeneral">0.00</span></td>
                    </tr>
                </tfoot>
            </table>

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

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

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



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