Server backup 2026-11-07 of uncommitted work in projects/pharma-web-celtic

Snapshot of the working tree on srv1071960 (branch main), taken during
server cleanup. .env files, node_modules, builds, logs and media were excluded.
This commit is contained in:
Shubhankar45
2026-11-07 05:43:12 +00:00
parent b001e2d03c
commit 0d30c58bf0
98 changed files with 1878 additions and 573 deletions
+35 -6
View File
@@ -80,7 +80,7 @@ FORMS: dict[str, FormSpec] = {
Col("From", "from_location", 25.0),
Col("To", "to_location", 23.2),
Col("POB", "pob", 15.3, "center"),
Col("Stockiest Visit", "stockiest_visit", 15.2, "center"),
Col("Stockist Visit", "stockiest_visit", 15.2, "center"),
),
serial_field="serial_no",
serial_dot=True,
@@ -231,6 +231,17 @@ _PLAN_CHEMIST_COLS = (
Col("NAME OF THE CHEMIST", "chemist_name", 52.8),
Col("PLANNED TIME", "planned_time", 37.0, "center"),
)
# Stockist visits: printed only when the report has any, so other reports keep their layout.
_STOCKIST_COLS = (
_serial("SR. NO.", 10.2),
Col("NAME OF THE STOCKIST", "stockist_name", 32.8),
Col("POB", "pob", 57.0),
)
_PLAN_STOCKIST_COLS = (
_serial("SR. NO.", 10.2),
Col("NAME OF THE STOCKIST", "stockist_name", 52.8),
Col("PLANNED TIME", "planned_time", 37.0, "center"),
)
# End-of-day report: the planned visits that were not made, and why.
_MISSED_COLS = (
_serial("SR. NO.", 8.6),
@@ -576,13 +587,14 @@ def build_dcr_context(
chemist_calls,
approval: dict[str, str] | None = None,
missed: list[Row] | None = None,
stockist_calls=(),
) -> dict[str, object]:
"""The approved Daily Call Report, laid out exactly like the printed company form.
Same template family, headings, column widths and number of ruled lines as the
``daily_call_report_csv`` company form: 10 doctor lines and 5 chemist lines, filled
from the top in visit order; more visits simply continue on the next page. The only
additions are the signatures: the MR's name, and (once approved) the Area Manager's
additions are the signatures: the MR's name, and (once approved) the Area Business Manager's
approval signature with its date and time.
A morning day plan uses the same form with a PLANNED TIME column in place of the
@@ -592,8 +604,8 @@ def build_dcr_context(
report_type = getattr(dcr, "report_type", None)
report_type = getattr(report_type, "value", report_type)
if report_type == "PLAN":
return _build_plan_context(dcr, doctor_calls, chemist_calls, approval)
is_self = report_type == "SELF" # an Area Manager's own report: no approval signature
return _build_plan_context(dcr, doctor_calls, chemist_calls, approval, stockist_calls)
is_self = report_type == "SELF" # an Area Business Manager's own report: no approval signature
doctors = [
{
"doctor_name": c.doctor.name,
@@ -605,6 +617,7 @@ def build_dcr_context(
for c in doctor_calls
]
chemists = [{"chemist_name": c.chemist.name, "pob": c.pob or ""} for c in chemist_calls]
stockists = [{"stockist_name": c.stockist.name, "pob": c.pob or ""} for c in stockist_calls]
meta = [
[("NAME:", dcr.mr.full_name), ("Date:", dcr.report_date.strftime("%d/%m/%Y"))],
[("HEADQUARTER:", dcr.headquarters.name), ("Month:", dcr.report_date.strftime("%B %Y"))],
@@ -619,12 +632,17 @@ def build_dcr_context(
"grids": {
"doctors": _grid(_DOCTOR_COLS, doctors, min_rows=10),
"chemists": _grid(_CHEMIST_COLS, chemists, min_rows=5, table_width=84),
**(
{"stockists": _grid(_STOCKIST_COLS, stockists, min_rows=0, table_width=84)}
if stockists
else {}
),
**({"missed": _grid(_MISSED_COLS, missed, min_rows=0)} if missed else {}),
},
"is_plan": False,
"stockist_visit": dcr.stockist_visit or "",
"order_value": dcr.order_value or "",
"signer_label": "Area Manager Signature" if is_self else "MR Signature",
"signer_label": "Area Business Manager Signature" if is_self else "MR Signature",
"mr_signed": f"{dcr.mr.full_name} ({dcr.mr.employee_code})",
"approval": approval, # {"name": ..., "at": "dd/mm/yyyy HH:MM"} or None
}
@@ -635,7 +653,9 @@ def _products(names: list[str] | str | None) -> str:
return names if isinstance(names, str) else ", ".join(names or [])
def _build_plan_context(dcr, doctor_calls, chemist_calls, approval) -> dict[str, object]:
def _build_plan_context(
dcr, doctor_calls, chemist_calls, approval, stockist_calls=()
) -> dict[str, object]:
doctors = [
{
"doctor_name": c.doctor.name,
@@ -649,6 +669,10 @@ def _build_plan_context(dcr, doctor_calls, chemist_calls, approval) -> dict[str,
{"chemist_name": c.chemist.name, "planned_time": c.visit_time.strftime("%H:%M")}
for c in chemist_calls
]
stockists = [
{"stockist_name": c.stockist.name, "planned_time": c.visit_time.strftime("%H:%M")}
for c in stockist_calls
]
meta = [
[("NAME:", dcr.mr.full_name), ("Date:", dcr.report_date.strftime("%d/%m/%Y"))],
[("HEADQUARTER:", dcr.headquarters.name), ("Month:", dcr.report_date.strftime("%B %Y"))],
@@ -663,6 +687,11 @@ def _build_plan_context(dcr, doctor_calls, chemist_calls, approval) -> dict[str,
"grids": {
"doctors": _grid(_PLAN_DOCTOR_COLS, doctors, min_rows=10),
"chemists": _grid(_PLAN_CHEMIST_COLS, chemists, min_rows=5, table_width=84),
**(
{"stockists": _grid(_PLAN_STOCKIST_COLS, stockists, min_rows=0, table_width=84)}
if stockists
else {}
),
},
"is_plan": True,
"stockist_visit": "",
+31
View File
@@ -0,0 +1,31 @@
"""Printable list of the Doctors & Chemists directory.
The browser sends the rows it already shows (the user's own scope, filters and search), so
this prints nothing the user cannot already see; it only lays them out on the company letterhead."""
from fastapi import APIRouter, Depends, Response
from pydantic import BaseModel, Field
from app.auth.dependencies import get_current_user
from app.pdf.service import csv_table_pdf_bytes
from app.users.models import User
router = APIRouter(prefix="/directory", tags=["directory"])
class DirectoryPdf(BaseModel):
title: str = Field(min_length=1, max_length=60)
columns: list[str] = Field(min_length=1, max_length=12)
rows: list[dict[str, str]] = Field(max_length=5000)
@router.post("/pdf")
async def directory_pdf(payload: DirectoryPdf, _: User = Depends(get_current_user)) -> Response:
columns = tuple(c for c in payload.columns if c.isidentifier())
rows = [{c: r.get(c, "") for c in columns} for r in payload.rows]
name = "".join(ch for ch in payload.title.lower() if ch.isalnum()) or "directory"
return Response(
csv_table_pdf_bytes(f"directory_{name}", payload.title, columns, rows),
media_type="application/pdf",
headers={"Content-Disposition": f'inline; filename="{name}.pdf"'},
)
+3 -2
View File
@@ -142,7 +142,7 @@ def _approval_signature_line(
table_name: str,
approval_status: str | None = None,
am_name: str | None = None,
am_role: str = "Area Manager",
am_role: str = "Area Business Manager",
) -> str:
return approval_signature_line(table_name, approval_status, am_name)
@@ -154,7 +154,7 @@ def csv_table_pdf_bytes(
rows: list[dict[str, object]],
approval_status: str | None = None,
am_name: str | None = None,
am_role: str = "Area Manager",
am_role: str = "Area Business Manager",
approved_at: str | None = None,
renumber: bool = False,
) -> bytes:
@@ -210,6 +210,7 @@ class PDFService:
sorted(dcr.chemist_calls, key=lambda c: c.visit_time),
await self._approval(dcr),
missed,
sorted(dcr.stockist_calls, key=lambda c: c.visit_time),
)
async def render_bytes(self, dcr: DailyCallReport) -> bytes:
+5 -1
View File
@@ -21,6 +21,10 @@
{{ grid(grids.doctors, left=True) }}
<h2 class="section">{{ "CHEMISTS TO VISIT" if is_plan else "CHEMIST VISIT" }}</h2>
{{ grid(grids.chemists, left=True) }}
{% if grids.stockists %}
<h2 class="section">{{ "STOCKISTS TO VISIT" if is_plan else "STOCKIST VISIT" }}</h2>
{{ grid(grids.stockists, left=True) }}
{% endif %}
{% if is_plan %}
{% if mr_remarks %}<div class="visit"><div><b>REMARKS :</b> {{ mr_remarks }}</div></div>{% endif %}
{% else %}
@@ -46,7 +50,7 @@
{% if approval %}
<div class="sign-label">APPROVAL SIGNATURE:</div>
<div class="signed">{{ approval.name }}</div>
<div class="signed-when">Area Manager &middot; {{ approval.at }}</div>
<div class="signed-when">Area Business Manager &middot; {{ approval.at }}</div>
{% endif %}
</td>
</tr>
+5 -1
View File
@@ -11,7 +11,11 @@ Website: {{ company_website }} E-Mail: {{ company_email }} PHONE: {{ company_p
{{ grids.chemists.headers | join(' | ') }}
{% for r in grids.chemists.rows %}{{ r.cells | join(' | ') }}
{% endfor %}
{% if grids.missed %}PLANNED VISITS NOT MADE
{% if grids.stockists %}{{ "STOCKISTS TO VISIT" if is_plan else "STOCKIST VISIT" }}
{{ grids.stockists.headers | join(' | ') }}
{% for r in grids.stockists.rows %}{{ r.cells | join(' | ') }}
{% endfor %}
{% endif %}{% if grids.missed %}PLANNED VISITS NOT MADE
{{ grids.missed.headers | join(' | ') }}
{% for r in grids.missed.rows %}{{ r.cells | join(' | ') }}
{% endfor %}
+1 -1
View File
@@ -45,7 +45,7 @@
<div class="sign-right">{{ text }}</div>
{% endmacro %}
{# Tour plan, standard tour plan and fare chart: MR signature plus the AM approval. #}
{# Tour plan, standard tour plan and fare chart: MR signature plus the ABM approval. #}
{% macro sign_approval(approval) %}
<table class="sign-approval">
<tr>