PYBS (Personel Yönetim Bilgi Sistemi) / modules/puantaj-rapor.php
puantaj-rapor.php 191 satır • 8.59 KB
<?php
// modules/puantaj-rapor.php
session_start();
require_once '../config/db.php';
require_once '../config/functions.php';

yetkiKontrol(['root', 'yonetici', 'muhasebe', 'insan_kaynaklari']);

$yil = $_GET['yil'];
$ay = $_GET['ay'];
$rol_filtre = $_GET['rol'] ?? 'tumu';
$personel_id = $_GET['personel_id'] ?? 'tumu';
$format = $_GET['format']; // excel veya print

$gun_sayisi = cal_days_in_month(CAL_GREGORIAN, $ay, $yil);
$ay_isimleri = ['01'=>'Ocak','02'=>'Şubat','03'=>'Mart','04'=>'Nisan','05'=>'Mayıs','06'=>'Haziran','07'=>'Temmuz','08'=>'Ağustos','09'=>'Eylül','10'=>'Ekim','11'=>'Kasım','12'=>'Aralık'];
$gun_kisa = ['Mon'=>'Pzt', 'Tue'=>'Sal', 'Wed'=>'Çar', 'Thu'=>'Per', 'Fri'=>'Cum', 'Sat'=>'Cts', 'Sun'=>'Pzr'];

$baslik = "PUANTAJ CETVELİ - " . mb_strtoupper($ay_isimleri[$ay]) . " " . $yil;

// SQL
$sql_per = "SELECT * FROM kullanicilar WHERE durum=1";
if ($rol_filtre != 'tumu') $sql_per .= " AND rol = '$rol_filtre'";
if ($personel_id != 'tumu') $sql_per .= " AND id = $personel_id";
$sql_per .= " ORDER BY ad ASC";
$personeller = $pdo->query($sql_per)->fetchAll();

$tatiller = $pdo->query("SELECT tarih FROM resmi_tatiller")->fetchAll(PDO::FETCH_COLUMN);
$gunluk_saat_std = (float)($pdo->query("SELECT ayar_degeri FROM site_ayarlari WHERE ayar_anahtari = 'gunluk_mesai_saati'")->fetchColumn() ?: 9);

// EXCEL HEADER
if ($format == 'excel') {
    header("Content-Type: application/vnd.ms-excel; charset=utf-8");
    header("Content-Disposition: attachment; filename=Puantaj_{$yil}_{$ay}.xls");
    header("Pragma: no-cache");
    header("Expires: 0");
    echo "\xEF\xBB\xBF"; // BOM
}
?>
<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <title><?php echo $baslik; ?></title>
    <style>
        body { font-family: Arial, sans-serif; font-size: 10px; margin: 0; padding: 20px; }
        
        /* TABLO */
        table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
        th, td { border: 1px solid #000; padding: 4px; text-align: center; }
        th { background-color: #eee; font-size: 9px; }
        
        /* LOGO & BAŞLIK (Sadece Print) */
        .header-print { text-align: center; margin-bottom: 20px; border-bottom: 2px solid #000; padding-bottom: 10px; }
        .logo { max-height: 60px; }
        .rapor-title { font-size: 18px; font-weight: bold; margin-top: 10px; }
        
        /* İMZA */
        .imza-blogu { display: flex; justify-content: space-between; margin-top: 40px; page-break-inside: avoid; }
        .imza-kutu { width: 24%; text-align: center; border: 1px solid #ccc; padding: 10px; height: 80px; }
        .imza-baslik { font-weight: bold; border-bottom: 1px solid #ccc; padding-bottom: 5px; margin-bottom: 30px; font-size: 11px; }

        /* RENKLER (Printte Çıkması İçin) */
        @media print {
            body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
            .bg-dark { background-color: #333 !important; color: #fff !important; }
            .bg-secondary { background-color: #ccc !important; }
            .bg-warning { background-color: #ffc107 !important; }
            .bg-danger { background-color: #dc3545 !important; color: #fff !important; }
            .bg-success { background-color: #198754 !important; color: #fff !important; }
            .bg-info { background-color: #0dcaf0 !important; }
            .no-print { display: none; }
            @page { size: landscape; margin: 10mm; } /* Yatay Yazdırma */
        }
    </style>
</head>
<body>

    <?php if($format == 'print'): ?>
        <div class="no-print" style="margin-bottom: 20px;">
            <button onclick="window.print()" style="padding: 10px 20px; font-weight: bold; cursor: pointer;">🖨️ YAZDIR</button>
        </div>
        <div class="header-print">
            <img src="../assets/img/logo.png" alt="Logo" class="logo"><br>
            <div class="rapor-title"><?php echo $baslik; ?></div>
            <div>Rapor Tarihi: <?php echo date('d.m.Y H:i'); ?></div>
        </div>
    <?php endif; ?>

    <table>
        <thead>
            <tr>
                <th style="width: 150px; text-align:left;">PERSONEL</th>
                <?php for($d=1; $d<=$gun_sayisi; $d++): 
                    $tarih = "$yil-$ay-" . sprintf('%02d', $d);
                    $gun_ing = date('D', strtotime($tarih));
                    $gun_tr = $gun_kisa[$gun_ing];
                    $bg = ($gun_ing=='Sat' || $gun_ing=='Sun') ? 'background-color:#ccc;' : '';
                ?>
                    <th style="<?php echo $bg; ?>"><?php echo $d; ?><br><?php echo $gun_tr; ?></th>
                <?php endfor; ?>
                <th style="background-color:#ddd;">NM</th>
                <th style="background-color:#ddd;">FM</th>
                <th style="background-color:#ddd;">İZ</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach($personeller as $per): 
                $toplam_normal = 0; $toplam_fazla = 0; $toplam_izin = 0;
            ?>
            <tr>
                <td style="text-align:left; font-weight:bold;"><?php echo $per['ad'].' '.$per['soyad']; ?></td>
                
                <?php for($d=1; $d<=$gun_sayisi; $d++): 
                    $g_tarih = "$yil-$ay-" . sprintf('%02d', $d);
                    $haftanin_gunu = date('N', strtotime($g_tarih));
                    
                    $hucre = ""; $style = "";
                    $is_tatil = in_array($g_tarih, $tatiller);
                    $is_haftasonu = ($haftanin_gunu == 7);

                    $izin = $pdo->query("SELECT izin_turu, saatlik_sure FROM izin_talepleri WHERE calisan_id={$per['id']} AND durum='onaylandi' AND '$g_tarih' BETWEEN DATE(baslangic_tarihi) AND DATE(bitis_tarihi)")->fetch();
                    $mesai = $pdo->query("SELECT SUM(toplam_saat) FROM mesai_hareketleri WHERE calisan_id={$per['id']} AND durum='onaylandi' AND tarih='$g_tarih' AND mesai_turu='fazla_mesai'")->fetchColumn() ?: 0;

                    $gunluk_normal = 0;
                    if (!$is_haftasonu && !$is_tatil) $gunluk_normal = $gunluk_saat_std;

                    if ($izin) {
                        if ($izin['izin_turu'] == 'saatlik') {
                            $gunluk_normal -= $izin['saatlik_sure'];
                            $hucre = (float)$gunluk_normal;
                            $style = "background-color:#ffeeba;";
                        } else {
                            $gunluk_normal = 0;
                            // İzin türüne göre kısaltma
                            $tur_map = [
                                'yillik'=>'Y.İZ', 'mazeret'=>'MAZ', 'hastalik'=>'RAP', 
                                'evlilik'=>'EVL', 'babalik'=>'BBL', 'olum'=>'ÖLM'
                            ];
                            $hucre = $tur_map[$izin['izin_turu']] ?? "İZİN";
                            $style = "background-color:#ffc107; font-weight:bold;";
                            $toplam_izin++;
                        }
                    } else {
                        if($gunluk_normal > 0) $hucre = (float)$gunluk_normal;
                    }

                    if ($mesai > 0) {
                        $toplam_fazla += $mesai;
                        if (!is_numeric($hucre)) $hucre .= "+".(float)$mesai;
                        else $hucre .= "+".(float)$mesai;
                        $style = "background-color:#d1e7dd; font-weight:bold;";
                    }

                    if ($hucre === "" && ($is_haftasonu || $is_tatil)) $style = "background-color:#eee;";
                    $toplam_normal += $gunluk_normal;
                ?>
                    <td style="<?php echo $style; ?>"><?php echo $hucre; ?></td>
                <?php endfor; ?>

                <td style="font-weight:bold;"><?php echo (float)$toplam_normal; ?></td>
                <td style="font-weight:bold; color:green;"><?php echo (float)$toplam_fazla; ?></td>
                <td style="font-weight:bold; color:orange;"><?php echo (float)$toplam_izin; ?></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>

    <?php if($format == 'print'): ?>
    <div class="imza-blogu">
        <div class="imza-kutu">
            <div class="imza-baslik">HAZIRLAYAN</div>
            </div>
        <div class="imza-kutu">
            <div class="imza-baslik">MUHASEBE</div>
        </div>
        <div class="imza-kutu">
            <div class="imza-baslik">İNSAN KAYNAKLARI</div>
        </div>
        <div class="imza-kutu">
            <div class="imza-baslik">GENEL MÜDÜR ONAYI</div>
        </div>
    </div>
    
    <script>
        window.onload = function() { setTimeout(function() { window.print(); }, 500); }
    </script>
    <?php endif; ?>

</body>
</html>