Auto-create and repair subscription engagements

This commit is contained in:
A R R R Associates
2026-08-19 15:39:08 +05:30
parent fee4d6d235
commit 2f061d29b4
3 changed files with 396 additions and 6 deletions
@@ -33,6 +33,17 @@
Map Scope
</a>
{% endif %}
{% if can_edit_subscription and plan.is_active and plan.status == 'active' %}
<form method="post" action="/services/subscriptions/{{ plan.id }}/generate-current"
onsubmit="return confirm('Generate the current engagement for FY {{ financial_year }}? Existing matching engagements will be reused.');">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
<input type="hidden" name="financial_year" value="{{ financial_year }}">
<button type="submit"
class="rounded-xl border border-emerald-300 px-4 py-2 text-sm font-medium text-emerald-700 hover:bg-emerald-50">
Generate Current Engagement
</button>
</form>
{% endif %}
<a href="/services/engagements/new?client_id={{ plan.client_id }}"
class="rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700">
Create Engagement
@@ -41,6 +52,34 @@
</div>
{% if generated %}
<div class="rounded-xl border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-800">
Current FY engagement generated successfully using the subscription defaults. Due dates, quality workflow and task generation were processed through the existing engagement engine.
</div>
{% endif %}
{% if existing %}
<div class="rounded-xl border border-sky-200 bg-sky-50 px-4 py-3 text-sm text-sky-800">
A matching engagement already exists for the current FY/period, so no duplicate was created.
</div>
{% endif %}
{% if generation_error %}
<div class="rounded-xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-800">
{% if generation_error == 'financial_year' %}
Engagement generation is not allowed because FY {{ financial_year }} is locked.
{% elif generation_error == 'review_partner_required' %}
This assurance service requires a Review Partner before an engagement can be generated.
{% elif generation_error == 'review_partner_independence' %}
The Review Partner must differ from the Engagement Partner and Performing Partner.
{% elif generation_error == 'inactive' %}
This subscription is inactive and cannot generate an engagement.
{% elif generation_error == 'service' %}
The underlying firm service is not enabled, so the engagement was not generated.
{% else %}
The current engagement could not be generated. Please verify the subscription scope and defaults.
{% endif %}
</div>
{% endif %}
<section class="rounded-2xl bg-white p-5 shadow-soft">
<div class="flex flex-wrap items-center justify-between gap-3">
<div>
@@ -13,12 +13,40 @@
Persistent client services shown by their assigned scope. Period-wise engagements are generated and tracked separately.
</p>
</div>
<a href="/services/engagements/new"
class="rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700">
Assign Service
</a>
<div class="flex flex-wrap items-center gap-2">
{% if can_edit_subscription %}
<form method="post" action="/services/subscriptions/generate-missing"
onsubmit="return confirm('Generate the current missing engagement for all active subscriptions in FY {{ financial_year }}? Existing engagements will not be duplicated.');">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
<input type="hidden" name="financial_year" value="{{ financial_year }}">
<button type="submit"
class="rounded-xl border border-emerald-300 px-4 py-2 text-sm font-medium text-emerald-700 hover:bg-emerald-50">
Generate Missing Engagements
</button>
</form>
{% endif %}
<a href="/services/engagements/new"
class="rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700">
Assign Service
</a>
</div>
</div>
{% if repaired or skipped %}
<div class="rounded-xl border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-800">
Missing-engagement repair completed for FY {{ financial_year }}. {{ repaired }} engagement(s) created and {{ skipped }} subscription(s) skipped because an engagement already existed or the subscription was not ready for generation.
</div>
{% endif %}
{% if repair_error %}
<div class="rounded-xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-800">
{% if repair_error == 'financial_year' %}
Engagement generation is not allowed because FY {{ financial_year }} is locked.
{% else %}
Missing engagements could not be generated.
{% endif %}
</div>
{% endif %}
<form method="get" class="flex flex-wrap items-end gap-3 rounded-2xl bg-white p-4 shadow-soft">
<div>
<label class="mb-1 block text-xs font-semibold uppercase tracking-wide text-slate-500">Search</label>