<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends AZ_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('az_auth');
$this->load->helper('az_config');
az_check_auth('dashboard');
}
public function index(){
$this->load->library('AZApp');
$app = $this->azapp;
$data_header['title'] = azlang('Dashboard');
$data_header['breadcrumb'] = array('dashboard');
$app->set_data_header($data_header);
$this->load->helper('az_core');
$js = az_add_js('home/vjs_home');
$app->add_js($js);
$idoutlet = $this->session->userdata('idoutlet');
if (strlen($idoutlet) > 0) {
$this->db->where('transaction_group.idoutlet', $idoutlet);
}
$this->db->group_by('transaction_group_status');
$this->db->select('transaction_group_status, count(grand_total_final) as total');
$this->db->where('status', 1);
$tg = $this->db->get('transaction_group');
$data['pending'] = 0;
$data['st_proses'] = 0;
$data['st_bersih'] = 0;
$data['diantar'] = 0;
$data['baru'] = 0;
$data['pick_up'] = 0;
foreach ($tg->result() as $key => $value) {
$the = $value->transaction_group_status;
$the = strtolower($the);
$the = str_replace(' ', '_', $the);
$data[$the] = $value->total;
}
$view = $this->load->view('home/v_home', $data, true);
$app->add_content($view);

// ==========================================================
//  KARTU "PANTAU BARBER"  (muncul untuk admin + produksi)
//  Dicek lewat HAK AKSES MENU, bukan nama role.
// ==========================================================
$idrole = $this->session->userdata('idrole');
$this->db->where('idrole', $idrole);
$this->db->where('menu_name', 'history_bill_production');
$this->db->where('access', 1);
$this->db->where('status', 1);
$boleh_barber = ($this->db->count_all_results('user_role') > 0);

if ($boleh_barber) {
    $url_barber  = app_url() . 'barber';
    $html_barber  = '<a class="pbrb-sc" href="' . $url_barber . '">';
    $html_barber .= '<span class="pbrb-sc-ico">&#127981;</span>';
    $html_barber .= '<span class="pbrb-sc-txt"><b>Pantau Barber</b>';
    $html_barber .= '<small>Pantauan produksi &mdash; bill terlambat, jatuh tempo &amp; express</small></span>';
    $html_barber .= '<span class="pbrb-sc-arr">&rarr;</span></a>';
    $html_barber .= '<style>'
        . '.pbrb-sc{display:flex;align-items:center;gap:14px;max-width:760px;margin:16px auto;padding:14px 18px;'
        . 'background:linear-gradient(120deg,#0c3b36,#138074);border-radius:12px;text-decoration:none;color:#fff;'
        . 'box-shadow:0 4px 14px rgba(12,59,54,.25);transition:transform .14s,box-shadow .14s;}'
        . '.pbrb-sc:hover{transform:translateY(-2px);box-shadow:0 9px 22px rgba(12,59,54,.35);color:#fff;text-decoration:none;}'
        . '.pbrb-sc-ico{font-size:26px;}'
        . '.pbrb-sc-txt{flex:1;line-height:1.3;}'
        . '.pbrb-sc-txt b{display:block;font-size:15px;letter-spacing:.4px;}'
        . '.pbrb-sc-txt small{font-size:11px;opacity:.85;}'
        . '.pbrb-sc-arr{font-size:20px;font-weight:800;}'
        . '</style>';
    $app->add_content($html_barber);
}

echo $app->render();
}
}