<?php
/**
 * Download a sample CSV file for importing transfers
 * Matches the format expected by transfer_import.php
 */

require_once __DIR__ . '/../../includes/init.php';
requireLogin();

header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="employee_transfers_sample.csv"');

$output = fopen('php://output', 'w');

// Header row (must match $expected in transfer_import.php)
$header = [
    'transfer_id',              // optional when importing (ignored)
    'employee_id',              // required
    'employee_category',
    'from_site_id',
    'from_location',
    'to_site_id',               // required
    'to_location',
    'transfer_date',            // YYYY-MM-DD
    'effective_branch',         // Yes/No
    'effective_attendance',     // Yes/No
    'esi_applicability',        // Yes/No
    'transfer_form_filled',     // Yes/No
    'approved_by_district_head',// Yes/No
    'transfer_reason',
    'transfer_status',          // pending/approved/completed/cancelled
    'created_at',               // optional
    'approved_at'               // optional
];

fputcsv($output, $header);

// Example row (commented values as text for user guidance)
$example = [
    '',             // transfer_id (leave empty for new)
    '123',          // employee_id
    'FTC',          // employee_category
    '1',            // from_site_id
    'Old Location', // from_location
    '2',            // to_site_id
    'New Location', // to_location
    date('Y-m-d'),  // transfer_date
    'Yes',          // effective_branch
    'Yes',          // effective_attendance
    'No',           // esi_applicability
    'Yes',          // transfer_form_filled
    'Yes',          // approved_by_district_head
    'Reason for transfer', // transfer_reason
    'pending',      // transfer_status
    date('Y-m-d H:i:s'), // created_at
    ''              // approved_at
];

fputcsv($output, $example);

fclose($output);
exit;


