diff --git a/assets/pasted-20251204-015537-032cd7e6.png b/assets/pasted-20251204-015537-032cd7e6.png
new file mode 100644
index 0000000..4e18bd2
Binary files /dev/null and b/assets/pasted-20251204-015537-032cd7e6.png differ
diff --git a/assets/pasted-20251204-015710-55b153a5.png b/assets/pasted-20251204-015710-55b153a5.png
new file mode 100644
index 0000000..a40fbea
Binary files /dev/null and b/assets/pasted-20251204-015710-55b153a5.png differ
diff --git a/assets/pasted-20251204-015859-ba057228.png b/assets/pasted-20251204-015859-ba057228.png
new file mode 100644
index 0000000..0e6d83e
Binary files /dev/null and b/assets/pasted-20251204-015859-ba057228.png differ
diff --git a/assets/pasted-20251204-015945-278d0108.png b/assets/pasted-20251204-015945-278d0108.png
new file mode 100644
index 0000000..59984be
Binary files /dev/null and b/assets/pasted-20251204-015945-278d0108.png differ
diff --git a/assets/pasted-20251204-020809-fbe187c3.png b/assets/pasted-20251204-020809-fbe187c3.png
new file mode 100644
index 0000000..16c6e2d
Binary files /dev/null and b/assets/pasted-20251204-020809-fbe187c3.png differ
diff --git a/assets/pasted-20251204-021404-14f90d2d.png b/assets/pasted-20251204-021404-14f90d2d.png
new file mode 100644
index 0000000..df41f82
Binary files /dev/null and b/assets/pasted-20251204-021404-14f90d2d.png differ
diff --git a/assets/pasted-20251204-021710-6689afd9.png b/assets/pasted-20251204-021710-6689afd9.png
new file mode 100644
index 0000000..d5fa782
Binary files /dev/null and b/assets/pasted-20251204-021710-6689afd9.png differ
diff --git a/assets/pasted-20251204-022151-982a3976.png b/assets/pasted-20251204-022151-982a3976.png
new file mode 100644
index 0000000..8cc1a37
Binary files /dev/null and b/assets/pasted-20251204-022151-982a3976.png differ
diff --git a/assets/pasted-20251204-022306-1a04c023.png b/assets/pasted-20251204-022306-1a04c023.png
new file mode 100644
index 0000000..06e303d
Binary files /dev/null and b/assets/pasted-20251204-022306-1a04c023.png differ
diff --git a/assets/pasted-20251204-022406-7fe85bc3.png b/assets/pasted-20251204-022406-7fe85bc3.png
new file mode 100644
index 0000000..3ac8a38
Binary files /dev/null and b/assets/pasted-20251204-022406-7fe85bc3.png differ
diff --git a/assets/pasted-20251204-022454-940b0a04.png b/assets/pasted-20251204-022454-940b0a04.png
new file mode 100644
index 0000000..fe98d95
Binary files /dev/null and b/assets/pasted-20251204-022454-940b0a04.png differ
diff --git a/assets/pasted-20251204-022551-bbe9e793.png b/assets/pasted-20251204-022551-bbe9e793.png
new file mode 100644
index 0000000..b5d54b8
Binary files /dev/null and b/assets/pasted-20251204-022551-bbe9e793.png differ
diff --git a/assets/pasted-20251204-022908-1d2c298f.png b/assets/pasted-20251204-022908-1d2c298f.png
new file mode 100644
index 0000000..245ceeb
Binary files /dev/null and b/assets/pasted-20251204-022908-1d2c298f.png differ
diff --git a/auth.php b/auth.php
new file mode 100644
index 0000000..f0691c7
--- /dev/null
+++ b/auth.php
@@ -0,0 +1,51 @@
+prepare("SELECT u.id, u.username, u.password, r.name as role_name
+ FROM users u
+ JOIN roles r ON u.role_id = r.id
+ WHERE u.username = ?");
+ $stmt->execute([$username]);
+ $user = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if ($user && password_verify($password, $user['password'])) {
+ // Authentication successful
+ $stmt = $pdo->prepare("SELECT p.name
+ FROM permissions p
+ JOIN role_permissions rp ON p.id = rp.permission_id
+ WHERE rp.role_id = (SELECT id FROM roles WHERE name = ?)");
+ $stmt->execute([$user['role_name']]);
+ $permissions = $stmt->fetchAll(PDO::FETCH_COLUMN);
+
+ $_SESSION['user'] = [
+ 'id' => $user['id'],
+ 'username' => $user['username'],
+ 'role' => $user['role_name'],
+ 'permissions' => $permissions
+ ];
+ unset($_SESSION['error']);
+ header('Location: index.php');
+ exit();
+ } else {
+ // Authentication failed
+ $_SESSION['error'] = 'Invalid username or password.';
+ header('Location: login.php');
+ exit();
+ }
+ } catch (PDOException $e) {
+ $_SESSION['error'] = 'Database error: ' . $e->getMessage();
+ header('Location: login.php');
+ exit();
+ }
+} else {
+ // Redirect if accessed directly
+ header('Location: login.php');
+ exit();
+}
\ No newline at end of file
diff --git a/db/migrations/001_create_customer_tables.sql b/db/migrations/001_create_customer_tables.sql
new file mode 100644
index 0000000..93a1d97
--- /dev/null
+++ b/db/migrations/001_create_customer_tables.sql
@@ -0,0 +1,39 @@
+CREATE TABLE IF NOT EXISTS `customer_applications` (
+`id` INT AUTO_INCREMENT PRIMARY KEY,
+`application_id` VARCHAR(255) NOT NULL UNIQUE,
+`customer_id` VARCHAR(255) NULL,
+`company_name` VARCHAR(255) NOT NULL,
+`company_website` VARCHAR(255) NULL,
+`company_phone` VARCHAR(255) NULL,
+`sales_owner` VARCHAR(255) NOT NULL,
+`payment_terms` VARCHAR(255) NOT NULL,
+`tags` TEXT NULL,
+`notes` TEXT NULL,
+`status` VARCHAR(50) NOT NULL DEFAULT 'DRAFT',
+`created_by` VARCHAR(255) NOT NULL,
+`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+CREATE TABLE IF NOT EXISTS `customer_contacts` (
+`id` INT AUTO_INCREMENT PRIMARY KEY,
+`customer_application_id` INT NOT NULL,
+`name` VARCHAR(255) NOT NULL,
+`email` VARCHAR(255) NOT NULL,
+`phone` VARCHAR(255) NULL,
+`is_primary` BOOLEAN NOT NULL DEFAULT FALSE,
+FOREIGN KEY (`customer_application_id`) REFERENCES `customer_applications`(`id`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+CREATE TABLE IF NOT EXISTS `customer_addresses` (
+`id` INT AUTO_INCREMENT PRIMARY KEY,
+`customer_application_id` INT NOT NULL,
+`address_type` VARCHAR(50) NOT NULL, -- e.g., 'BILLING', 'SHIPPING'
+`address_line_1` VARCHAR(255) NOT NULL,
+`address_line_2` VARCHAR(255) NULL,
+`city` VARCHAR(255) NOT NULL,
+`state` VARCHAR(255) NOT NULL,
+`postal_code` VARCHAR(50) NOT NULL,
+`country` VARCHAR(100) NOT NULL,
+FOREIGN KEY (`customer_application_id`) REFERENCES `customer_applications`(`id`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
\ No newline at end of file
diff --git a/db/migrations/002_create_application_files_table.sql b/db/migrations/002_create_application_files_table.sql
new file mode 100644
index 0000000..0cd8572
--- /dev/null
+++ b/db/migrations/002_create_application_files_table.sql
@@ -0,0 +1,8 @@
+CREATE TABLE IF NOT EXISTS `application_files` (
+`id` INT AUTO_INCREMENT PRIMARY KEY,
+`customer_application_id` INT NOT NULL,
+`filename` VARCHAR(255) NOT NULL,
+`filepath` VARCHAR(255) NOT NULL,
+`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+FOREIGN KEY (`customer_application_id`) REFERENCES `customer_applications`(`id`) ON DELETE CASCADE
+);
\ No newline at end of file
diff --git a/db/migrations/003_create_user_management_tables.sql b/db/migrations/003_create_user_management_tables.sql
new file mode 100644
index 0000000..09f1dcb
--- /dev/null
+++ b/db/migrations/003_create_user_management_tables.sql
@@ -0,0 +1,58 @@
+CREATE TABLE IF NOT EXISTS `users` (
+`id` INT AUTO_INCREMENT PRIMARY KEY,
+`username` VARCHAR(255) NOT NULL UNIQUE,
+`password` VARCHAR(255) NOT NULL,
+`role_id` INT NOT NULL,
+`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+CREATE TABLE IF NOT EXISTS `roles` (
+`id` INT AUTO_INCREMENT PRIMARY KEY,
+`name` VARCHAR(255) NOT NULL UNIQUE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+CREATE TABLE IF NOT EXISTS `permissions` (
+`id` INT AUTO_INCREMENT PRIMARY KEY,
+`name` VARCHAR(255) NOT NULL UNIQUE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+CREATE TABLE IF NOT EXISTS `role_permissions` (
+`role_id` INT NOT NULL,
+`permission_id` INT NOT NULL,
+PRIMARY KEY (`role_id`, `permission_id`),
+FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) ON DELETE CASCADE,
+FOREIGN KEY (`permission_id`) REFERENCES `permissions`(`id`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+INSERT IGNORE INTO `roles` (`name`) VALUES ('admin'), ('manager'), ('sales'), ('clerk');
+
+INSERT IGNORE INTO `permissions` (`name`) VALUES
+('create_application'),
+('edit_application'),
+('approve_application'),
+('view_applications'),
+('delete_application'),
+('manage_users'),
+('manage_roles'),
+('upload_files'),
+('delete_files');
+
+INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`)
+SELECT (SELECT id FROM roles WHERE name = 'admin'), id FROM permissions;
+
+INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`)
+SELECT (SELECT id FROM roles WHERE name = 'manager'), p.id
+FROM permissions p
+WHERE p.name IN ('create_application', 'edit_application', 'approve_application', 'view_applications', 'delete_application', 'upload_files', 'delete_files');
+
+INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`)
+SELECT (SELECT id FROM roles WHERE name = 'sales'), p.id
+FROM permissions p
+WHERE p.name IN ('create_application', 'edit_application', 'view_applications', 'upload_files', 'delete_files');
+
+INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`)
+SELECT (SELECT id FROM roles WHERE name = 'clerk'), p.id
+FROM permissions p
+WHERE p.name = 'view_applications';
+
+INSERT IGNORE INTO `users` (`username`, `password`, `role_id`) VALUES ('admin', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', (SELECT id FROM roles WHERE name = 'admin')); -- password is 'password'
\ No newline at end of file
diff --git a/db/migrations/004_add_approval_workflow_columns.sql b/db/migrations/004_add_approval_workflow_columns.sql
new file mode 100644
index 0000000..4cb9cbd
--- /dev/null
+++ b/db/migrations/004_add_approval_workflow_columns.sql
@@ -0,0 +1,13 @@
+ALTER TABLE customer_applications ADD COLUMN approval_level INT DEFAULT 1;
+ALTER TABLE customer_applications ADD COLUMN current_approver_role_id INT;
+CREATE TABLE IF NOT EXISTS application_approvals (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ application_id INT NOT NULL,
+ approver_id INT NOT NULL,
+ approval_level INT NOT NULL,
+ status VARCHAR(255) NOT NULL,
+ comments TEXT,
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ FOREIGN KEY (application_id) REFERENCES customer_applications(id),
+ FOREIGN KEY (approver_id) REFERENCES users(id)
+);
\ No newline at end of file
diff --git a/db/migrations/005_create_approver_roles.sql b/db/migrations/005_create_approver_roles.sql
new file mode 100644
index 0000000..0a71835
--- /dev/null
+++ b/db/migrations/005_create_approver_roles.sql
@@ -0,0 +1,45 @@
+INSERT IGNORE INTO `roles` (`name`) VALUES
+('Approver Level 1'),
+('Approver Level 2'),
+('Approver Level 3'),
+('Approver Level 4'),
+('Approver Level 5'),
+('Approver Level 6'),
+('Approver Level 7');
+
+INSERT IGNORE INTO `permissions` (`name`) VALUES
+('approve_level_1'),
+('approve_level_2'),
+('approve_level_3'),
+('approve_level_4'),
+('approve_level_5'),
+('approve_level_6'),
+('approve_level_7');
+
+-- Assign approve_level_1 permission to Approver Level 1 role
+INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`)
+SELECT (SELECT id FROM roles WHERE name = 'Approver Level 1'), (SELECT id FROM permissions WHERE name = 'approve_level_1');
+
+-- Assign approve_level_2 permission to Approver Level 2 role
+INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`)
+SELECT (SELECT id FROM roles WHERE name = 'Approver Level 2'), (SELECT id FROM permissions WHERE name = 'approve_level_2');
+
+-- Assign approve_level_3 permission to Approver Level 3 role
+INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`)
+SELECT (SELECT id FROM roles WHERE name = 'Approver Level 3'), (SELECT id FROM permissions WHERE name = 'approve_level_3');
+
+-- Assign approve_level_4 permission to Approver Level 4 role
+INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`)
+SELECT (SELECT id FROM roles WHERE name = 'Approver Level 4'), (SELECT id FROM permissions WHERE name = 'approve_level_4');
+
+-- Assign approve_level_5 permission to Approver Level 5 role
+INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`)
+SELECT (SELECT id FROM roles WHERE name = 'Approver Level 5'), (SELECT id FROM permissions WHERE name = 'approve_level_5');
+
+-- Assign approve_level_6 permission to Approver Level 6 role
+INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`)
+SELECT (SELECT id FROM roles WHERE name = 'Approver Level 6'), (SELECT id FROM permissions WHERE name = 'approve_level_6');
+
+-- Assign approve_level_7 permission to Approver Level 7 role
+INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`)
+SELECT (SELECT id FROM roles WHERE name = 'Approver Level 7'), (SELECT id FROM permissions WHERE name = 'approve_level_7');
diff --git a/db/migrations/006_add_trade_ref_bank_and_signature.sql b/db/migrations/006_add_trade_ref_bank_and_signature.sql
new file mode 100644
index 0000000..4b03904
--- /dev/null
+++ b/db/migrations/006_add_trade_ref_bank_and_signature.sql
@@ -0,0 +1,31 @@
+-- Add new tables for trade references and bank details
+CREATE TABLE IF NOT EXISTS `customer_trade_references` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `customer_application_id` int(11) NOT NULL,
+ `company_name` varchar(255) NOT NULL,
+ `contact_person` varchar(255) DEFAULT NULL,
+ `email` varchar(255) DEFAULT NULL,
+ `phone` varchar(50) DEFAULT NULL,
+ `address` text,
+ PRIMARY KEY (`id`),
+ KEY `customer_application_id` (`customer_application_id`),
+ CONSTRAINT `customer_trade_references_ibfk_1` FOREIGN KEY (`customer_application_id`) REFERENCES `customer_applications` (`id`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+CREATE TABLE IF NOT EXISTS `customer_bank_details` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `customer_application_id` int(11) NOT NULL,
+ `bank_name` varchar(255) DEFAULT NULL,
+ `branch` varchar(255) DEFAULT NULL,
+ `bsb_number` varchar(50) DEFAULT NULL,
+ `account_number` varchar(50) DEFAULT NULL,
+ `account_name` varchar(255) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `customer_application_id` (`customer_application_id`),
+ CONSTRAINT `customer_bank_details_ibfk_1` FOREIGN KEY (`customer_application_id`) REFERENCES `customer_applications` (`id`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+-- Add columns for declaration and signature to customer_applications
+ALTER TABLE `customer_applications`
+ADD COLUMN `declaration_text` TEXT,
+ADD COLUMN `signature_path` VARCHAR(255);
\ No newline at end of file
diff --git a/db/migrations/007_add_financial_credit_details.sql b/db/migrations/007_add_financial_credit_details.sql
new file mode 100644
index 0000000..3691b43
--- /dev/null
+++ b/db/migrations/007_add_financial_credit_details.sql
@@ -0,0 +1,20 @@
+ALTER TABLE `customer_applications`
+ADD COLUMN `major_product` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `capital` DECIMAL(20, 2) DEFAULT NULL,
+ADD COLUMN `capital_currency` VARCHAR(10) DEFAULT NULL,
+ADD COLUMN `main_shareholders` TEXT DEFAULT NULL,
+ADD COLUMN `num_employees` INT DEFAULT NULL,
+ADD COLUMN `payment_terms_ar` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `pl_year` YEAR DEFAULT NULL,
+ADD COLUMN `net_sales` DECIMAL(20, 2) DEFAULT NULL,
+ADD COLUMN `net_income_margin` DECIMAL(20, 2) DEFAULT NULL,
+ADD COLUMN `net_income_margin_ratio` DECIMAL(5, 2) DEFAULT NULL,
+ADD COLUMN `sales_target_this_year` DECIMAL(20, 2) DEFAULT NULL,
+ADD COLUMN `sales_target_next_year` DECIMAL(20, 2) DEFAULT NULL,
+ADD COLUMN `sales_target_after_next` DECIMAL(20, 2) DEFAULT NULL,
+ADD COLUMN `credit_rank` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `credit_limit` DECIMAL(20, 2) DEFAULT NULL,
+ADD COLUMN `credit_research_status` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `credit_research_reason` TEXT DEFAULT NULL,
+ADD COLUMN `tax_rate_area` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `billing_type` VARCHAR(255) DEFAULT NULL;
diff --git a/db/migrations/008_add_del_to_info.sql b/db/migrations/008_add_del_to_info.sql
new file mode 100644
index 0000000..bc74751
--- /dev/null
+++ b/db/migrations/008_add_del_to_info.sql
@@ -0,0 +1,21 @@
+-- Add columns for DEL-TO INFORMATIONS
+ALTER TABLE `customer_applications`
+ADD COLUMN `del_to_code` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `delivery_abbreviation` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_customer_name` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_address_1` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_address_2` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_address_3` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_address_4` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_postcode` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_phone` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_area_code` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_transportation_code` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_stock_point_code` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_recipient_section` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_country_code` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_shipment_flag` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_transport_days` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_shipment_condition_category` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_transport_service_exist` VARCHAR(255) DEFAULT NULL,
+ADD COLUMN `del_to_shipment_condition_place` VARCHAR(255) DEFAULT NULL;
diff --git a/db/migrations/009_add_sop_details.sql b/db/migrations/009_add_sop_details.sql
new file mode 100644
index 0000000..d499329
--- /dev/null
+++ b/db/migrations/009_add_sop_details.sql
@@ -0,0 +1,29 @@
+ALTER TABLE `customer_applications`
+ADD COLUMN `doc_req_do` VARCHAR(255),
+ADD COLUMN `doc_req_packing_list` VARCHAR(255),
+ADD COLUMN `doc_req_invoice` VARCHAR(255),
+ADD COLUMN `doc_req_export_permit` VARCHAR(255),
+ADD COLUMN `doc_req_po_do_inv` VARCHAR(255),
+ADD COLUMN `doc_req_do_inv` VARCHAR(255),
+ADD COLUMN `doc_req_others` TEXT,
+ADD COLUMN `pack_req_one_line_carton` VARCHAR(255),
+ADD COLUMN `pack_req_one_item_carton` VARCHAR(255),
+ADD COLUMN `pack_req_one_item_pocket` VARCHAR(255),
+ADD COLUMN `pack_req_thomson_label` VARCHAR(255),
+ADD COLUMN `pack_req_contents_label` VARCHAR(255),
+ADD COLUMN `pack_req_delivery_schedule` VARCHAR(255),
+ADD COLUMN `forwarder_name` VARCHAR(255),
+ADD COLUMN `forwarder_code` VARCHAR(255),
+ADD COLUMN `forwarder_address` TEXT,
+ADD COLUMN `forwarder_contact_person` VARCHAR(255),
+ADD COLUMN `forwarder_phone` VARCHAR(255),
+ADD COLUMN `forwarder_fax` VARCHAR(255),
+ADD COLUMN `forwarder_delivery_method` VARCHAR(255),
+ADD COLUMN `forwarder_delivery_timings` VARCHAR(255),
+ADD COLUMN `forwarder_delivery_requirements` TEXT,
+ADD COLUMN `special_instructions_shipping_mark` VARCHAR(255),
+ADD COLUMN `special_instructions_fax_documents` VARCHAR(255),
+ADD COLUMN `special_instructions_details` TEXT,
+ADD COLUMN `special_instructions_attention_to` VARCHAR(255),
+ADD COLUMN `special_instructions_fax_number` VARCHAR(255),
+ADD COLUMN `remarks` TEXT;
diff --git a/delete_file.php b/delete_file.php
new file mode 100644
index 0000000..9e2ccc5
--- /dev/null
+++ b/delete_file.php
@@ -0,0 +1,59 @@
+prepare("SELECT stored_filename FROM application_files WHERE id = ? AND application_id = ?");
+ $stmt->execute([$file_id, $application_id]);
+ $file = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if ($file) {
+ $filepath = __DIR__ . '/uploads/' . $file['stored_filename'];
+
+ // Delete the file from the filesystem
+ if (file_exists($filepath)) {
+ unlink($filepath);
+ }
+
+ // Delete the record from the database
+ $delete_stmt = $pdo->prepare("DELETE FROM application_files WHERE id = ?");
+ $delete_stmt->execute([$file_id]);
+
+ $_SESSION['message'] = 'File deleted successfully.';
+ $_SESSION['message_type'] = 'success';
+ } else {
+ $_SESSION['message'] = 'File not found or you do not have permission to delete it.';
+ $_SESSION['message_type'] = 'danger';
+ }
+
+ } catch (PDOException $e) {
+ // In a real app, log this error
+ $_SESSION['message'] = 'Database error while deleting file.';
+ $_SESSION['message_type'] = 'danger';
+ }
+
+ header('Location: view_application.php?id=' . $application_id);
+ exit();
+
+} else {
+ header('Location: index.php');
+ exit();
+}
\ No newline at end of file
diff --git a/edit_application.php b/edit_application.php
new file mode 100644
index 0000000..0992dcb
--- /dev/null
+++ b/edit_application.php
@@ -0,0 +1,282 @@
+prepare("SELECT * FROM customer_applications WHERE id = ?");
+ $stmt->execute([$application_id]);
+ $customer = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if ($customer) {
+ // Fetch contacts
+ $stmt = $pdo->prepare("SELECT * FROM customer_contacts WHERE customer_application_id = ? ORDER BY is_primary DESC, id ASC");
+ $stmt->execute([$application_id]);
+ $contacts = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+ // Fetch addresses
+ $stmt = $pdo->prepare("SELECT * FROM customer_addresses WHERE customer_application_id = ? ORDER BY id ASC");
+ $stmt->execute([$application_id]);
+ $addresses = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+ // Fetch files
+ $stmt = $pdo->prepare("SELECT * FROM application_files WHERE customer_application_id = ? ORDER BY created_at DESC");
+ $stmt->execute([$application_id]);
+ $files = $stmt->fetchAll(PDO::FETCH_ASSOC);
+ }
+
+} catch (PDOException $e) {
+ die("Database error: " . $e->getMessage());
+}
+
+if (!$customer) {
+ http_response_code(404);
+ echo "Application not found.";
+ exit();
+}
+?>
+
+
+
+
+
+ Edit Customer Application
+
+
+
+
+
+
+
Edit Customer Application #
+
+
+
+
+
+
diff --git a/includes/auth_helpers.php b/includes/auth_helpers.php
new file mode 100644
index 0000000..4fda5fc
--- /dev/null
+++ b/includes/auth_helpers.php
@@ -0,0 +1,27 @@
+ 'danger',
+ 'message' => 'You do not have permission to access this page.'
+ ];
+ header('Location: index.php');
+ exit();
+ }
+}
diff --git a/index.php b/index.php
index 7205f3d..eb3c6bd 100644
--- a/index.php
+++ b/index.php
@@ -1,150 +1,217 @@
-
+
-
-
- New Style
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ Dashboard -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
Analyzing your requirements and generating your website…
-
- Loading…
-
-
= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.
-
This page will update automatically as the plan is implemented.
-
Runtime: PHP = htmlspecialchars($phpVersion) ?> — UTC = htmlspecialchars($now) ?>
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Your dashboard is ready. From here you can manage customer applications.
+
+
+
+
+
+ ' : '
';
+ }
+ return '';
+ }
+
+ function getStatusBadgeClass($status) {
+ switch ($status) {
+ case 'pending_approval':
+ return 'bg-warning';
+ case 'approved':
+ return 'bg-success';
+ case 'rejected':
+ return 'bg-danger';
+ case 'reverted':
+ return 'bg-info';
+ case 'draft':
+ default:
+ return 'bg-secondary';
+ }
+ }
+
+ $sort_column = $_GET['sort'] ?? 'created_at';
+ $sort_order = $_GET['order'] ?? 'DESC';
+ $valid_columns = ['id', 'application_id', 'company_name', 'status', 'created_at'];
+ if (!in_array($sort_column, $valid_columns)) {
+ $sort_column = 'created_at';
+ }
+
+ $status_filter = $_GET['status'] ?? '';
+ $sql = "SELECT id, application_id, company_name, status, created_at FROM customer_applications";
+ $params = [];
+
+ if ($status_filter) {
+ $sql .= " WHERE status = ?";
+ $params[] = $status_filter;
+ }
+
+ $sql .= " ORDER BY $sort_column $sort_order";
+
+ $stmt = $pdo->prepare($sql);
+ $stmt->execute($params);
+ $applications = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+ if (count($applications) > 0) {
+ echo '
';
+ echo '';
+ echo '';
+ echo '| Application ID' . getSortIcon('application_id', $sort_column, $sort_order) . ' | ';
+ echo 'Company Name' . getSortIcon('company_name', $sort_column, $sort_order) . ' | ';
+ echo 'Status' . getSortIcon('status', $sort_column, $sort_order) . ' | ';
+ echo 'Date Submitted' . getSortIcon('created_at', $sort_column, $sort_order) . ' | ';
+ echo '
';
+ echo '';
+ echo '';
+ foreach ($applications as $app) { $badgeClass = getStatusBadgeClass($app['status']);
+ echo '';
+ echo '| ' . htmlspecialchars($app['application_id']) . ' | ';
+ echo '' . htmlspecialchars($app['company_name']) . ' | ';
+ echo '' . htmlspecialchars(ucfirst(str_replace('_', ' ', $app['status']))) . ' | ';
+ echo '' . htmlspecialchars(date("Y-m-d H:i", strtotime($app['created_at']))) . ' | ';
+ echo '
';
+ }
+ echo '';
+ echo '
';
+ } else {
+ echo '
No customer applications found.
';
+ }
+ } catch (PDOException $e) {
+ echo '
Error: Could not fetch applications.
';
+ // Optional: log error to a file
+ // error_log($e->getMessage());
+ }
+ ?>
+
+
+
+
+
-
+