| Server IP : 72.60.21.38 / Your IP : 216.73.216.164 Web Server : LiteSpeed System : Linux uk-fast-web1372.main-hosting.eu 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64 User : u390967363 ( 390967363) PHP Version : 8.2.30 Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail MySQL : OFF | cURL : ON | WGET : ON | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/u390967363/domains/aibenproperties.com/public_html/app/ |
Upload File : |
<?php
require_once 'includes/db.php';
require_once 'includes/functions.php';
if (session_status() === PHP_SESSION_NONE) { session_start(); }
header('Content-Type: application/json');
$clientId = isset($_GET['client_id']) ? (int)$_GET['client_id'] : 0;
$companyId = $_SESSION['company_id'] ?? null;
if ($clientId <= 0) { echo json_encode(['success'=>false,'error'=>'invalid']); exit; }
$out = ['success'=>false];
try {
$dealId = 0;
$estateId = null;
$sqm = '';
$amountOffered = 0.0;
$cidCol = 'user_id';
if (function_exists('tableHasColumn') && tableHasColumn('deals_submit','client_id')) { $cidCol = 'client_id'; }
$q = "SELECT id, estate_id, sqm, amount_offered FROM deals_submit WHERE {$cidCol} = ?";
$params = [$clientId];
if (!empty($companyId) && function_exists('tableHasColumn') && tableHasColumn('deals_submit','company_id')) { $q .= " AND (company_id = ? OR company_id IS NULL)"; $params[] = (int)$companyId; }
if (function_exists('tableHasColumn') && tableHasColumn('deals_submit','status')) { $q .= " AND status = 'active'"; }
$q .= " ORDER BY id DESC LIMIT 1";
$st = $pdo->prepare($q);
$st->execute($params);
$row = $st->fetch(PDO::FETCH_ASSOC);
if ($row) {
$dealId = (int)($row['id'] ?? 0);
$estateId = isset($row['estate_id']) ? (int)$row['estate_id'] : null;
$sqm = isset($row['sqm']) ? (string)$row['sqm'] : '';
$amountOffered = isset($row['amount_offered']) ? (float)$row['amount_offered'] : 0.0;
}
$estateName = null;
if (!empty($estateId) && function_exists('tableHasColumn') && tableHasColumn('estates','name')) {
$se = $pdo->prepare("SELECT name FROM estates WHERE id = ? LIMIT 1");
$se->execute([$estateId]);
$estateName = $se->fetchColumn() ?: null;
}
$thresholdPct = 20.0;
try {
if (function_exists('getCompanySetting')) {
$raw = getCompanySetting($companyId, 'allocation_min_deposit_pct', function_exists('getSetting') ? getSetting('allocation_min_deposit_pct', '20') : '20');
if ($raw !== null && $raw !== '') $thresholdPct = (float)$raw;
} else {
$raw = function_exists('getSetting') ? getSetting('allocation_min_deposit_pct', '20') : '20';
$thresholdPct = (float)$raw;
}
} catch (Throwable $eCfg) {}
$required = $amountOffered > 0 ? round(($thresholdPct/100.0) * $amountOffered, 2) : 0.0;
$totalPaid = 0.0;
try {
if ($dealId > 0 && function_exists('tableHasColumn') && tableHasColumn('payments','deal_id')) {
$qs = $pdo->prepare("SELECT COALESCE(SUM(amount),0) FROM payments WHERE deal_id = ? AND status = 'approved'");
$qs->execute([$dealId]);
$totalPaid = (float)$qs->fetchColumn();
}
} catch (Throwable $eSum) {}
$eligible = ($totalPaid >= $required);
$out = [
'success' => true,
'deal_id' => $dealId,
'estate_id' => $estateId,
'estate_name' => $estateName,
'sqm' => $sqm,
'amount_offered' => $amountOffered,
'threshold_pct' => $thresholdPct,
'required' => $required,
'total_paid' => $totalPaid,
'eligible' => $eligible
];
} catch (Throwable $e) {
$out = ['success'=>false,'error'=>'server'];
}
echo json_encode($out);