Added redirect() function for page redirects and updated credit system fields to include credit_note, credit_invoice_id and type for better reporting

This commit is contained in:
johnnyq 2025-08-01 13:37:23 -04:00
parent 41a8e41463
commit 7cfba7f2ef
5 changed files with 39 additions and 5 deletions

View File

@ -3809,6 +3809,18 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.2.6'");
}
if (CURRENT_DATABASE_VERSION == '2.2.6') {
mysqli_query($mysqli, "ALTER TABLE `credits` DROP `credit_reference`");
mysqli_query($mysqli, "ALTER TABLE `credits` ADD `credit_type` ENUM('prepaid', 'manual', 'refund', 'promotion', 'usage') NOT NULL DEFAULT 'manual' AFTER `credit_amount`");
mysqli_query($mysqli, "ALTER TABLE `credits` ADD `credit_note` TEXT NULL DEFAULT NULL AFTER `credit_type`");
mysqli_query($mysqli, "ALTER TABLE `credits` ADD `credit_invoice_id` INT(11) NULL DEFAULT NULL AFTER `credit_expire_at`");
mysqli_query($mysqli, "ALTER TABLE `credits` ADD INDEX (`credit_client_id`)");
mysqli_query($mysqli, "ALTER TABLE `credits` ADD INDEX (`credit_invoice_id`)");
mysqli_query($mysqli, "ALTER TABLE `credits` ADD INDEX (`credit_created_at`)");
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.2.7'");
}
/* 2025-07-21 - JQ For next release Pauyment Provider Switch Over
if (CURRENT_DATABASE_VERSION == '2.2.4') {

11
db.sql
View File

@ -849,12 +849,17 @@ DROP TABLE IF EXISTS `credits`;
CREATE TABLE `credits` (
`credit_id` int(11) NOT NULL AUTO_INCREMENT,
`credit_amount` decimal(15,2) NOT NULL,
`credit_reference` varchar(250) DEFAULT NULL,
`credit_type` enum('prepaid','manual','refund','promotion','usage') NOT NULL DEFAULT 'manual',
`credit_note` text DEFAULT NULL,
`credit_created_at` datetime NOT NULL DEFAULT current_timestamp(),
`credit_created_by` int(11) NOT NULL,
`credit_expire_at` date DEFAULT NULL,
`credit_invoice_id` int(11) DEFAULT NULL,
`credit_client_id` int(11) NOT NULL,
PRIMARY KEY (`credit_id`)
PRIMARY KEY (`credit_id`),
KEY `credit_client_id` (`credit_client_id`),
KEY `credit_invoice_id` (`credit_invoice_id`),
KEY `credit_created_at` (`credit_created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@ -2761,4 +2766,4 @@ CREATE TABLE `vendors` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2025-07-31 15:53:18
-- Dump completed on 2025-08-01 13:36:16

View File

@ -1670,4 +1670,21 @@ function sanitize_url($url) {
// Safe schemes: return escaped original URL
return htmlspecialchars($url ?? '', ENT_QUOTES, 'UTF-8');
}
function redirect($url = null, $permanent = false) {
// Use referer if no URL is provided
if (!$url) {
$url = $_SERVER['HTTP_REFERER'] ?? 'index.php';
}
if (!headers_sent()) {
header('Location: ' . $url, true, $permanent ? 301 : 302);
exit;
} else {
// Fallback for headers already sent
echo "<script>window.location.href = '" . addslashes($url) . "';</script>";
echo '<noscript><meta http-equiv="refresh" content="0;url=' . htmlspecialchars($url) . '"></noscript>';
exit;
}
}

View File

@ -5,4 +5,4 @@
* It is used in conjunction with database_updates.php
*/
DEFINE("LATEST_DATABASE_VERSION", "2.2.6");
DEFINE("LATEST_DATABASE_VERSION", "2.2.7");

View File

@ -626,7 +626,7 @@ if (isset($_POST['add_telemetry'])) {
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<li class="nav-item">
<a href="setup.php" class="nav-link <?php if (!isset($_GET) || empty($_GET)) { echo 'active'; } ?>">
<a href="index.php" class="nav-link <?php if (!isset($_GET) || empty($_GET)) { echo 'active'; } ?>">
<i class="nav-icon fas fa-home text-info"></i>
<p>1 - Welcome</p>
</a>