{% extends "base.html" %} {% block title %}Import Contracts & Facilities{% endblock %} {% block content %}

Import Contracts & Facilities

Bulk-create contracts and their facilities from an Excel workbook.

Download Template Back to Contracts
{# ── Format guide ── #}
Excel Format — two sheets
Sheet: Contracts
  • contract_name *required
  • description — optional
  • active — yes/no (default: yes)
Sheet: Facilities
  • contract_name *required — must match a row in Contracts sheet
  • facility_name *required
  • address, contact_person, contact_phone — optional
  • active — yes/no (default: yes)
Tips
  • Contracts that already exist (by name) are reused — not duplicated
  • Facilities that already exist within the same contract are skipped
  • The Facilities sheet is optional — you can import contracts only
  • Download the template to see the expected structure
{# ── Upload form (Phase 1) ── #} {% if not preview_rows %}
Upload Excel File
Maximum recommended file size: 2 MB.
{% else %} {# ── Preview results (Phase 1 response) ── #}
Preview — {{ preview_rows|length }} row(s) parsed {{ valid_count }} ready {% set exists_count = preview_rows | selectattr('status', 'equalto', 'exists') | list | length %} {% if exists_count > 0 %} {{ exists_count }} existing {% endif %} {% set err_count = preview_rows | selectattr('status', 'equalto', 'error') | list | length %} {% if err_count > 0 %} {{ err_count }} error(s) {% endif %}
{% for row in preview_rows %} {% endfor %}
Row Sheet Contract Name Facility Name Status
{{ row.row }} {{ row.sheet }} {{ row.contract_name or '—' }} {{ row.facility_name or '—' }} {% if row.status == 'ok' %} Ready {% elif row.status == 'exists' %} Exists {{ row.note }} {% else %} Error
    {% for e in row.errors %}
  • {{ e }}
  • {% endfor %}
{% endif %}
{# ── Action buttons (Phase 2 trigger) ── #} {% if has_errors %}
Errors found. Fix the issues above and re-upload. {% if valid_count > 0 %} You may still import the {{ valid_count }} valid row(s) by clicking below. {% endif %}
{% endif %}
{% if valid_count > 0 %}
{% endif %} Upload Different File
{% endif %} {% endblock %}