fix final step
This commit is contained in:
parent
9592c00565
commit
394546dc67
9 changed files with 137 additions and 82 deletions
|
@ -1,6 +1,7 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth import get_user_model
|
||||
from common.models import BaseModel
|
||||
from _helpers.utils import jalali_converter2
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
@ -35,4 +36,7 @@ class CertificateInstance(BaseModel):
|
|||
def __str__(self):
|
||||
return f"گواهی {self.process_instance.code}"
|
||||
|
||||
def jissued_at(self):
|
||||
return jalali_converter2(self.issued_at)
|
||||
|
||||
|
||||
|
|
|
@ -1,28 +1,71 @@
|
|||
{% extends '_base.html' %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>تاییدیه - {{ instance.code }}</title>
|
||||
{% load static %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container py-4">
|
||||
<div class="text-center mb-4">
|
||||
{% if template.company and template.company.logo %}
|
||||
<img src="{{ template.company.logo.url }}" alt="logo" style="max-height:90px">
|
||||
{% endif %}
|
||||
<h4 class="mt-2">{{ cert.rendered_title }}</h4>
|
||||
{% if template.company %}<div class="text-muted">{{ template.company.name }}</div>{% endif %}
|
||||
</div>
|
||||
<div style="white-space:pre-line; line-height:1.9;">
|
||||
{{ cert.rendered_body|safe }}
|
||||
</div>
|
||||
<div class="mt-5 d-flex justify-content-between">
|
||||
<div>تاریخ: {{ cert.issued_at }}</div>
|
||||
<div class="text-center">
|
||||
{% if template.company and template.company.signature %}
|
||||
<img src="{{ template.company.signature.url }}" alt="seal" style="max-height:120px">
|
||||
<!-- Fonts (match project) -->
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Public+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap" rel="stylesheet">
|
||||
|
||||
<!-- Core CSS (same as other prints) -->
|
||||
<link rel="stylesheet" href="{% static 'assets/vendor/css/rtl/core.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'assets/vendor/css/rtl/theme-default.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'assets/css/demo.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'assets/css/persian-fonts.css' %}">
|
||||
|
||||
<style>
|
||||
@page { size: A4; margin: 1cm; }
|
||||
@media print { body { print-color-adjust: exact; } .no-print { display: none !important; } }
|
||||
.header { border-bottom: 1px solid #dee2e6; padding-bottom: 16px; margin-bottom: 24px; }
|
||||
.company-name { font-weight: 600; }
|
||||
.body-text { white-space: pre-line; line-height: 1.9; }
|
||||
.signature-section { margin-top: 40px; border-top: 1px solid #dee2e6; padding-top: 24px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container-fluid py-3">
|
||||
<!-- Top-left request info -->
|
||||
<div class="d-flex mb-2">
|
||||
<div class="ms-auto text-end">
|
||||
<div class="">شماره درخواست: {{ instance.code }}</div>
|
||||
<div class="">تاریخ: {{ cert.jissued_at }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Header with logo and company -->
|
||||
<div class="header text-center">
|
||||
{% if template.company and template.company.logo %}
|
||||
<img src="{{ template.company.logo.url }}" alt="logo" style="max-height:90px">
|
||||
{% endif %}
|
||||
<div>مهر و امضای شرکت</div>
|
||||
<h4 class="mt-2">{{ cert.rendered_title }}</h4>
|
||||
{% if template.company %}
|
||||
<div class="text-muted company-name">{{ template.company.name }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Certificate body -->
|
||||
<div class="body-text">
|
||||
{{ cert.rendered_body|safe }}
|
||||
</div>
|
||||
|
||||
<!-- Signature -->
|
||||
<div class="signature-section d-flex justify-content-end">
|
||||
<div class="text-center">
|
||||
<div>مهر و امضای تایید کننده</div>
|
||||
<div class="text-muted">{{ template.company.name }}</div>
|
||||
{% if template.company and template.company.signature %}
|
||||
<img src="{{ template.company.signature.url }}" alt="seal" style="max-height:200px">
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>window.print()</script>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
<script>
|
||||
window.onload = function() { window.print(); setTimeout(function(){ window.close(); }, 200); };
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -18,40 +18,49 @@
|
|||
<link rel="stylesheet" href="{% static 'assets/vendor/libs/bs-stepper/bs-stepper.css' %}">
|
||||
<!-- Persian Date Picker CSS -->
|
||||
<link rel="stylesheet" href="https://unpkg.com/persian-datepicker@latest/dist/css/persian-datepicker.min.css">
|
||||
<style>
|
||||
@media print {
|
||||
.no-print { display: none !important; }
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% include '_toasts.html' %}
|
||||
|
||||
<!-- Instance Info Modal -->
|
||||
{% instance_info_modal instance %}
|
||||
|
||||
{% csrf_token %}
|
||||
<div class="container-xxl flex-grow-1 container-p-y">
|
||||
<div class="row">
|
||||
<div class="col-12 mb-4">
|
||||
<div class="d-flex align-items-center justify-content-between mb-3 no-print">
|
||||
<div class="d-flex align-items-center justify-content-between mb-3">
|
||||
<div>
|
||||
<h4 class="mb-1">{{ step.name }}: {{ instance.process.name }}</h4>
|
||||
<small class="text-muted d-block">
|
||||
اشتراک آب: {{ instance.well.water_subscription_number|default:"-" }}
|
||||
| نماینده: {{ instance.representative.profile.national_code|default:"-" }}
|
||||
{% instance_info instance %}
|
||||
</small>
|
||||
</div>
|
||||
<div class="d-flex gap-2">
|
||||
<a class="btn btn-outline-secondary" target="_blank" href="{% url 'certificates:certificate_print' instance.id %}"><i class="bx bx-printer"></i> پرینت</a>
|
||||
<a class="btn btn-outline-secondary" target="_blank" href="{% url 'certificates:certificate_print' instance.id %}">
|
||||
<i class="bx bx-printer me-2"></i> پرینت
|
||||
</a>
|
||||
|
||||
<a href="{% url 'processes:request_list' %}" class="btn btn-outline-secondary">بازگشت</a>
|
||||
<a href="{% url 'processes:request_list' %}" class="btn btn-outline-secondary">
|
||||
<i class="bx bx-chevron-right bx-sm ms-sm-n2"></i>
|
||||
بازگشت
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bs-stepper wizard-vertical vertical mt-2 no-print">
|
||||
<div class="bs-stepper wizard-vertical vertical mt-2">
|
||||
{% stepper_header instance step %}
|
||||
<div class="bs-stepper-content">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="d-flex mb-2">
|
||||
<div class="ms-auto text-end">
|
||||
<div>شماره درخواست: {{ instance.code }}</div>
|
||||
<div>تاریخ: {{ cert.jissued_at }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-center mb-3">
|
||||
{% if template.company and template.company.logo %}
|
||||
<img src="{{ template.company.logo.url }}" alt="logo" style="max-height:80px">
|
||||
|
@ -62,21 +71,22 @@
|
|||
<div class="mt-3" style="white-space:pre-line; line-height:1.9;">
|
||||
{{ cert.rendered_body|safe }}
|
||||
</div>
|
||||
<div class="mt-4 d-flex justify-content-between align-items-end">
|
||||
<div>
|
||||
<div>تاریخ صدور: {{ cert.issued_at }}</div>
|
||||
</div>
|
||||
<div class="signature-section d-flex justify-content-end">
|
||||
<div class="text-center">
|
||||
<div>مهر و امضای تایید کننده</div>
|
||||
<div class="text-muted">{{ template.company.name }}</div>
|
||||
{% if template.company and template.company.signature %}
|
||||
<img src="{{ template.company.signature.url }}" alt="seal" style="max-height:100px">
|
||||
<img src="{{ template.company.signature.url }}" alt="seal" style="max-height:200px">
|
||||
{% endif %}
|
||||
<div>مهر و امضای شرکت</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer d-flex justify-content-between">
|
||||
{% if previous_step %}
|
||||
<a href="{% url 'processes:step_detail' instance.id previous_step.id %}" class="btn btn-label-secondary">قبلی</a>
|
||||
<a href="{% url 'processes:step_detail' instance.id previous_step.id %}" class="btn btn-label-secondary">
|
||||
<i class="bx bx-chevron-right bx-sm ms-sm-n2"></i>
|
||||
قبلی
|
||||
</a>
|
||||
{% else %}<span></span>{% endif %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
|
|
|
@ -33,13 +33,14 @@ def _render_template(template: CertificateTemplate, instance: ProcessInstance):
|
|||
'company_name': (template.company.name if template.company else '') or '',
|
||||
'customer_full_name': rep.get_full_name() if rep else '',
|
||||
'water_subscription_number': getattr(well, 'water_subscription_number', '') or '',
|
||||
'address': getattr(well, 'address', '') or '',
|
||||
'address': getattr(well, 'county', '') or '',
|
||||
'visit_date_jalali': _to_jalali(getattr(latest_report, 'visited_date', None)) if latest_report else '',
|
||||
}
|
||||
title = (template.title or '').format(**ctx)
|
||||
body = (template.body or '')
|
||||
# Render body placeholders with bold values
|
||||
for k, v in ctx.items():
|
||||
body = body.replace(f"{{{{ {k} }}}}", str(v))
|
||||
body = body.replace(f"{{{{ {k} }}}}", f"<strong>{str(v)}</strong>")
|
||||
return title, body
|
||||
|
||||
|
||||
|
@ -50,6 +51,7 @@ def certificate_step(request, instance_id, step_id):
|
|||
# Ensure all previous steps are completed and invoice settled
|
||||
prior_steps = instance.process.steps.filter(order__lt=instance.current_step.order if instance.current_step else 9999)
|
||||
incomplete = StepInstance.objects.filter(process_instance=instance, step__in=prior_steps).exclude(status='completed').exists()
|
||||
|
||||
if incomplete:
|
||||
messages.error(request, 'ابتدا همه مراحل قبلی را تکمیل کنید')
|
||||
return redirect('processes:request_list')
|
||||
|
@ -87,6 +89,17 @@ def certificate_step(request, instance_id, step_id):
|
|||
except Exception:
|
||||
messages.error(request, 'شما مجوز تایید این مرحله را ندارید')
|
||||
return redirect('processes:step_detail', instance_id=instance.id, step_id=step.id)
|
||||
# Safety check: ensure ALL previous steps are completed before approval
|
||||
try:
|
||||
prev_steps_qs = instance.process.steps.filter(order__lt=step.order)
|
||||
has_incomplete = StepInstance.objects.filter(process_instance=instance, step__in=prev_steps_qs).exclude(status='completed').exists()
|
||||
if has_incomplete:
|
||||
messages.error(request, 'ابتدا همه مراحل قبلی را تکمیل کنید')
|
||||
return redirect('processes:step_detail', instance_id=instance.id, step_id=step.id)
|
||||
except Exception:
|
||||
messages.error(request, 'خطا در بررسی مراحل قبلی')
|
||||
return redirect('processes:step_detail', instance_id=instance.id, step_id=step.id)
|
||||
|
||||
cert.approved = True
|
||||
cert.approved_at = timezone.now()
|
||||
cert.save()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue