2 Commits

Author SHA1 Message Date
wrongecho
216db04d32 Flag duplicate numbering in debug 2025-11-27 10:27:54 +00:00
wrongecho
13b8f93e17 Add unique index to ticket, quote and invoice numbers 2025-11-27 10:27:11 +00:00
2 changed files with 46 additions and 3 deletions

View File

@@ -502,6 +502,12 @@ if (file_exists($dbSqlFile)) {
];
}
// Duplicate checks
$duplicate_tickets_sql = mysqli_query($mysqli, "SELECT ticket_number, COUNT(*) AS count FROM tickets GROUP BY ticket_number HAVING count > 1");
$duplicate_quotes_sql = mysqli_query($mysqli, "SELECT quote_number, COUNT(*) AS count FROM quotes GROUP BY quote_number HAVING count > 1");
$duplicate_invoices_sql = mysqli_query($mysqli, "SELECT invoice_number, COUNT(*) AS count FROM invoices GROUP BY invoice_number HAVING count > 1");
$mysqli->close();
?>
@@ -758,6 +764,40 @@ $mysqli->close();
</table>
</div>
<!-- Duplicated ticket/quote/invoice numbers -->
<h3 class="mt-3">Duplicated Numbering</h3>
<h4>Tickets</h4>
<ul>
<?php if (mysqli_num_rows($duplicate_tickets_sql) > 0 ) {
while ($row = $duplicate_tickets_sql->fetch_assoc()) {
echo "<li>" . $config_ticket_prefix . nullable_htmlentities($row['ticket_number']) . " (" . $row['count'] . ")" . "</li>";
}
} else {
echo "No duplicate ticket numbers.";
} ?>
</ul>
<h4>Quotes</h4>
<ul>
<?php if (mysqli_num_rows($duplicate_quotes_sql) > 0 ) {
while ($row = $duplicate_quotes_sql->fetch_assoc()) {
echo "<li>" . $config_quote_prefix . nullable_htmlentities($row['quote_number']) . " (" . $row['count'] . ")" . "</li>";
}
} else {
echo "No duplicate quote numbers.";
} ?>
</ul>
<h4>Invoices</h4>
<ul>
<?php if (mysqli_num_rows($duplicate_invoices_sql) > 0 ) {
while ($row = $duplicate_invoices_sql->fetch_assoc()) {
echo "<li>" . $config_invoice_prefix . nullable_htmlentities($row['invoice_number']) . " (" . $row['count'] . ")" . "</li>";
}
} else {
echo "No duplicate invoice numbers.";
} ?>
</ul>
</div>
</div>

9
db.sql
View File

@@ -1324,7 +1324,8 @@ CREATE TABLE `invoices` (
`invoice_category_id` int(11) NOT NULL,
`invoice_recurring_invoice_id` int(11) NOT NULL DEFAULT 0,
`invoice_client_id` int(11) NOT NULL,
PRIMARY KEY (`invoice_id`)
PRIMARY KEY (`invoice_id`),
UNIQUE KEY `invoice_number` (`invoice_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -1677,7 +1678,8 @@ CREATE TABLE `quotes` (
`quote_archived_at` datetime DEFAULT NULL,
`quote_category_id` int(11) NOT NULL,
`quote_client_id` int(11) NOT NULL,
PRIMARY KEY (`quote_id`)
PRIMARY KEY (`quote_id`),
UNIQUE KEY `quote_number` (`quote_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -2644,7 +2646,8 @@ CREATE TABLE `tickets` (
`ticket_project_id` int(11) NOT NULL DEFAULT 0,
`ticket_recurring_ticket_id` int(11) DEFAULT 0,
`ticket_order` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`ticket_id`)
PRIMARY KEY (`ticket_id`),
UNIQUE KEY `ticket_number` (`ticket_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;