{% load i18n %}

{% trans "Send To Department" %}

{% if complaint.sent_to_any_department %}
{% for idept in complaint.involved_departments.all %} {% if idept.sent %}
{{ idept.department.get_localized_name }} {% if idept.is_primary %} {% trans "Primary" %} {% endif %}
{{ idept.forwarded_at|date:"M d, Y" }}
{% if not idept.response_submitted %} {% trans "Awaiting Response" %} {% elif idept.manager_review_status == 'pending' %} {% trans "Pending Manager Review" %} {% elif idept.manager_review_status == 'rejected' %} {% trans "Rejected by Manager" %} {% elif idept.manager_review_status == 'approved' and idept.acceptance_status == 'pending' %} {% trans "Approved — Awaiting PX Review" %} {% elif idept.acceptance_status == 'acceptable' %} {% trans "Accepted" %} {% elif idept.acceptance_status == 'not_acceptable' %} {% trans "Rejected by PX" %} {% endif %}
{% if idept.response_notes %}

{% trans "Response" %}

{{ idept.response_notes|truncatechars:150 }}

{% endif %} {% if idept.manager_reviews.exists %}

{% trans "Manager Review Answers" %}

{% for review in idept.manager_reviews.all %}
{% for answer in review.answers.all %}
{{ answer.question.text_ar|default:answer.question.text_en }}: {% if answer.text_value == 'yes' %}{% trans "Yes" %}{% elif answer.text_value == 'no' %}{% trans "No" %}{% else %}{{ answer.text_value }}{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
{% endif %} {% endfor %}
{% if can_manage_actions and complaint.is_active_status %} {% endif %} {% endif %} {% if explanations %}
{% if can_manage_actions and complaint.is_active_status %} {% endif %}
{% for exp in explanations %}
{{ exp.staff.first_name|first }}{{ exp.staff.last_name|first }}

{{ exp.staff }}

{{ exp.staff.employee_id }} {% if exp.staff.department %} {{ exp.staff.department.get_localized_name }} {% endif %}
{% if exp.is_used %}{% trans "Submitted" %}{% else %}{% trans "Pending" %}{% endif %}
{% if exp.is_used and exp.explanation %} {% with linked_dept=exp.linked_involved_department %} {% if linked_dept and linked_dept.manager_review_status == 'pending' %}
{% trans "Pending Manager Review" %}

{% trans "Awaiting department manager approval." %}

{% elif linked_dept and linked_dept.manager_review_status == 'rejected' %}
{% trans "Rejected by Manager" %}

{% trans "Champion needs to re-submit." %}

{% else %}

{{ exp.explanation }}

{% if exp.attachment_count > 0 %}
{{ exp.attachment_count }} {% trans "attachment(s)" %}
{% endif %}
{% endif %} {% endwith %} {% endif %} {% for inv in exp.investigation.all %}
{% trans "Feedback" %} {{ inv.questions.count }} {% trans "questions" %}
{% for resp in inv.responses.all %}
{% if resp.is_completed %} {{ resp.staff.get_full_name }} {{ resp.completed_at|date:"M d, H:i" }} {% else %} {{ resp.staff.get_full_name }} {% trans "Pending" %} {% endif %}
{% endfor %}
{% if inv.questions.exists %}
{% for question in inv.questions.all %}
{{ forloop.counter }}

{{ question.question_text }}

{% for resp in inv.responses.all %} {% if resp.is_completed %} {% with answer=resp.answers.all %} {% for a in answer %} {% if a.question_id == question.id and a.answer_text %}
{{ resp.staff.get_full_name }}: {{ a.answer_text|truncatewords:40 }}
{% endif %} {% endfor %} {% endwith %} {% endif %} {% endfor %}
{% endfor %}
{% endif %} {% if inv.status == 'answers_received' and inv.explanation.token %} {% trans "Review & Submit Reply" %} {% endif %} {% if inv.status == 'reply_submitted' and inv.final_reply %}

{% trans "Final Reply" %}

{{ inv.final_reply|truncatewords:30 }}

{% endif %} {% if inv.status == 'reply_submitted' and inv.negligence_finding %}
{% if inv.negligence_finding == 'yes' %} {% trans "Negligence" %} {% endif %} {% if inv.policy_issue_finding == 'yes' %} {% trans "Policy Issue" %} {% endif %} {% if inv.requires_improvement_project == 'yes' %} {% trans "Improvement Project" %} {% endif %}
{% endif %} {% if inv.status == 'reply_submitted' and inv.requires_improvement_project == 'yes' and inv.improvement_project_note %}

{% trans "Improvement Project Recommended" %}

{{ inv.improvement_project_note }}

{% endif %}
{% endfor %} {% if can_manage_actions and complaint.is_active_status and not exp.is_used %}
{% if not exp.reminder_sent_at %} {% elif not exp.second_reminder_sent_at %} {% else %} {% trans "Reminders Sent" %} {% endif %}
{% if exp.reminder_sent_at %}
{% trans "1st reminder:" %} {{ exp.reminder_sent_at|date:"Y-m-d H:i" }} {% if exp.second_reminder_sent_at %} {% trans "2nd reminder:" %} {{ exp.second_reminder_sent_at|date:"Y-m-d H:i" }} {% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% else %} {% if not complaint.sent_to_any_department %}

{% trans "No requests sent yet" %}

{% if can_manage_actions and complaint.is_active_status %} {% endif %}
{% endif %} {% endif %}
function sendExplanationReminder(explanationId, reminderType) { const label = reminderType === 'first' ? '{% trans "first" %}' : '{% trans "second" %}'; if (!confirm('{% trans "Are you sure you want to send the" %} ' + label + ' {% trans "reminder?" %}')) { return; } const csrfToken = getCookie('csrftoken'); fetch(`/complaints/api/complaints/{{ complaint.id }}/send_explanation_reminder/`, { method: 'POST', headers: { 'X-CSRFToken': csrfToken, 'Content-Type': 'application/json' }, body: JSON.stringify({ explanation_id: explanationId, reminder_type: reminderType }) }) .then(response => { if (response.ok) { location.reload(); } else { response.json().then(data => { alert(data.error || '{% trans "Failed to send reminder. Please try again." %}'); }); } }) .catch(error => { console.error('Error:', error); alert('{% trans "An error occurred. Please try again." %}'); }); } function resendExplanation(token) { if (!confirm('{% trans "Are you sure you want to resend the explanation request?" %}')) { return; } fetch('/complaints/{{ complaint.id }}/resend-explanation/', { method: 'POST', headers: { 'X-CSRFToken': getCookie('csrftoken'), 'Content-Type': 'application/json' } }) .then(response => { if (response.ok) { alert('{% trans "Explanation request resent successfully!" %}'); } else { alert('{% trans "Failed to resend explanation request. Please try again." %}'); } }) .catch(error => { console.error('Error:', error); alert('{% trans "An error occurred. Please try again." %}'); }); } // Helper function to get CSRF token function getCookie(name) { let cookieValue = null; if (document.cookie && document.cookie !== '') { const cookies = document.cookie.split(';'); for (let i = 0; i < cookies.length; i++) { const cookie = cookies[i].trim(); if (cookie.substring(0, name.length + 1) === (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; }