feat(helpdesk): add domain linking, bulk actions, and revision polish to handovers
Adds domain selection (cascaded from debitor) to handover creation and edit, bulk delete with confirmation dialog, and various UI improvements to the handover wizard and list page. Includes migration for domain columns, domain-select AJAX endpoint, and updated tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,12 +15,14 @@ class HandoverRepository
|
||||
{
|
||||
$result = DB::insert(
|
||||
'INSERT INTO helpdesk_handovers '
|
||||
. '(tenant_id, debitor_no, debitor_name, product_code, status, schema_snapshot, field_values, created_by) '
|
||||
. 'VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
. '(tenant_id, debitor_no, debitor_name, product_code, domain_no, domain_url, status, schema_snapshot, field_values, created_by) '
|
||||
. 'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
(string) ($data['tenant_id'] ?? 0),
|
||||
(string) ($data['debitor_no'] ?? ''),
|
||||
(string) ($data['debitor_name'] ?? ''),
|
||||
(string) ($data['product_code'] ?? ''),
|
||||
(string) ($data['domain_no'] ?? ''),
|
||||
(string) ($data['domain_url'] ?? ''),
|
||||
(string) ($data['status'] ?? 'draft'),
|
||||
$data['schema_snapshot'] ?? null,
|
||||
$data['field_values'] ?? null,
|
||||
@@ -68,7 +70,7 @@ class HandoverRepository
|
||||
[$limit, $offset] = RepoQuery::sanitizeLimitOffset($filters, 20, 1, 100, 0);
|
||||
[$order, $dir] = RepoQuery::sanitizeOrder(
|
||||
$filters,
|
||||
['id', 'debitor_name', 'product_code', 'status', 'created_at', 'created_by'],
|
||||
['id', 'domain_url', 'debitor_name', 'product_code', 'status', 'created_at', 'created_by'],
|
||||
'created_at',
|
||||
'desc'
|
||||
);
|
||||
@@ -76,7 +78,7 @@ class HandoverRepository
|
||||
$where = ['h.tenant_id = ?'];
|
||||
$params = [(string) $tenantId];
|
||||
|
||||
RepoQuery::addLikeFilter($where, $params, ['h.debitor_name', 'h.debitor_no', 'h.product_code'], $search);
|
||||
RepoQuery::addLikeFilter($where, $params, ['h.debitor_name', 'h.debitor_no', 'h.domain_url', 'h.product_code'], $search);
|
||||
|
||||
if ($status !== '' && $status !== 'all') {
|
||||
$where[] = 'h.status = ?';
|
||||
@@ -92,8 +94,11 @@ class HandoverRepository
|
||||
$total = (int) (DB::selectValue('SELECT COUNT(*) FROM helpdesk_handovers h' . $whereSql, ...$params) ?? 0);
|
||||
|
||||
$rows = DB::select(
|
||||
'SELECT h.*, u.display_name AS created_by_name FROM helpdesk_handovers h'
|
||||
'SELECT h.*, u.display_name AS created_by_name,'
|
||||
. ' sp.name AS product_name, sp.bc_description AS product_bc_description'
|
||||
. ' FROM helpdesk_handovers h'
|
||||
. ' LEFT JOIN users u ON u.id = h.created_by'
|
||||
. ' LEFT JOIN helpdesk_software_products sp ON sp.code = h.product_code'
|
||||
. $whereSql
|
||||
. sprintf(' ORDER BY h.`%s` %s LIMIT ? OFFSET ?', $order, $dir),
|
||||
...array_merge($params, [(string) $limit, (string) $offset])
|
||||
@@ -141,6 +146,79 @@ class HandoverRepository
|
||||
return $result !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $ids
|
||||
*/
|
||||
public function deleteByIds(int $tenantId, array $ids): int
|
||||
{
|
||||
if ($ids === []) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$placeholders = implode(',', array_fill(0, count($ids), '?'));
|
||||
$params = array_map('strval', $ids);
|
||||
$params[] = (string) $tenantId;
|
||||
|
||||
$result = DB::update(
|
||||
'DELETE FROM helpdesk_handovers WHERE id IN (' . $placeholders . ') AND tenant_id = ?',
|
||||
...$params
|
||||
);
|
||||
|
||||
return is_int($result) ? $result : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all handovers linked to a specific domain.
|
||||
*
|
||||
* @api Called from DomainDetailService
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function findByDomainNo(int $tenantId, string $domainNo): array
|
||||
{
|
||||
if ($domainNo === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$rows = DB::select(
|
||||
'SELECT h.*, u.display_name AS created_by_name,'
|
||||
. ' sp.name AS product_name, sp.bc_description AS product_bc_description'
|
||||
. ' FROM helpdesk_handovers h'
|
||||
. ' LEFT JOIN users u ON u.id = h.created_by'
|
||||
. ' LEFT JOIN helpdesk_software_products sp ON sp.code = h.product_code'
|
||||
. ' WHERE h.tenant_id = ? AND h.domain_no = ?'
|
||||
. ' ORDER BY h.created_at DESC',
|
||||
(string) $tenantId,
|
||||
$domainNo
|
||||
);
|
||||
|
||||
$normalized = [];
|
||||
if (is_array($rows)) {
|
||||
foreach ($rows as $row) {
|
||||
$item = $this->normalizeRow($row);
|
||||
if ($item !== null) {
|
||||
$normalized[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
public function beginTransaction(): void
|
||||
{
|
||||
DB::handle()->begin_transaction();
|
||||
}
|
||||
|
||||
public function commitTransaction(): void
|
||||
{
|
||||
DB::handle()->commit();
|
||||
}
|
||||
|
||||
public function rollbackTransaction(): void
|
||||
{
|
||||
DB::handle()->rollback();
|
||||
}
|
||||
|
||||
private function normalizeRow(mixed $row): ?array
|
||||
{
|
||||
if (!is_array($row)) {
|
||||
|
||||
Reference in New Issue
Block a user