refactor: move priority emails to customer card
Priority emails are now per-customer, not per-company. Each customer can have a list of email addresses that automatically elevate ticket priority to "tärkeä" when they send email. Field added to customer form under "Lisätiedot" section. Removed separate priority_emails settings from API/rules tabs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
23
db.php
23
db.php
@@ -194,6 +194,7 @@ function initDatabase(): void {
|
||||
elaskuvalittaja VARCHAR(100),
|
||||
ytunnus VARCHAR(20),
|
||||
lisatiedot TEXT,
|
||||
priority_emails TEXT DEFAULT '',
|
||||
luotu DATETIME,
|
||||
muokattu DATETIME NULL,
|
||||
muokkaaja VARCHAR(100) DEFAULT '',
|
||||
@@ -373,6 +374,7 @@ function initDatabase(): void {
|
||||
$alters = [
|
||||
"ALTER TABLE tickets ADD COLUMN cc TEXT DEFAULT '' AFTER mailbox_id",
|
||||
"ALTER TABLE tickets ADD COLUMN priority VARCHAR(20) DEFAULT 'normaali' AFTER cc",
|
||||
"ALTER TABLE customers ADD COLUMN priority_emails TEXT DEFAULT '' AFTER lisatiedot",
|
||||
];
|
||||
foreach ($alters as $sql) {
|
||||
try { $db->query($sql); } catch (\Throwable $e) { /* sarake on jo olemassa */ }
|
||||
@@ -661,10 +663,10 @@ function dbSaveCustomer(string $companyId, array $customer): void {
|
||||
_dbExecute("
|
||||
INSERT INTO customers (id, company_id, yritys, yhteyshenkilö, puhelin, sahkoposti,
|
||||
laskutusosoite, laskutuspostinumero, laskutuskaupunki, laskutussahkoposti,
|
||||
elaskuosoite, elaskuvalittaja, ytunnus, lisatiedot, luotu, muokattu, muokkaaja)
|
||||
elaskuosoite, elaskuvalittaja, ytunnus, lisatiedot, priority_emails, luotu, muokattu, muokkaaja)
|
||||
VALUES (:id, :company_id, :yritys, :yhteyshenkilö, :puhelin, :sahkoposti,
|
||||
:laskutusosoite, :laskutuspostinumero, :laskutuskaupunki, :laskutussahkoposti,
|
||||
:elaskuosoite, :elaskuvalittaja, :ytunnus, :lisatiedot, :luotu, :muokattu, :muokkaaja)
|
||||
:elaskuosoite, :elaskuvalittaja, :ytunnus, :lisatiedot, :priority_emails, :luotu, :muokattu, :muokkaaja)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
yritys = VALUES(yritys), yhteyshenkilö = VALUES(yhteyshenkilö),
|
||||
puhelin = VALUES(puhelin), sahkoposti = VALUES(sahkoposti),
|
||||
@@ -672,6 +674,7 @@ function dbSaveCustomer(string $companyId, array $customer): void {
|
||||
laskutuskaupunki = VALUES(laskutuskaupunki), laskutussahkoposti = VALUES(laskutussahkoposti),
|
||||
elaskuosoite = VALUES(elaskuosoite), elaskuvalittaja = VALUES(elaskuvalittaja),
|
||||
ytunnus = VALUES(ytunnus), lisatiedot = VALUES(lisatiedot),
|
||||
priority_emails = VALUES(priority_emails),
|
||||
muokattu = VALUES(muokattu), muokkaaja = VALUES(muokkaaja)
|
||||
", [
|
||||
'id' => $customer['id'],
|
||||
@@ -688,6 +691,7 @@ function dbSaveCustomer(string $companyId, array $customer): void {
|
||||
'elaskuvalittaja' => $customer['elaskuvalittaja'] ?? '',
|
||||
'ytunnus' => $customer['ytunnus'] ?? '',
|
||||
'lisatiedot' => $customer['lisatiedot'] ?? '',
|
||||
'priority_emails' => $customer['priority_emails'] ?? '',
|
||||
'luotu' => $customer['luotu'] ?? date('Y-m-d H:i:s'),
|
||||
'muokattu' => $customer['muokattu'] ?? null,
|
||||
'muokkaaja' => $customer['muokkaaja'] ?? '',
|
||||
@@ -1081,15 +1085,14 @@ function dbDeleteTemplate(string $templateId): void {
|
||||
|
||||
// ==================== PRIORITY EMAILS (ASIAKKUUDET) ====================
|
||||
|
||||
function dbLoadPriorityEmails(string $companyId): array {
|
||||
return _dbFetchColumn("SELECT email FROM customer_priority_emails WHERE company_id = ?", [$companyId]);
|
||||
}
|
||||
|
||||
function dbIsPriorityEmail(string $companyId, string $email): bool {
|
||||
$email = strtolower(trim($email));
|
||||
if (!$email) return false;
|
||||
return (bool)_dbFetchScalar(
|
||||
"SELECT COUNT(*) FROM customer_priority_emails WHERE company_id = ? AND LOWER(email) = ?",
|
||||
[$companyId, $email]
|
||||
);
|
||||
// Hae kaikki asiakkaiden priority_emails kentät ja tarkista onko sähköposti listalla
|
||||
$rows = _dbFetchAll("SELECT priority_emails FROM customers WHERE company_id = ? AND priority_emails != ''", [$companyId]);
|
||||
foreach ($rows as $row) {
|
||||
$emails = array_map('strtolower', array_map('trim', explode("\n", $row['priority_emails'])));
|
||||
if (in_array($email, $emails)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user