<?php
require_once '../../config.php';
require_once ROOT . 'app/db.php';

$ay    = $_POST['ay'];
$yil   = $_POST['yil'];
$tutar = $_POST['tutar'];

if (!$ay || !$yil || !$tutar) {
    echo json_encode(['success' => false, 'error' => 'Eksik bilgi']);
    exit;
}

$daireler = db::execAll("SELECT ID FROM tb_daire WHERE aktif=1");

foreach ($daireler as $d) {
    db::execOne("
        INSERT IGNORE INTO tb_aidat (daireID, tutar, ay, yil)
        VALUES (?, ?, ?, ?)
    ", [
        $d->ID,
        $tutar,
        $ay,
        $yil
    ]);
}

echo json_encode([
    'success' => true,
    'message' => "$ay/$yil aidatları oluşturuldu"
]);
