{% extends 'auth/dashboard.html' %} {% load static %} {% block content %}

Welcome back, {{ request.user.get_full_name }}! 👋

{% if request.user.type == 'FARMER' %} Here's your farming dashboard overview {% elif request.user.is_superuser %} Here's your complete system overview {% else %} Here's your dashboard overview {% endif %}

{% if request.user.type == 'FARMER' %} New Contract Request {% endif %} {% if request.user.is_superuser %} New Contract {% endif %}
{% if request.user.type == 'FARMER' %}

Group Farming

{% if user_groups_count > 0 %}

You are a member of {{ user_groups_count }} group{{ user_groups_count|pluralize }} {% if is_group_signatory %} Signatory {% endif %}

{% if pending_group_signatures > 0 %}

{{ pending_group_signatures }} contract{{ pending_group_signatures|pluralize }} awaiting your signature

{% endif %} {% else %}

You are not a member of any farmer group yet.

Contact your field officer or administrator to join a group.

{% endif %}
{% if user_groups_count > 0 %} View My Groups {% if is_group_signatory %} Group Contracts {% endif %} {% else %} {% endif %}
{% if user_groups_count > 0 and user_groups_count <= 3 %}

Your Groups:

{% for group in user_groups %}

{{ group.name }}

{{ group.location }}

{% endfor %}
{% endif %}
{% endif %}

Total Contracts

{{ total_contracts|default:0 }}

{% if request.user.is_superuser %}

System-wide

{% endif %}
{% if request.user.type == 'FARMER' %}

Total Paid

KES {{ total_paid|default:0|floatformat:0 }}

{{ payment_completion_rate|default:0 }}% Complete

Pending Payments

KES {{ total_pending|default:0|floatformat:0 }}

Due Soon

{% elif request.user.is_superuser %}

Total Revenue

KES {{ total_payments_completed|default:0|floatformat:0 }}

{{ collection_rate|default:0 }}% Collection

Active Farmers

{{ total_farmers|default:0 }}

Registered

{% endif %}

Overdue Payments

{{ overdue_count|default:0 }}

Needs Attention

{% if contract_status_labels %}

Contract Status Distribution

{% endif %} {% if request.user.is_superuser and monthly_contract_labels or request.user.type == 'FARMER' and monthly_payment_labels %}

{% if request.user.type == 'FARMER' %}Payment History{% else %}Monthly Contracts{% endif %}

{% endif %}
{% if request.user.is_superuser %}
{% if payment_status_labels %}

Payment Status Overview

{% endif %} {% if top_input_labels %}

Top Inputs by Demand

{% endif %}
{% endif %}

Quick Actions

{% if request.user.type == 'FARMER' %} View My Contracts Payment History Browse Inputs {% elif request.user.is_superuser %} Create Contract Manage Users Manage Inputs Rates and Market Fees {% elif contract_can_manage_market_commission %} Market Fees {% endif %}

{% if request.user.type == 'FARMER' %} {% if upcoming_payments %}Upcoming Payments{% else %}Payment Schedule{% endif %} {% else %} Overdue Payments Alert {% endif %}

{% if request.user.type == 'FARMER' %} {% endif %} {% if request.user.type == 'FARMER' %} {% for payment in upcoming_payments %} {% empty %} {% endfor %} {% else %} {% for payment in overdue_payments %} {% empty %} {% endfor %} {% endif %}
Contract Amount Due Date StatusAction
#{{ payment.contract.id }} KES {{ payment.balance|floatformat:0 }} {{ payment.due_date|date:"M d, Y" }} {{ payment.get_status_display }} Pay Now

No upcoming payments

#{{ payment.contract.id }}
{{ payment.contract.farmer.get_full_name }}
KES {{ payment.balance|floatformat:0 }} {{ payment.due_date|date:"M d, Y" }} OVERDUE

No overdue payments

Recent Contracts

View All
{% if request.user.is_superuser %} {% endif %} {% for contract in recent_contracts %} {% if request.user.is_superuser %} {% endif %} {% empty %} {% endfor %}
IDFarmerType Amount Status Created Actions
#{{ contract.id }}{{ contract.farmer.get_full_name }}{{ contract.get_type_display }} KES {{ contract.total_amount|floatformat:0 }} {{ contract.get_status_display }} {{ contract.created_at|date:"M d, Y" }} View
No contracts found
{% if request.user.is_superuser and recent_payments %}

Recent Payments

View All
{% for payment in recent_payments %} {% endfor %}
Receipt # Farmer Contract Type Amount Date
{{ payment.mpesa_receipt_number|default:"N/A" }} {{ payment.farmer.get_full_name }} #{{ payment.contract.id }} {{ payment.get_payment_type_display }} KES {{ payment.amount|floatformat:0 }} {{ payment.created_at|date:"M d, Y H:i" }}
{% endif %} {% if request.user.is_superuser and low_stock_packages %}

Low Stock Alerts

{% for package in low_stock_packages %}

{{ package.variety.name }}

{{ package.stock }} left

{{ package.input.name }} - {{ package.unit_quantity }} {{ package.unit_type }}

Update Stock
{% endfor %}
{% endif %}
{% endblock %}