Document templates stage 3, the client standard and reviews: a template can be required of every client or of clients with chosen tags (leads and archived clients not counted, a template whose tags are all deleted applying to none rather than every client), with the template page showing how many clients have one with a bar and the clients missing it each with a Make button, and Admin > Document Templates showing the count on each template plus a new Required tab; documents can be made for several clients at once, one per client filled in from its own client, for a picked list or every missing client in one click, with fill-ins answered once for all and clients that already have one skipped unless unticked; a client's Files shows the documents it should have along the top opening Document from template with that template picked, the client overview shows a Documents missing count, and Document from template lists missing templates first; a template can ask for its documents to be reviewed every 3 or 6 months, yearly or every 2 years, a document falling due when not edited or marked reviewed for that long, with the document page showing Review due or the next review and who did the last one plus a Mark reviewed button, a Review due tab in Files listing due documents across every folder, and due counts on the client overview, the template page and the list, documents from archived templates not counted; an older document written before its template can be linked to it from its page so it counts and follows the template's review schedule; migration 3.2.7; fixed tag merges dropping merged tags from ticket templates (merges now carry over ticket template and required template tags) and deleting a document template marking all its documents as updated; changelog updated

This commit is contained in:
johnnyq
2026-10-18 19:49:20 -04:00
parent 3ee183a09a
commit 32b5288338
17 changed files with 1007 additions and 44 deletions

View File

@@ -6,7 +6,9 @@
* and what it asks for when a document is made (its fill-ins: set up, dragged
* into order) - who made it and last changed it, and its use: how many
* documents have been made from it, for how many clients, and the latest of
* them. A new document for a client can be made from here. The work is in
* them - and who should have one: the clients missing one, and the documents
* made from it due a review. A new document can be made from here for a
* client, for several at once, or for every client missing one. The work is in
* functions/document_template.php.
*/
@@ -42,8 +44,20 @@ while ($row = mysqli_fetch_assoc($sql)) {
$recent[] = $row;
}
// Who should have one, and the documents due a review - neither counts while it is archived
$required = intval($template['document_template_required']);
$required_tags = documentTemplateRequiredTags([$document_template_id])[$document_template_id];
$scope_text = documentTemplateScopeText($required, $required_tags);
$coverage = $required && !$archived ? documentTemplateCoverage($document_template_id, $required, array_keys($required_tags)) : null;
$review_months = intval($template['document_template_review_months']);
$due = $review_months && !$archived ? documentsReviewDue("documents.document_template_id = $document_template_id") : [];
$list_limit = 8;
$missing_text = $coverage && $coverage['missing'] ? (count($coverage['missing']) === 1 ? 'the client missing one' : 'the ' . count($coverage['missing']) . ' clients missing one') : '';
$edit_url = "modals/document_template/document_template_edit.php?id=$document_template_id";
$use_url = "modals/document_template/document_template_use.php?id=$document_template_id";
$several_url = "modals/document_template/document_template_use_several.php?id=$document_template_id";
$required_url = "modals/document_template/document_template_required.php?id=$document_template_id";
?>
@@ -68,7 +82,16 @@ $use_url = "modals/document_template/document_template_use.php?id=$document_temp
</div>
<div class="d-flex flex-wrap gap-2 d-print-none">
<?php if (!$archived) { ?>
<button type="button" class="btn btn-primary ajax-modal" data-modal-size="lg" data-modal-url="<?= $use_url ?>"><i class="fas fa-fw fa-plus me-2"></i>New document for a client</button>
<div class="btn-group">
<button type="button" class="btn btn-primary ajax-modal" data-modal-size="lg" data-modal-url="<?= $use_url ?>"><i class="fas fa-fw fa-plus me-2"></i>New document for a client</button>
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-label="More ways to make one"></button>
<div class="dropdown-menu dropdown-menu-end">
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="<?= $several_url ?>"><i class="fas fa-fw fa-copy me-2"></i>For several clients</a>
<?php if ($coverage && $coverage['missing']) { ?>
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="<?= $several_url ?>&missing=1"><i class="fas fa-fw fa-clipboard-check me-2"></i>For <?= $missing_text ?></a>
<?php } ?>
</div>
</div>
<?php } ?>
<button type="button" class="btn btn-outline-secondary ajax-modal" data-modal-size="xl" data-modal-url="<?= $edit_url ?>"><i class="fas fa-fw fa-edit me-2"></i>Edit</button>
<div class="dropdown">
@@ -105,6 +128,82 @@ $use_url = "modals/document_template/document_template_use.php?id=$document_temp
<div class="col-lg-4 d-print-none">
<div class="card mb-3" id="documentTemplateCoverage">
<div class="card-header d-flex align-items-center">
<h3 class="card-title mb-0"><i class="fas fa-fw fa-clipboard-check me-2"></i>Who should have one</h3>
<button type="button" class="btn btn-sm btn-link ms-auto ajax-modal" data-modal-url="<?= $required_url ?>"><i class="fas fa-edit me-1"></i>Set up</button>
</div>
<div class="card-body">
<?php if (!$required && !$review_months) { ?>
<div class="small text-secondary">No one in particular, and no reviews. Set it up to see which clients are missing one - every client, or the ones with a tag - and which documents made from it are due a review.</div>
<?php } elseif ($archived) { ?>
<div class="small text-secondary"><?= escapeHtml($scope_text ?: 'No one in particular') ?><?= $review_months ? ', reviewed ' . lcfirst(DOCUMENT_TEMPLATE_REVIEW_MONTHS[$review_months]) : '' ?> - not counted while it is archived.</div>
<?php } else { ?>
<?php if ($coverage) {
$percent = $coverage['clients'] ? intval(floor($coverage['covered'] * 100 / $coverage['clients'])) : 100;
?>
<div class="d-flex align-items-baseline gap-2 mb-1">
<span class="fw-semibold min-w-0 text-truncate" title="<?= escapeHtml($scope_text) ?>"><?= escapeHtml($scope_text) ?></span>
<span class="ms-auto small text-nowrap"><strong><?= $coverage['covered'] ?></strong> of <?= $coverage['clients'] ?> have one</span>
</div>
<div class="progress mb-2" role="progressbar" aria-label="Clients with one" aria-valuenow="<?= $percent ?>" aria-valuemin="0" aria-valuemax="100" style="height: 6px;">
<div class="progress-bar <?= $coverage['missing'] ? 'bg-warning' : 'bg-success' ?>" style="width: <?= $percent ?>%"></div>
</div>
<?php if ($coverage['missing']) { ?>
<div class="small text-secondary mb-1">Missing one</div>
<div class="list-group list-group-flush small mb-2">
<?php foreach (array_slice($coverage['missing'], 0, $list_limit, true) as $client_id => $client_name) { ?>
<div class="list-group-item px-0 d-flex align-items-center gap-2" data-missing-client-id="<?= $client_id ?>">
<i class="fas fa-fw fa-user text-secondary"></i>
<a class="min-w-0 flex-grow-1 text-truncate text-reset" href="/agent/files.php?client_id=<?= $client_id ?>"><?= escapeHtml($client_name) ?></a>
<button type="button" class="btn btn-sm btn-light py-0 ajax-modal" data-modal-size="lg" data-modal-url="<?= $use_url ?>&client_id=<?= $client_id ?>"><i class="fas fa-plus me-1"></i>Make</button>
</div>
<?php } ?>
</div>
<?php if (count($coverage['missing']) > $list_limit) { ?>
<div class="small text-secondary mb-2">and <?= count($coverage['missing']) - $list_limit ?> more</div>
<?php } ?>
<button type="button" class="btn btn-sm btn-outline-primary ajax-modal" data-modal-size="lg" data-modal-url="<?= $several_url ?>&missing=1"><i class="fas fa-copy me-1"></i>Make for <?= $missing_text ?></button>
<?php } elseif ($coverage['clients']) { ?>
<div class="small text-success"><i class="fas fa-fw fa-check me-1"></i>Every one of them has one.</div>
<?php } else { ?>
<div class="small text-secondary"><?= $required === DOCUMENT_TEMPLATE_REQUIRED_TAGGED ? ($required_tags ? 'No clients have ' . (count($required_tags) === 1 ? 'that tag' : 'those tags') : 'No tags picked, so no clients') : 'No clients yet' ?>.</div>
<?php } ?>
<?php } else { ?>
<div class="small text-secondary">No one in particular.</div>
<?php } ?>
<div class="border-top mt-3 pt-3 small">
<?php if (!$review_months) { ?>
<span class="text-secondary"><i class="fas fa-fw fa-calendar-check me-1"></i>The documents made from it aren't reviewed.</span>
<?php } else { ?>
<div class="d-flex align-items-baseline gap-2 mb-1">
<span><i class="fas fa-fw fa-calendar-check me-1 text-secondary"></i>Reviewed <?= lcfirst(DOCUMENT_TEMPLATE_REVIEW_MONTHS[$review_months]) ?></span>
<span class="ms-auto text-nowrap <?= $due ? 'text-warning-emphasis fw-semibold' : 'text-success' ?>"><?= $due ? count($due) . ' due' : '<i class="fas fa-check me-1"></i>None due' ?></span>
</div>
<?php if ($due) { ?>
<div class="list-group list-group-flush">
<?php foreach (array_slice($due, 0, $list_limit, true) as $due_id => $due_row) { ?>
<a class="list-group-item list-group-item-action px-0 d-flex align-items-center gap-2" href="/agent/document.php?client_id=<?= intval($due_row['document_client_id']) ?>&document_id=<?= $due_id ?>" data-due-document-id="<?= $due_id ?>">
<i class="fas fa-fw fa-file-alt text-secondary"></i>
<span class="min-w-0 flex-grow-1">
<span class="d-block text-truncate"><?= escapeHtml($due_row['client_name']) ?></span>
<span class="d-block text-truncate text-secondary"><?= escapeHtml($due_row['document_name']) ?></span>
</span>
<span class="text-secondary text-nowrap" title="Last edited or reviewed <?= escapeHtml($due_row['reviewed_at']) ?>"><?= timeAgo($due_row['reviewed_at']) ?></span>
</a>
<?php } ?>
</div>
<?php if (count($due) > $list_limit) { ?>
<div class="text-secondary mt-1">and <?= count($due) - $list_limit ?> more</div>
<?php } ?>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
</div>
</div>
<div class="card mb-3">
<div class="card-header"><h3 class="card-title mb-0"><i class="fas fa-fw fa-chart-line me-2"></i>Used</h3></div>
<div class="card-body">