<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php init_head(); ?>
<div id="wrapper">
    <div class="content">
        <div class="sm:tw-flex tw-space-y-3 sm:tw-space-y-0 tw-gap-6">
            <div class="sm:tw-border-r sm:tw-border-solid sm:tw-border-neutral-200 tw-pr-10 tw-w-80">
                <h4
                    class="tw-mt-0 tw-font-bold tw-text-lg tw-text-neutral-700 tw-ml-1.5 tw-inline-flex tw-items-center">
                    <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
                        stroke="currentColor" class="tw-w-5 tw-h-5 tw-mr-3 tw-ml-1">
                        <path stroke-linecap="round" stroke-linejoin="round"
                            d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25M9 16.5v.75m3-3v3M15 12v5.25m-4.5-15H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" />
                    </svg>

                    <?= _l('sales_report_heading'); ?>
                </h4>
                <ul class="reports tw-space-y-1">

                    <!--Ticket Report -->
                    <li>
  <a id="ticketsReportBtn" href="#"
   class="group tw-font-medium tw-px-2 tw-py-2 tw-text-neutral-500 hover:tw-text-neutral-800 active:tw-text-neutral-800 focus:tw-text-neutral-800 hover:tw-bg-neutral-200 tw-w-full tw-inline-flex tw-items-center tw-rounded-md tw-border tw-border-solid tw-border-transparent data-[active=true]:tw-bg-white data-[active=true]:tw-border-neutral-300 data-[active=true]:tw-shadow-sm data-[active=true]:tw-text-neutral-800"
     onclick="init_report(this, 'tickets-report'); return false;">
    <i class="fa-regular fa-life-ring tw-mr-2.5"></i>
    Incident Report (Table)
  </a>
</li>
<li>
  <a href="#"
     class="group tw-font-medium tw-px-2 tw-py-2 tw-text-neutral-500 hover:tw-text-neutral-800 active:tw-text-neutral-800 focus:tw-text-neutral-800 hover:tw-bg-neutral-200 tw-w-full tw-inline-flex tw-items-center tw-rounded-md tw-border tw-border-solid tw-border-transparent data-[active=true]:tw-bg-white data-[active=true]:tw-border-neutral-300 data-[active=true]:tw-shadow-sm data-[active=true]:tw-text-neutral-800"
     onclick="init_report(this, 'tickets-quarterly-matrix'); return false;">
    <i class="fa-regular fa-life-ring tw-mr-2.5"></i>
    Incident Report (Quarterly Matrix)
  </a>
</li>


                    <!--Ticket Report -->



                 
                </ul>
            </div>
            <div class="sm:tw-border-r sm:tw-border-solid sm:tw-border-neutral-200 tw-pr-10 tw-w-80">
                <h4 class="tw-mt-0 tw-font-bold tw-text-lg tw-text-neutral-700 tw-inline-flex tw-items-center">
                    <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
                        stroke="currentColor" class="tw-w-5 tw-h-5 tw-mr-3 tw-ml-3">
                        <path stroke-linecap=" round" stroke-linejoin="round"
                            d="M3 13.125C3 12.504 3.504 12 4.125 12h2.25c.621 0 1.125.504 1.125 1.125v6.75C7.5 20.496 6.996 21 6.375 21h-2.25A1.125 1.125 0 013 19.875v-6.75zM9.75 8.625c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v11.25c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V8.625zM16.5 4.125c0-.621.504-1.125 1.125-1.125h2.25C20.496 3 21 3.504 21 4.125v15.75c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V4.125z" />
                    </svg>

                    <?= _l('charts_based_report'); ?>
                </h4>
                <ul class="reports tw-space-y-1">

    <li>
  <a href="#"
     class="group tw-font-medium tw-px-2 tw-py-2 tw-text-neutral-500 hover:tw-text-neutral-800 ..."
     onclick="init_report(this,'tickets-by-month'); return false;">
    <i class="fa-solid fa-chart-column tw-mr-2.5"></i>
    Tickets by Month
  </a>
</li>
       
                    <li>
  <a href="#"
     class="group tw-font-medium tw-px-2 tw-py-2 tw-text-neutral-500 hover:tw-text-neutral-800 ..."
     onclick="init_report(this,'tickets-status-chart'); return false;">
    <i class="fa-solid fa-chart-column tw-mr-2.5"></i>
   Incident by Status (Chart)
  </a>
</li>
<li>
  <a href="#"
     class="group tw-font-medium tw-px-2 tw-py-2 tw-text-neutral-500 hover:tw-text-neutral-800 ..."
     onclick="init_report(this,'tickets-pies'); return false;">
    <i class="fa-solid fa-chart-pie tw-mr-2.5"></i>
    Incident Pie Charts
  </a>
</li>

       

                

                    
                </ul>
            </div>
            <div class="tw-flex-1 tw-max-w-sm">
                <?php if (isset($currencies)) { ?>
                <div id="currency" class="form-group hide">
                    <label for="currency"><i class="fa-regular fa-circle-question" data-toggle="tooltip"
                            title="<?= _l('report_sales_base_currency_select_explanation'); ?>"></i>
                        <?= _l('currency'); ?></label><br />
                    <select class="selectpicker" name="currency" data-width="100%"
                        data-none-selected-text="<?= _l('dropdown_non_selected_tex'); ?>">
                        <?php foreach ($currencies as $currency) {
                            $selected = '';
                            if ($currency['isdefault'] == 1) {
                                $selected = 'selected';
                            } ?>
                        <option
                            value="<?= e($currency['id']); ?>"
                            <?= e($selected); ?>>
                            <?= e($currency['name']); ?>
                        </option>
                        <?php
                        } ?>
                    </select>
                </div>
                <?php } ?>
                <div id="income-years" class="hide mbot15">
                    <label
                        for="payments_years"><?= _l('year'); ?></label><br />
                    <select class="selectpicker" name="payments_years" data-width="100%"
                        onchange="total_income_bar_report();"
                        data-none-selected-text="<?= _l('dropdown_non_selected_tex'); ?>">
                        <?php foreach ($payments_years as $year) { ?>
                        <option
                            value="<?= e($year['year']); ?>"
                            <?php if ($year['year'] == date('Y')) {
                                echo 'selected';
                            } ?>>
                            <?= e($year['year']); ?>
                        </option>
                        <?php } ?>
                    </select>
                </div>











                <div class="form-group hide" id="report-time">
                    <label
                        for="months-report"><?= _l('period_datepicker'); ?></label><br />
                    <select class="selectpicker" name="months-report" data-width="100%"
                        data-none-selected-text="<?= _l('dropdown_non_selected_tex'); ?>">
                        <option value="">
                            <?= _l('report_sales_months_all_time'); ?>
                        </option>
                        <option value="this_month">
                            <?= _l('this_month'); ?>
                        </option>
                        <option value="1">
                            <?= _l('last_month'); ?>
                        </option>
                        <option value="this_year">
                            <?= _l('this_year'); ?>
                        </option>
                        <option value="last_year">
                            <?= _l('last_year'); ?>
                        </option>
                        <option value="3"
                            data-subtext="<?= _d(date('Y-m-01', strtotime('-2 MONTH'))); ?> - <?= _d(date('Y-m-t')); ?>">
                            <?= _l('report_sales_months_three_months'); ?>
                        </option>
                        <option value="6"
                            data-subtext="<?= _d(date('Y-m-01', strtotime('-5 MONTH'))); ?> - <?= _d(date('Y-m-t')); ?>">
                            <?= _l('report_sales_months_six_months'); ?>
                        </option>
                        <option value="12"
                            data-subtext="<?= _d(date('Y-m-01', strtotime('-11 MONTH'))); ?> - <?= _d(date('Y-m-t')); ?>">
                            <?= _l('report_sales_months_twelve_months'); ?>
                        </option>
                        <option value="custom">
                            <?= _l('period_datepicker'); ?>
                        </option>
                    </select>
                </div>
                <div id="date-range" class="hide mbot15">
                    <div class="row">
                        <div class="col-md-6">
                            <label for="report-from"
                                class="control-label"><?= _l('report_sales_from_date'); ?></label>
                            <div class="input-group date">
                                <input type="text" class="form-control datepicker" id="report-from" name="report-from">
                                <div class="input-group-addon">
                                    <i class="fa-regular fa-calendar calendar-icon"></i>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <label for="report-to"
                                class="control-label"><?= _l('report_sales_to_date'); ?></label>
                            <div class="input-group date">
                                <input type="text" class="form-control datepicker" disabled="disabled" id="report-to"
                                    name="report-to">
                                <div class="input-group-addon">
                                    <i class="fa-regular fa-calendar calendar-icon"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php if (total_rows(db_prefix() . 'invoices', ['status' => 5]) > 0) { ?>
        <p class="text-danger tw-mt-3 tw-ml-3">
            <i class="fa-solid fa-circle-exclamation tw-mr-1" aria-hidden="true"></i>
            <?= _l('sales_report_cancelled_invoices_not_included'); ?>
        </p>
        <?php } ?>
        <div class="row">
            <div class="col-md-12 hide" id="report">
                <h4 class="tw-mt-9 tw-font-semibold tw-text-lg tw-text-neutral-700">
                    <?= _l('reports_sales_generated_report'); ?>
                </h4>
                <div class="panel_s">
                    <div class="panel-body panel-table-full">
                        <?php $this->load->view('admin/reports/includes/sales_income'); ?>
                        <?php $this->load->view('admin/reports/includes/ticket_chart'); ?>
                        <?php $this->load->view('admin/reports/includes/sales_payment_modes'); ?>
                        <?php $this->load->view('admin/reports/includes/sales_customers_groups'); ?>
                        <?php $this->load->view('admin/reports/includes/sales_customers'); ?>
                        <?php $this->load->view('admin/reports/includes/sales_invoices'); ?>
                        <?php $this->load->view('admin/reports/includes/sales_credit_notes'); ?>
                        <?php $this->load->view('admin/reports/includes/sales_items'); ?>
                        <?php $this->load->view('admin/reports/includes/sales_estimates'); ?>
                        <?php $this->load->view('admin/reports/includes/sales_payments'); ?>
                        <?php $this->load->view('admin/reports/includes/sales_proposals'); ?>
                        <?php $this->load->view('admin/reports/includes/tickets_report'); ?>
                        <?php $this->load->view('admin/reports/includes/tickets_month'); ?>
                        <?php $this->load->view('admin/reports/includes/ticket_quater'); ?>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php init_tail(); ?>
<?php $this->load->view('admin/reports/includes/sales_js'); ?>
<script>
document.addEventListener("DOMContentLoaded", function () {
    document.getElementById("ticketsReportBtn").click();
});
</script>
<script>
    $(document).on('click', '#btnExportTicketsMatrix', function(e){
  e.preventDefault();

  var year = $('select[name="tickets_matrix_year"]').val() || new Date().getFullYear();
  var months_report = $('select[name="months-report"]').val() || '';
  var report_from = $('input[name="report-from"]').val() || '';
  var report_to = $('input[name="report-to"]').val() || '';

  var url = admin_url + 'reports/tickets_quarterly_matrix_export'
    + '?year=' + encodeURIComponent(year)
    + '&months_report=' + encodeURIComponent(months_report)
    + '&report_from=' + encodeURIComponent(report_from)
    + '&report_to=' + encodeURIComponent(report_to);

  window.location.href = url;
});

</script>
</body>

</html>