Remove attribute for all associated customers if customer number exists; prevent re-adding exception in invoice collection logic.

This commit is contained in:
Jeppe Bundgaard
2025-11-04 10:29:34 +01:00
parent 6814dcd904
commit dbc96fd0b4
2 changed files with 17 additions and 1 deletions
+16
View File
@@ -220,6 +220,22 @@ class users_o extends db
$user_id = $this->id;
}
$attribute = $db->escape_string($attribute);
// If the user has a customer number, we will delete the attribute from all associated customers
$customer_number = $this->customer_number->value();
if (!empty($customer_number)) {
$sql = "SELECT * FROM users WHERE customer_number = $customer_number";
$result = $db->query($sql);
$user_ids = [];
while ($row = $result->fetch_assoc()) {
$user_ids[] = (int)$row['id'];
}
// Delete the attribute from all users
foreach ($user_ids as $user_id) {
$sql = "DELETE FROM customer_attributes WHERE user_id = $user_id AND attribute = '$attribute' LIMIT 1";
$db->query($sql);
}
return;
}
// Make sure the attribute exists
if (!$this->doesUserHaveAttribute((string)$attribute, (int)$user_id)) {
return;