<?php
require ROOT . "/pages/start.php"; ?>
<style>
    #upload_file {
        display: none;
    }
</style>
<?php
require ROOT . "/pages/header.php";

?>
<div class="page-header">
    <div class="page-header-left d-flex align-items-center">
        <div class="page-header-title">
            <h5 class="m-b-10 text-danger"><?= $this_on ?> ХИЧЭЭЛИЙН ЖИЛ</h5>
        </div>
        <ul class="breadcrumb">
            <li class="breadcrumb-item"><a href="/">Эхлэл</a></li>
            <li class="breadcrumb-item">"Б" цагийн тооцоо</li>
            <li class="breadcrumb-item">Статистик</li>
        </ul>
    </div>
</div>
<div class="main-content">
    <div class="card stretch stretch-full">
        <div class="card-header">
            <h5 class="card-title">Статистик</h5>
        </div>
        <div class="card-body overflow-auto">
            <div class="row">
                <div class="col">
                    <select class="form form-control mb-3" id="ajil_id">
                        <option value="1">Ажил, үйлчилгээний дэлгэрэнгүй</option>
                        <option value="2">Ажил, үйлчилгээ бодогдсон дүн (Кредитээр)</option>
                        <option value="3">Олон давтагдсан ажил, үйлчилгээ (Багшаар)</option>
                    </select>
                </div>
                <div class="col-md-2">
                    <select class="form form-control mb-3" id="year">
                        <?php
                        $currenton = $thison;
                        while ($currenton >= 2020) { ?>
                            <option <?php echo $currenton == 2020 ? "selected" : "" ?>><?= $currenton ?></option>
                        <?php $currenton--;
                        } ?>
                    </select>
                </div>
                <div class="col-md-2">
                    <select class="form form-control mb-3" id="toyear">
                        <?php
                        $currenton = $thison;
                        while ($currenton >= 2020) { ?>
                            <option <?php echo $currenton == $thison ? "selected" : "" ?>><?= $currenton ?></option>
                        <?php $currenton--;
                        } ?>
                    </select>
                </div>
                <div class="col-md-1">
                    <button class="btn btn-danger w-100" onclick="getreport()">ХАРАХ</button>
                </div>
                <div class="col-md-1">
                    <button class="btn btn-primary w-100" onclick="printdiv('data')">ХЭВЛЭХ</button>
                </div>
                <div class="col-md-1">
                    <button class="btn btn-success w-100" onclick="print()">EXCEL</button>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12" id="data">

                </div>
            </div>
        </div>
    </div>
</div>
<?php require ROOT . "/pages/main-end.php"; ?>
<?php
require ROOT . "/pages/footer.php"; ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script>
    function printdiv(printdivname) {
        var h = document.head;
        var headstr = "<html><body>";
        var footstr = "</body>";
        var newstr = document.getElementById(printdivname).innerHTML;
        var oldstr = document.body.innerHTML;
        document.body.innerHTML = headstr + newstr + footstr;
        window.print();
        document.body.innerHTML = oldstr;
        return false;
    }

    function getreport() {
        $.ajax({
            url: "analyst_ajax",
            type: "POST",
            data: {
                mode: 1,
                year: $('#year').val(),
                toyear: $('#toyear').val(),
                mode: $('#ajil_id').val()
            },
            error: function(xhr, textStatus, errorThrown) {
                $('#data').html("Алдаа гарлаа");
            },
            beforeSend: function() {
                $('#data').html("Түр хүлээнэ үү");
            },
            success: function(data) {
                $('#data').html(data);
            },
            async: true
        });
    }
</script>
<?php
require ROOT . "/pages/end.php";
?>