'Sales Manager', 2 => 'General Manager', 3 => 'Managing Director', 4 => 'Accounts', 5 => 'IT' ]; // --- End New Approval Workflow --- // Fetch application details $stmt = $pdo->prepare('SELECT a.*, r.name as current_approver_role FROM customer_applications a LEFT JOIN roles r ON a.current_approver_role_id = r.id WHERE a.id = ?'); $stmt->execute([$application_id]); $application = $stmt->fetch(); if (!$application) { die('Application not found.'); } // Fetch approval history $stmt_history = $pdo->prepare('SELECT ah.*, u.username as approver_name FROM application_approvals ah JOIN users u ON ah.approver_id = u.id WHERE ah.application_id = ? ORDER BY ah.created_at DESC'); $stmt_history->execute([$application_id]); $approval_history = $stmt_history->fetchAll(); // Fetch other details (contacts, addresses, etc.) - condensed for brevity $contacts = $pdo->query("SELECT * FROM customer_contacts WHERE customer_application_id = {$application_id}")->fetchAll(); $addresses = $pdo->query("SELECT * FROM customer_addresses WHERE customer_application_id = {$application_id}")->fetchAll(); $trade_references = $pdo->query("SELECT * FROM customer_trade_references WHERE customer_application_id = {$application_id}")->fetchAll(); $bank_details = $pdo->query("SELECT * FROM customer_bank_details WHERE customer_application_id = {$application_id}")->fetch(); $principals = $pdo->query("SELECT * FROM customer_principals WHERE customer_application_id = {$application_id}")->fetchAll(); // Get current user role $current_user_role_id = get_user_role_id(); $stmt_role = $pdo->prepare("SELECT name FROM roles WHERE id = ?"); $stmt_role->execute([$current_user_role_id]); $current_user_role_name = $stmt_role->fetchColumn(); $current_level = $application['approval_level']; $required_role = $approval_levels[$current_level] ?? null; $can_approve = ($current_user_role_name === $required_role || $current_user_role_name === 'admin'); ?>
Waiting for approval from: = htmlspecialchars($application['current_approver_role']) ?>
No approval history found.
Action: = htmlspecialchars($history['status']) ?>
By: = htmlspecialchars($history['approver_name']) ?>
Comments: = nl2br(htmlspecialchars($history['comments'])) ?>
= date('Y-m-d H:i:s', strtotime($history['created_at'])) ?>Company Name: = htmlspecialchars($application['company_name']) ?>
Company Website: = htmlspecialchars($application['company_website']) ?>
Company Phone: = htmlspecialchars($application['company_phone']) ?>
Test: Test