--
This commit is contained in:
+248
-48
@@ -17,7 +17,7 @@ from dataclasses import dataclass
|
||||
from datetime import date
|
||||
|
||||
DATE_FIELDS = {"report_date", "date_of_visit"}
|
||||
APPROVAL_FORMS = {"standard_tour_plan", "tour_plan", "fare_chart"}
|
||||
APPROVAL_FORMS = {"standard_tour_plan", "tour_plan", "fare_chart", "expense_statement"}
|
||||
SERIAL = "#" # pseudo-field: the running "Sl.No." column
|
||||
_ALIGN = {"left": "l", "center": "c", "right": "r"}
|
||||
|
||||
@@ -27,7 +27,7 @@ Meta = tuple[str, str] | None # (printed label, column) — None leaves the slo
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Col:
|
||||
header: str
|
||||
header: str # a "\n" starts a second line in the printed heading
|
||||
field: str
|
||||
width: float # percent of the table
|
||||
align: str = "left"
|
||||
@@ -94,20 +94,19 @@ FORMS: dict[str, FormSpec] = {
|
||||
Col("Date", "report_date", 15.3, "center"),
|
||||
Col("From", "from_location", 30.2),
|
||||
Col("To", "to_location", 27.1),
|
||||
Col("Kilometers (KM)", "kilometers_km", 17.6, "center"),
|
||||
Col("Kilometers (KM)\n(One Way)", "kilometers_km", 17.6, "center"),
|
||||
),
|
||||
serial_field="serial_no",
|
||||
serial_dot=True,
|
||||
),
|
||||
"area_covered": FormSpec(
|
||||
"area_covered",
|
||||
"AREA COVERED",
|
||||
"AREA COVERAGE",
|
||||
_NAME_HQ_MONTH,
|
||||
(
|
||||
Col("SALE STATUS", "sale_status", 34.0),
|
||||
Col("AREA TO COVER", "area_to_cover", 24.3),
|
||||
Col("SALE OBJECTIVE", "sale_objective", 20.8),
|
||||
Col("STATUS", "status", 20.9, "center"),
|
||||
Col("AREA TO COVER", "area_to_cover", 40.0),
|
||||
Col("SALE OBJECTIVE", "sale_objective", 30.0),
|
||||
Col("STATUS", "status", 30.0, "center"),
|
||||
),
|
||||
min_rows=28,
|
||||
full_letterhead=False,
|
||||
@@ -130,8 +129,8 @@ FORMS: dict[str, FormSpec] = {
|
||||
"FIELD ACTIVITY REPORT",
|
||||
_NAME_HQ_MONTH,
|
||||
(
|
||||
Col("DATE", "report_date", 14.5, "center"),
|
||||
Col("STATION WORKED", "station_worked", 36.6),
|
||||
Col("DATE", "report_date", 17.5, "center"),
|
||||
Col("STATION WORKED", "station_worked", 33.6),
|
||||
Col("NO. OF DOCTORS CALLED", "no_of_doctors_called", 19.8, "center"),
|
||||
Col("NO. OF CHEMISTS/PDS CALLED", "no_of_chemists_pds_called", 29.1, "center"),
|
||||
),
|
||||
@@ -142,15 +141,19 @@ FORMS: dict[str, FormSpec] = {
|
||||
"sales_and_stock_statement": FormSpec(
|
||||
"sales_and_stock_statement",
|
||||
"SALES AND STOCK STATEMENT",
|
||||
_NAME_HQ_DATE_MONTH,
|
||||
# No date: the statement is for a month, not a day.
|
||||
(
|
||||
(("NAME:", "name"), None),
|
||||
(("HEADQUARTER:", "headquarter"), ("Month:", "month")),
|
||||
),
|
||||
(
|
||||
_serial("Sl.No.", 7.0),
|
||||
Col("Name of the Product", "product_name", 22.6),
|
||||
Col("Opening", "opening", 15.0, "center"),
|
||||
Col("Receipt", "receipt", 14.7, "center"),
|
||||
Col("Sale", "sale", 15.0, "center"),
|
||||
Col("Closing", "closing", 12.2, "center"),
|
||||
Col("Value in PTS", "value_in_pts", 13.5, "center"),
|
||||
Col("Name of the Product", "product_name", 27.0),
|
||||
Col("Value in PTS", "value_in_pts", 15.0, "center"),
|
||||
Col("Opening", "opening", 13.0, "center"),
|
||||
Col("Receipt", "receipt", 13.0, "center"),
|
||||
Col("Sale", "sale", 12.5, "center"),
|
||||
Col("Closing", "closing", 12.5, "center"),
|
||||
),
|
||||
min_rows=26,
|
||||
serial_field="serial_no",
|
||||
@@ -160,17 +163,14 @@ FORMS: dict[str, FormSpec] = {
|
||||
"SALES PROJECTION",
|
||||
_NAME_HQ_MONTH,
|
||||
(
|
||||
_serial("SL. No.", 7.1),
|
||||
Col("NAME OF THE PRODUCT", "product_name", 22.7),
|
||||
Col("PTS", "pts", 10.7, "center"),
|
||||
Col("SEC. QTY", "secondary_qty", 9.1, "center"),
|
||||
Col("VALUE", "value", 9.6, "center"),
|
||||
Col("CLOSING", "closing", 11.6, "center"),
|
||||
Col("SEC. VALUE", "secondary_value", 10.1, "center"),
|
||||
# Header text is filled in per report from the "month" column — see
|
||||
# _sales_projection_columns — never a hardcoded month.
|
||||
Col("SALES", "aug_sales", 9.6, "center"),
|
||||
Col("VALUE", "value_2", 9.5, "center"),
|
||||
# Printed under two group headings: CLOSING and PROJECTION (see the template).
|
||||
_serial("SL. No.", 7.0),
|
||||
Col("NAME OF THE PRODUCT", "product_name", 29.0),
|
||||
Col("PTS", "pts", 12.0, "center"),
|
||||
Col("QUANTITY", "closing_qty", 13.0, "center"),
|
||||
Col("VALUE", "closing_value", 13.0, "center"),
|
||||
Col("QUANTITY", "projection_qty", 13.0, "center"),
|
||||
Col("VALUE", "projection_value", 13.0, "center"),
|
||||
),
|
||||
min_rows=26,
|
||||
serial_field="serial_no",
|
||||
@@ -181,6 +181,16 @@ FORMS: dict[str, FormSpec] = {
|
||||
"DAILY CALL REPORT",
|
||||
_NAME_HQ_DATE_MONTH,
|
||||
),
|
||||
"expense_statement": FormSpec(
|
||||
"expense_statement",
|
||||
"Expenses Statement",
|
||||
(
|
||||
(("Name", "name"), ("Designation", "designation")),
|
||||
(("H.Q.", "headquarter"), None),
|
||||
),
|
||||
min_rows=27,
|
||||
serial_field="serial_no",
|
||||
),
|
||||
"weekly_report": FormSpec(
|
||||
"weekly_report",
|
||||
"Weekly Report",
|
||||
@@ -208,6 +218,49 @@ _CHEMIST_COLS = (
|
||||
Col("POB", "pob", 57.0),
|
||||
)
|
||||
_CHEMIST_FIELDS = tuple(c.field for c in _CHEMIST_COLS if c.field != SERIAL)
|
||||
# The morning day plan: who the MR intends to visit, and when. No outcomes yet.
|
||||
_PLAN_DOCTOR_COLS = (
|
||||
_serial("SR. NO.", 8.6),
|
||||
Col("DR. NAME", "doctor_name", 32.0),
|
||||
Col("QUALIFICATION", "qualification", 17.0),
|
||||
Col("PLANNED TIME", "planned_time", 14.0, "center"),
|
||||
Col("REMARKS", "remarks", 28.4),
|
||||
)
|
||||
_PLAN_CHEMIST_COLS = (
|
||||
_serial("SR. NO.", 10.2),
|
||||
Col("NAME OF THE CHEMIST", "chemist_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),
|
||||
Col("NAME", "name", 33.0),
|
||||
Col("TYPE", "kind", 14.0, "center"),
|
||||
Col("REASON NOT VISITED", "reason", 44.4),
|
||||
)
|
||||
|
||||
# Expense Statement: money columns print as Rs | P pairs, like the printed form.
|
||||
_EXPENSE_COLS = (
|
||||
_serial("", 3.0),
|
||||
Col("DATE", "report_date", 8.6, "center"),
|
||||
Col("From", "from_location", 11.6),
|
||||
Col("To", "to_location", 11.6),
|
||||
Col("Rs", "fare_rs", 6.0, "right"),
|
||||
Col("P.", "fare_p", 3.2, "center"),
|
||||
Col("H.Q", "da_hq", 5.6, "right"),
|
||||
Col("EX", "da_ex", 5.6, "right"),
|
||||
Col("OUT", "da_out", 5.6, "right"),
|
||||
Col("Rs", "postage_rs", 5.4, "right"),
|
||||
Col("P.", "postage_p", 3.2, "center"),
|
||||
Col("Rs", "other_expense_rs", 6.0, "right"),
|
||||
Col("P.", "other_expense_p", 3.2, "center"),
|
||||
Col("Rs", "total_rs", 7.0, "right"),
|
||||
Col("P.", "total_p", 3.2, "center"),
|
||||
Col("Business Achived", "business_achieved", 11.2, "center"),
|
||||
)
|
||||
_EXPENSE_SPLIT = ("fare", "postage", "other_expense", "total")
|
||||
_EXPENSE_WHOLE = ("da_hq", "da_ex", "da_out")
|
||||
_EXPENSE_AMOUNTS = ("fare", "da_hq", "da_ex", "da_out", "postage", "other_expense")
|
||||
|
||||
_WEEKLY_SUMMARY = (
|
||||
("No. of Days Worked", "no_of_days_worked"),
|
||||
@@ -234,7 +287,9 @@ def _display(field: str, value: object) -> str:
|
||||
text = _text(value)
|
||||
if field in DATE_FIELDS and text:
|
||||
try:
|
||||
return date.fromisoformat(text[:10]).strftime("%d/%m/%Y")
|
||||
day = date.fromisoformat(text[:10])
|
||||
# Core Doctor Call Conversion prints just the day of the month (13, 25…).
|
||||
return str(day.day) if field == "date_of_visit" else day.strftime("%d/%m/%Y")
|
||||
except ValueError:
|
||||
return text
|
||||
return text
|
||||
@@ -254,12 +309,79 @@ def _has(row: Row, fields: tuple[str, ...]) -> bool:
|
||||
return any(_text(row.get(field)) for field in fields)
|
||||
|
||||
|
||||
def _sales_projection_columns(cols: tuple[Col, ...], rows: list[Row]) -> tuple[Col, ...]:
|
||||
"""The printed form's "<Month>. Sales" column: the month it prints is whichever
|
||||
month the rows were actually filled in for, never a fixed month."""
|
||||
month = _distinct(rows, "month")
|
||||
header = f"{month[:3].upper()}. SALES" if month else "SALES"
|
||||
return tuple(Col(header, c.field, c.width, c.align) if c.field == "aug_sales" else c for c in cols)
|
||||
def _amount(value: object) -> float | None:
|
||||
text = _text(value).replace(",", "")
|
||||
try:
|
||||
return float(text) if text else None
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
def _rupees(amount: float | None) -> tuple[str, str]:
|
||||
"""(Rs, P) as the printed form splits money: 1234.5 -> ("1234", "50")."""
|
||||
if amount is None:
|
||||
return "", ""
|
||||
paise = round(amount * 100)
|
||||
return str(paise // 100), f"{paise % 100:02d}"
|
||||
|
||||
|
||||
def _whole(amount: float | None) -> str:
|
||||
if amount is None:
|
||||
return ""
|
||||
return f"{amount:.0f}" if amount == int(amount) else f"{amount:.2f}"
|
||||
|
||||
|
||||
def call_average(rows: list[Row], field: str) -> str:
|
||||
"""Field Activity Report: calls in `field` summed over the days worked, divided by those days.
|
||||
|
||||
A working day is a distinct date with a row (rows without a date count one day each); the MR
|
||||
never types an average — it is always worked out from the figures."""
|
||||
days = {_text(r.get("report_date"))[:10] or f"row-{i}" for i, r in enumerate(rows) if _has(r, ("report_date", field))}
|
||||
if not days:
|
||||
return ""
|
||||
total = sum(v for v in (_amount(r.get(field)) for r in rows) if v is not None)
|
||||
average = round(total / len(days), 2)
|
||||
return f"{average:g}" if average == int(average) else f"{average:.2f}"
|
||||
|
||||
|
||||
def _sales_projection_totals(rows: list[Row]) -> list[str]:
|
||||
"""The TOTAL line under the Sales Projection: one sum per figure column (blank when nothing is filled in)."""
|
||||
totals: list[str] = []
|
||||
for field in ("closing_qty", "closing_value", "projection_qty", "projection_value"):
|
||||
values = [v for v in (_amount(r.get(field)) for r in rows) if v is not None]
|
||||
totals.append(_whole(round(sum(values), 2)) if values else "")
|
||||
return totals
|
||||
|
||||
|
||||
def _expense_row(row: Row) -> Row:
|
||||
out: Row = dict(row)
|
||||
amounts = {f: _amount(row.get(f)) for f in _EXPENSE_AMOUNTS}
|
||||
# The total is always the sum of the day's amounts, whatever was stored.
|
||||
present = [a for a in amounts.values() if a is not None]
|
||||
amounts["total"] = sum(present) if present else None
|
||||
for field in _EXPENSE_SPLIT:
|
||||
out[f"{field}_rs"], out[f"{field}_p"] = _rupees(amounts[field])
|
||||
for field in _EXPENSE_WHOLE:
|
||||
if amounts[field] is not None:
|
||||
out[field] = _whole(amounts[field])
|
||||
return out
|
||||
|
||||
|
||||
def _expense_totals(rows: list[Row]) -> dict[str, str]:
|
||||
"""The TOTAL line under the table, one figure per money column."""
|
||||
sums: dict[str, float | None] = {}
|
||||
for field in _EXPENSE_AMOUNTS:
|
||||
values = [v for v in (_amount(r.get(field)) for r in rows) if v is not None]
|
||||
sums[field] = sum(values) if values else None
|
||||
present = [v for v in sums.values() if v is not None]
|
||||
sums["total"] = sum(present) if present else None
|
||||
totals: dict[str, str] = {}
|
||||
for field in _EXPENSE_SPLIT:
|
||||
totals[f"{field}_rs"], totals[f"{field}_p"] = _rupees(sums[field])
|
||||
for field in _EXPENSE_WHOLE:
|
||||
totals[field] = _whole(sums[field])
|
||||
totals["claimed"] = f"{sums['total']:,.2f}" if sums["total"] is not None else ""
|
||||
return totals
|
||||
|
||||
|
||||
def _grid(
|
||||
@@ -367,6 +489,20 @@ def build_form_context(
|
||||
)
|
||||
extra["stockist_visit"] = _distinct(rows, "stockist_visit")
|
||||
extra["order_value"] = _distinct(rows, "order_value")
|
||||
elif spec.template == "expense_statement":
|
||||
printed = [_expense_row(r) for r in rows]
|
||||
grids["main"] = _grid(
|
||||
_EXPENSE_COLS,
|
||||
printed,
|
||||
min_rows=spec.min_rows,
|
||||
serial_field=None if renumber else spec.serial_field,
|
||||
)
|
||||
extra["sums"] = _expense_totals(rows)
|
||||
dates = sorted(
|
||||
{_text(r.get("report_date"))[:10] for r in rows if _text(r.get("report_date"))}
|
||||
)
|
||||
extra["period_from"] = _display("report_date", dates[0]) if dates else ""
|
||||
extra["period_to"] = _display("report_date", dates[-1]) if dates else ""
|
||||
elif spec.template == "weekly_report":
|
||||
extra["reports"] = [
|
||||
{
|
||||
@@ -377,20 +513,19 @@ def build_form_context(
|
||||
for r in rows or [{}]
|
||||
]
|
||||
else:
|
||||
columns = spec.columns
|
||||
if table_name == "sales_projection":
|
||||
columns = _sales_projection_columns(columns, rows)
|
||||
grids["main"] = _grid(
|
||||
columns,
|
||||
spec.columns,
|
||||
rows,
|
||||
min_rows=spec.min_rows,
|
||||
serial_field=None if renumber else spec.serial_field,
|
||||
serial_dot=spec.serial_dot,
|
||||
table_width=spec.table_width,
|
||||
)
|
||||
if table_name == "sales_projection":
|
||||
extra["totals"] = _sales_projection_totals(rows)
|
||||
if table_name == "field_activity_report":
|
||||
extra["doctor_call_avg"] = _distinct(rows, "doctor_call_avg")
|
||||
extra["chemist_call_avg"] = _distinct(rows, "chemist_call_avg")
|
||||
extra["doctor_call_avg"] = call_average(rows, "no_of_doctors_called")
|
||||
extra["chemist_call_avg"] = call_average(rows, "no_of_chemists_pds_called")
|
||||
|
||||
approval = None
|
||||
if table_name in APPROVAL_FORMS:
|
||||
@@ -426,12 +561,22 @@ _OUTCOME_NOTE = {"NOT_AVAILABLE": "Not available", "RESCHEDULED": "Rescheduled"}
|
||||
|
||||
|
||||
def _doctor_remarks(call) -> str:
|
||||
"""The remarks column; a visit that did not happen is flagged, since the form has no outcome column."""
|
||||
"""The remarks column; a visit that did not happen is flagged, since the form has no outcome column,
|
||||
and so is any gift given."""
|
||||
note = _OUTCOME_NOTE.get(getattr(call.call_outcome, "value", str(call.call_outcome)), "")
|
||||
return ". ".join(part for part in (note, (call.remarks or "").strip()) if part)
|
||||
# The printed form has no gift column either, so a gift is noted with the remarks.
|
||||
gift = (getattr(call, "gift", None) or "").strip()
|
||||
gift = f"Gift: {gift}" if gift else ""
|
||||
return ". ".join(part for part in (note, gift, (call.remarks or "").strip()) if part)
|
||||
|
||||
|
||||
def build_dcr_context(dcr, doctor_calls, chemist_calls, approval: dict[str, str] | None = None) -> dict[str, object]:
|
||||
def build_dcr_context(
|
||||
dcr,
|
||||
doctor_calls,
|
||||
chemist_calls,
|
||||
approval: dict[str, str] | None = None,
|
||||
missed: list[Row] | None = None,
|
||||
) -> 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
|
||||
@@ -439,13 +584,22 @@ def build_dcr_context(dcr, doctor_calls, chemist_calls, approval: dict[str, str]
|
||||
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
|
||||
approval signature with its date and time.
|
||||
|
||||
A morning day plan uses the same form with a PLANNED TIME column in place of the
|
||||
visit details. An end-of-day report adds the planned visits that were not made
|
||||
(``missed``: name / kind / reason rows).
|
||||
"""
|
||||
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
|
||||
doctors = [
|
||||
{
|
||||
"doctor_name": c.doctor.name,
|
||||
"qualification": c.doctor.qualification or "",
|
||||
"product_promote": c.product_promote or "",
|
||||
"product_sample": c.product_sample or "",
|
||||
"product_promote": _products(c.product_promote),
|
||||
"product_sample": _products(c.product_sample),
|
||||
"remarks": _doctor_remarks(c),
|
||||
}
|
||||
for c in doctor_calls
|
||||
@@ -457,17 +611,63 @@ def build_dcr_context(dcr, doctor_calls, chemist_calls, approval: dict[str, str]
|
||||
]
|
||||
return {
|
||||
"template": "dcr",
|
||||
"label": "Daily Call Report",
|
||||
"title": "DAILY CALL REPORT",
|
||||
"label": "Daily Call Report (Self)" if is_self else "Daily Call Report",
|
||||
"title": "DAILY CALL REPORT (SELF)" if is_self else "DAILY CALL REPORT",
|
||||
"title_suffix": f"{dcr.mr.full_name} — {dcr.report_date.strftime('%d/%m/%Y')}",
|
||||
"full_letterhead": True,
|
||||
"meta_rows": meta,
|
||||
"grids": {
|
||||
"doctors": _grid(_DOCTOR_COLS, doctors, min_rows=10),
|
||||
"chemists": _grid(_CHEMIST_COLS, chemists, min_rows=5, table_width=84),
|
||||
**({"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",
|
||||
"mr_signed": f"{dcr.mr.full_name} ({dcr.mr.employee_code})",
|
||||
"approval": approval, # {"name": ..., "at": "dd/mm/yyyy HH:MM"} or None
|
||||
}
|
||||
|
||||
|
||||
def _products(names: list[str] | str | None) -> str:
|
||||
"""Several products share one cell of the printed form."""
|
||||
return names if isinstance(names, str) else ", ".join(names or [])
|
||||
|
||||
|
||||
def _build_plan_context(dcr, doctor_calls, chemist_calls, approval) -> dict[str, object]:
|
||||
doctors = [
|
||||
{
|
||||
"doctor_name": c.doctor.name,
|
||||
"qualification": c.doctor.qualification or "",
|
||||
"planned_time": c.visit_time.strftime("%H:%M"),
|
||||
"remarks": (c.remarks or "").strip(),
|
||||
}
|
||||
for c in doctor_calls
|
||||
]
|
||||
chemists = [
|
||||
{"chemist_name": c.chemist.name, "planned_time": c.visit_time.strftime("%H:%M")}
|
||||
for c in chemist_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"))],
|
||||
]
|
||||
return {
|
||||
"template": "dcr",
|
||||
"label": "Daily Call Report (Plan)",
|
||||
"title": "DAILY CALL REPORT (PLAN)",
|
||||
"title_suffix": f"{dcr.mr.full_name} — {dcr.report_date.strftime('%d/%m/%Y')}",
|
||||
"full_letterhead": True,
|
||||
"meta_rows": meta,
|
||||
"grids": {
|
||||
"doctors": _grid(_PLAN_DOCTOR_COLS, doctors, min_rows=10),
|
||||
"chemists": _grid(_PLAN_CHEMIST_COLS, chemists, min_rows=5, table_width=84),
|
||||
},
|
||||
"is_plan": True,
|
||||
"stockist_visit": "",
|
||||
"order_value": "",
|
||||
"mr_remarks": dcr.mr_remarks or "",
|
||||
"mr_signed": f"{dcr.mr.full_name} ({dcr.mr.employee_code})",
|
||||
"approval": approval,
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ from app.common.enums import AuditAction, EntityType
|
||||
from app.config.settings import settings
|
||||
from app.pdf.forms import approval_signature_line, build_dcr_context, build_form_context
|
||||
from app.reports.models import DailyCallReport
|
||||
from app.reports.serializers import planned_visits
|
||||
from app.users.models import User
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -198,11 +199,17 @@ class PDFService:
|
||||
return {"name": approver.full_name, "at": when}
|
||||
|
||||
async def _context(self, dcr: DailyCallReport) -> dict:
|
||||
missed = [
|
||||
{"name": p.name, "kind": p.kind.title(), "reason": p.missed_reason}
|
||||
for p in planned_visits(dcr)
|
||||
if p.status == "MISSED"
|
||||
]
|
||||
return build_dcr_context(
|
||||
dcr,
|
||||
sorted(dcr.doctor_calls, key=lambda c: c.visit_time),
|
||||
sorted(dcr.chemist_calls, key=lambda c: c.visit_time),
|
||||
await self._approval(dcr),
|
||||
missed,
|
||||
)
|
||||
|
||||
async def render_bytes(self, dcr: DailyCallReport) -> bytes:
|
||||
|
||||
@@ -19,19 +19,27 @@
|
||||
|
||||
{% block form %}
|
||||
{{ grid(grids.doctors, left=True) }}
|
||||
<h2 class="section">CHEMIST VISIT</h2>
|
||||
<h2 class="section">{{ "CHEMISTS TO VISIT" if is_plan else "CHEMIST VISIT" }}</h2>
|
||||
{{ grid(grids.chemists, left=True) }}
|
||||
{% if is_plan %}
|
||||
{% if mr_remarks %}<div class="visit"><div><b>REMARKS :</b> {{ mr_remarks }}</div></div>{% endif %}
|
||||
{% else %}
|
||||
{% if grids.missed %}
|
||||
<h2 class="section">PLANNED VISITS NOT MADE</h2>
|
||||
{{ grid(grids.missed, left=True) }}
|
||||
{% endif %}
|
||||
<div class="visit">
|
||||
<div><b>STOCKIST VISIT :</b> {{ stockist_visit }}</div>
|
||||
<div><b>ORDER :</b> {{ order_value }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block signature %}
|
||||
<table class="dcr-sign">
|
||||
<tr>
|
||||
<td class="mr">
|
||||
<div class="sign-label">MR Signature</div>
|
||||
<div class="sign-label">{{ signer_label | default("MR Signature") }}</div>
|
||||
<div class="signed">{{ mr_signed }}</div>
|
||||
</td>
|
||||
<td class="am">
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
{{ company_name }}
|
||||
{{ company_address }}
|
||||
Website: {{ company_website }} E-Mail: {{ company_email }} PHONE: {{ company_phone }}
|
||||
DAILY CALL REPORT
|
||||
{{ title }}
|
||||
{% for pair in meta_rows %}{% for slot in pair %}{% if slot %}{{ slot[0] }} {{ slot[1] }} {% endif %}{% endfor %}
|
||||
{% endfor %}
|
||||
SR.NO | DR. NAME | QUALIFICATION | PRODUCT PROMOTE | PRODUCT SAMPLE | REMARKS
|
||||
{{ grids.doctors.headers | join(' | ') }}
|
||||
{% for r in grids.doctors.rows %}{{ r.cells | join(' | ') }}
|
||||
{% endfor %}
|
||||
CHEMIST VISIT
|
||||
SR.NO | NAME OF THE CHEMIST | POB
|
||||
{{ "CHEMISTS TO VISIT" if is_plan else "CHEMIST VISIT" }}
|
||||
{{ grids.chemists.headers | join(' | ') }}
|
||||
{% for r in grids.chemists.rows %}{{ r.cells | join(' | ') }}
|
||||
{% endfor %}
|
||||
STOCKIST VISIT : {{ stockist_visit }}
|
||||
{% if grids.missed %}PLANNED VISITS NOT MADE
|
||||
{{ grids.missed.headers | join(' | ') }}
|
||||
{% for r in grids.missed.rows %}{{ r.cells | join(' | ') }}
|
||||
{% endfor %}
|
||||
{% endif %}{% if not is_plan %}STOCKIST VISIT : {{ stockist_visit }}
|
||||
ORDER : {{ order_value }}
|
||||
|
||||
{% endif %}
|
||||
MR Signature: {{ mr_signed }}
|
||||
{% if approval %}APPROVAL SIGNATURE: {{ approval.name }} ({{ approval.at }})
|
||||
{% endif %}
|
||||
@@ -30,7 +30,7 @@
|
||||
<table class="grid{% if left %} left{% endif %}" style="width:{{ g.width }}">
|
||||
<colgroup>{% for w in g.widths %}<col style="width:{{ w }}">{% endfor %}</colgroup>
|
||||
<thead>
|
||||
<tr>{% for h in g.headers %}<th>{{ h }}</th>{% endfor %}</tr>
|
||||
<tr>{% for h in g.headers %}<th>{% for part in h.split("\n") %}{{ part }}{% if not loop.last %}<br>{% endif %}{% endfor %}</th>{% endfor %}</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for r in g.rows %}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
{% extends "forms/_form_base.html" %}
|
||||
{% from "forms/_macros.html" import letterhead %}
|
||||
|
||||
{% block page_box %}size: A4 landscape; margin: 7mm 11mm;{% endblock %}
|
||||
|
||||
{% block form_styles %}
|
||||
body { font-size: 10pt; }
|
||||
.company .name { font-size: 24pt; }
|
||||
.company .name { line-height: 1.05; }
|
||||
.company .line { font-size: 9pt; line-height: 1.2; font-style: italic; }
|
||||
h1.title { margin: 2mm 0 2mm; font-size: 15pt; letter-spacing: 1.5pt; font-style: italic; text-decoration: none; text-align: left; }
|
||||
h1.title .ln { min-width: 34mm; font-size: 10.5pt; letter-spacing: 0; font-style: normal; }
|
||||
table.who { width: 100%; border-collapse: collapse; margin: 1.5mm 0 0; }
|
||||
table.who td { padding: 0; font-size: 10pt; font-style: italic; font-weight: bold; white-space: nowrap; }
|
||||
table.who .ln { min-width: 52mm; font-style: normal; font-weight: normal; }
|
||||
table.who .ln.short { min-width: 30mm; }
|
||||
table.grid th, table.grid td { padding: 0 .9mm; }
|
||||
table.grid th { height: 5mm; font-size: 9pt; font-weight: normal; }
|
||||
table.grid thead tr:first-child th { font-weight: bold; }
|
||||
table.grid td { height: 4.2mm; font-size: 9pt; overflow-wrap: normal; white-space: nowrap; overflow: hidden; }
|
||||
table.grid tr.total td { font-weight: bold; }
|
||||
table.grid td.no { font-size: 8pt; }
|
||||
table.foot { width: 100%; margin-top: 2mm; border-collapse: collapse; page-break-inside: avoid; }
|
||||
table.foot td { vertical-align: top; padding: 0 2mm 0 0; font-size: 9pt; }
|
||||
.box { border: .7pt solid #000; padding: 1mm 2mm; }
|
||||
.box .office { text-align: center; font-style: italic; font-weight: bold; letter-spacing: 1.5pt; margin-bottom: 1mm; }
|
||||
.box .ln { min-width: 34mm; text-align: left; padding-left: 1mm; }
|
||||
.line-row { margin: 1.2mm 0; white-space: nowrap; }
|
||||
.status div { margin: .3mm 0; white-space: nowrap; }
|
||||
.status .ln { min-width: 18mm; height: 3.8mm; }
|
||||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
{{ letterhead(full_letterhead) }}
|
||||
<table class="who">
|
||||
<tr>
|
||||
<td>Name <span class="ln">{{ meta_rows[0][0][1] }}</span></td>
|
||||
<td>Designation <span class="ln">{{ meta_rows[0][1][1] }}</span></td>
|
||||
<td>H.Q. <span class="ln short">{{ meta_rows[1][0][1] }}</span></td>
|
||||
<td>Date <span class="ln short"></span></td>
|
||||
</tr>
|
||||
</table>
|
||||
<h1 class="title">Expenses Statement from Dt. <span class="ln">{{ period_from }}</span> to <span class="ln">{{ period_to }}</span></h1>
|
||||
|
||||
{% set g = grids.main %}
|
||||
<table class="grid" style="width:{{ g.width }}">
|
||||
<colgroup>{% for w in g.widths %}<col style="width:{{ w }}">{% endfor %}</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th rowspan="2"></th>
|
||||
<th rowspan="2">DATE</th>
|
||||
<th colspan="2">Place Of Visit</th>
|
||||
<th colspan="2">Fare</th>
|
||||
<th colspan="3">Daily Allowance</th>
|
||||
<th colspan="2">Postage</th>
|
||||
<th colspan="2">Other Expence</th>
|
||||
<th colspan="2">Total</th>
|
||||
<th rowspan="2">Business Achived</th>
|
||||
</tr>
|
||||
<tr>
|
||||
{% for h in g.headers[2:-1] %}<th>{{ h }}</th>{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for r in g.rows %}
|
||||
<tr>{% for c in r.cells %}<td class="{{ g.aligns[loop.index0] }}{% if loop.first %} no{% endif %}">{{ c }}</td>{% endfor %}</tr>
|
||||
{% endfor %}
|
||||
<tr class="total">
|
||||
<td colspan="4" class="c">TOTAL</td>
|
||||
<td class="r">{{ sums.fare_rs }}</td><td class="c">{{ sums.fare_p }}</td>
|
||||
<td class="r">{{ sums.da_hq }}</td><td class="r">{{ sums.da_ex }}</td><td class="r">{{ sums.da_out }}</td>
|
||||
<td class="r">{{ sums.postage_rs }}</td><td class="c">{{ sums.postage_p }}</td>
|
||||
<td class="r">{{ sums.other_expense_rs }}</td><td class="c">{{ sums.other_expense_p }}</td>
|
||||
<td class="r">{{ sums.total_rs }}</td><td class="c">{{ sums.total_p }}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table class="foot">
|
||||
<tr>
|
||||
<td style="width:46%">
|
||||
<div class="box">
|
||||
<div class="office">For Office Use Only</div>
|
||||
<div class="line-row">Amount Claimed <span class="ln">{{ sums.claimed }}</span> Amt. Passed <span class="ln"></span></div>
|
||||
<div class="line-row">Deduction / Addition with reason <span class="ln" style="min-width:60mm"></span></div>
|
||||
</div>
|
||||
</td>
|
||||
<td style="width:26%">
|
||||
<div class="box status">
|
||||
<div class="office">Report Status</div>
|
||||
<div>Daily Report :- <span class="ln"></span></div>
|
||||
<div>Stock and Sale Statement :- <span class="ln"></span></div>
|
||||
<div>Weekly Report :- <span class="ln"></span></div>
|
||||
<div>Monthly Apprasal :- <span class="ln"></span></div>
|
||||
</div>
|
||||
</td>
|
||||
<td style="width:28%">
|
||||
<div class="line-row">Signature :- <span class="ln">{{ approval.mr_name }}</span></div>
|
||||
<div class="line-row">Checked by :- <span class="ln">{% if approval.value != "PENDING" %}{{ approval.value }}{% endif %}</span></div>
|
||||
<div class="line-row">DATE :- <span class="ln">{{ approval.when }}</span></div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
{% endblock %}
|
||||
@@ -1,5 +1,4 @@
|
||||
{% extends "forms/_form_base.html" %}
|
||||
{% from "forms/_macros.html" import grid %}
|
||||
|
||||
{# Arial throughout, title tucked directly under the company name — as printed. #}
|
||||
{% block form_styles %}
|
||||
@@ -10,11 +9,35 @@
|
||||
font-size: 14pt;
|
||||
}
|
||||
table.grid th, table.grid td { font-family: "Liberation Sans", Arial, "DejaVu Sans", sans-serif; }
|
||||
table.grid th { height: 10mm; font-size: 9.5pt; }
|
||||
table.grid th { height: 7mm; font-size: 9.5pt; }
|
||||
table.grid th.sub { height: 6mm; font-size: 8.5pt; }
|
||||
table.grid td { font-size: 9.5pt; }
|
||||
table.grid td:nth-child(2) { font-weight: bold; }
|
||||
table.grid tr.total td { font-weight: bold; }
|
||||
table.grid tr.total td:nth-child(2) { text-align: right; }
|
||||
{% endblock %}
|
||||
|
||||
{# Two heading rows: CLOSING and PROJECTION each span their QUANTITY and VALUE. #}
|
||||
{% block form %}
|
||||
{{ grid(grids.main) }}
|
||||
{% set g = grids.main %}
|
||||
<table class="grid" style="width:{{ g.width }}">
|
||||
<colgroup>{% for w in g.widths %}<col style="width:{{ w }}">{% endfor %}</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
{% for h in g.headers[:3] %}<th rowspan="2">{{ h }}</th>{% endfor %}
|
||||
<th colspan="2">CLOSING</th>
|
||||
<th colspan="2">PROJECTION</th>
|
||||
</tr>
|
||||
<tr>{% for h in g.headers[3:] %}<th class="sub">{{ h }}</th>{% endfor %}</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for r in g.rows %}
|
||||
<tr>{% for c in r.cells %}<td class="{{ g.aligns[loop.index0] }}">{{ c }}</td>{% endfor %}</tr>
|
||||
{% endfor %}
|
||||
<tr class="total">
|
||||
<td></td><td>TOTAL</td><td></td>
|
||||
{% for t in totals %}<td class="{{ g.aligns[loop.index0 + 3] }}">{{ t }}</td>{% endfor %}
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user