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

Input Shop Checkout

Review cart items, select the farmer beneficiary, and place a direct purchase order.

{% if messages %}
{% for message in messages %}
{{ message }}
{% endfor %}
{% endif %} {% if pending_order %}

Pending payment: Order {{ pending_order.order_number }} (KES {{ pending_order.total_amount }})

Keep this page open until M-Pesa confirms payment. You will be redirected to tracking after payment succeeds.

{% endif %}

Cart Items ({{ cart_summary.count }})

Quantity updates automatically
{% csrf_token %}
{% for line in cart_lines %}
{{ line.package.input.name }}

{{ line.package.input.name }}

{{ line.package.variety.name }} • {{ line.unit_label }}

In stock: {{ line.available_stock }} {% if line.stock_issue %} Adjusted to available stock {% endif %} {% if not line.cash_allowed %} Direct purchase not allowed {% endif %}
Unit: KES {{ line.package.selling_price }}
Line subtotal: KES {{ line.line_subtotal }}
VAT included: KES {{ line.line_vat }}
{% if line.line_discount > 0 %}
Cash discount: -KES {{ line.line_discount }}
{% endif %}
Line total: KES {{ line.line_total }}
{% csrf_token %}
{% endfor %} {% if not cart_lines %} {% if pending_order and pending_order_items %} {% for item in pending_order_items %}
{{ item.package_name_snapshot }}

Pending Order Item

{{ item.package_name_snapshot }}

{% if item.variety_name_snapshot %}

{{ item.variety_name_snapshot }}

{% endif %}

{{ item.unit_label_snapshot }} {% if item.manufacturer_name_snapshot %} • {{ item.manufacturer_name_snapshot }}{% endif %}

Qty: {{ item.quantity }}
Unit: KES {{ item.unit_price_snapshot|floatformat:0 }}
Line total: KES {{ item.line_total|floatformat:0 }}
{% endfor %} {% else %}
{% if pending_order %} No active cart items. Waiting for payment confirmation on order {{ pending_order.order_number }}. {% else %} Your cart is empty. {% endif %}
{% endif %} {% endif %}

Order Summary

Subtotal KES {{ cart_summary.subtotal }}
Cash Discount -KES {{ cart_summary.discount }}
VAT (Included) KES {{ cart_summary.vat_total|default:0 }}
Pickup Station Fee KES {{ cart_summary.pickup_fee|default:0 }}
Total Payable KES {{ cart_summary.total_with_pickup|default:cart_summary.total }}

Place Order

{% if cart_lines %}
{% csrf_token %} {% if eligible_farmers|length > 1 %}
{% else %}
Farmer Beneficiary: {{ default_farmer.get_full_name }}
{% endif %}
{% if pickup_stations %}

Pickup fee is added to the total payable.

{% else %}
No pickup stations configured yet.
{% endif %}

Payment (Required)

{% if request.user.type == 'FARMER' %} Farmers pay by M-Pesa only. Select the phone number to receive the STK prompt and complete payment. {% else %} Cash is for admin/field officer only and is recorded immediately. M-Pesa sends an STK push after the order is created and will place the order after Safaricom confirms payment. {% endif %}

{% elif pending_order %}
{% csrf_token %}

Pending order {{ pending_order.order_number }}

Total: KES {{ pending_order.total_amount }} | Paid: KES {{ pending_order.amount_paid }} | Balance: KES {{ pending_order_balance_due }}

{% if pending_latest_payment %}

Last payment attempt: {{ pending_latest_payment.get_status_display }} {% if pending_latest_payment.failure_reason %} ({{ pending_latest_payment.failure_reason }}) {% endif %}

{% endif %}
{% else %}
Your cart is empty. Add items from the shop to continue.
{% endif %}
{% endblock %}