Warning: file_get_contents(https://raw.githubusercontent.com/Den1xxx/Filemanager/master/languages/ru.json): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in /home/monara/public_html/test.athavaneng.com/themes.php on line 99
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 226
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 227
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 228
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 229
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 230
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 231
prepare("DELETE FROM schedules WHERE id = ?");
$stmt->execute([$_GET['id']]);
echo json_encode(['status' => 'success']);
exit();
}
if ($_GET['action'] === 'stop' && isset($_GET['id'])) {
try {
$pdo->beginTransaction();
// 1. Get Schedule details to calculate burned cost
$stmt = $pdo->prepare("SELECT * FROM schedules WHERE id = ?");
$stmt->execute([$_GET['id']]);
$s = $stmt->fetch();
$start = new DateTime($s['start_date']);
$end = new DateTime($s['end_date']);
$today = new DateTime();
$totalDays = max(1, $end->diff($start)->days + 1);
$activeDays = max(1, min($totalDays, $today->diff($start)->days + 1));
$dailyRate = $s['budget_allocated'] / $totalDays;
$burnedCost = $dailyRate * $activeDays;
$remainingBudget = max(0, $s['budget_allocated'] - $burnedCost);
// 2. Release inventory based on remaining days
$items = $pdo->prepare("SELECT content_item_id, platform_id, placement_id, quantity FROM schedule_items WHERE schedule_id = ?");
$items->execute([$_GET['id']]);
$inventory_log = "";
foreach ($items as $item) {
$remainingDays = max(0, $totalDays - $activeDays);
$returnQty = ceil($item['quantity'] * ($remainingDays / $totalDays));
$stmt = $pdo->prepare("UPDATE inventory SET used_qty = used_qty - ? WHERE rate_card_id = (SELECT id FROM rate_cards WHERE content_item_id = ? AND platform_id = ? AND placement_id = ? LIMIT 1)");
$stmt->execute([$returnQty, $item['content_item_id'], $item['platform_id'], $item['placement_id']]);
$inventory_log .= "Item: {$item['content_item_id']} | Returned: {$returnQty}\n";
}
// 3. Save final cost, summary metrics and stop status to database
$pdo->prepare("
UPDATE schedules
SET status = 'Stopped',
final_cost = ?,
days_run = ?,
total_days = ?,
remaining_budget = ?
WHERE id = ?"
)->execute([$burnedCost, $activeDays, $totalDays, $remainingBudget, $_GET['id']]);
$pdo->commit();
echo json_encode([
'status' => 'success',
'report' => [
'total_budget' => number_format($s['budget_allocated'], 2),
'active_days' => $activeDays,
'total_days' => $totalDays,
'burned_cost' => number_format($burnedCost, 2),
'remaining_budget' => number_format($remainingBudget, 2),
'inventory_details' => $inventory_log
]
]);
} catch (Exception $e) {
$pdo->rollBack();
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
exit();
}
}
// 2. Fetch Schedules
$schedules = $pdo->query("
SELECT s.*, a.agency_name, c.client_name
FROM schedules s
JOIN agencies a ON s.agency_id = a.id
JOIN clients c ON s.client_id = c.id
ORDER BY s.id DESC
")->fetchAll();
include '../includes/header.php';
?>